From: Donatas Abraitis Date: Wed, 3 Aug 2022 09:53:16 +0000 (+0300) Subject: bgpd: Add `show bgp access-list` command to filter routes by ACL X-Git-Tag: base_8.4~170^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=ed12638288699c24b5860a892ee027a464e5838a;p=matthieu%2Ffrr.git bgpd: Add `show bgp access-list` command to filter routes by ACL The same as with prefix-list/route-maps/etc. ``` donatas-pc# show ip access-list spine ZEBRA: Zebra IP access list spine seq 5 permit 200.200.200.200/32 BGP: Zebra IP access list spine seq 5 permit 200.200.200.200/32 PIM: Zebra IP access list spine seq 5 permit 200.200.200.200/32 BABELD: Zebra IP access list spine seq 5 permit 200.200.200.200/32 donatas-pc# show bgp ipv4 unicast access-list ACCESSLIST_NAME Access-list name spine donatas-pc# show bgp ipv4 unicast access-list spine BGP table version is 9, local router ID is 172.17.0.3, vrf id 0 Default local pref 100, local AS 1 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 200.200.200.200/32 enp3s0 0 0 65000 3456 ? Displayed 1 routes and 10 total paths donatas-pc# ``` Signed-off-by: Donatas Abraitis --- diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 2fd747a113..abc02ea76d 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11052,6 +11052,13 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, != PREFIX_PERMIT) continue; } + if (type == bgp_show_type_access_list) { + struct access_list *alist = output_arg; + + if (access_list_apply(alist, dest_p) != + FILTER_PERMIT) + continue; + } if (type == bgp_show_type_filter_list) { struct as_list *as_list = output_arg; @@ -12285,6 +12292,7 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, |community-list <(1-500)|COMMUNITY_LIST_NAME> [exact-match]\ |filter-list AS_PATH_FILTER_NAME\ |prefix-list WORD\ + |access-list ACCESSLIST_NAME\ |route-map RMAP_NAME\ |rpki \ |version (1-4294967295)\ @@ -12323,6 +12331,8 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, "Regular expression access list name\n" "Display routes conforming to the prefix-list\n" "Prefix-list name\n" + "Display routes conforming to the access-list\n" + "Access-list name\n" "Display routes matching the route-map\n" "A route-map to match on\n" "RPKI route types\n" @@ -12466,6 +12476,21 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, output_arg = plist; } + if (argv_find(argv, argc, "access-list", &idx)) { + const char *access_list_str = argv[++idx]->arg; + struct access_list *alist; + + alist = access_list_lookup(afi, access_list_str); + if (!alist) { + vty_out(vty, "%% %s is not a valid access-list name\n", + access_list_str); + return CMD_WARNING; + } + + sh_type = bgp_show_type_access_list; + output_arg = alist; + } + if (argv_find(argv, argc, "route-map", &idx)) { const char *rmap_str = argv[++idx]->arg; struct route_map *rmap; diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 743b369bfa..6e8ef746aa 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -37,6 +37,7 @@ enum bgp_show_type { bgp_show_type_normal, bgp_show_type_regexp, bgp_show_type_prefix_list, + bgp_show_type_access_list, bgp_show_type_filter_list, bgp_show_type_route_map, bgp_show_type_neighbor,