]> granicus.if.org Git - ipset/blob - lib/ipset_bitmap_port.c
Userspace revision handling is reworked
[ipset] / lib / ipset_bitmap_port.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 /* Initial release */
13 static struct ipset_type ipset_bitmap_port0 = {
14         .name = "bitmap:port",
15         .alias = { "portmap", NULL },
16         .revision = 0,
17         .family = NFPROTO_UNSPEC,
18         .dimension = IPSET_DIM_ONE,
19         .elem = {
20                 [IPSET_DIM_ONE - 1] = {
21                         .parse = ipset_parse_tcp_udp_port,
22                         .print = ipset_print_port,
23                         .opt = IPSET_OPT_PORT
24                 },
25         },
26         .cmd = {
27                 [IPSET_CREATE] = {
28                         .args = {
29                                 IPSET_ARG_PORTRANGE,
30                                 IPSET_ARG_TIMEOUT,
31                                 /* Backward compatibility */
32                                 IPSET_ARG_FROM_PORT,
33                                 IPSET_ARG_TO_PORT,
34                                 IPSET_ARG_NONE,
35                         },
36                         .need = IPSET_FLAG(IPSET_OPT_PORT)
37                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
38                         .full = IPSET_FLAG(IPSET_OPT_PORT)
39                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
40                         .help = "range [PROTO:]FROM-TO",
41                 },
42                 [IPSET_ADD] = {
43                         .args = {
44                                 IPSET_ARG_TIMEOUT,
45                                 IPSET_ARG_NONE,
46                         },
47                         .need = IPSET_FLAG(IPSET_OPT_PORT),
48                         .full = IPSET_FLAG(IPSET_OPT_PORT)
49                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
50                         .help = "[PROTO:]PORT|FROM-TO",
51                 },
52                 [IPSET_DEL] = {
53                         .args = {
54                                 IPSET_ARG_NONE,
55                         },
56                         .need = IPSET_FLAG(IPSET_OPT_PORT),
57                         .full = IPSET_FLAG(IPSET_OPT_PORT)
58                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
59                         .help = "[PROTO:]PORT|FROM-TO",
60                 },
61                 [IPSET_TEST] = {
62                         .args = {
63                                 IPSET_ARG_NONE,
64                         },
65                         .need = IPSET_FLAG(IPSET_OPT_PORT),
66                         .full = IPSET_FLAG(IPSET_OPT_PORT),
67                         .help = "[PROTO:]PORT",
68                 },
69         },
70         .usage = "where PORT, FROM and TO are port numbers or port names from /etc/services.\n"
71                  "      PROTO is only needed if a service name is used and it does not exist\n"
72                  "      as a TCP service; it isn't used otherwise with the bitmap.",
73         .description = "Initial revision",
74 };
75
76 /* Counters support */
77 static struct ipset_type ipset_bitmap_port1 = {
78         .name = "bitmap:port",
79         .alias = { "portmap", NULL },
80         .revision = 1,
81         .family = NFPROTO_UNSPEC,
82         .dimension = IPSET_DIM_ONE,
83         .elem = {
84                 [IPSET_DIM_ONE - 1] = {
85                         .parse = ipset_parse_tcp_udp_port,
86                         .print = ipset_print_port,
87                         .opt = IPSET_OPT_PORT
88                 },
89         },
90         .cmd = {
91                 [IPSET_CREATE] = {
92                         .args = {
93                                 IPSET_ARG_PORTRANGE,
94                                 IPSET_ARG_TIMEOUT,
95                                 IPSET_ARG_COUNTERS,
96                                 /* Backward compatibility */
97                                 IPSET_ARG_FROM_PORT,
98                                 IPSET_ARG_TO_PORT,
99                                 IPSET_ARG_NONE,
100                         },
101                         .need = IPSET_FLAG(IPSET_OPT_PORT)
102                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
103                         .full = IPSET_FLAG(IPSET_OPT_PORT)
104                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
105                         .help = "range [PROTO:]FROM-TO",
106                 },
107                 [IPSET_ADD] = {
108                         .args = {
109                                 IPSET_ARG_TIMEOUT,
110                                 IPSET_ARG_PACKETS,
111                                 IPSET_ARG_BYTES,
112                                 IPSET_ARG_NONE,
113                         },
114                         .need = IPSET_FLAG(IPSET_OPT_PORT),
115                         .full = IPSET_FLAG(IPSET_OPT_PORT)
116                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
117                         .help = "[PROTO:]PORT|FROM-TO",
118                 },
119                 [IPSET_DEL] = {
120                         .args = {
121                                 IPSET_ARG_NONE,
122                         },
123                         .need = IPSET_FLAG(IPSET_OPT_PORT),
124                         .full = IPSET_FLAG(IPSET_OPT_PORT)
125                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
126                         .help = "[PROTO:]PORT|FROM-TO",
127                 },
128                 [IPSET_TEST] = {
129                         .args = {
130                                 IPSET_ARG_NONE,
131                         },
132                         .need = IPSET_FLAG(IPSET_OPT_PORT),
133                         .full = IPSET_FLAG(IPSET_OPT_PORT),
134                         .help = "[PROTO:]PORT",
135                 },
136         },
137         .usage = "where PORT, FROM and TO are port numbers or port names from /etc/services.\n"
138                  "      PROTO is only needed if a service name is used and it does not exist\n"
139                  "      as a TCP service; it isn't used otherwise with the bitmap.",
140         .description = "counters support",
141 };
142
143 /* Comment support */
144 static struct ipset_type ipset_bitmap_port2 = {
145         .name = "bitmap:port",
146         .alias = { "portmap", NULL },
147         .revision = 2,
148         .family = NFPROTO_UNSPEC,
149         .dimension = IPSET_DIM_ONE,
150         .elem = {
151                 [IPSET_DIM_ONE - 1] = {
152                         .parse = ipset_parse_tcp_udp_port,
153                         .print = ipset_print_port,
154                         .opt = IPSET_OPT_PORT
155                 },
156         },
157         .cmd = {
158                 [IPSET_CREATE] = {
159                         .args = {
160                                 IPSET_ARG_PORTRANGE,
161                                 IPSET_ARG_TIMEOUT,
162                                 IPSET_ARG_COUNTERS,
163                                 IPSET_ARG_COMMENT,
164                                 /* Backward compatibility */
165                                 IPSET_ARG_FROM_PORT,
166                                 IPSET_ARG_TO_PORT,
167                                 IPSET_ARG_NONE,
168                         },
169                         .need = IPSET_FLAG(IPSET_OPT_PORT)
170                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
171                         .full = IPSET_FLAG(IPSET_OPT_PORT)
172                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
173                         .help = "range [PROTO:]FROM-TO",
174                 },
175                 [IPSET_ADD] = {
176                         .args = {
177                                 IPSET_ARG_TIMEOUT,
178                                 IPSET_ARG_PACKETS,
179                                 IPSET_ARG_BYTES,
180                                 IPSET_ARG_ADT_COMMENT,
181                                 IPSET_ARG_NONE,
182                         },
183                         .need = IPSET_FLAG(IPSET_OPT_PORT),
184                         .full = IPSET_FLAG(IPSET_OPT_PORT)
185                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
186                         .help = "[PROTO:]PORT|FROM-TO",
187                 },
188                 [IPSET_DEL] = {
189                         .args = {
190                                 IPSET_ARG_NONE,
191                         },
192                         .need = IPSET_FLAG(IPSET_OPT_PORT),
193                         .full = IPSET_FLAG(IPSET_OPT_PORT)
194                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
195                         .help = "[PROTO:]PORT|FROM-TO",
196                 },
197                 [IPSET_TEST] = {
198                         .args = {
199                                 IPSET_ARG_NONE,
200                         },
201                         .need = IPSET_FLAG(IPSET_OPT_PORT),
202                         .full = IPSET_FLAG(IPSET_OPT_PORT),
203                         .help = "[PROTO:]PORT",
204                 },
205         },
206         .usage = "where PORT, FROM and TO are port numbers or port names from /etc/services.\n"
207                  "      PROTO is only needed if a service name is used and it does not exist\n"
208                  "      as a TCP service; it isn't used otherwise with the bitmap.",
209         .description = "comment support",
210 };
211
212 /* skbinfo support */
213 static struct ipset_type ipset_bitmap_port3 = {
214         .name = "bitmap:port",
215         .alias = { "portmap", NULL },
216         .revision = 3,
217         .family = NFPROTO_UNSPEC,
218         .dimension = IPSET_DIM_ONE,
219         .elem = {
220                 [IPSET_DIM_ONE - 1] = {
221                         .parse = ipset_parse_tcp_udp_port,
222                         .print = ipset_print_port,
223                         .opt = IPSET_OPT_PORT
224                 },
225         },
226         .cmd = {
227                 [IPSET_CREATE] = {
228                         .args = {
229                                 IPSET_ARG_PORTRANGE,
230                                 IPSET_ARG_TIMEOUT,
231                                 IPSET_ARG_COUNTERS,
232                                 IPSET_ARG_COMMENT,
233                                 IPSET_ARG_SKBINFO,
234                                 /* Backward compatibility */
235                                 IPSET_ARG_FROM_PORT,
236                                 IPSET_ARG_TO_PORT,
237                                 IPSET_ARG_NONE,
238                         },
239                         .need = IPSET_FLAG(IPSET_OPT_PORT)
240                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
241                         .full = IPSET_FLAG(IPSET_OPT_PORT)
242                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
243                         .help = "range [PROTO:]FROM-TO",
244                 },
245                 [IPSET_ADD] = {
246                         .args = {
247                                 IPSET_ARG_TIMEOUT,
248                                 IPSET_ARG_PACKETS,
249                                 IPSET_ARG_BYTES,
250                                 IPSET_ARG_ADT_COMMENT,
251                                 IPSET_ARG_SKBMARK,
252                                 IPSET_ARG_SKBPRIO,
253                                 IPSET_ARG_SKBQUEUE,
254                                 IPSET_ARG_NONE,
255                         },
256                         .need = IPSET_FLAG(IPSET_OPT_PORT),
257                         .full = IPSET_FLAG(IPSET_OPT_PORT)
258                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
259                         .help = "[PROTO:]PORT|FROM-TO",
260                 },
261                 [IPSET_DEL] = {
262                         .args = {
263                                 IPSET_ARG_NONE,
264                         },
265                         .need = IPSET_FLAG(IPSET_OPT_PORT),
266                         .full = IPSET_FLAG(IPSET_OPT_PORT)
267                                 | IPSET_FLAG(IPSET_OPT_PORT_TO),
268                         .help = "[PROTO:]PORT|FROM-TO",
269                 },
270                 [IPSET_TEST] = {
271                         .args = {
272                                 IPSET_ARG_NONE,
273                         },
274                         .need = IPSET_FLAG(IPSET_OPT_PORT),
275                         .full = IPSET_FLAG(IPSET_OPT_PORT),
276                         .help = "[PROTO:]PORT",
277                 },
278         },
279         .usage = "where PORT, FROM and TO are port numbers or port names from /etc/services.\n"
280                  "      PROTO is only needed if a service name is used and it does not exist\n"
281                  "      as a TCP service; it isn't used otherwise with the bitmap.",
282         .description = "skbinfo support",
283 };
284
285 void _init(void);
286 void _init(void)
287 {
288         ipset_type_add(&ipset_bitmap_port0);
289         ipset_type_add(&ipset_bitmap_port1);
290         ipset_type_add(&ipset_bitmap_port2);
291         ipset_type_add(&ipset_bitmap_port3);
292 }