netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org
Subject: [PATCH net-next 06/22] netfilter: x_tables: add xt_find_table
Date: Mon, 26 Apr 2021 19:10:40 +0200	[thread overview]
Message-ID: <20210426171056.345271-7-pablo@netfilter.org> (raw)
In-Reply-To: <20210426171056.345271-1-pablo@netfilter.org>

From: Florian Westphal <fw@strlen.de>

This will be used to obtain the xt_table struct given address family and
table name.

Followup patches will reduce the number of direct accesses to the xt_table
structures via net->ipv{4,6}.ip(6)table_{nat,mangle,...} pointers, then
remove them.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/linux/netfilter/x_tables.h |  1 +
 net/netfilter/x_tables.c           | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h
index 8ec48466410a..b2eec7de5280 100644
--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -322,6 +322,7 @@ struct xt_target *xt_request_find_target(u8 af, const char *name, u8 revision);
 int xt_find_revision(u8 af, const char *name, u8 revision, int target,
 		     int *err);
 
+struct xt_table *xt_find_table(struct net *net, u8 af, const char *name);
 struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
 				    const char *name);
 struct xt_table *xt_request_find_table_lock(struct net *net, u_int8_t af,
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index b7f8d2ed3cc2..1caba9507228 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1199,6 +1199,23 @@ void xt_free_table_info(struct xt_table_info *info)
 }
 EXPORT_SYMBOL(xt_free_table_info);
 
+struct xt_table *xt_find_table(struct net *net, u8 af, const char *name)
+{
+	struct xt_pernet *xt_net = net_generic(net, xt_pernet_id);
+	struct xt_table *t;
+
+	mutex_lock(&xt[af].mutex);
+	list_for_each_entry(t, &xt_net->tables[af], list) {
+		if (strcmp(t->name, name) == 0) {
+			mutex_unlock(&xt[af].mutex);
+			return t;
+		}
+	}
+	mutex_unlock(&xt[af].mutex);
+	return NULL;
+}
+EXPORT_SYMBOL(xt_find_table);
+
 /* Find table by name, grabs mutex & ref.  Returns ERR_PTR on error. */
 struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
 				    const char *name)
-- 
2.30.2


  parent reply	other threads:[~2021-04-26 17:11 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26 17:10 [PATCH net-next 00/22] Netfilter updates for net-next Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 01/22] netfilter: nat: move nf_xfrm_me_harder to where it is used Pablo Neira Ayuso
2021-04-26 19:53   ` patchwork-bot+netdevbpf
2021-04-26 17:10 ` [PATCH net-next 02/22] netfilter: nft_socket: add support for cgroupsv2 Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 03/22] netfilter: disable defrag once its no longer needed Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 04/22] netfilter: ebtables: remove the 3 ebtables pointers from struct net Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 05/22] netfilter: x_tables: remove ipt_unregister_table Pablo Neira Ayuso
2021-04-26 17:10 ` Pablo Neira Ayuso [this message]
2021-04-26 17:10 ` [PATCH net-next 07/22] netfilter: iptables: unregister the tables by name Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 08/22] netfilter: ip6tables: " Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 09/22] netfilter: arptables: " Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 10/22] netfilter: x_tables: remove paranoia tests Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 11/22] netfilter: xt_nat: pass table to hookfn Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 12/22] netfilter: ip_tables: pass table pointer via nf_hook_ops Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 13/22] netfilter: arp_tables: " Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 14/22] netfilter: ip6_tables: " Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 15/22] netfilter: remove all xt_table anchors from struct net Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 16/22] netfilter: nf_log_syslog: Unset bridge logger in pernet exit Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 17/22] netfilter: nftables: add nft_pernet() helper function Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 18/22] netfilter: nfnetlink: add struct nfnl_info and pass it to callbacks Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 19/22] netfilter: nfnetlink: pass struct nfnl_info to rcu callbacks Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 20/22] netfilter: nfnetlink: pass struct nfnl_info to batch callbacks Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 21/22] netfilter: nfnetlink: consolidate callback types Pablo Neira Ayuso
2021-04-26 17:10 ` [PATCH net-next 22/22] netfilter: allow to turn off xtables compat layer Pablo Neira Ayuso

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=20210426171056.345271-7-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).