]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: update logic to allocate SRv6 locator
authorRyoga Saito <ryoga.saito@linecorp.com>
Fri, 25 Feb 2022 13:40:28 +0000 (13:40 +0000)
committerRyoga Saito <ryoga.saito@linecorp.com>
Fri, 25 Feb 2022 15:34:24 +0000 (15:34 +0000)
For the later patches, this patch changes the behavior of alloc_new sid
so that bgpd record not only SID for VRF, but also Locator of SID.

Signed-off-by: Ryoga Saito <ryoga.saito@linecorp.com>
bgpd/bgp_mplsvpn.c
bgpd/bgpd.h

index eafc37f20c7c596abcaa176971d4ca11f4f8affe..1ca191012f7319763a2f994403903938b3462a5a 100644 (file)
@@ -520,7 +520,7 @@ static bool sid_exist(struct bgp *bgp, const struct in6_addr *sid)
  * else: try to allocate as auto-mode
  */
 static uint32_t alloc_new_sid(struct bgp *bgp, uint32_t index,
-                             struct in6_addr *sid)
+                             struct in6_addr *sid_locator)
 {
        struct listnode *node;
        struct prefix_ipv6 *chunk;
@@ -528,10 +528,11 @@ static uint32_t alloc_new_sid(struct bgp *bgp, uint32_t index,
        bool alloced = false;
        int label = 0;
 
-       if (!bgp || !sid)
+       if (!bgp || !sid_locator)
                return false;
 
        for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) {
+               *sid_locator = chunk->prefix;
                sid_buf = chunk->prefix;
                if (index != 0) {
                        label = index << 12;
@@ -556,7 +557,6 @@ static uint32_t alloc_new_sid(struct bgp *bgp, uint32_t index,
                return 0;
 
        sid_register(bgp, &sid_buf, bgp->srv6_locator_name);
-       *sid = sid_buf;
        return label;
 }
 
@@ -564,7 +564,7 @@ void ensure_vrf_tovpn_sid(struct bgp *bgp_vpn, struct bgp *bgp_vrf, afi_t afi)
 {
        int debug = BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF);
        char buf[256];
-       struct in6_addr *sid;
+       struct in6_addr *tovpn_sid, *tovpn_sid_locator;
        uint32_t tovpn_sid_index = 0, tovpn_sid_transpose_label;
        bool tovpn_sid_auto = false;
 
@@ -598,24 +598,33 @@ void ensure_vrf_tovpn_sid(struct bgp *bgp_vpn, struct bgp *bgp_vrf, afi_t afi)
                return;
        }
 
-       sid = XCALLOC(MTYPE_BGP_SRV6_SID, sizeof(struct in6_addr));
+       tovpn_sid_locator =
+               XCALLOC(MTYPE_BGP_SRV6_SID, sizeof(struct in6_addr));
        tovpn_sid_transpose_label =
-               alloc_new_sid(bgp_vpn, tovpn_sid_index, sid);
+               alloc_new_sid(bgp_vpn, tovpn_sid_index, tovpn_sid_locator);
        if (tovpn_sid_transpose_label == 0) {
                zlog_debug("%s: not allocated new sid for vrf %s: afi %s",
                           __func__, bgp_vrf->name_pretty, afi2str(afi));
                return;
        }
 
+       tovpn_sid = XCALLOC(MTYPE_BGP_SRV6_SID, sizeof(struct in6_addr));
+       *tovpn_sid = *tovpn_sid_locator;
+       transpose_sid(tovpn_sid, tovpn_sid_transpose_label,
+                     BGP_PREFIX_SID_SRV6_TRANSPOSITION_OFFSET,
+                     BGP_PREFIX_SID_SRV6_TRANSPOSITION_LENGTH);
+
        if (debug) {
-               inet_ntop(AF_INET6, sid, buf, sizeof(buf));
+               inet_ntop(AF_INET6, tovpn_sid, buf, sizeof(buf));
                zlog_debug("%s: new sid %s allocated for vrf %s: afi %s",
                           __func__, buf, bgp_vrf->name_pretty,
                           afi2str(afi));
        }
+
+       bgp_vrf->vpn_policy[afi].tovpn_sid = tovpn_sid;
+       bgp_vrf->vpn_policy[afi].tovpn_sid_locator = tovpn_sid_locator;
        bgp_vrf->vpn_policy[afi].tovpn_sid_transpose_label =
                tovpn_sid_transpose_label;
-       bgp_vrf->vpn_policy[afi].tovpn_sid = sid;
 }
 
 void transpose_sid(struct in6_addr *sid, uint32_t label, uint8_t offset,
index 926b0b033f32a22239790d58e91bdb8deaa9430b..a9475f39a76731feb63bd98d1cfdbdfdf5af7677 100644 (file)
@@ -234,6 +234,7 @@ struct vpn_policy {
         */
        uint32_t tovpn_sid_index; /* unset => set to 0 */
        struct in6_addr *tovpn_sid;
+       struct in6_addr *tovpn_sid_locator;
        uint32_t tovpn_sid_transpose_label;
        struct in6_addr *tovpn_zebra_vrf_sid_last_sent;
 };