Repository navigation
netlink: Dump routes in Linux FIB order and honor the dump family - #16765
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
force-pushed
the
test/cl1010782127
branch
8 times, most recently
from
November 3, 2026 01:11
53db750 to
34a0f56
Compare
## Summary
RTM_GETROUTE dumps differ from Linux in two ways:
1. **Order.** Netstack returns routes in its lookup order, longest prefix first. Linux dumps IPv4 routes by ascending destination, with longer prefixes first for the same destination (`fib_table_dump()`). IPv6 routes follow, in fib6 post-order (`fib6_walk_continue()`). So the default route comes first on Linux and last under gVisor. `/proc/net/route` has the same order problem.
2. **Family.** The family in the request is ignored, so an AF_INET6 dump also returns IPv4 routes, and the other way round. RTM_GETADDR dumps have the same problem.
Scripts often take the first line of `ip route`. We found this with a container health check that runs `ip route show default dev eth0 | awk '{print $3; exit}'`. With iproute2 4.11, the first line under gVisor was `fe80::/64 proto unspec scope link`, so the script used `unspec` as the gateway. Fixing only the family is not enough here, because the first line then becomes the subnet route.
This PR sorts netstack's route table in Linux dump order and filters AF_INET and AF_INET6 route and address dumps by family. It also sets RTF_HOST for /32 routes in `/proc/net/route`, as `fib_flag_trans()` does.
## Reproduction
This uses only the `busybox` image on Docker's default bridge network.
```
docker run --rm --runtime=runsc busybox:1.36.1 sh -c 'ip route; echo ---; ip -6 route'
```
busybox `ip -6 route` sends an AF_INET6 dump and prints every route it gets back.
Linux (runc):
```
default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0 scope link src 172.17.0.2
---
```
runsc before this PR:
```
172.17.0.0/16 dev eth0 scope link
127.0.0.0/8 dev lo scope link
default via 172.17.0.1 dev eth0 scope link
---
172.17.0.0/16 dev eth0 scope link
127.0.0.0/8 dev lo scope link
default via 172.17.0.1 dev eth0 scope link
```
The default route is last, and `ip -6 route` lists the IPv4 routes.
runsc with this PR:
```
default via 172.17.0.1 dev eth0 scope link
127.0.0.0/8 dev lo scope link
172.17.0.0/16 dev eth0 scope link
---
```
The remaining differences in `ip` output (127.0.0.0/8 in the main table, `scope link` on the default route, no `src`) already exist and are unrelated to this PR.
## Testing
- New unit tests: `TestRouteTableDumpOrder` and `TestDumpFamily`.
- New syscall tests: `NetlinkRouteIpInvariantTest.DumpFiltersFamily` and `NetlinkRouteIpInvariantTest.GetRouteDumpOrder`. They pass on Linux, on runsc, and on runsc with `--network=host`, and fail on runsc without this change.
FUTURE_COPYBARA_INTEGRATE_REVIEW=#16090 from cedriccchen:upstream-fix-netlink-route-dump-order 5f6df96
PiperOrigin-RevId: 1010782127
copybara-service
Bot
force-pushed
the
test/cl1010782127
branch
from
November 3, 2026 02:11
34a0f56 to
c97471b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
netlink: Dump routes in Linux FIB order and honor the dump family
Summary
RTM_GETROUTE dumps differ from Linux in two ways:
Order. Netstack returns routes in its lookup order, longest prefix first. Linux dumps IPv4 routes by ascending destination, with longer prefixes first for the same destination (
fib_table_dump()). IPv6 routes follow, in fib6 post-order (fib6_walk_continue()). So the default route comes first on Linux and last under gVisor./proc/net/routehas the same order problem.Family. The family in the request is ignored, so an AF_INET6 dump also returns IPv4 routes, and the other way round. RTM_GETADDR dumps have the same problem.
Scripts often take the first line of
ip route. We found this with a container health check that runsip route show default dev eth0 | awk '{print $3; exit}'. With iproute2 4.11, the first line under gVisor wasfe80::/64 proto unspec scope link, so the script usedunspecas the gateway. Fixing only the family is not enough here, because the first line then becomes the subnet route.This PR sorts netstack's route table in Linux dump order and filters AF_INET and AF_INET6 route and address dumps by family. It also sets RTF_HOST for /32 routes in
/proc/net/route, asfib_flag_trans()does.Reproduction
This uses only the
busyboximage on Docker's default bridge network.busybox
ip -6 routesends an AF_INET6 dump and prints every route it gets back.Linux (runc):
runsc before this PR:
The default route is last, and
ip -6 routelists the IPv4 routes.runsc with this PR:
The remaining differences in
ipoutput (127.0.0.0/8 in the main table,scope linkon the default route, nosrc) already exist and are unrelated to this PR.Testing
TestRouteTableDumpOrderandTestDumpFamily.NetlinkRouteIpInvariantTest.DumpFiltersFamilyandNetlinkRouteIpInvariantTest.GetRouteDumpOrder. They pass on Linux, on runsc, and on runsc with--network=host, and fail on runsc without this change.FUTURE_COPYBARA_INTEGRATE_REVIEW=#16090 from cedriccchen:upstream-fix-netlink-route-dump-order 5f6df96