Skip to content

Commit

Permalink
Merge pull request #17580 from varuntumbe/dev/label_pool_release_fix
Browse files Browse the repository at this point in the history
BGP Labelpool : Releasing the label in labelpool when VPN session gets removed
  • Loading branch information
ton31337 authored Dec 23, 2024
2 parents 61ba8b9 + d5c2f2d commit 9ce3b14
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 19 deletions.
29 changes: 29 additions & 0 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -4079,6 +4079,35 @@ void bgp_vpn_leak_export(struct bgp *from_bgp)
}
}

/* It releases the label from labelpool which
* was previously assigned and unsets the flag based on reset arg
* This also used in vty to release the label and to change the allocation mode as well
*/
void bgp_vpn_release_label(struct bgp *bgp, afi_t afi, bool reset)
{
if (!CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
return;
/*
* label has previously been automatically
* assigned by labelpool: release it
*
* NB if tovpn_label == MPLS_LABEL_NONE it
* means the automatic assignment is in flight
* and therefore the labelpool callback must
* detect that the auto label is not needed.
*/
if (bgp->vpn_policy[afi].tovpn_label == MPLS_LABEL_NONE)
return;
if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP))
return;

bgp_lp_release(LP_TYPE_VRF, &bgp->vpn_policy[afi], bgp->vpn_policy[afi].tovpn_label);
bgp->vpn_policy[afi].tovpn_label = MPLS_LABEL_NONE;

if (reset)
UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
}

/* The nexthops values are compared to
* find in the tree the appropriate cache entry
*/
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_mplsvpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ extern void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw,
bool is_config);
extern void bgp_vpn_leak_unimport(struct bgp *from_bgp);
extern void bgp_vpn_leak_export(struct bgp *from_bgp);
extern void bgp_vpn_release_label(struct bgp *bgp, afi_t afi, bool reset);

extern bool bgp_mplsvpn_path_uses_valid_mpls_label(struct bgp_path_info *pi);
extern int
Expand Down
21 changes: 2 additions & 19 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -9948,26 +9948,9 @@ DEFPY (af_label_vpn_export,
UNSET_FLAG(bgp->vpn_policy[afi].flags,
BGP_VPN_POLICY_TOVPN_LABEL_MANUAL_REG);

} else if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
} else if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
/* release any previous auto label */
if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {

/*
* label has previously been automatically
* assigned by labelpool: release it
*
* NB if tovpn_label == MPLS_LABEL_NONE it
* means the automatic assignment is in flight
* and therefore the labelpool callback must
* detect that the auto label is not needed.
*/

bgp_lp_release(LP_TYPE_VRF,
&bgp->vpn_policy[afi],
bgp->vpn_policy[afi].tovpn_label);
}
}
bgp_vpn_release_label(bgp, afi, false);

if (yes) {
if (label_auto) {
Expand Down
3 changes: 3 additions & 0 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4037,6 +4037,9 @@ int bgp_delete(struct bgp *bgp)

bgp_vpn_leak_unimport(bgp);

bgp_vpn_release_label(bgp, AFI_IP, true);
bgp_vpn_release_label(bgp, AFI_IP6, true);

hook_call(bgp_inst_delete, bgp);

FOREACH_AFI_SAFI (afi, safi)
Expand Down
Empty file.
117 changes: 117 additions & 0 deletions tests/topotests/bgp_vpnv4_ebgp_vpn_auto/r1/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
interface r1-eth1 vrf vrf1
ip address 173.31.1.1/32
!
interface r1-eth2 vrf vrf2
ip address 173.31.1.2/32
!
interface r1-eth3 vrf vrf3
ip address 173.31.1.3/32
!
interface r1-eth4 vrf vrf4
ip address 173.31.1.4/32
!
interface r1-eth5 vrf vrf5
ip address 173.31.1.5/32
!

interface r1-eth0
ip address 192.168.0.1/24
!

interface r1-eth6
ip address 193.170.0.1/24

interface lo
ip address 11.11.11.11/32
!
router ospf
ospf router-id 11.11.11.11
network 193.170.0.0/24 area 0.0.0.0
network 11.11.11.11/32 area 0.0.0.0
redistribute connected
exit
!
mpls ldp
router-id 11.11.11.11
!
address-family ipv4
discovery transport-address 11.11.11.11
!
interface r1-eth6
exit
!
exit-address-family
!
exit
!
bgp route-map delay-timer 1
router bgp 65500
bgp router-id 192.0.2.1
no bgp ebgp-requires-policy
neighbor 192.168.0.2 remote-as 65501
address-family ipv4 unicast
no neighbor 192.168.0.2 activate
exit-address-family
address-family ipv4 vpn
neighbor 192.168.0.2 activate
exit-address-family
!
router bgp 65500 vrf vrf1
bgp router-id 192.0.2.1
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:1
rt vpn both 53:1
export vpn
import vpn
exit-address-family
!
router bgp 65500 vrf vrf2
bgp router-id 192.0.2.1
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:2
rt vpn both 53:2
export vpn
import vpn
exit-address-family
!
router bgp 65500 vrf vrf3
bgp router-id 192.0.2.1
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:3
rt vpn both 53:3
export vpn
import vpn
exit-address-family
!
router bgp 65500 vrf vrf4
bgp router-id 192.0.2.1
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:4
rt vpn both 53:4
export vpn
import vpn
exit-address-family
!
router bgp 65500 vrf vrf5
bgp router-id 192.0.2.1
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:5
rt vpn both 53:5
export vpn
import vpn
exit-address-family
!

interface r1-eth0
mpls bgp forwarding
!
88 changes: 88 additions & 0 deletions tests/topotests/bgp_vpnv4_ebgp_vpn_auto/r2/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
interface r2-eth1 vrf vrf1
ip address 173.31.0.1/32
!
interface r2-eth2 vrf vrf2
ip address 173.31.0.2/32
!
interface r2-eth3 vrf vrf3
ip address 173.31.0.3/32
!
interface r2-eth4 vrf vrf4
ip address 173.31.0.4/32
!
interface r2-eth5 vrf vrf5
ip address 173.31.0.5/32
!
interface r2-eth0
ip address 192.168.0.2/24
!
router bgp 65501
bgp router-id 192.0.2.2
no bgp ebgp-requires-policy
neighbor 192.168.0.1 remote-as 65500
address-family ipv4 unicast
no neighbor 192.168.0.1 activate
exit-address-family
address-family ipv4 vpn
neighbor 192.168.0.1 activate
exit-address-family
!
router bgp 65501 vrf vrf1
bgp router-id 192.0.2.2
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:1
rt vpn both 53:1
export vpn
import vpn
exit-address-family
!
router bgp 65501 vrf vrf2
bgp router-id 192.0.2.2
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:2
rt vpn both 53:2
export vpn
import vpn
exit-address-family
!
router bgp 65501 vrf vrf3
bgp router-id 192.0.2.2
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:3
rt vpn both 53:3
export vpn
import vpn
exit-address-family
!
router bgp 65501 vrf vrf4
bgp router-id 192.0.2.2
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:4
rt vpn both 53:4
export vpn
import vpn
exit-address-family
!
router bgp 65501 vrf vrf5
bgp router-id 192.0.2.2
address-family ipv4 unicast
redistribute connected
label vpn export auto
rd vpn export 445:5
rt vpn both 53:5
export vpn
import vpn
exit-address-family
!

interface r2-eth0
mpls bgp forwarding
!
32 changes: 32 additions & 0 deletions tests/topotests/bgp_vpnv4_ebgp_vpn_auto/r3/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
interface r3-eth0
ip address 193.170.0.2/24
!
interface lo
ip address 33.33.33.33/32
!
interface r3-eth1
ip address 180.170.0.2/32
!
interface r3-eth2
ip address 180.170.0.3/32
!
router ospf
ospf router-id 33.33.33.33
network 193.170.0.0/24 area 0.0.0.0
network 33.33.33.33/32 area 0.0.0.0
redistribute connected
exit
!
mpls ldp
router-id 33.33.33.33
!
address-family ipv4
discovery transport-address 33.33.33.33
!
interface r3-eth0
exit
!
exit-address-family
!
exit
!
Loading

0 comments on commit 9ce3b14

Please sign in to comment.