From c286be9683dde27557c4cb8af40a78de1869e198 Mon Sep 17 00:00:00 2001 From: Liu Xiaofeng Date: Mon, 19 Dec 2016 10:53:38 +0100 Subject: [PATCH] bgpd: add network command for vpnv6 address family Add the next commands: network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD [route-map WORD] no network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD Also, fix show running-config for vpnv6 network, as well as modiying bgp_static_set_safi, and take into account matching afi table. Signed-off-by: Liu Xiaofeng Signed-off-by: Philippe Guibert --- bgpd/bgp_mplsvpn.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ bgpd/bgp_route.c | 23 ++++++++++++------ 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 49fb3e3949..7747f15797 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -494,6 +494,59 @@ DEFUN (no_vpnv4_network, return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg); } +DEFUN (vpnv6_network, + vpnv6_network_cmd, + "network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD", + "Specify a network to announce via BGP\n" + "IPv6 prefix /, e.g., 3ffe::/16\n" + "Specify Route Distinguisher\n" + "VPN Route Distinguisher\n" + "BGP tag\n" + "tag value\n") +{ + int idx_ipv6_prefix = 1; + int idx_ext_community = 3; + int idx_word = 5; + return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg, NULL); +} + +DEFUN (vpnv6_network_route_map, + vpnv6_network_route_map_cmd, + "network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD route-map WORD", + "Specify a network to announce via BGP\n" + "IPv6 prefix /, e.g., 3ffe::/16\n" + "Specify Route Distinguisher\n" + "VPN Route Distinguisher\n" + "BGP tag\n" + "tag value\n" + "route map\n" + "route map name\n") +{ + int idx_ipv6_prefix = 1; + int idx_ext_community = 3; + int idx_word = 5; + int idx_word_2 = 7; + return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg, argv[idx_word_2]->arg); +} + +/* For testing purpose, static route of MPLS-VPN. */ +DEFUN (no_vpnv6_network, + no_vpnv6_network_cmd, + "no network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD", + NO_STR + "Specify a network to announce via BGP\n" + "IPv6 prefix /, e.g., 3ffe::/16\n" + "Specify Route Distinguisher\n" + "VPN Route Distinguisher\n" + "BGP tag\n" + "tag value\n") +{ + int idx_ipv6_prefix = 2; + int idx_ext_community = 4; + int idx_word = 6; + return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg); +} + static int show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u_char use_json) { @@ -1305,6 +1358,11 @@ bgp_mplsvpn_init (void) install_element (VIEW_NODE, &show_bgp_ipv4_vpn_cmd); install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_cmd); + + install_element (BGP_VPNV6_NODE, &vpnv6_network_cmd); + install_element (BGP_VPNV6_NODE, &vpnv6_network_route_map_cmd); + install_element (BGP_VPNV6_NODE, &no_vpnv6_network_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_ip_bgp_vpnv4_all_cmd); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 0040c7a144..0d4b1ae3ff 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -4313,6 +4313,7 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str, struct bgp_table *table; struct bgp_static *bgp_static; u_char tag[3]; + afi_t afi; ret = str2prefix (ip_str, &p); if (! ret) @@ -4335,11 +4336,19 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str, vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); return CMD_WARNING; } - - prn = bgp_node_get (bgp->route[AFI_IP][safi], + if (p.family == AF_INET) + afi = AFI_IP; + else if (p.family == AF_INET6) + afi = AFI_IP6; + else + { + vty_out (vty, "%% Non Supported prefix%s", VTY_NEWLINE); + return CMD_WARNING; + } + prn = bgp_node_get (bgp->route[afi][safi], (struct prefix *)&prd); if (prn->info == NULL) - prn->info = bgp_table_init (AFI_IP, safi); + prn->info = bgp_table_init (afi, safi); else bgp_unlock_node (prn); table = prn->info; @@ -4372,7 +4381,7 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str, rn->info = bgp_static; bgp_static->valid = 1; - bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi); + bgp_static_update_safi (bgp, &p, bgp_static, afi, safi); } return CMD_SUCCESS; @@ -10303,7 +10312,7 @@ DEFUN (clear_ip_bgp_dampening_address_mask, /* also used for encap safi */ static int -bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp, +bgp_config_write_network_vpn (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, int *write) { struct bgp_node *prn; @@ -10353,8 +10362,8 @@ bgp_config_write_network (struct vty *vty, struct bgp *bgp, struct bgp_aggregate *bgp_aggregate; char buf[SU_ADDRSTRLEN]; - if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))) - return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write); + if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) + return bgp_config_write_network_vpn (vty, bgp, afi, safi, write); /* Network configuration. */ for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) -- 2.39.5