Tomato 1.25
[tomato.git] / release / src / linux / linux / net / ipv4 / netfilter / ipt_length.c
blob0cc00f1172ffd90cd0f2886d06d431d9ec00c7d0
1 /* Kernel module to match packet length. */
2 #include <linux/module.h>
3 #include <linux/skbuff.h>
5 #include <linux/netfilter_ipv4/ipt_length.h>
6 #include <linux/netfilter_ipv4/ip_tables.h>
8 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
9 MODULE_DESCRIPTION("IP tables packet length matching module");
10 MODULE_LICENSE("GPL");
12 static int
13 match(const struct sk_buff *skb,
14 const struct net_device *in,
15 const struct net_device *out,
16 const void *matchinfo,
17 int offset,
18 const void *hdr,
19 u_int16_t datalen,
20 int *hotdrop)
22 const struct ipt_length_info *info = matchinfo;
23 u_int16_t pktlen = ntohs(skb->nh.iph->tot_len);
25 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
28 static int
29 checkentry(const char *tablename,
30 const struct ipt_ip *ip,
31 void *matchinfo,
32 unsigned int matchsize,
33 unsigned int hook_mask)
35 if (matchsize != IPT_ALIGN(sizeof(struct ipt_length_info)))
36 return 0;
38 return 1;
41 static struct ipt_match length_match
42 = { { NULL, NULL }, "length", &match, &checkentry, NULL, THIS_MODULE };
44 static int __init init(void)
46 return ipt_register_match(&length_match);
49 static void __exit fini(void)
51 ipt_unregister_match(&length_match);
54 module_init(init);
55 module_exit(fini);