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.
9 #include <linux/module.h>
10 #include <linux/skbuff.h>
13 #include <linux/netfilter/xt_length.h>
14 #include <linux/netfilter/x_tables.h>
16 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
17 MODULE_DESCRIPTION("IP tables packet length matching module");
18 MODULE_LICENSE("GPL");
19 MODULE_ALIAS("ipt_length");
20 MODULE_ALIAS("ip6t_length");
23 match(const struct sk_buff *skb,
24 const struct net_device *in,
25 const struct net_device *out,
26 const void *matchinfo,
31 const struct xt_length_info *info = matchinfo;
32 u_int16_t pktlen = ntohs(skb->nh.iph->tot_len);
34 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
38 match6(const struct sk_buff *skb,
39 const struct net_device *in,
40 const struct net_device *out,
41 const void *matchinfo,
46 const struct xt_length_info *info = matchinfo;
47 u_int16_t pktlen = ntohs(skb->nh.ipv6h->payload_len) + sizeof(struct ipv6hdr);
49 return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
53 checkentry(const char *tablename,
56 unsigned int matchsize,
57 unsigned int hook_mask)
59 if (matchsize != XT_ALIGN(sizeof(struct xt_length_info)))
65 static struct xt_match length_match = {
68 .checkentry = &checkentry,
71 static struct xt_match length6_match = {
74 .checkentry = &checkentry,
78 static int __init init(void)
81 ret = xt_register_match(AF_INET, &length_match);
84 ret = xt_register_match(AF_INET6, &length6_match);
86 xt_unregister_match(AF_INET, &length_match);
91 static void __exit fini(void)
93 xt_unregister_match(AF_INET, &length_match);
94 xt_unregister_match(AF_INET6, &length6_match);