]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Add `show bgp access-list` command to filter routes by ACL
authorDonatas Abraitis <donatas@opensourcerouting.org>
Wed, 3 Aug 2022 09:53:16 +0000 (12:53 +0300)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Wed, 3 Aug 2022 09:58:14 +0000 (12:58 +0300)
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 <donatas@opensourcerouting.org>
bgpd/bgp_route.c
bgpd/bgp_route.h

index 2fd747a113acd4ae45c93e776d18b7910dffcb7e..abc02ea76d8bf30d5cbc7e50bdfaf600816d79d8 100644 (file)
@@ -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 <invalid|valid|notfound>\
           |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;
index 743b369bfa444e36608df7a4d81044e87ce69ede..6e8ef746aa2841b885c5b1f44632f5bc522e56a6 100644 (file)
@@ -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,