]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: Auto RD definitions and encoding
authorvivek <vivek@cumulusnetworks.com>
Tue, 27 Mar 2018 00:11:39 +0000 (17:11 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 25 Apr 2018 16:39:16 +0000 (12:39 -0400)
Setup a per-VRF identifier to use along with the Router Id to build the
RD. Define a function to encode the RD. Code is brought over from EVPN
and EVPN code has been modified to use the generic function.

Ticket: CM-20256
Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
bgpd/bgp_evpn.c
bgpd/bgp_rd.c
bgpd/bgp_rd.h
bgpd/bgpd.c
bgpd/bgpd.h

index 483d65be719f2fd022f4ff92a7f09c57f8c16300..49808e7cdd370436972a4869802a5bfd6448e02d 100644 (file)
@@ -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)
index 64e083d1ef25b9f7c9dc5284567200e33fd26e68..3f7ea160452dc731d1b46e70324983755f28a221 100644 (file)
@@ -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);
+}
index a8ea83a4a75c5b0f92b596bc593d88ca1f9bee03..c5ea34103ffa6fecb64971ab8e53df6ddcac9ef1 100644 (file)
@@ -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 */
index e18138584753aaa0e531ad73120428a51b429ff6..53ddbf61cce7a553cebd3dc50242d039f5063179 100644 (file)
@@ -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)
index b2f460e51f1f9c0e21a66b8eef6c055846641410..ae6c993d6897ea5f6926abac13a844cddfd7145b 100644 (file)
@@ -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;