@@ -25,7 +25,7 @@ const struct fw3_option fw3_cthelper_opts[] = {
25
25
FW3_OPT ("module" , string , cthelper , module ),
26
26
FW3_OPT ("description" , string , cthelper , description ),
27
27
FW3_OPT ("family" , family , cthelper , family ),
28
- FW3_OPT ("proto" , protocol , cthelper , proto ),
28
+ FW3_LIST ("proto" , protocol , cthelper , proto ),
29
29
FW3_OPT ("port" , port , cthelper , port ),
30
30
31
31
{ }
@@ -46,6 +46,23 @@ test_module(struct fw3_cthelper *helper)
46
46
return true;
47
47
}
48
48
49
+ static bool
50
+ check_cthelper_proto (const struct fw3_cthelper * helper )
51
+ {
52
+ struct fw3_protocol * proto ;
53
+
54
+ if (list_empty (& helper -> proto ))
55
+ return false;
56
+
57
+ list_for_each_entry (proto , & helper -> proto , list )
58
+ {
59
+ if (!proto -> protocol || proto -> any || proto -> invert )
60
+ return false;
61
+ }
62
+
63
+ return true;
64
+ }
65
+
49
66
static bool
50
67
check_cthelper (struct fw3_state * state , struct fw3_cthelper * helper , struct uci_element * e )
51
68
{
@@ -57,7 +74,7 @@ check_cthelper(struct fw3_state *state, struct fw3_cthelper *helper, struct uci_
57
74
{
58
75
warn_section ("helper" , helper , e , "must have a module assigned" );
59
76
}
60
- else if (!helper -> proto . protocol || helper -> proto . any || helper -> proto . invert )
77
+ else if (!check_cthelper_proto ( helper ) )
61
78
{
62
79
warn_section ("helper" , helper , e , "must specify a protocol" );
63
80
}
@@ -84,6 +101,7 @@ fw3_alloc_cthelper(struct fw3_state *state)
84
101
85
102
helper -> enabled = true;
86
103
helper -> family = FW3_FAMILY_ANY ;
104
+ INIT_LIST_HEAD (& helper -> proto );
87
105
88
106
list_add_tail (& helper -> list , & state -> cthelpers );
89
107
@@ -157,6 +175,20 @@ fw3_lookup_cthelper(struct fw3_state *state, const char *name)
157
175
return NULL ;
158
176
}
159
177
178
+ bool
179
+ fw3_cthelper_check_proto (const struct fw3_cthelper * h , const struct fw3_protocol * proto )
180
+ {
181
+ struct fw3_protocol * p ;
182
+
183
+ list_for_each_entry (p , & h -> proto , list )
184
+ {
185
+ if (p -> protocol == proto -> protocol )
186
+ return true;
187
+ }
188
+
189
+ return false;
190
+ }
191
+
160
192
struct fw3_cthelper *
161
193
fw3_lookup_cthelper_by_proto_port (struct fw3_state * state ,
162
194
struct fw3_protocol * proto ,
@@ -178,7 +210,7 @@ fw3_lookup_cthelper_by_proto_port(struct fw3_state *state,
178
210
if (!h -> enabled )
179
211
continue ;
180
212
181
- if (h -> proto . protocol != proto -> protocol )
213
+ if (! fw3_cthelper_check_proto ( h , proto ) )
182
214
continue ;
183
215
184
216
if (h -> port .set && (!port || !port -> set ))
@@ -198,11 +230,11 @@ fw3_lookup_cthelper_by_proto_port(struct fw3_state *state,
198
230
199
231
static void
200
232
print_helper_rule (struct fw3_ipt_handle * handle , struct fw3_cthelper * helper ,
201
- struct fw3_zone * zone )
233
+ struct fw3_zone * zone , struct fw3_protocol * proto )
202
234
{
203
235
struct fw3_ipt_rule * r ;
204
236
205
- r = fw3_ipt_rule_create (handle , & helper -> proto , NULL , NULL , NULL , NULL );
237
+ r = fw3_ipt_rule_create (handle , proto , NULL , NULL , NULL , NULL );
206
238
207
239
if (helper -> description && * helper -> description )
208
240
fw3_ipt_rule_comment (r , helper -> description );
@@ -215,6 +247,16 @@ print_helper_rule(struct fw3_ipt_handle *handle, struct fw3_cthelper *helper,
215
247
fw3_ipt_rule_replace (r , "zone_%s_helper" , zone -> name );
216
248
}
217
249
250
+ static void
251
+ expand_helper_rule (struct fw3_ipt_handle * handle , struct fw3_cthelper * helper ,
252
+ struct fw3_zone * zone )
253
+ {
254
+ struct fw3_protocol * proto ;
255
+
256
+ list_for_each_entry (proto , & helper -> proto , list )
257
+ print_helper_rule (handle , helper , zone , proto );
258
+ }
259
+
218
260
void
219
261
fw3_print_cthelpers (struct fw3_ipt_handle * handle , struct fw3_state * state ,
220
262
struct fw3_zone * zone )
@@ -249,7 +291,7 @@ fw3_print_cthelpers(struct fw3_ipt_handle *handle, struct fw3_state *state,
249
291
if (!test_module (helper ))
250
292
continue ;
251
293
252
- print_helper_rule (handle , helper , zone );
294
+ expand_helper_rule (handle , helper , zone );
253
295
}
254
296
}
255
297
else
@@ -271,7 +313,7 @@ fw3_print_cthelpers(struct fw3_ipt_handle *handle, struct fw3_state *state,
271
313
continue ;
272
314
}
273
315
274
- print_helper_rule (handle , helper , zone );
316
+ expand_helper_rule (handle , helper , zone );
275
317
}
276
318
}
277
319
}
0 commit comments