From: Philippe Guibert Date: Wed, 2 Apr 2025 11:20:18 +0000 (+0200) Subject: lib: add support for flavors in seg6 routes X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=a95fd3e76fc1e056c53752963017a7fd75ed99b2;p=mirror%2Ffrr.git lib: add support for flavors in seg6 routes Until now, the 'show ipv6 route' was not showing up the flavors. > ip/ip -6 route add 2007::1 encap seg6local action End flavors psp dev dum1 Before: > rt1# show ipv6 route > [..] > K>* 2007::1/128 [0/1024] is directly connected, dum1, seg6local End -, weight 1, 00:00:04 After: > rt1# show ipv6 route > [..] > K>* 2007::1/128 [0/1024] is directly connected, dum1, seg6local End (PSP), weight 1, 00:00:04 Note that the next-csid linux flavor will be handled separately. Signed-off-by: Philippe Guibert --- diff --git a/lib/srv6.c b/lib/srv6.c index 4d820e2fcc..e8a0d505df 100644 --- a/lib/srv6.c +++ b/lib/srv6.c @@ -116,35 +116,65 @@ void seg6local_context2json(const struct seg6local_context *ctx, } } +static char *seg6local_flavors2str(char *str, size_t size, + const struct seg6local_flavors_info *flv_info) +{ + size_t len = 0; + bool first = true; + + if (!CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_PSP | + ZEBRA_SEG6_LOCAL_FLV_OP_USP | + ZEBRA_SEG6_LOCAL_FLV_OP_USD)) + return str; + + len += snprintf(str + len, size - len, " ("); + if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_PSP)) { + len += snprintf(str + len, size - len, "%sPSP", first ? "" : "/"); + first = false; + } + if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_USP)) { + len += snprintf(str + len, size - len, "%sUSP", first ? "" : "/"); + first = false; + } + if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_USD)) + len += snprintf(str + len, size - len, "%sUSD", first ? "" : "/"); + + snprintf(str + len, size - len, ")"); + + return str; +} const char *seg6local_context2str(char *str, size_t size, const struct seg6local_context *ctx, uint32_t action) { - switch (action) { + char flavor[SRV6_FLAVORS_STRLEN], *p_flavor; + flavor[0] = '\0'; + p_flavor = seg6local_flavors2str(flavor, sizeof(flavor), &ctx->flv); + switch (action) { case ZEBRA_SEG6_LOCAL_ACTION_END: - snprintf(str, size, "-"); + snprintf(str, size, "%s", p_flavor); return str; case ZEBRA_SEG6_LOCAL_ACTION_END_X: case ZEBRA_SEG6_LOCAL_ACTION_END_DX6: - snprintfrr(str, size, "nh6 %pI6", &ctx->nh6); + snprintfrr(str, size, "nh6 %pI6%s", &ctx->nh6, p_flavor); return str; case ZEBRA_SEG6_LOCAL_ACTION_END_DX4: - snprintfrr(str, size, "nh4 %pI4", &ctx->nh4); + snprintfrr(str, size, "nh4 %pI4%s", &ctx->nh4, p_flavor); return str; case ZEBRA_SEG6_LOCAL_ACTION_END_T: case ZEBRA_SEG6_LOCAL_ACTION_END_DT6: case ZEBRA_SEG6_LOCAL_ACTION_END_DT4: case ZEBRA_SEG6_LOCAL_ACTION_END_DT46: - snprintf(str, size, "table %u", ctx->table); + snprintf(str, size, "table %u%s", ctx->table, p_flavor); return str; case ZEBRA_SEG6_LOCAL_ACTION_END_B6: case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP: - snprintfrr(str, size, "nh6 %pI6", &ctx->nh6); + snprintfrr(str, size, "nh6 %pI6%s", &ctx->nh6, p_flavor); return str; case ZEBRA_SEG6_LOCAL_ACTION_END_DX2: case ZEBRA_SEG6_LOCAL_ACTION_END_BM: diff --git a/lib/srv6.h b/lib/srv6.h index bd80253b55..708792fb28 100644 --- a/lib/srv6.h +++ b/lib/srv6.h @@ -88,6 +88,9 @@ struct seg6_segs { struct in6_addr segs[256]; }; +/* flavors psp, usd, usp, next-csid */ +#define SRV6_FLAVORS_STRLEN 50 + struct seg6local_flavors_info { /* Flavor operations */ uint32_t flv_ops;