summaryrefslogtreecommitdiff
path: root/net/core/utils.c
diff options
context:
space:
mode:
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);