blob: 4d914e39a1feb55592563dcbe211a5396b5a633b [file] [log] [blame]
Marc Bouchere6869a82000-03-20 06:03:29 +00001/* Shared library add-on to iptables to add TCP support. */
Jan Engelhardt32b8e612010-07-23 21:16:14 +02002#include <stdbool.h>
Marc Bouchere6869a82000-03-20 06:03:29 +00003#include <stdio.h>
4#include <netdb.h>
5#include <string.h>
6#include <stdlib.h>
7#include <getopt.h>
Thomas Jaroschecae0c32008-10-23 15:41:27 +02008#include <netinet/in.h>
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +00009#include <xtables.h>
10#include <linux/netfilter/xt_tcpudp.h>
Marc Bouchere6869a82000-03-20 06:03:29 +000011
Jan Engelhardt181dead2007-10-04 16:27:07 +000012static void tcp_help(void)
Marc Bouchere6869a82000-03-20 06:03:29 +000013{
14 printf(
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020015"tcp match options:\n"
Jan Engelhardt96727922008-08-13 14:42:41 +020016"[!] --tcp-flags mask comp match when TCP flags & mask == comp\n"
Marc Bouchere6869a82000-03-20 06:03:29 +000017" (Flags: SYN ACK FIN RST URG PSH ALL NONE)\n"
18"[!] --syn match when only SYN flag set\n"
Patrick McHardyYasuyuki KOZAKAIa8a4f5d2007-07-16 15:27:38 +000019" (equivalent to --tcp-flags SYN,RST,ACK,FIN SYN)\n"
Jan Engelhardt96727922008-08-13 14:42:41 +020020"[!] --source-port port[:port]\n"
Marc Bouchere6869a82000-03-20 06:03:29 +000021" --sport ...\n"
22" match source port(s)\n"
Jan Engelhardt96727922008-08-13 14:42:41 +020023"[!] --destination-port port[:port]\n"
Marc Bouchere6869a82000-03-20 06:03:29 +000024" --dport ...\n"
25" match destination port(s)\n"
Jan Engelhardt96727922008-08-13 14:42:41 +020026"[!] --tcp-option number match if TCP option set\n");
Marc Bouchere6869a82000-03-20 06:03:29 +000027}
28
Jan Engelhardt181dead2007-10-04 16:27:07 +000029static const struct option tcp_opts[] = {
Jan Engelhardt32b8e612010-07-23 21:16:14 +020030 {.name = "source-port", .has_arg = true, .val = '1'},
31 {.name = "sport", .has_arg = true, .val = '1'}, /* synonym */
32 {.name = "destination-port", .has_arg = true, .val = '2'},
33 {.name = "dport", .has_arg = true, .val = '2'}, /* synonym */
34 {.name = "syn", .has_arg = false, .val = '3'},
35 {.name = "tcp-flags", .has_arg = true, .val = '4'},
36 {.name = "tcp-option", .has_arg = true, .val = '5'},
37 XT_GETOPT_TABLEEND,
Marc Bouchere6869a82000-03-20 06:03:29 +000038};
39
Marc Bouchere6869a82000-03-20 06:03:29 +000040static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +010041parse_tcp_ports(const char *portstring, uint16_t *ports)
Marc Bouchere6869a82000-03-20 06:03:29 +000042{
43 char *buffer;
44 char *cp;
45
46 buffer = strdup(portstring);
47 if ((cp = strchr(buffer, ':')) == NULL)
Jan Engelhardtaae6be92009-01-30 04:24:47 +010048 ports[0] = ports[1] = xtables_parse_port(buffer, "tcp");
Marc Bouchere6869a82000-03-20 06:03:29 +000049 else {
50 *cp = '\0';
51 cp++;
52
Jan Engelhardtaae6be92009-01-30 04:24:47 +010053 ports[0] = buffer[0] ? xtables_parse_port(buffer, "tcp") : 0;
54 ports[1] = cp[0] ? xtables_parse_port(cp, "tcp") : 0xFFFF;
Harald Welted15fb342002-07-26 16:27:57 +000055
56 if (ports[0] > ports[1])
Jan Engelhardt1829ed42009-02-21 03:29:44 +010057 xtables_error(PARAMETER_PROBLEM,
Harald Welted15fb342002-07-26 16:27:57 +000058 "invalid portrange (min > max)");
Marc Bouchere6869a82000-03-20 06:03:29 +000059 }
60 free(buffer);
61}
62
63struct tcp_flag_names {
64 const char *name;
65 unsigned int flag;
66};
67
Jan Engelhardt0e2abed2007-10-04 16:25:58 +000068static const struct tcp_flag_names tcp_flag_names[]
Marc Bouchere6869a82000-03-20 06:03:29 +000069= { { "FIN", 0x01 },
70 { "SYN", 0x02 },
71 { "RST", 0x04 },
72 { "PSH", 0x08 },
73 { "ACK", 0x10 },
74 { "URG", 0x20 },
75 { "ALL", 0x3F },
76 { "NONE", 0 },
77};
78
79static unsigned int
80parse_tcp_flag(const char *flags)
81{
82 unsigned int ret = 0;
83 char *ptr;
84 char *buffer;
85
86 buffer = strdup(flags);
87
88 for (ptr = strtok(buffer, ","); ptr; ptr = strtok(NULL, ",")) {
89 unsigned int i;
Jan Engelhardt2c69b552009-04-30 19:32:02 +020090 for (i = 0; i < ARRAY_SIZE(tcp_flag_names); ++i)
Marc Bouchere6869a82000-03-20 06:03:29 +000091 if (strcasecmp(tcp_flag_names[i].name, ptr) == 0) {
92 ret |= tcp_flag_names[i].flag;
93 break;
94 }
Jan Engelhardt2c69b552009-04-30 19:32:02 +020095 if (i == ARRAY_SIZE(tcp_flag_names))
Jan Engelhardt1829ed42009-02-21 03:29:44 +010096 xtables_error(PARAMETER_PROBLEM,
Harald Welte2aa78fe2003-03-30 18:29:56 +000097 "Unknown TCP flag `%s'", ptr);
Jan Engelhardt2c69b552009-04-30 19:32:02 +020098 }
Marc Bouchere6869a82000-03-20 06:03:29 +000099
100 free(buffer);
101 return ret;
102}
103
104static void
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000105parse_tcp_flags(struct xt_tcp *tcpinfo,
Marc Bouchere6869a82000-03-20 06:03:29 +0000106 const char *mask,
107 const char *cmp,
108 int invert)
109{
110 tcpinfo->flg_mask = parse_tcp_flag(mask);
111 tcpinfo->flg_cmp = parse_tcp_flag(cmp);
112
113 if (invert)
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000114 tcpinfo->invflags |= XT_TCP_INV_FLAGS;
Marc Bouchere6869a82000-03-20 06:03:29 +0000115}
116
117static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100118parse_tcp_option(const char *option, uint8_t *result)
Marc Bouchere6869a82000-03-20 06:03:29 +0000119{
Harald Welteb4719762001-07-23 02:14:22 +0000120 unsigned int ret;
Marc Bouchere6869a82000-03-20 06:03:29 +0000121
Jan Engelhardt5f2922c2009-01-27 18:43:01 +0100122 if (!xtables_strtoui(option, NULL, &ret, 1, UINT8_MAX))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100123 xtables_error(PARAMETER_PROBLEM, "Bad TCP option \"%s\"", option);
Marc Bouchere6869a82000-03-20 06:03:29 +0000124
Jan Engelhardt213e1852009-01-27 17:24:34 +0100125 *result = ret;
Marc Bouchere6869a82000-03-20 06:03:29 +0000126}
127
Jan Engelhardt181dead2007-10-04 16:27:07 +0000128static void tcp_init(struct xt_entry_match *m)
Marc Bouchere6869a82000-03-20 06:03:29 +0000129{
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000130 struct xt_tcp *tcpinfo = (struct xt_tcp *)m->data;
Marc Bouchere6869a82000-03-20 06:03:29 +0000131
132 tcpinfo->spts[1] = tcpinfo->dpts[1] = 0xFFFF;
133}
134
135#define TCP_SRC_PORTS 0x01
136#define TCP_DST_PORTS 0x02
137#define TCP_FLAGS 0x04
138#define TCP_OPTION 0x08
139
Marc Bouchere6869a82000-03-20 06:03:29 +0000140static int
Jan Engelhardt181dead2007-10-04 16:27:07 +0000141tcp_parse(int c, char **argv, int invert, unsigned int *flags,
142 const void *entry, struct xt_entry_match **match)
Marc Bouchere6869a82000-03-20 06:03:29 +0000143{
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000144 struct xt_tcp *tcpinfo = (struct xt_tcp *)(*match)->data;
Marc Bouchere6869a82000-03-20 06:03:29 +0000145
146 switch (c) {
147 case '1':
148 if (*flags & TCP_SRC_PORTS)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100149 xtables_error(PARAMETER_PROBLEM,
Marc Bouchere6869a82000-03-20 06:03:29 +0000150 "Only one `--source-port' allowed");
Jan Engelhardtbf971282009-11-03 19:55:11 +0100151 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200152 parse_tcp_ports(optarg, tcpinfo->spts);
Marc Bouchere6869a82000-03-20 06:03:29 +0000153 if (invert)
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000154 tcpinfo->invflags |= XT_TCP_INV_SRCPT;
Marc Bouchere6869a82000-03-20 06:03:29 +0000155 *flags |= TCP_SRC_PORTS;
Marc Bouchere6869a82000-03-20 06:03:29 +0000156 break;
157
158 case '2':
159 if (*flags & TCP_DST_PORTS)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100160 xtables_error(PARAMETER_PROBLEM,
Marc Bouchere6869a82000-03-20 06:03:29 +0000161 "Only one `--destination-port' allowed");
Jan Engelhardtbf971282009-11-03 19:55:11 +0100162 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200163 parse_tcp_ports(optarg, tcpinfo->dpts);
Marc Bouchere6869a82000-03-20 06:03:29 +0000164 if (invert)
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000165 tcpinfo->invflags |= XT_TCP_INV_DSTPT;
Marc Bouchere6869a82000-03-20 06:03:29 +0000166 *flags |= TCP_DST_PORTS;
Marc Bouchere6869a82000-03-20 06:03:29 +0000167 break;
168
169 case '3':
170 if (*flags & TCP_FLAGS)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100171 xtables_error(PARAMETER_PROBLEM,
Marc Bouchere6869a82000-03-20 06:03:29 +0000172 "Only one of `--syn' or `--tcp-flags' "
173 " allowed");
Harald Welte38ed4212005-05-04 07:34:37 +0000174 parse_tcp_flags(tcpinfo, "SYN,RST,ACK,FIN", "SYN", invert);
Marc Bouchere6869a82000-03-20 06:03:29 +0000175 *flags |= TCP_FLAGS;
Marc Bouchere6869a82000-03-20 06:03:29 +0000176 break;
177
178 case '4':
179 if (*flags & TCP_FLAGS)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100180 xtables_error(PARAMETER_PROBLEM,
Marc Bouchere6869a82000-03-20 06:03:29 +0000181 "Only one of `--syn' or `--tcp-flags' "
182 " allowed");
Jan Engelhardtbf971282009-11-03 19:55:11 +0100183 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Marc Bouchere6869a82000-03-20 06:03:29 +0000184
185 if (!argv[optind]
186 || argv[optind][0] == '-' || argv[optind][0] == '!')
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100187 xtables_error(PARAMETER_PROBLEM,
Marc Bouchere6869a82000-03-20 06:03:29 +0000188 "--tcp-flags requires two args.");
189
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200190 parse_tcp_flags(tcpinfo, optarg, argv[optind],
Rusty Russell78001fe2000-09-01 05:22:10 +0000191 invert);
Rusty Russellfa9f9f92000-09-01 05:39:52 +0000192 optind++;
Marc Bouchere6869a82000-03-20 06:03:29 +0000193 *flags |= TCP_FLAGS;
Marc Bouchere6869a82000-03-20 06:03:29 +0000194 break;
195
196 case '5':
197 if (*flags & TCP_OPTION)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100198 xtables_error(PARAMETER_PROBLEM,
Marc Bouchere6869a82000-03-20 06:03:29 +0000199 "Only one `--tcp-option' allowed");
Jan Engelhardtbf971282009-11-03 19:55:11 +0100200 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200201 parse_tcp_option(optarg, &tcpinfo->option);
Marc Bouchere6869a82000-03-20 06:03:29 +0000202 if (invert)
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000203 tcpinfo->invflags |= XT_TCP_INV_OPTION;
Marc Bouchere6869a82000-03-20 06:03:29 +0000204 *flags |= TCP_OPTION;
Marc Bouchere6869a82000-03-20 06:03:29 +0000205 break;
Marc Bouchere6869a82000-03-20 06:03:29 +0000206 }
207
208 return 1;
209}
210
Jan Engelhardtdd6e4b92011-05-07 00:05:24 +0200211static const char *
Marc Bouchere6869a82000-03-20 06:03:29 +0000212port_to_service(int port)
213{
Jan Engelhardtdd6e4b92011-05-07 00:05:24 +0200214 const struct servent *service;
Marc Bouchere6869a82000-03-20 06:03:29 +0000215
216 if ((service = getservbyport(htons(port), "tcp")))
217 return service->s_name;
218
219 return NULL;
220}
221
222static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100223print_port(uint16_t port, int numeric)
Marc Bouchere6869a82000-03-20 06:03:29 +0000224{
Jan Engelhardtdd6e4b92011-05-07 00:05:24 +0200225 const char *service;
Marc Bouchere6869a82000-03-20 06:03:29 +0000226
227 if (numeric || (service = port_to_service(port)) == NULL)
228 printf("%u", port);
229 else
230 printf("%s", service);
231}
232
233static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100234print_ports(const char *name, uint16_t min, uint16_t max,
Marc Bouchere6869a82000-03-20 06:03:29 +0000235 int invert, int numeric)
236{
237 const char *inv = invert ? "!" : "";
238
239 if (min != 0 || max != 0xFFFF || invert) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100240 printf(" %s", name);
Marc Bouchere6869a82000-03-20 06:03:29 +0000241 if (min == max) {
242 printf(":%s", inv);
243 print_port(min, numeric);
244 } else {
245 printf("s:%s", inv);
246 print_port(min, numeric);
247 printf(":");
248 print_port(max, numeric);
249 }
Marc Bouchere6869a82000-03-20 06:03:29 +0000250 }
251}
252
253static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100254print_option(uint8_t option, int invert, int numeric)
Marc Bouchere6869a82000-03-20 06:03:29 +0000255{
256 if (option || invert)
Jan Engelhardt73866352010-12-18 02:04:59 +0100257 printf(" option=%s%u", invert ? "!" : "", option);
Marc Bouchere6869a82000-03-20 06:03:29 +0000258}
259
260static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100261print_tcpf(uint8_t flags)
Marc Bouchere6869a82000-03-20 06:03:29 +0000262{
Rusty Russelledf14cf2000-04-19 11:26:44 +0000263 int have_flag = 0;
Marc Bouchere6869a82000-03-20 06:03:29 +0000264
Rusty Russelledf14cf2000-04-19 11:26:44 +0000265 while (flags) {
Marc Bouchere6869a82000-03-20 06:03:29 +0000266 unsigned int i;
267
Rusty Russelledf14cf2000-04-19 11:26:44 +0000268 for (i = 0; (flags & tcp_flag_names[i].flag) == 0; i++);
Marc Bouchere6869a82000-03-20 06:03:29 +0000269
Rusty Russelledf14cf2000-04-19 11:26:44 +0000270 if (have_flag)
Marc Bouchere6869a82000-03-20 06:03:29 +0000271 printf(",");
272 printf("%s", tcp_flag_names[i].name);
Rusty Russelledf14cf2000-04-19 11:26:44 +0000273 have_flag = 1;
Marc Bouchere6869a82000-03-20 06:03:29 +0000274
275 flags &= ~tcp_flag_names[i].flag;
Rusty Russelledf14cf2000-04-19 11:26:44 +0000276 }
277
278 if (!have_flag)
279 printf("NONE");
Marc Bouchere6869a82000-03-20 06:03:29 +0000280}
281
282static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100283print_flags(uint8_t mask, uint8_t cmp, int invert, int numeric)
Marc Bouchere6869a82000-03-20 06:03:29 +0000284{
285 if (mask || invert) {
286 printf("flags:%s", invert ? "!" : "");
287 if (numeric)
Jan Engelhardt73866352010-12-18 02:04:59 +0100288 printf(" 0x%02X/0x%02X", mask, cmp);
Marc Bouchere6869a82000-03-20 06:03:29 +0000289 else {
Jan Engelhardt73866352010-12-18 02:04:59 +0100290 printf(" ");
Marc Bouchere6869a82000-03-20 06:03:29 +0000291 print_tcpf(mask);
Rusty Russell31728072000-09-01 06:29:06 +0000292 printf("/");
293 print_tcpf(cmp);
Marc Bouchere6869a82000-03-20 06:03:29 +0000294 }
295 }
296}
297
Marc Bouchere6869a82000-03-20 06:03:29 +0000298static void
Jan Engelhardt181dead2007-10-04 16:27:07 +0000299tcp_print(const void *ip, const struct xt_entry_match *match, int numeric)
Marc Bouchere6869a82000-03-20 06:03:29 +0000300{
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000301 const struct xt_tcp *tcp = (struct xt_tcp *)match->data;
Marc Bouchere6869a82000-03-20 06:03:29 +0000302
Jan Engelhardt73866352010-12-18 02:04:59 +0100303 printf(" tcp");
Marc Bouchere6869a82000-03-20 06:03:29 +0000304 print_ports("spt", tcp->spts[0], tcp->spts[1],
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000305 tcp->invflags & XT_TCP_INV_SRCPT,
Marc Bouchere6869a82000-03-20 06:03:29 +0000306 numeric);
307 print_ports("dpt", tcp->dpts[0], tcp->dpts[1],
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000308 tcp->invflags & XT_TCP_INV_DSTPT,
Marc Bouchere6869a82000-03-20 06:03:29 +0000309 numeric);
310 print_option(tcp->option,
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000311 tcp->invflags & XT_TCP_INV_OPTION,
Marc Bouchere6869a82000-03-20 06:03:29 +0000312 numeric);
313 print_flags(tcp->flg_mask, tcp->flg_cmp,
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000314 tcp->invflags & XT_TCP_INV_FLAGS,
Marc Bouchere6869a82000-03-20 06:03:29 +0000315 numeric);
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000316 if (tcp->invflags & ~XT_TCP_INV_MASK)
Jan Engelhardt73866352010-12-18 02:04:59 +0100317 printf(" Unknown invflags: 0x%X",
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000318 tcp->invflags & ~XT_TCP_INV_MASK);
Marc Bouchere6869a82000-03-20 06:03:29 +0000319}
320
Jan Engelhardt181dead2007-10-04 16:27:07 +0000321static void tcp_save(const void *ip, const struct xt_entry_match *match)
Marc Bouchere6869a82000-03-20 06:03:29 +0000322{
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000323 const struct xt_tcp *tcpinfo = (struct xt_tcp *)match->data;
Marc Bouchere6869a82000-03-20 06:03:29 +0000324
325 if (tcpinfo->spts[0] != 0
Rusty Russell73f72f52000-07-03 10:17:57 +0000326 || tcpinfo->spts[1] != 0xFFFF) {
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000327 if (tcpinfo->invflags & XT_TCP_INV_SRCPT)
Jan Engelhardt73866352010-12-18 02:04:59 +0100328 printf(" !");
Marc Bouchere6869a82000-03-20 06:03:29 +0000329 if (tcpinfo->spts[0]
330 != tcpinfo->spts[1])
Jan Engelhardt73866352010-12-18 02:04:59 +0100331 printf(" --sport %u:%u",
Marc Boucher9f2009c2000-04-07 17:30:28 +0000332 tcpinfo->spts[0],
333 tcpinfo->spts[1]);
Marc Bouchere6869a82000-03-20 06:03:29 +0000334 else
Jan Engelhardt73866352010-12-18 02:04:59 +0100335 printf(" --sport %u",
Marc Boucher9f2009c2000-04-07 17:30:28 +0000336 tcpinfo->spts[0]);
Marc Bouchere6869a82000-03-20 06:03:29 +0000337 }
338
339 if (tcpinfo->dpts[0] != 0
Rusty Russell73f72f52000-07-03 10:17:57 +0000340 || tcpinfo->dpts[1] != 0xFFFF) {
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000341 if (tcpinfo->invflags & XT_TCP_INV_DSTPT)
Jan Engelhardt73866352010-12-18 02:04:59 +0100342 printf(" !");
Marc Bouchere6869a82000-03-20 06:03:29 +0000343 if (tcpinfo->dpts[0]
344 != tcpinfo->dpts[1])
Jan Engelhardt73866352010-12-18 02:04:59 +0100345 printf(" --dport %u:%u",
Marc Boucher9f2009c2000-04-07 17:30:28 +0000346 tcpinfo->dpts[0],
347 tcpinfo->dpts[1]);
Marc Bouchere6869a82000-03-20 06:03:29 +0000348 else
Jan Engelhardt73866352010-12-18 02:04:59 +0100349 printf(" --dport %u",
Marc Boucher9f2009c2000-04-07 17:30:28 +0000350 tcpinfo->dpts[0]);
Marc Bouchere6869a82000-03-20 06:03:29 +0000351 }
352
353 if (tcpinfo->option
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000354 || (tcpinfo->invflags & XT_TCP_INV_OPTION)) {
355 if (tcpinfo->invflags & XT_TCP_INV_OPTION)
Jan Engelhardt73866352010-12-18 02:04:59 +0100356 printf(" !");
357 printf(" --tcp-option %u", tcpinfo->option);
Marc Bouchere6869a82000-03-20 06:03:29 +0000358 }
359
360 if (tcpinfo->flg_mask
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000361 || (tcpinfo->invflags & XT_TCP_INV_FLAGS)) {
362 if (tcpinfo->invflags & XT_TCP_INV_FLAGS)
Jan Engelhardt73866352010-12-18 02:04:59 +0100363 printf(" !");
364 printf(" --tcp-flags ");
Marc Bouchere6869a82000-03-20 06:03:29 +0000365 if (tcpinfo->flg_mask != 0xFF) {
Marc Bouchere6869a82000-03-20 06:03:29 +0000366 print_tcpf(tcpinfo->flg_mask);
367 }
Harald Welte67f23b22000-11-05 17:53:06 +0000368 printf(" ");
369 print_tcpf(tcpinfo->flg_cmp);
Marc Bouchere6869a82000-03-20 06:03:29 +0000370 }
371}
372
Jan Engelhardt181dead2007-10-04 16:27:07 +0000373static struct xtables_match tcp_match = {
Jan Engelhardtc5e85732009-06-12 20:55:44 +0200374 .family = NFPROTO_UNSPEC,
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000375 .name = "tcp",
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +0200376 .version = XTABLES_VERSION,
Yasuyuki KOZAKAI95f186e2007-07-24 06:59:00 +0000377 .size = XT_ALIGN(sizeof(struct xt_tcp)),
378 .userspacesize = XT_ALIGN(sizeof(struct xt_tcp)),
Jan Engelhardt181dead2007-10-04 16:27:07 +0000379 .help = tcp_help,
380 .init = tcp_init,
381 .parse = tcp_parse,
382 .print = tcp_print,
383 .save = tcp_save,
384 .extra_opts = tcp_opts,
Pablo Neira8caee8b2004-12-28 13:11:59 +0000385};
Marc Bouchere6869a82000-03-20 06:03:29 +0000386
387void
388_init(void)
389{
Jan Engelhardt181dead2007-10-04 16:27:07 +0000390 xtables_register_match(&tcp_match);
Marc Bouchere6869a82000-03-20 06:03:29 +0000391}