Skip to content

Commit

Permalink
Merge pull request #18064 from cscarpitta/fix/fix_srv6_sid_parameters
Browse files Browse the repository at this point in the history
staticd: Fix SRv6 SID installation and deletion
  • Loading branch information
donaldsharp authored Feb 13, 2025
2 parents caeef98 + a6d02fe commit 8a661e5
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 17 deletions.
5 changes: 5 additions & 0 deletions lib/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ void nexthop_json_helper(json_object *json_nexthop,
json_object *json_backups = NULL;
json_object *json_seg6local = NULL;
json_object *json_seg6local_context = NULL;
json_object *json_srv6_sid_structure = NULL;
json_object *json_seg6 = NULL;
json_object *json_segs = NULL;
int i;
Expand Down Expand Up @@ -1328,6 +1329,10 @@ void nexthop_json_helper(json_object *json_nexthop,
json_object_object_add(json_nexthop, "seg6localContext",
json_seg6local_context);

json_srv6_sid_structure = json_object_new_object();
srv6_sid_structure2json(&nexthop->nh_srv6->seg6local_ctx, json_srv6_sid_structure);
json_object_object_add(json_seg6local, "sidStructure", json_srv6_sid_structure);

if (nexthop->nh_srv6->seg6_segs &&
nexthop->nh_srv6->seg6_segs->num_segs == 1) {
json_seg6 = json_object_new_object();
Expand Down
8 changes: 8 additions & 0 deletions lib/srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ int snprintf_seg6_segs(char *str,
return strlen(str);
}

void srv6_sid_structure2json(const struct seg6local_context *ctx, json_object *json)
{
json_object_int_add(json, "blockLen", ctx->block_len);
json_object_int_add(json, "nodeLen", ctx->node_len);
json_object_int_add(json, "funcLen", ctx->function_len);
json_object_int_add(json, "argLen", ctx->argument_len);
}

void seg6local_context2json(const struct seg6local_context *ctx,
uint32_t action, json_object *json)
{
Expand Down
1 change: 1 addition & 0 deletions lib/srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ const char *seg6local_context2str(char *str, size_t size,
uint32_t action);
void seg6local_context2json(const struct seg6local_context *ctx,
uint32_t action, json_object *json);
void srv6_sid_structure2json(const struct seg6local_context *ctx, json_object *json);

static inline const char *srv6_sid_ctx2str(char *str, size_t size,
const struct srv6_sid_ctx *ctx)
Expand Down
62 changes: 54 additions & 8 deletions staticd/static_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ 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)
return;
Expand Down Expand Up @@ -696,10 +699,30 @@ void static_zebra_srv6_sid_install(struct static_srv6_sid *sid)
break;
}

ctx.block_len = sid->locator->block_bits_length;
ctx.node_len = sid->locator->node_bits_length;
ctx.function_len = sid->locator->function_bits_length;
ctx.argument_len = sid->locator->argument_bits_length;
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;
}

sid_locator = sid->addr;
sid_locator.prefixlen = sid->locator->block_bits_length + sid->locator->node_bits_length;
apply_mask(&sid_locator);

if (prefix_same(&sid_locator, &sid->locator->prefix))
ctx.node_len = sid->locator->node_bits_length;

ctx.function_len = sid->addr.prefixlen - (ctx.block_len + ctx.node_len);

/* Attach the SID to the SRv6 interface */
if (!ifp) {
Expand All @@ -724,6 +747,9 @@ void static_zebra_srv6_sid_uninstall(struct static_srv6_sid *sid)
struct interface *ifp = NULL;
struct seg6local_context ctx = {};
struct vrf *vrf;
struct prefix_ipv6 sid_block = {};
struct prefix_ipv6 locator_block = {};
struct prefix_ipv6 sid_locator = {};

if (!sid)
return;
Expand Down Expand Up @@ -803,10 +829,30 @@ void static_zebra_srv6_sid_uninstall(struct static_srv6_sid *sid)
}
}

ctx.block_len = sid->locator->block_bits_length;
ctx.node_len = sid->locator->node_bits_length;
ctx.function_len = sid->locator->function_bits_length;
ctx.argument_len = sid->locator->argument_bits_length;
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;
}

sid_locator = sid->addr;
sid_locator.prefixlen = sid->locator->block_bits_length + sid->locator->node_bits_length;
apply_mask(&sid_locator);

if (prefix_same(&sid_locator, &sid->locator->prefix))
ctx.node_len = sid->locator->node_bits_length;

ctx.function_len = sid->addr.prefixlen - (ctx.block_len + ctx.node_len);

static_zebra_send_localsid(ZEBRA_ROUTE_DELETE, &sid->addr.prefix, sid->addr.prefixlen,
ifp->ifindex, action, &ctx);
Expand Down
32 changes: 28 additions & 4 deletions tests/topotests/static_srv6_sids/expected_srv6_sids.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End"
"action": "End",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 0,
"argLen": 0
}
},
"seg6localContext": {

Expand Down Expand Up @@ -60,7 +66,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End.DT4"
"action": "End.DT4",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 16,
"argLen": 0
}
},
"seg6localContext": {
"table": 10
Expand Down Expand Up @@ -95,7 +107,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End.DT6"
"action": "End.DT6",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 16,
"argLen": 0
}
},
"seg6localContext": {
"table": 20
Expand Down Expand Up @@ -130,7 +148,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End.DT46"
"action": "End.DT46",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 16,
"argLen": 0
}
},
"seg6localContext": {
"table": 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End.DT4"
"action": "End.DT4",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 16,
"argLen": 0
}
},
"seg6localContext": {
"table": 10
Expand Down Expand Up @@ -60,7 +66,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End.DT6"
"action": "End.DT6",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 16,
"argLen": 0
}
},
"seg6localContext": {
"table": 20
Expand Down Expand Up @@ -95,7 +107,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End.DT46"
"action": "End.DT46",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 16,
"argLen": 0
}
},
"seg6localContext": {
"table": 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End.DT4"
"action": "End.DT4",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 16,
"argLen": 0
}
},
"seg6localContext": {
"table": 10
Expand Down Expand Up @@ -60,7 +66,13 @@
"active": true,
"weight": 1,
"seg6local": {
"action": "End.DT46"
"action": "End.DT46",
"sidStructure": {
"blockLen": 32,
"nodeLen": 16,
"funcLen": 16,
"argLen": 0
}
},
"seg6localContext": {
"table": 30
Expand Down

0 comments on commit 8a661e5

Please sign in to comment.