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>
11 #include <linux/ipv6.h>
14 #include <linux/netfilter/xt_length.h>
15 #include <linux/netfilter/x_tables.h>
17 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
18 MODULE_DESCRIPTION("IP tables packet length matching module");
19 MODULE_LICENSE("GPL");
20 MODULE_ALIAS("ipt_length");
21 MODULE_ALIAS("ip6t_length");
24 match(const struct sk_buff
*skb
,
25 const struct net_device
*in
,
26 const struct net_device
*out
,
27 const struct xt_match
*match
,
28 const void *matchinfo
,
33 const struct xt_length_info
*info
= matchinfo
;
34 u_int16_t pktlen
= ntohs(ip_hdr(skb
)->tot_len
);
36 return (pktlen
>= info
->min
&& pktlen
<= info
->max
) ^ info
->invert
;
40 match6(const struct sk_buff
*skb
,
41 const struct net_device
*in
,
42 const struct net_device
*out
,
43 const struct xt_match
*match
,
44 const void *matchinfo
,
49 const struct xt_length_info
*info
= matchinfo
;
50 const u_int16_t pktlen
= (ntohs(ipv6_hdr(skb
)->payload_len
) +
51 sizeof(struct ipv6hdr
));
53 return (pktlen
>= info
->min
&& pktlen
<= info
->max
) ^ info
->invert
;
56 static struct xt_match xt_length_match
[] = {
61 .matchsize
= sizeof(struct xt_length_info
),
68 .matchsize
= sizeof(struct xt_length_info
),
73 static int __init
xt_length_init(void)
75 return xt_register_matches(xt_length_match
,
76 ARRAY_SIZE(xt_length_match
));
79 static void __exit
xt_length_fini(void)
81 xt_unregister_matches(xt_length_match
, ARRAY_SIZE(xt_length_match
));
84 module_init(xt_length_init
);
85 module_exit(xt_length_fini
);