Linux-2.6.12-rc2
[linux-flexiantxendom0-natty.git] / net / ipv4 / netfilter / ipt_length.c
1 /* Kernel module to match packet length. */
2 /* (C) 1999-2001 James Morris <jmorros@intercode.com.au>
3  *
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  */
8
9 #include <linux/module.h>
10 #include <linux/skbuff.h>
11
12 #include <linux/netfilter_ipv4/ipt_length.h>
13 #include <linux/netfilter_ipv4/ip_tables.h>
14
15 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
16 MODULE_DESCRIPTION("IP tables packet length matching module");
17 MODULE_LICENSE("GPL");
18
19 static int
20 match(const struct sk_buff *skb,
21       const struct net_device *in,
22       const struct net_device *out,
23       const void *matchinfo,
24       int offset,
25       int *hotdrop)
26 {
27         const struct ipt_length_info *info = matchinfo;
28         u_int16_t pktlen = ntohs(skb->nh.iph->tot_len);
29         
30         return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
31 }
32
33 static int
34 checkentry(const char *tablename,
35            const struct ipt_ip *ip,
36            void *matchinfo,
37            unsigned int matchsize,
38            unsigned int hook_mask)
39 {
40         if (matchsize != IPT_ALIGN(sizeof(struct ipt_length_info)))
41                 return 0;
42
43         return 1;
44 }
45
46 static struct ipt_match length_match = {
47         .name           = "length",
48         .match          = &match,
49         .checkentry     = &checkentry,
50         .me             = THIS_MODULE,
51 };
52
53 static int __init init(void)
54 {
55         return ipt_register_match(&length_match);
56 }
57
58 static void __exit fini(void)
59 {
60         ipt_unregister_match(&length_match);
61 }
62
63 module_init(init);
64 module_exit(fini);