]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add support for flavors in seg6 routes
authorPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 2 Apr 2025 11:20:18 +0000 (13:20 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 1 May 2025 07:15:53 +0000 (09:15 +0200)
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 <philippe.guibert@6wind.com>
lib/srv6.c
lib/srv6.h

index 4d820e2fcc15e37b831410a034fbab4d1c6958d5..e8a0d505df9aca07a731a33a933f1df8b019621a 100644 (file)
@@ -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:
index bd80253b55a38a215cda8753451f9a75004a4013..708792fb288d8521e0748168f3a65ed0cb2fd806 100644 (file)
@@ -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;