Kernel skip some route updates - #20666
Conversation
Greptile OverviewGreptile SummaryThis PR optimizes zebra's dataplane by skipping redundant kernel route updates when both the nexthop group ID and route type remain unchanged between old and new route contexts. Key Changes
Use CaseThis addresses the scenario where an interface goes down/up: zebra adjusts the nexthop group internally, and an upper-level protocol (BGP/OSPF) sends a route update removing the downed nexthop. Since the kernel was already updated by zebra's nexthop group management, the route update to the kernel is redundant and can be safely skipped. Issue Found
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Protocol as Upper Protocol (BGP/OSPF)
participant Zebra as Zebra RIB
participant Dplane as Dataplane Provider
participant Kernel as Linux Kernel
Note over Protocol,Kernel: Interface Down Event Scenario
Protocol->>Zebra: Route update (remove failed nexthop)
Zebra->>Dplane: DPLANE_OP_ROUTE_UPDATE context
Note over Dplane: ctx with old_nhe_id and nhe_id
alt Skip kernel update already set
Dplane->>Dplane: Check dplane_ctx_is_skip_kernel()
Dplane->>Dplane: Mark success, skip kernel
else Kernel nexthops enabled + same NHG + same type
Dplane->>Dplane: Check zebra_nhg_kernel_nexthops_enabled()
Dplane->>Dplane: Compare old_nhe_id == nhe_id
Dplane->>Dplane: Compare old_type == type
Dplane->>Dplane: Increment dg_routes_kernel_skipped
Dplane->>Dplane: Mark ZEBRA_DPLANE_REQUEST_SUCCESS
Note over Dplane: Skip actual kernel update
else Normal kernel update
Dplane->>Kernel: netlink route update
Kernel-->>Dplane: Update result
end
Dplane->>Zebra: Update result (success)
Zebra->>Protocol: Trigger nexthop tracking
Zebra->>Protocol: Handle redistribution
|
| assert ( | ||
| skipped_updates_before == 0 | ||
| ), "Could not retrieve route updates skipped before shutdown" |
There was a problem hiding this comment.
Assertion logic and error message are mismatched. The condition checks if skipped_updates_before == 0, but the error message says "Could not retrieve route updates skipped before shutdown". If get_route_updates_skipped() returns -1, it means retrieval failed (which should be checked separately). If it returns a positive value, it means retrieval succeeded but there were already skipped updates before the test. Consider:
| assert ( | |
| skipped_updates_before == 0 | |
| ), "Could not retrieve route updates skipped before shutdown" | |
| assert ( | |
| skipped_updates_before >= 0 | |
| ), "Could not retrieve route updates skipped before shutdown" |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/topotests/zebra_nhg_check/test_zebra_nhg.py
Line: 392:394
Comment:
Assertion logic and error message are mismatched. The condition checks if `skipped_updates_before == 0`, but the error message says "Could not retrieve route updates skipped before shutdown". If `get_route_updates_skipped()` returns `-1`, it means retrieval failed (which should be checked separately). If it returns a positive value, it means retrieval succeeded but there were already skipped updates before the test. Consider:
```suggestion
assert (
skipped_updates_before >= 0
), "Could not retrieve route updates skipped before shutdown"
```
How can I resolve this? If you propose a fix, please make it concise.If a route being installed into the kernel is the same route type and the nexthop group id is the same and kernel nexthops are being used, then we can skip the route update. This test is expressly for the situation where a interface goes down/up, zebra adjusts the nexthop group and an upper level protocol sends the route down minus the downed nexthop. The kernel already has the correct nexthop data for the route so there is no need to update anything. Also add a counter to know when this happens so we can test that it is happening. These items currently depend on successful route installation: a) Nexthop tracking b) redistribution c) Better admin distance notifications. So the decision from my point of view is to have the same path for contexts such that all the things that need to happen after routes are in the dplane can just happen naturally. Additionally we don't need to have special case code to make these things happen at the end. Additionally if anything new needs to happen at the end it just happens naturally. Finally I am also concerned about the case where we have some dplane that is depending on this behavior currently. I don't know what may or may not need these route updates. This is especially true because if not using nexthop groups the kernel may actually need to be updated. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Just a simple change to show that routes are actually being skipped. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This code is the exact same that is now in the dplane, but it actually belongs there because it is avoiding the handling of redistribution and nexthop tracking entirely. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
b021110 to
372d097
Compare
|
I disagree with the frrbot recomendations. they are not with code I chagned. |
See individual commits for discussion, but in some cases skip some route update installations when certain conditions are met.