diff options
author | Nick Brown <nickbrow@google.com> | 2021-03-24 09:36:50 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-24 09:38:27 -0700 |
commit | ec0aa657edfd98a1e8dfbbf017ee6cf8c7f1a40e (patch) | |
tree | 8506257a2992c91db2d2c3b1e7d29eb9ef5279bc /pkg/tcpip/stack | |
parent | 8ee4a3f6d0e75e51e088a431376d2976b0dac866 (diff) |
Unexpose immutable fields in stack.Route
This change sets the inner `routeInfo` struct to be a named private member
and replaces direct access with access through getters. Note that direct
access to the fields of `routeInfo` is still possible through the `RouteInfo`
struct.
Fixes #4902
PiperOrigin-RevId: 364822872
Diffstat (limited to 'pkg/tcpip/stack')
-rw-r--r-- | pkg/tcpip/stack/forwarding_test.go | 4 | ||||
-rw-r--r-- | pkg/tcpip/stack/ndp_test.go | 8 | ||||
-rw-r--r-- | pkg/tcpip/stack/route.go | 85 | ||||
-rw-r--r-- | pkg/tcpip/stack/stack_test.go | 146 | ||||
-rw-r--r-- | pkg/tcpip/stack/transport_test.go | 4 |
5 files changed, 127 insertions, 120 deletions
diff --git a/pkg/tcpip/stack/forwarding_test.go b/pkg/tcpip/stack/forwarding_test.go index c987c1851..16ee75bc4 100644 --- a/pkg/tcpip/stack/forwarding_test.go +++ b/pkg/tcpip/stack/forwarding_test.go @@ -121,8 +121,8 @@ func (f *fwdTestNetworkEndpoint) WritePacket(r *Route, gso *GSO, params NetworkH // Add the protocol's header to the packet and send it to the link // endpoint. b := pkt.NetworkHeader().Push(fwdTestNetHeaderLen) - b[dstAddrOffset] = r.RemoteAddress[0] - b[srcAddrOffset] = r.LocalAddress[0] + b[dstAddrOffset] = r.RemoteAddress()[0] + b[srcAddrOffset] = r.LocalAddress()[0] b[protocolNumberOffset] = byte(params.Protocol) return f.nic.WritePacket(r, gso, fwdTestNetNumber, pkt) diff --git a/pkg/tcpip/stack/ndp_test.go b/pkg/tcpip/stack/ndp_test.go index 43e6d102c..0725e028b 100644 --- a/pkg/tcpip/stack/ndp_test.go +++ b/pkg/tcpip/stack/ndp_test.go @@ -578,8 +578,8 @@ func TestDADResolve(t *testing.T) { r, err := s.FindRoute(nicID, "", addr2, header.IPv6ProtocolNumber, false) if err != nil { t.Errorf("got FindRoute(%d, '', %s, %d, false): %s", nicID, addr2, header.IPv6ProtocolNumber, err) - } else if r.LocalAddress != addr1 { - t.Errorf("got r.LocalAddress = %s, want = %s", r.LocalAddress, addr1) + } else if r.LocalAddress() != addr1 { + t.Errorf("got r.LocalAddress() = %s, want = %s", r.LocalAddress(), addr1) } r.Release() } @@ -587,8 +587,8 @@ func TestDADResolve(t *testing.T) { r, err := s.FindRoute(nicID, addr1, addr2, header.IPv6ProtocolNumber, false) if err != nil { t.Errorf("got FindRoute(%d, %s, %s, %d, false): %s", nicID, addr1, addr2, header.IPv6ProtocolNumber, err) - } else if r.LocalAddress != addr1 { - t.Errorf("got r.LocalAddress = %s, want = %s", r.LocalAddress, addr1) + } else if r.LocalAddress() != addr1 { + t.Errorf("got r.LocalAddress() = %s, want = %s", r.LocalAddress(), addr1) } if r != nil { r.Release() diff --git a/pkg/tcpip/stack/route.go b/pkg/tcpip/stack/route.go index 4ba6794a0..39344808d 100644 --- a/pkg/tcpip/stack/route.go +++ b/pkg/tcpip/stack/route.go @@ -25,12 +25,8 @@ import ( // Route represents a route through the networking stack to a given destination. // // It is safe to call Route's methods from multiple goroutines. -// -// The exported fields are immutable. -// -// TODO(gvisor.dev/issue/4902): Unexpose immutable fields. type Route struct { - routeInfo + routeInfo routeInfo // localAddressNIC is the interface the address is associated with. // TODO(gvisor.dev/issue/4548): Remove this field once we can query the @@ -57,26 +53,49 @@ type Route struct { } type routeInfo struct { - // RemoteAddress is the final destination of the route. RemoteAddress tcpip.Address - // LocalAddress is the local address where the route starts. LocalAddress tcpip.Address - // LocalLinkAddress is the link-layer (MAC) address of the - // where the route starts. LocalLinkAddress tcpip.LinkAddress - // NextHop is the next node in the path to the destination. NextHop tcpip.Address - // NetProto is the network-layer protocol. NetProto tcpip.NetworkProtocolNumber - // Loop controls where WritePacket should send packets. Loop PacketLooping } +// RemoteAddress returns the route's destination. +func (r *Route) RemoteAddress() tcpip.Address { + return r.routeInfo.RemoteAddress +} + +// LocalAddress returns the route's local address. +func (r *Route) LocalAddress() tcpip.Address { + return r.routeInfo.LocalAddress +} + +// LocalLinkAddress returns the route's local link-layer address. +func (r *Route) LocalLinkAddress() tcpip.LinkAddress { + return r.routeInfo.LocalLinkAddress +} + +// NextHop returns the next node in the route's path to the destination. +func (r *Route) NextHop() tcpip.Address { + return r.routeInfo.NextHop +} + +// NetProto returns the route's network-layer protocol number. +func (r *Route) NetProto() tcpip.NetworkProtocolNumber { + return r.routeInfo.NetProto +} + +// Loop returns the route's required packet looping. +func (r *Route) Loop() PacketLooping { + return r.routeInfo.Loop +} + // RouteInfo contains all of Route's exported fields. type RouteInfo struct { routeInfo @@ -167,20 +186,20 @@ func makeRoute(netProto tcpip.NetworkProtocolNumber, gateway, localAddr, remoteA } r := makeRouteInner(netProto, localAddr, remoteAddr, outgoingNIC, localAddressNIC, localAddressEndpoint, loop) - if r.Loop&PacketOut == 0 { + if r.Loop()&PacketOut == 0 { // Packet will not leave the stack, no need for a gateway or a remote link // address. return r } if r.outgoingNIC.LinkEndpoint.Capabilities()&CapabilityResolutionRequired != 0 { - if linkRes, ok := r.outgoingNIC.linkAddrResolvers[r.NetProto]; ok { + if linkRes, ok := r.outgoingNIC.linkAddrResolvers[r.NetProto()]; ok { r.linkRes = linkRes } } if len(gateway) > 0 { - r.NextHop = gateway + r.routeInfo.NextHop = gateway return r } @@ -188,7 +207,7 @@ func makeRoute(netProto tcpip.NetworkProtocolNumber, gateway, localAddr, remoteA return r } - if linkAddr, ok := r.linkRes.resolver.ResolveStaticAddress(r.RemoteAddress); ok { + if linkAddr, ok := r.linkRes.resolver.ResolveStaticAddress(r.RemoteAddress()); ok { r.ResolveWith(linkAddr) return r } @@ -198,9 +217,9 @@ func makeRoute(netProto tcpip.NetworkProtocolNumber, gateway, localAddr, remoteA return r } - if r.RemoteAddress == r.LocalAddress { + if r.RemoteAddress() == r.LocalAddress() { // Local link address is already known. - r.ResolveWith(r.LocalLinkAddress) + r.ResolveWith(r.LocalLinkAddress()) } return r @@ -256,7 +275,7 @@ func (r *Route) NICID() tcpip.NICID { // MaxHeaderLength forwards the call to the network endpoint's implementation. func (r *Route) MaxHeaderLength() uint16 { - return r.outgoingNIC.getNetworkEndpoint(r.NetProto).MaxHeaderLength() + return r.outgoingNIC.getNetworkEndpoint(r.NetProto()).MaxHeaderLength() } // Stats returns a mutable copy of current stats. @@ -267,7 +286,7 @@ func (r *Route) Stats() tcpip.Stats { // PseudoHeaderChecksum forwards the call to the network endpoint's // implementation. func (r *Route) PseudoHeaderChecksum(protocol tcpip.TransportProtocolNumber, totalLen uint16) uint16 { - return header.PseudoHeaderChecksum(protocol, r.LocalAddress, r.RemoteAddress, totalLen) + return header.PseudoHeaderChecksum(protocol, r.LocalAddress(), r.RemoteAddress(), totalLen) } // RequiresTXTransportChecksum returns false if the route does not require @@ -358,7 +377,7 @@ func (r *Route) resolvedFields(afterResolve func(ResolvedFieldsResult)) (RouteIn // address on the outgoing interface. var linkAddressResolutionRequestLocalAddr tcpip.Address if r.localAddressNIC == r.outgoingNIC { - linkAddressResolutionRequestLocalAddr = r.LocalAddress + linkAddressResolutionRequestLocalAddr = r.LocalAddress() } afterResolveFields := fields @@ -378,15 +397,15 @@ func (r *Route) resolvedFields(afterResolve func(ResolvedFieldsResult)) (RouteIn } func (r *Route) nextHop() tcpip.Address { - if len(r.NextHop) == 0 { - return r.RemoteAddress + if len(r.NextHop()) == 0 { + return r.RemoteAddress() } - return r.NextHop + return r.NextHop() } // local returns true if the route is a local route. func (r *Route) local() bool { - return r.Loop == PacketLoop || r.outgoingNIC.IsLoopback() + return r.Loop() == PacketLoop || r.outgoingNIC.IsLoopback() } // IsResolutionRequired returns true if Resolve() must be called to resolve @@ -421,7 +440,7 @@ func (r *Route) isValidForOutgoingRLocked() bool { // If the source NIC and outgoing NIC are different, make sure the stack has // forwarding enabled, or the packet will be handled locally. - if r.outgoingNIC != r.localAddressNIC && !r.outgoingNIC.stack.Forwarding(r.NetProto) && (!r.outgoingNIC.stack.handleLocal || !r.outgoingNIC.hasAddress(r.NetProto, r.RemoteAddress)) { + if r.outgoingNIC != r.localAddressNIC && !r.outgoingNIC.stack.Forwarding(r.NetProto()) && (!r.outgoingNIC.stack.handleLocal || !r.outgoingNIC.hasAddress(r.NetProto(), r.RemoteAddress())) { return false } @@ -434,7 +453,7 @@ func (r *Route) WritePacket(gso *GSO, params NetworkHeaderParams, pkt *PacketBuf return &tcpip.ErrInvalidEndpointState{} } - return r.outgoingNIC.getNetworkEndpoint(r.NetProto).WritePacket(r, gso, params, pkt) + return r.outgoingNIC.getNetworkEndpoint(r.NetProto()).WritePacket(r, gso, params, pkt) } // WritePackets writes a list of n packets through the given route and returns @@ -444,7 +463,7 @@ func (r *Route) WritePackets(gso *GSO, pkts PacketBufferList, params NetworkHead return 0, &tcpip.ErrInvalidEndpointState{} } - return r.outgoingNIC.getNetworkEndpoint(r.NetProto).WritePackets(r, gso, pkts, params) + return r.outgoingNIC.getNetworkEndpoint(r.NetProto()).WritePackets(r, gso, pkts, params) } // WriteHeaderIncludedPacket writes a packet already containing a network @@ -454,17 +473,17 @@ func (r *Route) WriteHeaderIncludedPacket(pkt *PacketBuffer) tcpip.Error { return &tcpip.ErrInvalidEndpointState{} } - return r.outgoingNIC.getNetworkEndpoint(r.NetProto).WriteHeaderIncludedPacket(r, pkt) + return r.outgoingNIC.getNetworkEndpoint(r.NetProto()).WriteHeaderIncludedPacket(r, pkt) } // DefaultTTL returns the default TTL of the underlying network endpoint. func (r *Route) DefaultTTL() uint8 { - return r.outgoingNIC.getNetworkEndpoint(r.NetProto).DefaultTTL() + return r.outgoingNIC.getNetworkEndpoint(r.NetProto()).DefaultTTL() } // MTU returns the MTU of the underlying network endpoint. func (r *Route) MTU() uint32 { - return r.outgoingNIC.getNetworkEndpoint(r.NetProto).MTU() + return r.outgoingNIC.getNetworkEndpoint(r.NetProto()).MTU() } // Release decrements the reference counter of the resources associated with the @@ -489,7 +508,7 @@ func (r *Route) Acquire() { func (r *Route) acquireLocked() { if ep := r.mu.localAddressEndpoint; ep != nil { if !ep.IncRef() { - panic(fmt.Sprintf("failed to increment reference count for local address endpoint = %s", r.LocalAddress)) + panic(fmt.Sprintf("failed to increment reference count for local address endpoint = %s", r.LocalAddress())) } } } @@ -519,7 +538,7 @@ func (r *Route) isV4Broadcast(addr tcpip.Address) bool { // packet. func (r *Route) IsOutboundBroadcast() bool { // Only IPv4 has a notion of broadcast. - return r.isV4Broadcast(r.RemoteAddress) + return r.isV4Broadcast(r.RemoteAddress()) } // ConfirmReachable informs the network/link layer that the neighbour used for diff --git a/pkg/tcpip/stack/stack_test.go b/pkg/tcpip/stack/stack_test.go index 7ddf7a083..2814b94b4 100644 --- a/pkg/tcpip/stack/stack_test.go +++ b/pkg/tcpip/stack/stack_test.go @@ -172,20 +172,20 @@ func (f *fakeNetworkEndpoint) NetworkProtocolNumber() tcpip.NetworkProtocolNumbe func (f *fakeNetworkEndpoint) WritePacket(r *stack.Route, gso *stack.GSO, params stack.NetworkHeaderParams, pkt *stack.PacketBuffer) tcpip.Error { // Increment the sent packet count in the protocol descriptor. - f.proto.sendPacketCount[int(r.RemoteAddress[0])%len(f.proto.sendPacketCount)]++ + f.proto.sendPacketCount[int(r.RemoteAddress()[0])%len(f.proto.sendPacketCount)]++ // Add the protocol's header to the packet and send it to the link // endpoint. hdr := pkt.NetworkHeader().Push(fakeNetHeaderLen) pkt.NetworkProtocolNumber = fakeNetNumber - hdr[dstAddrOffset] = r.RemoteAddress[0] - hdr[srcAddrOffset] = r.LocalAddress[0] + hdr[dstAddrOffset] = r.RemoteAddress()[0] + hdr[srcAddrOffset] = r.LocalAddress()[0] hdr[protocolNumberOffset] = byte(params.Protocol) - if r.Loop&stack.PacketLoop != 0 { + if r.Loop()&stack.PacketLoop != 0 { f.HandlePacket(pkt.Clone()) } - if r.Loop&stack.PacketOut == 0 { + if r.Loop()&stack.PacketOut == 0 { return nil } @@ -597,12 +597,12 @@ func testRoute(t *testing.T, s *stack.Stack, nic tcpip.NICID, srcAddr, dstAddr, defer r.Release() - if r.LocalAddress != expectedSrcAddr { - t.Fatalf("Bad source address: expected %v, got %v", expectedSrcAddr, r.LocalAddress) + if r.LocalAddress() != expectedSrcAddr { + t.Fatalf("got Route.LocalAddress() = %s, want = %s", expectedSrcAddr, r.LocalAddress()) } - if r.RemoteAddress != dstAddr { - t.Fatalf("Bad destination address: expected %v, got %v", dstAddr, r.RemoteAddress) + if r.RemoteAddress() != dstAddr { + t.Fatalf("got Route.RemoteAddress() = %s, want = %s", dstAddr, r.RemoteAddress()) } } @@ -1451,11 +1451,11 @@ func TestExternalSendWithHandleLocal(t *testing.T) { } defer r.Release() - if r.LocalAddress != localAddr { - t.Errorf("got r.LocalAddress = %s, want = %s", r.LocalAddress, localAddr) + if r.LocalAddress() != localAddr { + t.Errorf("got r.LocalAddress() = %s, want = %s", r.LocalAddress(), localAddr) } - if r.RemoteAddress != dstAddr { - t.Errorf("got r.RemoteAddress = %s, want = %s", r.RemoteAddress, dstAddr) + if r.RemoteAddress() != dstAddr { + t.Errorf("got r.RemoteAddress() = %s, want = %s", r.RemoteAddress(), dstAddr) } if n := ep.Drain(); n != 0 { @@ -1522,11 +1522,11 @@ func TestSpoofingWithAddress(t *testing.T) { if err != nil { t.Fatal("FindRoute failed:", err) } - if r.LocalAddress != nonExistentLocalAddr { - t.Errorf("got Route.LocalAddress = %s, want = %s", r.LocalAddress, nonExistentLocalAddr) + if r.LocalAddress() != nonExistentLocalAddr { + t.Errorf("got Route.LocalAddress() = %s, want = %s", r.LocalAddress(), nonExistentLocalAddr) } - if r.RemoteAddress != dstAddr { - t.Errorf("got Route.RemoteAddress = %s, want = %s", r.RemoteAddress, dstAddr) + if r.RemoteAddress() != dstAddr { + t.Errorf("got Route.RemoteAddress() = %s, want = %s", r.RemoteAddress(), dstAddr) } // Sending a packet works. testSendTo(t, s, dstAddr, ep, nil) @@ -1537,11 +1537,11 @@ func TestSpoofingWithAddress(t *testing.T) { if err != nil { t.Fatal("FindRoute failed:", err) } - if r.LocalAddress != localAddr { - t.Errorf("got Route.LocalAddress = %s, want = %s", r.LocalAddress, nonExistentLocalAddr) + if r.LocalAddress() != localAddr { + t.Errorf("got Route.LocalAddress() = %s, want = %s", r.LocalAddress(), nonExistentLocalAddr) } - if r.RemoteAddress != dstAddr { - t.Errorf("got Route.RemoteAddress = %s, want = %s", r.RemoteAddress, dstAddr) + if r.RemoteAddress() != dstAddr { + t.Errorf("got Route.RemoteAddress() = %s, want = %s", r.RemoteAddress(), dstAddr) } // Sending a packet using the route works. testSend(t, r, ep, nil) @@ -1586,33 +1586,17 @@ func TestSpoofingNoAddress(t *testing.T) { if err != nil { t.Fatal("FindRoute failed:", err) } - if r.LocalAddress != nonExistentLocalAddr { - t.Errorf("got Route.LocalAddress = %s, want = %s", r.LocalAddress, nonExistentLocalAddr) + if r.LocalAddress() != nonExistentLocalAddr { + t.Errorf("got Route.LocalAddress() = %s, want = %s", r.LocalAddress(), nonExistentLocalAddr) } - if r.RemoteAddress != dstAddr { - t.Errorf("got Route.RemoteAddress = %s, want = %s", r.RemoteAddress, dstAddr) + if r.RemoteAddress() != dstAddr { + t.Errorf("got Route.RemoteAddress() = %s, want = %s", r.RemoteAddress(), dstAddr) } // Sending a packet works. // FIXME(b/139841518):Spoofing doesn't work if there is no primary address. // testSendTo(t, s, remoteAddr, ep, nil) } -func verifyRoute(gotRoute, wantRoute *stack.Route) error { - if gotRoute.LocalAddress != wantRoute.LocalAddress { - return fmt.Errorf("bad local address: got %s, want = %s", gotRoute.LocalAddress, wantRoute.LocalAddress) - } - if gotRoute.RemoteAddress != wantRoute.RemoteAddress { - return fmt.Errorf("bad remote address: got %s, want = %s", gotRoute.RemoteAddress, wantRoute.RemoteAddress) - } - if got, want := gotRoute.RemoteLinkAddress(), wantRoute.RemoteLinkAddress(); got != want { - return fmt.Errorf("bad remote link address: got %s, want = %s", got, want) - } - if gotRoute.NextHop != wantRoute.NextHop { - return fmt.Errorf("bad next-hop address: got %s, want = %s", gotRoute.NextHop, wantRoute.NextHop) - } - return nil -} - func TestOutgoingBroadcastWithEmptyRouteTable(t *testing.T) { s := stack.New(stack.Options{ NetworkProtocols: []stack.NetworkProtocolFactory{fakeNetFactory}, @@ -1640,11 +1624,12 @@ func TestOutgoingBroadcastWithEmptyRouteTable(t *testing.T) { if err != nil { t.Fatalf("FindRoute(1, %v, %v, %d) failed: %v", header.IPv4Any, header.IPv4Broadcast, fakeNetNumber, err) } - var wantRoute stack.Route - wantRoute.LocalAddress = header.IPv4Any - wantRoute.RemoteAddress = header.IPv4Broadcast - if err := verifyRoute(r, &wantRoute); err != nil { - t.Errorf("FindRoute(1, %v, %v, %d) returned unexpected Route: %v", header.IPv4Any, header.IPv4Broadcast, fakeNetNumber, err) + if r.LocalAddress() != header.IPv4Any { + t.Errorf("got Route.LocalAddress() = %s, want = %s", r.LocalAddress(), header.IPv4Any) + } + + if r.RemoteAddress() != header.IPv4Broadcast { + t.Errorf("got Route.RemoteAddress() = %s, want = %s", r.RemoteAddress(), header.IPv4Broadcast) } // If the NIC doesn't exist, it won't work. @@ -1700,11 +1685,12 @@ func TestOutgoingBroadcastWithRouteTable(t *testing.T) { if err != nil { t.Fatalf("FindRoute(1, %v, %v, %d) failed: %v", nic1Addr.Address, header.IPv4Broadcast, fakeNetNumber, err) } - var wantRoute stack.Route - wantRoute.LocalAddress = nic1Addr.Address - wantRoute.RemoteAddress = header.IPv4Broadcast - if err := verifyRoute(r, &wantRoute); err != nil { - t.Errorf("FindRoute(1, %v, %v, %d) returned unexpected Route: %v", nic1Addr.Address, header.IPv4Broadcast, fakeNetNumber, err) + if r.LocalAddress() != nic1Addr.Address { + t.Errorf("got Route.LocalAddress() = %s, want = %s", r.LocalAddress(), nic1Addr.Address) + } + + if r.RemoteAddress() != header.IPv4Broadcast { + t.Errorf("got Route.RemoteAddress() = %s, want = %s", r.RemoteAddress(), header.IPv4Broadcast) } // When an interface is not given, it consults the route table. @@ -1713,11 +1699,12 @@ func TestOutgoingBroadcastWithRouteTable(t *testing.T) { if err != nil { t.Fatalf("FindRoute(0, \"\", %s, %d) failed: %s", header.IPv4Broadcast, fakeNetNumber, err) } - wantRoute = stack.Route{} - wantRoute.LocalAddress = nic2Addr.Address - wantRoute.RemoteAddress = header.IPv4Broadcast - if err := verifyRoute(r, &wantRoute); err != nil { - t.Errorf("FindRoute(0, \"\", %s, %d) returned unexpected Route: %s)", header.IPv4Broadcast, fakeNetNumber, err) + if r.LocalAddress() != nic2Addr.Address { + t.Errorf("got Route.LocalAddress() = %s, want = %s", r.LocalAddress(), nic2Addr.Address) + } + + if r.RemoteAddress() != header.IPv4Broadcast { + t.Errorf("got Route.RemoteAddress() = %s, want = %s", r.RemoteAddress(), header.IPv4Broadcast) } // 2. Case: Having an explicit route for broadcast will select that one. @@ -1732,11 +1719,12 @@ func TestOutgoingBroadcastWithRouteTable(t *testing.T) { if err != nil { t.Fatalf("FindRoute(0, \"\", %s, %d) failed: %s", header.IPv4Broadcast, fakeNetNumber, err) } - wantRoute = stack.Route{} - wantRoute.LocalAddress = nic1Addr.Address - wantRoute.RemoteAddress = header.IPv4Broadcast - if err := verifyRoute(r, &wantRoute); err != nil { - t.Errorf("FindRoute(0, \"\", %s, %d) returned unexpected Route: %s)", header.IPv4Broadcast, fakeNetNumber, err) + if r.LocalAddress() != nic1Addr.Address { + t.Errorf("got Route.LocalAddress() = %s, want = %s", r.LocalAddress(), nic1Addr.Address) + } + + if r.RemoteAddress() != header.IPv4Broadcast { + t.Errorf("got Route.RemoteAddress() = %s, want = %s", r.RemoteAddress(), header.IPv4Broadcast) } } @@ -1817,11 +1805,11 @@ func TestMulticastOrIPv6LinkLocalNeedsNoRoute(t *testing.T) { if err != nil { t.Fatalf("FindRoute(1, %v, %v, %v) failed: %v", anyAddr, tc.address, fakeNetNumber, err) } - if r.LocalAddress != anyAddr { - t.Errorf("Bad local address: got %v, want = %v", r.LocalAddress, anyAddr) + if r.LocalAddress() != anyAddr { + t.Errorf("Bad local address: got %v, want = %v", r.LocalAddress(), anyAddr) } - if r.RemoteAddress != tc.address { - t.Errorf("Bad remote address: got %v, want = %v", r.RemoteAddress, tc.address) + if r.RemoteAddress() != tc.address { + t.Errorf("Bad remote address: got %v, want = %v", r.RemoteAddress(), tc.address) } } // If the NIC doesn't exist, it won't work. @@ -3654,23 +3642,23 @@ func TestOutgoingSubnetBroadcast(t *testing.T) { if err != nil { t.Fatalf("FindRoute(%d, '', %s, %d): %s", unspecifiedNICID, test.remoteAddr, netProto, err) } - if r.LocalAddress != test.expectedLocalAddress { - t.Errorf("got r.LocalAddress = %s, want = %s", r.LocalAddress, test.expectedLocalAddress) + if r.LocalAddress() != test.expectedLocalAddress { + t.Errorf("got r.LocalAddress() = %s, want = %s", r.LocalAddress(), test.expectedLocalAddress) } - if r.RemoteAddress != test.expectedRemoteAddress { - t.Errorf("got r.RemoteAddress = %s, want = %s", r.RemoteAddress, test.expectedRemoteAddress) + if r.RemoteAddress() != test.expectedRemoteAddress { + t.Errorf("got r.RemoteAddress = %s, want = %s", r.RemoteAddress(), test.expectedRemoteAddress) } if got := r.RemoteLinkAddress(); got != test.expectedRemoteLinkAddress { t.Errorf("got r.RemoteLinkAddress() = %s, want = %s", got, test.expectedRemoteLinkAddress) } - if r.NextHop != test.expectedNextHop { - t.Errorf("got r.NextHop = %s, want = %s", r.NextHop, test.expectedNextHop) + if r.NextHop() != test.expectedNextHop { + t.Errorf("got r.NextHop() = %s, want = %s", r.NextHop(), test.expectedNextHop) } - if r.NetProto != test.expectedNetProto { - t.Errorf("got r.NetProto = %d, want = %d", r.NetProto, test.expectedNetProto) + if r.NetProto() != test.expectedNetProto { + t.Errorf("got r.NetProto() = %d, want = %d", r.NetProto(), test.expectedNetProto) } - if r.Loop != test.expectedLoop { - t.Errorf("got r.Loop = %x, want = %x", r.Loop, test.expectedLoop) + if r.Loop() != test.expectedLoop { + t.Errorf("got r.Loop() = %x, want = %x", r.Loop(), test.expectedLoop) } }) } @@ -4245,11 +4233,11 @@ func TestFindRouteWithForwarding(t *testing.T) { return } - if r.LocalAddress != test.localAddr { - t.Errorf("got r.LocalAddress = %s, want = %s", r.LocalAddress, test.localAddr) + if r.LocalAddress() != test.localAddr { + t.Errorf("got r.LocalAddress() = %s, want = %s", r.LocalAddress(), test.localAddr) } - if r.RemoteAddress != test.netCfg.remoteAddr { - t.Errorf("got r.RemoteAddress = %s, want = %s", r.RemoteAddress, test.netCfg.remoteAddr) + if r.RemoteAddress() != test.netCfg.remoteAddr { + t.Errorf("got r.RemoteAddress() = %s, want = %s", r.RemoteAddress(), test.netCfg.remoteAddr) } if t.Failed() { diff --git a/pkg/tcpip/stack/transport_test.go b/pkg/tcpip/stack/transport_test.go index bebf4e6b5..054cced0c 100644 --- a/pkg/tcpip/stack/transport_test.go +++ b/pkg/tcpip/stack/transport_test.go @@ -92,7 +92,7 @@ func (*fakeTransportEndpoint) Read(io.Writer, tcpip.ReadOptions) (tcpip.ReadResu } func (f *fakeTransportEndpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcpip.Error) { - if len(f.route.RemoteAddress) == 0 { + if len(f.route.RemoteAddress()) == 0 { return 0, &tcpip.ErrNoRoute{} } @@ -230,7 +230,7 @@ func (f *fakeTransportEndpoint) HandlePacket(id stack.TransportEndpointID, pkt * NetProto: f.NetProto, }, proto: f.proto, - peerAddr: route.RemoteAddress, + peerAddr: route.RemoteAddress(), route: route, } ep.ops.InitHandler(ep, f.proto.stack, tcpip.GetStackSendBufferLimits) |