Skip to contentSkip to conversation

net: allow dissecting/matching tunnel control flags

PATCH Superseded Davide Caratti 3 participants 5 messages Feb 1, 2024 – Feb 3, 2024

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover net: allow dissecting/matching tunnel control flags

Ilya says: "for correct matching on decapsulated packets, we should match on not only tunnel id and headers, but also on tunnel configuration flags like TUNNEL_NO_CSUM and TUNNEL_DONT_FRAGMENT. This is done to distinguish similar tunnels with slightly different configs. And it is important since tunnel configuration is flow based, i.e. can be different for every packet, even though the main tunnel port is the same."

- patch 1 extends the kernel's flow dissector to extract these flags from the packet's tunnel metadata.
- patch 2 extends TC flower to match on any combination of TUNNEL_NO_CSUM, TUNNEL_OAM and TUNNEL_DONT_FRAGMENT.

v2:
- use NL_REQ_ATTR_CHECK() where possible (thanks Jamal)
- don't overwrite 'ret' in the error path of fl_set_key_flags()

Davide Caratti (2):
flow_dissector: add support for tunnel control flags net/sched: cls_flower: add support for matching tunnel control flags

 include/net/flow_dissector.h | 11 ++++++++
 include/uapi/linux/pkt_cls.h |  3 +++
 net/core/flow_dissector.c    | 13 +++++++++-
 net/sched/cls_flower.c       | 50 +++++++++++++++++++++++++++++++++++-
 4 files changed, 75 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 flow_dissector: add support for tunnel control flags

dissect [no]csum, [no]dontfrag, [no]oam flags on 'external' tunnels. This is a prerequisite for matching these control flags using TC flower.

---
 include/net/flow_dissector.h | 11 +++++++++++
 net/core/flow_dissector.c    | 13 ++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
include/net/flow_dissector.h +11 -0
index 1a7131d6cb0e..98a0050d5cc3 100644
@@ -329,6 +329,16 @@ struct flow_dissector_key_cfm {
 #define FLOW_DIS_CFM_MDL_MASK GENMASK(7, 5)
 #define FLOW_DIS_CFM_MDL_MAX 7
 
+/**
+ * struct flow_dissector_key_enc_flags
+ * @flags: tunnel control flags
+ */
+struct flow_dissector_key_enc_flags {
+	__be16 flags;
+};
+
+#define TUNNEL_FLAGS_PRESENT (TUNNEL_CSUM | TUNNEL_DONT_FRAGMENT | TUNNEL_OAM)
+
 enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
 	FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
@@ -363,6 +373,7 @@ enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_L2TPV3, /* struct flow_dissector_key_l2tpv3 */
 	FLOW_DISSECTOR_KEY_CFM, /* struct flow_dissector_key_cfm */
 	FLOW_DISSECTOR_KEY_IPSEC, /* struct flow_dissector_key_ipsec */
+	FLOW_DISSECTOR_KEY_ENC_FLAGS, /* struct flow_dissector_key_enc_flags */
 
 	FLOW_DISSECTOR_KEY_MAX,
 };
net/core/flow_dissector.c +12 -1
index 272f09251343..9099a5524d7c 100644
@@ -382,7 +382,9 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb,
 	    !dissector_uses_key(flow_dissector,
 				FLOW_DISSECTOR_KEY_ENC_IP) &&
 	    !dissector_uses_key(flow_dissector,
-				FLOW_DISSECTOR_KEY_ENC_OPTS))
+				FLOW_DISSECTOR_KEY_ENC_OPTS) &&
+	    !dissector_uses_key(flow_dissector,
+				FLOW_DISSECTOR_KEY_ENC_FLAGS))
 		return;
 
 	info = skb_tunnel_info(skb);
@@ -467,6 +469,15 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb,
 						TUNNEL_OPTIONS_PRESENT;
 		}
 	}
+
+	if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_ENC_FLAGS)) {
+		struct flow_dissector_key_enc_flags *enc_flags;
+
+		enc_flags = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_ENC_FLAGS,
+						      target_container);
+		enc_flags->flags = info->key.tun_flags & TUNNEL_FLAGS_PRESENT;
+	}
 }
 EXPORT_SYMBOL(skb_flow_dissect_tunnel_info);
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/2 net/sched: cls_flower: add support for matching tunnel control flags

In reply to Davide Caratti

extend cls_flower to match flags belonging to 'TUNNEL_FLAGS_PRESENT' mask inside skb tunnel metadata.

---
 include/uapi/linux/pkt_cls.h |  3 +++
 net/sched/cls_flower.c       | 50 +++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)
include/uapi/linux/pkt_cls.h +3 -0
index ea277039f89d..e3394f9d06b7 100644
@@ -554,6 +554,9 @@ enum {
 	TCA_FLOWER_KEY_SPI,		/* be32 */
 	TCA_FLOWER_KEY_SPI_MASK,	/* be32 */
 
+	TCA_FLOWER_KEY_ENC_FLAGS,	/* be16 */
+	TCA_FLOWER_KEY_ENC_FLAGS_MASK,	/* be16 */
+
 	__TCA_FLOWER_MAX,
 };
 
net/sched/cls_flower.c +49 -1

94 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH net-next v2 2/2] net/sched: cls_flower: add support for matching tunnel control flags

Quoted 2 lines · On Thu, 1 Feb 2024 17:51:44 +0100 Davide Caratti wrote:

extend cls_flower to match flags belonging to 'TUNNEL_FLAGS_PRESENT' mask inside skb tunnel metadata.

sparse complains about bad endian somewhere in this..

Signature · 1 line
pw-bot: cr
maintainer Acked-by on the v2 series
#4 lore raw
In reply to Davide Caratti
Quoted 8 lines · Davide Caratti

Ilya says: "for correct matching on decapsulated packets, we should match on not only tunnel id and headers, but also on tunnel configuration flags like TUNNEL_NO_CSUM and TUNNEL_DONT_FRAGMENT. This is done to distinguish similar tunnels with slightly different configs. And it is important since tunnel configuration is flow based, i.e. can be different for every packet, even though the main tunnel port is the same."

Quoted 5 lines

- patch 1 extends the kernel's flow dissector to extract these flags from the packet's tunnel metadata.
- patch 2 extends TC flower to match on any combination of TUNNEL_NO_CSUM, TUNNEL_OAM and TUNNEL_DONT_FRAGMENT.

For the patchset:

cheers,
jamal

Quoted 17 lines

v2:
- use NL_REQ_ATTR_CHECK() where possible (thanks Jamal)
- don't overwrite 'ret' in the error path of fl_set_key_flags()

Davide Caratti (2):
flow_dissector: add support for tunnel control flags net/sched: cls_flower: add support for matching tunnel control flags

 include/net/flow_dissector.h | 11 ++++++++
 include/uapi/linux/pkt_cls.h |  3 +++
 net/core/flow_dissector.c    | 13 +++++++++-
 net/sched/cls_flower.c       | 50 +++++++++++++++++++++++++++++++++++-
 4 files changed, 75 insertions(+), 2 deletions(-)

--
2.43.0