summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_evpn.c11
-rw-r--r--bgpd/bgp_rd.c12
-rw-r--r--bgpd/bgp_rd.h2
-rw-r--r--bgpd/bgpd.c8
-rw-r--r--bgpd/bgpd.h3
5 files changed, 26 insertions, 10 deletions
diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c
index 483d65be71..49808e7cdd 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -29,7 +29,6 @@
#include "stream.h"
#include "hash.h"
#include "jhash.h"
-#include "bitfield.h"
#include "zclient.h"
#include "bgpd/bgp_attr_evpn.h"
@@ -3988,12 +3987,7 @@ void bgp_evpn_derive_auto_rt_export(struct bgp *bgp, struct bgpevpn *vpn)
*/
void bgp_evpn_derive_auto_rd_for_vrf(struct bgp *bgp)
{
- char buf[100];
-
- bgp->vrf_prd.family = AF_UNSPEC;
- bgp->vrf_prd.prefixlen = 64;
- sprintf(buf, "%s:%hu", inet_ntoa(bgp->router_id), bgp->vrf_rd_id);
- (void)str2prefix_rd(buf, &bgp->vrf_prd);
+ form_auto_rd(bgp->router_id, bgp->vrf_rd_id, &bgp->vrf_prd);
}
/*
@@ -4577,7 +4571,6 @@ void bgp_evpn_cleanup(struct bgp *bgp)
list_delete_and_null(&bgp->vrf_export_rtl);
if (bgp->l2vnis)
list_delete_and_null(&bgp->l2vnis);
- bf_release_index(bm->rd_idspace, bgp->vrf_rd_id);
}
/*
@@ -4585,7 +4578,6 @@ void bgp_evpn_cleanup(struct bgp *bgp)
* Create
* VNI hash table
* hash for RT to VNI
- * assign a unique rd id for auto derivation of vrf_prd
*/
void bgp_evpn_init(struct bgp *bgp)
{
@@ -4606,7 +4598,6 @@ void bgp_evpn_init(struct bgp *bgp)
(int (*)(void *, void *))evpn_route_target_cmp;
bgp->l2vnis = list_new();
bgp->l2vnis->cmp = (int (*)(void *, void *))vni_hash_cmp;
- bf_assign_index(bm->rd_idspace, bgp->vrf_rd_id);
}
void bgp_evpn_vrf_delete(struct bgp *bgp_vrf)
diff --git a/bgpd/bgp_rd.c b/bgpd/bgp_rd.c
index 64e083d1ef..3f7ea16045 100644
--- a/bgpd/bgp_rd.c
+++ b/bgpd/bgp_rd.c
@@ -200,3 +200,15 @@ char *prefix_rd2str(struct prefix_rd *prd, char *buf, size_t size)
snprintf(buf, size, "Unknown Type: %d", type);
return buf;
}
+
+void form_auto_rd(struct in_addr router_id,
+ uint16_t rd_id,
+ struct prefix_rd *prd)
+{
+ char buf[100];
+
+ prd->family = AF_UNSPEC;
+ prd->prefixlen = 64;
+ sprintf(buf, "%s:%hu", inet_ntoa(router_id), rd_id);
+ str2prefix_rd(buf, prd);
+}
diff --git a/bgpd/bgp_rd.h b/bgpd/bgp_rd.h
index a8ea83a4a7..c5ea34103f 100644
--- a/bgpd/bgp_rd.h
+++ b/bgpd/bgp_rd.h
@@ -66,5 +66,7 @@ extern void decode_rd_vnc_eth(uint8_t *pnt, struct rd_vnc_eth *rd_vnc_eth);
extern int str2prefix_rd(const char *, struct prefix_rd *);
extern char *prefix_rd2str(struct prefix_rd *, char *, size_t);
+extern void form_auto_rd(struct in_addr router_id, uint16_t rd_id,
+ struct prefix_rd *prd);
#endif /* _QUAGGA_BGP_RD_H */
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index e181385847..53ddbf61cc 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -44,6 +44,7 @@
#include "table.h"
#include "lib/json.h"
#include "frr_pthread.h"
+#include "bitfield.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
@@ -3000,6 +3001,10 @@ static struct bgp *bgp_create(as_t *as, const char *name,
QOBJ_REG(bgp, bgp);
update_bgp_group_init(bgp);
+
+ /* assign a unique rd id for auto derivation of vrf's RD */
+ bf_assign_index(bm->rd_idspace, bgp->vrf_rd_id);
+
bgp_evpn_init(bgp);
return bgp;
}
@@ -3381,6 +3386,9 @@ void bgp_free(struct bgp *bgp)
bgp_address_destroy(bgp);
bgp_tip_hash_destroy(bgp);
+ /* release the auto RD id */
+ bf_release_index(bm->rd_idspace, bgp->vrf_rd_id);
+
bgp_evpn_cleanup(bgp);
if (bgp->name)
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index b2f460e51f..ae6c993d68 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -480,6 +480,9 @@ struct bgp {
/* unique ID for auto derivation of RD for this vrf */
uint16_t vrf_rd_id;
+ /* Automatically derived RD for this VRF */
+ struct prefix_rd vrf_prd_auto;
+
/* RD for this VRF */
struct prefix_rd vrf_prd;