All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nf-next 03/12] netfilter: add xt_find_table
Date: Tue, 20 Apr 2021 14:24:58 +0200	[thread overview]
Message-ID: <20210420122507.505-4-fw@strlen.de> (raw)
In-Reply-To: <20210420122507.505-1-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>
---
 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.26.3


  parent reply	other threads:[~2021-04-20 12:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-20 12:24 [PATCH nf-next 00/12] netfilter: remove xtables pointers from struct net Florian Westphal
2021-04-20 12:24 ` [PATCH nf-next 01/12] netfilter: ebtables: remove the 3 ebtables " Florian Westphal
2021-04-20 12:24 ` [PATCH nf-next 02/12] netfilter: x_tables: remove ipt_unregister_table Florian Westphal
2021-04-20 14:17   ` kernel test robot
2021-04-20 14:17     ` kernel test robot
2021-04-20 16:44   ` kernel test robot
2021-04-20 16:44     ` kernel test robot
2021-04-20 12:24 ` Florian Westphal [this message]
2021-04-20 12:24 ` [PATCH nf-next 04/12] netfilter: iptables: unregister the tables by name Florian Westphal
2021-04-20 12:25 ` [PATCH nf-next 05/12] netfilter: ip6tables: " Florian Westphal
2021-04-20 12:25 ` [PATCH nf-next 06/12] netfilter: arptables: " Florian Westphal
2021-04-20 12:25 ` [PATCH nf-next 07/12] netfilter: x_tables: remove paranoia tests Florian Westphal
2021-04-20 12:25 ` [PATCH nf-next 08/12] netfilter: xt_nat: pass table to hookfn Florian Westphal
2021-04-20 12:25 ` [PATCH nf-next 09/12] netfilter: ip_tables: pass table pointer via nf_hook_ops Florian Westphal
2021-04-20 12:25 ` [PATCH nf-next 10/12] netfilter: arp_tables: " Florian Westphal
2021-04-20 12:25 ` [PATCH nf-next 11/12] netfilter: ip6_tables: " Florian Westphal
2021-04-20 12:25 ` [PATCH nf-next 12/12] netfilter: remove all xt_table anchors from struct net Florian Westphal

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=20210420122507.505-4-fw@strlen.de \
    --to=fw@strlen.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.