From 5b9c03b0d36f680d5f4cd5134443d4e79d629c0f Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Thu, 9 Feb 2023 19:09:04 +0100 Subject: [PATCH] isisd: Add func to process a received SRv6 locator Add a callback function `isis_zebra_process_srv6_locator_add()` that is called upon receiving an SRv6 locator from zebra. When a new SRv6 locator is created in zebra, zebra sends a ZEBRA_SRV6_LOCATOR_ADD notification to all daemons informing them of the new locator. In IS-IS, we register the new `isis_zebra_process_srv6_locator_add()` callback as the handler for ZEBRA_SRV6_LOCATOR_ADD. This callback iterates over all areas of the current IS-IS instance and looks for an area for which the new locator was configured. If a match is found, we call `isis_zebra_srv6_manager_get_locator_chunk()` to ask zebra a chunk from the locator. If no match is found, we do nothing. Signed-off-by: Carmine Scarpitta --- isisd/isis_zebra.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index 09c1e2920c..b245b09bba 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -885,6 +885,51 @@ static int isis_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) return 0; } +/** + * Callback to process an SRv6 locator received from SRv6 Manager (zebra). + * + * @result 0 on success, -1 otherwise + */ +static int isis_zebra_process_srv6_locator_add(ZAPI_CALLBACK_ARGS) +{ + struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT); + struct srv6_locator loc = {}; + struct listnode *node; + struct isis_area *area; + + /* Decode the SRv6 locator */ + if (zapi_srv6_locator_decode(zclient->ibuf, &loc) < 0) + return -1; + + sr_debug( + "New SRv6 locator allocated in zebra: name %s, " + "prefix %pFX, block_len %u, node_len %u, func_len %u, arg_len %u", + loc.name, &loc.prefix, loc.block_bits_length, + loc.node_bits_length, loc.function_bits_length, + loc.argument_bits_length); + + /* Lookup on the IS-IS areas */ + for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { + /* If SRv6 is enabled on this area and the configured locator + * corresponds to the new locator, then request a chunk from the + * locator */ + if (area->srv6db.config.enabled && + strncmp(area->srv6db.config.srv6_locator_name, loc.name, + sizeof(area->srv6db.config.srv6_locator_name)) == 0) { + sr_debug( + "Sending a request to get a chunk from the SRv6 locator %s (%pFX) " + "for IS-IS area %s", + loc.name, &loc.prefix, area->area_tag); + + if (isis_zebra_srv6_manager_get_locator_chunk( + loc.name) < 0) + return -1; + } + } + + return 0; +} + /** * Request an SRv6 locator chunk to the SRv6 Manager (zebra) asynchronously. * @@ -924,6 +969,7 @@ static zclient_handler *const isis_handlers[] = { [ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] = isis_zebra_process_srv6_locator_chunk, + [ZEBRA_SRV6_LOCATOR_ADD] = isis_zebra_process_srv6_locator_add, }; void isis_zebra_init(struct event_loop *master, int instance) -- 2.39.5