Skip to content

Commit

Permalink
11547 Want connstat(1M) command to display per-connection TCP statistics
Browse files Browse the repository at this point in the history
Portions contributed by: Cody Peter Mello <cody.mello@joyent.com>
Portions contributed by: Ahmed G <ahmedg@delphix.com>
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
  • Loading branch information
sebroy authored and richlowe committed Aug 19, 2019
1 parent c12492c commit a2f0435
Show file tree
Hide file tree
Showing 24 changed files with 2,022 additions and 145 deletions.
6 changes: 4 additions & 2 deletions usr/src/cmd/Makefile
Expand Up @@ -21,8 +21,8 @@

#
# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2019 Joyent, Inc.
# Copyright (c) 2012 by Delphix. All rights reserved.
# Copyright (c) 2019, Joyent, Inc.
# Copyright (c) 2012, 2015 by Delphix. All rights reserved.
# Copyright (c) 2013 DEY Storage Systems, Inc. All rights reserved.
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
# Copyright 2016 Toomas Soome <tsoome@me.com>
Expand Down Expand Up @@ -98,6 +98,7 @@ COMMON_SUBDIRS= \
cmd-inet \
col \
compress \
connstat \
consadm \
coreadm \
cpio \
Expand Down Expand Up @@ -547,6 +548,7 @@ MSGSUBDIRS= \
cmd-inet \
col \
compress \
connstat \
consadm \
coreadm \
cpio \
Expand Down
51 changes: 51 additions & 0 deletions usr/src/cmd/connstat/Makefile
@@ -0,0 +1,51 @@
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#
#
# Copyright (c) 2015 by Delphix. All rights reserved.
#

PROG= connstat
OBJS= connstat_main.o connstat_mib.o connstat_tcp.o
SRCS= $(OBJS:%.o=%.c)
POFILES= connstat_main.po connstat_tcp.po connstat_mib.po
POFILE= connstat.po

include ../Makefile.cmd
include ../Makefile.ctf

CSTD= $(CSTD_GNU99)
LDLIBS += -lsocket -lnsl -lumem -lofmt
XGETFLAGS += -a -x $(PROG).xcl

.KEEP_STATE:

all: $(PROG)

$(PROG): $(OBJS)
$(LINK.c) -o $@ $(OBJS) $(LDLIBS)
$(POST_PROCESS)

$(POFILE): $(POFILES)
$(RM) $@
cat $(POFILES) > $@

install: all $(ROOTPROG)

clean:
$(RM) $(OBJS)

lint: lint_SRCS

include ../Makefile.targ
79 changes: 79 additions & 0 deletions usr/src/cmd/connstat/connstat.h
@@ -0,0 +1,79 @@
/*
* CDDL HEADER START
*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2015, 2016 by Delphix. All rights reserved.
*/

#ifndef _CONNSTAT_H
#define _CONNSTAT_H

#include <sys/types.h>
#include <sys/socket.h>
#include <ofmt.h>
#include <sys/stropts.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct connstat_conn_attr_s {
struct sockaddr_storage ca_laddr;
struct sockaddr_storage ca_raddr;
int ca_lport;
int ca_rport;
int ca_state;
} connstat_conn_attr_t;

typedef struct conn_walk_state_s {
ofmt_handle_t cws_ofmt;
uint_t cws_flags;
connstat_conn_attr_t cws_filter;
} conn_walk_state_t;

/* cws_flags */
#define CS_LOOPBACK 0x0001 /* Include loopback connections */
#define CS_IPV4 0x0002 /* Show only IPv4 connections */
#define CS_IPV6 0x0004 /* Show only IPv6 connections */
#define CS_LADDR 0x0008 /* Filter by laddr in cws_filter */
#define CS_RADDR 0x0010 /* Filter by raddr in cws_filter */
#define CS_LPORT 0x0020 /* Filter by lport in cws_filter */
#define CS_RPORT 0x0040 /* Filter by rport in cws_filter */
#define CS_STATE 0x0080 /* Filter by state in cws_filter */
#define CS_PARSABLE 0x0100 /* Parsable output */

typedef ofmt_field_t *connstat_getfieldsfunc_t(void);
typedef void connstat_walkfunc_t(struct strbuf *, conn_walk_state_t *);

typedef struct connstat_proto_s {
char *csp_proto;
char *csp_default_fields;
int csp_miblevel;
int csp_mibv4name;
int csp_mibv6name;
connstat_getfieldsfunc_t *csp_getfields;
connstat_walkfunc_t *csp_v4walk;
connstat_walkfunc_t *csp_v6walk;
} connstat_proto_t;

boolean_t print_string(ofmt_arg_t *, char *, uint_t);
boolean_t print_uint16(ofmt_arg_t *, char *, uint_t);
boolean_t print_uint32(ofmt_arg_t *, char *, uint_t);
boolean_t print_uint64(ofmt_arg_t *, char *, uint_t);

#ifdef __cplusplus
}
#endif

#endif /* _CONNSTAT_H */
84 changes: 84 additions & 0 deletions usr/src/cmd/connstat/connstat.xcl
@@ -0,0 +1,84 @@
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#
#
# Copyright (c) 2015 by Delphix. All rights reserved.
#

msgid "count"
msgid "established"
msgid "filter"
msgid "help"
msgid "interval"
msgid "ipv4"
msgid "ipv6"
msgid "no-loopback"
msgid "output"
msgid "parsable"
msgid "protocol"
msgid "timestamp"
msgid "tcp"
msgid "laddr,lport,raddr,rport,inbytes,outbytes,"
"retransbytes,suna,swnd,cwnd,rwnd"
msgid " %s\n"
msgid ""
msgid "c:eF:hi:Lo:Pp:T:46"
msgid "all"
msgid "laddr"
msgid "raddr"
msgid "lport"
msgid "rport"
msgid "= "
msgid "%s%ld\n"
msgid "%s%s\n"
msgid "%hu"
msgid "%u"
msgid "%llu"
msgid "%s: "
msgid "LADDR"
msgid "RADDR"
msgid "LPORT"
msgid "RPORT"
msgid "INBYTES"
msgid "INSEGS"
msgid "INUNORDERBYTES"
msgid "INUNORDERSEGS"
msgid "OUTBYTES"
msgid "OUTSEGS"
msgid "RETRANSBYTES"
msgid "RETRANSSEGS"
msgid "SUNA"
msgid "count"
msgid "SWND"
msgid "CWND"
msgid "RWND"
msgid "STATE"
msgid "CLOSED"
msgid "IDLE"
msgid "BOUND"
msgid "LISTEN"
msgid "SYN_SENT"
msgid "SYN_RCVD"
msgid "ESTABLISHED"
msgid "CLOSE_WAIT"
msgid "FIN_WAIT_1"
msgid "CLOSING"
msgid "LAST_ACK"
msgid "FIN_WAIT_2"
msgid "TIME_WAIT"
msgid "UNKNOWN(%d)"
msgid "/dev/arp"
msgid "putmsg"
msgid "getmsg"
msgid "malloc"

0 comments on commit a2f0435

Please sign in to comment.