[netfilter-cvslog] r6919 - in trunk/iptables: . include
yasuyuki at netfilter.org
yasuyuki at netfilter.org
Tue Jul 24 07:47:40 CEST 2007
Author: yasuyuki at netfilter.org
Date: 2007-07-24 07:47:40 +0200 (Tue, 24 Jul 2007)
New Revision: 6919
Modified:
trunk/iptables/include/ip6tables.h
trunk/iptables/include/iptables_common.h
trunk/iptables/include/xtables.h
trunk/iptables/ip6tables-restore.c
trunk/iptables/ip6tables.c
trunk/iptables/iptables-restore.c
trunk/iptables/iptables.c
trunk/iptables/xtables.c
Log:
Moves ip[6]tables_insmod() to xtables.c as xtables_insmod()
Modified: trunk/iptables/include/ip6tables.h
===================================================================
--- trunk/iptables/include/ip6tables.h 2007-07-24 05:45:33 UTC (rev 6918)
+++ trunk/iptables/include/ip6tables.h 2007-07-24 05:47:40 UTC (rev 6919)
@@ -174,8 +174,6 @@
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*/
Modified: trunk/iptables/include/iptables_common.h
===================================================================
--- trunk/iptables/include/iptables_common.h 2007-07-24 05:45:33 UTC (rev 6918)
+++ trunk/iptables/include/iptables_common.h 2007-07-24 05:47:40 UTC (rev 6919)
@@ -27,8 +27,6 @@
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)));
Modified: trunk/iptables/include/xtables.h
===================================================================
--- trunk/iptables/include/xtables.h 2007-07-24 05:45:33 UTC (rev 6918)
+++ trunk/iptables/include/xtables.h 2007-07-24 05:47:40 UTC (rev 6919)
@@ -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 */
Modified: trunk/iptables/ip6tables-restore.c
===================================================================
--- trunk/iptables/ip6tables-restore.c 2007-07-24 05:45:33 UTC (rev 6918)
+++ trunk/iptables/ip6tables-restore.c 2007-07-24 05:47:40 UTC (rev 6919)
@@ -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 @@
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);
}
Modified: trunk/iptables/ip6tables.c
===================================================================
--- trunk/iptables/ip6tables.c 2007-07-24 05:45:33 UTC (rev 6918)
+++ trunk/iptables/ip6tables.c 2007-07-24 05:47:40 UTC (rev 6919)
@@ -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>
@@ -51,10 +49,6 @@
#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_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 @@
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);
}
Modified: trunk/iptables/iptables-restore.c
===================================================================
--- trunk/iptables/iptables-restore.c 2007-07-24 05:45:33 UTC (rev 6918)
+++ trunk/iptables/iptables-restore.c 2007-07-24 05:47:40 UTC (rev 6919)
@@ -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 @@
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);
}
Modified: trunk/iptables/iptables.c
===================================================================
--- trunk/iptables/iptables.c 2007-07-24 05:45:33 UTC (rev 6918)
+++ trunk/iptables/iptables.c 2007-07-24 05:47:40 UTC (rev 6919)
@@ -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
@@ -49,10 +47,6 @@
#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 @@
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 @@
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);
}
Modified: trunk/iptables/xtables.c
===================================================================
--- trunk/iptables/xtables.c 2007-07-24 05:45:33 UTC (rev 6918)
+++ trunk/iptables/xtables.c 2007-07-24 05:47:40 UTC (rev 6919)
@@ -16,14 +16,27 @@
* 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 @@
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;
+}
+
More information about the netfilter-cvslog
mailing list