From 3b5cf99b297f28b5048d0cfdb0a08448259b5ce6 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 2 Dec 2019 10:43:39 +0100 Subject: [PATCH] dhcp6_test: add new DHCPv6 infra packet capture --- internal/dhcp6/dhcp6_test.go | 116 +++++++++++------- .../dhcp6/testdata/fiber7-2019-12-02.pcap | Bin 0 -> 506 bytes 2 files changed, 71 insertions(+), 45 deletions(-) create mode 100644 internal/dhcp6/testdata/fiber7-2019-12-02.pcap diff --git a/internal/dhcp6/dhcp6_test.go b/internal/dhcp6/dhcp6_test.go index f314a30..99faed5 100644 --- a/internal/dhcp6/dhcp6_test.go +++ b/internal/dhcp6/dhcp6_test.go @@ -27,54 +27,80 @@ import ( ) func TestDHCP6(t *testing.T) { - pcappath := os.Getenv("ROUTER7_PCAP_DIR") - if pcappath != "" { - pcappath = filepath.Join(pcappath, "dhcp6.pcap") - } - conn, err := pcapreplayer.NewPacketConn("testdata/fiber7.pcap", 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{ - {0x48, 0xe5, 0x9e}, // SOLICIT - {0x73, 0x8c, 0x3b}, // REQUEST + for _, tt := range []struct { + CaptureFile string + SolicitTID dhcpv6.TransactionID + RequestTID dhcpv6.TransactionID + Prefix net.IPNet + Expiry time.Duration + }{ + { + CaptureFile: "fiber7.pcap", + SolicitTID: dhcpv6.TransactionID{0x48, 0xe5, 0x9e}, + RequestTID: dhcpv6.TransactionID{0x73, 0x8c, 0x3b}, + Prefix: mustParseCIDR("2a02:168:4a00::/48"), + Expiry: 20 * time.Minute, }, - 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(20 * time.Minute), - Prefixes: []net.IPNet{ - mustParseCIDR("2a02:168:4a00::/48"), + { + CaptureFile: "fiber7-2019-12-02.pcap", + SolicitTID: dhcpv6.TransactionID{0x49, 0xb4, 0x8c}, + RequestTID: dhcpv6.TransactionID{0x49, 0xb4, 0x8c}, + Prefix: mustParseCIDR("2a02:168:4bf3::/48"), + Expiry: 1000 * time.Second, }, - 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) + } { + t.Run(tt.CaptureFile, func(t *testing.T) { + pcappath := os.Getenv("ROUTER7_PCAP_DIR") + if pcappath != "" { + pcappath = filepath.Join(pcappath, "dhcp6.pcap") + } + 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) + } + }) } } diff --git a/internal/dhcp6/testdata/fiber7-2019-12-02.pcap b/internal/dhcp6/testdata/fiber7-2019-12-02.pcap new file mode 100644 index 0000000000000000000000000000000000000000..def523aa4350ab97ac8544261169cb8e07c35674 GIT binary patch literal 506 zcmca|c+)~A1{MYwaA0F#U<7iaHa>~H&dSR05Xc5$2Hu@MJd+qyMBW$uZ@ZfZ5?L+y z|6c=$!N9q z-~);=swS9Q2Zb>F%$)<2(*WDT!2E)Nf&BslD}#g<6Jv$~1CRv)@(c{zI~W-F7chu3 zC@3(BDX5o&oePo`fbyB3Y84nH88m@xpm(6=NdZNm`VBw^dw+&11yUdnPtc-{hlM7y I4}K2=04=j%-T(jq literal 0 HcmV?d00001