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("iptables TCP MSS match module");
24 MODULE_ALIAS("ipt_tcpmss");
25 MODULE_ALIAS("ip6t_tcpmss");
28 match(const struct sk_buff
*skb
,
29 const struct net_device
*in
,
30 const struct net_device
*out
,
31 const struct xt_match
*match
,
32 const void *matchinfo
,
37 const struct xt_tcpmss_match_info
*info
= matchinfo
;
38 struct tcphdr _tcph
, *th
;
39 /* tcp.doff is only 4 bits, ie. max 15 * 4 bytes */
40 u8 _opt
[15 * 4 - sizeof(_tcph
)], *op
;
41 unsigned int i
, optlen
;
43 /* If we don't have the whole header, drop packet. */
44 th
= skb_header_pointer(skb
, protoff
, sizeof(_tcph
), &_tcph
);
49 if (th
->doff
*4 < sizeof(*th
))
52 optlen
= th
->doff
*4 - sizeof(*th
);
56 /* Truncated options. */
57 op
= skb_header_pointer(skb
, protoff
+ sizeof(*th
), optlen
, _opt
);
61 for (i
= 0; i
< optlen
; ) {
62 if (op
[i
] == TCPOPT_MSS
63 && (optlen
- i
) >= TCPOLEN_MSS
64 && op
[i
+1] == TCPOLEN_MSS
) {
67 mssval
= (op
[i
+2] << 8) | op
[i
+3];
69 return (mssval
>= info
->mss_min
&&
70 mssval
<= info
->mss_max
) ^ info
->invert
;
85 static struct xt_match xt_tcpmss_match
[] __read_mostly
= {
90 .matchsize
= sizeof(struct xt_tcpmss_match_info
),
98 .matchsize
= sizeof(struct xt_tcpmss_match_info
),
104 static int __init
xt_tcpmss_init(void)
106 return xt_register_matches(xt_tcpmss_match
,
107 ARRAY_SIZE(xt_tcpmss_match
));
110 static void __exit
xt_tcpmss_fini(void)
112 xt_unregister_matches(xt_tcpmss_match
, ARRAY_SIZE(xt_tcpmss_match
));
115 module_init(xt_tcpmss_init
);
116 module_exit(xt_tcpmss_fini
);