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[] = {
28 parse_tcp_mssvalue(const char *mssvalue)
30 unsigned int mssvaluenum;
32 if (string_to_number(mssvalue, 0, 65535, &mssvaluenum) != -1)
33 return (u_int16_t)mssvaluenum;
35 exit_error(PARAMETER_PROBLEM,
36 "Invalid mss `%s' specified", mssvalue);
40 parse_tcp_mssvalues(const char *mssvaluestring,
41 u_int16_t *mss_min, u_int16_t *mss_max)
46 buffer = strdup(mssvaluestring);
47 if ((cp = strchr(buffer, ':')) == NULL)
48 *mss_min = *mss_max = parse_tcp_mssvalue(buffer);
53 *mss_min = buffer[0] ? parse_tcp_mssvalue(buffer) : 0;
54 *mss_max = cp[0] ? parse_tcp_mssvalue(cp) : 0xFFFF;
59 /* Function which parses command options; returns true if it
62 parse(int c, char **argv, int invert, unsigned int *flags,
63 const struct ipt_entry *entry,
64 unsigned int *nfcache,
65 struct ipt_entry_match **match)
67 struct ipt_tcpmss_match_info *mssinfo =
68 (struct ipt_tcpmss_match_info *)(*match)->data;
73 exit_error(PARAMETER_PROBLEM,
74 "Only one `--mss' allowed");
75 check_inverse(optarg, &invert, &optind, 0);
76 parse_tcp_mssvalues(argv[optind-1],
77 &mssinfo->mss_min, &mssinfo->mss_max);
89 print_tcpmss(u_int16_t mss_min, u_int16_t mss_max, int invert, int numeric)
94 if (mss_min == mss_max)
95 printf("%u ", mss_min);
97 printf("%u:%u ", mss_min, mss_max);
100 /* Final check; must have specified --mss. */
102 final_check(unsigned int flags)
105 exit_error(PARAMETER_PROBLEM,
106 "tcpmss match: You must specify `--mss'");
109 /* Prints out the matchinfo. */
111 print(const struct ipt_ip *ip,
112 const struct ipt_entry_match *match,
115 const struct ipt_tcpmss_match_info *mssinfo =
116 (const struct ipt_tcpmss_match_info *)match->data;
118 printf("tcpmss match ");
119 print_tcpmss(mssinfo->mss_min, mssinfo->mss_max,
120 mssinfo->invert, numeric);
123 /* Saves the union ipt_matchinfo in parsable form to stdout. */
125 save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
127 const struct ipt_tcpmss_match_info *mssinfo =
128 (const struct ipt_tcpmss_match_info *)match->data;
131 print_tcpmss(mssinfo->mss_min, mssinfo->mss_max,
135 static struct iptables_match tcpmss = {
138 .version = IPTABLES_VERSION,
139 .size = IPT_ALIGN(sizeof(struct ipt_tcpmss_match_info)),
140 .userspacesize = IPT_ALIGN(sizeof(struct ipt_tcpmss_match_info)),
143 .final_check = &final_check,
151 register_match(&tcpmss);