Commit 817e076f authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: hashlimit: move rateinfo initialization to helper

followup patch would bloat main match function too much.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 7a909ac7
...@@ -407,6 +407,15 @@ static void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now) ...@@ -407,6 +407,15 @@ static void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
dh->rateinfo.prev = now; dh->rateinfo.prev = now;
} }
static void rateinfo_init(struct dsthash_ent *dh,
struct xt_hashlimit_htable *hinfo)
{
dh->rateinfo.prev = jiffies;
dh->rateinfo.credit = user2credits(hinfo->cfg.avg * hinfo->cfg.burst);
dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
dh->rateinfo.credit_cap = dh->rateinfo.credit;
}
static inline __be32 maskl(__be32 a, unsigned int l) static inline __be32 maskl(__be32 a, unsigned int l)
{ {
return l ? htonl(ntohl(a) & ~0 << (32 - l)) : 0; return l ? htonl(ntohl(a) & ~0 << (32 - l)) : 0;
...@@ -531,11 +540,7 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -531,11 +540,7 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
goto hotdrop; goto hotdrop;
} }
dh->expires = jiffies + msecs_to_jiffies(hinfo->cfg.expire); dh->expires = jiffies + msecs_to_jiffies(hinfo->cfg.expire);
dh->rateinfo.prev = jiffies; rateinfo_init(dh, hinfo);
dh->rateinfo.credit = user2credits(hinfo->cfg.avg *
hinfo->cfg.burst);
dh->rateinfo.credit_cap = dh->rateinfo.credit;
dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
} else { } else {
/* update expiration timeout */ /* update expiration timeout */
dh->expires = now + msecs_to_jiffies(hinfo->cfg.expire); dh->expires = now + msecs_to_jiffies(hinfo->cfg.expire);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment