From mboxrd@z Thu Jan 1 00:00:00 1970 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 60A1E1891AA for ; Thu, 9 Jan 2025 17:31:44 +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=1736443907; cv=none; b=ZBgl1LM+LKTl8lawg71wxf0XTiYbHtz+ANU1+6BN8rE42x8Xb0BnZxuXtleCLo4vGqhp5KQVPPRMiKJKxA91d6n7Kx9wX5XvQyweor0YDIujs7HjY4kFzrETwZ1wI8Qo1Nl0AoLcgnFDTljfmi9YDZFN03p+wPgbYWyzBaz7Fl8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736443907; c=relaxed/simple; bh=V7B+DRG2YPUMHnZ40U9thTgQdt7wn4QXWnSOlwGER+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SV3+oJtwogbIPY/GjlGi/BAJVFeOVbiZg18J03GtCjk68YRTeR4SdSKQRbkhfS8i0IEERZXsMLdGjP6x/3vp9hF9v29tRZ6kTOhvUNDD2u6k8MLRNpVUPTQJYCjEa3J5sk3MwxJ4io+f9EP3Ian9Y+Av1Q9SF6Jy9wqJXsikqAs= 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=hTmT/kBC; 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="hTmT/kBC" 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=t1/82x4+BbbZxFpSVq4DDloP76O3qOUyTsEVCzs1VRQ=; b=hTmT/kBCQ0XuC0ZbF5zAhpJ+om aFewVLQpAwXPSoFQfiapnmB8I3Gy7V8ZqCLSQsF8CBnYFY5ragiH8dGmVRRNXrwsYIsv2j5jQbPgP 3MKkxKOG7t0DH86e8T6uSk29/8UZd7Km3oYpPxO924Pt1fxoFw5ShwE7xZvoziCIjCy3lLZJuYylM giQzxUWvkj+TM85aoeq0gLrrkZFHHqEdb7v4GNsAzlYAxy3alDQdDZD7+sWGhusySOAapsP/DXIZp EFNK1981RxmdfWaENx1peRlPuFuZVU9XnQ27N8kKVHVzwV7GYGq3k3/jAU36Wp2xYJCljGojO1dDd VJewbWKg==; Authentication-Results: mail.nwl.cc; iprev=pass (localhost) smtp.remote-ip=::1 Received: from localhost ([::1] helo=xic) by orbyte.nwl.cc with esmtp (Exim 4.97.1) (envelope-from ) id 1tVwNi-000000006Mf-1W8f; Thu, 09 Jan 2025 18:31:42 +0100 From: Phil Sutter To: Pablo Neira Ayuso Cc: netfilter-devel@vger.kernel.org, Florian Westphal , Eric Garver Subject: [nf-next PATCH v7 6/6] netfilter: nf_tables: Simplify chain netdev notifier Date: Thu, 9 Jan 2025 18:31:37 +0100 Message-ID: <20250109173137.17954-7-phil@nwl.cc> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250109173137.17954-1-phil@nwl.cc> References: <20250109173137.17954-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 --- 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.47.1