From aa4ed1f658ff6d1f739fae9321747d381cd1de26 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Fri, 2 Mar 2018 15:43:07 +0100 Subject: [PATCH] bgpd: clear ip bgp instances with invalid safi 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 --- bgpd/bgp_vty.c | 68 ++++++++++++++++++++++++++++++++++++++++++++------ bgpd/bgp_vty.h | 3 +++ 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 15cc5673accf..e95699ca3e17 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -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, diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index cbb41f0840a5..c556bf18824a 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -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 */