From b071bdc86a58037f6c745647c97fca202f3caef9 Mon Sep 17 00:00:00 2001 From: Andrea Barberio Date: Tue, 23 Apr 2019 09:24:48 +0100 Subject: [dhcpv6] Solicit messages derive default IAID from MAC address IAID must be set by the client. This patch generates the IAID from the MAC address of the interface. To do so, a new WithIAID modifier is added, the interface of NewSolicitWithCID now requires a hwaddr parameter, and NewAdvertiseFromSolicit copies the IA_NA option from the solicit if present. Signed-off-by: Andrea Barberio --- dhcpv6/modifiers.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'dhcpv6/modifiers.go') diff --git a/dhcpv6/modifiers.go b/dhcpv6/modifiers.go index eaa370d..200a602 100644 --- a/dhcpv6/modifiers.go +++ b/dhcpv6/modifiers.go @@ -77,6 +77,21 @@ func WithIANA(addrs ...OptIAAddress) Modifier { } } +// WithIAID updates an OptIANA option with the provided IAID +func WithIAID(iaid [4]byte) Modifier { + return func(d DHCPv6) { + opt := d.GetOneOption(OptionIANA) + if opt == nil { + opt = &OptIANA{ + Options: Options{}, + } + } + iaNa := opt.(*OptIANA) + copy(iaNa.IaId[:], iaid[:]) + d.UpdateOption(iaNa) + } +} + // WithDNS adds or updates an OptDNSRecursiveNameServer func WithDNS(dnses ...net.IP) Modifier { return func(d DHCPv6) { -- cgit v1.2.3