f_flower: implement pfcp opts
Subsystems (3)
PATCH 1/1 f_flower: implement pfcp opts
From: Michal Swiatkowski <[email protected]>
Allow adding tc filter for PFCP header.
Add support for parsing TCA_FLOWER_KEY_ENC_OPTS_PFCP. Options are as follows: TYPE:SEID.
TYPE is a 8-bit value represented in hex and can be 1 for session header and 0 for node header. In PFCP packet this is S flag in header.
SEID is a 64-bit session id value represented in hex.
This patch enables adding hardware filters using PFCP fields, see [1].
[1] https://lore.kernel.org/intel-wired-lan/[email protected]
--- include/libnetlink.h | 6 ++ include/uapi/linux/pkt_cls.h | 14 ++++ man/man8/tc-flower.8 | 11 +++ tc/f_flower.c | 126 +++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+)
include/libnetlink.h +6 -0
@@ -260,6 +260,12 @@ static inline __u64 rta_getattr_u64(const struct rtattr *rta)memcpy (&tmp,RTA_DATA (rta),sizeof (__u64));return tmp; } + +static inline __be64 rta_getattr_be64 (const struct rtattr *rta) +{ +return htobe64 (rta_getattr_u64 (rta)); +} +static inline __s32 rta_getattr_s32 (const struct rtattr *rta) {return *(__s32 *)RTA_DATA (rta);
include/uapi/linux/pkt_cls.h +14 -0
@@ -629,6 +629,10 @@ enum {* TCA_FLOWER_KEY_ENC_OPT_GTP_ * attributes */ +TCA_FLOWER_KEY_ENC_OPTS_PFCP ,/* Nested +* TCA_FLOWER_KEY_ENC_IPT_PFCP +* attributes +*/ __TCA_FLOWER_KEY_ENC_OPTS_MAX, };
@@ -678,6 +682,16 @@ enum {#define TCA_FLOWER_KEY_ENC_OPT_GTP_MAX \ (__TCA_FLOWER_KEY_ENC_OPT_GTP_MAX - 1) +enum { +TCA_FLOWER_KEY_ENC_OPT_PFCP_UNSPEC , +TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE ,/* u8 */ +TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID ,/* be64 */ + __TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX, +}; + +#define TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX \ + (__TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX - 1) +enum {TCA_FLOWER_KEY_MPLS_OPTS_UNSPEC ,TCA_FLOWER_KEY_MPLS_OPTS_LSE ,
man/man8/tc-flower.8 +11 -0
@@ -97,6 +97,8 @@ flower \- flow based traffic control filter .B erspan_opts | .B gtp_opts +| +.B pfcp_opts } .IR OPTIONS " | " .BR ip_flags
@@ -444,6 +446,8 @@ Match the connection zone, and can be masked. .BI erspan_opts " OPTIONS" .TQ .BI gtp_opts " OPTIONS" +.TQ +.BI pfcp_opts " OPTIONS" Match on IP tunnel metadata. Key id .I NUMBER is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel).
@@ -485,6 +489,13 @@ doesn't support multiple options, and it consists of a key followed by a slash and corresponding mask. If the mask is missing, \fBtc\fR assumes a full-length match. The option can be described in the form PDU_TYPE:QFI/PDU_TYPE_MASK:QFI_MASK where both PDU_TYPE and QFI are represented as a 8bit hexadecimal values. +pfcp_opts +.I OPTIONS +doesn't support multiple options, and it consists of a key followed by a slash +and corresponding mask. If the mask is missing, \fBtc\fR assumes a full-length +match. The option can be described in the form TYPE:SEID/TYPE_MASK:SEID_MASK +where TYPE is represented as a 8bit number, SEID is represented by 64bit, both +of them are in hex. .TP .BI ip_flags " IP_FLAGS" .I IP_FLAGS
tc/f_flower.c +126 -0
162 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 6 lines · On Wed, 14 Jun 2023 11:17:58 +0200 Marcin Szycik…
tc/f_flower.c +6
-0+static void flower_print_pfcp_opts (const char *name,struct rtattr *attr, +char *strbuf,int len) +{ +struct rtattr *tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX +1 ]; +struct rtattr *i =RTA_DATA (attr); +int rem =RTA_PAYLOAD (attr);
tc/f_flower.c static void flower_print_gtp_opts(const char *name, struct rtattr *attr, · line 2659
Quoted 10 lines
tc/f_flower.c +10
-0+__be64 seid; +__u8 type; + +parse_rtattr (tb,TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX , i, rem); + type =rta_getattr_u8 (tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE ]); + seid =rta_getattr_be64 (tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID ]); + +snprintf (strbuf, len,"%02x:%llx" , type, seid); +} +
NAK you need to support JSON output.
Also whet if kernel gives partial data.
Quoted 14 lines · Stephen Hemminger
Quoted 11 lines · On Wed, 14 Jun 2023 11:17:58 +0200 Marcin Szycik…
tc/f_flower.c +11
-0+static void flower_print_pfcp_opts (const char *name,struct rtattr *attr, +char *strbuf,int len) +{ +struct rtattr *tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX +1 ]; +struct rtattr *i =RTA_DATA (attr); +int rem =RTA_PAYLOAD (attr); +__be64 seid; +__u8 type; + +parse_rtattr (tb,TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX , i, rem); + type =rta_getattr_u8 (tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE ]);
Quoted 8 lines
tc/f_flower.c static void flower_print_gtp_opts(const char *name, struct rtattr *attr, · line 2659
Quoted 5 lines
tc/f_flower.c +5
-0+ seid =rta_getattr_be64 (tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID ]); + +snprintf (strbuf, len,"%02x:%llx" , type, seid); +} +NAK you need to support JSON output.
Also whet if kernel gives partial data.
Hmm... when we were adding GTP opts parsing, you requested to remove JSON support [1]. Are you sure you want us to add it here?
Could you elaborate about partial data? Are there any similar functions which properly handle partial data?
[1] https://lore.kernel.org/netdev/[email protected]
Regards,
Marcin
Quoted 24 lines · On Thu, 15 Jun 2023 10:36:51 +0200 Marcin Szycik…
Quoted 14 lines · Stephen Hemminger
Quoted 11 lines · On Wed, 14 Jun 2023 11:17:58 +0200 Marcin Szycik…
tc/f_flower.c +11
-0+static void flower_print_pfcp_opts (const char *name,struct rtattr *attr, +char *strbuf,int len) +{ +struct rtattr *tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX +1 ]; +struct rtattr *i =RTA_DATA (attr); +int rem =RTA_PAYLOAD (attr); +__be64 seid; +__u8 type; + +parse_rtattr (tb,TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX , i, rem); + type =rta_getattr_u8 (tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE ]);Quoted 8 lines
tc/f_flower.c static void flower_print_gtp_opts(const char *name, struct rtattr *attr, · line 2659
Quoted 5 lines
tc/f_flower.c +5
-0+ seid =rta_getattr_be64 (tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID ]); + +snprintf (strbuf, len,"%02x:%llx" , type, seid); +} +NAK you need to support JSON output.
Also whet if kernel gives partial data.
Quoted 7 lines
Hmm... when we were adding GTP opts parsing, you requested to remove JSON support [1]. Are you sure you want us to add it here?
Could you elaborate about partial data? Are there any similar functions which properly handle partial data?
The handling of JSON in flower needs lots of cleanup work, not related to this patch. So changing my mind. This patch is OK, it just continues existing unique model of handling.
Ideally, there would not be all the special case handling of JSON in flower. And the code would be more robust about getting partial attributes back from the kernel. Other parts of tc are not as brittle.