netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/5] flower: match on the number of vlan tags
@ 2022-03-23 10:55 Boris Sukholitko
  2022-03-23 10:55 ` [PATCH net-next 1/5] Helper function for vlan ethtype checks Boris Sukholitko
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Boris Sukholitko @ 2022-03-23 10:55 UTC (permalink / raw)
  To: netdev, David S . Miller, Jakub Kicinski, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean,
	Eric Dumazet, zhang kai, Yoshiki Komachi
  Cc: Ilya Lifshits, Boris Sukholitko

[-- Attachment #1: Type: text/plain, Size: 1786 bytes --]

Hi,

Our customers in the fiber telecom world have network configurations
where they would like to control their traffic according to the number
of tags appearing in the packet.

For example, TR247 GPON conformance test suite specification mostly
talks about untagged, single, double tagged packets and gives lax
guidelines on the vlan protocol vs. number of vlan tags.

This is different from the common IT networks where 802.1Q and 802.1ad
protocols are usually describe single and double tagged packet. GPON
configurations that we work with have arbitrary mix the above protocols
and number of vlan tags in the packet.

The following patch series implement number of vlans flower filter. They
add num_of_vlans flower filter as an alternative to vlan ethtype protocol
matching. The end result is that the following command becomes possible:

tc filter add dev eth1 ingress flower \
  num_of_vlans 1 vlan_prio 5 action drop

More about the patch series:
  - patches 1-2 remove duplicate code by introducing is_key_vlan
    helper.
  - patch 3, 4 implement num_of_vlans in the dissector and in the
    flower.
  - patch 5 uses the num_of_vlans filter to allow further matching on
    vlan attributes.

Complementary iproute2 patches are being sent separately.

Thanks,
Boris.

Boris Sukholitko (5):
  Helper function for vlan ethtype checks
  Reduce identation after is_key_vlan refactoring
  Add number of vlan tags dissector
  Add number of vlan tags filter to the flower
  Consider the number of vlan tags for vlan filters

 include/net/flow_dissector.h |  9 ++++
 include/uapi/linux/pkt_cls.h |  2 +
 net/core/flow_dissector.c    | 20 +++++++++
 net/sched/cls_flower.c       | 86 +++++++++++++++++++++++-------------
 4 files changed, 86 insertions(+), 31 deletions(-)

-- 
2.29.2


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH net-next 1/5] Helper function for vlan ethtype checks
  2022-03-23 10:55 [PATCH net-next 0/5] flower: match on the number of vlan tags Boris Sukholitko
@ 2022-03-23 10:55 ` Boris Sukholitko
  2022-03-23 10:55 ` [PATCH net-next 2/5] Reduce identation after is_key_vlan refactoring Boris Sukholitko
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Boris Sukholitko @ 2022-03-23 10:55 UTC (permalink / raw)
  To: netdev, David S . Miller, Jakub Kicinski, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean,
	Eric Dumazet, zhang kai, Yoshiki Komachi
  Cc: Ilya Lifshits, Boris Sukholitko

[-- Attachment #1: Type: text/plain, Size: 2442 bytes --]

There are somewhat repetitive ethertype checks in fl_set_key. Refactor
them into is_vlan_key helper function.

To make the changes clearer, avoid touching identation levels. This is
the job for the next patch in the series.

Signed-off-by: Boris Sukholitko <boris.sukholitko@broadcom.com>
---
 net/sched/cls_flower.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 1a9b1f140f9e..6c355b293f02 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -1492,6 +1492,21 @@ static int fl_set_key_ct(struct nlattr **tb,
 	return 0;
 }
 
+static bool is_vlan_key(struct nlattr *tb, __be16 *ethertype,
+			struct fl_flow_key *key, struct fl_flow_key *mask)
+{
+	if (!tb)
+		return false;
+
+	*ethertype = nla_get_be16(tb);
+	if (eth_type_vlan(*ethertype))
+		return true;
+
+	key->basic.n_proto = *ethertype;
+	mask->basic.n_proto = cpu_to_be16(~0);
+	return false;
+}
+
 static int fl_set_key(struct net *net, struct nlattr **tb,
 		      struct fl_flow_key *key, struct fl_flow_key *mask,
 		      struct netlink_ext_ack *extack)
@@ -1514,17 +1529,12 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
 		       mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK,
 		       sizeof(key->eth.src));
 
-	if (tb[TCA_FLOWER_KEY_ETH_TYPE]) {
-		ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]);
-
-		if (eth_type_vlan(ethertype)) {
+	if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask)) {
 			fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
 					TCA_FLOWER_KEY_VLAN_PRIO, &key->vlan,
 					&mask->vlan);
 
-			if (tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]) {
-				ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]);
-				if (eth_type_vlan(ethertype)) {
+			if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], &ethertype, key, mask)) {
 					fl_set_key_vlan(tb, ethertype,
 							TCA_FLOWER_KEY_CVLAN_ID,
 							TCA_FLOWER_KEY_CVLAN_PRIO,
@@ -1534,15 +1544,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
 						       &mask->basic.n_proto,
 						       TCA_FLOWER_UNSPEC,
 						       sizeof(key->basic.n_proto));
-				} else {
-					key->basic.n_proto = ethertype;
-					mask->basic.n_proto = cpu_to_be16(~0);
-				}
 			}
-		} else {
-			key->basic.n_proto = ethertype;
-			mask->basic.n_proto = cpu_to_be16(~0);
-		}
 	}
 
 	if (key->basic.n_proto == htons(ETH_P_IP) ||
-- 
2.29.2


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 2/5] Reduce identation after is_key_vlan refactoring
  2022-03-23 10:55 [PATCH net-next 0/5] flower: match on the number of vlan tags Boris Sukholitko
  2022-03-23 10:55 ` [PATCH net-next 1/5] Helper function for vlan ethtype checks Boris Sukholitko
@ 2022-03-23 10:55 ` Boris Sukholitko
  2022-03-23 10:56 ` [PATCH net-next 3/5] Add number of vlan tags dissector Boris Sukholitko
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Boris Sukholitko @ 2022-03-23 10:55 UTC (permalink / raw)
  To: netdev, David S . Miller, Jakub Kicinski, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean,
	Eric Dumazet, zhang kai, Yoshiki Komachi
  Cc: Ilya Lifshits, Boris Sukholitko

[-- Attachment #1: Type: text/plain, Size: 1700 bytes --]

Whitespace only.

Signed-off-by: Boris Sukholitko <boris.sukholitko@broadcom.com>
---
 net/sched/cls_flower.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 6c355b293f02..e073787dfd1d 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -1530,21 +1530,21 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
 		       sizeof(key->eth.src));
 
 	if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask)) {
-			fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
-					TCA_FLOWER_KEY_VLAN_PRIO, &key->vlan,
-					&mask->vlan);
-
-			if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], &ethertype, key, mask)) {
-					fl_set_key_vlan(tb, ethertype,
-							TCA_FLOWER_KEY_CVLAN_ID,
-							TCA_FLOWER_KEY_CVLAN_PRIO,
-							&key->cvlan, &mask->cvlan);
-					fl_set_key_val(tb, &key->basic.n_proto,
-						       TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
-						       &mask->basic.n_proto,
-						       TCA_FLOWER_UNSPEC,
-						       sizeof(key->basic.n_proto));
-			}
+		fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
+				TCA_FLOWER_KEY_VLAN_PRIO, &key->vlan,
+				&mask->vlan);
+
+		if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], &ethertype, key, mask)) {
+			fl_set_key_vlan(tb, ethertype,
+					TCA_FLOWER_KEY_CVLAN_ID,
+					TCA_FLOWER_KEY_CVLAN_PRIO,
+					&key->cvlan, &mask->cvlan);
+			fl_set_key_val(tb, &key->basic.n_proto,
+				       TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
+				       &mask->basic.n_proto,
+				       TCA_FLOWER_UNSPEC,
+				       sizeof(key->basic.n_proto));
+		}
 	}
 
 	if (key->basic.n_proto == htons(ETH_P_IP) ||
-- 
2.29.2


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 3/5] Add number of vlan tags dissector
  2022-03-23 10:55 [PATCH net-next 0/5] flower: match on the number of vlan tags Boris Sukholitko
  2022-03-23 10:55 ` [PATCH net-next 1/5] Helper function for vlan ethtype checks Boris Sukholitko
  2022-03-23 10:55 ` [PATCH net-next 2/5] Reduce identation after is_key_vlan refactoring Boris Sukholitko
@ 2022-03-23 10:56 ` Boris Sukholitko
  2022-03-23 10:56 ` [PATCH net-next 4/5] Add number of vlan tags filter to the flower Boris Sukholitko
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Boris Sukholitko @ 2022-03-23 10:56 UTC (permalink / raw)
  To: netdev, David S . Miller, Jakub Kicinski, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean,
	Eric Dumazet, zhang kai, Yoshiki Komachi
  Cc: Ilya Lifshits, Boris Sukholitko

[-- Attachment #1: Type: text/plain, Size: 3126 bytes --]

Our customers in the fiber telecom world have network configurations
where they would like to control their traffic according to the number
of tags appearing in the packet.

For example, TR247 GPON conformance test suite specification mostly
talks about untagged, single, double tagged packets and gives lax
guidelines on the vlan protocol vs. number of vlan tags.

This is different from the common IT networks where 802.1Q and 802.1ad
protocols are usually describe single and double tagged packet. GPON
configurations that we work with have arbitrary mix the above protocols
and number of vlan tags in the packet.

This new dissector allows extracting the number of vlan tags existing in
the packet.

Signed-off-by: Boris Sukholitko <boris.sukholitko@broadcom.com>
---
 include/net/flow_dissector.h |  9 +++++++++
 net/core/flow_dissector.c    | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index aa33e1092e2c..10b83e03af01 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -251,6 +251,14 @@ struct flow_dissector_key_hash {
 	u32 hash;
 };
 
+/**
+ * struct flow_dissector_key_num_of_vlans:
+ * @num_of_vlans: num_of_vlans value
+ */
+struct flow_dissector_key_num_of_vlans {
+	u8 num_of_vlans;
+};
+
 enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
 	FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
@@ -280,6 +288,7 @@ enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_META, /* struct flow_dissector_key_meta */
 	FLOW_DISSECTOR_KEY_CT, /* struct flow_dissector_key_ct */
 	FLOW_DISSECTOR_KEY_HASH, /* struct flow_dissector_key_hash */
+	FLOW_DISSECTOR_KEY_NUM_OF_VLANS, /* struct flow_dissector_key_num_of_vlans */
 
 	FLOW_DISSECTOR_KEY_MAX,
 };
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 15833e1d6ea1..2027e8e72aad 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -1034,6 +1034,16 @@ bool __skb_flow_dissect(const struct net *net,
 		memcpy(key_eth_addrs, &eth->h_dest, sizeof(*key_eth_addrs));
 	}
 
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_NUM_OF_VLANS)) {
+		struct flow_dissector_key_num_of_vlans *key_num_of_vlans;
+
+		key_num_of_vlans = skb_flow_dissector_target(flow_dissector,
+							     FLOW_DISSECTOR_KEY_NUM_OF_VLANS,
+							     target_container);
+		key_num_of_vlans->num_of_vlans = 0;
+	}
+
 proto_again:
 	fdret = FLOW_DISSECT_RET_CONTINUE;
 
@@ -1157,6 +1167,16 @@ bool __skb_flow_dissect(const struct net *net,
 			nhoff += sizeof(*vlan);
 		}
 
+		if (dissector_uses_key(flow_dissector,
+				       FLOW_DISSECTOR_KEY_NUM_OF_VLANS)) {
+			struct flow_dissector_key_num_of_vlans *key_nvs;
+
+			key_nvs = skb_flow_dissector_target(flow_dissector,
+							    FLOW_DISSECTOR_KEY_NUM_OF_VLANS,
+							    target_container);
+			key_nvs->num_of_vlans++;
+		}
+
 		if (dissector_vlan == FLOW_DISSECTOR_KEY_MAX) {
 			dissector_vlan = FLOW_DISSECTOR_KEY_VLAN;
 		} else if (dissector_vlan == FLOW_DISSECTOR_KEY_VLAN) {
-- 
2.29.2


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 4/5] Add number of vlan tags filter to the flower
  2022-03-23 10:55 [PATCH net-next 0/5] flower: match on the number of vlan tags Boris Sukholitko
                   ` (2 preceding siblings ...)
  2022-03-23 10:56 ` [PATCH net-next 3/5] Add number of vlan tags dissector Boris Sukholitko
@ 2022-03-23 10:56 ` Boris Sukholitko
  2022-03-23 10:56 ` [PATCH net-next 5/5] Consider the number of vlan tags for vlan filters Boris Sukholitko
  2022-03-23 17:44 ` [PATCH net-next 0/5] flower: match on the number of vlan tags Jakub Kicinski
  5 siblings, 0 replies; 12+ messages in thread
From: Boris Sukholitko @ 2022-03-23 10:56 UTC (permalink / raw)
  To: netdev, David S . Miller, Jakub Kicinski, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean,
	Eric Dumazet, zhang kai, Yoshiki Komachi
  Cc: Ilya Lifshits, Boris Sukholitko

[-- Attachment #1: Type: text/plain, Size: 2697 bytes --]

These are bookkeeping parts of the new num_of_vlans filter.
Defines, dump, load and set are being done here.

Signed-off-by: Boris Sukholitko <boris.sukholitko@broadcom.com>
---
 include/uapi/linux/pkt_cls.h |  2 ++
 net/sched/cls_flower.c       | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index ee38b35c3f57..5b14380adb2b 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -587,6 +587,8 @@ enum {
 	TCA_FLOWER_KEY_HASH,		/* u32 */
 	TCA_FLOWER_KEY_HASH_MASK,	/* u32 */
 
+	TCA_FLOWER_KEY_NUM_OF_VLANS,    /* u8 */
+
 	__TCA_FLOWER_MAX,
 };
 
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index e073787dfd1d..42dd84f5a037 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -71,6 +71,7 @@ struct fl_flow_key {
 	} tp_range;
 	struct flow_dissector_key_ct ct;
 	struct flow_dissector_key_hash hash;
+	struct flow_dissector_key_num_of_vlans num_of_vlans;
 } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
 
 struct fl_flow_mask_range {
@@ -713,6 +714,7 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
 	[TCA_FLOWER_FLAGS]		= { .type = NLA_U32 },
 	[TCA_FLOWER_KEY_HASH]		= { .type = NLA_U32 },
 	[TCA_FLOWER_KEY_HASH_MASK]	= { .type = NLA_U32 },
+	[TCA_FLOWER_KEY_NUM_OF_VLANS]	= { .type = NLA_U8 },
 
 };
 
@@ -1528,6 +1530,11 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
 	fl_set_key_val(tb, key->eth.src, TCA_FLOWER_KEY_ETH_SRC,
 		       mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK,
 		       sizeof(key->eth.src));
+	fl_set_key_val(tb, &key->num_of_vlans,
+		       TCA_FLOWER_KEY_NUM_OF_VLANS,
+		       &mask->num_of_vlans,
+		       TCA_FLOWER_UNSPEC,
+		       sizeof(key->num_of_vlans));
 
 	if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask)) {
 		fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
@@ -1817,6 +1824,8 @@ static void fl_init_dissector(struct flow_dissector *dissector,
 			     FLOW_DISSECTOR_KEY_CT, ct);
 	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_HASH, hash);
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
+			     FLOW_DISSECTOR_KEY_NUM_OF_VLANS, num_of_vlans);
 
 	skb_flow_dissector_init(dissector, keys, cnt);
 }
@@ -2872,6 +2881,11 @@ static int fl_dump_key(struct sk_buff *skb, struct net *net,
 			    sizeof(key->basic.n_proto)))
 		goto nla_put_failure;
 
+	if (mask->num_of_vlans.num_of_vlans) {
+		if (nla_put_u8(skb, TCA_FLOWER_KEY_NUM_OF_VLANS, key->num_of_vlans.num_of_vlans))
+			goto nla_put_failure;
+	}
+
 	if (fl_dump_key_mpls(skb, &key->mpls, &mask->mpls))
 		goto nla_put_failure;
 
-- 
2.29.2


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 5/5] Consider the number of vlan tags for vlan filters
  2022-03-23 10:55 [PATCH net-next 0/5] flower: match on the number of vlan tags Boris Sukholitko
                   ` (3 preceding siblings ...)
  2022-03-23 10:56 ` [PATCH net-next 4/5] Add number of vlan tags filter to the flower Boris Sukholitko
@ 2022-03-23 10:56 ` Boris Sukholitko
  2022-03-23 17:44 ` [PATCH net-next 0/5] flower: match on the number of vlan tags Jakub Kicinski
  5 siblings, 0 replies; 12+ messages in thread
From: Boris Sukholitko @ 2022-03-23 10:56 UTC (permalink / raw)
  To: netdev, David S . Miller, Jakub Kicinski, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean,
	Eric Dumazet, zhang kai, Yoshiki Komachi
  Cc: Ilya Lifshits, Boris Sukholitko

[-- Attachment #1: Type: text/plain, Size: 2491 bytes --]

Currently the existence of vlan filters is conditional on the vlan
protocol being matched in the tc rule. I.e. the following rule:

tc filter add dev eth1 ingress flower vlan_prio 5

is illegal because we lack protocol 802.1q in the rule.

Having the num_of_vlans filter configured removes this restriction. The
following rule becomes ok:

tc filter add dev eth1 ingress flower num_of_vlans 1 vlan_prio 5

because we know that the packet is single tagged.

Signed-off-by: Boris Sukholitko <boris.sukholitko@broadcom.com>
---
 net/sched/cls_flower.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 42dd84f5a037..464a91e64b5f 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -1023,8 +1023,10 @@ static void fl_set_key_vlan(struct nlattr **tb,
 			VLAN_PRIORITY_MASK;
 		key_mask->vlan_priority = VLAN_PRIORITY_MASK;
 	}
-	key_val->vlan_tpid = ethertype;
-	key_mask->vlan_tpid = cpu_to_be16(~0);
+	if (ethertype) {
+		key_val->vlan_tpid = ethertype;
+		key_mask->vlan_tpid = cpu_to_be16(~0);
+	}
 }
 
 static void fl_set_key_flag(u32 flower_key, u32 flower_mask,
@@ -1495,13 +1497,18 @@ static int fl_set_key_ct(struct nlattr **tb,
 }
 
 static bool is_vlan_key(struct nlattr *tb, __be16 *ethertype,
-			struct fl_flow_key *key, struct fl_flow_key *mask)
+			struct fl_flow_key *key, struct fl_flow_key *mask,
+			int vthresh)
 {
-	if (!tb)
-		return false;
+	const bool good_num_of_vlans = key->num_of_vlans.num_of_vlans > vthresh;
+
+	if (!tb) {
+		*ethertype = 0;
+		return good_num_of_vlans;
+	}
 
 	*ethertype = nla_get_be16(tb);
-	if (eth_type_vlan(*ethertype))
+	if (good_num_of_vlans || eth_type_vlan(*ethertype))
 		return true;
 
 	key->basic.n_proto = *ethertype;
@@ -1536,12 +1543,13 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
 		       TCA_FLOWER_UNSPEC,
 		       sizeof(key->num_of_vlans));
 
-	if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask)) {
+	if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask, 0)) {
 		fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
 				TCA_FLOWER_KEY_VLAN_PRIO, &key->vlan,
 				&mask->vlan);
 
-		if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], &ethertype, key, mask)) {
+		if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE],
+				&ethertype, key, mask, 1)) {
 			fl_set_key_vlan(tb, ethertype,
 					TCA_FLOWER_KEY_CVLAN_ID,
 					TCA_FLOWER_KEY_CVLAN_PRIO,
-- 
2.29.2


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next 0/5] flower: match on the number of vlan tags
  2022-03-23 10:55 [PATCH net-next 0/5] flower: match on the number of vlan tags Boris Sukholitko
                   ` (4 preceding siblings ...)
  2022-03-23 10:56 ` [PATCH net-next 5/5] Consider the number of vlan tags for vlan filters Boris Sukholitko
@ 2022-03-23 17:44 ` Jakub Kicinski
  5 siblings, 0 replies; 12+ messages in thread
From: Jakub Kicinski @ 2022-03-23 17:44 UTC (permalink / raw)
  To: Boris Sukholitko
  Cc: netdev, David S . Miller, Jamal Hadi Salim, Cong Wang,
	Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean, Eric Dumazet,
	zhang kai, Yoshiki Komachi, Ilya Lifshits

On Wed, 23 Mar 2022 12:55:57 +0200 Boris Sukholitko wrote:
> Our customers in the fiber telecom world have network configurations
> where they would like to control their traffic according to the number
> of tags appearing in the packet.
> 
> For example, TR247 GPON conformance test suite specification mostly
> talks about untagged, single, double tagged packets and gives lax
> guidelines on the vlan protocol vs. number of vlan tags.
> 
> This is different from the common IT networks where 802.1Q and 802.1ad
> protocols are usually describe single and double tagged packet. GPON
> configurations that we work with have arbitrary mix the above protocols
> and number of vlan tags in the packet.
> 
> The following patch series implement number of vlans flower filter. They
> add num_of_vlans flower filter as an alternative to vlan ethtype protocol
> matching. The end result is that the following command becomes possible:
> 
> tc filter add dev eth1 ingress flower \
>   num_of_vlans 1 vlan_prio 5 action drop

# Form letter - net-next is closed

We have already sent the networking pull request for 5.18
and therefore net-next is closed for new drivers, features,
code refactoring and optimizations. We are currently accepting
bug fixes only.

Please repost when net-next reopens after 5.18-rc1 is cut.

RFC patches sent for review only are obviously welcome at any time.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next 0/5] flower: match on the number of vlan tags
  2022-04-12 10:54     ` Jamal Hadi Salim
@ 2022-04-14 12:59       ` Boris Sukholitko
  0 siblings, 0 replies; 12+ messages in thread
From: Boris Sukholitko @ 2022-04-14 12:59 UTC (permalink / raw)
  To: Jamal Hadi Salim
  Cc: netdev, David S . Miller, Jakub Kicinski, Cong Wang, Jiri Pirko,
	Gustavo A . R . Silva, Vladimir Oltean, Eric Dumazet, zhang kai,
	Yoshiki Komachi, Ilya Lifshits

[-- Attachment #1: Type: text/plain, Size: 1502 bytes --]

On Tue, Apr 12, 2022 at 06:54:43AM -0400, Jamal Hadi Salim wrote:
> On 2022-04-11 10:56, Boris Sukholitko wrote:
> > On Mon, Apr 11, 2022 at 10:07:14AM -0400, Jamal Hadi Salim wrote:
> > > On 2022-04-11 09:30, Boris Sukholitko wrote:
> > > > Hi,
> 
> [..]
> 
> > > Can you please provide more elaborate example of more than 1 vlan?
> > 
> > Perusing our logs, we have redirect rules such as:
> > 
> > tc filter add dev $GPON ingress flower num_of_vlans $N \
> >     action mirred egress redirect dev $DEV
> > 
> 
> Please add in the commit logs.
> 
> > where N can range from 0 to 3 and $DEV is the function of $N.
> > 
> 
> Also in the commit log, very specific to GPON. I have seen upto
> 4 in some telco environment.
> 
> > Also there are rules setting skb mark based on the number of vlans:
> > 
> > tc filter add dev $GPON ingress flower num_of_vlans $N vlan_prio \
> >     $P action skbedit mark $M
> > 

All of the above added to the commit log in v3 (added to the cover and
patch 3 in the series).

> 
> Yep makes sense.
> 
> 
> > > Where would the line be drawn:
> > > Is it max of two vlans?
> > 
> > We have seen the maximum of 3 vlans.
> > 
> > > Is there potential of <=X, meaning matching of upto X Vlans?
> > > 
> > 
> > We've managed to get by without such feature somehow :)
> 
> If needed should be extensible. You already have ability to count, so
> adding inequality check should not be hard to add when needed.
> 

Yes, it can certainly be done as a further patch.

Thanks,
Boris.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next 0/5] flower: match on the number of vlan tags
  2022-04-11 14:56   ` Boris Sukholitko
@ 2022-04-12 10:54     ` Jamal Hadi Salim
  2022-04-14 12:59       ` Boris Sukholitko
  0 siblings, 1 reply; 12+ messages in thread
From: Jamal Hadi Salim @ 2022-04-12 10:54 UTC (permalink / raw)
  To: Boris Sukholitko
  Cc: netdev, David S . Miller, Jakub Kicinski, Cong Wang, Jiri Pirko,
	Gustavo A . R . Silva, Vladimir Oltean, Eric Dumazet, zhang kai,
	Yoshiki Komachi, Ilya Lifshits

On 2022-04-11 10:56, Boris Sukholitko wrote:
> On Mon, Apr 11, 2022 at 10:07:14AM -0400, Jamal Hadi Salim wrote:
>> On 2022-04-11 09:30, Boris Sukholitko wrote:
>>> Hi,

[..]

>> Can you please provide more elaborate example of more than 1 vlan?
> 
> Perusing our logs, we have redirect rules such as:
> 
> tc filter add dev $GPON ingress flower num_of_vlans $N \
>     action mirred egress redirect dev $DEV
>

Please add in the commit logs.

> where N can range from 0 to 3 and $DEV is the function of $N.
> 

Also in the commit log, very specific to GPON. I have seen upto
4 in some telco environment.

> Also there are rules setting skb mark based on the number of vlans:
> 
> tc filter add dev $GPON ingress flower num_of_vlans $N vlan_prio \
>     $P action skbedit mark $M
>

Yep makes sense.


>> Where would the line be drawn:
>> Is it max of two vlans?
> 
> We have seen the maximum of 3 vlans.
> 
>> Is there potential of <=X, meaning matching of upto X Vlans?
>>
> 
> We've managed to get by without such feature somehow :)

If needed should be extensible. You already have ability to count, so
adding inequality check should not be hard to add when needed.

cheers,
jamal

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next 0/5] flower: match on the number of vlan tags
  2022-04-11 14:07 ` Jamal Hadi Salim
@ 2022-04-11 14:56   ` Boris Sukholitko
  2022-04-12 10:54     ` Jamal Hadi Salim
  0 siblings, 1 reply; 12+ messages in thread
From: Boris Sukholitko @ 2022-04-11 14:56 UTC (permalink / raw)
  To: Jamal Hadi Salim
  Cc: netdev, David S . Miller, Jakub Kicinski, Cong Wang, Jiri Pirko,
	Gustavo A . R . Silva, Vladimir Oltean, Eric Dumazet, zhang kai,
	Yoshiki Komachi, Ilya Lifshits

[-- Attachment #1: Type: text/plain, Size: 1994 bytes --]

On Mon, Apr 11, 2022 at 10:07:14AM -0400, Jamal Hadi Salim wrote:
> On 2022-04-11 09:30, Boris Sukholitko wrote:
> > Hi,
> > 
> > Our customers in the fiber telecom world have network configurations
> > where they would like to control their traffic according to the number
> > of tags appearing in the packet.
> > 
> > For example, TR247 GPON conformance test suite specification mostly
> > talks about untagged, single, double tagged packets and gives lax
> > guidelines on the vlan protocol vs. number of vlan tags.
> > 
> > This is different from the common IT networks where 802.1Q and 802.1ad
> > protocols are usually describe single and double tagged packet. GPON
> > configurations that we work with have arbitrary mix the above protocols
> > and number of vlan tags in the packet.
> > 
> > The following patch series implement number of vlans flower filter. They
> > add num_of_vlans flower filter as an alternative to vlan ethtype protocol
> > matching. The end result is that the following command becomes possible:
> > 
> > tc filter add dev eth1 ingress flower \
> >    num_of_vlans 1 vlan_prio 5 action drop
> > 
> 
> The idea looks sane. I guess flow dissector is now not just involving
> headers but metadata as well. I can see this applied to MPLS for example,
> etc.
> Can you please provide more elaborate example of more than 1 vlan?

Perusing our logs, we have redirect rules such as:

tc filter add dev $GPON ingress flower num_of_vlans $N \
   action mirred egress redirect dev $DEV

where N can range from 0 to 3 and $DEV is the function of $N.

Also there are rules setting skb mark based on the number of vlans:

tc filter add dev $GPON ingress flower num_of_vlans $N vlan_prio \
   $P action skbedit mark $M

> Where would the line be drawn:
> Is it max of two vlans?

We have seen the maximum of 3 vlans.

> Is there potential of <=X, meaning matching of upto X Vlans?
> 

We've managed to get by without such feature somehow :)

Thanks,
Boris.


> cheers,
> jamal

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next 0/5] flower: match on the number of vlan tags
  2022-04-11 13:30 Boris Sukholitko
@ 2022-04-11 14:07 ` Jamal Hadi Salim
  2022-04-11 14:56   ` Boris Sukholitko
  0 siblings, 1 reply; 12+ messages in thread
From: Jamal Hadi Salim @ 2022-04-11 14:07 UTC (permalink / raw)
  To: Boris Sukholitko, netdev, David S . Miller, Jakub Kicinski,
	Cong Wang, Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean,
	Eric Dumazet, zhang kai, Yoshiki Komachi
  Cc: Ilya Lifshits

On 2022-04-11 09:30, Boris Sukholitko wrote:
> Hi,
> 
> Our customers in the fiber telecom world have network configurations
> where they would like to control their traffic according to the number
> of tags appearing in the packet.
> 
> For example, TR247 GPON conformance test suite specification mostly
> talks about untagged, single, double tagged packets and gives lax
> guidelines on the vlan protocol vs. number of vlan tags.
> 
> This is different from the common IT networks where 802.1Q and 802.1ad
> protocols are usually describe single and double tagged packet. GPON
> configurations that we work with have arbitrary mix the above protocols
> and number of vlan tags in the packet.
> 
> The following patch series implement number of vlans flower filter. They
> add num_of_vlans flower filter as an alternative to vlan ethtype protocol
> matching. The end result is that the following command becomes possible:
> 
> tc filter add dev eth1 ingress flower \
>    num_of_vlans 1 vlan_prio 5 action drop
> 

The idea looks sane. I guess flow dissector is now not just involving
headers but metadata as well. I can see this applied to MPLS for 
example, etc.
Can you please provide more elaborate example of more than 1 vlan?

Where would the line be drawn:
Is it max of two vlans?
Is there potential of <=X, meaning matching of upto X Vlans?

cheers,
jamal

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH net-next 0/5] flower: match on the number of vlan tags
@ 2022-04-11 13:30 Boris Sukholitko
  2022-04-11 14:07 ` Jamal Hadi Salim
  0 siblings, 1 reply; 12+ messages in thread
From: Boris Sukholitko @ 2022-04-11 13:30 UTC (permalink / raw)
  To: netdev, David S . Miller, Jakub Kicinski, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, Gustavo A . R . Silva, Vladimir Oltean,
	Eric Dumazet, zhang kai, Yoshiki Komachi
  Cc: Ilya Lifshits, Boris Sukholitko

[-- Attachment #1: Type: text/plain, Size: 1786 bytes --]

Hi,

Our customers in the fiber telecom world have network configurations
where they would like to control their traffic according to the number
of tags appearing in the packet.

For example, TR247 GPON conformance test suite specification mostly
talks about untagged, single, double tagged packets and gives lax
guidelines on the vlan protocol vs. number of vlan tags.

This is different from the common IT networks where 802.1Q and 802.1ad
protocols are usually describe single and double tagged packet. GPON
configurations that we work with have arbitrary mix the above protocols
and number of vlan tags in the packet.

The following patch series implement number of vlans flower filter. They
add num_of_vlans flower filter as an alternative to vlan ethtype protocol
matching. The end result is that the following command becomes possible:

tc filter add dev eth1 ingress flower \
  num_of_vlans 1 vlan_prio 5 action drop

More about the patch series:
  - patches 1-2 remove duplicate code by introducing is_key_vlan
    helper.
  - patch 3, 4 implement num_of_vlans in the dissector and in the
    flower.
  - patch 5 uses the num_of_vlans filter to allow further matching on
    vlan attributes.

Complementary iproute2 patches are being sent separately.

Thanks,
Boris.

Boris Sukholitko (5):
  Helper function for vlan ethtype checks
  Reduce identation after is_key_vlan refactoring
  Add number of vlan tags dissector
  Add number of vlan tags filter to the flower
  Consider the number of vlan tags for vlan filters

 include/net/flow_dissector.h |  9 ++++
 include/uapi/linux/pkt_cls.h |  2 +
 net/core/flow_dissector.c    | 20 +++++++++
 net/sched/cls_flower.c       | 86 +++++++++++++++++++++++-------------
 4 files changed, 86 insertions(+), 31 deletions(-)

-- 
2.29.2


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-04-14 12:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23 10:55 [PATCH net-next 0/5] flower: match on the number of vlan tags Boris Sukholitko
2022-03-23 10:55 ` [PATCH net-next 1/5] Helper function for vlan ethtype checks Boris Sukholitko
2022-03-23 10:55 ` [PATCH net-next 2/5] Reduce identation after is_key_vlan refactoring Boris Sukholitko
2022-03-23 10:56 ` [PATCH net-next 3/5] Add number of vlan tags dissector Boris Sukholitko
2022-03-23 10:56 ` [PATCH net-next 4/5] Add number of vlan tags filter to the flower Boris Sukholitko
2022-03-23 10:56 ` [PATCH net-next 5/5] Consider the number of vlan tags for vlan filters Boris Sukholitko
2022-03-23 17:44 ` [PATCH net-next 0/5] flower: match on the number of vlan tags Jakub Kicinski
2022-04-11 13:30 Boris Sukholitko
2022-04-11 14:07 ` Jamal Hadi Salim
2022-04-11 14:56   ` Boris Sukholitko
2022-04-12 10:54     ` Jamal Hadi Salim
2022-04-14 12:59       ` Boris Sukholitko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).