From 2f49a5942b3003023c51a0426725d9e440deccfa Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 13 Dec 2016 22:51:41 -0200 Subject: [PATCH 01/35] ldpd: fix segfault when configuring multiple pseudowires Signed-off-by: Renato Westphal --- ldpd/ldp_vty_conf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index f2b21d8175..dd70365f3d 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -1250,7 +1250,7 @@ ldp_vty_l2vpn(struct vty *vty, struct vty_arg *args[]) l2vpn->type = L2VPN_TYPE_VPLS; LIST_INSERT_HEAD(&vty_conf->l2vpn_list, l2vpn, entry); - ldp_reload(vty_conf); + ldp_reload_ref(vty_conf, (void **)&l2vpn); VTY_PUSH_CONTEXT(LDP_L2VPN_NODE, l2vpn); return (CMD_SUCCESS); @@ -1432,7 +1432,7 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, struct vty_arg *args[]) } if (pw) { - VTY_PUSH_CONTEXT(LDP_PSEUDOWIRE_NODE, pw); + VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE, pw); goto cancel; } @@ -1454,7 +1454,7 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, struct vty_arg *args[]) LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry); ldp_reload_ref(vty_conf, (void **)&pw); - VTY_PUSH_CONTEXT(LDP_PSEUDOWIRE_NODE, pw); + VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE, pw); return (CMD_SUCCESS); @@ -1474,7 +1474,7 @@ ldp_vty_l2vpn_pw_cword(struct vty *vty, struct vty_arg *args[]) disable = (vty_get_arg_value(args, "no")) ? 1 : 0; preference_str = vty_get_arg_value(args, "preference"); - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) @@ -1510,7 +1510,7 @@ ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, struct vty_arg *args[]) return (CMD_WARNING); } - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) { @@ -1546,7 +1546,7 @@ ldp_vty_l2vpn_pw_nbr_id(struct vty *vty, struct vty_arg *args[]) return (CMD_WARNING); } - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) @@ -1578,7 +1578,7 @@ ldp_vty_l2vpn_pw_pwid(struct vty *vty, struct vty_arg *args[]) return (CMD_WARNING); } - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) @@ -1600,7 +1600,7 @@ ldp_vty_l2vpn_pw_pwstatus(struct vty *vty, struct vty_arg *args[]) disable = (vty_get_arg_value(args, "no")) ? 1 : 0; - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) From 9c0b0e6753b110a7e0ba4229873a6c10cd8c6bd5 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 19:20:10 -0200 Subject: [PATCH 02/35] ldpd: allow multiple link adjacencies with unnumbered interfaces Now we can have two different adjacencies coming from the same source address. Check for the adjacency's interface on adj_find() to disambiguate them. Signed-off-by: Renato Westphal --- ldpd/adjacency.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c index 3607ee96b3..d1a6facb30 100644 --- a/ldpd/adjacency.c +++ b/ldpd/adjacency.c @@ -117,6 +117,10 @@ adj_find(struct hello_source *source) switch (source->type) { case HELLO_LINK: + if (strcmp(source->link.ia->iface->name, + adj->source.link.ia->iface->name)) + continue; + if (ldp_addrcmp(source->link.ia->af, &adj->source.link.src_addr, &source->link.src_addr) == 0) From 54c8d91e5d79004d812ac816bf0785c8edd6c0cd Mon Sep 17 00:00:00 2001 From: Don Slice Date: Fri, 16 Dec 2016 08:53:30 -0800 Subject: [PATCH 03/35] ospf6d: resolve problem with area range lsid creation The problem reported was that routers downstream from the ABR would have prefixes in the IPv6 rib that should have been summarized. Testing showed that the prefixes were absent in the lsdb but not removed from the rib. The problem (and others) stemmed from determining the link-state id to use for the area-range statement only from other entries in the range-table. Since the area range statement creates inter-prefix LSAs (summaries) which are in all aspects identical to other inter-prefix LSAs, the number space for the lsid needs to be unique across all inter-prefix LSAs, not just unique between area range statements. This fix removes the use of range-table specific lsids and acquires the lsid just as any other inter-prefix LSA. Ticket: CM-13626 Signed-off-by: Don Slice Reviewed By: CCR-5489 Testing Done: Manual testing, repeated runs of the test that previously failed, ospf-smoke --- ospf6d/ospf6_abr.c | 9 +++------ ospf6d/ospf6_area.c | 4 ---- ospf6d/ospf6_lsdb.c | 18 ------------------ ospf6d/ospf6_lsdb.h | 3 --- 4 files changed, 3 insertions(+), 31 deletions(-) diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index 527d2ecfa7..f75a35fa50 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -424,12 +424,9 @@ ospf6_abr_originate_summary_to_area (struct ospf6_route *route, else { summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_PREFIX); - if (route->type == OSPF6_DEST_TYPE_RANGE) - summary->path.origin.id = route->linkstate_id; - else - summary->path.origin.id = - ospf6_new_ls_id (summary->path.origin.type, - summary->path.origin.adv_router, area->lsdb); + summary->path.origin.id = + ospf6_new_ls_id (summary->path.origin.type, + summary->path.origin.adv_router, area->lsdb); } summary = ospf6_route_add (summary, summary_table); } diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c index 685be58324..bbab8598b8 100644 --- a/ospf6d/ospf6_area.c +++ b/ospf6d/ospf6_area.c @@ -465,8 +465,6 @@ DEFUN (area_range, range->prefix = prefix; range->path.area_id = oa->area_id; range->path.cost = OSPF_AREA_RANGE_COST_UNSPEC; - range->linkstate_id = - (u_int32_t) htonl(ospf6_new_range_ls_id (oa->range_table)); } if (argc > 2) @@ -577,8 +575,6 @@ DEFUN (no_area_range, /* purge the old aggregated summary LSA */ ospf6_abr_originate_summary(range); } - ospf6_release_range_ls_id(oa->range_table, - (u_int32_t) ntohl(range->linkstate_id)); ospf6_route_remove (range, oa->range_table); return CMD_SUCCESS; diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c index 04bea84ae5..1d4b557cd5 100644 --- a/ospf6d/ospf6_lsdb.c +++ b/ospf6d/ospf6_lsdb.c @@ -547,24 +547,6 @@ ospf6_lsdb_show (struct vty *vty, enum ospf_lsdb_show_level level, } } -/* Decide new Link State ID to originate for the range. */ -u_int32_t -ospf6_new_range_ls_id (struct ospf6_route_table *range_table) -{ - u_int32_t id; - - bf_assign_index(range_table->idspace, id); - return (id); -} - -/* Release the LS ID back to the ID pool */ -void -ospf6_release_range_ls_id (struct ospf6_route_table *range_table, - u_int32_t id) -{ - bf_release_index(range_table->idspace, id); -} - u_int32_t ospf6_new_ls_id (u_int16_t type, u_int32_t adv_router, struct ospf6_lsdb *lsdb) diff --git a/ospf6d/ospf6_lsdb.h b/ospf6d/ospf6_lsdb.h index a8bfcae882..b21d9ee282 100644 --- a/ospf6d/ospf6_lsdb.h +++ b/ospf6d/ospf6_lsdb.h @@ -81,9 +81,6 @@ extern void ospf6_lsdb_show (struct vty *vty, extern u_int32_t ospf6_new_ls_id (u_int16_t type, u_int32_t adv_router, struct ospf6_lsdb *lsdb); -extern u_int32_t ospf6_new_range_ls_id (struct ospf6_route_table *range_table); -extern void ospf6_release_range_ls_id (struct ospf6_route_table *range_table, - u_int32_t id); extern u_int32_t ospf6_new_ls_seqnum (u_int16_t type, u_int32_t id, u_int32_t adv_router, struct ospf6_lsdb *lsdb); From 07bc3833841ec104b10f48d936da18aaf6ddcf29 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 19 Dec 2016 14:07:28 -0200 Subject: [PATCH 04/35] ldpd: add missing privilege dropping on error path Signed-off-by: Renato Westphal --- ldpd/socket.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ldpd/socket.c b/ldpd/socket.c index 1bb0837401..eaea9973a0 100644 --- a/ldpd/socket.c +++ b/ldpd/socket.c @@ -85,6 +85,8 @@ ldp_create_socket(int af, enum socket_type type) if (ldpd_privs.change(ZPRIVS_RAISE)) log_warn("%s: could not raise privs", __func__); if (sock_set_reuse(fd, 1) == -1) { + if (ldpd_privs.change(ZPRIVS_LOWER)) + log_warn("%s: could not lower privs", __func__); close(fd); return (-1); } From 6bfae35e5c7b020a7ffca41dbe0eefc77ff003c2 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 19 Dec 2016 14:43:25 -0200 Subject: [PATCH 05/35] ospf6d: fix broken indentation in "show ipv6 ospf6 neighbor" In the State/IfState column, we were reserving only 6 characters to print the state of each neighbor, but this is not enough for cases like "Loading" (7 characters) and "ExChange" (8 characters). Increase the width of this field to 8 to fix the broken indendation. ospf6d's output before this patch: ubuntu# show ipv6 ospf6 neighbor Neighbor ID Pri DeadTime State/IfState Duration I/F[State] 2.2.2.2 1 00:00:35 ExChange/DR 00:01:15 rt1-eth0[BDR] 3.3.3.3 1 00:00:35 Loading/DR 00:01:15 rt1-eth1[BDR] 4.4.4.4 1 00:00:35 Full/DR 00:01:15 rt1-eth2[BDR] 5.5.5.5 1 00:00:35 None/DR 00:01:10 rt1-eth3[BDR] 6.6.6.6 1 00:00:35 Down/DR 00:01:15 rt1-eth4[BDR] 7.7.7.7 1 00:00:35 Attempt/DR 00:01:15 rt1-eth5[BDR] 8.8.8.8 1 00:00:35 Init/DR 00:01:10 rt1-eth6[BDR] 9.9.9.9 1 00:00:35 Twoway/DR 00:01:14 rt1-eth7[BDR] 10.10.10.10 1 00:00:35 ExStart/DR 00:01:10 rt1-eth8[BDR] ospf6d's output with this patch: ubuntu# show ipv6 ospf6 neighbor Neighbor ID Pri DeadTime State/IfState Duration I/F[State] 2.2.2.2 1 00:00:36 ExChange/DR 00:00:44 rt1-eth0[BDR] 3.3.3.3 1 00:00:36 Loading/DR 00:00:39 rt1-eth1[BDR] 4.4.4.4 1 00:00:35 Full/DR 00:00:39 rt1-eth2[BDR] 5.5.5.5 1 00:00:36 None/DR 00:00:44 rt1-eth3[BDR] 6.6.6.6 1 00:00:36 Down/DR 00:00:39 rt1-eth4[BDR] 7.7.7.7 1 00:00:36 Attempt/DR 00:00:39 rt1-eth5[BDR] 8.8.8.8 1 00:00:36 Init/DR 00:00:39 rt1-eth6[BDR] 9.9.9.9 1 00:00:35 Twoway/DR 00:00:40 rt1-eth7[BDR] 10.10.10.10 1 00:00:36 ExStart/DR 00:00:39 rt1-eth8[BDR] Signed-off-by: Renato Westphal --- ospf6d/ospf6_neighbor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index f24ee84c8e..e9bb2493ff 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -682,7 +682,7 @@ ospf6_neighbor_show (struct vty *vty, struct ospf6_neighbor *on) "I/F", "State", VNL); */ - vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s", + vty_out (vty, "%-15s %3d %11s %8s/%-12s %11s %s[%s]%s", router_id, on->priority, deadtime, ospf6_neighbor_state_str[on->state], nstate, duration, on->ospf6_if->interface->name, @@ -711,7 +711,7 @@ ospf6_neighbor_show_drchoice (struct vty *vty, struct ospf6_neighbor *on) timersub (&now, &on->last_changed, &res); timerstring (&res, duration, sizeof (duration)); - vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s", + vty_out (vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]%s", router_id, ospf6_neighbor_state_str[on->state], duration, drouter, bdrouter, on->ospf6_if->interface->name, ospf6_interface_state_str[on->ospf6_if->state], @@ -856,11 +856,11 @@ DEFUN (show_ipv6_ospf6_neighbor, } if (showfunc == ospf6_neighbor_show) - vty_out (vty, "%-15s %3s %11s %6s/%-12s %11s %s[%s]%s", + vty_out (vty, "%-15s %3s %11s %8s/%-12s %11s %s[%s]%s", "Neighbor ID", "Pri", "DeadTime", "State", "IfState", "Duration", "I/F", "State", VNL); else if (showfunc == ospf6_neighbor_show_drchoice) - vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s", + vty_out (vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]%s", "RouterID", "State", "Duration", "DR", "BDR", "I/F", "State", VNL); From bdcf7abf820d36089feb3000d630227df744858e Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 19 Dec 2016 18:30:59 -0200 Subject: [PATCH 06/35] tools: teach xml2cli.pl the "[]" notation for optional arguments Requested by Daniel Walton. Signed-off-by: Renato Westphal --- tools/xml2cli.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/xml2cli.pl b/tools/xml2cli.pl index 1b45e7f726..e0980421bd 100755 --- a/tools/xml2cli.pl +++ b/tools/xml2cli.pl @@ -141,6 +141,8 @@ sub generate_arguments { # argument is the name of the node if ($node{'input'} or $node{'type'} eq "select") { $arg_value = "argv[" . $argc . "]->arg"; + } elsif ($node{'optional'}) { + $arg_value = "(argc > " . $argc . " ? argv[" . $argc. "]->arg : NULL)"; } else { $arg_value = '"' . $node{'name'} . '"'; } @@ -196,7 +198,11 @@ sub generate_code { $helpstr .= $::options{$options_name}{'help'}; } else { $funcname .= $node{'name'} . " "; - $cmdstr .= $node{'name'} . " "; + if ($node{'optional'}) { + $cmdstr .= "[" . $node{'name'} . "] "; + } else { + $cmdstr .= $node{'name'} . " "; + } $helpstr .= "\n \"" . $node{'help'} . "\\n\""; } @@ -279,6 +285,7 @@ sub parse_tree { $node{'help'} = $xml_node->findvalue('./@help'); $node{'function'} = $xml_node->findvalue('./@function'); $node{'ifdef'} = $xml_node->findvalue('./@ifdef'); + $node{'optional'} = $xml_node->findvalue('./@optional'); # push node to stack push (@nodes, \%node); From 607c1cbfd290e4e19c983c43dae22bd9a0ab827f Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 19 Dec 2016 23:29:49 -0200 Subject: [PATCH 07/35] build/ldpd: auto-generate ldp_vty_cmds.c from ldp_vty.xml Having ldp_vty_cmds.c around as part of the git repository was being a major source of confusion. Since this file is auto-generated from ldp_vty.xml, remove it from this git repository and make it be generated on demand by adding a make target for it. This patch adds another dependency to build Quagga, namely the LibXML Perl module, which can be installed with this command: $ sudo cpan XML::LibXML Signed-off-by: Renato Westphal --- ldpd/.gitignore | 2 +- ldpd/Makefile.am | 5 + ldpd/ldp_vty_cmds.c | 1726 ------------------------------------------- 3 files changed, 6 insertions(+), 1727 deletions(-) delete mode 100644 ldpd/ldp_vty_cmds.c diff --git a/ldpd/.gitignore b/ldpd/.gitignore index be90d42119..e4ee82587a 100644 --- a/ldpd/.gitignore +++ b/ldpd/.gitignore @@ -15,4 +15,4 @@ TAGS .arch-ids *~ *.loT - +ldp_vty_cmds.c diff --git a/ldpd/Makefile.am b/ldpd/Makefile.am index c292adf6fc..e7da216a65 100644 --- a/ldpd/Makefile.am +++ b/ldpd/Makefile.am @@ -9,6 +9,8 @@ AM_CFLAGS = $(WERROR) noinst_LIBRARIES = libldp.a sbin_PROGRAMS = ldpd +BUILT_SOURCES = ldp_vty_cmds.c + libldp_a_SOURCES = \ accept.c address.c adjacency.c control.c hello.c init.c interface.c \ keepalive.c l2vpn.c labelmapping.c lde.c lde_lib.c ldpd.c \ @@ -19,6 +21,9 @@ libldp_a_SOURCES = \ noinst_HEADERS = \ control.h lde.h ldpd.h ldpe.h ldp.h log.h ldp_debug.h ldp_vty.h +ldp_vty_cmds.c: $(srcdir)/ldp_vty.xml $(srcdir)/../tools/xml2cli.pl + @PERL@ $(srcdir)/../tools/xml2cli.pl $(srcdir)/ldp_vty.xml > $@ + ldpd_SOURCES = ldpd.c ldpd_LDADD = libldp.a ../lib/libzebra.la @LIBCAP@ diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c deleted file mode 100644 index 8aa593cf2c..0000000000 --- a/ldpd/ldp_vty_cmds.c +++ /dev/null @@ -1,1726 +0,0 @@ -/* Auto-generated from ldp_vty.xml. */ -/* Do not edit! */ - -#include - -#include "command.h" -#include "vty.h" -#include "ldp_vty.h" - -DEFUN (ldp_mpls_ldp, - ldp_mpls_ldp_cmd, - "mpls ldp", - "Global MPLS configuration subcommands\n" - "Label Distribution Protocol\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_mpls_ldp (vty, args); -} - -DEFUN (ldp_l2vpn_word_type_vpls, - ldp_l2vpn_word_type_vpls_cmd, - "l2vpn WORD type vpls", - "Configure l2vpn commands\n" - "L2VPN name\n" - "L2VPN type\n" - "Virtual Private LAN Service\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "name", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_l2vpn (vty, args); -} - -DEFUN (ldp_no_mpls_ldp, - ldp_no_mpls_ldp_cmd, - "no mpls ldp", - "Negate a command or set its defaults\n" - "Global MPLS configuration subcommands\n" - "Label Distribution Protocol\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - NULL - }; - return ldp_vty_mpls_ldp (vty, args); -} - -DEFUN (ldp_no_l2vpn_word_type_vpls, - ldp_no_l2vpn_word_type_vpls_cmd, - "no l2vpn WORD type vpls", - "Negate a command or set its defaults\n" - "Configure l2vpn commands\n" - "L2VPN name\n" - "L2VPN type\n" - "Virtual Private LAN Service\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "name", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn (vty, args); -} - -DEFUN (ldp_address_family_ipv4, - ldp_address_family_ipv4_cmd, - "address-family ipv4", - "Configure Address Family and its parameters\n" - "IPv4\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "address-family", .value = "ipv4" }, - NULL - }; - return ldp_vty_address_family (vty, args); -} - -DEFUN (ldp_address_family_ipv6, - ldp_address_family_ipv6_cmd, - "address-family ipv6", - "Configure Address Family and its parameters\n" - "IPv6\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "address-family", .value = "ipv6" }, - NULL - }; - return ldp_vty_address_family (vty, args); -} - -DEFUN (ldp_discovery_hello_holdtime_disc_time, - ldp_discovery_hello_holdtime_disc_time_cmd, - "discovery hello holdtime (1-65535)", - "Configure discovery parameters\n" - "LDP Link Hellos\n" - "Hello holdtime\n" - "Time (seconds) - 65535 implies infinite\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "hello_type", .value = "hello" }, - &(struct vty_arg) { .name = "seconds", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_disc_holdtime (vty, args); -} - -DEFUN (ldp_discovery_hello_interval_disc_time, - ldp_discovery_hello_interval_disc_time_cmd, - "discovery hello interval (1-65535)", - "Configure discovery parameters\n" - "LDP Link Hellos\n" - "Hello interval\n" - "Time (seconds)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "hello_type", .value = "hello" }, - &(struct vty_arg) { .name = "seconds", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_disc_interval (vty, args); -} - -DEFUN (ldp_discovery_targeted_hello_holdtime_disc_time, - ldp_discovery_targeted_hello_holdtime_disc_time_cmd, - "discovery targeted-hello holdtime (1-65535)", - "Configure discovery parameters\n" - "LDP Targeted Hellos\n" - "Targeted hello holdtime\n" - "Time (seconds) - 65535 implies infinite\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "hello_type", .value = "targeted-hello" }, - &(struct vty_arg) { .name = "seconds", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_disc_holdtime (vty, args); -} - -DEFUN (ldp_discovery_targeted_hello_interval_disc_time, - ldp_discovery_targeted_hello_interval_disc_time_cmd, - "discovery targeted-hello interval (1-65535)", - "Configure discovery parameters\n" - "LDP Targeted Hellos\n" - "Targeted hello interval\n" - "Time (seconds)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "hello_type", .value = "targeted-hello" }, - &(struct vty_arg) { .name = "seconds", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_disc_interval (vty, args); -} - -DEFUN (ldp_dual_stack_transport_connection_prefer_ipv4, - ldp_dual_stack_transport_connection_prefer_ipv4_cmd, - "dual-stack transport-connection prefer ipv4", - "Configure dual stack parameters\n" - "Configure TCP transport parameters\n" - "Configure prefered address family for TCP transport connection with neighbor\n" - "IPv4\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_trans_pref_ipv4 (vty, args); -} - -DEFUN (ldp_dual_stack_cisco_interop, - ldp_dual_stack_cisco_interop_cmd, - "dual-stack cisco-interop", - "Configure dual stack parameters\n" - "Use Cisco non-compliant format to send and interpret the Dual-Stack capability TLV\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_ds_cisco_interop (vty, args); -} - -DEFUN (ldp_neighbor_ipv4_password_word, - ldp_neighbor_ipv4_password_word_cmd, - "neighbor A.B.C.D password WORD", - "Configure neighbor parameters\n" - "LDP Id of neighbor\n" - "Configure password for MD5 authentication\n" - "The password\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "lsr_id", .value = argv[1]->arg }, - &(struct vty_arg) { .name = "password", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_neighbor_password (vty, args); -} - -DEFUN (ldp_neighbor_ipv4_session_holdtime_session_time, - ldp_neighbor_ipv4_session_holdtime_session_time_cmd, - "neighbor A.B.C.D session holdtime (15-65535)", - "Configure neighbor parameters\n" - "LDP Id of neighbor\n" - "Configure session parameters\n" - "Configure session holdtime\n" - "Time (seconds)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "lsr_id", .value = argv[1]->arg }, - &(struct vty_arg) { .name = "seconds", .value = argv[4]->arg }, - NULL - }; - return ldp_vty_session_holdtime (vty, args); -} - -DEFUN (ldp_neighbor_ipv4_ttl_security_disable, - ldp_neighbor_ipv4_ttl_security_disable_cmd, - "neighbor A.B.C.D ttl-security disable", - "Configure neighbor parameters\n" - "LDP Id of neighbor\n" - "LDP ttl security check\n" - "Disable ttl security\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "lsr_id", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_neighbor_ttl_security (vty, args); -} - -DEFUN (ldp_neighbor_ipv4_ttl_security_hops_hops, - ldp_neighbor_ipv4_ttl_security_hops_hops_cmd, - "neighbor A.B.C.D ttl-security hops (1-254)", - "Configure neighbor parameters\n" - "LDP Id of neighbor\n" - "LDP ttl security check\n" - "IP hops\n" - "maximum number of hops\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "lsr_id", .value = argv[1]->arg }, - &(struct vty_arg) { .name = "hops", .value = argv[4]->arg }, - NULL - }; - return ldp_vty_neighbor_ttl_security (vty, args); -} - -DEFUN (ldp_router_id_ipv4, - ldp_router_id_ipv4_cmd, - "router-id A.B.C.D", - "Configure router Id\n" - "LSR Id (in form of an IPv4 address)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "addr", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_router_id (vty, args); -} - -DEFUN (ldp_no_address_family_ipv4, - ldp_no_address_family_ipv4_cmd, - "no address-family ipv4", - "Negate a command or set its defaults\n" - "Configure Address Family and its parameters\n" - "IPv4\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "address-family", .value = "ipv4" }, - NULL - }; - return ldp_vty_address_family (vty, args); -} - -DEFUN (ldp_no_address_family_ipv6, - ldp_no_address_family_ipv6_cmd, - "no address-family ipv6", - "Negate a command or set its defaults\n" - "Configure Address Family and its parameters\n" - "IPv6\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "address-family", .value = "ipv6" }, - NULL - }; - return ldp_vty_address_family (vty, args); -} - -DEFUN (ldp_no_discovery_hello_holdtime_disc_time, - ldp_no_discovery_hello_holdtime_disc_time_cmd, - "no discovery hello holdtime (1-65535)", - "Negate a command or set its defaults\n" - "Configure discovery parameters\n" - "LDP Link Hellos\n" - "Hello holdtime\n" - "Time (seconds) - 65535 implies infinite\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "hello_type", .value = "hello" }, - &(struct vty_arg) { .name = "seconds", .value = argv[4]->arg }, - NULL - }; - return ldp_vty_disc_holdtime (vty, args); -} - -DEFUN (ldp_no_discovery_hello_interval_disc_time, - ldp_no_discovery_hello_interval_disc_time_cmd, - "no discovery hello interval (1-65535)", - "Negate a command or set its defaults\n" - "Configure discovery parameters\n" - "LDP Link Hellos\n" - "Hello interval\n" - "Time (seconds)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "hello_type", .value = "hello" }, - &(struct vty_arg) { .name = "seconds", .value = argv[4]->arg }, - NULL - }; - return ldp_vty_disc_interval (vty, args); -} - -DEFUN (ldp_no_discovery_targeted_hello_holdtime_disc_time, - ldp_no_discovery_targeted_hello_holdtime_disc_time_cmd, - "no discovery targeted-hello holdtime (1-65535)", - "Negate a command or set its defaults\n" - "Configure discovery parameters\n" - "LDP Targeted Hellos\n" - "Targeted hello holdtime\n" - "Time (seconds) - 65535 implies infinite\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "hello_type", .value = "targeted-hello" }, - &(struct vty_arg) { .name = "seconds", .value = argv[4]->arg }, - NULL - }; - return ldp_vty_disc_holdtime (vty, args); -} - -DEFUN (ldp_no_discovery_targeted_hello_interval_disc_time, - ldp_no_discovery_targeted_hello_interval_disc_time_cmd, - "no discovery targeted-hello interval (1-65535)", - "Negate a command or set its defaults\n" - "Configure discovery parameters\n" - "LDP Targeted Hellos\n" - "Targeted hello interval\n" - "Time (seconds)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "hello_type", .value = "targeted-hello" }, - &(struct vty_arg) { .name = "seconds", .value = argv[4]->arg }, - NULL - }; - return ldp_vty_disc_interval (vty, args); -} - -DEFUN (ldp_no_dual_stack_transport_connection_prefer_ipv4, - ldp_no_dual_stack_transport_connection_prefer_ipv4_cmd, - "no dual-stack transport-connection prefer ipv4", - "Negate a command or set its defaults\n" - "Configure dual stack parameters\n" - "Configure TCP transport parameters\n" - "Configure prefered address family for TCP transport connection with neighbor\n" - "IPv4\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - NULL - }; - return ldp_vty_trans_pref_ipv4 (vty, args); -} - -DEFUN (ldp_no_dual_stack_cisco_interop, - ldp_no_dual_stack_cisco_interop_cmd, - "no dual-stack cisco-interop", - "Negate a command or set its defaults\n" - "Configure dual stack parameters\n" - "Use Cisco non-compliant format to send and interpret the Dual-Stack capability TLV\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - NULL - }; - return ldp_vty_ds_cisco_interop (vty, args); -} - -DEFUN (ldp_no_neighbor_ipv4_password_word, - ldp_no_neighbor_ipv4_password_word_cmd, - "no neighbor A.B.C.D password WORD", - "Negate a command or set its defaults\n" - "Configure neighbor parameters\n" - "LDP Id of neighbor\n" - "Configure password for MD5 authentication\n" - "The password\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "lsr_id", .value = argv[2]->arg }, - &(struct vty_arg) { .name = "password", .value = argv[4]->arg }, - NULL - }; - return ldp_vty_neighbor_password (vty, args); -} - -DEFUN (ldp_no_neighbor_ipv4_session_holdtime_session_time, - ldp_no_neighbor_ipv4_session_holdtime_session_time_cmd, - "no neighbor A.B.C.D session holdtime (15-65535)", - "Negate a command or set its defaults\n" - "Configure neighbor parameters\n" - "LDP Id of neighbor\n" - "Configure session parameters\n" - "Configure session holdtime\n" - "Time (seconds)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "lsr_id", .value = argv[2]->arg }, - &(struct vty_arg) { .name = "seconds", .value = argv[5]->arg }, - NULL - }; - return ldp_vty_session_holdtime (vty, args); -} - -DEFUN (ldp_no_neighbor_ipv4_ttl_security_disable, - ldp_no_neighbor_ipv4_ttl_security_disable_cmd, - "no neighbor A.B.C.D ttl-security disable", - "Negate a command or set its defaults\n" - "Configure neighbor parameters\n" - "LDP Id of neighbor\n" - "LDP ttl security check\n" - "Disable ttl security\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "lsr_id", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_neighbor_ttl_security (vty, args); -} - -DEFUN (ldp_no_neighbor_ipv4_ttl_security_hops_hops, - ldp_no_neighbor_ipv4_ttl_security_hops_hops_cmd, - "no neighbor A.B.C.D ttl-security hops (1-254)", - "Negate a command or set its defaults\n" - "Configure neighbor parameters\n" - "LDP Id of neighbor\n" - "LDP ttl security check\n" - "IP hops\n" - "maximum number of hops\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "lsr_id", .value = argv[2]->arg }, - &(struct vty_arg) { .name = "hops", .value = argv[5]->arg }, - NULL - }; - return ldp_vty_neighbor_ttl_security (vty, args); -} - -DEFUN (ldp_no_router_id_ipv4, - ldp_no_router_id_ipv4_cmd, - "no router-id A.B.C.D", - "Negate a command or set its defaults\n" - "Configure router Id\n" - "LSR Id (in form of an IPv4 address)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "addr", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_router_id (vty, args); -} - -DEFUN (ldp_discovery_targeted_hello_accept, - ldp_discovery_targeted_hello_accept_cmd, - "discovery targeted-hello accept", - "Configure discovery parameters\n" - "LDP Targeted Hellos\n" - "Accept and respond to targeted hellos\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "hello_type", .value = "targeted-hello" }, - NULL - }; - return ldp_vty_targeted_hello_accept (vty, args); -} - -DEFUN (ldp_label_local_advertise_explicit_null, - ldp_label_local_advertise_explicit_null_cmd, - "label local advertise explicit-null", - "Configure label control and policies\n" - "Configure local label control and policies\n" - "Configure outbound label advertisement control\n" - "Configure explicit-null advertisement\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_explicit_null (vty, args); -} - -DEFUN (ldp_ttl_security_disable, - ldp_ttl_security_disable_cmd, - "ttl-security disable", - "LDP ttl security check\n" - "Disable ttl security\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_ttl_security (vty, args); -} - -DEFUN (ldp_session_holdtime_session_time, - ldp_session_holdtime_session_time_cmd, - "session holdtime (15-65535)", - "Configure session parameters\n" - "Configure session holdtime\n" - "Time (seconds)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "seconds", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_session_holdtime (vty, args); -} - -DEFUN (ldp_interface_ifname, - ldp_interface_ifname_cmd, - "interface IFNAME", - "Enable LDP on an interface and enter interface submode\n" - "Interface's name\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "ifname", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_interface (vty, args); -} - -DEFUN (ldp_discovery_transport_address_ipv4, - ldp_discovery_transport_address_ipv4_cmd, - "discovery transport-address A.B.C.D", - "Configure discovery parameters\n" - "Specify transport address for TCP connection\n" - "IP address to be used as transport address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "addr", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_trans_addr (vty, args); -} - -DEFUN (ldp_neighbor_ipv4_targeted, - ldp_neighbor_ipv4_targeted_cmd, - "neighbor A.B.C.D targeted", - "Configure neighbor parameters\n" - "IP address of neighbor\n" - "Establish targeted session\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "addr", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_neighbor_targeted (vty, args); -} - -DEFUN (ldp_no_discovery_targeted_hello_accept, - ldp_no_discovery_targeted_hello_accept_cmd, - "no discovery targeted-hello accept", - "Negate a command or set its defaults\n" - "Configure discovery parameters\n" - "LDP Targeted Hellos\n" - "Accept and respond to targeted hellos\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "hello_type", .value = "targeted-hello" }, - NULL - }; - return ldp_vty_targeted_hello_accept (vty, args); -} - -DEFUN (ldp_no_label_local_advertise_explicit_null, - ldp_no_label_local_advertise_explicit_null_cmd, - "no label local advertise explicit-null", - "Negate a command or set its defaults\n" - "Configure label control and policies\n" - "Configure local label control and policies\n" - "Configure outbound label advertisement control\n" - "Configure explicit-null advertisement\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - NULL - }; - return ldp_vty_explicit_null (vty, args); -} - -DEFUN (ldp_no_ttl_security_disable, - ldp_no_ttl_security_disable_cmd, - "no ttl-security disable", - "Negate a command or set its defaults\n" - "LDP ttl security check\n" - "Disable ttl security\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - NULL - }; - return ldp_vty_ttl_security (vty, args); -} - -DEFUN (ldp_no_session_holdtime_session_time, - ldp_no_session_holdtime_session_time_cmd, - "no session holdtime (15-65535)", - "Negate a command or set its defaults\n" - "Configure session parameters\n" - "Configure session holdtime\n" - "Time (seconds)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "seconds", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_session_holdtime (vty, args); -} - -DEFUN (ldp_no_interface_ifname, - ldp_no_interface_ifname_cmd, - "no interface IFNAME", - "Negate a command or set its defaults\n" - "Enable LDP on an interface and enter interface submode\n" - "Interface's name\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "ifname", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_interface (vty, args); -} - -DEFUN (ldp_no_discovery_transport_address_ipv4, - ldp_no_discovery_transport_address_ipv4_cmd, - "no discovery transport-address A.B.C.D", - "Negate a command or set its defaults\n" - "Configure discovery parameters\n" - "Specify transport address for TCP connection\n" - "IP address to be used as transport address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "addr", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_trans_addr (vty, args); -} - -DEFUN (ldp_no_neighbor_ipv4_targeted, - ldp_no_neighbor_ipv4_targeted_cmd, - "no neighbor A.B.C.D targeted", - "Negate a command or set its defaults\n" - "Configure neighbor parameters\n" - "IP address of neighbor\n" - "Establish targeted session\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "addr", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_neighbor_targeted (vty, args); -} - -DEFUN (ldp_discovery_transport_address_ipv6, - ldp_discovery_transport_address_ipv6_cmd, - "discovery transport-address X:X::X:X", - "Configure discovery parameters\n" - "Specify transport address for TCP connection\n" - "IPv6 address to be used as transport address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "addr", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_trans_addr (vty, args); -} - -DEFUN (ldp_neighbor_ipv6_targeted, - ldp_neighbor_ipv6_targeted_cmd, - "neighbor X:X::X:X targeted", - "Configure neighbor parameters\n" - "IPv6 address of neighbor\n" - "Establish targeted session\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "addr", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_neighbor_targeted (vty, args); -} - -DEFUN (ldp_no_discovery_transport_address_ipv6, - ldp_no_discovery_transport_address_ipv6_cmd, - "no discovery transport-address X:X::X:X", - "Negate a command or set its defaults\n" - "Configure discovery parameters\n" - "Specify transport address for TCP connection\n" - "IPv6 address to be used as transport address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "addr", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_trans_addr (vty, args); -} - -DEFUN (ldp_no_neighbor_ipv6_targeted, - ldp_no_neighbor_ipv6_targeted_cmd, - "no neighbor X:X::X:X targeted", - "Negate a command or set its defaults\n" - "Configure neighbor parameters\n" - "IPv6 address of neighbor\n" - "Establish targeted session\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "addr", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_neighbor_targeted (vty, args); -} - -DEFUN (ldp_bridge_ifname, - ldp_bridge_ifname_cmd, - "bridge IFNAME", - "Bridge interface\n" - "Interface's name\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "ifname", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_l2vpn_bridge (vty, args); -} - -DEFUN (ldp_mtu_mtu, - ldp_mtu_mtu_cmd, - "mtu (1500-9180)", - "set Maximum Transmission Unit\n" - "Maximum Transmission Unit value\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "mtu", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_l2vpn_mtu (vty, args); -} - -DEFUN (ldp_member_interface_ifname, - ldp_member_interface_ifname_cmd, - "member interface IFNAME", - "L2VPN member configuration\n" - "Local interface\n" - "Interface's name\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "ifname", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_interface (vty, args); -} - -DEFUN (ldp_member_pseudowire_ifname, - ldp_member_pseudowire_ifname_cmd, - "member pseudowire IFNAME", - "L2VPN member configuration\n" - "Pseudowire interface\n" - "Interface's name\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "ifname", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_pseudowire (vty, args); -} - -DEFUN (ldp_vc_type_pwtype, - ldp_vc_type_pwtype_cmd, - "vc type ", - "Virtual Circuit options\n" - "Virtual Circuit type to use\n" - "Ethernet (type 5)\n" - "Ethernet-tagged (type 4)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_pwtype (vty, args); -} - -DEFUN (ldp_no_bridge_ifname, - ldp_no_bridge_ifname_cmd, - "no bridge IFNAME", - "Negate a command or set its defaults\n" - "Bridge interface\n" - "Interface's name\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "ifname", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_bridge (vty, args); -} - -DEFUN (ldp_no_mtu_mtu, - ldp_no_mtu_mtu_cmd, - "no mtu (1500-9180)", - "Negate a command or set its defaults\n" - "set Maximum Transmission Unit\n" - "Maximum Transmission Unit value\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "mtu", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_mtu (vty, args); -} - -DEFUN (ldp_no_member_interface_ifname, - ldp_no_member_interface_ifname_cmd, - "no member interface IFNAME", - "Negate a command or set its defaults\n" - "L2VPN member configuration\n" - "Local interface\n" - "Interface's name\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "ifname", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_l2vpn_interface (vty, args); -} - -DEFUN (ldp_no_member_pseudowire_ifname, - ldp_no_member_pseudowire_ifname_cmd, - "no member pseudowire IFNAME", - "Negate a command or set its defaults\n" - "L2VPN member configuration\n" - "Pseudowire interface\n" - "Interface's name\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "ifname", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_l2vpn_pseudowire (vty, args); -} - -DEFUN (ldp_no_vc_type_pwtype, - ldp_no_vc_type_pwtype_cmd, - "no vc type ", - "Negate a command or set its defaults\n" - "Virtual Circuit options\n" - "Virtual Circuit type to use\n" - "Ethernet (type 5)\n" - "Ethernet-tagged (type 4)\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_l2vpn_pwtype (vty, args); -} - -DEFUN (ldp_control_word_cword, - ldp_control_word_cword_cmd, - "control-word ", - "Control-word options\n" - "Exclude control-word in pseudowire packets\n" - "Include control-word in pseudowire packets\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "preference", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_l2vpn_pw_cword (vty, args); -} - -DEFUN (ldp_neighbor_address_addr, - ldp_neighbor_address_addr_cmd, - "neighbor address ", - "Remote endpoint configuration\n" - "Specify the IPv4 or IPv6 address of the remote endpoint\n" - "IPv4 address\n" - "IPv6 address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "addr", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_pw_nbr_addr (vty, args); -} - -DEFUN (ldp_neighbor_lsr_id_ipv4, - ldp_neighbor_lsr_id_ipv4_cmd, - "neighbor lsr-id A.B.C.D", - "Remote endpoint configuration\n" - "Specify the LSR-ID of the remote endpoint\n" - "IPv4 address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "lsr-id", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_pw_nbr_id (vty, args); -} - -DEFUN (ldp_pw_id_pwid, - ldp_pw_id_pwid_cmd, - "pw-id (1-4294967295)", - "Set the Virtual Circuit ID\n" - "Virtual Circuit ID value\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "pwid", .value = argv[1]->arg }, - NULL - }; - return ldp_vty_l2vpn_pw_pwid (vty, args); -} - -DEFUN (ldp_pw_status_disable, - ldp_pw_status_disable_cmd, - "pw-status disable", - "Configure PW status\n" - "Disable PW status\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_l2vpn_pw_pwstatus (vty, args); -} - -DEFUN (ldp_no_control_word_cword, - ldp_no_control_word_cword_cmd, - "no control-word ", - "Negate a command or set its defaults\n" - "Control-word options\n" - "Exclude control-word in pseudowire packets\n" - "Include control-word in pseudowire packets\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "preference", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_pw_cword (vty, args); -} - -DEFUN (ldp_no_neighbor_address_addr, - ldp_no_neighbor_address_addr_cmd, - "no neighbor address ", - "Negate a command or set its defaults\n" - "Remote endpoint configuration\n" - "Specify the IPv4 or IPv6 address of the remote endpoint\n" - "IPv4 address\n" - "IPv6 address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "addr", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_l2vpn_pw_nbr_addr (vty, args); -} - -DEFUN (ldp_no_neighbor_lsr_id_ipv4, - ldp_no_neighbor_lsr_id_ipv4_cmd, - "no neighbor lsr-id A.B.C.D", - "Negate a command or set its defaults\n" - "Remote endpoint configuration\n" - "Specify the LSR-ID of the remote endpoint\n" - "IPv4 address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "lsr-id", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_l2vpn_pw_nbr_id (vty, args); -} - -DEFUN (ldp_no_pw_id_pwid, - ldp_no_pw_id_pwid_cmd, - "no pw-id (1-4294967295)", - "Negate a command or set its defaults\n" - "Set the Virtual Circuit ID\n" - "Virtual Circuit ID value\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "pwid", .value = argv[2]->arg }, - NULL - }; - return ldp_vty_l2vpn_pw_pwid (vty, args); -} - -DEFUN (ldp_no_pw_status_disable, - ldp_no_pw_status_disable_cmd, - "no pw-status disable", - "Negate a command or set its defaults\n" - "Configure PW status\n" - "Disable PW status\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - NULL - }; - return ldp_vty_l2vpn_pw_pwstatus (vty, args); -} - -DEFUN (ldp_show_mpls_ldp_neighbor, - ldp_show_mpls_ldp_neighbor_cmd, - "show mpls ldp neighbor", - "Show running system information\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Neighbor information\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_show_neighbor (vty, args); -} - -DEFUN (ldp_show_mpls_ldp_binding, - ldp_show_mpls_ldp_binding_cmd, - "show mpls ldp binding", - "Show running system information\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Label Information Base (LIB) information\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_show_binding (vty, args); -} - -DEFUN (ldp_show_mpls_ldp_discovery, - ldp_show_mpls_ldp_discovery_cmd, - "show mpls ldp discovery", - "Show running system information\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Discovery Hello Information\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_show_discovery (vty, args); -} - -DEFUN (ldp_show_mpls_ldp_interface, - ldp_show_mpls_ldp_interface_cmd, - "show mpls ldp interface", - "Show running system information\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "interface information\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_show_interface (vty, args); -} - -DEFUN (ldp_show_mpls_ldp_address_family_binding, - ldp_show_mpls_ldp_address_family_binding_cmd, - "show mpls ldp binding", - "Show running system information\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "IPv4 Address Family\n" - "IPv6 Address Family\n" - "Label Information Base (LIB) information\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "address-family", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_show_binding (vty, args); -} - -DEFUN (ldp_show_mpls_ldp_address_family_discovery, - ldp_show_mpls_ldp_address_family_discovery_cmd, - "show mpls ldp discovery", - "Show running system information\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "IPv4 Address Family\n" - "IPv6 Address Family\n" - "Discovery Hello Information\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "address-family", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_show_discovery (vty, args); -} - -DEFUN (ldp_show_mpls_ldp_address_family_interface, - ldp_show_mpls_ldp_address_family_interface_cmd, - "show mpls ldp interface", - "Show running system information\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "IPv4 Address Family\n" - "IPv6 Address Family\n" - "interface information\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "address-family", .value = argv[3]->arg }, - NULL - }; - return ldp_vty_show_interface (vty, args); -} - -DEFUN (ldp_show_l2vpn_atom_binding, - ldp_show_l2vpn_atom_binding_cmd, - "show l2vpn atom binding", - "Show running system information\n" - "Show information about Layer2 VPN\n" - "Show Any Transport over MPLS information\n" - "Show AToM label binding information\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_show_atom_binding (vty, args); -} - -DEFUN (ldp_show_l2vpn_atom_vc, - ldp_show_l2vpn_atom_vc_cmd, - "show l2vpn atom vc", - "Show running system information\n" - "Show information about Layer2 VPN\n" - "Show Any Transport over MPLS information\n" - "Show AToM virtual circuit information\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_show_atom_vc (vty, args); -} - -DEFUN (ldp_show_debugging_mpls_ldp, - ldp_show_debugging_mpls_ldp_cmd, - "show debugging mpls ldp", - "Show running system information\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_show_debugging (vty, args); -} - -DEFUN (ldp_clear_mpls_ldp_neighbor, - ldp_clear_mpls_ldp_neighbor_cmd, - "clear mpls ldp neighbor", - "Reset functions\n" - "Reset MPLS statistical information\n" - "Clear LDP state\n" - "Clear LDP neighbor sessions\n") -{ - struct vty_arg *args[] = { NULL }; - return ldp_vty_clear_nbr (vty, args); -} - -DEFUN (ldp_clear_mpls_ldp_neighbor_addr, - ldp_clear_mpls_ldp_neighbor_addr_cmd, - "clear mpls ldp neighbor ", - "Reset functions\n" - "Reset MPLS statistical information\n" - "Clear LDP state\n" - "Clear LDP neighbor sessions\n" - "IPv4 address\n" - "IPv6 address\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "addr", .value = argv[4]->arg }, - NULL - }; - return ldp_vty_clear_nbr (vty, args); -} - -DEFUN (ldp_debug_mpls_ldp_discovery_hello_dir, - ldp_debug_mpls_ldp_discovery_hello_dir_cmd, - "debug mpls ldp discovery hello ", - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Discovery messages\n" - "Discovery hello message\n" - "Received messages\n" - "Sent messages\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = "discovery" }, - &(struct vty_arg) { .name = "dir", .value = argv[5]->arg }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_debug_mpls_ldp_errors, - ldp_debug_mpls_ldp_errors_cmd, - "debug mpls ldp errors", - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Errors\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = "errors" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_debug_mpls_ldp_event, - ldp_debug_mpls_ldp_event_cmd, - "debug mpls ldp event", - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "LDP event information\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = "event" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_debug_mpls_ldp_messages_recv, - ldp_debug_mpls_ldp_messages_recv_cmd, - "debug mpls ldp messages recv", - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Messages\n" - "Received messages, excluding periodic Keep Alives\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = "messages" }, - &(struct vty_arg) { .name = "dir", .value = "recv" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_debug_mpls_ldp_messages_recv_all, - ldp_debug_mpls_ldp_messages_recv_all_cmd, - "debug mpls ldp messages recv all", - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Messages\n" - "Received messages, excluding periodic Keep Alives\n" - "Received messages, including periodic Keep Alives\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = "messages" }, - &(struct vty_arg) { .name = "dir", .value = "recv" }, - &(struct vty_arg) { .name = "all", .value = "all" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_debug_mpls_ldp_messages_sent, - ldp_debug_mpls_ldp_messages_sent_cmd, - "debug mpls ldp messages sent", - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Messages\n" - "Sent messages, excluding periodic Keep Alives\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = "messages" }, - &(struct vty_arg) { .name = "dir", .value = "sent" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_debug_mpls_ldp_messages_sent_all, - ldp_debug_mpls_ldp_messages_sent_all_cmd, - "debug mpls ldp messages sent all", - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Messages\n" - "Sent messages, excluding periodic Keep Alives\n" - "Sent messages, including periodic Keep Alives\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = "messages" }, - &(struct vty_arg) { .name = "dir", .value = "sent" }, - &(struct vty_arg) { .name = "all", .value = "all" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_debug_mpls_ldp_zebra, - ldp_debug_mpls_ldp_zebra_cmd, - "debug mpls ldp zebra", - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "LDP zebra information\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "type", .value = "zebra" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_no_debug_mpls_ldp_discovery_hello_dir, - ldp_no_debug_mpls_ldp_discovery_hello_dir_cmd, - "no debug mpls ldp discovery hello ", - "Negate a command or set its defaults\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Discovery messages\n" - "Discovery hello message\n" - "Received messages\n" - "Sent messages\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = "discovery" }, - &(struct vty_arg) { .name = "dir", .value = argv[6]->arg }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_no_debug_mpls_ldp_errors, - ldp_no_debug_mpls_ldp_errors_cmd, - "no debug mpls ldp errors", - "Negate a command or set its defaults\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Errors\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = "errors" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_no_debug_mpls_ldp_event, - ldp_no_debug_mpls_ldp_event_cmd, - "no debug mpls ldp event", - "Negate a command or set its defaults\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "LDP event information\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = "event" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_no_debug_mpls_ldp_messages_recv, - ldp_no_debug_mpls_ldp_messages_recv_cmd, - "no debug mpls ldp messages recv", - "Negate a command or set its defaults\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Messages\n" - "Received messages, excluding periodic Keep Alives\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = "messages" }, - &(struct vty_arg) { .name = "dir", .value = "recv" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_no_debug_mpls_ldp_messages_recv_all, - ldp_no_debug_mpls_ldp_messages_recv_all_cmd, - "no debug mpls ldp messages recv all", - "Negate a command or set its defaults\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Messages\n" - "Received messages, excluding periodic Keep Alives\n" - "Received messages, including periodic Keep Alives\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = "messages" }, - &(struct vty_arg) { .name = "dir", .value = "recv" }, - &(struct vty_arg) { .name = "all", .value = "all" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_no_debug_mpls_ldp_messages_sent, - ldp_no_debug_mpls_ldp_messages_sent_cmd, - "no debug mpls ldp messages sent", - "Negate a command or set its defaults\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Messages\n" - "Sent messages, excluding periodic Keep Alives\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = "messages" }, - &(struct vty_arg) { .name = "dir", .value = "sent" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_no_debug_mpls_ldp_messages_sent_all, - ldp_no_debug_mpls_ldp_messages_sent_all_cmd, - "no debug mpls ldp messages sent all", - "Negate a command or set its defaults\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "Messages\n" - "Sent messages, excluding periodic Keep Alives\n" - "Sent messages, including periodic Keep Alives\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = "messages" }, - &(struct vty_arg) { .name = "dir", .value = "sent" }, - &(struct vty_arg) { .name = "all", .value = "all" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -DEFUN (ldp_no_debug_mpls_ldp_zebra, - ldp_no_debug_mpls_ldp_zebra_cmd, - "no debug mpls ldp zebra", - "Negate a command or set its defaults\n" - "Debugging functions\n" - "MPLS information\n" - "Label Distribution Protocol\n" - "LDP zebra information\n") -{ - struct vty_arg *args[] = - { - &(struct vty_arg) { .name = "no", .value = "no" }, - &(struct vty_arg) { .name = "type", .value = "zebra" }, - NULL - }; - return ldp_vty_debug (vty, args); -} - -void -ldp_vty_init (void) -{ - install_element (CONFIG_NODE, &ldp_mpls_ldp_cmd); - install_element (CONFIG_NODE, &ldp_l2vpn_word_type_vpls_cmd); - install_element (CONFIG_NODE, &ldp_no_mpls_ldp_cmd); - install_element (CONFIG_NODE, &ldp_no_l2vpn_word_type_vpls_cmd); - install_element (CONFIG_NODE, &ldp_debug_mpls_ldp_discovery_hello_dir_cmd); - install_element (CONFIG_NODE, &ldp_debug_mpls_ldp_errors_cmd); - install_element (CONFIG_NODE, &ldp_debug_mpls_ldp_event_cmd); - install_element (CONFIG_NODE, &ldp_debug_mpls_ldp_messages_recv_cmd); - install_element (CONFIG_NODE, &ldp_debug_mpls_ldp_messages_recv_all_cmd); - install_element (CONFIG_NODE, &ldp_debug_mpls_ldp_messages_sent_cmd); - install_element (CONFIG_NODE, &ldp_debug_mpls_ldp_messages_sent_all_cmd); - install_element (CONFIG_NODE, &ldp_debug_mpls_ldp_zebra_cmd); - install_element (CONFIG_NODE, &ldp_no_debug_mpls_ldp_discovery_hello_dir_cmd); - install_element (CONFIG_NODE, &ldp_no_debug_mpls_ldp_errors_cmd); - install_element (CONFIG_NODE, &ldp_no_debug_mpls_ldp_event_cmd); - install_element (CONFIG_NODE, &ldp_no_debug_mpls_ldp_messages_recv_cmd); - install_element (CONFIG_NODE, &ldp_no_debug_mpls_ldp_messages_recv_all_cmd); - install_element (CONFIG_NODE, &ldp_no_debug_mpls_ldp_messages_sent_cmd); - install_element (CONFIG_NODE, &ldp_no_debug_mpls_ldp_messages_sent_all_cmd); - install_element (CONFIG_NODE, &ldp_no_debug_mpls_ldp_zebra_cmd); - install_node (&ldp_node, ldp_config_write); - install_default (LDP_NODE); - install_element (LDP_NODE, &ldp_address_family_ipv4_cmd); - install_element (LDP_NODE, &ldp_address_family_ipv6_cmd); - install_element (LDP_NODE, &ldp_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_NODE, &ldp_discovery_hello_interval_disc_time_cmd); - install_element (LDP_NODE, &ldp_discovery_targeted_hello_holdtime_disc_time_cmd); - install_element (LDP_NODE, &ldp_discovery_targeted_hello_interval_disc_time_cmd); - install_element (LDP_NODE, &ldp_dual_stack_transport_connection_prefer_ipv4_cmd); - install_element (LDP_NODE, &ldp_dual_stack_cisco_interop_cmd); - install_element (LDP_NODE, &ldp_neighbor_ipv4_password_word_cmd); - install_element (LDP_NODE, &ldp_neighbor_ipv4_session_holdtime_session_time_cmd); - install_element (LDP_NODE, &ldp_neighbor_ipv4_ttl_security_disable_cmd); - install_element (LDP_NODE, &ldp_neighbor_ipv4_ttl_security_hops_hops_cmd); - install_element (LDP_NODE, &ldp_router_id_ipv4_cmd); - install_element (LDP_NODE, &ldp_no_address_family_ipv4_cmd); - install_element (LDP_NODE, &ldp_no_address_family_ipv6_cmd); - install_element (LDP_NODE, &ldp_no_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_NODE, &ldp_no_discovery_hello_interval_disc_time_cmd); - install_element (LDP_NODE, &ldp_no_discovery_targeted_hello_holdtime_disc_time_cmd); - install_element (LDP_NODE, &ldp_no_discovery_targeted_hello_interval_disc_time_cmd); - install_element (LDP_NODE, &ldp_no_dual_stack_transport_connection_prefer_ipv4_cmd); - install_element (LDP_NODE, &ldp_no_dual_stack_cisco_interop_cmd); - install_element (LDP_NODE, &ldp_no_neighbor_ipv4_password_word_cmd); - install_element (LDP_NODE, &ldp_no_neighbor_ipv4_session_holdtime_session_time_cmd); - install_element (LDP_NODE, &ldp_no_neighbor_ipv4_ttl_security_disable_cmd); - install_element (LDP_NODE, &ldp_no_neighbor_ipv4_ttl_security_hops_hops_cmd); - install_element (LDP_NODE, &ldp_no_router_id_ipv4_cmd); - install_node (&ldp_ipv4_node, NULL); - install_default (LDP_IPV4_NODE); - install_element (LDP_IPV4_NODE, &ldp_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_discovery_hello_interval_disc_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_discovery_targeted_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_discovery_targeted_hello_interval_disc_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_discovery_targeted_hello_accept_cmd); - install_element (LDP_IPV4_NODE, &ldp_label_local_advertise_explicit_null_cmd); - install_element (LDP_IPV4_NODE, &ldp_ttl_security_disable_cmd); - install_element (LDP_IPV4_NODE, &ldp_session_holdtime_session_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_interface_ifname_cmd); - install_element (LDP_IPV4_NODE, &ldp_discovery_transport_address_ipv4_cmd); - install_element (LDP_IPV4_NODE, &ldp_neighbor_ipv4_targeted_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_discovery_hello_interval_disc_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_discovery_targeted_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_discovery_targeted_hello_interval_disc_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_discovery_targeted_hello_accept_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_label_local_advertise_explicit_null_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_ttl_security_disable_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_session_holdtime_session_time_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_interface_ifname_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_discovery_transport_address_ipv4_cmd); - install_element (LDP_IPV4_NODE, &ldp_no_neighbor_ipv4_targeted_cmd); - install_node (&ldp_ipv6_node, NULL); - install_default (LDP_IPV6_NODE); - install_element (LDP_IPV6_NODE, &ldp_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_discovery_hello_interval_disc_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_discovery_targeted_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_discovery_targeted_hello_interval_disc_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_discovery_targeted_hello_accept_cmd); - install_element (LDP_IPV6_NODE, &ldp_label_local_advertise_explicit_null_cmd); - install_element (LDP_IPV6_NODE, &ldp_ttl_security_disable_cmd); - install_element (LDP_IPV6_NODE, &ldp_session_holdtime_session_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_interface_ifname_cmd); - install_element (LDP_IPV6_NODE, &ldp_discovery_transport_address_ipv6_cmd); - install_element (LDP_IPV6_NODE, &ldp_neighbor_ipv6_targeted_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_discovery_hello_interval_disc_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_discovery_targeted_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_discovery_targeted_hello_interval_disc_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_discovery_targeted_hello_accept_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_label_local_advertise_explicit_null_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_ttl_security_disable_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_session_holdtime_session_time_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_interface_ifname_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_discovery_transport_address_ipv6_cmd); - install_element (LDP_IPV6_NODE, &ldp_no_neighbor_ipv6_targeted_cmd); - install_node (&ldp_ipv4_iface_node, NULL); - install_default (LDP_IPV4_IFACE_NODE); - install_element (LDP_IPV4_IFACE_NODE, &ldp_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV4_IFACE_NODE, &ldp_discovery_hello_interval_disc_time_cmd); - install_element (LDP_IPV4_IFACE_NODE, &ldp_no_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV4_IFACE_NODE, &ldp_no_discovery_hello_interval_disc_time_cmd); - install_node (&ldp_ipv6_iface_node, NULL); - install_default (LDP_IPV6_IFACE_NODE); - install_element (LDP_IPV6_IFACE_NODE, &ldp_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV6_IFACE_NODE, &ldp_discovery_hello_interval_disc_time_cmd); - install_element (LDP_IPV6_IFACE_NODE, &ldp_no_discovery_hello_holdtime_disc_time_cmd); - install_element (LDP_IPV6_IFACE_NODE, &ldp_no_discovery_hello_interval_disc_time_cmd); - install_node (&ldp_l2vpn_node, ldp_l2vpn_config_write); - install_default (LDP_L2VPN_NODE); - install_element (LDP_L2VPN_NODE, &ldp_bridge_ifname_cmd); - install_element (LDP_L2VPN_NODE, &ldp_mtu_mtu_cmd); - install_element (LDP_L2VPN_NODE, &ldp_member_interface_ifname_cmd); - install_element (LDP_L2VPN_NODE, &ldp_member_pseudowire_ifname_cmd); - install_element (LDP_L2VPN_NODE, &ldp_vc_type_pwtype_cmd); - install_element (LDP_L2VPN_NODE, &ldp_no_bridge_ifname_cmd); - install_element (LDP_L2VPN_NODE, &ldp_no_mtu_mtu_cmd); - install_element (LDP_L2VPN_NODE, &ldp_no_member_interface_ifname_cmd); - install_element (LDP_L2VPN_NODE, &ldp_no_member_pseudowire_ifname_cmd); - install_element (LDP_L2VPN_NODE, &ldp_no_vc_type_pwtype_cmd); - install_node (&ldp_pseudowire_node, NULL); - install_default (LDP_PSEUDOWIRE_NODE); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_control_word_cword_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_neighbor_address_addr_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_neighbor_lsr_id_ipv4_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_pw_id_pwid_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_pw_status_disable_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_no_control_word_cword_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_no_neighbor_address_addr_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_no_neighbor_lsr_id_ipv4_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_no_pw_id_pwid_cmd); - install_element (LDP_PSEUDOWIRE_NODE, &ldp_no_pw_status_disable_cmd); - install_node (&ldp_debug_node, ldp_debug_config_write); - install_element (ENABLE_NODE, &ldp_debug_mpls_ldp_discovery_hello_dir_cmd); - install_element (ENABLE_NODE, &ldp_debug_mpls_ldp_errors_cmd); - install_element (ENABLE_NODE, &ldp_debug_mpls_ldp_event_cmd); - install_element (ENABLE_NODE, &ldp_debug_mpls_ldp_messages_recv_cmd); - install_element (ENABLE_NODE, &ldp_debug_mpls_ldp_messages_recv_all_cmd); - install_element (ENABLE_NODE, &ldp_debug_mpls_ldp_messages_sent_cmd); - install_element (ENABLE_NODE, &ldp_debug_mpls_ldp_messages_sent_all_cmd); - install_element (ENABLE_NODE, &ldp_debug_mpls_ldp_zebra_cmd); - install_element (ENABLE_NODE, &ldp_no_debug_mpls_ldp_discovery_hello_dir_cmd); - install_element (ENABLE_NODE, &ldp_no_debug_mpls_ldp_errors_cmd); - install_element (ENABLE_NODE, &ldp_no_debug_mpls_ldp_event_cmd); - install_element (ENABLE_NODE, &ldp_no_debug_mpls_ldp_messages_recv_cmd); - install_element (ENABLE_NODE, &ldp_no_debug_mpls_ldp_messages_recv_all_cmd); - install_element (ENABLE_NODE, &ldp_no_debug_mpls_ldp_messages_sent_cmd); - install_element (ENABLE_NODE, &ldp_no_debug_mpls_ldp_messages_sent_all_cmd); - install_element (ENABLE_NODE, &ldp_no_debug_mpls_ldp_zebra_cmd); - install_element (VIEW_NODE, &ldp_show_mpls_ldp_neighbor_cmd); - install_element (VIEW_NODE, &ldp_show_mpls_ldp_binding_cmd); - install_element (VIEW_NODE, &ldp_show_mpls_ldp_discovery_cmd); - install_element (VIEW_NODE, &ldp_show_mpls_ldp_interface_cmd); - install_element (VIEW_NODE, &ldp_show_mpls_ldp_address_family_binding_cmd); - install_element (VIEW_NODE, &ldp_show_mpls_ldp_address_family_discovery_cmd); - install_element (VIEW_NODE, &ldp_show_mpls_ldp_address_family_interface_cmd); - install_element (VIEW_NODE, &ldp_show_l2vpn_atom_binding_cmd); - install_element (VIEW_NODE, &ldp_show_l2vpn_atom_vc_cmd); - install_element (VIEW_NODE, &ldp_show_debugging_mpls_ldp_cmd); - install_element (VIEW_NODE, &ldp_clear_mpls_ldp_neighbor_cmd); - install_element (VIEW_NODE, &ldp_clear_mpls_ldp_neighbor_addr_cmd); -} \ No newline at end of file From d3e1887ad6b5ae2199710b3278c277838e6ef913 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Sat, 3 Dec 2016 21:14:44 -0200 Subject: [PATCH 08/35] ldpd: use red-black trees to store 'lde_map' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/l2vpn.c | 4 ++-- ldpd/lde.c | 17 ++++++++++++++--- ldpd/lde.h | 9 ++++++--- ldpd/lde_lib.c | 18 +++++++++--------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index 851ff77b73..c0f6586854 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -459,7 +459,7 @@ l2vpn_binding_ctl(pid_t pid) fn = (struct fec_node *)f; if (fn->local_label == NO_LABEL && - LIST_EMPTY(&fn->downstream)) + RB_EMPTY(&fn->downstream)) continue; memset(&pwctl, 0, sizeof(pwctl)); @@ -477,7 +477,7 @@ l2vpn_binding_ctl(pid_t pid) } else pwctl.local_label = NO_LABEL; - LIST_FOREACH(me, &fn->downstream, entry) + RB_FOREACH(me, lde_map_head, &fn->downstream) if (f->u.pwid.lsr_id.s_addr == me->nexthop->id.s_addr) break; diff --git a/ldpd/lde.c b/ldpd/lde.c index 67ed982ec5..a1309c6448 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -45,12 +45,14 @@ static struct lde_nbr *lde_nbr_find(uint32_t); static void lde_nbr_clear(void); static void lde_nbr_addr_update(struct lde_nbr *, struct lde_addr *, int); +static __inline int lde_map_compare(struct lde_map *, struct lde_map *); static void lde_map_free(void *); static int lde_address_add(struct lde_nbr *, struct lde_addr *); static int lde_address_del(struct lde_nbr *, struct lde_addr *); static void lde_address_list_free(struct lde_nbr *); RB_GENERATE(nbr_tree, lde_nbr, entry, lde_nbr_compare) +RB_GENERATE(lde_map_head, lde_map, entry, lde_map_compare) struct ldpd_conf *ldeconf; struct nbr_tree lde_nbrs = RB_INITIALIZER(&lde_nbrs); @@ -1141,6 +1143,13 @@ lde_nbr_addr_update(struct lde_nbr *ln, struct lde_addr *lde_addr, int removed) } } +static __inline int +lde_map_compare(struct lde_map *a, struct lde_map *b) +{ + return (ldp_addrcmp(AF_INET, (union ldpd_addr *)&a->nexthop->id, + (union ldpd_addr *)&b->nexthop->id)); +} + struct lde_map * lde_map_add(struct lde_nbr *ln, struct fec_node *fn, int sent) { @@ -1154,13 +1163,15 @@ lde_map_add(struct lde_nbr *ln, struct fec_node *fn, int sent) me->nexthop = ln; if (sent) { - LIST_INSERT_HEAD(&fn->upstream, me, entry); + RB_INSERT(lde_map_head, &fn->upstream, me); + me->head = &fn->upstream; if (fec_insert(&ln->sent_map, &me->fec)) log_warnx("failed to add %s to sent map", log_fec(&me->fec)); /* XXX on failure more cleanup is needed */ } else { - LIST_INSERT_HEAD(&fn->downstream, me, entry); + RB_INSERT(lde_map_head, &fn->downstream, me); + me->head = &fn->downstream; if (fec_insert(&ln->recv_map, &me->fec)) log_warnx("failed to add %s to recv map", log_fec(&me->fec)); @@ -1185,7 +1196,7 @@ lde_map_free(void *ptr) { struct lde_map *map = ptr; - LIST_REMOVE(map, entry); + RB_REMOVE(lde_map_head, map->head, map); free(map); } diff --git a/ldpd/lde.h b/ldpd/lde.h index 5f5d37defb..fe90b2c852 100644 --- a/ldpd/lde.h +++ b/ldpd/lde.h @@ -62,10 +62,13 @@ struct lde_req { /* mapping entries */ struct lde_map { struct fec fec; - LIST_ENTRY(lde_map) entry; + struct lde_map_head *head; /* fec_node's upstream/downstream */ + RB_ENTRY(lde_map) entry; struct lde_nbr *nexthop; struct map map; }; +RB_HEAD(lde_map_head, lde_map); +RB_PROTOTYPE(lde_map_head, lde_map, entry, lde_map_cmp); /* withdraw entries */ struct lde_wdraw { @@ -112,8 +115,8 @@ struct fec_node { struct fec fec; LIST_HEAD(, fec_nh) nexthops; /* fib nexthops */ - LIST_HEAD(, lde_map) downstream; /* recv mappings */ - LIST_HEAD(, lde_map) upstream; /* sent mappings */ + struct lde_map_head downstream; /* recv mappings */ + struct lde_map_head upstream; /* sent mappings */ uint32_t local_label; void *data; /* fec specific data */ diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c index 14ac592af9..df65edad1a 100644 --- a/ldpd/lde_lib.c +++ b/ldpd/lde_lib.c @@ -159,7 +159,7 @@ rt_dump(pid_t pid) RB_FOREACH(f, fec_tree, &ft) { fn = (struct fec_node *)f; if (fn->local_label == NO_LABEL && - LIST_EMPTY(&fn->downstream)) + RB_EMPTY(&fn->downstream)) continue; rtctl.first = 1; @@ -179,7 +179,7 @@ rt_dump(pid_t pid) } rtctl.local_label = fn->local_label; - LIST_FOREACH(me, &fn->downstream, entry) { + RB_FOREACH(me, lde_map_head, &fn->downstream) { rtctl.in_use = lde_nbr_is_nexthop(fn, me->nexthop); rtctl.nexthop = me->nexthop->id; rtctl.remote_label = me->map.label; @@ -188,7 +188,7 @@ rt_dump(pid_t pid) &rtctl, sizeof(rtctl)); rtctl.first = 0; } - if (LIST_EMPTY(&fn->downstream)) { + if (RB_EMPTY(&fn->downstream)) { rtctl.in_use = 0; rtctl.nexthop.s_addr = INADDR_ANY; rtctl.remote_label = NO_LABEL; @@ -224,10 +224,10 @@ fec_free(void *arg) while ((fnh = LIST_FIRST(&fn->nexthops))) fec_nh_del(fnh); - if (!LIST_EMPTY(&fn->downstream)) + if (!RB_EMPTY(&fn->downstream)) log_warnx("%s: fec %s downstream list not empty", __func__, log_fec(&fn->fec)); - if (!LIST_EMPTY(&fn->upstream)) + if (!RB_EMPTY(&fn->upstream)) log_warnx("%s: fec %s upstream list not empty", __func__, log_fec(&fn->fec)); @@ -251,8 +251,8 @@ fec_add(struct fec *fec) fn->fec = *fec; fn->local_label = NO_LABEL; - LIST_INIT(&fn->upstream); - LIST_INIT(&fn->downstream); + RB_INIT(&fn->upstream); + RB_INIT(&fn->downstream); LIST_INIT(&fn->nexthops); if (fec_insert(&ft, &fn->fec)) @@ -774,8 +774,8 @@ lde_gc_timer(struct thread *thread) fn = (struct fec_node *) fec; if (!LIST_EMPTY(&fn->nexthops) || - !LIST_EMPTY(&fn->downstream) || - !LIST_EMPTY(&fn->upstream)) + !RB_EMPTY(&fn->downstream) || + !RB_EMPTY(&fn->upstream)) continue; fec_remove(&ft, &fn->fec); From 7d3d7491a0bc4b04ee6f65e26ae5f115df5a34f1 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 13 Dec 2016 15:29:35 -0200 Subject: [PATCH 09/35] ldpd: use red-black trees to store 'iface' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/interface.c | 37 +++++++++++++++++++++---------------- ldpd/lde.c | 4 ++-- ldpd/ldp_debug.c | 4 ++-- ldpd/ldp_vty_conf.c | 10 +++++----- ldpd/ldpd.c | 32 ++++++++++++++++---------------- ldpd/ldpd.h | 11 +++++++---- ldpd/ldpe.c | 8 ++++---- 7 files changed, 57 insertions(+), 49 deletions(-) diff --git a/ldpd/interface.c b/ldpd/interface.c index b6472fe5e8..06d36fef72 100644 --- a/ldpd/interface.c +++ b/ldpd/interface.c @@ -26,6 +26,7 @@ #include "sockopt.h" +static __inline int iface_compare(struct iface *, struct iface *); static struct if_addr *if_addr_new(struct kaddr *); static struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *); static int if_start(struct iface *, int); @@ -39,6 +40,14 @@ static int if_leave_ipv4_group(struct iface *, struct in_addr *); static int if_join_ipv6_group(struct iface *, struct in6_addr *); static int if_leave_ipv6_group(struct iface *, struct in6_addr *); +RB_GENERATE(iface_head, iface, entry, iface_compare) + +static __inline int +iface_compare(struct iface *a, struct iface *b) +{ + return (strcmp(a->name, b->name)); +} + struct iface * if_new(struct kif *kif) { @@ -69,18 +78,6 @@ if_new(struct kif *kif) return (iface); } -struct iface * -if_lookup(struct ldpd_conf *xconf, unsigned short ifindex) -{ - struct iface *iface; - - LIST_FOREACH(iface, &xconf->iface_list, entry) - if (iface->ifindex == ifindex) - return (iface); - - return (NULL); -} - void if_exit(struct iface *iface) { @@ -100,17 +97,25 @@ if_exit(struct iface *iface) } struct iface * -if_lookup_name(struct ldpd_conf *xconf, const char *ifname) +if_lookup(struct ldpd_conf *xconf, unsigned short ifindex) { struct iface *iface; - LIST_FOREACH(iface, &xconf->iface_list, entry) - if (strcmp(iface->name, ifname) == 0) + RB_FOREACH(iface, iface_head, &xconf->iface_tree) + if (iface->ifindex == ifindex) return (iface); return (NULL); } +struct iface * +if_lookup_name(struct ldpd_conf *xconf, const char *ifname) +{ + struct iface iface; + strlcpy(iface.name, ifname, sizeof(iface.name)); + return (RB_FIND(iface_head, &xconf->iface_tree, &iface)); +} + void if_update_info(struct iface *iface, struct kif *kif) { @@ -380,7 +385,7 @@ if_update_all(int af) { struct iface *iface; - LIST_FOREACH(iface, &leconf->iface_list, entry) + RB_FOREACH(iface, iface_head, &leconf->iface_tree) if_update(iface, af); } diff --git a/ldpd/lde.c b/ldpd/lde.c index a1309c6448..1e362185d2 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -473,7 +473,7 @@ lde_dispatch_parent(struct thread *thread) fatal(NULL); memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); - LIST_INIT(&nconf->iface_list); + RB_INIT(&nconf->iface_tree); LIST_INIT(&nconf->tnbr_list); LIST_INIT(&nconf->nbrp_list); LIST_INIT(&nconf->l2vpn_list); @@ -489,7 +489,7 @@ lde_dispatch_parent(struct thread *thread) niface->ipv4.iface = niface; niface->ipv6.iface = niface; - LIST_INSERT_HEAD(&nconf->iface_list, niface, entry); + RB_INSERT(iface_head, &nconf->iface_tree, niface); break; case IMSG_RECONF_TNBR: if ((ntnbr = malloc(sizeof(struct tnbr))) == NULL) diff --git a/ldpd/ldp_debug.c b/ldpd/ldp_debug.c index 15dd06a0f3..86b679d8aa 100644 --- a/ldpd/ldp_debug.c +++ b/ldpd/ldp_debug.c @@ -74,7 +74,7 @@ ldp_vty_debug(struct vty *vty, struct vty_arg *args[]) DEBUG_OFF(event, EVENT); else DEBUG_ON(event, EVENT); - } else if (strcmp(type_str, "messages") == 0) { + } else if (strcmp(type_str, "messages") == 0) { all = (vty_get_arg_value(args, "all")) ? 1 : 0; dir_str = vty_get_arg_value(args, "dir"); if (dir_str == NULL) @@ -99,7 +99,7 @@ ldp_vty_debug(struct vty *vty, struct vty_arg *args[]) DEBUG_ON(msg, MSG_SEND_ALL); } } - } else if (strcmp(type_str, "zebra") == 0) { + } else if (strcmp(type_str, "zebra") == 0) { if (disable) DEBUG_OFF(zebra, ZEBRA); else diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index dd70365f3d..689554d857 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -142,7 +142,7 @@ ldp_af_iface_config_write(struct vty *vty, int af) struct iface *iface; struct iface_af *ia; - LIST_FOREACH(iface, &ldpd_conf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &ldpd_conf->iface_tree) { ia = iface_af_get(iface, af); if (!ia->enabled) continue; @@ -857,7 +857,7 @@ ldp_vty_interface(struct vty *vty, struct vty_arg *args[]) ia = iface_af_get(iface, af); ia->enabled = 1; - LIST_INSERT_HEAD(&vty_conf->iface_list, iface, entry); + RB_INSERT(iface_head, &vty_conf->iface_tree, iface); ldp_reload_ref(vty_conf, (void **)&iface); } else { memset(&kif, 0, sizeof(kif)); @@ -1641,14 +1641,14 @@ iface_new_api(struct ldpd_conf *conf, const char *name) } iface = if_new(&kif); - LIST_INSERT_HEAD(&conf->iface_list, iface, entry); + RB_INSERT(iface_head, &conf->iface_tree, iface); return (iface); } void -iface_del_api(struct iface *iface) +iface_del_api(struct ldpd_conf *conf, struct iface *iface) { - LIST_REMOVE(iface, entry); + RB_REMOVE(iface_head, &conf->iface_tree, iface); free(iface); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index aa1dc57a7b..14cfaffbb9 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -850,7 +850,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) sizeof(*xconf)) == -1) return (-1); - LIST_FOREACH(iface, &xconf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &xconf->iface_tree) { if (main_imsg_compose_both(IMSG_RECONF_IFACE, iface, sizeof(*iface)) == -1) return (-1); @@ -954,10 +954,10 @@ ldp_config_reset_main(struct ldpd_conf *conf, void **ref) struct iface *iface; struct nbr_params *nbrp; - while ((iface = LIST_FIRST(&conf->iface_list)) != NULL) { + while ((iface = RB_ROOT(&conf->iface_tree)) != NULL) { if (ref && *ref == iface) *ref = NULL; - LIST_REMOVE(iface, entry); + RB_REMOVE(iface_head, &conf->iface_tree, iface); free(iface); } @@ -987,7 +987,7 @@ ldp_config_reset_af(struct ldpd_conf *conf, int af, void **ref) struct iface_af *ia; struct tnbr *tnbr, *ttmp; - LIST_FOREACH(iface, &conf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &conf->iface_tree) { ia = iface_af_get(iface, af); ia->enabled = 0; } @@ -1032,16 +1032,16 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) } while (0) COPY(xconf, conf); - LIST_INIT(&xconf->iface_list); + RB_INIT(&xconf->iface_tree); LIST_INIT(&xconf->tnbr_list); LIST_INIT(&xconf->nbrp_list); LIST_INIT(&xconf->l2vpn_list); - LIST_FOREACH(iface, &conf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &conf->iface_tree) { COPY(xi, iface); xi->ipv4.iface = xi; xi->ipv6.iface = xi; - LIST_INSERT_HEAD(&xconf->iface_list, xi, entry); + RB_INSERT(iface_head, &xconf->iface_tree, xi); } LIST_FOREACH(tnbr, &conf->tnbr_list, entry) { COPY(xt, tnbr); @@ -1093,8 +1093,8 @@ ldp_clear_config(struct ldpd_conf *xconf) struct nbr_params *nbrp; struct l2vpn *l2vpn; - while ((iface = LIST_FIRST(&xconf->iface_list)) != NULL) { - LIST_REMOVE(iface, entry); + while ((iface = RB_ROOT(&xconf->iface_tree)) != NULL) { + RB_REMOVE(iface_head, &xconf->iface_tree, iface); free(iface); } while ((tnbr = LIST_FIRST(&xconf->tnbr_list)) != NULL) { @@ -1236,10 +1236,10 @@ merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) { struct iface *iface, *itmp, *xi; - LIST_FOREACH_SAFE(iface, &conf->iface_list, entry, itmp) { + RB_FOREACH_SAFE(iface, iface_head, &conf->iface_tree, itmp) { /* find deleted interfaces */ if ((xi = if_lookup_name(xconf, iface->name)) == NULL) { - LIST_REMOVE(iface, entry); + RB_REMOVE(iface_head, &conf->iface_tree, iface); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1254,11 +1254,11 @@ merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) free(iface); } } - LIST_FOREACH_SAFE(xi, &xconf->iface_list, entry, itmp) { + RB_FOREACH_SAFE(xi, iface_head, &xconf->iface_tree, itmp) { /* find new interfaces */ if ((iface = if_lookup_name(conf, xi->name)) == NULL) { - LIST_REMOVE(xi, entry); - LIST_INSERT_HEAD(&conf->iface_list, xi, entry); + RB_REMOVE(iface_head, &xconf->iface_tree, xi); + RB_INSERT(iface_head, &conf->iface_tree, xi); if (ldpd_process == PROC_MAIN) { QOBJ_REG (xi, iface); @@ -1271,7 +1271,7 @@ merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) /* update existing interfaces */ merge_iface_af(&iface->ipv4, &xi->ipv4); merge_iface_af(&iface->ipv6, &xi->ipv6); - LIST_REMOVE(xi, entry); + RB_REMOVE(iface_head, &xconf->iface_tree, xi); if (ref && *ref == xi) *ref = iface; free(xi); @@ -1770,7 +1770,7 @@ config_new_empty(void) if (xconf == NULL) fatal(NULL); - LIST_INIT(&xconf->iface_list); + RB_INIT(&xconf->iface_tree); LIST_INIT(&xconf->tnbr_list); LIST_INIT(&xconf->nbrp_list); LIST_INIT(&xconf->l2vpn_list); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 630b192489..2c516c013b 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -264,7 +264,7 @@ struct iface_af { }; struct iface { - LIST_ENTRY(iface) entry; + RB_ENTRY(iface) entry; char name[IF_NAMESIZE]; unsigned int ifindex; struct if_addr_head addr_list; @@ -275,6 +275,8 @@ struct iface { struct iface_af ipv6; QOBJ_FIELDS }; +RB_HEAD(iface_head, iface); +RB_PROTOTYPE(iface_head, iface, entry, iface_compare); DECLARE_QOBJ_TYPE(iface) /* source of targeted hellos */ @@ -404,7 +406,7 @@ struct ldpd_conf { struct in_addr rtr_id; struct ldpd_af_conf ipv4; struct ldpd_af_conf ipv6; - LIST_HEAD(, iface) iface_list; + struct iface_head iface_tree; LIST_HEAD(, tnbr) tnbr_list; LIST_HEAD(, nbr_params) nbrp_list; LIST_HEAD(, l2vpn) l2vpn_list; @@ -627,9 +629,10 @@ void config_clear(struct ldpd_conf *); /* ldp_vty_conf.c */ /* NOTE: the parameters' names should be preserved because of codegen */ -struct iface *iface_new_api(struct ldpd_conf *cfg, +struct iface *iface_new_api(struct ldpd_conf *conf, const char *name); -void iface_del_api(struct iface *iface); +void iface_del_api(struct ldpd_conf *conf, + struct iface *iface); struct tnbr *tnbr_new_api(struct ldpd_conf *cfg, int af, union ldpd_addr *addr); void tnbr_del_api(struct tnbr *tnbr); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index aef33c8e37..16910a3cc8 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -414,7 +414,7 @@ ldpe_dispatch_main(struct thread *thread) fatal(NULL); memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); - LIST_INIT(&nconf->iface_list); + RB_INIT(&nconf->iface_tree); LIST_INIT(&nconf->tnbr_list); LIST_INIT(&nconf->nbrp_list); LIST_INIT(&nconf->l2vpn_list); @@ -430,7 +430,7 @@ ldpe_dispatch_main(struct thread *thread) niface->ipv4.iface = niface; niface->ipv6.iface = niface; - LIST_INSERT_HEAD(&nconf->iface_list, niface, entry); + RB_INSERT(iface_head, &nconf->iface_tree, niface); break; case IMSG_RECONF_TNBR: if ((ntnbr = malloc(sizeof(struct tnbr))) == NULL) @@ -772,7 +772,7 @@ ldpe_iface_af_ctl(struct ctl_conn *c, int af, unsigned int idx) struct iface_af *ia; struct ctl_iface *ictl; - LIST_FOREACH(iface, &leconf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &leconf->iface_tree) { if (idx == 0 || idx == iface->ifindex) { ia = iface_af_get(iface, af); if (!ia->enabled) @@ -805,7 +805,7 @@ ldpe_adj_ctl(struct ctl_conn *c) imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISCOVERY, 0, 0, -1, NULL, 0); - LIST_FOREACH(iface, &leconf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &leconf->iface_tree) { memset(&ictl, 0, sizeof(ictl)); ictl.active_v4 = (iface->ipv4.state == IF_STA_ACTIVE); ictl.active_v6 = (iface->ipv6.state == IF_STA_ACTIVE); From 7989cdba45f631fb14d1bcaf7103c9db25605971 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 13 Dec 2016 16:19:15 -0200 Subject: [PATCH 10/35] ldpd: use red-black trees to store 'tnbr' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/adjacency.c | 40 +++++++++++++++++++++++++--------------- ldpd/hello.c | 4 ++-- ldpd/l2vpn.c | 4 ++-- ldpd/lde.c | 4 ++-- ldpd/ldp_vty_conf.c | 12 ++++++------ ldpd/ldpd.c | 34 +++++++++++++++++----------------- ldpd/ldpd.h | 10 ++++++---- ldpd/ldpe.c | 10 +++++----- ldpd/ldpe.h | 2 +- 9 files changed, 66 insertions(+), 54 deletions(-) diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c index d1a6facb30..3f478df38a 100644 --- a/ldpd/adjacency.c +++ b/ldpd/adjacency.c @@ -26,11 +26,14 @@ #include "log.h" static int adj_itimer(struct thread *); -static void tnbr_del(struct tnbr *); +static __inline int tnbr_compare(struct tnbr *, struct tnbr *); +static void tnbr_del(struct ldpd_conf *, struct tnbr *); static int tnbr_hello_timer(struct thread *); static void tnbr_start_hello_timer(struct tnbr *); static void tnbr_stop_hello_timer(struct tnbr *); +RB_GENERATE(tnbr_head, tnbr, entry, tnbr_compare) + struct adj * adj_new(struct in_addr lsr_id, struct hello_source *source, union ldpd_addr *addr) @@ -165,7 +168,7 @@ adj_itimer(struct thread *thread) if (!(adj->source.target->flags & F_TNBR_CONFIGURED) && adj->source.target->pw_count == 0) { /* remove dynamic targeted neighbor */ - tnbr_del(adj->source.target); + tnbr_del(leconf, adj->source.target); return (0); } adj->source.target->adj = NULL; @@ -192,6 +195,17 @@ adj_stop_itimer(struct adj *adj) /* targeted neighbors */ +static __inline int +tnbr_compare(struct tnbr *a, struct tnbr *b) +{ + if (a->af < b->af) + return (-1); + if (a->af > b->af) + return (1); + + return (ldp_addrcmp(a->af, &a->addr, &b->addr)); +} + struct tnbr * tnbr_new(int af, union ldpd_addr *addr) { @@ -208,34 +222,30 @@ tnbr_new(int af, union ldpd_addr *addr) } static void -tnbr_del(struct tnbr *tnbr) +tnbr_del(struct ldpd_conf *xconf, struct tnbr *tnbr) { tnbr_stop_hello_timer(tnbr); if (tnbr->adj) adj_del(tnbr->adj, S_SHUTDOWN); - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr); free(tnbr); } struct tnbr * tnbr_find(struct ldpd_conf *xconf, int af, union ldpd_addr *addr) { - struct tnbr *tnbr; - - LIST_FOREACH(tnbr, &xconf->tnbr_list, entry) - if (af == tnbr->af && - ldp_addrcmp(af, addr, &tnbr->addr) == 0) - return (tnbr); - - return (NULL); + struct tnbr tnbr; + tnbr.af = af; + tnbr.addr = *addr; + return (RB_FIND(tnbr_head, &xconf->tnbr_tree, &tnbr)); } struct tnbr * -tnbr_check(struct tnbr *tnbr) +tnbr_check(struct ldpd_conf *xconf, struct tnbr *tnbr) { if (!(tnbr->flags & (F_TNBR_CONFIGURED|F_TNBR_DYNAMIC)) && tnbr->pw_count == 0) { - tnbr_del(tnbr); + tnbr_del(xconf, tnbr); return (NULL); } @@ -280,7 +290,7 @@ tnbr_update_all(int af) struct tnbr *tnbr; /* update targeted neighbors */ - LIST_FOREACH(tnbr, &leconf->tnbr_list, entry) + RB_FOREACH(tnbr, tnbr_head, &leconf->tnbr_tree) if (tnbr->af == af || af == AF_UNSPEC) tnbr_update(tnbr); } diff --git a/ldpd/hello.c b/ldpd/hello.c index 755b25aa85..0833ebbafb 100644 --- a/ldpd/hello.c +++ b/ldpd/hello.c @@ -261,7 +261,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, if (tnbr && (tnbr->flags & F_TNBR_DYNAMIC) && !((flags & F_HELLO_REQ_TARG))) { tnbr->flags &= ~F_TNBR_DYNAMIC; - tnbr = tnbr_check(tnbr); + tnbr = tnbr_check(leconf, tnbr); } if (!tnbr) { @@ -273,7 +273,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, tnbr = tnbr_new(af, src); tnbr->flags |= F_TNBR_DYNAMIC; tnbr_update(tnbr); - LIST_INSERT_HEAD(&leconf->tnbr_list, tnbr, entry); + RB_INSERT(tnbr_head, &leconf->tnbr_tree, tnbr); } source.type = HELLO_TARGETED; diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index c0f6586854..dc9879ef23 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -530,7 +530,7 @@ ldpe_l2vpn_pw_init(struct l2vpn_pw *pw) if (tnbr == NULL) { tnbr = tnbr_new(pw->af, &pw->addr); tnbr_update(tnbr); - LIST_INSERT_HEAD(&leconf->tnbr_list, tnbr, entry); + RB_INSERT(tnbr_head, &leconf->tnbr_tree, tnbr); } tnbr->pw_count++; @@ -544,6 +544,6 @@ ldpe_l2vpn_pw_exit(struct l2vpn_pw *pw) tnbr = tnbr_find(leconf, pw->af, &pw->addr); if (tnbr) { tnbr->pw_count--; - tnbr_check(tnbr); + tnbr_check(leconf, tnbr); } } diff --git a/ldpd/lde.c b/ldpd/lde.c index 1e362185d2..4b957c55e7 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -474,7 +474,7 @@ lde_dispatch_parent(struct thread *thread) memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); RB_INIT(&nconf->iface_tree); - LIST_INIT(&nconf->tnbr_list); + RB_INIT(&nconf->tnbr_tree); LIST_INIT(&nconf->nbrp_list); LIST_INIT(&nconf->l2vpn_list); break; @@ -496,7 +496,7 @@ lde_dispatch_parent(struct thread *thread) fatal(NULL); memcpy(ntnbr, imsg.data, sizeof(struct tnbr)); - LIST_INSERT_HEAD(&nconf->tnbr_list, ntnbr, entry); + RB_INSERT(tnbr_head, &nconf->tnbr_tree, ntnbr); break; case IMSG_RECONF_NBRP: if ((nnbrp = malloc(sizeof(struct nbr_params))) == NULL) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 689554d857..f5c98eb1ff 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -213,7 +213,7 @@ ldp_af_config_write(struct vty *vty, int af, struct ldpd_conf *conf, vty_out(vty, " session holdtime %u%s", af_conf->keepalive, VTY_NEWLINE); - LIST_FOREACH(tnbr, &ldpd_conf->tnbr_list, entry) { + RB_FOREACH(tnbr, tnbr_head, &ldpd_conf->tnbr_tree) { if (tnbr->af == af) { vty_out(vty, " !%s", VTY_NEWLINE); vty_out(vty, " neighbor %s targeted%s", @@ -955,7 +955,7 @@ ldp_vty_neighbor_targeted(struct vty *vty, struct vty_arg *args[]) if (tnbr == NULL) goto cancel; - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &vty_conf->tnbr_tree, tnbr); free(tnbr); ldp_reload(vty_conf); return (CMD_SUCCESS); @@ -966,7 +966,7 @@ ldp_vty_neighbor_targeted(struct vty *vty, struct vty_arg *args[]) tnbr = tnbr_new(af, &addr); tnbr->flags |= F_TNBR_CONFIGURED; - LIST_INSERT_HEAD(&vty_conf->tnbr_list, tnbr, entry); + RB_INSERT(tnbr_head, &vty_conf->tnbr_tree, tnbr); ldp_reload(vty_conf); @@ -1665,14 +1665,14 @@ tnbr_new_api(struct ldpd_conf *conf, int af, union ldpd_addr *addr) tnbr = tnbr_new(af, addr); tnbr->flags |= F_TNBR_CONFIGURED; - LIST_INSERT_HEAD(&conf->tnbr_list, tnbr, entry); + RB_INSERT(tnbr_head, &conf->tnbr_tree, tnbr); return (tnbr); } void -tnbr_del_api(struct tnbr *tnbr) +tnbr_del_api(struct ldpd_conf *conf, struct tnbr *tnbr) { - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr); free(tnbr); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 14cfaffbb9..cf793f58c3 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -856,7 +856,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) return (-1); } - LIST_FOREACH(tnbr, &xconf->tnbr_list, entry) { + RB_FOREACH(tnbr, tnbr_head, &xconf->tnbr_tree) { if (main_imsg_compose_both(IMSG_RECONF_TNBR, tnbr, sizeof(*tnbr)) == -1) return (-1); @@ -992,13 +992,13 @@ ldp_config_reset_af(struct ldpd_conf *conf, int af, void **ref) ia->enabled = 0; } - LIST_FOREACH_SAFE(tnbr, &conf->tnbr_list, entry, ttmp) { + RB_FOREACH_SAFE(tnbr, tnbr_head, &conf->tnbr_tree, ttmp) { if (tnbr->af != af) continue; if (ref && *ref == tnbr) *ref = NULL; - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr); free(tnbr); } @@ -1033,7 +1033,7 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) COPY(xconf, conf); RB_INIT(&xconf->iface_tree); - LIST_INIT(&xconf->tnbr_list); + RB_INIT(&xconf->tnbr_tree); LIST_INIT(&xconf->nbrp_list); LIST_INIT(&xconf->l2vpn_list); @@ -1043,9 +1043,9 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) xi->ipv6.iface = xi; RB_INSERT(iface_head, &xconf->iface_tree, xi); } - LIST_FOREACH(tnbr, &conf->tnbr_list, entry) { + RB_FOREACH(tnbr, tnbr_head, &conf->tnbr_tree) { COPY(xt, tnbr); - LIST_INSERT_HEAD(&xconf->tnbr_list, xt, entry); + RB_INSERT(tnbr_head, &xconf->tnbr_tree, xt); } LIST_FOREACH(nbrp, &conf->nbrp_list, entry) { COPY(xn, nbrp); @@ -1097,8 +1097,8 @@ ldp_clear_config(struct ldpd_conf *xconf) RB_REMOVE(iface_head, &xconf->iface_tree, iface); free(iface); } - while ((tnbr = LIST_FIRST(&xconf->tnbr_list)) != NULL) { - LIST_REMOVE(tnbr, entry); + while ((tnbr = RB_ROOT(&xconf->tnbr_tree)) != NULL) { + RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr); free(tnbr); } while ((nbrp = LIST_FIRST(&xconf->nbrp_list)) != NULL) { @@ -1295,7 +1295,7 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) { struct tnbr *tnbr, *ttmp, *xt; - LIST_FOREACH_SAFE(tnbr, &conf->tnbr_list, entry, ttmp) { + RB_FOREACH_SAFE(tnbr, tnbr_head, &conf->tnbr_tree, ttmp) { if (!(tnbr->flags & F_TNBR_CONFIGURED)) continue; @@ -1303,26 +1303,26 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) if ((xt = tnbr_find(xconf, tnbr->af, &tnbr->addr)) == NULL) { switch (ldpd_process) { case PROC_LDE_ENGINE: - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr); free(tnbr); break; case PROC_LDP_ENGINE: tnbr->flags &= ~F_TNBR_CONFIGURED; - tnbr_check(tnbr); + tnbr_check(conf, tnbr); break; case PROC_MAIN: - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr); QOBJ_UNREG (tnbr); free(tnbr); break; } } } - LIST_FOREACH_SAFE(xt, &xconf->tnbr_list, entry, ttmp) { + RB_FOREACH_SAFE(xt, tnbr_head, &xconf->tnbr_tree, ttmp) { /* find new tnbrs */ if ((tnbr = tnbr_find(conf, xt->af, &xt->addr)) == NULL) { - LIST_REMOVE(xt, entry); - LIST_INSERT_HEAD(&conf->tnbr_list, xt, entry); + RB_REMOVE(tnbr_head, &xconf->tnbr_tree, xt); + RB_INSERT(tnbr_head, &conf->tnbr_tree, xt); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1340,7 +1340,7 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) /* update existing tnbrs */ if (!(tnbr->flags & F_TNBR_CONFIGURED)) tnbr->flags |= F_TNBR_CONFIGURED; - LIST_REMOVE(xt, entry); + RB_REMOVE(tnbr_head, &xconf->tnbr_tree, xt); if (ref && *ref == xt) *ref = tnbr; free(xt); @@ -1771,7 +1771,7 @@ config_new_empty(void) fatal(NULL); RB_INIT(&xconf->iface_tree); - LIST_INIT(&xconf->tnbr_list); + RB_INIT(&xconf->tnbr_tree); LIST_INIT(&xconf->nbrp_list); LIST_INIT(&xconf->l2vpn_list); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 2c516c013b..7e5b4248a2 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -281,7 +281,7 @@ DECLARE_QOBJ_TYPE(iface) /* source of targeted hellos */ struct tnbr { - LIST_ENTRY(tnbr) entry; + RB_ENTRY(tnbr) entry; struct thread *hello_timer; struct adj *adj; int af; @@ -291,6 +291,8 @@ struct tnbr { uint8_t flags; QOBJ_FIELDS }; +RB_HEAD(tnbr_head, tnbr); +RB_PROTOTYPE(tnbr_head, tnbr, entry, tnbr_compare); DECLARE_QOBJ_TYPE(tnbr) #define F_TNBR_CONFIGURED 0x01 #define F_TNBR_DYNAMIC 0x02 @@ -407,7 +409,7 @@ struct ldpd_conf { struct ldpd_af_conf ipv4; struct ldpd_af_conf ipv6; struct iface_head iface_tree; - LIST_HEAD(, tnbr) tnbr_list; + struct tnbr_head tnbr_tree; LIST_HEAD(, nbr_params) nbrp_list; LIST_HEAD(, l2vpn) l2vpn_list; uint16_t lhello_holdtime; @@ -633,9 +635,9 @@ struct iface *iface_new_api(struct ldpd_conf *conf, const char *name); void iface_del_api(struct ldpd_conf *conf, struct iface *iface); -struct tnbr *tnbr_new_api(struct ldpd_conf *cfg, int af, +struct tnbr *tnbr_new_api(struct ldpd_conf *conf, int af, union ldpd_addr *addr); -void tnbr_del_api(struct tnbr *tnbr); +void tnbr_del_api(struct ldpd_conf *conf, struct tnbr *tnbr); struct nbr_params *nbrp_new_api(struct ldpd_conf *cfg, struct in_addr lsr_id); void nbrp_del_api(struct nbr_params *nbrp); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 16910a3cc8..699ce502f5 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -415,7 +415,7 @@ ldpe_dispatch_main(struct thread *thread) memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); RB_INIT(&nconf->iface_tree); - LIST_INIT(&nconf->tnbr_list); + RB_INIT(&nconf->tnbr_tree); LIST_INIT(&nconf->nbrp_list); LIST_INIT(&nconf->l2vpn_list); break; @@ -437,7 +437,7 @@ ldpe_dispatch_main(struct thread *thread) fatal(NULL); memcpy(ntnbr, imsg.data, sizeof(struct tnbr)); - LIST_INSERT_HEAD(&nconf->tnbr_list, ntnbr, entry); + RB_INSERT(tnbr_head, &nconf->tnbr_tree, ntnbr); break; case IMSG_RECONF_NBRP: if ((nnbrp = malloc(sizeof(struct nbr_params))) == NULL) @@ -743,12 +743,12 @@ ldpe_remove_dynamic_tnbrs(int af) { struct tnbr *tnbr, *safe; - LIST_FOREACH_SAFE(tnbr, &leconf->tnbr_list, entry, safe) { + RB_FOREACH_SAFE(tnbr, tnbr_head, &leconf->tnbr_tree, safe) { if (tnbr->af != af) continue; tnbr->flags &= ~F_TNBR_DYNAMIC; - tnbr_check(tnbr); + tnbr_check(leconf, tnbr); } } @@ -832,7 +832,7 @@ ldpe_adj_ctl(struct ctl_conn *c) } } - LIST_FOREACH(tnbr, &leconf->tnbr_list, entry) { + RB_FOREACH(tnbr, tnbr_head, &leconf->tnbr_tree) { memset(&tctl, 0, sizeof(tctl)); tctl.af = tnbr->af; tctl.addr = tnbr->addr; diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h index aab1a7fd9b..52899fd85c 100644 --- a/ldpd/ldpe.h +++ b/ldpd/ldpe.h @@ -225,7 +225,7 @@ void adj_start_itimer(struct adj *); void adj_stop_itimer(struct adj *); struct tnbr *tnbr_new(int, union ldpd_addr *); struct tnbr *tnbr_find(struct ldpd_conf *, int, union ldpd_addr *); -struct tnbr *tnbr_check(struct tnbr *); +struct tnbr *tnbr_check(struct ldpd_conf *, struct tnbr *); void tnbr_update(struct tnbr *); void tnbr_update_all(int); uint16_t tnbr_get_hello_holdtime(struct tnbr *); From 76c4abd19f322288394be872c9198c7d17cfac10 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 09:14:52 -0200 Subject: [PATCH 11/35] ldpd: use red-black trees to store 'nbr_params' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/lde.c | 4 ++-- ldpd/ldp_vty_conf.c | 14 +++++++------- ldpd/ldpd.c | 30 +++++++++++++++--------------- ldpd/ldpd.h | 11 +++++++---- ldpd/ldpe.c | 4 ++-- ldpd/neighbor.c | 19 ++++++++++++------- 6 files changed, 45 insertions(+), 37 deletions(-) diff --git a/ldpd/lde.c b/ldpd/lde.c index 4b957c55e7..80557ed4ef 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -475,7 +475,7 @@ lde_dispatch_parent(struct thread *thread) RB_INIT(&nconf->iface_tree); RB_INIT(&nconf->tnbr_tree); - LIST_INIT(&nconf->nbrp_list); + RB_INIT(&nconf->nbrp_tree); LIST_INIT(&nconf->l2vpn_list); break; case IMSG_RECONF_IFACE: @@ -503,7 +503,7 @@ lde_dispatch_parent(struct thread *thread) fatal(NULL); memcpy(nnbrp, imsg.data, sizeof(struct nbr_params)); - LIST_INSERT_HEAD(&nconf->nbrp_list, nnbrp, entry); + RB_INSERT(nbrp_head, &nconf->nbrp_tree, nnbrp); break; case IMSG_RECONF_L2VPN: if ((nl2vpn = malloc(sizeof(struct l2vpn))) == NULL) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index f5c98eb1ff..95b0971e64 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -265,7 +265,7 @@ ldp_config_write(struct vty *vty) if (ldpd_conf->flags & F_LDPD_DS_CISCO_INTEROP) vty_out(vty, " dual-stack cisco-interop%s", VTY_NEWLINE); - LIST_FOREACH(nbrp, &ldpd_conf->nbrp_list, entry) { + RB_FOREACH(nbrp, nbrp_head, &ldpd_conf->nbrp_tree) { if (nbrp->flags & F_NBRP_KEEPALIVE) vty_out(vty, " neighbor %s session holdtime %u%s", inet_ntoa(nbrp->lsr_id), nbrp->keepalive, @@ -740,7 +740,7 @@ ldp_vty_nbr_session_holdtime(struct vty *vty, struct vty_arg *args[]) } else { if (nbrp == NULL) { nbrp = nbr_params_new(lsr_id); - LIST_INSERT_HEAD(&vty_conf->nbrp_list, nbrp, entry); + RB_INSERT(nbrp_head, &vty_conf->nbrp_tree, nbrp); } else if (nbrp->keepalive == secs) goto cancel; @@ -1129,7 +1129,7 @@ ldp_vty_neighbor_password(struct vty *vty, struct vty_arg *args[]) } else { if (nbrp == NULL) { nbrp = nbr_params_new(lsr_id); - LIST_INSERT_HEAD(&vty_conf->nbrp_list, nbrp, entry); + RB_INSERT(nbrp_head, &vty_conf->nbrp_tree, nbrp); } else if (nbrp->auth.method == AUTH_MD5SIG && strcmp(nbrp->auth.md5key, password_str) == 0) goto cancel; @@ -1195,7 +1195,7 @@ ldp_vty_neighbor_ttl_security(struct vty *vty, struct vty_arg *args[]) } else { if (nbrp == NULL) { nbrp = nbr_params_new(lsr_id); - LIST_INSERT_HEAD(&vty_conf->nbrp_list, nbrp, entry); + RB_INSERT(nbrp_head, &vty_conf->nbrp_tree, nbrp); } nbrp->flags |= F_NBRP_GTSM; @@ -1685,14 +1685,14 @@ nbrp_new_api(struct ldpd_conf *conf, struct in_addr lsr_id) return (NULL); nbrp = nbr_params_new(lsr_id); - LIST_INSERT_HEAD(&conf->nbrp_list, nbrp, entry); + RB_INSERT(nbrp_head, &conf->nbrp_tree, nbrp); return (nbrp); } void -nbrp_del_api(struct nbr_params *nbrp) +nbrp_del_api(struct ldpd_conf *conf, struct nbr_params *nbrp) { - LIST_REMOVE(nbrp, entry); + RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp); free(nbrp); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index cf793f58c3..37cc0dec16 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -862,7 +862,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) return (-1); } - LIST_FOREACH(nbrp, &xconf->nbrp_list, entry) { + RB_FOREACH(nbrp, nbrp_head, &xconf->nbrp_tree) { if (main_imsg_compose_both(IMSG_RECONF_NBRP, nbrp, sizeof(*nbrp)) == -1) return (-1); @@ -961,10 +961,10 @@ ldp_config_reset_main(struct ldpd_conf *conf, void **ref) free(iface); } - while ((nbrp = LIST_FIRST(&conf->nbrp_list)) != NULL) { + while ((nbrp = RB_ROOT(&conf->nbrp_tree)) != NULL) { if (ref && *ref == nbrp) *ref = NULL; - LIST_REMOVE(nbrp, entry); + RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp); free(nbrp); } @@ -1034,7 +1034,7 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) COPY(xconf, conf); RB_INIT(&xconf->iface_tree); RB_INIT(&xconf->tnbr_tree); - LIST_INIT(&xconf->nbrp_list); + RB_INIT(&xconf->nbrp_tree); LIST_INIT(&xconf->l2vpn_list); RB_FOREACH(iface, iface_head, &conf->iface_tree) { @@ -1047,9 +1047,9 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) COPY(xt, tnbr); RB_INSERT(tnbr_head, &xconf->tnbr_tree, xt); } - LIST_FOREACH(nbrp, &conf->nbrp_list, entry) { + RB_FOREACH(nbrp, nbrp_head, &conf->nbrp_tree) { COPY(xn, nbrp); - LIST_INSERT_HEAD(&xconf->nbrp_list, xn, entry); + RB_INSERT(nbrp_head, &xconf->nbrp_tree, xn); } LIST_FOREACH(l2vpn, &conf->l2vpn_list, entry) { COPY(xl, l2vpn); @@ -1101,8 +1101,8 @@ ldp_clear_config(struct ldpd_conf *xconf) RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr); free(tnbr); } - while ((nbrp = LIST_FIRST(&xconf->nbrp_list)) != NULL) { - LIST_REMOVE(nbrp, entry); + while ((nbrp = RB_ROOT(&xconf->nbrp_tree)) != NULL) { + RB_REMOVE(nbrp_head, &xconf->nbrp_tree, nbrp); free(nbrp); } while ((l2vpn = LIST_FIRST(&xconf->l2vpn_list)) != NULL) { @@ -1354,7 +1354,7 @@ merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) struct nbr *nbr; int nbrp_changed; - LIST_FOREACH_SAFE(nbrp, &conf->nbrp_list, entry, ntmp) { + RB_FOREACH_SAFE(nbrp, nbrp_head, &conf->nbrp_tree, ntmp) { /* find deleted nbrps */ if ((xn = nbr_params_find(xconf, nbrp->lsr_id)) == NULL) { switch (ldpd_process) { @@ -1380,15 +1380,15 @@ merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) QOBJ_UNREG (nbrp); break; } - LIST_REMOVE(nbrp, entry); + RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp); free(nbrp); } } - LIST_FOREACH_SAFE(xn, &xconf->nbrp_list, entry, ntmp) { + RB_FOREACH_SAFE(xn, nbrp_head, &xconf->nbrp_tree, ntmp) { /* find new nbrps */ if ((nbrp = nbr_params_find(conf, xn->lsr_id)) == NULL) { - LIST_REMOVE(xn, entry); - LIST_INSERT_HEAD(&conf->nbrp_list, xn, entry); + RB_REMOVE(nbrp_head, &xconf->nbrp_tree, xn); + RB_INSERT(nbrp_head, &conf->nbrp_tree, xn); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1455,7 +1455,7 @@ merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) nbr_establish_connection(nbr); } } - LIST_REMOVE(xn, entry); + RB_REMOVE(nbrp_head, &xconf->nbrp_tree, xn); if (ref && *ref == xn) *ref = nbrp; free(xn); @@ -1772,7 +1772,7 @@ config_new_empty(void) RB_INIT(&xconf->iface_tree); RB_INIT(&xconf->tnbr_tree); - LIST_INIT(&xconf->nbrp_list); + RB_INIT(&xconf->nbrp_tree); LIST_INIT(&xconf->l2vpn_list); return (xconf); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 7e5b4248a2..d8f75a0eec 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -304,7 +304,7 @@ enum auth_method { /* neighbor specific parameters */ struct nbr_params { - LIST_ENTRY(nbr_params) entry; + RB_ENTRY(nbr_params) entry; struct in_addr lsr_id; uint16_t keepalive; int gtsm_enabled; @@ -317,6 +317,8 @@ struct nbr_params { uint8_t flags; QOBJ_FIELDS }; +RB_HEAD(nbrp_head, nbr_params); +RB_PROTOTYPE(nbrp_head, nbr_params, entry, nbr_params_compare); DECLARE_QOBJ_TYPE(nbr_params) #define F_NBRP_KEEPALIVE 0x01 #define F_NBRP_GTSM 0x02 @@ -410,7 +412,7 @@ struct ldpd_conf { struct ldpd_af_conf ipv6; struct iface_head iface_tree; struct tnbr_head tnbr_tree; - LIST_HEAD(, nbr_params) nbrp_list; + struct nbrp_head nbrp_tree; LIST_HEAD(, l2vpn) l2vpn_list; uint16_t lhello_holdtime; uint16_t lhello_interval; @@ -638,9 +640,10 @@ void iface_del_api(struct ldpd_conf *conf, struct tnbr *tnbr_new_api(struct ldpd_conf *conf, int af, union ldpd_addr *addr); void tnbr_del_api(struct ldpd_conf *conf, struct tnbr *tnbr); -struct nbr_params *nbrp_new_api(struct ldpd_conf *cfg, +struct nbr_params *nbrp_new_api(struct ldpd_conf *conf, struct in_addr lsr_id); -void nbrp_del_api(struct nbr_params *nbrp); +void nbrp_del_api(struct ldpd_conf *conf, + struct nbr_params *nbrp); struct l2vpn *l2vpn_new_api(struct ldpd_conf *cfg, const char *name); void l2vpn_del_api(struct l2vpn *l2vpn); struct l2vpn_if *l2vpn_if_new_api(struct ldpd_conf *conf, diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 699ce502f5..e9e45f8fe3 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -416,7 +416,7 @@ ldpe_dispatch_main(struct thread *thread) RB_INIT(&nconf->iface_tree); RB_INIT(&nconf->tnbr_tree); - LIST_INIT(&nconf->nbrp_list); + RB_INIT(&nconf->nbrp_tree); LIST_INIT(&nconf->l2vpn_list); break; case IMSG_RECONF_IFACE: @@ -444,7 +444,7 @@ ldpe_dispatch_main(struct thread *thread) fatal(NULL); memcpy(nnbrp, imsg.data, sizeof(struct nbr_params)); - LIST_INSERT_HEAD(&nconf->nbrp_list, nnbrp, entry); + RB_INSERT(nbrp_head, &nconf->nbrp_tree, nnbrp); break; case IMSG_RECONF_L2VPN: if ((nl2vpn = malloc(sizeof(struct l2vpn))) == NULL) diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c index 8376a01549..5addc4dda2 100644 --- a/ldpd/neighbor.c +++ b/ldpd/neighbor.c @@ -39,10 +39,13 @@ static void nbr_start_itimeout(struct nbr *); static int nbr_idtimer(struct thread *); static int nbr_act_session_operational(struct nbr *); static void nbr_send_labelmappings(struct nbr *); +static __inline int nbr_params_compare(struct nbr_params *, + struct nbr_params *); RB_GENERATE(nbr_id_head, nbr, id_tree, nbr_id_compare) RB_GENERATE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare) RB_GENERATE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare) +RB_GENERATE(nbrp_head, nbr_params, entry, nbr_params_compare) struct { int state; @@ -752,6 +755,12 @@ nbr_send_labelmappings(struct nbr *nbr) NULL, 0); } +static __inline int +nbr_params_compare(struct nbr_params *a, struct nbr_params *b) +{ + return (ntohl(a->lsr_id.s_addr) - ntohl(b->lsr_id.s_addr)); +} + struct nbr_params * nbr_params_new(struct in_addr lsr_id) { @@ -769,13 +778,9 @@ nbr_params_new(struct in_addr lsr_id) struct nbr_params * nbr_params_find(struct ldpd_conf *xconf, struct in_addr lsr_id) { - struct nbr_params *nbrp; - - LIST_FOREACH(nbrp, &xconf->nbrp_list, entry) - if (nbrp->lsr_id.s_addr == lsr_id.s_addr) - return (nbrp); - - return (NULL); + struct nbr_params nbrp; + nbrp.lsr_id = lsr_id; + return (RB_FIND(nbrp_head, &xconf->nbrp_tree, &nbrp)); } uint16_t From 90d7e7bd8b68530a80293e8d1c5c894c99b7a434 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 10:42:45 -0200 Subject: [PATCH 12/35] ldpd: use red-black trees to store 'l2vpn' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/l2vpn.c | 25 +++++++++++++++---------- ldpd/lde.c | 4 ++-- ldpd/ldp_vty_conf.c | 14 +++++++------- ldpd/ldpd.c | 28 ++++++++++++++-------------- ldpd/ldpd.h | 11 +++++++---- ldpd/ldpe.c | 4 ++-- 6 files changed, 47 insertions(+), 39 deletions(-) diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index dc9879ef23..b339c9ce6b 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -26,7 +26,16 @@ #include "lde.h" #include "log.h" -static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *); +static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *); +static __inline int l2vpn_compare(struct l2vpn *, struct l2vpn *); + +RB_GENERATE(l2vpn_head, l2vpn, entry, l2vpn_compare) + +static __inline int +l2vpn_compare(struct l2vpn *a, struct l2vpn *b) +{ + return (strcmp(a->name, b->name)); +} struct l2vpn * l2vpn_new(const char *name) @@ -52,13 +61,9 @@ l2vpn_new(const char *name) struct l2vpn * l2vpn_find(struct ldpd_conf *xconf, const char *name) { - struct l2vpn *l2vpn; - - LIST_FOREACH(l2vpn, &xconf->l2vpn_list, entry) - if (strcmp(l2vpn->name, name) == 0) - return (l2vpn); - - return (NULL); + struct l2vpn l2vpn; + strlcpy(l2vpn.name, name, sizeof(l2vpn.name)); + return (RB_FIND(l2vpn_head, &xconf->l2vpn_tree, &l2vpn)); } void @@ -399,7 +404,7 @@ l2vpn_sync_pws(int af, union ldpd_addr *addr) struct fec_node *fn; struct fec_nh *fnh; - LIST_FOREACH(l2vpn, &ldeconf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) { LIST_FOREACH(pw, &l2vpn->pw_list, entry) { if (af != pw->af || ldp_addrcmp(af, &pw->addr, addr)) continue; @@ -428,7 +433,7 @@ l2vpn_pw_ctl(pid_t pid) struct l2vpn_pw *pw; static struct ctl_pw pwctl; - LIST_FOREACH(l2vpn, &ldeconf->l2vpn_list, entry) + RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) LIST_FOREACH(pw, &l2vpn->pw_list, entry) { memset(&pwctl, 0, sizeof(pwctl)); strlcpy(pwctl.l2vpn_name, pw->l2vpn->name, diff --git a/ldpd/lde.c b/ldpd/lde.c index 80557ed4ef..3feb27d168 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -476,7 +476,7 @@ lde_dispatch_parent(struct thread *thread) RB_INIT(&nconf->iface_tree); RB_INIT(&nconf->tnbr_tree); RB_INIT(&nconf->nbrp_tree); - LIST_INIT(&nconf->l2vpn_list); + RB_INIT(&nconf->l2vpn_tree); break; case IMSG_RECONF_IFACE: if ((niface = malloc(sizeof(struct iface))) == NULL) @@ -514,7 +514,7 @@ lde_dispatch_parent(struct thread *thread) LIST_INIT(&nl2vpn->pw_list); LIST_INIT(&nl2vpn->pw_inactive_list); - LIST_INSERT_HEAD(&nconf->l2vpn_list, nl2vpn, entry); + RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn); break; case IMSG_RECONF_L2VPN_IF: if ((nlif = malloc(sizeof(struct l2vpn_if))) == NULL) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 95b0971e64..b66d8d4698 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -341,7 +341,7 @@ ldp_l2vpn_config_write(struct vty *vty) struct l2vpn_if *lif; struct l2vpn_pw *pw; - LIST_FOREACH(l2vpn, &ldpd_conf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &ldpd_conf->l2vpn_tree) { vty_out(vty, "l2vpn %s type vpls%s", l2vpn->name, VTY_NEWLINE); if (l2vpn->pw_type != DEFAULT_PW_TYPE) @@ -393,7 +393,7 @@ ldp_iface_is_configured(struct ldpd_conf *xconf, const char *ifname) if (if_lookup_name(xconf, ifname)) return (1); - LIST_FOREACH(l2vpn, &xconf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) { if (l2vpn_if_find_name(l2vpn, ifname)) return (1); if (l2vpn_pw_find_name(l2vpn, ifname)) @@ -1235,7 +1235,7 @@ ldp_vty_l2vpn(struct vty *vty, struct vty_arg *args[]) if (l2vpn == NULL) goto cancel; - LIST_REMOVE(l2vpn, entry); + RB_REMOVE(l2vpn_head, &vty_conf->l2vpn_tree, l2vpn); l2vpn_del(l2vpn); ldp_reload(vty_conf); return (CMD_SUCCESS); @@ -1248,7 +1248,7 @@ ldp_vty_l2vpn(struct vty *vty, struct vty_arg *args[]) l2vpn = l2vpn_new(name_str); l2vpn->type = L2VPN_TYPE_VPLS; - LIST_INSERT_HEAD(&vty_conf->l2vpn_list, l2vpn, entry); + RB_INSERT(l2vpn_head, &vty_conf->l2vpn_tree, l2vpn); ldp_reload_ref(vty_conf, (void **)&l2vpn); VTY_PUSH_CONTEXT(LDP_L2VPN_NODE, l2vpn); @@ -1706,12 +1706,12 @@ l2vpn_new_api(struct ldpd_conf *conf, const char *name) l2vpn = l2vpn_new(name); l2vpn->type = L2VPN_TYPE_VPLS; - LIST_INSERT_HEAD(&conf->l2vpn_list, l2vpn, entry); + RB_INSERT(l2vpn_head, &conf->l2vpn_tree, l2vpn); return (l2vpn); } void -l2vpn_del_api(struct l2vpn *l2vpn) +l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn) { struct l2vpn_if *lif; struct l2vpn_pw *pw; @@ -1728,7 +1728,7 @@ l2vpn_del_api(struct l2vpn *l2vpn) LIST_REMOVE(pw, entry); free(pw); } - LIST_REMOVE(l2vpn, entry); + RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn); free(l2vpn); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 37cc0dec16..dab761db7f 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -868,7 +868,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) return (-1); } - LIST_FOREACH(l2vpn, &xconf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) { if (main_imsg_compose_both(IMSG_RECONF_L2VPN, l2vpn, sizeof(*l2vpn)) == -1) return (-1); @@ -930,7 +930,7 @@ ldp_config_normalize(struct ldpd_conf *xconf, void **ref) ldp_config_reset_af(xconf, AF_INET6, ref); } - LIST_FOREACH(l2vpn, &xconf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) { LIST_FOREACH(pw, &l2vpn->pw_list, entry) { if (pw->flags & F_PW_STATIC_NBR_ADDR) continue; @@ -1035,7 +1035,7 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) RB_INIT(&xconf->iface_tree); RB_INIT(&xconf->tnbr_tree); RB_INIT(&xconf->nbrp_tree); - LIST_INIT(&xconf->l2vpn_list); + RB_INIT(&xconf->l2vpn_tree); RB_FOREACH(iface, iface_head, &conf->iface_tree) { COPY(xi, iface); @@ -1051,12 +1051,12 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) COPY(xn, nbrp); RB_INSERT(nbrp_head, &xconf->nbrp_tree, xn); } - LIST_FOREACH(l2vpn, &conf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &conf->l2vpn_tree) { COPY(xl, l2vpn); LIST_INIT(&xl->if_list); LIST_INIT(&xl->pw_list); LIST_INIT(&xl->pw_inactive_list); - LIST_INSERT_HEAD(&xconf->l2vpn_list, xl, entry); + RB_INSERT(l2vpn_head, &xconf->l2vpn_tree, xl); LIST_FOREACH(lif, &l2vpn->if_list, entry) { COPY(xf, lif); @@ -1105,8 +1105,8 @@ ldp_clear_config(struct ldpd_conf *xconf) RB_REMOVE(nbrp_head, &xconf->nbrp_tree, nbrp); free(nbrp); } - while ((l2vpn = LIST_FIRST(&xconf->l2vpn_list)) != NULL) { - LIST_REMOVE(l2vpn, entry); + while ((l2vpn = RB_ROOT(&xconf->l2vpn_tree)) != NULL) { + RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, l2vpn); l2vpn_del(l2vpn); } @@ -1469,10 +1469,10 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) struct l2vpn_if *lif; struct l2vpn_pw *pw; - LIST_FOREACH_SAFE(l2vpn, &conf->l2vpn_list, entry, ltmp) { + RB_FOREACH_SAFE(l2vpn, l2vpn_head, &conf->l2vpn_tree, ltmp) { /* find deleted l2vpns */ if ((xl = l2vpn_find(xconf, l2vpn->name)) == NULL) { - LIST_REMOVE(l2vpn, entry); + RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1494,11 +1494,11 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) l2vpn_del(l2vpn); } } - LIST_FOREACH_SAFE(xl, &xconf->l2vpn_list, entry, ltmp) { + RB_FOREACH_SAFE(xl, l2vpn_head, &xconf->l2vpn_tree, ltmp) { /* find new l2vpns */ if ((l2vpn = l2vpn_find(conf, xl->name)) == NULL) { - LIST_REMOVE(xl, entry); - LIST_INSERT_HEAD(&conf->l2vpn_list, xl, entry); + RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, xl); + RB_INSERT(l2vpn_head, &conf->l2vpn_tree, xl); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1516,7 +1516,7 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) /* update existing l2vpns */ merge_l2vpn(conf, l2vpn, xl, ref); - LIST_REMOVE(xl, entry); + RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, xl); if (ref && *ref == xl) *ref = l2vpn; free(xl); @@ -1773,7 +1773,7 @@ config_new_empty(void) RB_INIT(&xconf->iface_tree); RB_INIT(&xconf->tnbr_tree); RB_INIT(&xconf->nbrp_tree); - LIST_INIT(&xconf->l2vpn_list); + RB_INIT(&xconf->l2vpn_tree); return (xconf); } diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index d8f75a0eec..72e5dc5bcf 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -358,7 +358,7 @@ DECLARE_QOBJ_TYPE(l2vpn_pw) #define F_PW_STATIC_NBR_ADDR 0x20 /* static neighbor address configured */ struct l2vpn { - LIST_ENTRY(l2vpn) entry; + RB_ENTRY(l2vpn) entry; char name[L2VPN_NAME_LEN]; int type; int pw_type; @@ -370,6 +370,8 @@ struct l2vpn { LIST_HEAD(, l2vpn_pw) pw_inactive_list; QOBJ_FIELDS }; +RB_HEAD(l2vpn_head, l2vpn); +RB_PROTOTYPE(l2vpn_head, l2vpn, entry, l2vpn_compare); DECLARE_QOBJ_TYPE(l2vpn) #define L2VPN_TYPE_VPWS 1 #define L2VPN_TYPE_VPLS 2 @@ -413,7 +415,7 @@ struct ldpd_conf { struct iface_head iface_tree; struct tnbr_head tnbr_tree; struct nbrp_head nbrp_tree; - LIST_HEAD(, l2vpn) l2vpn_list; + struct l2vpn_head l2vpn_tree; uint16_t lhello_holdtime; uint16_t lhello_interval; uint16_t thello_holdtime; @@ -644,8 +646,9 @@ struct nbr_params *nbrp_new_api(struct ldpd_conf *conf, struct in_addr lsr_id); void nbrp_del_api(struct ldpd_conf *conf, struct nbr_params *nbrp); -struct l2vpn *l2vpn_new_api(struct ldpd_conf *cfg, const char *name); -void l2vpn_del_api(struct l2vpn *l2vpn); +struct l2vpn *l2vpn_new_api(struct ldpd_conf *conf, const char *name); +void l2vpn_del_api(struct ldpd_conf *conf, + struct l2vpn *l2vpn); struct l2vpn_if *l2vpn_if_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, const char *ifname); void l2vpn_if_del_api(struct l2vpn_if *lif); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index e9e45f8fe3..6edd180a43 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -417,7 +417,7 @@ ldpe_dispatch_main(struct thread *thread) RB_INIT(&nconf->iface_tree); RB_INIT(&nconf->tnbr_tree); RB_INIT(&nconf->nbrp_tree); - LIST_INIT(&nconf->l2vpn_list); + RB_INIT(&nconf->l2vpn_tree); break; case IMSG_RECONF_IFACE: if ((niface = malloc(sizeof(struct iface))) == NULL) @@ -455,7 +455,7 @@ ldpe_dispatch_main(struct thread *thread) LIST_INIT(&nl2vpn->pw_list); LIST_INIT(&nl2vpn->pw_inactive_list); - LIST_INSERT_HEAD(&nconf->l2vpn_list, nl2vpn, entry); + RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn); break; case IMSG_RECONF_L2VPN_IF: if ((nlif = malloc(sizeof(struct l2vpn_if))) == NULL) From 029c195854a229067a4c4374f17f8fa54fc1c56b Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 12:34:57 -0200 Subject: [PATCH 13/35] ldpd: use red-black trees to store 'l2vpn_if' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/l2vpn.c | 26 +++++++++++++++----------- ldpd/lde.c | 4 ++-- ldpd/ldp_vty_conf.c | 16 ++++++++-------- ldpd/ldpd.c | 22 +++++++++++----------- ldpd/ldpd.h | 9 ++++++--- ldpd/ldpe.c | 4 ++-- 6 files changed, 44 insertions(+), 37 deletions(-) diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index b339c9ce6b..02f25e18b0 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -28,8 +28,10 @@ static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *); static __inline int l2vpn_compare(struct l2vpn *, struct l2vpn *); +static __inline int l2vpn_if_compare(struct l2vpn_if *, struct l2vpn_if *); RB_GENERATE(l2vpn_head, l2vpn, entry, l2vpn_compare) +RB_GENERATE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare) static __inline int l2vpn_compare(struct l2vpn *a, struct l2vpn *b) @@ -51,7 +53,7 @@ l2vpn_new(const char *name) l2vpn->mtu = DEFAULT_L2VPN_MTU; l2vpn->pw_type = DEFAULT_PW_TYPE; - LIST_INIT(&l2vpn->if_list); + RB_INIT(&l2vpn->if_tree); LIST_INIT(&l2vpn->pw_list); LIST_INIT(&l2vpn->pw_inactive_list); @@ -72,8 +74,8 @@ l2vpn_del(struct l2vpn *l2vpn) struct l2vpn_if *lif; struct l2vpn_pw *pw; - while ((lif = LIST_FIRST(&l2vpn->if_list)) != NULL) { - LIST_REMOVE(lif, entry); + while ((lif = RB_ROOT(&l2vpn->if_tree)) != NULL) { + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) { @@ -106,6 +108,12 @@ l2vpn_exit(struct l2vpn *l2vpn) l2vpn_pw_exit(pw); } +static __inline int +l2vpn_if_compare(struct l2vpn_if *a, struct l2vpn_if *b) +{ + return (strcmp(a->ifname, b->ifname)); +} + struct l2vpn_if * l2vpn_if_new(struct l2vpn *l2vpn, struct kif *kif) { @@ -127,7 +135,7 @@ l2vpn_if_find(struct l2vpn *l2vpn, unsigned int ifindex) { struct l2vpn_if *lif; - LIST_FOREACH(lif, &l2vpn->if_list, entry) + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) if (lif->ifindex == ifindex) return (lif); @@ -137,13 +145,9 @@ l2vpn_if_find(struct l2vpn *l2vpn, unsigned int ifindex) struct l2vpn_if * l2vpn_if_find_name(struct l2vpn *l2vpn, const char *ifname) { - struct l2vpn_if *lif; - - LIST_FOREACH(lif, &l2vpn->if_list, entry) - if (strcmp(lif->ifname, ifname) == 0) - return (lif); - - return (NULL); + struct l2vpn_if lif; + strlcpy(lif.ifname, ifname, sizeof(lif.ifname)); + return (RB_FIND(l2vpn_if_head, &l2vpn->if_tree, &lif)); } diff --git a/ldpd/lde.c b/ldpd/lde.c index 3feb27d168..522650cdc6 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -510,7 +510,7 @@ lde_dispatch_parent(struct thread *thread) fatal(NULL); memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn)); - LIST_INIT(&nl2vpn->if_list); + RB_INIT(&nl2vpn->if_tree); LIST_INIT(&nl2vpn->pw_list); LIST_INIT(&nl2vpn->pw_inactive_list); @@ -522,7 +522,7 @@ lde_dispatch_parent(struct thread *thread) memcpy(nlif, imsg.data, sizeof(struct l2vpn_if)); nlif->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->if_list, nlif, entry); + RB_INSERT(l2vpn_if_head, &nl2vpn->if_tree, nlif); break; case IMSG_RECONF_L2VPN_PW: if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index b66d8d4698..b97964228d 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -354,7 +354,7 @@ ldp_l2vpn_config_write(struct vty *vty) vty_out(vty, " bridge %s%s", l2vpn->br_ifname, VTY_NEWLINE); - LIST_FOREACH(lif, &l2vpn->if_list, entry) + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) vty_out(vty, " member interface %s%s", lif->ifname, VTY_NEWLINE); @@ -1369,7 +1369,7 @@ ldp_vty_l2vpn_interface(struct vty *vty, struct vty_arg *args[]) if (lif == NULL) goto cancel; - LIST_REMOVE(lif, entry); + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); ldp_reload(vty_conf); return (CMD_SUCCESS); @@ -1392,7 +1392,7 @@ ldp_vty_l2vpn_interface(struct vty *vty, struct vty_arg *args[]) } lif = l2vpn_if_new(l2vpn, &kif); - LIST_INSERT_HEAD(&l2vpn->if_list, lif, entry); + RB_INSERT(l2vpn_if_head, &l2vpn->if_tree, lif); ldp_reload_ref(vty_conf, (void **)&l2vpn); @@ -1716,8 +1716,8 @@ l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn) struct l2vpn_if *lif; struct l2vpn_pw *pw; - while ((lif = LIST_FIRST(&l2vpn->if_list)) != NULL) { - LIST_REMOVE(lif, entry); + while ((lif = RB_ROOT(&l2vpn->if_tree)) != NULL) { + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) { @@ -1752,14 +1752,14 @@ l2vpn_if_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, } lif = l2vpn_if_new(l2vpn, &kif); - LIST_INSERT_HEAD(&l2vpn->if_list, lif, entry); + RB_INSERT(l2vpn_if_head, &l2vpn->if_tree, lif); return (lif); } void -l2vpn_if_del_api(struct l2vpn_if *lif) +l2vpn_if_del_api(struct l2vpn *l2vpn, struct l2vpn_if *lif) { - LIST_REMOVE(lif, entry); + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index dab761db7f..0df9bbd61d 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -873,7 +873,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) sizeof(*l2vpn)) == -1) return (-1); - LIST_FOREACH(lif, &l2vpn->if_list, entry) { + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) { if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF, lif, sizeof(*lif)) == -1) return (-1); @@ -1053,15 +1053,15 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) } RB_FOREACH(l2vpn, l2vpn_head, &conf->l2vpn_tree) { COPY(xl, l2vpn); - LIST_INIT(&xl->if_list); + RB_INIT(&xl->if_tree); LIST_INIT(&xl->pw_list); LIST_INIT(&xl->pw_inactive_list); RB_INSERT(l2vpn_head, &xconf->l2vpn_tree, xl); - LIST_FOREACH(lif, &l2vpn->if_list, entry) { + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) { COPY(xf, lif); xf->l2vpn = xl; - LIST_INSERT_HEAD(&xl->if_list, xf, entry); + RB_INSERT(l2vpn_if_head, &xl->if_tree, xf); } LIST_FOREACH(pw, &l2vpn->pw_list, entry) { COPY(xp, pw); @@ -1482,7 +1482,7 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) ldpe_l2vpn_exit(l2vpn); break; case PROC_MAIN: - LIST_FOREACH(lif, &l2vpn->if_list, entry) + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) QOBJ_UNREG (lif); LIST_FOREACH(pw, &l2vpn->pw_list, entry) QOBJ_UNREG (pw); @@ -1537,27 +1537,27 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void previous_mtu = l2vpn->mtu; /* merge intefaces */ - LIST_FOREACH_SAFE(lif, &l2vpn->if_list, entry, ftmp) { + RB_FOREACH_SAFE(lif, l2vpn_if_head, &l2vpn->if_tree, ftmp) { /* find deleted interfaces */ if ((xf = l2vpn_if_find_name(xl, lif->ifname)) == NULL) { if (ldpd_process == PROC_MAIN) QOBJ_UNREG (lif); - LIST_REMOVE(lif, entry); + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } } - LIST_FOREACH_SAFE(xf, &xl->if_list, entry, ftmp) { + RB_FOREACH_SAFE(xf, l2vpn_if_head, &xl->if_tree, ftmp) { /* find new interfaces */ if ((lif = l2vpn_if_find_name(l2vpn, xf->ifname)) == NULL) { - LIST_REMOVE(xf, entry); - LIST_INSERT_HEAD(&l2vpn->if_list, xf, entry); + RB_REMOVE(l2vpn_if_head, &xl->if_tree, xf); + RB_INSERT(l2vpn_if_head, &l2vpn->if_tree, xf); xf->l2vpn = l2vpn; if (ldpd_process == PROC_MAIN) QOBJ_REG (xf, l2vpn_if); continue; } - LIST_REMOVE(xf, entry); + RB_REMOVE(l2vpn_if_head, &xl->if_tree, xf); if (ref && *ref == xf) *ref = lif; free(xf); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 72e5dc5bcf..0a21856347 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -325,13 +325,15 @@ DECLARE_QOBJ_TYPE(nbr_params) #define F_NBRP_GTSM_HOPS 0x04 struct l2vpn_if { - LIST_ENTRY(l2vpn_if) entry; + RB_ENTRY(l2vpn_if) entry; struct l2vpn *l2vpn; char ifname[IF_NAMESIZE]; unsigned int ifindex; uint16_t flags; QOBJ_FIELDS }; +RB_HEAD(l2vpn_if_head, l2vpn_if); +RB_PROTOTYPE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare); DECLARE_QOBJ_TYPE(l2vpn_if) struct l2vpn_pw { @@ -365,7 +367,7 @@ struct l2vpn { int mtu; char br_ifname[IF_NAMESIZE]; unsigned int br_ifindex; - LIST_HEAD(, l2vpn_if) if_list; + struct l2vpn_if_head if_tree; LIST_HEAD(, l2vpn_pw) pw_list; LIST_HEAD(, l2vpn_pw) pw_inactive_list; QOBJ_FIELDS @@ -651,7 +653,8 @@ void l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn); struct l2vpn_if *l2vpn_if_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, const char *ifname); -void l2vpn_if_del_api(struct l2vpn_if *lif); +void l2vpn_if_del_api(struct l2vpn *l2vpn, + struct l2vpn_if *lif); struct l2vpn_pw *l2vpn_pw_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, const char *ifname); void l2vpn_pw_del_api(struct l2vpn_pw *pw); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 6edd180a43..2a9fb4c1d8 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -451,7 +451,7 @@ ldpe_dispatch_main(struct thread *thread) fatal(NULL); memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn)); - LIST_INIT(&nl2vpn->if_list); + RB_INIT(&nl2vpn->if_tree); LIST_INIT(&nl2vpn->pw_list); LIST_INIT(&nl2vpn->pw_inactive_list); @@ -463,7 +463,7 @@ ldpe_dispatch_main(struct thread *thread) memcpy(nlif, imsg.data, sizeof(struct l2vpn_if)); nlif->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->if_list, nlif, entry); + RB_INSERT(l2vpn_if_head, &nl2vpn->if_tree, nlif); break; case IMSG_RECONF_L2VPN_PW: if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL) From 20bacaeba2381b7b199166e006576606defbaf0f Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 13:53:07 -0200 Subject: [PATCH 14/35] ldpd: use red-black trees to store 'l2vpn_pw' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/l2vpn.c | 49 ++++++++++++++++++--------------- ldpd/lde.c | 8 +++--- ldpd/ldp_vty_conf.c | 22 +++++++-------- ldpd/ldpd.c | 66 ++++++++++++++++++++++----------------------- ldpd/ldpd.h | 11 +++++--- ldpd/ldpe.c | 8 +++--- 6 files changed, 86 insertions(+), 78 deletions(-) diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index 02f25e18b0..c1d0437fba 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -29,9 +29,11 @@ static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *); static __inline int l2vpn_compare(struct l2vpn *, struct l2vpn *); static __inline int l2vpn_if_compare(struct l2vpn_if *, struct l2vpn_if *); +static __inline int l2vpn_pw_compare(struct l2vpn_pw *, struct l2vpn_pw *); RB_GENERATE(l2vpn_head, l2vpn, entry, l2vpn_compare) RB_GENERATE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare) +RB_GENERATE(l2vpn_pw_head, l2vpn_pw, entry, l2vpn_pw_compare) static __inline int l2vpn_compare(struct l2vpn *a, struct l2vpn *b) @@ -54,8 +56,8 @@ l2vpn_new(const char *name) l2vpn->pw_type = DEFAULT_PW_TYPE; RB_INIT(&l2vpn->if_tree); - LIST_INIT(&l2vpn->pw_list); - LIST_INIT(&l2vpn->pw_inactive_list); + RB_INIT(&l2vpn->pw_tree); + RB_INIT(&l2vpn->pw_inactive_tree); return (l2vpn); } @@ -78,12 +80,12 @@ l2vpn_del(struct l2vpn *l2vpn) RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } - while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) { - LIST_REMOVE(pw, entry); + while ((pw = RB_ROOT(&l2vpn->pw_tree)) != NULL) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); free(pw); } - while ((pw = LIST_FIRST(&l2vpn->pw_inactive_list)) != NULL) { - LIST_REMOVE(pw, entry); + while ((pw = RB_ROOT(&l2vpn->pw_inactive_tree)) != NULL) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); } @@ -95,7 +97,7 @@ l2vpn_init(struct l2vpn *l2vpn) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) l2vpn_pw_init(pw); } @@ -104,7 +106,7 @@ l2vpn_exit(struct l2vpn *l2vpn) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) l2vpn_pw_exit(pw); } @@ -150,6 +152,11 @@ l2vpn_if_find_name(struct l2vpn *l2vpn, const char *ifname) return (RB_FIND(l2vpn_if_head, &l2vpn->if_tree, &lif)); } +static __inline int +l2vpn_pw_compare(struct l2vpn_pw *a, struct l2vpn_pw *b) +{ + return (strcmp(a->ifname, b->ifname)); +} struct l2vpn_pw * l2vpn_pw_new(struct l2vpn *l2vpn, struct kif *kif) @@ -171,10 +178,10 @@ l2vpn_pw_find(struct l2vpn *l2vpn, unsigned int ifindex) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) if (pw->ifindex == ifindex) return (pw); - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) if (pw->ifindex == ifindex) return (pw); @@ -185,15 +192,13 @@ struct l2vpn_pw * l2vpn_pw_find_name(struct l2vpn *l2vpn, const char *ifname) { struct l2vpn_pw *pw; + struct l2vpn_pw s; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) - if (strcmp(pw->ifname, ifname) == 0) - return (pw); - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) - if (strcmp(pw->ifname, ifname) == 0) - return (pw); - - return (NULL); + strlcpy(s.ifname, ifname, sizeof(s.ifname)); + pw = RB_FIND(l2vpn_pw_head, &l2vpn->pw_tree, &s); + if (pw) + return (pw); + return (RB_FIND(l2vpn_pw_head, &l2vpn->pw_inactive_tree, &s)); } void @@ -409,7 +414,7 @@ l2vpn_sync_pws(int af, union ldpd_addr *addr) struct fec_nh *fnh; RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) { - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { if (af != pw->af || ldp_addrcmp(af, &pw->addr, addr)) continue; @@ -438,7 +443,7 @@ l2vpn_pw_ctl(pid_t pid) static struct ctl_pw pwctl; RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { memset(&pwctl, 0, sizeof(pwctl)); strlcpy(pwctl.l2vpn_name, pw->l2vpn->name, sizeof(pwctl.l2vpn_name)); @@ -517,7 +522,7 @@ ldpe_l2vpn_init(struct l2vpn *l2vpn) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) ldpe_l2vpn_pw_init(pw); } @@ -526,7 +531,7 @@ ldpe_l2vpn_exit(struct l2vpn *l2vpn) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) ldpe_l2vpn_pw_exit(pw); } diff --git a/ldpd/lde.c b/ldpd/lde.c index 522650cdc6..aa83ef0aba 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -511,8 +511,8 @@ lde_dispatch_parent(struct thread *thread) memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn)); RB_INIT(&nl2vpn->if_tree); - LIST_INIT(&nl2vpn->pw_list); - LIST_INIT(&nl2vpn->pw_inactive_list); + RB_INIT(&nl2vpn->pw_tree); + RB_INIT(&nl2vpn->pw_inactive_tree); RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn); break; @@ -530,7 +530,7 @@ lde_dispatch_parent(struct thread *thread) memcpy(npw, imsg.data, sizeof(struct l2vpn_pw)); npw->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->pw_list, npw, entry); + RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_tree, npw); break; case IMSG_RECONF_L2VPN_IPW: if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL) @@ -538,7 +538,7 @@ lde_dispatch_parent(struct thread *thread) memcpy(npw, imsg.data, sizeof(struct l2vpn_pw)); npw->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->pw_inactive_list, npw, entry); + RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_inactive_tree, npw); break; case IMSG_RECONF_END: merge_config(ldeconf, nconf); diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index b97964228d..e408abb091 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -358,9 +358,9 @@ ldp_l2vpn_config_write(struct vty *vty) vty_out(vty, " member interface %s%s", lif->ifname, VTY_NEWLINE); - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) ldp_l2vpn_pw_config_write(vty, pw); - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) ldp_l2vpn_pw_config_write(vty, pw); vty_out(vty, " !%s", VTY_NEWLINE); @@ -1425,7 +1425,7 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, struct vty_arg *args[]) if (pw == NULL) goto cancel; - LIST_REMOVE(pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); ldp_reload(vty_conf); return (CMD_SUCCESS); @@ -1451,7 +1451,7 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, struct vty_arg *args[]) pw = l2vpn_pw_new(l2vpn, &kif); pw->flags = F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF; - LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); ldp_reload_ref(vty_conf, (void **)&pw); VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE, pw); @@ -1720,12 +1720,12 @@ l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn) RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } - while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) { - LIST_REMOVE(pw, entry); + while ((pw = RB_ROOT(&l2vpn->pw_tree)) != NULL) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); free(pw); } - while ((pw = LIST_FIRST(&l2vpn->pw_inactive_list)) != NULL) { - LIST_REMOVE(pw, entry); + while ((pw = RB_ROOT(&l2vpn->pw_inactive_tree)) != NULL) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); } RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn); @@ -1784,13 +1784,13 @@ l2vpn_pw_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, pw = l2vpn_pw_new(l2vpn, &kif); pw->flags = F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF; - LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); return (pw); } void -l2vpn_pw_del_api(struct l2vpn_pw *pw) +l2vpn_pw_del_api(struct l2vpn *l2vpn, struct l2vpn_pw *pw) { - LIST_REMOVE(pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 0df9bbd61d..943129f513 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -878,12 +878,12 @@ main_imsg_send_config(struct ldpd_conf *xconf) sizeof(*lif)) == -1) return (-1); } - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW, pw, sizeof(*pw)) == -1) return (-1); } - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) { if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW, pw, sizeof(*pw)) == -1) return (-1); @@ -931,14 +931,14 @@ ldp_config_normalize(struct ldpd_conf *xconf, void **ref) } RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) { - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { if (pw->flags & F_PW_STATIC_NBR_ADDR) continue; pw->af = AF_INET; pw->addr.v4 = pw->lsr_id; } - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) { if (pw->flags & F_PW_STATIC_NBR_ADDR) continue; @@ -1054,8 +1054,8 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) RB_FOREACH(l2vpn, l2vpn_head, &conf->l2vpn_tree) { COPY(xl, l2vpn); RB_INIT(&xl->if_tree); - LIST_INIT(&xl->pw_list); - LIST_INIT(&xl->pw_inactive_list); + RB_INIT(&xl->pw_tree); + RB_INIT(&xl->pw_inactive_tree); RB_INSERT(l2vpn_head, &xconf->l2vpn_tree, xl); RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) { @@ -1063,15 +1063,15 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) xf->l2vpn = xl; RB_INSERT(l2vpn_if_head, &xl->if_tree, xf); } - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { COPY(xp, pw); xp->l2vpn = xl; - LIST_INSERT_HEAD(&xl->pw_list, xp, entry); + RB_INSERT(l2vpn_pw_head, &xl->pw_tree, xp); } - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) { COPY(xp, pw); xp->l2vpn = xl; - LIST_INSERT_HEAD(&xl->pw_inactive_list, xp, entry); + RB_INSERT(l2vpn_pw_head, &xl->pw_inactive_tree, xp); } } #undef COPY @@ -1484,9 +1484,9 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) case PROC_MAIN: RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) QOBJ_UNREG (lif); - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) QOBJ_UNREG (pw); - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) QOBJ_UNREG (pw); QOBJ_UNREG (l2vpn); break; @@ -1530,7 +1530,7 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void struct l2vpn_pw *pw, *ptmp, *xp; struct nbr *nbr; int reset_nbr, reinstall_pwfec, reinstall_tnbr; - LIST_HEAD(, l2vpn_pw) pw_aux_list; + struct l2vpn_pw_head pw_aux_list; int previous_pw_type, previous_mtu; previous_pw_type = l2vpn->pw_type; @@ -1564,8 +1564,8 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void } /* merge active pseudowires */ - LIST_INIT(&pw_aux_list); - LIST_FOREACH_SAFE(pw, &l2vpn->pw_list, entry, ptmp) { + RB_INIT(&pw_aux_list); + RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_tree, ptmp) { /* find deleted active pseudowires */ if ((xp = l2vpn_pw_find_name(xl, pw->ifname)) == NULL) { switch (ldpd_process) { @@ -1580,15 +1580,15 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void break; } - LIST_REMOVE(pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); free(pw); } } - LIST_FOREACH_SAFE(xp, &xl->pw_list, entry, ptmp) { + RB_FOREACH_SAFE(xp, l2vpn_pw_head, &xl->pw_tree, ptmp) { /* find new active pseudowires */ if ((pw = l2vpn_pw_find_name(l2vpn, xp->ifname)) == NULL) { - LIST_REMOVE(xp, entry); - LIST_INSERT_HEAD(&l2vpn->pw_list, xp, entry); + RB_REMOVE(l2vpn_pw_head, &xl->pw_tree, xp); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_tree, xp); xp->l2vpn = l2vpn; switch (ldpd_process) { @@ -1644,8 +1644,8 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void } /* remove from active list */ - LIST_REMOVE(pw, entry); - LIST_INSERT_HEAD(&pw_aux_list, pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); + RB_INSERT(l2vpn_pw_head, &pw_aux_list, pw); } if (ldpd_process == PROC_LDP_ENGINE) { @@ -1689,27 +1689,27 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void l2vpn->mtu = previous_mtu; } - LIST_REMOVE(xp, entry); + RB_REMOVE(l2vpn_pw_head, &xl->pw_tree, xp); if (ref && *ref == xp) *ref = pw; free(xp); } /* merge inactive pseudowires */ - LIST_FOREACH_SAFE(pw, &l2vpn->pw_inactive_list, entry, ptmp) { + RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree, ptmp) { /* find deleted inactive pseudowires */ if ((xp = l2vpn_pw_find_name(xl, pw->ifname)) == NULL) { - LIST_REMOVE(pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); if (ldpd_process == PROC_MAIN) QOBJ_UNREG (pw); free(pw); } } - LIST_FOREACH_SAFE(xp, &xl->pw_inactive_list, entry, ptmp) { + RB_FOREACH_SAFE(xp, l2vpn_pw_head, &xl->pw_inactive_tree, ptmp) { /* find new inactive pseudowires */ if ((pw = l2vpn_pw_find_name(l2vpn, xp->ifname)) == NULL) { - LIST_REMOVE(xp, entry); - LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, xp, entry); + RB_REMOVE(l2vpn_pw_head, &xl->pw_inactive_tree, xp); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, xp); xp->l2vpn = l2vpn; if (ldpd_process == PROC_MAIN) QOBJ_REG (xp, l2vpn_pw); @@ -1728,8 +1728,8 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void /* check if the pseudowire should be activated */ if (pw->lsr_id.s_addr != INADDR_ANY && pw->pwid != 0) { /* remove from inactive list */ - LIST_REMOVE(pw, entry); - LIST_INSERT_HEAD(&l2vpn->pw_list, pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_tree, pw); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1743,16 +1743,16 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void } } - LIST_REMOVE(xp, entry); + RB_REMOVE(l2vpn_pw_head, &xl->pw_inactive_tree, xp); if (ref && *ref == xp) *ref = pw; free(xp); } /* insert pseudowires that were disabled in the inactive list */ - LIST_FOREACH_SAFE(pw, &pw_aux_list, entry, ptmp) { - LIST_REMOVE(pw, entry); - LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry); + RB_FOREACH_SAFE(pw, l2vpn_pw_head, &pw_aux_list, ptmp) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); } l2vpn->pw_type = xl->pw_type; diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 0a21856347..6836920bc9 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -337,7 +337,7 @@ RB_PROTOTYPE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare); DECLARE_QOBJ_TYPE(l2vpn_if) struct l2vpn_pw { - LIST_ENTRY(l2vpn_pw) entry; + RB_ENTRY(l2vpn_pw) entry; struct l2vpn *l2vpn; struct in_addr lsr_id; int af; @@ -351,6 +351,8 @@ struct l2vpn_pw { uint8_t flags; QOBJ_FIELDS }; +RB_HEAD(l2vpn_pw_head, l2vpn_pw); +RB_PROTOTYPE(l2vpn_pw_head, l2vpn_pw, entry, l2vpn_pw_compare); DECLARE_QOBJ_TYPE(l2vpn_pw) #define F_PW_STATUSTLV_CONF 0x01 /* status tlv configured */ #define F_PW_STATUSTLV 0x02 /* status tlv negotiated */ @@ -368,8 +370,8 @@ struct l2vpn { char br_ifname[IF_NAMESIZE]; unsigned int br_ifindex; struct l2vpn_if_head if_tree; - LIST_HEAD(, l2vpn_pw) pw_list; - LIST_HEAD(, l2vpn_pw) pw_inactive_list; + struct l2vpn_pw_head pw_tree; + struct l2vpn_pw_head pw_inactive_tree; QOBJ_FIELDS }; RB_HEAD(l2vpn_head, l2vpn); @@ -657,7 +659,8 @@ void l2vpn_if_del_api(struct l2vpn *l2vpn, struct l2vpn_if *lif); struct l2vpn_pw *l2vpn_pw_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, const char *ifname); -void l2vpn_pw_del_api(struct l2vpn_pw *pw); +void l2vpn_pw_del_api(struct l2vpn *l2vpn, + struct l2vpn_pw *pw); /* socket.c */ int ldp_create_socket(int, enum socket_type); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 2a9fb4c1d8..c3640d4131 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -452,8 +452,8 @@ ldpe_dispatch_main(struct thread *thread) memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn)); RB_INIT(&nl2vpn->if_tree); - LIST_INIT(&nl2vpn->pw_list); - LIST_INIT(&nl2vpn->pw_inactive_list); + RB_INIT(&nl2vpn->pw_tree); + RB_INIT(&nl2vpn->pw_inactive_tree); RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn); break; @@ -471,7 +471,7 @@ ldpe_dispatch_main(struct thread *thread) memcpy(npw, imsg.data, sizeof(struct l2vpn_pw)); npw->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->pw_list, npw, entry); + RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_tree, npw); break; case IMSG_RECONF_L2VPN_IPW: if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL) @@ -479,7 +479,7 @@ ldpe_dispatch_main(struct thread *thread) memcpy(npw, imsg.data, sizeof(struct l2vpn_pw)); npw->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->pw_inactive_list, npw, entry); + RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_inactive_tree, npw); break; case IMSG_RECONF_END: merge_config(leconf, nconf); From 057d48bd58776c31db20ec8cf3044cb1d20140d5 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 17:39:28 -0200 Subject: [PATCH 15/35] ldpd: use red-black trees to store 'adj' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/adjacency.c | 80 +++++++++++++++++++++++++++++------------------- ldpd/hello.c | 2 +- ldpd/interface.c | 8 ++--- ldpd/lde.c | 4 +-- ldpd/ldpd.h | 9 ++++-- ldpd/ldpe.c | 18 +++++------ ldpd/ldpe.h | 12 +++++--- ldpd/neighbor.c | 10 +++--- 8 files changed, 84 insertions(+), 59 deletions(-) diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c index 3f478df38a..2e7b43296a 100644 --- a/ldpd/adjacency.c +++ b/ldpd/adjacency.c @@ -25,6 +25,7 @@ #include "ldpe.h" #include "log.h" +static __inline int adj_compare(struct adj *, struct adj *); static int adj_itimer(struct thread *); static __inline int tnbr_compare(struct tnbr *, struct tnbr *); static void tnbr_del(struct ldpd_conf *, struct tnbr *); @@ -32,8 +33,47 @@ static int tnbr_hello_timer(struct thread *); static void tnbr_start_hello_timer(struct tnbr *); static void tnbr_stop_hello_timer(struct tnbr *); +RB_GENERATE(global_adj_head, adj, global_entry, adj_compare) +RB_GENERATE(nbr_adj_head, adj, nbr_entry, adj_compare) +RB_GENERATE(ia_adj_head, adj, ia_entry, adj_compare) RB_GENERATE(tnbr_head, tnbr, entry, tnbr_compare) +static __inline int +adj_compare(struct adj *a, struct adj *b) +{ + if (a->source.type < b->source.type) + return (-1); + if (a->source.type > b->source.type) + return (1); + + switch (a->source.type) { + case HELLO_LINK: + if (strcmp(a->source.link.ia->iface->name, + b->source.link.ia->iface->name) < 0) + return (-1); + if (strcmp(a->source.link.ia->iface->name, + b->source.link.ia->iface->name) > 0) + return (1); + if (a->source.link.ia->af < b->source.link.ia->af) + return (-1); + if (a->source.link.ia->af > b->source.link.ia->af) + return (1); + return (ldp_addrcmp(a->source.link.ia->af, + &a->source.link.src_addr, &b->source.link.src_addr)); + case HELLO_TARGETED: + if (a->source.target->af < b->source.target->af) + return (-1); + if (a->source.target->af > b->source.target->af) + return (1); + return (ldp_addrcmp(a->source.target->af, + &a->source.target->addr, &b->source.target->addr)); + default: + fatalx("adj_get_af: unknown hello type"); + } + + return (0); +} + struct adj * adj_new(struct in_addr lsr_id, struct hello_source *source, union ldpd_addr *addr) @@ -51,11 +91,11 @@ adj_new(struct in_addr lsr_id, struct hello_source *source, adj->source = *source; adj->trans_addr = *addr; - LIST_INSERT_HEAD(&global.adj_list, adj, global_entry); + RB_INSERT(global_adj_head, &global.adj_tree, adj); switch (source->type) { case HELLO_LINK: - LIST_INSERT_HEAD(&source->link.ia->adj_list, adj, ia_entry); + RB_INSERT(ia_adj_head, &source->link.ia->adj_tree, adj); break; case HELLO_TARGETED: source->target->adj = adj; @@ -73,12 +113,12 @@ adj_del_single(struct adj *adj) adj_stop_itimer(adj); - LIST_REMOVE(adj, global_entry); + RB_REMOVE(global_adj_head, &global.adj_tree, adj); if (adj->nbr) - LIST_REMOVE(adj, nbr_entry); + RB_REMOVE(nbr_adj_head, &adj->nbr->adj_tree, adj); switch (adj->source.type) { case HELLO_LINK: - LIST_REMOVE(adj, ia_entry); + RB_REMOVE(ia_adj_head, &adj->source.link.ia->adj_tree, adj); break; case HELLO_TARGETED: adj->source.target->adj = NULL; @@ -102,7 +142,7 @@ adj_del(struct adj *adj, uint32_t notif_status) * then delete it. */ if (nbr && nbr_adj_count(nbr, nbr->af) == 0) { - LIST_FOREACH_SAFE(adj, &nbr->adj_list, nbr_entry, atmp) + RB_FOREACH_SAFE(adj, nbr_adj_head, &nbr->adj_tree, atmp) adj_del_single(adj); session_shutdown(nbr, notif_status, 0, 0); nbr_del(nbr); @@ -112,31 +152,9 @@ adj_del(struct adj *adj, uint32_t notif_status) struct adj * adj_find(struct hello_source *source) { - struct adj *adj; - - LIST_FOREACH(adj, &global.adj_list, global_entry) { - if (adj->source.type != source->type) - continue; - - switch (source->type) { - case HELLO_LINK: - if (strcmp(source->link.ia->iface->name, - adj->source.link.ia->iface->name)) - continue; - - if (ldp_addrcmp(source->link.ia->af, - &adj->source.link.src_addr, - &source->link.src_addr) == 0) - return (adj); - break; - case HELLO_TARGETED: - if (adj->source.target == source->target) - return (adj); - break; - } - } - - return (NULL); + struct adj adj; + adj.source = *source; + return (RB_FIND(global_adj_head, &global.adj_tree, &adj)); } int diff --git a/ldpd/hello.c b/ldpd/hello.c index 0833ebbafb..95be1d5111 100644 --- a/ldpd/hello.c +++ b/ldpd/hello.c @@ -364,7 +364,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, adj = adj_new(lsr_id, &source, &trans_addr); if (nbr) { adj->nbr = nbr; - LIST_INSERT_HEAD(&nbr->adj_list, adj, nbr_entry); + RB_INSERT(nbr_adj_head, &nbr->adj_tree, adj); } } diff --git a/ldpd/interface.c b/ldpd/interface.c index 06d36fef72..8fea91b878 100644 --- a/ldpd/interface.c +++ b/ldpd/interface.c @@ -66,14 +66,14 @@ if_new(struct kif *kif) iface->ipv4.iface = iface; iface->ipv4.enabled = 0; iface->ipv4.state = IF_STA_DOWN; - LIST_INIT(&iface->ipv4.adj_list); + RB_INIT(&iface->ipv4.adj_tree); /* ipv6 */ iface->ipv6.af = AF_INET6; iface->ipv6.iface = iface; iface->ipv6.enabled = 0; iface->ipv6.state = IF_STA_DOWN; - LIST_INIT(&iface->ipv6.adj_list); + RB_INIT(&iface->ipv6.adj_tree); return (iface); } @@ -293,7 +293,7 @@ if_reset(struct iface *iface, int af) ia = iface_af_get(iface, af); if_stop_hello_timer(ia); - while ((adj = LIST_FIRST(&ia->adj_list)) != NULL) + while ((adj = RB_ROOT(&ia->adj_tree)) != NULL) adj_del(adj, S_SHUTDOWN); /* try to cleanup */ @@ -465,7 +465,7 @@ if_to_ctl(struct iface_af *ia) ictl.uptime = 0; ictl.adj_cnt = 0; - LIST_FOREACH(adj, &ia->adj_list, ia_entry) + RB_FOREACH(adj, ia_adj_head, &ia->adj_tree) ictl.adj_cnt++; return (&ictl); diff --git a/ldpd/lde.c b/ldpd/lde.c index aa83ef0aba..5b2ae00fe6 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -484,8 +484,8 @@ lde_dispatch_parent(struct thread *thread) memcpy(niface, imsg.data, sizeof(struct iface)); LIST_INIT(&niface->addr_list); - LIST_INIT(&niface->ipv4.adj_list); - LIST_INIT(&niface->ipv6.adj_list); + RB_INIT(&niface->ipv4.adj_tree); + RB_INIT(&niface->ipv6.adj_tree); niface->ipv4.iface = niface; niface->ipv6.iface = niface; diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 6836920bc9..4d575597ae 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -196,7 +196,10 @@ enum nbr_action { NBR_ACT_CLOSE_SESSION }; -TAILQ_HEAD(mapping_head, mapping_entry); +/* forward declarations */ +RB_HEAD(global_adj_head, adj); +RB_HEAD(nbr_adj_head, adj); +RB_HEAD(ia_adj_head, adj); struct map { uint8_t type; @@ -256,7 +259,7 @@ struct iface_af { int af; int enabled; int state; - LIST_HEAD(, adj) adj_list; + struct ia_adj_head adj_tree; time_t uptime; struct thread *hello_timer; uint16_t hello_holdtime; @@ -450,7 +453,7 @@ struct ldpd_global { uint32_t conf_seqnum; int pfkeysock; struct if_addr_head addr_list; - LIST_HEAD(, adj) adj_list; + struct global_adj_head adj_tree; struct in_addr mcast_addr_v4; struct in6_addr mcast_addr_v6; TAILQ_HEAD(, pending_conn) pending_conns; diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index c3640d4131..c960acf3b1 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -111,7 +111,7 @@ ldpe(const char *user, const char *group) ldpd_process = PROC_LDP_ENGINE; LIST_INIT(&global.addr_list); - LIST_INIT(&global.adj_list); + RB_INIT(&global.adj_tree); TAILQ_INIT(&global.pending_conns); if (inet_pton(AF_INET, AllRouters_v4, &global.mcast_addr_v4) != 1) fatal("inet_pton"); @@ -209,7 +209,7 @@ ldpe_shutdown(void) LIST_REMOVE(if_addr, entry); free(if_addr); } - while ((adj = LIST_FIRST(&global.adj_list)) != NULL) + while ((adj = RB_ROOT(&global.adj_tree)) != NULL) adj_del(adj, S_SHUTDOWN); /* clean up */ @@ -425,8 +425,8 @@ ldpe_dispatch_main(struct thread *thread) memcpy(niface, imsg.data, sizeof(struct iface)); LIST_INIT(&niface->addr_list); - LIST_INIT(&niface->ipv4.adj_list); - LIST_INIT(&niface->ipv6.adj_list); + RB_INIT(&niface->ipv4.adj_tree); + RB_INIT(&niface->ipv6.adj_tree); niface->ipv4.iface = niface; niface->ipv6.iface = niface; @@ -814,18 +814,18 @@ ldpe_adj_ctl(struct ctl_conn *c) continue; strlcpy(ictl.name, iface->name, sizeof(ictl.name)); - if (LIST_EMPTY(&iface->ipv4.adj_list) && - LIST_EMPTY(&iface->ipv6.adj_list)) + if (RB_EMPTY(&iface->ipv4.adj_tree) && + RB_EMPTY(&iface->ipv6.adj_tree)) ictl.no_adj = 1; imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISC_IFACE, 0, 0, -1, &ictl, sizeof(ictl)); - LIST_FOREACH(adj, &iface->ipv4.adj_list, ia_entry) { + RB_FOREACH(adj, ia_adj_head, &iface->ipv4.adj_tree) { actl = adj_to_ctl(adj); imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISC_ADJ, 0, 0, -1, actl, sizeof(struct ctl_adj)); } - LIST_FOREACH(adj, &iface->ipv6.adj_list, ia_entry) { + RB_FOREACH(adj, ia_adj_head, &iface->ipv6.adj_tree) { actl = adj_to_ctl(adj); imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISC_ADJ, 0, 0, -1, actl, sizeof(struct ctl_adj)); @@ -869,7 +869,7 @@ ldpe_nbr_ctl(struct ctl_conn *c) imsg_compose_event(&c->iev, IMSG_CTL_SHOW_NBR, 0, 0, -1, nctl, sizeof(struct ctl_nbr)); - LIST_FOREACH(adj, &nbr->adj_list, nbr_entry) { + RB_FOREACH(adj, nbr_adj_head, &nbr->adj_tree) { actl = adj_to_ctl(adj); imsg_compose_event(&c->iev, IMSG_CTL_SHOW_NBR_DISC, 0, 0, -1, actl, sizeof(struct ctl_adj)); diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h index 52899fd85c..81add63836 100644 --- a/ldpd/ldpe.h +++ b/ldpd/ldpe.h @@ -32,6 +32,9 @@ #define min(x,y) ((x) <= (y) ? (x) : (y)) #define max(x,y) ((x) > (y) ? (x) : (y)) +/* forward declarations */ +TAILQ_HEAD(mapping_head, mapping_entry); + struct hello_source { enum hello_type type; struct { @@ -42,9 +45,7 @@ struct hello_source { }; struct adj { - LIST_ENTRY(adj) global_entry; - LIST_ENTRY(adj) nbr_entry; - LIST_ENTRY(adj) ia_entry; + RB_ENTRY(adj) global_entry, nbr_entry, ia_entry; struct in_addr lsr_id; struct nbr *nbr; int ds_tlv; @@ -53,6 +54,9 @@ struct adj { uint16_t holdtime; union ldpd_addr trans_addr; }; +RB_PROTOTYPE(global_adj_head, adj, global_entry, adj_compare) +RB_PROTOTYPE(nbr_adj_head, adj, nbr_entry, adj_compare) +RB_PROTOTYPE(ia_adj_head, adj, ia_entry, adj_compare) struct tcp_conn { struct nbr *nbr; @@ -67,7 +71,7 @@ struct tcp_conn { struct nbr { RB_ENTRY(nbr) id_tree, addr_tree, pid_tree; struct tcp_conn *tcp; - LIST_HEAD(, adj) adj_list; /* adjacencies */ + struct nbr_adj_head adj_tree; /* adjacencies */ struct thread *ev_connect; struct thread *keepalive_timer; struct thread *keepalive_timeout; diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c index 5addc4dda2..d24ceb1229 100644 --- a/ldpd/neighbor.c +++ b/ldpd/neighbor.c @@ -229,7 +229,7 @@ nbr_new(struct in_addr id, int af, int ds_tlv, union ldpd_addr *addr, if ((nbr = calloc(1, sizeof(*nbr))) == NULL) fatal(__func__); - LIST_INIT(&nbr->adj_list); + RB_INIT(&nbr->adj_tree); nbr->state = NBR_STA_PRESENT; nbr->peerid = 0; nbr->af = af; @@ -244,10 +244,10 @@ nbr_new(struct in_addr id, int af, int ds_tlv, union ldpd_addr *addr, nbr->raddr_scope = scope_id; nbr->conf_seqnum = 0; - LIST_FOREACH(adj, &global.adj_list, global_entry) { + RB_FOREACH(adj, global_adj_head, &global.adj_tree) { if (adj->lsr_id.s_addr == nbr->id.s_addr) { adj->nbr = nbr; - LIST_INSERT_HEAD(&nbr->adj_list, adj, nbr_entry); + RB_INSERT(nbr_adj_head, &nbr->adj_tree, adj); } } @@ -366,7 +366,7 @@ nbr_adj_count(struct nbr *nbr, int af) struct adj *adj; int total = 0; - LIST_FOREACH(adj, &nbr->adj_list, nbr_entry) + RB_FOREACH(adj, nbr_adj_head, &nbr->adj_tree) if (adj_get_af(adj) == af) total++; @@ -624,7 +624,7 @@ nbr_establish_connection(struct nbr *nbr) * Send an extra hello to guarantee that the remote peer has formed * an adjacency as well. */ - LIST_FOREACH(adj, &nbr->adj_list, nbr_entry) + RB_FOREACH(adj, nbr_adj_head, &nbr->adj_tree) send_hello(adj->source.type, adj->source.link.ia, adj->source.target); From 41c17d61a274d3e565de6ff2e0d6a33f1db08f71 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 5 Jan 2017 12:44:23 -0500 Subject: [PATCH 16/35] lib: Stop potential uninitialized memory access VRF_UNKNOWN = MAX_INT16_T The vrf macros to determine where in the bitmap something belongs assume that the valid values of a vrf are 0 - (MAX_INT16 - 1) so when they attempt to determine where to look in the bitmap for VRF_DEFAULT, we can get invalid reads of memory. This happens because bgp can create vrf's with VRF_UNKNOWN when we get configuration for a vrf before we've been actually created in zebra. Ticket: CM-14090 Signed-off-by: Donald Sharp --- lib/vrf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/vrf.c b/lib/vrf.c index 39d8a89a7c..61b278dabf 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -381,7 +381,7 @@ vrf_bitmap_set (vrf_bitmap_t bmap, vrf_id_t vrf_id) u_char group = VRF_BITMAP_GROUP (vrf_id); u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id); - if (bmap == VRF_BITMAP_NULL) + if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN) return; if (bm->groups[group] == NULL) @@ -399,7 +399,8 @@ vrf_bitmap_unset (vrf_bitmap_t bmap, vrf_id_t vrf_id) u_char group = VRF_BITMAP_GROUP (vrf_id); u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id); - if (bmap == VRF_BITMAP_NULL || bm->groups[group] == NULL) + if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN || + bm->groups[group] == NULL) return; UNSET_FLAG (bm->groups[group][VRF_BITMAP_INDEX_IN_GROUP (offset)], @@ -413,7 +414,8 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id) u_char group = VRF_BITMAP_GROUP (vrf_id); u_char offset = VRF_BITMAP_BIT_OFFSET (vrf_id); - if (bmap == VRF_BITMAP_NULL || bm->groups[group] == NULL) + if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN || + bm->groups[group] == NULL) return 0; return CHECK_FLAG (bm->groups[group][VRF_BITMAP_INDEX_IN_GROUP (offset)], From 36da066554254ffe8d6224f2b3938ba2c0c3a2e0 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 5 Jan 2017 12:52:18 -0500 Subject: [PATCH 17/35] ospfd: Stop attempt to read beyond end of argv When unconfiguring certain commands in ospf, you can run into situations where we attempt to read beyond the end of a argv[] vector created. On certain platforms this will crash it. Ticket: CM-14090 Signed-off-by: Donald Sharp --- ospfd/ospf_vty.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 1b7c43147c..2c3aaa6808 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -1290,10 +1290,15 @@ DEFUN (no_ospf_area_vlink, /* message-digest-key */ /* Delete one key */ i++; - vl_config.crypto_key_id = strtol (argv[i], NULL, 10); - if (vl_config.crypto_key_id < 0) + if (i < argc) + { + vl_config.crypto_key_id = strtol (argv[i], NULL, 10); + if (vl_config.crypto_key_id < 0) + return CMD_WARNING; + vl_config.md5_key = NULL; + } + else return CMD_WARNING; - vl_config.md5_key = NULL; break; case 'h': From e14fda0fb4de174090a953e09fb677f1cfeddcbb Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 6 Jan 2017 12:24:03 -0500 Subject: [PATCH 18/35] bgpd: Allow 'neighbor X local-as Y' to have large values On ARM platforms specifying a local-as greater than 2 billion causes issues due to atoi usage. Ticket: CM-14019 Signed-off-by: Donald Sharp --- bgpd/bgp_vty.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 29649c5b24..b435543e39 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -3237,12 +3237,13 @@ DEFUN (neighbor_local_as, { struct peer *peer; int ret; - + as_t as; peer = peer_and_group_lookup_vty (vty, argv[0]); if (! peer) return CMD_WARNING; - ret = peer_local_as_set (peer, atoi (argv[1]), 0, 0); + VTY_GET_INTEGER_RANGE ("Local AS", as, argv[1], 1, BGP_AS4_MAX); + ret = peer_local_as_set (peer, as, 0, 0); return bgp_vty_return (vty, ret); } @@ -3257,12 +3258,14 @@ DEFUN (neighbor_local_as_no_prepend, { struct peer *peer; int ret; + as_t as; peer = peer_and_group_lookup_vty (vty, argv[0]); if (! peer) return CMD_WARNING; - ret = peer_local_as_set (peer, atoi (argv[1]), 1, 0); + VTY_GET_INTEGER_RANGE ("Local AS", as, argv[1], 1, BGP_AS4_MAX); + ret = peer_local_as_set (peer, as, 1, 0); return bgp_vty_return (vty, ret); } @@ -3278,12 +3281,14 @@ DEFUN (neighbor_local_as_no_prepend_replace_as, { struct peer *peer; int ret; + as_t as; peer = peer_and_group_lookup_vty (vty, argv[0]); if (! peer) return CMD_WARNING; - ret = peer_local_as_set (peer, atoi (argv[1]), 1, 1); + VTY_GET_INTEGER_RANGE ("Local AS", as, argv[1], 1, BGP_AS4_MAX); + ret = peer_local_as_set (peer, as, 1, 1); return bgp_vty_return (vty, ret); } From ec91182539f592ddd4d19228d728e5ec7623c196 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 6 Jan 2017 12:25:55 -0500 Subject: [PATCH 19/35] zebra: Allow tag values greater than 2 billion on arm Due to the usage of atol, values that are larger than 2 billion on arm for tag are not converted correctly. Ticket: CM-14099 Signed-off-by: Donald Sharp --- zebra/zebra_vty.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 98c20270c3..5088198624 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -104,7 +104,7 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd, /* tag */ if (tag_str) - tag = atol(tag_str); + VTY_GET_INTEGER_RANGE("tag", tag, tag_str, 0, 4294967295); /* VRF id */ zvrf = zebra_vrf_lookup_by_name (vrf_id_str); @@ -2707,11 +2707,11 @@ DEFUN (show_ip_route_tag, if (argc > 1) { - tag = atol(argv[1]); + VTY_GET_INTEGER_RANGE("tag", tag, argv[1], 0, 4294967295); VRF_GET_ID (vrf_id, argv[0]); } else - tag = atol(argv[0]); + VTY_GET_INTEGER_RANGE("tag", tag, argv[0], 0, 4294967295); table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); if (! table) @@ -3341,7 +3341,7 @@ DEFUN (show_ip_route_vrf_all_tag, route_tag_t tag = 0; if (argv[0]) - tag = atol(argv[0]); + VTY_GET_INTEGER_RANGE("tag", tag, argv[0], 0, 4294967295); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { @@ -3777,7 +3777,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, /* tag */ if (tag_str) - tag = atol(tag_str); + VTY_GET_INTEGER_RANGE("tag", tag, tag_str, 0, 4294967295); /* When gateway is valid IPv6 addrees, then gate is treated as nexthop address other case gate is treated as interface name. */ @@ -5026,10 +5026,10 @@ DEFUN (show_ipv6_route_tag, if (argc > 1) { VRF_GET_ID (vrf_id, argv[0]); - tag = atol(argv[1]); + VTY_GET_INTEGER_RANGE("tag", tag, argv[1], 0, 4294967295); } else - tag = atol(argv[0]); + VTY_GET_INTEGER_RANGE("tag", tag, argv[0], 0, 4294967295); table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); if (! table) @@ -5469,7 +5469,7 @@ DEFUN (show_ipv6_route_vrf_all_tag, route_tag_t tag = 0; if (argv[0]) - tag = atol(argv[0]); + VTY_GET_INTEGER_RANGE("tag", tag, argv[0], 0, 4294967295); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { From 07f2fb1374661390f48bc1fd748b5a72ecd4f60b Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 6 Jan 2017 20:19:40 +0100 Subject: [PATCH 20/35] isisd: clean up own LSPs correctly on update Signed-off-by: Christian Franke --- isisd/isis_lsp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index dedf2a71dd..c13bcc5d8a 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -550,6 +550,14 @@ lsp_update (struct isis_lsp *lsp, struct stream *stream, if (dnode) dnode_destroy (dict_delete (area->lspdb[level - 1], dnode)); + if (lsp->own_lsp) + { + zlog_err("ISIS-Upd (%s): BUG updating LSP %s still marked as own LSP", + area->area_tag, rawlspid_print(lsp->lsp_header->lsp_id)); + lsp_clear_data(lsp); + lsp->own_lsp = 0; + } + /* rebuild the lsp data */ lsp_update_data (lsp, stream, area, level); From 95f5922d277c9f4ab983545c0a99fb80c4c1655a Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 9 Jan 2017 12:35:57 -0200 Subject: [PATCH 21/35] build: check if the LibXML perl module is available Signed-off-by: Renato Westphal --- .gitignore | 1 + configure.ac | 2 + m4/ax_prog_perl_modules.m4 | 77 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 m4/ax_prog_perl_modules.m4 diff --git a/.gitignore b/.gitignore index 546faf6926..507b193b4b 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ build m4/*.m4 !m4/ax_sys_weak_alias.m4 !m4/ax_compare_version.m4 +!m4/ax_prog_perl_modules.m4 debian/autoreconf.after debian/autoreconf.before debian/files diff --git a/configure.ac b/configure.ac index d883063ddb..af9fa1ceb1 100755 --- a/configure.ac +++ b/configure.ac @@ -292,6 +292,8 @@ if test $ac_cv_lib_json_c_json_object_get = no; then fi fi +AX_PROG_PERL_MODULES(XML::LibXML, , AC_MSG_ERROR(XML::LibXML perl module is needed to compile)) + AC_ARG_ENABLE([dev_build], AS_HELP_STRING([--enable-dev-build], [build for development])) diff --git a/m4/ax_prog_perl_modules.m4 b/m4/ax_prog_perl_modules.m4 new file mode 100644 index 0000000000..11a326c930 --- /dev/null +++ b/m4/ax_prog_perl_modules.m4 @@ -0,0 +1,77 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_prog_perl_modules.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_PERL_MODULES([MODULES], [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +# +# DESCRIPTION +# +# Checks to see if the given perl modules are available. If true the shell +# commands in ACTION-IF-TRUE are executed. If not the shell commands in +# ACTION-IF-FALSE are run. Note if $PERL is not set (for example by +# calling AC_CHECK_PROG, or AC_PATH_PROG), AC_CHECK_PROG(PERL, perl, perl) +# will be run. +# +# MODULES is a space separated list of module names. To check for a +# minimum version of a module, append the version number to the module +# name, separated by an equals sign. +# +# Example: +# +# AX_PROG_PERL_MODULES( Text::Wrap Net::LDAP=1.0.3, , +# AC_MSG_WARN(Need some Perl modules) +# +# LICENSE +# +# Copyright (c) 2009 Dean Povey +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AU_ALIAS([AC_PROG_PERL_MODULES], [AX_PROG_PERL_MODULES]) +AC_DEFUN([AX_PROG_PERL_MODULES],[dnl + +m4_define([ax_perl_modules]) +m4_foreach([ax_perl_module], m4_split(m4_normalize([$1])), + [ + m4_append([ax_perl_modules], + [']m4_bpatsubst(ax_perl_module,=,[ ])[' ]) + ]) + +# Make sure we have perl +if test -z "$PERL"; then +AC_CHECK_PROG(PERL,perl,perl) +fi + +if test "x$PERL" != x; then + ax_perl_modules_failed=0 + for ax_perl_module in ax_perl_modules; do + AC_MSG_CHECKING(for perl module $ax_perl_module) + + # Would be nice to log result here, but can't rely on autoconf internals + $PERL -e "use $ax_perl_module; exit" > /dev/null 2>&1 + if test $? -ne 0; then + AC_MSG_RESULT(no); + ax_perl_modules_failed=1 + else + AC_MSG_RESULT(ok); + fi + done + + # Run optional shell commands + if test "$ax_perl_modules_failed" = 0; then + : + $2 + else + : + $3 + fi +else + AC_MSG_WARN(could not find perl) +fi])dnl From 2af38873d89e20bd039255418366c1601aa99e64 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 10 Jan 2017 23:33:50 +0000 Subject: [PATCH 22/35] lib: limit size of vty buffer to 4096 bytes This removes the automatic resizing of the vty input buffer and places a hard size cap of 4096 bytes. It also fixes a potentially unsafe strcpy. Signed-off-by: Quentin Young --- lib/vty.c | 98 ++++++++++++++++++++++++++++--------------------------- lib/vty.h | 2 +- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/lib/vty.c b/lib/vty.c index 1fe2e5d296..9b42eb5383 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -508,18 +508,6 @@ vty_write (struct vty *vty, const char *buf, size_t nbytes) buffer_put (vty->obuf, buf, nbytes); } -/* Ensure length of input buffer. Is buffer is short, double it. */ -static void -vty_ensure (struct vty *vty, int length) -{ - if (vty->max <= length) - { - vty->max *= 2; - vty->buf = XREALLOC (MTYPE_VTY, vty->buf, vty->max); - vty->error_buf = XREALLOC (MTYPE_VTY, vty->error_buf, vty->max); - } -} - /* Basic function to insert character into vty. */ static void vty_self_insert (struct vty *vty, char c) @@ -527,7 +515,9 @@ vty_self_insert (struct vty *vty, char c) int i; int length; - vty_ensure (vty, vty->length + 1); + if (vty->length + 1 > VTY_BUFSIZ) + return; + length = vty->length - vty->cp; memmove (&vty->buf[vty->cp + 1], &vty->buf[vty->cp], length); vty->buf[vty->cp] = c; @@ -544,26 +534,29 @@ vty_self_insert (struct vty *vty, char c) static void vty_self_insert_overwrite (struct vty *vty, char c) { - vty_ensure (vty, vty->length + 1); + if (vty->cp == vty->length) + { + vty_self_insert (vty, c); + return; + } + vty->buf[vty->cp++] = c; - - if (vty->cp > vty->length) - vty->length++; - - if ((vty->node == AUTH_NODE) || (vty->node == AUTH_ENABLE_NODE)) - return; - vty_write (vty, &c, 1); } -/* Insert a word into vty interface with overwrite mode. */ +/** + * Insert a string into vty->buf at the current cursor position. + * + * If the resultant string would be larger than VTY_BUFSIZ it is + * truncated to fit. + */ static void vty_insert_word_overwrite (struct vty *vty, char *str) { - int len = strlen (str); - vty_write (vty, str, len); - strcpy (&vty->buf[vty->cp], str); - vty->cp += len; + size_t nwrite = MIN ((int) strlen (str), VTY_BUFSIZ - vty->cp); + vty_write (vty, str, nwrite); + strncpy (&vty->buf[vty->cp], str, nwrite); + vty->cp += nwrite; vty->length = vty->cp; } @@ -2223,36 +2216,45 @@ vtysh_read (struct thread *thread) printf ("line: %.*s\n", nbytes, buf); #endif /* VTYSH_DEBUG */ - for (p = buf; p < buf+nbytes; p++) + if (vty->length + nbytes > VTY_BUFSIZ) { - vty_ensure(vty, vty->length+1); - vty->buf[vty->length++] = *p; - if (*p == '\0') + /* Clear command line buffer. */ + vty->cp = vty->length = 0; + vty_clear_buf (vty); + vty_out (vty, "%% Command is too long.%s", VTY_NEWLINE); + } + else + { + for (p = buf; p < buf+nbytes; p++) { - /* Pass this line to parser. */ - ret = vty_execute (vty); - /* Note that vty_execute clears the command buffer and resets - vty->length to 0. */ + vty->buf[vty->length++] = *p; + if (*p == '\0') + { + /* Pass this line to parser. */ + ret = vty_execute (vty); + /* Note that vty_execute clears the command buffer and resets + vty->length to 0. */ - /* Return result. */ + /* Return result. */ #ifdef VTYSH_DEBUG - printf ("result: %d\n", ret); - printf ("vtysh node: %d\n", vty->node); + printf ("result: %d\n", ret); + printf ("vtysh node: %d\n", vty->node); #endif /* VTYSH_DEBUG */ - /* hack for asynchronous "write integrated" - * - other commands in "buf" will be ditched - * - input during pending config-write is "unsupported" */ - if (ret == CMD_SUSPEND) - break; + /* hack for asynchronous "write integrated" + * - other commands in "buf" will be ditched + * - input during pending config-write is "unsupported" */ + if (ret == CMD_SUSPEND) + break; - /* warning: watchfrr hardcodes this result write */ - header[3] = ret; - buffer_put(vty->obuf, header, 4); + /* warning: watchquagga hardcodes this result write */ + header[3] = ret; + buffer_put(vty->obuf, header, 4); - if (!vty->t_write && (vtysh_flush(vty) < 0)) - /* Try to flush results; exit if a write error occurs. */ - return 0; + if (!vty->t_write && (vtysh_flush(vty) < 0)) + /* Try to flush results; exit if a write error occurs. */ + return 0; + } } } diff --git a/lib/vty.h b/lib/vty.h index 24bdcd1817..f0b833d4d8 100644 --- a/lib/vty.h +++ b/lib/vty.h @@ -26,7 +26,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "sockunion.h" #include "qobj.h" -#define VTY_BUFSIZ 512 +#define VTY_BUFSIZ 4096 #define VTY_MAXHIST 20 /* VTY struct. */ From d02fbbdb088ebaf1eb350887879739cd70094001 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Fri, 6 Jan 2017 10:50:31 -0500 Subject: [PATCH 23/35] bgpd: restore some missing afi/safi commands (Issue #14) Added defines and parse utility functions Fix vty code that treated vpn&encap as AFIs and some other related vty printing/handline issues Note: Includes branch specific changes (due to new parser) Signed-off-by: Lou Berger --- bgpd/bgp_route.c | 472 +++++++++++----------------- bgpd/bgp_vty.c | 778 ++++++++++++++++++++--------------------------- bgpd/bgp_vty.h | 17 +- 3 files changed, 524 insertions(+), 743 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index c717a930b1..e31c745e56 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8157,13 +8157,12 @@ DEFUN (show_ip_bgp, DEFUN (show_ip_bgp_ipv4, show_ip_bgp_ipv4_cmd, - "show ip bgp ipv4 (unicast|multicast) {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); @@ -8175,12 +8174,11 @@ DEFUN (show_ip_bgp_ipv4, ALIAS (show_ip_bgp_ipv4, show_bgp_ipv4_safi_cmd, - "show bgp ipv4 (unicast|multicast) {json}", + "show bgp ipv4 "BGP_SAFI_CMD_STR" {json}", SHOW_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "JavaScript Object Notation\n") DEFUN (show_ip_bgp_route, @@ -8216,10 +8214,10 @@ DEFUN (show_ip_bgp_route_pathtype, DEFUN (show_bgp_ipv4_safi_route_pathtype, show_bgp_ipv4_safi_route_pathtype_cmd, - "show bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D (bestpath|multipath) {json}", + "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D (bestpath|multipath) {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "IP prefix /, e.g., 35.0.0.0/8\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -8275,11 +8273,11 @@ DEFUN (show_bgp_ipv6_prefix, DEFUN (show_ip_bgp_ipv4_route, show_ip_bgp_ipv4_route_cmd, - "show ip bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}", SHOW_STR IP_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Network in the BGP routing table to display\n" "JavaScript Object Notation\n") { @@ -8292,10 +8290,10 @@ DEFUN (show_ip_bgp_ipv4_route, ALIAS (show_ip_bgp_ipv4_route, show_bgp_ipv4_safi_route_cmd, - "show bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D {json}", + "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Network in the BGP routing table to display\n" "JavaScript Object Notation\n") @@ -8489,11 +8487,11 @@ DEFUN (show_ip_bgp_prefix_pathtype, DEFUN (show_ip_bgp_ipv4_prefix, show_ip_bgp_ipv4_prefix_cmd, - "show ip bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D/M {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}", SHOW_STR IP_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "IP prefix /, e.g., 35.0.0.0/8\n" "JavaScript Object Notation\n") { @@ -8506,20 +8504,20 @@ DEFUN (show_ip_bgp_ipv4_prefix, ALIAS (show_ip_bgp_ipv4_prefix, show_bgp_ipv4_safi_prefix_cmd, - "show bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D/M {json}", + "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "IP prefix /, e.g., 35.0.0.0/8\n" "JavaScript Object Notation\n") DEFUN (show_ip_bgp_ipv4_prefix_pathtype, show_ip_bgp_ipv4_prefix_pathtype_cmd, - "show ip bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D/M (bestpath|multipath) {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}", SHOW_STR IP_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "IP prefix /, e.g., 35.0.0.0/8\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -8539,10 +8537,10 @@ DEFUN (show_ip_bgp_ipv4_prefix_pathtype, ALIAS (show_ip_bgp_ipv4_prefix_pathtype, show_bgp_ipv4_safi_prefix_pathtype_cmd, - "show bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D/M (bestpath|multipath) {json}", + "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "IP prefix /, e.g., 35.0.0.0/8\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -8710,13 +8708,11 @@ ALIAS (show_bgp, DEFUN (show_bgp_ipv6_safi, show_bgp_ipv6_safi_cmd, - "show bgp ipv6 (unicast|multicast) {json}", + "show bgp ipv6 "BGP_SAFI_CMD_STR" {json}", SHOW_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" - AFI_SAFI_STR + BGP_SAFI_HELP_STR "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); @@ -8761,10 +8757,10 @@ DEFUN (show_bgp_route, DEFUN (show_bgp_ipv6_safi_route, show_bgp_ipv6_safi_route_cmd, - "show bgp ipv6 (unicast|multicast|vpn|encap) X:X::X:X {json}", + "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Network in the BGP routing table to display\n" "JavaScript Object Notation\n") { @@ -8805,10 +8801,10 @@ ALIAS (show_bgp_route_pathtype, DEFUN (show_bgp_ipv6_safi_route_pathtype, show_bgp_ipv6_safi_route_pathtype_cmd, - "show bgp ipv6 (unicast|multicast|vpn|encap) X:X::X:X (bestpath|multipath) {json}", + "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X (bestpath|multipath) {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Network in the BGP routing table to display\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -8852,10 +8848,10 @@ DEFUN (show_bgp_prefix, DEFUN (show_bgp_ipv6_safi_prefix, show_bgp_ipv6_safi_prefix_cmd, - "show bgp ipv6 (unicast|multicast|vpn|encap) X:X::X:X/M {json}", + "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "IPv6 prefix /, e.g., 3ffe::/16\n" "JavaScript Object Notation\n") { @@ -8896,10 +8892,10 @@ ALIAS (show_bgp_prefix_pathtype, DEFUN (show_bgp_ipv6_safi_prefix_pathtype, show_bgp_ipv6_safi_prefix_pathtype_cmd, - "show bgp ipv6 (unicast|multicast|vpn|encap) X:X::X:X/M (bestpath|multipath) {json}", + "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M (bestpath|multipath) {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "IPv6 prefix /, e.g., 3ffe::/16\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -9322,22 +9318,19 @@ ALIAS (show_ip_bgp_flap_regexp, DEFUN (show_ip_bgp_ipv4_regexp, show_ip_bgp_ipv4_regexp_cmd, - "show ip bgp ipv4 (unicast|multicast) regexp .LINE", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" regexp .LINE", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the AS path regular expression\n" "A regular-expression to match the BGP AS paths\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST, - bgp_show_type_regexp); - - return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, - bgp_show_type_regexp); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_regexp (vty, argc, argv, AFI_IP, safi, + bgp_show_type_regexp); } #ifdef HAVE_IPV6 @@ -9472,22 +9465,19 @@ ALIAS (show_ip_bgp_flap_prefix_list, DEFUN (show_ip_bgp_ipv4_prefix_list, show_ip_bgp_ipv4_prefix_list_cmd, - "show ip bgp ipv4 (unicast|multicast) prefix-list WORD", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" prefix-list WORD", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes conforming to the prefix-list\n" "IP prefix-list name\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, - bgp_show_type_prefix_list); - - return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, - bgp_show_type_prefix_list); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, safi, + bgp_show_type_prefix_list); } #ifdef HAVE_IPV6 @@ -9621,22 +9611,19 @@ ALIAS (show_ip_bgp_flap_filter_list, DEFUN (show_ip_bgp_ipv4_filter_list, show_ip_bgp_ipv4_filter_list_cmd, - "show ip bgp ipv4 (unicast|multicast) filter-list WORD", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" filter-list WORD", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes conforming to the filter-list\n" "Regular expression access list name\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, - bgp_show_type_filter_list); - - return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, - bgp_show_type_filter_list); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, safi, + bgp_show_type_filter_list); } #ifdef HAVE_IPV6 @@ -9707,61 +9694,53 @@ DEFUN (show_ip_bgp_dampening_info, DEFUN (show_ip_bgp_ipv4_dampening_parameters, show_ip_bgp_ipv4_dampening_parameters_cmd, - "show ip bgp ipv4 (unicast|multicast) dampening parameters", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening parameters", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display detailed information about dampening\n" "Display detail of configured dampening parameters\n") { - if (strncmp(argv[0], "m", 1) == 0) - return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST); - - return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_dampening_parameters (vty, AFI_IP, safi); } DEFUN (show_ip_bgp_ipv4_dampening_flap_stats, show_ip_bgp_ipv4_dampening_flap_stats_cmd, - "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening flap-statistics", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display detailed information about dampening\n" "Display flap statistics of routes\n") { - if (strncmp(argv[0], "m", 1) == 0) - return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL, 0); - - return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, - bgp_show_type_flap_statistics, NULL, 0); } DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths, show_ip_bgp_ipv4_dampening_dampd_paths_cmd, - "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening dampened-paths", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display detailed information about dampening\n" "Display paths suppressed due to dampening\n") { - if (strncmp(argv[0], "m", 1) == 0) - return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL, 0); - - return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, - bgp_show_type_dampend_paths, NULL, 0); } static int @@ -9843,22 +9822,19 @@ ALIAS (show_ip_bgp_flap_route_map, DEFUN (show_ip_bgp_ipv4_route_map, show_ip_bgp_ipv4_route_map_cmd, - "show ip bgp ipv4 (unicast|multicast) route-map WORD", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" route-map WORD", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the route-map\n" "A route-map to match on\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, - bgp_show_type_route_map); - - return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, - bgp_show_type_route_map); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, safi, + bgp_show_type_route_map); } DEFUN (show_bgp_route_map, @@ -9919,21 +9895,18 @@ ALIAS (show_ip_bgp_flap_cidr_only, DEFUN (show_ip_bgp_ipv4_cidr_only, show_ip_bgp_ipv4_cidr_only_cmd, - "show ip bgp ipv4 (unicast|multicast) cidr-only", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" cidr-only", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display only routes with non-natural netmasks\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, - bgp_show_type_cidr_only, NULL, 0); - - return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, - bgp_show_type_cidr_only, NULL, 0); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show (vty, NULL, AFI_IP, safi, + bgp_show_type_cidr_only, NULL, 0); } DEFUN (show_ip_bgp_community_all, @@ -9950,21 +9923,18 @@ DEFUN (show_ip_bgp_community_all, DEFUN (show_ip_bgp_ipv4_community_all, show_ip_bgp_ipv4_community_all_cmd, - "show ip bgp ipv4 (unicast|multicast) community", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the communities\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, - bgp_show_type_community_all, NULL, 0); - - return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, - bgp_show_type_community_all, NULL, 0); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show (vty, NULL, AFI_IP, safi, + bgp_show_type_community_all, NULL, 0); } #ifdef HAVE_IPV6 @@ -10156,34 +10126,31 @@ ALIAS (show_ip_bgp_community, DEFUN (show_ip_bgp_ipv4_community, show_ip_bgp_ipv4_community_cmd, - "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "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") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST); - - return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, safi); } ALIAS (show_ip_bgp_ipv4_community, show_ip_bgp_ipv4_community2_cmd, - "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10196,13 +10163,12 @@ ALIAS (show_ip_bgp_ipv4_community, ALIAS (show_ip_bgp_ipv4_community, show_ip_bgp_ipv4_community3_cmd, - "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10219,13 +10185,12 @@ ALIAS (show_ip_bgp_ipv4_community, ALIAS (show_ip_bgp_ipv4_community, show_ip_bgp_ipv4_community4_cmd, - "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10246,14 +10211,11 @@ ALIAS (show_ip_bgp_ipv4_community, DEFUN (show_bgp_instance_afi_safi_community_all, show_bgp_instance_afi_safi_community_all_cmd, - "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community", + "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR - "Address family\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_AFI_SAFI_HELP_STR "Display routes matching the communities\n") { int afi; @@ -10268,14 +10230,14 @@ DEFUN (show_bgp_instance_afi_safi_community_all, return CMD_WARNING; } - afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; - safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; + afi = bgp_vty_safi_from_arg(argv[2]); + safi = bgp_vty_safi_from_arg(argv[3]); return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0); } DEFUN (show_bgp_instance_afi_safi_community, show_bgp_instance_afi_safi_community_cmd, - "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", + "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -10292,14 +10254,14 @@ DEFUN (show_bgp_instance_afi_safi_community, int afi; int safi; - afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; - safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; + afi = bgp_vty_safi_from_arg(argv[2]); + safi = bgp_vty_safi_from_arg(argv[3]); return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi); } ALIAS (show_bgp_instance_afi_safi_community, show_bgp_instance_afi_safi_community2_cmd, - "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -10319,7 +10281,7 @@ ALIAS (show_bgp_instance_afi_safi_community, ALIAS (show_bgp_instance_afi_safi_community, show_bgp_instance_afi_safi_community3_cmd, - "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -10343,7 +10305,7 @@ ALIAS (show_bgp_instance_afi_safi_community, ALIAS (show_bgp_instance_afi_safi_community, show_bgp_instance_afi_safi_community4_cmd, - "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -10450,13 +10412,12 @@ ALIAS (show_ip_bgp_community_exact, DEFUN (show_ip_bgp_ipv4_community_exact, show_ip_bgp_ipv4_community_exact_cmd, - "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10464,21 +10425,19 @@ DEFUN (show_ip_bgp_ipv4_community_exact, "Do not export to next AS (well-known community)\n" "Exact match of the communities") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST); - - return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, safi); } ALIAS (show_ip_bgp_ipv4_community_exact, show_ip_bgp_ipv4_community2_exact_cmd, - "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10492,13 +10451,12 @@ ALIAS (show_ip_bgp_ipv4_community_exact, ALIAS (show_ip_bgp_ipv4_community_exact, show_ip_bgp_ipv4_community3_exact_cmd, - "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10516,13 +10474,12 @@ ALIAS (show_ip_bgp_ipv4_community_exact, ALIAS (show_ip_bgp_ipv4_community_exact, show_ip_bgp_ipv4_community4_exact_cmd, - "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -11222,21 +11179,19 @@ DEFUN (show_ip_bgp_instance_community_list, DEFUN (show_ip_bgp_ipv4_community_list, show_ip_bgp_ipv4_community_list_cmd, - "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community-list (<1-500>|WORD)", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the community-list\n" "community-list number\n" "community-list name\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST); - - return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, safi); } DEFUN (show_ip_bgp_community_list_exact, @@ -11255,22 +11210,20 @@ DEFUN (show_ip_bgp_community_list_exact, DEFUN (show_ip_bgp_ipv4_community_list_exact, show_ip_bgp_ipv4_community_list_exact_cmd, - "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community-list (<1-500>|WORD) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Display routes matching the community-list\n" "community-list number\n" "community-list name\n" "Exact match of the communities\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST); - - return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, safi); } #ifdef HAVE_IPV6 @@ -11462,22 +11415,19 @@ ALIAS (show_ip_bgp_flap_prefix_longer, DEFUN (show_ip_bgp_ipv4_prefix_longer, show_ip_bgp_ipv4_prefix_longer_cmd, - "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M longer-prefixes", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "IP prefix /, e.g., 35.0.0.0/8\n" "Display route and more specific routes\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, - bgp_show_type_prefix_longer); - - return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, - bgp_show_type_prefix_longer); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, safi, + bgp_show_type_prefix_longer); } DEFUN (show_ip_bgp_flap_address, @@ -11939,54 +11889,30 @@ bgp_table_stats_vty (struct vty *vty, const char *name, vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); return CMD_WARNING; } - if (strncmp (afi_str, "ipv", 3) == 0) - { - if (strncmp (afi_str, "ipv4", 4) == 0) - afi = AFI_IP; - else if (strncmp (afi_str, "ipv6", 4) == 0) - afi = AFI_IP6; - else - { - vty_out (vty, "%% Invalid address family %s%s", - afi_str, VTY_NEWLINE); - return CMD_WARNING; - } - if (strncmp (safi_str, "m", 1) == 0) - safi = SAFI_MULTICAST; - else if (strncmp (safi_str, "u", 1) == 0) - safi = SAFI_UNICAST; - else if (strncmp (safi_str, "e", 1) == 0) - safi = SAFI_ENCAP; - else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0) - safi = SAFI_MPLS_VPN; - else - { - vty_out (vty, "%% Invalid subsequent address family %s%s", - safi_str, VTY_NEWLINE); - return CMD_WARNING; - } - } - else + afi = bgp_vty_afi_from_arg(afi_str); + if (afi == AFI_MAX) { vty_out (vty, "%% Invalid address family \"%s\"%s", afi_str, VTY_NEWLINE); return CMD_WARNING; } + safi = bgp_vty_safi_from_arg(safi_str); + if (safi == SAFI_MAX) + { + vty_out (vty, "%% Invalid subsequent address family %s%s", + safi_str, VTY_NEWLINE); + return CMD_WARNING; + } return bgp_table_stats (vty, bgp, afi, safi); } DEFUN (show_bgp_statistics, show_bgp_statistics_cmd, - "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics", + "show bgp "BGP_AFI_SAFI_CMD_STR" statistics", SHOW_STR BGP_STR - "Address family\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_INSTANCE_HELP_STR "BGP RIB advertisement statistics\n") { return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]); @@ -11994,16 +11920,11 @@ DEFUN (show_bgp_statistics, DEFUN (show_bgp_statistics_view, show_bgp_statistics_view_cmd, - "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast|vpn|encap) statistics", + "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" statistics", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR - "Address family\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_AFI_SAFI_HELP_STR "BGP RIB advertisement statistics\n") { return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]); @@ -12296,13 +12217,12 @@ DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts, DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, show_ip_bgp_ipv4_neighbor_prefix_counts_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12317,10 +12237,9 @@ DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, if (! peer) return CMD_WARNING; - if (strncmp (argv[0], "m", 1) == 0) - return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj); - - return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_peer_counts (vty, peer, AFI_IP, safi, uj); } DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, @@ -12330,8 +12249,7 @@ DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12674,13 +12592,12 @@ ALIAS (show_ip_bgp_instance_neighbor_advertised_route, "JavaScript Object Notation\n") DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, show_ip_bgp_ipv4_neighbor_advertised_route_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12690,6 +12607,8 @@ DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, { struct peer *peer; const char *rmap_name = NULL; + safi_t safi; + u_char uj = use_json(argc, argv); peer = peer_lookup_in_view (vty, NULL, argv[1], uj); @@ -12699,21 +12618,18 @@ DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) rmap_name = argv[2]; - if (strncmp (argv[0], "m", 1) == 0) - return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj); - else - return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj); + safi = bgp_vty_safi_from_arg(argv[0]); + return peer_adj_routes (vty, peer, AFI_IP, safi, 0, rmap_name, uj); } ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route, show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12965,13 +12881,12 @@ ALIAS (show_ip_bgp_instance_neighbor_received_routes, DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, show_ip_bgp_ipv4_neighbor_received_routes_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12981,6 +12896,7 @@ DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, { struct peer *peer; const char *rmap_name = NULL; + safi_t safi; u_char uj = use_json(argc, argv); peer = peer_lookup_in_view (vty, NULL, argv[1], uj); @@ -12990,21 +12906,18 @@ DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) rmap_name = argv[2]; - if (strncmp (argv[0], "m", 1) == 0) - return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj); - else - return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj); + safi = bgp_vty_safi_from_arg(argv[0]); + return peer_adj_routes (vty, peer, AFI_IP, safi, 1, rmap_name, uj); } ALIAS (show_ip_bgp_ipv4_neighbor_received_routes, show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -13014,14 +12927,11 @@ ALIAS (show_ip_bgp_ipv4_neighbor_received_routes, DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes, show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd, - "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}", + "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR - "Address family\n" - "Address family\n" - "Address family modifier\n" - "Address family modifier\n" + BGP_AFI_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -13041,8 +12951,8 @@ DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes, if (! peer) return CMD_WARNING; - afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; - safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; + afi = bgp_vty_safi_from_arg(argv[2]); + safi = bgp_vty_safi_from_arg(argv[3]); in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0; return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj); @@ -13137,13 +13047,12 @@ DEFUN (show_ip_bgp_neighbor_received_prefix_filter, DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter, show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -13200,38 +13109,16 @@ DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter, } } - if (strncmp (argv[0], "m", 1) == 0) { - sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi); count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); if (count) { if (!uj) - vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE); - prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); - } - else - { - if (uj) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_boolean_true_add(json_no, "noFuntionalOutput"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "No functional output%s", VTY_NEWLINE); - } - } - else - { - sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST); - count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); - if (count) - { - if (!uj) - vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE); + vty_out (vty, "Address family: %s%s", + afi_safi_print (AFI_IP, safi), VTY_NEWLINE); prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); } else @@ -13660,13 +13547,12 @@ DEFUN (show_ip_bgp_neighbor_damp, DEFUN (show_ip_bgp_ipv4_neighbor_routes, show_ip_bgp_ipv4_neighbor_routes_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -13675,18 +13561,16 @@ DEFUN (show_ip_bgp_ipv4_neighbor_routes, "JavaScript Object Notation\n") { struct peer *peer; + safi_t safi; u_char uj = use_json(argc, argv); peer = peer_lookup_in_view (vty, NULL, argv[1], uj); if (! peer) return CMD_WARNING; - if (strncmp (argv[0], "m", 1) == 0) - return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST, - bgp_show_type_neighbor, uj); - - return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, - bgp_show_type_neighbor, uj); + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_show_neighbor_route (vty, peer, AFI_IP, safi, + bgp_show_type_neighbor, uj); } #ifdef HAVE_IPV6 diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index b435543e39..1b8b135f66 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -107,22 +107,33 @@ bgp_node_safi (struct vty *vty) return safi; } +/* supports (ipv4|ipv6) */ +afi_t +bgp_vty_afi_from_arg(const char *afi_str) +{ + afi_t afi = AFI_MAX; /* unknown */ + if (!strcmp(afi_str, "ipv4")) { + afi = AFI_IP; + } +#ifdef HAVE_IPV6 + else if (!strcmp(afi_str, "ipv6")) { + afi = AFI_IP6; + } +#endif /* HAVE_IPV6 */ + return afi; +} + int bgp_parse_afi(const char *str, afi_t *afi) { - if (!strcmp(str, "ipv4")) { - *afi = AFI_IP; - return 0; - } -#ifdef HAVE_IPV6 - if (!strcmp(str, "ipv6")) { - *afi = AFI_IP6; - return 0; - } -#endif /* HAVE_IPV6 */ + *afi = bgp_vty_afi_from_arg(str); + if (*afi != AFI_MAX) + return 0; + else return -1; } + /* supports (unicast|multicast|vpn|encap) */ safi_t bgp_vty_safi_from_arg(const char *safi_str) @@ -135,7 +146,7 @@ bgp_vty_safi_from_arg(const char *safi_str) else if (strncmp (safi_str, "e", 1) == 0) safi = SAFI_ENCAP; else if (strncmp (safi_str, "v", 1) == 0) - safi = SAFI_MPLS_VPN; + safi = SAFI_MPLS_VPN; return safi; } @@ -359,10 +370,8 @@ bgp_clear_vty_error (struct vty *vty, struct peer *peer, afi_t afi, { case BGP_ERR_AF_UNCONFIGURED: vty_out (vty, - "%%BGP: Enable %s %s address family for the neighbor %s%s", - afi == AFI_IP6 ? "IPv6" : safi == SAFI_MPLS_VPN ? "VPNv4" : "IPv4", - safi == SAFI_MULTICAST ? "Multicast" : "Unicast", - peer->host, VTY_NEWLINE); + "%%BGP: Enable %s address family for the neighbor %s%s", + afi_safi_print(afi, safi), peer->host, VTY_NEWLINE); break; case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED: vty_out (vty, "%%BGP: Inbound soft reconfig for %s not possible as it%s has neither refresh capability, nor inbound soft reconfig%s", peer->host, VTY_NEWLINE, VTY_NEWLINE); @@ -6057,9 +6066,10 @@ DEFUN (address_family_ipv4, DEFUN (address_family_ipv4_safi, address_family_ipv4_safi_cmd, - "address-family ipv4 (unicast|multicast)", + "address-family ipv4 "BGP_SAFI_CMD_STR, "Enter Address Family command mode\n" - AFI_SAFI_STR) + "Address Family\n" + BGP_SAFI_HELP_STR) { switch (bgp_vty_safi_from_arg(argv[0])) { @@ -6093,16 +6103,28 @@ DEFUN (address_family_ipv6, DEFUN (address_family_ipv6_safi, address_family_ipv6_safi_cmd, - "address-family ipv6 (unicast|multicast)", + "address-family ipv6 "BGP_SAFI_CMD_STR, "Enter Address Family command mode\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n") + "Address Family\n" + BGP_SAFI_HELP_STR) { - if (strncmp (argv[0], "m", 1) == 0) - vty->node = BGP_IPV6M_NODE; - else - vty->node = BGP_IPV6_NODE; + int idx_safi = 0; + switch (bgp_vty_safi_from_arg(argv[idx_safi])) + { + case SAFI_MULTICAST: + vty->node = BGP_IPV6M_NODE; + break; + case SAFI_ENCAP: + vty->node = BGP_ENCAPV6_NODE; + break; + case SAFI_MPLS_VPN: + vty->node = BGP_VPNV6_NODE; + break; + case SAFI_UNICAST: + default: + vty->node = BGP_IPV6_NODE; + break; + } return CMD_SUCCESS; } @@ -6651,69 +6673,61 @@ ALIAS (clear_ip_bgp_all_soft_out, DEFUN (clear_ip_bgp_all_ipv4_soft_out, clear_ip_bgp_all_ipv4_soft_out_cmd, - "clear ip bgp * ipv4 (unicast|multicast) soft out", + "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all, - BGP_CLEAR_SOFT_OUT, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, - BGP_CLEAR_SOFT_OUT, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_all, + BGP_CLEAR_SOFT_OUT, NULL); } DEFUN (clear_ip_bgp_instance_all_ipv4_soft_out, clear_ip_bgp_instance_all_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) soft out", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[2], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all, - BGP_CLEAR_SOFT_OUT, NULL); - - return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all, + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[2]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_all, BGP_CLEAR_SOFT_OUT, NULL); } ALIAS (clear_ip_bgp_all_ipv4_soft_out, clear_ip_bgp_all_ipv4_out_cmd, - "clear ip bgp * ipv4 (unicast|multicast) out", + "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_all_ipv4_soft_out, clear_ip_bgp_instance_all_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) out", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) DEFUN (clear_ip_bgp_all_vpnv4_soft_out, @@ -6856,7 +6870,7 @@ ALIAS (clear_bgp_all_soft_out, DEFUN (clear_bgp_ipv6_safi_prefix, clear_bgp_ipv6_safi_prefix_cmd, - "clear bgp ipv6 (unicast|multicast) prefix X:X::X:X/M", + "clear bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M", CLEAR_STR BGP_STR "Address family\n" @@ -6864,15 +6878,14 @@ DEFUN (clear_bgp_ipv6_safi_prefix, "Clear bestpath and re-advertise\n" "IPv6 prefix /, e.g., 3ffe::/16\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_prefix (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL); - else - return bgp_clear_prefix (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_prefix (vty, NULL, argv[1], AFI_IP6, safi, NULL); } DEFUN (clear_bgp_instance_ipv6_safi_prefix, clear_bgp_instance_ipv6_safi_prefix_cmd, - "clear bgp " BGP_INSTANCE_CMD " ipv6 (unicast|multicast) prefix X:X::X:X/M", + "clear bgp " BGP_INSTANCE_CMD " ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M", CLEAR_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -6881,10 +6894,9 @@ DEFUN (clear_bgp_instance_ipv6_safi_prefix, "Clear bestpath and re-advertise\n" "IPv6 prefix /, e.g., 3ffe::/16\n") { - if (strncmp (argv[2], "m", 1) == 0) - return bgp_clear_prefix (vty, argv[1], argv[3], AFI_IP6, SAFI_MULTICAST, NULL); - else - return bgp_clear_prefix (vty, argv[1], argv[3], AFI_IP6, SAFI_UNICAST, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[2]); + return bgp_clear_prefix (vty, argv[1], argv[3], AFI_IP6, safi, NULL); } DEFUN (clear_ip_bgp_peer_soft_out, @@ -6941,29 +6953,26 @@ ALIAS (clear_ip_bgp_peer_soft_out, DEFUN (clear_ip_bgp_peer_ipv4_soft_out, clear_ip_bgp_peer_ipv4_soft_out_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) soft out", + "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_peer, - BGP_CLEAR_SOFT_OUT, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_peer, - BGP_CLEAR_SOFT_OUT, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_peer, + BGP_CLEAR_SOFT_OUT, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_ipv4_soft_out, clear_ip_bgp_instance_peer_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) soft out", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR @@ -6971,35 +6980,31 @@ DEFUN (clear_ip_bgp_instance_peer_ipv4_soft_out, "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_peer, - BGP_CLEAR_SOFT_OUT, argv[2]); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_peer, - BGP_CLEAR_SOFT_OUT, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_peer, + BGP_CLEAR_SOFT_OUT, argv[2]); } ALIAS (clear_ip_bgp_peer_ipv4_soft_out, clear_ip_bgp_peer_ipv4_out_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) out", + "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_out, clear_ip_bgp_instance_peer_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) out", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR @@ -7007,8 +7012,7 @@ ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_out, "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) /* NOTE: WORD peers have not been tested for vpnv4 */ @@ -7222,29 +7226,26 @@ ALIAS (clear_ip_bgp_peer_group_soft_out, DEFUN (clear_ip_bgp_peer_group_ipv4_soft_out, clear_ip_bgp_peer_group_ipv4_soft_out_cmd, - "clear ip bgp peer-group WORD ipv4 (unicast|multicast) soft out", + "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_group, - BGP_CLEAR_SOFT_OUT, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_group, - BGP_CLEAR_SOFT_OUT, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_group, + BGP_CLEAR_SOFT_OUT, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft_out, clear_ip_bgp_instance_peer_group_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) soft out", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR @@ -7252,35 +7253,31 @@ DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft_out, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_group, - BGP_CLEAR_SOFT_OUT, argv[2]); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_group, - BGP_CLEAR_SOFT_OUT, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_group, + BGP_CLEAR_SOFT_OUT, argv[2]); } ALIAS (clear_ip_bgp_peer_group_ipv4_soft_out, clear_ip_bgp_peer_group_ipv4_out_cmd, - "clear ip bgp peer-group WORD ipv4 (unicast|multicast) out", + "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_peer_group_ipv4_soft_out, clear_ip_bgp_instance_peer_group_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) out", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR @@ -7288,8 +7285,7 @@ ALIAS (clear_ip_bgp_instance_peer_group_ipv4_soft_out, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) DEFUN (clear_bgp_peer_group_soft_out, @@ -7434,70 +7430,62 @@ ALIAS (clear_ip_bgp_external_soft_out, DEFUN (clear_ip_bgp_external_ipv4_soft_out, clear_ip_bgp_external_ipv4_soft_out_cmd, - "clear ip bgp external ipv4 (unicast|multicast) soft out", + "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_external, - BGP_CLEAR_SOFT_OUT, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_external, - BGP_CLEAR_SOFT_OUT, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_external, + BGP_CLEAR_SOFT_OUT, NULL); } DEFUN (clear_ip_bgp_instance_external_ipv4_soft_out, clear_ip_bgp_instance_external_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) soft out", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[2], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_external, - BGP_CLEAR_SOFT_OUT, NULL); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_external, - BGP_CLEAR_SOFT_OUT, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[2]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_external, + BGP_CLEAR_SOFT_OUT, NULL); } ALIAS (clear_ip_bgp_external_ipv4_soft_out, clear_ip_bgp_external_ipv4_out_cmd, - "clear ip bgp external ipv4 (unicast|multicast) out", + "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_external_ipv4_soft_out, clear_ip_bgp_instance_external_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) out", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) DEFUN (clear_bgp_external_soft_out, @@ -7634,70 +7622,62 @@ ALIAS (clear_ip_bgp_as_soft_out, DEFUN (clear_ip_bgp_as_ipv4_soft_out, clear_ip_bgp_as_ipv4_soft_out_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) soft out", + "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_as, - BGP_CLEAR_SOFT_OUT, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_as, - BGP_CLEAR_SOFT_OUT, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_as, + BGP_CLEAR_SOFT_OUT, argv[0]); } DEFUN (clear_ip_bgp_instance_as_ipv4_soft_out, clear_ip_bgp_instance_as_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) soft out", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_OUT_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_as, - BGP_CLEAR_SOFT_OUT, argv[2]); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_as, - BGP_CLEAR_SOFT_OUT, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_as, + BGP_CLEAR_SOFT_OUT, argv[2]); } ALIAS (clear_ip_bgp_as_ipv4_soft_out, clear_ip_bgp_as_ipv4_out_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) out", + "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_as_ipv4_soft_out, clear_ip_bgp_instance_as_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) out", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) DEFUN (clear_ip_bgp_as_vpnv4_soft_out, @@ -7907,91 +7887,80 @@ DEFUN (clear_ip_bgp_all_in_prefix_filter, DEFUN (clear_ip_bgp_all_ipv4_soft_in, clear_ip_bgp_all_ipv4_soft_in_cmd, - "clear ip bgp * ipv4 (unicast|multicast) soft in", + "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all, - BGP_CLEAR_SOFT_IN, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, - BGP_CLEAR_SOFT_IN, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_all, + BGP_CLEAR_SOFT_IN, NULL); } DEFUN (clear_ip_bgp_instance_all_ipv4_soft_in, clear_ip_bgp_instance_all_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) soft in", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[2], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all, - BGP_CLEAR_SOFT_IN, NULL); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_all, + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[2]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_all, BGP_CLEAR_SOFT_IN, NULL); } ALIAS (clear_ip_bgp_all_ipv4_soft_in, clear_ip_bgp_all_ipv4_in_cmd, - "clear ip bgp * ipv4 (unicast|multicast) in", + "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_all_ipv4_soft_in, clear_ip_bgp_instance_all_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) in", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_all_ipv4_in_prefix_filter, clear_ip_bgp_all_ipv4_in_prefix_filter_cmd, - "clear ip bgp * ipv4 (unicast|multicast) in prefix-filter", + "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_all, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); } DEFUN (clear_ip_bgp_all_vpnv4_soft_in, @@ -8224,29 +8193,26 @@ DEFUN (clear_ip_bgp_peer_in_prefix_filter, DEFUN (clear_ip_bgp_peer_ipv4_soft_in, clear_ip_bgp_peer_ipv4_soft_in_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) soft in", + "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_peer, - BGP_CLEAR_SOFT_IN, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_peer, - BGP_CLEAR_SOFT_IN, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_peer, + BGP_CLEAR_SOFT_IN, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_ipv4_soft_in, clear_ip_bgp_instance_peer_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) soft in", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR @@ -8254,35 +8220,31 @@ DEFUN (clear_ip_bgp_instance_peer_ipv4_soft_in, "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_peer, - BGP_CLEAR_SOFT_IN, argv[2]); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_peer, - BGP_CLEAR_SOFT_IN, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_peer, + BGP_CLEAR_SOFT_IN, argv[2]); } ALIAS (clear_ip_bgp_peer_ipv4_soft_in, clear_ip_bgp_peer_ipv4_in_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) in", + "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_in, clear_ip_bgp_instance_peer_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) in", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR @@ -8290,30 +8252,26 @@ ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_in, "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_peer_ipv4_in_prefix_filter, clear_ip_bgp_peer_ipv4_in_prefix_filter_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) in prefix-filter", + "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR "Push out the existing ORF prefix-list\n") { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_peer, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_peer, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_peer, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } DEFUN (clear_ip_bgp_peer_vpnv4_soft_in, @@ -8568,29 +8526,26 @@ DEFUN (clear_ip_bgp_peer_group_in_prefix_filter, DEFUN (clear_ip_bgp_peer_group_ipv4_soft_in, clear_ip_bgp_peer_group_ipv4_soft_in_cmd, - "clear ip bgp peer-group WORD ipv4 (unicast|multicast) soft in", + "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_group, - BGP_CLEAR_SOFT_IN, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_group, - BGP_CLEAR_SOFT_IN, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_group, + BGP_CLEAR_SOFT_IN, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft_in, clear_ip_bgp_instance_peer_group_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) soft in", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR @@ -8598,35 +8553,31 @@ DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft_in, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_group, - BGP_CLEAR_SOFT_IN, argv[2]); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_group, - BGP_CLEAR_SOFT_IN, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_group, + BGP_CLEAR_SOFT_IN, argv[2]); } ALIAS (clear_ip_bgp_peer_group_ipv4_soft_in, clear_ip_bgp_peer_group_ipv4_in_cmd, - "clear ip bgp peer-group WORD ipv4 (unicast|multicast) in", + "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_peer_group_ipv4_soft_in, clear_ip_bgp_instance_peer_group_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) in", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR @@ -8634,30 +8585,26 @@ ALIAS (clear_ip_bgp_instance_peer_group_ipv4_soft_in, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_peer_group_ipv4_in_prefix_filter, clear_ip_bgp_peer_group_ipv4_in_prefix_filter_cmd, - "clear ip bgp peer-group WORD ipv4 (unicast|multicast) in prefix-filter", + "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n") { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_group, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_group, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_group, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } DEFUN (clear_bgp_peer_group_soft_in, @@ -8841,91 +8788,80 @@ DEFUN (clear_ip_bgp_external_in_prefix_filter, DEFUN (clear_ip_bgp_external_ipv4_soft_in, clear_ip_bgp_external_ipv4_soft_in_cmd, - "clear ip bgp external ipv4 (unicast|multicast) soft in", + "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_external, - BGP_CLEAR_SOFT_IN, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_external, - BGP_CLEAR_SOFT_IN, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_external, + BGP_CLEAR_SOFT_IN, NULL); } DEFUN (clear_ip_bgp_instance_external_ipv4_soft_in, clear_ip_bgp_instance_external_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) soft in", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[2], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_external, - BGP_CLEAR_SOFT_IN, NULL); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_external, - BGP_CLEAR_SOFT_IN, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[2]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_external, + BGP_CLEAR_SOFT_IN, NULL); } ALIAS (clear_ip_bgp_external_ipv4_soft_in, clear_ip_bgp_external_ipv4_in_cmd, - "clear ip bgp external ipv4 (unicast|multicast) in", + "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_external_ipv4_soft_in, clear_ip_bgp_instance_external_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) in", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_external_ipv4_in_prefix_filter, clear_ip_bgp_external_ipv4_in_prefix_filter_cmd, - "clear ip bgp external ipv4 (unicast|multicast) in prefix-filter", + "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n") { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_external, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_external, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_external, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); } DEFUN (clear_bgp_external_soft_in, @@ -9099,91 +9035,80 @@ DEFUN (clear_ip_bgp_as_in_prefix_filter, DEFUN (clear_ip_bgp_as_ipv4_soft_in, clear_ip_bgp_as_ipv4_soft_in_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) soft in", + "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_as, - BGP_CLEAR_SOFT_IN, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_as, - BGP_CLEAR_SOFT_IN, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_as, + BGP_CLEAR_SOFT_IN, argv[0]); } DEFUN (clear_ip_bgp_instance_as_ipv4_soft_in, clear_ip_bgp_instance_as_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) soft in", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR BGP_SOFT_IN_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_as, - BGP_CLEAR_SOFT_IN, argv[2]); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_as, - BGP_CLEAR_SOFT_IN, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_as, + BGP_CLEAR_SOFT_IN, argv[2]); } ALIAS (clear_ip_bgp_as_ipv4_soft_in, clear_ip_bgp_as_ipv4_in_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) in", + "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_as_ipv4_soft_in, clear_ip_bgp_instance_as_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) in", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_as_ipv4_in_prefix_filter, clear_ip_bgp_as_ipv4_in_prefix_filter_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) in prefix-filter", + "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n") { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_as, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_as, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_as, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } DEFUN (clear_ip_bgp_as_vpnv4_soft_in, @@ -9378,7 +9303,7 @@ ALIAS (clear_ip_bgp_all_soft, DEFUN (clear_ip_bgp_all_ipv4_soft, clear_ip_bgp_all_ipv4_soft_cmd, - "clear ip bgp * ipv4 (unicast|multicast) soft", + "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR @@ -9388,17 +9313,15 @@ DEFUN (clear_ip_bgp_all_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all, - BGP_CLEAR_SOFT_BOTH, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, - BGP_CLEAR_SOFT_BOTH, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_all, + BGP_CLEAR_SOFT_BOTH, NULL); } DEFUN (clear_ip_bgp_instance_all_ipv4_soft, clear_ip_bgp_instance_all_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) soft", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR @@ -9409,11 +9332,9 @@ DEFUN (clear_ip_bgp_instance_all_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - if (strncmp (argv[2], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all, - BGP_CLEAR_SOFT_BOTH, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[2]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_all, BGP_CLEAR_SOFT_BOTH, NULL); } @@ -9522,7 +9443,7 @@ ALIAS (clear_ip_bgp_peer_soft, DEFUN (clear_ip_bgp_peer_ipv4_soft, clear_ip_bgp_peer_ipv4_soft_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) soft", + "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR @@ -9533,17 +9454,15 @@ DEFUN (clear_ip_bgp_peer_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_peer, - BGP_CLEAR_SOFT_BOTH, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_peer, - BGP_CLEAR_SOFT_BOTH, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_peer, + BGP_CLEAR_SOFT_BOTH, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_ipv4_soft, clear_ip_bgp_instance_peer_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) soft", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR @@ -9555,12 +9474,10 @@ DEFUN (clear_ip_bgp_instance_peer_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_peer, - BGP_CLEAR_SOFT_BOTH, argv[2]); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_peer, - BGP_CLEAR_SOFT_BOTH, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_peer, + BGP_CLEAR_SOFT_BOTH, argv[2]); } DEFUN (clear_ip_bgp_peer_vpnv4_soft, @@ -9677,28 +9594,25 @@ ALIAS (clear_ip_bgp_peer_group_soft, DEFUN (clear_ip_bgp_peer_group_ipv4_soft, clear_ip_bgp_peer_group_ipv4_soft_cmd, - "clear ip bgp peer-group WORD ipv4 (unicast|multicast) soft", + "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_group, - BGP_CLEAR_SOFT_BOTH, argv[0]); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_group, - BGP_CLEAR_SOFT_BOTH, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_group, + BGP_CLEAR_SOFT_BOTH, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft, clear_ip_bgp_instance_peer_group_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) soft", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR @@ -9706,16 +9620,13 @@ DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_group, - BGP_CLEAR_SOFT_BOTH, argv[2]); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_group, - BGP_CLEAR_SOFT_BOTH, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_group, + BGP_CLEAR_SOFT_BOTH, argv[2]); } DEFUN (clear_bgp_peer_group_soft, @@ -9795,43 +9706,37 @@ ALIAS (clear_ip_bgp_external_soft, DEFUN (clear_ip_bgp_external_ipv4_soft, clear_ip_bgp_external_ipv4_soft_cmd, - "clear ip bgp external ipv4 (unicast|multicast) soft", + "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR) { - if (strncmp (argv[0], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_external, - BGP_CLEAR_SOFT_BOTH, NULL); - - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_external, - BGP_CLEAR_SOFT_BOTH, NULL); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[0]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_external, + BGP_CLEAR_SOFT_BOTH, NULL); } DEFUN (clear_ip_bgp_instance_external_ipv4_soft, clear_ip_bgp_instance_external_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) soft", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR BGP_SOFT_STR) { - if (strncmp (argv[2], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_external, + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[2]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_external, BGP_CLEAR_SOFT_BOTH, NULL); - - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_external, - BGP_CLEAR_SOFT_BOTH, NULL); } DEFUN (clear_bgp_external_soft, @@ -9907,7 +9812,7 @@ ALIAS (clear_ip_bgp_as_soft, DEFUN (clear_ip_bgp_as_ipv4_soft, clear_ip_bgp_as_ipv4_soft_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) soft", + "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR @@ -9917,17 +9822,15 @@ DEFUN (clear_ip_bgp_as_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - if (strncmp (argv[1], "m", 1) == 0) - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_as, - BGP_CLEAR_SOFT_BOTH, argv[0]); - - return bgp_clear_vty (vty, NULL,AFI_IP, SAFI_UNICAST, clear_as, - BGP_CLEAR_SOFT_BOTH, argv[0]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_as, + BGP_CLEAR_SOFT_BOTH, argv[0]); } DEFUN (clear_ip_bgp_instance_as_ipv4_soft, clear_ip_bgp_instance_as_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) soft", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft", CLEAR_STR IP_STR BGP_STR @@ -9938,12 +9841,10 @@ DEFUN (clear_ip_bgp_instance_as_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - if (strncmp (argv[3], "m", 1) == 0) - return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_as, - BGP_CLEAR_SOFT_BOTH, argv[2]); - - return bgp_clear_vty (vty, argv[1],AFI_IP, SAFI_UNICAST, clear_as, - BGP_CLEAR_SOFT_BOTH, argv[2]); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[3]); + return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_as, + BGP_CLEAR_SOFT_BOTH, argv[2]); } DEFUN (clear_ip_bgp_as_vpnv4_soft, @@ -10634,10 +10535,10 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi, { if (use_json) vty_out(vty, "{\"error\": {\"message\": \"No %s neighbor configured\"}}%s", - afi == AFI_IP ? "IPv4" : "IPv6", VTY_NEWLINE); + afi_safi_print(afi, safi), VTY_NEWLINE); else vty_out (vty, "No %s neighbor is configured%s", - afi == AFI_IP ? "IPv4" : "IPv6", VTY_NEWLINE); + afi_safi_print(afi, safi), VTY_NEWLINE); } if (dn_count && ! use_json) @@ -10778,7 +10679,7 @@ DEFUN (show_ip_bgp_ipv4_summary, SHOW_STR IP_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { @@ -10792,38 +10693,36 @@ ALIAS (show_ip_bgp_ipv4_summary, "show bgp ipv4 (unicast|multicast|vpn|encap) summary {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Summary of BGP neighbor status\n") DEFUN (show_ip_bgp_instance_ipv4_summary, show_ip_bgp_instance_ipv4_summary_cmd, - "show ip bgp view WORD ipv4 (unicast|multicast) summary {json}", + "show ip bgp view WORD ipv4 "BGP_SAFI_CMD_STR" summary {json}", SHOW_STR IP_STR BGP_STR "BGP view\n" "View name\n" "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - if (strncmp (argv[1], "m", 1) == 0) - return bgp_show_summary_vty (vty, argv[0], AFI_IP, SAFI_MULTICAST, uj); - else - return bgp_show_summary_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, uj); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[1]); + return bgp_show_summary_vty (vty, argv[0], AFI_IP, safi, uj); } ALIAS (show_ip_bgp_instance_ipv4_summary, show_bgp_instance_ipv4_safi_summary_cmd, - "show bgp view WORD ipv4 (unicast|multicast) summary {json}", + "show bgp view WORD ipv4 "BGP_SAFI_CMD_STR" summary {json}", SHOW_STR BGP_STR "BGP view\n" "View name\n" - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Summary of BGP neighbor status\n") DEFUN (show_ip_bgp_vpnv4_all_summary, @@ -10928,7 +10827,7 @@ DEFUN (show_bgp_ipv6_safi_summary, "show bgp ipv6 (unicast|multicast|vpn|encap) summary {json}", SHOW_STR BGP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { @@ -10939,19 +10838,18 @@ DEFUN (show_bgp_ipv6_safi_summary, DEFUN (show_bgp_instance_ipv6_safi_summary, show_bgp_instance_ipv6_safi_summary_cmd, - "show bgp " BGP_INSTANCE_CMD " ipv6 (unicast|multicast) summary {json}", + "show bgp " BGP_INSTANCE_CMD " ipv6 "BGP_SAFI_CMD_STR" summary {json}", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - if (strncmp (argv[2], "m", 1) == 0) - return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_MULTICAST, uj); - - return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, uj); + safi_t safi; + safi = bgp_vty_safi_from_arg(argv[2]); + return bgp_show_summary_vty (vty, argv[1], AFI_IP6, safi, uj); } /* old command */ @@ -10991,17 +10889,17 @@ afi_safi_print (afi_t afi, safi_t safi) else if (afi == AFI_IP && safi == SAFI_MULTICAST) return "IPv4 Multicast"; else if (afi == AFI_IP && safi == SAFI_MPLS_VPN) - return "VPN-IPv4 Unicast"; + return "IPv4 VPN"; else if (afi == AFI_IP && safi == SAFI_ENCAP) - return "ENCAP-IPv4 Unicast"; + return "IPv4 Encap"; else if (afi == AFI_IP6 && safi == SAFI_UNICAST) return "IPv6 Unicast"; else if (afi == AFI_IP6 && safi == SAFI_MULTICAST) return "IPv6 Multicast"; else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN) - return "VPN-IPv6 Unicast"; + return "IPv6 VPN"; else if (afi == AFI_IP6 && safi == SAFI_ENCAP) - return "ENCAP-IPv6 Unicast"; + return "IPv6 Encap"; else return "Unknown"; } @@ -12826,13 +12724,12 @@ DEFUN (show_ip_bgp_neighbors, ALIAS (show_ip_bgp_neighbors, show_ip_bgp_ipv4_neighbors_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "JavaScript Object Notation\n") @@ -12895,13 +12792,12 @@ DEFUN (show_ip_bgp_neighbors_peer, ALIAS (show_ip_bgp_neighbors_peer, show_ip_bgp_ipv4_neighbors_peer_cmd, - "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -13066,13 +12962,12 @@ DEFUN (show_ip_bgp_paths, DEFUN (show_ip_bgp_ipv4_paths, show_ip_bgp_ipv4_paths_cmd, - "show ip bgp ipv4 (unicast|multicast) paths", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" paths", SHOW_STR IP_STR BGP_STR "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_SAFI_HELP_STR "Path information\n") { vty_out (vty, "Address Refcnt Path\r\n"); @@ -13227,19 +13122,16 @@ DEFUN (show_bgp_instance_all_ipv6_updgrps, DEFUN (show_bgp_updgrps, show_bgp_updgrps_cmd, - "show bgp (ipv4|ipv6) (unicast|multicast|vpn|encap) update-groups", + "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups", SHOW_STR BGP_STR - "Address family\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n" + BGP_AFI_SAFI_HELP_STR "Detailed info about dynamic update groups\n") { afi_t afi; safi_t safi; - afi = (strcmp(argv[0], "ipv4") == 0) ? AFI_IP : AFI_IP6; + afi = bgp_vty_safi_from_arg(argv[0]); safi = bgp_vty_safi_from_arg(argv[1]); return (bgp_show_update_groups(vty, NULL, afi, safi, 0)); } @@ -13305,11 +13197,11 @@ DEFUN (show_bgp_instance_ipv6_updgrps_s, DEFUN (show_bgp_updgrps_s, show_bgp_updgrps_s_cmd, - "show bgp (ipv4|ipv6) (unicast|multicast|vpn|encap) update-groups SUBGROUP-ID", + "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID", SHOW_STR BGP_STR "Address family\n" - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "Detailed info about v6 dynamic update groups\n" "Specific subgroup to display detailed info for") { @@ -13317,7 +13209,7 @@ DEFUN (show_bgp_updgrps_s, safi_t safi; uint64_t subgrp_id; - afi = (strcmp(argv[0], "ipv4") == 0) ? AFI_IP : AFI_IP6; + afi = bgp_vty_safi_from_arg(argv[0]); safi = bgp_vty_safi_from_arg(argv[1]); VTY_GET_ULL("subgroup-id", subgrp_id, argv[2]); return(bgp_show_update_groups(vty, NULL, afi, safi, subgrp_id)); @@ -13416,11 +13308,10 @@ DEFUN (show_ip_bgp_instance_updgrps_adj, DEFUN (show_bgp_updgrps_afi_adj, show_bgp_updgrps_afi_adj_cmd, - "show bgp (ipv4|ipv6) (unicast|multicast|vpn|encap) update-groups (advertise-queue|advertised-routes|packet-queue)", + "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups (advertise-queue|advertised-routes|packet-queue)", SHOW_STR BGP_STR - "Address family\n" - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "BGP update groups\n" "Advertisement queue\n" "Announced routes\n" @@ -13430,7 +13321,7 @@ DEFUN (show_bgp_updgrps_afi_adj, afi_t afi; safi_t safi; - afi = (strcmp(argv[0], "ipv4") == 0) ? AFI_IP : AFI_IP6; + afi = bgp_vty_safi_from_arg(argv[0]); safi = bgp_vty_safi_from_arg(argv[1]); show_bgp_updgrps_adj_info_aux(vty, NULL, afi, safi, argv[2], 0); return CMD_SUCCESS; @@ -13510,11 +13401,10 @@ DEFUN (show_ip_bgp_instance_updgrps_adj_s, DEFUN (show_bgp_updgrps_afi_adj_s, show_bgp_updgrps_afi_adj_s_cmd, - "show bgp (ipv4|ipv6) (unicast|multicast|vpn|encap) update-groups SUBGROUP-ID (advertise-queue|advertised-routes|packet-queue)", + "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID (advertise-queue|advertised-routes|packet-queue)", SHOW_STR BGP_STR - "Address family\n" - AFI_SAFI_STR + BGP_AFI_SAFI_HELP_STR "BGP update groups\n" "Specific subgroup to display info for\n" "Advertisement queue\n" @@ -13526,7 +13416,7 @@ DEFUN (show_bgp_updgrps_afi_adj_s, safi_t safi; uint64_t subgrp_id; - afi = (strcmp(argv[0], "ipv4") == 0) ? AFI_IP : AFI_IP6; + afi = bgp_vty_safi_from_arg(argv[0]); safi = bgp_vty_safi_from_arg(argv[1]); VTY_GET_ULL("subgroup-id", subgrp_id, argv[2]); diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index 6b4e51bc50..53914e622b 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -30,12 +30,16 @@ struct bgp; #define BGP_INSTANCE_ALL_CMD "(view|vrf) all" #define BGP_INSTANCE_ALL_HELP_STR "BGP view\nBGP VRF\nAll Views/VRFs\n" -#define AFI_SAFI_STR \ - "Address family\n" \ - "Address Family modifier\n" \ - "Address Family modifier\n" \ - "Address Family modifier\n" \ +#define BGP_AFI_CMD_STR "(ipv4|ipv6)" +#define BGP_AFI_HELP_STR "Address Family\nAddress Family\n" +#define BGP_SAFI_CMD_STR "(unicast|multicast|vpn|encap)" +#define BGP_SAFI_HELP_STR \ + "Address Family modifier\n" \ + "Address Family modifier\n" \ + "Address Family modifier\n" \ "Address Family modifier\n" +#define BGP_AFI_SAFI_CMD_STR BGP_AFI_CMD_STR" "BGP_SAFI_CMD_STR +#define BGP_AFI_SAFI_HELP_STR BGP_AFI_HELP_STR BGP_SAFI_HELP_STR extern void bgp_vty_init (void); extern const char *afi_safi_print (afi_t, safi_t); @@ -53,6 +57,9 @@ bgp_parse_afi(const char *str, afi_t *afi); extern int bgp_parse_safi(const char *str, safi_t *safi); +extern afi_t +bgp_vty_afi_from_arg(const char *afi_str); + extern safi_t bgp_vty_safi_from_arg(const char *safi_str); From bbe820a858c7e856a97b9309f1aa595fc2aca11e Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Fri, 6 Jan 2017 18:25:56 -0500 Subject: [PATCH 24/35] bgpd: restore wildcard handling in show summary (Issue#14) Includes more branch specific afi/safi changes Signed-off-by: Lou Berger --- bgpd/bgp_vty.c | 133 +++++++++++++++++++++++++++++++++++++++++-------- bgpd/bgp_vty.h | 1 + 2 files changed, 113 insertions(+), 21 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 1b8b135f66..fad2d7ac1c 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -10553,6 +10553,62 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi, return CMD_SUCCESS; } +static void +bgp_show_summary_afi_safi (struct vty *vty, struct bgp *bgp, int afi, int safi, + u_char use_json, json_object *json) +{ + int is_first = 1; + int afi_wildcard = (afi == AFI_MAX); + int safi_wildcard = (safi == SAFI_MAX); + int is_wildcard = (afi_wildcard || safi_wildcard); + if (use_json && is_wildcard) + vty_out (vty, "{%s", VTY_NEWLINE); + if (afi_wildcard) + afi = 1; /* AFI_IP */ + while (afi < AFI_MAX) + { + if (safi_wildcard) + safi = 1; /* SAFI_UNICAST */ + while (safi < SAFI_MAX) + { + if (is_wildcard) + { + if (use_json) + { + json = json_object_new_object(); + + if (! is_first) + vty_out (vty, ",%s", VTY_NEWLINE); + else + is_first = 0; + + vty_out(vty, "\"%s\":", afi_safi_json(afi, safi)); + } + else + { + vty_out (vty, "%s%s Summary:%s", + VTY_NEWLINE, afi_safi_print(afi, safi), VTY_NEWLINE); + } + } + bgp_show_summary (vty, bgp, afi, safi, use_json, json); + if (safi == SAFI_MPLS_VPN) /* handle special cases to match zebra.h */ + safi = SAFI_ENCAP; + else + safi++; + if (! safi_wildcard) + safi = SAFI_MAX; + } + afi++; + if (! afi_wildcard || + afi == AFI_ETHER) /* special case, not handled yet */ + afi = AFI_MAX; + } + + if (use_json && is_wildcard) + vty_out (vty, "}%s", VTY_NEWLINE); + +} + static int bgp_show_summary_vty (struct vty *vty, const char *name, afi_t afi, safi_t safi, u_char use_json) @@ -10569,14 +10625,14 @@ bgp_show_summary_vty (struct vty *vty, const char *name, return CMD_WARNING; } - bgp_show_summary (vty, bgp, afi, safi, use_json, NULL); + bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL); return CMD_SUCCESS; } bgp = bgp_get_default (); if (bgp) - bgp_show_summary (vty, bgp, afi, safi, use_json, NULL); + bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL); return CMD_SUCCESS; } @@ -10621,7 +10677,7 @@ bgp_show_all_instances_summary_vty (struct vty *vty, afi_t afi, safi_t safi, (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) ? "Default" : bgp->name, VTY_NEWLINE); } - bgp_show_summary (vty, bgp, afi, safi, use_json, json); + bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, json); } if (use_json) @@ -10640,7 +10696,7 @@ DEFUN (show_ip_bgp_summary, "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_UNICAST, uj); + return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_MAX, uj); } DEFUN (show_ip_bgp_instance_summary, @@ -10654,7 +10710,7 @@ DEFUN (show_ip_bgp_instance_summary, "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - return bgp_show_summary_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, uj); + return bgp_show_summary_vty (vty, argv[1], AFI_IP, SAFI_MAX, uj); } DEFUN (show_ip_bgp_instance_all_summary, @@ -10669,17 +10725,18 @@ DEFUN (show_ip_bgp_instance_all_summary, { u_char uj = use_json(argc, argv); - bgp_show_all_instances_summary_vty (vty, AFI_IP, SAFI_UNICAST, uj); + bgp_show_all_instances_summary_vty (vty, AFI_IP, SAFI_MAX, uj); return CMD_SUCCESS; } DEFUN (show_ip_bgp_ipv4_summary, show_ip_bgp_ipv4_summary_cmd, - "show ip bgp ipv4 (unicast|multicast|vpn|encap) summary {json}", + "show ip bgp ipv4 "BGP_SAFI_CMD_STR" summary {json}", SHOW_STR IP_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + BGP_SAFI_HELP_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { @@ -10690,10 +10747,11 @@ DEFUN (show_ip_bgp_ipv4_summary, ALIAS (show_ip_bgp_ipv4_summary, show_bgp_ipv4_safi_summary_cmd, - "show bgp ipv4 (unicast|multicast|vpn|encap) summary {json}", + "show bgp ipv4 "BGP_SAFI_CMD_STR" summary {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + BGP_SAFI_HELP_STR "Summary of BGP neighbor status\n") DEFUN (show_ip_bgp_instance_ipv4_summary, @@ -10775,7 +10833,7 @@ DEFUN (show_bgp_summary, "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { - return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_UNICAST, use_json(argc, argv)); + return bgp_show_summary_vty (vty, NULL, AFI_MAX, SAFI_MAX, use_json(argc, argv)); } DEFUN (show_bgp_instance_summary, @@ -10787,7 +10845,7 @@ DEFUN (show_bgp_instance_summary, "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { - return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, use_json(argc, argv)); + return bgp_show_summary_vty (vty, argv[1], AFI_MAX, SAFI_MAX, use_json(argc, argv)); } DEFUN (show_bgp_instance_all_summary, @@ -10801,19 +10859,22 @@ DEFUN (show_bgp_instance_all_summary, { u_char uj = use_json(argc, argv); - bgp_show_all_instances_summary_vty (vty, AFI_IP6, SAFI_UNICAST, uj); + bgp_show_all_instances_summary_vty (vty, AFI_MAX, SAFI_MAX, uj); return CMD_SUCCESS; } -ALIAS (show_bgp_summary, +DEFUN (show_bgp_ipv6_summary, show_bgp_ipv6_summary_cmd, "show bgp ipv6 summary {json}", SHOW_STR BGP_STR "Address family\n" "Summary of BGP neighbor status\n") +{ + return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_MAX, use_json(argc, argv)); +} -ALIAS (show_bgp_instance_summary, +DEFUN (show_bgp_instance_ipv6__summary, show_bgp_instance_ipv6_summary_cmd, "show bgp " BGP_INSTANCE_CMD " ipv6 summary {json}", SHOW_STR @@ -10821,13 +10882,17 @@ ALIAS (show_bgp_instance_summary, BGP_INSTANCE_HELP_STR "Address family\n" "Summary of BGP neighbor status\n") +{ + return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_MAX, use_json(argc, argv)); +} DEFUN (show_bgp_ipv6_safi_summary, show_bgp_ipv6_safi_summary_cmd, - "show bgp ipv6 (unicast|multicast|vpn|encap) summary {json}", + "show bgp ipv6 "BGP_SAFI_CMD_STR" summary {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + BGP_SAFI_HELP_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { @@ -10863,7 +10928,7 @@ DEFUN (show_ipv6_bgp_summary, "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_UNICAST, uj); + return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_MAX, uj); } /* old command */ @@ -10904,6 +10969,29 @@ afi_safi_print (afi_t afi, safi_t safi) return "Unknown"; } +const char * +afi_safi_json (afi_t afi, safi_t safi) +{ + if (afi == AFI_IP && safi == SAFI_UNICAST) + return "IPv4Unicast"; + else if (afi == AFI_IP && safi == SAFI_MULTICAST) + return "IPv4Multicast"; + else if (afi == AFI_IP && safi == SAFI_MPLS_VPN) + return "IPv4VPN"; + else if (afi == AFI_IP && safi == SAFI_ENCAP) + return "IPv4Encap"; + else if (afi == AFI_IP6 && safi == SAFI_UNICAST) + return "IPv6Unicast"; + else if (afi == AFI_IP6 && safi == SAFI_MULTICAST) + return "IPv6Multicast"; + else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN) + return "IPv6VPN"; + else if (afi == AFI_IP6 && safi == SAFI_ENCAP) + return "IPv6Encap"; + else + return "Unknown"; +} + /* Show BGP peer's information. */ enum show_type { @@ -13125,7 +13213,8 @@ DEFUN (show_bgp_updgrps, "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + BGP_SAFI_HELP_STR "Detailed info about dynamic update groups\n") { afi_t afi; @@ -13311,7 +13400,8 @@ DEFUN (show_bgp_updgrps_afi_adj, "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups (advertise-queue|advertised-routes|packet-queue)", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + BGP_SAFI_HELP_STR "BGP update groups\n" "Advertisement queue\n" "Announced routes\n" @@ -13404,7 +13494,8 @@ DEFUN (show_bgp_updgrps_afi_adj_s, "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID (advertise-queue|advertised-routes|packet-queue)", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + BGP_SAFI_HELP_STR "BGP update groups\n" "Specific subgroup to display info for\n" "Advertisement queue\n" diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index 53914e622b..e3a51ac450 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -43,6 +43,7 @@ struct bgp; extern void bgp_vty_init (void); extern const char *afi_safi_print (afi_t, safi_t); +extern const char *afi_safi_json (afi_t, safi_t); extern int bgp_config_write_update_delay (struct vty *, struct bgp *); extern int bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp); extern int bgp_config_write_listen(struct vty *vty, struct bgp *bgp); From ec3484d972e109daa140f1a24877977a55ae242f Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Tue, 10 Jan 2017 15:53:03 -0500 Subject: [PATCH 25/35] bgpd: conditionally compile out old vpnv4 syntax (Issue #61) (under ifdef KEEP_OLD_VPNV4_COMMANDS) Signed-off-by: Lou Berger --- bgpd/bgp_mplsvpn.c | 17 ++++++++++++----- bgpd/bgp_route.c | 14 ++++++++++++++ bgpd/bgp_routemap.c | 37 ++++++++++++++++++++++--------------- bgpd/bgp_vty.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 20 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index d55acdd512..02febf8630 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -198,7 +198,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8) { - zlog_err ("%s [Error] Update packet error / VPNv4 (prefix length %d less than VPNv4 min length)", + zlog_err ("%s [Error] Update packet error / VPN (prefix length %d less than VPN min length)", peer->host, prefixlen); return -1; } @@ -206,7 +206,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, /* sanity check against packet data */ if ((pnt + psize) > lim) { - zlog_err ("%s [Error] Update packet error / VPNv4 (prefix length %d exceeds packet size %u)", + zlog_err ("%s [Error] Update packet error / VPN (prefix length %d exceeds packet size %u)", peer->host, prefixlen, (uint)(lim-pnt)); return -1; @@ -215,7 +215,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, /* sanity check against storage for the IP address portion */ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u)) { - zlog_err ("%s [Error] Update packet error / VPNv4 (psize %d exceeds storage size %zu)", + zlog_err ("%s [Error] Update packet error / VPN (psize %d exceeds storage size %zu)", peer->host, prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u)); return -1; @@ -224,7 +224,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, /* Sanity check against max bitlen of the address family */ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p)) { - zlog_err ("%s [Error] Update packet error / VPNv4 (psize %d exceeds family (%u) max byte len %u)", + zlog_err ("%s [Error] Update packet error / VPN (psize %d exceeds family (%u) max byte len %u)", peer->host, prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, p.family, prefix_blen (&p)); @@ -295,7 +295,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, /* Packet length consistency check. */ if (pnt != lim) { - zlog_err ("%s [Error] Update packet error / VPNv4 (%zu data remaining after parsing)", + zlog_err ("%s [Error] Update packet error / VPN (%zu data remaining after parsing)", peer->host, lim - pnt); return -1; } @@ -484,6 +484,7 @@ DEFUN (no_vpnv4_network, return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2]); } +#ifdef KEEP_OLD_VPNV4_COMMANDS static int show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u_char use_json) { @@ -650,6 +651,7 @@ show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u } return CMD_SUCCESS; } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ enum bgp_show_type { @@ -954,6 +956,7 @@ DEFUN (show_bgp_ipv6_vpn_rd, return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0, use_json (argc, argv)); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (show_ip_bgp_vpnv4_all, show_ip_bgp_vpnv4_all_cmd, "show ip bgp vpnv4 all", @@ -1269,6 +1272,7 @@ DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes, return show_adj_route_vpn (vty, peer, &prd, uj); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ void bgp_mplsvpn_init (void) @@ -1281,6 +1285,7 @@ bgp_mplsvpn_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_cmd); install_element (VIEW_NODE, &show_bgp_ipv6_vpn_cmd); install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_tags_cmd); @@ -1289,4 +1294,6 @@ bgp_mplsvpn_init (void) install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ + } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index e31c745e56..2320c08b1f 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8297,6 +8297,7 @@ ALIAS (show_ip_bgp_ipv4_route, "Network in the BGP routing table to display\n" "JavaScript Object Notation\n") +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (show_ip_bgp_vpnv4_all_route, show_ip_bgp_vpnv4_all_route_cmd, "show ip bgp vpnv4 all A.B.C.D {json}", @@ -8310,6 +8311,7 @@ DEFUN (show_ip_bgp_vpnv4_all_route, { return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (show_bgp_ipv4_safi_rd_route, show_bgp_ipv4_safi_rd_route_cmd, @@ -8430,6 +8432,7 @@ DEFUN (show_bgp_ipv6_safi_rd_prefix, return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv)); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (show_ip_bgp_vpnv4_rd_route, show_ip_bgp_vpnv4_rd_route_cmd, "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}", @@ -8454,6 +8457,7 @@ DEFUN (show_ip_bgp_vpnv4_rd_route, } return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (show_ip_bgp_prefix, show_ip_bgp_prefix_cmd, @@ -8546,6 +8550,7 @@ ALIAS (show_ip_bgp_ipv4_prefix_pathtype, "Display only multipaths\n" "JavaScript Object Notation\n") +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (show_ip_bgp_vpnv4_all_prefix, show_ip_bgp_vpnv4_all_prefix_cmd, "show ip bgp vpnv4 all A.B.C.D/M {json}", @@ -8583,6 +8588,7 @@ DEFUN (show_ip_bgp_vpnv4_rd_prefix, } return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv)); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (show_ip_bgp_view, show_ip_bgp_instance_cmd, @@ -12242,6 +12248,7 @@ DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, return bgp_peer_counts (vty, peer, AFI_IP, safi, uj); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd, "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", @@ -12266,6 +12273,7 @@ DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ static void show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, @@ -14776,8 +14784,10 @@ bgp_route_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd); install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd); @@ -14786,8 +14796,10 @@ bgp_route_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd); @@ -14892,7 +14904,9 @@ bgp_route_init (void) install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ #ifdef HAVE_IPV6 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd); diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index ea42cb57c9..61435ce207 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -2342,8 +2342,8 @@ struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = #endif /* HAVE_IPV6 */ -/* `set vpnv4 nexthop A.B.C.D' */ - +#ifdef KEEP_OLD_VPNV4_COMMANDS +/* `set ip vpn nexthop A.B.C.D' */ static route_map_result_t route_set_vpnv4_nexthop (void *rule, struct prefix *prefix, route_map_object_t type, void *object) @@ -2393,11 +2393,12 @@ route_set_vpnv4_nexthop_free (void *rule) /* Route map commands for ip nexthop set. */ struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd = { - "vpnv4 next-hop", + "ip vpn next-hop", route_set_vpnv4_nexthop, route_set_vpnv4_nexthop_compile, route_set_vpnv4_nexthop_free }; +#endif /* KEEP_OLD_VPNV4_COMMANDS */ /* `set originator-id' */ @@ -4500,39 +4501,41 @@ ALIAS (no_set_ipv6_nexthop_local, "IPv6 address of next hop\n") #endif /* HAVE_IPV6 */ +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (set_vpnv4_nexthop, set_vpnv4_nexthop_cmd, - "set vpnv4 next-hop A.B.C.D", + "set ip vpn next-hop A.B.C.D", SET_STR - "VPNv4 information\n" - "VPNv4 next-hop address\n" + "IP VPN information\n" + "IP VPN next-hop address\n" "IP address of next hop\n") { - return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]); + return bgp_route_set_add (vty, vty->index, "ip vpn next-hop", argv[0]); } DEFUN (no_set_vpnv4_nexthop, no_set_vpnv4_nexthop_cmd, - "no set vpnv4 next-hop", + "no set ip vpn next-hop", NO_STR SET_STR - "VPNv4 information\n" - "VPNv4 next-hop address\n") + "IP VPN information\n" + "IP VPN next-hop address\n") { if (argc == 0) - return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL); + return bgp_route_set_delete (vty, vty->index, "ip vpn next-hop", NULL); - return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]); + return bgp_route_set_delete (vty, vty->index, "ip vpn next-hop", argv[0]); } ALIAS (no_set_vpnv4_nexthop, no_set_vpnv4_nexthop_val_cmd, - "no set vpnv4 next-hop A.B.C.D", + "no set ip vpn next-hop A.B.C.D", NO_STR SET_STR - "VPNv4 information\n" - "VPNv4 next-hop address\n" + "IP VPN information\n" + "IP VPN next-hop address\n" "IP address of next hop\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (set_originator_id, set_originator_id_cmd, @@ -4604,7 +4607,9 @@ bgp_route_map_init (void) route_map_install_set (&route_set_aggregator_as_cmd); route_map_install_set (&route_set_community_cmd); route_map_install_set (&route_set_community_delete_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS route_map_install_set (&route_set_vpnv4_nexthop_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ route_map_install_set (&route_set_originator_id_cmd); route_map_install_set (&route_set_ecommunity_rt_cmd); route_map_install_set (&route_set_ecommunity_soo_cmd); @@ -4710,9 +4715,11 @@ bgp_route_map_init (void) install_element (RMAP_NODE, &set_ecommunity_soo_cmd); install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd); install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd); install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd); install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (RMAP_NODE, &set_originator_id_cmd); install_element (RMAP_NODE, &no_set_originator_id_cmd); install_element (RMAP_NODE, &no_set_originator_id_val_cmd); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index fad2d7ac1c..f2190c8303 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -6139,12 +6139,14 @@ DEFUN (address_family_vpnv4, return CMD_SUCCESS; } +#ifdef KEEP_OLD_VPNV4_COMMANDS ALIAS (address_family_vpnv4, address_family_vpnv4_unicast_cmd, "address-family vpnv4 unicast", "Enter Address Family command mode\n" "Address family\n" "Address Family Modifier\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (address_family_vpnv6, address_family_vpnv6_cmd, @@ -6156,12 +6158,14 @@ DEFUN (address_family_vpnv6, return CMD_SUCCESS; } +#ifdef KEEP_OLD_VPNV4_COMMANDS ALIAS (address_family_vpnv6, address_family_vpnv6_unicast_cmd, "address-family vpnv6 unicast", "Enter Address Family command mode\n" "Address family\n" "Address Family Modifier\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (address_family_encap, address_family_encap_cmd, @@ -6730,6 +6734,7 @@ ALIAS (clear_ip_bgp_instance_all_ipv4_soft_out, BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (clear_ip_bgp_all_vpnv4_soft_out, clear_ip_bgp_all_vpnv4_soft_out_cmd, "clear ip bgp * vpnv4 unicast soft out", @@ -6783,6 +6788,7 @@ ALIAS (clear_ip_bgp_all_encap_soft_out, "Address family\n" "Address Family Modifier\n" "Soft reconfig outbound update\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_all_soft_out, clear_bgp_all_soft_out_cmd, @@ -7015,6 +7021,7 @@ ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_out, BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) +#ifdef KEEP_OLD_VPNV4_COMMANDS /* NOTE: WORD peers have not been tested for vpnv4 */ DEFUN (clear_ip_bgp_peer_vpnv4_soft_out, clear_ip_bgp_peer_vpnv4_soft_out_cmd, @@ -7071,6 +7078,7 @@ ALIAS (clear_ip_bgp_peer_encap_soft_out, "Address family\n" "Address Family Modifier\n" "Soft reconfig outbound update\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_peer_soft_out, clear_bgp_peer_soft_out_cmd, @@ -7680,6 +7688,7 @@ ALIAS (clear_ip_bgp_instance_as_ipv4_soft_out, BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (clear_ip_bgp_as_vpnv4_soft_out, clear_ip_bgp_as_vpnv4_soft_out_cmd, "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft out", @@ -7733,6 +7742,7 @@ ALIAS (clear_ip_bgp_as_encap_soft_out, "Address family\n" "Address Family modifier\n" "Soft reconfig outbound update\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_as_soft_out, clear_bgp_as_soft_out_cmd, @@ -7963,6 +7973,7 @@ DEFUN (clear_ip_bgp_all_ipv4_in_prefix_filter, BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (clear_ip_bgp_all_vpnv4_soft_in, clear_ip_bgp_all_vpnv4_soft_in_cmd, "clear ip bgp * vpnv4 unicast soft in", @@ -8016,6 +8027,7 @@ ALIAS (clear_ip_bgp_all_encap_soft_in, "Address family\n" "Address Family Modifier\n" "Soft reconfig inbound update\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_all_soft_in, clear_bgp_all_soft_in_cmd, @@ -8274,6 +8286,7 @@ DEFUN (clear_ip_bgp_peer_ipv4_in_prefix_filter, BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (clear_ip_bgp_peer_vpnv4_soft_in, clear_ip_bgp_peer_vpnv4_soft_in_cmd, "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast soft in", @@ -8329,6 +8342,7 @@ ALIAS (clear_ip_bgp_peer_encap_soft_in, "Address family\n" "Address Family Modifier\n" "Soft reconfig inbound update\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_peer_soft_in, clear_bgp_peer_soft_in_cmd, @@ -9111,6 +9125,7 @@ DEFUN (clear_ip_bgp_as_ipv4_in_prefix_filter, BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (clear_ip_bgp_as_vpnv4_soft_in, clear_ip_bgp_as_vpnv4_soft_in_cmd, "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft in", @@ -9164,6 +9179,7 @@ ALIAS (clear_ip_bgp_as_encap_soft_in, "Address family\n" "Address Family modifier\n" "Soft reconfig inbound update\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_as_soft_in, clear_bgp_as_soft_in_cmd, @@ -9338,6 +9354,7 @@ DEFUN (clear_ip_bgp_instance_all_ipv4_soft, BGP_CLEAR_SOFT_BOTH, NULL); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (clear_ip_bgp_all_vpnv4_soft, clear_ip_bgp_all_vpnv4_soft_cmd, "clear ip bgp * vpnv4 unicast soft", @@ -9367,6 +9384,7 @@ DEFUN (clear_ip_bgp_all_encap_soft, return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_all, BGP_CLEAR_SOFT_BOTH, argv[0]); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_all_soft, clear_bgp_all_soft_cmd, @@ -9480,6 +9498,7 @@ DEFUN (clear_ip_bgp_instance_peer_ipv4_soft, BGP_CLEAR_SOFT_BOTH, argv[2]); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (clear_ip_bgp_peer_vpnv4_soft, clear_ip_bgp_peer_vpnv4_soft_cmd, "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast soft", @@ -9510,6 +9529,7 @@ DEFUN (clear_ip_bgp_peer_encap_soft, return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_peer, BGP_CLEAR_SOFT_BOTH, argv[0]); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_peer_soft, clear_bgp_peer_soft_cmd, @@ -9847,6 +9867,7 @@ DEFUN (clear_ip_bgp_instance_as_ipv4_soft, BGP_CLEAR_SOFT_BOTH, argv[2]); } +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (clear_ip_bgp_as_vpnv4_soft, clear_ip_bgp_as_vpnv4_soft_cmd, "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft", @@ -9876,6 +9897,7 @@ DEFUN (clear_ip_bgp_as_encap_soft, return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_as, BGP_CLEAR_SOFT_BOTH, argv[0]); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (clear_bgp_as_soft, clear_bgp_as_soft_cmd, @@ -10783,6 +10805,7 @@ ALIAS (show_ip_bgp_instance_ipv4_summary, BGP_AFI_SAFI_HELP_STR "Summary of BGP neighbor status\n") +#ifdef KEEP_OLD_VPNV4_COMMANDS DEFUN (show_ip_bgp_vpnv4_all_summary, show_ip_bgp_vpnv4_all_summary_cmd, "show ip bgp vpnv4 all summary {json}", @@ -10823,6 +10846,7 @@ DEFUN (show_ip_bgp_vpnv4_rd_summary, return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, uj); } +#endif /* KEEP_OLD_VPNV4_COMMANDS */ #ifdef HAVE_IPV6 DEFUN (show_bgp_summary, @@ -12821,6 +12845,7 @@ ALIAS (show_ip_bgp_neighbors, "Detailed information on TCP and BGP neighbor connections\n" "JavaScript Object Notation\n") +#ifdef KEEP_OLD_VPNV4_COMMANDS ALIAS (show_ip_bgp_neighbors, show_ip_bgp_vpnv4_all_neighbors_cmd, "show ip bgp vpnv4 all neighbors {json}", @@ -12843,6 +12868,7 @@ ALIAS (show_ip_bgp_neighbors, "VPN Route Distinguisher\n" "Detailed information on TCP and BGP neighbor connections\n" "JavaScript Object Notation\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ ALIAS (show_ip_bgp_neighbors, show_bgp_neighbors_cmd, @@ -12892,6 +12918,7 @@ ALIAS (show_ip_bgp_neighbors_peer, "Neighbor on bgp configured interface\n" "JavaScript Object Notation\n") +#ifdef KEEP_OLD_VPNV4_COMMANDS ALIAS (show_ip_bgp_neighbors_peer, show_ip_bgp_vpnv4_all_neighbors_peer_cmd, "show ip bgp vpnv4 all neighbors A.B.C.D {json}", @@ -12915,6 +12942,7 @@ ALIAS (show_ip_bgp_neighbors_peer, "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "JavaScript Object Notation\n") +#endif /* KEEP_OLD_VPNV4_COMMANDS */ ALIAS (show_ip_bgp_neighbors_peer, show_bgp_neighbors_peer_cmd, @@ -15617,10 +15645,14 @@ bgp_vty_init (void) install_element (BGP_NODE, &address_family_ipv6_safi_cmd); #endif /* HAVE_IPV6 */ install_element (BGP_NODE, &address_family_vpnv4_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (BGP_NODE, &address_family_vpnv6_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (BGP_NODE, &address_family_encap_cmd); install_element (BGP_NODE, &address_family_encapv4_cmd); @@ -15722,6 +15754,7 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_in_prefix_filter_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_in_cmd); @@ -15734,6 +15767,7 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_in_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (ENABLE_NODE, &clear_bgp_all_soft_in_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_in_cmd); install_element (ENABLE_NODE, &clear_bgp_all_in_cmd); @@ -15832,6 +15866,7 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_soft_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_out_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_out_cmd); @@ -15844,6 +15879,7 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_out_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (ENABLE_NODE, &clear_bgp_all_soft_out_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_out_cmd); install_element (ENABLE_NODE, &clear_bgp_all_out_cmd); @@ -15906,12 +15942,14 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_instance_external_ipv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_soft_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (ENABLE_NODE, &clear_bgp_all_soft_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_cmd); install_element (ENABLE_NODE, &clear_bgp_peer_soft_cmd); @@ -15963,8 +16001,10 @@ bgp_vty_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_summary_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_ipv4_summary_cmd); install_element (VIEW_NODE, &show_bgp_instance_ipv4_safi_summary_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_summary_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_summary_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ #ifdef HAVE_IPV6 install_element (VIEW_NODE, &show_bgp_summary_cmd); install_element (VIEW_NODE, &show_bgp_instance_summary_cmd); @@ -15980,10 +16020,12 @@ bgp_vty_init (void) install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_neighbors_peer_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbors_peer_cmd); +#ifdef KEEP_OLD_VPNV4_COMMANDS install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbors_peer_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbors_peer_cmd); +#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (VIEW_NODE, &show_ip_bgp_instance_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_all_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_neighbors_peer_cmd); From 9cabb64b320a946b401daa3f6ee7adcefe1548b6 Mon Sep 17 00:00:00 2001 From: vivek Date: Wed, 15 Jun 2016 10:25:35 -0700 Subject: [PATCH 26/35] Quagga: AFI/SAFI mappings IANA to/from internal values Introduce internal and IANA defintions for AFI/SAFI and mapping functions and modify code to use these. This refactoring will facilitate adding support for other AFI/SAFI whose IANA values won't be suitable for internal data structure definitions (e.g., they are not contiguous). The commit adds some fixes related to afi/safi testing with 'make check ' command. Signed-off-by: Vivek Venkatraman Reviewed-by: Donald Sharp Signed-off-by: Philippe Guibert Ticket: CM-11416 Reviewed By: CCR-3594 (mpls branch) Testing Done: Not tested now, tested earlier on mpls branch --- bgpd/bgp_attr.c | 62 ++++++-- bgpd/bgp_open.c | 273 +++++++++++++----------------------- bgpd/bgp_open.h | 1 - bgpd/bgp_packet.c | 101 ++++++------- bgpd/bgp_route.c | 15 +- bgpd/bgpd.c | 29 ++++ bgpd/bgpd.h | 11 +- bgpd/rfapi/rfapi_import.c | 5 +- lib/zebra.h | 67 ++++++++- tests/bgp_capability_test.c | 30 ++-- tests/bgp_mp_attr_test.c | 68 +++++---- 11 files changed, 347 insertions(+), 315 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 534a0323c4..9e0212b74c 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1857,8 +1857,8 @@ int bgp_mp_reach_parse (struct bgp_attr_parser_args *args, struct bgp_nlri *mp_update) { - afi_t afi; - safi_t safi; + afi_t pkt_afi, afi; + safi_t pkt_safi, safi; bgp_size_t nlri_len; size_t start; struct stream *s; @@ -1882,8 +1882,20 @@ bgp_mp_reach_parse (struct bgp_attr_parser_args *args, } /* Load AFI, SAFI. */ - afi = stream_getw (s); - safi = stream_getc (s); + pkt_afi = stream_getw (s); + pkt_safi = stream_getc (s); + + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi)) + { + /* Log if AFI or SAFI is unrecognized. This is not an error unless + * the attribute is otherwise malformed. + */ + if (bgp_debug_update(peer, NULL, NULL, 0)) + zlog_debug ("%s: MP_REACH received AFI %u or SAFI %u is unrecognized", + peer->host, pkt_afi, pkt_safi); + return BGP_ATTR_PARSE_ERROR; + } /* Get nexthop length. */ attre->mp_nexthop_len = stream_getc (s); @@ -1998,8 +2010,8 @@ bgp_mp_unreach_parse (struct bgp_attr_parser_args *args, struct bgp_nlri *mp_withdraw) { struct stream *s; - afi_t afi; - safi_t safi; + afi_t pkt_afi, afi; + safi_t pkt_safi, safi; u_int16_t withdraw_len; struct peer *const peer = args->peer; struct attr *const attr = args->attr; @@ -2011,9 +2023,21 @@ bgp_mp_unreach_parse (struct bgp_attr_parser_args *args, if ((length > STREAM_READABLE(s)) || (length < BGP_MP_UNREACH_MIN_SIZE)) return BGP_ATTR_PARSE_ERROR_NOTIFYPLS; - afi = stream_getw (s); - safi = stream_getc (s); - + pkt_afi = stream_getw (s); + pkt_safi = stream_getc (s); + + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi)) + { + /* Log if AFI or SAFI is unrecognized. This is not an error unless + * the attribute is otherwise malformed. + */ + if (bgp_debug_update(peer, NULL, NULL, 0)) + zlog_debug ("%s: MP_UNREACH received AFI %u or SAFI %u is unrecognized", + peer->host, pkt_afi, pkt_safi); + return BGP_ATTR_PARSE_ERROR; + } + withdraw_len = length - BGP_MP_UNREACH_MIN_SIZE; mp_withdraw->afi = afi; @@ -2634,6 +2658,8 @@ bgp_packet_mpattr_start (struct stream *s, afi_t afi, safi_t safi, afi_t nh_afi, struct attr *attr) { size_t sizep; + afi_t pkt_afi; + safi_t pkt_safi; /* Set extended bit always to encode the attribute length as 2 bytes */ stream_putc (s, BGP_ATTR_FLAG_OPTIONAL|BGP_ATTR_FLAG_EXTLEN); @@ -2641,8 +2667,12 @@ bgp_packet_mpattr_start (struct stream *s, afi_t afi, safi_t safi, afi_t nh_afi, sizep = stream_get_endp (s); stream_putw (s, 0); /* Marker: Attribute length. */ - stream_putw (s, afi); - stream_putc (s, (safi == SAFI_MPLS_VPN) ? SAFI_MPLS_LABELED_VPN : safi); + + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); + + stream_putw (s, pkt_afi); /* AFI */ + stream_putc (s, pkt_safi); /* SAFI */ /* Nexthop */ switch (nh_afi) @@ -3261,6 +3291,8 @@ size_t bgp_packet_mpunreach_start (struct stream *s, afi_t afi, safi_t safi) { unsigned long attrlen_pnt; + afi_t pkt_afi; + safi_t pkt_safi; /* Set extended bit always to encode the attribute length as 2 bytes */ stream_putc (s, BGP_ATTR_FLAG_OPTIONAL|BGP_ATTR_FLAG_EXTLEN); @@ -3269,8 +3301,12 @@ bgp_packet_mpunreach_start (struct stream *s, afi_t afi, safi_t safi) attrlen_pnt = stream_get_endp (s); stream_putw (s, 0); /* Length of this attribute. */ - stream_putw (s, afi); - stream_putc (s, (safi == SAFI_MPLS_VPN) ? SAFI_MPLS_LABELED_VPN : safi); + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); + + stream_putw (s, pkt_afi); + stream_putc (s, pkt_safi); + return attrlen_pnt; } diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index af3c0486e5..4a06881041 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -79,9 +79,13 @@ bgp_capability_vty_out (struct vty *vty, struct peer *peer, u_char use_json, jso if (hdr->code == CAPABILITY_CODE_MP) { + afi_t afi; + safi_t safi; + + bgp_map_afi_safi_iana2int (ntohs(mpc.afi), mpc.safi, &afi, &safi); if (use_json) { - switch (ntohs (mpc.afi)) + switch (afi) { case AFI_IP: json_object_string_add(json_cap, "capabilityErrorMultiProtocolAfi", "IPv4"); @@ -93,7 +97,7 @@ bgp_capability_vty_out (struct vty *vty, struct peer *peer, u_char use_json, jso json_object_int_add(json_cap, "capabilityErrorMultiProtocolAfiUnknown", ntohs (mpc.afi)); break; } - switch (mpc.safi) + switch (safi) { case SAFI_UNICAST: json_object_string_add(json_cap, "capabilityErrorMultiProtocolSafi", "unicast"); @@ -101,7 +105,7 @@ bgp_capability_vty_out (struct vty *vty, struct peer *peer, u_char use_json, jso case SAFI_MULTICAST: json_object_string_add(json_cap, "capabilityErrorMultiProtocolSafi", "multicast"); break; - case SAFI_MPLS_LABELED_VPN: + case SAFI_MPLS_VPN: json_object_string_add(json_cap, "capabilityErrorMultiProtocolSafi", "MPLS-labeled VPN"); break; case SAFI_ENCAP: @@ -115,7 +119,7 @@ bgp_capability_vty_out (struct vty *vty, struct peer *peer, u_char use_json, jso else { vty_out (vty, " Capability error for: Multi protocol "); - switch (ntohs (mpc.afi)) + switch (afi) { case AFI_IP: vty_out (vty, "AFI IPv4, "); @@ -127,7 +131,7 @@ bgp_capability_vty_out (struct vty *vty, struct peer *peer, u_char use_json, jso vty_out (vty, "AFI Unknown %d, ", ntohs (mpc.afi)); break; } - switch (mpc.safi) + switch (safi) { case SAFI_UNICAST: vty_out (vty, "SAFI Unicast"); @@ -135,7 +139,7 @@ bgp_capability_vty_out (struct vty *vty, struct peer *peer, u_char use_json, jso case SAFI_MULTICAST: vty_out (vty, "SAFI Multicast"); break; - case SAFI_MPLS_LABELED_VPN: + case SAFI_MPLS_VPN: vty_out (vty, "SAFI MPLS-labeled VPN"); break; case SAFI_ENCAP: @@ -178,35 +182,6 @@ bgp_capability_mp_data (struct stream *s, struct capability_mp_data *mpc) mpc->safi = stream_getc (s); } -int -bgp_afi_safi_valid_indices (afi_t afi, safi_t *safi) -{ - switch (afi) - { - case AFI_IP: - case AFI_IP6: - switch (*safi) - { - /* BGP MPLS-labeled VPN SAFI isn't contigious with others, remap */ - case SAFI_MPLS_LABELED_VPN: - *safi = SAFI_MPLS_VPN; - case SAFI_UNICAST: - case SAFI_MULTICAST: - case SAFI_MPLS_VPN: - case SAFI_ENCAP: - return 1; - } - break; - case AFI_ETHER: - default: - break; - } - - zlog_debug ("unknown afi/safi (%u/%u)", afi, *safi); - - return 0; -} - /* Set negotiated capability value. */ static int bgp_capability_mp (struct peer *peer, struct capability_header *hdr) @@ -228,7 +203,8 @@ bgp_capability_mp (struct peer *peer, struct capability_header *hdr) zlog_debug ("%s OPEN has MP_EXT CAP for afi/safi: %u/%u", peer->host, mpc.afi, mpc.safi); - if (!bgp_afi_safi_valid_indices (mpc.afi, &mpc.safi)) + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int (mpc.afi, mpc.safi, &mpc.afi, &mpc.safi)) return -1; /* Now safi remapped, and afi/safi are valid array indices */ @@ -271,8 +247,8 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) { struct stream *s = BGP_INPUT (peer); struct capability_orf_entry entry; - afi_t afi; - safi_t safi; + afi_t pkt_afi, afi; + safi_t pkt_safi, safi; u_char type; u_char mode; u_int16_t sm_cap = 0; /* capability send-mode receive */ @@ -282,22 +258,25 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) /* ORF Entry header */ bgp_capability_mp_data (s, &entry.mpc); entry.num = stream_getc (s); - afi = entry.mpc.afi; - safi = entry.mpc.safi; + pkt_afi = entry.mpc.afi; + pkt_safi = entry.mpc.safi; if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s ORF Cap entry for afi/safi: %u/%u", peer->host, entry.mpc.afi, entry.mpc.safi); - /* Check AFI and SAFI. */ - if (!bgp_afi_safi_valid_indices (entry.mpc.afi, &safi)) + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi)) { zlog_info ("%s Addr-family %d/%d not supported." " Ignoring the ORF capability", - peer->host, entry.mpc.afi, entry.mpc.safi); + peer->host, pkt_afi, pkt_safi); return 0; } + entry.mpc.afi = afi; + entry.mpc.safi = safi; + /* validate number field */ if (CAPABILITY_CODE_ORF_LEN + (entry.num * 2) > hdr->length) { @@ -321,7 +300,7 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) case ORF_MODE_RECEIVE: break; default: - bgp_capability_orf_not_support (peer, afi, safi, type, mode); + bgp_capability_orf_not_support (peer, pkt_afi, pkt_safi, type, mode); continue; } /* ORF Type and afi/safi error checks */ @@ -334,7 +313,7 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) case ORF_TYPE_PREFIX: break; default: - bgp_capability_orf_not_support (peer, afi, safi, type, mode); + bgp_capability_orf_not_support (peer, pkt_afi, pkt_safi, type, mode); continue; } break; @@ -344,12 +323,12 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) case ORF_TYPE_PREFIX_OLD: break; default: - bgp_capability_orf_not_support (peer, afi, safi, type, mode); + bgp_capability_orf_not_support (peer, pkt_afi, pkt_safi, type, mode); continue; } break; default: - bgp_capability_orf_not_support (peer, afi, safi, type, mode); + bgp_capability_orf_not_support (peer, pkt_afi, pkt_safi, type, mode); continue; } @@ -358,7 +337,7 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) || (afi == AFI_IP && safi == SAFI_MULTICAST) || (afi == AFI_IP6 && safi == SAFI_UNICAST))) { - bgp_capability_orf_not_support (peer, afi, safi, type, mode); + bgp_capability_orf_not_support (peer, pkt_afi, pkt_safi, type, mode); continue; } @@ -367,7 +346,7 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) " as %s for afi/safi: %d/%d", peer->host, LOOKUP (orf_type_str, type), LOOKUP (orf_mode_str, mode), - entry.mpc.afi, safi); + pkt_afi, pkt_safi); if (hdr->code == CAPABILITY_CODE_ORF) { @@ -381,7 +360,7 @@ bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr) } else { - bgp_capability_orf_not_support (peer, afi, safi, type, mode); + bgp_capability_orf_not_support (peer, pkt_afi, pkt_safi, type, mode); continue; } @@ -437,23 +416,26 @@ bgp_capability_restart (struct peer *peer, struct capability_header *caphdr) while (stream_get_getp (s) + 4 <= end) { - afi_t afi = stream_getw (s); - safi_t safi = stream_getc (s); + afi_t afi; + safi_t safi; + afi_t pkt_afi = stream_getw (s); + safi_t pkt_safi = stream_getc (s); u_char flag = stream_getc (s); - if (!bgp_afi_safi_valid_indices (afi, &safi)) + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi)) { if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s Addr-family %d/%d(afi/safi) not supported." " Ignore the Graceful Restart capability for this AFI/SAFI", - peer->host, afi, safi); + peer->host, pkt_afi, pkt_safi); } else if (!peer->afc[afi][safi]) { if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s Addr-family %d/%d(afi/safi) not enabled." " Ignore the Graceful Restart capability", - peer->host, afi, safi); + peer->host, pkt_afi, pkt_safi); } else { @@ -512,22 +494,25 @@ bgp_capability_addpath (struct peer *peer, struct capability_header *hdr) while (stream_get_getp (s) + 4 <= end) { - afi_t afi = stream_getw (s); - safi_t safi = stream_getc (s); + afi_t afi; + safi_t safi; + afi_t pkt_afi = stream_getw (s); + safi_t pkt_safi = stream_getc (s); u_char send_receive = stream_getc (s); if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s OPEN has AddPath CAP for afi/safi: %u/%u%s%s", - peer->host, afi, safi, + peer->host, pkt_afi, pkt_safi, (send_receive & BGP_ADDPATH_RX) ? ", receive" : "", (send_receive & BGP_ADDPATH_TX) ? ", transmit" : ""); - if (!bgp_afi_safi_valid_indices (afi, &safi)) + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi)) { if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s Addr-family %d/%d(afi/safi) not supported." " Ignore the Addpath Attribute for this AFI/SAFI", - peer->host, afi, safi); + peer->host, pkt_afi, pkt_safi); continue; } else if (!peer->afc[afi][safi]) @@ -535,7 +520,7 @@ bgp_capability_addpath (struct peer *peer, struct capability_header *hdr) if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s Addr-family %d/%d(afi/safi) not enabled." " Ignore the AddPath capability for this AFI/SAFI", - peer->host, afi, safi); + peer->host, pkt_afi, pkt_safi); continue; } @@ -565,20 +550,21 @@ bgp_capability_enhe (struct peer *peer, struct capability_header *hdr) while (stream_get_getp (s) + 6 <= end) { - afi_t afi = stream_getw (s); - safi_t safi = stream_getw (s); - afi_t nh_afi = stream_getw (s); + afi_t afi, pkt_afi = stream_getw (s); + safi_t safi, pkt_safi = stream_getw (s); + afi_t nh_afi, pkt_nh_afi = stream_getw (s); if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s Received with afi/safi/next-hop afi: %u/%u/%u", - peer->host, afi, safi, nh_afi); + peer->host, pkt_afi, pkt_safi, pkt_nh_afi); - if (!bgp_afi_safi_valid_indices (afi, &safi)) + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi)) { if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s Addr-family %d/%d(afi/safi) not supported." " Ignore the ENHE Attribute for this AFI/SAFI", - peer->host, afi, safi); + peer->host, pkt_afi, pkt_safi); continue; } @@ -587,11 +573,13 @@ bgp_capability_enhe (struct peer *peer, struct capability_header *hdr) * possibilities, so we ignore other values with a log. Also, only * Unicast SAFI is currently supported (and expected). */ + nh_afi = afi_iana2int (pkt_nh_afi); + if (afi != AFI_IP || safi != SAFI_UNICAST || nh_afi != AFI_IP6) { zlog_warn ("%s Unexpected afi/safi/next-hop afi: %u/%u/%u " "in Extended Next-hop capability, ignoring", - peer->host, afi, safi, nh_afi); + peer->host, pkt_afi, pkt_safi, pkt_nh_afi); continue; } @@ -1174,9 +1162,11 @@ bgp_open_capability_orf (struct stream *s, struct peer *peer, unsigned long orfp; unsigned long numberp; int number_of_orfs = 0; + afi_t pkt_afi; + safi_t pkt_safi; - if (safi == SAFI_MPLS_VPN) - safi = SAFI_MPLS_LABELED_VPN; + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); stream_putc (s, BGP_OPEN_OPT_CAP); capp = stream_get_endp (s); /* Set Capability Len Pointer */ @@ -1184,9 +1174,9 @@ bgp_open_capability_orf (struct stream *s, struct peer *peer, stream_putc (s, code); /* Capability Code */ orfp = stream_get_endp (s); /* Set ORF Len Pointer */ stream_putc (s, 0); /* ORF Length */ - stream_putw (s, afi); + stream_putw (s, pkt_afi); stream_putc (s, 0); - stream_putc (s, safi); + stream_putc (s, pkt_safi); numberp = stream_get_endp (s); /* Set Number Pointer */ stream_putc (s, 0); /* Number of ORFs */ @@ -1235,8 +1225,8 @@ bgp_open_capability (struct stream *s, struct peer *peer) { u_char len; unsigned long cp, capp, rcapp; - afi_t afi; - safi_t safi; + afi_t afi, pkt_afi; + safi_t safi, pkt_safi; as_t local_as; u_int32_t restart_time; u_char afi_safi_count = 0; @@ -1254,56 +1244,29 @@ bgp_open_capability (struct stream *s, struct peer *peer) || CHECK_FLAG (peer->flags, PEER_FLAG_DONT_CAPABILITY)) return; - /* IPv4 unicast. */ - if (peer->afc[AFI_IP][SAFI_UNICAST]) - { - peer->afc_adv[AFI_IP][SAFI_UNICAST] = 1; - stream_putc (s, BGP_OPEN_OPT_CAP); - stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); - stream_putc (s, CAPABILITY_CODE_MP); - stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, AFI_IP); - stream_putc (s, 0); - stream_putc (s, SAFI_UNICAST); - } - /* IPv4 multicast. */ - if (peer->afc[AFI_IP][SAFI_MULTICAST]) - { - peer->afc_adv[AFI_IP][SAFI_MULTICAST] = 1; - stream_putc (s, BGP_OPEN_OPT_CAP); - stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); - stream_putc (s, CAPABILITY_CODE_MP); - stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, AFI_IP); - stream_putc (s, 0); - stream_putc (s, SAFI_MULTICAST); - } - /* IPv4 VPN */ - if (peer->afc[AFI_IP][SAFI_MPLS_VPN]) - { - peer->afc_adv[AFI_IP][SAFI_MPLS_VPN] = 1; - stream_putc (s, BGP_OPEN_OPT_CAP); - stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); - stream_putc (s, CAPABILITY_CODE_MP); - stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, AFI_IP); - stream_putc (s, 0); - stream_putc (s, SAFI_MPLS_LABELED_VPN); - } - /* ENCAP */ - if (peer->afc[AFI_IP][SAFI_ENCAP]) - { - peer->afc_adv[AFI_IP][SAFI_ENCAP] = 1; - stream_putc (s, BGP_OPEN_OPT_CAP); - stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); - stream_putc (s, CAPABILITY_CODE_MP); - stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, AFI_IP); - stream_putc (s, 0); - stream_putc (s, SAFI_ENCAP); - } -#ifdef HAVE_IPV6 - /* Currently supporting RFC-5549 for Link-Local peering only */ + /* MP capability for configured AFI, SAFI */ + for (afi = AFI_IP ; afi < AFI_MAX ; afi++) + for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++) + { + if (peer->afc[afi][safi]) + { + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); + + peer->afc_adv[afi][safi] = 1; + stream_putc (s, BGP_OPEN_OPT_CAP); + stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); + stream_putc (s, CAPABILITY_CODE_MP); + stream_putc (s, CAPABILITY_CODE_MP_LEN); + stream_putw (s, pkt_afi); + stream_putc (s, 0); + stream_putc (s, pkt_safi); + } + } + + /* Extended nexthop capability - currently supporting RFC-5549 for + * Link-Local peering only + */ if (CHECK_FLAG (peer->flags, PEER_FLAG_CAPABILITY_ENHE) && peer->su.sa.sa_family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) @@ -1323,55 +1286,6 @@ bgp_open_capability (struct stream *s, struct peer *peer) if (CHECK_FLAG (peer->af_cap[AFI_IP][SAFI_UNICAST], PEER_CAP_ENHE_AF_RCV)) SET_FLAG (peer->af_cap[AFI_IP][SAFI_UNICAST], PEER_CAP_ENHE_AF_NEGO); } - /* IPv6 unicast. */ - if (peer->afc[AFI_IP6][SAFI_UNICAST]) - { - peer->afc_adv[AFI_IP6][SAFI_UNICAST] = 1; - stream_putc (s, BGP_OPEN_OPT_CAP); - stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); - stream_putc (s, CAPABILITY_CODE_MP); - stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, AFI_IP6); - stream_putc (s, 0); - stream_putc (s, SAFI_UNICAST); - } - /* IPv6 multicast. */ - if (peer->afc[AFI_IP6][SAFI_MULTICAST]) - { - peer->afc_adv[AFI_IP6][SAFI_MULTICAST] = 1; - stream_putc (s, BGP_OPEN_OPT_CAP); - stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); - stream_putc (s, CAPABILITY_CODE_MP); - stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, AFI_IP6); - stream_putc (s, 0); - stream_putc (s, SAFI_MULTICAST); - } - /* IPv6 VPN. */ - if (peer->afc[AFI_IP6][SAFI_MPLS_VPN]) - { - peer->afc_adv[AFI_IP6][SAFI_MPLS_VPN] = 1; - stream_putc (s, BGP_OPEN_OPT_CAP); - stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); - stream_putc (s, CAPABILITY_CODE_MP); - stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, AFI_IP6); - stream_putc (s, 0); - stream_putc (s, SAFI_MPLS_LABELED_VPN); - } - /* IPv6 ENCAP. */ - if (peer->afc[AFI_IP6][SAFI_ENCAP]) - { - peer->afc_adv[AFI_IP6][SAFI_ENCAP] = 1; - stream_putc (s, BGP_OPEN_OPT_CAP); - stream_putc (s, CAPABILITY_CODE_MP_LEN + 2); - stream_putc (s, CAPABILITY_CODE_MP); - stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, AFI_IP6); - stream_putc (s, 0); - stream_putc (s, SAFI_ENCAP); - } -#endif /* HAVE_IPV6 */ /* Route refresh. */ SET_FLAG (peer->cap, PEER_CAP_REFRESH_ADV); @@ -1420,8 +1334,11 @@ bgp_open_capability (struct stream *s, struct peer *peer) for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++) if (peer->afc[afi][safi]) { - stream_putw (s, afi); - stream_putc (s, safi); + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); + + stream_putw (s, pkt_afi); + stream_putc (s, pkt_safi); if (adv_addpath_tx) { @@ -1535,8 +1452,10 @@ bgp_open_capability (struct stream *s, struct peer *peer) for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++) if (peer->afc[afi][safi]) { - stream_putw (s, afi); - stream_putc (s, (safi == SAFI_MPLS_VPN) ? SAFI_MPLS_LABELED_VPN : safi); + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); + stream_putw (s, pkt_afi); + stream_putc (s, pkt_safi); if (bgp_flag_check(peer->bgp, BGP_FLAG_GR_PRESERVE_FWD)) stream_putc (s, RESTART_F_BIT); else diff --git a/bgpd/bgp_open.h b/bgpd/bgp_open.h index 8ec0a5416b..b0a396ec11 100644 --- a/bgpd/bgp_open.h +++ b/bgpd/bgp_open.h @@ -115,6 +115,5 @@ extern int bgp_open_option_parse (struct peer *, u_char, int *); extern void bgp_open_capability (struct stream *, struct peer *); extern void bgp_capability_vty_out (struct vty *, struct peer *, u_char, json_object *); extern as_t peek_for_as4_capability (struct peer *, u_char); -extern int bgp_afi_safi_valid_indices (afi_t, safi_t *); #endif /* _QUAGGA_BGP_OPEN_H */ diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index dffca37dd3..38470a3c7e 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -147,6 +147,8 @@ static struct stream * bgp_update_packet_eor (struct peer *peer, afi_t afi, safi_t safi) { struct stream *s; + afi_t pkt_afi; + safi_t pkt_safi; if (DISABLE_BGP_ANNOUNCE) return NULL; @@ -169,13 +171,16 @@ bgp_update_packet_eor (struct peer *peer, afi_t afi, safi_t safi) } else { + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); + /* Total Path Attribute Length */ stream_putw (s, 6); stream_putc (s, BGP_ATTR_FLAG_OPTIONAL); stream_putc (s, BGP_ATTR_MP_UNREACH_NLRI); stream_putc (s, 3); - stream_putw (s, afi); - stream_putc (s, (safi == SAFI_MPLS_VPN) ? SAFI_MPLS_LABELED_VPN : safi); + stream_putw (s, pkt_afi); + stream_putc (s, pkt_safi); } bgp_packet_set_size (s); @@ -690,15 +695,16 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi, struct stream *s; struct bgp_filter *filter; int orf_refresh = 0; + afi_t pkt_afi; + safi_t pkt_safi; if (DISABLE_BGP_ANNOUNCE) return; filter = &peer->filter[afi][safi]; - /* Adjust safi code. */ - if (safi == SAFI_MPLS_VPN) - safi = SAFI_MPLS_LABELED_VPN; + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); s = stream_new (BGP_MAX_PACKET_SIZE); @@ -709,9 +715,9 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi, bgp_packet_set_marker (s, BGP_MSG_ROUTE_REFRESH_OLD); /* Encode Route Refresh message. */ - stream_putw (s, afi); + stream_putw (s, pkt_afi); stream_putc (s, 0); - stream_putc (s, safi); + stream_putc (s, pkt_safi); if (orf_type == ORF_TYPE_PREFIX || orf_type == ORF_TYPE_PREFIX_OLD) @@ -734,7 +740,7 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi, zlog_debug ("%s sending REFRESH_REQ to remove ORF(%d) (%s) for afi/safi: %d/%d", peer->host, orf_type, (when_to_refresh == REFRESH_DEFER ? "defer" : "immediate"), - afi, safi); + pkt_afi, pkt_safi); } else { @@ -746,7 +752,7 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi, zlog_debug ("%s sending REFRESH_REQ with pfxlist ORF(%d) (%s) for afi/safi: %d/%d", peer->host, orf_type, (when_to_refresh == REFRESH_DEFER ? "defer" : "immediate"), - afi, safi); + pkt_afi, pkt_safi); } /* Total ORF Entry Len. */ @@ -761,7 +767,7 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi, { if (! orf_refresh) zlog_debug ("%s sending REFRESH_REQ for afi/safi: %d/%d", - peer->host, afi, safi); + peer->host, pkt_afi, pkt_safi); } /* Add packet to the peer. */ @@ -776,10 +782,11 @@ bgp_capability_send (struct peer *peer, afi_t afi, safi_t safi, int capability_code, int action) { struct stream *s; + afi_t pkt_afi; + safi_t pkt_safi; - /* Adjust safi code. */ - if (safi == SAFI_MPLS_VPN) - safi = SAFI_MPLS_LABELED_VPN; + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi); s = stream_new (BGP_MAX_PACKET_SIZE); @@ -792,14 +799,14 @@ bgp_capability_send (struct peer *peer, afi_t afi, safi_t safi, stream_putc (s, action); stream_putc (s, CAPABILITY_CODE_MP); stream_putc (s, CAPABILITY_CODE_MP_LEN); - stream_putw (s, afi); + stream_putw (s, pkt_afi); stream_putc (s, 0); - stream_putc (s, safi); + stream_putc (s, pkt_safi); if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s sending CAPABILITY has %s MP_EXT CAP for afi/safi: %d/%d", peer->host, action == CAPABILITY_ACTION_SET ? - "Advertising" : "Removing", afi, safi); + "Advertising" : "Removing", pkt_afi, pkt_safi); } /* Set packet size. */ @@ -1329,7 +1336,6 @@ bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet) case SAFI_MULTICAST: return bgp_nlri_parse_ip (peer, attr, packet); case SAFI_MPLS_VPN: - case SAFI_MPLS_LABELED_VPN: return bgp_nlri_parse_vpn (peer, attr, packet); case SAFI_ENCAP: return bgp_nlri_parse_encap (peer, attr, packet); @@ -1508,26 +1514,6 @@ bgp_update_receive (struct peer *peer, bgp_size_t size) if (!nlris[i].nlri) continue; - /* We use afi and safi as indices into tables and what not. It would - * be impossible, at this time, to support unknown afi/safis. And - * anyway, the peer needs to be configured to enable the afi/safi - * explicitly which requires UI support. - * - * Ignore unknown afi/safi NLRIs. - * - * Note: This means nlri[x].afi/safi still can not be trusted for - * indexing later in this function! - * - * Note2: This will also remap the wire code-point for VPN safi to the - * internal safi_t point, as needs be. - */ - if(!bgp_afi_safi_valid_indices (nlris[i].afi, &nlris[i].safi)) - { - zlog_info ("%s [Info] UPDATE with unsupported AFI/SAFI %u/%u", - peer->host, nlris[i].afi, nlris[i].safi); - continue; - } - /* NLRI is processed iff the peer if configured for the specific afi/safi */ if (!peer->afc[nlris[i].afi][nlris[i].safi]) { @@ -1586,9 +1572,7 @@ bgp_update_receive (struct peer *peer, bgp_size_t size) safi = SAFI_UNICAST; } else if (attr.flag & ATTR_FLAG_BIT (BGP_ATTR_MP_UNREACH_NLRI) - && nlris[NLRI_MP_WITHDRAW].length == 0 - && bgp_afi_safi_valid_indices (nlris[NLRI_MP_WITHDRAW].afi, - &nlris[NLRI_MP_WITHDRAW].safi)) + && nlris[NLRI_MP_WITHDRAW].length == 0) { afi = nlris[NLRI_MP_WITHDRAW].afi; safi = nlris[NLRI_MP_WITHDRAW].safi; @@ -1727,8 +1711,8 @@ bgp_keepalive_receive (struct peer *peer, bgp_size_t size) static void bgp_route_refresh_receive (struct peer *peer, bgp_size_t size) { - afi_t afi; - safi_t safi; + afi_t pkt_afi, afi; + safi_t pkt_safi, safi; struct stream *s; struct peer_af *paf; struct update_group *updgrp; @@ -1757,28 +1741,22 @@ bgp_route_refresh_receive (struct peer *peer, bgp_size_t size) s = peer->ibuf; /* Parse packet. */ - afi = stream_getw (s); + pkt_afi = stream_getw (s); (void)stream_getc (s); - safi = stream_getc (s); + pkt_safi = stream_getc (s); if (bgp_debug_update(peer, NULL, NULL, 0)) zlog_debug ("%s rcvd REFRESH_REQ for afi/safi: %d/%d", - peer->host, afi, safi); + peer->host, pkt_afi, pkt_safi); - /* Check AFI and SAFI. */ - if ((afi != AFI_IP && afi != AFI_IP6) - || (safi != SAFI_UNICAST && safi != SAFI_MULTICAST - && safi != SAFI_MPLS_LABELED_VPN)) + /* Convert AFI, SAFI to internal values and check. */ + if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi)) { zlog_info ("%s REFRESH_REQ for unrecognized afi/safi: %d/%d - ignored", - peer->host, afi, safi); + peer->host, pkt_afi, pkt_safi); return; } - /* Adjust safi code. */ - if (safi == SAFI_MPLS_LABELED_VPN) - safi = SAFI_MPLS_VPN; - if (size != BGP_MSG_ROUTE_REFRESH_MIN_SIZE - BGP_HEADER_SIZE) { u_char *end; @@ -1954,8 +1932,8 @@ bgp_capability_msg_parse (struct peer *peer, u_char *pnt, bgp_size_t length) struct capability_mp_data mpc; struct capability_header *hdr; u_char action; - afi_t afi; - safi_t safi; + afi_t pkt_afi, afi; + safi_t pkt_safi, safi; end = pnt + length; @@ -1999,18 +1977,19 @@ bgp_capability_msg_parse (struct peer *peer, u_char *pnt, bgp_size_t length) /* We know MP Capability Code. */ if (hdr->code == CAPABILITY_CODE_MP) { - afi = ntohs (mpc.afi); - safi = mpc.safi; + pkt_afi = ntohs (mpc.afi); + pkt_safi = mpc.safi; /* Ignore capability when override-capability is set. */ if (CHECK_FLAG (peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY)) continue; - if (!bgp_afi_safi_valid_indices (afi, &safi)) + /* Convert AFI, SAFI to internal values. */ + if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi)) { if (bgp_debug_neighbor_events(peer)) zlog_debug ("%s Dynamic Capability MP_EXT afi/safi invalid " - "(%u/%u)", peer->host, afi, safi); + "(%u/%u)", peer->host, pkt_afi, pkt_safi); continue; } @@ -2020,7 +1999,7 @@ bgp_capability_msg_parse (struct peer *peer, u_char *pnt, bgp_size_t length) peer->host, action == CAPABILITY_ACTION_SET ? "Advertising" : "Removing", - ntohs(mpc.afi) , mpc.safi); + pkt_afi, pkt_safi); if (action == CAPABILITY_ACTION_SET) { diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 6d8f721bfb..0040c7a144 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2119,6 +2119,9 @@ int bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, safi_t safi, int always) { + afi_t pkt_afi; + safi_t pkt_safi; + if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) return 0; @@ -2136,15 +2139,15 @@ bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)) return 0; + /* Convert AFI, SAFI to values for packet. */ + pkt_afi = afi_int2iana (afi); + pkt_safi = safi_int2iana (safi); { u_int8_t ndata[7]; - if (safi == SAFI_MPLS_VPN) - safi = SAFI_MPLS_LABELED_VPN; - - ndata[0] = (afi >> 8); - ndata[1] = afi; - ndata[2] = safi; + ndata[0] = (pkt_afi >> 8); + ndata[1] = pkt_afi; + ndata[2] = pkt_safi; ndata[3] = (peer->pmax[afi][safi] >> 24); ndata[4] = (peer->pmax[afi][safi] >> 16); ndata[5] = (peer->pmax[afi][safi] >> 8); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index f9c3f9af4b..5457822f3b 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -651,6 +651,35 @@ bgp_listen_limit_unset (struct bgp *bgp) return 0; } +int +bgp_map_afi_safi_iana2int (afi_t pkt_afi, safi_t pkt_safi, + afi_t *afi, safi_t *safi) +{ + /* Map from IANA values to internal values, return error if + * values are unrecognized. + */ + *afi = afi_iana2int (pkt_afi); + *safi = safi_iana2int (pkt_safi); + if (*afi == AFI_MAX || *safi == SAFI_MAX) + return -1; + + return 0; +} + +int +bgp_map_afi_safi_int2iana (afi_t afi, safi_t safi, + afi_t *pkt_afi, safi_t *pkt_safi) +{ + /* Map from internal values to IANA values, return error if + * internal values are bad (unexpected). + */ + if (afi == AFI_MAX || safi == SAFI_MAX) + return -1; + *pkt_afi = afi_int2iana (afi); + *pkt_safi = safi_int2iana (safi); + return 0; +} + struct peer_af * peer_af_create (struct peer *peer, afi_t afi, safi_t safi) { diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 76e19ac535..9a4d92715e 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1080,10 +1080,6 @@ struct bgp_nlri #define BGP_DEFAULT_RESTART_TIME 120 #define BGP_DEFAULT_STALEPATH_TIME 360 -/* RFC4364 */ -#define SAFI_MPLS_LABELED_VPN 128 -#define BGP_SAFI_VPN 128 - /* BGP uptime string length. */ #define BGP_UPTIME_LEN 25 @@ -1360,6 +1356,13 @@ extern void bgp_route_map_terminate(void); extern int peer_cmp (struct peer *p1, struct peer *p2); +extern int +bgp_map_afi_safi_iana2int (afi_t pkt_afi, safi_t pkt_safi, + afi_t *afi, safi_t *safi); +extern int +bgp_map_afi_safi_int2iana (afi_t afi, safi_t safi, + afi_t *pkt_afi, safi_t *pkt_safi); + extern struct peer_af * peer_af_create (struct peer *, afi_t, safi_t); extern struct peer_af * peer_af_find (struct peer *, afi_t, safi_t); extern int peer_af_delete (struct peer *, afi_t, safi_t); diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 25c05e65f8..716a1fb537 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -4086,7 +4086,6 @@ rfapiBgpInfoFilteredImportFunction (safi_t safi) switch (safi) { case SAFI_MPLS_VPN: - case BGP_SAFI_VPN: return rfapiBgpInfoFilteredImportVPN; case SAFI_ENCAP: @@ -4203,7 +4202,7 @@ rfapiProcessUpdate ( label); } - if (safi == SAFI_MPLS_VPN || safi == BGP_SAFI_VPN) + if (safi == SAFI_MPLS_VPN) { vnc_direct_bgp_rh_add_route (bgp, afi, p, peer, attr); } @@ -4332,7 +4331,7 @@ rfapiProcessWithdraw ( } /* TBD the deletion should happen after the lifetime expires */ - if (safi == SAFI_MPLS_VPN || safi == BGP_SAFI_VPN) + if (safi == SAFI_MPLS_VPN) vnc_direct_bgp_rh_del_route (bgp, afi, p, peer); if (safi == SAFI_MPLS_VPN) diff --git a/lib/zebra.h b/lib/zebra.h index 3a9ad15bf4..5a58cf8e6e 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -473,9 +473,28 @@ typedef enum { #define SAFI_MULTICAST 2 #define SAFI_MPLS_VPN 3 #define SAFI_RESERVED_4 4 -#define SAFI_ENCAP 7 /* per IANA */ +#define SAFI_ENCAP 5 #define SAFI_RESERVED_5 5 -#define SAFI_MAX 8 +#define SAFI_MAX 6 + +/* + * The above AFI and SAFI definitions are for internal use. The protocol + * definitions (IANA values) as for example used in BGP protocol packets + * are defined below and these will get mapped to/from the internal values + * in the appropriate places. + * The rationale is that the protocol (IANA) values may be sparse and are + * not optimal for use in data-structure sizing. + * Note: Only useful (i.e., supported) values are defined below. + */ +#define IANA_AFI_RESERVED 0 +#define IANA_AFI_IPV4 1 +#define IANA_AFI_IPV6 2 + +#define IANA_SAFI_RESERVED 0 +#define IANA_SAFI_UNICAST 1 +#define IANA_SAFI_MULTICAST 2 +#define IANA_SAFI_ENCAP 7 +#define IANA_SAFI_MPLS_VPN 128 /* Default Administrative Distance of each protocol. */ #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 @@ -509,4 +528,48 @@ typedef uint32_t route_tag_t; #define ROUTE_TAG_MAX UINT32_MAX #define ROUTE_TAG_PRI PRIu32 +static inline afi_t afi_iana2int (afi_t afi) +{ + if (afi == IANA_AFI_IPV4) + return AFI_IP; + if (afi == IANA_AFI_IPV6) + return AFI_IP6; + return AFI_MAX; +} + +static inline afi_t afi_int2iana (afi_t afi) +{ + if (afi == AFI_IP) + return IANA_AFI_IPV4; + if (afi == AFI_IP6) + return IANA_AFI_IPV6; + return IANA_AFI_RESERVED; +} + +static inline safi_t safi_iana2int (safi_t safi) +{ + if (safi == IANA_SAFI_UNICAST) + return SAFI_UNICAST; + if (safi == IANA_SAFI_MULTICAST) + return SAFI_MULTICAST; + if (safi == IANA_SAFI_MPLS_VPN) + return SAFI_MPLS_VPN; + if (safi == IANA_SAFI_ENCAP) + return SAFI_ENCAP; + return SAFI_MAX; +} + +static inline safi_t safi_int2iana (safi_t safi) +{ + if (safi == SAFI_UNICAST) + return IANA_SAFI_UNICAST; + if (safi == SAFI_MULTICAST) + return IANA_SAFI_MULTICAST; + if (safi == SAFI_MPLS_VPN) + return IANA_SAFI_MPLS_VPN; + if (safi == SAFI_ENCAP) + return IANA_SAFI_ENCAP; + return IANA_SAFI_RESERVED; +} + #endif /* _ZEBRA_H */ diff --git a/tests/bgp_capability_test.c b/tests/bgp_capability_test.c index 7fa4be5611..3ee6a121e4 100644 --- a/tests/bgp_capability_test.c +++ b/tests/bgp_capability_test.c @@ -124,21 +124,21 @@ static struct test_segment mp_segments[] = "MP IP6/MPLS-labeled VPN", { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x80 }, 6, SHOULD_PARSE, 0, - 1, AFI_IP6, SAFI_MPLS_LABELED_VPN, VALID_AFI, + 1, AFI_IP6, IANA_SAFI_MPLS_VPN, VALID_AFI, }, /* 7 */ { "MP5", "MP IP6/MPLS-VPN", { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x4 }, 6, SHOULD_PARSE, 0, - 1, AFI_IP6, SAFI_MPLS_VPN, VALID_AFI, + 1, AFI_IP6, IANA_SAFI_MPLS_VPN, VALID_AFI, }, /* 8 */ { "MP6", "MP IP4/MPLS-laveled VPN", { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80 }, 6, SHOULD_PARSE, 0, - 1, AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + 1, AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, /* 10 */ { "MP8", @@ -585,22 +585,26 @@ parse_test (struct peer *peer, struct test_segment *t, int type) if (!ret && t->validate_afi) { - safi_t safi = t->safi; + afi_t afi; + safi_t safi; - if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid) - failed++; - - printf ("MP: %u/%u (%u): recv %u, nego %u\n", - t->afi, t->safi, safi, - peer->afc_recv[t->afi][safi], - peer->afc_nego[t->afi][safi]); + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int (t->afi, t->safi, &afi, &safi)) + { + if (t->afi_valid == VALID_AFI) + failed++; + } + printf ("MP: %u(%u)/%u(%u): recv %u, nego %u\n", + t->afi, afi, t->safi, safi, + peer->afc_recv[afi][safi], + peer->afc_nego[afi][safi]); if (t->afi_valid == VALID_AFI) { - if (!peer->afc_recv[t->afi][safi]) + if (!peer->afc_recv[afi][safi]) failed++; - if (!peer->afc_nego[t->afi][safi]) + if (!peer->afc_nego[afi][safi]) failed++; } } diff --git a/tests/bgp_mp_attr_test.c b/tests/bgp_mp_attr_test.c index dfb8ed9f7a..f7c2af4405 100644 --- a/tests/bgp_mp_attr_test.c +++ b/tests/bgp_mp_attr_test.c @@ -317,7 +317,7 @@ static struct test_segment { { "IPv4-VPNv4", "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* nexthop bytes */ 12, /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ 0, 0, 0, 0, @@ -338,12 +338,12 @@ static struct test_segment { }, (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), SHOULD_PARSE, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, { "IPv4-VPNv4-bogus-plen", "IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* nexthop bytes */ 12, /* RD */ 0, 0, 1, 2, 0, 0xff, 3, 4, @@ -355,12 +355,12 @@ static struct test_segment { }, (3 + 1 + 3*4 + 1 + 3 + 4 + 1), SHOULD_ERR, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, { "IPv4-VPNv4-plen1-short", "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* nexthop bytes */ 12, /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ 0, 0, 0, 0, @@ -381,12 +381,12 @@ static struct test_segment { }, (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), SHOULD_ERR, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, { "IPv4-VPNv4-plen1-long", "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* nexthop bytes */ 12, /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ 0, 0, 0, 0, @@ -407,12 +407,12 @@ static struct test_segment { }, (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), SHOULD_ERR, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, { "IPv4-VPNv4-plenn-long", "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* nexthop bytes */ 12, /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ 0, 0, 0, 0, @@ -434,12 +434,12 @@ static struct test_segment { }, (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1), SHOULD_ERR, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, { "IPv4-VPNv4-plenn-short", "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* nexthop bytes */ 12, /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ 0, 0, 0, 0, @@ -460,12 +460,12 @@ static struct test_segment { }, (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), SHOULD_ERR, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, { "IPv4-VPNv4-bogus-rd-type", "IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* nexthop bytes */ 12, /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ 0, 0, 0, 0, @@ -486,12 +486,12 @@ static struct test_segment { }, (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)), SHOULD_PARSE, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, { "IPv4-VPNv4-0-nlri", "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* nexthop bytes */ 12, /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */ 0, 0, 0, 0, @@ -513,7 +513,7 @@ static struct test_segment { }, (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1), SHOULD_ERR, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, /* From bug #385 */ @@ -625,7 +625,7 @@ static struct test_segment mp_unreach_segments [] = { "IPv4-unreach-VPNv4", "IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs", { - /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN, + /* AFI / SAFI */ 0x0, AFI_IP, IANA_SAFI_MPLS_VPN, /* NLRI tuples */ 88 + 16, 0, 1, 2, /* tag */ /* rd, 8 octets */ @@ -641,7 +641,7 @@ static struct test_segment mp_unreach_segments [] = }, (3 + (1+3+8+2) + (1+3+8+3)), SHOULD_PARSE, - AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI, + AFI_IP, IANA_SAFI_MPLS_VPN, VALID_AFI, }, { NULL, NULL, {0}, 0, 0} }; @@ -656,19 +656,6 @@ handle_result (struct peer *peer, struct test_segment *t, { int oldfailed = failed; - if (!parse_ret) - { - safi_t safi = t->safi; - - if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid) - failed++; - - printf ("MP: %u/%u (%u): recv %u, nego %u\n", - t->afi, t->safi, safi, - peer->afc_recv[t->afi][safi], - peer->afc_nego[t->afi][safi]); - } - printf ("mp attr parsed?: %s\n", parse_ret ? "no" : "yes"); if (!parse_ret) printf ("nrli parsed?: %s\n", nlri_ret ? "no" : "yes"); @@ -720,9 +707,20 @@ parse_test (struct peer *peer, struct test_segment *t, int type) parse_ret = bgp_mp_reach_parse (&attr_args, &nlri); else parse_ret = bgp_mp_unreach_parse (&attr_args, &nlri); - - if (parse_ret == 0 && t->afi_valid == VALID_AFI) - assert (nlri.afi == t->afi && nlri.safi == t->safi); + if (!parse_ret) + { + afi_t pkt_afi; + safi_t pkt_safi; + + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_int2iana (nlri.afi, nlri.safi, &pkt_afi, &pkt_safi)) + assert (0); + + printf ("MP: %u(%u)/%u(%u): recv %u, nego %u\n", + nlri.afi , pkt_afi, nlri.safi, pkt_safi, + peer->afc_recv[nlri.afi][nlri.safi], + peer->afc_nego[nlri.afi][nlri.safi]); + } if (!parse_ret) { @@ -731,7 +729,7 @@ parse_test (struct peer *peer, struct test_segment *t, int type) else nlri_ret = bgp_nlri_parse (peer, NULL, &nlri); } - + zlog_err("xxxxxxxxxxxxxxxx nlri ret %u", nlri_ret); handle_result (peer, t, parse_ret, nlri_ret); } From 8c90786c956cbb2535d184dea684c935c204fc22 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Thu, 12 Jan 2017 08:54:22 -0500 Subject: [PATCH 27/35] bgpd: remove code contained by ifdef KEEP_OLD_VPNV4_COMMANDS Signed-off-by: Lou Berger --- bgpd/bgp_route.c | 120 --------- bgpd/bgp_routemap.c | 102 -------- bgpd/bgp_vty.c | 604 -------------------------------------------- 3 files changed, 826 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 2320c08b1f..7d423be631 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8297,22 +8297,6 @@ ALIAS (show_ip_bgp_ipv4_route, "Network in the BGP routing table to display\n" "JavaScript Object Notation\n") -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (show_ip_bgp_vpnv4_all_route, - show_ip_bgp_vpnv4_all_route_cmd, - "show ip bgp vpnv4 all A.B.C.D {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information about all VPNv4 NLRIs\n" - "Network in the BGP routing table to display\n" - "JavaScript Object Notation\n") -{ - return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); -} -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (show_bgp_ipv4_safi_rd_route, show_bgp_ipv4_safi_rd_route_cmd, "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D {json}", @@ -8432,33 +8416,6 @@ DEFUN (show_bgp_ipv6_safi_rd_prefix, return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv)); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (show_ip_bgp_vpnv4_rd_route, - show_ip_bgp_vpnv4_rd_route_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information for a route distinguisher\n" - "VPN Route Distinguisher\n" - "Network in the BGP routing table to display\n" - "JavaScript Object Notation\n") -{ - int ret; - struct prefix_rd prd; - u_char uj= use_json(argc, argv); - - ret = str2prefix_rd (argv[0], &prd); - if (! ret) - { - vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); - return CMD_WARNING; - } - return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj); -} -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (show_ip_bgp_prefix, show_ip_bgp_prefix_cmd, "show ip bgp A.B.C.D/M {json}", @@ -8550,45 +8507,6 @@ ALIAS (show_ip_bgp_ipv4_prefix_pathtype, "Display only multipaths\n" "JavaScript Object Notation\n") -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (show_ip_bgp_vpnv4_all_prefix, - show_ip_bgp_vpnv4_all_prefix_cmd, - "show ip bgp vpnv4 all A.B.C.D/M {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information about all VPNv4 NLRIs\n" - "IP prefix /, e.g., 35.0.0.0/8\n" - "JavaScript Object Notation\n") -{ - return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); -} - -DEFUN (show_ip_bgp_vpnv4_rd_prefix, - show_ip_bgp_vpnv4_rd_prefix_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information for a route distinguisher\n" - "VPN Route Distinguisher\n" - "IP prefix /, e.g., 35.0.0.0/8\n" - "JavaScript Object Notation\n") -{ - int ret; - struct prefix_rd prd; - - ret = str2prefix_rd (argv[0], &prd); - if (! ret) - { - vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); - return CMD_WARNING; - } - return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv)); -} -#endif /* KEEP_OLD_VPNV4_COMMANDS */ DEFUN (show_ip_bgp_view, show_ip_bgp_instance_cmd, @@ -12248,33 +12166,6 @@ DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, return bgp_peer_counts (vty, peer, AFI_IP, safi, uj); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, - show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd, - "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", - SHOW_STR - IP_STR - BGP_STR - "Address family\n" - BGP_SAFI_HELP_STR - "Detailed information on TCP and BGP neighbor connections\n" - "Neighbor to display information about\n" - "Neighbor to display information about\n" - "Neighbor on bgp configured interface\n" - "Display detailed prefix count information\n" - "JavaScript Object Notation\n") -{ - struct peer *peer; - u_char uj = use_json(argc, argv); - - peer = peer_lookup_in_view (vty, NULL, argv[0], uj); - if (! peer) - return CMD_WARNING; - - return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj); -} -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - static void show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in, const char *rmap_name, u_char use_json, json_object *json) @@ -14784,10 +14675,6 @@ bgp_route_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd); install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd); @@ -14796,10 +14683,6 @@ bgp_route_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd); @@ -14904,9 +14787,6 @@ bgp_route_init (void) install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ #ifdef HAVE_IPV6 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd); diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 61435ce207..d0cce4a955 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -2342,64 +2342,6 @@ struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = #endif /* HAVE_IPV6 */ -#ifdef KEEP_OLD_VPNV4_COMMANDS -/* `set ip vpn nexthop A.B.C.D' */ -static route_map_result_t -route_set_vpnv4_nexthop (void *rule, struct prefix *prefix, - route_map_object_t type, void *object) -{ - struct in_addr *address; - struct bgp_info *bgp_info; - - if (type == RMAP_BGP) - { - /* Fetch routemap's rule information. */ - address = rule; - bgp_info = object; - - /* Set next hop value. */ - (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address; - (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_len = 4; - } - - return RMAP_OKAY; -} - -static void * -route_set_vpnv4_nexthop_compile (const char *arg) -{ - int ret; - struct in_addr *address; - - address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); - - ret = inet_aton (arg, address); - - if (ret == 0) - { - XFREE (MTYPE_ROUTE_MAP_COMPILED, address); - return NULL; - } - - return address; -} - -static void -route_set_vpnv4_nexthop_free (void *rule) -{ - XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); -} - -/* Route map commands for ip nexthop set. */ -struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd = -{ - "ip vpn next-hop", - route_set_vpnv4_nexthop, - route_set_vpnv4_nexthop_compile, - route_set_vpnv4_nexthop_free -}; -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - /* `set originator-id' */ /* For origin set. */ @@ -4501,42 +4443,6 @@ ALIAS (no_set_ipv6_nexthop_local, "IPv6 address of next hop\n") #endif /* HAVE_IPV6 */ -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (set_vpnv4_nexthop, - set_vpnv4_nexthop_cmd, - "set ip vpn next-hop A.B.C.D", - SET_STR - "IP VPN information\n" - "IP VPN next-hop address\n" - "IP address of next hop\n") -{ - return bgp_route_set_add (vty, vty->index, "ip vpn next-hop", argv[0]); -} - -DEFUN (no_set_vpnv4_nexthop, - no_set_vpnv4_nexthop_cmd, - "no set ip vpn next-hop", - NO_STR - SET_STR - "IP VPN information\n" - "IP VPN next-hop address\n") -{ - if (argc == 0) - return bgp_route_set_delete (vty, vty->index, "ip vpn next-hop", NULL); - - return bgp_route_set_delete (vty, vty->index, "ip vpn next-hop", argv[0]); -} - -ALIAS (no_set_vpnv4_nexthop, - no_set_vpnv4_nexthop_val_cmd, - "no set ip vpn next-hop A.B.C.D", - NO_STR - SET_STR - "IP VPN information\n" - "IP VPN next-hop address\n" - "IP address of next hop\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (set_originator_id, set_originator_id_cmd, "set originator-id A.B.C.D", @@ -4607,9 +4513,6 @@ bgp_route_map_init (void) route_map_install_set (&route_set_aggregator_as_cmd); route_map_install_set (&route_set_community_cmd); route_map_install_set (&route_set_community_delete_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - route_map_install_set (&route_set_vpnv4_nexthop_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ route_map_install_set (&route_set_originator_id_cmd); route_map_install_set (&route_set_ecommunity_rt_cmd); route_map_install_set (&route_set_ecommunity_soo_cmd); @@ -4715,11 +4618,6 @@ bgp_route_map_init (void) install_element (RMAP_NODE, &set_ecommunity_soo_cmd); install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd); install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd); - install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd); - install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (RMAP_NODE, &set_originator_id_cmd); install_element (RMAP_NODE, &no_set_originator_id_cmd); install_element (RMAP_NODE, &no_set_originator_id_val_cmd); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index f2190c8303..a27a5f6b26 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -6139,15 +6139,6 @@ DEFUN (address_family_vpnv4, return CMD_SUCCESS; } -#ifdef KEEP_OLD_VPNV4_COMMANDS -ALIAS (address_family_vpnv4, - address_family_vpnv4_unicast_cmd, - "address-family vpnv4 unicast", - "Enter Address Family command mode\n" - "Address family\n" - "Address Family Modifier\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (address_family_vpnv6, address_family_vpnv6_cmd, "address-family vpnv6", @@ -6158,15 +6149,6 @@ DEFUN (address_family_vpnv6, return CMD_SUCCESS; } -#ifdef KEEP_OLD_VPNV4_COMMANDS -ALIAS (address_family_vpnv6, - address_family_vpnv6_unicast_cmd, - "address-family vpnv6 unicast", - "Enter Address Family command mode\n" - "Address family\n" - "Address Family Modifier\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (address_family_encap, address_family_encap_cmd, "address-family encap", @@ -6734,62 +6716,6 @@ ALIAS (clear_ip_bgp_instance_all_ipv4_soft_out, BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (clear_ip_bgp_all_vpnv4_soft_out, - clear_ip_bgp_all_vpnv4_soft_out_cmd, - "clear ip bgp * vpnv4 unicast soft out", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_STR - BGP_SOFT_OUT_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_all, - BGP_CLEAR_SOFT_OUT, NULL); -} - -ALIAS (clear_ip_bgp_all_vpnv4_soft_out, - clear_ip_bgp_all_vpnv4_out_cmd, - "clear ip bgp * vpnv4 unicast out", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_OUT_STR) - -DEFUN (clear_ip_bgp_all_encap_soft_out, - clear_ip_bgp_all_encap_soft_out_cmd, - "clear ip bgp * encap unicast soft out", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig\n" - "Soft reconfig outbound update\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_all, - BGP_CLEAR_SOFT_OUT, NULL); -} - -ALIAS (clear_ip_bgp_all_encap_soft_out, - clear_ip_bgp_all_encap_out_cmd, - "clear ip bgp * encap unicast out", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig outbound update\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_all_soft_out, clear_bgp_all_soft_out_cmd, "clear bgp * soft out", @@ -7021,65 +6947,6 @@ ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_out, BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) -#ifdef KEEP_OLD_VPNV4_COMMANDS -/* NOTE: WORD peers have not been tested for vpnv4 */ -DEFUN (clear_ip_bgp_peer_vpnv4_soft_out, - clear_ip_bgp_peer_vpnv4_soft_out_cmd, - "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast soft out", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "BGP neighbor on interface to clear\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_STR - BGP_SOFT_OUT_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_peer, - BGP_CLEAR_SOFT_OUT, argv[0]); -} - -ALIAS (clear_ip_bgp_peer_vpnv4_soft_out, - clear_ip_bgp_peer_vpnv4_out_cmd, - "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast out", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "BGP neighbor on interface to clear\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_OUT_STR) - -DEFUN (clear_ip_bgp_peer_encap_soft_out, - clear_ip_bgp_peer_encap_soft_out_cmd, - "clear ip bgp A.B.C.D encap unicast soft out", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig\n" - "Soft reconfig outbound update\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_peer, - BGP_CLEAR_SOFT_OUT, argv[0]); -} - -ALIAS (clear_ip_bgp_peer_encap_soft_out, - clear_ip_bgp_peer_encap_out_cmd, - "clear ip bgp A.B.C.D encap unicast out", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig outbound update\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_peer_soft_out, clear_bgp_peer_soft_out_cmd, "clear bgp (A.B.C.D|X:X::X:X|WORD) soft out", @@ -7688,62 +7555,6 @@ ALIAS (clear_ip_bgp_instance_as_ipv4_soft_out, BGP_SAFI_HELP_STR BGP_SOFT_OUT_STR) -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (clear_ip_bgp_as_vpnv4_soft_out, - clear_ip_bgp_as_vpnv4_soft_out_cmd, - "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft out", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family modifier\n" - BGP_SOFT_STR - BGP_SOFT_OUT_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_as, - BGP_CLEAR_SOFT_OUT, argv[0]); -} - -ALIAS (clear_ip_bgp_as_vpnv4_soft_out, - clear_ip_bgp_as_vpnv4_out_cmd, - "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast out", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family modifier\n" - BGP_SOFT_OUT_STR) - -DEFUN (clear_ip_bgp_as_encap_soft_out, - clear_ip_bgp_as_encap_soft_out_cmd, - "clear ip bgp " CMD_AS_RANGE " encap unicast soft out", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family modifier\n" - "Soft reconfig\n" - "Soft reconfig outbound update\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_as, - BGP_CLEAR_SOFT_OUT, argv[0]); -} - -ALIAS (clear_ip_bgp_as_encap_soft_out, - clear_ip_bgp_as_encap_out_cmd, - "clear ip bgp " CMD_AS_RANGE " encap unicast out", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family modifier\n" - "Soft reconfig outbound update\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_as_soft_out, clear_bgp_as_soft_out_cmd, "clear bgp " CMD_AS_RANGE " soft out", @@ -7973,62 +7784,6 @@ DEFUN (clear_ip_bgp_all_ipv4_in_prefix_filter, BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (clear_ip_bgp_all_vpnv4_soft_in, - clear_ip_bgp_all_vpnv4_soft_in_cmd, - "clear ip bgp * vpnv4 unicast soft in", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_STR - BGP_SOFT_IN_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_all, - BGP_CLEAR_SOFT_IN, NULL); -} - -ALIAS (clear_ip_bgp_all_vpnv4_soft_in, - clear_ip_bgp_all_vpnv4_in_cmd, - "clear ip bgp * vpnv4 unicast in", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_IN_STR) - -DEFUN (clear_ip_bgp_all_encap_soft_in, - clear_ip_bgp_all_encap_soft_in_cmd, - "clear ip bgp * encap unicast soft in", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig\n" - "Soft reconfig inbound update\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_all, - BGP_CLEAR_SOFT_IN, NULL); -} - -ALIAS (clear_ip_bgp_all_encap_soft_in, - clear_ip_bgp_all_encap_in_cmd, - "clear ip bgp * encap unicast in", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig inbound update\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_all_soft_in, clear_bgp_all_soft_in_cmd, "clear bgp * soft in", @@ -8286,64 +8041,6 @@ DEFUN (clear_ip_bgp_peer_ipv4_in_prefix_filter, BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (clear_ip_bgp_peer_vpnv4_soft_in, - clear_ip_bgp_peer_vpnv4_soft_in_cmd, - "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast soft in", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "BGP neighbor on interface to clear\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_STR - BGP_SOFT_IN_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_peer, - BGP_CLEAR_SOFT_IN, argv[0]); -} - -ALIAS (clear_ip_bgp_peer_vpnv4_soft_in, - clear_ip_bgp_peer_vpnv4_in_cmd, - "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast in", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "BGP neighbor on interface to clear\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_IN_STR) - -DEFUN (clear_ip_bgp_peer_encap_soft_in, - clear_ip_bgp_peer_encap_soft_in_cmd, - "clear ip bgp A.B.C.D encap unicast soft in", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig\n" - "Soft reconfig inbound update\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_peer, - BGP_CLEAR_SOFT_IN, argv[0]); -} - -ALIAS (clear_ip_bgp_peer_encap_soft_in, - clear_ip_bgp_peer_encap_in_cmd, - "clear ip bgp A.B.C.D encap unicast in", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig inbound update\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_peer_soft_in, clear_bgp_peer_soft_in_cmd, "clear bgp (A.B.C.D|X:X::X:X|WORD) soft in", @@ -9125,62 +8822,6 @@ DEFUN (clear_ip_bgp_as_ipv4_in_prefix_filter, BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (clear_ip_bgp_as_vpnv4_soft_in, - clear_ip_bgp_as_vpnv4_soft_in_cmd, - "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft in", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family modifier\n" - BGP_SOFT_STR - BGP_SOFT_IN_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_as, - BGP_CLEAR_SOFT_IN, argv[0]); -} - -ALIAS (clear_ip_bgp_as_vpnv4_soft_in, - clear_ip_bgp_as_vpnv4_in_cmd, - "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast in", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family modifier\n" - BGP_SOFT_IN_STR) - -DEFUN (clear_ip_bgp_as_encap_soft_in, - clear_ip_bgp_as_encap_soft_in_cmd, - "clear ip bgp " CMD_AS_RANGE " encap unicast soft in", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family modifier\n" - "Soft reconfig\n" - "Soft reconfig inbound update\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_as, - BGP_CLEAR_SOFT_IN, argv[0]); -} - -ALIAS (clear_ip_bgp_as_encap_soft_in, - clear_ip_bgp_as_encap_in_cmd, - "clear ip bgp " CMD_AS_RANGE " encap unicast in", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family modifier\n" - "Soft reconfig inbound update\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_as_soft_in, clear_bgp_as_soft_in_cmd, "clear bgp " CMD_AS_RANGE " soft in", @@ -9354,38 +8995,6 @@ DEFUN (clear_ip_bgp_instance_all_ipv4_soft, BGP_CLEAR_SOFT_BOTH, NULL); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (clear_ip_bgp_all_vpnv4_soft, - clear_ip_bgp_all_vpnv4_soft_cmd, - "clear ip bgp * vpnv4 unicast soft", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_all, - BGP_CLEAR_SOFT_BOTH, argv[0]); -} - -DEFUN (clear_ip_bgp_all_encap_soft, - clear_ip_bgp_all_encap_soft_cmd, - "clear ip bgp * encap unicast soft", - CLEAR_STR - IP_STR - BGP_STR - "Clear all peers\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_all, - BGP_CLEAR_SOFT_BOTH, argv[0]); -} -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_all_soft, clear_bgp_all_soft_cmd, "clear bgp * soft", @@ -9498,39 +9107,6 @@ DEFUN (clear_ip_bgp_instance_peer_ipv4_soft, BGP_CLEAR_SOFT_BOTH, argv[2]); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (clear_ip_bgp_peer_vpnv4_soft, - clear_ip_bgp_peer_vpnv4_soft_cmd, - "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast soft", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "BGP neighbor on interface to clear\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_peer, - BGP_CLEAR_SOFT_BOTH, argv[0]); -} - -DEFUN (clear_ip_bgp_peer_encap_soft, - clear_ip_bgp_peer_encap_soft_cmd, - "clear ip bgp A.B.C.D encap unicast soft", - CLEAR_STR - IP_STR - BGP_STR - "BGP neighbor address to clear\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_peer, - BGP_CLEAR_SOFT_BOTH, argv[0]); -} -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_peer_soft, clear_bgp_peer_soft_cmd, "clear bgp (A.B.C.D|X:X::X:X|WORD) soft", @@ -9867,38 +9443,6 @@ DEFUN (clear_ip_bgp_instance_as_ipv4_soft, BGP_CLEAR_SOFT_BOTH, argv[2]); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (clear_ip_bgp_as_vpnv4_soft, - clear_ip_bgp_as_vpnv4_soft_cmd, - "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family Modifier\n" - BGP_SOFT_STR) -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_as, - BGP_CLEAR_SOFT_BOTH, argv[0]); -} - -DEFUN (clear_ip_bgp_as_encap_soft, - clear_ip_bgp_as_encap_soft_cmd, - "clear ip bgp " CMD_AS_RANGE " encap unicast soft", - CLEAR_STR - IP_STR - BGP_STR - "Clear peers with the AS number\n" - "Address family\n" - "Address Family Modifier\n" - "Soft reconfig\n") -{ - return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_as, - BGP_CLEAR_SOFT_BOTH, argv[0]); -} -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - DEFUN (clear_bgp_as_soft, clear_bgp_as_soft_cmd, "clear bgp " CMD_AS_RANGE " soft", @@ -10805,49 +10349,6 @@ ALIAS (show_ip_bgp_instance_ipv4_summary, BGP_AFI_SAFI_HELP_STR "Summary of BGP neighbor status\n") -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (show_ip_bgp_vpnv4_all_summary, - show_ip_bgp_vpnv4_all_summary_cmd, - "show ip bgp vpnv4 all summary {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information about all VPNv4 NLRIs\n" - "Summary of BGP neighbor status\n" - "JavaScript Object Notation\n") -{ - u_char uj = use_json(argc, argv); - return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, uj); -} - -DEFUN (show_ip_bgp_vpnv4_rd_summary, - show_ip_bgp_vpnv4_rd_summary_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn summary {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information for a route distinguisher\n" - "VPN Route Distinguisher\n" - "Summary of BGP neighbor status\n" - "JavaScript Object Notation\n") -{ - int ret; - struct prefix_rd prd; - u_char uj = use_json(argc, argv); - - ret = str2prefix_rd (argv[0], &prd); - if (! ret) - { - vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); - return CMD_WARNING; - } - - return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, uj); -} -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - #ifdef HAVE_IPV6 DEFUN (show_bgp_summary, show_bgp_summary_cmd, @@ -12845,31 +12346,6 @@ ALIAS (show_ip_bgp_neighbors, "Detailed information on TCP and BGP neighbor connections\n" "JavaScript Object Notation\n") -#ifdef KEEP_OLD_VPNV4_COMMANDS -ALIAS (show_ip_bgp_neighbors, - show_ip_bgp_vpnv4_all_neighbors_cmd, - "show ip bgp vpnv4 all neighbors {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information about all VPNv4 NLRIs\n" - "Detailed information on TCP and BGP neighbor connections\n" - "JavaScript Object Notation\n") - -ALIAS (show_ip_bgp_neighbors, - show_ip_bgp_vpnv4_rd_neighbors_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information for a route distinguisher\n" - "VPN Route Distinguisher\n" - "Detailed information on TCP and BGP neighbor connections\n" - "JavaScript Object Notation\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - ALIAS (show_ip_bgp_neighbors, show_bgp_neighbors_cmd, "show bgp neighbors {json}", @@ -12918,32 +12394,6 @@ ALIAS (show_ip_bgp_neighbors_peer, "Neighbor on bgp configured interface\n" "JavaScript Object Notation\n") -#ifdef KEEP_OLD_VPNV4_COMMANDS -ALIAS (show_ip_bgp_neighbors_peer, - show_ip_bgp_vpnv4_all_neighbors_peer_cmd, - "show ip bgp vpnv4 all neighbors A.B.C.D {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information about all VPNv4 NLRIs\n" - "Detailed information on TCP and BGP neighbor connections\n" - "Neighbor to display information about\n" - "JavaScript Object Notation\n") - -ALIAS (show_ip_bgp_neighbors_peer, - show_ip_bgp_vpnv4_rd_neighbors_peer_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information about all VPNv4 NLRIs\n" - "Detailed information on TCP and BGP neighbor connections\n" - "Neighbor to display information about\n" - "JavaScript Object Notation\n") -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - ALIAS (show_ip_bgp_neighbors_peer, show_bgp_neighbors_peer_cmd, "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) {json}", @@ -15645,15 +15095,7 @@ bgp_vty_init (void) install_element (BGP_NODE, &address_family_ipv6_safi_cmd); #endif /* HAVE_IPV6 */ install_element (BGP_NODE, &address_family_vpnv4_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - install_element (BGP_NODE, &address_family_vpnv6_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - install_element (BGP_NODE, &address_family_encap_cmd); install_element (BGP_NODE, &address_family_encapv4_cmd); #ifdef HAVE_IPV6 @@ -15754,20 +15196,6 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_in_prefix_filter_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_soft_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_soft_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_in_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_in_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (ENABLE_NODE, &clear_bgp_all_soft_in_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_in_cmd); install_element (ENABLE_NODE, &clear_bgp_all_in_cmd); @@ -15866,20 +15294,6 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_soft_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_out_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_soft_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_soft_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_out_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_out_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (ENABLE_NODE, &clear_bgp_all_soft_out_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_out_cmd); install_element (ENABLE_NODE, &clear_bgp_all_out_cmd); @@ -15942,14 +15356,6 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_instance_external_ipv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_soft_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_soft_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_soft_cmd); - install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (ENABLE_NODE, &clear_bgp_all_soft_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_cmd); install_element (ENABLE_NODE, &clear_bgp_peer_soft_cmd); @@ -16001,10 +15407,6 @@ bgp_vty_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_summary_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_ipv4_summary_cmd); install_element (VIEW_NODE, &show_bgp_instance_ipv4_safi_summary_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_summary_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_summary_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ #ifdef HAVE_IPV6 install_element (VIEW_NODE, &show_bgp_summary_cmd); install_element (VIEW_NODE, &show_bgp_instance_summary_cmd); @@ -16020,12 +15422,6 @@ bgp_vty_init (void) install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_neighbors_peer_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbors_peer_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbors_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbors_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbors_peer_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbors_peer_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ install_element (VIEW_NODE, &show_ip_bgp_instance_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_all_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_neighbors_peer_cmd); From 912e52346f7f2f3b7289ddcae508414e56eb1111 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Thu, 12 Jan 2017 09:36:24 -0500 Subject: [PATCH 28/35] bgpd: convert 'show_ip_bgp_vpnv4' to afi/safi form (Issue #61) --- bgpd/bgp_mplsvpn.c | 274 +++++++++++++++++++++++---------------------- bgpd/bgp_route.c | 19 ++-- 2 files changed, 149 insertions(+), 144 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 02febf8630..b710e0b03b 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -35,6 +35,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "bgpd/bgp_attr.h" #include "bgpd/bgp_mplsvpn.h" #include "bgpd/bgp_packet.h" +#include "bgpd/bgp_vty.h" #if ENABLE_BGP_VNC #include "bgpd/rfapi/rfapi_backend.h" @@ -484,9 +485,8 @@ DEFUN (no_vpnv4_network, return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2]); } -#ifdef KEEP_OLD_VPNV4_COMMANDS static int -show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u_char use_json) +show_adj_route_vpn (struct vty *vty, struct peer *peer, afi_t afi, struct prefix_rd *prd, u_char use_json) { struct bgp *bgp; struct bgp_table *table; @@ -529,7 +529,7 @@ show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u json_object_string_add(json_ocode, "incomplete", "?"); } - for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; + for (rn = bgp_table_top (bgp->rib[afi][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn)) { if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) @@ -651,7 +651,6 @@ show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u } return CMD_SUCCESS; } -#endif /* KEEP_OLD_VPNV4_COMMANDS */ enum bgp_show_type { @@ -956,26 +955,25 @@ DEFUN (show_bgp_ipv6_vpn_rd, return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0, use_json (argc, argv)); } -#ifdef KEEP_OLD_VPNV4_COMMANDS -DEFUN (show_ip_bgp_vpnv4_all, - show_ip_bgp_vpnv4_all_cmd, - "show ip bgp vpnv4 all", +DEFUN (show_bgp_ip_vpn_all, + show_bgp_ip_vpn_all_cmd, + "show bgp "BGP_AFI_CMD_STR" vpn all", SHOW_STR IP_STR BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information about all VPNv4 NLRIs\n") + BGP_AFI_HELP_STR + "Display information about all VPN NLRIs\n") { - return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 0, 0); + return bgp_show_mpls_vpn (vty, bgp_vty_afi_from_arg(argv[0]), NULL, bgp_show_type_normal, NULL, 0, 0); } -DEFUN (show_ip_bgp_vpnv4_rd, - show_ip_bgp_vpnv4_rd_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn", +DEFUN (show_bgp_ip_vpn_rd, + show_bgp_ip_vpn_rd_cmd, + "show bgp "BGP_AFI_CMD_STR" vpn rd ASN:nn_or_IP-address:nn", SHOW_STR IP_STR BGP_STR - "Display VPNv4 NLRI specific information\n" + BGP_AFI_HELP_STR "Display information for a route distinguisher\n" "VPN Route Distinguisher\n") { @@ -988,29 +986,29 @@ DEFUN (show_ip_bgp_vpnv4_rd, vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0, 0); + return bgp_show_mpls_vpn (vty, bgp_vty_afi_from_arg(argv[0]), &prd, bgp_show_type_normal, NULL, 0, 0); } -DEFUN (show_ip_bgp_vpnv4_all_tags, - show_ip_bgp_vpnv4_all_tags_cmd, - "show ip bgp vpnv4 all tags", +DEFUN (show_bgp_ip_vpn_all_tags, + show_bgp_ip_vpn_all_tags_cmd, + "show bgp "BGP_AFI_CMD_STR" vpn all tags", SHOW_STR IP_STR BGP_STR - "Display VPNv4 NLRI specific information\n" + BGP_AFI_HELP_STR "Display information about all VPNv4 NLRIs\n" "Display BGP tags for prefixes\n") { - return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1, 0); + return bgp_show_mpls_vpn (vty, bgp_vty_afi_from_arg(argv[0]), NULL, bgp_show_type_normal, NULL, 1, 0); } -DEFUN (show_ip_bgp_vpnv4_rd_tags, - show_ip_bgp_vpnv4_rd_tags_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn tags", +DEFUN (show_bgp_ip_vpn_rd_tags, + show_bgp_ip_vpn_rd_tags_cmd, + "show bgp "BGP_AFI_CMD_STR" vpn rd ASN:nn_or_IP-address:nn tags", SHOW_STR IP_STR BGP_STR - "Display VPNv4 NLRI specific information\n" + BGP_AFI_HELP_STR "Display information for a route distinguisher\n" "VPN Route Distinguisher\n" "Display BGP tags for prefixes\n") @@ -1018,103 +1016,34 @@ DEFUN (show_ip_bgp_vpnv4_rd_tags, int ret; struct prefix_rd prd; - ret = str2prefix_rd (argv[0], &prd); + ret = str2prefix_rd (argv[1], &prd); if (! ret) { vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1, 0); + return bgp_show_mpls_vpn (vty, bgp_vty_afi_from_arg(argv[0]), &prd, bgp_show_type_normal, NULL, 1, 0); } -DEFUN (show_ip_bgp_vpnv4_all_neighbor_routes, - show_ip_bgp_vpnv4_all_neighbor_routes_cmd, - "show ip bgp vpnv4 all neighbors A.B.C.D routes {json}", +DEFUN (show_bgp_ip_vpn_all_neighbor_routes, + show_bgp_ip_vpn_all_neighbor_routes_cmd, + "show bgp "BGP_AFI_CMD_STR" vpn all neighbors (A.B.C.D|X:X::X:X) routes {json}", SHOW_STR IP_STR BGP_STR - "Display VPNv4 NLRI specific information\n" + BGP_AFI_HELP_STR "Display information about all VPNv4 NLRIs\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" - "Display routes learned from neighbor\n" - "JavaScript Object Notation\n") -{ - union sockunion su; - struct peer *peer; - int ret; - u_char uj = use_json(argc, argv); - - ret = str2sockunion (argv[0], &su); - if (ret < 0) - { - if (uj) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "Malformed address"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); - return CMD_WARNING; - } - - peer = peer_lookup (NULL, &su); - if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) - { - if (uj) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "No such neighbor or address family"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); - return CMD_WARNING; - } - - return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0, uj); -} - -DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes, - show_ip_bgp_vpnv4_rd_neighbor_routes_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes {json}", - SHOW_STR - IP_STR - BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information for a route distinguisher\n" - "VPN Route Distinguisher\n" - "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Display routes learned from neighbor\n" "JavaScript Object Notation\n") { - int ret; union sockunion su; struct peer *peer; - struct prefix_rd prd; + int ret; u_char uj = use_json(argc, argv); - - ret = str2prefix_rd (argv[0], &prd); - if (! ret) - { - if (uj) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "Malformed Route Distinguisher"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); - return CMD_WARNING; - } + afi_t afi = bgp_vty_afi_from_arg(argv[0]); ret = str2sockunion (argv[1], &su); if (ret < 0) @@ -1133,7 +1062,7 @@ DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes, } peer = peer_lookup (NULL, &su); - if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) + if (! peer || ! peer->afc[afi][SAFI_MPLS_VPN]) { if (uj) { @@ -1148,28 +1077,48 @@ DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes, return CMD_WARNING; } - return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_neighbor, &su, 0, uj); + return bgp_show_mpls_vpn (vty, afi, NULL, bgp_show_type_neighbor, &su, 0, uj); } -DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes, - show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd, - "show ip bgp vpnv4 all neighbors A.B.C.D advertised-routes {json}", +DEFUN (show_bgp_ip_vpn_rd_neighbor_routes, + show_bgp_ip_vpn_rd_neighbor_routes_cmd, + "show bgp "BGP_AFI_CMD_STR" vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes {json}", SHOW_STR IP_STR BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information about all VPNv4 NLRIs\n" + BGP_AFI_HELP_STR + "Display information for a route distinguisher\n" + "VPN Route Distinguisher\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" - "Display the routes advertised to a BGP neighbor\n" + "Neighbor to display information about\n" + "Display routes learned from neighbor\n" "JavaScript Object Notation\n") { int ret; - struct peer *peer; union sockunion su; + struct peer *peer; + struct prefix_rd prd; u_char uj = use_json(argc, argv); + afi_t afi = bgp_vty_afi_from_arg(argv[0]); - ret = str2sockunion (argv[0], &su); + ret = str2prefix_rd (argv[1], &prd); + if (! ret) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "Malformed Route Distinguisher"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); + return CMD_WARNING; + } + + ret = str2sockunion (argv[2], &su); if (ret < 0) { if (uj) @@ -1184,8 +1133,9 @@ DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes, vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); return CMD_WARNING; } + peer = peer_lookup (NULL, &su); - if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) + if (! peer || ! peer->afc[afi][SAFI_MPLS_VPN]) { if (uj) { @@ -1200,28 +1150,28 @@ DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes, return CMD_WARNING; } - return show_adj_route_vpn (vty, peer, NULL, uj); + return bgp_show_mpls_vpn (vty, afi, &prd, bgp_show_type_neighbor, &su, 0, uj); } -DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes, - show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd, - "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes {json}", +DEFUN (show_bgp_ip_vpn_all_neighbor_advertised_routes, + show_bgp_ip_vpn_all_neighbor_advertised_routes_cmd, + "show bgp "BGP_AFI_CMD_STR" vpn all neighbors (A.B.C.D|X:X::X:X) advertised-routes {json}", SHOW_STR IP_STR BGP_STR - "Display VPNv4 NLRI specific information\n" - "Display information for a route distinguisher\n" - "VPN Route Distinguisher\n" + BGP_AFI_HELP_STR + "Display information about all VPN NLRIs\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" + "Neighbor to display information about\n" "Display the routes advertised to a BGP neighbor\n" "JavaScript Object Notation\n") { int ret; struct peer *peer; - struct prefix_rd prd; union sockunion su; u_char uj = use_json(argc, argv); + afi_t afi = bgp_vty_afi_from_arg(argv[0]); ret = str2sockunion (argv[1], &su); if (ret < 0) @@ -1239,7 +1189,7 @@ DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes, return CMD_WARNING; } peer = peer_lookup (NULL, &su); - if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) + if (! peer || ! peer->afc[afi][SAFI_MPLS_VPN]) { if (uj) { @@ -1254,7 +1204,63 @@ DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes, return CMD_WARNING; } - ret = str2prefix_rd (argv[0], &prd); + return show_adj_route_vpn (vty, peer, afi, NULL, uj); +} + +DEFUN (show_bgp_ip_vpn_rd_neighbor_advertised_routes, + show_bgp_ip_vpn_rd_neighbor_advertised_routes_cmd, + "show bgp "BGP_AFI_CMD_STR" vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes {json}", + SHOW_STR + IP_STR + BGP_STR + BGP_AFI_HELP_STR + "Display information for a route distinguisher\n" + "VPN Route Distinguisher\n" + "Detailed information on TCP and BGP neighbor connections\n" + "Neighbor to display information about\n" + "Neighbor to display information about\n" + "Display the routes advertised to a BGP neighbor\n" + "JavaScript Object Notation\n") +{ + int ret; + struct peer *peer; + struct prefix_rd prd; + union sockunion su; + u_char uj = use_json(argc, argv); + afi_t afi = bgp_vty_afi_from_arg(argv[0]); + + ret = str2sockunion (argv[2], &su); + if (ret < 0) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "Malformed address"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "Malformed address: %s%s", argv[2], VTY_NEWLINE); + return CMD_WARNING; + } + peer = peer_lookup (NULL, &su); + if (! peer || ! peer->afc[afi][SAFI_MPLS_VPN]) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "No such neighbor or address family"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); + return CMD_WARNING; + } + + ret = str2prefix_rd (argv[1], &prd); if (! ret) { if (uj) @@ -1270,9 +1276,8 @@ DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes, return CMD_WARNING; } - return show_adj_route_vpn (vty, peer, &prd, uj); + return show_adj_route_vpn (vty, peer, afi, &prd, uj); } -#endif /* KEEP_OLD_VPNV4_COMMANDS */ void bgp_mplsvpn_init (void) @@ -1285,15 +1290,12 @@ bgp_mplsvpn_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_cmd); install_element (VIEW_NODE, &show_bgp_ipv6_vpn_cmd); install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_cmd); -#ifdef KEEP_OLD_VPNV4_COMMANDS - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_tags_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd); -#endif /* KEEP_OLD_VPNV4_COMMANDS */ - + install_element (VIEW_NODE, &show_bgp_ip_vpn_all_cmd); + install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_cmd); + install_element (VIEW_NODE, &show_bgp_ip_vpn_all_tags_cmd); + install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_tags_cmd); + install_element (VIEW_NODE, &show_bgp_ip_vpn_all_neighbor_routes_cmd); + install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_neighbor_routes_cmd); + install_element (VIEW_NODE, &show_bgp_ip_vpn_all_neighbor_advertised_routes_cmd); + install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_neighbor_advertised_routes_cmd); } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 7d423be631..9e1ae854d4 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -6416,7 +6416,8 @@ route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi == SAFI_ENCAP || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) { - if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) + if (attr->extra && + (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)) vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in)); else @@ -6427,13 +6428,15 @@ route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t { int len; char buf[BUFSIZ]; - - assert (attr->extra); - - len = vty_out (vty, "%s", - inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, - buf, BUFSIZ)); - len = 16 - len; + if (attr->extra) + { + len = vty_out (vty, "%s", + inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, + buf, BUFSIZ)); + len = 16 - len; + } + else + len = 0; if (len < 1) vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); else From 903c7f556e6631e5f20f2d720e35ce39ffb599eb Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 12 Jan 2017 13:10:48 -0500 Subject: [PATCH 29/35] apply rename to readme.md --- README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index 4476947490..95aa5eb248 100644 --- a/README +++ b/README @@ -1,9 +1,9 @@ -Quagga is free software that manages various IPv4 and IPv6 routing +Free Range Routing is free software that manages various IPv4 and IPv6 routing protocols. -Currently Quagga supports BGP4, BGP4+, OSPFv2, OSPFv3, RIPv1, +Currently Free Range Routing supports BGP4, BGP4+, OSPFv2, OSPFv3, RIPv1, RIPv2, RIPng, PIM-SSM and LDP as well as very early support for IS-IS. See the file REPORTING-BUGS to report bugs. -Quagga is free software. See the file COPYING for copying conditions. +Free Range Routing is free software. See the file COPYING for copying conditions. From 2f9a659926f5d91683f740bd527c4e9fe1cdda5c Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 13 Jan 2017 11:23:18 +0100 Subject: [PATCH 30/35] tests: ignore stderr for expect expect redirects both stdout and stderr to its input. This causes serious problems when libzebra prints log messages to stderr, which are then asynchronously inserted in the middle of lines of stdout test output. Ultimately this makes testbgpmpattr fail on FreeBSD. (The stdio buffering seems to be slightly different on FreeBSD, triggering the bug.) Just ignore stderr for expect. Signed-off-by: David Lamparter --- tests/bgpd.tests/aspathtest.exp | 2 +- tests/bgpd.tests/ecommtest.exp | 2 +- tests/bgpd.tests/testbgpcap.exp | 2 +- tests/bgpd.tests/testbgpmpath.exp | 2 +- tests/bgpd.tests/testbgpmpattr.exp | 2 +- tests/libzebra.tests/tabletest.exp | 2 +- tests/libzebra.tests/test-timer-correctness.exp | 2 +- tests/libzebra.tests/testnexthopiter.exp | 2 +- tests/libzebra.tests/teststream.exp | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/bgpd.tests/aspathtest.exp b/tests/bgpd.tests/aspathtest.exp index dfecec7801..f5f262f80a 100644 --- a/tests/bgpd.tests/aspathtest.exp +++ b/tests/bgpd.tests/aspathtest.exp @@ -3,7 +3,7 @@ set testprefix "aspathtest " set aborted 0 set color 1 -spawn "./aspathtest" +spawn sh -c "exec ./aspathtest 2>/dev/null" # proc onetest { test_name note start } { # proc headerline { line } { diff --git a/tests/bgpd.tests/ecommtest.exp b/tests/bgpd.tests/ecommtest.exp index 074952fab8..cbeb03af52 100644 --- a/tests/bgpd.tests/ecommtest.exp +++ b/tests/bgpd.tests/ecommtest.exp @@ -3,7 +3,7 @@ set testprefix "ecommtest " set aborted 0 set color 0 -spawn "./ecommtest" +spawn sh -c "exec ./ecommtest 2>/dev/null" # proc simpletest { start } { diff --git a/tests/bgpd.tests/testbgpcap.exp b/tests/bgpd.tests/testbgpcap.exp index 2572623f06..aba6906bc0 100644 --- a/tests/bgpd.tests/testbgpcap.exp +++ b/tests/bgpd.tests/testbgpcap.exp @@ -3,7 +3,7 @@ set testprefix "testbgpcap " set aborted 0 set color 1 -spawn "./testbgpcap" +spawn sh -c "exec ./testbgpcap 2>/dev/null" # proc simpletest { start } { diff --git a/tests/bgpd.tests/testbgpmpath.exp b/tests/bgpd.tests/testbgpmpath.exp index 96a51e390c..6820f636a4 100644 --- a/tests/bgpd.tests/testbgpmpath.exp +++ b/tests/bgpd.tests/testbgpmpath.exp @@ -3,7 +3,7 @@ set testprefix "testbgpmpath " set aborted 0 set color 1 -spawn "./testbgpmpath" +spawn sh -c "exec ./testbgpmpath 2>/dev/null" # proc simpletest { start } { diff --git a/tests/bgpd.tests/testbgpmpattr.exp b/tests/bgpd.tests/testbgpmpattr.exp index e6d7305a68..1abce3fc9a 100644 --- a/tests/bgpd.tests/testbgpmpattr.exp +++ b/tests/bgpd.tests/testbgpmpattr.exp @@ -3,7 +3,7 @@ set testprefix "testbgpmpattr " set aborted 0 set color 1 -spawn "./testbgpmpattr" +spawn sh -c "exec ./testbgpmpattr 2>/dev/null" # proc simpletest { start } { diff --git a/tests/libzebra.tests/tabletest.exp b/tests/libzebra.tests/tabletest.exp index 5838d4fc7c..7496994b7f 100644 --- a/tests/libzebra.tests/tabletest.exp +++ b/tests/libzebra.tests/tabletest.exp @@ -2,7 +2,7 @@ set timeout 10 set testprefix "tabletest " set aborted 0 -spawn "./tabletest" +spawn sh -c "exec ./tabletest 2>/dev/null" for {set i 0} {$i < 6} {incr i 1} { onesimple "cmp $i" "Verifying cmp"; } for {set i 0} {$i < 11} {incr i 1} { onesimple "succ $i" "Verifying successor"; } diff --git a/tests/libzebra.tests/test-timer-correctness.exp b/tests/libzebra.tests/test-timer-correctness.exp index 83531c7df8..570150cd51 100644 --- a/tests/libzebra.tests/test-timer-correctness.exp +++ b/tests/libzebra.tests/test-timer-correctness.exp @@ -2,6 +2,6 @@ set timeout 10 set testprefix "test-timer-correctness" set aborted 0 -spawn "./test-timer-correctness" +spawn sh -c "exec ./test-timer-correctness 2>/dev/null" onesimple "" "Expected output and actual output match." diff --git a/tests/libzebra.tests/testnexthopiter.exp b/tests/libzebra.tests/testnexthopiter.exp index be35a0a2b8..777b753995 100644 --- a/tests/libzebra.tests/testnexthopiter.exp +++ b/tests/libzebra.tests/testnexthopiter.exp @@ -2,7 +2,7 @@ set timeout 10 set testprefix "testnexthopiter " set aborted 0 -spawn "./testnexthopiter" +spawn sh -c "exec ./testnexthopiter 2>/dev/null" onesimple "simple" "Simple test passed." onesimple "prng" "PRNG test passed." diff --git a/tests/libzebra.tests/teststream.exp b/tests/libzebra.tests/teststream.exp index ca602e305b..c977bb4417 100644 --- a/tests/libzebra.tests/teststream.exp +++ b/tests/libzebra.tests/teststream.exp @@ -1,5 +1,5 @@ set timeout 10 -spawn "./teststream" +spawn sh -c "exec ./teststream 2>/dev/null" expect { "endp: 15, readable: 15, writeable: 1009" { } From 9d8927ee1f97a2d52bb80f1494666e46c2f0edf3 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 16 Dec 2016 00:09:46 +0100 Subject: [PATCH 31/35] tests: fix exit <> return mix-up in dejagnu exit 0 exits the entire testrunner... Oops. Also, "unresolved" breaks too many things, so make this a pass. Signed-off-by: David Lamparter [cherry-picked from master e988dfd35b0d9df437ac043a613472437c8842e6] --- tests/libzebra.tests/testcommands.exp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/libzebra.tests/testcommands.exp b/tests/libzebra.tests/testcommands.exp index d4bfc8231f..c5d5a00730 100644 --- a/tests/libzebra.tests/testcommands.exp +++ b/tests/libzebra.tests/testcommands.exp @@ -5,8 +5,8 @@ if {![info exists env(QUAGGA_TEST_COMMANDS)]} { # sadly, the test randomly fails when configure parameters differ from # what was used to create testcommands.refout. this can be fixed by # shipping a matching vtysh_cmd.c, which we'll add after 0.99.23 - unresolved "$test_name" - exit 0 + pass "$test_name" + return 0 } spawn sh -c "./testcommands -e 0 < $env(srcdir)/testcommands.in | diff -au - $env(srcdir)/testcommands.refout" From 81f28d26247891ffe348b195911472ea65d8ea83 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 16 Dec 2016 00:14:55 +0100 Subject: [PATCH 32/35] tests: fix mis-fixed format string PRIu64 is "u", we need "x", so PRIx64... Signed-off-by: David Lamparter Cc: Donald Sharp [cherry-picked from master eed831e065694b3746896b126f6ad47548ea9dc0] --- tests/test-stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-stream.c b/tests/test-stream.c index 7ef6374756..3ac45eb203 100644 --- a/tests/test-stream.c +++ b/tests/test-stream.c @@ -70,7 +70,7 @@ main (void) printf ("c: 0x%hhx\n", stream_getc (s)); printf ("w: 0x%hx\n", stream_getw (s)); printf ("l: 0x%x\n", stream_getl (s)); - printf ("q: 0x%" PRIu64 "\n", stream_getq (s)); + printf ("q: 0x%" PRIx64 "\n", stream_getq (s)); return 0; } From a6810074aa7b5cc621c8358bef99e44ee4dc3548 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 13 Jan 2017 14:10:00 +0100 Subject: [PATCH 33/35] watchfrr: indent to Linux CodingStyle before this patch, watchfrr was using an inconsistent style that matched neither GNU nor Linux kernel nor BSD style. Reindent to Linux kernel style, which should be pretty close to pimd & ldpd. indent (2.2.11) options used: -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1 Signed-off-by: David Lamparter --- watchfrr/watchfrr.c | 2156 +++++++++++++++++++-------------------- watchfrr/watchfrr.h | 2 +- watchfrr/watchfrr_vty.c | 38 +- 3 files changed, 1073 insertions(+), 1123 deletions(-) diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index 903e2bbe91..122d6db6d7 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -65,149 +65,136 @@ /* Needs to be global, referenced somewhere inside libzebra. */ struct thread_master *master; -typedef enum -{ - MODE_MONITOR = 0, - MODE_GLOBAL_RESTART, - MODE_SEPARATE_RESTART, - MODE_PHASED_ZEBRA_RESTART, - MODE_PHASED_ALL_RESTART +typedef enum { + MODE_MONITOR = 0, + MODE_GLOBAL_RESTART, + MODE_SEPARATE_RESTART, + MODE_PHASED_ZEBRA_RESTART, + MODE_PHASED_ALL_RESTART } watch_mode_t; -static const char *mode_str[] = -{ - "monitor", - "global restart", - "individual daemon restart", - "phased zebra restart", - "phased global restart for any failure", +static const char *mode_str[] = { + "monitor", + "global restart", + "individual daemon restart", + "phased zebra restart", + "phased global restart for any failure", }; -typedef enum -{ - PHASE_NONE = 0, - PHASE_STOPS_PENDING, - PHASE_WAITING_DOWN, - PHASE_ZEBRA_RESTART_PENDING, - PHASE_WAITING_ZEBRA_UP +typedef enum { + PHASE_NONE = 0, + PHASE_STOPS_PENDING, + PHASE_WAITING_DOWN, + PHASE_ZEBRA_RESTART_PENDING, + PHASE_WAITING_ZEBRA_UP } restart_phase_t; -static const char *phase_str[] = -{ - "None", - "Stop jobs running", - "Waiting for other daemons to come down", - "Zebra restart job running", - "Waiting for zebra to come up", - "Start jobs running", +static const char *phase_str[] = { + "None", + "Stop jobs running", + "Waiting for other daemons to come down", + "Zebra restart job running", + "Waiting for zebra to come up", + "Start jobs running", }; #define PHASE_TIMEOUT (3*gs.restart_timeout) -struct restart_info -{ - const char *name; - const char *what; - pid_t pid; - struct timeval time; - long interval; - struct thread *t_kill; - int kills; +struct restart_info { + const char *name; + const char *what; + pid_t pid; + struct timeval time; + long interval; + struct thread *t_kill; + int kills; }; -static struct global_state -{ - watch_mode_t mode; - restart_phase_t phase; - struct thread *t_phase_hanging; - const char *vtydir; - long period; - long timeout; - long restart_timeout; - long min_restart_interval; - long max_restart_interval; - int do_ping; - struct daemon *daemons; - const char *restart_command; - const char *start_command; - const char *stop_command; - struct restart_info restart; - int unresponsive_restart; - int loglevel; - struct daemon *special; /* points to zebra when doing phased restart */ - int numdaemons; - int numpids; - int numdown; /* # of daemons that are not UP or UNRESPONSIVE */ +static struct global_state { + watch_mode_t mode; + restart_phase_t phase; + struct thread *t_phase_hanging; + const char *vtydir; + long period; + long timeout; + long restart_timeout; + long min_restart_interval; + long max_restart_interval; + int do_ping; + struct daemon *daemons; + const char *restart_command; + const char *start_command; + const char *stop_command; + struct restart_info restart; + int unresponsive_restart; + int loglevel; + struct daemon *special; /* points to zebra when doing phased restart */ + int numdaemons; + int numpids; + int numdown; /* # of daemons that are not UP or UNRESPONSIVE */ } gs = { - .mode = MODE_MONITOR, - .phase = PHASE_NONE, - .vtydir = VTYDIR, - .period = 1000*DEFAULT_PERIOD, - .timeout = DEFAULT_TIMEOUT, - .restart_timeout = DEFAULT_RESTART_TIMEOUT, - .loglevel = DEFAULT_LOGLEVEL, - .min_restart_interval = DEFAULT_MIN_RESTART, - .max_restart_interval = DEFAULT_MAX_RESTART, - .do_ping = 1, -}; +.mode = MODE_MONITOR,.phase = PHASE_NONE,.vtydir = VTYDIR,.period = + 1000 * DEFAULT_PERIOD,.timeout = + DEFAULT_TIMEOUT,.restart_timeout = + DEFAULT_RESTART_TIMEOUT,.loglevel = + DEFAULT_LOGLEVEL,.min_restart_interval = + DEFAULT_MIN_RESTART,.max_restart_interval = + DEFAULT_MAX_RESTART,.do_ping = 1,}; -typedef enum -{ - DAEMON_INIT, - DAEMON_DOWN, - DAEMON_CONNECTING, - DAEMON_UP, - DAEMON_UNRESPONSIVE +typedef enum { + DAEMON_INIT, + DAEMON_DOWN, + DAEMON_CONNECTING, + DAEMON_UP, + DAEMON_UNRESPONSIVE } daemon_state_t; #define IS_UP(DMN) \ (((DMN)->state == DAEMON_UP) || ((DMN)->state == DAEMON_UNRESPONSIVE)) -static const char *state_str[] = -{ - "Init", - "Down", - "Connecting", - "Up", - "Unresponsive", +static const char *state_str[] = { + "Init", + "Down", + "Connecting", + "Up", + "Unresponsive", }; struct daemon { - const char *name; - daemon_state_t state; - int fd; - struct timeval echo_sent; - u_int connect_tries; - struct thread *t_wakeup; - struct thread *t_read; - struct thread *t_write; - struct daemon *next; - struct restart_info restart; + const char *name; + daemon_state_t state; + int fd; + struct timeval echo_sent; + u_int connect_tries; + struct thread *t_wakeup; + struct thread *t_read; + struct thread *t_write; + struct daemon *next; + struct restart_info restart; }; -static const struct option longopts[] = -{ - { "daemon", no_argument, NULL, 'd'}, - { "statedir", required_argument, NULL, 'S'}, - { "no-echo", no_argument, NULL, 'e'}, - { "loglevel", required_argument, NULL, 'l'}, - { "interval", required_argument, NULL, 'i'}, - { "timeout", required_argument, NULL, 't'}, - { "restart-timeout", required_argument, NULL, 'T'}, - { "restart", required_argument, NULL, 'r'}, - { "start-command", required_argument, NULL, 's'}, - { "kill-command", required_argument, NULL, 'k'}, - { "restart-all", required_argument, NULL, 'R'}, - { "all-restart", no_argument, NULL, 'a'}, - { "always-all-restart", no_argument, NULL, 'A'}, - { "unresponsive-restart", no_argument, NULL, 'z'}, - { "min-restart-interval", required_argument, NULL, 'm'}, - { "max-restart-interval", required_argument, NULL, 'M'}, - { "pid-file", required_argument, NULL, 'p'}, - { "blank-string", required_argument, NULL, 'b'}, - { "help", no_argument, NULL, 'h'}, - { "version", no_argument, NULL, 'v'}, - { NULL, 0, NULL, 0 } +static const struct option longopts[] = { + {"daemon", no_argument, NULL, 'd'}, + {"statedir", required_argument, NULL, 'S'}, + {"no-echo", no_argument, NULL, 'e'}, + {"loglevel", required_argument, NULL, 'l'}, + {"interval", required_argument, NULL, 'i'}, + {"timeout", required_argument, NULL, 't'}, + {"restart-timeout", required_argument, NULL, 'T'}, + {"restart", required_argument, NULL, 'r'}, + {"start-command", required_argument, NULL, 's'}, + {"kill-command", required_argument, NULL, 'k'}, + {"restart-all", required_argument, NULL, 'R'}, + {"all-restart", no_argument, NULL, 'a'}, + {"always-all-restart", no_argument, NULL, 'A'}, + {"unresponsive-restart", no_argument, NULL, 'z'}, + {"min-restart-interval", required_argument, NULL, 'm'}, + {"max-restart-interval", required_argument, NULL, 'M'}, + {"pid-file", required_argument, NULL, 'p'}, + {"blank-string", required_argument, NULL, 'b'}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {NULL, 0, NULL, 0} }; static int try_connect(struct daemon *dmn); @@ -215,14 +202,13 @@ static int wakeup_send_echo(struct thread *t_wakeup); static void try_restart(struct daemon *dmn); static void phase_check(void); -static int -usage(const char *progname, int status) +static int usage(const char *progname, int status) { - if (status != 0) - fprintf(stderr, "Try `%s --help' for more information.\n", progname); - else - { - printf("Usage : %s [OPTION...] ...\n\n\ + if (status != 0) + fprintf(stderr, "Try `%s --help' for more information.\n", + progname); + else { + printf("Usage : %s [OPTION...] ...\n\n\ Watchdog program to monitor status of frr daemons and try to restart\n\ them if they are down or unresponsive. It determines whether a daemon is\n\ up based on whether it can connect to the daemon's vty unix stream socket.\n\ @@ -266,12 +252,9 @@ the -m and -M options allow you to control the minimum delay between\n\ restart commands. The minimum restart delay is recalculated each time\n\ a restart is attempted: if the time since the last restart attempt exceeds\n\ twice the -M value, then the restart delay is set to the -m value.\n\ -Otherwise, the interval is doubled (but capped at the -M value).\n\n", - progname,mode_str[0],progname,mode_str[1],progname,mode_str[2], - progname,mode_str[3],progname,mode_str[4],progname,mode_str[2], - mode_str[3]); +Otherwise, the interval is doubled (but capped at the -M value).\n\n", progname, mode_str[0], progname, mode_str[1], progname, mode_str[2], progname, mode_str[3], progname, mode_str[4], progname, mode_str[2], mode_str[3]); - printf("Options:\n\ + printf("Options:\n\ -d, --daemon Run in daemon mode. In this mode, error messages are sent\n\ to syslog instead of stdout.\n\ -S, --statedir Set the vty socket directory (default is %s)\n\ @@ -329,221 +312,203 @@ Otherwise, the interval is doubled (but capped at the -M value).\n\n", it with a space. This is an ugly hack to circumvent problems\n\ passing command-line arguments with embedded spaces.\n\ -v, --version Print program version\n\ --h, --help Display this help and exit\n", - VTYDIR,DEFAULT_LOGLEVEL,LOG_EMERG,LOG_DEBUG,LOG_DEBUG, - DEFAULT_MIN_RESTART,DEFAULT_MAX_RESTART, - DEFAULT_PERIOD,DEFAULT_TIMEOUT,DEFAULT_RESTART_TIMEOUT, - DEFAULT_PIDFILE); - } +-h, --help Display this help and exit\n", VTYDIR, DEFAULT_LOGLEVEL, LOG_EMERG, LOG_DEBUG, LOG_DEBUG, DEFAULT_MIN_RESTART, DEFAULT_MAX_RESTART, DEFAULT_PERIOD, DEFAULT_TIMEOUT, DEFAULT_RESTART_TIMEOUT, DEFAULT_PIDFILE); + } - return status; + return status; } -static pid_t -run_background(char *shell_cmd) +static pid_t run_background(char *shell_cmd) { - pid_t child; + pid_t child; - switch (child = fork()) - { - case -1: - zlog_err("fork failed, cannot run command [%s]: %s", - shell_cmd,safe_strerror(errno)); - return -1; - case 0: - /* Child process. */ - /* Use separate process group so child processes can be killed easily. */ - if (setpgid(0,0) < 0) - zlog_warn("warning: setpgid(0,0) failed: %s",safe_strerror(errno)); - { - char shell[] = "sh"; - char dashc[] = "-c"; - char * const argv[4] = { shell, dashc, shell_cmd, NULL}; - execv("/bin/sh", argv); - zlog_err("execv(/bin/sh -c '%s') failed: %s", - shell_cmd,safe_strerror(errno)); - _exit(127); - } - default: - /* Parent process: we will reap the child later. */ - zlog_err("Forked background command [pid %d]: %s",(int)child,shell_cmd); - return child; - } + switch (child = fork()) { + case -1: + zlog_err("fork failed, cannot run command [%s]: %s", + shell_cmd, safe_strerror(errno)); + return -1; + case 0: + /* Child process. */ + /* Use separate process group so child processes can be killed easily. */ + if (setpgid(0, 0) < 0) + zlog_warn("warning: setpgid(0,0) failed: %s", + safe_strerror(errno)); + { + char shell[] = "sh"; + char dashc[] = "-c"; + char *const argv[4] = { shell, dashc, shell_cmd, NULL }; + execv("/bin/sh", argv); + zlog_err("execv(/bin/sh -c '%s') failed: %s", + shell_cmd, safe_strerror(errno)); + _exit(127); + } + default: + /* Parent process: we will reap the child later. */ + zlog_err("Forked background command [pid %d]: %s", (int)child, + shell_cmd); + return child; + } } -static struct timeval * -time_elapsed(struct timeval *result, const struct timeval *start_time) +static struct timeval *time_elapsed(struct timeval *result, + const struct timeval *start_time) { - gettimeofday(result,NULL); - result->tv_sec -= start_time->tv_sec; - result->tv_usec -= start_time->tv_usec; - while (result->tv_usec < 0) - { - result->tv_usec += 1000000L; - result->tv_sec--; - } - return result; + gettimeofday(result, NULL); + result->tv_sec -= start_time->tv_sec; + result->tv_usec -= start_time->tv_usec; + while (result->tv_usec < 0) { + result->tv_usec += 1000000L; + result->tv_sec--; + } + return result; } -static int -restart_kill(struct thread *t_kill) +static int restart_kill(struct thread *t_kill) { - struct restart_info *restart = THREAD_ARG(t_kill); - struct timeval delay; + struct restart_info *restart = THREAD_ARG(t_kill); + struct timeval delay; - time_elapsed(&delay,&restart->time); - zlog_warn("Warning: %s %s child process %d still running after " - "%ld seconds, sending signal %d", - restart->what,restart->name,(int)restart->pid, (long)delay.tv_sec, - (restart->kills ? SIGKILL : SIGTERM)); - kill(-restart->pid,(restart->kills ? SIGKILL : SIGTERM)); - restart->kills++; - restart->t_kill = thread_add_timer(master,restart_kill,restart, - gs.restart_timeout); - return 0; + time_elapsed(&delay, &restart->time); + zlog_warn("Warning: %s %s child process %d still running after " + "%ld seconds, sending signal %d", + restart->what, restart->name, (int)restart->pid, + (long)delay.tv_sec, (restart->kills ? SIGKILL : SIGTERM)); + kill(-restart->pid, (restart->kills ? SIGKILL : SIGTERM)); + restart->kills++; + restart->t_kill = thread_add_timer(master, restart_kill, restart, + gs.restart_timeout); + return 0; } -static struct restart_info * -find_child(pid_t child) +static struct restart_info *find_child(pid_t child) { - if (gs.mode == MODE_GLOBAL_RESTART) - { - if (gs.restart.pid == child) - return &gs.restart; - } - else - { - struct daemon *dmn; - for (dmn = gs.daemons; dmn; dmn = dmn->next) - { - if (dmn->restart.pid == child) - return &dmn->restart; - } - } - return NULL; + if (gs.mode == MODE_GLOBAL_RESTART) { + if (gs.restart.pid == child) + return &gs.restart; + } else { + struct daemon *dmn; + for (dmn = gs.daemons; dmn; dmn = dmn->next) { + if (dmn->restart.pid == child) + return &dmn->restart; + } + } + return NULL; } -static void -sigchild(void) +static void sigchild(void) { - pid_t child; - int status; - const char *name; - const char *what; - struct restart_info *restart; + pid_t child; + int status; + const char *name; + const char *what; + struct restart_info *restart; - switch (child = waitpid(-1,&status,WNOHANG)) - { - case -1: - zlog_err("waitpid failed: %s",safe_strerror(errno)); - return; - case 0: - zlog_warn("SIGCHLD received, but waitpid did not reap a child"); - return; - } + switch (child = waitpid(-1, &status, WNOHANG)) { + case -1: + zlog_err("waitpid failed: %s", safe_strerror(errno)); + return; + case 0: + zlog_warn("SIGCHLD received, but waitpid did not reap a child"); + return; + } - if (child == integrated_write_pid) - { - integrated_write_sigchld(status); - return; - } + if (child == integrated_write_pid) { + integrated_write_sigchld(status); + return; + } - if ((restart = find_child(child)) != NULL) - { - name = restart->name; - what = restart->what; - restart->pid = 0; - gs.numpids--; - thread_cancel(restart->t_kill); - restart->t_kill = NULL; - /* Update restart time to reflect the time the command completed. */ - gettimeofday(&restart->time,NULL); - } - else - { - zlog_err("waitpid returned status for an unknown child process %d", - (int)child); - name = "(unknown)"; - what = "background"; - } - if (WIFSTOPPED(status)) - zlog_warn("warning: %s %s process %d is stopped", - what,name,(int)child); - else if (WIFSIGNALED(status)) - zlog_warn("%s %s process %d terminated due to signal %d", - what,name,(int)child,WTERMSIG(status)); - else if (WIFEXITED(status)) - { - if (WEXITSTATUS(status) != 0) - zlog_warn("%s %s process %d exited with non-zero status %d", - what,name,(int)child,WEXITSTATUS(status)); - else - zlog_debug("%s %s process %d exited normally",what,name,(int)child); - } - else - zlog_err("cannot interpret %s %s process %d wait status 0x%x", - what,name,(int)child,status); - phase_check(); + if ((restart = find_child(child)) != NULL) { + name = restart->name; + what = restart->what; + restart->pid = 0; + gs.numpids--; + thread_cancel(restart->t_kill); + restart->t_kill = NULL; + /* Update restart time to reflect the time the command completed. */ + gettimeofday(&restart->time, NULL); + } else { + zlog_err + ("waitpid returned status for an unknown child process %d", + (int)child); + name = "(unknown)"; + what = "background"; + } + if (WIFSTOPPED(status)) + zlog_warn("warning: %s %s process %d is stopped", + what, name, (int)child); + else if (WIFSIGNALED(status)) + zlog_warn("%s %s process %d terminated due to signal %d", + what, name, (int)child, WTERMSIG(status)); + else if (WIFEXITED(status)) { + if (WEXITSTATUS(status) != 0) + zlog_warn + ("%s %s process %d exited with non-zero status %d", + what, name, (int)child, WEXITSTATUS(status)); + else + zlog_debug("%s %s process %d exited normally", what, + name, (int)child); + } else + zlog_err("cannot interpret %s %s process %d wait status 0x%x", + what, name, (int)child, status); + phase_check(); } static int run_job(struct restart_info *restart, const char *cmdtype, const char *command, int force, int update_interval) { - struct timeval delay; + struct timeval delay; - if (gs.loglevel > LOG_DEBUG+1) - zlog_debug("attempting to %s %s",cmdtype,restart->name); + if (gs.loglevel > LOG_DEBUG + 1) + zlog_debug("attempting to %s %s", cmdtype, restart->name); - if (restart->pid) - { - if (gs.loglevel > LOG_DEBUG+1) - zlog_debug("cannot %s %s, previous pid %d still running", - cmdtype,restart->name,(int)restart->pid); - return -1; - } + if (restart->pid) { + if (gs.loglevel > LOG_DEBUG + 1) + zlog_debug + ("cannot %s %s, previous pid %d still running", + cmdtype, restart->name, (int)restart->pid); + return -1; + } - /* Note: time_elapsed test must come before the force test, since we need - to make sure that delay is initialized for use below in updating the - restart interval. */ - if ((time_elapsed(&delay,&restart->time)->tv_sec < restart->interval) && - !force) - { - if (gs.loglevel > LOG_DEBUG+1) - zlog_debug("postponing %s %s: " - "elapsed time %ld < retry interval %ld", - cmdtype,restart->name,(long)delay.tv_sec,restart->interval); - return -1; - } + /* Note: time_elapsed test must come before the force test, since we need + to make sure that delay is initialized for use below in updating the + restart interval. */ + if ((time_elapsed(&delay, &restart->time)->tv_sec < restart->interval) + && !force) { + if (gs.loglevel > LOG_DEBUG + 1) + zlog_debug("postponing %s %s: " + "elapsed time %ld < retry interval %ld", + cmdtype, restart->name, (long)delay.tv_sec, + restart->interval); + return -1; + } - gettimeofday(&restart->time,NULL); - restart->kills = 0; - { - char cmd[strlen(command)+strlen(restart->name)+1]; - snprintf(cmd,sizeof(cmd),command,restart->name); - if ((restart->pid = run_background(cmd)) > 0) - { - restart->t_kill = thread_add_timer(master,restart_kill,restart, - gs.restart_timeout); - restart->what = cmdtype; - gs.numpids++; - } - else - restart->pid = 0; - } + gettimeofday(&restart->time, NULL); + restart->kills = 0; + { + char cmd[strlen(command) + strlen(restart->name) + 1]; + snprintf(cmd, sizeof(cmd), command, restart->name); + if ((restart->pid = run_background(cmd)) > 0) { + restart->t_kill = + thread_add_timer(master, restart_kill, restart, + gs.restart_timeout); + restart->what = cmdtype; + gs.numpids++; + } else + restart->pid = 0; + } - /* Calculate the new restart interval. */ - if (update_interval) - { - if (delay.tv_sec > 2*gs.max_restart_interval) - restart->interval = gs.min_restart_interval; - else if ((restart->interval *= 2) > gs.max_restart_interval) - restart->interval = gs.max_restart_interval; - if (gs.loglevel > LOG_DEBUG+1) - zlog_debug("restart %s interval is now %ld", - restart->name,restart->interval); - } - return restart->pid; + /* Calculate the new restart interval. */ + if (update_interval) { + if (delay.tv_sec > 2 * gs.max_restart_interval) + restart->interval = gs.min_restart_interval; + else if ((restart->interval *= 2) > gs.max_restart_interval) + restart->interval = gs.max_restart_interval; + if (gs.loglevel > LOG_DEBUG + 1) + zlog_debug("restart %s interval is now %ld", + restart->name, restart->interval); + } + return restart->pid; } #define SET_READ_HANDLER(DMN) \ @@ -551,889 +516,874 @@ run_job(struct restart_info *restart, const char *cmdtype, const char *command, #define SET_WAKEUP_DOWN(DMN) \ (DMN)->t_wakeup = thread_add_timer_msec(master,wakeup_down,(DMN), \ - FUZZY(gs.period)) + FUZZY(gs.period)) #define SET_WAKEUP_UNRESPONSIVE(DMN) \ (DMN)->t_wakeup = thread_add_timer_msec(master,wakeup_unresponsive,(DMN), \ - FUZZY(gs.period)) + FUZZY(gs.period)) #define SET_WAKEUP_ECHO(DMN) \ (DMN)->t_wakeup = thread_add_timer_msec(master,wakeup_send_echo,(DMN), \ FUZZY(gs.period)) -static int -wakeup_down(struct thread *t_wakeup) +static int wakeup_down(struct thread *t_wakeup) { - struct daemon *dmn = THREAD_ARG(t_wakeup); + struct daemon *dmn = THREAD_ARG(t_wakeup); - dmn->t_wakeup = NULL; - if (try_connect(dmn) < 0) - SET_WAKEUP_DOWN(dmn); - if ((dmn->connect_tries > 1) && (dmn->state != DAEMON_UP)) - try_restart(dmn); - return 0; + dmn->t_wakeup = NULL; + if (try_connect(dmn) < 0) + SET_WAKEUP_DOWN(dmn); + if ((dmn->connect_tries > 1) && (dmn->state != DAEMON_UP)) + try_restart(dmn); + return 0; } -static int -wakeup_init(struct thread *t_wakeup) +static int wakeup_init(struct thread *t_wakeup) { - struct daemon *dmn = THREAD_ARG(t_wakeup); + struct daemon *dmn = THREAD_ARG(t_wakeup); - dmn->t_wakeup = NULL; - if (try_connect(dmn) < 0) - { - SET_WAKEUP_DOWN(dmn); - zlog_err("%s state -> down : initial connection attempt failed", - dmn->name); - dmn->state = DAEMON_DOWN; - } - return 0; -} - -static void -daemon_down(struct daemon *dmn, const char *why) -{ - if (IS_UP(dmn) || (dmn->state == DAEMON_INIT)) - zlog_err("%s state -> down : %s",dmn->name,why); - else if (gs.loglevel > LOG_DEBUG) - zlog_debug("%s still down : %s",dmn->name,why); - if (IS_UP(dmn)) - gs.numdown++; - dmn->state = DAEMON_DOWN; - if (dmn->fd >= 0) - { - close(dmn->fd); - dmn->fd = -1; - } - THREAD_OFF(dmn->t_read); - THREAD_OFF(dmn->t_write); - THREAD_OFF(dmn->t_wakeup); - if (try_connect(dmn) < 0) - SET_WAKEUP_DOWN(dmn); - phase_check(); -} - -static int -handle_read(struct thread *t_read) -{ - struct daemon *dmn = THREAD_ARG(t_read); - static const char resp[sizeof(PING_TOKEN)+4] = PING_TOKEN "\n"; - char buf[sizeof(resp)+100]; - ssize_t rc; - struct timeval delay; - - dmn->t_read = NULL; - if ((rc = read(dmn->fd,buf,sizeof(buf))) < 0) - { - char why[100]; - - if (ERRNO_IO_RETRY(errno)) - { - /* Pretend it never happened. */ - SET_READ_HANDLER(dmn); - return 0; + dmn->t_wakeup = NULL; + if (try_connect(dmn) < 0) { + SET_WAKEUP_DOWN(dmn); + zlog_err("%s state -> down : initial connection attempt failed", + dmn->name); + dmn->state = DAEMON_DOWN; } - snprintf(why,sizeof(why),"unexpected read error: %s", - safe_strerror(errno)); - daemon_down(dmn,why); - return 0; - } - if (rc == 0) - { - daemon_down(dmn,"read returned EOF"); - return 0; - } - if (!dmn->echo_sent.tv_sec) - { - char why[sizeof(buf)+100]; - snprintf(why,sizeof(why),"unexpected read returns %d bytes: %.*s", - (int)rc,(int)rc,buf); - daemon_down(dmn,why); - return 0; - } + return 0; +} - /* We are expecting an echo response: is there any chance that the - response would not be returned entirely in the first read? That - seems inconceivable... */ - if ((rc != sizeof(resp)) || memcmp(buf,resp,sizeof(resp))) - { - char why[100+sizeof(buf)]; - snprintf(why,sizeof(why),"read returned bad echo response of %d bytes " - "(expecting %u): %.*s", - (int)rc,(u_int)sizeof(resp),(int)rc,buf); - daemon_down(dmn,why); - return 0; - } - - time_elapsed(&delay,&dmn->echo_sent); - dmn->echo_sent.tv_sec = 0; - if (dmn->state == DAEMON_UNRESPONSIVE) - { - if (delay.tv_sec < gs.timeout) - { - dmn->state = DAEMON_UP; - zlog_warn("%s state -> up : echo response received after %ld.%06ld " - "seconds", dmn->name, - (long)delay.tv_sec, (long)delay.tv_usec); +static void daemon_down(struct daemon *dmn, const char *why) +{ + if (IS_UP(dmn) || (dmn->state == DAEMON_INIT)) + zlog_err("%s state -> down : %s", dmn->name, why); + else if (gs.loglevel > LOG_DEBUG) + zlog_debug("%s still down : %s", dmn->name, why); + if (IS_UP(dmn)) + gs.numdown++; + dmn->state = DAEMON_DOWN; + if (dmn->fd >= 0) { + close(dmn->fd); + dmn->fd = -1; } - else - zlog_warn("%s: slow echo response finally received after %ld.%06ld " - "seconds", dmn->name, - (long)delay.tv_sec, (long)delay.tv_usec); - } - else if (gs.loglevel > LOG_DEBUG+1) - zlog_debug("%s: echo response received after %ld.%06ld seconds", - dmn->name, (long)delay.tv_sec, (long)delay.tv_usec); + THREAD_OFF(dmn->t_read); + THREAD_OFF(dmn->t_write); + THREAD_OFF(dmn->t_wakeup); + if (try_connect(dmn) < 0) + SET_WAKEUP_DOWN(dmn); + phase_check(); +} - SET_READ_HANDLER(dmn); - if (dmn->t_wakeup) - thread_cancel(dmn->t_wakeup); - SET_WAKEUP_ECHO(dmn); +static int handle_read(struct thread *t_read) +{ + struct daemon *dmn = THREAD_ARG(t_read); + static const char resp[sizeof(PING_TOKEN) + 4] = PING_TOKEN "\n"; + char buf[sizeof(resp) + 100]; + ssize_t rc; + struct timeval delay; - return 0; + dmn->t_read = NULL; + if ((rc = read(dmn->fd, buf, sizeof(buf))) < 0) { + char why[100]; + + if (ERRNO_IO_RETRY(errno)) { + /* Pretend it never happened. */ + SET_READ_HANDLER(dmn); + return 0; + } + snprintf(why, sizeof(why), "unexpected read error: %s", + safe_strerror(errno)); + daemon_down(dmn, why); + return 0; + } + if (rc == 0) { + daemon_down(dmn, "read returned EOF"); + return 0; + } + if (!dmn->echo_sent.tv_sec) { + char why[sizeof(buf) + 100]; + snprintf(why, sizeof(why), + "unexpected read returns %d bytes: %.*s", (int)rc, + (int)rc, buf); + daemon_down(dmn, why); + return 0; + } + + /* We are expecting an echo response: is there any chance that the + response would not be returned entirely in the first read? That + seems inconceivable... */ + if ((rc != sizeof(resp)) || memcmp(buf, resp, sizeof(resp))) { + char why[100 + sizeof(buf)]; + snprintf(why, sizeof(why), + "read returned bad echo response of %d bytes " + "(expecting %u): %.*s", (int)rc, (u_int) sizeof(resp), + (int)rc, buf); + daemon_down(dmn, why); + return 0; + } + + time_elapsed(&delay, &dmn->echo_sent); + dmn->echo_sent.tv_sec = 0; + if (dmn->state == DAEMON_UNRESPONSIVE) { + if (delay.tv_sec < gs.timeout) { + dmn->state = DAEMON_UP; + zlog_warn + ("%s state -> up : echo response received after %ld.%06ld " + "seconds", dmn->name, (long)delay.tv_sec, + (long)delay.tv_usec); + } else + zlog_warn + ("%s: slow echo response finally received after %ld.%06ld " + "seconds", dmn->name, (long)delay.tv_sec, + (long)delay.tv_usec); + } else if (gs.loglevel > LOG_DEBUG + 1) + zlog_debug("%s: echo response received after %ld.%06ld seconds", + dmn->name, (long)delay.tv_sec, (long)delay.tv_usec); + + SET_READ_HANDLER(dmn); + if (dmn->t_wakeup) + thread_cancel(dmn->t_wakeup); + SET_WAKEUP_ECHO(dmn); + + return 0; } /* * Wait till we notice that all daemons are ready before * we send we are ready to systemd */ -static void -daemon_send_ready (void) +static void daemon_send_ready(void) { - static int sent = 0; - if (!sent && gs.numdown == 0) - { + static int sent = 0; + if (!sent && gs.numdown == 0) { #if defined (HAVE_CUMULUS) - FILE *fp; + FILE *fp; - fp = fopen(DAEMON_VTY_DIR "/watchfrr.started", "w"); - fclose(fp); + fp = fopen(DAEMON_VTY_DIR "/watchfrr.started", "w"); + fclose(fp); #endif - zlog_notice ("Watchfrr: Notifying Systemd we are up and running"); - systemd_send_started(master, 0); - sent = 1; - } + zlog_notice + ("Watchfrr: Notifying Systemd we are up and running"); + systemd_send_started(master, 0); + sent = 1; + } } -static void -daemon_up(struct daemon *dmn, const char *why) +static void daemon_up(struct daemon *dmn, const char *why) { - dmn->state = DAEMON_UP; - gs.numdown--; - dmn->connect_tries = 0; - zlog_notice("%s state -> up : %s",dmn->name,why); - daemon_send_ready(); - if (gs.do_ping) - SET_WAKEUP_ECHO(dmn); - phase_check(); + dmn->state = DAEMON_UP; + gs.numdown--; + dmn->connect_tries = 0; + zlog_notice("%s state -> up : %s", dmn->name, why); + daemon_send_ready(); + if (gs.do_ping) + SET_WAKEUP_ECHO(dmn); + phase_check(); } -static int -check_connect(struct thread *t_write) +static int check_connect(struct thread *t_write) { - struct daemon *dmn = THREAD_ARG(t_write); - int sockerr; - socklen_t reslen = sizeof(sockerr); + struct daemon *dmn = THREAD_ARG(t_write); + int sockerr; + socklen_t reslen = sizeof(sockerr); - dmn->t_write = NULL; - if (getsockopt(dmn->fd,SOL_SOCKET,SO_ERROR,(char *)&sockerr,&reslen) < 0) - { - zlog_warn("%s: check_connect: getsockopt failed: %s", - dmn->name,safe_strerror(errno)); - daemon_down(dmn,"getsockopt failed checking connection success"); - return 0; - } - if ((reslen == sizeof(sockerr)) && sockerr) - { - char why[100]; - snprintf(why,sizeof(why), - "getsockopt reports that connection attempt failed: %s", - safe_strerror(sockerr)); - daemon_down(dmn,why); - return 0; - } + dmn->t_write = NULL; + if (getsockopt(dmn->fd, SOL_SOCKET, SO_ERROR, (char *)&sockerr, &reslen) + < 0) { + zlog_warn("%s: check_connect: getsockopt failed: %s", dmn->name, + safe_strerror(errno)); + daemon_down(dmn, + "getsockopt failed checking connection success"); + return 0; + } + if ((reslen == sizeof(sockerr)) && sockerr) { + char why[100]; + snprintf(why, sizeof(why), + "getsockopt reports that connection attempt failed: %s", + safe_strerror(sockerr)); + daemon_down(dmn, why); + return 0; + } - daemon_up(dmn,"delayed connect succeeded"); - return 0; + daemon_up(dmn, "delayed connect succeeded"); + return 0; } -static int -wakeup_connect_hanging(struct thread *t_wakeup) +static int wakeup_connect_hanging(struct thread *t_wakeup) { - struct daemon *dmn = THREAD_ARG(t_wakeup); - char why[100]; + struct daemon *dmn = THREAD_ARG(t_wakeup); + char why[100]; - dmn->t_wakeup = NULL; - snprintf(why,sizeof(why),"connection attempt timed out after %ld seconds", - gs.timeout); - daemon_down(dmn,why); - return 0; + dmn->t_wakeup = NULL; + snprintf(why, sizeof(why), + "connection attempt timed out after %ld seconds", gs.timeout); + daemon_down(dmn, why); + return 0; } /* Making connection to protocol daemon. */ -static int -try_connect(struct daemon *dmn) +static int try_connect(struct daemon *dmn) { - int sock; - struct sockaddr_un addr; - socklen_t len; + int sock; + struct sockaddr_un addr; + socklen_t len; - if (gs.loglevel > LOG_DEBUG+1) - zlog_debug("%s: attempting to connect",dmn->name); - dmn->connect_tries++; + if (gs.loglevel > LOG_DEBUG + 1) + zlog_debug("%s: attempting to connect", dmn->name); + dmn->connect_tries++; - memset (&addr, 0, sizeof (struct sockaddr_un)); - addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s.vty", - gs.vtydir,dmn->name); + memset(&addr, 0, sizeof(struct sockaddr_un)); + addr.sun_family = AF_UNIX; + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s.vty", + gs.vtydir, dmn->name); #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN - len = addr.sun_len = SUN_LEN(&addr); + len = addr.sun_len = SUN_LEN(&addr); #else - len = sizeof (addr.sun_family) + strlen (addr.sun_path); -#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */ + len = sizeof(addr.sun_family) + strlen(addr.sun_path); +#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */ - /* Quick check to see if we might succeed before we go to the trouble - of creating a socket. */ - if (access(addr.sun_path, W_OK) < 0) - { - if (errno != ENOENT) - zlog_err("%s: access to socket %s denied: %s", - dmn->name,addr.sun_path,safe_strerror(errno)); - return -1; - } - - if ((sock = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) - { - zlog_err("%s(%s): cannot make socket: %s", - __func__,addr.sun_path, safe_strerror(errno)); - return -1; - } - - if (set_nonblocking(sock) < 0 || set_cloexec(sock) < 0) - { - zlog_err("%s(%s): set_nonblocking/cloexec(%d) failed", - __func__, addr.sun_path, sock); - close(sock); - return -1; - } - - if (connect (sock, (struct sockaddr *) &addr, len) < 0) - { - if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK)) - { - if (gs.loglevel > LOG_DEBUG) - zlog_debug("%s(%s): connect failed: %s", - __func__,addr.sun_path, safe_strerror(errno)); - close (sock); - return -1; + /* Quick check to see if we might succeed before we go to the trouble + of creating a socket. */ + if (access(addr.sun_path, W_OK) < 0) { + if (errno != ENOENT) + zlog_err("%s: access to socket %s denied: %s", + dmn->name, addr.sun_path, + safe_strerror(errno)); + return -1; } - if (gs.loglevel > LOG_DEBUG) - zlog_debug("%s: connection in progress",dmn->name); - dmn->state = DAEMON_CONNECTING; - dmn->fd = sock; - dmn->t_write = thread_add_write(master,check_connect,dmn,dmn->fd); - dmn->t_wakeup = thread_add_timer(master,wakeup_connect_hanging,dmn, - gs.timeout); - SET_READ_HANDLER(dmn); - return 0; - } - dmn->fd = sock; - SET_READ_HANDLER(dmn); - daemon_up(dmn,"connect succeeded"); - return 1; -} - -static int -phase_hanging(struct thread *t_hanging) -{ - gs.t_phase_hanging = NULL; - zlog_err("Phase [%s] hanging for %ld seconds, aborting phased restart", - phase_str[gs.phase],PHASE_TIMEOUT); - gs.phase = PHASE_NONE; - return 0; -} - -static void -set_phase(restart_phase_t new_phase) -{ - gs.phase = new_phase; - if (gs.t_phase_hanging) - thread_cancel(gs.t_phase_hanging); - gs.t_phase_hanging = thread_add_timer(master,phase_hanging,NULL, - PHASE_TIMEOUT); -} - -static void -phase_check(void) -{ - switch (gs.phase) - { - case PHASE_NONE: - break; - case PHASE_STOPS_PENDING: - if (gs.numpids) - break; - zlog_info("Phased restart: all routing daemon stop jobs have completed."); - set_phase(PHASE_WAITING_DOWN); - /*FALLTHRU*/ - case PHASE_WAITING_DOWN: - if (gs.numdown+IS_UP(gs.special) < gs.numdaemons) - break; - zlog_info("Phased restart: all routing daemons now down."); - run_job(&gs.special->restart,"restart",gs.restart_command,1,1); - set_phase(PHASE_ZEBRA_RESTART_PENDING); - /*FALLTHRU*/ - case PHASE_ZEBRA_RESTART_PENDING: - if (gs.special->restart.pid) - break; - zlog_info("Phased restart: %s restart job completed.",gs.special->name); - set_phase(PHASE_WAITING_ZEBRA_UP); - /*FALLTHRU*/ - case PHASE_WAITING_ZEBRA_UP: - if (!IS_UP(gs.special)) - break; - zlog_info("Phased restart: %s is now up.",gs.special->name); - { - struct daemon *dmn; - for (dmn = gs.daemons; dmn; dmn = dmn->next) - { - if (dmn != gs.special) - run_job(&dmn->restart,"start",gs.start_command,1,0); - } - } - gs.phase = PHASE_NONE; - THREAD_OFF(gs.t_phase_hanging); - zlog_notice("Phased global restart has completed."); - break; - } -} - -static void -try_restart(struct daemon *dmn) -{ - switch (gs.mode) - { - case MODE_MONITOR: - return; - case MODE_GLOBAL_RESTART: - run_job(&gs.restart,"restart",gs.restart_command,0,1); - break; - case MODE_SEPARATE_RESTART: - run_job(&dmn->restart,"restart",gs.restart_command,0,1); - break; - case MODE_PHASED_ZEBRA_RESTART: - if (dmn != gs.special) - { - if ((gs.special->state == DAEMON_UP) && (gs.phase == PHASE_NONE)) - run_job(&dmn->restart,"restart",gs.restart_command,0,1); - else - zlog_debug("%s: postponing restart attempt because master %s daemon " - "not up [%s], or phased restart in progress", - dmn->name,gs.special->name,state_str[gs.special->state]); - break; - } - /*FALLTHRU*/ - case MODE_PHASED_ALL_RESTART: - if ((gs.phase != PHASE_NONE) || gs.numpids) - { - if (gs.loglevel > LOG_DEBUG+1) - zlog_debug("postponing phased global restart: restart already in " - "progress [%s], or outstanding child processes [%d]", - phase_str[gs.phase],gs.numpids); - break; - } - /* Is it too soon for a restart? */ - { - struct timeval delay; - if (time_elapsed(&delay,&gs.special->restart.time)->tv_sec < - gs.special->restart.interval) - { - if (gs.loglevel > LOG_DEBUG+1) - zlog_debug("postponing phased global restart: " - "elapsed time %ld < retry interval %ld", - (long)delay.tv_sec,gs.special->restart.interval); - break; + if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + zlog_err("%s(%s): cannot make socket: %s", + __func__, addr.sun_path, safe_strerror(errno)); + return -1; } - } - run_job(&gs.restart,"restart",gs.restart_command,0,1); - break; - default: - zlog_err("error: unknown restart mode %d",gs.mode); - break; - } + + if (set_nonblocking(sock) < 0 || set_cloexec(sock) < 0) { + zlog_err("%s(%s): set_nonblocking/cloexec(%d) failed", + __func__, addr.sun_path, sock); + close(sock); + return -1; + } + + if (connect(sock, (struct sockaddr *)&addr, len) < 0) { + if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK)) { + if (gs.loglevel > LOG_DEBUG) + zlog_debug("%s(%s): connect failed: %s", + __func__, addr.sun_path, + safe_strerror(errno)); + close(sock); + return -1; + } + if (gs.loglevel > LOG_DEBUG) + zlog_debug("%s: connection in progress", dmn->name); + dmn->state = DAEMON_CONNECTING; + dmn->fd = sock; + dmn->t_write = + thread_add_write(master, check_connect, dmn, dmn->fd); + dmn->t_wakeup = + thread_add_timer(master, wakeup_connect_hanging, dmn, + gs.timeout); + SET_READ_HANDLER(dmn); + return 0; + } + + dmn->fd = sock; + SET_READ_HANDLER(dmn); + daemon_up(dmn, "connect succeeded"); + return 1; } -static int -wakeup_unresponsive(struct thread *t_wakeup) +static int phase_hanging(struct thread *t_hanging) { - struct daemon *dmn = THREAD_ARG(t_wakeup); - - dmn->t_wakeup = NULL; - if (dmn->state != DAEMON_UNRESPONSIVE) - zlog_err("%s: no longer unresponsive (now %s), " - "wakeup should have been cancelled!", - dmn->name,state_str[dmn->state]); - else - { - SET_WAKEUP_UNRESPONSIVE(dmn); - try_restart(dmn); - } - return 0; + gs.t_phase_hanging = NULL; + zlog_err("Phase [%s] hanging for %ld seconds, aborting phased restart", + phase_str[gs.phase], PHASE_TIMEOUT); + gs.phase = PHASE_NONE; + return 0; } -static int -wakeup_no_answer(struct thread *t_wakeup) +static void set_phase(restart_phase_t new_phase) { - struct daemon *dmn = THREAD_ARG(t_wakeup); - - dmn->t_wakeup = NULL; - dmn->state = DAEMON_UNRESPONSIVE; - zlog_err("%s state -> unresponsive : no response yet to ping " - "sent %ld seconds ago",dmn->name,gs.timeout); - if (gs.unresponsive_restart) - { - SET_WAKEUP_UNRESPONSIVE(dmn); - try_restart(dmn); - } - return 0; + gs.phase = new_phase; + if (gs.t_phase_hanging) + thread_cancel(gs.t_phase_hanging); + gs.t_phase_hanging = thread_add_timer(master, phase_hanging, NULL, + PHASE_TIMEOUT); } -static int -wakeup_send_echo(struct thread *t_wakeup) +static void phase_check(void) { - static const char echocmd[] = "echo " PING_TOKEN; - ssize_t rc; - struct daemon *dmn = THREAD_ARG(t_wakeup); + switch (gs.phase) { + case PHASE_NONE: + break; + case PHASE_STOPS_PENDING: + if (gs.numpids) + break; + zlog_info + ("Phased restart: all routing daemon stop jobs have completed."); + set_phase(PHASE_WAITING_DOWN); - dmn->t_wakeup = NULL; - if (((rc = write(dmn->fd,echocmd,sizeof(echocmd))) < 0) || - ((size_t)rc != sizeof(echocmd))) - { - char why[100+sizeof(echocmd)]; - snprintf(why,sizeof(why),"write '%s' returned %d instead of %u", - echocmd,(int)rc,(u_int)sizeof(echocmd)); - daemon_down(dmn,why); - } - else - { - gettimeofday(&dmn->echo_sent,NULL); - dmn->t_wakeup = thread_add_timer(master,wakeup_no_answer,dmn,gs.timeout); - } - return 0; + /*FALLTHRU*/ + case PHASE_WAITING_DOWN: + if (gs.numdown + IS_UP(gs.special) < gs.numdaemons) + break; + zlog_info("Phased restart: all routing daemons now down."); + run_job(&gs.special->restart, "restart", gs.restart_command, 1, + 1); + set_phase(PHASE_ZEBRA_RESTART_PENDING); + + /*FALLTHRU*/ + case PHASE_ZEBRA_RESTART_PENDING: + if (gs.special->restart.pid) + break; + zlog_info("Phased restart: %s restart job completed.", + gs.special->name); + set_phase(PHASE_WAITING_ZEBRA_UP); + + /*FALLTHRU*/ + case PHASE_WAITING_ZEBRA_UP: + if (!IS_UP(gs.special)) + break; + zlog_info("Phased restart: %s is now up.", gs.special->name); + { + struct daemon *dmn; + for (dmn = gs.daemons; dmn; dmn = dmn->next) { + if (dmn != gs.special) + run_job(&dmn->restart, "start", + gs.start_command, 1, 0); + } + } + gs.phase = PHASE_NONE; + THREAD_OFF(gs.t_phase_hanging); + zlog_notice("Phased global restart has completed."); + break; + } } -static void -sigint(void) +static void try_restart(struct daemon *dmn) { - zlog_notice("Terminating on signal"); - systemd_send_stopping (); - exit(0); + switch (gs.mode) { + case MODE_MONITOR: + return; + case MODE_GLOBAL_RESTART: + run_job(&gs.restart, "restart", gs.restart_command, 0, 1); + break; + case MODE_SEPARATE_RESTART: + run_job(&dmn->restart, "restart", gs.restart_command, 0, 1); + break; + case MODE_PHASED_ZEBRA_RESTART: + if (dmn != gs.special) { + if ((gs.special->state == DAEMON_UP) + && (gs.phase == PHASE_NONE)) + run_job(&dmn->restart, "restart", + gs.restart_command, 0, 1); + else + zlog_debug + ("%s: postponing restart attempt because master %s daemon " + "not up [%s], or phased restart in progress", + dmn->name, gs.special->name, + state_str[gs.special->state]); + break; + } + + /*FALLTHRU*/ + case MODE_PHASED_ALL_RESTART: + if ((gs.phase != PHASE_NONE) || gs.numpids) { + if (gs.loglevel > LOG_DEBUG + 1) + zlog_debug + ("postponing phased global restart: restart already in " + "progress [%s], or outstanding child processes [%d]", + phase_str[gs.phase], gs.numpids); + break; + } + /* Is it too soon for a restart? */ + { + struct timeval delay; + if (time_elapsed(&delay, &gs.special->restart.time)-> + tv_sec < gs.special->restart.interval) { + if (gs.loglevel > LOG_DEBUG + 1) + zlog_debug + ("postponing phased global restart: " + "elapsed time %ld < retry interval %ld", + (long)delay.tv_sec, + gs.special->restart.interval); + break; + } + } + run_job(&gs.restart, "restart", gs.restart_command, 0, 1); + break; + default: + zlog_err("error: unknown restart mode %d", gs.mode); + break; + } } -static int -valid_command(const char *cmd) +static int wakeup_unresponsive(struct thread *t_wakeup) { - char *p; + struct daemon *dmn = THREAD_ARG(t_wakeup); - return ((p = strchr(cmd,'%')) != NULL) && (*(p+1) == 's') && !strchr(p+1,'%'); + dmn->t_wakeup = NULL; + if (dmn->state != DAEMON_UNRESPONSIVE) + zlog_err("%s: no longer unresponsive (now %s), " + "wakeup should have been cancelled!", + dmn->name, state_str[dmn->state]); + else { + SET_WAKEUP_UNRESPONSIVE(dmn); + try_restart(dmn); + } + return 0; +} + +static int wakeup_no_answer(struct thread *t_wakeup) +{ + struct daemon *dmn = THREAD_ARG(t_wakeup); + + dmn->t_wakeup = NULL; + dmn->state = DAEMON_UNRESPONSIVE; + zlog_err("%s state -> unresponsive : no response yet to ping " + "sent %ld seconds ago", dmn->name, gs.timeout); + if (gs.unresponsive_restart) { + SET_WAKEUP_UNRESPONSIVE(dmn); + try_restart(dmn); + } + return 0; +} + +static int wakeup_send_echo(struct thread *t_wakeup) +{ + static const char echocmd[] = "echo " PING_TOKEN; + ssize_t rc; + struct daemon *dmn = THREAD_ARG(t_wakeup); + + dmn->t_wakeup = NULL; + if (((rc = write(dmn->fd, echocmd, sizeof(echocmd))) < 0) || + ((size_t) rc != sizeof(echocmd))) { + char why[100 + sizeof(echocmd)]; + snprintf(why, sizeof(why), + "write '%s' returned %d instead of %u", echocmd, + (int)rc, (u_int) sizeof(echocmd)); + daemon_down(dmn, why); + } else { + gettimeofday(&dmn->echo_sent, NULL); + dmn->t_wakeup = + thread_add_timer(master, wakeup_no_answer, dmn, gs.timeout); + } + return 0; +} + +static void sigint(void) +{ + zlog_notice("Terminating on signal"); + systemd_send_stopping(); + exit(0); +} + +static int valid_command(const char *cmd) +{ + char *p; + + return ((p = strchr(cmd, '%')) != NULL) && (*(p + 1) == 's') + && !strchr(p + 1, '%'); } /* This is an ugly hack to circumvent problems with passing command-line arguments that contain spaces. The fix is to use a configuration file. */ -static char * -translate_blanks(const char *cmd, const char *blankstr) +static char *translate_blanks(const char *cmd, const char *blankstr) { - char *res; - char *p; - size_t bslen = strlen(blankstr); + char *res; + char *p; + size_t bslen = strlen(blankstr); - if (!(res = strdup(cmd))) - { - perror("strdup"); - exit(1); - } - while ((p = strstr(res,blankstr)) != NULL) - { - *p = ' '; - if (bslen != 1) - memmove(p+1,p+bslen,strlen(p+bslen)+1); - } - return res; + if (!(res = strdup(cmd))) { + perror("strdup"); + exit(1); + } + while ((p = strstr(res, blankstr)) != NULL) { + *p = ' '; + if (bslen != 1) + memmove(p + 1, p + bslen, strlen(p + bslen) + 1); + } + return res; } -struct zebra_privs_t watchfrr_privs = -{ +struct zebra_privs_t watchfrr_privs = { #ifdef VTY_GROUP - .vty_group = VTY_GROUP, + .vty_group = VTY_GROUP, #endif }; -int -main(int argc, char **argv) +int main(int argc, char **argv) { - const char *progname; - int opt; - int daemon_mode = 0; - const char *pidfile = DEFAULT_PIDFILE; - const char *special = "zebra"; - const char *blankstr = NULL; - static struct quagga_signal_t my_signals[] = - { - { - .signal = SIGINT, - .handler = sigint, - }, - { - .signal = SIGTERM, - .handler = sigint, - }, - { - .signal = SIGCHLD, - .handler = sigchild, - }, - }; + const char *progname; + int opt; + int daemon_mode = 0; + const char *pidfile = DEFAULT_PIDFILE; + const char *special = "zebra"; + const char *blankstr = NULL; + static struct quagga_signal_t my_signals[] = { + { + .signal = SIGINT, + .handler = sigint, + }, + { + .signal = SIGTERM, + .handler = sigint, + }, + { + .signal = SIGCHLD, + .handler = sigchild, + }, + }; - if ((progname = strrchr (argv[0], '/')) != NULL) - progname++; - else - progname = argv[0]; - - gs.restart.name = "all"; - while ((opt = getopt_long(argc, argv, "aAb:dek:l:m:M:i:p:r:R:S:s:t:T:zvh", - longopts, 0)) != EOF) - { - switch (opt) - { - case 0: - break; - case 'a': - if ((gs.mode != MODE_MONITOR) && (gs.mode != MODE_SEPARATE_RESTART)) - { - fputs("Ambiguous operating mode selected.\n",stderr); - return usage(progname,1); - } - gs.mode = MODE_PHASED_ZEBRA_RESTART; - break; - case 'A': - if ((gs.mode != MODE_MONITOR) && (gs.mode != MODE_SEPARATE_RESTART)) - { - fputs("Ambiguous operating mode selected.\n",stderr); - return usage(progname,1); - } - gs.mode = MODE_PHASED_ALL_RESTART; - break; - case 'b': - blankstr = optarg; - break; - case 'd': - daemon_mode = 1; - break; - case 'e': - gs.do_ping = 0; - break; - case 'k': - if (!valid_command(optarg)) - { - fprintf(stderr,"Invalid kill command, must contain '%%s': %s\n", - optarg); - return usage(progname,1); - } - gs.stop_command = optarg; - break; - case 'l': - { - char garbage[3]; - if ((sscanf(optarg,"%d%1s",&gs.loglevel,garbage) != 1) || - (gs.loglevel < LOG_EMERG)) - { - fprintf(stderr,"Invalid loglevel argument: %s\n",optarg); - return usage(progname,1); - } - } - break; - case 'm': - { - char garbage[3]; - if ((sscanf(optarg,"%ld%1s", - &gs.min_restart_interval,garbage) != 1) || - (gs.min_restart_interval < 0)) - { - fprintf(stderr,"Invalid min_restart_interval argument: %s\n", - optarg); - return usage(progname,1); - } - } - break; - case 'M': - { - char garbage[3]; - if ((sscanf(optarg,"%ld%1s", - &gs.max_restart_interval,garbage) != 1) || - (gs.max_restart_interval < 0)) - { - fprintf(stderr,"Invalid max_restart_interval argument: %s\n", - optarg); - return usage(progname,1); - } - } - break; - case 'i': - { - char garbage[3]; - int period; - if ((sscanf(optarg,"%d%1s",&period,garbage) != 1) || - (gs.period < 1)) - { - fprintf(stderr,"Invalid interval argument: %s\n",optarg); - return usage(progname,1); - } - gs.period = 1000*period; - } - break; - case 'p': - pidfile = optarg; - break; - case 'r': - if ((gs.mode == MODE_GLOBAL_RESTART) || - (gs.mode == MODE_SEPARATE_RESTART)) - { - fputs("Ambiguous operating mode selected.\n",stderr); - return usage(progname,1); - } - if (!valid_command(optarg)) - { - fprintf(stderr, - "Invalid restart command, must contain '%%s': %s\n", - optarg); - return usage(progname,1); - } - gs.restart_command = optarg; - if (gs.mode == MODE_MONITOR) - gs.mode = MODE_SEPARATE_RESTART; - break; - case 'R': - if (gs.mode != MODE_MONITOR) - { - fputs("Ambiguous operating mode selected.\n",stderr); - return usage(progname,1); - } - if (strchr(optarg,'%')) - { - fprintf(stderr, - "Invalid restart-all arg, must not contain '%%s': %s\n", - optarg); - return usage(progname,1); - } - gs.restart_command = optarg; - gs.mode = MODE_GLOBAL_RESTART; - break; - case 's': - if (!valid_command(optarg)) - { - fprintf(stderr,"Invalid start command, must contain '%%s': %s\n", - optarg); - return usage(progname,1); - } - gs.start_command = optarg; - break; - case 'S': - gs.vtydir = optarg; - break; - case 't': - { - char garbage[3]; - if ((sscanf(optarg,"%ld%1s",&gs.timeout,garbage) != 1) || - (gs.timeout < 1)) - { - fprintf(stderr,"Invalid timeout argument: %s\n",optarg); - return usage(progname,1); - } - } - break; - case 'T': - { - char garbage[3]; - if ((sscanf(optarg,"%ld%1s",&gs.restart_timeout,garbage) != 1) || - (gs.restart_timeout < 1)) - { - fprintf(stderr,"Invalid restart timeout argument: %s\n",optarg); - return usage(progname,1); - } - } - break; - case 'z': - gs.unresponsive_restart = 1; - break; - case 'v': - printf ("%s version %s\n", progname, FRR_VERSION); - puts("Copyright 2004 Andrew J. Schorr"); - return 0; - case 'h': - return usage(progname,0); - default: - fputs("Invalid option.\n",stderr); - return usage(progname,1); - } - } - - if (gs.unresponsive_restart && (gs.mode == MODE_MONITOR)) - { - fputs("Option -z requires a -r or -R restart option.\n",stderr); - return usage(progname,1); - } - switch (gs.mode) - { - case MODE_MONITOR: - if (gs.restart_command || gs.start_command || gs.stop_command) - { - fprintf(stderr,"No kill/(re)start commands needed for %s mode.\n", - mode_str[gs.mode]); - return usage(progname,1); - } - break; - case MODE_GLOBAL_RESTART: - case MODE_SEPARATE_RESTART: - if (!gs.restart_command || gs.start_command || gs.stop_command) - { - fprintf(stderr,"No start/kill commands needed in [%s] mode.\n", - mode_str[gs.mode]); - return usage(progname,1); - } - break; - case MODE_PHASED_ZEBRA_RESTART: - case MODE_PHASED_ALL_RESTART: - if (!gs.restart_command || !gs.start_command || !gs.stop_command) - { - fprintf(stderr, - "Need start, kill, and restart commands in [%s] mode.\n", - mode_str[gs.mode]); - return usage(progname,1); - } - break; - } - - if (blankstr) - { - if (gs.restart_command) - gs.restart_command = translate_blanks(gs.restart_command,blankstr); - if (gs.start_command) - gs.start_command = translate_blanks(gs.start_command,blankstr); - if (gs.stop_command) - gs.stop_command = translate_blanks(gs.stop_command,blankstr); - } - - gs.restart.interval = gs.min_restart_interval; - - zprivs_init (&watchfrr_privs); - - master = thread_master_create(); - cmd_init(-1); - memory_init(); - vty_init(master); - watchfrr_vty_init(); - vty_serv_sock(NULL, 0, WATCHFRR_VTYSH_PATH); - - signal_init (master, array_size(my_signals), my_signals); - srandom(time(NULL)); - - { - int i; - struct daemon *tail = NULL; - - for (i = optind; i < argc; i++) - { - struct daemon *dmn; - - if (!(dmn = (struct daemon *)calloc(1,sizeof(*dmn)))) - { - fprintf(stderr,"calloc(1,%u) failed: %s\n", - (u_int)sizeof(*dmn), safe_strerror(errno)); - return 1; - } - dmn->name = dmn->restart.name = argv[i]; - dmn->state = DAEMON_INIT; - gs.numdaemons++; - gs.numdown++; - dmn->fd = -1; - dmn->t_wakeup = thread_add_timer_msec(master,wakeup_init,dmn, - 100+(random() % 900)); - dmn->restart.interval = gs.min_restart_interval; - if (tail) - tail->next = dmn; + if ((progname = strrchr(argv[0], '/')) != NULL) + progname++; else - gs.daemons = dmn; - tail = dmn; + progname = argv[0]; + gs.restart.name = "all"; + while ((opt = + getopt_long(argc, argv, "aAb:dek:l:m:M:i:p:r:R:S:s:t:T:zvh", + longopts, 0)) != EOF) { + switch (opt) { + case 0: + break; + case 'a': + if ((gs.mode != MODE_MONITOR) + && (gs.mode != MODE_SEPARATE_RESTART)) { + fputs("Ambiguous operating mode selected.\n", + stderr); + return usage(progname, 1); + } + gs.mode = MODE_PHASED_ZEBRA_RESTART; + break; + case 'A': + if ((gs.mode != MODE_MONITOR) + && (gs.mode != MODE_SEPARATE_RESTART)) { + fputs("Ambiguous operating mode selected.\n", + stderr); + return usage(progname, 1); + } + gs.mode = MODE_PHASED_ALL_RESTART; + break; + case 'b': + blankstr = optarg; + break; + case 'd': + daemon_mode = 1; + break; + case 'e': + gs.do_ping = 0; + break; + case 'k': + if (!valid_command(optarg)) { + fprintf(stderr, + "Invalid kill command, must contain '%%s': %s\n", + optarg); + return usage(progname, 1); + } + gs.stop_command = optarg; + break; + case 'l': + { + char garbage[3]; + if ((sscanf + (optarg, "%d%1s", &gs.loglevel, + garbage) != 1) + || (gs.loglevel < LOG_EMERG)) { + fprintf(stderr, + "Invalid loglevel argument: %s\n", + optarg); + return usage(progname, 1); + } + } + break; + case 'm': + { + char garbage[3]; + if ((sscanf(optarg, "%ld%1s", + &gs.min_restart_interval, + garbage) != 1) + || (gs.min_restart_interval < 0)) { + fprintf(stderr, + "Invalid min_restart_interval argument: %s\n", + optarg); + return usage(progname, 1); + } + } + break; + case 'M': + { + char garbage[3]; + if ((sscanf(optarg, "%ld%1s", + &gs.max_restart_interval, + garbage) != 1) + || (gs.max_restart_interval < 0)) { + fprintf(stderr, + "Invalid max_restart_interval argument: %s\n", + optarg); + return usage(progname, 1); + } + } + break; + case 'i': + { + char garbage[3]; + int period; + if ((sscanf(optarg, "%d%1s", &period, garbage) + != 1) || (gs.period < 1)) { + fprintf(stderr, + "Invalid interval argument: %s\n", + optarg); + return usage(progname, 1); + } + gs.period = 1000 * period; + } + break; + case 'p': + pidfile = optarg; + break; + case 'r': + if ((gs.mode == MODE_GLOBAL_RESTART) || + (gs.mode == MODE_SEPARATE_RESTART)) { + fputs("Ambiguous operating mode selected.\n", + stderr); + return usage(progname, 1); + } + if (!valid_command(optarg)) { + fprintf(stderr, + "Invalid restart command, must contain '%%s': %s\n", + optarg); + return usage(progname, 1); + } + gs.restart_command = optarg; + if (gs.mode == MODE_MONITOR) + gs.mode = MODE_SEPARATE_RESTART; + break; + case 'R': + if (gs.mode != MODE_MONITOR) { + fputs("Ambiguous operating mode selected.\n", + stderr); + return usage(progname, 1); + } + if (strchr(optarg, '%')) { + fprintf(stderr, + "Invalid restart-all arg, must not contain '%%s': %s\n", + optarg); + return usage(progname, 1); + } + gs.restart_command = optarg; + gs.mode = MODE_GLOBAL_RESTART; + break; + case 's': + if (!valid_command(optarg)) { + fprintf(stderr, + "Invalid start command, must contain '%%s': %s\n", + optarg); + return usage(progname, 1); + } + gs.start_command = optarg; + break; + case 'S': + gs.vtydir = optarg; + break; + case 't': + { + char garbage[3]; + if ((sscanf + (optarg, "%ld%1s", &gs.timeout, + garbage) != 1) || (gs.timeout < 1)) { + fprintf(stderr, + "Invalid timeout argument: %s\n", + optarg); + return usage(progname, 1); + } + } + break; + case 'T': + { + char garbage[3]; + if ((sscanf + (optarg, "%ld%1s", &gs.restart_timeout, + garbage) != 1) + || (gs.restart_timeout < 1)) { + fprintf(stderr, + "Invalid restart timeout argument: %s\n", + optarg); + return usage(progname, 1); + } + } + break; + case 'z': + gs.unresponsive_restart = 1; + break; + case 'v': + printf("%s version %s\n", progname, FRR_VERSION); + puts("Copyright 2004 Andrew J. Schorr"); + return 0; + case 'h': + return usage(progname, 0); + default: + fputs("Invalid option.\n", stderr); + return usage(progname, 1); + } + } + + if (gs.unresponsive_restart && (gs.mode == MODE_MONITOR)) { + fputs("Option -z requires a -r or -R restart option.\n", + stderr); + return usage(progname, 1); + } + switch (gs.mode) { + case MODE_MONITOR: + if (gs.restart_command || gs.start_command || gs.stop_command) { + fprintf(stderr, + "No kill/(re)start commands needed for %s mode.\n", + mode_str[gs.mode]); + return usage(progname, 1); + } + break; + case MODE_GLOBAL_RESTART: + case MODE_SEPARATE_RESTART: + if (!gs.restart_command || gs.start_command || gs.stop_command) { + fprintf(stderr, + "No start/kill commands needed in [%s] mode.\n", + mode_str[gs.mode]); + return usage(progname, 1); + } + break; + case MODE_PHASED_ZEBRA_RESTART: + case MODE_PHASED_ALL_RESTART: + if (!gs.restart_command || !gs.start_command + || !gs.stop_command) { + fprintf(stderr, + "Need start, kill, and restart commands in [%s] mode.\n", + mode_str[gs.mode]); + return usage(progname, 1); + } + break; + } + + if (blankstr) { + if (gs.restart_command) + gs.restart_command = + translate_blanks(gs.restart_command, blankstr); + if (gs.start_command) + gs.start_command = + translate_blanks(gs.start_command, blankstr); + if (gs.stop_command) + gs.stop_command = + translate_blanks(gs.stop_command, blankstr); + } + + gs.restart.interval = gs.min_restart_interval; + + zprivs_init(&watchfrr_privs); + + master = thread_master_create(); + cmd_init(-1); + memory_init(); + vty_init(master); + watchfrr_vty_init(); + vty_serv_sock(NULL, 0, WATCHFRR_VTYSH_PATH); + + signal_init(master, array_size(my_signals), my_signals); + srandom(time(NULL)); + + { + int i; + struct daemon *tail = NULL; + + for (i = optind; i < argc; i++) { + struct daemon *dmn; + + if (!(dmn = (struct daemon *)calloc(1, sizeof(*dmn)))) { + fprintf(stderr, "calloc(1,%u) failed: %s\n", + (u_int) sizeof(*dmn), + safe_strerror(errno)); + return 1; + } + dmn->name = dmn->restart.name = argv[i]; + dmn->state = DAEMON_INIT; + gs.numdaemons++; + gs.numdown++; + dmn->fd = -1; + dmn->t_wakeup = + thread_add_timer_msec(master, wakeup_init, dmn, + 100 + (random() % 900)); + dmn->restart.interval = gs.min_restart_interval; + if (tail) + tail->next = dmn; + else + gs.daemons = dmn; + tail = dmn; + + if (((gs.mode == MODE_PHASED_ZEBRA_RESTART) || + (gs.mode == MODE_PHASED_ALL_RESTART)) && + !strcmp(dmn->name, special)) + gs.special = dmn; + } + } + if (!gs.daemons) { + fputs("Must specify one or more daemons to monitor.\n", stderr); + return usage(progname, 1); + } if (((gs.mode == MODE_PHASED_ZEBRA_RESTART) || - (gs.mode == MODE_PHASED_ALL_RESTART)) && - !strcmp(dmn->name,special)) - gs.special = dmn; - } - } - if (!gs.daemons) - { - fputs("Must specify one or more daemons to monitor.\n",stderr); - return usage(progname,1); - } - if (((gs.mode == MODE_PHASED_ZEBRA_RESTART) || - (gs.mode == MODE_PHASED_ALL_RESTART)) && !gs.special) - { - fprintf(stderr,"In mode [%s], but cannot find master daemon %s\n", - mode_str[gs.mode],special); - return usage(progname,1); - } - - zlog_default = openzlog(progname, ZLOG_WATCHFRR, 0, - LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); - zlog_set_level(NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); - if (daemon_mode) - { - zlog_set_level(NULL, ZLOG_DEST_SYSLOG, MIN(gs.loglevel,LOG_DEBUG)); - if (daemon (0, 0) < 0) - { - fprintf(stderr, "Watchfrr daemon failed: %s", strerror(errno)); - exit (1); + (gs.mode == MODE_PHASED_ALL_RESTART)) && !gs.special) { + fprintf(stderr, + "In mode [%s], but cannot find master daemon %s\n", + mode_str[gs.mode], special); + return usage(progname, 1); } - } - else - zlog_set_level(NULL, ZLOG_DEST_STDOUT, MIN(gs.loglevel,LOG_DEBUG)); - /* Make sure we're not already running. */ - pid_output (pidfile); + zlog_default = openzlog(progname, ZLOG_WATCHFRR, 0, + LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); + zlog_set_level(NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); + if (daemon_mode) { + zlog_set_level(NULL, ZLOG_DEST_SYSLOG, + MIN(gs.loglevel, LOG_DEBUG)); + if (daemon(0, 0) < 0) { + fprintf(stderr, "Watchfrr daemon failed: %s", + strerror(errno)); + exit(1); + } + } else + zlog_set_level(NULL, ZLOG_DEST_STDOUT, + MIN(gs.loglevel, LOG_DEBUG)); - /* Announce which daemons are being monitored. */ - { - struct daemon *dmn; - size_t len = 0; + /* Make sure we're not already running. */ + pid_output(pidfile); - for (dmn = gs.daemons; dmn; dmn = dmn->next) - len += strlen(dmn->name)+1; - - { - char buf[len+1]; - char *p = buf; - - for (dmn = gs.daemons; dmn; dmn = dmn->next) + /* Announce which daemons are being monitored. */ { - if (p != buf) - *p++ = ' '; - strcpy(p,dmn->name); - p += strlen(p); + struct daemon *dmn; + size_t len = 0; + + for (dmn = gs.daemons; dmn; dmn = dmn->next) + len += strlen(dmn->name) + 1; + + { + char buf[len + 1]; + char *p = buf; + + for (dmn = gs.daemons; dmn; dmn = dmn->next) { + if (p != buf) + *p++ = ' '; + strcpy(p, dmn->name); + p += strlen(p); + } + zlog_notice("%s %s watching [%s], mode [%s]", + progname, FRR_VERSION, buf, + mode_str[gs.mode]); + } } - zlog_notice("%s %s watching [%s], mode [%s]", - progname, FRR_VERSION, buf, mode_str[gs.mode]); - } - } - { - struct thread thread; + { + struct thread thread; - while (thread_fetch (master, &thread)) - thread_call (&thread); - } + while (thread_fetch(master, &thread)) + thread_call(&thread); + } - systemd_send_stopping (); - /* Not reached. */ - return 0; + systemd_send_stopping(); + /* Not reached. */ + return 0; } diff --git a/watchfrr/watchfrr.h b/watchfrr/watchfrr.h index 4a479c72e6..719ad4dfd8 100644 --- a/watchfrr/watchfrr.h +++ b/watchfrr/watchfrr.h @@ -26,4 +26,4 @@ extern void watchfrr_vty_init(void); extern pid_t integrated_write_pid; extern void integrated_write_sigchld(int status); -#endif /* FRR_WATCHFRR_H */ +#endif /* FRR_WATCHFRR_H */ diff --git a/watchfrr/watchfrr_vty.c b/watchfrr/watchfrr_vty.c index 4fffb020d7..bf3e1510a7 100644 --- a/watchfrr/watchfrr_vty.c +++ b/watchfrr/watchfrr_vty.c @@ -31,18 +31,18 @@ pid_t integrated_write_pid; static int integrated_result_fd; -DEFUN (config_write_integrated, - config_write_integrated_cmd, - "write integrated", - "Write running configuration to memory, network, or terminal\n" - "Write integrated all-daemon Frr.conf file\n") +DEFUN(config_write_integrated, + config_write_integrated_cmd, + "write integrated", + "Write running configuration to memory, network, or terminal\n" + "Write integrated all-daemon Frr.conf file\n") { pid_t child; sigset_t oldmask, sigmask; if (integrated_write_pid != -1) { vty_out(vty, "%% configuration write already in progress.%s", - VTY_NEWLINE); + VTY_NEWLINE); return CMD_WARNING; } @@ -61,20 +61,20 @@ DEFUN (config_write_integrated, child = fork(); if (child == -1) { vty_out(vty, "%% configuration write fork() failed: %s.%s", - safe_strerror(errno), VTY_NEWLINE); + safe_strerror(errno), VTY_NEWLINE); sigprocmask(SIG_SETMASK, &oldmask, NULL); return CMD_WARNING; } if (child != 0) { - /* note: the VTY won't write a command return value to vtysh; the - * session temporarily enters an intentional "hang" state. This is - * to make sure latency in vtysh doing the config write (several - * seconds is not rare to see) does not interfere with watchfrr's - * supervisor job. - * - * The fd is duplicated here so we don't need to hold a vty pointer - * (which could become invalid in the meantime). - */ + /* note: the VTY won't write a command return value to vtysh; the + * session temporarily enters an intentional "hang" state. This is + * to make sure latency in vtysh doing the config write (several + * seconds is not rare to see) does not interfere with watchfrr's + * supervisor job. + * + * The fd is duplicated here so we don't need to hold a vty pointer + * (which could become invalid in the meantime). + */ integrated_write_pid = child; integrated_result_fd = dup(vty->wfd); sigprocmask(SIG_SETMASK, &oldmask, NULL); @@ -93,7 +93,7 @@ DEFUN (config_write_integrated, /* unbuffered write; we just messed with stdout... */ char msg[512]; snprintf(msg, sizeof(msg), "error executing %s: %s\n", - VTYSH_BIN_PATH, safe_strerror(errno)); + VTYSH_BIN_PATH, safe_strerror(errno)); write(1, msg, strlen(msg)); exit(1); } @@ -104,11 +104,11 @@ void integrated_write_sigchld(int status) if (WIFEXITED(status)) { zlog_info("configuration write completed with exit code %d", - WEXITSTATUS(status)); + WEXITSTATUS(status)); reply[3] = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { zlog_warn("configuration write terminated by signal %d", - WTERMSIG(status)); + WTERMSIG(status)); } else { zlog_warn("configuration write terminated"); } From 78af6edc6cd7d17fa11d11fbb9f54efd459230e2 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 10 Jan 2017 23:33:50 +0000 Subject: [PATCH 34/35] lib: limit size of vty buffer to 4096 bytes This removes the automatic resizing of the vty input buffer and places a hard size cap of 4096 bytes. It also fixes a potentially unsafe strcpy. Signed-off-by: Quentin Young [cherry-picked from master 2af38873d89e20bd039255418366c1601aa99e64] --- lib/vty.c | 102 ++++++++++++++++++++++++++++-------------------------- lib/vty.h | 2 +- 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/lib/vty.c b/lib/vty.c index 5919e5220a..23d7153417 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -508,18 +508,6 @@ vty_write (struct vty *vty, const char *buf, size_t nbytes) buffer_put (vty->obuf, buf, nbytes); } -/* Ensure length of input buffer. Is buffer is short, double it. */ -static void -vty_ensure (struct vty *vty, int length) -{ - if (vty->max <= length) - { - vty->max *= 2; - vty->buf = XREALLOC (MTYPE_VTY, vty->buf, vty->max); - vty->error_buf = XREALLOC (MTYPE_VTY, vty->error_buf, vty->max); - } -} - /* Basic function to insert character into vty. */ static void vty_self_insert (struct vty *vty, char c) @@ -527,7 +515,9 @@ vty_self_insert (struct vty *vty, char c) int i; int length; - vty_ensure (vty, vty->length + 1); + if (vty->length + 1 > VTY_BUFSIZ) + return; + length = vty->length - vty->cp; memmove (&vty->buf[vty->cp + 1], &vty->buf[vty->cp], length); vty->buf[vty->cp] = c; @@ -544,26 +534,29 @@ vty_self_insert (struct vty *vty, char c) static void vty_self_insert_overwrite (struct vty *vty, char c) { - vty_ensure (vty, vty->length + 1); + if (vty->cp == vty->length) + { + vty_self_insert (vty, c); + return; + } + vty->buf[vty->cp++] = c; - - if (vty->cp > vty->length) - vty->length++; - - if ((vty->node == AUTH_NODE) || (vty->node == AUTH_ENABLE_NODE)) - return; - vty_write (vty, &c, 1); } -/* Insert a word into vty interface with overwrite mode. */ +/** + * Insert a string into vty->buf at the current cursor position. + * + * If the resultant string would be larger than VTY_BUFSIZ it is + * truncated to fit. + */ static void vty_insert_word_overwrite (struct vty *vty, char *str) { - int len = strlen (str); - vty_write (vty, str, len); - strcpy (&vty->buf[vty->cp], str); - vty->cp += len; + size_t nwrite = MIN ((int) strlen (str), VTY_BUFSIZ - vty->cp); + vty_write (vty, str, nwrite); + strncpy (&vty->buf[vty->cp], str, nwrite); + vty->cp += nwrite; vty->length = vty->cp; } @@ -2217,37 +2210,46 @@ vtysh_read (struct thread *thread) printf ("line: %.*s\n", nbytes, buf); #endif /* VTYSH_DEBUG */ - for (p = buf; p < buf+nbytes; p++) + if (vty->length + nbytes > VTY_BUFSIZ) { - vty_ensure(vty, vty->length+1); - vty->buf[vty->length++] = *p; - if (*p == '\0') - { - /* Pass this line to parser. */ - ret = vty_execute (vty); - /* Note that vty_execute clears the command buffer and resets - vty->length to 0. */ + /* Clear command line buffer. */ + vty->cp = vty->length = 0; + vty_clear_buf (vty); + vty_out (vty, "%% Command is too long.%s", VTY_NEWLINE); + } + else + { + for (p = buf; p < buf+nbytes; p++) + { + vty->buf[vty->length++] = *p; + if (*p == '\0') + { + /* Pass this line to parser. */ + ret = vty_execute (vty); + /* Note that vty_execute clears the command buffer and resets + vty->length to 0. */ - /* Return result. */ + /* Return result. */ #ifdef VTYSH_DEBUG - printf ("result: %d\n", ret); - printf ("vtysh node: %d\n", vty->node); + printf ("result: %d\n", ret); + printf ("vtysh node: %d\n", vty->node); #endif /* VTYSH_DEBUG */ - /* hack for asynchronous "write integrated" - * - other commands in "buf" will be ditched - * - input during pending config-write is "unsupported" */ - if (ret == CMD_SUSPEND) - break; + /* hack for asynchronous "write integrated" + * - other commands in "buf" will be ditched + * - input during pending config-write is "unsupported" */ + if (ret == CMD_SUSPEND) + break; - /* warning: watchfrr hardcodes this result write */ - header[3] = ret; - buffer_put(vty->obuf, header, 4); + /* warning: watchquagga hardcodes this result write */ + header[3] = ret; + buffer_put(vty->obuf, header, 4); - if (!vty->t_write && (vtysh_flush(vty) < 0)) - /* Try to flush results; exit if a write error occurs. */ - return 0; - } + if (!vty->t_write && (vtysh_flush(vty) < 0)) + /* Try to flush results; exit if a write error occurs. */ + return 0; + } + } } vty_event (VTYSH_READ, sock, vty); diff --git a/lib/vty.h b/lib/vty.h index 51d61b4a8c..f5c019dd61 100644 --- a/lib/vty.h +++ b/lib/vty.h @@ -26,7 +26,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "sockunion.h" #include "qobj.h" -#define VTY_BUFSIZ 512 +#define VTY_BUFSIZ 4096 #define VTY_MAXHIST 20 #if defined(VTY_DEPRECATE_INDEX) && defined(__GNUC__) && \ From 6f3b38578810977af89bdd7903b4c5e6146f9cbe Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 13 Jan 2017 15:10:05 +0100 Subject: [PATCH 35/35] partial merge: revert "LabNConsulting/working/2.0/afi-safi-vty/c" Unfortunately, the CLI changes need to be redone on master since the CLI has massively changed there. Signed-off-by: David Lamparter --- bgpd/bgp_mplsvpn.c | 277 ++++---- bgpd/bgp_route.c | 595 ++++++++++++------ bgpd/bgp_routemap.c | 95 +++ bgpd/bgp_vty.c | 1455 ++++++++++++++++++++++++++++++------------- bgpd/bgp_vty.h | 18 +- 5 files changed, 1659 insertions(+), 781 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index b710e0b03b..d55acdd512 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -35,7 +35,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "bgpd/bgp_attr.h" #include "bgpd/bgp_mplsvpn.h" #include "bgpd/bgp_packet.h" -#include "bgpd/bgp_vty.h" #if ENABLE_BGP_VNC #include "bgpd/rfapi/rfapi_backend.h" @@ -199,7 +198,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8) { - zlog_err ("%s [Error] Update packet error / VPN (prefix length %d less than VPN min length)", + zlog_err ("%s [Error] Update packet error / VPNv4 (prefix length %d less than VPNv4 min length)", peer->host, prefixlen); return -1; } @@ -207,7 +206,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, /* sanity check against packet data */ if ((pnt + psize) > lim) { - zlog_err ("%s [Error] Update packet error / VPN (prefix length %d exceeds packet size %u)", + zlog_err ("%s [Error] Update packet error / VPNv4 (prefix length %d exceeds packet size %u)", peer->host, prefixlen, (uint)(lim-pnt)); return -1; @@ -216,7 +215,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, /* sanity check against storage for the IP address portion */ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u)) { - zlog_err ("%s [Error] Update packet error / VPN (psize %d exceeds storage size %zu)", + zlog_err ("%s [Error] Update packet error / VPNv4 (psize %d exceeds storage size %zu)", peer->host, prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u)); return -1; @@ -225,7 +224,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, /* Sanity check against max bitlen of the address family */ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p)) { - zlog_err ("%s [Error] Update packet error / VPN (psize %d exceeds family (%u) max byte len %u)", + zlog_err ("%s [Error] Update packet error / VPNv4 (psize %d exceeds family (%u) max byte len %u)", peer->host, prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, p.family, prefix_blen (&p)); @@ -296,7 +295,7 @@ bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, /* Packet length consistency check. */ if (pnt != lim) { - zlog_err ("%s [Error] Update packet error / VPN (%zu data remaining after parsing)", + zlog_err ("%s [Error] Update packet error / VPNv4 (%zu data remaining after parsing)", peer->host, lim - pnt); return -1; } @@ -486,7 +485,7 @@ DEFUN (no_vpnv4_network, } static int -show_adj_route_vpn (struct vty *vty, struct peer *peer, afi_t afi, struct prefix_rd *prd, u_char use_json) +show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u_char use_json) { struct bgp *bgp; struct bgp_table *table; @@ -529,7 +528,7 @@ show_adj_route_vpn (struct vty *vty, struct peer *peer, afi_t afi, struct prefix json_object_string_add(json_ocode, "incomplete", "?"); } - for (rn = bgp_table_top (bgp->rib[afi][SAFI_MPLS_VPN]); rn; + for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn)) { if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) @@ -955,25 +954,25 @@ DEFUN (show_bgp_ipv6_vpn_rd, return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0, use_json (argc, argv)); } -DEFUN (show_bgp_ip_vpn_all, - show_bgp_ip_vpn_all_cmd, - "show bgp "BGP_AFI_CMD_STR" vpn all", +DEFUN (show_ip_bgp_vpnv4_all, + show_ip_bgp_vpnv4_all_cmd, + "show ip bgp vpnv4 all", SHOW_STR IP_STR BGP_STR - BGP_AFI_HELP_STR - "Display information about all VPN NLRIs\n") + "Display VPNv4 NLRI specific information\n" + "Display information about all VPNv4 NLRIs\n") { - return bgp_show_mpls_vpn (vty, bgp_vty_afi_from_arg(argv[0]), NULL, bgp_show_type_normal, NULL, 0, 0); + return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 0, 0); } -DEFUN (show_bgp_ip_vpn_rd, - show_bgp_ip_vpn_rd_cmd, - "show bgp "BGP_AFI_CMD_STR" vpn rd ASN:nn_or_IP-address:nn", +DEFUN (show_ip_bgp_vpnv4_rd, + show_ip_bgp_vpnv4_rd_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn", SHOW_STR IP_STR BGP_STR - BGP_AFI_HELP_STR + "Display VPNv4 NLRI specific information\n" "Display information for a route distinguisher\n" "VPN Route Distinguisher\n") { @@ -986,29 +985,29 @@ DEFUN (show_bgp_ip_vpn_rd, vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_mpls_vpn (vty, bgp_vty_afi_from_arg(argv[0]), &prd, bgp_show_type_normal, NULL, 0, 0); + return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0, 0); } -DEFUN (show_bgp_ip_vpn_all_tags, - show_bgp_ip_vpn_all_tags_cmd, - "show bgp "BGP_AFI_CMD_STR" vpn all tags", +DEFUN (show_ip_bgp_vpnv4_all_tags, + show_ip_bgp_vpnv4_all_tags_cmd, + "show ip bgp vpnv4 all tags", SHOW_STR IP_STR BGP_STR - BGP_AFI_HELP_STR + "Display VPNv4 NLRI specific information\n" "Display information about all VPNv4 NLRIs\n" "Display BGP tags for prefixes\n") { - return bgp_show_mpls_vpn (vty, bgp_vty_afi_from_arg(argv[0]), NULL, bgp_show_type_normal, NULL, 1, 0); + return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1, 0); } -DEFUN (show_bgp_ip_vpn_rd_tags, - show_bgp_ip_vpn_rd_tags_cmd, - "show bgp "BGP_AFI_CMD_STR" vpn rd ASN:nn_or_IP-address:nn tags", +DEFUN (show_ip_bgp_vpnv4_rd_tags, + show_ip_bgp_vpnv4_rd_tags_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn tags", SHOW_STR IP_STR BGP_STR - BGP_AFI_HELP_STR + "Display VPNv4 NLRI specific information\n" "Display information for a route distinguisher\n" "VPN Route Distinguisher\n" "Display BGP tags for prefixes\n") @@ -1016,26 +1015,25 @@ DEFUN (show_bgp_ip_vpn_rd_tags, int ret; struct prefix_rd prd; - ret = str2prefix_rd (argv[1], &prd); + ret = str2prefix_rd (argv[0], &prd); if (! ret) { vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); return CMD_WARNING; } - return bgp_show_mpls_vpn (vty, bgp_vty_afi_from_arg(argv[0]), &prd, bgp_show_type_normal, NULL, 1, 0); + return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1, 0); } -DEFUN (show_bgp_ip_vpn_all_neighbor_routes, - show_bgp_ip_vpn_all_neighbor_routes_cmd, - "show bgp "BGP_AFI_CMD_STR" vpn all neighbors (A.B.C.D|X:X::X:X) routes {json}", +DEFUN (show_ip_bgp_vpnv4_all_neighbor_routes, + show_ip_bgp_vpnv4_all_neighbor_routes_cmd, + "show ip bgp vpnv4 all neighbors A.B.C.D routes {json}", SHOW_STR IP_STR BGP_STR - BGP_AFI_HELP_STR + "Display VPNv4 NLRI specific information\n" "Display information about all VPNv4 NLRIs\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" - "Neighbor to display information about\n" "Display routes learned from neighbor\n" "JavaScript Object Notation\n") { @@ -1043,7 +1041,77 @@ DEFUN (show_bgp_ip_vpn_all_neighbor_routes, struct peer *peer; int ret; u_char uj = use_json(argc, argv); - afi_t afi = bgp_vty_afi_from_arg(argv[0]); + + ret = str2sockunion (argv[0], &su); + if (ret < 0) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "Malformed address"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); + return CMD_WARNING; + } + + peer = peer_lookup (NULL, &su); + if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "No such neighbor or address family"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); + return CMD_WARNING; + } + + return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0, uj); +} + +DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes, + show_ip_bgp_vpnv4_rd_neighbor_routes_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information for a route distinguisher\n" + "VPN Route Distinguisher\n" + "Detailed information on TCP and BGP neighbor connections\n" + "Neighbor to display information about\n" + "Display routes learned from neighbor\n" + "JavaScript Object Notation\n") +{ + int ret; + union sockunion su; + struct peer *peer; + struct prefix_rd prd; + u_char uj = use_json(argc, argv); + + ret = str2prefix_rd (argv[0], &prd); + if (! ret) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "Malformed Route Distinguisher"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); + return CMD_WARNING; + } ret = str2sockunion (argv[1], &su); if (ret < 0) @@ -1062,7 +1130,7 @@ DEFUN (show_bgp_ip_vpn_all_neighbor_routes, } peer = peer_lookup (NULL, &su); - if (! peer || ! peer->afc[afi][SAFI_MPLS_VPN]) + if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) { if (uj) { @@ -1077,48 +1145,28 @@ DEFUN (show_bgp_ip_vpn_all_neighbor_routes, return CMD_WARNING; } - return bgp_show_mpls_vpn (vty, afi, NULL, bgp_show_type_neighbor, &su, 0, uj); + return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_neighbor, &su, 0, uj); } -DEFUN (show_bgp_ip_vpn_rd_neighbor_routes, - show_bgp_ip_vpn_rd_neighbor_routes_cmd, - "show bgp "BGP_AFI_CMD_STR" vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes {json}", +DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes, + show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd, + "show ip bgp vpnv4 all neighbors A.B.C.D advertised-routes {json}", SHOW_STR IP_STR BGP_STR - BGP_AFI_HELP_STR - "Display information for a route distinguisher\n" - "VPN Route Distinguisher\n" + "Display VPNv4 NLRI specific information\n" + "Display information about all VPNv4 NLRIs\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" - "Neighbor to display information about\n" - "Display routes learned from neighbor\n" + "Display the routes advertised to a BGP neighbor\n" "JavaScript Object Notation\n") { int ret; - union sockunion su; struct peer *peer; - struct prefix_rd prd; + union sockunion su; u_char uj = use_json(argc, argv); - afi_t afi = bgp_vty_afi_from_arg(argv[0]); - ret = str2prefix_rd (argv[1], &prd); - if (! ret) - { - if (uj) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "Malformed Route Distinguisher"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); - return CMD_WARNING; - } - - ret = str2sockunion (argv[2], &su); + ret = str2sockunion (argv[0], &su); if (ret < 0) { if (uj) @@ -1133,9 +1181,8 @@ DEFUN (show_bgp_ip_vpn_rd_neighbor_routes, vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); return CMD_WARNING; } - peer = peer_lookup (NULL, &su); - if (! peer || ! peer->afc[afi][SAFI_MPLS_VPN]) + if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) { if (uj) { @@ -1150,28 +1197,28 @@ DEFUN (show_bgp_ip_vpn_rd_neighbor_routes, return CMD_WARNING; } - return bgp_show_mpls_vpn (vty, afi, &prd, bgp_show_type_neighbor, &su, 0, uj); + return show_adj_route_vpn (vty, peer, NULL, uj); } -DEFUN (show_bgp_ip_vpn_all_neighbor_advertised_routes, - show_bgp_ip_vpn_all_neighbor_advertised_routes_cmd, - "show bgp "BGP_AFI_CMD_STR" vpn all neighbors (A.B.C.D|X:X::X:X) advertised-routes {json}", +DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes, + show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes {json}", SHOW_STR IP_STR BGP_STR - BGP_AFI_HELP_STR - "Display information about all VPN NLRIs\n" + "Display VPNv4 NLRI specific information\n" + "Display information for a route distinguisher\n" + "VPN Route Distinguisher\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" - "Neighbor to display information about\n" "Display the routes advertised to a BGP neighbor\n" "JavaScript Object Notation\n") { int ret; struct peer *peer; + struct prefix_rd prd; union sockunion su; u_char uj = use_json(argc, argv); - afi_t afi = bgp_vty_afi_from_arg(argv[0]); ret = str2sockunion (argv[1], &su); if (ret < 0) @@ -1189,7 +1236,7 @@ DEFUN (show_bgp_ip_vpn_all_neighbor_advertised_routes, return CMD_WARNING; } peer = peer_lookup (NULL, &su); - if (! peer || ! peer->afc[afi][SAFI_MPLS_VPN]) + if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) { if (uj) { @@ -1204,63 +1251,7 @@ DEFUN (show_bgp_ip_vpn_all_neighbor_advertised_routes, return CMD_WARNING; } - return show_adj_route_vpn (vty, peer, afi, NULL, uj); -} - -DEFUN (show_bgp_ip_vpn_rd_neighbor_advertised_routes, - show_bgp_ip_vpn_rd_neighbor_advertised_routes_cmd, - "show bgp "BGP_AFI_CMD_STR" vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes {json}", - SHOW_STR - IP_STR - BGP_STR - BGP_AFI_HELP_STR - "Display information for a route distinguisher\n" - "VPN Route Distinguisher\n" - "Detailed information on TCP and BGP neighbor connections\n" - "Neighbor to display information about\n" - "Neighbor to display information about\n" - "Display the routes advertised to a BGP neighbor\n" - "JavaScript Object Notation\n") -{ - int ret; - struct peer *peer; - struct prefix_rd prd; - union sockunion su; - u_char uj = use_json(argc, argv); - afi_t afi = bgp_vty_afi_from_arg(argv[0]); - - ret = str2sockunion (argv[2], &su); - if (ret < 0) - { - if (uj) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "Malformed address"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "Malformed address: %s%s", argv[2], VTY_NEWLINE); - return CMD_WARNING; - } - peer = peer_lookup (NULL, &su); - if (! peer || ! peer->afc[afi][SAFI_MPLS_VPN]) - { - if (uj) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "No such neighbor or address family"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); - return CMD_WARNING; - } - - ret = str2prefix_rd (argv[1], &prd); + ret = str2prefix_rd (argv[0], &prd); if (! ret) { if (uj) @@ -1276,7 +1267,7 @@ DEFUN (show_bgp_ip_vpn_rd_neighbor_advertised_routes, return CMD_WARNING; } - return show_adj_route_vpn (vty, peer, afi, &prd, uj); + return show_adj_route_vpn (vty, peer, &prd, uj); } void @@ -1290,12 +1281,12 @@ bgp_mplsvpn_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_cmd); install_element (VIEW_NODE, &show_bgp_ipv6_vpn_cmd); install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_cmd); - install_element (VIEW_NODE, &show_bgp_ip_vpn_all_cmd); - install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_cmd); - install_element (VIEW_NODE, &show_bgp_ip_vpn_all_tags_cmd); - install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_tags_cmd); - install_element (VIEW_NODE, &show_bgp_ip_vpn_all_neighbor_routes_cmd); - install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_neighbor_routes_cmd); - install_element (VIEW_NODE, &show_bgp_ip_vpn_all_neighbor_advertised_routes_cmd); - install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_neighbor_advertised_routes_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_tags_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd); } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 9e1ae854d4..c717a930b1 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -6416,8 +6416,7 @@ route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi == SAFI_ENCAP || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) { - if (attr->extra && - (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)) + if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in)); else @@ -6428,15 +6427,13 @@ route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t { int len; char buf[BUFSIZ]; - if (attr->extra) - { - len = vty_out (vty, "%s", - inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, - buf, BUFSIZ)); - len = 16 - len; - } - else - len = 0; + + assert (attr->extra); + + len = vty_out (vty, "%s", + inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, + buf, BUFSIZ)); + len = 16 - len; if (len < 1) vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); else @@ -8160,12 +8157,13 @@ DEFUN (show_ip_bgp, DEFUN (show_ip_bgp_ipv4, show_ip_bgp_ipv4_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" {json}", + "show ip bgp ipv4 (unicast|multicast) {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); @@ -8177,11 +8175,12 @@ DEFUN (show_ip_bgp_ipv4, ALIAS (show_ip_bgp_ipv4, show_bgp_ipv4_safi_cmd, - "show bgp ipv4 "BGP_SAFI_CMD_STR" {json}", + "show bgp ipv4 (unicast|multicast) {json}", SHOW_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "JavaScript Object Notation\n") DEFUN (show_ip_bgp_route, @@ -8217,10 +8216,10 @@ DEFUN (show_ip_bgp_route_pathtype, DEFUN (show_bgp_ipv4_safi_route_pathtype, show_bgp_ipv4_safi_route_pathtype_cmd, - "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D (bestpath|multipath) {json}", + "show bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D (bestpath|multipath) {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "IP prefix /, e.g., 35.0.0.0/8\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -8276,11 +8275,11 @@ DEFUN (show_bgp_ipv6_prefix, DEFUN (show_ip_bgp_ipv4_route, show_ip_bgp_ipv4_route_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}", + "show ip bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D {json}", SHOW_STR IP_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "Network in the BGP routing table to display\n" "JavaScript Object Notation\n") { @@ -8293,13 +8292,27 @@ DEFUN (show_ip_bgp_ipv4_route, ALIAS (show_ip_bgp_ipv4_route, show_bgp_ipv4_safi_route_cmd, - "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D {json}", + "show bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "Network in the BGP routing table to display\n" "JavaScript Object Notation\n") +DEFUN (show_ip_bgp_vpnv4_all_route, + show_ip_bgp_vpnv4_all_route_cmd, + "show ip bgp vpnv4 all A.B.C.D {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information about all VPNv4 NLRIs\n" + "Network in the BGP routing table to display\n" + "JavaScript Object Notation\n") +{ + return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); +} + DEFUN (show_bgp_ipv4_safi_rd_route, show_bgp_ipv4_safi_rd_route_cmd, "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D {json}", @@ -8419,6 +8432,31 @@ DEFUN (show_bgp_ipv6_safi_rd_prefix, return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL, use_json (argc, argv)); } +DEFUN (show_ip_bgp_vpnv4_rd_route, + show_ip_bgp_vpnv4_rd_route_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information for a route distinguisher\n" + "VPN Route Distinguisher\n" + "Network in the BGP routing table to display\n" + "JavaScript Object Notation\n") +{ + int ret; + struct prefix_rd prd; + u_char uj= use_json(argc, argv); + + ret = str2prefix_rd (argv[0], &prd); + if (! ret) + { + vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); + return CMD_WARNING; + } + return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj); +} + DEFUN (show_ip_bgp_prefix, show_ip_bgp_prefix_cmd, "show ip bgp A.B.C.D/M {json}", @@ -8451,11 +8489,11 @@ DEFUN (show_ip_bgp_prefix_pathtype, DEFUN (show_ip_bgp_ipv4_prefix, show_ip_bgp_ipv4_prefix_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}", + "show ip bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D/M {json}", SHOW_STR IP_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "IP prefix /, e.g., 35.0.0.0/8\n" "JavaScript Object Notation\n") { @@ -8468,20 +8506,20 @@ DEFUN (show_ip_bgp_ipv4_prefix, ALIAS (show_ip_bgp_ipv4_prefix, show_bgp_ipv4_safi_prefix_cmd, - "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M {json}", + "show bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D/M {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "IP prefix /, e.g., 35.0.0.0/8\n" "JavaScript Object Notation\n") DEFUN (show_ip_bgp_ipv4_prefix_pathtype, show_ip_bgp_ipv4_prefix_pathtype_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}", + "show ip bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D/M (bestpath|multipath) {json}", SHOW_STR IP_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "IP prefix /, e.g., 35.0.0.0/8\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -8501,15 +8539,52 @@ DEFUN (show_ip_bgp_ipv4_prefix_pathtype, ALIAS (show_ip_bgp_ipv4_prefix_pathtype, show_bgp_ipv4_safi_prefix_pathtype_cmd, - "show bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M (bestpath|multipath) {json}", + "show bgp ipv4 (unicast|multicast|vpn|encap) A.B.C.D/M (bestpath|multipath) {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "IP prefix /, e.g., 35.0.0.0/8\n" "Display only the bestpath\n" "Display only multipaths\n" "JavaScript Object Notation\n") +DEFUN (show_ip_bgp_vpnv4_all_prefix, + show_ip_bgp_vpnv4_all_prefix_cmd, + "show ip bgp vpnv4 all A.B.C.D/M {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information about all VPNv4 NLRIs\n" + "IP prefix /, e.g., 35.0.0.0/8\n" + "JavaScript Object Notation\n") +{ + return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); +} + +DEFUN (show_ip_bgp_vpnv4_rd_prefix, + show_ip_bgp_vpnv4_rd_prefix_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information for a route distinguisher\n" + "VPN Route Distinguisher\n" + "IP prefix /, e.g., 35.0.0.0/8\n" + "JavaScript Object Notation\n") +{ + int ret; + struct prefix_rd prd; + + ret = str2prefix_rd (argv[0], &prd); + if (! ret) + { + vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); + return CMD_WARNING; + } + return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv)); +} DEFUN (show_ip_bgp_view, show_ip_bgp_instance_cmd, @@ -8635,11 +8710,13 @@ ALIAS (show_bgp, DEFUN (show_bgp_ipv6_safi, show_bgp_ipv6_safi_cmd, - "show bgp ipv6 "BGP_SAFI_CMD_STR" {json}", + "show bgp ipv6 (unicast|multicast) {json}", SHOW_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" + AFI_SAFI_STR "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); @@ -8684,10 +8761,10 @@ DEFUN (show_bgp_route, DEFUN (show_bgp_ipv6_safi_route, show_bgp_ipv6_safi_route_cmd, - "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X {json}", + "show bgp ipv6 (unicast|multicast|vpn|encap) X:X::X:X {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "Network in the BGP routing table to display\n" "JavaScript Object Notation\n") { @@ -8728,10 +8805,10 @@ ALIAS (show_bgp_route_pathtype, DEFUN (show_bgp_ipv6_safi_route_pathtype, show_bgp_ipv6_safi_route_pathtype_cmd, - "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X (bestpath|multipath) {json}", + "show bgp ipv6 (unicast|multicast|vpn|encap) X:X::X:X (bestpath|multipath) {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "Network in the BGP routing table to display\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -8775,10 +8852,10 @@ DEFUN (show_bgp_prefix, DEFUN (show_bgp_ipv6_safi_prefix, show_bgp_ipv6_safi_prefix_cmd, - "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M {json}", + "show bgp ipv6 (unicast|multicast|vpn|encap) X:X::X:X/M {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "IPv6 prefix /, e.g., 3ffe::/16\n" "JavaScript Object Notation\n") { @@ -8819,10 +8896,10 @@ ALIAS (show_bgp_prefix_pathtype, DEFUN (show_bgp_ipv6_safi_prefix_pathtype, show_bgp_ipv6_safi_prefix_pathtype_cmd, - "show bgp ipv6 "BGP_SAFI_CMD_STR" X:X::X:X/M (bestpath|multipath) {json}", + "show bgp ipv6 (unicast|multicast|vpn|encap) X:X::X:X/M (bestpath|multipath) {json}", SHOW_STR BGP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "IPv6 prefix /, e.g., 3ffe::/16\n" "Display only the bestpath\n" "Display only multipaths\n" @@ -9245,19 +9322,22 @@ ALIAS (show_ip_bgp_flap_regexp, DEFUN (show_ip_bgp_ipv4_regexp, show_ip_bgp_ipv4_regexp_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" regexp .LINE", + "show ip bgp ipv4 (unicast|multicast) regexp .LINE", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the AS path regular expression\n" "A regular-expression to match the BGP AS paths\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_regexp (vty, argc, argv, AFI_IP, safi, - bgp_show_type_regexp); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST, + bgp_show_type_regexp); + + return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, + bgp_show_type_regexp); } #ifdef HAVE_IPV6 @@ -9392,19 +9472,22 @@ ALIAS (show_ip_bgp_flap_prefix_list, DEFUN (show_ip_bgp_ipv4_prefix_list, show_ip_bgp_ipv4_prefix_list_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" prefix-list WORD", + "show ip bgp ipv4 (unicast|multicast) prefix-list WORD", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes conforming to the prefix-list\n" "IP prefix-list name\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, safi, - bgp_show_type_prefix_list); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, + bgp_show_type_prefix_list); + + return bgp_show_prefix_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, + bgp_show_type_prefix_list); } #ifdef HAVE_IPV6 @@ -9538,19 +9621,22 @@ ALIAS (show_ip_bgp_flap_filter_list, DEFUN (show_ip_bgp_ipv4_filter_list, show_ip_bgp_ipv4_filter_list_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" filter-list WORD", + "show ip bgp ipv4 (unicast|multicast) filter-list WORD", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes conforming to the filter-list\n" "Regular expression access list name\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, safi, - bgp_show_type_filter_list); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, + bgp_show_type_filter_list); + + return bgp_show_filter_list (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, + bgp_show_type_filter_list); } #ifdef HAVE_IPV6 @@ -9621,53 +9707,61 @@ DEFUN (show_ip_bgp_dampening_info, DEFUN (show_ip_bgp_ipv4_dampening_parameters, show_ip_bgp_ipv4_dampening_parameters_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening parameters", + "show ip bgp ipv4 (unicast|multicast) dampening parameters", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display detailed information about dampening\n" "Display detail of configured dampening parameters\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_dampening_parameters (vty, AFI_IP, safi); + if (strncmp(argv[0], "m", 1) == 0) + return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST); + + return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST); } DEFUN (show_ip_bgp_ipv4_dampening_flap_stats, show_ip_bgp_ipv4_dampening_flap_stats_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening flap-statistics", + "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display detailed information about dampening\n" "Display flap statistics of routes\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show (vty, NULL, AFI_IP, safi, + if (strncmp(argv[0], "m", 1) == 0) + return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_flap_statistics, NULL, 0); + + return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, + bgp_show_type_flap_statistics, NULL, 0); } DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths, show_ip_bgp_ipv4_dampening_dampd_paths_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" dampening dampened-paths", + "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display detailed information about dampening\n" "Display paths suppressed due to dampening\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show (vty, NULL, AFI_IP, safi, + if (strncmp(argv[0], "m", 1) == 0) + return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_dampend_paths, NULL, 0); + + return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, + bgp_show_type_dampend_paths, NULL, 0); } static int @@ -9749,19 +9843,22 @@ ALIAS (show_ip_bgp_flap_route_map, DEFUN (show_ip_bgp_ipv4_route_map, show_ip_bgp_ipv4_route_map_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" route-map WORD", + "show ip bgp ipv4 (unicast|multicast) route-map WORD", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the route-map\n" "A route-map to match on\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, safi, - bgp_show_type_route_map); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, + bgp_show_type_route_map); + + return bgp_show_route_map (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, + bgp_show_type_route_map); } DEFUN (show_bgp_route_map, @@ -9822,18 +9919,21 @@ ALIAS (show_ip_bgp_flap_cidr_only, DEFUN (show_ip_bgp_ipv4_cidr_only, show_ip_bgp_ipv4_cidr_only_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" cidr-only", + "show ip bgp ipv4 (unicast|multicast) cidr-only", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display only routes with non-natural netmasks\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show (vty, NULL, AFI_IP, safi, - bgp_show_type_cidr_only, NULL, 0); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, + bgp_show_type_cidr_only, NULL, 0); + + return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, + bgp_show_type_cidr_only, NULL, 0); } DEFUN (show_ip_bgp_community_all, @@ -9850,18 +9950,21 @@ DEFUN (show_ip_bgp_community_all, DEFUN (show_ip_bgp_ipv4_community_all, show_ip_bgp_ipv4_community_all_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community", + "show ip bgp ipv4 (unicast|multicast) community", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show (vty, NULL, AFI_IP, safi, - bgp_show_type_community_all, NULL, 0); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, + bgp_show_type_community_all, NULL, 0); + + return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, + bgp_show_type_community_all, NULL, 0); } #ifdef HAVE_IPV6 @@ -10053,31 +10156,34 @@ ALIAS (show_ip_bgp_community, DEFUN (show_ip_bgp_ipv4_community, show_ip_bgp_ipv4_community_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export)", + "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\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") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, safi); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST); + + return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST); } ALIAS (show_ip_bgp_ipv4_community, show_ip_bgp_ipv4_community2_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10090,12 +10196,13 @@ ALIAS (show_ip_bgp_ipv4_community, ALIAS (show_ip_bgp_ipv4_community, show_ip_bgp_ipv4_community3_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10112,12 +10219,13 @@ ALIAS (show_ip_bgp_ipv4_community, ALIAS (show_ip_bgp_ipv4_community, show_ip_bgp_ipv4_community4_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10138,11 +10246,14 @@ ALIAS (show_ip_bgp_ipv4_community, DEFUN (show_bgp_instance_afi_safi_community_all, show_bgp_instance_afi_safi_community_all_cmd, - "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community", + "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + "Address family\n" + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n") { int afi; @@ -10157,14 +10268,14 @@ DEFUN (show_bgp_instance_afi_safi_community_all, return CMD_WARNING; } - afi = bgp_vty_safi_from_arg(argv[2]); - safi = bgp_vty_safi_from_arg(argv[3]); + afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; + safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0); } DEFUN (show_bgp_instance_afi_safi_community, show_bgp_instance_afi_safi_community_cmd, - "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export)", + "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -10181,14 +10292,14 @@ DEFUN (show_bgp_instance_afi_safi_community, int afi; int safi; - afi = bgp_vty_safi_from_arg(argv[2]); - safi = bgp_vty_safi_from_arg(argv[3]); + afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; + safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi); } ALIAS (show_bgp_instance_afi_safi_community, show_bgp_instance_afi_safi_community2_cmd, - "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -10208,7 +10319,7 @@ ALIAS (show_bgp_instance_afi_safi_community, ALIAS (show_bgp_instance_afi_safi_community, show_bgp_instance_afi_safi_community3_cmd, - "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -10232,7 +10343,7 @@ ALIAS (show_bgp_instance_afi_safi_community, ALIAS (show_bgp_instance_afi_safi_community, show_bgp_instance_afi_safi_community4_cmd, - "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", + "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -10339,12 +10450,13 @@ ALIAS (show_ip_bgp_community_exact, DEFUN (show_ip_bgp_ipv4_community_exact, show_ip_bgp_ipv4_community_exact_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) exact-match", + "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10352,19 +10464,21 @@ DEFUN (show_ip_bgp_ipv4_community_exact, "Do not export to next AS (well-known community)\n" "Exact match of the communities") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, safi); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST); + + return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST); } ALIAS (show_ip_bgp_ipv4_community_exact, show_ip_bgp_ipv4_community2_exact_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", + "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10378,12 +10492,13 @@ ALIAS (show_ip_bgp_ipv4_community_exact, ALIAS (show_ip_bgp_ipv4_community_exact, show_ip_bgp_ipv4_community3_exact_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", + "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -10401,12 +10516,13 @@ ALIAS (show_ip_bgp_ipv4_community_exact, ALIAS (show_ip_bgp_ipv4_community_exact, show_ip_bgp_ipv4_community4_exact_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", + "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -11106,19 +11222,21 @@ DEFUN (show_ip_bgp_instance_community_list, DEFUN (show_ip_bgp_ipv4_community_list, show_ip_bgp_ipv4_community_list_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community-list (<1-500>|WORD)", + "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the community-list\n" "community-list number\n" "community-list name\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, safi); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_MULTICAST); + + return bgp_show_community_list (vty, NULL, argv[1], 0, AFI_IP, SAFI_UNICAST); } DEFUN (show_ip_bgp_community_list_exact, @@ -11137,20 +11255,22 @@ DEFUN (show_ip_bgp_community_list_exact, DEFUN (show_ip_bgp_ipv4_community_list_exact, show_ip_bgp_ipv4_community_list_exact_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" community-list (<1-500>|WORD) exact-match", + "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Display routes matching the community-list\n" "community-list number\n" "community-list name\n" "Exact match of the communities\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, safi); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_MULTICAST); + + return bgp_show_community_list (vty, NULL, argv[1], 1, AFI_IP, SAFI_UNICAST); } #ifdef HAVE_IPV6 @@ -11342,19 +11462,22 @@ ALIAS (show_ip_bgp_flap_prefix_longer, DEFUN (show_ip_bgp_ipv4_prefix_longer, show_ip_bgp_ipv4_prefix_longer_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" A.B.C.D/M longer-prefixes", + "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "IP prefix /, e.g., 35.0.0.0/8\n" "Display route and more specific routes\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, safi, - bgp_show_type_prefix_longer); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, + bgp_show_type_prefix_longer); + + return bgp_show_prefix_longer (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, + bgp_show_type_prefix_longer); } DEFUN (show_ip_bgp_flap_address, @@ -11816,30 +11939,54 @@ bgp_table_stats_vty (struct vty *vty, const char *name, vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); return CMD_WARNING; } - afi = bgp_vty_afi_from_arg(afi_str); - if (afi == AFI_MAX) + if (strncmp (afi_str, "ipv", 3) == 0) + { + if (strncmp (afi_str, "ipv4", 4) == 0) + afi = AFI_IP; + else if (strncmp (afi_str, "ipv6", 4) == 0) + afi = AFI_IP6; + else + { + vty_out (vty, "%% Invalid address family %s%s", + afi_str, VTY_NEWLINE); + return CMD_WARNING; + } + if (strncmp (safi_str, "m", 1) == 0) + safi = SAFI_MULTICAST; + else if (strncmp (safi_str, "u", 1) == 0) + safi = SAFI_UNICAST; + else if (strncmp (safi_str, "e", 1) == 0) + safi = SAFI_ENCAP; + else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0) + safi = SAFI_MPLS_VPN; + else + { + vty_out (vty, "%% Invalid subsequent address family %s%s", + safi_str, VTY_NEWLINE); + return CMD_WARNING; + } + } + else { vty_out (vty, "%% Invalid address family \"%s\"%s", afi_str, VTY_NEWLINE); return CMD_WARNING; } - safi = bgp_vty_safi_from_arg(safi_str); - if (safi == SAFI_MAX) - { - vty_out (vty, "%% Invalid subsequent address family %s%s", - safi_str, VTY_NEWLINE); - return CMD_WARNING; - } return bgp_table_stats (vty, bgp, afi, safi); } DEFUN (show_bgp_statistics, show_bgp_statistics_cmd, - "show bgp "BGP_AFI_SAFI_CMD_STR" statistics", + "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics", SHOW_STR BGP_STR - BGP_INSTANCE_HELP_STR + "Address family\n" + "Address family\n" + "Address Family modifier\n" + "Address Family modifier\n" + "Address Family modifier\n" + "Address Family modifier\n" "BGP RIB advertisement statistics\n") { return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]); @@ -11847,11 +11994,16 @@ DEFUN (show_bgp_statistics, DEFUN (show_bgp_statistics_view, show_bgp_statistics_view_cmd, - "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" statistics", + "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast|vpn|encap) statistics", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + "Address family\n" + "Address Family modifier\n" + "Address Family modifier\n" + "Address Family modifier\n" + "Address Family modifier\n" "BGP RIB advertisement statistics\n") { return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]); @@ -12144,12 +12296,13 @@ DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts, DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, show_ip_bgp_ipv4_neighbor_prefix_counts_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12164,9 +12317,36 @@ DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, if (! peer) return CMD_WARNING; - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_peer_counts (vty, peer, AFI_IP, safi, uj); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj); + + return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); +} + +DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, + show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd, + "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", + SHOW_STR + IP_STR + BGP_STR + "Address family\n" + "Address Family modifier\n" + "Address Family modifier\n" + "Detailed information on TCP and BGP neighbor connections\n" + "Neighbor to display information about\n" + "Neighbor to display information about\n" + "Neighbor on bgp configured interface\n" + "Display detailed prefix count information\n" + "JavaScript Object Notation\n") +{ + struct peer *peer; + u_char uj = use_json(argc, argv); + + peer = peer_lookup_in_view (vty, NULL, argv[0], uj); + if (! peer) + return CMD_WARNING; + + return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj); } static void @@ -12494,12 +12674,13 @@ ALIAS (show_ip_bgp_instance_neighbor_advertised_route, "JavaScript Object Notation\n") DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, show_ip_bgp_ipv4_neighbor_advertised_route_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12509,8 +12690,6 @@ DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, { struct peer *peer; const char *rmap_name = NULL; - safi_t safi; - u_char uj = use_json(argc, argv); peer = peer_lookup_in_view (vty, NULL, argv[1], uj); @@ -12520,18 +12699,21 @@ DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) rmap_name = argv[2]; - safi = bgp_vty_safi_from_arg(argv[0]); - return peer_adj_routes (vty, peer, AFI_IP, safi, 0, rmap_name, uj); + if (strncmp (argv[0], "m", 1) == 0) + return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj); + else + return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj); } ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route, show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12783,12 +12965,13 @@ ALIAS (show_ip_bgp_instance_neighbor_received_routes, DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, show_ip_bgp_ipv4_neighbor_received_routes_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12798,7 +12981,6 @@ DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, { struct peer *peer; const char *rmap_name = NULL; - safi_t safi; u_char uj = use_json(argc, argv); peer = peer_lookup_in_view (vty, NULL, argv[1], uj); @@ -12808,18 +12990,21 @@ DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) rmap_name = argv[2]; - safi = bgp_vty_safi_from_arg(argv[0]); - return peer_adj_routes (vty, peer, AFI_IP, safi, 1, rmap_name, uj); + if (strncmp (argv[0], "m", 1) == 0) + return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj); + else + return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj); } ALIAS (show_ip_bgp_ipv4_neighbor_received_routes, show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12829,11 +13014,14 @@ ALIAS (show_ip_bgp_ipv4_neighbor_received_routes, DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes, show_bgp_instance_afi_safi_neighbor_adv_recd_routes_cmd, - "show bgp " BGP_INSTANCE_CMD " "BGP_AFI_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}", + "show bgp " BGP_INSTANCE_CMD " (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR - BGP_AFI_SAFI_HELP_STR + "Address family\n" + "Address family\n" + "Address family modifier\n" + "Address family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -12853,8 +13041,8 @@ DEFUN (show_bgp_instance_afi_safi_neighbor_adv_recd_routes, if (! peer) return CMD_WARNING; - afi = bgp_vty_safi_from_arg(argv[2]); - safi = bgp_vty_safi_from_arg(argv[3]); + afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; + safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0; return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj); @@ -12949,12 +13137,13 @@ DEFUN (show_ip_bgp_neighbor_received_prefix_filter, DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter, show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -13011,16 +13200,38 @@ DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter, } } + if (strncmp (argv[0], "m", 1) == 0) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi); + sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST); count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); if (count) { if (!uj) - vty_out (vty, "Address family: %s%s", - afi_safi_print (AFI_IP, safi), VTY_NEWLINE); + vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE); + prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); + } + else + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_boolean_true_add(json_no, "noFuntionalOutput"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "No functional output%s", VTY_NEWLINE); + } + } + else + { + sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST); + count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); + if (count) + { + if (!uj) + vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE); prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); } else @@ -13449,12 +13660,13 @@ DEFUN (show_ip_bgp_neighbor_damp, DEFUN (show_ip_bgp_ipv4_neighbor_routes, show_ip_bgp_ipv4_neighbor_routes_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -13463,16 +13675,18 @@ DEFUN (show_ip_bgp_ipv4_neighbor_routes, "JavaScript Object Notation\n") { struct peer *peer; - safi_t safi; u_char uj = use_json(argc, argv); peer = peer_lookup_in_view (vty, NULL, argv[1], uj); if (! peer) return CMD_WARNING; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_show_neighbor_route (vty, peer, AFI_IP, safi, - bgp_show_type_neighbor, uj); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST, + bgp_show_type_neighbor, uj); + + return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, + bgp_show_type_neighbor, uj); } #ifdef HAVE_IPV6 @@ -14678,6 +14892,8 @@ bgp_route_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd); install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd); @@ -14686,6 +14902,8 @@ bgp_route_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_prefix_pathtype_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd); @@ -14790,6 +15008,7 @@ bgp_route_init (void) install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd); + install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd); #ifdef HAVE_IPV6 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd); diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index d0cce4a955..ea42cb57c9 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -2342,6 +2342,63 @@ struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = #endif /* HAVE_IPV6 */ +/* `set vpnv4 nexthop A.B.C.D' */ + +static route_map_result_t +route_set_vpnv4_nexthop (void *rule, struct prefix *prefix, + route_map_object_t type, void *object) +{ + struct in_addr *address; + struct bgp_info *bgp_info; + + if (type == RMAP_BGP) + { + /* Fetch routemap's rule information. */ + address = rule; + bgp_info = object; + + /* Set next hop value. */ + (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address; + (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_len = 4; + } + + return RMAP_OKAY; +} + +static void * +route_set_vpnv4_nexthop_compile (const char *arg) +{ + int ret; + struct in_addr *address; + + address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); + + ret = inet_aton (arg, address); + + if (ret == 0) + { + XFREE (MTYPE_ROUTE_MAP_COMPILED, address); + return NULL; + } + + return address; +} + +static void +route_set_vpnv4_nexthop_free (void *rule) +{ + XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); +} + +/* Route map commands for ip nexthop set. */ +struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd = +{ + "vpnv4 next-hop", + route_set_vpnv4_nexthop, + route_set_vpnv4_nexthop_compile, + route_set_vpnv4_nexthop_free +}; + /* `set originator-id' */ /* For origin set. */ @@ -4443,6 +4500,40 @@ ALIAS (no_set_ipv6_nexthop_local, "IPv6 address of next hop\n") #endif /* HAVE_IPV6 */ +DEFUN (set_vpnv4_nexthop, + set_vpnv4_nexthop_cmd, + "set vpnv4 next-hop A.B.C.D", + SET_STR + "VPNv4 information\n" + "VPNv4 next-hop address\n" + "IP address of next hop\n") +{ + return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]); +} + +DEFUN (no_set_vpnv4_nexthop, + no_set_vpnv4_nexthop_cmd, + "no set vpnv4 next-hop", + NO_STR + SET_STR + "VPNv4 information\n" + "VPNv4 next-hop address\n") +{ + if (argc == 0) + return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL); + + return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]); +} + +ALIAS (no_set_vpnv4_nexthop, + no_set_vpnv4_nexthop_val_cmd, + "no set vpnv4 next-hop A.B.C.D", + NO_STR + SET_STR + "VPNv4 information\n" + "VPNv4 next-hop address\n" + "IP address of next hop\n") + DEFUN (set_originator_id, set_originator_id_cmd, "set originator-id A.B.C.D", @@ -4513,6 +4604,7 @@ bgp_route_map_init (void) route_map_install_set (&route_set_aggregator_as_cmd); route_map_install_set (&route_set_community_cmd); route_map_install_set (&route_set_community_delete_cmd); + route_map_install_set (&route_set_vpnv4_nexthop_cmd); route_map_install_set (&route_set_originator_id_cmd); route_map_install_set (&route_set_ecommunity_rt_cmd); route_map_install_set (&route_set_ecommunity_soo_cmd); @@ -4618,6 +4710,9 @@ bgp_route_map_init (void) install_element (RMAP_NODE, &set_ecommunity_soo_cmd); install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd); install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd); + install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd); + install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd); + install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd); install_element (RMAP_NODE, &set_originator_id_cmd); install_element (RMAP_NODE, &no_set_originator_id_cmd); install_element (RMAP_NODE, &no_set_originator_id_val_cmd); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index a27a5f6b26..b435543e39 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -107,33 +107,22 @@ bgp_node_safi (struct vty *vty) return safi; } -/* supports (ipv4|ipv6) */ -afi_t -bgp_vty_afi_from_arg(const char *afi_str) -{ - afi_t afi = AFI_MAX; /* unknown */ - if (!strcmp(afi_str, "ipv4")) { - afi = AFI_IP; - } -#ifdef HAVE_IPV6 - else if (!strcmp(afi_str, "ipv6")) { - afi = AFI_IP6; - } -#endif /* HAVE_IPV6 */ - return afi; -} - int bgp_parse_afi(const char *str, afi_t *afi) { - *afi = bgp_vty_afi_from_arg(str); - if (*afi != AFI_MAX) - return 0; - else + if (!strcmp(str, "ipv4")) { + *afi = AFI_IP; + return 0; + } +#ifdef HAVE_IPV6 + if (!strcmp(str, "ipv6")) { + *afi = AFI_IP6; + return 0; + } +#endif /* HAVE_IPV6 */ return -1; } - /* supports (unicast|multicast|vpn|encap) */ safi_t bgp_vty_safi_from_arg(const char *safi_str) @@ -146,7 +135,7 @@ bgp_vty_safi_from_arg(const char *safi_str) else if (strncmp (safi_str, "e", 1) == 0) safi = SAFI_ENCAP; else if (strncmp (safi_str, "v", 1) == 0) - safi = SAFI_MPLS_VPN; + safi = SAFI_MPLS_VPN; return safi; } @@ -370,8 +359,10 @@ bgp_clear_vty_error (struct vty *vty, struct peer *peer, afi_t afi, { case BGP_ERR_AF_UNCONFIGURED: vty_out (vty, - "%%BGP: Enable %s address family for the neighbor %s%s", - afi_safi_print(afi, safi), peer->host, VTY_NEWLINE); + "%%BGP: Enable %s %s address family for the neighbor %s%s", + afi == AFI_IP6 ? "IPv6" : safi == SAFI_MPLS_VPN ? "VPNv4" : "IPv4", + safi == SAFI_MULTICAST ? "Multicast" : "Unicast", + peer->host, VTY_NEWLINE); break; case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED: vty_out (vty, "%%BGP: Inbound soft reconfig for %s not possible as it%s has neither refresh capability, nor inbound soft reconfig%s", peer->host, VTY_NEWLINE, VTY_NEWLINE); @@ -6066,10 +6057,9 @@ DEFUN (address_family_ipv4, DEFUN (address_family_ipv4_safi, address_family_ipv4_safi_cmd, - "address-family ipv4 "BGP_SAFI_CMD_STR, + "address-family ipv4 (unicast|multicast)", "Enter Address Family command mode\n" - "Address Family\n" - BGP_SAFI_HELP_STR) + AFI_SAFI_STR) { switch (bgp_vty_safi_from_arg(argv[0])) { @@ -6103,28 +6093,16 @@ DEFUN (address_family_ipv6, DEFUN (address_family_ipv6_safi, address_family_ipv6_safi_cmd, - "address-family ipv6 "BGP_SAFI_CMD_STR, + "address-family ipv6 (unicast|multicast)", "Enter Address Family command mode\n" - "Address Family\n" - BGP_SAFI_HELP_STR) + "Address family\n" + "Address Family modifier\n" + "Address Family modifier\n") { - int idx_safi = 0; - switch (bgp_vty_safi_from_arg(argv[idx_safi])) - { - case SAFI_MULTICAST: - vty->node = BGP_IPV6M_NODE; - break; - case SAFI_ENCAP: - vty->node = BGP_ENCAPV6_NODE; - break; - case SAFI_MPLS_VPN: - vty->node = BGP_VPNV6_NODE; - break; - case SAFI_UNICAST: - default: - vty->node = BGP_IPV6_NODE; - break; - } + if (strncmp (argv[0], "m", 1) == 0) + vty->node = BGP_IPV6M_NODE; + else + vty->node = BGP_IPV6_NODE; return CMD_SUCCESS; } @@ -6139,6 +6117,13 @@ DEFUN (address_family_vpnv4, return CMD_SUCCESS; } +ALIAS (address_family_vpnv4, + address_family_vpnv4_unicast_cmd, + "address-family vpnv4 unicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family Modifier\n") + DEFUN (address_family_vpnv6, address_family_vpnv6_cmd, "address-family vpnv6", @@ -6149,6 +6134,13 @@ DEFUN (address_family_vpnv6, return CMD_SUCCESS; } +ALIAS (address_family_vpnv6, + address_family_vpnv6_unicast_cmd, + "address-family vpnv6 unicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family Modifier\n") + DEFUN (address_family_encap, address_family_encap_cmd, "address-family encap", @@ -6659,63 +6651,125 @@ ALIAS (clear_ip_bgp_all_soft_out, DEFUN (clear_ip_bgp_all_ipv4_soft_out, clear_ip_bgp_all_ipv4_soft_out_cmd, - "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp * ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_all, - BGP_CLEAR_SOFT_OUT, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all, + BGP_CLEAR_SOFT_OUT, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, + BGP_CLEAR_SOFT_OUT, NULL); } DEFUN (clear_ip_bgp_instance_all_ipv4_soft_out, clear_ip_bgp_instance_all_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[2]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_all, + if (strncmp (argv[2], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all, + BGP_CLEAR_SOFT_OUT, NULL); + + return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all, BGP_CLEAR_SOFT_OUT, NULL); } ALIAS (clear_ip_bgp_all_ipv4_soft_out, clear_ip_bgp_all_ipv4_out_cmd, - "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp * ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_all_ipv4_soft_out, clear_ip_bgp_instance_all_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) +DEFUN (clear_ip_bgp_all_vpnv4_soft_out, + clear_ip_bgp_all_vpnv4_soft_out_cmd, + "clear ip bgp * vpnv4 unicast soft out", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_STR + BGP_SOFT_OUT_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_all, + BGP_CLEAR_SOFT_OUT, NULL); +} + +ALIAS (clear_ip_bgp_all_vpnv4_soft_out, + clear_ip_bgp_all_vpnv4_out_cmd, + "clear ip bgp * vpnv4 unicast out", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_OUT_STR) + +DEFUN (clear_ip_bgp_all_encap_soft_out, + clear_ip_bgp_all_encap_soft_out_cmd, + "clear ip bgp * encap unicast soft out", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig\n" + "Soft reconfig outbound update\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_all, + BGP_CLEAR_SOFT_OUT, NULL); +} + +ALIAS (clear_ip_bgp_all_encap_soft_out, + clear_ip_bgp_all_encap_out_cmd, + "clear ip bgp * encap unicast out", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig outbound update\n") + DEFUN (clear_bgp_all_soft_out, clear_bgp_all_soft_out_cmd, "clear bgp * soft out", @@ -6802,7 +6856,7 @@ ALIAS (clear_bgp_all_soft_out, DEFUN (clear_bgp_ipv6_safi_prefix, clear_bgp_ipv6_safi_prefix_cmd, - "clear bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M", + "clear bgp ipv6 (unicast|multicast) prefix X:X::X:X/M", CLEAR_STR BGP_STR "Address family\n" @@ -6810,14 +6864,15 @@ DEFUN (clear_bgp_ipv6_safi_prefix, "Clear bestpath and re-advertise\n" "IPv6 prefix /, e.g., 3ffe::/16\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_prefix (vty, NULL, argv[1], AFI_IP6, safi, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_prefix (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL); + else + return bgp_clear_prefix (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL); } DEFUN (clear_bgp_instance_ipv6_safi_prefix, clear_bgp_instance_ipv6_safi_prefix_cmd, - "clear bgp " BGP_INSTANCE_CMD " ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M", + "clear bgp " BGP_INSTANCE_CMD " ipv6 (unicast|multicast) prefix X:X::X:X/M", CLEAR_STR BGP_STR BGP_INSTANCE_HELP_STR @@ -6826,9 +6881,10 @@ DEFUN (clear_bgp_instance_ipv6_safi_prefix, "Clear bestpath and re-advertise\n" "IPv6 prefix /, e.g., 3ffe::/16\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[2]); - return bgp_clear_prefix (vty, argv[1], argv[3], AFI_IP6, safi, NULL); + if (strncmp (argv[2], "m", 1) == 0) + return bgp_clear_prefix (vty, argv[1], argv[3], AFI_IP6, SAFI_MULTICAST, NULL); + else + return bgp_clear_prefix (vty, argv[1], argv[3], AFI_IP6, SAFI_UNICAST, NULL); } DEFUN (clear_ip_bgp_peer_soft_out, @@ -6885,26 +6941,29 @@ ALIAS (clear_ip_bgp_peer_soft_out, DEFUN (clear_ip_bgp_peer_ipv4_soft_out, clear_ip_bgp_peer_ipv4_soft_out_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_peer, - BGP_CLEAR_SOFT_OUT, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_peer, + BGP_CLEAR_SOFT_OUT, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_peer, + BGP_CLEAR_SOFT_OUT, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_ipv4_soft_out, clear_ip_bgp_instance_peer_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR @@ -6912,31 +6971,35 @@ DEFUN (clear_ip_bgp_instance_peer_ipv4_soft_out, "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_peer, - BGP_CLEAR_SOFT_OUT, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_peer, + BGP_CLEAR_SOFT_OUT, argv[2]); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_peer, + BGP_CLEAR_SOFT_OUT, argv[2]); } ALIAS (clear_ip_bgp_peer_ipv4_soft_out, clear_ip_bgp_peer_ipv4_out_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_out, clear_ip_bgp_instance_peer_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR @@ -6944,9 +7007,67 @@ ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_out, "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) +/* NOTE: WORD peers have not been tested for vpnv4 */ +DEFUN (clear_ip_bgp_peer_vpnv4_soft_out, + clear_ip_bgp_peer_vpnv4_soft_out_cmd, + "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast soft out", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "BGP neighbor on interface to clear\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_STR + BGP_SOFT_OUT_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_peer, + BGP_CLEAR_SOFT_OUT, argv[0]); +} + +ALIAS (clear_ip_bgp_peer_vpnv4_soft_out, + clear_ip_bgp_peer_vpnv4_out_cmd, + "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast out", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "BGP neighbor on interface to clear\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_OUT_STR) + +DEFUN (clear_ip_bgp_peer_encap_soft_out, + clear_ip_bgp_peer_encap_soft_out_cmd, + "clear ip bgp A.B.C.D encap unicast soft out", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig\n" + "Soft reconfig outbound update\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_peer, + BGP_CLEAR_SOFT_OUT, argv[0]); +} + +ALIAS (clear_ip_bgp_peer_encap_soft_out, + clear_ip_bgp_peer_encap_out_cmd, + "clear ip bgp A.B.C.D encap unicast out", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig outbound update\n") + DEFUN (clear_bgp_peer_soft_out, clear_bgp_peer_soft_out_cmd, "clear bgp (A.B.C.D|X:X::X:X|WORD) soft out", @@ -7101,26 +7222,29 @@ ALIAS (clear_ip_bgp_peer_group_soft_out, DEFUN (clear_ip_bgp_peer_group_ipv4_soft_out, clear_ip_bgp_peer_group_ipv4_soft_out_cmd, - "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp peer-group WORD ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_group, - BGP_CLEAR_SOFT_OUT, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_group, + BGP_CLEAR_SOFT_OUT, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_group, + BGP_CLEAR_SOFT_OUT, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft_out, clear_ip_bgp_instance_peer_group_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR @@ -7128,31 +7252,35 @@ DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft_out, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_group, - BGP_CLEAR_SOFT_OUT, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_group, + BGP_CLEAR_SOFT_OUT, argv[2]); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_group, + BGP_CLEAR_SOFT_OUT, argv[2]); } ALIAS (clear_ip_bgp_peer_group_ipv4_soft_out, clear_ip_bgp_peer_group_ipv4_out_cmd, - "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp peer-group WORD ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_peer_group_ipv4_soft_out, clear_ip_bgp_instance_peer_group_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR @@ -7160,7 +7288,8 @@ ALIAS (clear_ip_bgp_instance_peer_group_ipv4_soft_out, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) DEFUN (clear_bgp_peer_group_soft_out, @@ -7305,62 +7434,70 @@ ALIAS (clear_ip_bgp_external_soft_out, DEFUN (clear_ip_bgp_external_ipv4_soft_out, clear_ip_bgp_external_ipv4_soft_out_cmd, - "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp external ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_external, - BGP_CLEAR_SOFT_OUT, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_external, + BGP_CLEAR_SOFT_OUT, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_external, + BGP_CLEAR_SOFT_OUT, NULL); } DEFUN (clear_ip_bgp_instance_external_ipv4_soft_out, clear_ip_bgp_instance_external_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[2]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_external, - BGP_CLEAR_SOFT_OUT, NULL); + if (strncmp (argv[2], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_external, + BGP_CLEAR_SOFT_OUT, NULL); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_external, + BGP_CLEAR_SOFT_OUT, NULL); } ALIAS (clear_ip_bgp_external_ipv4_soft_out, clear_ip_bgp_external_ipv4_out_cmd, - "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp external ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_external_ipv4_soft_out, clear_ip_bgp_instance_external_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) DEFUN (clear_bgp_external_soft_out, @@ -7497,64 +7634,126 @@ ALIAS (clear_ip_bgp_as_soft_out, DEFUN (clear_ip_bgp_as_ipv4_soft_out, clear_ip_bgp_as_ipv4_soft_out_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_as, - BGP_CLEAR_SOFT_OUT, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_as, + BGP_CLEAR_SOFT_OUT, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_as, + BGP_CLEAR_SOFT_OUT, argv[0]); } DEFUN (clear_ip_bgp_instance_as_ipv4_soft_out, clear_ip_bgp_instance_as_ipv4_soft_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft out", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) soft out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_OUT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_as, - BGP_CLEAR_SOFT_OUT, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_as, + BGP_CLEAR_SOFT_OUT, argv[2]); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_as, + BGP_CLEAR_SOFT_OUT, argv[2]); } ALIAS (clear_ip_bgp_as_ipv4_soft_out, clear_ip_bgp_as_ipv4_out_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) ALIAS (clear_ip_bgp_instance_as_ipv4_soft_out, clear_ip_bgp_instance_as_ipv4_out_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" out", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) out", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_OUT_STR) +DEFUN (clear_ip_bgp_as_vpnv4_soft_out, + clear_ip_bgp_as_vpnv4_soft_out_cmd, + "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft out", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family modifier\n" + BGP_SOFT_STR + BGP_SOFT_OUT_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_as, + BGP_CLEAR_SOFT_OUT, argv[0]); +} + +ALIAS (clear_ip_bgp_as_vpnv4_soft_out, + clear_ip_bgp_as_vpnv4_out_cmd, + "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast out", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family modifier\n" + BGP_SOFT_OUT_STR) + +DEFUN (clear_ip_bgp_as_encap_soft_out, + clear_ip_bgp_as_encap_soft_out_cmd, + "clear ip bgp " CMD_AS_RANGE " encap unicast soft out", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family modifier\n" + "Soft reconfig\n" + "Soft reconfig outbound update\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_as, + BGP_CLEAR_SOFT_OUT, argv[0]); +} + +ALIAS (clear_ip_bgp_as_encap_soft_out, + clear_ip_bgp_as_encap_out_cmd, + "clear ip bgp " CMD_AS_RANGE " encap unicast out", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family modifier\n" + "Soft reconfig outbound update\n") + DEFUN (clear_bgp_as_soft_out, clear_bgp_as_soft_out_cmd, "clear bgp " CMD_AS_RANGE " soft out", @@ -7708,82 +7907,147 @@ DEFUN (clear_ip_bgp_all_in_prefix_filter, DEFUN (clear_ip_bgp_all_ipv4_soft_in, clear_ip_bgp_all_ipv4_soft_in_cmd, - "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp * ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_all, - BGP_CLEAR_SOFT_IN, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all, + BGP_CLEAR_SOFT_IN, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, + BGP_CLEAR_SOFT_IN, NULL); } DEFUN (clear_ip_bgp_instance_all_ipv4_soft_in, clear_ip_bgp_instance_all_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[2]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_all, + if (strncmp (argv[2], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all, + BGP_CLEAR_SOFT_IN, NULL); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_all, BGP_CLEAR_SOFT_IN, NULL); } ALIAS (clear_ip_bgp_all_ipv4_soft_in, clear_ip_bgp_all_ipv4_in_cmd, - "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp * ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_all_ipv4_soft_in, clear_ip_bgp_instance_all_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_all_ipv4_in_prefix_filter, clear_ip_bgp_all_ipv4_in_prefix_filter_cmd, - "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", + "clear ip bgp * ipv4 (unicast|multicast) in prefix-filter", CLEAR_STR IP_STR BGP_STR "Clear all peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_all, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); } +DEFUN (clear_ip_bgp_all_vpnv4_soft_in, + clear_ip_bgp_all_vpnv4_soft_in_cmd, + "clear ip bgp * vpnv4 unicast soft in", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_STR + BGP_SOFT_IN_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_all, + BGP_CLEAR_SOFT_IN, NULL); +} + +ALIAS (clear_ip_bgp_all_vpnv4_soft_in, + clear_ip_bgp_all_vpnv4_in_cmd, + "clear ip bgp * vpnv4 unicast in", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_IN_STR) + +DEFUN (clear_ip_bgp_all_encap_soft_in, + clear_ip_bgp_all_encap_soft_in_cmd, + "clear ip bgp * encap unicast soft in", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig\n" + "Soft reconfig inbound update\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_all, + BGP_CLEAR_SOFT_IN, NULL); +} + +ALIAS (clear_ip_bgp_all_encap_soft_in, + clear_ip_bgp_all_encap_in_cmd, + "clear ip bgp * encap unicast in", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig inbound update\n") + DEFUN (clear_bgp_all_soft_in, clear_bgp_all_soft_in_cmd, "clear bgp * soft in", @@ -7960,26 +8224,29 @@ DEFUN (clear_ip_bgp_peer_in_prefix_filter, DEFUN (clear_ip_bgp_peer_ipv4_soft_in, clear_ip_bgp_peer_ipv4_soft_in_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_peer, - BGP_CLEAR_SOFT_IN, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_peer, + BGP_CLEAR_SOFT_IN, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_peer, + BGP_CLEAR_SOFT_IN, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_ipv4_soft_in, clear_ip_bgp_instance_peer_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR @@ -7987,31 +8254,35 @@ DEFUN (clear_ip_bgp_instance_peer_ipv4_soft_in, "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_peer, - BGP_CLEAR_SOFT_IN, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_peer, + BGP_CLEAR_SOFT_IN, argv[2]); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_peer, + BGP_CLEAR_SOFT_IN, argv[2]); } ALIAS (clear_ip_bgp_peer_ipv4_soft_in, clear_ip_bgp_peer_ipv4_in_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_in, clear_ip_bgp_instance_peer_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR @@ -8019,28 +8290,88 @@ ALIAS (clear_ip_bgp_instance_peer_ipv4_soft_in, "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_peer_ipv4_in_prefix_filter, clear_ip_bgp_peer_ipv4_in_prefix_filter_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", + "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) in prefix-filter", CLEAR_STR IP_STR BGP_STR "BGP neighbor address to clear\n" "BGP neighbor on interface to clear\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR "Push out the existing ORF prefix-list\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_peer, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_peer, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_peer, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } +DEFUN (clear_ip_bgp_peer_vpnv4_soft_in, + clear_ip_bgp_peer_vpnv4_soft_in_cmd, + "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast soft in", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "BGP neighbor on interface to clear\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_STR + BGP_SOFT_IN_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_peer, + BGP_CLEAR_SOFT_IN, argv[0]); +} + +ALIAS (clear_ip_bgp_peer_vpnv4_soft_in, + clear_ip_bgp_peer_vpnv4_in_cmd, + "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast in", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "BGP neighbor on interface to clear\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_IN_STR) + +DEFUN (clear_ip_bgp_peer_encap_soft_in, + clear_ip_bgp_peer_encap_soft_in_cmd, + "clear ip bgp A.B.C.D encap unicast soft in", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig\n" + "Soft reconfig inbound update\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_peer, + BGP_CLEAR_SOFT_IN, argv[0]); +} + +ALIAS (clear_ip_bgp_peer_encap_soft_in, + clear_ip_bgp_peer_encap_in_cmd, + "clear ip bgp A.B.C.D encap unicast in", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig inbound update\n") + DEFUN (clear_bgp_peer_soft_in, clear_bgp_peer_soft_in_cmd, "clear bgp (A.B.C.D|X:X::X:X|WORD) soft in", @@ -8237,26 +8568,29 @@ DEFUN (clear_ip_bgp_peer_group_in_prefix_filter, DEFUN (clear_ip_bgp_peer_group_ipv4_soft_in, clear_ip_bgp_peer_group_ipv4_soft_in_cmd, - "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp peer-group WORD ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_group, - BGP_CLEAR_SOFT_IN, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_group, + BGP_CLEAR_SOFT_IN, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_group, + BGP_CLEAR_SOFT_IN, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft_in, clear_ip_bgp_instance_peer_group_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR @@ -8264,31 +8598,35 @@ DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft_in, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_group, - BGP_CLEAR_SOFT_IN, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_group, + BGP_CLEAR_SOFT_IN, argv[2]); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_group, + BGP_CLEAR_SOFT_IN, argv[2]); } ALIAS (clear_ip_bgp_peer_group_ipv4_soft_in, clear_ip_bgp_peer_group_ipv4_in_cmd, - "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp peer-group WORD ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_peer_group_ipv4_soft_in, clear_ip_bgp_instance_peer_group_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR @@ -8296,26 +8634,30 @@ ALIAS (clear_ip_bgp_instance_peer_group_ipv4_soft_in, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_peer_group_ipv4_in_prefix_filter, clear_ip_bgp_peer_group_ipv4_in_prefix_filter_cmd, - "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", + "clear ip bgp peer-group WORD ipv4 (unicast|multicast) in prefix-filter", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_group, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_group, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_group, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } DEFUN (clear_bgp_peer_group_soft_in, @@ -8499,80 +8841,91 @@ DEFUN (clear_ip_bgp_external_in_prefix_filter, DEFUN (clear_ip_bgp_external_ipv4_soft_in, clear_ip_bgp_external_ipv4_soft_in_cmd, - "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp external ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_external, - BGP_CLEAR_SOFT_IN, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_external, + BGP_CLEAR_SOFT_IN, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_external, + BGP_CLEAR_SOFT_IN, NULL); } DEFUN (clear_ip_bgp_instance_external_ipv4_soft_in, clear_ip_bgp_instance_external_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[2]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_external, - BGP_CLEAR_SOFT_IN, NULL); + if (strncmp (argv[2], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_external, + BGP_CLEAR_SOFT_IN, NULL); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_external, + BGP_CLEAR_SOFT_IN, NULL); } ALIAS (clear_ip_bgp_external_ipv4_soft_in, clear_ip_bgp_external_ipv4_in_cmd, - "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp external ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_external_ipv4_soft_in, clear_ip_bgp_instance_external_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_external_ipv4_in_prefix_filter, clear_ip_bgp_external_ipv4_in_prefix_filter_cmd, - "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", + "clear ip bgp external ipv4 (unicast|multicast) in prefix-filter", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_external, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_external, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_external, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL); } DEFUN (clear_bgp_external_soft_in, @@ -8746,82 +9099,147 @@ DEFUN (clear_ip_bgp_as_in_prefix_filter, DEFUN (clear_ip_bgp_as_ipv4_soft_in, clear_ip_bgp_as_ipv4_soft_in_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_as, - BGP_CLEAR_SOFT_IN, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_as, + BGP_CLEAR_SOFT_IN, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_as, + BGP_CLEAR_SOFT_IN, argv[0]); } DEFUN (clear_ip_bgp_instance_as_ipv4_soft_in, clear_ip_bgp_instance_as_ipv4_soft_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft in", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) soft in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR BGP_SOFT_IN_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_as, - BGP_CLEAR_SOFT_IN, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_as, + BGP_CLEAR_SOFT_IN, argv[2]); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_as, + BGP_CLEAR_SOFT_IN, argv[2]); } ALIAS (clear_ip_bgp_as_ipv4_soft_in, clear_ip_bgp_as_ipv4_in_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) ALIAS (clear_ip_bgp_instance_as_ipv4_soft_in, clear_ip_bgp_instance_as_ipv4_in_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" in", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) in", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR) DEFUN (clear_ip_bgp_as_ipv4_in_prefix_filter, clear_ip_bgp_as_ipv4_in_prefix_filter_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" in prefix-filter", + "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) in prefix-filter", CLEAR_STR IP_STR BGP_STR "Clear peers with the AS number\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n") { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_as, - BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_as, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_as, + BGP_CLEAR_SOFT_IN_ORF_PREFIX, argv[0]); } +DEFUN (clear_ip_bgp_as_vpnv4_soft_in, + clear_ip_bgp_as_vpnv4_soft_in_cmd, + "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft in", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family modifier\n" + BGP_SOFT_STR + BGP_SOFT_IN_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_as, + BGP_CLEAR_SOFT_IN, argv[0]); +} + +ALIAS (clear_ip_bgp_as_vpnv4_soft_in, + clear_ip_bgp_as_vpnv4_in_cmd, + "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast in", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family modifier\n" + BGP_SOFT_IN_STR) + +DEFUN (clear_ip_bgp_as_encap_soft_in, + clear_ip_bgp_as_encap_soft_in_cmd, + "clear ip bgp " CMD_AS_RANGE " encap unicast soft in", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family modifier\n" + "Soft reconfig\n" + "Soft reconfig inbound update\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_as, + BGP_CLEAR_SOFT_IN, argv[0]); +} + +ALIAS (clear_ip_bgp_as_encap_soft_in, + clear_ip_bgp_as_encap_in_cmd, + "clear ip bgp " CMD_AS_RANGE " encap unicast in", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family modifier\n" + "Soft reconfig inbound update\n") + DEFUN (clear_bgp_as_soft_in, clear_bgp_as_soft_in_cmd, "clear bgp " CMD_AS_RANGE " soft in", @@ -8960,7 +9378,7 @@ ALIAS (clear_ip_bgp_all_soft, DEFUN (clear_ip_bgp_all_ipv4_soft, clear_ip_bgp_all_ipv4_soft_cmd, - "clear ip bgp * ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp * ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR @@ -8970,15 +9388,17 @@ DEFUN (clear_ip_bgp_all_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_all, - BGP_CLEAR_SOFT_BOTH, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all, + BGP_CLEAR_SOFT_BOTH, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, + BGP_CLEAR_SOFT_BOTH, NULL); } DEFUN (clear_ip_bgp_instance_all_ipv4_soft, clear_ip_bgp_instance_all_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp " BGP_INSTANCE_CMD " * ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR @@ -8989,12 +9409,44 @@ DEFUN (clear_ip_bgp_instance_all_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[2]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_all, + if (strncmp (argv[2], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all, + BGP_CLEAR_SOFT_BOTH, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all, BGP_CLEAR_SOFT_BOTH, NULL); } +DEFUN (clear_ip_bgp_all_vpnv4_soft, + clear_ip_bgp_all_vpnv4_soft_cmd, + "clear ip bgp * vpnv4 unicast soft", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_all, + BGP_CLEAR_SOFT_BOTH, argv[0]); +} + +DEFUN (clear_ip_bgp_all_encap_soft, + clear_ip_bgp_all_encap_soft_cmd, + "clear ip bgp * encap unicast soft", + CLEAR_STR + IP_STR + BGP_STR + "Clear all peers\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_all, + BGP_CLEAR_SOFT_BOTH, argv[0]); +} + DEFUN (clear_bgp_all_soft, clear_bgp_all_soft_cmd, "clear bgp * soft", @@ -9070,7 +9522,7 @@ ALIAS (clear_ip_bgp_peer_soft, DEFUN (clear_ip_bgp_peer_ipv4_soft, clear_ip_bgp_peer_ipv4_soft_cmd, - "clear ip bgp (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp (A.B.C.D|WORD) ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR @@ -9081,15 +9533,17 @@ DEFUN (clear_ip_bgp_peer_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_peer, - BGP_CLEAR_SOFT_BOTH, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_peer, + BGP_CLEAR_SOFT_BOTH, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_peer, + BGP_CLEAR_SOFT_BOTH, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_ipv4_soft, clear_ip_bgp_instance_peer_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp " BGP_INSTANCE_CMD " (A.B.C.D|WORD) ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR @@ -9101,10 +9555,43 @@ DEFUN (clear_ip_bgp_instance_peer_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_peer, - BGP_CLEAR_SOFT_BOTH, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_peer, + BGP_CLEAR_SOFT_BOTH, argv[2]); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_peer, + BGP_CLEAR_SOFT_BOTH, argv[2]); +} + +DEFUN (clear_ip_bgp_peer_vpnv4_soft, + clear_ip_bgp_peer_vpnv4_soft_cmd, + "clear ip bgp (A.B.C.D|WORD) vpnv4 unicast soft", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "BGP neighbor on interface to clear\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_peer, + BGP_CLEAR_SOFT_BOTH, argv[0]); +} + +DEFUN (clear_ip_bgp_peer_encap_soft, + clear_ip_bgp_peer_encap_soft_cmd, + "clear ip bgp A.B.C.D encap unicast soft", + CLEAR_STR + IP_STR + BGP_STR + "BGP neighbor address to clear\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_peer, + BGP_CLEAR_SOFT_BOTH, argv[0]); } DEFUN (clear_bgp_peer_soft, @@ -9190,25 +9677,28 @@ ALIAS (clear_ip_bgp_peer_group_soft, DEFUN (clear_ip_bgp_peer_group_ipv4_soft, clear_ip_bgp_peer_group_ipv4_soft_cmd, - "clear ip bgp peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp peer-group WORD ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_group, - BGP_CLEAR_SOFT_BOTH, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_group, + BGP_CLEAR_SOFT_BOTH, argv[0]); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_group, + BGP_CLEAR_SOFT_BOTH, argv[0]); } DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft, clear_ip_bgp_instance_peer_group_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp " BGP_INSTANCE_CMD " peer-group WORD ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR @@ -9216,13 +9706,16 @@ DEFUN (clear_ip_bgp_instance_peer_group_ipv4_soft, "Clear all members of peer-group\n" "BGP peer-group name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_group, - BGP_CLEAR_SOFT_BOTH, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_group, + BGP_CLEAR_SOFT_BOTH, argv[2]); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_group, + BGP_CLEAR_SOFT_BOTH, argv[2]); } DEFUN (clear_bgp_peer_group_soft, @@ -9302,37 +9795,43 @@ ALIAS (clear_ip_bgp_external_soft, DEFUN (clear_ip_bgp_external_ipv4_soft, clear_ip_bgp_external_ipv4_soft_cmd, - "clear ip bgp external ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp external ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[0]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_external, - BGP_CLEAR_SOFT_BOTH, NULL); + if (strncmp (argv[0], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_external, + BGP_CLEAR_SOFT_BOTH, NULL); + + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_external, + BGP_CLEAR_SOFT_BOTH, NULL); } DEFUN (clear_ip_bgp_instance_external_ipv4_soft, clear_ip_bgp_instance_external_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp " BGP_INSTANCE_CMD " external ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Clear all external peers\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[2]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_external, + if (strncmp (argv[2], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_external, BGP_CLEAR_SOFT_BOTH, NULL); + + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_external, + BGP_CLEAR_SOFT_BOTH, NULL); } DEFUN (clear_bgp_external_soft, @@ -9408,7 +9907,7 @@ ALIAS (clear_ip_bgp_as_soft, DEFUN (clear_ip_bgp_as_ipv4_soft, clear_ip_bgp_as_ipv4_soft_cmd, - "clear ip bgp " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp " CMD_AS_RANGE " ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR @@ -9418,15 +9917,17 @@ DEFUN (clear_ip_bgp_as_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_clear_vty (vty, NULL, AFI_IP, safi, clear_as, - BGP_CLEAR_SOFT_BOTH, argv[0]); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_as, + BGP_CLEAR_SOFT_BOTH, argv[0]); + + return bgp_clear_vty (vty, NULL,AFI_IP, SAFI_UNICAST, clear_as, + BGP_CLEAR_SOFT_BOTH, argv[0]); } DEFUN (clear_ip_bgp_instance_as_ipv4_soft, clear_ip_bgp_instance_as_ipv4_soft_cmd, - "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 "BGP_SAFI_CMD_STR" soft", + "clear ip bgp " BGP_INSTANCE_CMD " " CMD_AS_RANGE " ipv4 (unicast|multicast) soft", CLEAR_STR IP_STR BGP_STR @@ -9437,10 +9938,42 @@ DEFUN (clear_ip_bgp_instance_as_ipv4_soft, "Address Family Modifier\n" BGP_SOFT_STR) { - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[3]); - return bgp_clear_vty (vty, argv[1], AFI_IP, safi, clear_as, - BGP_CLEAR_SOFT_BOTH, argv[2]); + if (strncmp (argv[3], "m", 1) == 0) + return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_as, + BGP_CLEAR_SOFT_BOTH, argv[2]); + + return bgp_clear_vty (vty, argv[1],AFI_IP, SAFI_UNICAST, clear_as, + BGP_CLEAR_SOFT_BOTH, argv[2]); +} + +DEFUN (clear_ip_bgp_as_vpnv4_soft, + clear_ip_bgp_as_vpnv4_soft_cmd, + "clear ip bgp " CMD_AS_RANGE " vpnv4 unicast soft", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family Modifier\n" + BGP_SOFT_STR) +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, clear_as, + BGP_CLEAR_SOFT_BOTH, argv[0]); +} + +DEFUN (clear_ip_bgp_as_encap_soft, + clear_ip_bgp_as_encap_soft_cmd, + "clear ip bgp " CMD_AS_RANGE " encap unicast soft", + CLEAR_STR + IP_STR + BGP_STR + "Clear peers with the AS number\n" + "Address family\n" + "Address Family Modifier\n" + "Soft reconfig\n") +{ + return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_ENCAP, clear_as, + BGP_CLEAR_SOFT_BOTH, argv[0]); } DEFUN (clear_bgp_as_soft, @@ -10101,10 +10634,10 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi, { if (use_json) vty_out(vty, "{\"error\": {\"message\": \"No %s neighbor configured\"}}%s", - afi_safi_print(afi, safi), VTY_NEWLINE); + afi == AFI_IP ? "IPv4" : "IPv6", VTY_NEWLINE); else vty_out (vty, "No %s neighbor is configured%s", - afi_safi_print(afi, safi), VTY_NEWLINE); + afi == AFI_IP ? "IPv4" : "IPv6", VTY_NEWLINE); } if (dn_count && ! use_json) @@ -10119,62 +10652,6 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi, return CMD_SUCCESS; } -static void -bgp_show_summary_afi_safi (struct vty *vty, struct bgp *bgp, int afi, int safi, - u_char use_json, json_object *json) -{ - int is_first = 1; - int afi_wildcard = (afi == AFI_MAX); - int safi_wildcard = (safi == SAFI_MAX); - int is_wildcard = (afi_wildcard || safi_wildcard); - if (use_json && is_wildcard) - vty_out (vty, "{%s", VTY_NEWLINE); - if (afi_wildcard) - afi = 1; /* AFI_IP */ - while (afi < AFI_MAX) - { - if (safi_wildcard) - safi = 1; /* SAFI_UNICAST */ - while (safi < SAFI_MAX) - { - if (is_wildcard) - { - if (use_json) - { - json = json_object_new_object(); - - if (! is_first) - vty_out (vty, ",%s", VTY_NEWLINE); - else - is_first = 0; - - vty_out(vty, "\"%s\":", afi_safi_json(afi, safi)); - } - else - { - vty_out (vty, "%s%s Summary:%s", - VTY_NEWLINE, afi_safi_print(afi, safi), VTY_NEWLINE); - } - } - bgp_show_summary (vty, bgp, afi, safi, use_json, json); - if (safi == SAFI_MPLS_VPN) /* handle special cases to match zebra.h */ - safi = SAFI_ENCAP; - else - safi++; - if (! safi_wildcard) - safi = SAFI_MAX; - } - afi++; - if (! afi_wildcard || - afi == AFI_ETHER) /* special case, not handled yet */ - afi = AFI_MAX; - } - - if (use_json && is_wildcard) - vty_out (vty, "}%s", VTY_NEWLINE); - -} - static int bgp_show_summary_vty (struct vty *vty, const char *name, afi_t afi, safi_t safi, u_char use_json) @@ -10191,14 +10668,14 @@ bgp_show_summary_vty (struct vty *vty, const char *name, return CMD_WARNING; } - bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL); + bgp_show_summary (vty, bgp, afi, safi, use_json, NULL); return CMD_SUCCESS; } bgp = bgp_get_default (); if (bgp) - bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL); + bgp_show_summary (vty, bgp, afi, safi, use_json, NULL); return CMD_SUCCESS; } @@ -10243,7 +10720,7 @@ bgp_show_all_instances_summary_vty (struct vty *vty, afi_t afi, safi_t safi, (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) ? "Default" : bgp->name, VTY_NEWLINE); } - bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, json); + bgp_show_summary (vty, bgp, afi, safi, use_json, json); } if (use_json) @@ -10262,7 +10739,7 @@ DEFUN (show_ip_bgp_summary, "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_MAX, uj); + return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_UNICAST, uj); } DEFUN (show_ip_bgp_instance_summary, @@ -10276,7 +10753,7 @@ DEFUN (show_ip_bgp_instance_summary, "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - return bgp_show_summary_vty (vty, argv[1], AFI_IP, SAFI_MAX, uj); + return bgp_show_summary_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, uj); } DEFUN (show_ip_bgp_instance_all_summary, @@ -10291,18 +10768,17 @@ DEFUN (show_ip_bgp_instance_all_summary, { u_char uj = use_json(argc, argv); - bgp_show_all_instances_summary_vty (vty, AFI_IP, SAFI_MAX, uj); + bgp_show_all_instances_summary_vty (vty, AFI_IP, SAFI_UNICAST, uj); return CMD_SUCCESS; } DEFUN (show_ip_bgp_ipv4_summary, show_ip_bgp_ipv4_summary_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" summary {json}", + "show ip bgp ipv4 (unicast|multicast|vpn|encap) summary {json}", SHOW_STR IP_STR BGP_STR - "Address family\n" - BGP_SAFI_HELP_STR + AFI_SAFI_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { @@ -10313,42 +10789,84 @@ DEFUN (show_ip_bgp_ipv4_summary, ALIAS (show_ip_bgp_ipv4_summary, show_bgp_ipv4_safi_summary_cmd, - "show bgp ipv4 "BGP_SAFI_CMD_STR" summary {json}", + "show bgp ipv4 (unicast|multicast|vpn|encap) summary {json}", SHOW_STR BGP_STR - "Address family\n" - BGP_SAFI_HELP_STR + AFI_SAFI_STR "Summary of BGP neighbor status\n") DEFUN (show_ip_bgp_instance_ipv4_summary, show_ip_bgp_instance_ipv4_summary_cmd, - "show ip bgp view WORD ipv4 "BGP_SAFI_CMD_STR" summary {json}", + "show ip bgp view WORD ipv4 (unicast|multicast) summary {json}", SHOW_STR IP_STR BGP_STR "BGP view\n" "View name\n" "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[1]); - return bgp_show_summary_vty (vty, argv[0], AFI_IP, safi, uj); + if (strncmp (argv[1], "m", 1) == 0) + return bgp_show_summary_vty (vty, argv[0], AFI_IP, SAFI_MULTICAST, uj); + else + return bgp_show_summary_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, uj); } ALIAS (show_ip_bgp_instance_ipv4_summary, show_bgp_instance_ipv4_safi_summary_cmd, - "show bgp view WORD ipv4 "BGP_SAFI_CMD_STR" summary {json}", + "show bgp view WORD ipv4 (unicast|multicast) summary {json}", SHOW_STR BGP_STR "BGP view\n" "View name\n" - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "Summary of BGP neighbor status\n") +DEFUN (show_ip_bgp_vpnv4_all_summary, + show_ip_bgp_vpnv4_all_summary_cmd, + "show ip bgp vpnv4 all summary {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information about all VPNv4 NLRIs\n" + "Summary of BGP neighbor status\n" + "JavaScript Object Notation\n") +{ + u_char uj = use_json(argc, argv); + return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, uj); +} + +DEFUN (show_ip_bgp_vpnv4_rd_summary, + show_ip_bgp_vpnv4_rd_summary_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn summary {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information for a route distinguisher\n" + "VPN Route Distinguisher\n" + "Summary of BGP neighbor status\n" + "JavaScript Object Notation\n") +{ + int ret; + struct prefix_rd prd; + u_char uj = use_json(argc, argv); + + ret = str2prefix_rd (argv[0], &prd); + if (! ret) + { + vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); + return CMD_WARNING; + } + + return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_MPLS_VPN, uj); +} + #ifdef HAVE_IPV6 DEFUN (show_bgp_summary, show_bgp_summary_cmd, @@ -10358,7 +10876,7 @@ DEFUN (show_bgp_summary, "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { - return bgp_show_summary_vty (vty, NULL, AFI_MAX, SAFI_MAX, use_json(argc, argv)); + return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_UNICAST, use_json(argc, argv)); } DEFUN (show_bgp_instance_summary, @@ -10370,7 +10888,7 @@ DEFUN (show_bgp_instance_summary, "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { - return bgp_show_summary_vty (vty, argv[1], AFI_MAX, SAFI_MAX, use_json(argc, argv)); + return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, use_json(argc, argv)); } DEFUN (show_bgp_instance_all_summary, @@ -10384,22 +10902,19 @@ DEFUN (show_bgp_instance_all_summary, { u_char uj = use_json(argc, argv); - bgp_show_all_instances_summary_vty (vty, AFI_MAX, SAFI_MAX, uj); + bgp_show_all_instances_summary_vty (vty, AFI_IP6, SAFI_UNICAST, uj); return CMD_SUCCESS; } -DEFUN (show_bgp_ipv6_summary, +ALIAS (show_bgp_summary, show_bgp_ipv6_summary_cmd, "show bgp ipv6 summary {json}", SHOW_STR BGP_STR "Address family\n" "Summary of BGP neighbor status\n") -{ - return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_MAX, use_json(argc, argv)); -} -DEFUN (show_bgp_instance_ipv6__summary, +ALIAS (show_bgp_instance_summary, show_bgp_instance_ipv6_summary_cmd, "show bgp " BGP_INSTANCE_CMD " ipv6 summary {json}", SHOW_STR @@ -10407,17 +10922,13 @@ DEFUN (show_bgp_instance_ipv6__summary, BGP_INSTANCE_HELP_STR "Address family\n" "Summary of BGP neighbor status\n") -{ - return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_MAX, use_json(argc, argv)); -} DEFUN (show_bgp_ipv6_safi_summary, show_bgp_ipv6_safi_summary_cmd, - "show bgp ipv6 "BGP_SAFI_CMD_STR" summary {json}", + "show bgp ipv6 (unicast|multicast|vpn|encap) summary {json}", SHOW_STR BGP_STR - "Address family\n" - BGP_SAFI_HELP_STR + AFI_SAFI_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { @@ -10428,18 +10939,19 @@ DEFUN (show_bgp_ipv6_safi_summary, DEFUN (show_bgp_instance_ipv6_safi_summary, show_bgp_instance_ipv6_safi_summary_cmd, - "show bgp " BGP_INSTANCE_CMD " ipv6 "BGP_SAFI_CMD_STR" summary {json}", + "show bgp " BGP_INSTANCE_CMD " ipv6 (unicast|multicast) summary {json}", SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "Summary of BGP neighbor status\n" "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - safi_t safi; - safi = bgp_vty_safi_from_arg(argv[2]); - return bgp_show_summary_vty (vty, argv[1], AFI_IP6, safi, uj); + if (strncmp (argv[2], "m", 1) == 0) + return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_MULTICAST, uj); + + return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, uj); } /* old command */ @@ -10453,7 +10965,7 @@ DEFUN (show_ipv6_bgp_summary, "JavaScript Object Notation\n") { u_char uj = use_json(argc, argv); - return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_MAX, uj); + return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_UNICAST, uj); } /* old command */ @@ -10479,40 +10991,17 @@ afi_safi_print (afi_t afi, safi_t safi) else if (afi == AFI_IP && safi == SAFI_MULTICAST) return "IPv4 Multicast"; else if (afi == AFI_IP && safi == SAFI_MPLS_VPN) - return "IPv4 VPN"; + return "VPN-IPv4 Unicast"; else if (afi == AFI_IP && safi == SAFI_ENCAP) - return "IPv4 Encap"; + return "ENCAP-IPv4 Unicast"; else if (afi == AFI_IP6 && safi == SAFI_UNICAST) return "IPv6 Unicast"; else if (afi == AFI_IP6 && safi == SAFI_MULTICAST) return "IPv6 Multicast"; else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN) - return "IPv6 VPN"; + return "VPN-IPv6 Unicast"; else if (afi == AFI_IP6 && safi == SAFI_ENCAP) - return "IPv6 Encap"; - else - return "Unknown"; -} - -const char * -afi_safi_json (afi_t afi, safi_t safi) -{ - if (afi == AFI_IP && safi == SAFI_UNICAST) - return "IPv4Unicast"; - else if (afi == AFI_IP && safi == SAFI_MULTICAST) - return "IPv4Multicast"; - else if (afi == AFI_IP && safi == SAFI_MPLS_VPN) - return "IPv4VPN"; - else if (afi == AFI_IP && safi == SAFI_ENCAP) - return "IPv4Encap"; - else if (afi == AFI_IP6 && safi == SAFI_UNICAST) - return "IPv6Unicast"; - else if (afi == AFI_IP6 && safi == SAFI_MULTICAST) - return "IPv6Multicast"; - else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN) - return "IPv6VPN"; - else if (afi == AFI_IP6 && safi == SAFI_ENCAP) - return "IPv6Encap"; + return "ENCAP-IPv6 Unicast"; else return "Unknown"; } @@ -12337,12 +12826,36 @@ DEFUN (show_ip_bgp_neighbors, ALIAS (show_ip_bgp_neighbors, show_ip_bgp_ipv4_neighbors_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" + "Detailed information on TCP and BGP neighbor connections\n" + "JavaScript Object Notation\n") + +ALIAS (show_ip_bgp_neighbors, + show_ip_bgp_vpnv4_all_neighbors_cmd, + "show ip bgp vpnv4 all neighbors {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information about all VPNv4 NLRIs\n" + "Detailed information on TCP and BGP neighbor connections\n" + "JavaScript Object Notation\n") + +ALIAS (show_ip_bgp_neighbors, + show_ip_bgp_vpnv4_rd_neighbors_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information for a route distinguisher\n" + "VPN Route Distinguisher\n" "Detailed information on TCP and BGP neighbor connections\n" "JavaScript Object Notation\n") @@ -12382,18 +12895,43 @@ DEFUN (show_ip_bgp_neighbors_peer, ALIAS (show_ip_bgp_neighbors_peer, show_ip_bgp_ipv4_neighbors_peer_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" neighbors (A.B.C.D|X:X::X:X|WORD) {json}", + "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) {json}", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" "Neighbor on bgp configured interface\n" "JavaScript Object Notation\n") +ALIAS (show_ip_bgp_neighbors_peer, + show_ip_bgp_vpnv4_all_neighbors_peer_cmd, + "show ip bgp vpnv4 all neighbors A.B.C.D {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information about all VPNv4 NLRIs\n" + "Detailed information on TCP and BGP neighbor connections\n" + "Neighbor to display information about\n" + "JavaScript Object Notation\n") + +ALIAS (show_ip_bgp_neighbors_peer, + show_ip_bgp_vpnv4_rd_neighbors_peer_cmd, + "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D {json}", + SHOW_STR + IP_STR + BGP_STR + "Display VPNv4 NLRI specific information\n" + "Display information about all VPNv4 NLRIs\n" + "Detailed information on TCP and BGP neighbor connections\n" + "Neighbor to display information about\n" + "JavaScript Object Notation\n") + ALIAS (show_ip_bgp_neighbors_peer, show_bgp_neighbors_peer_cmd, "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) {json}", @@ -12528,12 +13066,13 @@ DEFUN (show_ip_bgp_paths, DEFUN (show_ip_bgp_ipv4_paths, show_ip_bgp_ipv4_paths_cmd, - "show ip bgp ipv4 "BGP_SAFI_CMD_STR" paths", + "show ip bgp ipv4 (unicast|multicast) paths", SHOW_STR IP_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address Family modifier\n" + "Address Family modifier\n" "Path information\n") { vty_out (vty, "Address Refcnt Path\r\n"); @@ -12688,17 +13227,19 @@ DEFUN (show_bgp_instance_all_ipv6_updgrps, DEFUN (show_bgp_updgrps, show_bgp_updgrps_cmd, - "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups", + "show bgp (ipv4|ipv6) (unicast|multicast|vpn|encap) update-groups", SHOW_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + "Address family\n" + "Address Family modifier\n" + "Address Family modifier\n" "Detailed info about dynamic update groups\n") { afi_t afi; safi_t safi; - afi = bgp_vty_safi_from_arg(argv[0]); + afi = (strcmp(argv[0], "ipv4") == 0) ? AFI_IP : AFI_IP6; safi = bgp_vty_safi_from_arg(argv[1]); return (bgp_show_update_groups(vty, NULL, afi, safi, 0)); } @@ -12764,11 +13305,11 @@ DEFUN (show_bgp_instance_ipv6_updgrps_s, DEFUN (show_bgp_updgrps_s, show_bgp_updgrps_s_cmd, - "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID", + "show bgp (ipv4|ipv6) (unicast|multicast|vpn|encap) update-groups SUBGROUP-ID", SHOW_STR BGP_STR "Address family\n" - BGP_AFI_SAFI_HELP_STR + AFI_SAFI_STR "Detailed info about v6 dynamic update groups\n" "Specific subgroup to display detailed info for") { @@ -12776,7 +13317,7 @@ DEFUN (show_bgp_updgrps_s, safi_t safi; uint64_t subgrp_id; - afi = bgp_vty_safi_from_arg(argv[0]); + afi = (strcmp(argv[0], "ipv4") == 0) ? AFI_IP : AFI_IP6; safi = bgp_vty_safi_from_arg(argv[1]); VTY_GET_ULL("subgroup-id", subgrp_id, argv[2]); return(bgp_show_update_groups(vty, NULL, afi, safi, subgrp_id)); @@ -12875,11 +13416,11 @@ DEFUN (show_ip_bgp_instance_updgrps_adj, DEFUN (show_bgp_updgrps_afi_adj, show_bgp_updgrps_afi_adj_cmd, - "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups (advertise-queue|advertised-routes|packet-queue)", + "show bgp (ipv4|ipv6) (unicast|multicast|vpn|encap) update-groups (advertise-queue|advertised-routes|packet-queue)", SHOW_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + AFI_SAFI_STR "BGP update groups\n" "Advertisement queue\n" "Announced routes\n" @@ -12889,7 +13430,7 @@ DEFUN (show_bgp_updgrps_afi_adj, afi_t afi; safi_t safi; - afi = bgp_vty_safi_from_arg(argv[0]); + afi = (strcmp(argv[0], "ipv4") == 0) ? AFI_IP : AFI_IP6; safi = bgp_vty_safi_from_arg(argv[1]); show_bgp_updgrps_adj_info_aux(vty, NULL, afi, safi, argv[2], 0); return CMD_SUCCESS; @@ -12969,11 +13510,11 @@ DEFUN (show_ip_bgp_instance_updgrps_adj_s, DEFUN (show_bgp_updgrps_afi_adj_s, show_bgp_updgrps_afi_adj_s_cmd, - "show bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID (advertise-queue|advertised-routes|packet-queue)", + "show bgp (ipv4|ipv6) (unicast|multicast|vpn|encap) update-groups SUBGROUP-ID (advertise-queue|advertised-routes|packet-queue)", SHOW_STR BGP_STR "Address family\n" - BGP_SAFI_HELP_STR + AFI_SAFI_STR "BGP update groups\n" "Specific subgroup to display info for\n" "Advertisement queue\n" @@ -12985,7 +13526,7 @@ DEFUN (show_bgp_updgrps_afi_adj_s, safi_t safi; uint64_t subgrp_id; - afi = bgp_vty_safi_from_arg(argv[0]); + afi = (strcmp(argv[0], "ipv4") == 0) ? AFI_IP : AFI_IP6; safi = bgp_vty_safi_from_arg(argv[1]); VTY_GET_ULL("subgroup-id", subgrp_id, argv[2]); @@ -15095,7 +15636,11 @@ bgp_vty_init (void) install_element (BGP_NODE, &address_family_ipv6_safi_cmd); #endif /* HAVE_IPV6 */ install_element (BGP_NODE, &address_family_vpnv4_cmd); + install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); + install_element (BGP_NODE, &address_family_vpnv6_cmd); + install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd); + install_element (BGP_NODE, &address_family_encap_cmd); install_element (BGP_NODE, &address_family_encapv4_cmd); #ifdef HAVE_IPV6 @@ -15196,6 +15741,18 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_in_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_in_prefix_filter_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_soft_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_soft_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_in_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_in_cmd); install_element (ENABLE_NODE, &clear_bgp_all_soft_in_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_in_cmd); install_element (ENABLE_NODE, &clear_bgp_all_in_cmd); @@ -15294,6 +15851,18 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_soft_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_out_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_soft_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_soft_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_out_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_out_cmd); install_element (ENABLE_NODE, &clear_bgp_all_soft_out_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_out_cmd); install_element (ENABLE_NODE, &clear_bgp_all_out_cmd); @@ -15356,6 +15925,12 @@ bgp_vty_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_instance_external_ipv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_soft_cmd); install_element (ENABLE_NODE, &clear_ip_bgp_instance_as_ipv4_soft_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_all_encap_soft_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_peer_encap_soft_cmd); + install_element (ENABLE_NODE, &clear_ip_bgp_as_encap_soft_cmd); install_element (ENABLE_NODE, &clear_bgp_all_soft_cmd); install_element (ENABLE_NODE, &clear_bgp_instance_all_soft_cmd); install_element (ENABLE_NODE, &clear_bgp_peer_soft_cmd); @@ -15407,6 +15982,8 @@ bgp_vty_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_safi_summary_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_ipv4_summary_cmd); install_element (VIEW_NODE, &show_bgp_instance_ipv4_safi_summary_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_summary_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_summary_cmd); #ifdef HAVE_IPV6 install_element (VIEW_NODE, &show_bgp_summary_cmd); install_element (VIEW_NODE, &show_bgp_instance_summary_cmd); @@ -15422,6 +15999,10 @@ bgp_vty_init (void) install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_neighbors_peer_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbors_peer_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbors_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbors_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbors_peer_cmd); + install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbors_peer_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_all_neighbors_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_neighbors_peer_cmd); diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index e3a51ac450..6b4e51bc50 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -30,20 +30,15 @@ struct bgp; #define BGP_INSTANCE_ALL_CMD "(view|vrf) all" #define BGP_INSTANCE_ALL_HELP_STR "BGP view\nBGP VRF\nAll Views/VRFs\n" -#define BGP_AFI_CMD_STR "(ipv4|ipv6)" -#define BGP_AFI_HELP_STR "Address Family\nAddress Family\n" -#define BGP_SAFI_CMD_STR "(unicast|multicast|vpn|encap)" -#define BGP_SAFI_HELP_STR \ - "Address Family modifier\n" \ - "Address Family modifier\n" \ - "Address Family modifier\n" \ +#define AFI_SAFI_STR \ + "Address family\n" \ + "Address Family modifier\n" \ + "Address Family modifier\n" \ + "Address Family modifier\n" \ "Address Family modifier\n" -#define BGP_AFI_SAFI_CMD_STR BGP_AFI_CMD_STR" "BGP_SAFI_CMD_STR -#define BGP_AFI_SAFI_HELP_STR BGP_AFI_HELP_STR BGP_SAFI_HELP_STR extern void bgp_vty_init (void); extern const char *afi_safi_print (afi_t, safi_t); -extern const char *afi_safi_json (afi_t, safi_t); extern int bgp_config_write_update_delay (struct vty *, struct bgp *); extern int bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp); extern int bgp_config_write_listen(struct vty *vty, struct bgp *bgp); @@ -58,9 +53,6 @@ bgp_parse_afi(const char *str, afi_t *afi); extern int bgp_parse_safi(const char *str, safi_t *safi); -extern afi_t -bgp_vty_afi_from_arg(const char *afi_str); - extern safi_t bgp_vty_safi_from_arg(const char *safi_str);