[MIPS] Add topology_init.
[linux-2.6/kmemtrace.git] / net / netfilter / xt_length.c
blob39c8faea63dec5c6e857197a042bc462b4e8dfc0
1 /* Kernel module to match packet length. */
2 /* (C) 1999-2001 James Morris <jmorros@intercode.com.au>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <linux/module.h>
10 #include <linux/skbuff.h>
11 #include <linux/ipv6.h>
12 #include <net/ip.h>
14 #include <linux/netfilter/xt_length.h>
15 #include <linux/netfilter/x_tables.h>
17 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
18 MODULE_DESCRIPTION("IP tables packet length matching module");
19 MODULE_LICENSE("GPL");
20 MODULE_ALIAS("ipt_length");
21 MODULE_ALIAS("ip6t_length");
23 static int
24 match(const struct sk_buff *skb,
25 const struct net_device *in,
26 const struct net_device *out,
27 const void *matchinfo,
28 int offset,
29 unsigned int protoff,
30 int *hotdrop)
32 const struct xt_length_info *info = matchinfo;
33 u_int16_t pktlen = ntohs(skb->nh.iph->tot_len);
35 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
38 static int
39 match6(const struct sk_buff *skb,
40 const struct net_device *in,
41 const struct net_device *out,
42 const void *matchinfo,
43 int offset,
44 unsigned int protoff,
45 int *hotdrop)
47 const struct xt_length_info *info = matchinfo;
48 u_int16_t pktlen = ntohs(skb->nh.ipv6h->payload_len) + sizeof(struct ipv6hdr);
50 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
53 static int
54 checkentry(const char *tablename,
55 const void *ip,
56 void *matchinfo,
57 unsigned int matchsize,
58 unsigned int hook_mask)
60 if (matchsize != XT_ALIGN(sizeof(struct xt_length_info)))
61 return 0;
63 return 1;
66 static struct xt_match length_match = {
67 .name = "length",
68 .match = &match,
69 .checkentry = &checkentry,
70 .me = THIS_MODULE,
72 static struct xt_match length6_match = {
73 .name = "length",
74 .match = &match6,
75 .checkentry = &checkentry,
76 .me = THIS_MODULE,
79 static int __init init(void)
81 int ret;
82 ret = xt_register_match(AF_INET, &length_match);
83 if (ret)
84 return ret;
85 ret = xt_register_match(AF_INET6, &length6_match);
86 if (ret)
87 xt_unregister_match(AF_INET, &length_match);
89 return ret;
92 static void __exit fini(void)
94 xt_unregister_match(AF_INET, &length_match);
95 xt_unregister_match(AF_INET6, &length6_match);
98 module_init(init);
99 module_exit(fini);