diff options
| author | Jafar Al-Gharaibeh <jafar@atcorp.com> | 2025-04-08 10:56:13 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-08 10:56:13 -0500 |
| commit | 18716fecb975bd6fbfa7544a26971ea21fbb1b87 (patch) | |
| tree | aac4da08cf68ccac1540b7adc017d7a740dec8bf /staticd/static_zebra.c | |
| parent | 8bd485a286fba0d2e9c4e7351e5fb0a5913d7edd (diff) | |
| parent | 5a75a0685c6bc9af890d5bd61f69bde7870db913 (diff) | |
Merge pull request #18609 from cscarpitta/fix/backport_check_sid_loc_block_beforehand
staticd: Avoid requesting SRv6 sid from zebra when loc and sid block don't match (manual backport #18580)
Diffstat (limited to 'staticd/static_zebra.c')
| -rw-r--r-- | staticd/static_zebra.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index 9a794d4d02..21a5eda6b4 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -615,8 +615,6 @@ void static_zebra_srv6_sid_install(struct static_srv6_sid *sid) struct seg6local_context ctx = {}; struct interface *ifp = NULL; struct vrf *vrf; - struct prefix_ipv6 sid_block = {}; - struct prefix_ipv6 locator_block = {}; struct prefix_ipv6 sid_locator = {}; if (!sid) @@ -699,22 +697,7 @@ void static_zebra_srv6_sid_install(struct static_srv6_sid *sid) break; } - sid_block = sid->addr; - sid_block.prefixlen = sid->locator->block_bits_length; - apply_mask(&sid_block); - - locator_block = sid->locator->prefix; - locator_block.prefixlen = sid->locator->block_bits_length; - apply_mask(&locator_block); - - if (prefix_same(&sid_block, &locator_block)) - ctx.block_len = sid->locator->block_bits_length; - else { - zlog_warn("SID block %pFX does not match locator block %pFX", &sid_block, - &locator_block); - return; - } - + ctx.block_len = sid->locator->block_bits_length; sid_locator = sid->addr; sid_locator.prefixlen = sid->locator->block_bits_length + sid->locator->node_bits_length; apply_mask(&sid_locator); @@ -860,13 +843,37 @@ void static_zebra_srv6_sid_uninstall(struct static_srv6_sid *sid) UNSET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA); } +/* Validate if the sid block and locator block are the same */ +static bool static_zebra_sid_locator_block_check(struct static_srv6_sid *sid) +{ + struct prefix_ipv6 sid_block = {}; + struct prefix_ipv6 locator_block = {}; + + sid_block = sid->addr; + sid_block.prefixlen = sid->locator->block_bits_length; + apply_mask(&sid_block); + + locator_block = sid->locator->prefix; + locator_block.prefixlen = sid->locator->block_bits_length; + apply_mask(&locator_block); + + if (!prefix_same(&sid_block, &locator_block)) { + zlog_warn("SID block %pFX does not match locator block %pFX", &sid_block, + &locator_block); + + return false; + } + + return true; +} + extern void static_zebra_request_srv6_sid(struct static_srv6_sid *sid) { struct srv6_sid_ctx ctx = {}; int ret = 0; struct vrf *vrf; - if (!sid) + if (!sid || !static_zebra_sid_locator_block_check(sid)) return; /* convert `srv6_endpoint_behavior_codepoint` to `seg6local_action_t` */ |
