From aaf5129c05ecdf1d013fbb51fc0edd0c0415ed39 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Tue, 8 Nov 2022 11:54:48 -0800 Subject: [PATCH] netstack: don't verify IPv4 checksum when offload is enabled There's no reason to check it. PiperOrigin-RevId: 487012436 --- pkg/tcpip/network/ipv4/ipv4.go | 4 ++-- pkg/tcpip/network/ipv6/ipv6.go | 2 +- pkg/tcpip/stack/conntrack.go | 4 ++-- pkg/tcpip/stack/nic.go | 2 +- pkg/tcpip/stack/packet_buffer.go | 8 ++++---- pkg/tcpip/transport/tcp/segment.go | 4 ++-- pkg/tcpip/transport/udp/endpoint.go | 2 +- pkg/tcpip/transport/udp/protocol.go | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/tcpip/network/ipv4/ipv4.go b/pkg/tcpip/network/ipv4/ipv4.go index 447f44414..8b9f267cf 100644 --- a/pkg/tcpip/network/ipv4/ipv4.go +++ b/pkg/tcpip/network/ipv4/ipv4.go @@ -835,7 +835,7 @@ func (e *endpoint) handleLocalPacket(pkt stack.PacketBufferPtr, canSkipRXChecksu pkt = pkt.CloneToInbound() defer pkt.DecRef() - pkt.RXTransportChecksumValidated = canSkipRXChecksum + pkt.RXChecksumValidated = canSkipRXChecksum h, ok := e.protocol.parseAndValidate(pkt) if !ok { @@ -1705,7 +1705,7 @@ func (p *protocol) parseAndValidate(pkt stack.PacketBufferPtr) (header.IPv4, boo return nil, false } - if !h.IsChecksumValid() { + if !pkt.RXChecksumValidated && !h.IsChecksumValid() { return nil, false } diff --git a/pkg/tcpip/network/ipv6/ipv6.go b/pkg/tcpip/network/ipv6/ipv6.go index ec6ccdf86..a87308b8e 100644 --- a/pkg/tcpip/network/ipv6/ipv6.go +++ b/pkg/tcpip/network/ipv6/ipv6.go @@ -1101,7 +1101,7 @@ func (e *endpoint) handleLocalPacket(pkt stack.PacketBufferPtr, canSkipRXChecksu pkt = pkt.CloneToInbound() defer pkt.DecRef() - pkt.RXTransportChecksumValidated = canSkipRXChecksum + pkt.RXChecksumValidated = canSkipRXChecksum hView, ok := e.protocol.parseAndValidate(pkt) if !ok { diff --git a/pkg/tcpip/stack/conntrack.go b/pkg/tcpip/stack/conntrack.go index b70035784..5a18025ae 100644 --- a/pkg/tcpip/stack/conntrack.go +++ b/pkg/tcpip/stack/conntrack.go @@ -530,7 +530,7 @@ func (ct *ConnTrack) getConnAndUpdate(pkt PacketBufferPtr, skipChecksumValidatio uint16(pkt.Data().Size()), tid.srcAddr, tid.dstAddr, - pkt.RXTransportChecksumValidated || skipChecksumValidation) + pkt.RXChecksumValidated || skipChecksumValidation) if !csumValid || !ok { return nil } @@ -542,7 +542,7 @@ func (ct *ConnTrack) getConnAndUpdate(pkt PacketBufferPtr, skipChecksumValidatio pkt.NetworkProtocolNumber, tid.srcAddr, tid.dstAddr, - pkt.RXTransportChecksumValidated || skipChecksumValidation) + pkt.RXChecksumValidated || skipChecksumValidation) if !lengthValid || !csumValid { return nil } diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go index 9dce040a9..8cfb1dea6 100644 --- a/pkg/tcpip/stack/nic.go +++ b/pkg/tcpip/stack/nic.go @@ -731,7 +731,7 @@ func (n *nic) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt Pac return } - pkt.RXTransportChecksumValidated = n.NetworkLinkEndpoint.Capabilities()&CapabilityRXChecksumOffload != 0 + pkt.RXChecksumValidated = n.NetworkLinkEndpoint.Capabilities()&CapabilityRXChecksumOffload != 0 networkEndpoint.HandlePacket(pkt) } diff --git a/pkg/tcpip/stack/packet_buffer.go b/pkg/tcpip/stack/packet_buffer.go index a849df8a5..3f80093a2 100644 --- a/pkg/tcpip/stack/packet_buffer.go +++ b/pkg/tcpip/stack/packet_buffer.go @@ -162,9 +162,9 @@ type packetBuffer struct { // NICID is the ID of the last interface the network packet was handled at. NICID tcpip.NICID - // RXTransportChecksumValidated indicates that transport checksum verification - // may be safely skipped. - RXTransportChecksumValidated bool + // RXChecksumValidated indicates that checksum verification may be + // safely skipped. + RXChecksumValidated bool // NetworkPacketInfo holds an incoming packet's network-layer information. NetworkPacketInfo NetworkPacketInfo @@ -390,7 +390,7 @@ func (pk PacketBufferPtr) Clone() PacketBufferPtr { newPk.TransportProtocolNumber = pk.TransportProtocolNumber newPk.PktType = pk.PktType newPk.NICID = pk.NICID - newPk.RXTransportChecksumValidated = pk.RXTransportChecksumValidated + newPk.RXChecksumValidated = pk.RXChecksumValidated newPk.NetworkPacketInfo = pk.NetworkPacketInfo newPk.tuple = pk.tuple newPk.InitRefs() diff --git a/pkg/tcpip/transport/tcp/segment.go b/pkg/tcpip/transport/tcp/segment.go index abdac9077..1655a17dd 100644 --- a/pkg/tcpip/transport/tcp/segment.go +++ b/pkg/tcpip/transport/tcp/segment.go @@ -101,7 +101,7 @@ func newIncomingSegment(id stack.TransportEndpointID, clock tcpip.Clock, pkt sta uint16(pkt.Data().Size()), netHdr.SourceAddress(), netHdr.DestinationAddress(), - pkt.RXTransportChecksumValidated) + pkt.RXChecksumValidated) if !ok { return nil, fmt.Errorf("header data offset does not respect size constraints: %d < offset < %d, got offset=%d", header.TCPMinimumSize, len(hdr), hdr.DataOffset()) } @@ -119,7 +119,7 @@ func newIncomingSegment(id stack.TransportEndpointID, clock tcpip.Clock, pkt sta s.pkt = pkt.IncRef() s.csumValid = csumValid - if !s.pkt.RXTransportChecksumValidated { + if !s.pkt.RXChecksumValidated { s.csum = csum } return s, nil diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index ff75c5def..28f6feaf7 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -913,7 +913,7 @@ func (e *endpoint) HandlePacket(id stack.TransportEndpointID, pkt stack.PacketBu pkt.NetworkProtocolNumber, netHdr.SourceAddress(), netHdr.DestinationAddress(), - pkt.RXTransportChecksumValidated) + pkt.RXChecksumValidated) if !lengthValid { // Malformed packet. e.stack.Stats().UDP.MalformedPacketsReceived.Increment() diff --git a/pkg/tcpip/transport/udp/protocol.go b/pkg/tcpip/transport/udp/protocol.go index 2a8518efd..d4de0d2b4 100644 --- a/pkg/tcpip/transport/udp/protocol.go +++ b/pkg/tcpip/transport/udp/protocol.go @@ -87,7 +87,7 @@ func (p *protocol) HandleUnknownDestinationPacket(id stack.TransportEndpointID, pkt.NetworkProtocolNumber, netHdr.SourceAddress(), netHdr.DestinationAddress(), - pkt.RXTransportChecksumValidated) + pkt.RXChecksumValidated) if !lengthValid { p.stack.Stats().UDP.MalformedPacketsReceived.Increment() return stack.UnknownDestinationPacketMalformed