From: Wei Tao <taowei@kylinos.cn>
To: jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com
Cc: horms@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Wei Tao <taowei@kylinos.cn>
Subject: [PATCH net] net/sched: cls_fw: allow filter replace without re-specifying mask
Date: Wed, 14 Oct 2026 10:45:48 +0800 [thread overview]
Message-ID: <20261014024548.37874-1-taowei@kylinos.cn> (raw)
The fw classifier keeps the fwmark mask in the fw_head shared by all
filters of a tcf_proto instance, so the mask is a property of the head
and not of the individual filter: it is set when the head is created
and cannot be changed by a filter that is being replaced. Nevertheless
fw_set_parms() rejects such a replace with -EINVAL whenever the head
mask is not the default 0xFFFFFFFF and the mask is not repeated on the
command line:
# tc qdisc add dev lo clsact
# tc filter add dev lo ingress prio 1 handle 1/0xffff fw classid 1:10
# tc filter replace dev lo ingress prio 1 handle 1 fw classid 1:20
RTNETLINK answers: Invalid argument
The same happens for tc filter change, which calls fw_set_parms() on the
existing filter as well.
The check only makes sense for a newly created filter, where the mask
has to be spelled out so that a filter cannot silently match on a
non-default mask inherited from the existing head. A filter that is
being replaced already shares the head mask and inherits it unchanged,
so the check can be skipped for it.
Tell the two cases apart with a new "new_filter" argument to
fw_set_parms(), which fw_change() sets only when it creates a filter,
and report the error through extack instead of failing silently.
Fixes: b4e9b520ca5d ("[NET_SCHED]: Add mask support to fwmark classifier")
Signed-off-by: Wei Tao <taowei@kylinos.cn>
---
net/sched/cls_fw.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index a462b262719c..f1b648a11e7c 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -204,7 +204,8 @@ static const struct nla_policy fw_policy[TCA_FW_MAX + 1] = {
static int fw_set_parms(struct net *net, struct tcf_proto *tp,
struct fw_filter *f, struct nlattr **tb,
- struct nlattr **tca, unsigned long base, u32 flags,
+ struct nlattr **tca, unsigned long base,
+ bool new_filter, u32 flags,
struct netlink_ext_ack *extack)
{
struct fw_head *head = rtnl_dereference(tp->root);
@@ -229,8 +230,10 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,
mask = nla_get_u32(tb[TCA_FW_MASK]);
if (mask != head->mask)
return err;
- } else if (head->mask != 0xFFFFFFFF)
+ } else if (head->mask != 0xFFFFFFFF && new_filter) {
+ NL_SET_ERR_MSG(extack, "Mask must be provided for new filter");
return err;
+ }
if (tb[TCA_FW_CLASSID]) {
f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]);
@@ -291,7 +294,8 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
return err;
}
- err = fw_set_parms(net, tp, fnew, tb, tca, base, flags, extack);
+ err = fw_set_parms(net, tp, fnew, tb, tca, base, false,
+ flags, extack);
if (err < 0) {
tcf_exts_destroy(&fnew->exts);
kfree(fnew);
@@ -340,7 +344,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
f->id = handle;
f->tp = tp;
- err = fw_set_parms(net, tp, f, tb, tca, base, flags, extack);
+ err = fw_set_parms(net, tp, f, tb, tca, base, true, flags, extack);
if (err < 0)
goto errout;
--
2.33.0
next reply other threads:[~2026-10-14 2:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 2:45 Wei Tao [this message]
2026-10-14 2:50 ` [PATCH net] net/sched: cls_fw: allow filter replace without re-specifying mask netdev-bot+sinfo
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=20261014024548.37874-1-taowei@kylinos.cn \
--to=taowei@kylinos.cn \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.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 \
/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