gettimeofday() in hping

Kris Kennaway kris at FreeBSD.org
Sun Feb 3 14:01:27 PST 2008


Kris Kennaway wrote:

>> Fixing all of the above I can send at about 13MB/sec (timecounter is 
>> not relevant any more).  The CPU is spending about 75% of the time in 
>> the kernel, so
>              that is the next place to look. [hit send too soon]

Actually 15MB/sec once I disable all kernel debugging.  This is 
identical to Linux 2.6.24 on the same hardware.  The patch I use to fix 
hping brain-damage is attached.

Kris



-------------- next part --------------
diff -ru work/hping3-20051105/opensockraw.c work~/hping3-20051105/opensockraw.c
--- opensockraw.c.orig	2003-09-01 00:22:06.000000000 +0000
+++ opensockraw.c	2008-02-03 19:45:28.000000000 +0000
@@ -17,7 +17,7 @@
 
 int open_sockraw()
 {
-	int s;
+	int s, t, val;
 
 	s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
 	if (s == -1) {
@@ -25,5 +25,12 @@
 		return -1;
 	}
 
+	val = 262144;
+	t = setsockopt(s, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
+	if (t == -1) {
+		perror("[open_sockraw] setsockopt()");
+		return -1;
+	}
+
 	return s;
 }
diff -ru work/hping3-20051105/sendip.c work~/hping3-20051105/sendip.c
--- sendip.c.orig	2004-04-09 23:38:56.000000000 +0000
+++ sendip.c	2008-02-03 19:50:35.000000000 +0000
@@ -110,7 +110,7 @@
 	result = sendto(sockraw, packet, packetsize, 0,
 		(struct sockaddr*)&remote, sizeof(remote));
 	
-	if (result == -1 && errno != EINTR && !opt_rand_dest && !opt_rand_source) {
+	if (result == -1 && errno != ENOBUFS && errno != EINTR && !opt_rand_dest && !opt_rand_source) {
 		perror("[send_ip] sendto");
 		if (close(sockraw) == -1)
 			perror("[ipsender] close(sockraw)");
diff -ru work/hping3-20051105/sendtcp.c work~/hping3-20051105/sendtcp.c
--- sendtcp.c.orig	2003-09-01 00:22:06.000000000 +0000
+++ sendtcp.c	2008-02-03 20:30:51.000000000 +0000
@@ -85,8 +85,10 @@
 		      packet_size);
 #endif
 
+#if 0
 	/* adds this pkt in delaytable */
 	delaytable_add(sequence, src_port, time(NULL), get_usec(), S_SENT);
+#endif
 
 	/* send packet */
 	send_ip_handler(packet+PSEUDOHDR_SIZE, packet_size);
--- send.c.orig	2003-08-31 17:23:53.000000000 +0000
+++ send.c	2008-02-03 21:58:59.000000000 +0000
@@ -63,6 +63,8 @@
 	}
 }
 
+static int sigalarm_handler = 0;
+
 /* The signal handler for SIGALRM will send the packets */
 void send_packet (int signal_id)
 {
@@ -79,12 +81,15 @@
 	else			send_tcp();
 
 	sent_pkt++;
-	Signal(SIGALRM, send_packet);
+	if (!opt_flood && !sigalarm_handler) {
+		Signal(SIGALRM, send_packet);
+		sigalarm_handler = 1;
+	}
 
 	if (count != -1 && count == sent_pkt) { /* count reached? */
 		Signal(SIGALRM, print_statistics);
 		alarm(COUNTREACHED_TIMEOUT);
-	} else if (!opt_listenmode) {
+	} else if (!opt_listenmode && !opt_flood) {
 		if (opt_waitinusec == FALSE)
 			alarm(sending_wait);
 		else


More information about the freebsd-hackers mailing list