Revert "iptables: update to 1.4.18" due to toolchain-issue:
[openwrt.git] / package / network / utils / iptables / patches / 400-lenient-restore.patch
1 --- a/ip6tables-restore.c
2 +++ b/ip6tables-restore.c
3 @@ -16,6 +16,8 @@
4  #include <string.h>
5  #include <stdio.h>
6  #include <stdlib.h>
7 +#include <stdarg.h>
8 +#include <setjmp.h>
9  #include "ip6tables.h"
10  #include "xtables.h"
11  #include "libiptc/libip6tc.h"
12 @@ -27,6 +29,7 @@
13  #define DEBUGP(x, args...)
14  #endif
15  
16 +static jmp_buf jmp;
17  static int binary = 0, counters = 0, verbose = 0, noflush = 0;
18  
19  /* Keeping track of external matches and targets.  */
20 @@ -37,6 +40,7 @@ static const struct option options[] = {
21         {.name = "test",     .has_arg = false, .val = 't'},
22         {.name = "help",     .has_arg = false, .val = 'h'},
23         {.name = "noflush",  .has_arg = false, .val = 'n'},
24 +       {.name = "lenient",  .has_arg = false, .val = 'l'},
25         {.name = "modprobe", .has_arg = true,  .val = 'M'},
26         {NULL},
27  };
28 @@ -52,6 +56,7 @@ static void print_usage(const char *name
29                         "          [ --test ]\n"
30                         "          [ --help ]\n"
31                         "          [ --noflush ]\n"
32 +                       "          [ --lenient ]\n"
33                         "          [ --modprobe=<command>]\n", name);
34  
35         exit(1);
36 @@ -114,6 +119,17 @@ static void free_argv(void) {
37                 free(newargv[i]);
38  }
39  
40 +static void catch_exit_error(enum xtables_exittype status, const char *msg, ...)
41 +{
42 +       va_list args;
43 +       fprintf(stderr, "line %d: ", line);
44 +       va_start(args, msg);
45 +       vfprintf(stderr, msg, args);
46 +       va_end(args);
47 +       fprintf(stderr, "\n");
48 +       longjmp(jmp, status);
49 +}
50 +
51  #ifdef IPTABLES_MULTI
52  int ip6tables_restore_main(int argc, char *argv[])
53  #else
54 @@ -141,7 +157,7 @@ int main(int argc, char *argv[])
55         init_extensions();
56  #endif
57  
58 -       while ((c = getopt_long(argc, argv, "bcvthnM:", options, NULL)) != -1) {
59 +       while ((c = getopt_long(argc, argv, "bcvthnlM:", options, NULL)) != -1) {
60                 switch (c) {
61                         case 'b':
62                                 binary = 1;
63 @@ -162,6 +178,9 @@ int main(int argc, char *argv[])
64                         case 'n':
65                                 noflush = 1;
66                                 break;
67 +                       case 'l':
68 +                               ip6tables_globals.exit_err = catch_exit_error;
69 +                               break;
70                         case 'M':
71                                 xtables_modprobe_program = optarg;
72                                 break;
73 @@ -440,8 +459,11 @@ int main(int argc, char *argv[])
74                         for (a = 0; a < newargc; a++)
75                                 DEBUGP("argv[%u]: %s\n", a, newargv[a]);
76  
77 -                       ret = do_command6(newargc, newargv,
78 -                                        &newargv[2], &handle);
79 +                       if (!setjmp(jmp))
80 +                               ret = do_command6(newargc, newargv,
81 +                                                &newargv[2], &handle);
82 +                       else
83 +                               ret = 1;
84  
85                         free_argv();
86                         fflush(stdout);
87 --- a/iptables-restore.c
88 +++ b/iptables-restore.c
89 @@ -13,6 +13,8 @@
90  #include <string.h>
91  #include <stdio.h>
92  #include <stdlib.h>
93 +#include <stdarg.h>
94 +#include <setjmp.h>
95  #include "iptables.h"
96  #include "xtables.h"
97  #include "libiptc/libiptc.h"
98 @@ -24,6 +26,7 @@
99  #define DEBUGP(x, args...)
100  #endif
101  
102 +static jmp_buf jmp;
103  static int binary = 0, counters = 0, verbose = 0, noflush = 0;
104  
105  /* Keeping track of external matches and targets.  */
106 @@ -34,6 +37,7 @@ static const struct option options[] = {
107         {.name = "test",     .has_arg = false, .val = 't'},
108         {.name = "help",     .has_arg = false, .val = 'h'},
109         {.name = "noflush",  .has_arg = false, .val = 'n'},
110 +       {.name = "lenient",  .has_arg = false, .val = 'l'},
111         {.name = "modprobe", .has_arg = true,  .val = 'M'},
112         {.name = "table",    .has_arg = true,  .val = 'T'},
113         {NULL},
114 @@ -52,6 +56,7 @@ static void print_usage(const char *name
115                         "          [ --test ]\n"
116                         "          [ --help ]\n"
117                         "          [ --noflush ]\n"
118 +                       "          [ --lenient ]\n"
119                         "          [ --table=<TABLE> ]\n"
120                         "          [ --modprobe=<command>]\n", name);
121  
122 @@ -114,6 +119,17 @@ static void free_argv(void) {
123                 free(newargv[i]);
124  }
125  
126 +static void catch_exit_error(enum xtables_exittype status, const char *msg, ...)
127 +{
128 +       va_list args;
129 +       fprintf(stderr, "line %d: ", line);
130 +       va_start(args, msg);
131 +       vfprintf(stderr, msg, args);
132 +       va_end(args);
133 +       fprintf(stderr, "\n");
134 +       longjmp(jmp, status);
135 +}
136 +
137  #ifdef IPTABLES_MULTI
138  int
139  iptables_restore_main(int argc, char *argv[])
140 @@ -144,7 +160,7 @@ main(int argc, char *argv[])
141         init_extensions();
142  #endif
143  
144 -       while ((c = getopt_long(argc, argv, "bcvthnM:T:", options, NULL)) != -1) {
145 +       while ((c = getopt_long(argc, argv, "bcvthnlM:T:", options, NULL)) != -1) {
146                 switch (c) {
147                         case 'b':
148                                 binary = 1;
149 @@ -165,6 +181,9 @@ main(int argc, char *argv[])
150                         case 'n':
151                                 noflush = 1;
152                                 break;
153 +                       case 'l':
154 +                               iptables_globals.exit_err = catch_exit_error;
155 +                               break;
156                         case 'M':
157                                 xtables_modprobe_program = optarg;
158                                 break;
159 @@ -445,8 +464,11 @@ main(int argc, char *argv[])
160                         for (a = 0; a < newargc; a++)
161                                 DEBUGP("argv[%u]: %s\n", a, newargv[a]);
162  
163 -                       ret = do_command(newargc, newargv,
164 -                                        &newargv[2], &handle);
165 +                       if (!setjmp(jmp))
166 +                               ret = do_command(newargc, newargv,
167 +                                                &newargv[2], &handle);
168 +                       else
169 +                               ret = 1;
170  
171                         free_argv();
172                         fflush(stdout);