mirror of
https://github.com/slackhq/nebula.git
synced 2026-04-01 08:05:18 +02:00
thanks clod!
This commit is contained in:
@@ -496,11 +496,12 @@ func rewritePacket(data []byte, fp *firewall.Packet, oldIP netip.AddrPort, newIP
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Firewall) findUsableSNATPort(fp *firewall.Packet, c *conn) error {
|
func (f *Firewall) findUsableSNATPort(fp *firewall.Packet, c *conn) error {
|
||||||
|
const halfThePorts = 0x7fff
|
||||||
oldPort := fp.RemotePort
|
oldPort := fp.RemotePort
|
||||||
conntrack := f.Conntrack
|
conntrack := f.Conntrack
|
||||||
conntrack.Lock()
|
conntrack.Lock()
|
||||||
defer conntrack.Unlock()
|
defer conntrack.Unlock()
|
||||||
for numPortsChecked := 0; numPortsChecked < 0x7ff; numPortsChecked++ {
|
for numPortsChecked := 0; numPortsChecked < halfThePorts; numPortsChecked++ {
|
||||||
_, ok := conntrack.Conns[*fp]
|
_, ok := conntrack.Conns[*fp]
|
||||||
if !ok {
|
if !ok {
|
||||||
//yay, we can use this port
|
//yay, we can use this port
|
||||||
@@ -510,8 +511,8 @@ func (f *Firewall) findUsableSNATPort(fp *firewall.Packet, c *conn) error {
|
|||||||
}
|
}
|
||||||
//increment and retry. There's probably better strategies out there
|
//increment and retry. There's probably better strategies out there
|
||||||
fp.RemotePort++
|
fp.RemotePort++
|
||||||
if fp.RemotePort < 0x7fff {
|
if fp.RemotePort < halfThePorts {
|
||||||
fp.RemotePort += 0x7fff // keep it ephemeral for now
|
fp.RemotePort += halfThePorts // keep it ephemeral for now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user