diff options
author | Renato Westphal <renato@openbsd.org> | 2018-04-16 00:05:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-16 00:05:27 +0200 |
commit | 6b4fdc1cb134ebf0b03df22426aa13c5c51984f8 (patch) | |
tree | 54dacff7cc3ef462ce42dc2fac1a4f69bdd2fb7a /bgpd/bgp_mplsvpn.c | |
parent | Merge pull request #2068 from LabNConsulting/working/master/rfapi-sa (diff) | |
parent | bgpd: vpn-vrf leaking: use dynamic label pool for "auto" labels (diff) | |
download | frr-6b4fdc1cb134ebf0b03df22426aa13c5c51984f8.tar.xz frr-6b4fdc1cb134ebf0b03df22426aa13c5c51984f8.zip |
Merge pull request #2036 from LabNConsulting/working/master/bgp-vpn-leak-labelmgr
bgpd: dynamic mpls label pool
Diffstat (limited to 'bgpd/bgp_mplsvpn.c')
-rw-r--r-- | bgpd/bgp_mplsvpn.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 13a283a05..8900862b8 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -310,6 +310,65 @@ void vpn_leak_zebra_vrf_label_withdraw(struct bgp *bgp, afi_t afi) bgp->vpn_policy[afi].tovpn_zebra_vrf_label_last_sent = label; } +int vpn_leak_label_callback( + mpls_label_t label, + void *labelid, + bool allocated) +{ + struct vpn_policy *vp = (struct vpn_policy *)labelid; + int debug = BGP_DEBUG(vpn, VPN_LEAK_LABEL); + + if (debug) + zlog_debug("%s: label=%u, allocated=%d", + __func__, label, allocated); + + if (!allocated) { + /* + * previously-allocated label is now invalid + */ + if (CHECK_FLAG(vp->flags, BGP_VPN_POLICY_TOVPN_LABEL_AUTO) && + (vp->tovpn_label != MPLS_LABEL_NONE)) { + + vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, + vp->afi, bgp_get_default(), vp->bgp); + vp->tovpn_label = MPLS_LABEL_NONE; + vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, + vp->afi, bgp_get_default(), vp->bgp); + } + return 0; + } + + /* + * New label allocation + */ + if (!CHECK_FLAG(vp->flags, BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) { + + /* + * not currently configured for auto label, reject allocation + */ + return -1; + } + + if (vp->tovpn_label != MPLS_LABEL_NONE) { + if (label == vp->tovpn_label) { + /* already have same label, accept but do nothing */ + return 0; + } + /* Shouldn't happen: different label allocation */ + zlog_err("%s: %s had label %u but got new assignment %u", + __func__, vp->bgp->name_pretty, vp->tovpn_label, label); + /* use new one */ + } + + vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, + vp->afi, bgp_get_default(), vp->bgp); + vp->tovpn_label = label; + vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, + vp->afi, bgp_get_default(), vp->bgp); + + return 0; +} + static int ecom_intersect(struct ecommunity *e1, struct ecommunity *e2) { int i; |