Skip to contentSkip to conversation

ice: PPPoE offload support

RFC PATCH Superseded Marcin Szycik 3 participants 14 messages Jul 8, 2022 – Jul 17, 2022

Subsystems (4)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover ice: PPPoE offload support

Add support for dissecting PPPoE and PPP-specific fields in flow dissector:
PPPoE session id and PPP protocol type. Add support for those fields in tc-flower and support offloading PPPoE. Finally, add support for hardware offload of PPPoE packets in switchdev mode in ice driver.

Example filter:
tc filter add dev $PF1 ingress protocol ppp_ses prio 1 flower pppoe_sid \
1234 ppp_proto ip skip_sw action mirred egress redirect dev $VF1_PR

Changes in iproute2 are required to use the new fields (will be submitted soon).

ICE COMMS DDP package is required to create a filter in ice.

v4:
* PPPoE header validation
* added MPLS support
* added support for compressed PPP protocol field
* flow_dissector_key_pppoe::session_id stored in __be16
* new field: flow_dissector_key_pppoe::type
* always add an ethtype lookup if PPP/PPPoE options are provided (to prevent setting incorrect ethtype)
* rebase
v3:
* revert byte order changes in is_ppp_proto_supported from previous version
* add kernel-doc for is_ppp_proto_supported
* add more CC
v2: cosmetic changes

Marcin Szycik (1):
ice: Add support for PPPoE hardware offload

Wojciech Drewek (3):
flow_dissector: Add PPPoE dissectors
net/sched: flower: Add PPPoE filter
flow_offload: Introduce flow_match_pppoe

 drivers/net/ethernet/intel/ice/ice.h          |   1 +
 .../net/ethernet/intel/ice/ice_flex_pipe.c    |   5 +-
 .../ethernet/intel/ice/ice_protocol_type.h    |  11 ++
 drivers/net/ethernet/intel/ice/ice_switch.c   | 165 ++++++++++++++++++
 drivers/net/ethernet/intel/ice/ice_tc_lib.c   |  71 +++++++-
 drivers/net/ethernet/intel/ice/ice_tc_lib.h   |   8 +
 include/net/flow_dissector.h                  |  13 ++
 include/net/flow_offload.h                    |   6 +
 include/uapi/linux/pkt_cls.h                  |   3 +
 net/core/flow_dissector.c                     |  84 ++++++++-
 net/core/flow_offload.c                       |   7 +
 net/sched/cls_flower.c                        |  61 +++++++
 12 files changed, 426 insertions(+), 9 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

RFC PATCH v4 1/4 flow_dissector: Add PPPoE dissectors

From: Wojciech Drewek <[email protected]>

Allow to dissect PPPoE specific fields which are:
- session ID (16 bits)
- ppp protocol (16 bits)
- type (16 bits) - this is PPPoE ethertype, for now only ETH_P_PPP_SES is supported, possible ETH_P_PPP_DISC in the future

The goal is to make the following TC command possible:

  # tc filter add dev ens6f0 ingress prio 1 protocol ppp_ses \
      flower \
        pppoe_sid 12 \
        ppp_proto ip \
      action drop

Note that only PPPoE Session is supported.

---
v4:
* pppoe header validation
* added MPLS dissection
* added support for compressed ppp protocol field
* flow_dissector_key_pppoe::session_id stored in __be16
* new field: flow_dissector_key_pppoe::type
v3: revert byte order changes in is_ppp_proto_supported from
previous version
v2: ntohs instead of htons in is_ppp_proto_supported

 include/net/flow_dissector.h | 13 ++++++
 net/core/flow_dissector.c    | 84 +++++++++++++++++++++++++++++++++---
 2 files changed, 90 insertions(+), 7 deletions(-)
include/net/flow_dissector.h +13 -0
index a4c6057c7097..af0d429b9a26 100644
@@ -261,6 +261,18 @@ struct flow_dissector_key_num_of_vlans {
 	u8 num_of_vlans;
 };
 
+/**
+ * struct flow_dissector_key_pppoe:
+ * @session_id: pppoe session id
+ * @ppp_proto: ppp protocol
+ * @type: pppoe eth type
+ */
+struct flow_dissector_key_pppoe {
+	__be16 session_id;
+	__be16 ppp_proto;
+	__be16 type;
+};
+
 enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
 	FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
@@ -291,6 +303,7 @@ enum flow_dissector_key_id {
 	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_PPPOE, /* struct flow_dissector_key_pppoe */
 
 	FLOW_DISSECTOR_KEY_MAX,
 };
net/core/flow_dissector.c +77 -7

109 lines not on this page · raw message

Signature · 1 line
2.35.1
#2 lore raw

Re: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 43 lines · Marcin Szycik

From: Wojciech Drewek <[email protected]>

Allow to dissect PPPoE specific fields which are:
- session ID (16 bits)
- ppp protocol (16 bits)
- type (16 bits) - this is PPPoE ethertype, for now only ETH_P_PPP_SES is supported, possible ETH_P_PPP_DISC in the future

The goal is to make the following TC command possible:

  # tc filter add dev ens6f0 ingress prio 1 protocol ppp_ses \
      flower \
        pppoe_sid 12 \
        ppp_proto ip \
      action drop

Note that only PPPoE Session is supported.

---
v4:
* pppoe header validation
* added MPLS dissection
* added support for compressed ppp protocol field
* flow_dissector_key_pppoe::session_id stored in __be16
* new field: flow_dissector_key_pppoe::type
v3: revert byte order changes in is_ppp_proto_supported from
previous version
v2: ntohs instead of htons in is_ppp_proto_supported

 include/net/flow_dissector.h | 13 ++++++
 net/core/flow_dissector.c    | 84 +++++++++++++++++++++++++++++++++---
 2 files changed, 90 insertions(+), 7 deletions(-)
include/net/flow_dissector.h +0 -0
index a4c6057c7097..af0d429b9a26 100644
@@ -261,6 +261,18 @@ struct flow_dissector_key_num_of_vlans {
 	u8 num_of_vlans;
 };
 

include/net/flow_dissector.h struct flow_dissector_key_num_of_vlans { · line 273

Quoted 10 lines
include/net/flow_dissector.h +10 -0
+/**
+ * struct flow_dissector_key_pppoe:
+ * @session_id: pppoe session id
+ * @ppp_proto: ppp protocol
+ * @type: pppoe eth type
+ */
+struct flow_dissector_key_pppoe {
+	__be16 session_id;
+	__be16 ppp_proto;
+	__be16 type;

I don't understand the need for the new 'type' field.

Quoted 75 lines
include/net/flow_dissector.h +3 -0
+};
+
 enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
 	FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
@@ -291,6 +303,7 @@ enum flow_dissector_key_id {
 	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_PPPOE, /* struct flow_dissector_key_pppoe */
 
 	FLOW_DISSECTOR_KEY_MAX,
 };
net/core/flow_dissector.c +38 -3
index 6aee04f75e3e..3a90219d2354 100644
@@ -895,6 +895,42 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
 	return result == BPF_OK;
 }
 
+/**
+ * is_ppp_proto_supported - checks if inner PPP protocol should be dissected
+ * @proto: protocol type (PPP proto field)
+ */
+static bool is_ppp_proto_supported(__be16 proto)
+{
+	switch (proto) {
+	case htons(PPP_AT):
+	case htons(PPP_IPX):
+	case htons(PPP_VJC_COMP):
+	case htons(PPP_VJC_UNCOMP):
+	case htons(PPP_MP):
+	case htons(PPP_COMPFRAG):
+	case htons(PPP_COMP):
+	case htons(PPP_IPCP):
+	case htons(PPP_ATCP):
+	case htons(PPP_IPXCP):
+	case htons(PPP_IPV6CP):
+	case htons(PPP_CCPFRAG):
+	case htons(PPP_MPLSCP):
+	case htons(PPP_LCP):
+	case htons(PPP_PAP):
+	case htons(PPP_LQR):
+	case htons(PPP_CHAP):
+	case htons(PPP_CBCP):
+		return true;
+	default:
+		return false;
+	}
+}
+
+static bool is_pppoe_ses_hdr_valid(struct pppoe_hdr hdr)
+{
+	return hdr.ver == 1 && hdr.type == 1 && hdr.code == 0;
+}
+
 /**
  * __skb_flow_dissect - extract the flow_keys struct and return it
  * @net: associated network namespace, derived from @skb if NULL
@@ -1214,26 +1250,60 @@ bool __skb_flow_dissect(const struct net *net,
 			struct pppoe_hdr hdr;
 			__be16 proto;
 		} *hdr, _hdr;
+		__be16 ppp_proto;
+
 		hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
 		if (!hdr) {
 			fdret = FLOW_DISSECT_RET_OUT_BAD;
 			break;
 		}
 
-		nhoff += PPPOE_SES_HLEN;
-		switch (hdr->proto) {
-		case htons(PPP_IP):

net/core/flow_dissector.c bool __skb_flow_dissect(const struct net *net, · line 1270

Quoted 10 lines
net/core/flow_dissector.c +10 -0
+		if (!is_pppoe_ses_hdr_valid(hdr->hdr)) {
+			fdret = FLOW_DISSECT_RET_OUT_BAD;
+			break;
+		}
+
+		/* least significant bit of the first byte
+		 * indicates if protocol field was compressed
+		 */
+		if (hdr->proto & 1) {
+			ppp_proto = hdr->proto << 8;

This is little endian specific code. We can't make such assumptions.

Quoted 46 lines
net/core/flow_dissector.c +29 -4
+			nhoff += PPPOE_SES_HLEN - 1;
+		} else {
+			ppp_proto = hdr->proto;
+			nhoff += PPPOE_SES_HLEN;
+		}
+
+		if (ppp_proto == htons(PPP_IP)) {
 			proto = htons(ETH_P_IP);
 			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
-			break;
-		case htons(PPP_IPV6):
+		} else if (ppp_proto == htons(PPP_IPV6)) {
 			proto = htons(ETH_P_IPV6);
 			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
-			break;
-		default:
+		} else if (ppp_proto == htons(PPP_MPLS_UC)) {
+			proto = htons(ETH_P_MPLS_UC);
+			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
+		} else if (ppp_proto == htons(PPP_MPLS_MC)) {
+			proto = htons(ETH_P_MPLS_MC);
+			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
+		} else if (is_ppp_proto_supported(ppp_proto)) {
+			fdret = FLOW_DISSECT_RET_OUT_GOOD;
+		} else {
 			fdret = FLOW_DISSECT_RET_OUT_BAD;
 			break;
 		}
+
+		if (dissector_uses_key(flow_dissector,
+				       FLOW_DISSECTOR_KEY_PPPOE)) {
+			struct flow_dissector_key_pppoe *key_pppoe;
+
+			key_pppoe = skb_flow_dissector_target(flow_dissector,
+							      FLOW_DISSECTOR_KEY_PPPOE,
+							      target_container);
+			key_pppoe->session_id = hdr->hdr.sid;
+			key_pppoe->ppp_proto = ppp_proto;
+			key_pppoe->type = htons(ETH_P_PPP_SES);
+		}
 		break;
 	}
 	case htons(ETH_P_TIPC): {
Signature · 1 line
2.35.1
#3 lore raw

RE: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 59 lines

-----Original Message-----
From: Guillaume Nault <[email protected]>
Sent: piątek, 8 lipca 2022 21:05
To: Marcin Szycik <[email protected]>
Cc: [email protected]; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; Brandeburg, Jesse <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Drewek, Wojciech <[email protected]>; Lobakin, Alexandr <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 43 lines · Marcin Szycik

From: Wojciech Drewek <[email protected]>

Allow to dissect PPPoE specific fields which are:
- session ID (16 bits)
- ppp protocol (16 bits)
- type (16 bits) - this is PPPoE ethertype, for now only ETH_P_PPP_SES is supported, possible ETH_P_PPP_DISC in the future

The goal is to make the following TC command possible:

  # tc filter add dev ens6f0 ingress prio 1 protocol ppp_ses \
      flower \
        pppoe_sid 12 \
        ppp_proto ip \
      action drop

Note that only PPPoE Session is supported.

---
v4:
* pppoe header validation
* added MPLS dissection
* added support for compressed ppp protocol field
* flow_dissector_key_pppoe::session_id stored in __be16
* new field: flow_dissector_key_pppoe::type
v3: revert byte order changes in is_ppp_proto_supported from
previous version
v2: ntohs instead of htons in is_ppp_proto_supported

 include/net/flow_dissector.h | 13 ++++++
 net/core/flow_dissector.c    | 84 +++++++++++++++++++++++++++++++++---
 2 files changed, 90 insertions(+), 7 deletions(-)
include/net/flow_dissector.h +0 -0
index a4c6057c7097..af0d429b9a26 100644
@@ -261,6 +261,18 @@ struct flow_dissector_key_num_of_vlans {
 	u8 num_of_vlans;
 };
 
Quoted 12 lines

include/net/flow_dissector.h struct flow_dissector_key_num_of_vlans { · line 273

Quoted 10 lines
include/net/flow_dissector.h +10 -0
+/**
+ * struct flow_dissector_key_pppoe:
+ * @session_id: pppoe session id
+ * @ppp_proto: ppp protocol
+ * @type: pppoe eth type
+ */
+struct flow_dissector_key_pppoe {
+	__be16 session_id;
+	__be16 ppp_proto;
+	__be16 type;

I don't understand the need for the new 'type' field.

Let's say user want to add below filter with just protocol field:
tc filter add dev ens6f0 ingress prio 1 protocol ppp_ses action drop

cls_flower would set basic.n_proto to ETH_P_PPP_SES, then PPPoE packet
arrives with ppp_proto = PPP_IP, which means that in __skb_flow_dissect basic.n_proto is going to be set to ETH_P_IP. We have a mismatch here cls_flower set basic.n_proto to ETH_P_PPP_SES and flow_dissector set it to ETH_P_IP. That's why in such example basic.n_proto has to be set to 0 (it works the same with vlans) and key_pppoe::type has to be used. In other words basic.n_proto can't be used for storing ETH_P_PPP_SES because it will store encapsulated protocol.

We could also use it to match on ETH_P_PPP_DISC.

Quoted 73 lines
Quoted 73 lines
include/net/flow_dissector.h +3 -0
+};
+
 enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
 	FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
@@ -291,6 +303,7 @@ enum flow_dissector_key_id {
 	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_PPPOE, /* struct flow_dissector_key_pppoe */
 
 	FLOW_DISSECTOR_KEY_MAX,
 };
net/core/flow_dissector.c +38 -0
index 6aee04f75e3e..3a90219d2354 100644
@@ -895,6 +895,42 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
 	return result == BPF_OK;
 }
 
+/**
+ * is_ppp_proto_supported - checks if inner PPP protocol should be dissected
+ * @proto: protocol type (PPP proto field)
+ */
+static bool is_ppp_proto_supported(__be16 proto)
+{
+	switch (proto) {
+	case htons(PPP_AT):
+	case htons(PPP_IPX):
+	case htons(PPP_VJC_COMP):
+	case htons(PPP_VJC_UNCOMP):
+	case htons(PPP_MP):
+	case htons(PPP_COMPFRAG):
+	case htons(PPP_COMP):
+	case htons(PPP_IPCP):
+	case htons(PPP_ATCP):
+	case htons(PPP_IPXCP):
+	case htons(PPP_IPV6CP):
+	case htons(PPP_CCPFRAG):
+	case htons(PPP_MPLSCP):
+	case htons(PPP_LCP):
+	case htons(PPP_PAP):
+	case htons(PPP_LQR):
+	case htons(PPP_CHAP):
+	case htons(PPP_CBCP):
+		return true;
+	default:
+		return false;
+	}
+}
+
+static bool is_pppoe_ses_hdr_valid(struct pppoe_hdr hdr)
+{
+	return hdr.ver == 1 && hdr.type == 1 && hdr.code == 0;
+}
+
 /**
  * __skb_flow_dissect - extract the flow_keys struct and return it
  * @net: associated network namespace, derived from @skb if NULL
@@ -1214,26 +1250,60 @@ bool __skb_flow_dissect(const struct net *net,
 			struct pppoe_hdr hdr;
 			__be16 proto;
 		} *hdr, _hdr;
+		__be16 ppp_proto;
+
 		hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
 		if (!hdr) {
 			fdret = FLOW_DISSECT_RET_OUT_BAD;
 			break;
 		}
 
Quoted 15 lines

net/core/flow_dissector.c bool __skb_flow_dissect(const struct net *net, · line 1270

Quoted 13 lines
net/core/flow_dissector.c +10 -3
-		nhoff += PPPOE_SES_HLEN;
-		switch (hdr->proto) {
-		case htons(PPP_IP):
+		if (!is_pppoe_ses_hdr_valid(hdr->hdr)) {
+			fdret = FLOW_DISSECT_RET_OUT_BAD;
+			break;
+		}
+
+		/* least significant bit of the first byte
+		 * indicates if protocol field was compressed
+		 */
+		if (hdr->proto & 1) {
+			ppp_proto = hdr->proto << 8;

This is little endian specific code. We can't make such assumptions.

Both ppp_proto and hdr->prot are stored in __be16 so left shift by 8 bits should always be ok, am I right?
Should I use cpu_to_be16 on both 1 and 8. Is that what you mean?

Quoted 39 lines
Quoted 39 lines
net/core/flow_dissector.c +27 -4
+			nhoff += PPPOE_SES_HLEN - 1;
+		} else {
+			ppp_proto = hdr->proto;
+			nhoff += PPPOE_SES_HLEN;
+		}
+
+		if (ppp_proto == htons(PPP_IP)) {
 			proto = htons(ETH_P_IP);
 			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
-			break;
-		case htons(PPP_IPV6):
+		} else if (ppp_proto == htons(PPP_IPV6)) {
 			proto = htons(ETH_P_IPV6);
 			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
-			break;
-		default:
+		} else if (ppp_proto == htons(PPP_MPLS_UC)) {
+			proto = htons(ETH_P_MPLS_UC);
+			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
+		} else if (ppp_proto == htons(PPP_MPLS_MC)) {
+			proto = htons(ETH_P_MPLS_MC);
+			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
+		} else if (is_ppp_proto_supported(ppp_proto)) {
+			fdret = FLOW_DISSECT_RET_OUT_GOOD;
+		} else {
 			fdret = FLOW_DISSECT_RET_OUT_BAD;
 			break;
 		}
+
+		if (dissector_uses_key(flow_dissector,
+				       FLOW_DISSECTOR_KEY_PPPOE)) {
+			struct flow_dissector_key_pppoe *key_pppoe;
+
+			key_pppoe = skb_flow_dissector_target(flow_dissector,
+							      FLOW_DISSECTOR_KEY_PPPOE,
+							      target_container);
+			key_pppoe->session_id = hdr->hdr.sid;
+			key_pppoe->ppp_proto = ppp_proto;
Quoted 8 lines
Quoted 8 lines
net/core/flow_dissector.c +2 -1
+			key_pppoe->type = htons(ETH_P_PPP_SES);
+		}
 		break;
 	}
 	case htons(ETH_P_TIPC): {
--

2.35.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#4 lore raw

Re: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 24 lines · Wojciech
Quoted 8 lines
Quoted 8 lines
include/net/flow_dissector.h +0 -0
index a4c6057c7097..af0d429b9a26 100644
@@ -261,6 +261,18 @@ struct flow_dissector_key_num_of_vlans {
 	u8 num_of_vlans;
 };
 
Quoted 12 lines

include/net/flow_dissector.h struct flow_dissector_key_num_of_vlans { · line 273

Quoted 10 lines
include/net/flow_dissector.h +10 -0
+/**
+ * struct flow_dissector_key_pppoe:
+ * @session_id: pppoe session id
+ * @ppp_proto: ppp protocol
+ * @type: pppoe eth type
+ */
+struct flow_dissector_key_pppoe {
+	__be16 session_id;
+	__be16 ppp_proto;
+	__be16 type;

I don't understand the need for the new 'type' field.

Let's say user want to add below filter with just protocol field:
tc filter add dev ens6f0 ingress prio 1 protocol ppp_ses action drop

Quoted 8 lines

cls_flower would set basic.n_proto to ETH_P_PPP_SES, then PPPoE packet
arrives with ppp_proto = PPP_IP, which means that in __skb_flow_dissect basic.n_proto is going to be set to ETH_P_IP. We have a mismatch here cls_flower set basic.n_proto to ETH_P_PPP_SES and flow_dissector set it to ETH_P_IP. That's why in such example basic.n_proto has to be set to 0 (it works the same with vlans) and key_pppoe::type has to be used. In other words basic.n_proto can't be used for storing ETH_P_PPP_SES because it will store encapsulated protocol.

We could also use it to match on ETH_P_PPP_DISC.

Thanks for the explanation. That makes sense.

Quoted 28 lines
Quoted 12 lines
Quoted 12 lines
include/net/flow_dissector.h +2 -0
@@ -1214,26 +1250,60 @@ bool __skb_flow_dissect(const struct net *net,
 			struct pppoe_hdr hdr;
 			__be16 proto;
 		} *hdr, _hdr;
+		__be16 ppp_proto;
+
 		hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
 		if (!hdr) {
 			fdret = FLOW_DISSECT_RET_OUT_BAD;
 			break;
 		}
 
Quoted 15 lines

include/net/flow_dissector.h bool __skb_flow_dissect(const struct net *net, · line 1270

Quoted 13 lines
include/net/flow_dissector.h +10 -3
-		nhoff += PPPOE_SES_HLEN;
-		switch (hdr->proto) {
-		case htons(PPP_IP):
+		if (!is_pppoe_ses_hdr_valid(hdr->hdr)) {
+			fdret = FLOW_DISSECT_RET_OUT_BAD;
+			break;
+		}
+
+		/* least significant bit of the first byte
+		 * indicates if protocol field was compressed
+		 */
+		if (hdr->proto & 1) {
+			ppp_proto = hdr->proto << 8;

This is little endian specific code. We can't make such assumptions.

Quoted 2 lines

Both ppp_proto and hdr->prot are stored in __be16 so left shift by 8 bits should always be ok, am I right?

Sorry, I don't understand. How could the test and the bit shift operation give the correct result on a big endian machine?

Let's say we handle an IPv4 packet and the PPP protocol field isn't compressed. That is, protocol is 0x0021.
On a big endian machine 'hdr->proto & 1' is true and the bit shift sets ppp_proto to 0x2100, while the code should have left the original value untouched.

Quoted 1 line

Should I use cpu_to_be16 on both 1 and 8. Is that what you mean?

I can't see how cpu_to_be16() could help here. I was thinking of simply using ntohs(hdr->proto).

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#5 lore raw

RE: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 81 lines

-----Original Message-----
From: Guillaume Nault <[email protected]>
Sent: wtorek, 12 lipca 2022 19:20
To: Drewek, Wojciech <[email protected]>
Cc: Marcin Szycik <[email protected]>; [email protected]; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; Brandeburg, Jesse <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lobakin, Alexandr <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 24 lines · Wojciech
Quoted 8 lines
Quoted 8 lines
include/net/flow_dissector.h +0 -0
index a4c6057c7097..af0d429b9a26 100644
@@ -261,6 +261,18 @@ struct flow_dissector_key_num_of_vlans {
 	u8 num_of_vlans;
 };
 
Quoted 12 lines

include/net/flow_dissector.h struct flow_dissector_key_num_of_vlans { · line 273

Quoted 10 lines
include/net/flow_dissector.h +10 -0
+/**
+ * struct flow_dissector_key_pppoe:
+ * @session_id: pppoe session id
+ * @ppp_proto: ppp protocol
+ * @type: pppoe eth type
+ */
+struct flow_dissector_key_pppoe {
+	__be16 session_id;
+	__be16 ppp_proto;
+	__be16 type;

I don't understand the need for the new 'type' field.

Let's say user want to add below filter with just protocol field:
tc filter add dev ens6f0 ingress prio 1 protocol ppp_ses action drop

Quoted 8 lines

cls_flower would set basic.n_proto to ETH_P_PPP_SES, then PPPoE packet
arrives with ppp_proto = PPP_IP, which means that in __skb_flow_dissect basic.n_proto is going to be set to ETH_P_IP. We have a mismatch here cls_flower set basic.n_proto to ETH_P_PPP_SES and flow_dissector set it to ETH_P_IP. That's why in such example basic.n_proto has to be set to 0 (it works the same with vlans) and key_pppoe::type has to be used. In other words basic.n_proto can't be used for storing ETH_P_PPP_SES because it will store encapsulated protocol.

We could also use it to match on ETH_P_PPP_DISC.

Thanks for the explanation. That makes sense.

Quoted 28 lines
Quoted 12 lines
Quoted 12 lines
include/net/flow_dissector.h +2 -0
@@ -1214,26 +1250,60 @@ bool __skb_flow_dissect(const struct net *net,
 			struct pppoe_hdr hdr;
 			__be16 proto;
 		} *hdr, _hdr;
+		__be16 ppp_proto;
+
 		hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
 		if (!hdr) {
 			fdret = FLOW_DISSECT_RET_OUT_BAD;
 			break;
 		}
 
Quoted 15 lines

include/net/flow_dissector.h bool __skb_flow_dissect(const struct net *net, · line 1270

Quoted 13 lines
include/net/flow_dissector.h +10 -3
-		nhoff += PPPOE_SES_HLEN;
-		switch (hdr->proto) {
-		case htons(PPP_IP):
+		if (!is_pppoe_ses_hdr_valid(hdr->hdr)) {
+			fdret = FLOW_DISSECT_RET_OUT_BAD;
+			break;
+		}
+
+		/* least significant bit of the first byte
+		 * indicates if protocol field was compressed
+		 */
+		if (hdr->proto & 1) {
+			ppp_proto = hdr->proto << 8;

This is little endian specific code. We can't make such assumptions.

Quoted 2 lines

Both ppp_proto and hdr->prot are stored in __be16 so left shift by 8 bits should always be ok, am I right?

Quoted 9 lines

Sorry, I don't understand. How could the test and the bit shift operation give the correct result on a big endian machine?

Let's say we handle an IPv4 packet and the PPP protocol field isn't compressed. That is, protocol is 0x0021.
On a big endian machine 'hdr->proto & 1' is true and the bit shift sets ppp_proto to 0x2100, while the code should have left the original value untouched.

Ok, I see now, we'll fix it in the next version.

Quoted 4 lines
Quoted 1 line

Should I use cpu_to_be16 on both 1 and 8. Is that what you mean?

I can't see how cpu_to_be16() could help here. I was thinking of simply using ntohs(hdr->proto).

#6 lore raw

RE: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 98 lines

-----Original Message-----
From: Drewek, Wojciech
Sent: środa, 13 lipca 2022 09:59
To: Guillaume Nault <[email protected]>
Cc: Marcin Szycik <[email protected]>; [email protected]; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; Brandeburg, Jesse <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lobakin, Alexandr <[email protected]>; [email protected]; [email protected]
Subject: RE: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 82 lines

-----Original Message-----
From: Guillaume Nault <[email protected]>
Sent: wtorek, 12 lipca 2022 19:20
To: Drewek, Wojciech <[email protected]>
Cc: Marcin Szycik <[email protected]>; [email protected]; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; Brandeburg, Jesse <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Lobakin, Alexandr <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 24 lines · Wojciech
Quoted 8 lines
Quoted 8 lines
include/net/flow_dissector.h +0 -0
index a4c6057c7097..af0d429b9a26 100644
@@ -261,6 +261,18 @@ struct flow_dissector_key_num_of_vlans {
 	u8 num_of_vlans;
 };
 
Quoted 12 lines

include/net/flow_dissector.h struct flow_dissector_key_num_of_vlans { · line 273

Quoted 10 lines
include/net/flow_dissector.h +10 -0
+/**
+ * struct flow_dissector_key_pppoe:
+ * @session_id: pppoe session id
+ * @ppp_proto: ppp protocol
+ * @type: pppoe eth type
+ */
+struct flow_dissector_key_pppoe {
+	__be16 session_id;
+	__be16 ppp_proto;
+	__be16 type;

I don't understand the need for the new 'type' field.

Let's say user want to add below filter with just protocol field:
tc filter add dev ens6f0 ingress prio 1 protocol ppp_ses action drop

Quoted 8 lines

cls_flower would set basic.n_proto to ETH_P_PPP_SES, then PPPoE packet
arrives with ppp_proto = PPP_IP, which means that in __skb_flow_dissect basic.n_proto is going to be set to ETH_P_IP. We have a mismatch here cls_flower set basic.n_proto to ETH_P_PPP_SES and flow_dissector set it to ETH_P_IP. That's why in such example basic.n_proto has to be set to 0 (it works the same with vlans) and key_pppoe::type has to be used. In other words basic.n_proto can't be used for storing ETH_P_PPP_SES because it will store encapsulated protocol.

We could also use it to match on ETH_P_PPP_DISC.

Thanks for the explanation. That makes sense.

Quoted 28 lines
Quoted 12 lines
Quoted 12 lines
include/net/flow_dissector.h +2 -0
@@ -1214,26 +1250,60 @@ bool __skb_flow_dissect(const struct net *net,
 			struct pppoe_hdr hdr;
 			__be16 proto;
 		} *hdr, _hdr;
+		__be16 ppp_proto;
+
 		hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
 		if (!hdr) {
 			fdret = FLOW_DISSECT_RET_OUT_BAD;
 			break;
 		}
 
Quoted 15 lines

include/net/flow_dissector.h bool __skb_flow_dissect(const struct net *net, · line 1270

Quoted 13 lines
include/net/flow_dissector.h +10 -3
-		nhoff += PPPOE_SES_HLEN;
-		switch (hdr->proto) {
-		case htons(PPP_IP):
+		if (!is_pppoe_ses_hdr_valid(hdr->hdr)) {
+			fdret = FLOW_DISSECT_RET_OUT_BAD;
+			break;
+		}
+
+		/* least significant bit of the first byte
+		 * indicates if protocol field was compressed
+		 */
+		if (hdr->proto & 1) {
+			ppp_proto = hdr->proto << 8;

This is little endian specific code. We can't make such assumptions.

Quoted 2 lines

Both ppp_proto and hdr->prot are stored in __be16 so left shift by 8 bits should always be ok, am I right?

Sorry, I don't understand. How could the test and the bit shift operation give the correct result on a big endian machine?

Quoted 8 lines
Quoted 6 lines

Let's say we handle an IPv4 packet and the PPP protocol field isn't compressed. That is, protocol is 0x0021.
On a big endian machine 'hdr->proto & 1' is true and the bit shift sets ppp_proto to 0x2100, while the code should have left the original value untouched.

Ok, I see now, we'll fix it in the next version.

I think this should work with both LE and BE arch, what do you think Guillaume? We don't want to spam so much with next versions so maybe it is better to ask earlier.

	u16 ppp_proto;

	ppp_proto = ntohs(hdr->proto);
	if (ppp_proto & 256) {
		ppp_proto = htons(ppp_proto >> 8);
		nhoff += PPPOE_SES_HLEN - 1;
	} else {
		ppp_proto = htons(ppp_proto);
		nhoff += PPPOE_SES_HLEN;
	}
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Should I use cpu_to_be16 on both 1 and 8. Is that what you mean?

I can't see how cpu_to_be16() could help here. I was thinking of simply using ntohs(hdr->proto).

#7 lore raw

Re: [RFC PATCH net-next v4 1/4] flow_dissector: Add PPPoE dissectors

Quoted 4 lines · Wojciech

I think this should work with both LE and BE arch, what do you think Guillaume? We don't want to spam so much with next versions so maybe it is better to ask earlier.

Quoted 10 lines
	u16 ppp_proto;

	ppp_proto = ntohs(hdr->proto);
	if (ppp_proto & 256) {
		ppp_proto = htons(ppp_proto >> 8);
		nhoff += PPPOE_SES_HLEN - 1;
	} else {
		ppp_proto = htons(ppp_proto);
		nhoff += PPPOE_SES_HLEN;
	}

Sorry for responding late. I was away this week (and will be next week too) and have very sporadic (and slow) Internet connection and limitted time for review. I saw you've sent a v5 with this code, I'll reply there. Thanks for being so patient.

#8 lore raw

RFC PATCH v4 2/4 net/sched: flower: Add PPPoE filter

In reply to Marcin Szycik

From: Wojciech Drewek <[email protected]>

Add support for PPPoE specific fields for tc-flower. Those fields can be provided only when protocol was set to ETH_P_PPP_SES. Defines, dump, load and set are being done here.

Overwrite basic.n_proto only in case of PPP_IP and PPP_IPV6, otherwise leave it as ETH_P_PPP_SES.

---
v4:
* support of MPLS inner fields
* session_id stored in __be16

 include/uapi/linux/pkt_cls.h |  3 ++
 net/sched/cls_flower.c       | 61 ++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)
include/uapi/linux/pkt_cls.h +3 -0
index 9a2ee1e39fad..c142c0f8ed8a 100644
@@ -589,6 +589,9 @@ enum {
 
 	TCA_FLOWER_KEY_NUM_OF_VLANS,    /* u8 */
 
+	TCA_FLOWER_KEY_PPPOE_SID,	/* be16 */
+	TCA_FLOWER_KEY_PPP_PROTO,	/* be16 */
+
 	__TCA_FLOWER_MAX,
 };
 
net/sched/cls_flower.c +61 -0

103 lines not on this page · raw message

Signature · 1 line
2.35.1
#9 lore raw

Re: [RFC PATCH net-next v4 2/4] net/sched: flower: Add PPPoE filter

Quoted 7 lines · Marcin Szycik

From: Wojciech Drewek <[email protected]>

Add support for PPPoE specific fields for tc-flower. Those fields can be provided only when protocol was set to ETH_P_PPP_SES. Defines, dump, load and set are being done here.

Overwrite basic.n_proto only in case of PPP_IP and PPP_IPV6,

... and PPP_MPLS_UC/PPP_MPLS_MC in this new patch version.

Quoted 60 lines

otherwise leave it as ETH_P_PPP_SES.

---
v4:
* support of MPLS inner fields
* session_id stored in __be16

 include/uapi/linux/pkt_cls.h |  3 ++
 net/sched/cls_flower.c       | 61 ++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)
include/uapi/linux/pkt_cls.h +3 -0
index 9a2ee1e39fad..c142c0f8ed8a 100644
@@ -589,6 +589,9 @@ enum {
 
 	TCA_FLOWER_KEY_NUM_OF_VLANS,    /* u8 */
 
+	TCA_FLOWER_KEY_PPPOE_SID,	/* be16 */
+	TCA_FLOWER_KEY_PPP_PROTO,	/* be16 */
+
 	__TCA_FLOWER_MAX,
 };
 
net/sched/cls_flower.c +5 -0
index dcca70144dff..2a0ebad0e61c 100644
@@ -16,6 +16,7 @@
 #include <linux/in6.h>
 #include <linux/ip.h>
 #include <linux/mpls.h>
+#include <linux/ppp_defs.h>
 
 #include <net/sch_generic.h>
 #include <net/pkt_cls.h>
@@ -73,6 +74,7 @@ struct fl_flow_key {
 	struct flow_dissector_key_ct ct;
 	struct flow_dissector_key_hash hash;
 	struct flow_dissector_key_num_of_vlans num_of_vlans;
+	struct flow_dissector_key_pppoe pppoe;
 } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
 
 struct fl_flow_mask_range {
@@ -714,6 +716,8 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
 	[TCA_FLOWER_KEY_HASH]		= { .type = NLA_U32 },
 	[TCA_FLOWER_KEY_HASH_MASK]	= { .type = NLA_U32 },
 	[TCA_FLOWER_KEY_NUM_OF_VLANS]	= { .type = NLA_U8 },
+	[TCA_FLOWER_KEY_PPPOE_SID]	= { .type = NLA_U16 },
+	[TCA_FLOWER_KEY_PPP_PROTO]	= { .type = NLA_U16 },
 
 };
 
@@ -1041,6 +1045,50 @@ static void fl_set_key_vlan(struct nlattr **tb,
 	}
 }
 
+static void fl_set_key_pppoe(struct nlattr **tb,

net/sched/cls_flower.c static void fl_set_key_vlan(struct nlattr **tb, · line 1058

Quoted 10 lines
net/sched/cls_flower.c +10 -0
+			     struct flow_dissector_key_pppoe *key_val,
+			     struct flow_dissector_key_pppoe *key_mask,
+			     struct fl_flow_key *key,
+			     struct fl_flow_key *mask)
+{
+	/* key_val::type must be set to ETH_P_PPP_SES
+	 * because ETH_P_PPP_SES was stored in basic.n_proto
+	 * which might get overwritten by ppp_proto
+	 * or might be set to 0, the role of key_val::type
+	 * is simmilar to vlan_key::tpid

Didn't you mean "vlan_tpid"?

Quoted 73 lines
net/sched/cls_flower.c +46 -0
+	 */
+	key_val->type = htons(ETH_P_PPP_SES);
+	key_mask->type = cpu_to_be16(~0);
+
+	if (tb[TCA_FLOWER_KEY_PPPOE_SID]) {
+		key_val->session_id =
+			nla_get_be16(tb[TCA_FLOWER_KEY_PPPOE_SID]);
+		key_mask->session_id = cpu_to_be16(~0);
+	}
+	if (tb[TCA_FLOWER_KEY_PPP_PROTO]) {
+		key_val->ppp_proto =
+			nla_get_be16(tb[TCA_FLOWER_KEY_PPP_PROTO]);
+		key_mask->ppp_proto = cpu_to_be16(~0);
+
+		if (key_val->ppp_proto == htons(PPP_IP)) {
+			key->basic.n_proto = htons(ETH_P_IP);
+			mask->basic.n_proto = cpu_to_be16(~0);
+		} else if (key_val->ppp_proto == htons(PPP_IPV6)) {
+			key->basic.n_proto = htons(ETH_P_IPV6);
+			mask->basic.n_proto = cpu_to_be16(~0);
+		} else if (key_val->ppp_proto == htons(PPP_MPLS_UC)) {
+			key->basic.n_proto = htons(ETH_P_MPLS_UC);
+			mask->basic.n_proto = cpu_to_be16(~0);
+		} else if (key_val->ppp_proto == htons(PPP_MPLS_MC)) {
+			key->basic.n_proto = htons(ETH_P_MPLS_MC);
+			mask->basic.n_proto = cpu_to_be16(~0);
+		}
+	} else {
+		key->basic.n_proto = 0;
+		mask->basic.n_proto = cpu_to_be16(0);
+	}
+}
+
 static void fl_set_key_flag(u32 flower_key, u32 flower_mask,
 			    u32 *dissector_key, u32 *dissector_mask,
 			    u32 flower_flag_bit, u32 dissector_flag_bit)
@@ -1651,6 +1699,9 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
 		}
 	}
 
+	if (key->basic.n_proto == htons(ETH_P_PPP_SES))
+		fl_set_key_pppoe(tb, &key->pppoe, &mask->pppoe, key, mask);
+
 	if (key->basic.n_proto == htons(ETH_P_IP) ||
 	    key->basic.n_proto == htons(ETH_P_IPV6)) {
 		fl_set_key_val(tb, &key->basic.ip_proto, TCA_FLOWER_KEY_IP_PROTO,
@@ -1923,6 +1974,8 @@ static void fl_init_dissector(struct flow_dissector *dissector,
 			     FLOW_DISSECTOR_KEY_HASH, hash);
 	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_NUM_OF_VLANS, num_of_vlans);
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
+			     FLOW_DISSECTOR_KEY_PPPOE, pppoe);
 
 	skb_flow_dissector_init(dissector, keys, cnt);
 }
@@ -3051,6 +3104,14 @@ static int fl_dump_key(struct sk_buff *skb, struct net *net,
 	    fl_dump_key_ip(skb, false, &key->ip, &mask->ip)))
 		goto nla_put_failure;
 
+	if (mask->pppoe.session_id &&
+	    nla_put_be16(skb, TCA_FLOWER_KEY_PPPOE_SID, key->pppoe.session_id))
+		goto nla_put_failure;
+
+	if (mask->basic.n_proto && mask->pppoe.ppp_proto &&
+	    nla_put_be16(skb, TCA_FLOWER_KEY_PPP_PROTO, key->pppoe.ppp_proto))
+		goto nla_put_failure;
+
 	if (key->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
 	    (fl_dump_key_val(skb, &key->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC,
 			     &mask->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC_MASK,
Signature · 1 line
2.35.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#10 lore raw

RE: [RFC PATCH net-next v4 2/4] net/sched: flower: Add PPPoE filter

Quoted 85 lines

-----Original Message-----
From: Guillaume Nault <[email protected]>
Sent: piątek, 8 lipca 2022 21:23
To: Marcin Szycik <[email protected]>
Cc: [email protected]; Nguyen, Anthony L <[email protected]>; [email protected]; [email protected]; Brandeburg, Jesse <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Drewek, Wojciech <[email protected]>; Lobakin, Alexandr <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH net-next v4 2/4] net/sched: flower: Add PPPoE filter

Quoted 7 lines · Marcin Szycik

From: Wojciech Drewek <[email protected]>

Add support for PPPoE specific fields for tc-flower. Those fields can be provided only when protocol was set to ETH_P_PPP_SES. Defines, dump, load and set are being done here.

Overwrite basic.n_proto only in case of PPP_IP and PPP_IPV6,

... and PPP_MPLS_UC/PPP_MPLS_MC in this new patch version.

Quoted 59 lines

otherwise leave it as ETH_P_PPP_SES.

---
v4:
* support of MPLS inner fields
* session_id stored in __be16

 include/uapi/linux/pkt_cls.h |  3 ++
 net/sched/cls_flower.c       | 61 ++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)
include/uapi/linux/pkt_cls.h +3 -0
index 9a2ee1e39fad..c142c0f8ed8a 100644
@@ -589,6 +589,9 @@ enum {
 
 	TCA_FLOWER_KEY_NUM_OF_VLANS,    /* u8 */
 
+	TCA_FLOWER_KEY_PPPOE_SID,	/* be16 */
+	TCA_FLOWER_KEY_PPP_PROTO,	/* be16 */
+
 	__TCA_FLOWER_MAX,
 };
 
net/sched/cls_flower.c +4 -0
index dcca70144dff..2a0ebad0e61c 100644
@@ -16,6 +16,7 @@
 #include <linux/in6.h>
 #include <linux/ip.h>
 #include <linux/mpls.h>
+#include <linux/ppp_defs.h>
 
 #include <net/sch_generic.h>
 #include <net/pkt_cls.h>
@@ -73,6 +74,7 @@ struct fl_flow_key {
 	struct flow_dissector_key_ct ct;
 	struct flow_dissector_key_hash hash;
 	struct flow_dissector_key_num_of_vlans num_of_vlans;
+	struct flow_dissector_key_pppoe pppoe;
 } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
 
 struct fl_flow_mask_range {
@@ -714,6 +716,8 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
 	[TCA_FLOWER_KEY_HASH]		= { .type = NLA_U32 },
 	[TCA_FLOWER_KEY_HASH_MASK]	= { .type = NLA_U32 },
 	[TCA_FLOWER_KEY_NUM_OF_VLANS]	= { .type = NLA_U8 },
+	[TCA_FLOWER_KEY_PPPOE_SID]	= { .type = NLA_U16 },
+	[TCA_FLOWER_KEY_PPP_PROTO]	= { .type = NLA_U16 },
 
 };
 
@@ -1041,6 +1045,50 @@ static void fl_set_key_vlan(struct nlattr **tb,
 	}
 }
 
Quoted 13 lines

net/sched/cls_flower.c static void fl_set_key_vlan(struct nlattr **tb, · line 1058

Quoted 11 lines
net/sched/cls_flower.c +11 -0
+static void fl_set_key_pppoe(struct nlattr **tb,
+			     struct flow_dissector_key_pppoe *key_val,
+			     struct flow_dissector_key_pppoe *key_mask,
+			     struct fl_flow_key *key,
+			     struct fl_flow_key *mask)
+{
+	/* key_val::type must be set to ETH_P_PPP_SES
+	 * because ETH_P_PPP_SES was stored in basic.n_proto
+	 * which might get overwritten by ppp_proto
+	 * or might be set to 0, the role of key_val::type
+	 * is simmilar to vlan_key::tpid

Didn't you mean "vlan_tpid"?

Yes, is vlan_key::tpid not clear/valid?

Quoted 60 lines
Quoted 60 lines
net/sched/cls_flower.c +38 -0
+	 */
+	key_val->type = htons(ETH_P_PPP_SES);
+	key_mask->type = cpu_to_be16(~0);
+
+	if (tb[TCA_FLOWER_KEY_PPPOE_SID]) {
+		key_val->session_id =
+			nla_get_be16(tb[TCA_FLOWER_KEY_PPPOE_SID]);
+		key_mask->session_id = cpu_to_be16(~0);
+	}
+	if (tb[TCA_FLOWER_KEY_PPP_PROTO]) {
+		key_val->ppp_proto =
+			nla_get_be16(tb[TCA_FLOWER_KEY_PPP_PROTO]);
+		key_mask->ppp_proto = cpu_to_be16(~0);
+
+		if (key_val->ppp_proto == htons(PPP_IP)) {
+			key->basic.n_proto = htons(ETH_P_IP);
+			mask->basic.n_proto = cpu_to_be16(~0);
+		} else if (key_val->ppp_proto == htons(PPP_IPV6)) {
+			key->basic.n_proto = htons(ETH_P_IPV6);
+			mask->basic.n_proto = cpu_to_be16(~0);
+		} else if (key_val->ppp_proto == htons(PPP_MPLS_UC)) {
+			key->basic.n_proto = htons(ETH_P_MPLS_UC);
+			mask->basic.n_proto = cpu_to_be16(~0);
+		} else if (key_val->ppp_proto == htons(PPP_MPLS_MC)) {
+			key->basic.n_proto = htons(ETH_P_MPLS_MC);
+			mask->basic.n_proto = cpu_to_be16(~0);
+		}
+	} else {
+		key->basic.n_proto = 0;
+		mask->basic.n_proto = cpu_to_be16(0);
+	}
+}
+
 static void fl_set_key_flag(u32 flower_key, u32 flower_mask,
 			    u32 *dissector_key, u32 *dissector_mask,
 			    u32 flower_flag_bit, u32 dissector_flag_bit)
@@ -1651,6 +1699,9 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
 		}
 	}
 
+	if (key->basic.n_proto == htons(ETH_P_PPP_SES))
+		fl_set_key_pppoe(tb, &key->pppoe, &mask->pppoe, key, mask);
+
 	if (key->basic.n_proto == htons(ETH_P_IP) ||
 	    key->basic.n_proto == htons(ETH_P_IPV6)) {
 		fl_set_key_val(tb, &key->basic.ip_proto, TCA_FLOWER_KEY_IP_PROTO,
@@ -1923,6 +1974,8 @@ static void fl_init_dissector(struct flow_dissector *dissector,
 			     FLOW_DISSECTOR_KEY_HASH, hash);
 	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_NUM_OF_VLANS, num_of_vlans);
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
+			     FLOW_DISSECTOR_KEY_PPPOE, pppoe);
 
 	skb_flow_dissector_init(dissector, keys, cnt);
 }
@@ -3051,6 +3104,14 @@ static int fl_dump_key(struct sk_buff *skb, struct net *net,
 	    fl_dump_key_ip(skb, false, &key->ip, &mask->ip)))
 		goto nla_put_failure;
 
Quoted 14 lines
Quoted 12 lines
net/sched/cls_flower.c +8 -1
+	if (mask->pppoe.session_id &&
+	    nla_put_be16(skb, TCA_FLOWER_KEY_PPPOE_SID, key->pppoe.session_id))
+		goto nla_put_failure;
+
+	if (mask->basic.n_proto && mask->pppoe.ppp_proto &&
+	    nla_put_be16(skb, TCA_FLOWER_KEY_PPP_PROTO, key->pppoe.ppp_proto))
+		goto nla_put_failure;
+
 	if (key->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
 	    (fl_dump_key_val(skb, &key->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC,
 			     &mask->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC_MASK,
--
Quoted 2 lines

2.35.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#11 lore raw

Re: [RFC PATCH net-next v4 2/4] net/sched: flower: Add PPPoE filter

Quoted 14 lines · Wojciech
Quoted 5 lines
Quoted 5 lines
net/sched/cls_flower.c +5 -0
+static void fl_set_key_pppoe(struct nlattr **tb,
+			     struct flow_dissector_key_pppoe *key_val,
+			     struct flow_dissector_key_pppoe *key_mask,
+			     struct fl_flow_key *key,
+			     struct fl_flow_key *mask)
Quoted 8 lines

net/sched/cls_flower.c static void fl_set_key_vlan(struct nlattr **tb, · line 1058

Quoted 6 lines
net/sched/cls_flower.c +6 -0
+{
+	/* key_val::type must be set to ETH_P_PPP_SES
+	 * because ETH_P_PPP_SES was stored in basic.n_proto
+	 * which might get overwritten by ppp_proto
+	 * or might be set to 0, the role of key_val::type
+	 * is simmilar to vlan_key::tpid

Didn't you mean "vlan_tpid"?

Quoted 1 line

Yes, is vlan_key::tpid not clear/valid?

At least it wasn't entirely clear to me as I wondered if I got the comment right. And it's basically free to use the real name of the structure field.

#12 lore raw

RFC PATCH v4 3/4 flow_offload: Introduce flow_match_pppoe

In reply to Marcin Szycik

From: Wojciech Drewek <[email protected]>

Allow to offload PPPoE filters by adding flow_rule_match_pppoe. Drivers can extract PPPoE specific fields from now on.

---
 include/net/flow_offload.h | 6 ++++++
 net/core/flow_offload.c    | 7 +++++++
 2 files changed, 13 insertions(+)
include/net/flow_offload.h +6 -0
index 7ac313858037..8826606c8464 100644
@@ -72,6 +72,10 @@ struct flow_match_ct {
 	struct flow_dissector_key_ct *key, *mask;
 };
 
+struct flow_match_pppoe {
+	struct flow_dissector_key_pppoe *key, *mask;
+};
+
 struct flow_rule;
 
 void flow_rule_match_meta(const struct flow_rule *rule,
@@ -116,6 +120,8 @@ void flow_rule_match_enc_opts(const struct flow_rule *rule,
 			      struct flow_match_enc_opts *out);
 void flow_rule_match_ct(const struct flow_rule *rule,
 			struct flow_match_ct *out);
+void flow_rule_match_pppoe(const struct flow_rule *rule,
+			   struct flow_match_pppoe *out);
 
 enum flow_action_id {
 	FLOW_ACTION_ACCEPT		= 0,
net/core/flow_offload.c +7 -0
index 929f6379a279..d13d293e3de2 100644
@@ -223,6 +223,13 @@ void flow_rule_match_ct(const struct flow_rule *rule,
 }
 EXPORT_SYMBOL(flow_rule_match_ct);
 
+void flow_rule_match_pppoe(const struct flow_rule *rule,
+			   struct flow_match_pppoe *out)
+{
+	FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_PPPOE, out);
+}
+EXPORT_SYMBOL(flow_rule_match_pppoe);
+
 struct flow_block_cb *flow_block_cb_alloc(flow_setup_cb_t *cb,
 					  void *cb_ident, void *cb_priv,
 					  void (*release)(void *cb_priv))
Signature · 1 line
2.35.1
#13 lore raw

RFC PATCH v4 4/4 ice: Add support for PPPoE hardware offload

In reply to Marcin Szycik

Add support for creating PPPoE filters in switchdev mode. Add support for parsing PPPoE and PPP-specific tc options: pppoe_sid and ppp_proto.

Example filter:
tc filter add dev $PF1 ingress protocol ppp_ses prio 1 flower pppoe_sid \
1234 ppp_proto ip skip_sw action mirred egress redirect dev $VF1_PR

Changes in iproute2 are required to use the new fields.

ICE COMMS DDP package is required to create a filter as it contains PPPoE profiles. Added a warning message when loaded DDP package does not contain required profiles.

---
v4:
* adapted code to the redefined ice_tc_pppoe_hdr (session_id is now

    stored in __be16)

* removed note about missing support for vlan fields:
263957263a00 ("ice: switch: dynamically add VLAN headers to dummy packets") is already accepted
* always add an ethtype lookup if PPP/PPPoE options are provided (to prevent setting incorrect ethtype)
* rebase
v2: wrap one long line

 drivers/net/ethernet/intel/ice/ice.h          |   1 +
 .../net/ethernet/intel/ice/ice_flex_pipe.c    |   5 +-
 .../ethernet/intel/ice/ice_protocol_type.h    |  11 ++
 drivers/net/ethernet/intel/ice/ice_switch.c   | 165 ++++++++++++++++++
 drivers/net/ethernet/intel/ice/ice_tc_lib.c   |  71 +++++++-
 drivers/net/ethernet/intel/ice/ice_tc_lib.h   |   8 +
 6 files changed, 259 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +1 -0
index 60453b3b8d23..0e48a930f004 100644
@@ -52,6 +52,7 @@
 #include <net/udp_tunnel.h>
 #include <net/vxlan.h>
 #include <net/gtp.h>
+#include <linux/ppp_defs.h>
 #include "ice_devids.h"
 #include "ice_type.h"
 #include "ice_txrx.h"
drivers/net/ethernet/intel/ice/ice_flex_pipe.c +4 -1
index ada5198b5b16..4b3bb19e1d06 100644
@@ -1964,8 +1964,11 @@ ice_get_sw_fv_list(struct ice_hw *hw, struct ice_prot_lkup_ext *lkups,
 			}
 		}
 	} while (fv);
-	if (list_empty(fv_list))
+	if (list_empty(fv_list)) {
+		dev_warn(ice_hw_to_dev(hw), "Required profiles not found in currently loaded DDP package");
 		return -EIO;
+	}
+
 	return 0;
 
 err:
drivers/net/ethernet/intel/ice/ice_protocol_type.h +11 -0
index d4a0d089649c..560efc7654c7 100644
@@ -43,6 +43,7 @@ enum ice_protocol_type {
 	ICE_NVGRE,
 	ICE_GTP,
 	ICE_GTP_NO_PAY,
+	ICE_PPPOE,
 	ICE_VLAN_EX,
 	ICE_VLAN_IN,
 	ICE_VXLAN_GPE,
@@ -109,6 +110,7 @@ enum ice_prot_id {
 #define ICE_TCP_IL_HW		49
 #define ICE_UDP_ILOS_HW		53
 #define ICE_GRE_OF_HW		64
+#define ICE_PPPOE_HW		103
 
 #define ICE_UDP_OF_HW	52 /* UDP Tunnels */
 #define ICE_META_DATA_ID_HW 255 /* this is used for tunnel and VLAN type */
@@ -207,6 +209,14 @@ struct ice_udp_gtp_hdr {
 	u8 rsvrd;
 };
 
+struct ice_pppoe_hdr {
+	u8 rsrvd_ver_type;
+	u8 rsrvd_code;
+	__be16 session_id;
+	__be16 length;
+	__be16 ppp_prot_id; /* control and data only */
+};
+
 struct ice_nvgre_hdr {
 	__be16 flags;
 	__be16 protocol;
@@ -224,6 +234,7 @@ union ice_prot_hdr {
 	struct ice_udp_tnl_hdr tnl_hdr;
 	struct ice_nvgre_hdr nvgre_hdr;
 	struct ice_udp_gtp_hdr gtp_hdr;
+	struct ice_pppoe_hdr pppoe_hdr;
 };
 
 /* This is mapping table entry that maps every word within a given protocol
drivers/net/ethernet/intel/ice/ice_switch.c +165 -0

207 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_tc_lib.c +70 -1

101 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_tc_lib.h +8 -0
index 0193874cd203..91cd3d3778c7 100644
@@ -24,6 +24,8 @@
 #define ICE_TC_FLWR_FIELD_ETH_TYPE_ID		BIT(17)
 #define ICE_TC_FLWR_FIELD_ENC_OPTS		BIT(18)
 #define ICE_TC_FLWR_FIELD_CVLAN			BIT(19)
+#define ICE_TC_FLWR_FIELD_PPPOE_SESSID		BIT(20)
+#define ICE_TC_FLWR_FIELD_PPP_PROTO		BIT(21)
 
 #define ICE_TC_FLOWER_MASK_32   0xFFFFFFFF
 
@@ -44,6 +46,11 @@ struct ice_tc_vlan_hdr {
 	__be16 vlan_tpid;
 };
 
+struct ice_tc_pppoe_hdr {
+	__be16 session_id;
+	__be16 ppp_proto;
+};
+
 struct ice_tc_l2_hdr {
 	u8 dst_mac[ETH_ALEN];
 	u8 src_mac[ETH_ALEN];
@@ -84,6 +91,7 @@ struct ice_tc_flower_lyr_2_4_hdrs {
 	struct ice_tc_l2_hdr l2_mask;
 	struct ice_tc_vlan_hdr vlan_hdr;
 	struct ice_tc_vlan_hdr cvlan_hdr;
+	struct ice_tc_pppoe_hdr pppoe_hdr;
 	/* L3 (IPv4[6]) layer fields with their mask */
 	struct ice_tc_l3_hdr l3_key;
 	struct ice_tc_l3_hdr l3_mask;
Signature · 1 line
2.35.1