From 54843950dd9d42efe310d0b69feee4c6f02a2582 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 29 Apr 2019 19:16:19 +0200 Subject: [PATCH] dhcp6: allow overriding hardwareaddr in test This fixes the breakage introduced by commit https://github.com/insomniacslk/dhcp/commit/8166b9a9db9b180c02622ebf3dcff01ff2b2e0a6 --- internal/dhcp6/dhcp6.go | 16 ++++++++++++---- internal/dhcp6/dhcp6_test.go | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/dhcp6/dhcp6.go b/internal/dhcp6/dhcp6.go index ba36eda..66683c0 100644 --- a/internal/dhcp6/dhcp6.go +++ b/internal/dhcp6/dhcp6.go @@ -48,6 +48,11 @@ type ClientConfig struct { Conn net.PacketConn // for testing TransactionIDs []dhcpv6.TransactionID // for testing + + // HardwareAddr allows overriding the hardware address in tests. If nil, + // defaults to the hardware address of the interface identified by + // InterfaceName. + HardwareAddr net.HardwareAddr } // Config contains the obtained network configuration. @@ -110,6 +115,11 @@ func NewClient(cfg ClientConfig) (*Client, error) { } } + hardwareAddr := iface.HardwareAddr + if cfg.HardwareAddr != nil { + hardwareAddr = cfg.HardwareAddr + } + var duid *dhcpv6.Duid if cfg.DUID != nil { var err error @@ -123,7 +133,7 @@ func NewClient(cfg ClientConfig) (*Client, error) { Type: dhcpv6.DUID_LLT, HwType: iana.HWTypeEthernet, Time: dhcpv6.GetTime(), - LinkLayerAddr: iface.HardwareAddr, + LinkLayerAddr: hardwareAddr, } } @@ -137,11 +147,9 @@ func NewClient(cfg ClientConfig) (*Client, error) { conn = udpConn } - log.Printf("cfg.hardwareAddr = %#v", iface.hardwareAddr) - return &Client{ interfaceName: cfg.InterfaceName, - hardwareAddr: iface.HardwareAddr, + hardwareAddr: hardwareAddr, timeNow: time.Now, raddr: raddr, Conn: conn, diff --git a/internal/dhcp6/dhcp6_test.go b/internal/dhcp6/dhcp6_test.go index a59a038..262d888 100644 --- a/internal/dhcp6/dhcp6_test.go +++ b/internal/dhcp6/dhcp6_test.go @@ -51,6 +51,7 @@ func TestDHCP6(t *testing.T) { {0x48, 0xe5, 0x9e}, // SOLICIT {0x73, 0x8c, 0x3b}, // REQUEST }, + HardwareAddr: []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}, }) if err != nil { t.Fatal(err)