svn commit: r323507 - head/usr.bin/sockstat

Michael Tuexen tuexen at FreeBSD.org
Tue Sep 12 21:36:14 UTC 2017


Author: tuexen
Date: Tue Sep 12 21:36:13 2017
New Revision: 323507
URL: https://svnweb.freebsd.org/changeset/base/323507

Log:
  Add support for printing the path state for SCTP association.

Modified:
  head/usr.bin/sockstat/sockstat.1
  head/usr.bin/sockstat/sockstat.c

Modified: head/usr.bin/sockstat/sockstat.1
==============================================================================
--- head/usr.bin/sockstat/sockstat.1	Tue Sep 12 21:12:04 2017	(r323506)
+++ head/usr.bin/sockstat/sockstat.1	Tue Sep 12 21:36:13 2017	(r323507)
@@ -153,8 +153,12 @@ The address the foreign end of the socket is bound to 
 The remote UDP encapsulation port number if
 .Fl U
 is specified (only for SCTP).
-.It Li STATE
-The protocol state if
+.It Li PATH STATE
+The path state if
+.Fl s
+is specified (only for SCTP).
+.It Li CONN STATE
+The connection state if
 .Fl s
 is specified (only for SCTP or TCP).
 .It Li STACK

Modified: head/usr.bin/sockstat/sockstat.c
==============================================================================
--- head/usr.bin/sockstat/sockstat.c	Tue Sep 12 21:12:04 2017	(r323506)
+++ head/usr.bin/sockstat/sockstat.c	Tue Sep 12 21:36:13 2017	(r323507)
@@ -97,6 +97,7 @@ static int	*ports;
 struct addr {
 	struct sockaddr_storage address;
 	unsigned int encaps_port;
+	int state;
 	struct addr *next;
 };
 
@@ -534,6 +535,7 @@ gather_sctp(void)
 					    xraddr->address.sa.sa_family);
 				}
 				faddr->encaps_port = xraddr->encaps_port; 
+				faddr->state = xraddr->state;
 				faddr->next = NULL;
 				if (prev_faddr == NULL)
 					sock->faddr = faddr;
@@ -939,7 +941,7 @@ check_ports(struct sock *s)
 }
 
 static const char *
-sctp_state(int state)
+sctp_conn_state(int state)
 {
 	switch (state) {
 	case SCTP_CLOSED:
@@ -978,6 +980,25 @@ sctp_state(int state)
 	}
 }
 
+static const char *
+sctp_path_state(int state)
+{
+	switch (state) {
+	case SCTP_UNCONFIRMED:
+		return "UNCONFIRMED";
+		break;
+	case SCTP_ACTIVE:
+		return "ACTIVE";
+		break;
+	case SCTP_INACTIVE:
+		return "INACTIVE";
+		break;
+	default:
+		return "UNKNOWN";
+		break;
+	}
+}
+
 static void
 displaysock(struct sock *s, int pos)
 {
@@ -1062,6 +1083,19 @@ displaysock(struct sock *s, int pos)
 			}
 			offset += 7;
 		}
+		if (opt_s) {
+			if (faddr != NULL &&
+			    s->proto == IPPROTO_SCTP &&
+			    s->state != SCTP_CLOSED &&
+			    s->state != SCTP_BOUND &&
+			    s->state != SCTP_LISTEN) {
+				while (pos < offset)
+					pos += xprintf(" ");
+				pos += xprintf("%s",
+				    sctp_path_state(faddr->state));
+			}
+			offset += 13;
+		}
 		if (first) {
 			if (opt_s) {
 				if (s->proto == IPPROTO_SCTP ||
@@ -1071,7 +1105,7 @@ displaysock(struct sock *s, int pos)
 					switch (s->proto) {
 					case IPPROTO_SCTP:
 						pos += xprintf("%s",
-						    sctp_state(s->state));
+						    sctp_conn_state(s->state));
 						break;
 					case IPPROTO_TCP:
 						if (s->state >= 0 &&
@@ -1118,8 +1152,10 @@ display(void)
 	    "LOCAL ADDRESS", "FOREIGN ADDRESS");
 	if (opt_U)
 		printf(" %-6s", "ENCAPS");
-	if (opt_s)
-		printf(" %-12s", "STATE");
+	if (opt_s) {
+		printf(" %-12s", "PATH STATE");
+		printf(" %-12s", "CONN STATE");
+	}
 	if (opt_S)
 		printf(" %.*s", TCP_FUNCTION_NAME_LEN_MAX, "STACK");
 	printf("\n");


More information about the svn-src-all mailing list