bgpd: 'show bgp [ipv4|ipv6] neighbors' displays all address family neighbors

Display only ipv4 neighbors when 'show bgp ipv4 neighbors' command is issued.
Display only ipv6 neighbors when 'show bgp ipv6 neighbors' command is issued.
Take the address family of the peer address into account, while displaying the neighbors.

Signed-off-by: Akhilesh Samineni <akhilesh.samineni@broadcom.com>
This commit is contained in:
Akhilesh Samineni 2019-02-24 15:00:31 +05:30
parent 09720d3189
commit d1927ebe5f
2 changed files with 73 additions and 7 deletions

View File

@ -8499,7 +8499,7 @@ const char *afi_safi_json(afi_t afi, safi_t safi)
}
/* Show BGP peer's information. */
enum show_type { show_all, show_peer };
enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
afi_t afi, safi_t safi,
@ -10896,6 +10896,14 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
struct peer *peer;
int find = 0;
bool nbr_output = false;
afi_t afi = AFI_MAX;
safi_t safi = SAFI_MAX;
if (type == show_ipv4_peer || type == show_ipv4_all) {
afi = AFI_IP;
} else if (type == show_ipv6_peer || type == show_ipv6_all) {
afi = AFI_IP6;
}
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
@ -10924,17 +10932,54 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
}
}
break;
case show_ipv4_peer:
case show_ipv6_peer:
FOREACH_SAFI (safi) {
if (peer->afc[afi][safi]) {
if (conf_if) {
if ((peer->conf_if
&& !strcmp(peer->conf_if, conf_if))
|| (peer->hostname
&& !strcmp(peer->hostname, conf_if))) {
find = 1;
bgp_show_peer(vty, peer, use_json,
json);
break;
}
} else {
if (sockunion_same(&peer->su, su)) {
find = 1;
bgp_show_peer(vty, peer, use_json,
json);
break;
}
}
}
}
break;
case show_ipv4_all:
case show_ipv6_all:
FOREACH_SAFI (safi) {
if (peer->afc[afi][safi]) {
bgp_show_peer(vty, peer, use_json, json);
nbr_output = true;
break;
}
}
break;
}
}
if (type == show_peer && !find) {
if ((type == show_peer || type == show_ipv4_peer ||
type == show_ipv6_peer) && !find) {
if (use_json)
json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
else
vty_out(vty, "%% No such neighbor in this view/vrf\n");
}
if (type != show_peer && !nbr_output && !use_json)
if (type != show_peer && type != show_ipv4_peer &&
type != show_ipv6_peer && !nbr_output && !use_json)
vty_out(vty, "%% No BGP neighbors found\n");
if (use_json) {
@ -11000,7 +11045,8 @@ static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
: bgp->name);
}
if (type == show_peer) {
if (type == show_peer || type == show_ipv4_peer ||
type == show_ipv6_peer) {
ret = str2sockunion(ip_str, &su);
if (ret < 0)
bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
@ -11009,7 +11055,7 @@ static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
bgp_show_neighbor(vty, bgp, type, &su, NULL,
use_json, json);
} else {
bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
bgp_show_neighbor(vty, bgp, type, NULL, NULL,
use_json, json);
}
json_object_free(json);
@ -11102,6 +11148,7 @@ DEFUN (show_ip_bgp_neighbors,
char *vrf = NULL;
char *sh_arg = NULL;
enum show_type sh_type;
afi_t afi = AFI_MAX;
bool uj = use_json(argc, argv);
@ -11117,13 +11164,29 @@ DEFUN (show_ip_bgp_neighbors,
vrf = argv[idx + 1]->arg;
idx++;
if (argv_find(argv, argc, "ipv4", &idx)) {
sh_type = show_ipv4_all;
afi = AFI_IP;
} else if (argv_find(argv, argc, "ipv6", &idx)) {
sh_type = show_ipv6_all;
afi = AFI_IP6;
} else {
sh_type = show_all;
}
if (argv_find(argv, argc, "A.B.C.D", &idx)
|| argv_find(argv, argc, "X:X::X:X", &idx)
|| argv_find(argv, argc, "WORD", &idx)) {
sh_type = show_peer;
sh_arg = argv[idx]->arg;
} else
sh_type = show_all;
}
if (sh_type == show_peer && afi == AFI_IP) {
sh_type = show_ipv4_peer;
} else if (sh_type == show_peer && afi == AFI_IP6) {
sh_type = show_ipv6_peer;
}
return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
}

View File

@ -99,6 +99,9 @@ enum bgp_af_index {
for (afi = AFI_IP; afi < AFI_MAX; afi++) \
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
#define FOREACH_SAFI(safi) \
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
extern struct frr_pthread *bgp_pth_io;
extern struct frr_pthread *bgp_pth_ka;