diff options
author | Ghanan Gowripalan <ghanan@google.com> | 2021-01-15 16:46:51 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-01-15 16:49:15 -0800 |
commit | fd5b52c87ff8fbabf2b293fc95ec9f9f04e5621c (patch) | |
tree | 9c557488caa1cce91986edc3f70f39b96e494c97 /pkg/tcpip/stack/nic.go | |
parent | 12d9790833cc2f6a9b197066a5ecbeb434f74164 (diff) |
Only pass stack.Route's fields to LinkEndpoints
stack.Route is used to send network packets and resolve link addresses.
A LinkEndpoint does not need to do either of these and only needs the
route's fields at the time of the packet write request.
Since LinkEndpoints only need the route's fields when writing packets,
pass a stack.RouteInfo instead.
PiperOrigin-RevId: 352108405
Diffstat (limited to 'pkg/tcpip/stack/nic.go')
-rw-r--r-- | pkg/tcpip/stack/nic.go | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go index 8a946b4fa..c8d0323cb 100644 --- a/pkg/tcpip/stack/nic.go +++ b/pkg/tcpip/stack/nic.go @@ -321,21 +321,18 @@ func (n *NIC) WritePacket(r *Route, gso *GSO, protocol tcpip.NetworkProtocolNumb return err } - return n.writePacket(r, gso, protocol, pkt) + return n.writePacket(r.Fields(), gso, protocol, pkt) } // WritePacketToRemote implements NetworkInterface. func (n *NIC) WritePacketToRemote(remoteLinkAddr tcpip.LinkAddress, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) *tcpip.Error { - r := Route{ - routeInfo: routeInfo{ - NetProto: protocol, - }, - } - r.ResolveWith(remoteLinkAddr) - return n.writePacket(&r, gso, protocol, pkt) + var r RouteInfo + r.NetProto = protocol + r.RemoteLinkAddress = remoteLinkAddr + return n.writePacket(r, gso, protocol, pkt) } -func (n *NIC) writePacket(r *Route, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) *tcpip.Error { +func (n *NIC) writePacket(r RouteInfo, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) *tcpip.Error { // WritePacket takes ownership of pkt, calculate numBytes first. numBytes := pkt.Size() @@ -352,7 +349,7 @@ func (n *NIC) writePacket(r *Route, gso *GSO, protocol tcpip.NetworkProtocolNumb func (n *NIC) WritePackets(r *Route, gso *GSO, pkts PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) { // TODO(gvisor.dev/issue/4458): Queue packets whie link address resolution // is being peformed like WritePacket. - writtenPackets, err := n.LinkEndpoint.WritePackets(r, gso, pkts, protocol) + writtenPackets, err := n.LinkEndpoint.WritePackets(r.Fields(), gso, pkts, protocol) n.stats.Tx.Packets.IncrementBy(uint64(writtenPackets)) writtenBytes := 0 for i, pb := 0, pkts.Front(); i < writtenPackets && pb != nil; i, pb = i+1, pb.Next() { |