blob: 718d4c42d4891704b2e676ceb980466e7607b252 [file] [log] [blame]
Patrick McHardy38100132006-11-13 19:38:44 +00001/* Shared library add-on to iptables for SCTP matching
2 *
3 * (C) 2003 by Harald Welte <laforge@gnumonks.org>
4 *
5 * This program is distributed under the terms of GNU GPL v2, 1991
6 *
7 * libipt_ecn.c borrowed heavily from libipt_dscp.c
8 *
9 */
Jan Engelhardt32b8e612010-07-23 21:16:14 +020010#include <stdbool.h>
Patrick McHardy38100132006-11-13 19:38:44 +000011#include <stdio.h>
12#include <string.h>
13#include <stdlib.h>
14#include <getopt.h>
15#include <netdb.h>
16#include <ctype.h>
17
Thomas Jaroschecae0c32008-10-23 15:41:27 +020018#include <netinet/in.h>
Yasuyuki KOZAKAI19f29502007-07-24 07:02:26 +000019#include <xtables.h>
Patrick McHardy38100132006-11-13 19:38:44 +000020
Patrick McHardy38100132006-11-13 19:38:44 +000021#include <linux/netfilter/xt_sctp.h>
22
Patrick McHardy38100132006-11-13 19:38:44 +000023#if 0
24#define DEBUGP(format, first...) printf(format, ##first)
25#define static
26#else
27#define DEBUGP(format, fist...)
28#endif
29
30static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +010031print_chunk(uint32_t chunknum, int numeric);
Patrick McHardy38100132006-11-13 19:38:44 +000032
Jan Engelhardt181dead2007-10-04 16:27:07 +000033static void sctp_init(struct xt_entry_match *m)
Patrick McHardy38100132006-11-13 19:38:44 +000034{
35 int i;
36 struct xt_sctp_info *einfo = (struct xt_sctp_info *)m->data;
37
38 memset(einfo, 0, sizeof(struct xt_sctp_info));
39
40 for (i = 0; i < XT_NUM_SCTP_FLAGS; i++) {
41 einfo->flag_info[i].chunktype = -1;
42 }
43}
44
Jan Engelhardt181dead2007-10-04 16:27:07 +000045static void sctp_help(void)
Patrick McHardy38100132006-11-13 19:38:44 +000046{
47 printf(
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020048"sctp match options\n"
Jan Engelhardt96727922008-08-13 14:42:41 +020049"[!] --source-port port[:port] match source port(s)\n"
Patrick McHardy38100132006-11-13 19:38:44 +000050" --sport ...\n"
Jan Engelhardt96727922008-08-13 14:42:41 +020051"[!] --destination-port port[:port] match destination port(s)\n"
Patrick McHardy38100132006-11-13 19:38:44 +000052" --dport ...\n"
Jan Engelhardt96727922008-08-13 14:42:41 +020053"[!] --chunk-types (all|any|none) (chunktype[:flags])+ match if all, any or none of\n"
Patrick McHardy38100132006-11-13 19:38:44 +000054" chunktypes are present\n"
Shan Wei4a498502010-06-08 14:16:57 +020055"chunktypes - DATA INIT INIT_ACK SACK HEARTBEAT HEARTBEAT_ACK ABORT SHUTDOWN SHUTDOWN_ACK ERROR COOKIE_ECHO COOKIE_ACK ECN_ECNE ECN_CWR SHUTDOWN_COMPLETE ASCONF ASCONF_ACK FORWARD_TSN ALL NONE\n");
Patrick McHardy38100132006-11-13 19:38:44 +000056}
57
Jan Engelhardt181dead2007-10-04 16:27:07 +000058static const struct option sctp_opts[] = {
Jan Engelhardt32b8e612010-07-23 21:16:14 +020059 {.name = "source-port", .has_arg = true, .val = '1'},
60 {.name = "sport", .has_arg = true, .val = '1'},
61 {.name = "destination-port", .has_arg = true, .val = '2'},
62 {.name = "dport", .has_arg = true, .val = '2'},
63 {.name = "chunk-types", .has_arg = true, .val = '3'},
64 XT_GETOPT_TABLEEND,
Patrick McHardy38100132006-11-13 19:38:44 +000065};
66
67static void
68parse_sctp_ports(const char *portstring,
Jan Engelhardt7ac40522011-01-07 12:34:04 +010069 uint16_t *ports)
Patrick McHardy38100132006-11-13 19:38:44 +000070{
71 char *buffer;
72 char *cp;
73
74 buffer = strdup(portstring);
75 DEBUGP("%s\n", portstring);
76 if ((cp = strchr(buffer, ':')) == NULL) {
Jan Engelhardtaae6be92009-01-30 04:24:47 +010077 ports[0] = ports[1] = xtables_parse_port(buffer, "sctp");
Patrick McHardy38100132006-11-13 19:38:44 +000078 }
79 else {
80 *cp = '\0';
81 cp++;
82
Jan Engelhardtaae6be92009-01-30 04:24:47 +010083 ports[0] = buffer[0] ? xtables_parse_port(buffer, "sctp") : 0;
84 ports[1] = cp[0] ? xtables_parse_port(cp, "sctp") : 0xFFFF;
Patrick McHardy38100132006-11-13 19:38:44 +000085
86 if (ports[0] > ports[1])
Jan Engelhardt1829ed42009-02-21 03:29:44 +010087 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +000088 "invalid portrange (min > max)");
89 }
90 free(buffer);
91}
92
93struct sctp_chunk_names {
94 const char *name;
95 unsigned int chunk_type;
96 const char *valid_flags;
97};
98
99/*'ALL' and 'NONE' will be treated specially. */
Jan Engelhardt0e2abed2007-10-04 16:25:58 +0000100static const struct sctp_chunk_names sctp_chunk_names[]
Shan Weib9f458f2010-06-08 14:15:39 +0200101= { { .name = "DATA", .chunk_type = 0, .valid_flags = "----IUBE"},
Patrick McHardy38100132006-11-13 19:38:44 +0000102 { .name = "INIT", .chunk_type = 1, .valid_flags = "--------"},
103 { .name = "INIT_ACK", .chunk_type = 2, .valid_flags = "--------"},
104 { .name = "SACK", .chunk_type = 3, .valid_flags = "--------"},
105 { .name = "HEARTBEAT", .chunk_type = 4, .valid_flags = "--------"},
106 { .name = "HEARTBEAT_ACK", .chunk_type = 5, .valid_flags = "--------"},
107 { .name = "ABORT", .chunk_type = 6, .valid_flags = "-------T"},
108 { .name = "SHUTDOWN", .chunk_type = 7, .valid_flags = "--------"},
109 { .name = "SHUTDOWN_ACK", .chunk_type = 8, .valid_flags = "--------"},
110 { .name = "ERROR", .chunk_type = 9, .valid_flags = "--------"},
111 { .name = "COOKIE_ECHO", .chunk_type = 10, .valid_flags = "--------"},
112 { .name = "COOKIE_ACK", .chunk_type = 11, .valid_flags = "--------"},
113 { .name = "ECN_ECNE", .chunk_type = 12, .valid_flags = "--------"},
114 { .name = "ECN_CWR", .chunk_type = 13, .valid_flags = "--------"},
115 { .name = "SHUTDOWN_COMPLETE", .chunk_type = 14, .valid_flags = "-------T"},
Naohiro Ooiwaecd7f5e2008-02-29 12:45:27 +0000116 { .name = "ASCONF", .chunk_type = 193, .valid_flags = "--------"},
117 { .name = "ASCONF_ACK", .chunk_type = 128, .valid_flags = "--------"},
Shan Wei4a498502010-06-08 14:16:57 +0200118 { .name = "FORWARD_TSN", .chunk_type = 192, .valid_flags = "--------"},
Patrick McHardy38100132006-11-13 19:38:44 +0000119};
120
121static void
122save_chunk_flag_info(struct xt_sctp_flag_info *flag_info,
123 int *flag_count,
124 int chunktype,
125 int bit,
126 int set)
127{
128 int i;
129
130 for (i = 0; i < *flag_count; i++) {
131 if (flag_info[i].chunktype == chunktype) {
132 DEBUGP("Previous match found\n");
133 flag_info[i].chunktype = chunktype;
134 flag_info[i].flag_mask |= (1 << bit);
135 if (set) {
136 flag_info[i].flag |= (1 << bit);
137 }
138
139 return;
140 }
141 }
142
143 if (*flag_count == XT_NUM_SCTP_FLAGS) {
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100144 xtables_error (PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +0000145 "Number of chunk types with flags exceeds currently allowed limit."
Yasuyuki KOZAKAI19f29502007-07-24 07:02:26 +0000146 "Increasing this limit involves changing IPT_NUM_SCTP_FLAGS and"
Patrick McHardy38100132006-11-13 19:38:44 +0000147 "recompiling both the kernel space and user space modules\n");
148 }
149
150 flag_info[*flag_count].chunktype = chunktype;
151 flag_info[*flag_count].flag_mask |= (1 << bit);
152 if (set) {
153 flag_info[*flag_count].flag |= (1 << bit);
154 }
155 (*flag_count)++;
156}
157
158static void
159parse_sctp_chunk(struct xt_sctp_info *einfo,
160 const char *chunks)
161{
162 char *ptr;
163 char *buffer;
164 unsigned int i, j;
165 int found = 0;
166 char *chunk_flags;
167
168 buffer = strdup(chunks);
169 DEBUGP("Buffer: %s\n", buffer);
170
171 SCTP_CHUNKMAP_RESET(einfo->chunkmap);
172
173 if (!strcasecmp(buffer, "ALL")) {
174 SCTP_CHUNKMAP_SET_ALL(einfo->chunkmap);
175 goto out;
176 }
177
178 if (!strcasecmp(buffer, "NONE")) {
179 SCTP_CHUNKMAP_RESET(einfo->chunkmap);
180 goto out;
181 }
182
183 for (ptr = strtok(buffer, ","); ptr; ptr = strtok(NULL, ",")) {
184 found = 0;
185 DEBUGP("Next Chunk type %s\n", ptr);
186
187 if ((chunk_flags = strchr(ptr, ':')) != NULL) {
188 *chunk_flags++ = 0;
189 }
190
Jan Engelhardt2c69b552009-04-30 19:32:02 +0200191 for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
Patrick McHardy38100132006-11-13 19:38:44 +0000192 if (strcasecmp(sctp_chunk_names[i].name, ptr) == 0) {
193 DEBUGP("Chunk num %d\n", sctp_chunk_names[i].chunk_type);
194 SCTP_CHUNKMAP_SET(einfo->chunkmap,
195 sctp_chunk_names[i].chunk_type);
196 found = 1;
197 break;
198 }
Patrick McHardy38100132006-11-13 19:38:44 +0000199 if (!found)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100200 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +0000201 "Unknown sctp chunk `%s'", ptr);
202
203 if (chunk_flags) {
204 DEBUGP("Chunk flags %s\n", chunk_flags);
205 for (j = 0; j < strlen(chunk_flags); j++) {
206 char *p;
207 int bit;
208
209 if ((p = strchr(sctp_chunk_names[i].valid_flags,
210 toupper(chunk_flags[j]))) != NULL) {
211 bit = p - sctp_chunk_names[i].valid_flags;
212 bit = 7 - bit;
213
214 save_chunk_flag_info(einfo->flag_info,
215 &(einfo->flag_count), i, bit,
216 isupper(chunk_flags[j]));
217 } else {
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100218 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +0000219 "Invalid flags for chunk type %d\n", i);
220 }
221 }
222 }
223 }
224out:
225 free(buffer);
226}
227
228static void
229parse_sctp_chunks(struct xt_sctp_info *einfo,
230 const char *match_type,
231 const char *chunks)
232{
233 DEBUGP("Match type: %s Chunks: %s\n", match_type, chunks);
234 if (!strcasecmp(match_type, "ANY")) {
235 einfo->chunk_match_type = SCTP_CHUNK_MATCH_ANY;
236 } else if (!strcasecmp(match_type, "ALL")) {
237 einfo->chunk_match_type = SCTP_CHUNK_MATCH_ALL;
238 } else if (!strcasecmp(match_type, "ONLY")) {
239 einfo->chunk_match_type = SCTP_CHUNK_MATCH_ONLY;
240 } else {
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100241 xtables_error (PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +0000242 "Match type has to be one of \"ALL\", \"ANY\" or \"ONLY\"");
243 }
244
245 SCTP_CHUNKMAP_RESET(einfo->chunkmap);
246 parse_sctp_chunk(einfo, chunks);
247}
248
249static int
Jan Engelhardt181dead2007-10-04 16:27:07 +0000250sctp_parse(int c, char **argv, int invert, unsigned int *flags,
251 const void *entry, struct xt_entry_match **match)
Patrick McHardy38100132006-11-13 19:38:44 +0000252{
253 struct xt_sctp_info *einfo
254 = (struct xt_sctp_info *)(*match)->data;
255
256 switch (c) {
257 case '1':
258 if (*flags & XT_SCTP_SRC_PORTS)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100259 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +0000260 "Only one `--source-port' allowed");
261 einfo->flags |= XT_SCTP_SRC_PORTS;
Jan Engelhardtbf971282009-11-03 19:55:11 +0100262 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200263 parse_sctp_ports(optarg, einfo->spts);
Patrick McHardy38100132006-11-13 19:38:44 +0000264 if (invert)
265 einfo->invflags |= XT_SCTP_SRC_PORTS;
266 *flags |= XT_SCTP_SRC_PORTS;
267 break;
268
269 case '2':
270 if (*flags & XT_SCTP_DEST_PORTS)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100271 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +0000272 "Only one `--destination-port' allowed");
273 einfo->flags |= XT_SCTP_DEST_PORTS;
Jan Engelhardtbf971282009-11-03 19:55:11 +0100274 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200275 parse_sctp_ports(optarg, einfo->dpts);
Patrick McHardy38100132006-11-13 19:38:44 +0000276 if (invert)
277 einfo->invflags |= XT_SCTP_DEST_PORTS;
278 *flags |= XT_SCTP_DEST_PORTS;
279 break;
280
281 case '3':
282 if (*flags & XT_SCTP_CHUNK_TYPES)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100283 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +0000284 "Only one `--chunk-types' allowed");
Jan Engelhardtbf971282009-11-03 19:55:11 +0100285 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy38100132006-11-13 19:38:44 +0000286
287 if (!argv[optind]
288 || argv[optind][0] == '-' || argv[optind][0] == '!')
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100289 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy38100132006-11-13 19:38:44 +0000290 "--chunk-types requires two args");
291
292 einfo->flags |= XT_SCTP_CHUNK_TYPES;
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200293 parse_sctp_chunks(einfo, optarg, argv[optind]);
Patrick McHardy38100132006-11-13 19:38:44 +0000294 if (invert)
295 einfo->invflags |= XT_SCTP_CHUNK_TYPES;
296 optind++;
297 *flags |= XT_SCTP_CHUNK_TYPES;
298 break;
Patrick McHardy38100132006-11-13 19:38:44 +0000299 }
300 return 1;
301}
302
Patrick McHardy38100132006-11-13 19:38:44 +0000303static char *
304port_to_service(int port)
305{
306 struct servent *service;
307
308 if ((service = getservbyport(htons(port), "sctp")))
309 return service->s_name;
310
311 return NULL;
312}
313
314static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100315print_port(uint16_t port, int numeric)
Patrick McHardy38100132006-11-13 19:38:44 +0000316{
317 char *service;
318
319 if (numeric || (service = port_to_service(port)) == NULL)
320 printf("%u", port);
321 else
322 printf("%s", service);
323}
324
325static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100326print_ports(const char *name, uint16_t min, uint16_t max,
Patrick McHardy38100132006-11-13 19:38:44 +0000327 int invert, int numeric)
328{
329 const char *inv = invert ? "!" : "";
330
331 if (min != 0 || max != 0xFFFF || invert) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100332 printf(" %s", name);
Patrick McHardy38100132006-11-13 19:38:44 +0000333 if (min == max) {
334 printf(":%s", inv);
335 print_port(min, numeric);
336 } else {
337 printf("s:%s", inv);
338 print_port(min, numeric);
339 printf(":");
340 print_port(max, numeric);
341 }
Patrick McHardy38100132006-11-13 19:38:44 +0000342 }
343}
344
345static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100346print_chunk_flags(uint32_t chunknum, uint8_t chunk_flags, uint8_t chunk_flags_mask)
Patrick McHardy38100132006-11-13 19:38:44 +0000347{
348 int i;
349
350 DEBUGP("type: %d\tflags: %x\tflag mask: %x\n", chunknum, chunk_flags,
351 chunk_flags_mask);
352
353 if (chunk_flags_mask) {
354 printf(":");
355 }
356
357 for (i = 7; i >= 0; i--) {
358 if (chunk_flags_mask & (1 << i)) {
359 if (chunk_flags & (1 << i)) {
360 printf("%c", sctp_chunk_names[chunknum].valid_flags[7-i]);
361 } else {
362 printf("%c", tolower(sctp_chunk_names[chunknum].valid_flags[7-i]));
363 }
364 }
365 }
366}
367
368static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100369print_chunk(uint32_t chunknum, int numeric)
Patrick McHardy38100132006-11-13 19:38:44 +0000370{
371 if (numeric) {
372 printf("0x%04X", chunknum);
373 }
374 else {
375 int i;
376
Jan Engelhardt2c69b552009-04-30 19:32:02 +0200377 for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
Patrick McHardy38100132006-11-13 19:38:44 +0000378 if (sctp_chunk_names[i].chunk_type == chunknum)
379 printf("%s", sctp_chunk_names[chunknum].name);
Patrick McHardy38100132006-11-13 19:38:44 +0000380 }
381}
382
383static void
Li Zefan1f25b402007-10-18 09:12:49 +0000384print_chunks(const struct xt_sctp_info *einfo, int numeric)
Patrick McHardy38100132006-11-13 19:38:44 +0000385{
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100386 uint32_t chunk_match_type = einfo->chunk_match_type;
Li Zefan1f25b402007-10-18 09:12:49 +0000387 const struct xt_sctp_flag_info *flag_info = einfo->flag_info;
388 int flag_count = einfo->flag_count;
Patrick McHardy38100132006-11-13 19:38:44 +0000389 int i, j;
390 int flag;
391
392 switch (chunk_match_type) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100393 case SCTP_CHUNK_MATCH_ANY: printf(" any"); break;
394 case SCTP_CHUNK_MATCH_ALL: printf(" all"); break;
395 case SCTP_CHUNK_MATCH_ONLY: printf(" only"); break;
Jan Engelhardtda580fe2011-01-08 03:16:14 +0100396 default: printf("Never reach here\n"); break;
Patrick McHardy38100132006-11-13 19:38:44 +0000397 }
398
Li Zefan1f25b402007-10-18 09:12:49 +0000399 if (SCTP_CHUNKMAP_IS_CLEAR(einfo->chunkmap)) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100400 printf(" NONE");
Patrick McHardy38100132006-11-13 19:38:44 +0000401 goto out;
402 }
403
Li Zefan1f25b402007-10-18 09:12:49 +0000404 if (SCTP_CHUNKMAP_IS_ALL_SET(einfo->chunkmap)) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100405 printf(" ALL");
Patrick McHardy38100132006-11-13 19:38:44 +0000406 goto out;
407 }
408
409 flag = 0;
410 for (i = 0; i < 256; i++) {
Li Zefan1f25b402007-10-18 09:12:49 +0000411 if (SCTP_CHUNKMAP_IS_SET(einfo->chunkmap, i)) {
Patrick McHardy38100132006-11-13 19:38:44 +0000412 if (flag)
413 printf(",");
Jan Engelhardt73866352010-12-18 02:04:59 +0100414 else
415 putchar(' ');
Patrick McHardy38100132006-11-13 19:38:44 +0000416 flag = 1;
417 print_chunk(i, numeric);
418 for (j = 0; j < flag_count; j++) {
419 if (flag_info[j].chunktype == i) {
420 print_chunk_flags(i, flag_info[j].flag,
421 flag_info[j].flag_mask);
422 }
423 }
424 }
425 }
Patrick McHardy38100132006-11-13 19:38:44 +0000426out:
427 return;
428}
429
Patrick McHardy38100132006-11-13 19:38:44 +0000430static void
Jan Engelhardt181dead2007-10-04 16:27:07 +0000431sctp_print(const void *ip, const struct xt_entry_match *match, int numeric)
Patrick McHardy38100132006-11-13 19:38:44 +0000432{
433 const struct xt_sctp_info *einfo =
434 (const struct xt_sctp_info *)match->data;
435
Jan Engelhardt73866352010-12-18 02:04:59 +0100436 printf(" sctp");
Patrick McHardy38100132006-11-13 19:38:44 +0000437
438 if (einfo->flags & XT_SCTP_SRC_PORTS) {
439 print_ports("spt", einfo->spts[0], einfo->spts[1],
440 einfo->invflags & XT_SCTP_SRC_PORTS,
441 numeric);
442 }
443
444 if (einfo->flags & XT_SCTP_DEST_PORTS) {
445 print_ports("dpt", einfo->dpts[0], einfo->dpts[1],
446 einfo->invflags & XT_SCTP_DEST_PORTS,
447 numeric);
448 }
449
450 if (einfo->flags & XT_SCTP_CHUNK_TYPES) {
451 /* FIXME: print_chunks() is used in save() where the printing of '!'
452 s taken care of, so we need to do that here as well */
453 if (einfo->invflags & XT_SCTP_CHUNK_TYPES) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100454 printf(" !");
Patrick McHardy38100132006-11-13 19:38:44 +0000455 }
Li Zefan1f25b402007-10-18 09:12:49 +0000456 print_chunks(einfo, numeric);
Patrick McHardy38100132006-11-13 19:38:44 +0000457 }
458}
459
Jan Engelhardt181dead2007-10-04 16:27:07 +0000460static void sctp_save(const void *ip, const struct xt_entry_match *match)
Patrick McHardy38100132006-11-13 19:38:44 +0000461{
462 const struct xt_sctp_info *einfo =
463 (const struct xt_sctp_info *)match->data;
464
465 if (einfo->flags & XT_SCTP_SRC_PORTS) {
466 if (einfo->invflags & XT_SCTP_SRC_PORTS)
Jan Engelhardt73866352010-12-18 02:04:59 +0100467 printf(" !");
Patrick McHardy38100132006-11-13 19:38:44 +0000468 if (einfo->spts[0] != einfo->spts[1])
Jan Engelhardt73866352010-12-18 02:04:59 +0100469 printf(" --sport %u:%u",
Patrick McHardy38100132006-11-13 19:38:44 +0000470 einfo->spts[0], einfo->spts[1]);
471 else
Jan Engelhardt73866352010-12-18 02:04:59 +0100472 printf(" --sport %u", einfo->spts[0]);
Patrick McHardy38100132006-11-13 19:38:44 +0000473 }
474
475 if (einfo->flags & XT_SCTP_DEST_PORTS) {
476 if (einfo->invflags & XT_SCTP_DEST_PORTS)
Jan Engelhardt73866352010-12-18 02:04:59 +0100477 printf(" !");
Patrick McHardy38100132006-11-13 19:38:44 +0000478 if (einfo->dpts[0] != einfo->dpts[1])
Jan Engelhardt73866352010-12-18 02:04:59 +0100479 printf(" --dport %u:%u",
Patrick McHardy38100132006-11-13 19:38:44 +0000480 einfo->dpts[0], einfo->dpts[1]);
481 else
Jan Engelhardt73866352010-12-18 02:04:59 +0100482 printf(" --dport %u", einfo->dpts[0]);
Patrick McHardy38100132006-11-13 19:38:44 +0000483 }
484
485 if (einfo->flags & XT_SCTP_CHUNK_TYPES) {
486 if (einfo->invflags & XT_SCTP_CHUNK_TYPES)
Jan Engelhardt73866352010-12-18 02:04:59 +0100487 printf(" !");
488 printf(" --chunk-types");
Patrick McHardy38100132006-11-13 19:38:44 +0000489
Li Zefan1f25b402007-10-18 09:12:49 +0000490 print_chunks(einfo, 0);
Patrick McHardy38100132006-11-13 19:38:44 +0000491 }
492}
493
Jan Engelhardt181dead2007-10-04 16:27:07 +0000494static struct xtables_match sctp_match = {
Yasuyuki KOZAKAI19f29502007-07-24 07:02:26 +0000495 .name = "sctp",
Jan Engelhardtc5e85732009-06-12 20:55:44 +0200496 .family = NFPROTO_UNSPEC,
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +0200497 .version = XTABLES_VERSION,
Yasuyuki KOZAKAI19f29502007-07-24 07:02:26 +0000498 .size = XT_ALIGN(sizeof(struct xt_sctp_info)),
499 .userspacesize = XT_ALIGN(sizeof(struct xt_sctp_info)),
Jan Engelhardt181dead2007-10-04 16:27:07 +0000500 .help = sctp_help,
501 .init = sctp_init,
502 .parse = sctp_parse,
503 .print = sctp_print,
504 .save = sctp_save,
505 .extra_opts = sctp_opts,
Patrick McHardy38100132006-11-13 19:38:44 +0000506};
507
508void _init(void)
509{
Jan Engelhardt181dead2007-10-04 16:27:07 +0000510 xtables_register_match(&sctp_match);
Patrick McHardy38100132006-11-13 19:38:44 +0000511}