]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
Combine IP{,6}T_LIB_DIR into XTABLES_LIBDIR
authorJan Engelhardt <jengelh@medozas.de>
Mon, 11 Feb 2008 00:02:00 +0000 (01:02 +0100)
committerPatrick McHardy <kaber@trash.net>
Sun, 13 Apr 2008 05:25:24 +0000 (07:25 +0200)
12 files changed:
configure.ac
extensions/GNUmakefile.in
include/ip6tables.h
include/iptables.h
ip6tables-restore.c
ip6tables-save.c
ip6tables-standalone.c
iptables-restore.c
iptables-save.c
iptables-standalone.c
libiptc/libiptc.c
xtables.c

index c816b2e16c667887e1497dc350e5a4c14e13cb4a..5aa0557a120edf7d30aff16274744f0128157462 100644 (file)
@@ -22,11 +22,11 @@ AC_ARG_WITH([ksource],
        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 @@ regular_CFLAGS="-D_LARGEFILE_SOURCE=1 -D_LARGE_FILES -D_FILE_OFFSET_BITS=64 \
        -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])
index cf094f2f461c34a39fc44393057f8001aafd20d9..ee204697f826dc8d1a8cc24e3159cdbbdb8c8f34 100644 (file)
@@ -7,7 +7,7 @@ prefix      := @prefix@
 exec_prefix := @exec_prefix@
 libdir      := @libdir@
 libexecdir  := @libexecdir@
-iptdir      := @iptdir@
+xtlibdir    := @xtlibdir@
 
 CC             := @CC@
 CCLD           := ${CC}
@@ -82,8 +82,8 @@ targets_install :=
 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;
index 4a511b77168202c4e4fb35d8b7849cff1179e9af..e1539eb299f41b62c911729f33b8e75163e8f2aa 100644 (file)
@@ -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
index 7ce9080175278e407baad312c5a18e65ab4f2c37..094c64e754a9c92d4fc941cf3aa0d6cf1505d80f 100644 (file)
@@ -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)
index e9cc0ff8985f9f2422936e527d2e768013324e55..2c3e95de4fa6d33cce1d9cb845a6a13c3b44ce59 100644 (file)
@@ -131,9 +131,14 @@ int main(int argc, char *argv[])
        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();
index e7eade17df65f63c4e14645aec1685cd773bfb49..e4408872c4c61b3875a7618493b31d48e90cb0e3 100644 (file)
@@ -332,9 +332,14 @@ int main(int argc, char *argv[])
        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();
index 4029c1f60de1fd47c79dfbbcb56a29e6978308ac..1bb81bc66f00e83a2085f67a3fc2d6978d597c15 100644 (file)
@@ -52,9 +52,14 @@ main(int argc, char *argv[])
        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();
index b751d2c88958b2ca12ed58725d510856f1a6cc1f..f556fa54f0cb254c7005026d1b26320d25e61608 100644 (file)
@@ -132,9 +132,14 @@ main(int argc, char *argv[])
        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();
index c0c37eda1b74a3fd12bc973d1e43248c20fb53dc..1ce2090174cd17c318cbeb3166063f5e2067c10e 100644 (file)
@@ -357,9 +357,14 @@ main(int argc, char *argv[])
        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();
index 55c7ce980850e9838bfa66b7cf1a1c8fe2589182..369adaf93ec4d52531f4452bcb87006a7471777c 100644 (file)
@@ -53,9 +53,14 @@ main(int argc, char *argv[])
        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();
index de8dc60ede89de41d3c2322621b9f4b4de0a6128..2b788c198b6edfc30aca1924de92cda40becafd8 100644 (file)
 #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;
index 89863d7b0f79d4fe095b0d6e15df6d64d1ad686b..b26b416191c46fde7f865da475ec2649b63366a9 100644 (file)
--- a/xtables.c
+++ b/xtables.c
@@ -305,12 +305,58 @@ void parse_interface(const char *arg, char *vianame, unsigned char *mask)
        }
 }
 
+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,25 +389,7 @@ struct xtables_match *find_match(const char *name, enum xt_tryload tryload,
 
 #ifndef NO_SHARED_LIBS
        if (!ptr && tryload != DONT_LOAD && tryload != DURING_LOAD) {
-               char path[strlen(lib_dir) + sizeof("/.so")
-                         + strlen(afinfo.libprefix) + strlen(name)];
-
-               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());
-               }
+               ptr = load_extension(lib_dir, afinfo.libprefix, name, false);
 
                if (ptr == NULL && tryload == LOAD_MUST_SUCCEED)
                        exit_error(PARAMETER_PROBLEM,
@@ -403,9 +431,6 @@ struct xtables_match *find_match(const char *name, enum xt_tryload tryload,
 
 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 @@ struct xtables_target *find_target(const char *name, enum xt_tryload tryload)
 
 #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",