[netfilter-cvslog] r7471 - in trunk/iptables: . extensions include libiptc

kaber at trash.net kaber at trash.net
Sun Apr 13 07:25:24 CEST 2008


Author: kaber at trash.net
Date: 2008-04-13 07:25:24 +0200 (Sun, 13 Apr 2008)
New Revision: 7471

Modified:
   trunk/iptables/configure.ac
   trunk/iptables/extensions/GNUmakefile.in
   trunk/iptables/include/ip6tables.h
   trunk/iptables/include/iptables.h
   trunk/iptables/ip6tables-restore.c
   trunk/iptables/ip6tables-save.c
   trunk/iptables/ip6tables-standalone.c
   trunk/iptables/iptables-restore.c
   trunk/iptables/iptables-save.c
   trunk/iptables/iptables-standalone.c
   trunk/iptables/libiptc/libiptc.c
   trunk/iptables/xtables.c
Log:
[PATCH 05/13] Combine IP{,6}T_LIB_DIR into XTABLES_LIBDIR


Modified: trunk/iptables/configure.ac
===================================================================
--- trunk/iptables/configure.ac	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/configure.ac	2008-04-13 05:25:24 UTC (rev 7471)
@@ -22,11 +22,11 @@
 	AS_HELP_STRING([--with-ksource=PATH],
 	[Path to kernel source directory [[/lib/modules/CURRENT/source]]]),
 	[ksourcedir="$withval"])
-AC_ARG_WITH([iptdir],
-	AS_HELP_STRING([--with-iptdir=PATH],
+AC_ARG_WITH([xtlibdir],
+	AS_HELP_STRING([--with-xtlibdir=PATH],
 	[Path to iptables modules [[LIBEXECDIR/iptables]]]),
-	[iptdir="$withval"],
-	[iptdir="${libexecdir}/iptables"])
+	[xtlibdir="$withval"],
+	[xtlibdir="${libexecdir}/iptables"])
 AC_ARG_ENABLE([devel],
 	AS_HELP_STRING([--enable-devel],
 	[Build and install development files (libipq, libipq-devel, iptables-devel)]))
@@ -40,12 +40,11 @@
 	-D_REENTRANT -Wall -Waggregate-return -Wmissing-declarations \
 	-Wmissing-prototypes -Wredundant-decls -Wshadow -Wstrict-prototypes \
 	-Winline -pipe -DIPTABLES_VERSION=\\\"$PACKAGE_VERSION\\\" \
-	-DIPT_LIB_DIR=\\\"\${iptdir}\\\" -DIP6T_LIB_DIR=\\\"\${iptdir}\\\"";
-regular_CFLAGS="$regular_CFLAGS -DXTABLES_INTERNAL"
+	-DXTABLES_LIBDIR=\\\"\${xtlibdir}\\\" -DXTABLES_INTERNAL";
 kinclude_CFLAGS="-I\"$kbuilddir/include\" -I\"$ksourcedir/include\"";
 
 AC_SUBST([regular_CFLAGS kinclude_CFLAGS])
 AC_SUBST([kbuilddir])
 AC_SUBST([ksourcedir])
-AC_SUBST([iptdir])
+AC_SUBST([xtlibdir])
 AC_OUTPUT([Makefile extensions/GNUmakefile libipq/Makefile])

Modified: trunk/iptables/extensions/GNUmakefile.in
===================================================================
--- trunk/iptables/extensions/GNUmakefile.in	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/extensions/GNUmakefile.in	2008-04-13 05:25:24 UTC (rev 7471)
@@ -7,7 +7,7 @@
 exec_prefix := @exec_prefix@
 libdir      := @libdir@
 libexecdir  := @libexecdir@
-iptdir      := @iptdir@
+xtlibdir    := @xtlibdir@
 
 CC             := @CC@
 CCLD           := ${CC}
@@ -82,8 +82,8 @@
 all: ${targets}
 
 install: ${targets_install}
-	@mkdir -p "${DESTDIR}${iptdir}";
-	install -pm0755 $^ "${DESTDIR}${iptdir}/";
+	@mkdir -p "${DESTDIR}${xtlibdir}";
+	install -pm0755 $^ "${DESTDIR}${xtlibdir}/";
 
 clean:
 	rm -f *.o *.oo *.so *.a {matches,targets}[46].man initext4.c initext6.c;

Modified: trunk/iptables/include/ip6tables.h
===================================================================
--- trunk/iptables/include/ip6tables.h	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/include/ip6tables.h	2008-04-13 05:25:24 UTC (rev 7471)
@@ -5,10 +5,6 @@
 
 #include "libiptc/libip6tc.h"
 
-#ifndef IP6T_LIB_DIR
-#define IP6T_LIB_DIR XT_LIB_DIR
-#endif
-
 #ifndef IP6T_SO_GET_REVISION_MATCH /* Old kernel source. */
 #define IP6T_SO_GET_REVISION_MATCH	68
 #define IP6T_SO_GET_REVISION_TARGET	69

Modified: trunk/iptables/include/iptables.h
===================================================================
--- trunk/iptables/include/iptables.h	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/include/iptables.h	2008-04-13 05:25:24 UTC (rev 7471)
@@ -4,10 +4,6 @@
 #include "xtables.h"
 #include "libiptc/libiptc.h"
 
-#ifndef IPT_LIB_DIR
-#define IPT_LIB_DIR XT_LIB_DIR
-#endif
-
 #ifndef IPT_SO_GET_REVISION_MATCH /* Old kernel source. */
 #define IPT_SO_GET_REVISION_MATCH	(IPT_BASE_CTL + 2)
 #define IPT_SO_GET_REVISION_TARGET	(IPT_BASE_CTL + 3)

Modified: trunk/iptables/ip6tables-restore.c
===================================================================
--- trunk/iptables/ip6tables-restore.c	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/ip6tables-restore.c	2008-04-13 05:25:24 UTC (rev 7471)
@@ -131,9 +131,14 @@
 	program_version = IPTABLES_VERSION;
 	line = 0;
 
-	lib_dir = getenv("IP6TABLES_LIB_DIR");
-	if (!lib_dir)
-		lib_dir = IP6T_LIB_DIR;
+	lib_dir = getenv("XTABLES_LIBDIR");
+	if (lib_dir == NULL) {
+		lib_dir = getenv("IP6TABLES_LIB_DIR");
+		if (lib_dir != NULL)
+			fprintf(stderr, "IP6TABLES_LIB_DIR is deprecated\n");
+	}
+	if (lib_dir == NULL)
+		lib_dir = XTABLES_LIBDIR;
 
 #ifdef NO_SHARED_LIBS
 	init_extensions();

Modified: trunk/iptables/ip6tables-save.c
===================================================================
--- trunk/iptables/ip6tables-save.c	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/ip6tables-save.c	2008-04-13 05:25:24 UTC (rev 7471)
@@ -332,9 +332,14 @@
 	program_name = "ip6tables-save";
 	program_version = IPTABLES_VERSION;
 
-	lib_dir = getenv("IP6TABLES_LIB_DIR");
-	if (!lib_dir)
-		lib_dir = IP6T_LIB_DIR;
+	lib_dir = getenv("XTABLES_LIBDIR");
+	if (lib_dir == NULL) {
+		lib_dir = getenv("IP6TABLES_LIB_DIR");
+		if (lib_dir != NULL)
+			fprintf(stderr, "IP6TABLES_LIB_DIR is deprecated\n");
+	}
+	if (lib_dir == NULL)
+		lib_dir = XTABLES_LIBDIR;
 
 #ifdef NO_SHARED_LIBS
 	init_extensions();

Modified: trunk/iptables/ip6tables-standalone.c
===================================================================
--- trunk/iptables/ip6tables-standalone.c	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/ip6tables-standalone.c	2008-04-13 05:25:24 UTC (rev 7471)
@@ -52,9 +52,14 @@
 	program_name = "ip6tables";
 	program_version = IPTABLES_VERSION;
 
-	lib_dir = getenv("IP6TABLES_LIB_DIR");
-	if (!lib_dir)
-		lib_dir = IP6T_LIB_DIR;
+	lib_dir = getenv("XTABLES_LIBDIR");
+	if (lib_dir == NULL) {
+		lib_dir = getenv("IP6TABLES_LIB_DIR");
+		if (lib_dir != NULL)
+			fprintf(stderr, "IP6TABLES_LIB_DIR is deprecated\n");
+	}
+	if (lib_dir == NULL)
+		lib_dir = XTABLES_LIBDIR;
 
 #ifdef NO_SHARED_LIBS
 	init_extensions();

Modified: trunk/iptables/iptables-restore.c
===================================================================
--- trunk/iptables/iptables-restore.c	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/iptables-restore.c	2008-04-13 05:25:24 UTC (rev 7471)
@@ -132,9 +132,14 @@
 	program_version = IPTABLES_VERSION;
 	line = 0;
 
-	lib_dir = getenv("IPTABLES_LIB_DIR");
-	if (!lib_dir)
-		lib_dir = IPT_LIB_DIR;
+	lib_dir = getenv("XTABLES_LIBDIR");
+	if (lib_dir == NULL) {
+		lib_dir = getenv("IPTABLES_LIB_DIR");
+		if (lib_dir != NULL)
+			fprintf(stderr, "IPTABLES_LIB_DIR is deprecated\n");
+	}
+	if (lib_dir == NULL)
+		lib_dir = XTABLES_LIBDIR;
 
 #ifdef NO_SHARED_LIBS
 	init_extensions();

Modified: trunk/iptables/iptables-save.c
===================================================================
--- trunk/iptables/iptables-save.c	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/iptables-save.c	2008-04-13 05:25:24 UTC (rev 7471)
@@ -357,9 +357,14 @@
 	program_name = "iptables-save";
 	program_version = IPTABLES_VERSION;
 
-	lib_dir = getenv("IPTABLES_LIB_DIR");
-	if (!lib_dir)
-		lib_dir = IPT_LIB_DIR;
+	lib_dir = getenv("XTABLES_LIBDIR");
+	if (lib_dir == NULL) {
+		lib_dir = getenv("IPTABLES_LIB_DIR");
+		if (lib_dir != NULL)
+			fprintf(stderr, "IPTABLES_LIB_DIR is deprecated\n");
+	}
+	if (lib_dir == NULL)
+		lib_dir = XTABLES_LIBDIR;
 
 #ifdef NO_SHARED_LIBS
 	init_extensions();

Modified: trunk/iptables/iptables-standalone.c
===================================================================
--- trunk/iptables/iptables-standalone.c	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/iptables-standalone.c	2008-04-13 05:25:24 UTC (rev 7471)
@@ -53,9 +53,14 @@
 	program_name = "iptables";
 	program_version = IPTABLES_VERSION;
 
-	lib_dir = getenv("IPTABLES_LIB_DIR");
-	if (!lib_dir)
-		lib_dir = IPT_LIB_DIR;
+	lib_dir = getenv("XTABLES_LIBDIR");
+	if (lib_dir == NULL) {
+		lib_dir = getenv("IPTABLES_LIB_DIR");
+		if (lib_dir != NULL)
+			fprintf(stderr, "IPTABLES_LIB_DIR is deprecated\n");
+	}
+	if (lib_dir == NULL)
+		lib_dir = XTABLES_LIBDIR;
 
 #ifdef NO_SHARED_LIBS
 	init_extensions();

Modified: trunk/iptables/libiptc/libiptc.c
===================================================================
--- trunk/iptables/libiptc/libiptc.c	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/libiptc/libiptc.c	2008-04-13 05:25:24 UTC (rev 7471)
@@ -46,10 +46,6 @@
 #define debug(x, args...)
 #endif
 
-#ifndef IPT_LIB_DIR
-#define IPT_LIB_DIR "/usr/local/lib/iptables"
-#endif
-
 static int sockfd = -1;
 static int sockfd_use = 0;
 static void *iptc_fn = NULL;

Modified: trunk/iptables/xtables.c
===================================================================
--- trunk/iptables/xtables.c	2008-04-13 05:20:50 UTC (rev 7470)
+++ trunk/iptables/xtables.c	2008-04-13 05:25:24 UTC (rev 7471)
@@ -305,12 +305,58 @@
 	}
 }
 
+static void *load_extension(const char *search_path, const char *prefix,
+    const char *name, bool is_target)
+{
+	const char *dir = search_path, *next;
+	void *ptr = NULL;
+	struct stat sb;
+	char path[256];
+
+	do {
+		next = strchr(dir, ':');
+		if (next == NULL)
+			next = dir + strlen(dir);
+		snprintf(path, sizeof(path), "%.*s/libxt_%s.so",
+		         next - dir, dir, name);
+
+		if (dlopen(path, RTLD_NOW) != NULL) {
+			/* Found library.  If it didn't register itself,
+			   maybe they specified target as match. */
+			if (is_target)
+				ptr = find_target(name, DONT_LOAD);
+			else
+				ptr = find_match(name, DONT_LOAD, NULL);
+		} else if (stat(path, &sb) == 0) {
+			fprintf(stderr, "%s: %s\n", path, dlerror());
+		}
+
+		if (ptr != NULL)
+			return ptr;
+
+		snprintf(path, sizeof(path), "%.*s/%s%s.so",
+		         next - dir, dir, prefix, name);
+		if (dlopen(path, RTLD_NOW) != NULL) {
+			if (is_target)
+				ptr = find_target(name, DONT_LOAD);
+			else
+				ptr = find_match(name, DONT_LOAD, NULL);
+		} else if (stat(path, &sb) == 0) {
+			fprintf(stderr, "%s: %s\n", path, dlerror());
+		}
+
+		if (ptr != NULL)
+			return ptr;
+
+		dir = next + 1;
+	} while (*next != '\0');
+
+	return NULL;
+}
+
 struct xtables_match *find_match(const char *name, enum xt_tryload tryload,
 				 struct xtables_rule_match **matches)
 {
-#ifndef NO_SHARED_LIBS
-	struct stat sb;
-#endif
 	struct xtables_match *ptr;
 	const char *icmp6 = "icmp6";
 
@@ -343,26 +389,8 @@
 
 #ifndef NO_SHARED_LIBS
 	if (!ptr && tryload != DONT_LOAD && tryload != DURING_LOAD) {
-		char path[strlen(lib_dir) + sizeof("/.so")
-			  + strlen(afinfo.libprefix) + strlen(name)];
+		ptr = load_extension(lib_dir, afinfo.libprefix, name, false);
 
-		sprintf(path, "%s/libxt_%s.so", lib_dir, name);
-		if (dlopen(path, RTLD_NOW) != NULL)
-			/* Found library.  If it didn't register itself,
-			   maybe they specified target as match. */
-			ptr = find_match(name, DONT_LOAD, NULL);
-		else if (stat(path, &sb) == 0)
-			fprintf(stderr, "%s: %s\n", path, dlerror());
-
-		if (ptr == NULL) {
-			sprintf(path, "%s/%s%s.so", lib_dir, afinfo.libprefix,
-				name);
-			if (dlopen(path, RTLD_NOW) != NULL)
-				ptr = find_match(name, DONT_LOAD, NULL);
-			else if (stat(path, &sb) == 0)
-				fprintf(stderr, "%s: %s\n", path, dlerror());
-		}
-
 		if (ptr == NULL && tryload == LOAD_MUST_SUCCEED)
 			exit_error(PARAMETER_PROBLEM,
 				   "Couldn't load match `%s':%s\n",
@@ -403,9 +431,6 @@
 
 struct xtables_target *find_target(const char *name, enum xt_tryload tryload)
 {
-#ifndef NO_SHARED_LIBS
-	struct stat sb;
-#endif
 	struct xtables_target *ptr;
 
 	/* Standard target? */
@@ -423,25 +448,8 @@
 
 #ifndef NO_SHARED_LIBS
 	if (!ptr && tryload != DONT_LOAD && tryload != DURING_LOAD) {
-		char path[strlen(lib_dir) + sizeof("/.so")
-			  + strlen(afinfo.libprefix) + strlen(name)];
+		ptr = load_extension(lib_dir, afinfo.libprefix, name, true);
 
-		sprintf(path, "%s/libxt_%s.so", lib_dir, name);
-		if (dlopen(path, RTLD_NOW) != NULL)
-			/* Found library.  If it didn't register itself,
-			   maybe they specified match as a target. */
-			ptr = find_target(name, DONT_LOAD);
-		else if (stat(path, &sb) == 0)
-			fprintf(stderr, "%s: %s\n", path, dlerror());
-
-		if (ptr == NULL) {
-			sprintf(path, "%s/%s%s.so", lib_dir, afinfo.libprefix,
-				name);
-			if (dlopen(path, RTLD_NOW) != NULL)
-				ptr = find_target(name, DONT_LOAD);
-			else if (stat(path, &sb) == 0)
-				fprintf(stderr, "%s: %s\n", path, dlerror());
-		}
 		if (ptr == NULL && tryload == LOAD_MUST_SUCCEED)
 			exit_error(PARAMETER_PROBLEM,
 				   "Couldn't load target `%s':%s\n",




More information about the netfilter-cvslog mailing list