mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>
To: netdev@vger.kernel.org
Cc: "Asbjørn Sloth Tønnesen" <ast@fiberby.net>,
	"Davide Caratti" <dcaratti@redhat.com>,
	"Ilya Maximets" <i.maximets@ovn.org>,
	"Jamal Hadi Salim" <jhs@mojatatu.com>,
	"Cong Wang" <xiyou.wangcong@gmail.com>,
	"Jiri Pirko" <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"David Ahern" <dsahern@kernel.org>,
	"Simon Horman" <horms@kernel.org>,
	"Ratheesh Kannoth" <rkannoth@marvell.com>,
	"Florian Westphal" <fw@strlen.de>,
	"Alexander Lobakin" <aleksander.lobakin@intel.com>,
	"Donald Hunter" <donald.hunter@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next v4 13/13] net/sched: cls_flower: propagate tca[TCA_OPTIONS] to NL_REQ_ATTR_CHECK
Date: Sat, 13 Jul 2024 02:19:10 +0000	[thread overview]
Message-ID: <20240713021911.1631517-14-ast@fiberby.net> (raw)
In-Reply-To: <20240713021911.1631517-1-ast@fiberby.net>

NL_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 argument
nl_len = 76 (60) nl_flags = 0x300 nl_type = 2
        error: -22
        extack: {'msg': 'Missing flags mask',
                 'miss-type': 111, 'miss-nest': 56}

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
 net/sched/cls_flower.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 38b2df387c1e1..e280c27cb9f9a 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -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;
 
-- 
2.45.2


  parent reply	other threads:[~2024-07-13  2:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-13  2:18 [PATCH net-next v4 00/13] flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage Asbjørn Sloth Tønnesen
2024-07-13  2:18 ` [PATCH net-next v4 01/13] net/sched: flower: refactor control flag definitions Asbjørn Sloth Tønnesen
2024-07-13  2:18 ` [PATCH net-next v4 02/13] doc: netlink: specs: tc: describe flower control flags Asbjørn Sloth Tønnesen
2024-07-13 13:16   ` Donald Hunter
2024-07-13  2:19 ` [PATCH net-next v4 03/13] net/sched: flower: define new tunnel flags Asbjørn Sloth Tønnesen
2024-07-13 13:19   ` Donald Hunter
2024-07-13  2:19 ` [PATCH net-next v4 04/13] net/sched: cls_flower: prepare fl_{set,dump}_key_flags() for ENC_FLAGS Asbjørn Sloth Tønnesen
2024-07-13  2:19 ` [PATCH net-next v4 05/13] net/sched: cls_flower: add policy for TCA_FLOWER_KEY_FLAGS Asbjørn Sloth Tønnesen
2024-07-13  2:19 ` [PATCH net-next v4 06/13] flow_dissector: prepare for encapsulated control flags Asbjørn Sloth Tønnesen
2024-07-13  2:19 ` [PATCH net-next v4 07/13] flow_dissector: set encapsulated control flags from tun_flags Asbjørn Sloth Tønnesen
2024-07-13  2:19 ` [PATCH net-next v4 08/13] net/sched: cls_flower: add tunnel flags to fl_{set,dump}_key_flags() Asbjørn Sloth Tønnesen
2024-07-13  2:19 ` [PATCH net-next v4 09/13] net/sched: cls_flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage Asbjørn Sloth Tønnesen
2024-07-13  2:19 ` [PATCH net-next v4 10/13] doc: netlink: specs: tc: flower: add enc-flags Asbjørn Sloth Tønnesen
2024-07-13 13:21   ` Donald Hunter
2024-07-13  2:19 ` [PATCH net-next v4 11/13] flow_dissector: cleanup FLOW_DISSECTOR_KEY_ENC_FLAGS Asbjørn Sloth Tønnesen
2024-07-13  2:19 ` [PATCH net-next v4 12/13] flow_dissector: set encapsulation control flags for non-IP Asbjørn Sloth Tønnesen
2024-07-13  2:19 ` Asbjørn Sloth Tønnesen [this message]
2024-07-15 16:40 ` [PATCH net-next v4 00/13] flower: rework TCA_FLOWER_KEY_ENC_FLAGS usage patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240713021911.1631517-14-ast@fiberby.net \
    --to=ast@fiberby.net \
    --cc=aleksander.lobakin@intel.com \
    --cc=davem@davemloft.net \
    --cc=dcaratti@redhat.com \
    --cc=donald.hunter@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=i.maximets@ovn.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rkannoth@marvell.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®