]> granicus.if.org Git - ipset/blob - lib/ipset_list_set.c
45934e73323d307d78cf17cf4efced9ccc7dc214
[ipset] / lib / ipset_list_set.c
1 /* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation.
6  */
7 #include <libipset/data.h>                      /* IPSET_OPT_* */
8 #include <libipset/parse.h>                     /* parser functions */
9 #include <libipset/print.h>                     /* printing functions */
10 #include <libipset/types.h>                     /* prototypes */
11
12 /* Parse commandline arguments */
13 static const struct ipset_arg list_set_create_args0[] = {
14         { .name = { "size", NULL },
15           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_SIZE,
16           .parse = ipset_parse_uint32,          .print = ipset_print_number,
17         },
18         { .name = { "timeout", NULL },
19           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_TIMEOUT,
20           .parse = ipset_parse_timeout,         .print = ipset_print_number,
21         },
22         { },
23 };
24
25 static const struct ipset_arg list_set_adt_args0[] = {
26         { .name = { "timeout", NULL },
27           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_TIMEOUT,
28           .parse = ipset_parse_timeout,         .print = ipset_print_number,
29         },
30         { .name = { "before", NULL },
31           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_NAMEREF,
32           .parse = ipset_parse_before,
33         },
34         { .name = { "after", NULL },
35           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_NAMEREF,
36           .parse = ipset_parse_after,
37         },
38         { },
39 };
40
41 static const char list_set_usage0[] =
42 "create SETNAME list:set\n"
43 "               [size VALUE] [timeout VALUE]\n"
44 "add    SETNAME NAME [before|after NAME] [timeout VALUE]\n"
45 "del    SETNAME NAME [before|after NAME]\n"
46 "test   SETNAME NAME [before|after NAME]\n\n"
47 "where NAME are existing set names.\n";
48
49 static struct ipset_type ipset_list_set0 = {
50         .name = "list:set",
51         .alias = { "setlist", NULL },
52         .revision = 0,
53         .family = NFPROTO_UNSPEC,
54         .dimension = IPSET_DIM_ONE,
55         .elem = {
56                 [IPSET_DIM_ONE - 1] = {
57                         .parse = ipset_parse_setname,
58                         .print = ipset_print_name,
59                         .opt = IPSET_OPT_NAME
60                 },
61         },
62         .compat_parse_elem = ipset_parse_name_compat,
63         .args = {
64                 [IPSET_CREATE] = list_set_create_args0,
65                 [IPSET_ADD] = list_set_adt_args0,
66                 [IPSET_DEL] = list_set_adt_args0,
67                 [IPSET_TEST] = list_set_adt_args0,
68         },
69         .mandatory = {
70                 [IPSET_CREATE] = 0,
71                 [IPSET_ADD] = IPSET_FLAG(IPSET_OPT_NAME),
72                 [IPSET_DEL] = IPSET_FLAG(IPSET_OPT_NAME),
73                 [IPSET_TEST] = IPSET_FLAG(IPSET_OPT_NAME),
74         },
75         .full = {
76                 [IPSET_CREATE] = IPSET_FLAG(IPSET_OPT_SIZE)
77                         | IPSET_FLAG(IPSET_OPT_TIMEOUT),
78                 [IPSET_ADD] = IPSET_FLAG(IPSET_OPT_NAME)
79                         | IPSET_FLAG(IPSET_OPT_BEFORE)
80                         | IPSET_FLAG(IPSET_OPT_NAMEREF)
81                         | IPSET_FLAG(IPSET_OPT_TIMEOUT),
82                 [IPSET_DEL] = IPSET_FLAG(IPSET_OPT_NAME)
83                         | IPSET_FLAG(IPSET_OPT_BEFORE)
84                         | IPSET_FLAG(IPSET_OPT_NAMEREF),
85                 [IPSET_TEST] = IPSET_FLAG(IPSET_OPT_NAME)
86                         | IPSET_FLAG(IPSET_OPT_BEFORE)
87                         | IPSET_FLAG(IPSET_OPT_NAMEREF),
88         },
89
90         .usage = list_set_usage0,
91         .description = "Initial revision",
92 };
93
94 /* Parse commandline arguments */
95 static const struct ipset_arg list_set_create_args1[] = {
96         { .name = { "size", NULL },
97           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_SIZE,
98           .parse = ipset_parse_uint32,          .print = ipset_print_number,
99         },
100         { .name = { "timeout", NULL },
101           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_TIMEOUT,
102           .parse = ipset_parse_timeout,         .print = ipset_print_number,
103         },
104         { .name = { "counters", NULL },
105           .has_arg = IPSET_NO_ARG,              .opt = IPSET_OPT_COUNTERS,
106           .parse = ipset_parse_flag,            .print = ipset_print_flag,
107         },
108         { },
109 };
110
111 static const struct ipset_arg list_set_adt_args1[] = {
112         { .name = { "timeout", NULL },
113           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_TIMEOUT,
114           .parse = ipset_parse_timeout,         .print = ipset_print_number,
115         },
116         { .name = { "before", NULL },
117           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_NAMEREF,
118           .parse = ipset_parse_before,
119         },
120         { .name = { "after", NULL },
121           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_NAMEREF,
122           .parse = ipset_parse_after,
123         },
124         { .name = { "packets", NULL },
125           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_PACKETS,
126           .parse = ipset_parse_uint64,          .print = ipset_print_number,
127         },
128         { .name = { "bytes", NULL },
129           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_BYTES,
130           .parse = ipset_parse_uint64,          .print = ipset_print_number,
131         },
132         { },
133 };
134
135 static const char list_set_usage1[] =
136 "create SETNAME list:set\n"
137 "               [size VALUE] [timeout VALUE] [counters\n"
138 "add    SETNAME NAME [before|after NAME] [timeout VALUE]\n"
139 "               [packets VALUE] [bytes VALUE]\n"
140 "del    SETNAME NAME [before|after NAME]\n"
141 "test   SETNAME NAME [before|after NAME]\n\n"
142 "where NAME are existing set names.\n";
143
144 static struct ipset_type ipset_list_set1 = {
145         .name = "list:set",
146         .alias = { "setlist", NULL },
147         .revision = 1,
148         .family = NFPROTO_UNSPEC,
149         .dimension = IPSET_DIM_ONE,
150         .elem = {
151                 [IPSET_DIM_ONE - 1] = {
152                         .parse = ipset_parse_setname,
153                         .print = ipset_print_name,
154                         .opt = IPSET_OPT_NAME
155                 },
156         },
157         .compat_parse_elem = ipset_parse_name_compat,
158         .args = {
159                 [IPSET_CREATE] = list_set_create_args1,
160                 [IPSET_ADD] = list_set_adt_args1,
161                 [IPSET_DEL] = list_set_adt_args1,
162                 [IPSET_TEST] = list_set_adt_args1,
163         },
164         .mandatory = {
165                 [IPSET_CREATE] = 0,
166                 [IPSET_ADD] = IPSET_FLAG(IPSET_OPT_NAME),
167                 [IPSET_DEL] = IPSET_FLAG(IPSET_OPT_NAME),
168                 [IPSET_TEST] = IPSET_FLAG(IPSET_OPT_NAME),
169         },
170         .full = {
171                 [IPSET_CREATE] = IPSET_FLAG(IPSET_OPT_SIZE)
172                         | IPSET_FLAG(IPSET_OPT_TIMEOUT)
173                         | IPSET_FLAG(IPSET_OPT_COUNTERS),
174                 [IPSET_ADD] = IPSET_FLAG(IPSET_OPT_NAME)
175                         | IPSET_FLAG(IPSET_OPT_BEFORE)
176                         | IPSET_FLAG(IPSET_OPT_NAMEREF)
177                         | IPSET_FLAG(IPSET_OPT_TIMEOUT)
178                         | IPSET_FLAG(IPSET_OPT_PACKETS)
179                         | IPSET_FLAG(IPSET_OPT_BYTES),
180                 [IPSET_DEL] = IPSET_FLAG(IPSET_OPT_NAME)
181                         | IPSET_FLAG(IPSET_OPT_BEFORE)
182                         | IPSET_FLAG(IPSET_OPT_NAMEREF),
183                 [IPSET_TEST] = IPSET_FLAG(IPSET_OPT_NAME)
184                         | IPSET_FLAG(IPSET_OPT_BEFORE)
185                         | IPSET_FLAG(IPSET_OPT_NAMEREF),
186         },
187
188         .usage = list_set_usage1,
189         .description = "counters support",
190 };
191
192 /* Parse commandline arguments */
193 static const struct ipset_arg list_set_create_args2[] = {
194         { .name = { "size", NULL },
195           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_SIZE,
196           .parse = ipset_parse_uint32,          .print = ipset_print_number,
197         },
198         { .name = { "timeout", NULL },
199           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_TIMEOUT,
200           .parse = ipset_parse_timeout,         .print = ipset_print_number,
201         },
202         { .name = { "counters", NULL },
203           .has_arg = IPSET_NO_ARG,              .opt = IPSET_OPT_COUNTERS,
204           .parse = ipset_parse_flag,            .print = ipset_print_flag,
205         },
206         { .name = { "comment", NULL },
207           .has_arg = IPSET_NO_ARG,              .opt = IPSET_OPT_CREATE_COMMENT,
208           .parse = ipset_parse_flag,            .print = ipset_print_flag,
209         },
210         { },
211 };
212
213 static const struct ipset_arg list_set_adt_args2[] = {
214         { .name = { "timeout", NULL },
215           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_TIMEOUT,
216           .parse = ipset_parse_timeout,         .print = ipset_print_number,
217         },
218         { .name = { "before", NULL },
219           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_NAMEREF,
220           .parse = ipset_parse_before,
221         },
222         { .name = { "after", NULL },
223           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_NAMEREF,
224           .parse = ipset_parse_after,
225         },
226         { .name = { "packets", NULL },
227           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_PACKETS,
228           .parse = ipset_parse_uint64,          .print = ipset_print_number,
229         },
230         { .name = { "bytes", NULL },
231           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_BYTES,
232           .parse = ipset_parse_uint64,          .print = ipset_print_number,
233         },
234         { .name = { "comment", NULL },
235           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_ADT_COMMENT,
236           .parse = ipset_parse_comment,         .print = ipset_print_comment,
237         },
238         { },
239 };
240
241 static const char list_set_usage2[] =
242 "create SETNAME list:set\n"
243 "               [size VALUE] [timeout VALUE] [counters] [comment]\n"
244 "add    SETNAME NAME [before|after NAME] [timeout VALUE]\n"
245 "               [packets VALUE] [bytes VALUE] [comment STRING]\n"
246 "del    SETNAME NAME [before|after NAME]\n"
247 "test   SETNAME NAME [before|after NAME]\n\n"
248 "where NAME are existing set names.\n";
249
250 static struct ipset_type ipset_list_set2 = {
251         .name = "list:set",
252         .alias = { "setlist", NULL },
253         .revision = 2,
254         .family = NFPROTO_UNSPEC,
255         .dimension = IPSET_DIM_ONE,
256         .elem = {
257                 [IPSET_DIM_ONE - 1] = {
258                         .parse = ipset_parse_setname,
259                         .print = ipset_print_name,
260                         .opt = IPSET_OPT_NAME
261                 },
262         },
263         .compat_parse_elem = ipset_parse_name_compat,
264         .args = {
265                 [IPSET_CREATE] = list_set_create_args2,
266                 [IPSET_ADD] = list_set_adt_args2,
267                 [IPSET_DEL] = list_set_adt_args2,
268                 [IPSET_TEST] = list_set_adt_args2,
269         },
270         .mandatory = {
271                 [IPSET_CREATE] = 0,
272                 [IPSET_ADD] = IPSET_FLAG(IPSET_OPT_NAME),
273                 [IPSET_DEL] = IPSET_FLAG(IPSET_OPT_NAME),
274                 [IPSET_TEST] = IPSET_FLAG(IPSET_OPT_NAME),
275         },
276         .full = {
277                 [IPSET_CREATE] = IPSET_FLAG(IPSET_OPT_SIZE)
278                         | IPSET_FLAG(IPSET_OPT_TIMEOUT)
279                         | IPSET_FLAG(IPSET_OPT_COUNTERS)
280                         | IPSET_FLAG(IPSET_OPT_CREATE_COMMENT),
281                 [IPSET_ADD] = IPSET_FLAG(IPSET_OPT_NAME)
282                         | IPSET_FLAG(IPSET_OPT_BEFORE)
283                         | IPSET_FLAG(IPSET_OPT_NAMEREF)
284                         | IPSET_FLAG(IPSET_OPT_TIMEOUT)
285                         | IPSET_FLAG(IPSET_OPT_PACKETS)
286                         | IPSET_FLAG(IPSET_OPT_BYTES)
287                         | IPSET_FLAG(IPSET_OPT_ADT_COMMENT),
288                 [IPSET_DEL] = IPSET_FLAG(IPSET_OPT_NAME)
289                         | IPSET_FLAG(IPSET_OPT_BEFORE)
290                         | IPSET_FLAG(IPSET_OPT_NAMEREF),
291                 [IPSET_TEST] = IPSET_FLAG(IPSET_OPT_NAME)
292                         | IPSET_FLAG(IPSET_OPT_BEFORE)
293                         | IPSET_FLAG(IPSET_OPT_NAMEREF),
294         },
295
296         .usage = list_set_usage2,
297         .description = "comment support",
298 };
299
300 /* Parse commandline arguments */
301 static const struct ipset_arg list_set_create_args3[] = {
302         { .name = { "size", NULL },
303           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_SIZE,
304           .parse = ipset_parse_uint32,          .print = ipset_print_number,
305         },
306         { .name = { "timeout", NULL },
307           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_TIMEOUT,
308           .parse = ipset_parse_timeout,         .print = ipset_print_number,
309         },
310         { .name = { "counters", NULL },
311           .has_arg = IPSET_NO_ARG,              .opt = IPSET_OPT_COUNTERS,
312           .parse = ipset_parse_flag,            .print = ipset_print_flag,
313         },
314         { .name = { "comment", NULL },
315           .has_arg = IPSET_NO_ARG,              .opt = IPSET_OPT_CREATE_COMMENT,
316           .parse = ipset_parse_flag,            .print = ipset_print_flag,
317         },
318         { .name = { "skbinfo", NULL },
319           .has_arg = IPSET_NO_ARG,              .opt = IPSET_OPT_SKBINFO,
320           .parse = ipset_parse_flag,            .print = ipset_print_flag,
321         },
322         { },
323 };
324
325 static const struct ipset_arg list_set_adt_args3[] = {
326         { .name = { "timeout", NULL },
327           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_TIMEOUT,
328           .parse = ipset_parse_timeout,         .print = ipset_print_number,
329         },
330         { .name = { "before", NULL },
331           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_NAMEREF,
332           .parse = ipset_parse_before,
333         },
334         { .name = { "after", NULL },
335           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_NAMEREF,
336           .parse = ipset_parse_after,
337         },
338         { .name = { "packets", NULL },
339           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_PACKETS,
340           .parse = ipset_parse_uint64,          .print = ipset_print_number,
341         },
342         { .name = { "bytes", NULL },
343           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_BYTES,
344           .parse = ipset_parse_uint64,          .print = ipset_print_number,
345         },
346         { .name = { "comment", NULL },
347           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_ADT_COMMENT,
348           .parse = ipset_parse_comment,         .print = ipset_print_comment,
349         },
350         { .name = { "skbmark", NULL },
351           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_SKBMARK,
352           .parse = ipset_parse_skbmark,         .print = ipset_print_skbmark,
353         },
354         { .name = { "skbprio", NULL },
355           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_SKBPRIO,
356           .parse = ipset_parse_skbprio,         .print = ipset_print_skbprio,
357         },
358         { .name = { "skbqueue", NULL },
359           .has_arg = IPSET_MANDATORY_ARG,       .opt = IPSET_OPT_SKBQUEUE,
360           .parse = ipset_parse_uint16,          .print = ipset_print_number,
361         },
362         { },
363 };
364
365 static const char list_set_usage3[] =
366 "create SETNAME list:set\n"
367 "               [size VALUE] [timeout VALUE] [counters] [comment]\n"
368 "               [skbinfo]\n"
369 "add    SETNAME NAME [before|after NAME] [timeout VALUE]\n"
370 "               [packets VALUE] [bytes VALUE] [comment STRING]\n"
371 "               [skbmark VALUE] [skbprio VALUE] [skbqueue VALUE]\n"
372 "del    SETNAME NAME [before|after NAME]\n"
373 "test   SETNAME NAME [before|after NAME]\n\n"
374 "where NAME are existing set names.\n";
375
376 static struct ipset_type ipset_list_set3 = {
377         .name = "list:set",
378         .alias = { "setlist", NULL },
379         .revision = 3,
380         .family = NFPROTO_UNSPEC,
381         .dimension = IPSET_DIM_ONE,
382         .elem = {
383                 [IPSET_DIM_ONE - 1] = {
384                         .parse = ipset_parse_setname,
385                         .print = ipset_print_name,
386                         .opt = IPSET_OPT_NAME
387                 },
388         },
389         .compat_parse_elem = ipset_parse_name_compat,
390         .args = {
391                 [IPSET_CREATE] = list_set_create_args3,
392                 [IPSET_ADD] = list_set_adt_args3,
393                 [IPSET_DEL] = list_set_adt_args2,
394                 [IPSET_TEST] = list_set_adt_args2,
395         },
396         .mandatory = {
397                 [IPSET_CREATE] = 0,
398                 [IPSET_ADD] = IPSET_FLAG(IPSET_OPT_NAME),
399                 [IPSET_DEL] = IPSET_FLAG(IPSET_OPT_NAME),
400                 [IPSET_TEST] = IPSET_FLAG(IPSET_OPT_NAME),
401         },
402         .full = {
403                 [IPSET_CREATE] = IPSET_FLAG(IPSET_OPT_SIZE)
404                         | IPSET_FLAG(IPSET_OPT_TIMEOUT)
405                         | IPSET_FLAG(IPSET_OPT_COUNTERS)
406                         | IPSET_FLAG(IPSET_OPT_CREATE_COMMENT)
407                         | IPSET_FLAG(IPSET_OPT_SKBINFO),
408                 [IPSET_ADD] = IPSET_FLAG(IPSET_OPT_NAME)
409                         | IPSET_FLAG(IPSET_OPT_BEFORE)
410                         | IPSET_FLAG(IPSET_OPT_NAMEREF)
411                         | IPSET_FLAG(IPSET_OPT_TIMEOUT)
412                         | IPSET_FLAG(IPSET_OPT_PACKETS)
413                         | IPSET_FLAG(IPSET_OPT_BYTES)
414                         | IPSET_FLAG(IPSET_OPT_ADT_COMMENT)
415                         | IPSET_FLAG(IPSET_OPT_SKBMARK)
416                         | IPSET_FLAG(IPSET_OPT_SKBPRIO)
417                         | IPSET_FLAG(IPSET_OPT_SKBQUEUE),
418                 [IPSET_DEL] = IPSET_FLAG(IPSET_OPT_NAME)
419                         | IPSET_FLAG(IPSET_OPT_BEFORE)
420                         | IPSET_FLAG(IPSET_OPT_NAMEREF),
421                 [IPSET_TEST] = IPSET_FLAG(IPSET_OPT_NAME)
422                         | IPSET_FLAG(IPSET_OPT_BEFORE)
423                         | IPSET_FLAG(IPSET_OPT_NAMEREF),
424         },
425
426         .usage = list_set_usage3,
427         .description = "skbinfo support",
428 };
429 void _init(void);
430 void _init(void)
431 {
432         ipset_type_add(&ipset_list_set0);
433         ipset_type_add(&ipset_list_set1);
434         ipset_type_add(&ipset_list_set2);
435         ipset_type_add(&ipset_list_set3);
436 }