mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: don't allocate in newIncomingSegment
Manual inlining makes the compiler's life easier. In a redis-benchmark PING_INLINE test, this reduces allocations by 8.2%. PiperOrigin-RevId: 616180984
This commit is contained in:
committed by
gVisor bot
parent
bcc70e30fc
commit
846276b44b
@@ -94,13 +94,27 @@ type segment struct {
|
||||
|
||||
func newIncomingSegment(id stack.TransportEndpointID, clock tcpip.Clock, pkt *stack.PacketBuffer) (*segment, error) {
|
||||
hdr := header.TCP(pkt.TransportHeader().Slice())
|
||||
netHdr := pkt.Network()
|
||||
var srcAddr tcpip.Address
|
||||
var dstAddr tcpip.Address
|
||||
switch netProto := pkt.NetworkProtocolNumber; netProto {
|
||||
case header.IPv4ProtocolNumber:
|
||||
hdr := header.IPv4(pkt.NetworkHeader().Slice())
|
||||
srcAddr = hdr.SourceAddress()
|
||||
dstAddr = hdr.DestinationAddress()
|
||||
case header.IPv6ProtocolNumber:
|
||||
hdr := header.IPv6(pkt.NetworkHeader().Slice())
|
||||
srcAddr = hdr.SourceAddress()
|
||||
dstAddr = hdr.DestinationAddress()
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown network protocol number %d", netProto))
|
||||
}
|
||||
|
||||
csum, csumValid, ok := header.TCPValid(
|
||||
hdr,
|
||||
func() uint16 { return pkt.Data().Checksum() },
|
||||
uint16(pkt.Data().Size()),
|
||||
netHdr.SourceAddress(),
|
||||
netHdr.DestinationAddress(),
|
||||
srcAddr,
|
||||
dstAddr,
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user