summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/network
diff options
context:
space:
mode:
authorGhanan Gowripalan <ghanan@google.com>2021-01-15 16:46:51 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-15 16:49:15 -0800
commitfd5b52c87ff8fbabf2b293fc95ec9f9f04e5621c (patch)
tree9c557488caa1cce91986edc3f70f39b96e494c97 /pkg/tcpip/network
parent12d9790833cc2f6a9b197066a5ecbeb434f74164 (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/network')
-rw-r--r--pkg/tcpip/network/arp/arp_test.go14
-rw-r--r--pkg/tcpip/network/ipv6/icmp_test.go16
-rw-r--r--pkg/tcpip/network/testutil/testutil.go4
3 files changed, 25 insertions, 9 deletions
diff --git a/pkg/tcpip/network/arp/arp_test.go b/pkg/tcpip/network/arp/arp_test.go
index 6b61f57ad..0536e1698 100644
--- a/pkg/tcpip/network/arp/arp_test.go
+++ b/pkg/tcpip/network/arp/arp_test.go
@@ -560,15 +560,23 @@ func (*testInterface) Promiscuous() bool {
return false
}
+func (t *testInterface) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) *tcpip.Error {
+ return t.LinkEndpoint.WritePacket(r.Fields(), gso, protocol, pkt)
+}
+
+func (t *testInterface) WritePackets(r *stack.Route, gso *stack.GSO, pkts stack.PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
+ return t.LinkEndpoint.WritePackets(r.Fields(), gso, pkts, protocol)
+}
+
func (t *testInterface) WritePacketToRemote(remoteLinkAddr tcpip.LinkAddress, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) *tcpip.Error {
if t.writeErr != nil {
return t.writeErr
}
- var r stack.Route
+ var r stack.RouteInfo
r.NetProto = protocol
- r.ResolveWith(remoteLinkAddr)
- return t.LinkEndpoint.WritePacket(&r, gso, protocol, pkt)
+ r.RemoteLinkAddress = remoteLinkAddr
+ return t.LinkEndpoint.WritePacket(r, gso, protocol, pkt)
}
func TestLinkAddressRequest(t *testing.T) {
diff --git a/pkg/tcpip/network/ipv6/icmp_test.go b/pkg/tcpip/network/ipv6/icmp_test.go
index 0ec0a0fef..b1e6a70a2 100644
--- a/pkg/tcpip/network/ipv6/icmp_test.go
+++ b/pkg/tcpip/network/ipv6/icmp_test.go
@@ -77,7 +77,7 @@ func (*stubLinkEndpoint) LinkAddress() tcpip.LinkAddress {
return ""
}
-func (*stubLinkEndpoint) WritePacket(*stack.Route, *stack.GSO, tcpip.NetworkProtocolNumber, *stack.PacketBuffer) *tcpip.Error {
+func (*stubLinkEndpoint) WritePacket(stack.RouteInfo, *stack.GSO, tcpip.NetworkProtocolNumber, *stack.PacketBuffer) *tcpip.Error {
return nil
}
@@ -148,11 +148,19 @@ func (*testInterface) Promiscuous() bool {
return false
}
+func (t *testInterface) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) *tcpip.Error {
+ return t.LinkEndpoint.WritePacket(r.Fields(), gso, protocol, pkt)
+}
+
+func (t *testInterface) WritePackets(r *stack.Route, gso *stack.GSO, pkts stack.PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
+ return t.LinkEndpoint.WritePackets(r.Fields(), gso, pkts, protocol)
+}
+
func (t *testInterface) WritePacketToRemote(remoteLinkAddr tcpip.LinkAddress, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) *tcpip.Error {
- var r stack.Route
+ var r stack.RouteInfo
r.NetProto = protocol
- r.ResolveWith(remoteLinkAddr)
- return t.LinkEndpoint.WritePacket(&r, gso, protocol, pkt)
+ r.RemoteLinkAddress = remoteLinkAddr
+ return t.LinkEndpoint.WritePacket(r, gso, protocol, pkt)
}
func TestICMPCounts(t *testing.T) {
diff --git a/pkg/tcpip/network/testutil/testutil.go b/pkg/tcpip/network/testutil/testutil.go
index 5c3363759..3af44991f 100644
--- a/pkg/tcpip/network/testutil/testutil.go
+++ b/pkg/tcpip/network/testutil/testutil.go
@@ -62,7 +62,7 @@ func (*MockLinkEndpoint) MaxHeaderLength() uint16 { return 0 }
func (*MockLinkEndpoint) LinkAddress() tcpip.LinkAddress { return "" }
// WritePacket implements LinkEndpoint.WritePacket.
-func (ep *MockLinkEndpoint) WritePacket(_ *stack.Route, _ *stack.GSO, _ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) *tcpip.Error {
+func (ep *MockLinkEndpoint) WritePacket(_ stack.RouteInfo, _ *stack.GSO, _ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) *tcpip.Error {
if ep.allowPackets == 0 {
return ep.err
}
@@ -72,7 +72,7 @@ func (ep *MockLinkEndpoint) WritePacket(_ *stack.Route, _ *stack.GSO, _ tcpip.Ne
}
// WritePackets implements LinkEndpoint.WritePackets.
-func (ep *MockLinkEndpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts stack.PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
+func (ep *MockLinkEndpoint) WritePackets(r stack.RouteInfo, gso *stack.GSO, pkts stack.PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
var n int
for pkt := pkts.Front(); pkt != nil; pkt = pkt.Next() {