summaryrefslogtreecommitdiff
path: root/net/core/utils.c
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2004-02-05 23:09:25 -0800
committerHideaki Yoshifuji <yoshfuji@linux-ipv6.org>2004-02-05 23:09:25 -0800
commit353131f37e48c775ed37e18eafd7a570d0feac15 (patch)
tree3e037f88e0b854b03d35700910e54b57a55b2da5 /net/core/utils.c
parentf8c11435c19d5cee964370d8fd62d397f2b4c212 (diff)
[NET]: Simply net_ratelimit().
Reimplement net_ratelimit() in terms of the new printk_ratelimit(). As net_ratelimit() already has it own sysctls we generalise printk_ratelimit() a bit so that networking does not lose its existing sysctls and so that it can use different time constants from the more generic printk_ratelimit().
Diffstat (limited to 'net/core/utils.c')
-rw-r--r--net/core/utils.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/net/core/utils.c b/net/core/utils.c
index 995f2b5168c2..8058d9c5e236 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -41,37 +41,11 @@ int net_msg_cost = 5*HZ;
int net_msg_burst = 10;
/*
- * This enforces a rate limit: not more than one kernel message
- * every 5secs to make a denial-of-service attack impossible.
- *
- * All warning printk()s should be guarded by this function.
+ * All net warning printk()s should be guarded by this function.
*/
int net_ratelimit(void)
{
- static spinlock_t ratelimit_lock = SPIN_LOCK_UNLOCKED;
- static unsigned long toks = 10*5*HZ;
- static unsigned long last_msg;
- static int missed;
- unsigned long flags;
- unsigned long now = jiffies;
-
- spin_lock_irqsave(&ratelimit_lock, flags);
- toks += now - last_msg;
- last_msg = now;
- if (toks > net_msg_burst)
- toks = net_msg_burst;
- if (toks >= net_msg_cost) {
- int lost = missed;
- missed = 0;
- toks -= net_msg_cost;
- spin_unlock_irqrestore(&ratelimit_lock, flags);
- if (lost)
- printk(KERN_WARNING "NET: %d messages suppressed.\n", lost);
- return 1;
- }
- missed++;
- spin_unlock_irqrestore(&ratelimit_lock, flags);
- return 0;
+ return __printk_ratelimit(net_msg_cost, net_msg_burst);
}
EXPORT_SYMBOL(net_random);