From fe611f77dee4b607b2148aa2c9a1257e54a122e4 Mon Sep 17 00:00:00 2001 From: Timothy Middelkoop Date: Mon, 1 Dec 2025 03:39:54 +0000 Subject: [PATCH] IPv6: Add dnsmasq non-static config Signed-off-by: Timothy Middelkoop --- overlays/host/internal/host_test.go | 58 ++++++++++++++++++- overlays/host/internal/warewulf.conf | 4 +- overlays/host/internal/warewulf.conf-ipv6 | 6 -- overlays/host/internal/warewulf.conf-static | 6 ++ .../rootfs/etc/dnsmasq.d/ww4-hosts.conf.ww | 27 ++++++--- .../internal/systemd_networkd_test.go | 2 + .../etc/systemd/network/default.network.ww | 10 ++-- 7 files changed, 91 insertions(+), 22 deletions(-) delete mode 100644 overlays/host/internal/warewulf.conf-ipv6 diff --git a/overlays/host/internal/host_test.go b/overlays/host/internal/host_test.go index f8a39c68..19b46e7c 100644 --- a/overlays/host/internal/host_test.go +++ b/overlays/host/internal/host_test.go @@ -53,9 +53,16 @@ func Test_hostOverlay(t *testing.T) { log: host_dnsmasq, header: "", }, + { + name: "host:dnsmasq(static)", + conf: "warewulf.conf-static", + args: []string{"--render", "host", "host", "etc/dnsmasq.d/ww4-hosts.conf.ww"}, + log: host_dnsmasq_static, + header: "", + }, { name: "host:/etc/exports", - conf: "", + conf: "warewulf.conf", args: []string{"--render", "host", "host", "etc/exports.ww"}, log: host_exports, header: "", @@ -264,8 +271,6 @@ dhcp-boot=tag:aarch64,"/warewulf/snponly.efi" # iPXE binary will get the following configuration file dhcp-boot=tag:iPXE,"http://192.168.0.1:9873/ipxe/${mac:hexhyp}?assetkey=${asset}&uuid=${uuid}" dhcp-no-override -# define the the range -dhcp-range=192.168.0.100,192.168.0.199,255.255.255.0,6h # IPv6 routing announcements enable-ra @@ -282,6 +287,53 @@ dhcp-option=tag:aarch64,option6:bootfile-url,"tftp://[2001:db8::1]/warewulf/snpo # IPv6 iPXE binary will get the following configuration file dhcp-option=tag:iPXE,option6:bootfile-url,"http://[2001:db8::1]:9873/ipxe/${mac:hexhyp}?assetkey=${asset}&uuid=${uuid}" +# define the dhcp range +dhcp-range=192.168.0.100,192.168.0.199,255.255.255.0,6h +dhcp-range=2001:db8::,ra-stateless,64,6h +` + +const host_dnsmasq_static string = `backupFile: false +writeFile: true +Filename: etc/dnsmasq.d/ww4-hosts.conf +# This file was autgenerated by warewulf + +# select the x86 hosts which will get the iXPE binary +dhcp-match=set:bios,option:client-arch,0 #legacy boot +dhcp-match=set:x86PC,option:client-arch, 7 #EFI x86-64 +dhcp-match=set:x86PC,option:client-arch, 6 #EFI x86-64 +dhcp-match=set:x86PC,option:client-arch, 9 #EFI x86-64 +dhcp-match=set:aarch64,option:client-arch, 11 #EFI aarch64 +dhcp-match=set:iPXE,77,"iPXE" +dhcp-userclass=set:iPXE,iPXE +dhcp-vendorclass=set:efi-http,HTTPClient:Arch:00016 +dhcp-option-force=tag:efi-http,60,HTTPClient +# for http boot always use shim/grub +dhcp-boot=tag:efi-http,"http://192.168.0.1:9873/efiboot/shim.efi" +dhcp-boot=tag:x86PC,"/warewulf/ipxe-snponly-x86_64.efi" +dhcp-boot=tag:aarch64,"/warewulf/snponly.efi" +# iPXE binary will get the following configuration file +dhcp-boot=tag:iPXE,"http://192.168.0.1:9873/ipxe/${mac:hexhyp}?assetkey=${asset}&uuid=${uuid}" +dhcp-no-override + +# IPv6 routing announcements +enable-ra + +# IPv6 matching (client-arch=61) +dhcp-match=set:x86PC,option6:61,0007 # EFI x86-64 +dhcp-match=set:aarch64,option6:61,0011 # EFI aarch64 +dhcp-vendorclass=set:x86PC,enterprise:343,PXEClient:Arch:00007 # EFI x86-64 +dhcp-vendorclass=set:aarch64,enterprise:343,PXEClient:Arch:00011 # EFI aarch64 + +# IPv6 bootfile-url (iPXE EFI binary) +dhcp-option=tag:x86PC,option6:bootfile-url,"tftp://[2001:db8::1]/warewulf/ipxe-snponly-x86_64.efi" +dhcp-option=tag:aarch64,option6:bootfile-url,"tftp://[2001:db8::1]/warewulf/snponly.efi" +# IPv6 iPXE binary will get the following configuration file +dhcp-option=tag:iPXE,option6:bootfile-url,"http://[2001:db8::1]:9873/ipxe/${mac:hexhyp}?assetkey=${asset}&uuid=${uuid}" + +# define the dhcp range +dhcp-range=192.168.0.100,192.168.0.199,255.255.255.0,6h +dhcp-range=2001:db8::100,2001:db8::1FF,6h + # hosts dhcp-host=e6:92:39:49:7b:03,id:00:03:00:01:e6:92:39:49:7b:03,set:warewulf,192.168.3.21,[2001:db8::111],node1,infinite dhcp-host=9a:77:29:73:14:f1,id:00:03:00:01:9a:77:29:73:14:f1,set:warewulf,192.168.3.22,[2001:db8::112],node1,infinite diff --git a/overlays/host/internal/warewulf.conf b/overlays/host/internal/warewulf.conf index 76fda62d..6cc62633 100644 --- a/overlays/host/internal/warewulf.conf +++ b/overlays/host/internal/warewulf.conf @@ -1,5 +1,4 @@ ipaddr: 192.168.0.1/24 -ipaddr6: 2001:db8::1/64 netmask: 255.255.255.0 network: 192.168.0.0 warewulf: @@ -10,8 +9,11 @@ warewulf: host overlay: true dhcp: enabled: true + template: default range start: 192.168.0.100 range end: 192.168.0.199 + range6 start: "" + range6 end: "" tftp: enabled: false nfs: diff --git a/overlays/host/internal/warewulf.conf-ipv6 b/overlays/host/internal/warewulf.conf-ipv6 deleted file mode 100644 index af5334bd..00000000 --- a/overlays/host/internal/warewulf.conf-ipv6 +++ /dev/null @@ -1,6 +0,0 @@ -ipaddr6: 2001:db8::1 -prefixlen6: 64 -dhcp: - enabled: true - range6 start: 2001:db8::100 - range6 end: 2001:db8::0:1FF diff --git a/overlays/host/internal/warewulf.conf-static b/overlays/host/internal/warewulf.conf-static index 90562647..26d11eed 100644 --- a/overlays/host/internal/warewulf.conf-static +++ b/overlays/host/internal/warewulf.conf-static @@ -1,6 +1,8 @@ ipaddr: 192.168.0.1/24 netmask: 255.255.255.0 network: 192.168.0.0 +ipaddr6: 2001:db8::1/64 +prefixlen6: 64 warewulf: port: 9873 secure: false @@ -10,6 +12,10 @@ warewulf: dhcp: enabled: true template: static + range start: 192.168.0.100 + range end: 192.168.0.199 + range6 start: 2001:db8::100 + range6 end: 2001:db8::1FF tftp: enabled: false nfs: diff --git a/overlays/host/rootfs/etc/dnsmasq.d/ww4-hosts.conf.ww b/overlays/host/rootfs/etc/dnsmasq.d/ww4-hosts.conf.ww index 8da1b86e..782570d1 100644 --- a/overlays/host/rootfs/etc/dnsmasq.d/ww4-hosts.conf.ww +++ b/overlays/host/rootfs/etc/dnsmasq.d/ww4-hosts.conf.ww @@ -30,15 +30,9 @@ dhcp-no-override enable-tftp tftp-root={{ $.Tftp.TftpRoot }} {{- end }} -{{ if and $.Dhcp.RangeStart $.Dhcp.RangeEnd -}} -# define the the range -dhcp-range={{$.Dhcp.RangeStart}},{{$.Dhcp.RangeEnd}},{{$.Netmask}},6h -{{ end -}} -{{ if and $.Dhcp.Range6Start $.Dhcp.Range6End -}} -dhcp-range={{$.Dhcp.Range6Start}},{{$.Dhcp.Range6End}},6h -{{ end -}} {{- if .Ipv6 }} + # IPv6 routing announcements enable-ra @@ -61,6 +55,21 @@ dhcp-option=tag:iPXE,option6:bootfile-url,"http://[{{$.Ipaddr6}}]:{{$.Warewulf.P {{- end }} +# define the dhcp range +{{ if and $.Dhcp.RangeStart $.Dhcp.RangeEnd -}} +dhcp-range={{$.Dhcp.RangeStart}},{{$.Dhcp.RangeEnd}},{{$.Netmask}},6h +{{ else -}} +dhcp-range={{$.Network}},static,{{$.Netmask}},6h +{{ end -}} +{{ if .Ipv6 -}} +{{ if and $.Dhcp.Range6Start $.Dhcp.Range6End -}} +dhcp-range={{$.Dhcp.Range6Start}},{{$.Dhcp.Range6End}},6h +{{ else -}} +dhcp-range={{$.Network6}},ra-stateless,{{$.PrefixLen6}},6h +{{ end -}} +{{ end -}} + +{{ if eq .Dhcp.Template "static" }} # hosts {{ range $node := $.AllNodes -}} {{ range $devname, $netdev := $node.NetDevs -}} @@ -68,7 +77,7 @@ dhcp-host= {{- if $netdev.Hwaddr -}} {{$netdev.Hwaddr}},id:00:03:00:01:{{$netdev.Hwaddr}}, {{- end -}} - set:warewulf, + set:{{ $node.Tags.Tag | default "warewulf" }}, {{- if $netdev.Ipaddr -}} {{- $netdev.Ipaddr -}}, {{- end -}} @@ -78,3 +87,5 @@ dhcp-host= {{$node.Id}},infinite {{ end -}} {{ end -}} + +{{- end -}} diff --git a/overlays/systemd.networkd/internal/systemd_networkd_test.go b/overlays/systemd.networkd/internal/systemd_networkd_test.go index 70f9e83c..a13ad4bc 100644 --- a/overlays/systemd.networkd/internal/systemd_networkd_test.go +++ b/overlays/systemd.networkd/internal/systemd_networkd_test.go @@ -86,6 +86,7 @@ Address=192.168.3.22/24 Gateway=192.168.3.1 IPv6AcceptRA=no IPv6PrivacyExtensions=false +LinkLocalAddressing=ipv6 Address=2001:db8::23/64 Gateway=2001:db8::1 @@ -128,6 +129,7 @@ Address=192.168.3.22/24 Gateway=192.168.3.1 IPv6AcceptRA=no IPv6PrivacyExtensions=false +LinkLocalAddressing=ipv6 Address=2001:db8::23/64 Gateway=2001:db8::1 diff --git a/overlays/systemd.networkd/rootfs/etc/systemd/network/default.network.ww b/overlays/systemd.networkd/rootfs/etc/systemd/network/default.network.ww index ecf6139b..9559629b 100644 --- a/overlays/systemd.networkd/rootfs/etc/systemd/network/default.network.ww +++ b/overlays/systemd.networkd/rootfs/etc/systemd/network/default.network.ww @@ -15,29 +15,31 @@ DHCP=no {{- end }} {{- if $netdev.IpCIDR }} Address={{ $netdev.IpCIDR }} -{{- end }} {{- if $netdev.Gateway }} Gateway={{ $netdev.Gateway }} {{- end }} +{{- end }} {{- if $netdev.IpCIDR6 }} IPv6AcceptRA=no IPv6PrivacyExtensions=false +LinkLocalAddressing=ipv6 Address={{ $netdev.IpCIDR6 }} -{{- end }} {{- if $netdev.Gateway6 }} Gateway={{ $netdev.Gateway6 }} {{- end }} +{{- end }} {{- range $tk, $tv := $netdev.Tags }} {{- if regexMatch "^DNS[0-9]*$" $tk }} DNS={{ $tv }} {{- end }} {{- end }} -{{- if $netdev.MTU }} - [Link] +{{- if $netdev.MTU }} MTUBytes={{ $netdev.MTU }} {{- end }} + +{{- /* Route */}} {{- range $tk, $tv := $netdev.Tags }} {{- if eq (substr 0 5 $tk) "route" }} {{- $route := splitList "," $tv }}