From c37ddf4f6e93d582d6708adc71deff4b65a5633c Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 8 Jun 2018 16:51:33 +0200 Subject: [PATCH] integrationradvd: unflake test --- integrationradvd_test.go | 10 ++++++++-- internal/radvd/radvd.go | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/integrationradvd_test.go b/integrationradvd_test.go index c75eed7..f93ec48 100644 --- a/integrationradvd_test.go +++ b/integrationradvd_test.go @@ -30,6 +30,8 @@ func TestRouterAdvertisement(t *testing.T) { exec.Command("ip", "netns", "exec", ns, "ip", "addr", "add", "192.168.23.1/24", "dev", "veth0b"), exec.Command("ip", "netns", "exec", ns, "ip", "link", "set", "veth0b", "up"), exec.Command("ip", "netns", "exec", ns, "ip", "link", "set", "veth0b"), + + exec.Command("/bin/sh", "-c", "echo 1 > /proc/sys/net/ipv6/conf/veth0a/forwarding"), } for _, cmd := range nsSetup { @@ -52,8 +54,12 @@ func TestRouterAdvertisement(t *testing.T) { srv.SetPrefixes([]net.IPNet{ net.IPNet{IP: net.ParseIP("2a02:168:4a00::"), Mask: net.CIDRMask(64, 128)}, }) + conn, err := net.ListenIP("ip6:ipv6-icmp", &net.IPAddr{net.IPv6unspecified, ""}) + if err != nil { + t.Fatal(err) + } go func() { - if err := srv.ListenAndServe("veth0a"); err != nil { + if err := srv.Serve("veth0a", conn); err != nil { t.Fatal(err) } }() @@ -66,7 +72,7 @@ func TestRouterAdvertisement(t *testing.T) { rdisc6.Stderr = os.Stderr b, err := rdisc6.Output() if err != nil { - t.Fatal(err) + t.Fatalf("%v: %v (output: %v)", rdisc6.Args, err, string(b)) } t.Logf("b = %s", string(b)) diff --git a/internal/radvd/radvd.go b/internal/radvd/radvd.go index 79a8590..d18c3ad 100644 --- a/internal/radvd/radvd.go +++ b/internal/radvd/radvd.go @@ -36,20 +36,13 @@ func (s *Server) SetPrefixes(prefixes []net.IPNet) { } } -func (s *Server) ListenAndServe(ifname string) error { +func (s *Server) Serve(ifname string, conn net.PacketConn) error { var err error s.iface, err = net.InterfaceByName(ifname) if err != nil { return err } - // TODO(correctness): would it be better to listen on - // net.IPv6linklocalallrouters? Just specifying that results in an error, - // though. - conn, err := net.ListenIP("ip6:ipv6-icmp", &net.IPAddr{net.IPv6unspecified, ""}) - if err != nil { - return err - } defer conn.Close() s.pc = ipv6.NewPacketConn(conn) s.pc.SetHopLimit(255) // as per RFC 4861, section 4.1 @@ -89,6 +82,17 @@ func (s *Server) ListenAndServe(ifname string) error { return nil } +func (s *Server) ListenAndServe(ifname string) error { + // TODO(correctness): would it be better to listen on + // net.IPv6linklocalallrouters? Just specifying that results in an error, + // though. + conn, err := net.ListenIP("ip6:ipv6-icmp", &net.IPAddr{net.IPv6unspecified, ""}) + if err != nil { + return err + } + return s.Serve(ifname, conn) +} + type sourceLinkLayerAddress struct { address net.HardwareAddr }