flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage
Subsystems (4)
v2 cover flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage
This series reworks the recently added TCA_FLOWER_KEY_ENC_FLAGS attribute, to be more like TCA_FLOWER_KEY_FLAGS, and use the unused u32 flags field in FLOW_DISSECTOR_KEY_ENC_CONTROL, instead of adding a new flags field as FLOW_DISSECTOR_KEY_ENC_FLAGS.
I have defined the new FLOW_DIS_F_* and TCA_FLOWER_KEY_FLAGS_* flags to co-exist with the existing flags, so the meaning of the flags field in struct flow_dissector_key_control is not depending on the context it is used in. If we run out of bits then we can always split them up later, if we really want to. Future flags might also be valid in both contexts.
iproute2 RFC patch: (needs update of uAPI headers)
https://lore.kernel.org/897379f1850a50d8c320ca3facd06c5f03943bac.1719506876.git.dcaratti@redhat.com/
---
Changelog:
v2:
- Refactor flower control flag definitions (requested by Jakub and Alexander)
- Add Tested-by from Davide Caratti on patch 3-10.
v1: https://lore.kernel.org/[email protected]/
- Change netlink attribute type from NLA_U32 to NLA_BE32.
- Ensure that the FLOW_DISSECTOR_KEY_ENC_CONTROL
is also masked for non-IP.
- Fix preexisting typo in kdoc for struct flow_dissector_key_control (all suggested by Davide)
RFC: https://lore.kernel.org/[email protected]/
Asbjørn Sloth Tønnesen (10):
net/sched: flower: refactor tunnel flag definitions net/sched: flower: define new tunnel flags
net/sched: cls_flower: prepare fl_{set,dump}_key_flags() for ENC_FLAGS net/sched: cls_flower: add policy for TCA_FLOWER_KEY_FLAGS
flow_dissector: prepare for encapsulated control flags
flow_dissector: set encapsulated control flags from tun_flags net/sched: cls_flower: add tunnel flags to fl_{set,dump}_key_flags() net/sched: cls_flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage
flow_dissector: cleanup FLOW_DISSECTOR_KEY_ENC_FLAGS
flow_dissector: set encapsulation control flags for non-IP
include/net/flow_dissector.h | 30 ++++---- include/net/ip_tunnels.h | 12 --- include/uapi/linux/pkt_cls.h | 11 ++- net/core/flow_dissector.c | 50 ++++++------ net/sched/cls_flower.c | 142 ++++++++++++++++++++--------------- 5 files changed, 135 insertions(+), 110 deletions(-)
Signature · 1 line
2.45.2
PATCH v2 1/10 net/sched: flower: refactor tunnel flag definitions
Redefine the flower control flags as an enum, so they are included in BTF info.
Make the kernel-side enum a more explicit superset of TCA_FLOWER_KEY_FLAGS_*, new flags still need to be added to both enums, but at least the bit position only has to be defined once.
FLOW_DIS_ENCAPSULATION is never set for mask, so it can't be exposed to userspace in an unsupported flags mask error message, so it will be placed one bit position above the last uAPI flag.
--- include/net/flow_dissector.h | 14 +++++++++++--- include/uapi/linux/pkt_cls.h | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-)
include/net/flow_dissector.h +11 -3
@@ -7,6 +7,7 @@#include <linux/siphash.h> #include <linux/string.h> #include <uapi/linux/if_ether.h> +#include <uapi/linux/pkt_cls.h> struct bpf_prog ;struct net ;
@@ -24,9 +25,16 @@ struct flow_dissector_key_control {u32 flags; }; -#define FLOW_DIS_IS_FRAGMENT BIT(0) -#define FLOW_DIS_FIRST_FRAG BIT(1) -#define FLOW_DIS_ENCAPSULATION BIT(2) +/* The control flags are kept in sync with TCA_FLOWER_KEY_FLAGS_*, as those +* flags are exposed to userspace in some error paths, ie. unsupported flags. +*/ +enum flow_dissector_ctrl_flags { +FLOW_DIS_IS_FRAGMENT =TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT , +FLOW_DIS_FIRST_FRAG =TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST , + +/* These flags are internal to the kernel */ +FLOW_DIS_ENCAPSULATION = (TCA_FLOWER_KEY_FLAGS_MAX <<1 ), +};enum flow_dissect_ret {FLOW_DISSECT_RET_OUT_GOOD ,
include/uapi/linux/pkt_cls.h +3 -0
@@ -677,8 +677,11 @@ enum {enum {TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 <<0 ),TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 <<1 ), + __TCA_FLOWER_KEY_FLAGS_MAX, }; +#define TCA_FLOWER_KEY_FLAGS_MAX (__TCA_FLOWER_KEY_FLAGS_MAX - 1) +enum {TCA_FLOWER_KEY_CFM_OPT_UNSPEC ,TCA_FLOWER_KEY_CFM_MD_LEVEL ,
Signature · 1 line
2.45.2
Re: [PATCH net-next v2 01/10] net/sched: flower: refactor tunnel flag definitions
Quoted 1 line · Asbjørn Sloth Tønnesen
net/sched: flower: refactor tunnel flag definitions
Should have been: "net/sched: flower: refactor control flag definitions"
After the split, tunnel control flags are first introduced in the next patch.
I will properly do a new spin tomorrow.
Davide, I think David Ahern would be happy [1] if you could post a new iproute2 patch, since the kernel patches should preferably hit net-next this week (due to uAPI breakage).
[1] https://lore.kernel.org/[email protected]/
Signature · 1 line
pw-bot: changes-requested
Re: [PATCH net-next v2 01/10] net/sched: flower: refactor tunnel flag definitions
hello,
Quoted 1 line · Asbjørn Sloth Tønnesen
[...]
Quoted 2 lines
Davide, I think David Ahern would be happy [1] if you could post a new iproute2 patch, since the kernel patches should preferably hit net-next this week (due to uAPI breakage).
I will send an updated patch (don't use "matches" + add missing man page + rename keywords [1]) in the next hours.
thanks,
Signature · 3 lines
davide [1]
Quoted 1 line
Nit: I would prefix all of these with "
tun_".
"tun_" or just "tun" ? please note that each flag can have a "no" prefix, so is it better
notuncsum
notundf
notunoam
notuncrit
or
notun_csumnotun_dfnotun_oamnotun_crit
?
(I'm for not using the underscore - but I'm open to ideas: please let me know)
Re: [PATCH net-next v2 01/10] net/sched: flower: refactor tunnel flag definitions
Hi Davide,
Quoted 7 lines · Davide Caratti
On Mon, Jul 8, 2024 at 1:12 PM Asbjørn Sloth Tønnesen<[email protected]> wrote:
[...]Quoted 2 lines
Davide, I think David Ahern would be happy [1] if you could post a new iproute2 patch, since the kernel patches should preferably hit net-next this week (due to uAPI breakage).
I will send an updated patch (don't use "matches" + add missing man page + rename keywords [1]) in the next hours.
Great.
Quoted 11 lines
Quoted 1 line
Nit: I would prefix all of these with "
tun_"."
tun_" or just "tun" ? please note that each flag can have a "no" prefix, so is it betternotuncsum
notundf
notunoam
notuncritor
Quoted 8 lines
notun_csumnotun_dfnotun_oamnotun_crit?
(I'm for not using the underscore - but I'm open to ideas: please let me know)
I'm fine with no underscores, alternatively recognizing both "no" and "no_" prefixes.
Signature · 4 lines
Best regards Asbjørn Sloth Tønnesen Network Engineer Fiberby - AS42541
PATCH v2 2/10 net/sched: flower: define new tunnel flags
In reply to Asbjørn Sloth TønnesenDefine new TCA_FLOWER_KEY_FLAGS_* flags for use in struct flow_dissector_key_control, covering the same flags as currently exposed through TCA_FLOWER_KEY_ENC_FLAGS.
Put the new flags under FLOW_DIS_F_*. The idea is that we can later, move the existing flags under FLOW_DIS_F_* as well.
--- include/net/flow_dissector.h | 7 ++++++- include/uapi/linux/pkt_cls.h | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-)
include/net/flow_dissector.h +6 -1
@@ -17,7 +17,8 @@ struct sk_buff;* struct flow_dissector_key_control: * @thoff: Transport header offset * @addr_type: Type of key. One of FLOW_DISSECTOR_KEY_* -* @flags: Key flags. Any of FLOW_DIS_(IS_FRAGMENT|FIRST_FRAGENCAPSULATION) +* @flags: Key flags. +* Any of FLOW_DIS_(IS_FRAGMENT|FIRST_FRAG|ENCAPSULATION|F_*) */ struct flow_dissector_key_control {u16 thoff;
@@ -31,6 +32,10 @@ struct flow_dissector_key_control {enum flow_dissector_ctrl_flags {FLOW_DIS_IS_FRAGMENT =TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT ,FLOW_DIS_FIRST_FRAG =TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST , +FLOW_DIS_F_TUNNEL_CSUM =TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM , +FLOW_DIS_F_TUNNEL_DONT_FRAGMENT =TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT , +FLOW_DIS_F_TUNNEL_OAM =TCA_FLOWER_KEY_FLAGS_TUNNEL_OAM , +FLOW_DIS_F_TUNNEL_CRIT_OPT =TCA_FLOWER_KEY_FLAGS_TUNNEL_CRIT_OPT ,/* These flags are internal to the kernel */ FLOW_DIS_ENCAPSULATION = (TCA_FLOWER_KEY_FLAGS_MAX <<1 ),
include/uapi/linux/pkt_cls.h +4 -0
@@ -677,6 +677,10 @@ enum {enum {TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 <<0 ),TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 <<1 ), +TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM = (1 <<2 ), +TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT = (1 <<3 ), +TCA_FLOWER_KEY_FLAGS_TUNNEL_OAM = (1 <<4 ), +TCA_FLOWER_KEY_FLAGS_TUNNEL_CRIT_OPT = (1 <<5 ), __TCA_FLOWER_KEY_FLAGS_MAX, };
Signature · 1 line
2.45.2
PATCH v2 3/10 net/sched: cls_flower: prepare fl_{set,dump}_key_flags() for ENC_FLAGS
In reply to Asbjørn Sloth TønnesenPrepare fl_set_key_flags/fl_dump_key_flags() for use with TCA_FLOWER_KEY_ENC_FLAGS{,_MASK}.
This patch adds an encap argument, similar to fl_set_key_ip/ fl_dump_key_ip(), and determine the flower keys based on the encap argument, and use them in the rest of the two functions.
Since these functions are so far, only called with encap set false, then there is no functional change.
--- net/sched/cls_flower.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-)
net/sched/cls_flower.c +30 -10
@@ -1166,19 +1166,28 @@ static void fl_set_key_flag(u32 flower_key, u32 flower_mask, } } -static int fl_set_key_flags (struct nlattr **tb,u32 *flags_key, +static int fl_set_key_flags (struct nlattr **tb,bool encap,u32 *flags_key,u32 *flags_mask,struct netlink_ext_ack *extack) { +int fl_key, fl_mask;u32 key, mask; +if (encap) { + fl_key =TCA_FLOWER_KEY_ENC_FLAGS ; + fl_mask =TCA_FLOWER_KEY_ENC_FLAGS_MASK ; + }else { + fl_key =TCA_FLOWER_KEY_FLAGS ; + fl_mask =TCA_FLOWER_KEY_FLAGS_MASK ; + } +/* mask is mandatory for flags */ -if (!tb[TCA_FLOWER_KEY_FLAGS_MASK ]) { +if (NL_REQ_ATTR_CHECK (extack,NULL , tb, fl_mask)) {NL_SET_ERR_MSG (extack,"Missing flags mask" );return -EINVAL ; } - key =be32_to_cpu (nla_get_be32 (tb[TCA_FLOWER_KEY_FLAGS ])); - mask =be32_to_cpu (nla_get_be32 (tb[TCA_FLOWER_KEY_FLAGS_MASK ])); + key =be32_to_cpu (nla_get_be32 (tb[fl_key])); + mask =be32_to_cpu (nla_get_be32 (tb[fl_mask])); *flags_key =0 ; *flags_mask =0 ;
@@ -2086,7 +2095,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb,return ret;if (tb[TCA_FLOWER_KEY_FLAGS ]) { - ret =fl_set_key_flags (tb, &key->control.flags, + ret =fl_set_key_flags (tb, false, &key->control.flags, &mask->control.flags, extack);if (ret)return ret;
@@ -3084,12 +3093,22 @@ static void fl_get_key_flag(u32 dissector_key, u32 dissector_mask, } } -static int fl_dump_key_flags (struct sk_buff *skb,u32 flags_key,u32 flags_mask) +static int fl_dump_key_flags (struct sk_buff *skb,bool encap, +u32 flags_key,u32 flags_mask) { -u32 key, mask; +int fl_key, fl_mask;__be32 _key, _mask; +u32 key, mask;int err; +if (encap) { + fl_key =TCA_FLOWER_KEY_ENC_FLAGS ; + fl_mask =TCA_FLOWER_KEY_ENC_FLAGS_MASK ; + }else { + fl_key =TCA_FLOWER_KEY_FLAGS ; + fl_mask =TCA_FLOWER_KEY_FLAGS_MASK ; + } +if (!memchr_inv (&flags_mask,0 ,sizeof (flags_mask)))return 0 ;
@@ -3105,11 +3124,11 @@ static int fl_dump_key_flags(struct sk_buff *skb, u32 flags_key, u32 flags_mask) _key =cpu_to_be32 (key); _mask =cpu_to_be32 (mask); - err =nla_put (skb,TCA_FLOWER_KEY_FLAGS ,4 , &_key); + err =nla_put (skb, fl_key,4 , &_key);if (err)return err; -return nla_put (skb,TCA_FLOWER_KEY_FLAGS_MASK ,4 , &_mask); +return nla_put (skb, fl_mask,4 , &_mask); } static int fl_dump_key_geneve_opt(struct sk_buff *skb,
@@ -3632,7 +3651,8 @@ static int fl_dump_key(struct sk_buff *skb, struct net *net,if (fl_dump_key_ct (skb, &key->ct, &mask->ct)) goto nla_put_failure; -if (fl_dump_key_flags (skb, key->control.flags, mask->control.flags)) +if (fl_dump_key_flags (skb, false, key->control.flags, + mask->control.flags)) goto nla_put_failure; if (fl_dump_key_val(skb, &key->hash.hash, TCA_FLOWER_KEY_HASH,
Signature · 1 line
2.45.2
PATCH v2 4/10 net/sched: cls_flower: add policy for TCA_FLOWER_KEY_FLAGS
In reply to Asbjørn Sloth TønnesenThis policy guards fl_set_key_flags() from seeing flags not used in the context of TCA_FLOWER_KEY_FLAGS.
In order For the policy check to be performed with the correct endianness, then we also needs to change the attribute type to NLA_BE32 (Thanks Davide).
TCA_FLOWER_KEY_FLAGS{,_MASK} already has a be32 comment in include/uapi/linux/pkt_cls.h.
--- net/sched/cls_flower.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/sched/cls_flower.c +8 -2
@@ -41,6 +41,10 @@#define TCA_FLOWER_KEY_CT_FLAGS_MASK \ (TCA_FLOWER_KEY_CT_FLAGS_MAX - 1) +#define TCA_FLOWER_KEY_FLAGS_POLICY_MASK \ + (TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT | \ + TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST) +#define TUNNEL_FLAGS_PRESENT (\ _BITUL(IP_TUNNEL_CSUM_BIT) | \ _BITUL(IP_TUNNEL_DONT_FRAGMENT_BIT) | \
@@ -676,8 +680,10 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = { [TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK] = { .type = NLA_U16 }, [TCA_FLOWER_KEY_ENC_UDP_DST_PORT] = { .type = NLA_U16 }, [TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK] = { .type = NLA_U16 }, - [TCA_FLOWER_KEY_FLAGS] = { .type = NLA_U32 }, - [TCA_FLOWER_KEY_FLAGS_MASK] = { .type = NLA_U32 }, + [TCA_FLOWER_KEY_FLAGS ] =NLA_POLICY_MASK (NLA_BE32 , + TCA_FLOWER_KEY_FLAGS_POLICY_MASK), + [TCA_FLOWER_KEY_FLAGS_MASK ] =NLA_POLICY_MASK (NLA_BE32 , + TCA_FLOWER_KEY_FLAGS_POLICY_MASK), [TCA_FLOWER_KEY_ICMPV4_TYPE] = { .type = NLA_U8 }, [TCA_FLOWER_KEY_ICMPV4_TYPE_MASK] = { .type = NLA_U8 }, [TCA_FLOWER_KEY_ICMPV4_CODE] = { .type = NLA_U8 },
Signature · 1 line
2.45.2
PATCH v2 5/10 flow_dissector: prepare for encapsulated control flags
In reply to Asbjørn Sloth TønnesenRename skb_flow_dissect_set_enc_addr_type() to skb_flow_dissect_set_enc_control(), and make it set both addr_type and flags in FLOW_DISSECTOR_KEY_ENC_CONTROL.
--- net/core/flow_dissector.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
net/core/flow_dissector.c +12 -9
@@ -299,9 +299,10 @@ void skb_flow_dissect_meta(const struct sk_buff *skb,EXPORT_SYMBOL (skb_flow_dissect_meta);static void -skb_flow_dissect_set_enc_addr_type (enum flow_dissector_key_id type, -struct flow_dissector *flow_dissector, -void *target_container) +skb_flow_dissect_set_enc_control (enum flow_dissector_key_id type, +u32 ctrl_flags, +struct flow_dissector *flow_dissector, +void *target_container) {struct flow_dissector_key_control *ctrl;
@@ -312,6 +313,7 @@ skb_flow_dissect_set_enc_addr_type(enum flow_dissector_key_id type,FLOW_DISSECTOR_KEY_ENC_CONTROL , target_container); ctrl->addr_type = type; + ctrl->flags = ctrl_flags; }void
@@ -367,6 +369,7 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb, { struct ip_tunnel_info *info; struct ip_tunnel_key *key; + u32 ctrl_flags = 0; /* A quick check to see if there might be something to do. */ if (!dissector_uses_key(flow_dissector,
@@ -395,9 +398,9 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb,switch (ip_tunnel_info_af (info)) {case AF_INET : -skb_flow_dissect_set_enc_addr_type (FLOW_DISSECTOR_KEY_IPV4_ADDRS , - flow_dissector, - target_container); +skb_flow_dissect_set_enc_control (FLOW_DISSECTOR_KEY_IPV4_ADDRS , + ctrl_flags, flow_dissector, + target_container);if (dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS )) {struct flow_dissector_key_ipv4_addrs *ipv4;
@@ -410,9 +413,9 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb, }break ;case AF_INET6 : -skb_flow_dissect_set_enc_addr_type (FLOW_DISSECTOR_KEY_IPV6_ADDRS , - flow_dissector, - target_container); +skb_flow_dissect_set_enc_control (FLOW_DISSECTOR_KEY_IPV6_ADDRS , + ctrl_flags, flow_dissector, + target_container);if (dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS )) {struct flow_dissector_key_ipv6_addrs *ipv6;
Signature · 1 line
2.45.2
PATCH v2 6/10 flow_dissector: set encapsulated control flags from tun_flags
In reply to Asbjørn Sloth TønnesenSet the new FLOW_DIS_F_TUNNEL_* encapsulated control flags, based on if their counter-part is set in tun_flags.
These flags are not userspace visible yet, as the code to dump encapsulated control flags will first be added, and later activated in the following patches.
--- net/core/flow_dissector.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/core/flow_dissector.c +9 -0
@@ -396,6 +396,15 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb, key = &info->key; +if (test_bit (IP_TUNNEL_CSUM_BIT , key->tun_flags)) + ctrl_flags |=FLOW_DIS_F_TUNNEL_CSUM ; +if (test_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , key->tun_flags)) + ctrl_flags |=FLOW_DIS_F_TUNNEL_DONT_FRAGMENT ; +if (test_bit (IP_TUNNEL_OAM_BIT , key->tun_flags)) + ctrl_flags |=FLOW_DIS_F_TUNNEL_OAM ; +if (test_bit (IP_TUNNEL_CRIT_OPT_BIT , key->tun_flags)) + ctrl_flags |=FLOW_DIS_F_TUNNEL_CRIT_OPT ; +switch (ip_tunnel_info_af (info)) {case AF_INET : skb_flow_dissect_set_enc_control(FLOW_DISSECTOR_KEY_IPV4_ADDRS,
Signature · 1 line
2.45.2
PATCH v2 7/10 net/sched: cls_flower: add tunnel flags to fl_{set,dump}_key_flags()
In reply to Asbjørn Sloth TønnesenPrepare to set and dump the tunnel flags.
This code won't see any of these flags yet, as these flags aren't allowed by the NLA_POLICY_MASK, and the functions doesn't get called with encap set to true yet.
--- net/sched/cls_flower.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
net/sched/cls_flower.c +30 -0
@@ -1204,6 +1204,21 @@ static int fl_set_key_flags(struct nlattr **tb, bool encap, u32 *flags_key,TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST , FLOW_DIS_FIRST_FRAG); +fl_set_key_flag (key, mask, flags_key, flags_mask, +TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM , +FLOW_DIS_F_TUNNEL_CSUM ); + +fl_set_key_flag (key, mask, flags_key, flags_mask, +TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT , +FLOW_DIS_F_TUNNEL_DONT_FRAGMENT ); + +fl_set_key_flag (key, mask, flags_key, flags_mask, +TCA_FLOWER_KEY_FLAGS_TUNNEL_OAM ,FLOW_DIS_F_TUNNEL_OAM ); + +fl_set_key_flag (key, mask, flags_key, flags_mask, +TCA_FLOWER_KEY_FLAGS_TUNNEL_CRIT_OPT , +FLOW_DIS_F_TUNNEL_CRIT_OPT ); +return 0 ; }
@@ -3127,6 +3142,21 @@ static int fl_dump_key_flags(struct sk_buff *skb, bool encap,TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST , FLOW_DIS_FIRST_FRAG); +fl_get_key_flag (flags_key, flags_mask, &key, &mask, +TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM , +FLOW_DIS_F_TUNNEL_CSUM ); + +fl_get_key_flag (flags_key, flags_mask, &key, &mask, +TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT , +FLOW_DIS_F_TUNNEL_DONT_FRAGMENT ); + +fl_get_key_flag (flags_key, flags_mask, &key, &mask, +TCA_FLOWER_KEY_FLAGS_TUNNEL_OAM ,FLOW_DIS_F_TUNNEL_OAM ); + +fl_get_key_flag (flags_key, flags_mask, &key, &mask, +TCA_FLOWER_KEY_FLAGS_TUNNEL_CRIT_OPT , +FLOW_DIS_F_TUNNEL_CRIT_OPT ); + _key =cpu_to_be32 (key); _mask =cpu_to_be32 (mask);
Signature · 1 line
2.45.2
PATCH v2 8/10 net/sched: cls_flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage
In reply to Asbjørn Sloth TønnesenThis patch changes how TCA_FLOWER_KEY_ENC_FLAGS is used, so that it is used with TCA_FLOWER_KEY_FLAGS_* flags, in the same way as TCA_FLOWER_KEY_FLAGS is currently used.
Where TCA_FLOWER_KEY_FLAGS uses {key,mask}->control.flags, then TCA_FLOWER_KEY_ENC_FLAGS now uses {key,mask}->enc_control.flags, therefore {key,mask}->enc_flags is now unused.
As the generic fl_set_key_flags/fl_dump_key_flags() is used with encap set to true, then fl_{set,dump}_key_enc_flags() is removed.
This breaks unreleased userspace API (net-next since 2024-06-04).
--- include/uapi/linux/pkt_cls.h | 4 +-- net/sched/cls_flower.c | 56 +++++++++--------------------------- 2 files changed, 15 insertions(+), 45 deletions(-)
include/uapi/linux/pkt_cls.h +2 -2
@@ -554,8 +554,8 @@ enum {TCA_FLOWER_KEY_SPI ,/* be32 */ TCA_FLOWER_KEY_SPI_MASK ,/* be32 */ -TCA_FLOWER_KEY_ENC_FLAGS ,/* u32 */ -TCA_FLOWER_KEY_ENC_FLAGS_MASK ,/* u32 */ +TCA_FLOWER_KEY_ENC_FLAGS ,/* be32 */ +TCA_FLOWER_KEY_ENC_FLAGS_MASK ,/* be32 */ __TCA_FLOWER_MAX, };
net/sched/cls_flower.c +13 -43
92 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v2 9/10 flow_dissector: cleanup FLOW_DISSECTOR_KEY_ENC_FLAGS
In reply to Asbjørn Sloth TønnesenNow that TCA_FLOWER_KEY_ENC_FLAGS is unused, as it's former data is stored behind TCA_FLOWER_KEY_ENC_CONTROL, then remove the last bits of FLOW_DISSECTOR_KEY_ENC_FLAGS.
FLOW_DISSECTOR_KEY_ENC_FLAGS is unreleased, and have been in net-next since 2024-06-04.
--- include/net/flow_dissector.h | 9 --------- include/net/ip_tunnels.h | 12 ------------ net/core/flow_dissector.c | 16 +--------------- net/sched/cls_flower.c | 3 --- 4 files changed, 1 insertion(+), 39 deletions(-)
include/net/flow_dissector.h +0 -9
@@ -342,14 +342,6 @@ struct flow_dissector_key_cfm {#define FLOW_DIS_CFM_MDL_MASK GENMASK(7, 5)#define FLOW_DIS_CFM_MDL_MAX 7 -/** -* struct flow_dissector_key_enc_flags: tunnel metadata control flags -* @flags: tunnel control flags -*/ -struct flow_dissector_key_enc_flags { -u32 flags; -}; -enum flow_dissector_key_id {FLOW_DISSECTOR_KEY_CONTROL ,/* struct flow_dissector_key_control */ FLOW_DISSECTOR_KEY_BASIC ,/* struct flow_dissector_key_basic */
@@ -384,7 +376,6 @@ enum flow_dissector_key_id {FLOW_DISSECTOR_KEY_L2TPV3 ,/* struct flow_dissector_key_l2tpv3 */ FLOW_DISSECTOR_KEY_CFM ,/* struct flow_dissector_key_cfm */ FLOW_DISSECTOR_KEY_IPSEC ,/* struct flow_dissector_key_ipsec */ -FLOW_DISSECTOR_KEY_ENC_FLAGS ,/* struct flow_dissector_key_enc_flags */ FLOW_DISSECTOR_KEY_MAX, };
include/net/ip_tunnels.h +0 -12
@@ -247,18 +247,6 @@ static inline bool ip_tunnel_is_options_present(const unsigned long *flags)return ip_tunnel_flags_intersect (flags, present); } -static inline void ip_tunnel_set_encflags_present (unsigned long *flags) -{ -IP_TUNNEL_DECLARE_FLAGS (present) = { }; - -__set_bit (IP_TUNNEL_CSUM_BIT , present); -__set_bit (IP_TUNNEL_DONT_FRAGMENT_BIT , present); -__set_bit (IP_TUNNEL_OAM_BIT , present); -__set_bit (IP_TUNNEL_CRIT_OPT_BIT , present); - -ip_tunnel_flags_or (flags, flags, present); -} -static inline bool ip_tunnel_flags_is_be16_compat (const unsigned long *flags) {IP_TUNNEL_DECLARE_FLAGS (supp) = { };
net/core/flow_dissector.c +1 -15
@@ -385,9 +385,7 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb, !dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ENC_IP ) && !dissector_uses_key (flow_dissector, -FLOW_DISSECTOR_KEY_ENC_OPTS ) && - !dissector_uses_key (flow_dissector, - FLOW_DISSECTOR_KEY_ENC_FLAGS)) + FLOW_DISSECTOR_KEY_ENC_OPTS)) return; info =skb_tunnel_info (skb);
@@ -489,18 +487,6 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb, IP_TUNNEL_GENEVE_OPT_BIT); enc_opt->dst_opt_type = val < __IP_TUNNEL_FLAG_NUM ? val :0 ; } - -if (dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ENC_FLAGS )) { -struct flow_dissector_key_enc_flags *enc_flags; -IP_TUNNEL_DECLARE_FLAGS (flags) = {}; - - enc_flags =skb_flow_dissector_target (flow_dissector, -FLOW_DISSECTOR_KEY_ENC_FLAGS , - target_container); -ip_tunnel_set_encflags_present (flags); -ip_tunnel_flags_and (flags, flags, info->key.tun_flags); - enc_flags->flags =bitmap_read (flags,IP_TUNNEL_CSUM_BIT ,32 ); - } }EXPORT_SYMBOL (skb_flow_dissect_tunnel_info);
net/sched/cls_flower.c +0 -3
@@ -85,7 +85,6 @@ struct fl_flow_key {struct flow_dissector_key_l2tpv3 l2tpv3;struct flow_dissector_key_ipsec ipsec;struct flow_dissector_key_cfm cfm; -struct flow_dissector_key_enc_flags enc_flags; }__aligned(BITS_PER_LONG / 8) ;/* Ensure that we can do comparisons as longs. */ struct fl_flow_mask_range {
@@ -2223,8 +2222,6 @@ static void fl_init_dissector(struct flow_dissector *dissector, FLOW_DISSECTOR_KEY_IPSEC, ipsec);FL_KEY_SET_IF_MASKED (mask, keys, cnt,FLOW_DISSECTOR_KEY_CFM , cfm); -FL_KEY_SET_IF_MASKED (mask, keys, cnt, -FLOW_DISSECTOR_KEY_ENC_FLAGS , enc_flags);skb_flow_dissector_init (dissector, keys, cnt); }
Signature · 1 line
2.45.2
PATCH v2 10/10 flow_dissector: set encapsulation control flags for non-IP
In reply to Asbjørn Sloth TønnesenMake sure to set encapsulated control flags also for non-IP packets, such that it's possible to allow matching on e.g. TUNNEL_OAM on a geneve packet carrying a non-IP packet.
--- net/core/flow_dissector.c | 4 ++++ net/sched/cls_flower.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
net/core/flow_dissector.c +4 -0
@@ -434,6 +434,10 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb, ipv6->dst = key->u.ipv6.dst; }break ; +default : +skb_flow_dissect_set_enc_control (0 , ctrl_flags, flow_dissector, + target_container); +break ; }if (dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ENC_KEYID )) {
net/sched/cls_flower.c +2 -1
@@ -2199,7 +2199,8 @@ static void fl_init_dissector(struct flow_dissector *dissector,FL_KEY_SET_IF_MASKED (mask, keys, cnt,FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS , enc_ipv6);if (FL_KEY_IS_MASKED (mask, enc_ipv4) || -FL_KEY_IS_MASKED (mask, enc_ipv6)) +FL_KEY_IS_MASKED (mask, enc_ipv6) || +FL_KEY_IS_MASKED (mask, enc_control))FL_KEY_SET (keys, cnt,FLOW_DISSECTOR_KEY_ENC_CONTROL , enc_control); FL_KEY_SET_IF_MASKED(mask, keys, cnt,
Signature · 1 line
2.45.2