dhcp6_test: add new DHCPv6 infra packet capture
This commit is contained in:
parent
70edcab16b
commit
3b5cf99b29
@ -27,54 +27,80 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDHCP6(t *testing.T) {
|
func TestDHCP6(t *testing.T) {
|
||||||
pcappath := os.Getenv("ROUTER7_PCAP_DIR")
|
for _, tt := range []struct {
|
||||||
if pcappath != "" {
|
CaptureFile string
|
||||||
pcappath = filepath.Join(pcappath, "dhcp6.pcap")
|
SolicitTID dhcpv6.TransactionID
|
||||||
}
|
RequestTID dhcpv6.TransactionID
|
||||||
conn, err := pcapreplayer.NewPacketConn("testdata/fiber7.pcap", pcappath)
|
Prefix net.IPNet
|
||||||
if err != nil {
|
Expiry time.Duration
|
||||||
t.Fatal(err)
|
}{
|
||||||
}
|
{
|
||||||
defer conn.Close()
|
CaptureFile: "fiber7.pcap",
|
||||||
laddr, err := net.ResolveUDPAddr("udp6", "[fe80::42:aff:fea5:966e]:546")
|
SolicitTID: dhcpv6.TransactionID{0x48, 0xe5, 0x9e},
|
||||||
if err != nil {
|
RequestTID: dhcpv6.TransactionID{0x73, 0x8c, 0x3b},
|
||||||
t.Fatal(err)
|
Prefix: mustParseCIDR("2a02:168:4a00::/48"),
|
||||||
}
|
Expiry: 20 * time.Minute,
|
||||||
now := time.Now()
|
|
||||||
c, err := NewClient(ClientConfig{
|
|
||||||
// NOTE(stapelberg): dhcpv6.NewSolicitForInterface requires an interface
|
|
||||||
// name to get the MAC address.
|
|
||||||
InterfaceName: "lo",
|
|
||||||
LocalAddr: laddr,
|
|
||||||
Conn: conn,
|
|
||||||
TransactionIDs: []dhcpv6.TransactionID{
|
|
||||||
{0x48, 0xe5, 0x9e}, // SOLICIT
|
|
||||||
{0x73, 0x8c, 0x3b}, // REQUEST
|
|
||||||
},
|
},
|
||||||
HardwareAddr: []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
c.timeNow = func() time.Time { return now }
|
|
||||||
|
|
||||||
c.ObtainOrRenew()
|
{
|
||||||
if err := c.Err(); err != nil {
|
CaptureFile: "fiber7-2019-12-02.pcap",
|
||||||
t.Fatalf("unexpected error: %v", err)
|
SolicitTID: dhcpv6.TransactionID{0x49, 0xb4, 0x8c},
|
||||||
}
|
RequestTID: dhcpv6.TransactionID{0x49, 0xb4, 0x8c},
|
||||||
got := c.Config()
|
Prefix: mustParseCIDR("2a02:168:4bf3::/48"),
|
||||||
want := Config{
|
Expiry: 1000 * time.Second,
|
||||||
RenewAfter: now.Add(20 * time.Minute),
|
|
||||||
Prefixes: []net.IPNet{
|
|
||||||
mustParseCIDR("2a02:168:4a00::/48"),
|
|
||||||
},
|
},
|
||||||
DNS: []string{
|
} {
|
||||||
"2001:1620:2777:1::10",
|
t.Run(tt.CaptureFile, func(t *testing.T) {
|
||||||
"2001:1620:2777:2::20",
|
pcappath := os.Getenv("ROUTER7_PCAP_DIR")
|
||||||
},
|
if pcappath != "" {
|
||||||
}
|
pcappath = filepath.Join(pcappath, "dhcp6.pcap")
|
||||||
if diff := cmp.Diff(want, got); diff != "" {
|
}
|
||||||
t.Fatalf("unexpected config: diff (-want +got):\n%s", diff)
|
conn, err := pcapreplayer.NewPacketConn("testdata/"+tt.CaptureFile, pcappath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
laddr, err := net.ResolveUDPAddr("udp6", "[fe80::42:aff:fea5:966e]:546")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
now := time.Now()
|
||||||
|
c, err := NewClient(ClientConfig{
|
||||||
|
// NOTE(stapelberg): dhcpv6.NewSolicitForInterface requires an interface
|
||||||
|
// name to get the MAC address.
|
||||||
|
InterfaceName: "lo",
|
||||||
|
LocalAddr: laddr,
|
||||||
|
Conn: conn,
|
||||||
|
TransactionIDs: []dhcpv6.TransactionID{
|
||||||
|
tt.SolicitTID,
|
||||||
|
tt.RequestTID,
|
||||||
|
},
|
||||||
|
HardwareAddr: []byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
c.timeNow = func() time.Time { return now }
|
||||||
|
|
||||||
|
c.ObtainOrRenew()
|
||||||
|
if err := c.Err(); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
got := c.Config()
|
||||||
|
want := Config{
|
||||||
|
RenewAfter: now.Add(tt.Expiry),
|
||||||
|
Prefixes: []net.IPNet{
|
||||||
|
tt.Prefix,
|
||||||
|
},
|
||||||
|
DNS: []string{
|
||||||
|
"2001:1620:2777:1::10",
|
||||||
|
"2001:1620:2777:2::20",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff(want, got); diff != "" {
|
||||||
|
t.Fatalf("unexpected config: diff (-want +got):\n%s", diff)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
internal/dhcp6/testdata/fiber7-2019-12-02.pcap
vendored
Normal file
BIN
internal/dhcp6/testdata/fiber7-2019-12-02.pcap
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user