diff options
author | Ting-Yu Wang <anivia@google.com> | 2020-05-29 12:58:50 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-05-29 13:00:30 -0700 |
commit | 341be65421edff16fd9eeb593301ce1d66148772 (patch) | |
tree | 0cb608fd8e23450d8b0983a2d422efdecdf676b0 /pkg/tcpip/stack/nic.go | |
parent | f498e46ef9153cd9254ae4995954632654577562 (diff) |
Update WritePacket* API to take ownership of packets to be written.
Updates #2404.
PiperOrigin-RevId: 313834784
Diffstat (limited to 'pkg/tcpip/stack/nic.go')
-rw-r--r-- | pkg/tcpip/stack/nic.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go index 9213cbb9a..05646e5e2 100644 --- a/pkg/tcpip/stack/nic.go +++ b/pkg/tcpip/stack/nic.go @@ -1304,13 +1304,16 @@ func (n *NIC) forwardPacket(r *Route, protocol tcpip.NetworkProtocolNumber, pkt pkt.Header = buffer.NewPrependable(linkHeaderLen) } + // WritePacket takes ownership of pkt, calculate numBytes first. + numBytes := pkt.Header.UsedLength() + pkt.Data.Size() + if err := n.linkEP.WritePacket(r, nil /* gso */, protocol, pkt); err != nil { r.Stats().IP.OutgoingPacketErrors.Increment() return } n.stats.Tx.Packets.Increment() - n.stats.Tx.Bytes.IncrementBy(uint64(pkt.Header.UsedLength() + pkt.Data.Size())) + n.stats.Tx.Bytes.IncrementBy(uint64(numBytes)) } // DeliverTransportPacket delivers the packets to the appropriate transport |