This commit is contained in:
JackDoan
2026-02-20 11:59:51 -06:00
parent 2319eb9492
commit e77f49abb8

View File

@@ -461,7 +461,7 @@ func TestFirewall_FindUsableSNATPort(t *testing.T) {
} }
fw := NewFirewall(l, time.Second, time.Minute, time.Hour, c, snatAddr) fw := NewFirewall(l, time.Second, time.Minute, time.Hour, c, snatAddr)
// Fill all 0x7ff ports // Fill all ports
baseFP := firewall.Packet{ baseFP := firewall.Packet{
LocalAddr: netip.MustParseAddr("192.168.1.1"), LocalAddr: netip.MustParseAddr("192.168.1.1"),
RemoteAddr: snatAddr, RemoteAddr: snatAddr,
@@ -469,16 +469,16 @@ func TestFirewall_FindUsableSNATPort(t *testing.T) {
Protocol: firewall.ProtoUDP, Protocol: firewall.ProtoUDP,
} }
fw.Conntrack.Lock() fw.Conntrack.Lock()
for i := 0; i < 0x7ff; i++ { for i := 0; i < 65535; i++ {
fp := baseFP fp := baseFP
fp.RemotePort = uint16(0x7ff + i) fp.RemotePort = uint16(i)
fw.Conntrack.Conns[fp] = &conn{} fw.Conntrack.Conns[fp] = &conn{}
} }
fw.Conntrack.Unlock() fw.Conntrack.Unlock()
// Try to find a port starting from 0x7ff // Try to find a port starting from 0x8000
fp := baseFP fp := baseFP
fp.RemotePort = 0x7ff fp.RemotePort = 0x8000
cn := &conn{} cn := &conn{}
err := fw.findUsableSNATPort(&fp, cn) err := fw.findUsableSNATPort(&fp, cn)
assert.ErrorIs(t, err, ErrCannotSNAT) assert.ErrorIs(t, err, ErrCannotSNAT)