]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
iptables-save: module loading corrections
authorJan Engelhardt <jengelh@medozas.de>
Thu, 19 Mar 2009 15:57:35 +0000 (16:57 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Thu, 19 Mar 2009 15:57:35 +0000 (16:57 +0100)
1. Ignore the absence of /proc/net/ip_tables_names, which happens
when x_tables.ko is not loaded. This is equivalent to having
x_tables.ko, but no tabe modules, loaded. As such, success should
be returned.

2. Load table when explicitly requested by the -t option. Users might
expect "*foo" etc. to be output when `iptables-save -t foo` is
executed. So do autoload x_tables.ko and the table in this case.

*. Do this for both iptables-save and ip6tables-save, and adjust
the manpages for the new -M (modprobe program location) option that
is introduced.

Based upon a patch by Soren Hansen.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
ip6tables-save.8
ip6tables-save.c
iptables-save.8
iptables-save.c

index c8b3e96af0a32bdd37cf3d37e22e7a4f6013e754..47eb44ad2249b0c9a942601446fa9913e311abeb 100644 (file)
@@ -21,7 +21,7 @@
 .SH NAME
 ip6tables-save \- Save IPv6 Tables
 .SH SYNOPSIS
-.BR "ip6tables-save " "[-c] [-t table]"
+.BR "ip6tables-save " "[-M modprobe] [-c] [-t table]"
 .br
 .SH DESCRIPTION
 .PP
@@ -29,6 +29,10 @@ ip6tables-save \- Save IPv6 Tables
 is used to dump the contents of an IPv6 Table in easily parseable format
 to STDOUT. Use I/O-redirection provided by your shell to write to a file.
 .TP
+\fB\-M\fP \fImodprobe_program\fP
+Specify the path to the modprobe program. By default, iptables-save will
+inspect /proc/sys/kernel/modprobe to determine the executable's path.
+.TP
 \fB\-c\fR, \fB\-\-counters\fR
 include the current values of all packet and byte counters in the output
 .TP
index 55010c44ecd7562943ee0d2c5b11b9e434bae766..97205c1c9e11b66d2e13535d2a67ad23d2d10e81 100644 (file)
@@ -29,6 +29,7 @@ static const struct option options[] = {
        {.name = "counters", .has_arg = false, .val = 'c'},
        {.name = "dump",     .has_arg = false, .val = 'd'},
        {.name = "table",    .has_arg = true,  .val = 't'},
+       {.name = "modprobe", .has_arg = true,  .val = 'M'},
        {NULL},
 };
 
@@ -42,9 +43,7 @@ static int for_each_table(int (*func)(const char *tablename))
 
        procfile = fopen("/proc/net/ip6_tables_names", "r");
        if (!procfile)
-               xtables_error(OTHER_PROBLEM,
-                          "Unable to open /proc/net/ip6_tables_names: %s\n",
-                          strerror(errno));
+               return ret;
 
        while (fgets(tablename, sizeof(tablename), procfile)) {
                if (tablename[strlen(tablename) - 1] != '\n')
@@ -68,6 +67,10 @@ static int do_output(const char *tablename)
                return for_each_table(&do_output);
 
        h = ip6tc_init(tablename);
+       if (h == NULL) {
+               xtables_load_ko(xtables_modprobe_program, false);
+               h = ip6tc_init(tablename);
+       }
        if (!h)
                xtables_error(OTHER_PROBLEM, "Cannot initialize: %s\n",
                           ip6tc_strerror(errno));
@@ -162,6 +165,9 @@ int main(int argc, char *argv[])
                        /* Select specific table. */
                        tablename = optarg;
                        break;
+               case 'M':
+                       xtables_modprobe_program = optarg;
+                       break;
                case 'd':
                        do_output(tablename);
                        exit(0);
index f9c7d6533da5b7f38177deb8a611afb20b048128..de5fd48b09b0bc9efe121b6038d8c884286bbf8c 100644 (file)
@@ -21,7 +21,7 @@
 .SH NAME
 iptables-save \- Save IP Tables
 .SH SYNOPSIS
-.BR "iptables-save " "[-c] [-t table]"
+.BR "iptables-save " "[-M modprobe] [-c] [-t table]"
 .br
 .SH DESCRIPTION
 .PP
@@ -29,6 +29,10 @@ iptables-save \- Save IP Tables
 is used to dump the contents of an IP Table in easily parseable format
 to STDOUT. Use I/O-redirection provided by your shell to write to a file.
 .TP
+\fB\-M\fP \fImodprobe_program\fP
+Specify the path to the modprobe program. By default, iptables-save will
+inspect /proc/sys/kernel/modprobe to determine the executable's path.
+.TP
 \fB\-c\fR, \fB\-\-counters\fR
 include the current values of all packet and byte counters in the output
 .TP
index 55cfe6a1472d96657104a0ae1b52cc22efed137c..6000b494c5b770062afd1d9730bb78bbea049ad7 100644 (file)
@@ -28,6 +28,7 @@ static const struct option options[] = {
        {.name = "counters", .has_arg = false, .val = 'c'},
        {.name = "dump",     .has_arg = false, .val = 'd'},
        {.name = "table",    .has_arg = true,  .val = 't'},
+       {.name = "modprobe", .has_arg = true,  .val = 'M'},
        {NULL},
 };
 
@@ -40,9 +41,7 @@ static int for_each_table(int (*func)(const char *tablename))
 
        procfile = fopen("/proc/net/ip_tables_names", "r");
        if (!procfile)
-               xtables_error(OTHER_PROBLEM,
-                          "Unable to open /proc/net/ip_tables_names: %s\n",
-                          strerror(errno));
+               return ret;
 
        while (fgets(tablename, sizeof(tablename), procfile)) {
                if (tablename[strlen(tablename) - 1] != '\n')
@@ -66,6 +65,10 @@ static int do_output(const char *tablename)
                return for_each_table(&do_output);
 
        h = iptc_init(tablename);
+       if (h == NULL) {
+               xtables_load_ko(xtables_modprobe_program, false);
+               h = iptc_init(tablename);
+       }
        if (!h)
                xtables_error(OTHER_PROBLEM, "Cannot initialize: %s\n",
                           iptc_strerror(errno));
@@ -162,6 +165,9 @@ main(int argc, char *argv[])
                        /* Select specific table. */
                        tablename = optarg;
                        break;
+               case 'M':
+                       xtables_modprobe_program = optarg;
+                       break;
                case 'd':
                        do_output(tablename);
                        exit(0);