Merge pull request #11188 from opensourcerouting/fix/argv_find

bgpd: Cleanup
This commit is contained in:
Donald Sharp 2022-05-13 07:35:57 -04:00 committed by GitHub
commit 69df174216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 48 deletions

View File

@ -627,8 +627,8 @@ static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv,
int argc, struct prefix **argv_pp) int argc, struct prefix **argv_pp)
{ {
struct prefix *argv_p; struct prefix *argv_p;
struct ethaddr mac; struct ethaddr mac = {};
struct ipaddr ip; struct ipaddr ip = {};
int evpn_type = 0; int evpn_type = 0;
int mac_idx = 0; int mac_idx = 0;
int ip_idx = 0; int ip_idx = 0;
@ -641,19 +641,28 @@ static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv,
if (evpn_type == BGP_EVPN_MAC_IP_ROUTE) { if (evpn_type == BGP_EVPN_MAC_IP_ROUTE) {
memset(&ip, 0, sizeof(struct ipaddr)); memset(&ip, 0, sizeof(struct ipaddr));
argv_find(argv, argc, "mac", &mac_idx); if (argv_find(argv, argc, "mac", &mac_idx))
(void)prefix_str2mac(argv[mac_idx + 1]->arg, &mac); if (!prefix_str2mac(argv[mac_idx + 1]->arg, &mac)) {
vty_out(vty, "%% Malformed MAC address\n");
return CMD_WARNING;
}
argv_find(argv, argc, "ip", &ip_idx); if (argv_find(argv, argc, "ip", &ip_idx))
str2ipaddr(argv[ip_idx + 1]->arg, &ip); if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) {
vty_out(vty, "%% Malformed IP address\n");
return CMD_WARNING;
}
build_evpn_type2_prefix((struct prefix_evpn *)argv_p, build_evpn_type2_prefix((struct prefix_evpn *)argv_p,
&mac, &ip); &mac, &ip);
} else if (evpn_type == BGP_EVPN_IMET_ROUTE) { } else if (evpn_type == BGP_EVPN_IMET_ROUTE) {
memset(&ip, 0, sizeof(struct ipaddr)); memset(&ip, 0, sizeof(struct ipaddr));
argv_find(argv, argc, "ip", &ip_idx); if (argv_find(argv, argc, "ip", &ip_idx))
str2ipaddr(argv[ip_idx + 1]->arg, &ip); if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) {
vty_out(vty, "%% Malformed IP address\n");
return CMD_WARNING;
}
build_evpn_type3_prefix((struct prefix_evpn *)argv_p, build_evpn_type3_prefix((struct prefix_evpn *)argv_p,
ip.ipaddr_v4); ip.ipaddr_v4);

View File

@ -1419,8 +1419,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd,
struct prefix_rd prd; struct prefix_rd prd;
int rd_all = 0; int rd_all = 0;
argv_find(argv, argc, "all", &rd_all); if (argv_find(argv, argc, "all", &rd_all))
if (rd_all)
return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal, return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal,
NULL, SHOW_DISPLAY_STANDARD, NULL, SHOW_DISPLAY_STANDARD,
use_json(argc, argv)); use_json(argc, argv));
@ -1469,8 +1468,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_tags,
struct prefix_rd prd; struct prefix_rd prd;
int rd_all = 0; int rd_all = 0;
argv_find(argv, argc, "all", &rd_all); if (argv_find(argv, argc, "all", &rd_all))
if (rd_all)
return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal, return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal,
NULL, SHOW_DISPLAY_TAGS, 0); NULL, SHOW_DISPLAY_TAGS, 0);
@ -1587,8 +1585,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes,
return CMD_WARNING; return CMD_WARNING;
} }
argv_find(argv, argc, "all", &rd_all); if (argv_find(argv, argc, "all", &rd_all)) {
if (!rd_all) {
argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN", argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN",
&idx_ext_community); &idx_ext_community);
ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd); ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd);
@ -1797,8 +1794,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes,
return CMD_WARNING; return CMD_WARNING;
} }
argv_find(argv, argc, "all", &rd_all); if (argv_find(argv, argc, "all", &rd_all))
if (rd_all)
return show_adj_route_vpn(vty, peer, NULL, AFI_L2VPN, SAFI_EVPN, return show_adj_route_vpn(vty, peer, NULL, AFI_L2VPN, SAFI_EVPN,
uj); uj);
else { else {
@ -1860,8 +1856,7 @@ DEFUN(show_ip_bgp_evpn_rd_overlay,
struct prefix_rd prd; struct prefix_rd prd;
int rd_all = 0; int rd_all = 0;
argv_find(argv, argc, "all", &rd_all); if (argv_find(argv, argc, "all", &rd_all))
if (rd_all)
return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal, return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal,
NULL, SHOW_DISPLAY_OVERLAY, NULL, SHOW_DISPLAY_OVERLAY,
use_json(argc, argv)); use_json(argc, argv));
@ -4693,7 +4688,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd,
JSON_STR) JSON_STR)
{ {
struct bgp *bgp; struct bgp *bgp;
int ret; int ret = 0;
struct prefix_rd prd; struct prefix_rd prd;
int type = 0; int type = 0;
bool uj = false; bool uj = false;
@ -4710,15 +4705,16 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd,
if (uj) if (uj)
json = json_object_new_object(); json = json_object_new_object();
argv_find(argv, argc, "all", &rd_all); if (argv_find(argv, argc, "all", &rd_all)) {
if (!rd_all) {
/* get the RD */ /* get the RD */
argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN", if (argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN",
&idx_ext_community); &idx_ext_community)) {
ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd); ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd);
if (!ret) { if (!ret) {
vty_out(vty, "%% Malformed Route Distinguisher\n"); vty_out(vty,
return CMD_WARNING; "%% Malformed Route Distinguisher\n");
return CMD_WARNING;
}
} }
} }
@ -4757,7 +4753,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd_macip,
JSON_STR) JSON_STR)
{ {
struct bgp *bgp; struct bgp *bgp;
int ret; int ret = 0;
struct prefix_rd prd; struct prefix_rd prd;
struct ethaddr mac; struct ethaddr mac;
struct ipaddr ip; struct ipaddr ip;
@ -4781,14 +4777,15 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd_macip,
json = json_object_new_object(); json = json_object_new_object();
/* get the prd */ /* get the prd */
argv_find(argv, argc, "all", &rd_all); if (argv_find(argv, argc, "all", &rd_all)) {
if (!rd_all) { if (argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN",
argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community)) {
&idx_ext_community); ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd);
ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd); if (!ret) {
if (!ret) { vty_out(vty,
vty_out(vty, "%% Malformed Route Distinguisher\n"); "%% Malformed Route Distinguisher\n");
return CMD_WARNING; return CMD_WARNING;
}
} }
} }

View File

@ -1974,8 +1974,8 @@ DEFUN (bgp_maxmed_onstartup,
VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT(bgp, bgp);
int idx = 0; int idx = 0;
argv_find(argv, argc, "(5-86400)", &idx); if (argv_find(argv, argc, "(5-86400)", &idx))
bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10); bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
if (argv_find(argv, argc, "(0-4294967295)", &idx)) if (argv_find(argv, argc, "(0-4294967295)", &idx))
bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10); bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
else else
@ -2275,9 +2275,12 @@ DEFUN (bgp_coalesce_time,
VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT(bgp, bgp);
int idx = 0; int idx = 0;
argv_find(argv, argc, "(0-4294967295)", &idx);
bgp->heuristic_coalesce = false; bgp->heuristic_coalesce = false;
bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
if (argv_find(argv, argc, "(0-4294967295)", &idx))
bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -19243,8 +19246,7 @@ DEFUN (community_list_standard,
int style = COMMUNITY_LIST_STANDARD; int style = COMMUNITY_LIST_STANDARD;
int idx = 0; int idx = 0;
argv_find(argv, argc, "(0-4294967295)", &idx); if (argv_find(argv, argc, "(0-4294967295)", &idx))
if (idx)
seq = argv[idx]->arg; seq = argv[idx]->arg;
idx = 0; idx = 0;
@ -19292,8 +19294,7 @@ DEFUN (no_community_list_standard_all,
char *seq = NULL; char *seq = NULL;
int idx = 0; int idx = 0;
argv_find(argv, argc, "(0-4294967295)", &idx); if (argv_find(argv, argc, "(0-4294967295)", &idx))
if (idx)
seq = argv[idx]->arg; seq = argv[idx]->arg;
idx = 0; idx = 0;
@ -19356,8 +19357,7 @@ DEFUN (community_list_expanded_all,
int style = COMMUNITY_LIST_EXPANDED; int style = COMMUNITY_LIST_EXPANDED;
int idx = 0; int idx = 0;
argv_find(argv, argc, "(0-4294967295)", &idx); if (argv_find(argv, argc, "(0-4294967295)", &idx))
if (idx)
seq = argv[idx]->arg; seq = argv[idx]->arg;
idx = 0; idx = 0;
@ -19406,8 +19406,7 @@ DEFUN (no_community_list_expanded_all,
int style = COMMUNITY_LIST_EXPANDED; int style = COMMUNITY_LIST_EXPANDED;
int idx = 0; int idx = 0;
argv_find(argv, argc, "(0-4294967295)", &idx); if (argv_find(argv, argc, "(0-4294967295)", &idx))
if (idx)
seq = argv[idx]->arg; seq = argv[idx]->arg;
idx = 0; idx = 0;

View File

@ -4,8 +4,10 @@ identifier argv;
identifier argc; identifier argc;
expression e1; expression e1;
expression e2; expression e2;
identifier I;
@@ @@
(
- argv_find(argv, argc, e1, &idx); - argv_find(argv, argc, e1, &idx);
if ( if (
- idx - idx
@ -14,3 +16,8 @@ expression e2;
{ {
e2; e2;
} }
|
- argv_find(argv, argc, e1, &idx);
... when != I = idx;
when strict
)