mirror of
https://github.com/slackhq/nebula.git
synced 2025-11-22 16:34:25 +01:00
claude suggests this bound checking optimization
it is about 4.4% better on the bench-cpu-long cpu usage test
This commit is contained in:
@@ -333,12 +333,13 @@ func parseV6(data []byte, incoming bool, fp *firewall.Packet) error {
|
||||
}
|
||||
|
||||
fp.Protocol = uint8(proto)
|
||||
ports := data[offset : offset+4]
|
||||
if incoming {
|
||||
fp.RemotePort = binary.BigEndian.Uint16(data[offset : offset+2])
|
||||
fp.LocalPort = binary.BigEndian.Uint16(data[offset+2 : offset+4])
|
||||
fp.RemotePort = binary.BigEndian.Uint16(ports[0:2])
|
||||
fp.LocalPort = binary.BigEndian.Uint16(ports[2:4])
|
||||
} else {
|
||||
fp.LocalPort = binary.BigEndian.Uint16(data[offset : offset+2])
|
||||
fp.RemotePort = binary.BigEndian.Uint16(data[offset+2 : offset+4])
|
||||
fp.LocalPort = binary.BigEndian.Uint16(ports[0:2])
|
||||
fp.RemotePort = binary.BigEndian.Uint16(ports[2:4])
|
||||
}
|
||||
|
||||
fp.Fragment = false
|
||||
|
||||
Reference in New Issue
Block a user