]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
Moves ip[6]tables_insmod() to xtables.c as xtables_insmod()
authorYasuyuki KOZAKAI <yasuyuki@netfilter.org>
Tue, 24 Jul 2007 05:47:40 +0000 (05:47 +0000)
committerYasuyuki KOZAKAI <yasuyuki@netfilter.org>
Tue, 24 Jul 2007 05:47:40 +0000 (05:47 +0000)
include/ip6tables.h
include/iptables_common.h
include/xtables.h
ip6tables-restore.c
ip6tables.c
iptables-restore.c
iptables.c
xtables.c

index 8afe2ce3fa473ce10556ab304de6b0eebfc457b7..b6757a32d1f367be3cfab0dbd2a2adf1ed81a9f0 100644 (file)
@@ -174,8 +174,6 @@ extern void parse_interface(const char *arg, char *vianame, unsigned char *mask)
 extern int for_each_chain(int (*fn)(const ip6t_chainlabel, int, ip6tc_handle_t *), int verbose, int builtinstoo, ip6tc_handle_t *handle);
 extern int flush_entries(const ip6t_chainlabel chain, int verbose, ip6tc_handle_t *handle);
 extern int delete_chain(const ip6t_chainlabel chain, int verbose, ip6tc_handle_t *handle);
-extern int
-ip6tables_insmod(const char *modname, const char *modprobe, int quiet);
 extern int load_ip6tables_ko(const char *modprobe, int quiet);
 
 #endif /*_IP6TABLES_USER_H*/
index 3b29327bd93c72f8ebd413b4f382dd56596d1a07..3b61e72d0656acd3536291124d89288c18c42748 100644 (file)
@@ -27,8 +27,6 @@ extern int string_to_number_ll(const char *,
                            unsigned long long int, 
                            unsigned long long int,
                            unsigned long long *);
-extern int
-iptables_insmod(const char *modname, const char *modprobe, int quiet);
 extern int load_iptables_ko(const char *modprobe, int quiet);
 void exit_error(enum exittype, char *, ...)__attribute__((noreturn,
                                                          format(printf,2,3)));
index 6ef13fe18b693d42237efbffc8be048b8300db2f..97395f3fba2e27bb5566e7f748717423b9219763 100644 (file)
@@ -4,4 +4,7 @@
 extern void *fw_calloc(size_t count, size_t size);
 extern void *fw_malloc(size_t size);
 
+extern const char *modprobe;
+extern int xtables_insmod(const char *modname, const char *modprobe, int quiet);
+
 #endif /* _XTABLES_H */
index 25c6ebd9d6c4f39d30eaf3f5a73ff2f5dc1e8962..bc32c06ee933197fb37a47c411cc411ef06568d2 100644 (file)
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "ip6tables.h"
+#include "xtables.h"
 #include "libiptc/libip6tc.h"
 
 #ifdef DEBUG
@@ -62,7 +63,7 @@ ip6tc_handle_t create_handle(const char *tablename, const char* modprobe)
 
        if (!handle) {
                /* try to insmod the module if iptc_init failed */
-               ip6tables_insmod("ip6_tables", modprobe, 0);
+               xtables_insmod("ip6_tables", modprobe, 0);
                handle = ip6tc_init(tablename);
        }
 
index a096b7952fad962e3a9fbdc3ccbdd8a1954ea352..2a06bc04c401554ecb583cb827a7597ddbc3bfaa 100644 (file)
@@ -31,7 +31,6 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <dlfcn.h>
 #include <ctype.h>
 #include <stdarg.h>
 #include <limits.h>
@@ -40,7 +39,6 @@
 #include <arpa/inet.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 
 #define FALSE 0
 #endif
 
-#ifndef PROC_SYS_MODPROBE
-#define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe"
-#endif
-
 #define FMT_NUMERIC    0x0001
 #define FMT_NOCOUNTS   0x0002
 #define FMT_KILOMEGAGIGA 0x0004
@@ -193,9 +187,6 @@ const char *program_version;
 const char *program_name;
 char *lib_dir;
 
-/* the path to command to load kernel module */
-const char *modprobe = NULL;
-
 /* Keeping track of external matches and targets: linked lists.  */
 struct ip6tables_match *ip6tables_matches = NULL;
 struct ip6tables_target *ip6tables_targets = NULL;
@@ -1699,83 +1690,13 @@ list_entries(const ip6t_chainlabel chain, int verbose, int numeric,
        return found;
 }
 
-static char *get_modprobe(void)
-{
-       int procfile;
-       char *ret;
-
-#define PROCFILE_BUFSIZ 1024
-       procfile = open(PROC_SYS_MODPROBE, O_RDONLY);
-       if (procfile < 0)
-               return NULL;
-
-       ret = malloc(PROCFILE_BUFSIZ);
-       if (ret) {
-               memset(ret, 0, PROCFILE_BUFSIZ);
-               switch (read(procfile, ret, PROCFILE_BUFSIZ)) {
-               case -1: goto fail;
-               case PROCFILE_BUFSIZ: goto fail; /* Partial read.  Wierd */
-               }
-               if (ret[strlen(ret)-1]=='\n') 
-                       ret[strlen(ret)-1]=0;
-               close(procfile);
-               return ret;
-       }
- fail:
-       free(ret);
-       close(procfile);
-       return NULL;
-}
-
-int ip6tables_insmod(const char *modname, const char *modprobe, int quiet)
-{
-       char *buf = NULL;
-       char *argv[4];
-       int status;
-
-       /* If they don't explicitly set it, read out of kernel */
-       if (!modprobe) {
-               buf = get_modprobe();
-               if (!buf)
-                       return -1;
-               modprobe = buf;
-       }
-
-       switch (fork()) {
-       case 0:
-               argv[0] = (char *)modprobe;
-               argv[1] = (char *)modname;
-               if (quiet) {
-                       argv[2] = "-q";
-                       argv[3] = NULL;
-               } else {
-                       argv[2] = NULL;
-                       argv[3] = NULL;
-               }
-               execv(argv[0], argv);
-
-               /* not usually reached */
-               exit(1);
-       case -1:
-               return -1;
-
-       default: /* parent */
-               wait(&status);
-       }
-
-       free(buf);
-       if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
-               return 0;
-       return -1;
-}
-
 int load_ip6tables_ko(const char *modprobe, int quiet)
 {
        static int loaded = 0;
        static int ret = -1;
 
        if (!loaded) {
-               ret = ip6tables_insmod("ip6_tables", modprobe, quiet);
+               ret = xtables_insmod("ip6_tables", modprobe, quiet);
                loaded = (ret == 0);
        }
 
index 61631ae77951157c232b6c6e04fdd946f03ab22f..66918a022c0f6605c7081e13f1918c7f610cc98d 100644 (file)
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "iptables.h"
+#include "xtables.h"
 #include "libiptc/libiptc.h"
 
 #ifdef DEBUG
@@ -59,7 +60,7 @@ iptc_handle_t create_handle(const char *tablename, const char* modprobe )
 
        if (!handle) {
                /* try to insmod the module if iptc_init failed */
-               iptables_insmod("ip_tables", modprobe, 0);
+               xtables_insmod("ip_tables", modprobe, 0);
                handle = iptc_init(tablename);
        }
 
index 166016e35e611ae23462ec3f60d344e0fceaf077..39b8e0156a9cf24326ca8770f87bdc182e5afa5d 100644 (file)
@@ -31,7 +31,6 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <dlfcn.h>
 #include <ctype.h>
 #include <stdarg.h>
 #include <limits.h>
@@ -39,7 +38,6 @@
 #include <iptables.h>
 #include <xtables.h>
 #include <fcntl.h>
-#include <sys/wait.h>
 #include <sys/utsname.h>
 
 #ifndef TRUE
 #define FALSE 0
 #endif
 
-#ifndef PROC_SYS_MODPROBE
-#define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe"
-#endif
-
 #define FMT_NUMERIC    0x0001
 #define FMT_NOCOUNTS   0x0002
 #define FMT_KILOMEGAGIGA 0x0004
@@ -197,9 +191,6 @@ char *lib_dir;
 
 int kernel_version;
 
-/* the path to command to load kernel module */
-const char *modprobe = NULL;
-
 /* Keeping track of external matches and targets: linked lists.  */
 struct iptables_match *iptables_matches = NULL;
 struct iptables_target *iptables_targets = NULL;
@@ -1763,83 +1754,13 @@ list_entries(const ipt_chainlabel chain, int verbose, int numeric,
        return found;
 }
 
-static char *get_modprobe(void)
-{
-       int procfile;
-       char *ret;
-
-#define PROCFILE_BUFSIZ        1024
-       procfile = open(PROC_SYS_MODPROBE, O_RDONLY);
-       if (procfile < 0)
-               return NULL;
-
-       ret = (char *) malloc(PROCFILE_BUFSIZ);
-       if (ret) {
-               memset(ret, 0, PROCFILE_BUFSIZ);
-               switch (read(procfile, ret, PROCFILE_BUFSIZ)) {
-               case -1: goto fail;
-               case PROCFILE_BUFSIZ: goto fail; /* Partial read.  Wierd */
-               }
-               if (ret[strlen(ret)-1]=='\n') 
-                       ret[strlen(ret)-1]=0;
-               close(procfile);
-               return ret;
-       }
- fail:
-       free(ret);
-       close(procfile);
-       return NULL;
-}
-
-int iptables_insmod(const char *modname, const char *modprobe, int quiet)
-{
-       char *buf = NULL;
-       char *argv[4];
-       int status;
-
-       /* If they don't explicitly set it, read out of kernel */
-       if (!modprobe) {
-               buf = get_modprobe();
-               if (!buf)
-                       return -1;
-               modprobe = buf;
-       }
-
-       switch (fork()) {
-       case 0:
-               argv[0] = (char *)modprobe;
-               argv[1] = (char *)modname;
-               if (quiet) {
-                       argv[2] = "-q";
-                       argv[3] = NULL;
-               } else {
-                       argv[2] = NULL;
-                       argv[3] = NULL;
-               }
-               execv(argv[0], argv);
-
-               /* not usually reached */
-               exit(1);
-       case -1:
-               return -1;
-
-       default: /* parent */
-               wait(&status);
-       }
-
-       free(buf);
-       if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
-               return 0;
-       return -1;
-}
-
 int load_iptables_ko(const char *modprobe, int quiet)
 {
        static int loaded = 0;
        static int ret = -1;
 
        if (!loaded) {
-               ret = iptables_insmod("ip_tables", modprobe, quiet);
+               ret = xtables_insmod("ip_tables", modprobe, quiet);
                loaded = (ret == 0);
        }
 
index 667656a00b88bc54b01d51e9bd62742afea720ef..1b65b95408055a5d0847b87c9bb5375c8c28a48c 100644 (file)
--- a/xtables.c
+++ b/xtables.c
  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-
+#include <dlfcn.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 #include <iptables_common.h>
 #include <xtables.h>
 
+#ifndef PROC_SYS_MODPROBE
+#define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe"
+#endif
+
+/* the path to command to load kernel module */
+const char *modprobe = NULL;
+
 void *fw_calloc(size_t count, size_t size)
 {
        void *p;
@@ -47,3 +60,74 @@ void *fw_malloc(size_t size)
 
        return p;
 }
+
+static char *get_modprobe(void)
+{
+       int procfile;
+       char *ret;
+
+#define PROCFILE_BUFSIZ        1024
+       procfile = open(PROC_SYS_MODPROBE, O_RDONLY);
+       if (procfile < 0)
+               return NULL;
+
+       ret = (char *) malloc(PROCFILE_BUFSIZ);
+       if (ret) {
+               memset(ret, 0, PROCFILE_BUFSIZ);
+               switch (read(procfile, ret, PROCFILE_BUFSIZ)) {
+               case -1: goto fail;
+               case PROCFILE_BUFSIZ: goto fail; /* Partial read.  Wierd */
+               }
+               if (ret[strlen(ret)-1]=='\n') 
+                       ret[strlen(ret)-1]=0;
+               close(procfile);
+               return ret;
+       }
+ fail:
+       free(ret);
+       close(procfile);
+       return NULL;
+}
+
+int xtables_insmod(const char *modname, const char *modprobe, int quiet)
+{
+       char *buf = NULL;
+       char *argv[4];
+       int status;
+
+       /* If they don't explicitly set it, read out of kernel */
+       if (!modprobe) {
+               buf = get_modprobe();
+               if (!buf)
+                       return -1;
+               modprobe = buf;
+       }
+
+       switch (fork()) {
+       case 0:
+               argv[0] = (char *)modprobe;
+               argv[1] = (char *)modname;
+               if (quiet) {
+                       argv[2] = "-q";
+                       argv[3] = NULL;
+               } else {
+                       argv[2] = NULL;
+                       argv[3] = NULL;
+               }
+               execv(argv[0], argv);
+
+               /* not usually reached */
+               exit(1);
+       case -1:
+               return -1;
+
+       default: /* parent */
+               wait(&status);
+       }
+
+       free(buf);
+       if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+               return 0;
+       return -1;
+}
+