Module Name:    src
Committed By:   christos
Date:           Sat Nov 23 22:01:12 UTC 2013

Modified Files:
        src/usr.bin/netstat: inet.c inet6.c main.c netstat.h

Log Message:
Update for new pcb tailq's.
While here fix ipv6 pcb printing by making tcp6_dump with tcp.
XXX: Merge the inet and the inet6 code. It is silly to need to specify
-p tcp6 to print a tcp6 pcb, we already know what it is.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/netstat/netstat.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.103 src/usr.bin/netstat/inet.c:1.104
--- src/usr.bin/netstat/inet.c:1.103	Thu Jun 20 06:43:18 2013
+++ src/usr.bin/netstat/inet.c	Sat Nov 23 17:01:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.103 2013/06/20 10:43:18 martin Exp $	*/
+/*	$NetBSD: inet.c,v 1.104 2013/11/23 22:01:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.103 2013/06/20 10:43:18 martin Exp $");
+__RCSID("$NetBSD: inet.c,v 1.104 2013/11/23 22:01:12 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -265,7 +265,7 @@ getpcblist_sysctl(const char *name, size
 static struct kinfo_pcb *
 getpcblist_kmem(u_long off, const char *name, size_t *len) {
 	struct inpcbtable table;
-	struct inpcb *head, *next, *prev;
+	struct inpcb_hdr *next, *prev;
 	struct inpcb inpcb;
 	struct tcpcb tcpcb;
 	struct socket sockb;
@@ -273,6 +273,7 @@ getpcblist_kmem(u_long off, const char *
 	struct kinfo_pcb *pcblist;
 	size_t size = 100, i;
 	struct sockaddr_in sin; 
+	struct inpcbqueue *head;
 
 	if (off == 0) {
 		*len = 0;
@@ -280,22 +281,18 @@ getpcblist_kmem(u_long off, const char *
 	}
 
 	kread(off, (char *)&table, sizeof table);
-	prev = head =
-	    (struct inpcb *)&((struct inpcbtable *)off)->inpt_queue.cqh_first;
-	next = (struct inpcb *)table.inpt_queue.cqh_first;
+	head = &table.inpt_queue;
+	next = TAILQ_FIRST(head);
+	prev = TAILQ_END(head);
 
 	if ((pcblist = malloc(size)) == NULL)
 		err(1, "malloc");
 
 	i = 0;
-	while (next != head) {
+	while (next != TAILQ_END(head)) {
 		kread((u_long)next, (char *)&inpcb, sizeof inpcb);
-		if ((struct inpcb *)inpcb.inp_queue.cqe_prev != prev) {
-			warnx("bad pcb");
-			break;
-		}
 		prev = next;
-		next = (struct inpcb *)inpcb.inp_queue.cqe_next;
+		next = TAILQ_NEXT(&inpcb, inp_queue);
 
 		if (inpcb.inp_af != AF_INET)
 			continue;
@@ -305,7 +302,7 @@ getpcblist_kmem(u_long off, const char *
 			kread((u_long)inpcb.inp_ppcb,
 			    (char *)&tcpcb, sizeof (tcpcb));
 		}
-		pcblist[i].ki_ppcbaddr = 
+		pcblist[i].ki_ppcbaddr =
 		    istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev;
 		pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc;
 		pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc;

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.65 src/usr.bin/netstat/inet6.c:1.66
--- src/usr.bin/netstat/inet6.c:1.65	Sat Oct 19 11:56:06 2013
+++ src/usr.bin/netstat/inet6.c	Sat Nov 23 17:01:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.65 2013/10/19 15:56:06 christos Exp $	*/
+/*	$NetBSD: inet6.c,v 1.66 2013/11/23 22:01:12 christos Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,10 +64,12 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.65 2013/10/19 15:56:06 christos Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.66 2013/11/23 22:01:12 christos Exp $");
 #endif
 #endif /* not lint */
 
+#define _CALLOUT_PRIVATE
+
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
@@ -90,22 +92,26 @@ __RCSID("$NetBSD: inet6.c,v 1.65 2013/10
 #include <netinet6/in6_pcb.h>
 #include <netinet6/in6_var.h>
 #ifdef TCP6
-#include <netinet6/tcp6.h>
-#include <netinet6/tcp6_seq.h>
+#include <netinet/tcp6.h>
+#include <netinet/tcp6_seq.h>
 #define TCP6STATES
-#include <netinet6/tcp6_fsm.h>
+#include <netinet/tcp6_fsm.h>
 #define TCP6TIMERS
-#include <netinet6/tcp6_timer.h>
-#include <netinet6/tcp6_var.h>
-#include <netinet6/tcp6_debug.h>
+#include <netinet/tcp6_timer.h>
+#include <netinet/tcp6_var.h>
+#include <netinet/tcp6_debug.h>
 #else
+#define TCP6T_NTIMERS	TCPT_NTIMERS
+#define tcp6timers tcptimers
+#define tcp6states tcpstates
+#define TCP6_NSTATES	TCP_NSTATES
+#define tcp6cb tcpcb
 #include <netinet/tcp.h>
 #include <netinet/tcpip.h>
 #include <netinet/tcp_seq.h>
-/*#define TCPSTATES*/
 #include <netinet/tcp_fsm.h>
 extern const char * const tcpstates[];
-/*#define	TCPTIMERS*/
+extern const char * const tcptimers[];
 #include <netinet/tcp_timer.h>
 #include <netinet/tcp_var.h>
 #include <netinet/tcp_debug.h>
@@ -280,33 +286,30 @@ static struct kinfo_pcb *
 getpcblist_kmem(u_long off, const char *name, size_t *len) {
 
 	struct inpcbtable table;
-	struct in6pcb *head, *prev, *next;
+	struct inpcb_hdr *next, *prev;
 	int istcp = strcmp(name, "tcp6") == 0;
 	struct kinfo_pcb *pcblist;
 	size_t size = 100, i;
 	struct sockaddr_in6 sin6;
+	struct inpcbqueue *head;
 
 	if (off == 0) {
 		*len = 0;
 		return NULL;
 	}
 	kread(off, (char *)&table, sizeof (table));
-	head = prev =
-	    (struct in6pcb *)&((struct inpcbtable *)off)->inpt_queue.cqh_first;
-	next = (struct in6pcb *)table.inpt_queue.cqh_first;
+	head = &table.inpt_queue;
+	next = TAILQ_FIRST(head);
+	prev = TAILQ_END(head);
 
 	if ((pcblist = malloc(size)) == NULL)
 		err(1, "malloc");
 
 	i = 0;
-	while (next != head) {
+	while (next != TAILQ_END(head)) {
 		kread((u_long)next, (char *)&in6pcb, sizeof in6pcb);
-		if ((struct in6pcb *)in6pcb.in6p_queue.cqe_prev != prev) {
-			warnx("bad pcb");
-			break;
-		}
+		next = TAILQ_NEXT(&in6pcb, in6p_queue);
 		prev = next;
-		next = (struct in6pcb *)in6pcb.in6p_queue.cqe_next;
 
 		if (in6pcb.in6p_af != AF_INET6)
 			continue;
@@ -1430,17 +1433,20 @@ inet6name(const struct in6_addr *in6p)
 	return (line);
 }
 
-#ifdef TCP6
 /*
  * Dump the contents of a TCP6 PCB.
  */
 void
-tcp6_dump(u_long pcbaddr)
-	u_long pcbaddr;
+tcp6_dump(u_long off, const char *name, u_long pcbaddr)
 {
-	struct tcp6cb tcp6cb;
-	int i;
+	callout_impl_t *ci;
+	int i, hardticks;
 	struct kinfo_pcb *pcblist;
+#ifdef TCP6
+#define mypcb tcp6cb
+#else
+#define mypcb tcpcb
+#endif
 	size_t j, len;
 
 	if (use_sysctl)
@@ -1456,55 +1462,63 @@ tcp6_dump(u_long pcbaddr)
 	if (j == len)
 		errx(1, "0x%lx is not a valid pcb address", pcbaddr);
 
-	kread(pcbaddr, (char *)&tcp6cb, sizeof(tcp6cb));
+	kread(pcbaddr, (char *)&mypcb, sizeof(mypcb));
+	hardticks = get_hardticks();
 
 	printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
-
 	printf("Timers:\n");
-	for (i = 0; i < TCP6T_NTIMERS; i++)
-		printf("\t%s: %u", tcp6timers[i], tcp6cb.t_timer[i]);
+	for (i = 0; i < TCP6T_NTIMERS; i++) {
+		ci = (callout_impl_t *)&tcpcb.t_timer[i];
+		printf("\t%s: %d", tcptimers[i],
+		    (ci->c_flags & CALLOUT_PENDING) ?
+		    ci->c_time - hardticks : 0);
+	}
 	printf("\n\n");
 
-	if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
-		printf("State: %d", tcp6cb.t_state);
+	if (mypcb.t_state < 0 || mypcb.t_state >= TCP6_NSTATES)
+		printf("State: %d", mypcb.t_state);
 	else
-		printf("State: %s", tcp6states[tcp6cb.t_state]);
-	printf(", flags 0x%x, in6pcb 0x%lx\n\n", tcp6cb.t_flags,
-	    (u_long)tcp6cb.t_in6pcb);
-
-	printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcp6cb.t_rxtshift,
-	    tcp6cb.t_rxtcur, tcp6cb.t_dupacks);
-	printf("peermaxseg %u, maxseg %u, force %d\n\n", tcp6cb.t_peermaxseg,
-	    tcp6cb.t_maxseg, tcp6cb.t_force);
+		printf("State: %s", tcp6states[mypcb.t_state]);
+	printf(", flags 0x%x, in6pcb 0x%lx\n\n", mypcb.t_flags,
+	    (u_long)mypcb.t_in6pcb);
+
+	printf("rxtshift %d, rxtcur %d, dupacks %d\n", mypcb.t_rxtshift,
+	    mypcb.t_rxtcur, mypcb.t_dupacks);
+#ifdef TCP6
+	printf("peermaxseg %u, maxseg %u, force %d\n\n", mypcb.t_peermaxseg,
+	    mypcb.t_maxseg, mypcb.t_force);
+#endif
 
 	printf("snd_una %u, snd_nxt %u, snd_up %u\n",
-	    tcp6cb.snd_una, tcp6cb.snd_nxt, tcp6cb.snd_up);
+	    mypcb.snd_una, mypcb.snd_nxt, mypcb.snd_up);
 	printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %llu\n\n",
-	    tcp6cb.snd_wl1, tcp6cb.snd_wl2, tcp6cb.iss,
-	    (unsigned long long)tcp6cb.snd_wnd);
+	    mypcb.snd_wl1, mypcb.snd_wl2, mypcb.iss,
+	    (unsigned long long)mypcb.snd_wnd);
 
 	printf("rcv_wnd %llu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
-	    (unsigned long long)cp6cb.rcv_wnd, tcp6cb.rcv_nxt,
-	    tcp6cb.rcv_up, tcp6cb.irs);
+	    (unsigned long long)mypcb.rcv_wnd, mypcb.rcv_nxt,
+	    mypcb.rcv_up, mypcb.irs);
 
 	printf("rcv_adv %u, snd_max %u, snd_cwnd %llu, snd_ssthresh %llu\n",
-	    tcp6cb.rcv_adv, tcp6cb.snd_max, (unsigned long long)tcp6cb.snd_cwnd,
-	    (unsigned long long)tcp6cb.snd_ssthresh);
+	    mypcb.rcv_adv, mypcb.snd_max, (unsigned long long)mypcb.snd_cwnd,
+	    (unsigned long long)mypcb.snd_ssthresh);
 
-	printf("idle %d, rtt %d, rtseq %u, srtt %d, rttvar %d, rttmin %d, "
-	    "max_sndwnd %llu\n\n", tcp6cb.t_idle, tcp6cb.t_rtt, tcp6cb.t_rtseq,
-	    tcp6cb.t_srtt, tcp6cb.t_rttvar, tcp6cb.t_rttmin,
-	    (unsigned long long)tcp6cb.max_sndwnd);
+#ifdef TCP6
+	printf("idle %d, rtt %d, " mypcb.t_idle, mypcb.t_rtt)
+#endif
+	printf("rtseq %u, srtt %d, rttvar %d, rttmin %d, "
+	    "max_sndwnd %llu\n\n", mypcb.t_rtseq,
+	    mypcb.t_srtt, mypcb.t_rttvar, mypcb.t_rttmin,
+	    (unsigned long long)mypcb.max_sndwnd);
 
-	printf("oobflags %d, iobc %d, softerror %d\n\n", tcp6cb.t_oobflags,
-	    tcp6cb.t_iobc, tcp6cb.t_softerror);
+	printf("oobflags %d, iobc %d, softerror %d\n\n", mypcb.t_oobflags,
+	    mypcb.t_iobc, mypcb.t_softerror);
 
 	printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
-	    tcp6cb.snd_scale, tcp6cb.rcv_scale, tcp6cb.request_r_scale,
-	    tcp6cb.requested_s_scale);
+	    mypcb.snd_scale, mypcb.rcv_scale, mypcb.request_r_scale,
+	    mypcb.requested_s_scale);
 	printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
-	    tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent);
+	    mypcb.ts_recent, mypcb.ts_recent_age, mypcb.last_ack_sent);
 }
-#endif
 
 #endif /*INET6*/

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.87 src/usr.bin/netstat/main.c:1.88
--- src/usr.bin/netstat/main.c:1.87	Fri Oct 18 18:18:14 2013
+++ src/usr.bin/netstat/main.c	Sat Nov 23 17:01:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.87 2013/10/18 22:18:14 bad Exp $	*/
+/*	$NetBSD: main.c,v 1.88 2013/11/23 22:01:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.87 2013/10/18 22:18:14 bad Exp $");
+__RCSID("$NetBSD: main.c,v 1.88 2013/11/23 22:01:12 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -227,7 +227,7 @@ struct protox ip6protox[] = {
 	  tcp6_stats,	NULL,		tcp6_dump,	"tcp6" },
 #else
 	{ N_TCBTABLE,	N_TCP6STAT,	1,	ip6protopr,
-	  tcp_stats,	NULL,		tcp_dump,	"tcp6" },
+	  tcp_stats,	NULL,		tcp6_dump,	"tcp6" },
 #endif
 	{ N_UDBTABLE,	N_UDP6STAT,	1,	ip6protopr,
 	  udp6_stats,	NULL,		0,	"udp6" },

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.47 src/usr.bin/netstat/netstat.h:1.48
--- src/usr.bin/netstat/netstat.h:1.47	Wed Jun 19 17:12:03 2013
+++ src/usr.bin/netstat/netstat.h	Sat Nov 23 17:01:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.47 2013/06/19 21:12:03 christos Exp $	*/
+/*	$NetBSD: netstat.h,v 1.48 2013/11/23 22:01:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -92,7 +92,7 @@ struct sockaddr_in6;
 struct in6_addr;
 void	ip6protopr __P((u_long, const char *));
 void	tcp6_stats __P((u_long, const char *));
-void	tcp6_dump __P((u_long));
+void	tcp6_dump __P((u_long, const char *, u_long));
 void	udp6_stats __P((u_long, const char *));
 void	ip6_stats __P((u_long, const char *));
 void	ip6_ifstats __P((const char *));

Reply via email to