netfilter: limit, hashlimit: avoid duplicated inline

credit_cap can be set to credit, which avoids inlining user2credits
twice. Also, remove inline keyword and let compiler decide.

old:
    684     192       0     876     36c net/netfilter/xt_limit.o
   4927     344      32    5303    14b7 net/netfilter/xt_hashlimit.o
now:
    668     192       0     860     35c net/netfilter/xt_limit.o
   4793     344      32    5169    1431 net/netfilter/xt_hashlimit.o

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
Florian Westphal 2012-05-07 10:51:43 +00:00 committed by Pablo Neira Ayuso
parent cf308a1fae
commit 7a909ac70f
2 changed files with 5 additions and 8 deletions

View File

@ -389,8 +389,7 @@ static void htable_put(struct xt_hashlimit_htable *hinfo)
#define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ) #define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ)
/* Precision saver. */ /* Precision saver. */
static inline u_int32_t static u32 user2credits(u32 user)
user2credits(u_int32_t user)
{ {
/* If multiplying would overflow... */ /* If multiplying would overflow... */
if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY)) if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
@ -400,7 +399,7 @@ user2credits(u_int32_t user)
return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE; return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE;
} }
static inline void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now) static void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
{ {
dh->rateinfo.credit += (now - dh->rateinfo.prev) * CREDITS_PER_JIFFY; dh->rateinfo.credit += (now - dh->rateinfo.prev) * CREDITS_PER_JIFFY;
if (dh->rateinfo.credit > dh->rateinfo.credit_cap) if (dh->rateinfo.credit > dh->rateinfo.credit_cap)
@ -535,8 +534,7 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
dh->rateinfo.prev = jiffies; dh->rateinfo.prev = jiffies;
dh->rateinfo.credit = user2credits(hinfo->cfg.avg * dh->rateinfo.credit = user2credits(hinfo->cfg.avg *
hinfo->cfg.burst); hinfo->cfg.burst);
dh->rateinfo.credit_cap = user2credits(hinfo->cfg.avg * dh->rateinfo.credit_cap = dh->rateinfo.credit;
hinfo->cfg.burst);
dh->rateinfo.cost = user2credits(hinfo->cfg.avg); dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
} else { } else {
/* update expiration timeout */ /* update expiration timeout */

View File

@ -88,8 +88,7 @@ limit_mt(const struct sk_buff *skb, struct xt_action_param *par)
} }
/* Precision saver. */ /* Precision saver. */
static u_int32_t static u32 user2credits(u32 user)
user2credits(u_int32_t user)
{ {
/* If multiplying would overflow... */ /* If multiplying would overflow... */
if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY)) if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
@ -123,7 +122,7 @@ static int limit_mt_check(const struct xt_mtchk_param *par)
128. */ 128. */
priv->prev = jiffies; priv->prev = jiffies;
priv->credit = user2credits(r->avg * r->burst); /* Credits full. */ priv->credit = user2credits(r->avg * r->burst); /* Credits full. */
r->credit_cap = user2credits(r->avg * r->burst); /* Credits full. */ r->credit_cap = priv->credit; /* Credits full. */
r->cost = user2credits(r->avg); r->cost = user2credits(r->avg);
} }
return 0; return 0;