From 893bec80591fcb86ea7d9868cd1982a503fa2170 Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Wed, 26 Feb 2003 17:16:38 +0000 Subject: [PATCH] o fix ppsratecheck to interpret a maxpps of zero as "ignore everything" o add a comment explaining the significance of using 0 or -1 (actually any negative value) for maxpps --- sys/kern/kern_time.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 9cca995e5d7..6a046fa54f4 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -679,6 +679,10 @@ ratecheck(struct timeval *lasttime, const struct timeval *mininterval) * Return 0 if the limit is to be enforced (e.g. the caller * should drop a packet because of the rate limitation). * + * maxpps of 0 always causes zero to be returned. maxpps of -1 + * always causes 1 to be returned; this effectively defeats rate + * limiting. + * * Note that we maintain the struct timeval for compatibility * with other bsd systems. We reuse the storage and just monitor * clock ticks for minimal overhead. @@ -697,7 +701,7 @@ ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps) if (lasttime->tv_sec == 0 || (u_int)(now - lasttime->tv_sec) >= hz) { lasttime->tv_sec = now; *curpps = 1; - return (1); + return (maxpps != 0); } else { (*curpps)++; /* NB: ignore potential overflow */ return (maxpps < 0 || *curpps < maxpps);