dhcp6: allow overriding hardwareaddr in test

This fixes the breakage introduced by commit
8166b9a9db
This commit is contained in:
Michael Stapelberg 2019-04-29 19:16:19 +02:00
parent 02741e8d28
commit 54843950dd
2 changed files with 13 additions and 4 deletions

View File

@ -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,

View File

@ -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)