bgpd: Check argv_find() value instead of the index

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2022-05-12 10:23:28 +03:00
parent ededfdb4d1
commit 9b01d28988
3 changed files with 40 additions and 40 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,19 @@ 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); (void)prefix_str2mac(argv[mac_idx + 1]->arg, &mac);
argv_find(argv, argc, "ip", &ip_idx); if (argv_find(argv, argc, "ip", &ip_idx))
str2ipaddr(argv[ip_idx + 1]->arg, &ip); str2ipaddr(argv[ip_idx + 1]->arg, &ip);
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); str2ipaddr(argv[ip_idx + 1]->arg, &ip);
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;
} }