Skip to content

zebra: support brief json for show ip route command - #20950

Merged
mjstapp merged 3 commits into
FRRouting:masterfrom
hnattamaisub:ip_route_brief
Apr 9, 2026
Merged

zebra: support brief json for show ip route command#20950
mjstapp merged 3 commits into
FRRouting:masterfrom
hnattamaisub:ip_route_brief

Conversation

@hnattamaisub

@hnattamaisub hnattamaisub commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Added brief option for 'show ip route' command.

The new cli will look like below:
r1# show ip route brief json
{"10.0.0.1/32":[{"protocol":"static","selected":true,"destSelected":true,"distance":1,"metric":0,"installed":true,"nexthopGroupId":6,"vrfId":0,"vrfName":"default","uptime":"00:00:17"}]
,"10.0.0.2/32":[{"protocol":"static","selected":true,"destSelected":true,"distance":1,"metric":0,"installed":true,"nexthopGroupId":5,"vrfId":0,"vrfName":"default","uptime":"00:00:17"}]
,"10.0.0.3/32":[{"protocol":"static","selected":true,"destSelected":true,"distance":1,"metric":0,"installed":true,"nexthopGroupId":6,"vrfId":0,"vrfName":"default","uptime":"00:00:17"}]
,"192.168.1.0/24":[{"protocol":"connected","selected":true,"destSelected":true,"distance":0,"metric":0,"installed":true,"nexthopGroupId":4,"vrfId":0,"vrfName":"default","uptime":"00:00:17"}]
,"192.168.1.1/32":[{"protocol":"local","selected":true,"destSelected":true,"distance":0,"metric":0,"installed":true,"nexthopGroupId":4,"vrfId":0,"vrfName":"default","uptime":"00:00:17"}]
}
r1# show ipv6 route brief json
{"fe80::/64":[{"protocol":"connected","selected":true,"destSelected":true,"distance":0,"metric":0,"installed":true,"nexthopGroupId":8,"vrfId":0,"vrfName":"default","uptime":"00:05:47"}]
}
r1#

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

greptile-apps Bot commented Feb 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a brief option to show ip route and show ip route vrf all commands, producing a compact JSON output with only essential fields per route (protocol, selected, destSelected, distance, metric, installed, nexthopGroupId, vrfId, vrfName, uptime, and a few conditional flags) instead of the full nexthop details.

Key changes:

  • zebra/zebra_vty.c: Adds a bool brief member to struct route_show_ctx. The DEFPY command is extended with [<brief$brief>] for both IPv4 and IPv6 paths. Inside vty_show_ip_route, the JSON output block is restructured β€” brief fields are emitted unconditionally, with prefix, prefixLen, nexthop arrays, and NHG detail gated behind if (!brief). The brief flag propagates correctly via ctx.brief = !!brief at line 1779 and ctx->brief is used at line 933.
  • Tests: Two new tests added to test_static_route_blackhole.py: test_show_ip_route_brief_json verifies required fields are present for each expected prefix, and test_show_ip_route_brief_json_vrf_consistency validates that vrf default, plain (no vrf), and vrf all brief outputs produce consistent prefix sets.
  • Docs: doc/user/zebra.rst documents the new option and the VRF-all structure ({"vrf-name": {"prefix": [...]}}) in the brief view.

Previously flagged issues (early return bypassing json_object_array_add, brief hardcoded to false in vrf-all calls, duplicate nexthopGroupId emission) are all resolved in the current code β€” the ctx struct correctly carries brief through all VRF/table iterations.

Confidence Score: 5/5

Safe to merge β€” all previously flagged critical issues are resolved and no new bugs found.

All P0/P1 issues raised in prior review rounds (early JSON return bypassing array_add, brief hardcoded false in vrf-all paths, duplicate nexthopGroupId) are fixed in the current commit. The brief flag propagates correctly through the route_show_ctx struct into every VRF/table iteration. The new tests cover the basic field-presence check and VRF consistency. No remaining findings exceed P2.

No files require special attention.

Vulnerabilities

No security concerns identified. The brief flag only affects JSON field filtering in show command output and introduces no new input paths, authentication changes, or data-modification logic.

Important Files Changed

Filename Overview
zebra/zebra_vty.c Core implementation of brief JSON output; brief flag correctly propagated via route_show_ctx.brief through all VRF/table iterations; JSON block properly restructured with shared brief/full fields followed by if (!brief) guarded detail section.
tests/topotests/static_route_blackhole/test_static_route_blackhole.py Two new tests cover brief JSON output and VRF consistency; test routes (blackhole, reject, Null0) will have selected/destSelected/installed flags set so conditional-field assertions are valid for this config.
doc/user/zebra.rst Documents new brief option, brief JSON field list, and VRF-all structure; accurately describes behavior including VRF-all nesting.
tests/topotests/static_route_blackhole/r1/frr.conf No changes to route config; existing blackhole/reject/Null0 routes plus interface-derived connected/local routes supply all prefixes tested by the new brief JSON tests.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["show ip route [vrf NAME|all] [brief] json"] --> B["DEFPY show_route handler\nctx.brief = !!brief"]
    B --> C{vrf_all?}
    C -- yes --> D["RB_FOREACH vrfs\nvty_json_key(vrf_name)"]
    D --> E["do_show_ip_route(ctx)"]
    C -- no --> E
    E --> F["do_show_route_helper(ctx)"]
    F --> G["vty_show_ip_route(ctx->brief)"]
    G --> H{json?}
    H -- no --> I["Text output\n(brief ignored)"]
    H -- yes --> J["Emit shared brief fields\nprotocol, selected, distance,\nmetric, installed, nexthopGroupId,\nvrfId, vrfName, uptime"]
    J --> K{brief?}
    K -- yes --> L["json_object_array_add\nReturn brief JSON"]
    K -- no --> M["Emit full fields\nprefix, prefixLen, instance,\ntag, nexthops, backupNexthops,\nNHG detail/summary"]
    M --> L
Loading

Reviews (4): Last reviewed commit: "doc: add documentation for 'show ip/ipv6..." | Re-trigger Greptile

@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.

4 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment thread zebra/zebra_vty.c Outdated
Comment thread zebra/zebra_vty.c Outdated
@hnattamaisub
hnattamaisub force-pushed the ip_route_brief branch 3 times, most recently from 6b034c8 to 9e758c9 Compare February 27, 2026 04:59
@hnattamaisub
hnattamaisub marked this pull request as draft February 27, 2026 05:13
@mjstapp

mjstapp commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

@greptileio rereview

@mjstapp

mjstapp commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

@greptileai review this draft

Comment thread zebra/zebra_vty.c Outdated
Comment thread zebra/zebra_vty.c Outdated
Comment thread zebra/zebra_vty.c Outdated
Comment thread zebra/zebra_vty.c Outdated
Comment thread zebra/zebra_vty.c Outdated
Comment thread zebra/zebra_vty.c
Comment thread zebra/zebra_vty.c
Comment thread zebra/zebra_vty.c Outdated
Comment thread zebra/zebra_vty.c Outdated
@riw777
riw777 self-requested a review March 3, 2026 16:03
@hnattamaisub

Copy link
Copy Markdown
Contributor Author

ci:rerun

@hnattamaisub
hnattamaisub force-pushed the ip_route_brief branch 2 times, most recently from 111c11d to 970eb41 Compare March 12, 2026 04:44
@hnattamaisub

Copy link
Copy Markdown
Contributor Author

ci:rerun

@mjstapp

mjstapp commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

this is zebra, not bgpd, right?

@hnattamaisub hnattamaisub changed the title bgpd: support brief json for show ip route command zebra: support brief json for show ip route command Mar 16, 2026
@hnattamaisub

Copy link
Copy Markdown
Contributor Author

this is zebra, not bgpd, right?

yes, changed now, thanks

@hnattamaisub
hnattamaisub marked this pull request as ready for review March 17, 2026 06:25
Comment thread zebra/zebra_vty.c Outdated
Implementation of show ip route brief command

Signed-off-by: harini <hnattamaisub@nvidia.com>
Signed-off-by: harini <hnattamaisub@nvidia.com>
Signed-off-by: harini <hnattamaisub@nvidia.com>
@hnattamaisub

Copy link
Copy Markdown
Contributor Author

ci:rerun

1 similar comment
@hnattamaisub

Copy link
Copy Markdown
Contributor Author

ci:rerun

@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

@hnattamaisub

Copy link
Copy Markdown
Contributor Author

@riw777 can we please merge this , if there is no concern?

@mjstapp

mjstapp commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

@greptileai review

@mjstapp

mjstapp commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

let's get another pass

@riw777

riw777 commented Apr 8, 2026

Copy link
Copy Markdown
Member

looks good, waiting for @mjstapp to clear his comments

@mjstapp mjstapp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm ok with this now

@mjstapp
mjstapp merged commit 0148e77 into FRRouting:master Apr 9, 2026
22 checks passed
@hnattamaisub
hnattamaisub deleted the ip_route_brief branch April 9, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation master rebase PR needs rebase size/L tests Topotests, make check, etc zebra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants