Maddy
Maddy

Reputation: 1389

IPv6 route lookup order

bash-3.00# /usr/sbin/ip -6 route show
default via fdc6:3001:8e20:9ce9::1 dev int0  metric 1024  expires 2133437sec mtu 1500 advmss 1440 metric10 4294967295
unreachable default dev lo  proto none  metric -1  error -101 metric10 255
unreachable default dev lo  proto none  metric -1  error -101 metric10 255
unreachable default dev lo  proto none  metric -1  error -101 metric10 255
fdc6:3001:8e20:b06::/64 dev ext0  metric 256  expires 2132985sec mtu 1500 advmss 1440 metric10 4294967295
fdc6:3001:8e20:9ce9::/64 dev int0  metric 256  expires 2132977sec mtu 1500 advmss 1440 metric10 4294967295
fe80::/64 dev int0  metric 256  expires 2132977sec mtu 1500 advmss 1440 metric10 4294967295
fe80::/64 dev ext0  metric 256  expires 2132985sec mtu 1500 advmss 1440 metric10 4294967295
default via fe80::226:88ff:fee2:5d01 dev int0  proto kernel  metric 1024  expires 154sec mtu 1500 advmss 1440 metric10 64
default via fe80::226:88ff:fee2:5d02 dev ext0  proto kernel  metric 1024  expires 175sec mtu 1500 advmss 1440 metric10 64
default via fdc6:3001:8e20:b06::1 dev ext0  metric 1024  expires 2133059sec mtu 1500 advmss 1440 metric10 4294967295
unreachable default dev lo  proto none  metric -1  error -101 metric10 255
ff00::/8 dev int0  metric 256  expires 2132977sec mtu 1500 advmss 1440 metric10 4294967295
ff00::/8 dev ext0  metric 256  expires 2132985sec mtu 1500 advmss 1440 metric10 4294967295
unreachable default dev lo  proto none  metric -1  error -101 metric10 255

In the output above, does the ordering of the routes indicate the order in which the routes are looked-up? Or does the 'hoplimit' (the last column) influence the ordering of the lookup? What's the difference between 'hoplimit' and 'metric', and which of the two influence the lookup order?

Upvotes: 0

Views: 3309

Answers (3)

Matthias Urlichs
Matthias Urlichs

Reputation: 2544

You're seeing the effects of a Redirect ICMP message.

Say ip -6 route flush cache to make your routing work again.

Say sysctl -w net.ipv6.conf.all.accept_redirects=0 to ignore future redirects.

The most likely cause for this is a gateway with incomplete routes at startup/restart. You might want to tell that system not to send redirect packets.

Upvotes: 0

Kristof Provost
Kristof Provost

Reputation: 26332

The route lookup for IPv6 is not fundamentally different from legacy IPv4.

The IP stack will find the route which best matches (i.e. longest prefix) the target IP and has the lowest metric.

The hop limit does not influence the routing decision. The metric indicates the 'cost' of the route. It's supposed to be set based on the number of hops to the destination and the bandwidth, latency, price, ... of the route. The hop limit is merely used to pre-set the hop limit field in the IPv6 header.

Upvotes: 0

Celada
Celada

Reputation: 22261

  1. Routes are first looked up by longest match. So if there is a /64 route, a /48 route, and a default route (which is /0) which all match the destination of the packet, the /64 route will be used and the others will be ignored.

    Example: given a destination of fdc6:3001:8e20:9ce9:1:2:3:4 and the following routes:

    default via fdc6:3001:8e20:9ce9::1 dev int0  metric 1024  expires 2133437sec mtu 1500 advmss 1440 metric10 4294967295
    fdc6:3001:8e20:9ce9::/64 dev int0  metric 256  expires 2132977sec mtu 1500 advmss 1440 metric10 4294967295
    

    The /64 route will always be chosen.

    This is notwithstanding your comment that implies otherwise. What you describe in your comment shouldn't happen. Please provide the exact source and destination IP addresses and source and destination MAC addresses of the problematic packet to diagnose this further.

  2. In case there are multiple routes to the destination with the same prefix length, the one(s) with the best metric is preferred.

    You don't have any examples in your routing table where ties are broken by metric. You'd need routes with the same destination and prefix length but different metrics.

  3. If there are still multiple routes, load balancing over each of the available paths takes place.

The hoplimit is not used at all in the route lookup process. It is used to set the hop limit of locally originated outgoing packets after the choice of route has been made.

Upvotes: 3

Related Questions