Received: from orbyte.nwl.cc (orbyte.nwl.cc [151.80.46.58]) (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 841081AC897 for ; Thu, 26 Sep 2024 09:57:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=151.80.46.58 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727344623; cv=none; b=hHtgiI5Eappk6Dh3hC2pKsTPMwX9y8ff3o9qETG3nHCs5hU1FPGUajc4hYFOXqsehFDhAyZ7e9P5BULxqPP6hbDL3FfbY5310Uu4pV7txwVk0aJsaGvieWg0uept3m/5dlsM2Iy0HYEHO3qPDuWZYD4V9A448gM0oZ6y6h+/rsk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727344623; c=relaxed/simple; bh=caGLcvYK12iZEFo7Zq1jH91eIGKp4jmCyuyso0VTRcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jvi4dzVsS0eL/1IONjd8D+fGvtU0p9fFOwle3uv9E8a+VXIA0vn0zIPb7PnlXZOZUnYnlDUnPNoqhsJLVy2JFYH1u4sAEXhB0JTadHognIyIfVQJLkTK1DWTa7+1yVYyfr2WjJE5l/B61AaVAhaoi/UKaf4rTx0+gW1I1LZfggg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nwl.cc; spf=pass smtp.mailfrom=nwl.cc; dkim=pass (2048-bit key) header.d=nwl.cc header.i=@nwl.cc header.b=i7gLgkzM; arc=none smtp.client-ip=151.80.46.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nwl.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nwl.cc Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nwl.cc header.i=@nwl.cc header.b="i7gLgkzM" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nwl.cc; s=mail2022; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=SAsePu84j49dhGYZ3vROPI7oGjyoLOpdsnuFHDLX+vQ=; b=i7gLgkzMxEqqLeuQQYQcZRt+kR blkp+CbCAk21xrC6ikMumMGj2+2U5m79zxG9lzYAoSYF3WKdEq8+716SU60BIKApaniwZKTxjDjw8 P7RdllzsUw6C6pupPxZRDLsVlak98G77neWuMw2/KkPIkv0WU9eCNkYApZgX2/lbYwx6NxF4mqve+ 9p4pRhZxqhH5+AqNwrWaA/aWg20KDQMitlIrFmNapNdK2HYt95z7jTX+GPFueFRHzvj8R+wp51Q4q 8yrgyzm5+5kVz8DML0a9tmR1sWlPaBoyytsk9/tA00zqb/UkAfKKD13nlTa9UiY/1ra61X9cOmiqc O/B8Lxag==; Received: from localhost ([::1] helo=xic) by orbyte.nwl.cc with esmtp (Exim 4.97.1) (envelope-from ) id 1stlF5-000000006HT-3yAT; Thu, 26 Sep 2024 11:57:00 +0200 From: Phil Sutter To: Pablo Neira Ayuso Cc: netfilter-devel@vger.kernel.org, Florian Westphal , Eric Garver Subject: [nf-next PATCH v5 06/18] netfilter: nf_tables: Simplify chain netdev notifier Date: Thu, 26 Sep 2024 11:56:31 +0200 Message-ID: <20240926095643.8801-7-phil@nwl.cc> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240926095643.8801-1-phil@nwl.cc> References: <20240926095643.8801-1-phil@nwl.cc> Precedence: bulk X-Mailing-List: netfilter-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit With conditional chain deletion gone, callback code simplifies: Instead of filling an nft_ctx object, just pass basechain to the per-chain function. Also plain list_for_each_entry() is safe now. Signed-off-by: Phil Sutter --- Changes since v4: - New patch. --- net/netfilter/nft_chain_filter.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/net/netfilter/nft_chain_filter.c b/net/netfilter/nft_chain_filter.c index 543f258b7c6b..19a553550c76 100644 --- a/net/netfilter/nft_chain_filter.c +++ b/net/netfilter/nft_chain_filter.c @@ -319,17 +319,16 @@ static const struct nft_chain_type nft_chain_filter_netdev = { }; static void nft_netdev_event(unsigned long event, struct net_device *dev, - struct nft_ctx *ctx) + struct nft_base_chain *basechain) { - struct nft_base_chain *basechain = nft_base_chain(ctx->chain); struct nft_hook *hook; list_for_each_entry(hook, &basechain->hook_list, list) { if (hook->ops.dev != dev) continue; - if (!(ctx->chain->table->flags & NFT_TABLE_F_DORMANT)) - nf_unregister_net_hook(ctx->net, &hook->ops); + if (!(basechain->chain.table->flags & NFT_TABLE_F_DORMANT)) + nf_unregister_net_hook(dev_net(dev), &hook->ops); list_del_rcu(&hook->list); kfree_rcu(hook, rcu); @@ -343,25 +342,20 @@ static int nf_tables_netdev_event(struct notifier_block *this, struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct nft_base_chain *basechain; struct nftables_pernet *nft_net; - struct nft_chain *chain, *nr; + struct nft_chain *chain; struct nft_table *table; - struct nft_ctx ctx = { - .net = dev_net(dev), - }; if (event != NETDEV_UNREGISTER) return NOTIFY_DONE; - nft_net = nft_pernet(ctx.net); + nft_net = nft_pernet(dev_net(dev)); mutex_lock(&nft_net->commit_mutex); list_for_each_entry(table, &nft_net->tables, list) { if (table->family != NFPROTO_NETDEV && table->family != NFPROTO_INET) continue; - ctx.family = table->family; - ctx.table = table; - list_for_each_entry_safe(chain, nr, &table->chains, list) { + list_for_each_entry(chain, &table->chains, list) { if (!nft_is_base_chain(chain)) continue; @@ -370,8 +364,7 @@ static int nf_tables_netdev_event(struct notifier_block *this, basechain->ops.hooknum != NF_INET_INGRESS) continue; - ctx.chain = chain; - nft_netdev_event(event, dev, &ctx); + nft_netdev_event(event, dev, basechain); } } mutex_unlock(&nft_net->commit_mutex); -- 2.43.0