From 9d6a46aa1e6ee89985c0d38fa1ed64bef94e0a67 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Sun, 29 Oct 2017 22:43:19 -0400 Subject: [PATCH] bgpd: rfapi - open rfd for vrf groups on export config, keep open until group deleted Signed-off-by: Lou Berger --- bgpd/rfapi/bgp_rfapi_cfg.c | 21 ++++++++------ bgpd/rfapi/rfapi_private.h | 1 + bgpd/rfapi/rfapi_vty.c | 57 +++++++++++++++++++------------------ bgpd/rfapi/vnc_export_bgp.c | 3 -- 4 files changed, 44 insertions(+), 38 deletions(-) diff --git a/bgpd/rfapi/bgp_rfapi_cfg.c b/bgpd/rfapi/bgp_rfapi_cfg.c index c96e869f1c..b09d82d014 100644 --- a/bgpd/rfapi/bgp_rfapi_cfg.c +++ b/bgpd/rfapi/bgp_rfapi_cfg.c @@ -1459,9 +1459,11 @@ DEFUN (vnc_export_nvegroup, rfg_new = bgp_rfapi_cfg_match_byname(bgp, argv[5]->arg, RFAPI_GROUP_CFG_NVE); - if (rfg_new == NULL) + if (rfg_new == NULL) { rfg_new = bgp_rfapi_cfg_match_byname(bgp, argv[5]->arg, RFAPI_GROUP_CFG_VRF); + vnc_add_vrf_opener(bgp, rfg_new); + } if (rfg_new == NULL) { vty_out(vty, "Can't group named \"%s\".\n", argv[5]->arg); @@ -2432,8 +2434,7 @@ bgp_rfapi_delete_named_nve_group(struct vty *vty, /* NULL = no output */ */ for (ALL_LIST_ELEMENTS_RO(bgp->rfapi_cfg->rfg_export_direct_bgp_l, node, rfgn)) { - if (rfg_name == NULL || (type == RFAPI_GROUP_CFG_NVE - && !strcmp(rfgn->name, rfg_name))) { + if (rfgn->rfg == rfg) { rfgn->rfg = NULL; /* remove exported routes from this group */ vnc_direct_bgp_del_group(bgp, rfg); @@ -2446,21 +2447,25 @@ bgp_rfapi_delete_named_nve_group(struct vty *vty, /* NULL = no output */ */ for (ALL_LIST_ELEMENTS_RO(bgp->rfapi_cfg->rfg_export_zebra_l, node, rfgn)) { - - if (rfg_name == NULL || (type == RFAPI_GROUP_CFG_NVE - && !strcmp(rfgn->name, rfg_name))) { + if (rfgn->rfg == rfg) { rfgn->rfg = NULL; /* remove exported routes from this group */ vnc_zebra_del_group(bgp, rfg); break; } } - if (rfg) + if (rfg) { + if (rfg->rfd) + clear_vnc_vrf_closer(rfg); bgp_rfapi_delete_nve_group(vty, bgp, rfg); + } else /* must be delete all */ for (ALL_LIST_ELEMENTS(bgp->rfapi_cfg->nve_groups_sequential, - node, nnode, rfg)) + node, nnode, rfg)) { + if (rfg->rfd) + clear_vnc_vrf_closer(rfg); bgp_rfapi_delete_nve_group(vty, bgp, rfg); + } return CMD_SUCCESS; } diff --git a/bgpd/rfapi/rfapi_private.h b/bgpd/rfapi/rfapi_private.h index cef319b43f..c82a0d6c6f 100644 --- a/bgpd/rfapi/rfapi_private.h +++ b/bgpd/rfapi/rfapi_private.h @@ -345,6 +345,7 @@ extern void rfapi_un_options_free(struct rfapi_un_option *goner); extern void rfapi_vn_options_free(struct rfapi_vn_option *goner); +extern void vnc_add_vrf_opener(struct bgp *bgp, struct rfapi_nve_group_cfg *rfg); extern void clear_vnc_vrf_closer(struct rfapi_nve_group_cfg *rfg); /*------------------------------------------ * rfapi_extract_l2o diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 5b080ae1e6..953ea739dc 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -4632,6 +4632,35 @@ notcfg: * add [vrf ] prefix * [rd ] [label ] [local-preference <0-4294967295>] ************************************************************************/ +void vnc_add_vrf_opener(struct bgp *bgp, struct rfapi_nve_group_cfg *rfg) +{ + if (rfg->rfd == NULL) /* need new rfapi_handle */ + { + /* based on rfapi_open */ + struct rfapi_descriptor *rfd; + rfd = XCALLOC(MTYPE_RFAPI_DESC, + sizeof(struct rfapi_descriptor)); + rfd->bgp = bgp; + rfg->rfd = rfd; + /* leave most fields empty as will get from (dynamic) config + * when needed */ + rfd->default_tunneltype_option.type = BGP_ENCAP_TYPE_MPLS; + rfd->cookie = rfg; + if (rfg->vn_prefix.family + && !CHECK_FLAG(rfg->flags, RFAPI_RFG_VPN_NH_SELF)) { + rfapiQprefix2Raddr(&rfg->vn_prefix, &rfd->vn_addr); + } else { + memset(&rfd->vn_addr, 0, sizeof(struct rfapi_ip_addr)); + rfd->vn_addr.addr_family = AF_INET; + rfd->vn_addr.addr.v4 = bgp->router_id; + } + rfd->un_addr = rfd->vn_addr; /* sigh, need something in UN for + lookups */ + vnc_zlog_debug_verbose("%s: Opening RFD for VRF %s", __func__, + rfg->name); + rfapi_init_and_open(bgp, rfd, rfg); + } +} /* NOTE: this functions parallels vnc_direct_add_rn_group_rd */ static int vnc_add_vrf_prefix(struct vty *vty, const char *arg_vrf, @@ -4725,32 +4754,7 @@ static int vnc_add_vrf_prefix(struct vty *vty, const char *arg_vrf, } } rpfx.cost = 255 - (pref & 255); - if (rfg->rfd == NULL) /* need new rfapi_handle */ - { - /* based on rfapi_open */ - struct rfapi_descriptor *rfd; - rfd = XCALLOC(MTYPE_RFAPI_DESC, - sizeof(struct rfapi_descriptor)); - rfd->bgp = bgp; - rfg->rfd = rfd; - /* leave most fields empty as will get from (dynamic) config - * when needed */ - rfd->default_tunneltype_option.type = BGP_ENCAP_TYPE_MPLS; - rfd->cookie = rfg; - if (rfg->vn_prefix.family - && !CHECK_FLAG(rfg->flags, RFAPI_RFG_VPN_NH_SELF)) { - rfapiQprefix2Raddr(&rfg->vn_prefix, &rfd->vn_addr); - } else { - memset(&rfd->vn_addr, 0, sizeof(struct rfapi_ip_addr)); - rfd->vn_addr.addr_family = AF_INET; - rfd->vn_addr.addr.v4 = bgp->router_id; - } - rfd->un_addr = rfd->vn_addr; /* sigh, need something in UN for - lookups */ - vnc_zlog_debug_verbose("%s: Opening RFD for VRF %s", __func__, - rfg->name); - rfapi_init_and_open(bgp, rfd, rfg); - } + vnc_add_vrf_opener(bgp, rfg); if (!rfapi_register(rfg->rfd, &rpfx, RFAPI_INFINITE_LIFETIME, NULL, (cur_opt ? optary : NULL), RFAPI_REGISTER_ADD)) { @@ -4907,7 +4911,6 @@ static int vnc_clear_vrf(struct vty *vty, struct bgp *bgp, const char *arg_vrf, start_count = rfapi_cfg_group_it_count(rfg); clear_vnc_prefix(&cda); - clear_vnc_vrf_closer(rfg); vty_out(vty, "Cleared %u out of %d prefixes.\n", cda.pfx_count, start_count); return CMD_SUCCESS; diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index 7092218663..50cd42bf79 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -1367,9 +1367,6 @@ static void vnc_direct_del_rn_group_rd(struct bgp *bgp, NULL, /* RD not used for unicast */ NULL, NULL); /* tag not used for unicast */ - if (rfg->type == RFAPI_GROUP_CFG_VRF) { - clear_vnc_vrf_closer(rfg); - } return; } -- 2.39.5