From a239951ddef337f70078fc77b18499964825564c Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Sat, 3 Jun 2023 08:39:33 +0200 Subject: [PATCH] isisd: Add function to send SRv6 SID to zebra Add a function to install/remove an SRv6 SID in the forwarding plane through Zebra. Signed-off-by: Carmine Scarpitta --- isisd/isis_zebra.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index 1706d27a3a..d05a5bdbb2 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -823,6 +823,73 @@ static int isis_zebra_client_close_notify(ZAPI_CALLBACK_ARGS) return ret; } +/** + * Send SRv6 SID to ZEBRA for installation or deletion. + * + * @param cmd ZEBRA_ROUTE_ADD or ZEBRA_ROUTE_DELETE + * @param sid SRv6 SID to install or delete + * @param prefixlen Prefix length + * @param oif Outgoing interface + * @param action SID action + * @param context SID context + */ +static void isis_zebra_send_localsid(int cmd, const struct in6_addr *sid, + uint16_t prefixlen, ifindex_t oif, + enum seg6local_action_t action, + const struct seg6local_context *context) +{ + struct prefix_ipv6 p = {}; + struct zapi_route api = {}; + struct zapi_nexthop *znh; + + if (cmd != ZEBRA_ROUTE_ADD && cmd != ZEBRA_ROUTE_DELETE) { + flog_warn(EC_LIB_DEVELOPMENT, "%s: wrong ZEBRA command", + __func__); + return; + } + + if (prefixlen > IPV6_MAX_BITLEN) { + flog_warn(EC_LIB_DEVELOPMENT, "%s: wrong prefixlen %u", + __func__, prefixlen); + return; + } + + sr_debug(" |- %s SRv6 SID %pI6 behavior %s", + cmd == ZEBRA_ROUTE_ADD ? "Add" : "Delete", sid, + seg6local_action2str(action)); + + p.family = AF_INET6; + p.prefixlen = prefixlen; + p.prefix = *sid; + + api.vrf_id = VRF_DEFAULT; + api.type = PROTO_TYPE; + api.instance = 0; + api.safi = SAFI_UNICAST; + memcpy(&api.prefix, &p, sizeof(p)); + + if (cmd == ZEBRA_ROUTE_DELETE) + return (void)zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, + &api); + + SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); + SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); + + znh = &api.nexthops[0]; + + memset(znh, 0, sizeof(*znh)); + + znh->type = NEXTHOP_TYPE_IFINDEX; + znh->ifindex = oif; + SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL); + znh->seg6local_action = action; + memcpy(&znh->seg6local_ctx, context, sizeof(struct seg6local_context)); + + api.nexthop_num = 1; + + zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); +} + /** * Callback to process an SRv6 locator chunk received from SRv6 Manager (zebra). * -- 2.39.5