diff options
author | Philippe Guibert <philippe.guibert@6wind.com> | 2017-01-18 12:27:52 +0100 |
---|---|---|
committer | Philippe Guibert <philippe.guibert@6wind.com> | 2017-01-18 12:39:46 +0100 |
commit | d6902373107d0e460d85e8342b0d2fff18b08a97 (patch) | |
tree | f3b132ab57c4525eb0d5ea8d1ce9f4d3fff9cc72 | |
parent | configure: add enable_old_vpn_commands configuration param (diff) | |
download | frr-d6902373107d0e460d85e8342b0d2fff18b08a97.tar.xz frr-d6902373107d0e460d85e8342b0d2fff18b08a97.zip |
bgpd: add define of compilation for vpn commands
Use KEEP_OLD_VPN_COMMANDS define to brace some vty commands used by bgp
to configure or show vpnvx contexts using old method, that is to say
using vty keyword vpnv4 or vpnv6 command.
In addition to this, the commit adds two new commands under route-map
with new format:
[no] set ipv4|ipv6 vpn nexthop <IPv4 Address> | <IPv6 Address>
It also add following command in old format:
[no] set vpnv6 nexthop <IPv6 Address>
Note that the commit does not take into account the availability of old
commands that are not available in new format.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com
-rw-r--r-- | bgpd/bgp_mplsvpn.c | 20 | ||||
-rw-r--r-- | bgpd/bgp_mplsvpn.h | 7 | ||||
-rw-r--r-- | bgpd/bgp_route.c | 26 | ||||
-rw-r--r-- | bgpd/bgp_routemap.c | 196 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 29 |
5 files changed, 230 insertions, 48 deletions
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 16f08aad6..bfbddb6c3 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -41,11 +41,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "bgpd/rfapi/rfapi_backend.h" #endif -#define BGP_VPNVX_HELP_STR \ - "Address Family \n" \ - "Address Family \n" - -static int +extern int argv_find_and_parse_vpnvx(struct cmd_token **argv, int argc, int *index, afi_t *afi) { int ret = 0; @@ -222,7 +218,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; } @@ -230,7 +226,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; @@ -239,7 +235,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; @@ -248,7 +244,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)); @@ -319,7 +315,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; } @@ -1009,6 +1005,7 @@ DEFUN (show_bgp_ip_vpn_rd, return CMD_SUCCESS; } +#ifdef KEEP_OLD_VPN_COMMANDS DEFUN (show_ip_bgp_vpn_all, show_ip_bgp_vpn_all_cmd, "show [ip] bgp <vpnv4|vpnv6>", @@ -1377,6 +1374,7 @@ DEFUN (show_ip_bgp_vpn_rd_neighbor_advertised_routes, } return CMD_SUCCESS; } +#endif /* KEEP_OLD_VPN_COMMANDS */ void bgp_mplsvpn_init (void) @@ -1389,6 +1387,7 @@ bgp_mplsvpn_init (void) install_element (BGP_VPNV6_NODE, &no_vpnv6_network_cmd); install_element (VIEW_NODE, &show_bgp_ip_vpn_rd_cmd); +#ifdef KEEP_OLD_VPN_COMMANDS install_element (VIEW_NODE, &show_ip_bgp_vpn_all_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpn_rd_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpn_all_tags_cmd); @@ -1397,4 +1396,5 @@ bgp_mplsvpn_init (void) install_element (VIEW_NODE, &show_ip_bgp_vpn_rd_neighbor_routes_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd); install_element (VIEW_NODE, &show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd); +#endif /* KEEP_OLD_VPN_COMMANDS */ } diff --git a/bgpd/bgp_mplsvpn.h b/bgpd/bgp_mplsvpn.h index f75b98905..336b73616 100644 --- a/bgpd/bgp_mplsvpn.h +++ b/bgpd/bgp_mplsvpn.h @@ -55,6 +55,10 @@ typedef enum { (label) == MPLS_LABEL_IPV6_EXPLICIT_NULL || \ (label) == MPLS_LABEL_IMPLICIT_NULL) +#define BGP_VPNVX_HELP_STR \ + "Address Family \n" \ + "Address Family \n" + struct rd_as { u_int16_t type; @@ -94,4 +98,7 @@ extern int str2prefix_rd (const char *, struct prefix_rd *); extern int str2tag (const char *, u_char *); extern char *prefix_rd2str (struct prefix_rd *, char *, size_t); +extern int +argv_find_and_parse_vpnvx(struct cmd_token **argv, int argc, int *index, afi_t *afi); + #endif /* _QUAGGA_BGP_MPLSVPN_H */ diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 26c500af1..f5ae712df 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -9151,13 +9151,14 @@ DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, 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]", +#ifdef KEEP_OLD_VPN_COMMANDS +DEFUN (show_ip_bgp_vpn_neighbor_prefix_counts, + show_ip_bgp_vpn_neighbor_prefix_counts_cmd, + "show [ip] bgp <vpnv4|vpnv6> all neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]", SHOW_STR IP_STR BGP_STR - "Address Family\n" + BGP_VPNVX_HELP_STR "Display information about all VPNv4 NLRIs\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" @@ -9177,13 +9178,13 @@ DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj); } -DEFUN (show_ip_bgp_vpnv4_all_route_prefix, - show_ip_bgp_vpnv4_all_route_prefix_cmd, - "show [ip] bgp vpnv4 all <A.B.C.D|A.B.C.D/M> [json]", +DEFUN (show_ip_bgp_vpn_all_route_prefix, + show_ip_bgp_vpn_all_route_prefix_cmd, + "show [ip] bgp <vpnv4|vpnv6> all <A.B.C.D|A.B.C.D/M> [json]", SHOW_STR IP_STR BGP_STR - "Address Family\n" + BGP_VPNVX_HELP_STR "Display information about all VPNv4 NLRIs\n" "Network in the BGP routing table to display\n" "Network in the BGP routing table to display\n" @@ -9195,6 +9196,7 @@ DEFUN (show_ip_bgp_vpnv4_all_route_prefix, network = argv_find (argv, argc, "A.B.C.D/M", &idx) ? argv[idx]->arg : NULL; return bgp_show_route (vty, NULL, network, AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); } +#endif /* KEEP_OLD_VPN_COMMANDS */ static void show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, @@ -10532,7 +10534,9 @@ bgp_route_init (void) install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd); install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd); install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd); - install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_prefix_cmd); +#ifdef KEEP_OLD_VPN_COMMANDS + install_element (VIEW_NODE, &show_ip_bgp_vpn_all_route_prefix_cmd); +#endif /* KEEP_OLD_VPN_COMMANDS */ /* BGP dampening clear commands */ install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd); @@ -10544,7 +10548,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); - install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd); +#ifdef KEEP_OLD_VPN_COMMANDS + install_element (ENABLE_NODE, &show_ip_bgp_vpn_neighbor_prefix_counts_cmd); +#endif /* KEEP_OLD_VPN_COMMANDS */ 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 4f7f51fbb..50524baa0 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -2340,7 +2340,7 @@ struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = route_set_ipv6_nexthop_peer_free }; -/* `set vpnv4 nexthop A.B.C.D' */ +/* `set ip vpn nexthop A.B.C.D' */ static route_map_result_t route_set_vpnv4_nexthop (void *rule, struct prefix *prefix, @@ -2382,8 +2382,49 @@ route_set_vpnv4_nexthop_compile (const char *arg) return address; } +/* `set ipv6 vpn nexthop A.B.C.D' */ + +static route_map_result_t +route_set_vpnv6_nexthop (void *rule, struct prefix *prefix, + route_map_object_t type, void *object) +{ + struct in6_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. */ + memcpy (&(bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global, address, sizeof(struct in6_addr)); + (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL; + } + + return RMAP_OKAY; +} + +static void * +route_set_vpnv6_nexthop_compile (const char *arg) +{ + int ret; + struct in6_addr *address; + + address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); + ret = inet_pton (AF_INET6, arg, address); + + if (ret == 0) + { + XFREE (MTYPE_ROUTE_MAP_COMPILED, address); + return NULL; + } + + return address; +} + static void -route_set_vpnv4_nexthop_free (void *rule) +route_set_vpn_nexthop_free (void *rule) { XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); } @@ -2391,10 +2432,19 @@ 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 + route_set_vpn_nexthop_free +}; + +/* Route map commands for ip nexthop set. */ +struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd = +{ + "ipv6 vpn next-hop", + route_set_vpnv6_nexthop, + route_set_vpnv6_nexthop_compile, + route_set_vpn_nexthop_free }; /* `set originator-id' */ @@ -3881,37 +3931,124 @@ DEFUN (no_set_ipv6_nexthop_global, "ipv6 next-hop global", argv[idx_ipv6]->arg); } -DEFUN (set_vpnv4_nexthop, - set_vpnv4_nexthop_cmd, - "set vpnv4 next-hop A.B.C.D", +#ifdef KEEP_OLD_VPN_COMMANDS +DEFUN (set_vpn_nexthop, + set_vpn_nexthop_cmd, + "set <vpnv4|vpnv6> next-hop [A.B.C.D|X:X::X:X]", SET_STR "VPNv4 information\n" - "VPNv4 next-hop address\n" - "IP address of next hop\n") + "VPNv6 information\n" + "VPN next-hop address\n" + "IP address of next hop\n" + "IPv6 address of next hop\n") { - int idx_ipv4 = 3; - return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), - "vpnv4 next-hop", argv[idx_ipv4]->arg); -} + int idx_ip = 3; + afi_t afi; + int idx = 0; + if (argv_find_and_parse_vpnvx (argv, argc, &idx, &afi)) + { + if (afi == AFI_IP) + return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), + "ip vpn next-hop", argv[idx_ip]->arg); + else + return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 vpn next-hop", argv[idx_ip]->arg); + } + return CMD_SUCCESS; +} -DEFUN (no_set_vpnv4_nexthop, - no_set_vpnv4_nexthop_cmd, - "no set vpnv4 next-hop [A.B.C.D]", +DEFUN (no_set_vpn_nexthop, + no_set_vpn_nexthop_cmd, + "no set vpn next-hop [A.B.C.D|X:X::X:X]", NO_STR SET_STR - "VPNv4 information\n" - "VPNv4 next-hop address\n" - "IP address of next hop\n") + "VPN information\n" + "VPN next-hop address\n" + "IP address of next hop\n" + "IPv6 address of next hop\n") { - int idx_ipv4 = 4; - if (argc <= idx_ipv4) - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "vpnv4 next-hop", NULL); - return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), - "vpnv4 next-hop", argv[idx_ipv4]->arg); + int idx_ip = 4; + char *arg; + afi_t afi; + int idx = 0; + + if (argc <= idx_ip) + arg = NULL; + else + arg = argv[idx_ip]->arg; + if (argv_find_and_parse_vpnvx (argv, argc, &idx, &afi)) + { + if (afi == AFI_IP) + return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), + "ip vpn next-hop", arg); + else + return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 vpn next-hop", argv[idx_ip]->arg); + } + return CMD_SUCCESS; +} +#endif /* KEEP_OLD_VPN_COMMANDS */ + +DEFUN (set_ipx_vpn_nexthop, + set_ipx_vpn_nexthop_cmd, + "set <ipv4|ipv6> vpn next-hop [A.B.C.D|X:X::X:X]", + SET_STR + "IPv4 information\n" + "IPv6 information\n" + "VPN information\n" + "VPN next-hop address\n" + "IP address of next hop\n" + "IPv6 address of next hop\n") +{ + int idx_ip = 4; + afi_t afi; + int idx = 0; + + if (argv_find_and_parse_afi (argv, argc, &idx, &afi)) + { + if (afi == AFI_IP) + return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), + "ip vpn next-hop", argv[idx_ip]->arg); + else + return generic_set_add (vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 vpn next-hop", argv[idx_ip]->arg); + } + return CMD_SUCCESS; } +DEFUN (no_set_ipx_vpn_nexthop, + no_set_ipx_vpn_nexthop_cmd, + "no set <ipv4|ipv6> vpn next-hop [A.B.C.D|X:X::X:X]", + NO_STR + SET_STR + "IPv4 information\n" + "IPv6 information\n" + "VPN information\n" + "VPN next-hop address\n" + "IP address of next hop\n" + "IPv6 address of next hop\n") +{ + int idx_ip = 5; + char *arg; + afi_t afi; + int idx = 0; + + if (argc <= idx_ip) + arg = NULL; + else + arg = argv[idx_ip]->arg; + if (argv_find_and_parse_afi (argv, argc, &idx, &afi)) + { + if (afi == AFI_IP) + return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), + "ip vpn next-hop", arg); + else + return generic_set_delete (vty, VTY_GET_CONTEXT(route_map_index), + "ipv6 vpn next-hop", argv[idx_ip]->arg); + } + return CMD_SUCCESS; +} DEFUN (set_originator_id, set_originator_id_cmd, @@ -4022,6 +4159,7 @@ bgp_route_map_init (void) 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_vpnv6_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); @@ -4075,8 +4213,12 @@ bgp_route_map_init (void) install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd); install_element (RMAP_NODE, &set_ecommunity_soo_cmd); install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd); - install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd); - install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd); +#ifdef KEEP_OLD_VPN_COMMANDS + install_element (RMAP_NODE, &set_vpn_nexthop_cmd); + install_element (RMAP_NODE, &no_set_vpn_nexthop_cmd); +#endif /* KEEP_OLD_VPN_COMMANDS */ + install_element (RMAP_NODE, &set_ipx_vpn_nexthop_cmd); + install_element (RMAP_NODE, &no_set_ipx_vpn_nexthop_cmd); install_element (RMAP_NODE, &set_originator_id_cmd); install_element (RMAP_NODE, &no_set_originator_id_cmd); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 6d23af03e..fd6718e2a 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -5564,6 +5564,7 @@ DEFUN (address_family_ipv6_safi, return CMD_SUCCESS; } +#ifdef KEEP_OLD_VPN_COMMANDS DEFUN (address_family_vpnv4, address_family_vpnv4_cmd, "address-family vpnv4 [unicast]", @@ -5585,6 +5586,29 @@ DEFUN (address_family_vpnv6, vty->node = BGP_VPNV6_NODE; return CMD_SUCCESS; } +#endif /* KEEP_OLD_VPN_COMMANDS */ + +DEFUN (address_family_ipv4_vpn, + address_family_ipv4_vpn_cmd, + "address-family ipv4 vpn", + "Enter Address Family command mode\n" + "Address Family\n" + "Subsequent Address Family modifier\n") +{ + vty->node = BGP_VPNV4_NODE; + return CMD_SUCCESS; +} + +DEFUN (address_family_ipv6_vpn, + address_family_ipv6_vpn_cmd, + "address-family ipv6 vpn", + "Enter Address Family command mode\n" + "Address Family\n" + "Subsequent Address Family modifier\n") +{ + vty->node = BGP_VPNV6_NODE; + return CMD_SUCCESS; +} DEFUN (address_family_encap, address_family_encap_cmd, @@ -10684,9 +10708,12 @@ bgp_vty_init (void) install_element (BGP_NODE, &address_family_ipv4_safi_cmd); install_element (BGP_NODE, &address_family_ipv6_cmd); install_element (BGP_NODE, &address_family_ipv6_safi_cmd); +#ifdef KEEP_OLD_VPN_COMMANDS install_element (BGP_NODE, &address_family_vpnv4_cmd); - install_element (BGP_NODE, &address_family_vpnv6_cmd); +#endif /* KEEP_OLD_VPN_COMMANDS */ + install_element (BGP_NODE, &address_family_ipv4_vpn_cmd); + install_element (BGP_NODE, &address_family_ipv6_vpn_cmd); install_element (BGP_NODE, &address_family_encap_cmd); install_element (BGP_NODE, &address_family_encapv6_cmd); |