mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 01:40:16 +00:00
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:
parent
2794d40202
commit
a70a28a577
@ -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,20 +11976,16 @@ 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_STR
|
|
||||||
BGP_INSTANCE_HELP_STR
|
|
||||||
BGP_AFI_HELP_STR
|
|
||||||
BGP_SAFI_WITH_LABEL_HELP_STR
|
BGP_SAFI_WITH_LABEL_HELP_STR
|
||||||
"Display the entries for all address families\n"
|
"Display the entries for all address families\n"
|
||||||
"Display only routes with non-natural netmasks\n"
|
"Display only routes with non-natural netmasks\n"
|
||||||
"Display detailed information about dampening\n"
|
"Display detailed information about dampening\n"
|
||||||
"Display flap statistics of routes\n"
|
"Display flap statistics of routes\n"
|
||||||
"Display paths suppressed due to dampening\n"
|
"Display paths suppressed due to dampening\n"
|
||||||
"Display routes matching the communities\n"
|
"Display routes matching the communities\n" COMMUNITY_AANN_STR
|
||||||
COMMUNITY_AANN_STR
|
|
||||||
"Do not send outside local AS (well-known community)\n"
|
"Do not send outside local AS (well-known community)\n"
|
||||||
"Do not advertise to any peer (well-known community)\n"
|
"Do not advertise to any peer (well-known community)\n"
|
||||||
"Do not export to next AS (well-known community)\n"
|
"Do not export to next AS (well-known community)\n"
|
||||||
@ -11968,7 +12007,8 @@ DEFPY (show_ip_bgp_json,
|
|||||||
"A path that has no rpki data\n"
|
"A path that has no rpki data\n"
|
||||||
"Display prefixes with matching version numbers\n"
|
"Display prefixes with matching version numbers\n"
|
||||||
"Version number and above\n"
|
"Version number and above\n"
|
||||||
JSON_STR
|
"Display prefixes with matching BGP community alias\n"
|
||||||
|
"BGP community alias\n" JSON_STR
|
||||||
"Display detailed version of JSON output\n"
|
"Display detailed version of JSON output\n"
|
||||||
"Increase table width for longer prefixes\n")
|
"Increase table width for longer prefixes\n")
|
||||||
{
|
{
|
||||||
@ -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,
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user