From 310837ddb3bc940c36ecc70c1471a1c3ce25a281 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 26 Apr 2023 19:06:28 -0400 Subject: [PATCH] Use statically-generated mac addresses. --- ansible/roles/bhyve/files/bhyve_netgraph_bridge.bash | 11 ++++++++++- ansible/roles/jail_nat_dhcp/files/kea-dhcp4.conf | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ansible/roles/bhyve/files/bhyve_netgraph_bridge.bash b/ansible/roles/bhyve/files/bhyve_netgraph_bridge.bash index 7741002..23db06c 100644 --- a/ansible/roles/bhyve/files/bhyve_netgraph_bridge.bash +++ b/ansible/roles/bhyve/files/bhyve_netgraph_bridge.bash @@ -38,6 +38,8 @@ function start_vm { bridge_name="bridge_${host_interface_name}" ip_range="$5" + mac_address=$(calculate_mac_address "$name") + assert_bridge "$host_interface_name" "$bridge_name" "$ip_range" bridge_link_name=$(detect_available_link "${bridge_name}") @@ -60,7 +62,8 @@ function start_vm { -H \ -s 0,hostbridge \ -s "4,nvme,/dev/zvol/${zfs_path}/disk0" \ - -s "2:0,virtio-net,netgraph,path=${bridge_name}:,peerhook=${bridge_link_name}" \ + -s "2:0,virtio-net,netgraph,path=${bridge_name}:,peerhook=${bridge_link_name},mac=${mac_address}" \ + -s 3,ahci-cd,/vm/.iso/archlinux-2023.04.01-x86_64.iso \ -s 29,fbuf,tcp=0.0.0.0:5900,w=1920,h=1080 \ -s 30,xhci,tablet \ -s 31,lpc -l com1,stdio \ @@ -129,5 +132,11 @@ function ng_exists { ngctl status "${1}" >/dev/null 2>&1 } +function calculate_mac_address { + name="$1" + source=$(md5 -r -s "$name" | awk '{print $1}') + echo "${source:0:2}:${source:2:2}:${source:4:2}:${source:6:2}:${source:8:2}:${source:10:2}" +} + main "${@}" diff --git a/ansible/roles/jail_nat_dhcp/files/kea-dhcp4.conf b/ansible/roles/jail_nat_dhcp/files/kea-dhcp4.conf index 9e09e7f..ce2043c 100644 --- a/ansible/roles/jail_nat_dhcp/files/kea-dhcp4.conf +++ b/ansible/roles/jail_nat_dhcp/files/kea-dhcp4.conf @@ -6,12 +6,18 @@ "subnet4": [ { "subnet": "10.215.1.0/24", - "pools": [ { "pool": "10.215.1.10-10.215.1.250" } ], + "pools": [ { "pool": "10.215.1.10-10.215.1.200" } ], "option-data": [ { "name": "routers", "data": "10.215.1.1" } + ], + "reservations": [ + { + "hw-address": "d6:19:4c:68:fc:c7", + "ip-address": "10.215.1.201" + } ] } ],