Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Jan 2016 18:37:37 +0000 (UTC)
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r294231 - stable/10/usr.bin/sockstat
Message-ID:  <201601171837.u0HIbbAD023628@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tuexen
Date: Sun Jan 17 18:37:36 2016
New Revision: 294231
URL: https://svnweb.freebsd.org/changeset/base/294231

Log:
  MFC r287182:
  Add SCTP support.

Modified:
  stable/10/usr.bin/sockstat/sockstat.1
  stable/10/usr.bin/sockstat/sockstat.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/sockstat/sockstat.1
==============================================================================
--- stable/10/usr.bin/sockstat/sockstat.1	Sun Jan 17 18:35:46 2016	(r294230)
+++ stable/10/usr.bin/sockstat/sockstat.1	Sun Jan 17 18:37:36 2016	(r294231)
@@ -27,7 +27,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd July 14, 2015
+.Dd August 27, 2015
 .Dt SOCKSTAT 1
 .Os
 .Sh NAME
@@ -85,7 +85,7 @@ as they are defined in
 .Xr protocols 5 .
 .It Fl s
 Display the protocol state, if applicable.
-This is currently only implemented for TCP.
+This is currently only implemented for SCTP and TCP.
 .It Fl u
 Show
 .Dv AF_LOCAL

Modified: stable/10/usr.bin/sockstat/sockstat.c
==============================================================================
--- stable/10/usr.bin/sockstat/sockstat.c	Sun Jan 17 18:35:46 2016	(r294230)
+++ stable/10/usr.bin/sockstat/sockstat.c	Sun Jan 17 18:37:36 2016	(r294231)
@@ -332,6 +332,12 @@ gather_sctp(void)
 		sock->socket = xinpcb->socket;
 		sock->proto = IPPROTO_SCTP;
 		sock->protoname = "sctp";
+		if (xinpcb->flags & SCTP_PCB_FLAGS_UNBOUND)
+			sock->state = SCTP_CLOSED;
+		else if (xinpcb->maxqlen == 0)
+			sock->state = SCTP_BOUND;
+		else
+			sock->state = SCTP_LISTEN;
 		if (xinpcb->flags & SCTP_PCB_FLAGS_BOUND_V6) {
 			sock->family = AF_INET6;
 			sock->vflag = INP_IPV6;
@@ -421,6 +427,7 @@ gather_sctp(void)
 				sock->socket = xinpcb->socket;
 				sock->proto = IPPROTO_SCTP;
 				sock->protoname = "sctp";
+				sock->state = (int)xstcb->state;
 				if (xinpcb->flags & SCTP_PCB_FLAGS_BOUND_V6) {
 					sock->family = AF_INET6;
 					sock->vflag = INP_IPV6;
@@ -906,6 +913,46 @@ check_ports(struct sock *s)
 	return (0);
 }
 
+static const char *
+sctp_state(int state)
+{
+	switch (state) {
+	case SCTP_CLOSED:
+		return "CLOSED";
+		break;
+	case SCTP_BOUND:
+		return "BOUND";
+		break;
+	case SCTP_LISTEN:
+		return "LISTEN";
+		break;
+	case SCTP_COOKIE_WAIT:
+		return "COOKIE_WAIT";
+		break;
+	case SCTP_COOKIE_ECHOED:
+		return "COOKIE_ECHOED";
+		break;
+	case SCTP_ESTABLISHED:
+		return "ESTABLISHED";
+		break;
+	case SCTP_SHUTDOWN_SENT:
+		return "SHUTDOWN_SENT";
+		break;
+	case SCTP_SHUTDOWN_RECEIVED:
+		return "SHUTDOWN_RECEIVED";
+		break;
+	case SCTP_SHUTDOWN_ACK_SENT:
+		return "SHUTDOWN_ACK_SENT";
+		break;
+	case SCTP_SHUTDOWN_PENDING:
+		return "SHUTDOWN_PENDING";
+		break;
+	default:
+		return "UNKNOWN";
+		break;
+	}
+}
+
 static void
 displaysock(struct sock *s, int pos)
 {
@@ -975,13 +1022,22 @@ displaysock(struct sock *s, int pos)
 		default:
 			abort();
 		}
-		if (first && opt_s && s->proto == IPPROTO_TCP) {
+		if (first && opt_s &&
+		    (s->proto == IPPROTO_SCTP || s->proto == IPPROTO_TCP)) {
 			while (pos < 80)
 				pos += xprintf(" ");
-			if (s->state >= 0 && s->state < TCP_NSTATES)
-				pos += xprintf("%s", tcpstates[s->state]);
-			else
-				pos += xprintf("?");
+			switch (s->proto) {
+			case IPPROTO_SCTP:
+				pos += xprintf("%s", sctp_state(s->state));
+				break;
+			case IPPROTO_TCP:
+				if (s->state >= 0 && s->state < TCP_NSTATES)
+					pos +=
+					    xprintf("%s", tcpstates[s->state]);
+				else
+					pos += xprintf("?");
+				break;
+			}
 		}
 		if (laddr != NULL)
 			laddr = laddr->next;



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