diff options
Diffstat (limited to 'bgpd/bgp_vty.c')
-rw-r--r-- | bgpd/bgp_vty.c | 272 |
1 files changed, 159 insertions, 113 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 48d8ecbe..40efd6b8 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -57,9 +57,7 @@ extern struct in_addr router_id_zebra; afi_t bgp_node_afi (struct vty *vty) { - enum node_type node = vty_get_node(vty) ; - - if (node == BGP_IPV6_NODE || node == BGP_IPV6M_NODE) + if (vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE) return AFI_IP6; return AFI_IP; } @@ -69,11 +67,9 @@ bgp_node_afi (struct vty *vty) safi_t bgp_node_safi (struct vty *vty) { - enum node_type node = vty_get_node(vty) ; - - if (node == BGP_VPNV4_NODE) + if (vty->node == BGP_VPNV4_NODE) return SAFI_MPLS_VPN; - if (node == BGP_IPV4M_NODE || node == BGP_IPV6M_NODE) + if (vty->node == BGP_IPV4M_NODE || vty->node == BGP_IPV6M_NODE) return SAFI_MULTICAST; return SAFI_UNICAST; } @@ -323,12 +319,13 @@ DEFUN_DEPRECATED (neighbor_version, } /* "router bgp" commands. */ -DEFUN (router_bgp, - router_bgp_cmd, - "router bgp " CMD_AS_RANGE, - ROUTER_STR - BGP_STR - AS_STR) +DEFUN_ATTR (router_bgp, + router_bgp_cmd, + "router bgp " CMD_AS_RANGE, + ROUTER_STR + BGP_STR + AS_STR, + CMD_ATTR_NODE + BGP_NODE) { int ret; as_t as; @@ -347,9 +344,11 @@ DEFUN (router_bgp, vty_out (vty, "Please specify 'bgp multiple-instance' first%s", VTY_NEWLINE); return CMD_WARNING; + case BGP_ERR_AS_MISMATCH: vty_out (vty, "BGP is already running; AS is %u%s", as, VTY_NEWLINE); return CMD_WARNING; + case BGP_ERR_INSTANCE_MISMATCH: vty_out (vty, "BGP view name and AS number mismatch%s", VTY_NEWLINE); vty_out (vty, "BGP instance is already running; AS is %u%s", @@ -357,20 +356,21 @@ DEFUN (router_bgp, return CMD_WARNING; } - vty_set_node(vty, BGP_NODE) ; + vty->node = BGP_NODE ; vty->index = bgp; return CMD_SUCCESS; } -ALIAS (router_bgp, - router_bgp_view_cmd, - "router bgp " CMD_AS_RANGE " view WORD", - ROUTER_STR - BGP_STR - AS_STR - "BGP view\n" - "view name\n") +ALIAS_ATTR (router_bgp, + router_bgp_view_cmd, + "router bgp " CMD_AS_RANGE " view WORD", + ROUTER_STR + BGP_STR + AS_STR + "BGP view\n" + "view name\n", + CMD_ATTR_NODE + BGP_NODE) /* "no router bgp" commands. */ DEFUN (no_router_bgp, @@ -606,7 +606,7 @@ ALIAS (no_bgp_confederation_identifier, DEFUN (bgp_confederation_peers, bgp_confederation_peers_cmd, - "bgp confederation peers ." CMD_AS_RANGE, + "bgp confederation peers .ASs", "BGP specific commands\n" "AS confederation parameters\n" "Peer ASs in BGP confederation\n" @@ -636,7 +636,7 @@ DEFUN (bgp_confederation_peers, DEFUN (no_bgp_confederation_peers, no_bgp_confederation_peers_cmd, - "no bgp confederation peers ." CMD_AS_RANGE, + "no bgp confederation peers .ASs", NO_STR "BGP specific commands\n" "AS confederation parameters\n" @@ -4050,90 +4050,118 @@ DEFUN (no_neighbor_ttl_security, } /* Address family configuration. */ -DEFUN (address_family_ipv4, - address_family_ipv4_cmd, - "address-family ipv4", - "Enter Address Family command mode\n" - "Address family\n") -{ - vty_set_node(vty, BGP_IPV4_NODE) ; +DEFUN_ATTR (address_family_ipv4, + address_family_ipv4_cmd, + "address-family ipv4", + "Enter Address Family command mode\n" + "Address family\n", + CMD_ATTR_NODE + BGP_IPV4_NODE) +{ + vty->node = BGP_IPV4_NODE ; return CMD_SUCCESS; } -DEFUN (address_family_ipv4_safi, - address_family_ipv4_safi_cmd, - "address-family ipv4 (unicast|multicast)", - "Enter Address Family command mode\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n") +DEFUN_ATTR (address_family_ipv4_safi_unicast, + address_family_ipv4_safi_unicast_cmd, + "address-family ipv4 unicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family modifier\n", + CMD_ATTR_NODE + BGP_IPV4_NODE) { - if (strncmp (argv[0], "m", 1) == 0) - vty_set_node(vty, BGP_IPV4M_NODE) ; - else - vty_set_node(vty, BGP_IPV4_NODE) ; + vty->node = BGP_IPV4_NODE ; + return CMD_SUCCESS; +} +DEFUN_ATTR (address_family_ipv4_safi_multicast, + address_family_ipv4_safi_multicast_cmd, + "address-family ipv4 multicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family modifier\n", + CMD_ATTR_NODE + BGP_IPV4M_NODE) +{ + vty->node = BGP_IPV4M_NODE ; return CMD_SUCCESS; } -DEFUN (address_family_ipv6, - address_family_ipv6_cmd, - "address-family ipv6", - "Enter Address Family command mode\n" - "Address family\n") +DEFUN_ATTR (address_family_ipv6, + address_family_ipv6_cmd, + "address-family ipv6", + "Enter Address Family command mode\n" + "Address family\n", + CMD_ATTR_NODE + BGP_IPV6_NODE) { - vty_set_node(vty, BGP_IPV6_NODE) ; + vty->node = BGP_IPV6_NODE ; return CMD_SUCCESS; } -DEFUN (address_family_ipv6_safi, - address_family_ipv6_safi_cmd, - "address-family ipv6 (unicast|multicast)", - "Enter Address Family command mode\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n") +DEFUN_ATTR (address_family_ipv6_safi_unicast, + address_family_ipv6_safi_unicast_cmd, + "address-family ipv6 unicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family modifier\n", + CMD_ATTR_NODE + BGP_IPV6_NODE) { - if (strncmp (argv[0], "m", 1) == 0) - vty_set_node(vty, BGP_IPV6M_NODE) ; - else - vty_set_node(vty, BGP_IPV6_NODE) ; + vty->node = BGP_IPV6_NODE ; + return CMD_SUCCESS; +} +DEFUN_ATTR (address_family_ipv6_safi_multicast, + address_family_ipv6_safi_multicast_cmd, + "address-family ipv6 multicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family modifier\n", + CMD_ATTR_NODE + BGP_IPV6M_NODE) +{ + vty->node = BGP_IPV6M_NODE ; return CMD_SUCCESS; } -DEFUN (address_family_vpnv4, - address_family_vpnv4_cmd, - "address-family vpnv4", - "Enter Address Family command mode\n" - "Address family\n") +DEFUN_ATTR (address_family_vpnv4, + address_family_vpnv4_cmd, + "address-family vpnv4", + "Enter Address Family command mode\n" + "Address family\n", + CMD_ATTR_NODE + BGP_VPNV4_NODE) { - vty_set_node(vty, BGP_VPNV4_NODE) ; + vty->node = BGP_VPNV4_NODE ; return CMD_SUCCESS; } -ALIAS (address_family_vpnv4, +ALIAS_ATTR (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") + "Address Family Modifier\n", + CMD_ATTR_NODE + BGP_VPNV4_NODE) -DEFUN (exit_address_family, - exit_address_family_cmd, - "exit-address-family", - "Exit from Address Family configuration mode\n") +DEFUN_ATTR (exit_address_family, + exit_address_family_cmd, + "exit-address-family", + "Exit from Address Family configuration mode\n", + CMD_ATTR_NODE + BGP_NODE) { - enum node_type node = vty_get_node(vty) ; + node_type_t node = vty->node ; - if (node == BGP_IPV4_NODE + if ( node == BGP_IPV4_NODE || node == BGP_IPV4M_NODE || node == BGP_VPNV4_NODE || node == BGP_IPV6_NODE || node == BGP_IPV6M_NODE) - vty_set_node(vty, BGP_NODE); - return CMD_SUCCESS; -} + { + vty->node = BGP_NODE ; + return CMD_SUCCESS ; + } + else + { + vty_out(vty, "%% No address family to leave\n") ; + return CMD_WARNING ; + } ; +} ; /* BGP clear sort. */ typedef enum @@ -6651,52 +6679,55 @@ DEFUN (show_bgp_memory, BGP_STR "Global BGP memory statistics\n") { + mem_stats_t mst[1] ; char memstrbuf[MTYPE_MEMSTR_LEN]; unsigned long count; + mem_get_stats(mst) ; + /* RIB related usage stats */ - count = mtype_stats_alloc (MTYPE_BGP_NODE); + count = mem_get_alloc(mst, MTYPE_BGP_NODE); vty_out (vty, "%ld RIB nodes, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct bgp_node)), VTY_NEWLINE); - count = mtype_stats_alloc (MTYPE_BGP_ROUTE); + count = mem_get_alloc(mst, MTYPE_BGP_ROUTE); vty_out (vty, "%ld BGP routes, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct bgp_info)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_BGP_ROUTE_EXTRA))) + if ((count = mem_get_alloc(mst, MTYPE_BGP_ROUTE_EXTRA))) vty_out (vty, "%ld BGP route ancillaries, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct bgp_info_extra)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_BGP_STATIC))) + if ((count = mem_get_alloc(mst, MTYPE_BGP_STATIC))) vty_out (vty, "%ld Static routes, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct bgp_static)), VTY_NEWLINE); /* Adj-In/Out */ - if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_IN))) + if ((count = mem_get_alloc(mst, MTYPE_BGP_ADJ_IN))) vty_out (vty, "%ld Adj-In entries, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct bgp_adj_in)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_OUT))) + if ((count = mem_get_alloc(mst, MTYPE_BGP_ADJ_OUT))) vty_out (vty, "%ld Adj-Out entries, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct bgp_adj_out)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_BGP_NEXTHOP_CACHE))) + if ((count = mem_get_alloc(mst, MTYPE_BGP_NEXTHOP_CACHE))) vty_out (vty, "%ld Nexthop cache entries, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct bgp_nexthop_cache)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_BGP_DAMP_INFO))) + if ((count = mem_get_alloc(mst, MTYPE_BGP_DAMP_INFO))) vty_out (vty, "%ld Dampening entries, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct bgp_damp_info)), @@ -6708,7 +6739,7 @@ DEFUN (show_bgp_memory, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof(struct attr)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_ATTR_EXTRA))) + if ((count = mem_get_alloc(mst, MTYPE_ATTR_EXTRA))) vty_out (vty, "%ld BGP extra attributes, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof(struct attr_extra)), @@ -6724,7 +6755,7 @@ DEFUN (show_bgp_memory, count * sizeof (struct aspath)), VTY_NEWLINE); - count = mtype_stats_alloc (MTYPE_AS_SEG); + count = mem_get_alloc(mst, MTYPE_AS_SEG); vty_out (vty, "%ld BGP AS-PATH segments, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct assegment)), @@ -6736,43 +6767,43 @@ DEFUN (show_bgp_memory, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct community)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_ECOMMUNITY))) + if ((count = mem_get_alloc(mst, MTYPE_ECOMMUNITY))) vty_out (vty, "%ld BGP community entries, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct ecommunity)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_CLUSTER))) + if ((count = mem_get_alloc(mst, MTYPE_CLUSTER))) vty_out (vty, "%ld Cluster lists, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct cluster_list)), VTY_NEWLINE); /* Peer related usage */ - count = mtype_stats_alloc (MTYPE_BGP_PEER); + count = mem_get_alloc(mst, MTYPE_BGP_PEER); vty_out (vty, "%ld peers, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct peer)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_PEER_GROUP))) + if ((count = mem_get_alloc(mst, MTYPE_PEER_GROUP))) vty_out (vty, "%ld peer groups, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct peer_group)), VTY_NEWLINE); /* Other */ - if ((count = mtype_stats_alloc (MTYPE_HASH))) + if ((count = mem_get_alloc(mst, MTYPE_HASH))) vty_out (vty, "%ld hash tables, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct hash)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_HASH_BACKET))) + if ((count = mem_get_alloc(mst, MTYPE_HASH_BACKET))) vty_out (vty, "%ld hash buckets, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (struct hash_backet)), VTY_NEWLINE); - if ((count = mtype_stats_alloc (MTYPE_BGP_REGEXP))) + if ((count = mem_get_alloc(mst, MTYPE_BGP_REGEXP))) vty_out (vty, "%ld compiled regexes, using %s of memory%s", count, mtype_memstr (memstrbuf, sizeof (memstrbuf), count * sizeof (regex_t)), @@ -9040,37 +9071,50 @@ bgp_config_write_redistribute (struct vty *vty, struct bgp *bgp, afi_t afi, /* BGP node structure. */ static struct cmd_node bgp_node = { - BGP_NODE, - "%s(config-router)# ", - 1, + .node = BGP_NODE, + .prompt = "%s(config-router)# ", + + .config_to_vtysh = true, }; static struct cmd_node bgp_ipv4_unicast_node = { - BGP_IPV4_NODE, - "%s(config-router-af)# ", - 1, + .node = BGP_IPV4_NODE, + .prompt = "%s(config-router-af)# ", + + .parent = BGP_NODE, + + .config_to_vtysh = true, }; static struct cmd_node bgp_ipv4_multicast_node = { - BGP_IPV4M_NODE, - "%s(config-router-af)# ", - 1, + .node = BGP_IPV4M_NODE, + .prompt = "%s(config-router-af)# ", + + .parent = BGP_NODE, + + .config_to_vtysh = true, }; static struct cmd_node bgp_ipv6_unicast_node = { - BGP_IPV6_NODE, - "%s(config-router-af)# ", - 1, + .node = BGP_IPV6_NODE, + .prompt = "%s(config-router-af)# ", + + .parent = BGP_NODE, + + .config_to_vtysh = true, }; static struct cmd_node bgp_ipv6_multicast_node = { - BGP_IPV6M_NODE, - "%s(config-router-af)# ", - 1, + .node = BGP_IPV6M_NODE, + .prompt = "%s(config-router-af)# ", + + .parent = BGP_NODE, + + .config_to_vtysh = true, }; static struct cmd_node bgp_vpnv4_node = @@ -9788,10 +9832,12 @@ bgp_vty_init (void) /* address-family commands. */ install_element (BGP_NODE, &address_family_ipv4_cmd); - install_element (BGP_NODE, &address_family_ipv4_safi_cmd); + install_element (BGP_NODE, &address_family_ipv4_safi_unicast_cmd); + install_element (BGP_NODE, &address_family_ipv4_safi_multicast_cmd); #ifdef HAVE_IPV6 install_element (BGP_NODE, &address_family_ipv6_cmd); - install_element (BGP_NODE, &address_family_ipv6_safi_cmd); + install_element (BGP_NODE, &address_family_ipv6_safi_unicast_cmd); + install_element (BGP_NODE, &address_family_ipv6_safi_multicast_cmd); #endif /* HAVE_IPV6 */ install_element (BGP_NODE, &address_family_vpnv4_cmd); install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); @@ -10564,7 +10610,7 @@ DEFUN (show_ip_community_list, { struct symbol_table* table; vector extract ; - vector_index i ; + vector_index_t i ; struct symbol* sym ; struct community_list *list; @@ -10923,7 +10969,7 @@ DEFUN (show_ip_extcommunity_list, { struct symbol_table* table; vector extract ; - vector_index i ; + vector_index_t i ; struct symbol* sym ; struct community_list *list; @@ -10994,7 +11040,7 @@ community_list_config_write_list(struct vty* vty, int what) struct community_list *list; struct community_entry *entry; vector extract ; - vector_index i ; + vector_index_t i ; struct symbol* sym ; int write = 0; |