Skip to content

Commit dcc1615

Browse files
committed
bgpd: Display received and advertised EVPN routes from neighbors
"show bgp l2vpn evpn neighbors <neighbor> [advertised-routes|routes]' did not work due to various bugs. First, the command only accepted IPv4 addresses as valid neighbor ID, thereby rejecting unnumbered BGP and IPv6 neighbor address. Second, the SAFI was hardcoded to MPLS_VPN even though we were passing the safi. Third, "all" made no sense in the command context and to make the command uniform across all address families, I removed the "all" keyword from the command. Signed-off-by: Dinesh G Dutt <[email protected]>
1 parent 3a73896 commit dcc1615

File tree

5 files changed

+175
-116
lines changed

5 files changed

+175
-116
lines changed

bgpd/bgp_evpn_vty.c

+111-57
Original file line numberDiff line numberDiff line change
@@ -1069,11 +1069,9 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
10691069
pi = pi->next) {
10701070
total_count++;
10711071
if (type == bgp_show_type_neighbor) {
1072-
union sockunion *su = output_arg;
1072+
struct peer *peer = output_arg;
10731073

1074-
if (pi->peer->su_remote == NULL
1075-
|| !sockunion_same(
1076-
pi->peer->su_remote, su))
1074+
if (peer_cmp(peer, pi->peer) != 0)
10771075
continue;
10781076
}
10791077
if (header) {
@@ -1292,29 +1290,41 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_tags,
12921290
0);
12931291
}
12941292

1295-
DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_routes,
1296-
show_ip_bgp_l2vpn_evpn_all_neighbor_routes_cmd,
1297-
"show [ip] bgp l2vpn evpn all neighbors A.B.C.D routes [json]",
1293+
DEFUN(show_ip_bgp_l2vpn_evpn_neighbor_routes,
1294+
show_ip_bgp_l2vpn_evpn_neighbor_routes_cmd,
1295+
"show [ip] bgp l2vpn evpn neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
12981296
SHOW_STR
12991297
IP_STR
13001298
BGP_STR
13011299
L2VPN_HELP_STR
13021300
EVPN_HELP_STR
1303-
"Display information about all EVPN NLRIs\n"
13041301
"Detailed information on TCP and BGP neighbor connections\n"
1305-
"Neighbor to display information about\n"
1302+
"IPv4 Neighbor to display information about\n"
1303+
"IPv6 Neighbor to display information about\n"
1304+
"Neighbor on BGP configured interface\n"
13061305
"Display routes learned from neighbor\n" JSON_STR)
13071306
{
1308-
int idx_ipv4 = 0;
1309-
union sockunion su;
1307+
int idx = 0;
13101308
struct peer *peer;
1311-
int ret;
1309+
char *peerstr = NULL;
13121310
bool uj = use_json(argc, argv);
1311+
afi_t afi = AFI_L2VPN;
1312+
safi_t safi = SAFI_EVPN;
1313+
struct bgp *bgp = NULL;
13131314

1314-
argv_find(argv, argc, "A.B.C.D", &idx_ipv4);
1315+
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
1316+
&bgp, uj);
1317+
if (!idx) {
1318+
vty_out(vty, "No index\n");
1319+
return CMD_WARNING;
1320+
}
1321+
1322+
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
1323+
argv_find(argv, argc, "neighbors", &idx);
1324+
peerstr = argv[++idx]->arg;
13151325

1316-
ret = str2sockunion(argv[idx_ipv4]->arg, &su);
1317-
if (ret < 0) {
1326+
peer = peer_lookup_in_view(vty, bgp, peerstr, uj);
1327+
if (!peer) {
13181328
if (uj) {
13191329
json_object *json_no = NULL;
13201330
json_no = json_object_new_object();
@@ -1325,11 +1335,9 @@ DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_routes,
13251335
json_object_free(json_no);
13261336
} else
13271337
vty_out(vty, "Malformed address: %s\n",
1328-
argv[idx_ipv4]->arg);
1338+
argv[idx]->arg);
13291339
return CMD_WARNING;
13301340
}
1331-
1332-
peer = peer_lookup(NULL, &su);
13331341
if (!peer || !peer->afc[AFI_L2VPN][SAFI_EVPN]) {
13341342
if (uj) {
13351343
json_object *json_no = NULL;
@@ -1345,13 +1353,13 @@ DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_routes,
13451353
return CMD_WARNING;
13461354
}
13471355

1348-
return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_neighbor, &su, 0,
1356+
return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_neighbor, peer, 0,
13491357
uj);
13501358
}
13511359

13521360
DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes,
13531361
show_ip_bgp_l2vpn_evpn_rd_neighbor_routes_cmd,
1354-
"show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN neighbors A.B.C.D routes [json]",
1362+
"show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN neighbors <A.B.C.D|X:X::X:X|WORD> routes [json]",
13551363
SHOW_STR
13561364
IP_STR
13571365
BGP_STR
@@ -1360,20 +1368,30 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes,
13601368
"Display information for a route distinguisher\n"
13611369
"VPN Route Distinguisher\n"
13621370
"Detailed information on TCP and BGP neighbor connections\n"
1363-
"Neighbor to display information about\n"
1371+
"IPv4 Neighbor to display information about\n"
1372+
"IPv6 Neighbor to display information about\n"
1373+
"Neighbor on BGP configured interface\n"
13641374
"Display routes learned from neighbor\n" JSON_STR)
13651375
{
13661376
int idx_ext_community = 0;
1367-
int idx_ipv4 = 0;
1377+
int idx = 0;
13681378
int ret;
1369-
union sockunion su;
13701379
struct peer *peer;
1380+
char *peerstr = NULL;
13711381
struct prefix_rd prd;
13721382
bool uj = use_json(argc, argv);
1383+
afi_t afi = AFI_L2VPN;
1384+
safi_t safi = SAFI_EVPN;
1385+
struct bgp *bgp = NULL;
13731386

1374-
argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community);
1375-
argv_find(argv, argc, "A.B.C.D", &idx_ipv4);
1387+
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
1388+
&bgp, uj);
1389+
if (!idx) {
1390+
vty_out(vty, "No index\n");
1391+
return CMD_WARNING;
1392+
}
13761393

1394+
argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community);
13771395
ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd);
13781396
if (!ret) {
13791397
if (uj) {
@@ -1389,8 +1407,12 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes,
13891407
return CMD_WARNING;
13901408
}
13911409

1392-
ret = str2sockunion(argv[idx_ipv4]->arg, &su);
1393-
if (ret < 0) {
1410+
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
1411+
argv_find(argv, argc, "neighbors", &idx);
1412+
peerstr = argv[++idx]->arg;
1413+
1414+
peer = peer_lookup_in_view(vty, bgp, peerstr, uj);
1415+
if (!peer) {
13941416
if (uj) {
13951417
json_object *json_no = NULL;
13961418
json_no = json_object_new_object();
@@ -1401,11 +1423,9 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes,
14011423
json_object_free(json_no);
14021424
} else
14031425
vty_out(vty, "Malformed address: %s\n",
1404-
argv[idx_ext_community]->arg);
1426+
argv[idx]->arg);
14051427
return CMD_WARNING;
14061428
}
1407-
1408-
peer = peer_lookup(NULL, &su);
14091429
if (!peer || !peer->afc[AFI_L2VPN][SAFI_EVPN]) {
14101430
if (uj) {
14111431
json_object *json_no = NULL;
@@ -1421,33 +1441,48 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes,
14211441
return CMD_WARNING;
14221442
}
14231443

1424-
return bgp_show_ethernet_vpn(vty, &prd, bgp_show_type_neighbor, &su, 0,
1444+
return bgp_show_ethernet_vpn(vty, &prd, bgp_show_type_neighbor, peer, 0,
14251445
uj);
14261446
}
14271447

1428-
DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes,
1429-
show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes_cmd,
1430-
"show [ip] bgp l2vpn evpn all neighbors A.B.C.D advertised-routes [json]",
1448+
DEFUN(show_ip_bgp_l2vpn_evpn_neighbor_advertised_routes,
1449+
show_ip_bgp_l2vpn_evpn_neighbor_advertised_routes_cmd,
1450+
"show [ip] bgp l2vpn evpn neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
14311451
SHOW_STR
14321452
IP_STR
14331453
BGP_STR
14341454
L2VPN_HELP_STR
14351455
EVPN_HELP_STR
1436-
"Display information about all EVPN NLRIs\n"
14371456
"Detailed information on TCP and BGP neighbor connections\n"
1438-
"Neighbor to display information about\n"
1457+
"IPv4 Neighbor to display information about\n"
1458+
"IPv6 Neighbor to display information about\n"
1459+
"Neighbor on BGP configured interface\n"
14391460
"Display the routes advertised to a BGP neighbor\n" JSON_STR)
14401461
{
1441-
int idx_ipv4 = 0;
1442-
int ret;
1462+
int idx = 0;
14431463
struct peer *peer;
1444-
union sockunion su;
14451464
bool uj = use_json(argc, argv);
1465+
struct bgp *bgp = NULL;
1466+
afi_t afi = AFI_L2VPN;
1467+
safi_t safi = SAFI_EVPN;
1468+
char *peerstr = NULL;
1469+
1470+
if (uj)
1471+
argc--;
14461472

1447-
argv_find(argv, argc, "A.B.C.D", &idx_ipv4);
1473+
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
1474+
&bgp, uj);
1475+
if (!idx) {
1476+
vty_out(vty, "No index\n");
1477+
return CMD_WARNING;
1478+
}
1479+
1480+
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
1481+
argv_find(argv, argc, "neighbors", &idx);
1482+
peerstr = argv[++idx]->arg;
14481483

1449-
ret = str2sockunion(argv[idx_ipv4]->arg, &su);
1450-
if (ret < 0) {
1484+
peer = peer_lookup_in_view(vty, bgp, peerstr, uj);
1485+
if (!peer) {
14511486
if (uj) {
14521487
json_object *json_no = NULL;
14531488
json_no = json_object_new_object();
@@ -1458,10 +1493,9 @@ DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes,
14581493
json_object_free(json_no);
14591494
} else
14601495
vty_out(vty, "Malformed address: %s\n",
1461-
argv[idx_ipv4]->arg);
1496+
argv[idx]->arg);
14621497
return CMD_WARNING;
14631498
}
1464-
peer = peer_lookup(NULL, &su);
14651499
if (!peer || !peer->afc[AFI_L2VPN][SAFI_EVPN]) {
14661500
if (uj) {
14671501
json_object *json_no = NULL;
@@ -1482,7 +1516,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes,
14821516

14831517
DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes,
14841518
show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes_cmd,
1485-
"show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN neighbors A.B.C.D advertised-routes [json]",
1519+
"show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN neighbors <A.B.C.D|X:X::X:X|WORD> advertised-routes [json]",
14861520
SHOW_STR
14871521
IP_STR
14881522
BGP_STR
@@ -1491,22 +1525,43 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes,
14911525
"Display information for a route distinguisher\n"
14921526
"VPN Route Distinguisher\n"
14931527
"Detailed information on TCP and BGP neighbor connections\n"
1494-
"Neighbor to display information about\n"
1528+
"IPv4 Neighbor to display information about\n"
1529+
"IPv6 Neighbor to display information about\n"
1530+
"Neighbor on BGP configured interface\n"
14951531
"Display the routes advertised to a BGP neighbor\n" JSON_STR)
14961532
{
14971533
int idx_ext_community = 0;
1498-
int idx_ipv4 = 0;
1534+
int idx = 0;
14991535
int ret;
15001536
struct peer *peer;
15011537
struct prefix_rd prd;
1502-
union sockunion su;
1538+
struct bgp *bgp = NULL;
15031539
bool uj = use_json(argc, argv);
1540+
char *peerstr = NULL;
1541+
afi_t afi = AFI_L2VPN;
1542+
safi_t safi = SAFI_EVPN;
1543+
1544+
if (uj)
1545+
argc--;
1546+
1547+
if (uj)
1548+
argc--;
1549+
1550+
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
1551+
&bgp, uj);
1552+
if (!idx) {
1553+
vty_out(vty, "No index\n");
1554+
return CMD_WARNING;
1555+
}
15041556

15051557
argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community);
1506-
argv_find(argv, argc, "A.B.C.D", &idx_ipv4);
15071558

1508-
ret = str2sockunion(argv[idx_ipv4]->arg, &su);
1509-
if (ret < 0) {
1559+
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
1560+
argv_find(argv, argc, "neighbors", &idx);
1561+
peerstr = argv[++idx]->arg;
1562+
1563+
peer = peer_lookup_in_view(vty, bgp, peerstr, uj);
1564+
if (!peer) {
15101565
if (uj) {
15111566
json_object *json_no = NULL;
15121567
json_no = json_object_new_object();
@@ -1517,10 +1572,9 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes,
15171572
json_object_free(json_no);
15181573
} else
15191574
vty_out(vty, "Malformed address: %s\n",
1520-
argv[idx_ext_community]->arg);
1575+
argv[idx]->arg);
15211576
return CMD_WARNING;
15221577
}
1523-
peer = peer_lookup(NULL, &su);
15241578
if (!peer || !peer->afc[AFI_L2VPN][SAFI_EVPN]) {
15251579
if (uj) {
15261580
json_object *json_no = NULL;
@@ -1599,7 +1653,7 @@ DEFUN(show_ip_bgp_evpn_rd_overlay,
15991653
use_json(argc, argv));
16001654
}
16011655

1602-
/* For testing purpose, static route of MPLS-VPN. */
1656+
/* For testing purpose, static route of EVPN RT-5. */
16031657
DEFUN(evpnrt5_network,
16041658
evpnrt5_network_cmd,
16051659
"network <A.B.C.D/M|X:X::X:X/M> rd ASN:NN_OR_IP-ADDRESS:NN ethtag WORD label WORD esi WORD gwip <A.B.C.D|X:X::X:X> routermac WORD [route-map WORD]",
@@ -1638,7 +1692,7 @@ DEFUN(evpnrt5_network,
16381692
argv[idx_routermac]->arg);
16391693
}
16401694

1641-
/* For testing purpose, static route of MPLS-VPN. */
1695+
/* For testing purpose, static route of EVPN RT-5. */
16421696
DEFUN(no_evpnrt5_network,
16431697
no_evpnrt5_network_cmd,
16441698
"no network <A.B.C.D/M|X:X::X:X/M> rd ASN:NN_OR_IP-ADDRESS:NN ethtag WORD label WORD esi WORD gwip <A.B.C.D|X:X::X:X>",
@@ -5323,12 +5377,12 @@ void bgp_ethernetvpn_init(void)
53235377
install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_all_tags_cmd);
53245378
install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_rd_tags_cmd);
53255379
install_element(VIEW_NODE,
5326-
&show_ip_bgp_l2vpn_evpn_all_neighbor_routes_cmd);
5380+
&show_ip_bgp_l2vpn_evpn_neighbor_routes_cmd);
53275381
install_element(VIEW_NODE,
53285382
&show_ip_bgp_l2vpn_evpn_rd_neighbor_routes_cmd);
53295383
install_element(
53305384
VIEW_NODE,
5331-
&show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes_cmd);
5385+
&show_ip_bgp_l2vpn_evpn_neighbor_advertised_routes_cmd);
53325386
install_element(
53335387
VIEW_NODE,
53345388
&show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes_cmd);

0 commit comments

Comments
 (0)