Split IPv6 extension walker case clause into helpers

This commit is contained in:
Viktor Liu
2026-05-04 12:29:42 +02:00
parent b2d61f3b0b
commit 5ba9882fd4

View File

@@ -278,25 +278,40 @@ func parseICMPv6(payload []byte) (ipHdrLen, icmpLen int, src, dst tcpip.Address,
func skipIPv6ExtensionsToICMPv6(payload []byte, next uint8, hdrEnd int) (int, bool) { func skipIPv6ExtensionsToICMPv6(payload []byte, next uint8, hdrEnd int) (int, bool) {
off := header.IPv6MinimumSize off := header.IPv6MinimumSize
for { for {
switch next { if next == uint8(header.ICMPv6ProtocolNumber) {
case uint8(header.ICMPv6ProtocolNumber):
return off, true return off, true
}
if !isWalkableIPv6ExtHdr(next) {
return 0, false
}
newOff, newNext, ok := advanceIPv6ExtHdr(payload, off, hdrEnd)
if !ok {
return 0, false
}
off = newOff
next = newNext
}
}
func isWalkableIPv6ExtHdr(id uint8) bool {
switch id {
case uint8(header.IPv6HopByHopOptionsExtHdrIdentifier), case uint8(header.IPv6HopByHopOptionsExtHdrIdentifier),
uint8(header.IPv6RoutingExtHdrIdentifier), uint8(header.IPv6RoutingExtHdrIdentifier),
uint8(header.IPv6DestinationOptionsExtHdrIdentifier): uint8(header.IPv6DestinationOptionsExtHdrIdentifier):
return true
}
return false
}
func advanceIPv6ExtHdr(payload []byte, off, hdrEnd int) (int, uint8, bool) {
if off+8 > hdrEnd { if off+8 > hdrEnd {
return 0, false return 0, 0, false
} }
extLen := (int(payload[off+1]) + 1) * 8 extLen := (int(payload[off+1]) + 1) * 8
if off+extLen > hdrEnd { if off+extLen > hdrEnd {
return 0, false return 0, 0, false
}
next = payload[off]
off += extLen
default:
return 0, false
}
} }
return off + extLen, payload[off], true
} }
func (f *Forwarder) handleICMPDirect(payload []byte) bool { func (f *Forwarder) handleICMPDirect(payload []byte) bool {