netfilter: hashlimit: move rateinfo initialization to helper
authorFlorian Westphal <fw@strlen.de>
Mon, 7 May 2012 10:51:44 +0000 (10:51 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 9 May 2012 10:54:06 +0000 (12:54 +0200)
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>
net/netfilter/xt_hashlimit.c

index 2195eb0727a322170fb3f6e769603a24109a62d2..b6bbd0630e5f018c00e4b3df1a7c4b0bdf1f6284 100644 (file)
@@ -407,6 +407,15 @@ static void rateinfo_recalc(struct dsthash_ent *dh, unsigned long 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)
 {
        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)
                        goto hotdrop;
                }
                dh->expires = jiffies + msecs_to_jiffies(hinfo->cfg.expire);
-               dh->rateinfo.prev = jiffies;
-               dh->rateinfo.credit = user2credits(hinfo->cfg.avg *
-                                     hinfo->cfg.burst);
-               dh->rateinfo.credit_cap = dh->rateinfo.credit;
-               dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
+               rateinfo_init(dh, hinfo);
        } else {
                /* update expiration timeout */
                dh->expires = now + msecs_to_jiffies(hinfo->cfg.expire);