Skip to content

Commit a07c568

Browse files
committed
fix some problems
1 parent 0a5efcf commit a07c568

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

config/other.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ func setDefaults(conf *Config, bus awlevent.Bus) {
174174
if conf.VPNConfig.IPNet == "" {
175175
conf.VPNConfig.IPNet = DefaultVPNNetworkSubnet
176176
}
177-
if conf.VPNConfig.IPNetV6 == "" {
177+
178+
// IPv6 support is a significant change, so it's opt-in for existing users
179+
// to ensure a safe upgrade path. We only set the default for new configs.
180+
if isEmptyConfig && conf.VPNConfig.IPNetV6 == "" {
178181
conf.VPNConfig.IPNetV6 = DefaultVPNNetworkSubnet6
179182
}
180183
if ip, _ := conf.VPNLocalIPMask(); ip == nil {

service/tunnel.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,11 @@ func (t *Tunnel) writeInboundBatch(packets []*vpn.Packet, bufs [][]byte, senderI
726726
isOurGateway := t.vpnGatewayClientEnabled && vp.peerID == t.vpnGatewayPeerID
727727
t.peersLock.RUnlock()
728728

729-
localIPv4, _ := t.conf.VPNLocalIPMask()
730-
localIPv6, _ := t.conf.VPNLocalIPMaskV6()
729+
localIPv4 := t.awlSubnet.IP
730+
var localIPv6 net.IP
731+
if t.awlSubnet6 != nil {
732+
localIPv6 = t.awlSubnet6.IP
733+
}
731734

732735
allowGateway := vp.weAllowUsingAsExitNode.Load()
733736

@@ -789,6 +792,12 @@ func (t *Tunnel) writeInboundBatch(packets []*vpn.Packet, bufs [][]byte, senderI
789792
}
790793

791794
// isNonRoutableIP returns true for IPs that should not be forwarded through the gateway.
795+
//
796+
// TODO(gateway): add client-side drop of
797+
// private destinations (10/8, 172.16/12, 192.168/16, CGNAT, link-local)
798+
// before sending to the gateway: fast local refusal instead of a silent drop
799+
// at the exit node's filter. Not a replacement for the server-side filtering
800+
// (iptables on Linux, WFP on Windows) — the server cannot trust clients.
792801
func isNonRoutableIP(ip net.IP) bool {
793802
return ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() || ip.IsMulticast()
794803
}

socks5/server_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net/http"
99
"net/url"
1010
"sync"
11-
"sync/atomic"
1211
"testing"
1312

1413
"github.com/stretchr/testify/require"
@@ -117,14 +116,13 @@ func TestProxyWithAuthRejection(t *testing.T) {
117116
}
118117
}
119118

120-
var testPortCounter int32 = 25000
121-
122119
func pickFreeAddr(t testing.TB) string {
123-
port := atomic.AddInt32(&testPortCounter, 1)
124-
if port < testPortCounter {
125-
t.Fatalf("port counter overflow: %d", port)
120+
l, err := net.Listen("tcp", "127.0.0.1:0")
121+
if err != nil {
122+
t.Fatal(err)
126123
}
127-
return fmt.Sprintf("127.0.0.1:%d", port)
124+
defer l.Close()
125+
return l.Addr().String()
128126
}
129127

130128
// startUpstreamServer starts an HTTP server that responds with "test text" on /test.

test_suite_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,13 @@ func (t *testTun) Close() error {
536536
return nil
537537
}
538538

539-
var testPortCounter int32 = 20000
540-
541539
func pickFreeAddr(t testing.TB) string {
542-
port := atomic.AddInt32(&testPortCounter, 1)
543-
if port < testPortCounter {
544-
t.Fatalf("port counter overflow: %d", port)
540+
l, err := net.Listen("tcp", "127.0.0.1:0")
541+
if err != nil {
542+
t.Fatal(err)
545543
}
546-
return fmt.Sprintf("127.0.0.1:%d", port)
544+
defer l.Close()
545+
return l.Addr().String()
547546
}
548547

549548
func testPacket(length int) []byte {

0 commit comments

Comments
 (0)