Skip to content

Commit ba2fce4

Browse files
committed
fix some problems for testing
1 parent 10ff81d commit ba2fce4

3 files changed

Lines changed: 19 additions & 23 deletions

File tree

application_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,6 @@ func TestUpdatePeerSettingsIPAddr(t *testing.T) {
794794
})
795795
ts.NoError(err)
796796
})
797-
798797
}
799798

800799
func TestDisableVPNInterface(t *testing.T) {

service/tunnel.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,7 @@ func (t *Tunnel) HandleReadPackets(packets []*vpn.Packet) {
279279
// from the internet via NAT, not our own p2p initiative to the
280280
// same peer). Subnet check is local to this side — no cross-side
281281
// dependency on the client's awl subnet.
282-
var srcFromInternet bool
283-
if packet.IsIPv6 {
284-
if t.awlSubnet6 != nil {
285-
srcFromInternet = !t.awlSubnet6.Contains(packet.Src)
286-
}
287-
} else {
288-
srcFromInternet = !t.awlSubnet.Contains(packet.Src)
289-
}
282+
srcFromInternet := !t.isAWLSubnet(packet.Src, packet.IsIPv6)
290283

291284
if vpnPeer.weAllowUsingAsExitNode.Load() && t.vpnGatewayServerEnabled && srcFromInternet {
292285
packet.GatewayDir = vpn.GatewayDirReturn
@@ -319,14 +312,7 @@ func (t *Tunnel) HandleReadPackets(packets []*vpn.Packet) {
319312

320313
// VPN gateway client mode: forward non-local packets to the gateway peer.
321314
if t.vpnGatewayClientEnabled && t.vpnGatewayPeer != nil {
322-
var isAWLSubnet bool
323-
if packet.IsIPv6 {
324-
if t.awlSubnet6 != nil {
325-
isAWLSubnet = t.awlSubnet6.Contains(packet.Dst)
326-
}
327-
} else {
328-
isAWLSubnet = t.awlSubnet.Contains(packet.Dst)
329-
}
315+
isAWLSubnet := t.isAWLSubnet(packet.Dst, packet.IsIPv6)
330316

331317
if isNonRoutableIP(packet.Dst) || isAWLSubnet {
332318
continue
@@ -362,6 +348,16 @@ func (t *Tunnel) makeTunnelStream(ctx context.Context, peerID peer.ID) (network.
362348
return stream, nil
363349
}
364350

351+
func (t *Tunnel) isAWLSubnet(ip net.IP, isIPv6 bool) bool {
352+
if isIPv6 {
353+
if t.awlSubnet6 != nil {
354+
return t.awlSubnet6.Contains(ip)
355+
}
356+
return false
357+
}
358+
return t.awlSubnet.Contains(ip)
359+
}
360+
365361
type VpnPeer struct {
366362
peerID peer.ID
367363
localIP atomic.Pointer[net.IP]

vpn/netstate/vpn_hostnet_integration_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ import (
4949
)
5050

5151
const (
52-
testTunIf = "awl0"
53-
testAwlSubnet = "10.66.0.0/16"
52+
testTunIf = "awl0"
53+
testAwlSubnet = "10.66.0.0/16"
54+
testAwlSubnet6 = "fd00:66::/48"
5455
ipForwardPath = "/proc/sys/net/ipv4/ip_forward"
5556
)
5657

@@ -65,7 +66,7 @@ func TestGatewayHostNetNATLifecycle(t *testing.T) {
6566
before := snapshotNet(t)
6667

6768
mgr := NewManager()
68-
require.NoError(t, mgr.EnableServerNAT(testAwlSubnet, testTunIf))
69+
require.NoError(t, mgr.EnableServerNAT(testAwlSubnet, testAwlSubnet6, testTunIf))
6970
require.True(t, mgr.ServerNATActive())
7071

7172
assertNATApplied(t)
@@ -97,13 +98,13 @@ func TestGatewayHostNetNATIdempotentResetup(t *testing.T) {
9798
before := snapshotNet(t)
9899

99100
mgr1 := NewManager()
100-
require.NoError(t, mgr1.EnableServerNAT(testAwlSubnet, testTunIf))
101+
require.NoError(t, mgr1.EnableServerNAT(testAwlSubnet, testAwlSubnet6, testTunIf))
101102
applied1 := snapshotNet(t)
102103

103104
// Second manager over the live state of the first — simulates a leftover
104105
// from a process that was killed before teardown ran.
105106
mgr2 := NewManager()
106-
require.NoError(t, mgr2.EnableServerNAT(testAwlSubnet, testTunIf),
107+
require.NoError(t, mgr2.EnableServerNAT(testAwlSubnet, testAwlSubnet6, testTunIf),
107108
"re-setup over leftover state must succeed (cleanupStaleNAT)")
108109
applied2 := snapshotNet(t)
109110

@@ -126,7 +127,7 @@ func TestGatewayHostNetNATPreservesExistingIPForward(t *testing.T) {
126127
}
127128

128129
mgr := NewManager()
129-
require.NoError(t, mgr.EnableServerNAT(testAwlSubnet, testTunIf))
130+
require.NoError(t, mgr.EnableServerNAT(testAwlSubnet, testAwlSubnet6, testTunIf))
130131
require.Equal(t, "1", readForward(t))
131132

132133
require.NoError(t, mgr.DisableServerNAT())

0 commit comments

Comments
 (0)