aboutsummaryrefslogtreecommitdiffstats
path: root/net/netfilter
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2012-05-07 06:51:44 -0400
committerPablo Neira Ayuso <pablo@netfilter.org>2012-05-09 06:54:06 -0400
commit817e076f61bca3d0270af60632d1fe07cd4919f1 (patch)
treebb967f28527dff220aaa152c493b6d9811aea6fa /net/netfilter
parent7a909ac70f6b0823d9f23a43f19598d4b57ac901 (diff)
netfilter: hashlimit: move rateinfo initialization to helper
followup patch would bloat main match function too much. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/netfilter')
-rw-r--r--net/netfilter/xt_hashlimit.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 2195eb0727a..b6bbd0630e5 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -407,6 +407,15 @@ static void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
407 dh->rateinfo.prev = now; 407 dh->rateinfo.prev = now;
408} 408}
409 409
410static void rateinfo_init(struct dsthash_ent *dh,
411 struct xt_hashlimit_htable *hinfo)
412{
413 dh->rateinfo.prev = jiffies;
414 dh->rateinfo.credit = user2credits(hinfo->cfg.avg * hinfo->cfg.burst);
415 dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
416 dh->rateinfo.credit_cap = dh->rateinfo.credit;
417}
418
410static inline __be32 maskl(__be32 a, unsigned int l) 419static inline __be32 maskl(__be32 a, unsigned int l)
411{ 420{
412 return l ? htonl(ntohl(a) & ~0 << (32 - l)) : 0; 421 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 goto hotdrop; 540 goto hotdrop;
532 } 541 }
533 dh->expires = jiffies + msecs_to_jiffies(hinfo->cfg.expire); 542 dh->expires = jiffies + msecs_to_jiffies(hinfo->cfg.expire);
534 dh->rateinfo.prev = jiffies; 543 rateinfo_init(dh, hinfo);
535 dh->rateinfo.credit = user2credits(hinfo->cfg.avg *
536 hinfo->cfg.burst);
537 dh->rateinfo.credit_cap = dh->rateinfo.credit;
538 dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
539 } else { 544 } else {
540 /* update expiration timeout */ 545 /* update expiration timeout */
541 dh->expires = now + msecs_to_jiffies(hinfo->cfg.expire); 546 dh->expires = now + msecs_to_jiffies(hinfo->cfg.expire);