From 86b51224d4c10246c5a4e543186faa05b04ed4be Mon Sep 17 00:00:00 2001 From: Hajimu UMEMOTO Date: Wed, 22 Oct 2003 19:23:51 +0000 Subject: [PATCH] we have ppsratecheck(). --- sys/net/net_osdep.h | 1 + sys/netinet6/icmp6.c | 74 -------------------------------------------- 2 files changed, 1 insertion(+), 74 deletions(-) diff --git a/sys/net/net_osdep.h b/sys/net/net_osdep.h index 62b7dc05946..01a7199a79c 100644 --- a/sys/net/net_osdep.h +++ b/sys/net/net_osdep.h @@ -304,6 +304,7 @@ extern const char *if_name(struct ifnet *); #define if_addrlist if_addrhead #define if_list if_link +#define HAVE_PPSRATECHECK #define WITH_CONVERT_AND_STRIP_IP_LEN #if 1 /* at this moment, all OSes do this */ diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 5b4c5d807fa..aa963260ad3 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -129,10 +129,6 @@ static int icmp6_rip6_input __P((struct mbuf **, int)); static int icmp6_ratelimit __P((const struct in6_addr *, const int, const int)); static const char *icmp6_redirect_diag __P((struct in6_addr *, struct in6_addr *, struct in6_addr *)); -#define HAVE_PPSRATECHECK -#ifndef HAVE_PPSRATECHECK -static int ppsratecheck __P((struct timeval *, int *, int)); -#endif static struct mbuf *ni6_input __P((struct mbuf *, int)); static struct mbuf *ni6_nametodns __P((const char *, int, int)); static int ni6_dnsmatch __P((const char *, int, const char *, int)); @@ -2738,76 +2734,6 @@ icmp6_ctloutput(so, sopt) return (error); } -#ifndef HAVE_PPSRATECHECK -#ifndef timersub -#define timersub(tvp, uvp, vvp) \ - do { \ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ - if ((vvp)->tv_usec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_usec += 1000000; \ - } \ - } while (0) -#endif - -/* - * ppsratecheck(): packets (or events) per second limitation. - */ -static int -ppsratecheck(lasttime, curpps, maxpps) - struct timeval *lasttime; - int *curpps; - int maxpps; /* maximum pps allowed */ -{ - struct timeval tv, delta; - int s, rv; - - s = splclock(); - microtime(&tv); - splx(s); - - timersub(&tv, lasttime, &delta); - - /* - * Check for 0,0 so that the message will be seen at least once. - * If more than one second has passed since the last update of - * lasttime, reset the counter. - * - * We do increment *curpps even in *curpps < maxpps case, as some may - * try to use *curpps for stat purposes as well. - */ - if ((lasttime->tv_sec == 0 && lasttime->tv_usec == 0) || - delta.tv_sec >= 1) { - *lasttime = tv; - *curpps = 0; - rv = 1; - } else if (maxpps < 0) - rv = 1; - else if (*curpps < maxpps) - rv = 1; - else - rv = 0; - -#if 1 /* DIAGNOSTIC? */ - /* be careful about wrap-around */ - if (*curpps + 1 > *curpps) - *curpps = *curpps + 1; -#else - /* - * assume that there's not too many calls to this function. - * not sure if the assumption holds, as it depends on *caller's* - * behavior, not the behavior of this function. - * IMHO it is wrong to make assumption on the caller's behavior, - * so the above #if is #if 1, not #ifdef DIAGNOSTIC. - */ - *curpps = *curpps + 1; -#endif - - return (rv); -} -#endif - /* * Perform rate limit check. * Returns 0 if it is okay to send the icmp6 packet.