[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220628112918.11296-2-marcin.szycik@linux.intel.com>
Date: Tue, 28 Jun 2022 13:29:15 +0200
From: Marcin Szycik <marcin.szycik@...ux.intel.com>
To: netdev@...r.kernel.org
Cc: anthony.l.nguyen@...el.com, davem@...emloft.net,
xiyou.wangcong@...il.com, jesse.brandeburg@...el.com,
gustavoars@...nel.org, baowen.zheng@...igine.com,
boris.sukholitko@...adcom.com, edumazet@...gle.com,
kuba@...nel.org, jhs@...atatu.com, jiri@...nulli.us,
kurt@...utronix.de, pablo@...filter.org, pabeni@...hat.com,
paulb@...dia.com, simon.horman@...igine.com,
komachi.yoshiki@...il.com, zhangkaiheb@....com,
intel-wired-lan@...ts.osuosl.org,
michal.swiatkowski@...ux.intel.com, wojciech.drewek@...el.com,
alexandr.lobakin@...el.com
Subject: [RFC PATCH net-next v2 1/4] flow_dissector: Add PPPoE dissectors
From: Wojciech Drewek <wojciech.drewek@...el.com>
Allow to dissect PPPoE specific fields which are:
- session ID (16 bits)
- ppp protocol (16 bits)
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.
Signed-off-by: Wojciech Drewek <wojciech.drewek@...el.com>
---
v2: use ntohs instead of htons in is_ppp_proto_supported
include/net/flow_dissector.h | 11 ++++++++
net/core/flow_dissector.c | 51 +++++++++++++++++++++++++++++++-----
2 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index a4c6057c7097..8ff40c7c3f1c 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -261,6 +261,16 @@ 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
+ */
+struct flow_dissector_key_pppoe {
+ u16 session_id;
+ __be16 ppp_proto;
+};
+
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 +301,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,
};
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 6aee04f75e3e..a758b1980e4a 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -895,6 +895,35 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
return result == BPF_OK;
}
+static bool is_ppp_proto_supported(__be16 proto)
+{
+ switch (ntohs(proto)) {
+ case PPP_AT:
+ case PPP_IPX:
+ case PPP_VJC_COMP:
+ case PPP_VJC_UNCOMP:
+ case PPP_MP:
+ case PPP_COMPFRAG:
+ case PPP_COMP:
+ case PPP_MPLS_UC:
+ case PPP_MPLS_MC:
+ case PPP_IPCP:
+ case PPP_ATCP:
+ case PPP_IPXCP:
+ case PPP_IPV6CP:
+ case PPP_CCPFRAG:
+ case PPP_MPLSCP:
+ case PPP_LCP:
+ case PPP_PAP:
+ case PPP_LQR:
+ case PPP_CHAP:
+ case PPP_CBCP:
+ return true;
+ default:
+ return false;
+ }
+}
+
/**
* __skb_flow_dissect - extract the flow_keys struct and return it
* @net: associated network namespace, derived from @skb if NULL
@@ -1221,19 +1250,29 @@ bool __skb_flow_dissect(const struct net *net,
}
nhoff += PPPOE_SES_HLEN;
- switch (hdr->proto) {
- case htons(PPP_IP):
+ if (hdr->proto == htons(PPP_IP)) {
proto = htons(ETH_P_IP);
fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
- break;
- case htons(PPP_IPV6):
+ } else if (hdr->proto == htons(PPP_IPV6)) {
proto = htons(ETH_P_IPV6);
fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
- break;
- default:
+ } else if (is_ppp_proto_supported(hdr->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 = ntohs(hdr->hdr.sid);
+ key_pppoe->ppp_proto = hdr->proto;
+ }
break;
}
case htons(ETH_P_TIPC): {
--
2.35.1
Powered by blists - more mailing lists