🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #3023

[PATCH net] net/sched: cls_fw: allow filter replace without re-specifying mask

#3023
From: Wei Tao
Date: Wed, 14 Oct 2026 02:45
80 lines
8662 bytes
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
Technical Details
Message-ID: <20261014024548.37874-1-taowei@kylinos.cn>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345974-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345974-linux-kernel-netdev=dewy.ru
From: taowei@kylinos.cn (Wei Tao)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] net/sched: cls_fw: allow filter replace without re-specifying mask
Date: Wed, 14 Oct 2026 10:45:48 +0800
Organization: Usenet Network
Sender: cs_taowei@163.com
Message-ID: <20261014024548.37874-1-taowei@kylinos.cn>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2202271"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ODt4NyMuZ/ZaHdngOVruG8qnQ+o= sha256:y/cLDYcDyCkKaPBOTBdaT2juZ7kn99YSVyazmPRqp+A=
	sha1:LkD4WttATnlvMFsfE31cYwdH1vY= sha256:rKVGvJVQYwP2J2cGfd546l1BZmRLoR7GLDIGIM5QlFc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9445910FFAF; Wed, 14 Oct 2026 05:47:49 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.649
X-Spam-Status: No, score=-0.649 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=163.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id TDhXKm69JK4v;
	Wed, 14 Oct 2026 05:47:46 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-345974-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=kylinos.cn
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 673E610FFA9; Wed, 14 Oct 2026 05:47:34 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sea.lore.kernel.org (Postfix) with ESMTP id 641263830E; Wed, 14 Oct 2026 02:47:32 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 491903254B8;
	Wed, 14 Oct 2026 02:47:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Gs0Y6MT6"
X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B2281E5018;
	Wed, 14 Oct 2026 02:47:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791946051; cv=none; b=qpEoGN8s0IyL1S/pWOkU9SzFgJ1dGglqh3U45rN2ARHW8Ov8YxBGnjhd4wjujMPstdJywJmqcpDHbjDopiol+XLhNqdxZThiK9G/hcSH3CkYFtXwbnNFyjfVCEhUW51FdNocipkQCHfBBnZH9G4NXxAXkC98IXeRyKFRVN9eR4k=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791946051; c=relaxed/simple;
	bh=bU47t5azK/M7N5ZkIsA0t+/wEEAt4+XV8/3+W4p/3YA=;
	h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dZZwSSAerckaZjDMj3xgzYu/c0tk00uJoKH+mWNoRV+HpnevMIkDxcnXwme4lrmXADAwU3cGXD578+LyvFhu0XHFTMtAgDy4Vl8hK80bxcxplEmoi4NjL4IiQCDDhWTBOR+USKjh+EiaEK+zlZuC6GKVP/7zMU/yBee3r4eOW3Y=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Gs0Y6MT6; arc=none smtp.client-ip=220.197.31.5
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;
	s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=an
	ruDG1Od+mlES8g/2ElYftNeL5m7dyUazrMLwBBX3k=; b=Gs0Y6MT6RlGL46T4xo
	K8eEJMiHOcQ/qm9YQsBvs6V1y6MMqBMxUZB5WG0GGO1MklNCQHS0kBDAHzuUYeEJ
	6qO2ei0JJfbCFhK5WOU1jOMv46mvJry7wSM/HwNbanyadK5VmYBe1i5L585o3Ao0
	kYfxApcEpp2/rNYB3sEGq5JXM=
X-Received: from localhost.localdomain (unknown [])
	by gzsmtp4 (Coremail) with SMTP id PygvCgDHX1YS7c5qceXuEQ--.32271S2;
	Wed, 14 Oct 2026 10:46:44 +0800 (CST)
X-Cc: horms@kernel.org,
	netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Wei Tao <taowei@kylinos.cn>
X-Mailer: git-send-email 2.25.1
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-CM-TRANSID: PygvCgDHX1YS7c5qceXuEQ--.32271S2
X-Coremail-Antispam: 1Uf129KBjvJXoWxZF1kXF1xXry8Cw4DArWxtFb_yoW5Cr1DpF
	1rK3WUGFsrtFyjgrWkJw1kK34a9rs3JryxuF10k34SyrZIgF4FqrWI9ayfW3yUGFZ7Ca42
	qFs0q3y5W39rArJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jtGYdUUUUU=
X-CM-SenderInfo: xfvb3tprzhxqqrwthudrp/xtbC4RTOEGrO7RQCgAAA30