diff options
author | Florian Westphal <fw@strlen.de> | 2012-05-07 06:51:43 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-05-09 06:54:06 -0400 |
commit | 7a909ac70f6b0823d9f23a43f19598d4b57ac901 (patch) | |
tree | 50802cd6633ab06b3076615de771bde7ae5bb361 /net/netfilter | |
parent | cf308a1fae432f315989e2da6878bfaa3daa22b1 (diff) |
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>
Diffstat (limited to 'net/netfilter')
-rw-r--r-- | net/netfilter/xt_hashlimit.c | 8 | ||||
-rw-r--r-- | net/netfilter/xt_limit.c | 5 |
2 files changed, 5 insertions, 8 deletions
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c index d95f9c963cde..2195eb0727a3 100644 --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c | |||
@@ -389,8 +389,7 @@ static void htable_put(struct xt_hashlimit_htable *hinfo) | |||
389 | #define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ) | 389 | #define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ) |
390 | 390 | ||
391 | /* Precision saver. */ | 391 | /* Precision saver. */ |
392 | static inline u_int32_t | 392 | static u32 user2credits(u32 user) |
393 | user2credits(u_int32_t user) | ||
394 | { | 393 | { |
395 | /* If multiplying would overflow... */ | 394 | /* If multiplying would overflow... */ |
396 | if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY)) | 395 | if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY)) |
@@ -400,7 +399,7 @@ user2credits(u_int32_t user) | |||
400 | return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE; | 399 | return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE; |
401 | } | 400 | } |
402 | 401 | ||
403 | static inline void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now) | 402 | static void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now) |
404 | { | 403 | { |
405 | dh->rateinfo.credit += (now - dh->rateinfo.prev) * CREDITS_PER_JIFFY; | 404 | dh->rateinfo.credit += (now - dh->rateinfo.prev) * CREDITS_PER_JIFFY; |
406 | if (dh->rateinfo.credit > dh->rateinfo.credit_cap) | 405 | if (dh->rateinfo.credit > dh->rateinfo.credit_cap) |
@@ -535,8 +534,7 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par) | |||
535 | dh->rateinfo.prev = jiffies; | 534 | dh->rateinfo.prev = jiffies; |
536 | dh->rateinfo.credit = user2credits(hinfo->cfg.avg * | 535 | dh->rateinfo.credit = user2credits(hinfo->cfg.avg * |
537 | hinfo->cfg.burst); | 536 | hinfo->cfg.burst); |
538 | dh->rateinfo.credit_cap = user2credits(hinfo->cfg.avg * | 537 | dh->rateinfo.credit_cap = dh->rateinfo.credit; |
539 | hinfo->cfg.burst); | ||
540 | dh->rateinfo.cost = user2credits(hinfo->cfg.avg); | 538 | dh->rateinfo.cost = user2credits(hinfo->cfg.avg); |
541 | } else { | 539 | } else { |
542 | /* update expiration timeout */ | 540 | /* update expiration timeout */ |
diff --git a/net/netfilter/xt_limit.c b/net/netfilter/xt_limit.c index 32b7a579a032..5c22ce8ab309 100644 --- a/net/netfilter/xt_limit.c +++ b/net/netfilter/xt_limit.c | |||
@@ -88,8 +88,7 @@ limit_mt(const struct sk_buff *skb, struct xt_action_param *par) | |||
88 | } | 88 | } |
89 | 89 | ||
90 | /* Precision saver. */ | 90 | /* Precision saver. */ |
91 | static u_int32_t | 91 | static u32 user2credits(u32 user) |
92 | user2credits(u_int32_t user) | ||
93 | { | 92 | { |
94 | /* If multiplying would overflow... */ | 93 | /* If multiplying would overflow... */ |
95 | if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY)) | 94 | if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY)) |
@@ -123,7 +122,7 @@ static int limit_mt_check(const struct xt_mtchk_param *par) | |||
123 | 128. */ | 122 | 128. */ |
124 | priv->prev = jiffies; | 123 | priv->prev = jiffies; |
125 | priv->credit = user2credits(r->avg * r->burst); /* Credits full. */ | 124 | priv->credit = user2credits(r->avg * r->burst); /* Credits full. */ |
126 | r->credit_cap = user2credits(r->avg * r->burst); /* Credits full. */ | 125 | r->credit_cap = priv->credit; /* Credits full. */ |
127 | r->cost = user2credits(r->avg); | 126 | r->cost = user2credits(r->avg); |
128 | } | 127 | } |
129 | return 0; | 128 | return 0; |