Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Aug 2009 17:44:29 GMT
From:      Fang Wang <fangwang@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 167409 for review
Message-ID:  <200908161744.n7GHiTWN000559@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=167409

Change 167409 by fangwang@fangwang_utobsd on 2009/08/16 17:44:10

	Fix style, copyright, add some comments. 

Affected files ...

.. //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_input.c#8 edit
.. //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_output.c#10 edit
.. //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_subr.c#6 edit
.. //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_timer.c#9 edit
.. //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_usrreq.c#10 edit
.. //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_var.h#15 edit
.. //depot/projects/soc2009/tcputo/src/tools/regression/netinet/tcputo/README#3 edit
.. //depot/projects/soc2009/tcputo/src/tools/regression/netinet/tcputo/tcputo.c#8 edit

Differences ...

==== //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_input.c#8 (text+ko) ====

@@ -1188,12 +1188,12 @@
 
 	/*
 	 * If TCP user timeout option is received, because it's an
-	 * optional option, we do nothing at this moment. We will
-	 * process when we need to use it. And we need it in two 
+	 * optional option, we do nothing at this moment.  We will
+	 * process when we need to use it.  And we need it in two
 	 * cases:
 	 *    1. We need do retransmission.
 	 *    2. Users request a UTO value.
-	 */	 
+	 */
 	if (to.to_flags & TOF_UTO) {
 		tp->uto_flags |= TCPUTO_RCVD;
 		tp->rcv_uto = to.to_uto;
@@ -2251,10 +2251,10 @@
 
 process_ACK:
 		/*
-		* If we are sending the UTO option, and we receive a ACK acknowledge the
-		* segment carrying the UTO option,  the UTO was send successfully. So we
-		* stop sending the UTO option.
-		*/
+		 * If we are sending the UTO option, and we receive a ACK
+		 * acknowledge the segment carrying the UTO option,  the UTO
+		 * was send successfully. So we stop sending the UTO option.
+		 */
 		if (tp->uto_flags & TCPUTO_SENDING)
 			if (SEQ_GEQ(th->th_ack, tp->uto_carrier))
 				tp->uto_flags &= ~TCPUTO_SENDING;
@@ -2971,7 +2971,7 @@
 				continue;
 			to->to_flags |= TOF_UTO;
 			bcopy((char *)cp + 2,
-			    (char *)&to->to_uto, sizeof(to->to_uto));			
+			    (char *)&to->to_uto, sizeof(to->to_uto));
 			to->to_uto = ntohs(to->to_uto);
 			break;
 		default:

==== //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_output.c#10 (text+ko) ====

@@ -711,13 +711,16 @@
 		hdrlen += optlen = tcp_addoptions(&to, opt);
 
 		/* 
-		* According to RFC 5482:
-		* "In addition to exchanging UTO options in the SYN segments, a
-		*  connection that has enabled UTO options SHOULD include a UTO option
-		*  in the first packet that does not have the SYN flag set. This helps  to minimize
-		*  the amount of state information TCP must keep for  connections in non-synchronized states." 
-		* So even though UTO options is put in SYN segment successfully, we still transmit it.
-		*/
+		 * According to RFC 5482:
+		 * "In addition to exchanging UTO options in the SYN segments,
+		 *  a connection that has enabled UTO options SHOULD include a
+		 *  UTO option in the first packet that does not have the SYN
+		 *  flag set. This helps  to minimize the amount of state
+		 *  information TCP must keep for  connections in
+		 *  non-synchronized states." 
+		 * So even though UTO option is put in SYN segment successfully,
+		 * we still transmit it.
+		 */
 		if (tp->uto_flags & (TCPUTO_NEED | TCPUTO_SENDING) &&
 		    (to.to_flags & TOF_UTO) == 0) {
 			if ((flags & TH_SYN) == 0) {
@@ -1478,7 +1481,7 @@
 		case TOF_UTO:
 			{
 			if (TCP_MAXOLEN - optlen < TCPOLEN_UTO)
-				continue;			
+				continue;
 			*optp++ = TCPOPT_UTO;
 			*optp++ = TCPOLEN_UTO;
 			optlen += TCPOLEN_UTO;

==== //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_subr.c#6 (text+ko) ====

@@ -745,9 +745,10 @@
 	if (tcp_uto_enable)
 		tp->uto_flags |= TCPUTO_ENABLE;
 	/*
-	* According to RFC 5482, t_uto_adv is UTO option advertised to the remote TCP peer.  
-	* It defaults to the default system-wide  USER TIMEOUT.
-	*/
+	 * According to RFC 5482, t_uto_adv is UTO option advertised to the
+	 * remote TCP peer.  It defaults to the default system-wide USER
+	 * TIMEOUT.
+	 */
 	tp->t_uto_adv = TCPTV_UTO_DEFAULT;
 	/*
 	 * IPv4 TTL initialization is necessary for an IPv6 socket as well,

==== //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_timer.c#9 (text+ko) ====

@@ -114,9 +114,11 @@
 int	tcp_uto_min;
 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, uto_min, CTLTYPE_INT|CTLFLAG_RW,
     &tcp_uto_min, 0, sysctl_msec_to_ticks, "I", "Minimun user timeout");
+
 int	tcp_uto_max;
 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, uto_max, CTLTYPE_INT|CTLFLAG_RW,
     &tcp_uto_max, 0, sysctl_msec_to_ticks, "I", "Maximum user timeout");
+
 int	tcp_uto_enable = 0;
 SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_enableuto, CTLFLAG_RW,
     &tcp_uto_enable , 0, "Enable TCP user timeout option on all TCP connections");
@@ -501,12 +503,13 @@
 	 * been acked within retransmit interval.  Back off
 	 * to a longer retransmit interval and retransmit one segment.
 	 */
-	if ((++tp->t_rxtshift > TCP_MAXRXTSHIFT && (tp->uto_flags & TCPUTO_IMPL) == 0) || 
+	if ((++tp->t_rxtshift > TCP_MAXRXTSHIFT &&
+	    (tp->uto_flags & TCPUTO_IMPL) == 0) ||
 	    (tp->t_uto_left == 0 && tp->uto_flags & TCPUTO_IMPL)) {
 		tp->t_rxtshift = TCP_MAXRXTSHIFT;
 		TCPSTAT_INC(tcps_timeoutdrop);
 		tp = tcp_drop(tp, tp->t_softerror ?
-			      tp->t_softerror : ETIMEDOUT);
+		    tp->t_softerror : ETIMEDOUT);
 		goto out;
 	}
 	INP_INFO_WUNLOCK(&V_tcbinfo);
@@ -537,19 +540,20 @@
 		if ((tp->uto_flags & TCPUTO_IMPL) == 0) {
 			rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift];
 			TCPT_RANGESET(tp->t_rxtcur, rexmt,
-				      tp->t_rttmin, TCPTV_REXMTMAX);
+			    tp->t_rttmin, TCPTV_REXMTMAX);
 		} else {
 			int rxtshift, interval;
 			rxtshift = min(TCP_MAXRXTSHIFT, tp->t_rxtshift);
 			interval = min(TCP_REXMTMAX, tcp_backoff[rxtshift]);
 			rexmt = TCP_REXMTVAL(tp) * tcp_backoff[rxtshift];
 			TCPT_RANGESET(tp->t_rxtcur, rexmt,
-				      tp->t_rttmin, TCPTV_REXMTMAX);
+			    tp->t_rttmin, TCPTV_REXMTMAX);
 			if (tp->t_uto_left < interval) {
-				tp->t_rxtcur = (tp->t_rxtcur * tp->t_uto_left) / interval;
+				tp->t_rxtcur = (tp->t_rxtcur * tp->t_uto_left)
+				    / interval;
 				/*  Prevent t_rxtcur to be zero */
 				TCPT_RANGESET(tp->t_rxtcur, tp->t_rxtcur,
-					      tp->t_rttmin, TCPTV_REXMTMAX);
+				    tp->t_rttmin, TCPTV_REXMTMAX);
 			}
 			tp->t_uto_left -= min(tp->t_uto_left, interval);
 		}

==== //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_usrreq.c#10 (text+ko) ====

@@ -1379,7 +1379,8 @@
 				return (error);
 
 			INP_WLOCK_RECHECK(inp);
-			if (tu.flags & ~(ENABLE_UTO | STORE_UTO | ENABLE_CHANGE)) {
+			if (tu.flags & ~(ENABLE_UTO | STORE_UTO |
+			    ENABLE_CHANGE)) {
 				error = EINVAL;
 				break;
 			}
@@ -1398,10 +1399,12 @@
 					}
 					if (tp->uto_flags & TCPUTO_ENABLE &&
 					    tp->uto_flags & TCPUTO_NEED) {
-						tp->t_uto_impl = min(tcp_uto_max, 
-								max(tu.uto * hz, tcp_uto_min));
+						tp->t_uto_impl =  min(
+						    tcp_uto_max, max(tu.uto*hz,
+						    tcp_uto_min));
 						tp->t_uto_adv = tp->t_uto_impl;
-						tp->uto_flags &= ~TCPUTO_CHANGEABLE;
+						tp->uto_flags &=
+						    ~TCPUTO_CHANGEABLE;
 						tp->uto_flags |= TCPUTO_IMPL;
 					}
 				} else

==== //depot/projects/soc2009/tcputo/src/sys/netinet/tcp_var.h#15 (text+ko) ====

@@ -254,19 +254,20 @@
 /*
 * Resolve user timeout value(ticks).
 */
-#define	TCPT_RESOLVE_UTO(tp) do {						\
-	if ((tp)->uto_flags & TCPUTO_ENABLE &&					\
-	    (tp)->uto_flags & TCPUTO_RCVD &&					\
-	    (tp)->uto_flags & TCPUTO_CHANGEABLE) {				\
-		(tp)->t_uto_impl = (tp)->rcv_uto >> 1;				\
-		if ((tp)->rcv_uto & 1)						\
-			(tp)->t_uto_impl *= 60;					\
-		(tp)->t_uto_impl *= hz;						\
-		(tp)->t_uto_impl = min(tcp_uto_max,				\
-		    max((tp)->t_uto_adv, max((tp)->t_uto_impl, tcp_uto_min)));	\
-		(tp)->uto_flags &= ~TCPUTO_RCVD;				\
-		(tp)->uto_flags |= TCPUTO_IMPL;					\
-	}									\
+#define	TCPT_RESOLVE_UTO(tp) do {				\
+	if ((tp)->uto_flags & TCPUTO_ENABLE &&			\
+	    (tp)->uto_flags & TCPUTO_RCVD &&			\
+	    (tp)->uto_flags & TCPUTO_CHANGEABLE) {		\
+		(tp)->t_uto_impl = (tp)->rcv_uto >> 1;		\
+		if ((tp)->rcv_uto & 1)				\
+			(tp)->t_uto_impl *= 60;			\
+		(tp)->t_uto_impl *= hz;				\
+		(tp)->t_uto_impl = min(tcp_uto_max,		\
+		    max((tp)->t_uto_adv,			\
+		    max((tp)->t_uto_impl, tcp_uto_min)));	\
+		(tp)->uto_flags &= ~TCPUTO_RCVD;		\
+		(tp)->uto_flags |= TCPUTO_IMPL;			\
+	}							\
 } while(0)
 
 #ifdef TCP_SIGNATURE

==== //depot/projects/soc2009/tcputo/src/tools/regression/netinet/tcputo/README#3 (text+ko) ====

@@ -21,4 +21,4 @@
 
 After that, interrupt the connection without detected by operating system, and
 wait until process exits.
-$FreeBSD: src/tools/regression/netinet/tcputo/README,v 1.0 2008/08/15 20:26:52 fw Exp $
+$FreeBSD: src/tools/regression/netinet/tcputo/README,v 1.0 2009/08/17 00:56:31 fw Exp $

==== //depot/projects/soc2009/tcputo/src/tools/regression/netinet/tcputo/tcputo.c#8 (text+ko) ====

@@ -23,9 +23,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/tools/regression/netinet/tcputo/tcputo.c 2009/08/15 20:28:31 fw $
+ * $FreeBSD: src/tools/regression/netinet/tcputo/tcputo.c 2009/08/17 00:56:31 fw $
+ */
+
+/*
+ * TCP regression test for tcp user timeout; build a TCP connection, interrupt
+ * it without detected by operating system, and make sure the timeout time and
+ * retransmission times has been changed appropriately.
  */
 
+
 #include <sys/types.h>
 #include <sys/socket.h>
 
@@ -49,22 +56,22 @@
 #include <pthread.h>
 
 #define	SIZE_ETHERNET	sizeof(struct ether_header)
+#define	MAX_RXT	200
 
 struct tcprxt {
 	struct timeval ts;
-	u_int th_off;
-	tcp_seq th_seq;
-	tcp_seq th_ack;
+	u_int	th_off;
+	tcp_seq	th_seq;
+	tcp_seq	th_ack;
 	u_short	th_win;
-	u_char th_flags;
+	u_char	th_flags;
 };
 
-#define	MAX_RXT	200
+static struct tcprxt	rxts[MAX_RXT];
 
-struct tcprxt	rxts[MAX_RXT];
-
-void
-parse_packet(u_char *args, const struct pcap_pkthdr *pkt_header, const u_char *packet)
+static void
+parse_packet(u_char *args, const struct pcap_pkthdr *pkt_header,
+    const u_char *packet)
 {
 	const struct ip *ip;
 	const struct tcphdr *tcp;
@@ -108,10 +115,12 @@
 				uto >>= 1;
 			p = localtime(&pkt_header->ts.tv_sec);
 			printf("uto packet: ");
-			printf("%02d:%02d:%02d.%-6u ", p->tm_hour, p->tm_min, p->tm_sec,
-				pkt_header->ts.tv_usec);
-			printf("%s.%d > ", inet_ntoa(ip->ip_src), htons(tcp->th_sport));
-			printf("%s.%d, ", inet_ntoa(ip->ip_dst), htons(tcp->th_dport));
+			printf("%02d:%02d:%02d.%-6u ", p->tm_hour, p->tm_min,
+			    p->tm_sec, pkt_header->ts.tv_usec);
+			printf("%s.%d > ", inet_ntoa(ip->ip_src),
+			    htons(tcp->th_sport));
+			printf("%s.%d, ", inet_ntoa(ip->ip_dst),
+			    htons(tcp->th_dport));
 			printf("flags [");
 			if (tcp->th_flags & TH_SYN)
 				printf("S");
@@ -124,7 +133,8 @@
 			if (tcp->th_flags & TH_URG)
 				printf("U");
 			printf("], ");
-			printf("uto %u, win %u, length %u\n", uto, htons(tcp->th_win), length);
+			printf("uto %u, win %u, length %u\n", uto,
+			    htons(tcp->th_win), length);
 		}
 		hlen -= optlen - 1;
 		tcpopt += optlen - 2;
@@ -137,12 +147,13 @@
 		rxt.th_ack = htonl(tcp->th_ack);
 		rxt.th_seq = htonl(tcp->th_seq);
 		rxt.th_flags = tcp->th_flags;
-		memcpy(&rxts[0], &rxts[1], sizeof(struct tcprxt) * (MAX_RXT - 1));
+		memcpy(&rxts[0], &rxts[1],
+		    sizeof(struct tcprxt) * (MAX_RXT - 1));
 		memcpy(&rxts[MAX_RXT - 1], &rxt, sizeof(rxt));
 	}
 }
 
-void *
+static void *
 dump_packet(void *arg)
 {
 	pcap_t *handle;
@@ -160,10 +171,12 @@
 	int flag;
 
 	optlen = sizeof(srcaddr);
-	if (getsockname(*((int *)arg), (struct sockaddr *)&srcaddr, &optlen) == -1)
+	if (getsockname(*((int *)arg), (struct sockaddr *)&srcaddr,
+	    &optlen) == -1)
 		err(-1, "getsockname");
 	optlen = sizeof(dstaddr);
-	if (getpeername(*((int *)arg), (struct sockaddr *)&dstaddr, &optlen) == -1)
+	if (getpeername(*((int *)arg), (struct sockaddr *)&dstaddr,
+	    &optlen) == -1)
 		err(-1, "getsockname");
 
 	if (pcap_findalldevs(&alldevsp, errbuf) == -1) {
@@ -177,7 +190,8 @@
 		addrp = devp->addresses;
 		while (addrp != NULL && flag) {
 			devaddrp = (struct sockaddr_in *)addrp->addr;
-			if (!memcmp(&devaddrp->sin_addr, &srcaddr.sin_addr, sizeof(srcaddr.sin_addr))) {
+			if (!memcmp(&devaddrp->sin_addr, &srcaddr.sin_addr,
+			    sizeof(srcaddr.sin_addr))) {
 				flag = 0;
 				break;
 			}
@@ -194,48 +208,56 @@
 	}
 
 	if (pcap_lookupnet(devp->name, &net, &mask, errbuf) == -1) {
-		fprintf(stderr, "Couldn't get netmask for device %s: %s\n", devp->name, errbuf);
+		fprintf(stderr, "Couldn't get netmask for device %s: %s\n",
+		    devp->name, errbuf);
 		net = 0;
 		mask = 0;
 	}
 
 	handle = pcap_open_live(devp->name, BUFSIZ, 1, 1000, errbuf);
 	if (handle == NULL) {
-		fprintf(stderr, "Couldn't open device %s: %s\n", devp->name, errbuf);
+		fprintf(stderr, "Couldn't open device %s: %s\n",
+		    devp->name, errbuf);
 		exit(-1);
 	}
 
 	pcap_freealldevs(alldevsp);
 
 	snprintf(filter_exp, sizeof(filter_exp),
-		"(tcp src port %d and dst port %d) or (tcp src port %d and dst port %d)",
-		ntohs(srcaddr.sin_port), ntohs(dstaddr.sin_port),
-		ntohs(dstaddr.sin_port), ntohs(srcaddr.sin_port));
+	    "(tcp src port %d and dst port %d) or"
+	    "(tcp src port %d and dst port %d)",
+	    ntohs(srcaddr.sin_port), ntohs(dstaddr.sin_port),
+	    ntohs(dstaddr.sin_port), ntohs(srcaddr.sin_port));
 
 	if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
-		fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle));
+		fprintf(stderr, "Couldn't parse filter %s: %s\n",
+		    filter_exp, pcap_geterr(handle));
 		exit(-1);
 	}
 	if (pcap_setfilter(handle, &fp) == -1) {
-		fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle));
+		fprintf(stderr, "Couldn't install filter %s: %s\n",
+		    filter_exp, pcap_geterr(handle));
 		exit(-1);
 	}
 
 	pcap_loop(handle, -1, parse_packet, NULL);
 	pcap_close(handle);
-	
+
 	return NULL;
 }
 
-void print_result()
+static void
+print_result()
 {
 	tcp_seq rxt_seq;
 	int i, last, rxt_nr;
 	struct tm *p;
-
+	
+	/* Get the retransmit sequence number */
 	rxt_seq = rxts[MAX_RXT - 2].th_seq;
 	for (last = -1, rxt_nr = 0, i = 0; i < MAX_RXT; i++) {
-		if (rxts[i].th_seq && (rxts[i].th_seq == rxt_seq || rxts[i].th_flags & TH_RST)) {
+		if (rxts[i].th_seq &&
+		    (rxts[i].th_seq == rxt_seq || rxts[i].th_flags & TH_RST)) {
 			if (rxts[i].th_flags & TH_RST)
 				printf("reset packet, ");
 			else if (rxt_nr)
@@ -243,16 +265,25 @@
 			else if (!rxt_nr)
 				printf("send packet, ");
 			p = localtime(&rxts[i].ts.tv_sec);
-			printf("%02d:%02d:%02d.%-6u ", p->tm_hour, p->tm_min, p->tm_sec, rxts[i].ts.tv_usec);
+			printf("%02d:%02d:%02d.%-6u ", p->tm_hour, p->tm_min,
+			    p->tm_sec, rxts[i].ts.tv_usec);
 			if (last != -1) {
+				/* print interval between two packets */
 				if (rxts[i].ts.tv_usec < rxts[last].ts.tv_usec)
-					printf("(%2u.%-6u) ", rxts[i].ts.tv_sec - rxts[last].ts.tv_sec - 1, 
-						1000000 + rxts[i].ts.tv_usec - rxts[last].ts.tv_usec);
+					printf("(%2u.%-6u) ",
+					    rxts[i].ts.tv_sec -
+					    rxts[last].ts.tv_sec - 1,
+					    1000000 + rxts[i].ts.tv_usec -
+					    rxts[last].ts.tv_usec);
 				else
-					printf("(%2u.%-6u) ", rxts[i].ts.tv_sec - rxts[last].ts.tv_sec, 
-						rxts[i].ts.tv_usec - rxts[last].ts.tv_usec);
+					printf("(%2u.%-6u) ",
+					    rxts[i].ts.tv_sec -
+					    rxts[last].ts.tv_sec,
+					    rxts[i].ts.tv_usec -
+					    rxts[last].ts.tv_usec);
 			}
-			printf("seq %u, ack %u, ", rxts[i].th_seq, rxts[i].th_ack);
+			printf("seq %u, ack %u, ",
+			    rxts[i].th_seq, rxts[i].th_ack);
 			printf("win %u\n", rxts[i].th_win);
 			last = i;
 			rxt_nr++;
@@ -260,11 +291,12 @@
 	}
 }
 
-int
+static int
 print_uto_status(int sock, int print)
 {
 	static struct tcputo tu = {0, 0};
-	int default_uto = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 64 + 64 + 64 + 64 + 64 + 64;
+	int default_uto = 1 + 2 + 4 + 8 + 16 + 32 + 64 +
+	    64 + 64 + 64 + 64 + 64 + 64;
 	int optlen;
 	int utoval;
 
@@ -274,26 +306,29 @@
 		if (tu.flags & ENABLE_UTO) {
 			printf("tcputo: enabled, ");
 			if (tu.flags & STORE_UTO) {
-				printf("user timeout(changed): %d seconds\n", tu.uto);
+				printf("user timeout(changed): %d seconds\n",
+				    tu.uto);
 				utoval = tu.uto;
 			} else {
-				printf("user timeout(default): %d seconds\n", default_uto);
+				printf("user timeout(default): %d seconds\n",
+				    default_uto);
 				utoval = default_uto;
 			}
 		} else {
-			printf("tcputo: disabled, default timeout: %d seconds\n", default_uto);
+			printf("tcputo: disabled, default timeout: %d "
+			    "seconds\n", default_uto);
 			utoval = default_uto;
 		}
 	}
 
-	return utoval;
+	return (utoval);
 }
 
 static void
 usage(void)
 {
-	fprintf(stderr, "tcpconnect server port [uto [timeout seconds]]\n");
-	fprintf(stderr, "tcpconnect client ip port [uto [timeout seconds]]\n");
+	fprintf(stderr, "tcpconnect server port [uto [timeout]]\n");
+	fprintf(stderr, "tcpconnect client ip port [uto [timeout]]\n");
 	exit(-1);
 }
 
@@ -346,7 +381,8 @@
 	if (listen_sock == -1)
 		err(-1, "socket");
 	optval = 1;
-	if (setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1)
+	if (setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &optval,
+	    sizeof(optval)) == -1)
 		err(-1, "setsockopt");
 
 	if (bind(listen_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)
@@ -365,6 +401,10 @@
 
 	if (argc >= 2) {
 		memset(&uto, 0, sizeof(uto));
+		/*
+		 * If TCP UTO is enabled but not set, make it changeable,
+		 * otherwise, make it unchangeable.
+		 */
 		if (!strcmp(argv[1], "uto")) {
 			uto.flags |= ENABLE_UTO;
 			uto.flags |= ENABLE_CHANGE;
@@ -377,21 +417,27 @@
 			uto.flags |= STORE_UTO;
 			uto.flags &= ~ENABLE_CHANGE;
 		}
-		if (setsockopt(accept_sock, IPPROTO_TCP, TCP_UTO, &uto, sizeof(uto)) == -1)
+		if (setsockopt(accept_sock, IPPROTO_TCP, TCP_UTO, &uto,
+		    sizeof(uto)) == -1)
 			err(-1, "setsockopt");
 	}
 
 	optval = 4*1024;
-	if (setsockopt(accept_sock, SOL_SOCKET, SO_SNDBUF, &optval, sizeof(optval)) == -1)
+	if (setsockopt(accept_sock, SOL_SOCKET, SO_SNDBUF, &optval,
+	    sizeof(optval)) == -1)
 		err(-1, "setsockopt");
 
 	while(1) {
 		sleep(1);
-		while(recv(accept_sock, buf, 8*1024, MSG_DONTWAIT) > 0);
+		while (recv(accept_sock, buf, 8*1024, MSG_DONTWAIT) > 0);
 		(void)tcputo_timer();
+		/*
+		 * Send more data than socket send buffer,
+		 * so that data are not buffered.
+		 */
 		if (send(accept_sock, buf, 8*1024, MSG_NOSIGNAL) >= 0) {
 			(void)tcputo_timer();
-			print_uto_status(accept_sock, 0);
+			(void)print_uto_status(accept_sock, 0);
 			continue;
 		}
 		user_timeout = tcputo_timer();
@@ -400,7 +446,7 @@
 	}
 	/* wait for the reset packet to be captured */
 	sleep(1);
-	pthread_kill(tid, SIGTERM);
+	(void)pthread_kill(tid, SIGTERM);
 
 	close(accept_sock);
 }
@@ -436,11 +482,16 @@
 		err(-1, "socket");
 
 	optval = 4*1024;
-	if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &optval, sizeof(optval)) == -1)
+	if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &optval,
+	    sizeof(optval)) == -1)
 		err(-1, "setsockopt");
 
 	if (argc >= 3) {
 		memset(&uto, 0, sizeof(uto));
+		/*
+		 * If TCP UTO is enabled but not set, make it changeable,
+		 * otherwise, make it unchangeable.
+		 */
 		if (!strcmp(argv[2], "uto")) {
 			uto.flags |= ENABLE_UTO;
 			uto.flags |= ENABLE_CHANGE;
@@ -453,7 +504,8 @@
 			uto.flags |= STORE_UTO;
 			uto.flags &= ~ENABLE_CHANGE;
 		}
-		if (setsockopt(sock, IPPROTO_TCP, TCP_UTO, &uto, sizeof(uto)) == -1)
+		if (setsockopt(sock, IPPROTO_TCP, TCP_UTO, &uto,
+		    sizeof(uto)) == -1)
 			err(-1, "setsockopt");
 	}
 
@@ -467,9 +519,13 @@
 		sleep(1);
 		while(recv(sock, buf, 8*1024, MSG_DONTWAIT) > 0);
 		(void)tcputo_timer();
+		/*
+		 * Send more data than socket send buffer,
+		 * so that data are not buffered.
+		 */
 		if (send(sock, buf, 8*1024, MSG_NOSIGNAL) > 0) {
 			(void)tcputo_timer();
-			print_uto_status(sock, 0);
+			(void)print_uto_status(sock, 0);
 			continue;
 		}
 		user_timeout = tcputo_timer();
@@ -478,7 +534,7 @@
 	}
 	/* wait for the reset packet to be captured */
 	sleep(1);
-	pthread_kill(tid, SIGTERM);
+	(void)pthread_kill(tid, SIGTERM);
 
 	close(sock);
 }
@@ -498,7 +554,7 @@
 	else
 		usage();
 	
-	print_uto_status(-1, 1);
+	(void)print_uto_status(-1, 1);
 	print_result();
 
 	exit(0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908161744.n7GHiTWN000559>