diff options
author | Lou Berger <lberger@labn.net> | 2017-10-09 21:20:19 +0200 |
---|---|---|
committer | Lou Berger <lberger@labn.net> | 2017-10-31 16:06:17 +0100 |
commit | 05d58af09c639752acb8389932947e9e1c17c225 (patch) | |
tree | 9fb046ff9c7b37cf8b5637fe3a67670f6662cc5b /bgpd/rfapi/bgp_rfapi_cfg.c | |
parent | bgpd: add afi/safi to debug output (diff) | |
download | frr-05d58af09c639752acb8389932947e9e1c17c225.tar.xz frr-05d58af09c639752acb8389932947e9e1c17c225.zip |
bgpd: vrf-policy add prefix lists and route-maps on export
Signed-off-by: Lou Berger <lberger@labn.net>
Diffstat (limited to 'bgpd/rfapi/bgp_rfapi_cfg.c')
-rw-r--r-- | bgpd/rfapi/bgp_rfapi_cfg.c | 141 |
1 files changed, 101 insertions, 40 deletions
diff --git a/bgpd/rfapi/bgp_rfapi_cfg.c b/bgpd/rfapi/bgp_rfapi_cfg.c index e82ca3bbb..9fc3a8af8 100644 --- a/bgpd/rfapi/bgp_rfapi_cfg.c +++ b/bgpd/rfapi/bgp_rfapi_cfg.c @@ -32,6 +32,7 @@ #include "bgpd/bgp_route.h" #include "bgpd/bgp_mplsvpn.h" +#include "bgpd/bgp_vty.h" #include "bgpd/bgp_ecommunity.h" #include "bgpd/rfapi/rfapi.h" #include "bgpd/rfapi/bgp_rfapi_cfg.h" @@ -1602,6 +1603,8 @@ DEFUN (vnc_nve_group_export_no_prefixlist, { VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); + int idx = 0; + int is_bgp = 1; afi_t afi; VNC_VTY_CONFIG_CHECK(bgp); @@ -1613,17 +1616,15 @@ DEFUN (vnc_nve_group_export_no_prefixlist, return CMD_WARNING_CONFIG_FAILED; } - if (strmatch(argv[3]->text, "ipv4")) { - afi = AFI_IP; - } else { - afi = AFI_IP6; - } - - if (argv[2]->arg[0] == 'b') { - if (((argc > 5) && strmatch(argv[5]->text, - rfg->plist_export_bgp_name[afi])) - || (argc <= 5)) { + argv_find_and_parse_afi(argv, argc, &idx, &afi); + if (argv[idx-1]->text[0] == 'z') + is_bgp = 0; + idx += 2; /* skip afi and keyword */ + if (is_bgp) { + if (idx == argc || + strmatch(argv[idx]->arg, + rfg->plist_export_bgp_name[afi])) { if (rfg->plist_export_bgp_name[afi]) free(rfg->plist_export_bgp_name[afi]); rfg->plist_export_bgp_name[afi] = NULL; @@ -1632,9 +1633,9 @@ DEFUN (vnc_nve_group_export_no_prefixlist, vnc_direct_bgp_reexport_group_afi(bgp, rfg, afi); } } else { - if (((argc > 5) && strmatch(argv[5]->text, - rfg->plist_export_zebra_name[afi])) - || (argc <= 5)) { + if (idx == argc || + strmatch(argv[idx]->arg, + rfg->plist_export_zebra_name[afi])) { if (rfg->plist_export_zebra_name[afi]) free(rfg->plist_export_zebra_name[afi]); rfg->plist_export_zebra_name[afi] = NULL; @@ -1646,6 +1647,15 @@ DEFUN (vnc_nve_group_export_no_prefixlist, return CMD_SUCCESS; } +ALIAS (vnc_nve_group_export_no_prefixlist, + vnc_vrf_policy_export_no_prefixlist_cmd, + "no export <ipv4|ipv6> prefix-list [NAME]", + NO_STR + "Export to VRF\n" + "IPv4 routes\n" + "IPv6 routes\n" + "Prefix-list for filtering exported routes\n" "prefix list name\n") + DEFUN (vnc_nve_group_export_prefixlist, vnc_nve_group_export_prefixlist_cmd, "export <bgp|zebra> <ipv4|ipv6> prefix-list NAME", @@ -1658,6 +1668,8 @@ DEFUN (vnc_nve_group_export_prefixlist, { VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); + int idx = 0; + int is_bgp = 1; afi_t afi; VNC_VTY_CONFIG_CHECK(bgp); @@ -1669,33 +1681,40 @@ DEFUN (vnc_nve_group_export_prefixlist, return CMD_WARNING_CONFIG_FAILED; } - if (strmatch(argv[2]->text, "ipv4")) { - afi = AFI_IP; - } else { - afi = AFI_IP6; - } + argv_find_and_parse_afi(argv, argc, &idx, &afi); + if (argv[idx-1]->text[0] == 'z') + is_bgp = 0; + idx = argc - 1; - if (argv[1]->arg[0] == 'b') { + if (is_bgp) { if (rfg->plist_export_bgp_name[afi]) free(rfg->plist_export_bgp_name[afi]); - rfg->plist_export_bgp_name[afi] = strdup(argv[4]->arg); + rfg->plist_export_bgp_name[afi] = strdup(argv[idx]->arg); rfg->plist_export_bgp[afi] = - prefix_list_lookup(afi, argv[4]->arg); + prefix_list_lookup(afi, argv[idx]->arg); vnc_direct_bgp_reexport_group_afi(bgp, rfg, afi); } else { if (rfg->plist_export_zebra_name[afi]) free(rfg->plist_export_zebra_name[afi]); - rfg->plist_export_zebra_name[afi] = strdup(argv[4]->arg); + rfg->plist_export_zebra_name[afi] = strdup(argv[idx]->arg); rfg->plist_export_zebra[afi] = - prefix_list_lookup(afi, argv[4]->arg); + prefix_list_lookup(afi, argv[idx]->arg); vnc_zebra_reexport_group_afi(bgp, rfg, afi); } return CMD_SUCCESS; } +ALIAS (vnc_nve_group_export_prefixlist, + vnc_vrf_policy_export_prefixlist_cmd, + "export <ipv4|ipv6> prefix-list NAME", + "Export to VRF\n" + "IPv4 routes\n" + "IPv6 routes\n" + "Prefix-list for filtering exported routes\n" "prefix list name\n") + DEFUN (vnc_nve_group_export_no_routemap, vnc_nve_group_export_no_routemap_cmd, "no export <bgp|zebra> route-map [NAME]", @@ -1707,6 +1726,8 @@ DEFUN (vnc_nve_group_export_no_routemap, { VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); + int idx = 2; + int is_bgp = 1; VNC_VTY_CONFIG_CHECK(bgp); @@ -1716,12 +1737,21 @@ DEFUN (vnc_nve_group_export_no_routemap, vty_out(vty, "Current NVE group no longer exists\n"); return CMD_WARNING_CONFIG_FAILED; } + switch (argv[idx]->text[0]) { + case 'z': + is_bgp = 0; + /* fall thru */ + case 'b': + idx +=2; + break; + default: /* route-map */ + idx++; + break; + } - if (argv[2]->arg[0] == 'b') { - if (((argc > 4) - && strmatch(argv[4]->text, rfg->routemap_export_bgp_name)) - || (argc <= 4)) { - + if (is_bgp) { + if (idx == argc || + strmatch(argv[idx]->arg, rfg->routemap_export_bgp_name)) { if (rfg->routemap_export_bgp_name) free(rfg->routemap_export_bgp_name); rfg->routemap_export_bgp_name = NULL; @@ -1731,9 +1761,9 @@ DEFUN (vnc_nve_group_export_no_routemap, vnc_direct_bgp_reexport_group_afi(bgp, rfg, AFI_IP6); } } else { - if (((argc > 4) && strmatch(argv[4]->text, - rfg->routemap_export_zebra_name)) - || (argc <= 4)) { + if (idx == argc || + strmatch(argv[idx]->arg, + rfg->routemap_export_zebra_name)) { if (rfg->routemap_export_zebra_name) free(rfg->routemap_export_zebra_name); rfg->routemap_export_zebra_name = NULL; @@ -1746,6 +1776,13 @@ DEFUN (vnc_nve_group_export_no_routemap, return CMD_SUCCESS; } +ALIAS (vnc_nve_group_export_no_routemap, + vnc_vrf_policy_export_no_routemap_cmd, + "no export route-map [NAME]", + NO_STR + "Export to VRF\n" + "Route-map for filtering exported routes\n" "route map name\n") + DEFUN (vnc_nve_group_export_routemap, vnc_nve_group_export_routemap_cmd, "export <bgp|zebra> route-map NAME", @@ -1756,6 +1793,8 @@ DEFUN (vnc_nve_group_export_routemap, { VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); + int idx = 0; + int is_bgp = 1; VNC_VTY_CONFIG_CHECK(bgp); @@ -1766,26 +1805,36 @@ DEFUN (vnc_nve_group_export_routemap, return CMD_WARNING_CONFIG_FAILED; } - if (argv[1]->arg[0] == 'b') { + if (argv[1]->text[0] == 'z') + is_bgp = 0; + idx = argc - 1; + + if (is_bgp) { if (rfg->routemap_export_bgp_name) free(rfg->routemap_export_bgp_name); - rfg->routemap_export_bgp_name = strdup(argv[3]->arg); + rfg->routemap_export_bgp_name = strdup(argv[idx]->arg); rfg->routemap_export_bgp = - route_map_lookup_by_name(argv[3]->arg); + route_map_lookup_by_name(argv[idx]->arg); vnc_direct_bgp_reexport_group_afi(bgp, rfg, AFI_IP); vnc_direct_bgp_reexport_group_afi(bgp, rfg, AFI_IP6); } else { if (rfg->routemap_export_zebra_name) free(rfg->routemap_export_zebra_name); - rfg->routemap_export_zebra_name = strdup(argv[3]->arg); + rfg->routemap_export_zebra_name = strdup(argv[idx]->arg); rfg->routemap_export_zebra = - route_map_lookup_by_name(argv[3]->arg); + route_map_lookup_by_name(argv[idx]->arg); vnc_zebra_reexport_group_afi(bgp, rfg, AFI_IP); vnc_zebra_reexport_group_afi(bgp, rfg, AFI_IP6); } return CMD_SUCCESS; } +ALIAS (vnc_nve_group_export_routemap, + vnc_vrf_policy_export_routemap_cmd, + "export route-map NAME", + "Export to VRF\n" + "Route-map for filtering exported routes\n" "route map name\n") + DEFUN (vnc_nve_export_no_prefixlist, vnc_nve_export_no_prefixlist_cmd, "no vnc export <bgp|zebra> <ipv4|ipv6> prefix-list [NAME]", @@ -3687,6 +3736,14 @@ void bgp_rfapi_cfg_init(void) install_element(BGP_VRF_POLICY_NODE, &vnc_vrf_policy_rt_export_cmd); install_element(BGP_VRF_POLICY_NODE, &vnc_vrf_policy_rt_both_cmd); install_element(BGP_VRF_POLICY_NODE, &vnc_vrf_policy_rd_cmd); + install_element(BGP_VRF_POLICY_NODE, + &vnc_vrf_policy_export_prefixlist_cmd); + install_element(BGP_VRF_POLICY_NODE, + &vnc_vrf_policy_export_routemap_cmd); + install_element(BGP_VRF_POLICY_NODE, + &vnc_vrf_policy_export_no_prefixlist_cmd); + install_element(BGP_VRF_POLICY_NODE, + &vnc_vrf_policy_export_no_routemap_cmd); install_element(BGP_VRF_POLICY_NODE, &exit_vrf_policy_cmd); install_element(BGP_VNC_L2_GROUP_NODE, &vnc_l2_group_lni_cmd); @@ -3880,14 +3937,16 @@ int bgp_rfapi_cfg_write(struct vty *vty, struct bgp *bgp) if (rfg->plist_export_bgp_name[afi]) { vty_out(vty, - " export bgp %s prefix-list %s\n", + " export %s%s prefix-list %s\n", + (rfg->type == RFAPI_GROUP_CFG_VRF ? "" : "bgp "), afistr, rfg->plist_export_bgp_name [afi]); } if (rfg->plist_export_zebra_name[afi]) { vty_out(vty, - " export zebra %s prefix-list %s\n", + " export %s%s prefix-list %s\n", + (rfg->type == RFAPI_GROUP_CFG_VRF ? "" : "zebra "), afistr, rfg->plist_export_zebra_name [afi]); @@ -3921,11 +3980,13 @@ int bgp_rfapi_cfg_write(struct vty *vty, struct bgp *bgp) } if (rfg->routemap_export_bgp_name) { - vty_out(vty, " export bgp route-map %s\n", + vty_out(vty, " export %sroute-map %s\n", + (rfg->type == RFAPI_GROUP_CFG_VRF ? "" : "bgp "), rfg->routemap_export_bgp_name); } if (rfg->routemap_export_zebra_name) { - vty_out(vty, " export zebra route-map %s\n", + vty_out(vty, " export %sroute-map %s\n", + (rfg->type == RFAPI_GROUP_CFG_VRF ? "" : "zebra "), rfg->routemap_export_zebra_name); } if (rfg->routemap_redist_name[ZEBRA_ROUTE_BGP_DIRECT]) { |