]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
netfilter: x_tables: add and use xt_unregister_table_pre_exit
authorFlorian Westphal <fw@strlen.de>
Wed, 6 May 2026 10:07:15 +0000 (12:07 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 7 May 2026 23:30:16 +0000 (01:30 +0200)
Remove the copypasted variants of _pre_exit and add one single
function in the xtables core.  ebtables is not compatible with
x_tables and therefore unchanged.

This is a preparation patch to reduce noise in the followup
bug fixes.

Reviewed-by: Tristan Madani <tristan@talencesecurity.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
19 files changed:
include/linux/netfilter/x_tables.h
include/linux/netfilter_arp/arp_tables.h
include/linux/netfilter_ipv4/ip_tables.h
include/linux/netfilter_ipv6/ip6_tables.h
net/ipv4/netfilter/arp_tables.c
net/ipv4/netfilter/arptable_filter.c
net/ipv4/netfilter/ip_tables.c
net/ipv4/netfilter/iptable_filter.c
net/ipv4/netfilter/iptable_mangle.c
net/ipv4/netfilter/iptable_nat.c
net/ipv4/netfilter/iptable_raw.c
net/ipv4/netfilter/iptable_security.c
net/ipv6/netfilter/ip6_tables.c
net/ipv6/netfilter/ip6table_filter.c
net/ipv6/netfilter/ip6table_mangle.c
net/ipv6/netfilter/ip6table_nat.c
net/ipv6/netfilter/ip6table_raw.c
net/ipv6/netfilter/ip6table_security.c
net/netfilter/x_tables.c

index cb4b694dd9e402e3ebf23d4d4187db473ea3317a..74486714ae20070cadeb503fe0fb177b4cdcb0a9 100644 (file)
@@ -309,6 +309,7 @@ struct xt_table *xt_register_table(struct net *net,
                                   struct xt_table_info *bootstrap,
                                   struct xt_table_info *newinfo);
 void *xt_unregister_table(struct xt_table *table);
+void xt_unregister_table_pre_exit(struct net *net, u8 af, const char *name);
 
 struct xt_table_info *xt_replace_table(struct xt_table *table,
                                       unsigned int num_counters,
index a40aaf645fa4798b4d517f515d77a6d3d312ef52..05631a25e622932cb3137aa9c3310ff9b748620a 100644 (file)
@@ -53,7 +53,6 @@ int arpt_register_table(struct net *net, const struct xt_table *table,
                        const struct arpt_replace *repl,
                        const struct nf_hook_ops *ops);
 void arpt_unregister_table(struct net *net, const char *name);
-void arpt_unregister_table_pre_exit(struct net *net, const char *name);
 extern unsigned int arpt_do_table(void *priv, struct sk_buff *skb,
                                  const struct nf_hook_state *state);
 
index 132b0e4a6d4df6359df1059aec617e2596916e11..13593391d6058de9e0696a446fee49f03003d5ee 100644 (file)
@@ -26,7 +26,6 @@ int ipt_register_table(struct net *net, const struct xt_table *table,
                       const struct ipt_replace *repl,
                       const struct nf_hook_ops *ops);
 
-void ipt_unregister_table_pre_exit(struct net *net, const char *name);
 void ipt_unregister_table_exit(struct net *net, const char *name);
 
 /* Standard entry. */
index 8b8885a73c764994e8a3c68d63bcc12ef20a287b..c6d5b927830dd31af01fc6299a6b5bd6a5727e1f 100644 (file)
@@ -27,7 +27,6 @@ extern void *ip6t_alloc_initial_table(const struct xt_table *);
 int ip6t_register_table(struct net *net, const struct xt_table *table,
                        const struct ip6t_replace *repl,
                        const struct nf_hook_ops *ops);
-void ip6t_unregister_table_pre_exit(struct net *net, const char *name);
 void ip6t_unregister_table_exit(struct net *net, const char *name);
 extern unsigned int ip6t_do_table(void *priv, struct sk_buff *skb,
                                  const struct nf_hook_state *state);
index c02e46a0271a0fe0c3458d9cd291104c07b99d7e..bd348b7bad2c5f8e233a7ddc1441c35eb3b50a76 100644 (file)
@@ -1554,15 +1554,6 @@ int arpt_register_table(struct net *net,
        return ret;
 }
 
-void arpt_unregister_table_pre_exit(struct net *net, const char *name)
-{
-       struct xt_table *table = xt_find_table(net, NFPROTO_ARP, name);
-
-       if (table)
-               nf_unregister_net_hooks(net, table->ops, hweight32(table->valid_hooks));
-}
-EXPORT_SYMBOL(arpt_unregister_table_pre_exit);
-
 void arpt_unregister_table(struct net *net, const char *name)
 {
        struct xt_table *table = xt_find_table(net, NFPROTO_ARP, name);
index 78cd5ee24448f624526ea6595e4ad8252b927425..393d9a8c77390055c2e0019501069137983fe033 100644 (file)
@@ -43,7 +43,7 @@ static int arptable_filter_table_init(struct net *net)
 
 static void __net_exit arptable_filter_net_pre_exit(struct net *net)
 {
-       arpt_unregister_table_pre_exit(net, "filter");
+       xt_unregister_table_pre_exit(net, NFPROTO_ARP, "filter");
 }
 
 static void __net_exit arptable_filter_net_exit(struct net *net)
index 488c5945ebb235f4b81412567c8c5d4916644533..864489928fb5aa7eb566955070ef93df77e4e5a6 100644 (file)
@@ -1756,14 +1756,6 @@ int ipt_register_table(struct net *net, const struct xt_table *table,
        return ret;
 }
 
-void ipt_unregister_table_pre_exit(struct net *net, const char *name)
-{
-       struct xt_table *table = xt_find_table(net, NFPROTO_IPV4, name);
-
-       if (table)
-               nf_unregister_net_hooks(net, table->ops, hweight32(table->valid_hooks));
-}
-
 void ipt_unregister_table_exit(struct net *net, const char *name)
 {
        struct xt_table *table = xt_find_table(net, NFPROTO_IPV4, name);
@@ -1854,7 +1846,6 @@ static void __exit ip_tables_fini(void)
 }
 
 EXPORT_SYMBOL(ipt_register_table);
-EXPORT_SYMBOL(ipt_unregister_table_pre_exit);
 EXPORT_SYMBOL(ipt_unregister_table_exit);
 EXPORT_SYMBOL(ipt_do_table);
 module_init(ip_tables_init);
index 3ab908b74795177fa037a0381547076d1d248107..b2fbd9651d61aa3b8fb019f1d61b7ce9ad52c884 100644 (file)
@@ -61,7 +61,7 @@ static int __net_init iptable_filter_net_init(struct net *net)
 
 static void __net_exit iptable_filter_net_pre_exit(struct net *net)
 {
-       ipt_unregister_table_pre_exit(net, "filter");
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV4, "filter");
 }
 
 static void __net_exit iptable_filter_net_exit(struct net *net)
index 385d945d8ebea04bbe92676a3ee57dccf06434ce..a99e619961975f5eb43195af5c0c805f2666dfa8 100644 (file)
@@ -96,7 +96,7 @@ static int iptable_mangle_table_init(struct net *net)
 
 static void __net_exit iptable_mangle_net_pre_exit(struct net *net)
 {
-       ipt_unregister_table_pre_exit(net, "mangle");
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV4, "mangle");
 }
 
 static void __net_exit iptable_mangle_net_exit(struct net *net)
index 625a1ca13b1bad060f690e289a41fc2ccc572bb3..8fc4912e790d8fb6c21f49eac7657dcd13a76e60 100644 (file)
@@ -129,6 +129,7 @@ static int iptable_nat_table_init(struct net *net)
 static void __net_exit iptable_nat_net_pre_exit(struct net *net)
 {
        ipt_nat_unregister_lookups(net);
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV4, "nat");
 }
 
 static void __net_exit iptable_nat_net_exit(struct net *net)
index 0e7f53964d0af627dbc72a7f7fbfc345f118d591..42511721e538a0c96a5b048f411d785ea4b49481 100644 (file)
@@ -53,7 +53,7 @@ static int iptable_raw_table_init(struct net *net)
 
 static void __net_exit iptable_raw_net_pre_exit(struct net *net)
 {
-       ipt_unregister_table_pre_exit(net, "raw");
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV4, "raw");
 }
 
 static void __net_exit iptable_raw_net_exit(struct net *net)
index d885443cb267984eb475475b44fbc09c1b5468f8..4646bf6d7d2bd639a27b6112b71956c7e2e7b414 100644 (file)
@@ -50,7 +50,7 @@ static int iptable_security_table_init(struct net *net)
 
 static void __net_exit iptable_security_net_pre_exit(struct net *net)
 {
-       ipt_unregister_table_pre_exit(net, "security");
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV4, "security");
 }
 
 static void __net_exit iptable_security_net_exit(struct net *net)
index dbe7c7acd702ef76657266c01908c6fe42f65a37..edf50bc7787e5680b5e1c11023f489503afe68d0 100644 (file)
@@ -1765,14 +1765,6 @@ int ip6t_register_table(struct net *net, const struct xt_table *table,
        return ret;
 }
 
-void ip6t_unregister_table_pre_exit(struct net *net, const char *name)
-{
-       struct xt_table *table = xt_find_table(net, NFPROTO_IPV6, name);
-
-       if (table)
-               nf_unregister_net_hooks(net, table->ops, hweight32(table->valid_hooks));
-}
-
 void ip6t_unregister_table_exit(struct net *net, const char *name)
 {
        struct xt_table *table = xt_find_table(net, NFPROTO_IPV6, name);
@@ -1864,7 +1856,6 @@ static void __exit ip6_tables_fini(void)
 }
 
 EXPORT_SYMBOL(ip6t_register_table);
-EXPORT_SYMBOL(ip6t_unregister_table_pre_exit);
 EXPORT_SYMBOL(ip6t_unregister_table_exit);
 EXPORT_SYMBOL(ip6t_do_table);
 
index e8992693e14a041758d53a3daad2084d6a555760..f05a9e4b2c6762ea364bd680f53e5fb3305d37a7 100644 (file)
@@ -60,7 +60,7 @@ static int __net_init ip6table_filter_net_init(struct net *net)
 
 static void __net_exit ip6table_filter_net_pre_exit(struct net *net)
 {
-       ip6t_unregister_table_pre_exit(net, "filter");
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV6, "filter");
 }
 
 static void __net_exit ip6table_filter_net_exit(struct net *net)
index 8dd4cd0c47bd4db87b14754a4c5d2bcbd115619a..afa4a5703e433951fc579e26c231c0e9dcc49aad 100644 (file)
@@ -89,7 +89,7 @@ static int ip6table_mangle_table_init(struct net *net)
 
 static void __net_exit ip6table_mangle_net_pre_exit(struct net *net)
 {
-       ip6t_unregister_table_pre_exit(net, "mangle");
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV6, "mangle");
 }
 
 static void __net_exit ip6table_mangle_net_exit(struct net *net)
index 5be723232df8f1cb33a595fb0fc3c3ac66199913..bb8aa3fc42b45e273cfddecb32fbc44138c80a7e 100644 (file)
@@ -131,6 +131,7 @@ static int ip6table_nat_table_init(struct net *net)
 static void __net_exit ip6table_nat_net_pre_exit(struct net *net)
 {
        ip6t_nat_unregister_lookups(net);
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV6, "nat");
 }
 
 static void __net_exit ip6table_nat_net_exit(struct net *net)
index fc9f6754028f2c4fc3fd5bb83ec1dca5225d4a74..32d2da81c52a7dbf600b26866cc22bcfd7633eb3 100644 (file)
@@ -52,7 +52,7 @@ static int ip6table_raw_table_init(struct net *net)
 
 static void __net_exit ip6table_raw_net_pre_exit(struct net *net)
 {
-       ip6t_unregister_table_pre_exit(net, "raw");
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV6, "raw");
 }
 
 static void __net_exit ip6table_raw_net_exit(struct net *net)
index 4df14a9bae782d808147ee10af6299235ce227a7..3dfd8d6ea4b906943dfaf004d03ca200a75cec5d 100644 (file)
@@ -49,7 +49,7 @@ static int ip6table_security_table_init(struct net *net)
 
 static void __net_exit ip6table_security_net_pre_exit(struct net *net)
 {
-       ip6t_unregister_table_pre_exit(net, "security");
+       xt_unregister_table_pre_exit(net, NFPROTO_IPV6, "security");
 }
 
 static void __net_exit ip6table_security_net_exit(struct net *net)
index 06f27bea9eedb6b9d8aed95a5fa93f057c762968..9c1e896c7b03b693a7b67809cb7a5b20284c5600 100644 (file)
@@ -1650,6 +1650,35 @@ void *xt_unregister_table(struct xt_table *table)
        return private;
 }
 EXPORT_SYMBOL_GPL(xt_unregister_table);
+
+/**
+ * xt_unregister_table_pre_exit - pre-shutdown unregister of a table
+ * @net: network namespace
+ * @af: address family (e.g., NFPROTO_IPV4, NFPROTO_IPV6)
+ * @name: name of the table to unregister
+ *
+ * Unregisters the specified netfilter table from the given network namespace
+ * and also unregisters the hooks from netfilter core: no new packets will be
+ * processed.
+ */
+void xt_unregister_table_pre_exit(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);
+
+                       if (t->ops) /* nat table registers with nat core, t->ops is NULL. */
+                               nf_unregister_net_hooks(net, t->ops, hweight32(t->valid_hooks));
+                       return;
+               }
+       }
+       mutex_unlock(&xt[af].mutex);
+}
+EXPORT_SYMBOL(xt_unregister_table_pre_exit);
 #endif
 
 #ifdef CONFIG_PROC_FS