diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-03-13 17:47:47 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-03-13 17:47:47 +0000 |
commit | f6f99d23a5c3f625ab9100fd6e8d82d1005b7792 (patch) | |
tree | 49da0b2f89b21415f461d692e9279b0d5520c4e3 | |
parent | bc50e54cd6edc4d0c398ff7202c28d05a250edf6 (diff) | |
parent | 28d26d2c4f231c447a10bcbcfb8223a804c9d8bc (diff) |
Merge release-20200219.0-162-g28d26d2 (automated)
-rw-r--r-- | pkg/tcpip/stack/nic.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go index 3cd5fec71..230ee0697 100644 --- a/pkg/tcpip/stack/nic.go +++ b/pkg/tcpip/stack/nic.go @@ -15,6 +15,7 @@ package stack import ( + "fmt" "log" "reflect" "sort" @@ -1259,9 +1260,24 @@ func (n *NIC) DeliverNetworkPacket(linkEP LinkEndpoint, remote, local tcpip.Link func (n *NIC) forwardPacket(r *Route, protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) { // TODO(b/143425874) Decrease the TTL field in forwarded packets. - pkt.Header = buffer.NewPrependableFromView(pkt.Data.First()) + + firstData := pkt.Data.First() pkt.Data.RemoveFirst() + if linkHeaderLen := int(n.linkEP.MaxHeaderLength()); linkHeaderLen == 0 { + pkt.Header = buffer.NewPrependableFromView(firstData) + } else { + firstDataLen := len(firstData) + + // pkt.Header should have enough capacity to hold n.linkEP's headers. + pkt.Header = buffer.NewPrependable(firstDataLen + linkHeaderLen) + + // TODO(b/151227689): avoid copying the packet when forwarding + if n := copy(pkt.Header.Prepend(firstDataLen), firstData); n != firstDataLen { + panic(fmt.Sprintf("copied %d bytes, expected %d", n, firstDataLen)) + } + } + if err := n.linkEP.WritePacket(r, nil /* gso */, protocol, pkt); err != nil { r.Stats().IP.OutgoingPacketErrors.Increment() return |