8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/slab.h>
11 #include <linux/module.h>
16 #include <linux/netfilter/x_tables.h>
53 #define MAX_CPJ (0xFFFFFFFF / (HZ*60*60*24))
58 #define _POW2_BELOW2(x) ((x)|((x)>>1))
59 #define _POW2_BELOW4(x) (_POW2_BELOW2(x)|_POW2_BELOW2((x)>>2))
60 #define _POW2_BELOW8(x) (_POW2_BELOW4(x)|_POW2_BELOW4((x)>>4))
61 #define _POW2_BELOW16(x) (_POW2_BELOW8(x)|_POW2_BELOW8((x)>>8))
62 #define _POW2_BELOW32(x) (_POW2_BELOW16(x)|_POW2_BELOW16((x)>>16))
63 #define POW2_BELOW32(x) ((_POW2_BELOW32(x)>>1) + 1)
65 #define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ)
74 spin_lock_bh(&limit_lock);
82 spin_unlock_bh(&limit_lock);
86 spin_unlock_bh(&limit_lock);
108 || user2credits(r->
avg * r->
burst) < user2credits(r->
avg)) {
109 pr_info(
"Overflow, try lower: %u/%u\n",
126 r->
cost = user2credits(r->
avg);
139 struct compat_xt_rateinfo {
152 static void limit_mt_compat_from_user(
void *
dst,
const void *
src)
154 const struct compat_xt_rateinfo *cm =
src;
158 .prev = cm->prev | (
unsigned long)cm->master << 32,
159 .credit = cm->credit,
160 .credit_cap = cm->credit_cap,
163 memcpy(dst, &m,
sizeof(m));
166 static int limit_mt_compat_to_user(
void __user *dst,
const void *src)
169 struct compat_xt_rateinfo cm = {
176 .master = m->
prev >> 32,
187 .checkentry = limit_mt_check,
188 .destroy = limit_mt_destroy,
191 .compatsize =
sizeof(
struct compat_xt_rateinfo),
192 .compat_from_user = limit_mt_compat_from_user,
193 .compat_to_user = limit_mt_compat_to_user,
198 static int __init limit_mt_init(
void)
203 static void __exit limit_mt_exit(
void)