Skip to content

Commit

Permalink
isisd: Add pack function for SRv6 Locator TLV
Browse files Browse the repository at this point in the history
Add a function to pack an SRv6 Locator TLV and all its Sub-TLVs
(RFC 9352 section sonic-net#7.1).

Signed-off-by: Carmine Scarpitta <[email protected]>
  • Loading branch information
cscarpitta committed Sep 11, 2023
1 parent efb113b commit b2f0b7d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions isisd/isis_tlvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5588,6 +5588,43 @@ static void free_item_srv6_locator(struct isis_item *i)
XFREE(MTYPE_ISIS_TLV, item);
}

static int pack_item_srv6_locator(struct isis_item *i, struct stream *s,
size_t *min_len)
{
struct isis_srv6_locator_tlv *loc = (struct isis_srv6_locator_tlv *)i;

if (STREAM_WRITEABLE(s) < 7 + (unsigned)PSIZE(loc->prefix.prefixlen)) {
*min_len = 7 + (unsigned)PSIZE(loc->prefix.prefixlen);
return 1;
}

stream_putl(s, loc->metric);
stream_putc(s, loc->flags);
stream_putc(s, loc->algorithm);
/* Locator size */
stream_putc(s, loc->prefix.prefixlen);
/* Locator prefix */
stream_put(s, &loc->prefix.prefix.s6_addr,
PSIZE(loc->prefix.prefixlen));

if (loc->subtlvs) {
/* Pack Sub-TLVs */
if (pack_subtlvs(loc->subtlvs, s))
return 1;
} else {
/* No Sub-TLVs */
if (STREAM_WRITEABLE(s) < 1) {
*min_len = 8 + (unsigned)PSIZE(loc->prefix.prefixlen);
return 1;
}

/* Put 0 as Sub-TLV length, because we have no Sub-TLVs */
stream_putc(s, 0);
}

return 0;
}

/* Functions related to tlvs in general */

struct isis_tlvs *isis_alloc_tlvs(void)
Expand Down

0 comments on commit b2f0b7d

Please sign in to comment.