1 /* Shared library add-on to iptables to add tcp MSS matching support. */
9 #include <linux/netfilter_ipv4/ipt_tcpmss.h>
11 /* Function which prints out usage message. */
16 "tcpmss match v%s options:\n"
17 "[!] --mss value[:value] Match TCP MSS range.\n"
18 " (only valid for TCP SYN or SYN/ACK packets)\n",
22 static struct option opts[] = {
27 /* Initialize the match. */
29 init(struct ipt_entry_match *m, unsigned int *nfcache)
31 *nfcache |= NFC_IP_PROTO_UNKNOWN;
35 parse_tcp_mssvalue(const char *mssvalue)
37 unsigned int mssvaluenum;
39 if (string_to_number(mssvalue, 0, 65535, &mssvaluenum) != -1)
40 return (u_int16_t)mssvaluenum;
42 exit_error(PARAMETER_PROBLEM,
43 "Invalid mss `%s' specified", mssvalue);
47 parse_tcp_mssvalues(const char *mssvaluestring,
48 u_int16_t *mss_min, u_int16_t *mss_max)
53 buffer = strdup(mssvaluestring);
54 if ((cp = strchr(buffer, ':')) == NULL)
55 *mss_min = *mss_max = parse_tcp_mssvalue(buffer);
60 *mss_min = buffer[0] ? parse_tcp_mssvalue(buffer) : 0;
61 *mss_max = cp[0] ? parse_tcp_mssvalue(cp) : 0xFFFF;
66 /* Function which parses command options; returns true if it
69 parse(int c, char **argv, int invert, unsigned int *flags,
70 const struct ipt_entry *entry,
71 unsigned int *nfcache,
72 struct ipt_entry_match **match)
74 struct ipt_tcpmss_match_info *mssinfo =
75 (struct ipt_tcpmss_match_info *)(*match)->data;
80 exit_error(PARAMETER_PROBLEM,
81 "Only one `--mss' allowed");
82 check_inverse(optarg, &invert, &optind, 0);
83 parse_tcp_mssvalues(argv[optind-1],
84 &mssinfo->mss_min, &mssinfo->mss_max);
96 print_tcpmss(u_int16_t mss_min, u_int16_t mss_max, int invert, int numeric)
101 if (mss_min == mss_max)
102 printf("%u ", mss_min);
104 printf("%u:%u ", mss_min, mss_max);
107 /* Final check; must have specified --mss. */
109 final_check(unsigned int flags)
112 exit_error(PARAMETER_PROBLEM,
113 "tcpmss match: You must specify `--mss'");
116 /* Prints out the matchinfo. */
118 print(const struct ipt_ip *ip,
119 const struct ipt_entry_match *match,
122 const struct ipt_tcpmss_match_info *mssinfo =
123 (const struct ipt_tcpmss_match_info *)match->data;
125 printf("tcpmss match ");
126 print_tcpmss(mssinfo->mss_min, mssinfo->mss_max,
127 mssinfo->invert, numeric);
130 /* Saves the union ipt_matchinfo in parsable form to stdout. */
132 save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
134 const struct ipt_tcpmss_match_info *mssinfo =
135 (const struct ipt_tcpmss_match_info *)match->data;
138 print_tcpmss(mssinfo->mss_min, mssinfo->mss_max,
143 struct iptables_match tcpmss
147 IPT_ALIGN(sizeof(struct ipt_tcpmss_match_info)),
148 IPT_ALIGN(sizeof(struct ipt_tcpmss_match_info)),
160 register_match(&tcpmss);