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>
12 #include <linux/if_ether.h>
14 #include <net/netfilter/nf_conntrack.h>
15 #include <linux/netfilter_ipv4/ip_tables.h>
16 #include <linux/netfilter_ipv4/ipt_BCOUNT.h>
18 // #define DEBUG_BCOUNT
21 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
22 target(struct sk_buff
**pskb
,
23 const struct net_device
*in
,
24 const struct net_device
*out
,
26 const struct xt_target
*target
,
28 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
29 target(struct sk_buff
*skb
,
30 const struct net_device
*in
,
31 const struct net_device
*out
,
33 const struct xt_target
*target
,
35 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28) */
36 target(struct sk_buff
*skb
,
37 const struct xt_target_param
*par
)
40 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
41 struct sk_buff
*skb
= *pskb
;
44 enum ip_conntrack_info ctinfo
;
46 ct
= nf_ct_get(skb
, &ctinfo
);
48 ct
->bcount
+= (skb
)->len
;
49 if (ct
->bcount
>= 0x0FFFFFFF) ct
->bcount
= 0x0FFFFFFF;
52 printf(KERN_DEBUG
"BCOUNT %lx %lx\n", (skb
)->len
, ct
->bcount
);
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
60 checkentry(const char *tablename
,
62 const struct xt_target
*target
,
64 unsigned int hook_mask
)
65 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
67 checkentry(const char *tablename
,
69 const struct xt_target
*target
,
71 unsigned int hook_mask
)
72 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28) */
74 checkentry(const struct xt_tgchk_param
*par
)
80 static struct ipt_target BCOUNT_target
= {
84 .targetsize
= sizeof(struct ipt_BCOUNT_target
),
85 .checkentry
= checkentry
,
89 static int __init
init(void)
91 return xt_register_target(&BCOUNT_target
);
94 static void __exit
fini(void)
96 xt_unregister_target(&BCOUNT_target
);
103 MODULE_AUTHOR("Jonathan Zarate");
104 MODULE_DESCRIPTION("BCOUNT target");
105 MODULE_LICENSE("GPL");