From 9ba64e09f017c852a3b362bc0f6def21a103ca12 Mon Sep 17 00:00:00 2001 From: Stuart Geipel Date: Wed, 21 Aug 2024 11:49:24 -0700 Subject: [PATCH] add ipv6 test to peek count --- pkg/network/tracer/tracer_linux_test.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/network/tracer/tracer_linux_test.go b/pkg/network/tracer/tracer_linux_test.go index 59d2bf1e61b38..c524e9cf801d7 100644 --- a/pkg/network/tracer/tracer_linux_test.go +++ b/pkg/network/tracer/tracer_linux_test.go @@ -1117,24 +1117,35 @@ func (s *TracerSuite) TestSelfConnect() { return len(conns) == 2 }, 5*time.Second, 100*time.Millisecond, "could not find expected number of tcp connections, expected: 2") } - func (s *TracerSuite) TestUDPPeekCount() { t := s.T() + t.Run("v4", func(t *testing.T) { + testUDPPeekCount(t, "udp4", "127.0.0.1") + }) + t.Run("v6", func(t *testing.T) { + if !testConfig().CollectUDPv6Conns { + t.Skip("UDPv6 disabled") + } + testUDPPeekCount(t, "udp6", "[::1]") + }) +} +func testUDPPeekCount(t *testing.T, udpnet, ip string) { config := testConfig() tr := setupTracer(t, config) - ln, err := net.ListenPacket("udp", "127.0.0.1:0") + serverAddr := fmt.Sprintf("%s:%d", ip, 0) + ln, err := net.ListenPacket(udpnet, serverAddr) require.NoError(t, err) defer ln.Close() saddr := ln.LocalAddr().String() - laddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0") + laddr, err := net.ResolveUDPAddr(udpnet, serverAddr) require.NoError(t, err) - raddr, err := net.ResolveUDPAddr("udp", saddr) + raddr, err := net.ResolveUDPAddr(udpnet, saddr) require.NoError(t, err) - c, err := net.DialUDP("udp", laddr, raddr) + c, err := net.DialUDP(udpnet, laddr, raddr) require.NoError(t, err) defer c.Close()