History log of /freebsd-head/usr.bin/systat/netstat.c
Revision Date Author Comments
872b698bd4a1bfc0bf008c09228e6fd238809c75 20-Nov-2017 pfg <pfg@FreeBSD.org> General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
7168fac38845f2e3dded297a95af76ede2fc01f2 02-Oct-2017 glebius <glebius@FreeBSD.org> Hide struct socket and struct unpcb from the userland.

Violators may define _WANT_SOCKET and _WANT_UNPCB respectively and
are not guaranteed for stability of the structures. The violators
list is the the usual one: libprocstat(3) and netstat(1) internally
and lsof in ports.

In struct xunpcb remove the inclusion of kernel structure and add
a bunch of spare fields. The xsocket already has socket not included,
but add there spares as well. Embed xsockbuf into xsocket.

Sort declarations in sys/socketvar.h to separate kernel only from
userland available ones.

PR: 221820 (exp-run)
3a5c9aaf2b2ea107bcaf0ba28b706238d92bdbbd 21-Mar-2017 glebius <glebius@FreeBSD.org> Hide struct inpcb, struct tcpcb from the userland.

This is a painful change, but it is needed. On the one hand, we avoid
modifying them, and this slows down some ideas, on the other hand we still
eventually modify them and tools like netstat(1) never work on next version of
FreeBSD. We maintain a ton of spares in them, and we already got some ifdef
hell at the end of tcpcb.

Details:
- Hide struct inpcb, struct tcpcb under _KERNEL || _WANT_FOO.
- Make struct xinpcb, struct xtcpcb pure API structures, not including
kernel structures inpcb and tcpcb inside. Export into these structures
the fields from inpcb and tcpcb that are known to be used, and put there
a ton of spare space.
- Make kernel and userland utilities compilable after these changes.
- Bump __FreeBSD_version.

Reviewed by: rrs, gnn
Differential Revision: D10018
7e6cabd06e6caa6a02eeb86308dc0cb3f27e10da 28-Feb-2017 imp <imp@FreeBSD.org> Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96
00d578928eca75be320b36d37543a7e2a4f9fbdb 27-May-2016 grehan <grehan@FreeBSD.org> Create branch for bhyve graphics import.
b9140f06e39542ce964c5ebdceb847b4bf624130 20-Apr-2016 araujo <araujo@FreeBSD.org> Use NULL instead of 0 for pointers.

gethostbyname(3) will return NULL for error status.

MFC after: 2 weeks.
9487eaf98f45a433931bad91a3463694f5423688 27-Jan-2016 glebius <glebius@FreeBSD.org> Augment struct tcpstat with tcps_states[], which is used for book-keeping
the amount of TCP connections by state. Provides a cheap way to get
connection count without traversing the whole pcb list.

Sponsored by: Netflix
d812607618045f7758140f41939c1413679196e9 24-Sep-2015 delphij <delphij@FreeBSD.org> MFC r287633:

- Avoid accessing window properties directly, instead, use accessors.
This should be no-op for now, but allows the code to work if we
move to NCURSES_OPAQUE.
- Use calloc() instead of malloc+bzero.
c4ba6d848bb9ccb12d15f4e4aebc9fcf5c0aca86 10-Sep-2015 delphij <delphij@FreeBSD.org> - Avoid accessing window properties directly, instead, use accessors.
This should be no-op for now, but allows the code to work if we
move to NCURSES_OPAQUE.
- Use calloc() instead of malloc+bzero.

MFC after: 2 weeks
78c1f8fbf46602fa3a316af9a8cb3221b76a24b2 01-Dec-2014 dim <dim@FreeBSD.org> Merge ^/head r275262 through r275363.
25da94eb3ed654f7181ce453c6c5cc7e77d38133 30-Nov-2014 glebius <glebius@FreeBSD.org> Merge from projects/sendfile:

o Introduce a notion of "not ready" mbufs in socket buffers. These
mbufs are now being populated by some I/O in background and are
referenced outside. This forces following implications:
- An mbuf which is "not ready" can't be taken out of the buffer.
- An mbuf that is behind a "not ready" in the queue neither.
- If sockbet buffer is flushed, then "not ready" mbufs shouln't be
freed.

o In struct sockbuf the sb_cc field is split into sb_ccc and sb_acc.
The sb_ccc stands for ""claimed character count", or "committed
character count". And the sb_acc is "available character count".
Consumers of socket buffer API shouldn't already access them directly,
but use sbused() and sbavail() respectively.
o Not ready mbufs are marked with M_NOTREADY, and ready but blocked ones
with M_BLOCKED.
o New field sb_fnrdy points to the first not ready mbuf, to avoid linear
search.
o New function sbready() is provided to activate certain amount of mbufs
in a socket buffer.

A special note on SCTP:
SCTP has its own sockbufs. Unfortunately, FreeBSD stack doesn't yet
allow protocol specific sockbufs. Thus, SCTP does some hacks to make
itself compatible with FreeBSD: it manages sockbufs on its own, but keeps
sb_cc updated to inform the stack of amount of data in them. The new
notion of "not ready" data isn't supported by SCTP. Instead, only a
mechanical substitute is done: s/sb_cc/sb_ccc/.
A proper solution would be to take away struct sockbuf from struct
socket and allow protocols to implement their own socket buffers, like
SCTP already does. This was discussed with rrs@.

Sponsored by: Netflix
Sponsored by: Nginx, Inc.
eb1a5f8de9f7ea602c373a710f531abbf81141c4 21-Feb-2014 gjb <gjb@FreeBSD.org> Move ^/user/gjb/hacking/release-embedded up one directory, and remove
^/user/gjb/hacking since this is likely to be merged to head/ soon.

Sponsored by: The FreeBSD Foundation
6b01bbf146ab195243a8e7d43bb11f8835c76af8 27-Dec-2013 gjb <gjb@FreeBSD.org> Copy head@r259933 -> user/gjb/hacking/release-embedded for initial
inclusion of (at least) arm builds with the release.

Sponsored by: The FreeBSD Foundation
6b68275a843448f1b144d4384f8e43f7304224e6 05-Feb-2012 ed <ed@FreeBSD.org> Whitespace fixes.

- Remove redundant empty lines.
- Replace ^L by \014. This allows you to safely cat/grep/etc this file
without causing confusion.
e7e5b53bf16ab3b35646f0580b36fa7d7afa9678 03-Jan-2012 ed <ed@FreeBSD.org> Replace index() and rindex() calls with strchr() and strrchr().

The index() and rindex() functions were marked LEGACY in the 2001
revision of POSIX and were subsequently removed from the 2008 revision.
The strchr() and strrchr() functions are part of the C standard.

This makes the source code a lot more consistent, as most of these C
files also call into other str*() routines. In fact, about a dozen
already perform strchr() calls.
2f1e586900d3dd1525085e659a5098430694a597 15-Oct-2011 ed <ed@FreeBSD.org> Fix whitespace inconsistencies in systat(1).

According to md5(1), the resulting binary is the same.
9304e224e74af981127c0d8c72015e36a2c06743 24-Jun-2011 kevlo <kevlo@FreeBSD.org> Remove duplicated header files
29af67e52c02dc751039a3117bc88ae6192e891e 11-Dec-2010 joel <joel@FreeBSD.org> Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson
09f9c897d33c41618ada06fbbcf1a9b3812dee53 19-Oct-2010 jamie <jamie@FreeBSD.org> A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.
f1216d1f0ade038907195fc114b7e630623b402c 19-Mar-2010 delphij <delphij@FreeBSD.org> Create a custom branch where I will be able to do the merge.
0842b7d53ffede64468e775f5c79965e3d9e48ae 13-Dec-2009 delphij <delphij@FreeBSD.org> Revert most part of 200420 as requested, as more review and polish is
needed.
b963db4652a0bf1718825e8e1a9bc93e87b7a80f 11-Dec-2009 delphij <delphij@FreeBSD.org> Remove unneeded header includes from usr.bin/ except contributed code.

Tested with: make universe
038bfe209eeb1f951b217069a584edbcc92d0f2c 15-Mar-2009 rwatson <rwatson@FreeBSD.org> Correct a number of evolved problems with inp_vflag and inp_flags:
certain flags that should have been in inp_flags ended up in inp_vflag,
meaning that they were inconsistently locked, and in one case,
interpreted. Move the following flags from inp_vflag to gaps in the
inp_flags space (and clean up the inp_flags constants to make gaps
more obvious to future takers):

INP_TIMEWAIT
INP_SOCKREF
INP_ONESBCAST
INP_DROPPED

Some aspects of this change have no effect on kernel ABI at all, as these
are UDP/TCP/IP-internal uses; however, netstat and sockstat detect
INP_TIMEWAIT when listing TCP sockets, so any MFC will need to take this
into account.

MFC after: 1 week (or after dependencies are MFC'd)
Reviewed by: bz
19b6af98ec71398e77874582eb84ec5310c7156f 22-Nov-2008 dfr <dfr@FreeBSD.org> Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
performance in Xen's HVM mode.
cf5320822f93810742e3d4a1ac8202db8482e633 19-Oct-2008 lulf <lulf@FreeBSD.org> - Import the HEAD csup code which is the basis for the cvsmode work.
8f8cb7cbeccab35f93144e4796554b23c37ca424 16-Jan-2008 delphij <delphij@FreeBSD.org> ANSIfy and remove register.

Resulting binary verified with strip(1)+md5(1).
35fe3338af3d4b54cc684b378bf8fca7a2cbce64 05-Jan-2007 yar <yar@FreeBSD.org> MFC all the recent fixes to systat(1). As a pleasant
side-effect, this reduces its difference against HEAD
almost to zero.

Idea by: bde
OK by: re
0ceaba73fc1ee61fbde03d631b1ed00d2fdb89ba 27-Nov-2006 yar <yar@FreeBSD.org> The logic of fetchnetstat_sysctl() isn't too complex: if idx is 0,
we set and use xtp; if idx is 1, we set and use xip; the other cases
are impossible. However, GCC cannot see that xip and xtp are always
initialized before use because they are initialized and used in
different if/else blocks. So setting them to NULL at the very
beginning won't hurt.
cf3ea4f2b87ee8ddcfb809cf0423d7619a9dd024 27-Nov-2006 yar <yar@FreeBSD.org> + WARNS=4 reminds that nlist.n_name isn't const.
+ Use C99 initializers to be WARNS-clean.
+ The last element in a namelist should have its n_name set to NULL,
not to an empty string.
23e0bb44c9a5172503c12bb894ead65e32b5ac6f 27-Nov-2006 yar <yar@FreeBSD.org> Don't discard a const qualifier from constant strings.
c4e64014b7b707ed9a96ba6b0d4afac890bf9d5f 30-Apr-2006 bde <bde@FreeBSD.org> Remove trailing whitespace.

Submitted by: Se=E1n Farley <sean-freebsd at farley dot org>
PR: bin/81874
1a769818fed8aac0f389ffe0e1c8b90b88451e87 30-Apr-2006 bde <bde@FreeBSD.org> Show the load average in the tcp display (it was already shown, perhaps
not very usefully, in all other displays). This was the original point
of the PR.

Move the load average up by 2 so that it starts in row 0 for all windows
(2 lines above it were wasted for all other windows except vmstat).
Move everything below it up by 2 or 3 (3 for icmp and icmp6 which had
an extra blank line due from not compensating for the foot-shooting in
note (3); only ip and ip6 compensated). Reduce the magic numbers related
to this.

Notes by the submitter:
%%%
1. All the subwin() calls are identical using #define MAINWIN_ROW 3
(systat.h).
2. The load average is at the top of the window.
3. Each display starts on the fourth line. I made changes to those
displays that shifted the start line (i.e., icmp). This entailed a
lot of changes within the comments at the top of those displays.
4. For ip6, I shifted the "Input next-header histogram" column down one
row to separate it from "IPv6 Output". I raised "bad scope packets"
and "address selection failed" up one row to stay with "IPv6 Input"
(valid?). They were down one row to probably line up at the bottom,
but I think they should stick with their fellow items in a column.
5. I condensed ifstat a bit. It had a lot of empty rows.
%%%

Submitted by: Se=E1n Farley <sean-freebsd at farley dot org>
PR: bin/81874
ead15b3b3f4bb2afabb64c928522d1b0ca0e2966 19-Feb-2005 ume <ume@FreeBSD.org> simply ignore unknown address family.

MFC after: 1 week
ba650c0652625385cd7663670825460deb6e7088 19-Feb-2005 ume <ume@FreeBSD.org> teach IPv6 to `systat -netstat'.

Tested by: kuriyama
MFC after: 1 week
d4e4b731a60d06676a0749fde2558c1b9e00baec 24-Dec-2003 silby <silby@FreeBSD.org> Make systat -net aware of compressed time_wait sockets.
9902e77aa2063d0a89ede6590b1e001a99e765d7 01-Aug-2003 dwmalone <dwmalone@FreeBSD.org> Add ip6 and icmp6 displays to systat.

MFC after: 2 weeks
86b3836232069126cbad3fccd52778f5adc4a676 24-Jul-2002 jdp <jdp@FreeBSD.org> Widen struct sockbuf's sb_timeo member to int from short. With
non-default but reasonable values of hz this member overflowed,
breaking NFS over UDP.

Also, as long as I'm plowing up struct sockbuf ... Change certain
members from u_long/long to u_int/int in order to reduce wasted
space on 64-bit machines. This change was requested by Andrew
Gallatin.

Netstat and systat need to be rebuilt. I am incrementing
__FreeBSD_version in case any ports need to change.
0b20191705a346bc322deac818912bd4eab96a1b 22-Mar-2002 imp <imp@FreeBSD.org> remove __P
fa1f2b928010b69e6b1c78b220d8285e3145eeeb 12-Dec-2001 markm <markm@FreeBSD.org> WARNS=2 fixes with NO_WERROR set, as there are some header issues
with namelists. use __FBSDID().
d6fecac748fdca2de8bbfd045bceab19277abab1 23-Mar-2001 tmm <tmm@FreeBSD.org> Get rid of setgid kmem for systat, and while being there, fix some bugs
and compiler warnings.
The data for network statistics are still obtained via the kvm interface
if systat was started with the needed privileges, otherwise sysctls are
used. The reason for this is that with really many open sockets, the
sysctl method is probably slower, but it systat -netstat is probably not
really usable in either mode under these conditions.

Approved by: rwatson
f2049d4440aeb04c6d2abff0d6e9760ea9da4699 30-Dec-2000 phk <phk@FreeBSD.org> My bad, committed the submitted patch rather than the fixed patch.
4cc97bc78a4b54701485e6d8ce445ad01c69e5b1 30-Dec-2000 phk <phk@FreeBSD.org> Use macro API to <sys/queue.h>

Submitted by: "Jason" <jsmethers@pdq.net>
Reviewed by: phk
b42951578188c5aab5c9f8cbcde4a743f8092cdc 02-Apr-2000 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'ALSA'.
ce5c0946e0a212c993ee42f6c191e939621e713b 30-Aug-1999 peter <peter@FreeBSD.org> systat is way too comfortable with curses internals...
3b842d34e82312a8004a7ecd65ccdb837ef72ac1 28-Aug-1999 peter <peter@FreeBSD.org> $Id$ -> $FreeBSD$
59bd962db0b15e40e537519e0bbb41148341bf44 08-Oct-1998 obrien <obrien@FreeBSD.org> Quiet many compiler warnings.
fdde6212a237c4acaa251ba634d6e37ee6b16610 12-Jun-1998 peter <peter@FreeBSD.org> #include <arpa/inet.h>
a51cfac66561e49404427c1f83558e065a044bd9 09-Jun-1998 imp <imp@FreeBSD.org> o Use snprintf rather than sprintf
o Add more checks for buffer overflows
o Use snprintf rather than strcat/cpy and have better checks for max
length exceeded.

Most of these changes are not exploitable buffer overruns, but it never
hurts to be safe.

Inspired by and obtained from: OpenBSD
0506343883d62f6649f7bbaf1a436133cef6261d 11-Jan-1998 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'jb'.
7c6e96080c4fb49bf912942804477d202a53396c 10-Jan-1998 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'JB'.
f390c26dd9214a3602049fa55835b2d367ef60df 22-Feb-1997 peter <peter@FreeBSD.org> Revert $FreeBSD$ to $Id$
808a36ef658c1810327b5d329469bcf5dad24b28 14-Jan-1997 jkh <jkh@FreeBSD.org> Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.
ccfee521f5122303db041e7b4d3157e6a6e08ee8 02-Nov-1996 phk <phk@FreeBSD.org> bin/1942 curses problem in systat
truncate if too long for field.
2.2 candidate.
928320c3b6a55543a046b8f813902a148613b129 28-Oct-1996 wollman <wollman@FreeBSD.org> Eliminate unnecessary include of <sys/mbuf.h>.
42390683e5de322e34b244ea03ffa0e6e1b0cb0f 11-Mar-1996 dg <dg@FreeBSD.org> Move #include of queue.h before #include of socketvar.h in preparation for
struct socket changes.
86f1bc4514fdcfd255f37f3218fe234bdc3664fc 05-Nov-1995 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'LINUX'.
a14d555c873398b14776ca4f2c33f9c69617afb9 30-May-1995 rgrimes <rgrimes@FreeBSD.org> Remove trailing whitespace.
87a5fb27fc6e651b8abafa30796d5b84e4ce2e72 09-Apr-1995 dg <dg@FreeBSD.org> Updated for 4.4BSD queue macros. (Oops, I forgot to commit this last night;
sorry Jordan).
2e14d9ebc3d3592c67bdf625af9ebe0dfc386653 14-Mar-1995 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'MATT_THOMAS'.
34cd81d75f398ee455e61969b118639dacbfd7a6 23-Sep-1994 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'MACKERRAS'.
e16baf7a5fe7ac1453381d0017ed1dcdeefbc995 07-Aug-1994 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'SUNRPC'.
f9ab90d9d6d02989a075d0f0074496d5b1045e4b 27-May-1994 rgrimes <rgrimes@FreeBSD.org> BSD 4.4 Lite Usr.bin Sources