flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage
Subsystems (5)
v4 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 v2 patch:
https://lore.kernel.org/560bcd549ca8ab24b1ad5abe352580a621f6d426.1720790774.git.dcaratti@redhat.com/
---
Changelog:
v4:
- Define control flags in ynl
- Describe enc-flags in ynl
- Propagate tca[TCA_OPTIONS] to NL_REQ_ATTR_CHECK
(all 3 requested by Jakub)
- Link to new iproute2 patch in cover
- Add Reviewed-By from Davide to patches that haven't changed since v3.
v3: https://lore.kernel.org/[email protected]/
- Retitle patch 1 (tunnel flags -> control flags)
v2: https://lore.kernel.org/[email protected]/
- 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 (13):
net/sched: flower: refactor control flag definitions
doc: netlink: specs: tc: describe flower control flags 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
doc: netlink: specs: tc: flower: add enc-flags
flow_dissector: cleanup FLOW_DISSECTOR_KEY_ENC_FLAGS
flow_dissector: set encapsulation control flags for non-IP net/sched: cls_flower: propagate tca[TCA_OPTIONS] to NL_REQ_ATTR_CHECK
Documentation/netlink/specs/tc.yaml | 26 +++++ 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 | 168 ++++++++++++++++------------ 6 files changed, 177 insertions(+), 120 deletions(-)
Signature · 1 line
2.45.2
PATCH v4 1/13 net/sched: flower: refactor control 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
PATCH v4 2/13 doc: netlink: specs: tc: describe flower control flags
In reply to Asbjørn Sloth TønnesenDescribe the flower control flags, and use them
for key-flags and key-flags-mask.
The flag names have been taken from iproute2.
--- Documentation/netlink/specs/tc.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/netlink/specs/tc.yaml +10 -0
@@ -41,6 +41,12 @@ definitions: - in-hw - not-in-nw - verbose + - + name: tc-flower-key-ctrl-flags + type: flags + entries: + - frag + - firstfrag - name: tc-stats type: struct
@@ -2536,10 +2542,14 @@ attribute-sets: name: key-flags type: u32 byte-order: big-endian + enum: tc-flower-key-ctrl-flags + enum-as-flags: true - name: key-flags-mask type: u32 byte-order: big-endian + enum: tc-flower-key-ctrl-flags + enum-as-flags: true - name: key-icmpv4-code type: u8
Signature · 1 line
2.45.2
Re: [PATCH net-next v4 02/13] doc: netlink: specs: tc: describe flower control flags
Quoted 8 lines · Asbjørn Sloth Tønnesen
Describe the flower control flags, and use them
for key-flags and key-flags-mask.The flag names have been taken from iproute2.
Suggested-by Jakub Kicinski <[email protected]>Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>
PATCH v4 3/13 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.
The ynl flag names have been taken from the RFC iproute2 patch.
--- Documentation/netlink/specs/tc.yaml | 4 ++++ include/net/flow_dissector.h | 7 ++++++- include/uapi/linux/pkt_cls.h | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-)
Documentation/netlink/specs/tc.yaml +4 -0
@@ -47,6 +47,10 @@ definitions: entries: - frag - firstfrag + - tuncsum + - tundf + - tunoam + - tuncrit - name: tc-stats type: struct
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
Re: [PATCH net-next v4 03/13] net/sched: flower: define new tunnel flags
Quoted 11 lines · Asbjørn Sloth Tønnesen
Define new TCA_FLOWER_KEY_FLAGS_* flags for use in struct
flow_dissector_key_control, covering the same flags as currently exposed throughTCA_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.
The ynl flag names have been taken from the RFC iproute2 patch.
Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>
PATCH v4 4/13 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 v4 5/13 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 v4 6/13 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 v4 7/13 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 v4 8/13 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 v4 9/13 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 v4 10/13 doc: netlink: specs: tc: flower: add enc-flags
In reply to Asbjørn Sloth TønnesenDescribe key-enc-flags and key-enc-flags-mask.
These are defined similarly to key-flags and key-flags-mask.
--- Documentation/netlink/specs/tc.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Documentation/netlink/specs/tc.yaml +12 -0
@@ -2763,6 +2763,18 @@ attribute-sets: name: key-spi-mask type: u32 byte-order: big-endian + - + name: key-enc-flags + type: u32 + byte-order: big-endian + enum: tc-flower-key-ctrl-flags + enum-as-flags: true + - + name: key-enc-flags-mask + type: u32 + byte-order: big-endian + enum: tc-flower-key-ctrl-flags + enum-as-flags: true - name: tc-flower-key-enc-opts-attrs attributes:
Signature · 1 line
2.45.2
Re: [PATCH net-next v4 10/13] doc: netlink: specs: tc: flower: add enc-flags
Quoted 7 lines · Asbjørn Sloth Tønnesen
Describe key-enc-flags and key-enc-flags-mask.
These are defined similarly to key-flags and key-flags-mask.
Suggested-by Jakub Kicinski <[email protected]>Signed-off-by Asbjørn Sloth Tønnesen <[email protected]>
PATCH v4 11/13 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 v4 12/13 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
PATCH v4 13/13 net/sched: cls_flower: propagate tca[TCA_OPTIONS] to NL_REQ_ATTR_CHECK
In reply to Asbjørn Sloth TønnesenNL_REQ_ATTR_CHECK() is used in fl_set_key_flags() to set extended attributes about the origin of an error, this patch propagates tca[TCA_OPTIONS] through.
Before this patch:
$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/tc.yaml \
--do newtfilter --json '{
"chain": 0, "family": 0, "handle": 4, "ifindex": 22,
"info": 262152,
"kind": "flower",
"options": {
"flags": 0, "key-enc-flags": 8,
"key-eth-type": 2048 },
"parent": 4294967283 }'
Netlink error: Invalid argument
nl_len = 68 (52) nl_flags = 0x300 nl_type = 2
error: -22
extack: {'msg': 'Missing flags mask',
'miss-type': 111}After this patch:
[same cmd]
Netlink error: Invalid argumentnl_len = 76 (60) nl_flags = 0x300 nl_type = 2
error: -22
extack: {'msg': 'Missing flags mask',
'miss-type': 111, 'miss-nest': 56}--- net/sched/cls_flower.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
net/sched/cls_flower.c +20 -14
@@ -1171,8 +1171,9 @@ static void fl_set_key_flag(u32 flower_key, u32 flower_mask, } } -static int fl_set_key_flags (struct nlattr **tb,bool encap,u32 *flags_key, -u32 *flags_mask,struct netlink_ext_ack *extack) +static int fl_set_key_flags (struct nlattr *tca_opts,struct nlattr **tb, +bool encap,u32 *flags_key,u32 *flags_mask, +struct netlink_ext_ack *extack) {int fl_key, fl_mask;u32 key, mask;
@@ -1186,7 +1187,7 @@ static int fl_set_key_flags(struct nlattr **tb, bool encap, u32 *flags_key, }/* mask is mandatory for flags */ -if (NL_REQ_ATTR_CHECK (extack,NULL , tb, fl_mask)) { +if (NL_REQ_ATTR_CHECK (extack, tca_opts, tb, fl_mask)) {NL_SET_ERR_MSG (extack,"Missing flags mask" );return -EINVAL ; }
@@ -1865,9 +1866,9 @@ static int fl_set_key_cfm(struct nlattr **tb,return 0 ; } -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) +static int fl_set_key (struct net *net,struct nlattr *tca_opts, +struct nlattr **tb,struct fl_flow_key *key, +struct fl_flow_key *mask,struct netlink_ext_ack *extack) {__be16 ethertype;int ret =0 ;
@@ -2100,14 +2101,16 @@ 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, false, &key->control.flags, + ret =fl_set_key_flags (tca_opts, tb, false, + &key->control.flags, &mask->control.flags, extack);if (ret)return ret; }if (tb[TCA_FLOWER_KEY_ENC_FLAGS ]) - ret =fl_set_key_flags (tb, true, &key->enc_control.flags, + ret =fl_set_key_flags (tca_opts, tb, true, + &key->enc_control.flags, &mask->enc_control.flags, extack);return ret;
@@ -2358,6 +2361,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, {struct cls_fl_head *head =fl_head_dereference (tp);bool rtnl_held = !(flags &TCA_ACT_FLAGS_NO_RTNL ); +struct nlattr *tca_opts = tca[TCA_OPTIONS ];struct cls_fl_filter *fold = *arg;bool bound_to_filter = false;struct cls_fl_filter *fnew;
@@ -2366,7 +2370,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,bool in_ht;int err; -if (!tca[TCA_OPTIONS ]) { +if (!tca_opts) { err = -EINVAL ; goto errout_fold; }
@@ -2384,7 +2388,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, } err =nla_parse_nested_deprecated (tb,TCA_FLOWER_MAX , - tca[TCA_OPTIONS ], fl_policy,NULL ); + tca_opts, fl_policy,NULL );if (err <0 ) goto errout_tb;
@@ -2460,7 +2464,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, bound_to_filter = true; } - err =fl_set_key (net, tb, &fnew->key, &mask->key, extack); + err =fl_set_key (net, tca_opts, tb, &fnew->key, &mask->key, extack);if (err) goto unbind_filter;
@@ -2800,18 +2804,19 @@ static void *fl_tmplt_create(struct net *net, struct tcf_chain *chain,struct nlattr **tca, struct netlink_ext_ack *extack) { + struct nlattr *tca_opts = tca[TCA_OPTIONS];struct fl_flow_tmplt *tmplt;struct nlattr **tb;int err; -if (!tca[TCA_OPTIONS ]) +if (!tca_opts)return ERR_PTR (-EINVAL ); tb =kcalloc (TCA_FLOWER_MAX +1 ,sizeof (struct nlattr *),GFP_KERNEL );if (!tb)return ERR_PTR (-ENOBUFS ); err =nla_parse_nested_deprecated (tb,TCA_FLOWER_MAX , - tca[TCA_OPTIONS ], fl_policy,NULL ); + tca_opts, fl_policy,NULL );if (err) goto errout_tb;
@@ -2821,7 +2826,8 @@ static void *fl_tmplt_create(struct net *net, struct tcf_chain *chain, goto errout_tb; } tmplt->chain = chain; - err =fl_set_key (net, tb, &tmplt->dummy_key, &tmplt->mask, extack); + err =fl_set_key (net, tca_opts, tb, &tmplt->dummy_key, + &tmplt->mask, extack);if (err) goto errout_tmplt;
Signature · 1 line
2.45.2
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Sat, 13 Jul 2024 02:18:57 +0000 you wrote:
This series reworks the recently added
TCA_FLOWER_KEY_ENC_FLAGSattribute, to be more likeTCA_FLOWER_KEY_FLAGS, and use the unused u32 flags field inFLOW_DISSECTOR_KEY_ENC_CONTROL, instead of adding a new flags field asFLOW_DISSECTOR_KEY_ENC_FLAGS.
Quoted 8 lines
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_controlis 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.[...]
Here is the summary with links:
- [net-next,v4,01/13] net/sched: flower: refactor control flag definitions
https://git.kernel.org/netdev/net-next/c/6e5c85c003e4 - [net-next,v4,02/13] doc: netlink: specs: tc: describe flower control flags https://git.kernel.org/netdev/net-next/c/49ba9fc1c773 - [net-next,v4,03/13] net/sched: flower: define new tunnel flags https://git.kernel.org/netdev/net-next/c/bfda5a63137b - [net-next,v4,04/13] net/sched: cls_flower: prepare fl_{set,dump}_key_flags() for ENC_FLAGS https://git.kernel.org/netdev/net-next/c/fcb4bb07a927 - [net-next,v4,05/13] net/sched: cls_flower: add policy for TCA_FLOWER_KEY_FLAGS https://git.kernel.org/netdev/net-next/c/0e83a7875d69 - [net-next,v4,06/13] flow_dissector: prepare for encapsulated control flags https://git.kernel.org/netdev/net-next/c/4d0aed380f9d - [net-next,v4,07/13] flow_dissector: set encapsulated control flags from tun_flags https://git.kernel.org/netdev/net-next/c/03afeb613bfe - [net-next,v4,08/13] net/sched: cls_flower: add tunnel flags to fl_{set,dump}_key_flags() https://git.kernel.org/netdev/net-next/c/988f8723d398 - [net-next,v4,09/13] net/sched: cls_flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage https://git.kernel.org/netdev/net-next/c/11036bd7a0b3 - [net-next,v4,10/13] doc: netlink: specs: tc: flower: add enc-flags https://git.kernel.org/netdev/net-next/c/880a51a8ab8c - [net-next,v4,11/13] flow_dissector: cleanup FLOW_DISSECTOR_KEY_ENC_FLAGS https://git.kernel.org/netdev/net-next/c/db5271d50ec1 - [net-next,v4,12/13] flow_dissector: set encapsulation control flags for non-IP https://git.kernel.org/netdev/net-next/c/706bf4f44c6d - [net-next,v4,13/13] net/sched: cls_flower: propagate tca[TCA_OPTIONS] to NL_REQ_ATTR_CHECK https://git.kernel.org/netdev/net-next/c/536b97acddd7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html