History log of /freebsd-head/usr.bin/netstat/inet.c
Revision Date Author Comments
9b9f9167f52b0a4d8955354a94f1fb33ae519157 07-Mar-2020 hrs <hrs@FreeBSD.org> Fix an issue of net.inet.igmp.stats handler.
The header of (struct igmpstat) could be cleared by sysctl(3).
This can be reproduced by "netstat -s -z -p igmp".

PR: 244584
MFC after: 1 week
497c158d879d8c2e80e5ad9c248432dad96433c6 12-Nov-2019 bz <bz@FreeBSD.org> netstat: igmp stats, error on unexpected information, not only warn

The igmp stats tend to print two lines of warning for an unexpected
version and length. Despite an invalid version and struct size it
continues to try to do something with the data. Do not try to parse
the remainder of the struct and error on warning.

Note the underlying issue of the data not being available properly
is still there and needs to be fixed seperately.

Reported by: test cases, lwhsu
MFC after: 3 weeks
ff799ad3113722e62202923911715594798a429a 03-Oct-2019 jhb <jhb@FreeBSD.org> Restore description of packets dropped due to full reassembly queue.

r265408 renamed tcps_rcvmemdrop to tcps_rcvreassfull and gave it a more
specific description. r279122 (libxo-ification) reverted that change.
This commit brings it back, but with a small tweak to the description.

MFC after: 2 weeks
886b55fe42b1fd37bf2102d5f3bd94419e1a45d4 09-Mar-2019 bz <bz@FreeBSD.org> Improve ARP logging.

r344504 added an extra ARP_LOG() call in case of an if_output() failure.
It turns out IPv4 can be noisy. In order to not spam the console by default:
(a) add a counter for these events so people can keep better track of how
often it happens, and
(b) add a sysctl to select the default ARP_LOG log level and set it to
INFO avoiding the one (the new) DEBUG level by default.

Claim a spare (1st one after 10 years since the stats were added) in order
to not break netstat from FreeBSD 12->13 updates in the future.

Reviewed by: karels
Differential Revision: https://reviews.freebsd.org/D19490
ba9633beef89036849f5994f67d1fa40e482b89c 03-Mar-2019 bz <bz@FreeBSD.org> Fix compilation of world with WITHOUT_{INET,INET6}_SUPPORT or both set.

Buildworld failed when both WITHOUT_INET6_SUPPORT and INET equivalent were set.
Fix netstat and syslogd by applying appropriate #ifdef INET/INET6 to make world
compile again.

Reviewed by: ngie, hrs, ume
Welcomed by: Michael Dexter (D17040)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D19418
39f527e7eedb9cb4fb142f42f239c78ab536c970 10-Jul-2018 brooks <brooks@FreeBSD.org> Use uintptr_t alone when assigning to kvaddr_t variables.

Suggested by: jhb
e2ea71f5bbc27582a2cdd1414a526e9988de23bc 05-Jul-2018 brooks <brooks@FreeBSD.org> Work around lame warnings in ancient gcc on 32-bit platforms.

Fixes r335979.
6615ed4c6149c9810ba766e318f591d44a0596df 05-Jul-2018 brooks <brooks@FreeBSD.org> Make struct xinpcb and friends word-size independent.

Replace size_t members with ksize_t (uint64_t) and pointer members
(never used as pointers in userspace, but instead as unique
idenitifiers) with kvaddr_t (uint64_t). This makes the structs
identical between 32-bit and 64-bit ABIs.

On 64-bit bit systems, the ABI is maintained. On 32-bit systems,
this is an ABI breaking change. The ABI of most of these structs
was previously broken in r315662. This also imposes a small API
change on userspace consumers who must handle kernel pointers
becoming virtual addresses.

PR: 228301 (exp-run by antoine)
Reviewed by: jtl, kib, rwatson (various versions)
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D15386
a93bdf696399217f88b8cebf0d5961053e1c4acd 22-Mar-2018 jtl <jtl@FreeBSD.org> Add the "TCP Blackbox Recorder" which we discussed at the developer
summits at BSDCan and BSDCam in 2017.

The TCP Blackbox Recorder allows you to capture events on a TCP connection
in a ring buffer. It stores metadata with the event. It optionally stores
the TCP header associated with an event (if the event is associated with a
packet) and also optionally stores information on the sockets.

It supports setting a log ID on a TCP connection and using this to correlate
multiple connections that share a common log ID.

You can log connections in different modes. If you are doing a coordinated
test with a particular connection, you may tell the system to put it in
mode 4 (continuous dump). Or, if you just want to monitor for errors, you
can put it in mode 1 (ring buffer) and dump all the ring buffers associated
with the connection ID when we receive an error signal for that connection
ID. You can set a default mode that will be applied to a particular ratio
of incoming connections. You can also manually set a mode using a socket
option.

This commit includes only basic probes. rrs@ has added quite an abundance
of probes in his TCP development work. He plans to commit those soon.

There are user-space programs which we plan to commit as ports. These read
the data from the log device and output pcapng files, and then let you
analyze the data (and metadata) in the pcapng files.

Reviewed by: gnn (previous version)
Obtained from: Netflix, Inc.
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D11085
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)
d0208bfad08d9ebc898e1eafe8c2c4d4fc3cb32f 25-Aug-2017 sbruno <sbruno@FreeBSD.org> Use counter(9) for PLPMTUD counters.

Remove unused PLPMTUD sysctl counters.

Bump UPDATING and FreeBSD Version to indicate a rebuild is required.

Submitted by: kevin.bowling@kev009.com
Reviewed by: jtl
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D12003
e35d543ec17b735ba76bb3311ed4a430d6cc945e 08-Jun-2017 glebius <glebius@FreeBSD.org> Listening sockets improvements.

o Separate fields of struct socket that belong to listening from
fields that belong to normal dataflow, and unionize them. This
shrinks the structure a bit.
- Take out selinfo's from the socket buffers into the socket. The
first reason is to support braindamaged scenario when a socket is
added to kevent(2) and then listen(2) is cast on it. The second
reason is that there is future plan to make socket buffers pluggable,
so that for a dataflow socket a socket buffer can be changed, and
in this case we also want to keep same selinfos through the lifetime
of a socket.
- Remove struct struct so_accf. Since now listening stuff no longer
affects struct socket size, just move its fields into listening part
of the union.
- Provide sol_upcall field and enforce that so_upcall_set() may be called
only on a dataflow socket, which has buffers, and for listening sockets
provide solisten_upcall_set().

o Remove ACCEPT_LOCK() global.
- Add a mutex to socket, to be used instead of socket buffer lock to lock
fields of struct socket that don't belong to a socket buffer.
- Allow to acquire two socket locks, but the first one must belong to a
listening socket.
- Make soref()/sorele() to use atomic(9). This allows in some situations
to do soref() without owning socket lock. There is place for improvement
here, it is possible to make sorele() also to lock optionally.
- Most protocols aren't touched by this change, except UNIX local sockets.
See below for more information.

o Reduce copy-and-paste in kernel modules that accept connections from
listening sockets: provide function solisten_dequeue(), and use it in
the following modules: ctl(4), iscsi(4), ng_btsocket(4), ng_ksocket(4),
infiniband, rpc.

o UNIX local sockets.
- Removal of ACCEPT_LOCK() global uncovered several races in the UNIX
local sockets. Most races exist around spawning a new socket, when we
are connecting to a local listening socket. To cover them, we need to
hold locks on both PCBs when spawning a third one. This means holding
them across sonewconn(). This creates a LOR between pcb locks and
unp_list_lock.
- To fix the new LOR, abandon the global unp_list_lock in favor of global
unp_link_lock. Indeed, separating these two locks didn't provide us any
extra parralelism in the UNIX sockets.
- Now call into uipc_attach() may happen with unp_link_lock hold if, we
are accepting, or without unp_link_lock in case if we are just creating
a socket.
- Another problem in UNIX sockets is that uipc_close() basicly did nothing
for a listening socket. The vnode remained opened for connections. This
is fixed by removing vnode in uipc_close(). Maybe the right way would be
to do it for all sockets (not only listening), simply move the vnode
teardown from uipc_detach() to uipc_close()?

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D9770
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
22a79f89d46c27589ffe9e7addb6cc9cd03072b3 10-Mar-2017 glebius <glebius@FreeBSD.org> Typo.
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
0fb6ad528e5c3b098a7410f8f804d39fcd21ee10 06-Feb-2017 ae <ae@FreeBSD.org> Merge projects/ipsec into head/.

Small summary
-------------

o Almost all IPsec releated code was moved into sys/netipsec.
o New kernel modules added: ipsec.ko and tcpmd5.ko. New kernel
option IPSEC_SUPPORT added. It enables support for loading
and unloading of ipsec.ko and tcpmd5.ko kernel modules.
o IPSEC_NAT_T option was removed. Now NAT-T support is enabled by
default. The UDP_ENCAP_ESPINUDP_NON_IKE encapsulation type
support was removed. Added TCP/UDP checksum handling for
inbound packets that were decapsulated by transport mode SAs.
setkey(8) modified to show run-time NAT-T configuration of SA.
o New network pseudo interface if_ipsec(4) added. For now it is
build as part of ipsec.ko module (or with IPSEC kernel).
It implements IPsec virtual tunnels to create route-based VPNs.
o The network stack now invokes IPsec functions using special
methods. The only one header file <netipsec/ipsec_support.h>
should be included to declare all the needed things to work
with IPsec.
o All IPsec protocols handlers (ESP/AH/IPCOMP protosw) were removed.
Now these protocols are handled directly via IPsec methods.
o TCP_SIGNATURE support was reworked to be more close to RFC.
o PF_KEY SADB was reworked:
- now all security associations stored in the single SPI namespace,
and all SAs MUST have unique SPI.
- several hash tables added to speed up lookups in SADB.
- SADB now uses rmlock to protect access, and concurrent threads
can do SA lookups in the same time.
- many PF_KEY message handlers were reworked to reflect changes
in SADB.
- SADB_UPDATE message was extended to support new PF_KEY headers:
SADB_X_EXT_NEW_ADDRESS_SRC and SADB_X_EXT_NEW_ADDRESS_DST. They
can be used by IKE daemon to change SA addresses.
o ipsecrequest and secpolicy structures were cardinally changed to
avoid locking protection for ipsecrequest. Now we support
only limited number (4) of bundled SAs, but they are supported
for both INET and INET6.
o INPCB security policy cache was introduced. Each PCB now caches
used security policies to avoid SP lookup for each packet.
o For inbound security policies added the mode, when the kernel does
check for full history of applied IPsec transforms.
o References counting rules for security policies and security
associations were changed. The proper SA locking added into xform
code.
o xform code was also changed. Now it is possible to unregister xforms.
tdb_xxx structures were changed and renamed to reflect changes in
SADB/SPDB, and changed rules for locking and refcounting.

Reviewed by: gnn, wblock
Obtained from: Yandex LLC
Relnotes: yes
Sponsored by: Yandex LLC
Differential Revision: https://reviews.freebsd.org/D9352
1b12c4f0adbb7641116ff77a2a7eb4fb00abf1bc 05-Jan-2017 delphij <delphij@FreeBSD.org> Use strlcpy and snprintf in netstat(1).

Expand inet6name() line buffer to NI_MAXHOST and use strlcpy/snprintf
in various places.

Reported by: Anton Yuzhaninov <citrin citrin ru>
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D8916
b35cc2e296d823aaf3fea884607fccc6ad929083 28-Dec-2016 araujo <araujo@FreeBSD.org> Print hostcache usage counts with TCP statistics.

PR: 196252
Submitted by: Anton Yuzhaninov <citrin+pr@citrin.ru>
MFC after: 3 weeks.
7df95e052cf5fca0ccc995e0e0481eb88a3ee5e4 15-Jul-2016 tuexen <tuexen@FreeBSD.org> When calling netstat -Laptcp the local address values are not aligned
with the corresponding entry in the table header.
r295136 increased the value width from 14 to 32 without the corresponding
change to the table header. This commit adds the change to the table
header width.

MFC after: 3 days
00d578928eca75be320b36d37543a7e2a4f9fbdb 27-May-2016 grehan <grehan@FreeBSD.org> Create branch for bhyve graphics import.
d2d25bb0ca583e8268be8a67a3b38491a95bdb46 18-Apr-2016 araujo <araujo@FreeBSD.org> Use NULL instead of 0 for pointers.

Also malloc will return NULL if it cannot allocate memory.

MFC after: 2 weeks.
c39b2fd5d1f987bd7aa2e9893a928d17dbafecd4 15-Mar-2016 glebius <glebius@FreeBSD.org> Print running TCP connection counts with TCP statistics.
b04e8a547e7e868f83d0fab68feb768770323303 02-Feb-2016 alfred <alfred@FreeBSD.org> Increase max allowed backlog for listen sockets
from short to int.

PR: 203922
Submitted by: White Knight <white_knight@2ch.net>
MFC After: 4 weeks
e491a7871f29b017f7fe0432fc303bd6ff5dd6e0 10-Jan-2016 ngie <ngie@FreeBSD.org> Unbreak stable/10 buildworlds on arm/arm, mips/mips, mips/mips64, mips/mipsel,
mips/mipsn32, powerpc/powerpc, powerpc/powerpc64, sparc64/sparc64 with gcc
after r293307 (some of the BURN_BRIDGES code)

MFC after: 3 days
Pointyhat to: markj
Sponsored by: EMC / Isilon Storage Division

MFC r279017:

r279017 (by glebius):

Burn bridges to FreeBSD 7.x IGMP stats.
513e9b690f5bb0abdec4b77b4ab0de8385608740 07-Jan-2016 markj <markj@FreeBSD.org> MFC r287649:
Use a common subroutine to fetch and zero protocol stats instead of
duplicating roughly similar code for each protocol.
97e188cb583ae63776b78147ccf97ff168432ff3 25-Nov-2015 ume <ume@FreeBSD.org> Fix udp entry of `netstat -TW'.
745eb99f16975feb3b889e9cbd120749a5edfc2e 24-Nov-2015 ume <ume@FreeBSD.org> Correct alignment of the addresses in the `netstat -aW' output.
65d9a559eb7b19c7541531c4e8891e6d45b00ff2 11-Sep-2015 markj <markj@FreeBSD.org> Use a common subroutine to fetch and zero protocol stats instead of
duplicating roughly similar code for each protocol.

MFC after: 2 weeks
df2a89db2bc25e73b139f02c6fbe0095a4168253 01-Sep-2015 hrs <hrs@FreeBSD.org> - Add -W flag support for network column in intpr() (-i flag) and
routepr() (-r flag). It is too narrow to show an IPv6 prefix
in most cases.

- Accept "local" as a synonym of "unix" in protocol family name.

- Show a prefix length in CIDR notation when name resolution failed in
netname().

- Make routename() and netname() AF-independent and remove
unnecessary typecasting from struct sockaddr.

- Use getnameinfo(3) to format L2 addr in intpr().

- Fix a bug which showed "Address" when -A flag is specfied in pr_rthdr().

- Replace cryptic GETSA() macro with SA_SIZE().

- Fix declarations shadowing local variables with the same names.

- Add more static, remove unused header files and variables.

MFC after: 1 week
39fb34452ff3bc4927f319c53cfad417efb4e883 06-Apr-2015 hiren <hiren@FreeBSD.org> MFC r266418, r266448

Add the flowtype to the inpcb.
Add -R to netstat to dump RSS/flow information.

Reviewed by: delphij
Relnotes: yes (for r266448)
Sponsored by: Limelight Networks
0ea1b83e3703e39c50804c558e396324cec66c74 21-Feb-2015 marcel <marcel@FreeBSD.org> Convert netstat to use libxo.

Obtained from: Phil Shafer <phil@juniper.net>
Ported to -current by: alfred@ (mostly), Kim Shrier
Formatting: marcel@
Sponsored by: Juniper Networks, Inc.
bfb8a573120c248d08d110e0844f163a066bd5d7 19-Feb-2015 glebius <glebius@FreeBSD.org> Burn bridges to FreeBSD 7.x IGMP stats.
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.
4e0609eb851ad23d1af64d386fcb0f7728793c29 16-Aug-2014 bz <bz@FreeBSD.org> MFC r261525:

Print the MD5 signature information introduced in r221023 (head) in the
TCP statistics output.
a2ba9f176ff963b871323eae90c27c214cbb165c 19-May-2014 adrian <adrian@FreeBSD.org> Add -R to netstat to dump RSS/flow information.

This is intended to help in diagnostics and debugging of NIC and stack
flowid support.

Eventually this will grow another column (RSS CPU ID) but
that currently isn't cached in the inpcb.

There's also no clean flowtype -> flowtype identifier string. This is
the mbuf M_HASHTYPE_* values for RSS.

Here's some example output:

adrian@adrian-hackbox:~/work/freebsd/head/src % netstat -Rn | more
Active Internet connections
Proto Recv-Q Send-Q Local Address Foreign Address flowid ftype
tcp4 0 0 10.11.1.65.22 10.11.1.64.12409 29041942 2
udp4 0 0 127.0.0.1.123 *.* 00000000 0
udp6 0 0 fe80::1%lo0.123 *.* 00000000 0
udp6 0 0 ::1.123 *.* 00000000 0
udp4 0 0 10.11.1.65.123 *.* 00000000 0

Tested:

* amd64 system w/ igb NIC; local driver changes to expose RSS flowid in if_igb.
68ca190323e7bcd6d570e89b1cfd93450a605c07 06-May-2014 glebius <glebius@FreeBSD.org> - Remove net.inet.tcp.reass.overflows sysctl. It counts exactly
same events that tcpstat's tcps_rcvmemdrop counter counts.
- Rename tcps_rcvmemdrop to tcps_rcvreassfull and improve its
description in netstat(1) output.

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
ba8b0edcbe6eb8251145314eaab374a2904646cd 05-Feb-2014 bz <bz@FreeBSD.org> Print the MD5 signature information introduced in r221023 in the
TCP statistics output.

MFC after: 3 weeks
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
430162610d43c9304f918e90063b5da86a8a5ad1 09-Jul-2013 ae <ae@FreeBSD.org> Migrate struct carpstats to PCPU counters.
705a50a05300cbec6176269dfe8b9e5ae0b12dab 09-Jul-2013 ae <ae@FreeBSD.org> Migrate structs arpstat, icmpstat, mrtstat, pimstat and udpstat to PCPU
counters.
1b1e1de2b2e27f692afabbf18eee1f7a70caa049 09-Jul-2013 ae <ae@FreeBSD.org> Use new macros to implement ipstat and tcpstat using PCPU counters.
Change interface of kread_counters() similar ot kread() in the netstat(1).
1a36dfcc879833c6fdc45e20d39db618b110f55c 09-Jul-2013 ae <ae@FreeBSD.org> Prepare network statistics structures for migration to PCPU counters.
Use uint64_t as type for all fields of structures.

Changed structures: ahstat, arpstat, espstat, icmp6_ifstat, icmp6stat,
in6_ifstat, ip6stat, ipcompstat, ipipstat, ipsecstat, mrt6stat, mrtstat,
pfkeystat, pim6stat, pimstat, rip6stat, udpstat.

Discussed with: arch@
21122c283428cb5befbc9946b8191cc085c8d996 10-Apr-2013 glebius <glebius@FreeBSD.org> Use kvm_counter_u64_fetch() to fix obtaining ipstat and tcpstat from
kernel core files.

Sponsored by: Nginx, Inc.
2a0fbb38ed223899ff5d9aaa8c88b3894a38ed5e 08-Apr-2013 glebius <glebius@FreeBSD.org> Merge from projects/counters: TCP/IP stats.

Convert 'struct ipstat' and 'struct tcpstat' to counter(9).

This speeds up IP forwarding at extreme packet rates, and
makes accounting more precise.

Sponsored by: Nginx, Inc.
8f92a0e98309ecb478adf087a1888c41e6819e5a 19-Feb-2013 charnier <charnier@FreeBSD.org> WARNS=6 compliance
9f101aeb57abe7bf47cd58141dcaa1bb1fb1a56a 22-Jan-2013 glebius <glebius@FreeBSD.org> Use pluralies() for "entry"/"entries".
67d5f1a727273d8e141e96c429114dff9fb06ec3 19-Jun-2012 np <np@FreeBSD.org> - Updated TOE support in the kernel.

- Stateful TCP offload drivers for Terminator 3 and 4 (T3 and T4) ASICs.
These are available as t3_tom and t4_tom modules that augment cxgb(4)
and cxgbe(4) respectively. The cxgb/cxgbe drivers continue to work as
usual with or without these extra features.

- iWARP driver for Terminator 3 ASIC (kernel verbs). T4 iWARP in the
works and will follow soon.

Build-tested with make universe.

30s overview
============
What interfaces support TCP offload? Look for TOE4 and/or TOE6 in the
capabilities of an interface:
# ifconfig -m | grep TOE

Enable/disable TCP offload on an interface (just like any other ifnet
capability):
# ifconfig cxgbe0 toe
# ifconfig cxgbe0 -toe

Which connections are offloaded? Look for toe4 and/or toe6 in the
output of netstat and sockstat:
# netstat -np tcp | grep toe
# sockstat -46c | grep toe

Reviewed by: bz, gnn
Sponsored by: Chelsio communications.
MFC after: ~3 months (after 9.1, and after ensuring MFC is feasible)
7e5a8c601f7c328808a7bd25d555a95c795edf62 13-Apr-2012 delphij <delphij@FreeBSD.org> Eliminate an unused parameter of static method igmp_stats_live_old().

MFC after: 1 month
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.
dbaa5c88937ce4735bac50f57d01657a3cd480f2 26-Mar-2011 ru <ru@FreeBSD.org> Fixed sockets display somewhat (-L, -T, -x, -Lx, with and without -A).
(I didn't try to fix negative TCP timers with -x.)

MFC after: 3 days
5115240a6cdc054f7eea804355742f97c74578d8 21-Mar-2011 jeff <jeff@FreeBSD.org> - Merge in OFED 1.5.3 from projects/ofed/head
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
3d2c99a2abbc1340b0993212b77c066dab836d7b 22-Nov-2010 gnn <gnn@FreeBSD.org> Restore the (state) and \n printout when not using -T.

Pointed out by: brucec@
MFC after: 3 weeks
79e78b2c61c034f70491270cd04b4c5672a6c0c7 18-Nov-2010 dim <dim@FreeBSD.org> Sync: merge r215396 through r215463 from ^/head.
67b3b6b168c800611c4683cb81384e4a678517c6 17-Nov-2010 gnn <gnn@FreeBSD.org> Add new, per connection, statistics for TCP, including:
Retransmitted Packets
Zero Window Advertisements
Out of Order Receives

These statistics are available via the -T argument to
netstat(1).
MFC after: 2 weeks
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.
07c7ca7c366d860131106658c7d6bc84e0e1738c 05-Oct-2010 ru <ru@FreeBSD.org> Show hostcache statistics.

Submitted by: Maxim Dounin
f1216d1f0ade038907195fc114b7e630623b402c 19-Mar-2010 delphij <delphij@FreeBSD.org> Create a custom branch where I will be able to do the merge.
889d37774b3df1dc9414bebc108c1960664dfb1c 28-Jan-2010 gnn <gnn@FreeBSD.org> MFC r196797:

Add ARP statistics to the kernel and netstat.
9c5b455a41ce8f7b10145c8a290f81331587c91b 23-Sep-2009 silby <silby@FreeBSD.org> In netstat -x, do not try to print out tcp timer status for udp sockets.
ded53b4033d64348edff9f7b9fe6d19d8d418ad2 16-Sep-2009 silby <silby@FreeBSD.org> Add the ability to see TCP timers via netstat -x. This can be a useful
feature when you have a seemingly stuck socket and want to figure
out why it has not been closed yet.

No plans to MFC this, as it changes the netstat sysctl ABI.

Reviewed by: andre, rwatson, Eric Van Gyzen
60eb51e7a3e3a1dfacd9d9284b7e21e1fe4de011 03-Sep-2009 gnn <gnn@FreeBSD.org> Add ARP statistics to the kernel and netstat.

New counters now exist for:
requests sent
replies sent
requests received
replies received
packets received
total packets dropped due to no ARP entry
entrys timed out
Duplicate IPs seen

The new statistics are seen in the netstat command
when it is given the -s command line switch.

MFC after: 2 weeks
In collaboration with: bz
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
71233409ea6a2f4d751847c05e7aad9375278d94 09-Mar-2009 bms <bms@FreeBSD.org> Merge IGMPv3 and Source-Specific Multicast (SSM) to the FreeBSD
IPv4 stack.

Diffs are minimized against p4.
PCS has been used for some protocol verification, more widespread
testing of recorded sources in Group-and-Source queries is needed.
sizeof(struct igmpstat) has changed.

__FreeBSD_version is bumped to 800070.
b66b1bfcddae9bff426f7be893c2fe4870370f68 28-Nov-2008 gnn <gnn@FreeBSD.org> Fix a printing problem when using the -L flag to netstat caused
by adding the -x flag earlier.

Submitted by: Anton Yuzhaninov
MFC after: 3 days
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.
cbecb62bfe4d08b1c22267fd67b968fa8d80de73 17-Oct-2008 delphij <delphij@FreeBSD.org> Use strlcpy() when we mean it.
0a21b0e69fe6da565111bf9bc48bf8fdb1a70c4d 01-Sep-2008 obrien <obrien@FreeBSD.org> MFC: r182602: Minimize changes CURRENT<->releng7.
5dc67fc4b3450e41c41b69ce34725367c0c87228 01-Sep-2008 obrien <obrien@FreeBSD.org> Minimize changes CURRENT<->releng7.
08e8549c49ad71e5e3966a1c1616cb6e7ff009e1 26-Aug-2008 rpaulo <rpaulo@FreeBSD.org> Add ECN stats.
aa17b308bb5c74a477dfedece515cf0e22c95400 29-Jul-2008 emax <emax@FreeBSD.org> Fix build
368bdf05e9188bfc74fa11ed733351ed1c1e5c2c 15-May-2008 gnn <gnn@FreeBSD.org> Update the kernel to count the number of mbufs and clusters
(all types) used per socket buffer.

Add support to netstat to print out all of the socket buffer
statistics.

Update the netstat manual page to describe the new -x flag
which gives the extended output.

Reviewed by: rwatson, julian
e20702e40922461a79ea00b86bcfc130d4998b28 16-Mar-2008 obrien <obrien@FreeBSD.org> MFC: rev 1.82: make a few messages more consistant
4e4c1baf05facc6b498b90fd6adbd3a8e2c1444a 16-Mar-2008 obrien <obrien@FreeBSD.org> MFC: style(9)
913cd7552bbc11c316f59318c0cc00ab939cdc51 24-Jan-2008 ru <ru@FreeBSD.org> MFC: 1.79: Fix printing of the number of syncache entries added.
02ad23dc69b5059d3fec5db986a43d95b38d353c 04-Jan-2008 obrien <obrien@FreeBSD.org> MFC: rev. 1.76: 'netstat -A -p tcp' prints the Tcpcb pointer in the 1st col
21f57c54a6251181207511c934f057402bc5965a 04-Jan-2008 obrien <obrien@FreeBSD.org> Make a few messages more consistant with the others.
42e1a3c481dfe5a38ee9d62c7a2bb392a9c635bc 04-Jan-2008 obrien <obrien@FreeBSD.org> more style(9)
74070565806ee33326b76dcdd5e1e0a86cd4e6ed 02-Jan-2008 obrien <obrien@FreeBSD.org> style(9)
+ kread is not a boolean, so check it as such
+ fix $FreeBSD$ Ids
+ denote copyrights with /*-
+ misc whitespace changes.
ff8db90dd7087915382193bcb6dfbc7cfedf32cc 18-Dec-2007 ru <ru@FreeBSD.org> Fix printing of the number of syncache entries added.
818361dec31495e88061ffe2312c04e835d973d5 04-Oct-2007 obrien <obrien@FreeBSD.org> MFC: Use uintmax_t to pass around 64-bit quantities, including to printf().
Using uintmax_t is also robust to further extensions in both the C language
and the bitwidth of kernel counters.
a2842c2079470430f9a346814d8788886c1f886d 03-Oct-2007 obrien <obrien@FreeBSD.org> MFC: 2006/07/28 commit achieving WARNS=3
Also fix nlist 'nl' should be terminated by a NULL entry.
44ff2749c081059ba6487d842a736b022cce05bb 23-Jul-2007 jhb <jhb@FreeBSD.org> MFC: Restore netstat -M functionality for most statistics on core dumps.
One change in this patch relative to the changes in HEAD is that the
mroute statistics will still fallback to using libkvm on live kernels
if the sysctl fails.
27187e7f6bd04a94e9ada0ca994e7c828abb4514 16-Jul-2007 jhb <jhb@FreeBSD.org> Restore netstat -M functionality for most statistics on core dumps. In
general, when support was added to netstat for fetching data using sysctl,
no provision was left for fetching equivalent data from a core dump, and
in fact, netstat would _always_ fetch data from the live kernel using
sysctl even when -M was specified resulting in the user believing they
were getting data from coredumps when they actually weren't. Some specific
changes:
- Add a global 'live' variable that is true if netstat is running against
the live kernel and false if -M has been specified.
- Stop abusing the sysctl flag in the protocol tables to hold the protocol
number. Instead, the protocol is now its own field in the tables, and
it is passed as a separate parameter to the PCB and stat routines rather
than overloading the KVM offset parameter.
- Don't run PCB or stats functions who don't have a namelist offset if we
are being run against a crash dump (!live).
- For the inet and unix PCB routines, we generate the same buffer from KVM
that the sysctl usually generates complete with the header and trailer.
- Don't run bpf stats for !live (before it would just silently always run
live).
- kread() no longer trashes memory when opening the buffer if there is an
error on open and the passed in buffer is smaller than _POSIX2_LINE_MAX.
- The multicast routing code doesn't fallback to kvm on live kernels if
the sysctl fails. Keeping this made the code rather hairy, and netstat
is already tied to the kernel ABI anyway (even when using sysctl's since
things like xinpcb contain an inpcb) so any kernels this is run against
that have the multicast routing stuff should have the sysctls.
- Don't try to dig around in the kernel linker in the netgraph PCB routine
for core dumps.

Other notes:
- sctp's PCB routine only works on live kernels, it looked rather
complicated to generate all the same stuff via KVM. Someone can always
add it later if desired though.
- Fix the ipsec removal bug where N_xxx for IPSEC stats weren't renumbered.
- Use sysctlbyname() everywhere rather than hardcoded mib values.

MFC after: 1 week
Approved by: re (rwatson)
ffd77d9ba5a1376d64ccbb2909a7179c05de81bc 12-Jun-2007 bms <bms@FreeBSD.org> Import rewrite of IPv4 socket multicast layer to support source-specific
and protocol-independent host mode multicast. The code is written to
accomodate IPv6, IGMPv3 and MLDv2 with only a little additional work.

This change only pertains to FreeBSD's use as a multicast end-station and
does not concern multicast routing; for an IGMPv3/MLDv2 router
implementation, consider the XORP project.

The work is based on Wilbert de Graaf's IGMPv3 code drop for FreeBSD 4.6,
which is available at: http://www.kloosterhof.com/wilbert/igmpv3.html

Summary
* IPv4 multicast socket processing is now moved out of ip_output.c
into a new module, in_mcast.c.
* The in_mcast.c module implements the IPv4 legacy any-source API in
terms of the protocol-independent source-specific API.
* Source filters are lazy allocated as the common case does not use them.
They are part of per inpcb state and are covered by the inpcb lock.
* struct ip_mreqn is now supported to allow applications to specify
multicast joins by interface index in the legacy IPv4 any-source API.
* In UDP, an incoming multicast datagram only requires that the source
port matches the 4-tuple if the socket was already bound by source port.
An unbound socket SHOULD be able to receive multicasts sent from an
ephemeral source port.
* The UDP socket multicast filter mode defaults to exclusive, that is,
sources present in the per-socket list will be blocked from delivery.
* The RFC 3678 userland functions have been added to libc: setsourcefilter,
getsourcefilter, setipv4sourcefilter, getipv4sourcefilter.
* Definitions for IGMPv3 are merged but not yet used.
* struct sockaddr_storage is now referenced from <netinet/in.h>. It
is therefore defined there if not already declared in the same way
as for the C99 types.
* The RFC 1724 hack (specify 0.0.0.0/8 addresses to IP_MULTICAST_IF
which are then interpreted as interface indexes) is now deprecated.
* A patch for the Rhyolite.com routed in the FreeBSD base system
is available in the -net archives. This only affects individuals
running RIPv1 or RIPv2 via point-to-point and/or unnumbered interfaces.
* Make IPv6 detach path similar to IPv4's in code flow; functionally same.
* Bump __FreeBSD_version to 700048; see UPDATING.

This work was financially supported by another FreeBSD committer.

Obtained from: p4://bms_netdev
Submitted by: Wilbert de Graaf (original work)
Reviewed by: rwatson (locking), silence from fenner,
net@ (but with encouragement)
eaf028c6977643c9c214a40fd06fbc57089ae62b 14-May-2007 maxim <maxim@FreeBSD.org> MFC rev. 1.75: fill the list of icmp types; make its size depend
on ICMP_MAXTYPE.
97ae8d65064f09cc003c1dfe3c026c12171f3974 13-May-2007 andre <andre@FreeBSD.org> 'netstat -A -p tcp' doesn't print the Socket but the Tcpcb pointer in the
first column.
0c15c5c2c2b9fdb8cc6eb3e1aac2d072e48a181a 30-Apr-2007 maxim <maxim@FreeBSD.org> o Fill the list of icmp types; make its size depend on ICMP_MAXTYPE.
o Print "unknown ICMP" instead of "(null)" if we don't have a description for a icmp type.

Based on code

Submitted by: Christoph Weber-Fahr
PR: misc/112126
MFC after: 2 weeks
384aeb29f6100b5e13581c56efdea6d423675769 26-Feb-2007 mohans <mohans@FreeBSD.org> Reap FIN_WAIT_2 connections marked SOCANTRCVMORE faster. This mitigate
potential issues where the peer does not close, potentially leaving
thousands of connections in FIN_WAIT_2. This is controlled by a new sysctl
fast_finwait2_recycle, which is disabled by default.

Reviewed by: gnn, silby.
605d460600a10bd77a6f30bcd67bffc116200ef7 20-Sep-2006 wkoszek <wkoszek@FreeBSD.org> Export tcps_rcvmemdrop available in 'struct tcpstat' with netstat(1).

Requested by: Tomasz Pilat <tomasz.pilat (at) axelspringer.pl>
Approved by: andre
59fab84bab308e4a3eb124a99ce391729ed77614 28-Jul-2006 yar <yar@FreeBSD.org> - Achieve WARNS=3 by using sparse initializers or avoiding initializers at all.
- Fix a nlist initialization: it should be terminated by a NULL entry.
- Constify.
- Catch an unused parameter.

Tested on: i386 amd64 ia64
e1db503689ae54aa3513f73b6e1aa4212ded2641 28-Jul-2006 yar <yar@FreeBSD.org> Achieve WARNS=2 by using uintmax_t to pass around 64-bit quantities,
including to printf(). Using uintmax_t is also robust to further
extensions in both the C language and the bitwidth of kernel counters.

Tested on: i386 amd64 ia64
07d3bbca19d5a7fa364cbc44cc52f3a4ef8b0a76 12-Apr-2005 ru <ru@FreeBSD.org> Silence a warning on systems without carp(4).
f01ea9b62654b444f236eae247140d7e5c0b8f7f 09-Mar-2005 ps <ps@FreeBSD.org> Add limits on the number of elements in the sack scoreboard both
per-connection and globally. This eliminates potential DoS attacks
where SACK scoreboard elements tie up too much memory.

Submitted by: Raja Mukerji (raja at moselle dot com).
Reviewed by: Mohan Srinivasan (mohans at yahoo-inc dot com).
e1d22638d0a8257ed01b7f95d1b6d5cef74ebd07 22-Feb-2005 glebius <glebius@FreeBSD.org> Add CARP (Common Address Redundancy Protocol), which allows multiple
hosts to share an IP address, providing high availability and load
balancing.

Original work on CARP done by Michael Shalayeff, with many
additions by Marco Pfatschbacher and Ryan McBride.

FreeBSD port done solely by Max Laier.

Patch by: mlaier
Obtained from: OpenBSD (mickey, mcbride)
cd48a1d32b7e37d716e9ca0da9ba773994c976b3 26-Jul-2004 charnier <charnier@FreeBSD.org> Add __FBSDID. Replace local variable sin by sockin to not conflict with sin(3).
Use warnx() instead of warn() when error message is not of any interest. Add
prototypes.
f5e286321ca69809902a4e0158febc71480ad969 29-Jun-2004 ps <ps@FreeBSD.org> Add SACK statistics to netstat.
6f2c3ad82da733bf2135cc2a015f095309337c84 16-Jun-2004 bms <bms@FreeBSD.org> Make netstat(1) more closely follow documented behaviour. If a TCP
socket in LISTEN state happens to be bound to an interface, it will
show up in netstat(1) output even without the -a switch.

As the definition of "sockets used by server processes" is a
difficult one to qualify with regards to UDP, do not change the
output behaviour for UDP sockets.

PR: bin/26359
94247dad2ef8d0c7998a10b464a63ed0dbd3809c 02-Jun-2004 fjoe <fjoe@FreeBSD.org> Add missing dot and newline in a message.

Submitted by: Igor Sysoev <is (at) rambler-co.ru>
MFC after: 3 days
11a1318135d14e179519f7006521a0be6b9baa99 12-May-2004 ru <ru@FreeBSD.org> Output style nit.
bd609915e07121dc82cca7d677c8057f0468b425 26-Apr-2004 silby <silby@FreeBSD.org> Add the bad reset statistic (corresponds to tcp_input.c rev 1.235)
08e8eb2b40c0e5b6b1d511c0a68bd174602757b5 12-Mar-2004 des <des@FreeBSD.org> Do not print a warning about net.inet.pim.stats if errno is
ENOENT, because that means we do not have PIM in the kernel.

Submitted by: hmp
MFC after: 1 week
feaeb43d02b84e57f77d9ab15abb3e6d6bf62595 23-Oct-2003 ru <ru@FreeBSD.org> Print the correct ICMP statistics for "no return routes".
27325403c64a9b3337b47535dc2680886c4064fe 07-Aug-2003 hsu <hsu@FreeBSD.org> 1. Add support for printing PIM-related statistics with
netstat -s -p pim

2. Print information about the bandwidth meters installed in the kernel with
netstat -g

Submitted by: Pavlin Radoslavov <pavlin@icir.org>
ccc6071f7ea7e2ba54dfcf45ff8afda2e395aa3d 02-Apr-2003 mdodd <mdodd@FreeBSD.org> Back out support for RFC3514.

RFC3514 poses an unacceptale risk to compliant systems.
e72fdee732ab55fc784034c81ccedda4b5279816 01-Apr-2003 mdodd <mdodd@FreeBSD.org> Implement support for RFC 3514 (The Security Flag in the IPv4 Header).
(See: ftp://ftp.rfc-editor.org/in-notes/rfc3514.txt)

This fulfills the host requirements for userland support by
way of the setsockopt() IP_EVIL_INTENT message.

There are three sysctl tunables provided to govern system behavior.

net.inet.ip.rfc3514:

Enables support for rfc3514. As this is an
Informational RFC and support is not yet widespread
this option is disabled by default.

net.inet.ip.hear_no_evil

If set the host will discard all received evil packets.

net.inet.ip.speak_no_evil

If set the host will discard all transmitted evil packets.

The IP statistics counter 'ips_evil' (available via 'netstat') provides
information on the number of 'evil' packets recieved.

For reference, the '-E' option to 'ping' has been provided to demonstrate
and test the implementation.
2da153c5bb45b9d849dd9db0ed1e7bd4b90abbba 14-Jan-2003 mtm <mtm@FreeBSD.org> o Typo/Grammar fixes
o Added mini-function to correctly handle singular/plural
of words ending in 'ly'

Approved by: markm (mentor)
Not objected to by: -audit
cb4604919fc3c4fef1de7daff27468d6c5fbd56d 05-Sep-2002 dwmalone <dwmalone@FreeBSD.org> Warns cleanups for netstat:
1) Include arpa/inet.h for ntohs.
2) Constness fixes.
3) Fix shadowing except for "sin" which shouldn't be in scope.
4) Remove register keyword.
5) Add missing initialsers to user defined structs.
5) Make prototype of netname6 globally visable.
6) Use right macros for printing syncache stats (even though entrie isn't
a word).
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.
62fef107e4bc6cf89c04fb8fee26b7aea2cf04c3 19-Jul-2002 dillon <dillon@FreeBSD.org> Add the tcps_sndrexmitbad statistic, keep track of late acks that caused
unnecessary retransmissions.
cfe5212a8b36139b260e85fe117efef6bbbc5a4b 30-Nov-2001 ru <ru@FreeBSD.org> - Make ip_rtaddr() global, and use it to look up the correct source
address in icmp_reflect().
- Two new "struct icmpstat" members: icps_badaddr and icps_noroute.

PR: kern/31575
Obtained from: BSD/OS
MFC after: 1 week
7e4737a17a89fe0f71b6b62c33f5cb8b254ddbd8 22-Nov-2001 jlemon <jlemon@FreeBSD.org> Add syncache statistics to netstat.
733af41f5a8c821afd7b0bfc9fc0e9db8b770646 07-Sep-2001 ru <ru@FreeBSD.org> Don't print stray socket addresses (-A) with the listen queue display (-L).
Also, print socket's protocol with the -L.
f8e11dde2671e192fa12edbf3487f63e8e0ade6e 23-Jun-2001 ru <ru@FreeBSD.org> Add netstat(1) knob to reset net.inet.{ip|icmp|tcp|udp|igmp}.stats.
For example, ``netstat -s -p ip -z'' will show and reset IP stats.

PR: bin/17338
f5fc9b53400a054604623dad4c679865150873d4 15-Jun-2001 assar <assar@FreeBSD.org> remove warnings
remove superfluous declarations
make things more consistent
ee746c97f9f42b279e24583560b4f0eaef1e081b 15-Jun-2001 assar <assar@FreeBSD.org> remove K&R support
6c0b683445bcb0c4262928ed96c5600046fd89c4 15-Jun-2001 assar <assar@FreeBSD.org> revert removal of warning and K&R support

Requested by: bde
9e34fe7efd02802c8741141cf670713ba1ade2e5 15-Jun-2001 assar <assar@FreeBSD.org> remove most of the warnings
ea6e16bc20e4706c99c89ec7b7f3ab3be1791a4c 15-Jun-2001 assar <assar@FreeBSD.org> add the option -S for printing port numbers symbolically but addresses
numerically. clean up the CFLAGS in Makefile.
832f8d224926758a9ae0b23a6b45353e44fbc87a 11-Jun-2001 ume <ume@FreeBSD.org> Sync with recent KAME.
This work was based on kame-20010528-freebsd43-snap.tgz and some
critical problem after the snap was out were fixed.
There are many many changes since last KAME merge.

TODO:
- The definitions of SADB_* in sys/net/pfkeyv2.h are still different
from RFC2407/IANA assignment because of binary compatibility
issue. It should be fixed under 5-CURRENT.
- ip6po_m member of struct ip6_pktopts is no longer used. But, it
is still there because of binary compatibility issue. It should
be removed under 5-CURRENT.

Reviewed by: itojun
Obtained from: KAME
MFC after: 3 weeks
cd8d72036779073e9a559040e5b29558621cdc99 15-Mar-2001 des <des@FreeBSD.org> Add a -W flag that tells netstat not to truncate addresses even if they are
too long for the column they're printed in.

Move variable definitions out of netstat.h and into main.c.

Clean up some warnings.
dd004da290c46c50b50ee5c919ad6eab35694921 14-Mar-2001 brian <brian@FreeBSD.org> MAXHOSTNAMELEN includes space for a NUL.
Don't roll our own version of trimdomain(), use the one in libutil.

Not objected to by: freebsd-audit
e7537660da15b12ac3a6e5a2f6d88f50e7c159ec 13-Mar-2001 ru <ru@FreeBSD.org> Count and show incoming UDP datagrams with no checksum.
77ac5d68c962311b7a303ced7d56bbcf8e95f7d2 04-Jul-2000 itojun <itojun@FreeBSD.org> sync with latest kame netstat. basically, more statistics
b42951578188c5aab5c9f8cbcde4a743f8092cdc 02-Apr-2000 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'ALSA'.
b8e88750ca8496f0291145d8c4a7b0ab0efc5e3c 07-Jan-2000 shin <shin@FreeBSD.org> -permit protocol specific statistics at iflag,
only when either of sflag and "-f inet6" is specified.
-fix the indentation of default output

Specified by: Stephen McKay <syssgm@detir.qld.gov.au>

Reviewed and Confirmed by: Stephen McKay <syssgm@detir.qld.gov.au>
39eef9ac50edc8fec68a286507de869f0ca3af45 13-Dec-1999 guido <guido@FreeBSD.org> Add new option, -L that will listen the various listen queue lengths.

Reviewed by: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>,
Clive Lin <clive@GnatS.CirX.ORG>
70f0bdf6818a73c858bc47a23afc1e9d7c56d716 07-Dec-1999 shin <shin@FreeBSD.org> udp IPv6 support, IPv6/IPv4 tunneling support in kernel,
packet divert at kernel for IPv6/IPv4 translater daemon

This includes queue related patch submitted by jburkhol@home.com.

Submitted by: queue related patch from jburkhol@home.com
Reviewed by: freebsd-arch, cvs-committers
Obtained from: KAME project
698af92f8613624eb9b69ed626a553ef9ed11bc3 21-Oct-1999 julian <julian@FreeBSD.org> Cleanup towards -Wall
3b842d34e82312a8004a7ecd65ccdb837ef72ac1 28-Aug-1999 peter <peter@FreeBSD.org> $Id$ -> $FreeBSD$
f234b406a45a445cc33488b6a9260e82cb4d01b8 06-Jul-1999 des <des@FreeBSD.org> Don't truncate port numbers.

Submitted by: ru
ebe2a5b78b2965a3e89ad5e36383d886999bc947 10-Mar-1999 des <des@FreeBSD.org> Fix fstat compatibility by printing the address of the tcppcb instead of
that of the regular socket pcb for TCP sockets.

PR: bin/9963
Submitted by: Ruslan Ermilov <ru@ucb.crimea.ua>
0609531ab6b945c4918206f095bc1f6640408654 06-Jul-1998 bde <bde@FreeBSD.org> Fixed printf format errors.
94f67b7ef56a6df8d3c217cd5cc00b14f2dc3ae2 09-Jun-1998 imp <imp@FreeBSD.org> o Use snprintf over sprintf.
o Use strncpy correctly.
o Use enough buffer for line.

Inspired by or Obtained from: Similar changes in OpenBSD
03f5c9148465bdafdf9987a02bd1303a47b83ee7 19-May-1998 pb <pb@FreeBSD.org> Make "netstat -s" display stats on fast-forwarded packets.
Obtained from: NetBSD code
e37570d81294700974f15cb7d91068b206166646 15-May-1998 wollman <wollman@FreeBSD.org> mbuf, inet, and unix modules no longer read kvm.
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'.
fefb31984036c52416ff19dddb3e14a5227b987c 25-Aug-1997 wollman <wollman@FreeBSD.org> Print out the two new fields in the ICMP stats. While we're at it, also
convert icmp_stats() to use sysctl(3) to retrieve the information
rather than kvm. This makes it easy to also print whether ICMP address
mask responses are enabled, so do so.
f390c26dd9214a3602049fa55835b2d367ef60df 22-Feb-1997 peter <peter@FreeBSD.org> Revert $FreeBSD$ to $Id$
fe537196d330ad8f0b38629a10633c0313ffd586 21-Jan-1997 wollman <wollman@FreeBSD.org> Print out the new uninteresting-multicast-packets statistic.
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.
ac82b8a657c8154201e4791f40f7ba417f5debdb 07-Jan-1997 pst <pst@FreeBSD.org> TCP statistics are unsigned counters.

Tor Egge reports counter wrap and requests and update to quad_t sized
counters, which is also a good thing to do, but I'm unhappy about adding
two more instructions into the code path every time we doink a counter.

Maybe with or after the Lite2 merge...
Submitted by: Tor Egge <Tor.Egge@idt.ntnu.no>
cd2ff97ceed98bfea914f0b9efea6c84cd0d6039 28-Oct-1996 wollman <wollman@FreeBSD.org> Eliminate unnecessary include of <sys/mbuf.h>. PCBs aren't stored in mbufs
any more.
733856f9647223ba9a8e2cac728e15d5adaa040b 23-Aug-1996 phk <phk@FreeBSD.org> Try to make netstat more smart about port numbers.
Feedback most welcome.
99c2eebb28f179cf7f98673935ba27d2a1dc9c23 05-Jun-1996 wollman <wollman@FreeBSD.org> Print PCB hash miss statistic.
5c1e86ebb424294fcfae39ae7ff1efcf8808086d 02-Jun-1996 alex <alex@FreeBSD.org> Code cleanup: remove unused variables, use correct *printf format
specifiers (some unsigned values were printed as signed, some longs
were printed as ints), and place parentheses around assignments in
if statements.
42390683e5de322e34b244ea03ffa0e6e1b0cb0f 11-Mar-1996 dg <dg@FreeBSD.org> Move #include of queue.h before #include of socketvar.h in preparation for
struct socket changes.
89b4ca893fe13e54c6d973cb8ba18e9fb0e54dc0 26-Feb-1996 guido <guido@FreeBSD.org> Add a counter for the number of times the listen queue was overflowed to
the tcpstat structure. (netstat -s)
Reviewed by: wollman
Obtained from: Steves, TCP/IP Ill. vol.3, page 189
297db4d6f76e22d93e587a48e8ba9cc319d61a24 15-Jan-1996 peter <peter@FreeBSD.org> tidy up the domain name trimming code, and move it to a single place
rather than having the same bit of code duplicated in three places,
each with their own static copy of the host's local name.
e0dc99202602929138dfd9fb9d465d21b685919c 14-Jan-1996 peter <peter@FreeBSD.org> Merge in Lite-2 changes.
5476eae499a3e1c3530620c0ebc3a69ffb2f25ba 14-Jan-1996 peter <peter@FreeBSD.org> Import netstat from 4.4Lite-2 - this version eliminates some of the
severely bogus mask guessing in the netname code, and also reports the
mask length of the route (like linux's netstat, but in a much more compact
form)

The current code is doing bogus things like shifting c-class subnets by
4 bits and looking them up, causing a DNS lookup of 0x0C0CBxxx which
takes an eternity to fail.
6ef4e82f0f2c507c27c3787fb8e0d899e2dbadca 23-Dec-1995 ache <ache@FreeBSD.org> Change .8s port name restriction to .15s, modern tcp port
have longer names, check /etc/services.
kerberos_master triggers this bug: it is undistiguishable from
simple kerberos for .8s
86f1bc4514fdcfd255f37f3218fe234bdc3664fc 05-Nov-1995 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'LINUX'.
5bca48107ea8ea02e0f118410ab9dbbed629f50a 27-Oct-1995 adam <adam@FreeBSD.org> - #if defined(TF_NEEDSYN) && defined(TF_NEEDSYN)
+ #if defined(TF_NEEDSYN) && defined(TF_NEEDFIN)
349dc9727a2eac61877fa9f3118afa6a91acca76 13-Oct-1995 wollman <wollman@FreeBSD.org> In TCP statistics, display new statistic about how many resends were
initiated as a result of the Path MTU discovery process.
d07d67048ecfd869ae329f73245a968f13f85372 29-Jul-1995 dg <dg@FreeBSD.org> Output statistics as unsigned in the -w section.
Look at error return of kread() and stop on error.
Fix warning in kread() to not output "kvm_read:" twice.
Killed PCB cache misses stat as we no longer have it.
42b1f12f0a00225e1b9a5ef2f729cce023024f25 29-Jul-1995 dg <dg@FreeBSD.org> Add "connections dropped by persist timeout" statistic.
0c180bc68dad77998226a4a36c7ae7d8bf0fb36e 19-Jun-1995 wollman <wollman@FreeBSD.org> Correct spelling mistake: upcated -> updated.
37654c52dbc6c26dbc699033a70f26ecb1fc5ea7 19-Jun-1995 wollman <wollman@FreeBSD.org> Print out the statistics for cache updates of rtt, rttvar, and ssthresh.
ed7f6aebaf1534af96e9f1bb5c676877f5895067 09-Apr-1995 dg <dg@FreeBSD.org> That's what I get for doing things in a hurry...applied up-to-date patch
to this file rather than old one (before I renamed the structure element).
f070f04029ac2cfae7875c56a92168080ce03046 09-Apr-1995 dg <dg@FreeBSD.org> Oops, remove some chaff from previous commit.
aef6dbd77bce0cbf593b63c208181b0a0811845c 09-Apr-1995 dg <dg@FreeBSD.org> Updated netstat to grok 4.4 QUEUE macros now being used to like the PCBs
together.
2e14d9ebc3d3592c67bdf625af9ebe0dfc386653 14-Mar-1995 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'MATT_THOMAS'.
d48b4f1df6956a05e49a7415644fce5ea4dfbb04 14-Feb-1995 wollman <wollman@FreeBSD.org> Make netstat report the correct state for T/TCP.

Submitted by: Andras Olah <olah@cs.utwente.nl>
e361064e532ab32d6494d4ab2e4f1d00999aa794 02-Oct-1994 wollman <wollman@FreeBSD.org> Document router advertisement and solicitation messages in ICMP input
histogram.
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