bgpd: Show BGP prefixes by community alias

This includes both community/large-community.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
Donatas Abraitis 2021-05-19 17:04:48 +03:00
parent 2794d40202
commit a70a28a577
2 changed files with 98 additions and 41 deletions

View File

@ -23,6 +23,7 @@
#include <math.h> #include <math.h>
#include "printfrr.h" #include "printfrr.h"
#include "frrstr.h"
#include "prefix.h" #include "prefix.h"
#include "linklist.h" #include "linklist.h"
#include "memory.h" #include "memory.h"
@ -10570,7 +10571,6 @@ static int bgp_show_community(struct vty *vty, struct bgp *bgp,
const char *comstr, int exact, afi_t afi, const char *comstr, int exact, afi_t afi,
safi_t safi, uint8_t show_flags); safi_t safi, uint8_t show_flags);
static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
struct bgp_table *table, enum bgp_show_type type, struct bgp_table *table, enum bgp_show_type type,
void *output_arg, char *rd, int is_last, void *output_arg, char *rd, int is_last,
@ -10647,6 +10647,48 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
continue; continue;
} }
if (type == bgp_show_type_community_alias) {
char *alias = output_arg;
char **communities;
int num;
bool found = false;
if (pi->attr->community) {
frrstr_split(pi->attr->community->str,
" ", &communities, &num);
for (int i = 0; i < num; i++) {
const char *com2alias =
bgp_community2alias(
communities[i]);
if (strncmp(alias, com2alias,
strlen(com2alias))
== 0) {
found = true;
break;
}
}
}
if (!found && pi->attr->lcommunity) {
frrstr_split(pi->attr->lcommunity->str,
" ", &communities, &num);
for (int i = 0; i < num; i++) {
const char *com2alias =
bgp_community2alias(
communities[i]);
if (strncmp(alias, com2alias,
strlen(com2alias))
== 0) {
found = true;
break;
}
}
}
if (!found)
continue;
}
if (type == bgp_show_type_rpki) { if (type == bgp_show_type_rpki) {
if (dest_p->family == AF_INET if (dest_p->family == AF_INET
|| dest_p->family == AF_INET6) || dest_p->family == AF_INET6)
@ -11920,9 +11962,10 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd,
} }
/* BGP route print out function with JSON */ /* BGP route print out function with JSON */
DEFPY (show_ip_bgp_json, DEFPY(show_ip_bgp_json, show_ip_bgp_json_cmd,
show_ip_bgp_json_cmd, "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]\ " [" BGP_SAFI_WITH_LABEL_CMD_STR
"]]\
[all$all]\ [all$all]\
[cidr-only\ [cidr-only\
|dampening <flap-statistics|dampened-paths>\ |dampening <flap-statistics|dampened-paths>\
@ -11933,44 +11976,41 @@ DEFPY (show_ip_bgp_json,
|route-filter-translated-v4] [exact-match]\ |route-filter-translated-v4] [exact-match]\
|rpki <invalid|valid|notfound>\ |rpki <invalid|valid|notfound>\
|version (1-4294967295)\ |version (1-4294967295)\
|alias WORD\
] [json$uj [detail$detail] | wide$wide]", ] [json$uj [detail$detail] | wide$wide]",
SHOW_STR SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
IP_STR BGP_SAFI_WITH_LABEL_HELP_STR
BGP_STR "Display the entries for all address families\n"
BGP_INSTANCE_HELP_STR "Display only routes with non-natural netmasks\n"
BGP_AFI_HELP_STR "Display detailed information about dampening\n"
BGP_SAFI_WITH_LABEL_HELP_STR "Display flap statistics of routes\n"
"Display the entries for all address families\n" "Display paths suppressed due to dampening\n"
"Display only routes with non-natural netmasks\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR
"Display detailed information about dampening\n" "Do not send outside local AS (well-known community)\n"
"Display flap statistics of routes\n" "Do not advertise to any peer (well-known community)\n"
"Display paths suppressed due to dampening\n" "Do not export to next AS (well-known community)\n"
"Display routes matching the communities\n" "Graceful shutdown (well-known community)\n"
COMMUNITY_AANN_STR "Do not export to any peer (well-known community)\n"
"Do not send outside local AS (well-known community)\n" "Inform EBGP peers to blackhole traffic to prefix (well-known community)\n"
"Do not advertise to any peer (well-known community)\n" "Staled Long-lived Graceful Restart VPN route (well-known community)\n"
"Do not export to next AS (well-known community)\n" "Removed because Long-lived Graceful Restart was not enabled for VPN route (well-known community)\n"
"Graceful shutdown (well-known community)\n" "Should accept local VPN route if exported and imported into different VRF (well-known community)\n"
"Do not export to any peer (well-known community)\n" "Should accept VPN route with local nexthop (well-known community)\n"
"Inform EBGP peers to blackhole traffic to prefix (well-known community)\n" "RT VPNv6 route filtering (well-known community)\n"
"Staled Long-lived Graceful Restart VPN route (well-known community)\n" "RT VPNv4 route filtering (well-known community)\n"
"Removed because Long-lived Graceful Restart was not enabled for VPN route (well-known community)\n" "RT translated VPNv6 route filtering (well-known community)\n"
"Should accept local VPN route if exported and imported into different VRF (well-known community)\n" "RT translated VPNv4 route filtering (well-known community)\n"
"Should accept VPN route with local nexthop (well-known community)\n" "Exact match of the communities\n"
"RT VPNv6 route filtering (well-known community)\n" "RPKI route types\n"
"RT VPNv4 route filtering (well-known community)\n" "A valid path as determined by rpki\n"
"RT translated VPNv6 route filtering (well-known community)\n" "A invalid path as determined by rpki\n"
"RT translated VPNv4 route filtering (well-known community)\n" "A path that has no rpki data\n"
"Exact match of the communities\n" "Display prefixes with matching version numbers\n"
"RPKI route types\n" "Version number and above\n"
"A valid path as determined by rpki\n" "Display prefixes with matching BGP community alias\n"
"A invalid path as determined by rpki\n" "BGP community alias\n" JSON_STR
"A path that has no rpki data\n" "Display detailed version of JSON output\n"
"Display prefixes with matching version numbers\n" "Increase table width for longer prefixes\n")
"Version number and above\n"
JSON_STR
"Display detailed version of JSON output\n"
"Increase table width for longer prefixes\n")
{ {
afi_t afi = AFI_IP6; afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST; safi_t safi = SAFI_UNICAST;
@ -11980,6 +12020,7 @@ DEFPY (show_ip_bgp_json,
int exact_match = 0; int exact_match = 0;
char *community = NULL; char *community = NULL;
char *prefix_version = NULL; char *prefix_version = NULL;
char *bgp_community_alias = NULL;
bool first = true; bool first = true;
uint8_t show_flags = 0; uint8_t show_flags = 0;
enum rpki_states rpki_target_state = RPKI_NOT_BEING_USED; enum rpki_states rpki_target_state = RPKI_NOT_BEING_USED;
@ -12056,6 +12097,12 @@ DEFPY (show_ip_bgp_json,
prefix_version = argv[idx + 1]->arg; prefix_version = argv[idx + 1]->arg;
} }
/* Display prefixes with matching BGP community alias */
if (argv_find(argv, argc, "alias", &idx)) {
sh_type = bgp_show_type_community_alias;
bgp_community_alias = argv[idx + 1]->arg;
}
if (!all) { if (!all) {
/* show bgp: AFI_IP6, show ip bgp: AFI_IP */ /* show bgp: AFI_IP6, show ip bgp: AFI_IP */
if (community) if (community)
@ -12066,6 +12113,10 @@ DEFPY (show_ip_bgp_json,
return bgp_show(vty, bgp, afi, safi, sh_type, return bgp_show(vty, bgp, afi, safi, sh_type,
prefix_version, show_flags, prefix_version, show_flags,
rpki_target_state); rpki_target_state);
else if (bgp_community_alias)
return bgp_show(vty, bgp, afi, safi, sh_type,
bgp_community_alias, show_flags,
rpki_target_state);
else else
return bgp_show(vty, bgp, afi, safi, sh_type, NULL, return bgp_show(vty, bgp, afi, safi, sh_type, NULL,
show_flags, rpki_target_state); show_flags, rpki_target_state);
@ -12108,6 +12159,11 @@ DEFPY (show_ip_bgp_json,
sh_type, prefix_version, sh_type, prefix_version,
show_flags, show_flags,
rpki_target_state); rpki_target_state);
else if (bgp_community_alias)
return bgp_show(
vty, bgp, afi, safi, sh_type,
bgp_community_alias, show_flags,
rpki_target_state);
else else
bgp_show(vty, bgp, afi, safi, sh_type, bgp_show(vty, bgp, afi, safi, sh_type,
NULL, show_flags, NULL, show_flags,

View File

@ -42,6 +42,7 @@ enum bgp_show_type {
bgp_show_type_neighbor, bgp_show_type_neighbor,
bgp_show_type_cidr_only, bgp_show_type_cidr_only,
bgp_show_type_prefix_longer, bgp_show_type_prefix_longer,
bgp_show_type_community_alias,
bgp_show_type_community_all, bgp_show_type_community_all,
bgp_show_type_community, bgp_show_type_community,
bgp_show_type_community_exact, bgp_show_type_community_exact,