Blame SOURCES/0069-libxtables-Boost-rule-target-checks-by-announcing-ch.patch

d8275f
From 86bf4207cb744c38807fb5c42c5921fc9964a2af Mon Sep 17 00:00:00 2001
d8275f
From: Phil Sutter <phil@nwl.cc>
d8275f
Date: Fri, 4 Mar 2022 12:50:01 +0100
d8275f
Subject: [PATCH] libxtables: Boost rule target checks by announcing chain
d8275f
 names
d8275f
d8275f
When restoring a ruleset, feed libxtables with chain names from
d8275f
respective lines to avoid an extension search.
d8275f
d8275f
While the user's intention is clear, this effectively disables the
d8275f
sanity check for clashes with target extensions. But:
d8275f
d8275f
* The check yielded only a warning and the clashing chain was finally
d8275f
  accepted.
d8275f
d8275f
* Users crafting iptables dumps for feeding into iptables-restore likely
d8275f
  know what they're doing.
d8275f
d8275f
Signed-off-by: Phil Sutter <phil@nwl.cc>
d8275f
Acked-by: Florian Westphal <fw@strlen.de>
d8275f
(cherry picked from commit ac4c84cc63d3cc021ca532692885a644fcde4518)
d8275f
---
d8275f
 include/xtables.h           | 3 +++
d8275f
 iptables/iptables-restore.c | 1 +
d8275f
 iptables/xtables-restore.c  | 1 +
d8275f
 libxtables/xtables.c        | 6 ++++++
d8275f
 4 files changed, 11 insertions(+)
d8275f
d8275f
diff --git a/include/xtables.h b/include/xtables.h
d8275f
index 4aa084a1a2a30..d77a73a4303a7 100644
d8275f
--- a/include/xtables.h
d8275f
+++ b/include/xtables.h
d8275f
@@ -632,6 +632,9 @@ void xt_xlate_add_comment(struct xt_xlate *xl, const char *comment);
d8275f
 const char *xt_xlate_get_comment(struct xt_xlate *xl);
d8275f
 const char *xt_xlate_get(struct xt_xlate *xl);
d8275f
 
d8275f
+/* informed target lookups */
d8275f
+void xtables_announce_chain(const char *name);
d8275f
+
d8275f
 #ifdef XTABLES_INTERNAL
d8275f
 
d8275f
 /* Shipped modules rely on this... */
d8275f
diff --git a/iptables/iptables-restore.c b/iptables/iptables-restore.c
d8275f
index b0a51d491c508..339abaa32a055 100644
d8275f
--- a/iptables/iptables-restore.c
d8275f
+++ b/iptables/iptables-restore.c
d8275f
@@ -309,6 +309,7 @@ ip46tables_restore_main(const struct iptables_restore_cb *cb,
d8275f
 						cb->ops->strerror(errno));
d8275f
 			}
d8275f
 
d8275f
+			xtables_announce_chain(chain);
d8275f
 			ret = 1;
d8275f
 
d8275f
 		} else if (in_table) {
d8275f
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
d8275f
index a078da32045dc..41e7cb7661464 100644
d8275f
--- a/iptables/xtables-restore.c
d8275f
+++ b/iptables/xtables-restore.c
d8275f
@@ -150,6 +150,7 @@ static void xtables_restore_parse_line(struct nft_handle *h,
d8275f
 				   "%s: line %u chain name invalid\n",
d8275f
 				   xt_params->program_name, line);
d8275f
 
d8275f
+		xtables_announce_chain(chain);
d8275f
 		assert_valid_chain_name(chain);
d8275f
 
d8275f
 		policy = strtok(NULL, " \t\n");
d8275f
diff --git a/libxtables/xtables.c b/libxtables/xtables.c
d8275f
index 1e1c218df7441..4aee74acb6816 100644
d8275f
--- a/libxtables/xtables.c
d8275f
+++ b/libxtables/xtables.c
d8275f
@@ -274,6 +274,12 @@ static void notargets_hlist_insert(const char *name)
d8275f
 	hlist_add_head(&cur->node, &notargets[djb_hash(name) % NOTARGET_HSIZE]);
d8275f
 }
d8275f
 
d8275f
+void xtables_announce_chain(const char *name)
d8275f
+{
d8275f
+	if (!notargets_hlist_lookup(name))
d8275f
+		notargets_hlist_insert(name);
d8275f
+}
d8275f
+
d8275f
 void xtables_init(void)
d8275f
 {
d8275f
 	xtables_libdir = getenv("XTABLES_LIBDIR");
d8275f
-- 
d8275f
2.34.1
d8275f