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/registration.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/registration.go')
-rw-r--r-- | pkg/tcpip/stack/registration.go | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/pkg/tcpip/stack/registration.go b/pkg/tcpip/stack/registration.go index 924790779..0f6ec92c9 100644 --- a/pkg/tcpip/stack/registration.go +++ b/pkg/tcpip/stack/registration.go @@ -513,6 +513,23 @@ type NetworkInterface interface { // WritePacketToRemote writes the packet to the given remote link address. WritePacketToRemote(tcpip.LinkAddress, *GSO, tcpip.NetworkProtocolNumber, *PacketBuffer) *tcpip.Error + + // WritePacket writes a packet with the given protocol through the given + // route. + // + // WritePacket takes ownership of the packet buffer. The packet buffer's + // network and transport header must be set. + WritePacket(*Route, *GSO, tcpip.NetworkProtocolNumber, *PacketBuffer) *tcpip.Error + + // WritePackets writes packets with the given protocol through the given + // route. Must not be called with an empty list of packet buffers. + // + // WritePackets takes ownership of the packet buffers. + // + // Right now, WritePackets is used only when the software segmentation + // offload is enabled. If it will be used for something else, syscall filters + // may need to be updated. + WritePackets(*Route, *GSO, PacketBufferList, tcpip.NetworkProtocolNumber) (int, *tcpip.Error) } // LinkResolvableNetworkEndpoint handles link resolution events. @@ -708,24 +725,6 @@ type NetworkLinkEndpoint interface { // LinkAddress returns the link address (typically a MAC) of the // endpoint. LinkAddress() tcpip.LinkAddress - - // WritePacket writes a packet with the given protocol through the - // given route. It takes ownership of pkt. pkt.NetworkHeader and - // pkt.TransportHeader must have already been set. - // - // To participate in transparent bridging, a LinkEndpoint implementation - // should call eth.Encode with header.EthernetFields.SrcAddr set to - // r.LocalLinkAddress if it is provided. - WritePacket(r *Route, gso *GSO, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) *tcpip.Error - - // WritePackets writes packets with the given protocol through the - // given route. pkts must not be zero length. It takes ownership of pkts and - // underlying packets. - // - // Right now, WritePackets is used only when the software segmentation - // offload is enabled. If it will be used for something else, it may - // require to change syscall filters. - WritePackets(r *Route, gso *GSO, pkts PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) } // LinkEndpoint is the interface implemented by data link layer protocols (e.g., @@ -768,6 +767,26 @@ type LinkEndpoint interface { // AddHeader adds a link layer header to pkt if required. AddHeader(local, remote tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) + + // WritePacket writes a packet with the given protocol and route. + // + // WritePacket takes ownership of the packet buffer. The packet buffer's + // network and transport header must be set. + // + // To participate in transparent bridging, a LinkEndpoint implementation + // should call eth.Encode with header.EthernetFields.SrcAddr set to + // r.LocalLinkAddress if it is provided. + WritePacket(RouteInfo, *GSO, tcpip.NetworkProtocolNumber, *PacketBuffer) *tcpip.Error + + // WritePackets writes packets with the given protocol and route. Must not be + // called with an empty list of packet buffers. + // + // WritePackets takes ownership of the packet buffers. + // + // Right now, WritePackets is used only when the software segmentation + // offload is enabled. If it will be used for something else, syscall filters + // may need to be updated. + WritePackets(RouteInfo, *GSO, PacketBufferList, tcpip.NetworkProtocolNumber) (int, *tcpip.Error) } // InjectableLinkEndpoint is a LinkEndpoint where inbound packets are |