From cf4898bc9904c9c59889537e53378332dc10b281 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 4 Oct 2018 17:46:52 +0000 Subject: [PATCH 1/2] bgpd: fix broken show community commands SHA c5f1e1b broke about half of the community-related show commands; fix them Signed-off-by: Quentin Young --- bgpd/bgp_route.c | 77 +++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 715393b91d..755e9b7f97 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -9087,10 +9087,6 @@ DEFUN (show_ip_bgp, |prefix-list WORD\ |filter-list WORD\ |statistics\ - |community [exact-match]\ |community-list <(1-500)|WORD> [exact-match]\ |A.B.C.D/M longer-prefixes\ |X:X::X:X/M longer-prefixes\ @@ -9110,23 +9106,6 @@ DEFUN (show_ip_bgp, "Display routes conforming to the filter-list\n" "Regular expression access list name\n" "BGP RIB advertisement statistics\n" - "Display routes matching the communities\n" - COMMUNITY_AANN_STR - "Do not send outside local AS (well-known community)\n" - "Do not advertise to any peer (well-known community)\n" - "Do not export to next AS (well-known community)\n" - "Graceful shutdown (well-known community)\n" - "Do not export to any peer (well-known community)\n" - "Inform EBGP peers to blackhole traffic to prefix (well-known community)\n" - "Staled Long-lived Graceful Restart VPN route (well-known community)\n" - "Removed because Long-lived Graceful Restart was not enabled for VPN route (well-known community)\n" - "Should accept local VPN route if exported and imported into different VRF (well-known community)\n" - "Should accept VPN route with local nexthop (well-known community)\n" - "RT VPNv6 route filtering (well-known community)\n" - "RT VPNv4 route filtering (well-known community)\n" - "RT translated VPNv6 route filtering (well-known community)\n" - "RT translated VPNv4 route filtering (well-known community)\n" - "Exact match of the communities\n" "Display routes matching the community-list\n" "community-list number\n" "community-list name\n" @@ -9188,11 +9167,14 @@ DEFUN (show_ip_bgp, DEFUN (show_ip_bgp_json, show_ip_bgp_json_cmd, "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]\ - [<\ - cidr-only\ - |dampening \ - |community [] [exact-match]\ - >] [json]", + [cidr-only\ + |dampening \ + |community [AA:NN|local-AS|no-advertise|no-export\ + |graceful-shutdown|no-peer|blackhole|llgr-stale|no-llgr\ + |accept-own|accept-own-nexthop|route-filter-v6\ + |route-filter-v4|route-filter-translated-v6\ + |route-filter-translated-v4] [exact-match]\ + ] [json]", SHOW_STR IP_STR BGP_STR @@ -9209,6 +9191,16 @@ DEFUN (show_ip_bgp_json, "Do not advertise to any peer (well-known community)\n" "Do not export to next AS (well-known community)\n" "Graceful shutdown (well-known community)\n" + "Do not export to any peer (well-known community)\n" + "Inform EBGP peers to blackhole traffic to prefix (well-known community)\n" + "Staled Long-lived Graceful Restart VPN route (well-known community)\n" + "Removed because Long-lived Graceful Restart was not enabled for VPN route (well-known community)\n" + "Should accept local VPN route if exported and imported into different VRF (well-known community)\n" + "Should accept VPN route with local nexthop (well-known community)\n" + "RT VPNv6 route filtering (well-known community)\n" + "RT VPNv4 route filtering (well-known community)\n" + "RT translated VPNv6 route filtering (well-known community)\n" + "RT translated VPNv4 route filtering (well-known community)\n" "Exact match of the communities\n" JSON_STR) { @@ -9217,7 +9209,6 @@ DEFUN (show_ip_bgp_json, enum bgp_show_type sh_type = bgp_show_type_normal; struct bgp *bgp = NULL; int idx = 0; - int idx_community_type = 0; int exact_match = 0; bool uj = use_json(argc, argv); @@ -9244,29 +9235,23 @@ DEFUN (show_ip_bgp_json, } if (argv_find(argv, argc, "community", &idx)) { + char *maybecomm = idx + 1 < argc ? argv[idx + 1]->text : NULL; + char *community = NULL; - /* show a specific community */ - if (argv_find(argv, argc, "local-AS", &idx_community_type) || - argv_find(argv, argc, "no-advertise", - &idx_community_type) || - argv_find(argv, argc, "no-export", - &idx_community_type) || - argv_find(argv, argc, "graceful-shutdown", - &idx_community_type) || - argv_find(argv, argc, "AA:NN", &idx_community_type)) { - if (argv_find(argv, argc, "exact-match", &idx)) - exact_match = 1; + if (maybecomm && !strmatch(maybecomm, "json") + && !strmatch(maybecomm, "exact-match")) + community = maybecomm; - return (bgp_show_community(vty, bgp, - argv[idx_community_type]->arg, - exact_match, afi, safi, uj)); - } else { + if (argv_find(argv, argc, "exact-match", &idx)) + exact_match = 1; - /* show all communities */ + if (community) + return bgp_show_community(vty, bgp, community, + exact_match, afi, safi, uj); + else return (bgp_show(vty, bgp, afi, safi, - bgp_show_type_community_all, NULL, - uj)); - } + bgp_show_type_community_all, NULL, + uj)); } return bgp_show(vty, bgp, afi, safi, sh_type, NULL, uj); From cee9c03192ca785076aebe00d5e62cf22122ff07 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 4 Oct 2018 18:10:09 +0000 Subject: [PATCH 2/2] bgpd: complete description code for communities When this description code was added, it was all dead code since none of the bools that checked if the communities were present were ever changed from 0. Signed-off-by: Quentin Young --- bgpd/bgp_route.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 755e9b7f97..1693147b89 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8666,17 +8666,39 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp, best = count; if (ri->extra && ri->extra->suppress) suppress = 1; - if (ri->attr->community != NULL) { - if (community_include(ri->attr->community, - COMMUNITY_NO_ADVERTISE)) - no_advertise = 1; - if (community_include(ri->attr->community, - COMMUNITY_NO_EXPORT)) - no_export = 1; - if (community_include(ri->attr->community, - COMMUNITY_LOCAL_AS)) - local_as = 1; - } + + if (ri->attr->community == NULL) + continue; + + no_advertise += community_include( + ri->attr->community, COMMUNITY_NO_ADVERTISE); + no_export += community_include(ri->attr->community, + COMMUNITY_NO_EXPORT); + local_as += community_include(ri->attr->community, + COMMUNITY_LOCAL_AS); + accept_own += community_include(ri->attr->community, + COMMUNITY_ACCEPT_OWN); + route_filter_translated_v4 += community_include( + ri->attr->community, + COMMUNITY_ROUTE_FILTER_TRANSLATED_v4); + route_filter_translated_v6 += community_include( + ri->attr->community, + COMMUNITY_ROUTE_FILTER_TRANSLATED_v6); + route_filter_v4 += community_include( + ri->attr->community, COMMUNITY_ROUTE_FILTER_v4); + route_filter_v6 += community_include( + ri->attr->community, COMMUNITY_ROUTE_FILTER_v6); + llgr_stale += community_include(ri->attr->community, + COMMUNITY_LLGR_STALE); + no_llgr += community_include(ri->attr->community, + COMMUNITY_NO_LLGR); + accept_own_nexthop += + community_include(ri->attr->community, + COMMUNITY_ACCEPT_OWN_NEXTHOP); + blackhole += community_include(ri->attr->community, + COMMUNITY_BLACKHOLE); + no_peer += community_include(ri->attr->community, + COMMUNITY_NO_PEER); } }