Linux-2.6.12-rc2
[linux-2.6] / net / ipv6 / netfilter / ip6t_length.c
1 /* Length Match - IPv6 Port */
2
3 /* (C) 1999-2001 James Morris <jmorros@intercode.com.au>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9
10
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <linux/netfilter_ipv6/ip6t_length.h>
14 #include <linux/netfilter_ipv6/ip6_tables.h>
15
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
18 MODULE_DESCRIPTION("IPv6 packet length match");
19
20 static int
21 match(const struct sk_buff *skb,
22       const struct net_device *in,
23       const struct net_device *out,
24       const void *matchinfo,
25       int offset,
26       unsigned int protoff,
27       int *hotdrop)
28 {
29         const struct ip6t_length_info *info = matchinfo;
30         u_int16_t pktlen = ntohs(skb->nh.ipv6h->payload_len) + sizeof(struct ipv6hdr);
31         
32         return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
33 }
34
35 static int
36 checkentry(const char *tablename,
37            const struct ip6t_ip6 *ip,
38            void *matchinfo,
39            unsigned int matchsize,
40            unsigned int hook_mask)
41 {
42         if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_length_info)))
43                 return 0;
44
45         return 1;
46 }
47
48 static struct ip6t_match length_match = {
49         .name           = "length",
50         .match          = &match,
51         .checkentry     = &checkentry,
52         .me             = THIS_MODULE,
53 };
54
55 static int __init init(void)
56 {
57         return ip6t_register_match(&length_match);
58 }
59
60 static void __exit fini(void)
61 {
62         ip6t_unregister_match(&length_match);
63 }
64
65 module_init(init);
66 module_exit(fini);