From: Carmine Scarpitta Date: Wed, 22 Feb 2023 10:18:46 +0000 (+0100) Subject: isisd: Add func to install SRv6 SID in dplane X-Git-Tag: base_9.1~88^2~100 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=8b6d051c540fc84d6856238446883fa72c77022b;p=matthieu%2Ffrr.git isisd: Add func to install SRv6 SID in dplane Add a function to install an SRv6 SID in the data plane through zebra. Signed-off-by: Carmine Scarpitta --- diff --git a/isisd/isis_srv6.h b/isisd/isis_srv6.h index bae2d0f449..094374e893 100644 --- a/isisd/isis_srv6.h +++ b/isisd/isis_srv6.h @@ -18,6 +18,9 @@ #define SRV6_MAX_H_ENCAPS 2 #define SRV6_MAX_END_D 5 +/* Name of the interface used for installing SRv6 SIDs into the data plane */ +#define SRV6_IFNAME "sr0" + /* SRv6 SID structure */ struct isis_srv6_sid_structure { uint8_t loc_block_len; diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index d05a5bdbb2..29fb238af2 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -890,6 +890,71 @@ static void isis_zebra_send_localsid(int cmd, const struct in6_addr *sid, zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); } +/** + * Install SRv6 SID in the forwarding plane through Zebra. + * + * @param area IS-IS area + * @param sid SRv6 SID + */ +void isis_zebra_srv6_sid_install(struct isis_area *area, + struct isis_srv6_sid *sid) +{ + enum seg6local_action_t action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; + uint16_t prefixlen = IPV6_MAX_BITLEN; + struct seg6local_context ctx = {}; + struct interface *ifp; + + if (!area || !sid) + return; + + sr_debug("ISIS-SRv6 (%s): setting SRv6 SID %pI6", area->area_tag, + &sid->sid); + + switch (sid->behavior) { + case SRV6_ENDPOINT_BEHAVIOR_END: + action = ZEBRA_SEG6_LOCAL_ACTION_END; + prefixlen = IPV6_MAX_BITLEN; + break; + case SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID: + action = ZEBRA_SEG6_LOCAL_ACTION_END; + prefixlen = sid->locator->block_bits_length + + sid->locator->node_bits_length; + SET_SRV6_FLV_OP(ctx.flv.flv_ops, + ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID); + ctx.flv.lcblock_len = sid->locator->block_bits_length; + ctx.flv.lcnode_func_len = sid->locator->node_bits_length; + break; + case SRV6_ENDPOINT_BEHAVIOR_END_X: + case SRV6_ENDPOINT_BEHAVIOR_END_X_NEXT_CSID: + case SRV6_ENDPOINT_BEHAVIOR_RESERVED: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID: + case SRV6_ENDPOINT_BEHAVIOR_OPAQUE: + default: + zlog_err( + "ISIS-SRv6 (%s): unsupported SRv6 endpoint behavior %u", + area->area_tag, sid->behavior); + return; + } + + /* Attach the SID to the SRv6 interface */ + ifp = if_lookup_by_name(SRV6_IFNAME, VRF_DEFAULT); + if (!ifp) { + zlog_warn( + "Failed to install SRv6 SID %pI6: %s interface not found", + &sid->sid, SRV6_IFNAME); + return; + } + + /* Send the SID to zebra */ + isis_zebra_send_localsid(ZEBRA_ROUTE_ADD, &sid->sid, prefixlen, + ifp->ifindex, action, &ctx); +} + /** * Callback to process an SRv6 locator chunk received from SRv6 Manager (zebra). * diff --git a/isisd/isis_zebra.h b/isisd/isis_zebra.h index 94a4666697..b4b9d22e81 100644 --- a/isisd/isis_zebra.h +++ b/isisd/isis_zebra.h @@ -57,6 +57,8 @@ void isis_zebra_vrf_register(struct isis *isis); void isis_zebra_vrf_deregister(struct isis *isis); int isis_zebra_ls_register(bool up); +extern void isis_zebra_srv6_sid_install(struct isis_area *area, + struct isis_srv6_sid *sid); extern int isis_zebra_srv6_manager_get_locator_chunk(const char *name); extern int isis_zebra_srv6_manager_release_locator_chunk(const char *name);