diff --git a/pkg/sentry/socket/netlink/route/protocol.go b/pkg/sentry/socket/netlink/route/protocol.go index d526acb73..7195a46f4 100644 --- a/pkg/sentry/socket/netlink/route/protocol.go +++ b/pkg/sentry/socket/netlink/route/protocol.go @@ -335,7 +335,7 @@ func fillRoute(routes []inet.Route, addr []byte) (inet.Route, *syserr.Error) { idx = idxDef } if idx == -1 { - return inet.Route{}, syserr.ErrNoRoute + return inet.Route{}, syserr.ErrHostUnreachable } route := routes[idx] diff --git a/pkg/syserr/netstack.go b/pkg/syserr/netstack.go index ab5d9e4dd..6f1797045 100644 --- a/pkg/syserr/netstack.go +++ b/pkg/syserr/netstack.go @@ -74,8 +74,8 @@ func TranslateNetstackError(err tcpip.Error) *Error { return ErrDuplicateNICID case *tcpip.ErrDuplicateAddress: return ErrDuplicateAddress - case *tcpip.ErrNoRoute: - return ErrNoRoute + case *tcpip.ErrHostUnreachable: + return ErrHostUnreachable case *tcpip.ErrAlreadyBound: return ErrAlreadyBound case *tcpip.ErrInvalidEndpointState: diff --git a/pkg/syserr/syserr.go b/pkg/syserr/syserr.go index ca50f1239..3657f5c35 100644 --- a/pkg/syserr/syserr.go +++ b/pkg/syserr/syserr.go @@ -210,7 +210,7 @@ var ( ErrTimedOut = newWithHost("connection timed out", errno.ETIMEDOUT, unix.ETIMEDOUT) ErrConnectionRefused = newWithHost("connection refused", errno.ECONNREFUSED, unix.ECONNREFUSED) ErrHostDown = newWithHost("host is down", errno.EHOSTDOWN, unix.EHOSTDOWN) - ErrNoRoute = newWithHost("no route to host", errno.EHOSTUNREACH, unix.EHOSTUNREACH) + ErrHostUnreachable = newWithHost("no route to host", errno.EHOSTUNREACH, unix.EHOSTUNREACH) ErrAlreadyInProgress = newWithHost("operation already in progress", errno.EALREADY, unix.EALREADY) ErrInProgress = newWithHost("operation now in progress", errno.EINPROGRESS, unix.EINPROGRESS) ErrStaleFileHandle = newWithHost("stale file handle", errno.ESTALE, unix.ESTALE) diff --git a/pkg/tcpip/adapters/gonet/gonet_test.go b/pkg/tcpip/adapters/gonet/gonet_test.go index e48bea4f9..ea2297117 100644 --- a/pkg/tcpip/adapters/gonet/gonet_test.go +++ b/pkg/tcpip/adapters/gonet/gonet_test.go @@ -737,11 +737,11 @@ func TestTCPDialError(t *testing.T) { switch _, err := DialTCP(s, addr, ipv4.ProtocolNumber); err := err.(type) { case *net.OpError: - if err.Err.Error() != (&tcpip.ErrNoRoute{}).String() { - t.Errorf("got DialTCP() = %s, want = %s", err, &tcpip.ErrNoRoute{}) + if err.Err.Error() != (&tcpip.ErrHostUnreachable{}).String() { + t.Errorf("got DialTCP() = %s, want = %s", err, &tcpip.ErrHostUnreachable{}) } default: - t.Errorf("got DialTCP(...) = %v, want %s", err, &tcpip.ErrNoRoute{}) + t.Errorf("got DialTCP(...) = %v, want %s", err, &tcpip.ErrHostUnreachable{}) } } diff --git a/pkg/tcpip/errors.go b/pkg/tcpip/errors.go index 2eb822822..ff0a7be4f 100644 --- a/pkg/tcpip/errors.go +++ b/pkg/tcpip/errors.go @@ -380,19 +380,19 @@ func (*ErrNoPortAvailable) IgnoreStats() bool { } func (*ErrNoPortAvailable) String() string { return "no ports are available" } -// ErrNoRoute indicates the operation is not able to find a route to the -// destination. +// ErrHostUnreachable indicates that a destination host could not be +// reached. // // +stateify savable -type ErrNoRoute struct{} +type ErrHostUnreachable struct{} -func (*ErrNoRoute) isError() {} +func (*ErrHostUnreachable) isError() {} // IgnoreStats implements Error. -func (*ErrNoRoute) IgnoreStats() bool { +func (*ErrHostUnreachable) IgnoreStats() bool { return false } -func (*ErrNoRoute) String() string { return "no route" } +func (*ErrHostUnreachable) String() string { return "no route to host" } // ErrNoSuchFile is used to indicate that ENOENT should be returned the to // calling application. diff --git a/pkg/tcpip/link/muxed/injectable.go b/pkg/tcpip/link/muxed/injectable.go index 0a6981ebb..5c421d0b5 100644 --- a/pkg/tcpip/link/muxed/injectable.go +++ b/pkg/tcpip/link/muxed/injectable.go @@ -93,7 +93,7 @@ func (m *InjectableEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcp for _, pkt := range pkts.AsSlice() { endpoint, ok := m.routes[pkt.EgressRoute.RemoteAddress] if !ok { - return i, &tcpip.ErrNoRoute{} + return i, &tcpip.ErrHostUnreachable{} } var tmpPkts stack.PacketBufferList @@ -115,7 +115,7 @@ func (m *InjectableEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcp func (m *InjectableEndpoint) InjectOutbound(dest tcpip.Address, packet *bufferv2.View) tcpip.Error { endpoint, ok := m.routes[dest] if !ok { - return &tcpip.ErrNoRoute{} + return &tcpip.ErrHostUnreachable{} } return endpoint.InjectOutbound(dest, packet) } diff --git a/pkg/tcpip/link/rawfile/errors.go b/pkg/tcpip/link/rawfile/errors.go index 7e21a78d4..e21b4bf28 100644 --- a/pkg/tcpip/link/rawfile/errors.go +++ b/pkg/tcpip/link/rawfile/errors.go @@ -34,7 +34,7 @@ func TranslateErrno(e unix.Errno) tcpip.Error { case unix.EEXIST: return &tcpip.ErrDuplicateAddress{} case unix.ENETUNREACH: - return &tcpip.ErrNoRoute{} + return &tcpip.ErrHostUnreachable{} case unix.EINVAL: return &tcpip.ErrInvalidEndpointState{} case unix.EALREADY: diff --git a/pkg/tcpip/network/internal/ip/errors.go b/pkg/tcpip/network/internal/ip/errors.go index 62f111750..5ff59fd59 100644 --- a/pkg/tcpip/network/internal/ip/errors.go +++ b/pkg/tcpip/network/internal/ip/errors.go @@ -58,12 +58,12 @@ func (*ErrLinkLocalDestinationAddress) isForwardingError() {} func (*ErrLinkLocalDestinationAddress) String() string { return "link local destination address" } -// ErrNoRoute indicates that a route for the received packet couldn't be found. -type ErrNoRoute struct{} +// ErrHostUnreachable indicates that the destinatino host could not be reached. +type ErrHostUnreachable struct{} -func (*ErrNoRoute) isForwardingError() {} +func (*ErrHostUnreachable) isForwardingError() {} -func (*ErrNoRoute) String() string { return "no route" } +func (*ErrHostUnreachable) String() string { return "no route to host" } // ErrMessageTooLong indicates the packet was too big for the outgoing MTU. // diff --git a/pkg/tcpip/network/ipv4/ipv4.go b/pkg/tcpip/network/ipv4/ipv4.go index c9c77fe26..447f44414 100644 --- a/pkg/tcpip/network/ipv4/ipv4.go +++ b/pkg/tcpip/network/ipv4/ipv4.go @@ -744,12 +744,14 @@ func (e *endpoint) forwardUnicastPacket(pkt stack.PacketBufferPtr) ip.Forwarding r, err := stk.FindRoute(0, "", dstAddr, ProtocolNumber, false /* multicastLoop */) switch err.(type) { case nil: - case *tcpip.ErrNoRoute, *tcpip.ErrNetworkUnreachable: + // TODO(https://gvisor.dev/issues/8105): We should not observe ErrHostUnreachable from route + // lookups. + case *tcpip.ErrHostUnreachable, *tcpip.ErrNetworkUnreachable: // We return the original error rather than the result of returning // the ICMP packet because the original error is more relevant to // the caller. _ = e.protocol.returnError(&icmpReasonNetworkUnreachable{}, pkt, false /* deliveredLocally */) - return &ip.ErrNoRoute{} + return &ip.ErrHostUnreachable{} default: return &ip.ErrOther{Err: err} } @@ -918,7 +920,7 @@ func (e *endpoint) forwardMulticastPacket(h header.IPv4, pkt stack.PacketBufferP default: panic(fmt.Sprintf("unexpected GetRouteResultState: %s", result.GetRouteResultState)) } - return &ip.ErrNoRoute{} + return &ip.ErrHostUnreachable{} } func (e *endpoint) updateOptionsForForwarding(pkt stack.PacketBufferPtr) ip.ForwardingError { @@ -1009,7 +1011,7 @@ func (e *endpoint) forwardMulticastPacketForOutgoingInterface(pkt stack.PacketBu if route == nil { // Failed to convert to a stack.Route. This likely means that the outgoing // endpoint no longer exists. - return &ip.ErrNoRoute{} + return &ip.ErrHostUnreachable{} } defer route.Release() @@ -1105,7 +1107,7 @@ func (e *endpoint) handleForwardingError(err ip.ForwardingError) { stats.Forwarding.LinkLocalDestination.Increment() case *ip.ErrTTLExceeded: stats.Forwarding.ExhaustedTTL.Increment() - case *ip.ErrNoRoute: + case *ip.ErrHostUnreachable: stats.Forwarding.Unrouteable.Increment() case *ip.ErrParameterProblem: stats.MalformedPacketsReceived.Increment() @@ -1583,7 +1585,7 @@ func (p *protocol) RemoveMulticastRoute(addresses stack.UnicastSourceAndMulticas } if removed := p.multicastRouteTable.RemoveInstalledRoute(addresses); !removed { - return &tcpip.ErrNoRoute{} + return &tcpip.ErrHostUnreachable{} } return nil @@ -1627,7 +1629,7 @@ func (p *protocol) MulticastRouteLastUsedTime(addresses stack.UnicastSourceAndMu timestamp, found := p.multicastRouteTable.GetLastUsedTimestamp(addresses) if !found { - return tcpip.MonotonicTime{}, &tcpip.ErrNoRoute{} + return tcpip.MonotonicTime{}, &tcpip.ErrHostUnreachable{} } return timestamp, nil diff --git a/pkg/tcpip/network/ipv4/ipv4_test.go b/pkg/tcpip/network/ipv4/ipv4_test.go index 5fb4f0677..26183e01a 100644 --- a/pkg/tcpip/network/ipv4/ipv4_test.go +++ b/pkg/tcpip/network/ipv4/ipv4_test.go @@ -118,8 +118,8 @@ func TestExcludeBroadcast(t *testing.T) { // Cannot connect using a broadcast address as the source. { err := ep.Connect(randomAddr) - if _, ok := err.(*tcpip.ErrNoRoute); !ok { - t.Errorf("got ep.Connect(...) = %v, want = %v", err, &tcpip.ErrNoRoute{}) + if _, ok := err.(*tcpip.ErrHostUnreachable); !ok { + t.Errorf("got ep.Connect(...) = %v, want = %v", err, &tcpip.ErrHostUnreachable{}) } } diff --git a/pkg/tcpip/network/ipv6/ipv6.go b/pkg/tcpip/network/ipv6/ipv6.go index 190e28835..943d1e1c1 100644 --- a/pkg/tcpip/network/ipv6/ipv6.go +++ b/pkg/tcpip/network/ipv6/ipv6.go @@ -968,11 +968,13 @@ func (e *endpoint) forwardUnicastPacket(pkt stack.PacketBufferPtr) ip.Forwarding r, err := stk.FindRoute(0, "", dstAddr, ProtocolNumber, false /* multicastLoop */) switch err.(type) { case nil: - case *tcpip.ErrNoRoute, *tcpip.ErrNetworkUnreachable: + // TODO(https://gvisor.dev/issues/8105): We should not observe ErrHostUnreachable from route + // lookups. + case *tcpip.ErrHostUnreachable, *tcpip.ErrNetworkUnreachable: // We return the original error rather than the result of returning the // ICMP packet because the original error is more relevant to the caller. _ = e.protocol.returnError(&icmpReasonNetUnreachable{}, pkt, false /* deliveredLocally */) - return &ip.ErrNoRoute{} + return &ip.ErrHostUnreachable{} default: return &ip.ErrOther{Err: err} } @@ -1151,7 +1153,7 @@ func (e *endpoint) forwardMulticastPacket(h header.IPv6, pkt stack.PacketBufferP default: panic(fmt.Sprintf("unexpected GetRouteResultState: %s", result.GetRouteResultState)) } - return &ip.ErrNoRoute{} + return &ip.ErrHostUnreachable{} } // forwardValidatedMulticastPacket attempts to forward the pkt using the @@ -1211,7 +1213,7 @@ func (e *endpoint) forwardMulticastPacketForOutgoingInterface(pkt stack.PacketBu if route == nil { // Failed to convert to a stack.Route. This likely means that the outgoing // endpoint no longer exists. - return &ip.ErrNoRoute{} + return &ip.ErrHostUnreachable{} } defer route.Release() return e.forwardPacketWithRoute(route, pkt) @@ -1230,7 +1232,7 @@ func (e *endpoint) handleForwardingError(err ip.ForwardingError) { stats.Forwarding.LinkLocalDestination.Increment() case *ip.ErrTTLExceeded: stats.Forwarding.ExhaustedTTL.Increment() - case *ip.ErrNoRoute: + case *ip.ErrHostUnreachable: stats.Forwarding.Unrouteable.Increment() case *ip.ErrParameterProblem: stats.Forwarding.ExtensionHeaderProblem.Increment() @@ -2460,7 +2462,7 @@ func (p *protocol) RemoveMulticastRoute(addresses stack.UnicastSourceAndMulticas } if removed := p.multicastRouteTable.RemoveInstalledRoute(addresses); !removed { - return &tcpip.ErrNoRoute{} + return &tcpip.ErrHostUnreachable{} } return nil @@ -2476,7 +2478,7 @@ func (p *protocol) MulticastRouteLastUsedTime(addresses stack.UnicastSourceAndMu timestamp, found := p.multicastRouteTable.GetLastUsedTimestamp(addresses) if !found { - return tcpip.MonotonicTime{}, &tcpip.ErrNoRoute{} + return tcpip.MonotonicTime{}, &tcpip.ErrHostUnreachable{} } return timestamp, nil diff --git a/pkg/tcpip/stack/ndp_test.go b/pkg/tcpip/stack/ndp_test.go index 82fdb4246..cc06d5649 100644 --- a/pkg/tcpip/stack/ndp_test.go +++ b/pkg/tcpip/stack/ndp_test.go @@ -626,8 +626,8 @@ func TestDADResolve(t *testing.T) { // tentative address. { r, err := s.FindRoute(nicID, "", addr2, header.IPv6ProtocolNumber, false) - if _, ok := err.(*tcpip.ErrNoRoute); !ok { - t.Errorf("got FindRoute(%d, '', %s, %d, false) = (%+v, %v), want = (_, %s)", nicID, addr2, header.IPv6ProtocolNumber, r, err, &tcpip.ErrNoRoute{}) + if _, ok := err.(*tcpip.ErrHostUnreachable); !ok { + t.Errorf("got FindRoute(%d, '', %s, %d, false) = (%+v, %v), want = (_, %s)", nicID, addr2, header.IPv6ProtocolNumber, r, err, &tcpip.ErrHostUnreachable{}) } if r != nil { r.Release() @@ -635,8 +635,8 @@ func TestDADResolve(t *testing.T) { } { r, err := s.FindRoute(nicID, addr1, addr2, header.IPv6ProtocolNumber, false) - if _, ok := err.(*tcpip.ErrNoRoute); !ok { - t.Errorf("got FindRoute(%d, %s, %s, %d, false) = (%+v, %v), want = (_, %s)", nicID, addr1, addr2, header.IPv6ProtocolNumber, r, err, &tcpip.ErrNoRoute{}) + if _, ok := err.(*tcpip.ErrHostUnreachable); !ok { + t.Errorf("got FindRoute(%d, %s, %s, %d, false) = (%+v, %v), want = (_, %s)", nicID, addr1, addr2, header.IPv6ProtocolNumber, r, err, &tcpip.ErrHostUnreachable{}) } if r != nil { r.Release() @@ -3813,8 +3813,8 @@ func TestAutoGenAddrJobDeprecation(t *testing.T) { { err := ep.Connect(dstAddr) - if _, ok := err.(*tcpip.ErrNoRoute); !ok { - t.Errorf("got ep.Connect(%+v) = %s, want = %s", dstAddr, err, &tcpip.ErrNoRoute{}) + if _, ok := err.(*tcpip.ErrHostUnreachable); !ok { + t.Errorf("got ep.Connect(%+v) = %s, want = %s", dstAddr, err, &tcpip.ErrHostUnreachable{}) } } } diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index 5b444a47e..7d2f80883 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -306,7 +306,7 @@ func (t *TransportEndpointInfo) AddrNetProtoLocked(addr tcpip.FullAddress, v6onl case netProto == t.NetProto: case netProto == header.IPv4ProtocolNumber && t.NetProto == header.IPv6ProtocolNumber: if v6only { - return tcpip.FullAddress{}, 0, &tcpip.ErrNoRoute{} + return tcpip.FullAddress{}, 0, &tcpip.ErrHostUnreachable{} } default: return tcpip.FullAddress{}, 0, &tcpip.ErrInvalidEndpointState{} @@ -1384,7 +1384,8 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n } } - return nil, &tcpip.ErrNoRoute{} + // TODO(https://gvisor.dev/issues/8105): This should be ErrNetworkUnreachable. + return nil, &tcpip.ErrHostUnreachable{} } if id == 0 { @@ -1404,11 +1405,13 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n } if needRoute { - return nil, &tcpip.ErrNoRoute{} + // TODO(https://gvisor.dev/issues/8105): This should be ErrNetworkUnreachable. + return nil, &tcpip.ErrHostUnreachable{} } if header.IsV6LoopbackAddress(remoteAddr) { return nil, &tcpip.ErrBadLocalAddress{} } + // TODO(https://gvisor.dev/issues/8105): This should be ErrNetworkUnreachable. return nil, &tcpip.ErrNetworkUnreachable{} } diff --git a/pkg/tcpip/stack/stack_test.go b/pkg/tcpip/stack/stack_test.go index 42dcd8506..2733fb68c 100644 --- a/pkg/tcpip/stack/stack_test.go +++ b/pkg/tcpip/stack/stack_test.go @@ -849,8 +849,8 @@ func testRoute(t *testing.T, s *stack.Stack, nic tcpip.NICID, srcAddr, dstAddr, func testNoRoute(t *testing.T, s *stack.Stack, nic tcpip.NICID, srcAddr, dstAddr tcpip.Address) { _, err := s.FindRoute(nic, srcAddr, dstAddr, fakeNetNumber, false /* multicastLoop */) - if _, ok := err.(*tcpip.ErrNoRoute); !ok { - t.Fatalf("FindRoute returned unexpected error, got = %v, want = %s", err, &tcpip.ErrNoRoute{}) + if _, ok := err.(*tcpip.ErrHostUnreachable); !ok { + t.Fatalf("FindRoute returned unexpected error, got = %v, want = %s", err, &tcpip.ErrHostUnreachable{}) } } @@ -1378,7 +1378,7 @@ func TestAddressRemoval(t *testing.T) { t.Fatal("RemoveAddress failed:", err) } testFailingRecv(t, fakeNet, localAddrByte, ep, buf) - testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{}) + testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrHostUnreachable{}) // Check that removing the same address fails. err := s.RemoveAddress(1, localAddr) @@ -1438,7 +1438,7 @@ func TestAddressRemovalWithRouteHeld(t *testing.T) { } testFailingRecv(t, fakeNet, localAddrByte, ep, buf) testFailingSend(t, r, nil, &tcpip.ErrInvalidEndpointState{}) - testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{}) + testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrHostUnreachable{}) // Check that removing the same address fails. { @@ -1539,7 +1539,7 @@ func TestEndpointExpiration(t *testing.T) { // FIXME(b/139841518):Spoofing doesn't work if there is no primary address. // testSendTo(t, s, remoteAddr, ep, nil) } else { - testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{}) + testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrHostUnreachable{}) } // 2. Add Address, everything should work. @@ -1574,7 +1574,7 @@ func TestEndpointExpiration(t *testing.T) { // FIXME(b/139841518):Spoofing doesn't work if there is no primary address. // testSendTo(t, s, remoteAddr, ep, nil) } else { - testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{}) + testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrHostUnreachable{}) } // 4. Add Address back, everything should work again. @@ -1614,7 +1614,7 @@ func TestEndpointExpiration(t *testing.T) { testSendTo(t, s, remoteAddr, ep, nil) } else { testFailingSend(t, r, nil, &tcpip.ErrInvalidEndpointState{}) - testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{}) + testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrHostUnreachable{}) } // 7. Add Address back, everything should work again. @@ -1650,7 +1650,7 @@ func TestEndpointExpiration(t *testing.T) { // FIXME(b/139841518):Spoofing doesn't work if there is no primary address. // testSendTo(t, s, remoteAddr, ep, nil) } else { - testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrNoRoute{}) + testFailingSendTo(t, s, remoteAddr, nil, &tcpip.ErrHostUnreachable{}) } }) } @@ -1693,8 +1693,8 @@ func TestPromiscuousMode(t *testing.T) { // Check that we can't get a route as there is no local address. _, err := s.FindRoute(0, "", "\x02", fakeNetNumber, false /* multicastLoop */) - if _, ok := err.(*tcpip.ErrNoRoute); !ok { - t.Fatalf("FindRoute returned unexpected error: got = %v, want = %s", err, &tcpip.ErrNoRoute{}) + if _, ok := err.(*tcpip.ErrHostUnreachable); !ok { + t.Fatalf("FindRoute returned unexpected error: got = %v, want = %s", err, &tcpip.ErrHostUnreachable{}) } // Set promiscuous mode to false, then check that packet can't be @@ -1914,7 +1914,7 @@ func TestSpoofingNoAddress(t *testing.T) { t.Errorf("FindRoute succeeded with route %+v when it should have failed", r) } // Sending a packet fails. - testFailingSendTo(t, s, dstAddr, nil, &tcpip.ErrNoRoute{}) + testFailingSendTo(t, s, dstAddr, nil, &tcpip.ErrHostUnreachable{}) // With address spoofing enabled, FindRoute permits any address to be used // as the source. @@ -2123,7 +2123,7 @@ func TestMulticastOrIPv6LinkLocalNeedsNoRoute(t *testing.T) { var want tcpip.Error = &tcpip.ErrNetworkUnreachable{} if tc.routeNeeded { - want = &tcpip.ErrNoRoute{} + want = &tcpip.ErrHostUnreachable{} } // If there is no endpoint, it won't work. @@ -2144,8 +2144,8 @@ func TestMulticastOrIPv6LinkLocalNeedsNoRoute(t *testing.T) { if r, err := s.FindRoute(1, anyAddr, tc.address, fakeNetNumber, false /* multicastLoop */); tc.routeNeeded { // Route table is empty but we need a route, this should cause an error. - if _, ok := err.(*tcpip.ErrNoRoute); !ok { - t.Fatalf("got FindRoute(1, %v, %v, %v) = %v, want = %v", anyAddr, tc.address, fakeNetNumber, err, &tcpip.ErrNoRoute{}) + if _, ok := err.(*tcpip.ErrHostUnreachable); !ok { + t.Fatalf("got FindRoute(1, %v, %v, %v) = %v, want = %v", anyAddr, tc.address, fakeNetNumber, err, &tcpip.ErrHostUnreachable{}) } } else { if err != nil { @@ -4521,7 +4521,7 @@ func TestFindRouteWithForwarding(t *testing.T) { forwardingEnabled: false, addrNIC: nicID1, localAddrWithPrefix: fakeNetCfg.nic2AddrWithPrefix, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4530,7 +4530,7 @@ func TestFindRouteWithForwarding(t *testing.T) { forwardingEnabled: true, addrNIC: nicID1, localAddrWithPrefix: fakeNetCfg.nic2AddrWithPrefix, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4539,7 +4539,7 @@ func TestFindRouteWithForwarding(t *testing.T) { forwardingEnabled: false, addrNIC: nicID1, localAddrWithPrefix: fakeNetCfg.nic1AddrWithPrefix, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4575,7 +4575,7 @@ func TestFindRouteWithForwarding(t *testing.T) { forwardingEnabled: false, addrNIC: nicID2, localAddrWithPrefix: fakeNetCfg.nic1AddrWithPrefix, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4584,7 +4584,7 @@ func TestFindRouteWithForwarding(t *testing.T) { forwardingEnabled: true, addrNIC: nicID2, localAddrWithPrefix: fakeNetCfg.nic1AddrWithPrefix, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4608,7 +4608,7 @@ func TestFindRouteWithForwarding(t *testing.T) { netCfg: fakeNetCfg, forwardingEnabled: false, localAddrWithPrefix: fakeNetCfg.nic1AddrWithPrefix, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4624,7 +4624,7 @@ func TestFindRouteWithForwarding(t *testing.T) { netCfg: ipv6LinkLocalNIC1WithGlobalRemote, forwardingEnabled: false, addrNIC: nicID1, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4632,7 +4632,7 @@ func TestFindRouteWithForwarding(t *testing.T) { netCfg: ipv6LinkLocalNIC1WithGlobalRemote, forwardingEnabled: true, addrNIC: nicID1, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4640,7 +4640,7 @@ func TestFindRouteWithForwarding(t *testing.T) { netCfg: ipv6LinkLocalNIC1WithGlobalRemote, forwardingEnabled: false, localAddrWithPrefix: ipv6LinkLocalNIC1WithGlobalRemote.nic1AddrWithPrefix, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { @@ -4648,7 +4648,7 @@ func TestFindRouteWithForwarding(t *testing.T) { netCfg: ipv6LinkLocalNIC1WithGlobalRemote, forwardingEnabled: true, localAddrWithPrefix: ipv6LinkLocalNIC1WithGlobalRemote.nic1AddrWithPrefix, - findRouteErr: &tcpip.ErrNoRoute{}, + findRouteErr: &tcpip.ErrHostUnreachable{}, dependentOnForwarding: false, }, { diff --git a/pkg/tcpip/stack/transport_test.go b/pkg/tcpip/stack/transport_test.go index 61796c718..46f63ad8b 100644 --- a/pkg/tcpip/stack/transport_test.go +++ b/pkg/tcpip/stack/transport_test.go @@ -95,7 +95,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 { - return 0, &tcpip.ErrNoRoute{} + return 0, &tcpip.ErrHostUnreachable{} } v := make([]byte, p.Len()) @@ -146,7 +146,7 @@ func (f *fakeTransportEndpoint) Connect(addr tcpip.FullAddress) tcpip.Error { // Find the route. r, err := f.proto.stack.FindRoute(addr.NIC, "", addr.Addr, fakeNetNumber, false /* multicastLoop */) if err != nil { - return &tcpip.ErrNoRoute{} + return &tcpip.ErrHostUnreachable{} } // Try to register so that we can start receiving packets. diff --git a/pkg/tcpip/tests/integration/link_resolution_test.go b/pkg/tcpip/tests/integration/link_resolution_test.go index 7b2663c59..a0c6ae5e5 100644 --- a/pkg/tcpip/tests/integration/link_resolution_test.go +++ b/pkg/tcpip/tests/integration/link_resolution_test.go @@ -246,9 +246,9 @@ func TestTCPLinkResolutionFailure(t *testing.T) { name: "IPv4 without resolvable remote", netProto: ipv4.ProtocolNumber, remoteAddr: utils.Ipv4Addr3.AddressWithPrefix.Address, - expectedWriteErr: &tcpip.ErrNoRoute{}, + expectedWriteErr: &tcpip.ErrHostUnreachable{}, sockError: tcpip.SockError{ - Err: &tcpip.ErrNoRoute{}, + Err: &tcpip.ErrHostUnreachable{}, Dst: tcpip.FullAddress{ NIC: host1NICID, Addr: utils.Ipv4Addr3.AddressWithPrefix.Address, @@ -271,9 +271,9 @@ func TestTCPLinkResolutionFailure(t *testing.T) { name: "IPv6 without resolvable remote", netProto: ipv6.ProtocolNumber, remoteAddr: utils.Ipv6Addr3.AddressWithPrefix.Address, - expectedWriteErr: &tcpip.ErrNoRoute{}, + expectedWriteErr: &tcpip.ErrHostUnreachable{}, sockError: tcpip.SockError{ - Err: &tcpip.ErrNoRoute{}, + Err: &tcpip.ErrHostUnreachable{}, Dst: tcpip.FullAddress{ NIC: host1NICID, Addr: utils.Ipv6Addr3.AddressWithPrefix.Address, diff --git a/pkg/tcpip/tests/integration/multicast_forward_test.go b/pkg/tcpip/tests/integration/multicast_forward_test.go index 7662ec181..892823fe4 100644 --- a/pkg/tcpip/tests/integration/multicast_forward_test.go +++ b/pkg/tcpip/tests/integration/multicast_forward_test.go @@ -587,7 +587,7 @@ func TestMulticastRouteLastUsedTime(t *testing.T) { name: "no matching route", srcAddr: remoteUnicastAddr, dstAddr: otherMulticastAddr, - wantErr: &tcpip.ErrNoRoute{}, + wantErr: &tcpip.ErrHostUnreachable{}, }, { name: "multicast source", @@ -745,7 +745,7 @@ func TestRemoveMulticastRoute(t *testing.T) { name: "no matching route", srcAddr: remoteUnicastAddr, dstAddr: otherMulticastAddr, - wantErr: &tcpip.ErrNoRoute{}, + wantErr: &tcpip.ErrHostUnreachable{}, }, { name: "multicast source", diff --git a/pkg/tcpip/tests/integration/route_test.go b/pkg/tcpip/tests/integration/route_test.go index 97796eb75..db5f447df 100644 --- a/pkg/tcpip/tests/integration/route_test.go +++ b/pkg/tcpip/tests/integration/route_test.go @@ -131,7 +131,7 @@ func TestLocalPing(t *testing.T) { netProto: ipv4.ProtocolNumber, linkEndpoint: loopback.New, icmpBuf: ipv4ICMPBuf, - expectedConnectErr: &tcpip.ErrNoRoute{}, + expectedConnectErr: &tcpip.ErrHostUnreachable{}, checkLinkEndpoint: func(*testing.T, stack.LinkEndpoint) {}, }, { @@ -140,7 +140,7 @@ func TestLocalPing(t *testing.T) { netProto: ipv6.ProtocolNumber, linkEndpoint: loopback.New, icmpBuf: ipv6ICMPBuf, - expectedConnectErr: &tcpip.ErrNoRoute{}, + expectedConnectErr: &tcpip.ErrHostUnreachable{}, checkLinkEndpoint: func(*testing.T, stack.LinkEndpoint) {}, }, { @@ -149,7 +149,7 @@ func TestLocalPing(t *testing.T) { netProto: ipv4.ProtocolNumber, linkEndpoint: channelEP, icmpBuf: ipv4ICMPBuf, - expectedConnectErr: &tcpip.ErrNoRoute{}, + expectedConnectErr: &tcpip.ErrHostUnreachable{}, checkLinkEndpoint: channelEPCheck, }, { @@ -158,7 +158,7 @@ func TestLocalPing(t *testing.T) { netProto: ipv6.ProtocolNumber, linkEndpoint: channelEP, icmpBuf: ipv6ICMPBuf, - expectedConnectErr: &tcpip.ErrNoRoute{}, + expectedConnectErr: &tcpip.ErrHostUnreachable{}, checkLinkEndpoint: channelEPCheck, }, } @@ -281,7 +281,7 @@ func TestLocalUDP(t *testing.T) { { name: "Unassigned local address", addAddress: false, - expectedWriteErr: &tcpip.ErrNoRoute{}, + expectedWriteErr: &tcpip.ErrHostUnreachable{}, }, { name: "Assigned local address", diff --git a/pkg/tcpip/transport/datagram_test.go b/pkg/tcpip/transport/datagram_test.go index 135867369..2d280a6da 100644 --- a/pkg/tcpip/transport/datagram_test.go +++ b/pkg/tcpip/transport/datagram_test.go @@ -740,7 +740,7 @@ func TestIPv6PacketInfo(t *testing.T) { pktInfo: tcpip.IPv6PacketInfo{ NIC: nicID1, }, - expectedErr: &tcpip.ErrNoRoute{}, + expectedErr: &tcpip.ErrHostUnreachable{}, }, { name: "Bind wildcard and NIC & SendTo with packet info NIC matching", @@ -773,7 +773,7 @@ func TestIPv6PacketInfo(t *testing.T) { pktInfo: tcpip.IPv6PacketInfo{ NIC: nicID1, }, - expectedErr: &tcpip.ErrNoRoute{}, + expectedErr: &tcpip.ErrHostUnreachable{}, }, { name: "Bind specified & SendTo with packet info NIC not matching bound addr", @@ -857,7 +857,7 @@ func TestIPv6PacketInfo(t *testing.T) { pktInfo: tcpip.IPv6PacketInfo{ NIC: nicID1, }, - expectedErr: &tcpip.ErrNoRoute{}, + expectedErr: &tcpip.ErrHostUnreachable{}, }, { name: "Bind wildcard & Connect with NIC then Send with packet info NIC matching", @@ -890,7 +890,7 @@ func TestIPv6PacketInfo(t *testing.T) { pktInfo: tcpip.IPv6PacketInfo{ NIC: nicID1, }, - expectedErr: &tcpip.ErrNoRoute{}, + expectedErr: &tcpip.ErrHostUnreachable{}, }, { name: "Bind specified & Connect then Send with packet info NIC not matching but local addr specified", @@ -907,7 +907,7 @@ func TestIPv6PacketInfo(t *testing.T) { NIC: nicID1, Addr: ipv6Addr1, }, - expectedErr: &tcpip.ErrNoRoute{}, + expectedErr: &tcpip.ErrHostUnreachable{}, }, // Connect @@ -950,7 +950,7 @@ func TestIPv6PacketInfo(t *testing.T) { pktInfo: tcpip.IPv6PacketInfo{ NIC: nicID1, }, - expectedErr: &tcpip.ErrNoRoute{}, + expectedErr: &tcpip.ErrHostUnreachable{}, }, { name: "Connect then Send with packet info NIC not matching", @@ -962,7 +962,7 @@ func TestIPv6PacketInfo(t *testing.T) { pktInfo: tcpip.IPv6PacketInfo{ NIC: nicID1, }, - expectedErr: &tcpip.ErrNoRoute{}, + expectedErr: &tcpip.ErrHostUnreachable{}, }, // Connect and SendTo diff --git a/pkg/tcpip/transport/icmp/endpoint.go b/pkg/tcpip/transport/icmp/endpoint.go index 9a348b084..8c737d51f 100644 --- a/pkg/tcpip/transport/icmp/endpoint.go +++ b/pkg/tcpip/transport/icmp/endpoint.go @@ -300,7 +300,7 @@ func (e *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp e.stats.WriteErrors.WriteClosed.Increment() case *tcpip.ErrInvalidEndpointState: e.stats.WriteErrors.InvalidEndpointState.Increment() - case *tcpip.ErrNoRoute, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable: + case *tcpip.ErrHostUnreachable, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable: // Errors indicating any problem with IP routing of the packet. e.stats.SendErrors.NoRoute.Increment() default: diff --git a/pkg/tcpip/transport/internal/network/endpoint.go b/pkg/tcpip/transport/internal/network/endpoint.go index 1a5fbc6a6..2f6acc781 100644 --- a/pkg/tcpip/transport/internal/network/endpoint.go +++ b/pkg/tcpip/transport/internal/network/endpoint.go @@ -447,7 +447,7 @@ func (e *Endpoint) AcquireContextForWrite(opts tcpip.WriteOptions) (WriteContext // interface (usually when using link-local addresses), make sure the // interface matches the specified local interface. if nicID != 0 && nicID != pktInfoNICID { - return WriteContext{}, &tcpip.ErrNoRoute{} + return WriteContext{}, &tcpip.ErrHostUnreachable{} } // If a local address is not specified, then we need to make sure the @@ -459,7 +459,7 @@ func (e *Endpoint) AcquireContextForWrite(opts tcpip.WriteOptions) (WriteContext // // The bound interface is usually only set for link-local addresses. if info.BindNICID != 0 && info.BindNICID != pktInfoNICID { - return WriteContext{}, &tcpip.ErrNoRoute{} + return WriteContext{}, &tcpip.ErrHostUnreachable{} } if len(info.ID.LocalAddress) != 0 && e.stack.CheckLocalAddress(pktInfoNICID, header.IPv6ProtocolNumber, info.ID.LocalAddress) == 0 { return WriteContext{}, &tcpip.ErrBadLocalAddress{} @@ -483,7 +483,7 @@ func (e *Endpoint) AcquireContextForWrite(opts tcpip.WriteOptions) (WriteContext } else { if info.BindNICID != 0 { if nicID != 0 && nicID != info.BindNICID { - return WriteContext{}, &tcpip.ErrNoRoute{} + return WriteContext{}, &tcpip.ErrHostUnreachable{} } nicID = info.BindNICID diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index c9ea3621d..64b588403 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -327,7 +327,7 @@ func (e *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp e.stats.WriteErrors.WriteClosed.Increment() case *tcpip.ErrInvalidEndpointState: e.stats.WriteErrors.InvalidEndpointState.Increment() - case *tcpip.ErrNoRoute, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable: + case *tcpip.ErrHostUnreachable, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable: // Errors indicating any problem with IP routing of the packet. e.stats.SendErrors.NoRoute.Increment() default: diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index a4efb2486..613c6c43e 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -2385,7 +2385,7 @@ func (e *endpoint) connect(addr tcpip.FullAddress, handshake bool) tcpip.Error { } if nicID != 0 && nicID != e.boundNICID { - return &tcpip.ErrNoRoute{} + return &tcpip.ErrHostUnreachable{} } nicID = e.boundNICID @@ -2906,7 +2906,7 @@ func (e *endpoint) HandleError(transErr stack.TransportError, pkt stack.PacketBu case stack.PacketTooBigTransportError: handlePacketTooBig(transErr.Info()) case stack.DestinationHostUnreachableTransportError: - e.onICMPError(&tcpip.ErrNoRoute{}, transErr, pkt) + e.onICMPError(&tcpip.ErrHostUnreachable{}, transErr, pkt) case stack.DestinationNetworkUnreachableTransportError: e.onICMPError(&tcpip.ErrNetworkUnreachable{}, transErr, pkt) } diff --git a/pkg/tcpip/transport/tcp/test/e2e/dual_stack_test.go b/pkg/tcpip/transport/tcp/test/e2e/dual_stack_test.go index b2e618a21..c93d49f45 100644 --- a/pkg/tcpip/transport/tcp/test/e2e/dual_stack_test.go +++ b/pkg/tcpip/transport/tcp/test/e2e/dual_stack_test.go @@ -42,7 +42,7 @@ func TestV4MappedConnectOnV6Only(t *testing.T) { // Start connection attempt, it must fail. err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestV4MappedAddr, Port: context.TestPort}) - if d := cmp.Diff(&tcpip.ErrNoRoute{}, err); d != "" { + if d := cmp.Diff(&tcpip.ErrHostUnreachable{}, err); d != "" { t.Fatalf("c.EP.Connect(...) mismatch (-want +got):\n%s", d) } } diff --git a/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go b/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go index 3cdcda86c..b5b06a741 100644 --- a/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go +++ b/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go @@ -188,7 +188,7 @@ func TestConnectICMPError(t *testing.T) { for { if err := wep.LastErrorLocked(); err != nil { - if d := cmp.Diff(&tcpip.ErrNoRoute{}, err); d != "" { + if d := cmp.Diff(&tcpip.ErrHostUnreachable{}, err); d != "" { t.Errorf("ep.LastErrorLocked() mismatch (-want +got):\n%s", d) } break @@ -261,7 +261,7 @@ func TestActiveFailedConnectionAttemptIncrement(t *testing.T) { { err := c.EP.Connect(tcpip.FullAddress{NIC: 2, Addr: context.TestAddr, Port: context.TestPort}) - if d := cmp.Diff(&tcpip.ErrNoRoute{}, err); d != "" { + if d := cmp.Diff(&tcpip.ErrHostUnreachable{}, err); d != "" { t.Errorf("c.EP.Connect(...) mismatch (-want +got):\n%s", d) } } diff --git a/pkg/tcpip/transport/testing/context/context.go b/pkg/tcpip/transport/testing/context/context.go index ee18b4619..708398279 100644 --- a/pkg/tcpip/transport/testing/context/context.go +++ b/pkg/tcpip/transport/testing/context/context.go @@ -221,7 +221,7 @@ func (c *Context) CheckEndpointWriteStats(incr uint64, want *tcpip.TransportEndp want.WriteErrors.WriteClosed.IncrementBy(incr) case *tcpip.ErrInvalidEndpointState: want.WriteErrors.InvalidEndpointState.IncrementBy(incr) - case *tcpip.ErrNoRoute, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable: + case *tcpip.ErrHostUnreachable, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable: want.SendErrors.NoRoute.IncrementBy(incr) default: want.SendErrors.SendToNetworkFailed.IncrementBy(incr) diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index 78783f582..ff75c5def 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -370,7 +370,7 @@ func (e *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp e.stats.WriteErrors.WriteClosed.Increment() case *tcpip.ErrInvalidEndpointState: e.stats.WriteErrors.InvalidEndpointState.Increment() - case *tcpip.ErrNoRoute, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable: + case *tcpip.ErrHostUnreachable, *tcpip.ErrBroadcastDisabled, *tcpip.ErrNetworkUnreachable: // Errors indicating any problem with IP routing of the packet. e.stats.SendErrors.NoRoute.Increment() default: diff --git a/pkg/tcpip/transport/udp/udp_test.go b/pkg/tcpip/transport/udp/udp_test.go index 53f486fcd..d92a3cfee 100644 --- a/pkg/tcpip/transport/udp/udp_test.go +++ b/pkg/tcpip/transport/udp/udp_test.go @@ -754,7 +754,7 @@ func TestV4WriteOnV6Only(t *testing.T) { c.CreateEndpointForFlow(context.UnicastV6Only, udp.ProtocolNumber) // Write to V4 mapped address. - testWriteOpSequenceFails(c, context.UnicastV4in6, writeOpSequence, &tcpip.ErrNoRoute{}) + testWriteOpSequenceFails(c, context.UnicastV4in6, writeOpSequence, &tcpip.ErrHostUnreachable{}) } }