netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iptables]: xtables: tolerate DNS lookup failures
@ 2025-03-07 13:42 Guido Trentalancia
  2025-03-07 14:07 ` Jan Engelhardt
  0 siblings, 1 reply; 22+ messages in thread
From: Guido Trentalancia @ 2025-03-07 13:42 UTC (permalink / raw)
  To: netfilter-devel

libxtables: tolerate DNS lookup failures

Do not abort on DNS lookup failure, just skip the
rule and keep processing the rest of the rules.

This is particularly useful, for example, when
iptables-restore is called at system bootup
before the network is up and the DNS can be
reached.

Signed-off-by: Guido Trentalancia <guido@trentalancia.com>
---
 libxtables/xtables.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff -pru iptables-1.8.9-orig/libxtables/xtables.c iptables-1.8.9-new/libxtables/xtables.c
--- iptables-1.8.9-orig/libxtables/xtables.c	2023-01-12 11:27:35.000000000 +0100
+++ iptables-1.8.9-new/libxtables/xtables.c	2025-03-07 14:03:35.907011754 +0100
@@ -1710,7 +1710,8 @@ ipparse_hostnetwork(const char *name, un
 	if ((addrptmp = host_to_ipaddr(name, naddrs)) != NULL)
 		return addrptmp;
 
-	xt_params->exit_err(PARAMETER_PROBLEM, "host/network `%s' not found", name);
+	fprintf(stderr, "host/network `%s' not found - skipping rule\n", name);
+	return NULL;
 }
 
 static struct in_addr *parse_ipmask(const char *mask)
@@ -1788,6 +1789,8 @@ void xtables_ipparse_multiple(const char
 			strcpy(buf, "0.0.0.0");
 
 		addrp = ipparse_hostnetwork(buf, &n);
+		if (addrp == NULL)
+			continue;
 		if (n > 1) {
 			count += n - 1;
 			*addrpp = xtables_realloc(*addrpp,
@@ -1847,6 +1850,8 @@ void xtables_ipparse_any(const char *nam
 		strcpy(buf, "0.0.0.0");
 
 	addrp = *addrpp = ipparse_hostnetwork(buf, naddrs);
+	if (addrp == NULL)
+		return;
 	n = *naddrs;
 	for (i = 0, j = 0; i < n; ++i) {
 		addrp[j++].s_addr &= maskp->s_addr;
@@ -2005,7 +2010,8 @@ ip6parse_hostnetwork(const char *name, u
 	if ((addrp = host_to_ip6addr(name, naddrs)) != NULL)
 		return addrp;
 
-	xt_params->exit_err(PARAMETER_PROBLEM, "host/network `%s' not found", name);
+	fprintf(stderr, "host/network `%s' not found - skipping rule\n", name);
+	return NULL;
 }
 
 static struct in6_addr *parse_ip6mask(char *mask)
@@ -2084,6 +2090,8 @@ xtables_ip6parse_multiple(const char *na
 			strcpy(buf, "::");
 
 		addrp = ip6parse_hostnetwork(buf, &n);
+		if (addrp == NULL)
+			continue;
 		if (n > 1) {
 			count += n - 1;
 			*addrpp = xtables_realloc(*addrpp,
@@ -2137,6 +2145,8 @@ void xtables_ip6parse_any(const char *na
 		strcpy(buf, "::");
 
 	addrp = *addrpp = ip6parse_hostnetwork(buf, naddrs);
+	if (addrp == NULL)
+		return;
 	n = *naddrs;
 	for (i = 0, j = 0; i < n; ++i) {
 		for (k = 0; k < 4; ++k)

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2025-03-21 14:53 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-07 13:42 [PATCH iptables]: xtables: tolerate DNS lookup failures Guido Trentalancia
2025-03-07 14:07 ` Jan Engelhardt
2025-03-07 14:48   ` Reindl Harald
2025-03-07 15:31     ` Guido Trentalancia
2025-03-07 19:15       ` Reindl Harald
2025-03-07 19:32         ` Guido Trentalancia
2025-03-07 20:07           ` Reindl Harald
2025-03-07 20:37             ` Guido Trentalancia
2025-03-07 20:48               ` Reindl Harald
2025-03-07 20:58                 ` Guido Trentalancia
2025-03-08 17:35                   ` Jozsef Kadlecsik
2025-03-07 15:24   ` Guido Trentalancia
2025-03-07 15:46     ` Guido Trentalancia
2025-03-07 17:02       ` Jan Engelhardt
2025-03-07 17:15         ` Guido Trentalancia
2025-03-07 16:51     ` Jan Engelhardt
2025-03-07 17:09       ` Guido Trentalancia
2025-03-07 17:21         ` Jan Engelhardt
2025-03-07 17:40           ` Guido Trentalancia
2025-03-20 15:39             ` Phil Sutter
2025-03-21 11:21               ` Guido Trentalancia
2025-03-21 14:53                 ` Phil Sutter

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).