00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#include <asm/uaccess.h>
00017
#include <asm/system.h>
00018
#include <linux/types.h>
00019
#include <linux/kernel.h>
00020
#include <linux/sched.h>
00021
#include <linux/string.h>
00022
#include <linux/mm.h>
00023
00024 static unsigned long net_rand_seed = 152L;
00025
00026 unsigned long net_random(
void)
00027 {
00028
net_rand_seed=
net_rand_seed*69069L+1;
00029
return net_rand_seed^jiffies;
00030 }
00031
00032 void net_srandom(
unsigned long entropy)
00033 {
00034
net_rand_seed ^= entropy;
00035
net_random();
00036 }
00037
00038 int net_msg_cost = 5*HZ;
00039 int net_msg_burst = 10*5*HZ;
00040
00041
00042
00043
00044
00045
00046
00047 int net_ratelimit(
void)
00048 {
00049
static spinlock_t ratelimit_lock = SPIN_LOCK_UNLOCKED;
00050
static unsigned long toks = 10*5*HZ;
00051
static unsigned long last_msg;
00052
static int missed;
00053
unsigned long flags;
00054
unsigned long now = jiffies;
00055
00056 spin_lock_irqsave(&ratelimit_lock, flags);
00057 toks += now - last_msg;
00058 last_msg = now;
00059
if (toks >
net_msg_burst)
00060 toks =
net_msg_burst;
00061
if (toks >=
net_msg_cost) {
00062
int lost = missed;
00063 missed = 0;
00064 toks -=
net_msg_cost;
00065 spin_unlock_irqrestore(&ratelimit_lock, flags);
00066
if (lost)
00067 printk(KERN_WARNING
"NET: %d messages suppressed.\n", lost);
00068
return 1;
00069 }
00070 missed++;
00071 spin_unlock_irqrestore(&ratelimit_lock, flags);
00072
return 0;
00073 }