blob: f12403c55c3acd52b21ab6e02c9f6c4a2ae52393 [file] [log] [blame]
Harald Welte8f578a02003-05-03 18:05:58 +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 */
10#include <stdio.h>
11#include <string.h>
12#include <stdlib.h>
13#include <getopt.h>
14#include <netdb.h>
Kiran Kumar54924022004-03-02 18:38:27 +000015#include <ctype.h>
Harald Welte8f578a02003-05-03 18:05:58 +000016
17#include <iptables.h>
18#include <linux/netfilter_ipv4/ip_tables.h>
19#include <linux/netfilter_ipv4/ipt_sctp.h>
20
Harald Welte12915232004-02-21 09:20:34 +000021#if 0
22#define DEBUGP(format, first...) printf(format, ##first)
23#define static
24#else
25#define DEBUGP(format, fist...)
26#endif
27
Kiran Kumar54924022004-03-02 18:38:27 +000028static void
29print_chunk(u_int32_t chunknum, int numeric);
Harald Welte12915232004-02-21 09:20:34 +000030
Harald Welte8f578a02003-05-03 18:05:58 +000031/* Initialize the match. */
32static void
Harald Welte12915232004-02-21 09:20:34 +000033init(struct ipt_entry_match *m,
34 unsigned int *nfcache)
Harald Welte8f578a02003-05-03 18:05:58 +000035{
Kiran Kumar54924022004-03-02 18:38:27 +000036 int i;
Harald Welte8f578a02003-05-03 18:05:58 +000037 struct ipt_sctp_info *einfo = (struct ipt_sctp_info *)m->data;
38
Kiran Kumar54924022004-03-02 18:38:27 +000039 memset(einfo, 0, sizeof(struct ipt_sctp_info));
Harald Welte12915232004-02-21 09:20:34 +000040
Kiran Kumar54924022004-03-02 18:38:27 +000041 for (i = 0; i < IPT_NUM_SCTP_FLAGS; i++) {
42 einfo->flag_info[i].chunktype = -1;
43 }
Harald Welte8f578a02003-05-03 18:05:58 +000044}
45
Harald Welte12915232004-02-21 09:20:34 +000046static void help(void)
Harald Welte8f578a02003-05-03 18:05:58 +000047{
48 printf(
49"SCTP match v%s options\n"
Harald Welte12915232004-02-21 09:20:34 +000050" --source-port [!] port[:port] match source port(s)\n"
Harald Welte8f578a02003-05-03 18:05:58 +000051" --sport ...\n"
Harald Welte12915232004-02-21 09:20:34 +000052" --destination-port [!] port[:port] match destination port(s)\n"
53" --dport ...\n"
54" --chunk-types [!] (all|any|none) (chunktype[:flags])+ match if all, any or none of\n"
55" chunktypes are present\n"
56"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 ALL NONE\n",
Harald Welte8f578a02003-05-03 18:05:58 +000057 IPTABLES_VERSION);
58}
59
60static struct option opts[] = {
61 { .name = "source-port", .has_arg = 1, .flag = 0, .val = '1' },
62 { .name = "sport", .has_arg = 1, .flag = 0, .val = '1' },
63 { .name = "destination-port", .has_arg = 1, .flag = 0, .val = '2' },
64 { .name = "dport", .has_arg = 1, .flag = 0, .val = '2' },
Harald Welte12915232004-02-21 09:20:34 +000065 { .name = "chunk-types", .has_arg = 1, .flag = 0, .val = '3' },
Harald Welte8f578a02003-05-03 18:05:58 +000066 { .name = 0 }
67};
68
69static int
70service_to_port(const char *name)
71{
72 struct servent *service;
73
74 if ((service = getservbyname(name, "sctp")) != NULL)
75 return ntohs((unsigned short) service->s_port);
76
77 return -1;
78}
79
80static u_int16_t
81parse_sctp_port(const char *port)
82{
83 unsigned int portnum;
84
Harald Welte12915232004-02-21 09:20:34 +000085 DEBUGP("%s\n", port);
Harald Welte8f578a02003-05-03 18:05:58 +000086 if (string_to_number(port, 0, 65535, &portnum) != -1 ||
87 (portnum = service_to_port(port)) != -1)
88 return (u_int16_t)portnum;
89
90 exit_error(PARAMETER_PROBLEM,
Harald Welte12915232004-02-21 09:20:34 +000091 "invalid SCTP port/service `%s' specified", port);
Harald Welte8f578a02003-05-03 18:05:58 +000092}
93
Harald Welte8f578a02003-05-03 18:05:58 +000094static void
Harald Welte12915232004-02-21 09:20:34 +000095parse_sctp_ports(const char *portstring,
96 u_int16_t *ports)
Harald Welte8f578a02003-05-03 18:05:58 +000097{
98 char *buffer;
99 char *cp;
100
101 buffer = strdup(portstring);
Harald Welte12915232004-02-21 09:20:34 +0000102 DEBUGP("%s\n", portstring);
103 if ((cp = strchr(buffer, ':')) == NULL) {
Harald Welte8f578a02003-05-03 18:05:58 +0000104 ports[0] = ports[1] = parse_sctp_port(buffer);
Harald Welte12915232004-02-21 09:20:34 +0000105 }
Harald Welte8f578a02003-05-03 18:05:58 +0000106 else {
107 *cp = '\0';
108 cp++;
109
110 ports[0] = buffer[0] ? parse_sctp_port(buffer) : 0;
111 ports[1] = cp[0] ? parse_sctp_port(cp) : 0xFFFF;
112
113 if (ports[0] > ports[1])
114 exit_error(PARAMETER_PROBLEM,
115 "invalid portrange (min > max)");
116 }
117 free(buffer);
118}
119
120struct sctp_chunk_names {
121 const char *name;
Harald Welte12915232004-02-21 09:20:34 +0000122 unsigned int chunk_type;
Kiran Kumar54924022004-03-02 18:38:27 +0000123 const char *valid_flags;
Harald Welte8f578a02003-05-03 18:05:58 +0000124};
125
Harald Welte12915232004-02-21 09:20:34 +0000126/*'ALL' and 'NONE' will be treated specially. */
Harald Welte8f578a02003-05-03 18:05:58 +0000127static struct sctp_chunk_names sctp_chunk_names[]
Kiran Kumar54924022004-03-02 18:38:27 +0000128= { { .name = "DATA", .chunk_type = 0, .valid_flags = "-----UBE"},
129 { .name = "INIT", .chunk_type = 1, .valid_flags = "--------"},
130 { .name = "INIT_ACK", .chunk_type = 2, .valid_flags = "--------"},
131 { .name = "SACK", .chunk_type = 3, .valid_flags = "--------"},
132 { .name = "HEARTBEAT", .chunk_type = 4, .valid_flags = "--------"},
133 { .name = "HEARTBEAT_ACK", .chunk_type = 5, .valid_flags = "--------"},
134 { .name = "ABORT", .chunk_type = 6, .valid_flags = "-------T"},
135 { .name = "SHUTDOWN", .chunk_type = 7, .valid_flags = "--------"},
136 { .name = "SHUTDOWN_ACK", .chunk_type = 8, .valid_flags = "--------"},
137 { .name = "ERROR", .chunk_type = 9, .valid_flags = "--------"},
138 { .name = "COOKIE_ECHO", .chunk_type = 10, .valid_flags = "--------"},
139 { .name = "COOKIE_ACK", .chunk_type = 11, .valid_flags = "--------"},
140 { .name = "ECN_ECNE", .chunk_type = 12, .valid_flags = "--------"},
141 { .name = "ECN_CWR", .chunk_type = 13, .valid_flags = "--------"},
142 { .name = "SHUTDOWN_COMPLETE", .chunk_type = 14, .valid_flags = "-------T"},
143 { .name = "ASCONF", .chunk_type = 31, .valid_flags = "--------"},
144 { .name = "ASCONF_ACK", .chunk_type = 30, .valid_flags = "--------"},
Harald Welte8f578a02003-05-03 18:05:58 +0000145};
146
Harald Welte12915232004-02-21 09:20:34 +0000147static void
Kiran Kumar54924022004-03-02 18:38:27 +0000148save_chunk_flag_info(struct ipt_sctp_flag_info *flag_info,
149 int *flag_count,
150 int chunktype,
151 int bit,
152 int set)
153{
154 int i;
155
156 for (i = 0; i < *flag_count; i++) {
157 if (flag_info[i].chunktype == chunktype) {
158 DEBUGP("Previous match found\n");
159 flag_info[i].chunktype = chunktype;
160 flag_info[i].flag_mask |= (1 << bit);
161 if (set) {
162 flag_info[i].flag |= (1 << bit);
163 }
164
165 return;
166 }
167 }
168
169 if (*flag_count == IPT_NUM_SCTP_FLAGS) {
170 exit_error (PARAMETER_PROBLEM,
171 "Number of chunk types with flags exceeds currently allowed limit."
172 "Increasing this limit involves changing IPT_NUM_SCTP_FLAGS and"
173 "recompiling both the kernel space and user space modules\n");
174 }
175
176 flag_info[*flag_count].chunktype = chunktype;
177 flag_info[*flag_count].flag_mask |= (1 << bit);
178 if (set) {
179 flag_info[*flag_count].flag |= (1 << bit);
180 }
181 (*flag_count)++;
182}
183
184static void
Harald Welte12915232004-02-21 09:20:34 +0000185parse_sctp_chunk(struct ipt_sctp_info *einfo,
186 const char *chunks)
Harald Welte8f578a02003-05-03 18:05:58 +0000187{
Harald Welte8f578a02003-05-03 18:05:58 +0000188 char *ptr;
189 char *buffer;
Kiran Kumar54924022004-03-02 18:38:27 +0000190 unsigned int i, j;
Harald Welte12915232004-02-21 09:20:34 +0000191 int found = 0;
Kiran Kumar54924022004-03-02 18:38:27 +0000192 char *chunk_flags;
Harald Welte8f578a02003-05-03 18:05:58 +0000193
Harald Welte12915232004-02-21 09:20:34 +0000194 buffer = strdup(chunks);
195 DEBUGP("Buffer: %s\n", buffer);
196
197 SCTP_CHUNKMAP_RESET(einfo->chunkmap);
198
199 if (!strcasecmp(buffer, "ALL")) {
200 SCTP_CHUNKMAP_SET_ALL(einfo->chunkmap);
201 goto out;
202 }
203
204 if (!strcasecmp(buffer, "NONE")) {
205 SCTP_CHUNKMAP_RESET(einfo->chunkmap);
206 goto out;
207 }
Harald Welte8f578a02003-05-03 18:05:58 +0000208
209 for (ptr = strtok(buffer, ","); ptr; ptr = strtok(NULL, ",")) {
Harald Welte12915232004-02-21 09:20:34 +0000210 found = 0;
211 DEBUGP("Next Chunk type %s\n", ptr);
Kiran Kumar54924022004-03-02 18:38:27 +0000212
213 if ((chunk_flags = strchr(ptr, ':')) != NULL) {
214 *chunk_flags++ = 0;
215 }
216
Harald Welte12915232004-02-21 09:20:34 +0000217 for (i = 0; i < ELEMCOUNT(sctp_chunk_names); i++) {
Harald Welte8f578a02003-05-03 18:05:58 +0000218 if (strcasecmp(sctp_chunk_names[i].name, ptr) == 0) {
Harald Welte12915232004-02-21 09:20:34 +0000219 DEBUGP("Chunk num %d\n", sctp_chunk_names[i].chunk_type);
220 SCTP_CHUNKMAP_SET(einfo->chunkmap,
221 sctp_chunk_names[i].chunk_type);
Harald Welte8f578a02003-05-03 18:05:58 +0000222 found = 1;
223 break;
224 }
225 }
226 if (!found)
227 exit_error(PARAMETER_PROBLEM,
228 "Unknown sctp chunk `%s'", ptr);
Kiran Kumar54924022004-03-02 18:38:27 +0000229
230 if (chunk_flags) {
231 DEBUGP("Chunk flags %s\n", chunk_flags);
232 for (j = 0; j < strlen(chunk_flags); j++) {
233 char *p;
234 int bit;
235
236 if ((p = strchr(sctp_chunk_names[i].valid_flags,
237 toupper(chunk_flags[j]))) != NULL) {
238 bit = p - sctp_chunk_names[i].valid_flags;
239 bit = 7 - bit;
240
241 save_chunk_flag_info(einfo->flag_info,
242 &(einfo->flag_count), i, bit,
243 isupper(chunk_flags[j]));
244 } else {
245 exit_error(PARAMETER_PROBLEM,
246 "Invalid flags for chunk type %d\n", i);
247 }
248 }
249 }
Harald Welte8f578a02003-05-03 18:05:58 +0000250 }
Harald Welte12915232004-02-21 09:20:34 +0000251out:
Harald Welte8f578a02003-05-03 18:05:58 +0000252 free(buffer);
Harald Welte8f578a02003-05-03 18:05:58 +0000253}
254
255static void
256parse_sctp_chunks(struct ipt_sctp_info *einfo,
Harald Welte12915232004-02-21 09:20:34 +0000257 const char *match_type,
258 const char *chunks)
Harald Welte8f578a02003-05-03 18:05:58 +0000259{
Harald Welte12915232004-02-21 09:20:34 +0000260 DEBUGP("Match type: %s Chunks: %s\n", match_type, chunks);
261 if (!strcasecmp(match_type, "ANY")) {
262 einfo->chunk_match_type = SCTP_CHUNK_MATCH_ANY;
263 } else if (!strcasecmp(match_type, "ALL")) {
264 einfo->chunk_match_type = SCTP_CHUNK_MATCH_ALL;
265 } else if (!strcasecmp(match_type, "ONLY")) {
266 einfo->chunk_match_type = SCTP_CHUNK_MATCH_ONLY;
267 } else {
268 exit_error (PARAMETER_PROBLEM,
269 "Match type has to be one of \"ALL\", \"ANY\" or \"ONLY\"");
270 }
Harald Welte8f578a02003-05-03 18:05:58 +0000271
Harald Welte12915232004-02-21 09:20:34 +0000272 SCTP_CHUNKMAP_RESET(einfo->chunkmap);
273 parse_sctp_chunk(einfo, chunks);
Harald Welte8f578a02003-05-03 18:05:58 +0000274}
275
Harald Welte8f578a02003-05-03 18:05:58 +0000276static int
277parse(int c, char **argv, int invert, unsigned int *flags,
278 const struct ipt_entry *entry,
279 unsigned int *nfcache,
280 struct ipt_entry_match **match)
281{
282 struct ipt_sctp_info *einfo
283 = (struct ipt_sctp_info *)(*match)->data;
284
285 switch (c) {
286 case '1':
Harald Welte12915232004-02-21 09:20:34 +0000287 if (*flags & IPT_SCTP_SRC_PORTS)
Harald Welte8f578a02003-05-03 18:05:58 +0000288 exit_error(PARAMETER_PROBLEM,
289 "Only one `--source-port' allowed");
Harald Welte12915232004-02-21 09:20:34 +0000290 einfo->flags |= IPT_SCTP_SRC_PORTS;
Harald Welte8f578a02003-05-03 18:05:58 +0000291 check_inverse(optarg, &invert, &optind, 0);
292 parse_sctp_ports(argv[optind-1], einfo->spts);
293 if (invert)
Harald Welte12915232004-02-21 09:20:34 +0000294 einfo->invflags |= IPT_SCTP_SRC_PORTS;
295 *flags |= IPT_SCTP_SRC_PORTS;
Harald Welte8f578a02003-05-03 18:05:58 +0000296 *nfcache |= NFC_IP_SRC_PT;
297 break;
298
299 case '2':
Harald Welte12915232004-02-21 09:20:34 +0000300 if (*flags & IPT_SCTP_DEST_PORTS)
Harald Welte8f578a02003-05-03 18:05:58 +0000301 exit_error(PARAMETER_PROBLEM,
302 "Only one `--destination-port' allowed");
Harald Welte12915232004-02-21 09:20:34 +0000303 einfo->flags |= IPT_SCTP_DEST_PORTS;
Harald Welte8f578a02003-05-03 18:05:58 +0000304 check_inverse(optarg, &invert, &optind, 0);
305 parse_sctp_ports(argv[optind-1], einfo->dpts);
306 if (invert)
Harald Welte12915232004-02-21 09:20:34 +0000307 einfo->invflags |= IPT_SCTP_DEST_PORTS;
308 *flags |= IPT_SCTP_DEST_PORTS;
Harald Welte8f578a02003-05-03 18:05:58 +0000309 *nfcache |= NFC_IP_DST_PT;
310 break;
311
312 case '3':
Harald Welte12915232004-02-21 09:20:34 +0000313 if (*flags & IPT_SCTP_CHUNK_TYPES)
Harald Welte8f578a02003-05-03 18:05:58 +0000314 exit_error(PARAMETER_PROBLEM,
Harald Welte12915232004-02-21 09:20:34 +0000315 "Only one `--chunk-types' allowed");
Harald Welte8f578a02003-05-03 18:05:58 +0000316 check_inverse(optarg, &invert, &optind, 0);
317
318 if (!argv[optind]
319 || argv[optind][0] == '-' || argv[optind][0] == '!')
320 exit_error(PARAMETER_PROBLEM,
Harald Welte12915232004-02-21 09:20:34 +0000321 "--chunk-types requires two args");
Harald Welte8f578a02003-05-03 18:05:58 +0000322
Harald Welte12915232004-02-21 09:20:34 +0000323 einfo->flags |= IPT_SCTP_CHUNK_TYPES;
324 parse_sctp_chunks(einfo, argv[optind-1], argv[optind]);
325 if (invert)
326 einfo->invflags |= IPT_SCTP_CHUNK_TYPES;
Harald Welte8f578a02003-05-03 18:05:58 +0000327 optind++;
Harald Welte12915232004-02-21 09:20:34 +0000328 *flags |= IPT_SCTP_CHUNK_TYPES;
Harald Welte8f578a02003-05-03 18:05:58 +0000329 break;
Harald Welte12915232004-02-21 09:20:34 +0000330
Harald Welte8f578a02003-05-03 18:05:58 +0000331 default:
332 return 0;
333 }
Harald Welte8f578a02003-05-03 18:05:58 +0000334 return 1;
335}
336
337static void
338final_check(unsigned int flags)
339{
340}
341
342static char *
343port_to_service(int port)
344{
345 struct servent *service;
346
347 if ((service = getservbyport(htons(port), "sctp")))
348 return service->s_name;
349
350 return NULL;
351}
352
353static void
354print_port(u_int16_t port, int numeric)
355{
356 char *service;
357
358 if (numeric || (service = port_to_service(port)) == NULL)
359 printf("%u", port);
360 else
361 printf("%s", service);
362}
363
364static void
365print_ports(const char *name, u_int16_t min, u_int16_t max,
366 int invert, int numeric)
367{
368 const char *inv = invert ? "!" : "";
369
370 if (min != 0 || max != 0xFFFF || invert) {
371 printf("%s", name);
372 if (min == max) {
373 printf(":%s", inv);
374 print_port(min, numeric);
375 } else {
376 printf("s:%s", inv);
377 print_port(min, numeric);
378 printf(":");
379 print_port(max, numeric);
380 }
381 printf(" ");
382 }
383}
384
385static void
Kiran Kumar54924022004-03-02 18:38:27 +0000386print_chunk_flags(u_int32_t chunknum, u_int8_t chunk_flags, u_int8_t chunk_flags_mask)
387{
388 int i;
389
390 DEBUGP("type: %d\tflags: %x\tflag mask: %x\n", chunknum, chunk_flags,
391 chunk_flags_mask);
392
393 if (chunk_flags_mask) {
394 printf(":");
395 }
396
397 for (i = 7; i >= 0; i--) {
398 if (chunk_flags_mask & (1 << i)) {
399 if (chunk_flags & (1 << i)) {
400 printf("%c", sctp_chunk_names[chunknum].valid_flags[7-i]);
401 } else {
402 printf("%c", tolower(sctp_chunk_names[chunknum].valid_flags[7-i]));
403 }
404 }
405 }
406}
407
408static void
Harald Welte12915232004-02-21 09:20:34 +0000409print_chunk(u_int32_t chunknum, int numeric)
Harald Welte8f578a02003-05-03 18:05:58 +0000410{
Harald Welte12915232004-02-21 09:20:34 +0000411 if (numeric) {
412 printf("0x%04X", chunknum);
Harald Welte8f578a02003-05-03 18:05:58 +0000413 }
Harald Welte12915232004-02-21 09:20:34 +0000414 else {
Kiran Kumar54924022004-03-02 18:38:27 +0000415 int i;
416
417 for (i = 0; i < ELEMCOUNT(sctp_chunk_names); i++) {
418 if (sctp_chunk_names[i].chunk_type == chunknum)
419 printf("%s", sctp_chunk_names[chunknum].name);
420 }
Harald Welte12915232004-02-21 09:20:34 +0000421 }
Harald Welte8f578a02003-05-03 18:05:58 +0000422}
423
424static void
Harald Welte12915232004-02-21 09:20:34 +0000425print_chunks(u_int32_t chunk_match_type,
426 const u_int32_t *chunkmap,
Kiran Kumar54924022004-03-02 18:38:27 +0000427 const struct ipt_sctp_flag_info *flag_info,
428 int flag_count,
Harald Welte12915232004-02-21 09:20:34 +0000429 int numeric)
Harald Welte8f578a02003-05-03 18:05:58 +0000430{
Kiran Kumar54924022004-03-02 18:38:27 +0000431 int i, j;
Harald Welte12915232004-02-21 09:20:34 +0000432 int flag;
433
434 switch (chunk_match_type) {
435 case SCTP_CHUNK_MATCH_ANY: printf("any "); break;
436 case SCTP_CHUNK_MATCH_ALL: printf("all "); break;
437 case SCTP_CHUNK_MATCH_ONLY: printf("only "); break;
438 default: printf("Never reach herer\n"); break;
439 }
440
441 if (SCTP_CHUNKMAP_IS_CLEAR(chunkmap)) {
442 printf("NONE ");
443 goto out;
444 }
445
446 if (SCTP_CHUNKMAP_IS_ALL_SET(chunkmap)) {
447 printf("ALL ");
448 goto out;
449 }
450
451 flag = 0;
452 for (i = 0; i < 256; i++) {
453 if (SCTP_CHUNKMAP_IS_SET(chunkmap, i)) {
454 flag && printf(",");
455 flag = 1;
456 print_chunk(i, numeric);
Kiran Kumar54924022004-03-02 18:38:27 +0000457 for (j = 0; j < flag_count; j++) {
458 if (flag_info[j].chunktype == i) {
459 print_chunk_flags(i, flag_info[j].flag,
460 flag_info[j].flag_mask);
461 }
462 }
Harald Welte8f578a02003-05-03 18:05:58 +0000463 }
464 }
Harald Welte12915232004-02-21 09:20:34 +0000465
466 flag && printf(" ");
467out:
468 return;
Harald Welte8f578a02003-05-03 18:05:58 +0000469}
470
471/* Prints out the matchinfo. */
472static void
473print(const struct ipt_ip *ip,
474 const struct ipt_entry_match *match,
475 int numeric)
476{
477 const struct ipt_sctp_info *einfo =
478 (const struct ipt_sctp_info *)match->data;
479
480 printf("sctp ");
481
Harald Welte12915232004-02-21 09:20:34 +0000482 if (einfo->flags & IPT_SCTP_SRC_PORTS) {
483 print_ports("spt", einfo->spts[0], einfo->spts[1],
484 einfo->invflags & IPT_SCTP_SRC_PORTS,
485 numeric);
486 }
Harald Welte8f578a02003-05-03 18:05:58 +0000487
Harald Welte12915232004-02-21 09:20:34 +0000488 if (einfo->flags & IPT_SCTP_DEST_PORTS) {
489 print_ports("dpt", einfo->dpts[0], einfo->dpts[1],
490 einfo->invflags & IPT_SCTP_DEST_PORTS,
491 numeric);
492 }
493
494 if (einfo->flags & IPT_SCTP_CHUNK_TYPES) {
495 /* FIXME: print_chunks() is used in save() where the printing of '!'
496 s taken care of, so we need to do that here as well */
497 if (einfo->invflags & IPT_SCTP_CHUNK_TYPES) {
498 printf("! ");
499 }
Kiran Kumar54924022004-03-02 18:38:27 +0000500 print_chunks(einfo->chunk_match_type, einfo->chunkmap,
501 einfo->flag_info, einfo->flag_count, numeric);
Harald Welte12915232004-02-21 09:20:34 +0000502 }
Harald Welte8f578a02003-05-03 18:05:58 +0000503}
504
505/* Saves the union ipt_matchinfo in parsable form to stdout. */
506static void
Harald Welte12915232004-02-21 09:20:34 +0000507save(const struct ipt_ip *ip,
508 const struct ipt_entry_match *match)
Harald Welte8f578a02003-05-03 18:05:58 +0000509{
510 const struct ipt_sctp_info *einfo =
511 (const struct ipt_sctp_info *)match->data;
512
Harald Welte12915232004-02-21 09:20:34 +0000513 if (einfo->flags & IPT_SCTP_SRC_PORTS) {
514 if (einfo->invflags & IPT_SCTP_SRC_PORTS)
Harald Welte8f578a02003-05-03 18:05:58 +0000515 printf("! ");
516 if (einfo->spts[0] != einfo->spts[1])
517 printf("--sport %u:%u ",
518 einfo->spts[0], einfo->spts[1]);
519 else
520 printf("--sport %u ", einfo->spts[0]);
521 }
522
Harald Welte12915232004-02-21 09:20:34 +0000523 if (einfo->flags & IPT_SCTP_DEST_PORTS) {
524 if (einfo->invflags & IPT_SCTP_DEST_PORTS)
Harald Welte8f578a02003-05-03 18:05:58 +0000525 printf("! ");
526 if (einfo->dpts[0] != einfo->dpts[1])
527 printf("--dport %u:%u ",
528 einfo->dpts[0], einfo->dpts[1]);
529 else
530 printf("--dport %u ", einfo->dpts[0]);
531 }
532
Harald Welte12915232004-02-21 09:20:34 +0000533 if (einfo->flags & IPT_SCTP_CHUNK_TYPES) {
534 if (einfo->invflags & IPT_SCTP_CHUNK_TYPES)
Harald Welte8f578a02003-05-03 18:05:58 +0000535 printf("! ");
Harald Welte12915232004-02-21 09:20:34 +0000536 printf("--chunk-types ");
537
Kiran Kumar54924022004-03-02 18:38:27 +0000538 print_chunks(einfo->chunk_match_type, einfo->chunkmap,
539 einfo->flag_info, einfo->flag_count, 0);
Harald Welte8f578a02003-05-03 18:05:58 +0000540 }
541}
542
543static
544struct iptables_match sctp
545= { .name = "sctp",
546 .version = IPTABLES_VERSION,
547 .size = IPT_ALIGN(sizeof(struct ipt_sctp_info)),
548 .userspacesize = IPT_ALIGN(sizeof(struct ipt_sctp_info)),
549 .help = &help,
550 .init = &init,
551 .parse = &parse,
552 .final_check = &final_check,
553 .print = &print,
554 .save = &save,
555 .extra_opts = opts
556};
557
558void _init(void)
559{
560 register_match(&sctp);
561}
Harald Welte12915232004-02-21 09:20:34 +0000562