Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Alexandre Cassen
Mon, 09 Nov 2026 13:11
[PATCH iproute2-next 0/2] flower: support a mask on enc_key_id
Author: Alexandre Cassen
Date: Mon, 09 Nov 2026 13:11
Date: Mon, 09 Nov 2026 13:11
31 lines
9035 bytes
9035 bytes
tc support for the flower mask of the kernel series "tc flower: tunnel key
partitioning for RX queue steering". One rule handles a block of tunnel
keys:
tc filter add dev eth0 ingress protocol ip flower skip_sw \
ip_proto udp dst_port 2152 enc_key_id 0x40000000/0xc0000000 \
action skbedit queue_mapping 1 skip_sw
Patch 1 follows the kernel header and can be dropped once the headers are
synced. Patch 2 adds the mask to parsing, printing and the man page.
Exact rules dump as before. An older kernel ignores the attribute. Exact
rules keep working there. A masked rule matches as if it had a full mask.
Tested under User-Mode Linux and on ConnectX-7 against the kernel series
and a kernel without it.
Alexandre Cassen (2):
uapi: pkt_cls: add flower mask for enc_key_id
flower: support a mask on enc_key_id
include/uapi/linux/pkt_cls.h | 2 ++
man/man8/tc-flower.8 | 15 +++++++++----
tc/f_flower.c | 41 +++++++++++++++++++-----------------
tc/tc_util.c | 12 +++++++++++
tc/tc_util.h | 2 ++
5 files changed, 49 insertions(+), 23 deletions(-)
--
2.47.3
[PATCH iproute2-next 1/2] uapi: pkt_cls: add flower mask for enc_key_id
Author: Alexandre Cassen
Date: Mon, 09 Nov 2026 13:11
Date: Mon, 09 Nov 2026 13:11
24 lines
8683 bytes
8683 bytes
Follow the kernel series adding this attribute. This patch can be dropped
once the headers are synced.
Signed-off-by: Alexandre Cassen <acassen@corp.free.fr>
---
include/uapi/linux/pkt_cls.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index 3c24e8e2..16c3f96f 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -560,6 +560,8 @@ enum {
TCA_FLOWER_KEY_ENC_FLAGS, /* be32 */
TCA_FLOWER_KEY_ENC_FLAGS_MASK, /* be32 */
+ TCA_FLOWER_KEY_ENC_KEY_ID_MASK, /* be32 */
+
__TCA_FLOWER_MAX,
};
--
2.47.3
[PATCH iproute2-next 2/2] flower: support a mask on enc_key_id
Author: Alexandre Cassen
Date: Mon, 09 Nov 2026 13:11
Date: Mon, 09 Nov 2026 13:11
177 lines
14124 bytes
14124 bytes
A block of tunnel keys takes one filter per key. Add a mask:
enc_key_id 0x40000000/0xc0000000
The key also accepts a 0x prefix. A plain number stays decimal. The dump
prints a partial mask.
Signed-off-by: Alexandre Cassen <acassen@corp.free.fr>
---
man/man8/tc-flower.8 | 15 +++++++++++----
tc/f_flower.c | 41 ++++++++++++++++++++++-------------------
tc/tc_util.c | 12 ++++++++++++
tc/tc_util.h | 2 ++
4 files changed, 47 insertions(+), 23 deletions(-)
diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8
index 3f8ba465..d64873b5 100644
--- a/man/man8/tc-flower.8
+++ b/man/man8/tc-flower.8
@@ -80,7 +80,7 @@ flower \- flow based traffic control filter
.BR arp_tha " | " arp_sha " } "
.IR MASKED_LLADDR " | "
.B enc_key_id
-.IR KEY-ID " | {"
+.IR MASKED_KEY_ID " | {"
.BR enc_dst_ip " | " enc_src_ip " } { "
.IR ipv4_address " | " ipv6_address " } | "
.B enc_dst_port
@@ -407,7 +407,7 @@ provided in LLADDR format, in which case it is a bitwise mask, or as a
number of high bits to match. If the mask is missing then a match on all
bits is assumed.
.TP
-.BI enc_key_id " NUMBER"
+.BI enc_key_id " MASKED_KEY_ID"
.TQ
.BI enc_dst_ip " PREFIX"
.TQ
@@ -468,8 +468,15 @@ Match the connection zone, and can be masked.
.TQ
.BI pfcp_opts " OPTIONS"
Match on IP tunnel metadata. Key id
-.I NUMBER
-is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel).
+.I MASKED_KEY_ID
+is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel), in decimal or in
+hexadecimal with a 0x prefix. A mask may be optionally provided to limit the
+bits which are matched. A mask is provided by following the value with a slash
+and then the mask. If the mask is missing then a match on all bits is assumed.
+Some drivers also offload the key id on a physical port, where nothing
+decapsulates the packet and the hardware reads the key from its tunnel header.
+Such a filter has no software equivalent and may require
+.BR skip_sw .
.I PREFIX
must be a valid IPv4 or IPv6 address optionally followed by a slash and the
prefix length. If the prefix is missing, \fBtc\fR assumes a full-length
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 6fc2c6a1..54643fd7 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -88,7 +88,7 @@ static void explain(void)
" arp_sha MASKED-LLADDR |\n"
" enc_dst_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
" enc_src_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
- " enc_key_id [ KEY-ID ] |\n"
+ " enc_key_id [ MASKED-KEY-ID ] |\n"
" enc_tos MASKED-IP_TOS |\n"
" enc_ttl MASKED-IP_TTL |\n"
" geneve_opts MASKED-OPTIONS |\n"
@@ -925,16 +925,25 @@ err:
return err;
}
-static int flower_parse_key_id(const char *str, int type, struct nlmsghdr *n)
+static int flower_parse_key_id(char *str, int type, int mask_type,
+ struct nlmsghdr *n)
{
- int ret;
- __be32 key_id;
+ __be32 key_id, mask = htonl(UINT32_MAX);
+ char *slash;
+
+ slash = strchr(str, '/');
+ if (slash)
+ *slash = '\0';
+
+ /* A plain number stays decimal, as it was before masks */
+ if (get_be32(&key_id, str, strncmp(str, "0x", 2) ? 10 : 16) ||
+ (slash && get_be32(&mask, slash + 1, 0)))
+ return -1;
- ret = get_be32(&key_id, str, 10);
- if (!ret)
- addattr32(n, MAX_MSG, type, key_id);
+ addattr32(n, MAX_MSG, type, key_id);
+ addattr32(n, MAX_MSG, mask_type, mask);
- return ret;
+ return 0;
}
static int flower_parse_enc_port(char *str, int type, struct nlmsghdr *n)
@@ -2193,7 +2202,9 @@ static int flower_parse_opt(const struct filter_util *qu, char *handle,
} else if (matches(*argv, "enc_key_id") == 0) {
NEXT_ARG();
ret = flower_parse_key_id(*argv,
- TCA_FLOWER_KEY_ENC_KEY_ID, n);
+ TCA_FLOWER_KEY_ENC_KEY_ID,
+ TCA_FLOWER_KEY_ENC_KEY_ID_MASK,
+ n);
if (ret < 0) {
fprintf(stderr, "Illegal \"enc_key_id\"\n");
return -1;
@@ -2662,15 +2673,6 @@ static void flower_print_ct_mark(struct rtattr *attr,
print_masked_u32("ct_mark", attr, mask_attr, true);
}
-static void flower_print_key_id(const char *name, struct rtattr *attr)
-{
- if (!attr)
- return;
-
- print_nl();
- print_uint_indent_name_value(name, rta_getattr_be32(attr));
-}
-
static void flower_print_geneve_opts(const char *name, struct rtattr *attr,
char *strbuf)
{
@@ -3281,7 +3283,8 @@ static int flower_print_opt(const struct filter_util *qu, FILE *f,
tb[TCA_FLOWER_KEY_ENC_IPV6_SRC],
tb[TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK]);
- flower_print_key_id("enc_key_id", tb[TCA_FLOWER_KEY_ENC_KEY_ID]);
+ print_masked_be32("enc_key_id", tb[TCA_FLOWER_KEY_ENC_KEY_ID],
+ tb[TCA_FLOWER_KEY_ENC_KEY_ID_MASK], true);
flower_print_port("enc_dst_port", tb[TCA_FLOWER_KEY_ENC_UDP_DST_PORT],
tb[TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK]);
diff --git a/tc/tc_util.c b/tc/tc_util.c
index 45d76e75..291f0d9e 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -940,6 +940,18 @@ void print_masked_be16(const char *name, struct rtattr *attr,
mask_attr, newline);
}
+static __u32 __rta_getattr_be32_u32(const struct rtattr *attr)
+{
+ return rta_getattr_be32(attr);
+}
+
+void print_masked_be32(const char *name, struct rtattr *attr,
+ struct rtattr *mask_attr, bool newline)
+{
+ print_masked_type(UINT32_MAX, __rta_getattr_be32_u32, name, attr,
+ mask_attr, newline);
+}
+
void print_ext_msg(struct rtattr **tb)
{
if (!tb[TCA_EXT_WARN_MSG])
diff --git a/tc/tc_util.h b/tc/tc_util.h
index 8ebca396..e46696a9 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -135,6 +135,8 @@ void print_masked_u8(const char *name, struct rtattr *attr,
struct rtattr *mask_attr, bool newline);
void print_masked_be16(const char *name, struct rtattr *attr,
struct rtattr *mask_attr, bool newline);
+void print_masked_be32(const char *name, struct rtattr *attr,
+ struct rtattr *mask_attr, bool newline);
void print_ext_msg(struct rtattr **tb);
#endif
--
2.47.3
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads