[NETFILTER]: Fix whitespace errors
[linux-2.6-block.git] / net / netfilter / xt_length.c
CommitLineData
2e4e6a17
HW
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>
37d8dc82 11#include <linux/ipv6.h>
2e4e6a17
HW
12#include <net/ip.h>
13
14#include <linux/netfilter/xt_length.h>
15#include <linux/netfilter/x_tables.h>
16
17MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
18MODULE_DESCRIPTION("IP tables packet length matching module");
19MODULE_LICENSE("GPL");
20MODULE_ALIAS("ipt_length");
21MODULE_ALIAS("ip6t_length");
22
23static int
24match(const struct sk_buff *skb,
25 const struct net_device *in,
26 const struct net_device *out,
c4986734 27 const struct xt_match *match,
2e4e6a17
HW
28 const void *matchinfo,
29 int offset,
30 unsigned int protoff,
31 int *hotdrop)
32{
33 const struct xt_length_info *info = matchinfo;
34 u_int16_t pktlen = ntohs(skb->nh.iph->tot_len);
601e68e1 35
2e4e6a17
HW
36 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
37}
38
39static int
40match6(const struct sk_buff *skb,
41 const struct net_device *in,
42 const struct net_device *out,
c4986734 43 const struct xt_match *match,
2e4e6a17
HW
44 const void *matchinfo,
45 int offset,
46 unsigned int protoff,
47 int *hotdrop)
48{
49 const struct xt_length_info *info = matchinfo;
50 u_int16_t pktlen = ntohs(skb->nh.ipv6h->payload_len) + sizeof(struct ipv6hdr);
601e68e1 51
2e4e6a17
HW
52 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
53}
54
4470bbc7
PM
55static struct xt_match xt_length_match[] = {
56 {
57 .name = "length",
58 .family = AF_INET,
59 .match = match,
60 .matchsize = sizeof(struct xt_length_info),
61 .me = THIS_MODULE,
62 },
63 {
64 .name = "length",
65 .family = AF_INET6,
66 .match = match6,
67 .matchsize = sizeof(struct xt_length_info),
68 .me = THIS_MODULE,
69 },
2e4e6a17
HW
70};
71
65b4b4e8 72static int __init xt_length_init(void)
2e4e6a17 73{
4470bbc7
PM
74 return xt_register_matches(xt_length_match,
75 ARRAY_SIZE(xt_length_match));
2e4e6a17
HW
76}
77
65b4b4e8 78static void __exit xt_length_fini(void)
2e4e6a17 79{
4470bbc7 80 xt_unregister_matches(xt_length_match, ARRAY_SIZE(xt_length_match));
2e4e6a17
HW
81}
82
65b4b4e8
AM
83module_init(xt_length_init);
84module_exit(xt_length_fini);