From syssgm@dtir.qld.gov.au  Mon Jan  4 04:33:46 1999
Received: from ren.dtir.qld.gov.au (ns.detir.qld.gov.au [203.46.81.66])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id EAA08450
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 4 Jan 1999 04:33:44 -0800 (PST)
          (envelope-from syssgm@dtir.qld.gov.au)
Received: by ren.dtir.qld.gov.au; id WAA09117; Mon, 4 Jan 1999 22:32:49 +1000 (EST)
Received: from ogre.dtir.qld.gov.au(167.123.8.3) by ren.dtir.qld.gov.au via smap (3.2)
	id xma009113; Mon, 4 Jan 99 22:32:29 +1000
Received: from atlas.dtir.qld.gov.au (atlas.dtir.qld.gov.au [167.123.8.9])
	by ogre.dtir.qld.gov.au (8.8.8/8.8.7) with ESMTP id WAA01700
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 4 Jan 1999 22:32:29 +1000 (EST)
Received: from nymph.dtir.qld.gov.au (nymph.dtir.qld.gov.au [167.123.10.10])
	by atlas.dtir.qld.gov.au (8.8.5/8.8.5) with ESMTP id WAA10997
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 4 Jan 1999 22:32:28 +1000 (EST)
Received: (from syssgm@localhost)
	by nymph.dtir.qld.gov.au (8.8.8/8.8.7) id WAA00489;
	Mon, 4 Jan 1999 22:32:28 +1000 (EST)
	(envelope-from syssgm)
Message-Id: <199901041232.WAA00489@nymph.dtir.qld.gov.au>
Date: Mon, 4 Jan 1999 22:32:28 +1000 (EST)
From: Stephen McKay <syssgm@dtir.qld.gov.au>
Reply-To: syssgm@dtir.qld.gov.au
To: FreeBSD-gnats-submit@freebsd.org
Cc: syssgm@dtir.qld.gov.au
Subject: [PATCH] Flood ping doesn't flood
X-Send-Pr-Version: 3.2

>Number:         9308
>Category:       bin
>Synopsis:       [PATCH] Flood ping doesn't flood
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan  4 04:40:00 PST 1999
>Closed-Date:    Sat May 8 08:44:03 PDT 1999
>Last-Modified:  Sat May  8 08:45:21 PDT 1999
>Originator:     Stephen McKay
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Just me
>Environment:

	2.2.7, 2.2.8, 3.0, -current

>Description:

	Is your flood ping limp and flagging?  Do you remember a day long
	ago when your eyesight was keen and your bones didn't hurt and you
	got more than 50 pings per second from "ping -f"?

	Why, I remember the days of 1500 pings per second!

	You can have those glory days back with this tiny patch:

>How-To-Repeat:

# time ping -c1000 -f localhost 
PING localhost (127.0.0.1): 56 data bytes
.
--- localhost ping statistics ---
1000 packets transmitted, 1000 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.052/0.059/1.299/0.044 ms
ping -c1000 -f localhost  0.04s user 0.43s system 2% cpu 20.017 total
                                                         ^^^^^^

(By the way, the code is trying for 100 pings per second but gets only 50.
This is because timeouts are rounded up in select() and you CAN'T have a
timeout of less than 2 clock ticks.)

(Apply patch and then...)

# time ./ping -c1000 -f localhost 
PING localhost (127.0.0.1): 56 data bytes
.
--- localhost ping statistics ---
1000 packets transmitted, 1000 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.048/0.087/0.198/0.009 ms
./ping -c1000 -f localhost  0.02s user 0.41s system 82% cpu 0.524 total
                                                            ^^^^^

>Fix:
	
Index: ping.c
===================================================================
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.41
diff -u -r1.41 ping.c
--- ping.c	1998/08/26 18:51:37	1.41
+++ ping.c	1999/01/04 11:59:16
@@ -553,13 +553,14 @@
 			if (npackets && nreceived >= npackets)
 				break;
 		}
-		if (n == 0) {
+		if (n == 0 || options & F_FLOOD) {
 			if (!npackets || ntransmitted < npackets)
 				pinger();
 			else {
 				if (almost_done)
 					break;
 				almost_done = 1;
+				intvl.tv_usec = 0;
 				if (nreceived) {
 					intvl.tv_sec = 2 * tmax / 1000;
 					if (!intvl.tv_sec)
>Release-Note:
>Audit-Trail:

From: Stephen McKay <syssgm@detir.qld.gov.au>
To: freebsd-gnats-submit@freebsd.org
Cc: syssgm@detir.qld.gov.au
Subject: Re: bin/9308: [PATCH] Flood ping doesn't flood
Date: Thu, 06 May 1999 19:58:13 +1000

 Back in January, I wrote:
 
 > Is your flood ping limp and flagging? ...
 
 My word but I've been slack!  I even got a version of my patch through
 the Bruce filter, and it's still not committed!
 
 Here's what I'm going to commit soon.  It minimally fixes the flood ping
 problem, and also restores -l behaviour to that described in the manual page.
 
 In a couple of days I'll commit it to -stable too, just before the freeze.
 
 Stephen.
 
 Index: ping.c
 ===================================================================
 RCS file: /cvs/src/sbin/ping/ping.c,v
 retrieving revision 1.43
 diff -u -r1.43 ping.c
 --- ping.c	1999/04/25 22:33:30	1.43
 +++ ping.c	1999/05/05 15:57:24
 @@ -274,11 +274,10 @@
  			if (*ep || ep == optarg || ultmp > INT_MAX)
  				errx(EX_USAGE, 
  				     "invalid preload value: `%s'", optarg);
 -			if (getuid()) {
 +			if (uid) {
  				errno = EPERM;
  				err(EX_NOPERM, "-l flag");
  			}
 -			options |= F_FLOOD;
  			preload = ultmp;
  			break;
  		case 'L':
 @@ -554,6 +553,8 @@
  		if (timeout.tv_sec < 0)
  			timeout.tv_sec = timeout.tv_usec = 0;
  		n = select(s + 1, &rfds, NULL, NULL, &timeout);
 +		if (n < 0)
 +			continue;	/* Must be EINTR. */
  		if (n == 1) {
  			struct timeval *t = 0;
  #ifdef SO_TIMESTAMP
 @@ -585,13 +586,14 @@
  			if (npackets && nreceived >= npackets)
  				break;
  		}
 -		if (n == 0) {
 +		if (n == 0 || options & F_FLOOD) {
  			if (!npackets || ntransmitted < npackets)
  				pinger();
  			else {
  				if (almost_done)
  					break;
  				almost_done = 1;
 +				intvl.tv_usec = 0;
  				if (nreceived) {
  					intvl.tv_sec = 2 * tmax / 1000;
  					if (!intvl.tv_sec)
 
State-Changed-From-To: open->closed 
State-Changed-By: mckay 
State-Changed-When: Sat May 8 08:44:03 PDT 1999 
State-Changed-Why:  
Fixed in rev 1.44 and 1.42.2.1 
>Unformatted:
