From c37812dd2a13857863756765a24b0cd2415736c4 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Fri, 14 Apr 2023 10:44:41 +0200 Subject: [PATCH] lib: fix handle seg6local routes on default vrf An L3VPN network can be configured on the main BGP instance, with an SRv6 SID. By declaring a network, a seg6local route is created but remains invalid. The below BGP VPN configuration the default VRF has been used: > router bgp 1 > address-family ipv6 unicast > sid vpn export auto > rd vpn export 1:30 > rt vpn both 77:77 > import vpn > export vpn > network 2001:7::/64 > exit-address-family The below seg6local route has been added: > # show ipv6 route > [..] > B 2001:db8:2:2:300::/128 [20/0] is directly connected, unknown inactive, seg6local End.DT6 table 254, seg6 ::, weight 1, 00:00:07 > When creating the seg6local route, an interface is used as nexthop. The interface index is obtained from the vrf identifier. This is true when using VRF interfaces, but is wrong when using the lo interface which usually has the '1' ifindex whereas the vrf id for the default VRF is 0. Get the appropriate index from the vrf identifier. The below seg6local route is visible: > # show ipv6 route > [..] > B>* 2001:db8:1:1:300::/128 [20/0] is directly connected, lo, seg6local End.DT6 table 254, seg6 ::, weight 1, 00:00:15 > Signed-off-by: Philippe Guibert --- lib/zclient.c | 9 +++++++-- lib/zclient.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/zclient.c b/lib/zclient.c index d42cb20191..8526cbfaa1 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -427,13 +427,18 @@ enum zclient_send_status zclient_send_vrf_label(struct zclient *zclient, } enum zclient_send_status zclient_send_localsid(struct zclient *zclient, - const struct in6_addr *sid, ifindex_t oif, + const struct in6_addr *sid, vrf_id_t vrf_id, enum seg6local_action_t action, const struct seg6local_context *context) { struct prefix_ipv6 p = {}; struct zapi_route api = {}; struct zapi_nexthop *znh; + struct interface *ifp; + + ifp = if_get_vrf_loopback(vrf_id); + if (ifp == NULL) + return ZCLIENT_SEND_FAILURE; p.family = AF_INET6; p.prefixlen = IPV6_MAX_BITLEN; @@ -456,7 +461,7 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient, memset(znh, 0, sizeof(*znh)); znh->type = NEXTHOP_TYPE_IFINDEX; - znh->ifindex = oif; + znh->ifindex = ifp->ifindex; SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL); znh->seg6local_action = action; memcpy(&znh->seg6local_ctx, context, sizeof(struct seg6local_context)); diff --git a/lib/zclient.h b/lib/zclient.h index 367e5b1474..e43393fd70 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -901,7 +901,7 @@ zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id, afi_t afi, extern enum zclient_send_status zclient_send_localsid(struct zclient *zclient, const struct in6_addr *sid, - ifindex_t oif, enum seg6local_action_t action, + vrf_id_t vrf_id, enum seg6local_action_t action, const struct seg6local_context *context); extern void zclient_send_reg_requests(struct zclient *, vrf_id_t);