Skip to content

Commit

Permalink
zebra, lib: add locator name in sid notify messages
Browse files Browse the repository at this point in the history
In the near future, some daemons may only register SIDs. This may be
the case for the pathd daemon when creating SRv6 binding SIDs.

When a locator is getting deleted at ZEBRA level, the daemon may have
an easy way to find out the SIds to unregister to.

This commit proposes to add the locator name to the SID_SRV6_NOTIFY
message whenever possible. Only case when an allocation failure happens,
the locator will not be present. In all other places, the notify API
at procol levels has the locator name extra-parameter.

Signed-off-by: Philippe Guibert <[email protected]>
Signed-off-by: Carmine Scarpitta <[email protected]>
  • Loading branch information
pguibert6WIND authored and cscarpitta committed Jun 17, 2024
1 parent 209223d commit 36a310c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
18 changes: 17 additions & 1 deletion lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -2136,9 +2136,12 @@ bool zapi_iptable_notify_decode(struct stream *s,
bool zapi_srv6_sid_notify_decode(struct stream *s, struct srv6_sid_ctx *ctx,
struct in6_addr *sid_value, uint32_t *func,
uint32_t *wide_func,
enum zapi_srv6_sid_notify *note)
enum zapi_srv6_sid_notify *note,
char **p_locator_name)
{
uint32_t f, wf;
uint16_t len;
static char locator_name[SRV6_LOCNAME_SIZE] = {};

STREAM_GET(note, s, sizeof(*note));
STREAM_GET(ctx, s, sizeof(struct srv6_sid_ctx));
Expand All @@ -2151,6 +2154,19 @@ bool zapi_srv6_sid_notify_decode(struct stream *s, struct srv6_sid_ctx *ctx,
if (wide_func)
*wide_func = wf;

STREAM_GETW(s, len);
if (len > SRV6_LOCNAME_SIZE) {
*p_locator_name = NULL;
return false;
}
if (p_locator_name) {
if (len == 0)
*p_locator_name = NULL;
else {
STREAM_GET(locator_name, s, len);
*p_locator_name = locator_name;
}
}
return true;

stream_failure:
Expand Down
3 changes: 2 additions & 1 deletion lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,8 @@ bool zapi_ipset_notify_decode(struct stream *s,
bool zapi_srv6_sid_notify_decode(struct stream *s, struct srv6_sid_ctx *ctx,
struct in6_addr *sid_value, uint32_t *func,
uint32_t *wide_func,
enum zapi_srv6_sid_notify *note);
enum zapi_srv6_sid_notify *note,
char **locator_name);

/* Nexthop-group message apis */
extern enum zclient_send_status
Expand Down
11 changes: 10 additions & 1 deletion zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,9 @@ void zsend_neighbor_notify(int cmd, struct interface *ifp,

void zsend_srv6_sid_notify(struct zserv *client, const struct srv6_sid_ctx *ctx,
struct in6_addr *sid_value, uint32_t func,
uint32_t wide_func, enum zapi_srv6_sid_notify note)
uint32_t wide_func, const char *locator_name,
enum zapi_srv6_sid_notify note)

{
struct stream *s;
uint16_t cmd = ZEBRA_SRV6_SID_NOTIFY;
Expand All @@ -1027,6 +1029,13 @@ void zsend_srv6_sid_notify(struct zserv *client, const struct srv6_sid_ctx *ctx,
stream_putl(s, func);
/* SRv6 wide SID function */
stream_putl(s, wide_func);
/* SRv6 locator name optional */
if (locator_name) {
stream_putw(s, strlen(locator_name));
stream_put(s, locator_name, strlen(locator_name));
} else
stream_putw(s, 0);

stream_putw_at(s, 0, stream_get_endp(s));

zserv_send_message(client, s);
Expand Down
2 changes: 1 addition & 1 deletion zebra/zapi_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extern void zsend_neighbor_notify(int cmd, struct interface *ifp,
extern void zsend_srv6_sid_notify(struct zserv *client,
const struct srv6_sid_ctx *ctx,
struct in6_addr *sid_value, uint32_t func,
uint32_t wide_func,
uint32_t wide_func, const char *locator_name,
enum zapi_srv6_sid_notify note);

extern int zsend_client_close_notify(struct zserv *client,
Expand Down
15 changes: 12 additions & 3 deletions zebra/zebra_srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,7 @@ static int srv6_manager_get_sid_internal(struct zebra_srv6_sid **sid,
sid_value ? sid_value : &in6addr_any, locator_name);

/* Notify client about SID alloc failure */
zsend_srv6_sid_notify(client, ctx, sid_value, 0, 0,
zsend_srv6_sid_notify(client, ctx, sid_value, 0, 0, NULL,
ZAPI_SRV6_SID_FAIL_ALLOC);
} else if (ret == 0) {
if (IS_ZEBRA_DEBUG_PACKET)
Expand All @@ -2294,6 +2294,8 @@ static int srv6_manager_get_sid_internal(struct zebra_srv6_sid **sid,

zsend_srv6_sid_notify(client, ctx, &(*sid)->value, (*sid)->func,
(*sid)->wide_func,
(*sid)->locator ? (*sid)->locator->name
: NULL,
ZAPI_SRV6_SID_ALLOCATED);
} else {
if (IS_ZEBRA_DEBUG_PACKET)
Expand All @@ -2308,6 +2310,9 @@ static int srv6_manager_get_sid_internal(struct zebra_srv6_sid **sid,
for (ALL_LIST_ELEMENTS_RO((*sid)->client_list, node, c))
zsend_srv6_sid_notify(c, ctx, &(*sid)->value,
(*sid)->func, (*sid)->wide_func,
(*sid)->locator
? (*sid)->locator->name
: NULL,
ZAPI_SRV6_SID_ALLOCATED);
}

Expand Down Expand Up @@ -2366,6 +2371,7 @@ static int srv6_manager_release_sid_internal(struct zserv *client,
struct zebra_srv6_sid_ctx *zctx;
struct listnode *node, *nnode;
char buf[256];
const char *locator_name = NULL;

if (IS_ZEBRA_DEBUG_PACKET)
zlog_debug("%s: releasing SRv6 SID associated with ctx %s",
Expand All @@ -2374,6 +2380,9 @@ static int srv6_manager_release_sid_internal(struct zserv *client,
/* Lookup Zebra SID context and release it */
for (ALL_LIST_ELEMENTS(srv6->sids, node, nnode, zctx))
if (memcmp(&zctx->ctx, ctx, sizeof(struct srv6_sid_ctx)) == 0) {
if (zctx->sid && zctx->sid->locator)
locator_name =
(const char *)zctx->sid->locator->name;
ret = release_srv6_sid(client, zctx);
break;
}
Expand All @@ -2383,10 +2392,10 @@ static int srv6_manager_release_sid_internal(struct zserv *client,
srv6_sid_ctx2str(buf, sizeof(buf), ctx));

if (ret == 0)
zsend_srv6_sid_notify(client, ctx, NULL, 0, 0,
zsend_srv6_sid_notify(client, ctx, NULL, 0, 0, locator_name,
ZAPI_SRV6_SID_RELEASED);
else
zsend_srv6_sid_notify(client, ctx, NULL, 0, 0,
zsend_srv6_sid_notify(client, ctx, NULL, 0, 0, locator_name,
ZAPI_SRV6_SID_FAIL_RELEASE);

return ret;
Expand Down

0 comments on commit 36a310c

Please sign in to comment.