From owner-svn-src-all@freebsd.org Sun Jan 17 18:37:38 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5884DA8524B; Sun, 17 Jan 2016 18:37:38 +0000 (UTC) (envelope-from tuexen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 34C351372; Sun, 17 Jan 2016 18:37:38 +0000 (UTC) (envelope-from tuexen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0HIbbPA023630; Sun, 17 Jan 2016 18:37:37 GMT (envelope-from tuexen@FreeBSD.org) Received: (from tuexen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0HIbbAD023628; Sun, 17 Jan 2016 18:37:37 GMT (envelope-from tuexen@FreeBSD.org) Message-Id: <201601171837.u0HIbbAD023628@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tuexen set sender to tuexen@FreeBSD.org using -f From: Michael Tuexen Date: Sun, 17 Jan 2016 18:37:37 +0000 (UTC) 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 X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jan 2016 18:37:38 -0000 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;