Skip to content

Kernel skip some route updates - #20666

Merged
riw777 merged 3 commits into
FRRouting:masterfrom
donaldsharp:kernel_skip_some_route_updates
Feb 14, 2026
Merged

Kernel skip some route updates#20666
riw777 merged 3 commits into
FRRouting:masterfrom
donaldsharp:kernel_skip_some_route_updates

Conversation

@donaldsharp

Copy link
Copy Markdown
Member

See individual commits for discussion, but in some cases skip some route update installations when certain conditions are met.

@frrbot frrbot Bot added tests Topotests, make check, etc zebra labels Feb 3, 2026
@greptile-apps

greptile-apps Bot commented Feb 3, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

This 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

  • Optimization Logic: When kernel nexthops are enabled and a route update has the same nexthop group ID and type as the existing route, the kernel update is skipped since the kernel already has the correct nexthop data
  • Counter Tracking: Added dg_routes_kernel_skipped atomic counter to track skipped updates, exposed via show zebra dplane detailed command
  • Test Coverage: Added test case in test_zebra_nhg.py to verify the skip counter increments during interface down/up scenarios

Use Case

This 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

  • The test has incorrect assertion logic at line 392-394 that checks if skipped_updates_before == 0 but uses an error message about retrieval failure, when -1 indicates retrieval failure and positive values indicate successful retrieval with existing skipped updates

Confidence Score: 4/5

  • Safe to merge after fixing the test assertion logic issue
  • The core optimization logic in zebra_dplane.c is sound and follows existing patterns (similar check exists at line 4628). The atomic counter is properly implemented with memory_order_relaxed. However, the test contains an incorrect assertion that conflates retrieval failure (-1) with unexpected pre-existing skipped updates (> 0), which should be fixed before merge.
  • tests/topotests/zebra_nhg_check/test_zebra_nhg.py requires assertion logic fix at line 392-394

Important Files Changed

Filename Overview
zebra/zebra_dplane.c Added optimization to skip redundant kernel route updates when nexthop group and route type unchanged, with proper counter tracking
tests/topotests/zebra_nhg_check/test_zebra_nhg.py Added test validation for route skip counter, but contains incorrect assertion logic for error checking

Sequence Diagram

sequenceDiagram
    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
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +392 to +394
assert (
skipped_updates_before == 0
), "Could not retrieve route updates skipped before shutdown"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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>
@donaldsharp
donaldsharp force-pushed the kernel_skip_some_route_updates branch from b021110 to 372d097 Compare February 3, 2026 15:28
@github-actions github-actions Bot added size/L and removed size/M labels Feb 3, 2026
@donaldsharp

Copy link
Copy Markdown
Member Author

I disagree with the frrbot recomendations. they are not with code I chagned.

@riw777 riw777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@riw777
riw777 merged commit f10991d into FRRouting:master Feb 14, 2026
19 checks passed
@donaldsharp
donaldsharp deleted the kernel_skip_some_route_updates branch April 30, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

master size/L tests Topotests, make check, etc zebra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants