3 bcount match (experimental)
4 Copyright (C) 2006 Jonathan Zarate
6 Licensed under GNU GPL v2 or later.
9 #include <linux/module.h>
10 #include <linux/skbuff.h>
11 #include <linux/version.h>
13 #include <net/netfilter/nf_conntrack.h>
14 #include <linux/netfilter_ipv4/ip_tables.h>
15 #include <linux/netfilter_ipv4/ipt_bcount.h>
18 #define LOG(...) do { } while (0);
21 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
26 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
27 match(const struct sk_buff
*skb
, const struct net_device
*in
, const struct net_device
*out
,
28 const struct xt_match
*match
, const void *matchinfo
, int offset
,
29 unsigned int protoff
, int *hotdrop
)
30 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28) */
31 match(const struct sk_buff
*skb
, const struct xt_match_param
*par
)
34 const struct ipt_bcount_match
*info
;
36 enum ip_conntrack_info ctinfo
;
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
41 info
= par
->matchinfo
;
43 ct
= nf_ct_get((struct sk_buff
*)skb
, &ctinfo
);
44 if (!ct
) return !info
->invert
;
45 return ((ct
->bcount
>= info
->min
) && (ct
->bcount
<= info
->max
)) ^ info
->invert
;
48 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
53 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
54 checkentry(const char *tablename
, const void *inf
, const struct xt_match
*match
,
55 void *matchinfo
, unsigned int hook_mask
)
57 checkentry(const struct xt_mtchk_param
*par
)
63 static struct xt_match bcount_match
= {
67 .matchsize
= sizeof(struct ipt_bcount_match
),
68 .checkentry
= &checkentry
,
73 static int __init
init(void)
75 LOG(KERN_INFO
"ipt_bcount <" __DATE__
" " __TIME__
"> loaded\n");
76 return xt_register_match(&bcount_match
);
79 static void __exit
fini(void)
81 xt_unregister_match(&bcount_match
);
88 MODULE_AUTHOR("Jonathan Zarate");
89 MODULE_DESCRIPTION("bcount match");
90 MODULE_LICENSE("GPL");