1 /* Kernel module to match TCP MSS values. */
3 /* Copyright (C) 2000 Marc Boucher <marc@mbsi.ca>
4 * Portions (C) 2005 by Harald Welte <laforge@netfilter.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
15 #include <linux/netfilter/xt_tcpmss.h>
16 #include <linux/netfilter/x_tables.h>
18 #include <linux/netfilter_ipv4/ip_tables.h>
19 #include <linux/netfilter_ipv6/ip6_tables.h>
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
23 MODULE_DESCRIPTION("Xtables: TCP MSS match");
24 MODULE_ALIAS("ipt_tcpmss");
25 MODULE_ALIAS("ip6t_tcpmss");
28 tcpmss_mt(const struct sk_buff
*skb
, const struct xt_match_param
*par
)
30 const struct xt_tcpmss_match_info
*info
= par
->matchinfo
;
31 const struct tcphdr
*th
;
33 /* tcp.doff is only 4 bits, ie. max 15 * 4 bytes */
35 u8 _opt
[15 * 4 - sizeof(_tcph
)];
36 unsigned int i
, optlen
;
38 /* If we don't have the whole header, drop packet. */
39 th
= skb_header_pointer(skb
, par
->thoff
, sizeof(_tcph
), &_tcph
);
44 if (th
->doff
*4 < sizeof(*th
))
47 optlen
= th
->doff
*4 - sizeof(*th
);
51 /* Truncated options. */
52 op
= skb_header_pointer(skb
, par
->thoff
+ sizeof(*th
), optlen
, _opt
);
56 for (i
= 0; i
< optlen
; ) {
57 if (op
[i
] == TCPOPT_MSS
58 && (optlen
- i
) >= TCPOLEN_MSS
59 && op
[i
+1] == TCPOLEN_MSS
) {
62 mssval
= (op
[i
+2] << 8) | op
[i
+3];
64 return (mssval
>= info
->mss_min
&&
65 mssval
<= info
->mss_max
) ^ info
->invert
;
80 static struct xt_match tcpmss_mt_reg
[] __read_mostly
= {
83 .family
= NFPROTO_IPV4
,
85 .matchsize
= sizeof(struct xt_tcpmss_match_info
),
91 .family
= NFPROTO_IPV6
,
93 .matchsize
= sizeof(struct xt_tcpmss_match_info
),
99 static int __init
tcpmss_mt_init(void)
101 return xt_register_matches(tcpmss_mt_reg
, ARRAY_SIZE(tcpmss_mt_reg
));
104 static void __exit
tcpmss_mt_exit(void)
106 xt_unregister_matches(tcpmss_mt_reg
, ARRAY_SIZE(tcpmss_mt_reg
));
109 module_init(tcpmss_mt_init
);
110 module_exit(tcpmss_mt_exit
);