Repository navigation
netstack: remove only the first matching route on RTM_DELROUTE - #15301
Merged
Merged
Conversation
milantracy
requested changes
Oct 5, 2026
milantracy
left a comment
Member
There was a problem hiding this comment.
please add test at test/syscalls/linux/socket_netlink_route.cc and test/rtnetlink/linux/route_test.sh
please also let others know that you are interested working on an issue via commenting on the issue etc, otherwise, there might be some conflicts
Contributor
Author
|
Added the tests in 178e872.
Both tests fail without the |
milantracy
requested changes
Oct 5, 2026
milantracy
left a comment
Member
There was a problem hiding this comment.
please squash 2 commits into 1
adi-IL
force-pushed
the
bot/gvisor-15295
branch
from
October 5, 2026 23:33
178e872 to
7577af3
Compare
Contributor
Author
milantracy
approved these changes
Oct 6, 2026
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 6, 2026
Fixes #15295 `netstack.Stack.RemoveRoute` passes a match function to `tcpip.Stack.RemoveRoutes`, which removes every route that matches. One RTM_DELROUTE request can therefore delete several routes. Linux deletes only the first matching route per request and returns ESRCH when nothing matches. This change adds a `found` flag to the match function in `RemoveRoute`. After the first match, the function returns false for every later route. `tcpip.Stack.RemoveRoutes` does not change. The first match is the oldest matching route in the route table. Linux sorts routes with the same prefix by metric, so its first match is the route with the lowest metric. gVisor cannot do that yet. `tcpip.Route` has no metric field and `localRoute` ignores RTA_PRIORITY. Metric ordering is out of scope for this PR. Testing: - New `TestRemoveRouteRemovesFirstMatchOnly` in `pkg/sentry/socket/netstack/stack_test.go`. It adds two 10.0.0.0/24 routes on NIC 1 and NIC 2 and sends RTM_DELROUTE three times. The first request leaves only the NIC 2 route, the second leaves an empty table, and the third returns ESRCH. The test uses NICs to tell the routes apart because the routes carry no metric. Without the `stack.go` change it fails with `route table after first RemoveRoute = [], want only the NIC 2 route`. - The `netstack_test` target in `BUILD` gets the deps the new test needs. - `//pkg/sentry/socket/netstack:netstack_test` and `//pkg/tcpip/stack:stack_test` pass locally under bazel. - `test/syscalls/linux/socket_netlink_route.cc` gains `NetlinkRouteTest.DeleteRouteRemovesFirstMatchOnly`. It adds 10.0.0.0/24 on two interfaces and deletes three times with no output interface. The route count goes from 2 to 1 to 0, and the third delete returns ESRCH. - `test/rtnetlink/linux/route_test.sh` runs the same sequence with `ip route del`. - Local bazel runs of `//test/syscalls:socket_netlink_route_test_runsc_systrap_directfs` (71 tests, including the new one) and `//test/rtnetlink:route_test_runsc_systrap_overlay_directfs` pass with the fix. Both fail without the `stack.go` change. The same tests also pass on native Linux. ptrace runsc variants were not run. FUTURE_COPYBARA_INTEGRATE_REVIEW=#15301 from adi-IL:bot/gvisor-15295 7577af3 PiperOrigin-RevId: 994048898
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.
Fixes #15295
netstack.Stack.RemoveRoutepasses a match function totcpip.Stack.RemoveRoutes, which removes every route that matches. One RTM_DELROUTE request can therefore delete several routes. Linux deletes only the first matching route per request and returns ESRCH when nothing matches.This change adds a
foundflag to the match function inRemoveRoute. After the first match, the function returns false for every later route.tcpip.Stack.RemoveRoutesdoes not change.The first match is the oldest matching route in the route table. Linux sorts routes with the same prefix by metric, so its first match is the route with the lowest metric. gVisor cannot do that yet.
tcpip.Routehas no metric field andlocalRouteignores RTA_PRIORITY. Metric ordering is out of scope for this PR.Testing:
TestRemoveRouteRemovesFirstMatchOnlyinpkg/sentry/socket/netstack/stack_test.go. It adds two 10.0.0.0/24 routes on NIC 1 and NIC 2 and sends RTM_DELROUTE three times. The first request leaves only the NIC 2 route, the second leaves an empty table, and the third returns ESRCH. The test uses NICs to tell the routes apart because the routes carry no metric. Without thestack.gochange it fails withroute table after first RemoveRoute = [], want only the NIC 2 route.netstack_testtarget inBUILDgets the deps the new test needs.//pkg/sentry/socket/netstack:netstack_testand//pkg/tcpip/stack:stack_testpass locally under bazel.test/syscalls/linux/socket_netlink_route.ccgainsNetlinkRouteTest.DeleteRouteRemovesFirstMatchOnly. It adds 10.0.0.0/24 on two interfaces and deletes three times with no output interface. The route count goes from 2 to 1 to 0, and the third delete returns ESRCH.test/rtnetlink/linux/route_test.shruns the same sequence withip route del.//test/syscalls:socket_netlink_route_test_runsc_systrap_directfs(71 tests, including the new one) and//test/rtnetlink:route_test_runsc_systrap_overlay_directfspass with the fix. Both fail without thestack.gochange. The same tests also pass on native Linux. ptrace runsc variants were not run.