diff options
author | Yuqing Zhao <galadriel.zyq@alibaba-inc.com> | 2025-01-13 11:04:19 +0100 |
---|---|---|
committer | Yuqing Zhao <galadriel.zyq@alibaba-inc.com> | 2025-01-18 11:28:49 +0100 |
commit | 33615773c45b791941d925e5a37af53b5a55b58d (patch) | |
tree | 956b306b454847b3d1f3b6015f3eb542a100d4b4 /staticd | |
parent | staticd: Request/Release SIDs to SID Manager (diff) | |
download | frr-33615773c45b791941d925e5a37af53b5a55b58d.tar.xz frr-33615773c45b791941d925e5a37af53b5a55b58d.zip |
staticd: Install SIDs when a dependent interface goes up/down
Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Diffstat (limited to 'staticd')
-rw-r--r-- | staticd/static_srv6.c | 40 | ||||
-rw-r--r-- | staticd/static_srv6.h | 9 | ||||
-rw-r--r-- | staticd/static_zebra.c | 4 |
3 files changed, 53 insertions, 0 deletions
diff --git a/staticd/static_srv6.c b/staticd/static_srv6.c index d8e55894f..032bb9de9 100644 --- a/staticd/static_srv6.c +++ b/staticd/static_srv6.c @@ -14,6 +14,7 @@ #include "static_srv6.h" #include "static_vrf.h" #include "static_zebra.h" +#include "static_debug.h" /* * List of SRv6 SIDs. @@ -25,6 +26,45 @@ DEFINE_MTYPE_STATIC(STATIC, STATIC_SRV6_LOCATOR, "Static SRv6 locator"); DEFINE_MTYPE_STATIC(STATIC, STATIC_SRV6_SID, "Static SRv6 SID"); /* + * When an interface is enabled in the kernel, go through all the static SRv6 SIDs in + * the system that use this interface and install/remove them in the zebra RIB. + * + * ifp - The interface being enabled + * is_up - Whether the interface is up or down + */ +void static_ifp_srv6_sids_update(struct interface *ifp, bool is_up) +{ + struct static_srv6_sid *sid; + struct listnode *node; + + if (!srv6_sids || !ifp) + return; + + DEBUGD(&static_dbg_srv6, "%s: Interface %s %s. %s SIDs that depend on the interface", + __func__, (is_up) ? "enabled" : "disabled", (is_up) ? "Removing" : "disabled", + ifp->name); + + /* + * iterate over the list of SRv6 SIDs and remove the SIDs that use this + * VRF from the zebra RIB + */ + for (ALL_LIST_ELEMENTS_RO(srv6_sids, node, sid)) { + if ((strcmp(sid->attributes.vrf_name, ifp->name) == 0) || + (strncmp(ifp->name, DEFAULT_SRV6_IFNAME, sizeof(ifp->name)) == 0 && + (sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END || + sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID))) { + if (is_up) { + static_zebra_srv6_sid_install(sid); + SET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA); + } else { + static_zebra_srv6_sid_uninstall(sid); + UNSET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA); + } + } + } +} + +/* * Allocate an SRv6 SID object and initialize the fields common to all the * behaviors (i.e., SID address and behavor). */ diff --git a/staticd/static_srv6.h b/staticd/static_srv6.h index bed0ab7fa..48986092a 100644 --- a/staticd/static_srv6.h +++ b/staticd/static_srv6.h @@ -85,6 +85,15 @@ extern void static_srv6_init(void); /* Clean up all the SRv6 data structures. */ extern void static_srv6_cleanup(void); +/* + * When an interface is enabled in the kernel, go through all the static SRv6 SIDs in + * the system that use this interface and install/remove them in the zebra RIB. + * + * ifp - The interface being enabled + * is_up - Whether the interface is up or down + */ +void static_ifp_srv6_sids_update(struct interface *ifp, bool is_up); + struct static_srv6_locator *static_srv6_locator_alloc(const char *name); void static_srv6_locator_free(struct static_srv6_locator *locator); struct static_srv6_locator *static_srv6_locator_lookup(const char *name); diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index 6e8d275d6..e87eaed00 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -116,6 +116,8 @@ static int static_ifp_up(struct interface *ifp) { static_ifindex_update(ifp, true); + static_ifp_srv6_sids_update(ifp, true); + return 0; } @@ -123,6 +125,8 @@ static int static_ifp_down(struct interface *ifp) { static_ifindex_update(ifp, false); + static_ifp_srv6_sids_update(ifp, false); + return 0; } |