powerpc: define support for 16G hugepages
[linux-2.6/mini2440.git] / net / netfilter / xt_tcpmss.c
blob6771bf01275bcc5bf7df6ee1334a2f182938bfd7
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.
9 */
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <net/tcp.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");
27 static bool
28 tcpmss_mt(const struct sk_buff *skb, const struct net_device *in,
29 const struct net_device *out, const struct xt_match *match,
30 const void *matchinfo, int offset, unsigned int protoff,
31 bool *hotdrop)
33 const struct xt_tcpmss_match_info *info = matchinfo;
34 const struct tcphdr *th;
35 struct tcphdr _tcph;
36 /* tcp.doff is only 4 bits, ie. max 15 * 4 bytes */
37 const u_int8_t *op;
38 u8 _opt[15 * 4 - sizeof(_tcph)];
39 unsigned int i, optlen;
41 /* If we don't have the whole header, drop packet. */
42 th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
43 if (th == NULL)
44 goto dropit;
46 /* Malformed. */
47 if (th->doff*4 < sizeof(*th))
48 goto dropit;
50 optlen = th->doff*4 - sizeof(*th);
51 if (!optlen)
52 goto out;
54 /* Truncated options. */
55 op = skb_header_pointer(skb, protoff + sizeof(*th), optlen, _opt);
56 if (op == NULL)
57 goto dropit;
59 for (i = 0; i < optlen; ) {
60 if (op[i] == TCPOPT_MSS
61 && (optlen - i) >= TCPOLEN_MSS
62 && op[i+1] == TCPOLEN_MSS) {
63 u_int16_t mssval;
65 mssval = (op[i+2] << 8) | op[i+3];
67 return (mssval >= info->mss_min &&
68 mssval <= info->mss_max) ^ info->invert;
70 if (op[i] < 2)
71 i++;
72 else
73 i += op[i+1] ? : 1;
75 out:
76 return info->invert;
78 dropit:
79 *hotdrop = true;
80 return false;
83 static struct xt_match tcpmss_mt_reg[] __read_mostly = {
85 .name = "tcpmss",
86 .family = AF_INET,
87 .match = tcpmss_mt,
88 .matchsize = sizeof(struct xt_tcpmss_match_info),
89 .proto = IPPROTO_TCP,
90 .me = THIS_MODULE,
93 .name = "tcpmss",
94 .family = AF_INET6,
95 .match = tcpmss_mt,
96 .matchsize = sizeof(struct xt_tcpmss_match_info),
97 .proto = IPPROTO_TCP,
98 .me = THIS_MODULE,
102 static int __init tcpmss_mt_init(void)
104 return xt_register_matches(tcpmss_mt_reg, ARRAY_SIZE(tcpmss_mt_reg));
107 static void __exit tcpmss_mt_exit(void)
109 xt_unregister_matches(tcpmss_mt_reg, ARRAY_SIZE(tcpmss_mt_reg));
112 module_init(tcpmss_mt_init);
113 module_exit(tcpmss_mt_exit);