2022-08-18 15:03:47 +00:00
|
|
|
package ingress
|
|
|
|
|
|
|
|
import (
|
2022-10-13 10:01:25 +00:00
|
|
|
"bytes"
|
2022-08-18 15:03:47 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-09-02 16:29:50 +00:00
|
|
|
"net"
|
2022-08-18 15:03:47 +00:00
|
|
|
"net/netip"
|
2022-09-06 12:46:21 +00:00
|
|
|
"strings"
|
2022-09-09 15:48:42 +00:00
|
|
|
"sync"
|
2022-08-18 15:03:47 +00:00
|
|
|
"testing"
|
2024-01-15 16:49:17 +00:00
|
|
|
"time"
|
2022-08-18 15:03:47 +00:00
|
|
|
|
2024-01-15 16:49:17 +00:00
|
|
|
"github.com/fortytw2/leaktest"
|
2022-08-18 15:03:47 +00:00
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"golang.org/x/net/icmp"
|
|
|
|
"golang.org/x/net/ipv4"
|
2022-09-06 12:46:21 +00:00
|
|
|
"golang.org/x/net/ipv6"
|
2022-08-18 15:03:47 +00:00
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/packet"
|
2022-10-13 10:01:25 +00:00
|
|
|
quicpogs "github.com/cloudflare/cloudflared/quic"
|
|
|
|
"github.com/cloudflare/cloudflared/tracing"
|
2022-08-18 15:03:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-01-15 16:49:17 +00:00
|
|
|
noopLogger = zerolog.Nop()
|
|
|
|
localhostIP = netip.MustParseAddr("127.0.0.1")
|
|
|
|
localhostIPv6 = netip.MustParseAddr("::1")
|
|
|
|
testFunnelIdleTimeout = time.Millisecond * 10
|
2022-08-18 15:03:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestICMPProxyEcho makes sure we can send ICMP echo via the Request method and receives response via the
|
|
|
|
// ListenResponse method
|
2022-09-06 12:20:50 +00:00
|
|
|
//
|
|
|
|
// Note: if this test fails on your device under Linux, then most likely you need to make sure that your user
|
|
|
|
// is allowed in ping_group_range. See the following gist for how to do that:
|
|
|
|
// https://github.com/ValentinBELYN/icmplib/blob/main/docs/6-use-icmplib-without-privileges.md
|
2022-09-13 13:00:54 +00:00
|
|
|
func TestICMPRouterEcho(t *testing.T) {
|
|
|
|
testICMPRouterEcho(t, true)
|
|
|
|
testICMPRouterEcho(t, false)
|
2022-09-06 12:46:21 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 13:00:54 +00:00
|
|
|
func testICMPRouterEcho(t *testing.T, sendIPv4 bool) {
|
2024-01-15 16:49:17 +00:00
|
|
|
defer leaktest.Check(t)()
|
|
|
|
|
2022-08-18 15:03:47 +00:00
|
|
|
const (
|
|
|
|
echoID = 36571
|
2022-09-06 12:46:21 +00:00
|
|
|
endSeq = 20
|
2022-08-18 15:03:47 +00:00
|
|
|
)
|
2022-08-22 16:41:51 +00:00
|
|
|
|
2024-11-27 20:46:08 +00:00
|
|
|
router, err := NewICMPRouter(localhostIP, localhostIPv6, &noopLogger, testFunnelIdleTimeout)
|
2022-08-18 15:03:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
proxyDone := make(chan struct{})
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go func() {
|
2022-09-13 13:00:54 +00:00
|
|
|
router.Serve(ctx)
|
2022-08-18 15:03:47 +00:00
|
|
|
close(proxyDone)
|
|
|
|
}()
|
|
|
|
|
2022-10-13 10:01:25 +00:00
|
|
|
muxer := newMockMuxer(1)
|
2024-11-27 20:46:08 +00:00
|
|
|
responder := newPacketResponder(muxer, 0, packet.NewEncoder())
|
2022-08-18 15:03:47 +00:00
|
|
|
|
2022-09-06 12:46:21 +00:00
|
|
|
protocol := layers.IPProtocolICMPv6
|
|
|
|
if sendIPv4 {
|
|
|
|
protocol = layers.IPProtocolICMPv4
|
2022-08-18 15:03:47 +00:00
|
|
|
}
|
2022-09-06 12:46:21 +00:00
|
|
|
localIPs := getLocalIPs(t, sendIPv4)
|
|
|
|
ips := make([]*packet.IP, len(localIPs))
|
|
|
|
for i, localIP := range localIPs {
|
|
|
|
ips[i] = &packet.IP{
|
|
|
|
Src: localIP,
|
|
|
|
Dst: localIP,
|
|
|
|
Protocol: protocol,
|
2022-09-13 13:00:54 +00:00
|
|
|
TTL: packet.DefaultTTL,
|
2022-09-02 16:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-06 12:46:21 +00:00
|
|
|
var icmpType icmp.Type = ipv6.ICMPTypeEchoRequest
|
|
|
|
if sendIPv4 {
|
|
|
|
icmpType = ipv4.ICMPTypeEcho
|
|
|
|
}
|
2022-09-02 16:29:50 +00:00
|
|
|
for seq := 0; seq < endSeq; seq++ {
|
|
|
|
for i, ip := range ips {
|
|
|
|
pk := packet.ICMP{
|
2022-09-06 12:46:21 +00:00
|
|
|
IP: ip,
|
2022-09-02 16:29:50 +00:00
|
|
|
Message: &icmp.Message{
|
2022-09-06 12:46:21 +00:00
|
|
|
Type: icmpType,
|
2022-09-02 16:29:50 +00:00
|
|
|
Code: 0,
|
|
|
|
Body: &icmp.Echo{
|
|
|
|
ID: echoID + i,
|
|
|
|
Seq: seq,
|
|
|
|
Data: []byte(fmt.Sprintf("icmp echo seq %d", seq)),
|
|
|
|
},
|
2022-08-18 15:03:47 +00:00
|
|
|
},
|
2022-09-02 16:29:50 +00:00
|
|
|
}
|
2024-11-27 20:46:08 +00:00
|
|
|
require.NoError(t, router.Request(ctx, &pk, responder))
|
2022-10-19 13:37:10 +00:00
|
|
|
validateEchoFlow(t, <-muxer.cfdToEdge, &pk)
|
2022-08-18 15:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
2024-01-15 16:49:17 +00:00
|
|
|
|
|
|
|
// Make sure funnel cleanup kicks in
|
|
|
|
time.Sleep(testFunnelIdleTimeout * 2)
|
2022-08-18 15:03:47 +00:00
|
|
|
cancel()
|
|
|
|
<-proxyDone
|
|
|
|
}
|
|
|
|
|
2022-10-13 10:01:25 +00:00
|
|
|
func TestTraceICMPRouterEcho(t *testing.T) {
|
2024-01-15 16:49:17 +00:00
|
|
|
defer leaktest.Check(t)()
|
|
|
|
|
2022-10-13 10:01:25 +00:00
|
|
|
tracingCtx := "ec31ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1"
|
|
|
|
|
2024-11-27 20:46:08 +00:00
|
|
|
router, err := NewICMPRouter(localhostIP, localhostIPv6, &noopLogger, testFunnelIdleTimeout)
|
2022-10-13 10:01:25 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
proxyDone := make(chan struct{})
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go func() {
|
|
|
|
router.Serve(ctx)
|
|
|
|
close(proxyDone)
|
|
|
|
}()
|
|
|
|
|
2022-10-14 13:44:17 +00:00
|
|
|
// Buffer 3 packets, request span, reply span and reply
|
|
|
|
muxer := newMockMuxer(3)
|
2022-10-13 10:01:25 +00:00
|
|
|
tracingIdentity, err := tracing.NewIdentity(tracingCtx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
serializedIdentity, err := tracingIdentity.MarshalBinary()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-11-27 20:46:08 +00:00
|
|
|
responder := newPacketResponder(muxer, 0, packet.NewEncoder())
|
|
|
|
responder.AddTraceContext(tracing.NewTracedContext(ctx, tracingIdentity.String(), &noopLogger), serializedIdentity)
|
2022-10-13 10:01:25 +00:00
|
|
|
|
|
|
|
echo := &icmp.Echo{
|
|
|
|
ID: 12910,
|
|
|
|
Seq: 182,
|
|
|
|
Data: []byte(t.Name()),
|
|
|
|
}
|
|
|
|
pk := packet.ICMP{
|
|
|
|
IP: &packet.IP{
|
|
|
|
Src: localhostIP,
|
|
|
|
Dst: localhostIP,
|
|
|
|
Protocol: layers.IPProtocolICMPv4,
|
|
|
|
TTL: packet.DefaultTTL,
|
|
|
|
},
|
|
|
|
Message: &icmp.Message{
|
|
|
|
Type: ipv4.ICMPTypeEcho,
|
|
|
|
Code: 0,
|
|
|
|
Body: echo,
|
|
|
|
},
|
|
|
|
}
|
2022-10-16 16:55:35 +00:00
|
|
|
|
2024-11-27 20:46:08 +00:00
|
|
|
require.NoError(t, router.Request(ctx, &pk, responder))
|
2022-10-19 13:37:10 +00:00
|
|
|
firstPK := <-muxer.cfdToEdge
|
|
|
|
var requestSpan *quicpogs.TracingSpanPacket
|
|
|
|
// The order of receiving reply or request span is not deterministic
|
|
|
|
switch firstPK.Type() {
|
|
|
|
case quicpogs.DatagramTypeIP:
|
|
|
|
// reply packet
|
|
|
|
validateEchoFlow(t, firstPK, &pk)
|
|
|
|
case quicpogs.DatagramTypeTracingSpan:
|
|
|
|
// Request span
|
|
|
|
requestSpan = firstPK.(*quicpogs.TracingSpanPacket)
|
|
|
|
require.NotEmpty(t, requestSpan.Spans)
|
|
|
|
require.True(t, bytes.Equal(serializedIdentity, requestSpan.TracingIdentity))
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("received unexpected packet type %d", firstPK.Type()))
|
2022-10-16 16:55:35 +00:00
|
|
|
}
|
2022-10-14 13:44:17 +00:00
|
|
|
|
2022-10-19 13:37:10 +00:00
|
|
|
secondPK := <-muxer.cfdToEdge
|
|
|
|
if requestSpan != nil {
|
|
|
|
// If first packet is request span, second packet should be the reply
|
|
|
|
validateEchoFlow(t, secondPK, &pk)
|
|
|
|
} else {
|
|
|
|
requestSpan = secondPK.(*quicpogs.TracingSpanPacket)
|
|
|
|
require.NotEmpty(t, requestSpan.Spans)
|
|
|
|
require.True(t, bytes.Equal(serializedIdentity, requestSpan.TracingIdentity))
|
2022-10-16 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 13:44:17 +00:00
|
|
|
// Reply span
|
2022-10-19 13:37:10 +00:00
|
|
|
thirdPacket := <-muxer.cfdToEdge
|
|
|
|
replySpan, ok := thirdPacket.(*quicpogs.TracingSpanPacket)
|
2022-10-13 10:01:25 +00:00
|
|
|
require.True(t, ok)
|
2022-10-14 13:44:17 +00:00
|
|
|
require.NotEmpty(t, replySpan.Spans)
|
|
|
|
require.True(t, bytes.Equal(serializedIdentity, replySpan.TracingIdentity))
|
|
|
|
require.False(t, bytes.Equal(requestSpan.Spans, replySpan.Spans))
|
2022-10-13 10:01:25 +00:00
|
|
|
|
|
|
|
echo.Seq++
|
|
|
|
pk.Body = echo
|
|
|
|
// Only first request for a flow is traced. The edge will not send tracing context for the second request
|
2024-11-27 20:46:08 +00:00
|
|
|
newResponder := newPacketResponder(muxer, 0, packet.NewEncoder())
|
|
|
|
require.NoError(t, router.Request(ctx, &pk, newResponder))
|
2022-10-19 13:37:10 +00:00
|
|
|
validateEchoFlow(t, <-muxer.cfdToEdge, &pk)
|
2022-10-13 10:01:25 +00:00
|
|
|
|
2022-10-14 13:44:17 +00:00
|
|
|
select {
|
2022-10-19 13:37:10 +00:00
|
|
|
case receivedPacket := <-muxer.cfdToEdge:
|
2022-10-14 13:44:17 +00:00
|
|
|
panic(fmt.Sprintf("Receive unexpected packet %+v", receivedPacket))
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:49:17 +00:00
|
|
|
time.Sleep(testFunnelIdleTimeout * 2)
|
2022-10-13 10:01:25 +00:00
|
|
|
cancel()
|
|
|
|
<-proxyDone
|
|
|
|
}
|
|
|
|
|
2022-09-09 15:48:42 +00:00
|
|
|
// TestConcurrentRequests makes sure icmpRouter can send concurrent requests to the same destination with different
|
|
|
|
// echo ID. This simulates concurrent ping to the same destination.
|
|
|
|
func TestConcurrentRequestsToSameDst(t *testing.T) {
|
2024-01-15 16:49:17 +00:00
|
|
|
defer leaktest.Check(t)()
|
|
|
|
|
2022-09-09 15:48:42 +00:00
|
|
|
const (
|
|
|
|
concurrentPings = 5
|
|
|
|
endSeq = 5
|
|
|
|
)
|
|
|
|
|
2024-11-27 20:46:08 +00:00
|
|
|
router, err := NewICMPRouter(localhostIP, localhostIPv6, &noopLogger, testFunnelIdleTimeout)
|
2022-09-09 15:48:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
proxyDone := make(chan struct{})
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go func() {
|
|
|
|
router.Serve(ctx)
|
|
|
|
close(proxyDone)
|
|
|
|
}()
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
// icmpv4 and icmpv6 each has concurrentPings
|
|
|
|
wg.Add(concurrentPings * 2)
|
|
|
|
for i := 0; i < concurrentPings; i++ {
|
|
|
|
echoID := 38451 + i
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
2022-10-13 10:01:25 +00:00
|
|
|
|
|
|
|
muxer := newMockMuxer(1)
|
2024-11-27 20:46:08 +00:00
|
|
|
responder := newPacketResponder(muxer, 0, packet.NewEncoder())
|
2022-09-09 15:48:42 +00:00
|
|
|
for seq := 0; seq < endSeq; seq++ {
|
|
|
|
pk := &packet.ICMP{
|
|
|
|
IP: &packet.IP{
|
|
|
|
Src: localhostIP,
|
|
|
|
Dst: localhostIP,
|
|
|
|
Protocol: layers.IPProtocolICMPv4,
|
|
|
|
TTL: packet.DefaultTTL,
|
|
|
|
},
|
|
|
|
Message: &icmp.Message{
|
|
|
|
Type: ipv4.ICMPTypeEcho,
|
|
|
|
Code: 0,
|
|
|
|
Body: &icmp.Echo{
|
|
|
|
ID: echoID,
|
|
|
|
Seq: seq,
|
|
|
|
Data: []byte(fmt.Sprintf("icmpv4 echo id %d, seq %d", echoID, seq)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-11-27 20:46:08 +00:00
|
|
|
require.NoError(t, router.Request(ctx, pk, responder))
|
2022-10-19 13:37:10 +00:00
|
|
|
validateEchoFlow(t, <-muxer.cfdToEdge, pk)
|
2022-09-09 15:48:42 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
2022-10-13 10:01:25 +00:00
|
|
|
muxer := newMockMuxer(1)
|
2024-11-27 20:46:08 +00:00
|
|
|
responder := newPacketResponder(muxer, 0, packet.NewEncoder())
|
2022-09-09 15:48:42 +00:00
|
|
|
for seq := 0; seq < endSeq; seq++ {
|
|
|
|
pk := &packet.ICMP{
|
|
|
|
IP: &packet.IP{
|
|
|
|
Src: localhostIPv6,
|
|
|
|
Dst: localhostIPv6,
|
|
|
|
Protocol: layers.IPProtocolICMPv6,
|
|
|
|
TTL: packet.DefaultTTL,
|
|
|
|
},
|
|
|
|
Message: &icmp.Message{
|
|
|
|
Type: ipv6.ICMPTypeEchoRequest,
|
|
|
|
Code: 0,
|
|
|
|
Body: &icmp.Echo{
|
|
|
|
ID: echoID,
|
|
|
|
Seq: seq,
|
|
|
|
Data: []byte(fmt.Sprintf("icmpv6 echo id %d, seq %d", echoID, seq)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-11-27 20:46:08 +00:00
|
|
|
require.NoError(t, router.Request(ctx, pk, responder))
|
2022-10-19 13:37:10 +00:00
|
|
|
validateEchoFlow(t, <-muxer.cfdToEdge, pk)
|
2022-09-09 15:48:42 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2024-01-15 16:49:17 +00:00
|
|
|
|
|
|
|
time.Sleep(testFunnelIdleTimeout * 2)
|
2022-09-09 15:48:42 +00:00
|
|
|
cancel()
|
|
|
|
<-proxyDone
|
|
|
|
}
|
|
|
|
|
2022-08-18 15:03:47 +00:00
|
|
|
// TestICMPProxyRejectNotEcho makes sure it rejects messages other than echo
|
2022-09-13 13:00:54 +00:00
|
|
|
func TestICMPRouterRejectNotEcho(t *testing.T) {
|
2024-01-15 16:49:17 +00:00
|
|
|
defer leaktest.Check(t)()
|
|
|
|
|
2022-08-18 15:03:47 +00:00
|
|
|
msgs := []icmp.Message{
|
|
|
|
{
|
|
|
|
Type: ipv4.ICMPTypeDestinationUnreachable,
|
|
|
|
Code: 1,
|
|
|
|
Body: &icmp.DstUnreach{
|
|
|
|
Data: []byte("original packet"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ipv4.ICMPTypeTimeExceeded,
|
|
|
|
Code: 1,
|
|
|
|
Body: &icmp.TimeExceeded{
|
|
|
|
Data: []byte("original packet"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ipv4.ICMPType(2),
|
|
|
|
Code: 0,
|
|
|
|
Body: &icmp.PacketTooBig{
|
|
|
|
MTU: 1280,
|
|
|
|
Data: []byte("original packet"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-09-13 13:00:54 +00:00
|
|
|
testICMPRouterRejectNotEcho(t, localhostIP, msgs)
|
2022-09-06 12:46:21 +00:00
|
|
|
msgsV6 := []icmp.Message{
|
|
|
|
{
|
|
|
|
Type: ipv6.ICMPTypeDestinationUnreachable,
|
|
|
|
Code: 3,
|
|
|
|
Body: &icmp.DstUnreach{
|
|
|
|
Data: []byte("original packet"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ipv6.ICMPTypeTimeExceeded,
|
|
|
|
Code: 0,
|
|
|
|
Body: &icmp.TimeExceeded{
|
|
|
|
Data: []byte("original packet"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ipv6.ICMPTypePacketTooBig,
|
|
|
|
Code: 0,
|
|
|
|
Body: &icmp.PacketTooBig{
|
|
|
|
MTU: 1280,
|
|
|
|
Data: []byte("original packet"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-09-13 13:00:54 +00:00
|
|
|
testICMPRouterRejectNotEcho(t, localhostIPv6, msgsV6)
|
2022-09-06 12:46:21 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 13:00:54 +00:00
|
|
|
func testICMPRouterRejectNotEcho(t *testing.T, srcDstIP netip.Addr, msgs []icmp.Message) {
|
2024-11-27 20:46:08 +00:00
|
|
|
router, err := NewICMPRouter(localhostIP, localhostIPv6, &noopLogger, testFunnelIdleTimeout)
|
2022-08-18 15:03:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-10-13 10:01:25 +00:00
|
|
|
muxer := newMockMuxer(1)
|
2024-11-27 20:46:08 +00:00
|
|
|
responder := newPacketResponder(muxer, 0, packet.NewEncoder())
|
2022-09-06 12:46:21 +00:00
|
|
|
protocol := layers.IPProtocolICMPv4
|
|
|
|
if srcDstIP.Is6() {
|
|
|
|
protocol = layers.IPProtocolICMPv6
|
|
|
|
}
|
2022-08-18 15:03:47 +00:00
|
|
|
for _, m := range msgs {
|
|
|
|
pk := packet.ICMP{
|
|
|
|
IP: &packet.IP{
|
2022-09-06 12:46:21 +00:00
|
|
|
Src: srcDstIP,
|
|
|
|
Dst: srcDstIP,
|
|
|
|
Protocol: protocol,
|
2022-09-13 13:00:54 +00:00
|
|
|
TTL: packet.DefaultTTL,
|
2022-08-18 15:03:47 +00:00
|
|
|
},
|
|
|
|
Message: &m,
|
|
|
|
}
|
2024-11-27 20:46:08 +00:00
|
|
|
require.Error(t, router.Request(context.Background(), &pk, responder))
|
2022-08-18 15:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:37:10 +00:00
|
|
|
func validateEchoFlow(t *testing.T, pk quicpogs.Packet, echoReq *packet.ICMP) {
|
2022-10-13 10:01:25 +00:00
|
|
|
decoder := packet.NewICMPDecoder()
|
|
|
|
decoded, err := decoder.Decode(packet.RawPacket{Data: pk.Payload()})
|
2022-10-19 13:37:10 +00:00
|
|
|
require.NoError(t, err, pk)
|
2022-08-18 15:03:47 +00:00
|
|
|
require.Equal(t, decoded.Src, echoReq.Dst)
|
|
|
|
require.Equal(t, decoded.Dst, echoReq.Src)
|
|
|
|
require.Equal(t, echoReq.Protocol, decoded.Protocol)
|
|
|
|
|
2022-09-06 12:46:21 +00:00
|
|
|
if echoReq.Type == ipv4.ICMPTypeEcho {
|
|
|
|
require.Equal(t, ipv4.ICMPTypeEchoReply, decoded.Type)
|
|
|
|
} else {
|
|
|
|
require.Equal(t, ipv6.ICMPTypeEchoReply, decoded.Type)
|
|
|
|
}
|
2022-08-18 15:03:47 +00:00
|
|
|
require.Equal(t, 0, decoded.Code)
|
2022-09-22 09:49:19 +00:00
|
|
|
require.NotZero(t, decoded.Checksum)
|
2022-09-06 12:46:21 +00:00
|
|
|
|
2022-08-22 16:41:51 +00:00
|
|
|
require.Equal(t, echoReq.Body, decoded.Body)
|
2022-08-18 15:03:47 +00:00
|
|
|
}
|
2022-09-06 12:46:21 +00:00
|
|
|
|
|
|
|
func getLocalIPs(t *testing.T, ipv4 bool) []netip.Addr {
|
|
|
|
interfaces, err := net.Interfaces()
|
|
|
|
require.NoError(t, err)
|
|
|
|
localIPs := []netip.Addr{}
|
|
|
|
for _, i := range interfaces {
|
2023-06-26 11:33:43 +00:00
|
|
|
// Skip TUN devices, and Docker Networks
|
|
|
|
if strings.Contains(i.Name, "tun") || strings.Contains(i.Name, "docker") || strings.HasPrefix(i.Name, "br-") {
|
2022-09-06 12:46:21 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
addrs, err := i.Addrs()
|
|
|
|
require.NoError(t, err)
|
|
|
|
for _, addr := range addrs {
|
|
|
|
if ipnet, ok := addr.(*net.IPNet); ok && (ipnet.IP.IsPrivate() || ipnet.IP.IsLoopback()) {
|
2023-06-26 11:33:43 +00:00
|
|
|
// TODO DEVTOOLS-12514: We only run the IPv6 against the loopback interface due to issues on the CI runners.
|
|
|
|
if (ipv4 && ipnet.IP.To4() != nil) || (!ipv4 && ipnet.IP.To4() == nil && ipnet.IP.IsLoopback()) {
|
2022-09-06 12:46:21 +00:00
|
|
|
localIPs = append(localIPs, netip.MustParseAddr(ipnet.IP.String()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return localIPs
|
|
|
|
}
|