Skip to content

Commit

Permalink
bgpd: clear ip bgp instances with invalid safi
Browse files Browse the repository at this point in the history
This commit fixes the handling of incoming parameters passed in
following vty functions:

clear ip bgp ipv6 [safi] prefix []
clear ip bgp [vrf ] ipv6 [safi] prefix []

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
  • Loading branch information
pguibert6WIND committed Mar 2, 2018
1 parent c98f4d8 commit aa4ed1f
Showing 2 changed files with 64 additions and 7 deletions.
68 changes: 61 additions & 7 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
@@ -322,6 +322,44 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
return *idx;
}


int bgp_vty_find_and_parse_bgp(struct vty *vty,
struct cmd_token **argv, int argc,
int *idx, struct bgp **bgp)
{
char *vrf_name = NULL;

assert(bgp);

if (argv_find(argv, argc, "view", idx)
|| argv_find(argv, argc, "vrf", idx)) {
vrf_name = argv[*idx + 1]->arg;

if (strmatch(vrf_name, "all"))
*bgp = NULL;
else {
*bgp = bgp_lookup_by_name(vrf_name);
if (!*bgp) {
vty_out(vty,
"View/Vrf specified is unknown: %s\n",
vrf_name);
*idx = 0;
return 0;
}
}
} else {
*bgp = bgp_get_default();
if (!*bgp) {
vty_out(vty, "Unable to find default BGP instance\n");
*idx = 0;
return 0;
}
}
*idx += 1;
return *idx;
}


static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
{
struct interface *ifp = NULL;
@@ -6414,10 +6452,16 @@ DEFUN (clear_bgp_ipv6_safi_prefix,
"IPv6 prefix\n")
{
int idx_safi = 3;
int idx_ipv6_prefixlen = 5;
int idx_ipv6_prefix = 5;
safi_t safi = SAFI_UNICAST;

argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
if (argv_find(argv, argc, "prefix", &idx_ipv6_prefix))
idx_ipv6_prefix+=1;

return bgp_clear_prefix(
vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
vty, NULL, argv[idx_ipv6_prefix]->arg, AFI_IP6,
safi, NULL);
}

DEFUN (clear_bgp_instance_ipv6_safi_prefix,
@@ -6433,11 +6477,21 @@ DEFUN (clear_bgp_instance_ipv6_safi_prefix,
"IPv6 prefix\n")
{
int idx_word = 3;
int idx_safi = 5;
int idx_ipv6_prefixlen = 7;
int idx_safi;
int idx_ipv6_prefix = 7;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp;

argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);

bgp_vty_find_and_parse_bgp(vty, argv, argc, &idx_word, &bgp);

if (argv_find(argv, argc, "prefix", &idx_ipv6_prefix))
idx_ipv6_prefix+=1;

return bgp_clear_prefix(
vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg,
AFI_IP6, bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
vty, argv[idx_word]->arg, argv[idx_ipv6_prefix]->arg,
AFI_IP6, safi, NULL);
}

DEFUN (show_bgp_views,
3 changes: 3 additions & 0 deletions bgpd/bgp_vty.h
Original file line number Diff line number Diff line change
@@ -69,6 +69,9 @@ extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
struct cmd_token **argv,
int argc, int *idx, afi_t *afi,
safi_t *safi, struct bgp **bgp);
extern int bgp_vty_find_and_parse_bgp(struct vty *vty,
struct cmd_token **argv, int argc,
int *idx, struct bgp **bgp);
extern int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
safi_t safi, u_char use_json);
#endif /* _QUAGGA_BGP_VTY_H */

0 comments on commit aa4ed1f

Please sign in to comment.