mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 18:39:58 +00:00
TUN-6695: Implement ICMP proxy for linux
This commit is contained in:

committed by
Chung-Ting Huang

parent
faa86ffeca
commit
fc20a22685
52
ingress/icmp_linux_test.go
Normal file
52
ingress/icmp_linux_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
//go:build linux
|
||||
|
||||
package ingress
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/netip"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cloudflare/cloudflared/packet"
|
||||
)
|
||||
|
||||
func TestCloseIdleFlow(t *testing.T) {
|
||||
const (
|
||||
echoID = 19234
|
||||
idleTimeout = time.Millisecond * 100
|
||||
)
|
||||
conn, err := newICMPConn(localhostIP)
|
||||
require.NoError(t, err)
|
||||
flow := packet.Flow{
|
||||
Src: netip.MustParseAddr("172.16.0.1"),
|
||||
}
|
||||
icmpFlow := newICMPFlow(conn, &flow, echoID, &noopLogger)
|
||||
shutdownC := make(chan struct{})
|
||||
flowErr := make(chan error)
|
||||
go func() {
|
||||
flowErr <- icmpFlow.serve(shutdownC, idleTimeout)
|
||||
}()
|
||||
|
||||
require.Equal(t, errFlowInactive, <-flowErr)
|
||||
}
|
||||
|
||||
func TestCloseConnStopFlow(t *testing.T) {
|
||||
const (
|
||||
echoID = 19234
|
||||
)
|
||||
conn, err := newICMPConn(localhostIP)
|
||||
require.NoError(t, err)
|
||||
flow := packet.Flow{
|
||||
Src: netip.MustParseAddr("172.16.0.1"),
|
||||
}
|
||||
icmpFlow := newICMPFlow(conn, &flow, echoID, &noopLogger)
|
||||
shutdownC := make(chan struct{})
|
||||
conn.Close()
|
||||
|
||||
err = icmpFlow.serve(shutdownC, defaultCloseAfterIdle)
|
||||
require.True(t, errors.Is(err, net.ErrClosed))
|
||||
}
|
Reference in New Issue
Block a user