History log of /freebsd-head/usr.bin/netstat/netgraph.c
Revision Date Author Comments
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)
00d578928eca75be320b36d37543a7e2a4f9fbdb 27-May-2016 grehan <grehan@FreeBSD.org> Create branch for bhyve graphics import.
07e5aa0065f06f476317da8415d66994ec2d47e2 02-Sep-2015 hrs <hrs@FreeBSD.org> Simplify kvm symbol resolution and error handling. The symbol table
nl_symbols will eventually be organized into several modules depending
on MK_* variables.
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.
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

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
o New field sb_fnrdy points to the first not ready mbuf, to avoid linear
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.
78bde6490528c198cd485385ecb997b6031f1bdb 19-Mar-2014 glebius <glebius@FreeBSD.org> Merge r259562,r259566,r259638,r259645,r260124 by melifaro:

Switch netstat -rn to use standard API for retrieving list
of routes instead of peeking inside in-kernel radix via kget.
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
8bd5f6c17c9114783f5e62ffeb7b2dac564d3a30 20-Dec-2013 melifaro <melifaro@FreeBSD.org> Use more fine-grained kvm(3) symbol lookup: routing code retrieves only
necessary symbols needed per subsystem. Main kvm(3) init is now delayed
as much as possbile. This finally fixes performance issues reported in
Some non-working code (ng_socket.ko symbol addresses calculation) removed.
Some global variables eliminated.

PR: kern/167204
MFC after: 4 weeks
d5bb5249b28f8b367e607754ee57bb2949cff37d 23-Jan-2012 glebius <glebius@FreeBSD.org> In ng_socket(4) expose less kernel internals to userland. This commit
breaks ABI, but makes probability of ABI breakage in future less.
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.
dc583d98a589fcdab130f8f010e7c5d6a48604c1 02-Apr-2010 glebius <glebius@FreeBSD.org> Merge r205082, r205083 that fix 'netstat -f netgraph' functionality.
f1216d1f0ade038907195fc114b7e630623b402c 19-Mar-2010 delphij <delphij@FreeBSD.org> Create a custom branch where I will be able to do the merge.
e93d3296963195868bf04a7a6820ceef4c6a679d 12-Mar-2010 glebius <glebius@FreeBSD.org> Now fix functionality of 'netstat -f netgraph' that hasn't worked
starting from netgraph import in 1999.

netstat(8) used pointer to node as node address, oops. That didn't
work, we need the node ID in brackets to successfully address a node.
We can't look into ng_node, due to inability to include netgraph/netgraph.h
in userland code. So let the node make a hint for a userland, storing
the node ID in its private data.

MFC after: 2 weeks
0842b7d53ffede64468e775f5c79965e3d9e48ae 13-Dec-2009 delphij <delphij@FreeBSD.org> Revert most part of 200420 as requested, as more review and polish is
b963db4652a0bf1718825e8e1a9bc93e87b7a80f 11-Dec-2009 delphij <delphij@FreeBSD.org> Remove unneeded header includes from usr.bin/ except contributed code.

Tested with: make universe
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.
4e4c1baf05facc6b498b90fd6adbd3a8e2c1444a 16-Mar-2008 obrien <obrien@FreeBSD.org> MFC: 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.
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
- 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
- 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)
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
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
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

Netstat and systat need to be rebuilt. I am incrementing
__FreeBSD_version in case any ports need to change.
f5fc9b53400a054604623dad4c679865150873d4 15-Jun-2001 assar <assar@FreeBSD.org> remove warnings
remove superfluous declarations
make things more consistent
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
4ea1588b37cbd62c1c2af3dfbd4c731cde0ea954 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'.
8c8443ab963c1f888eb1da4c5868b9f578078f9b 24-Oct-1999 dillon <dillon@FreeBSD.org> Put include <netgraph.h> back in - problem was due to a cvsup mess on
freefall. There may also be a real problem w/ buildworld but the fix
would go somewhere else, not here.
405fc1165a74f692670f70b4749507b6a98f08ec 23-Oct-1999 dillon <dillon@FreeBSD.org> Cleanup missing includes, stale includes, and a few printf format
c5c63975d538cf48ceb99ba48c341293676d15c0 21-Oct-1999 julian <julian@FreeBSD.org> Whistle's Netgraph link-layer (sometimes more) networking infrastructure.
Been in production for 3 years now. Gives Instant Frame relay to if_sr
and if_ar drivers, and PPPOE support soon. See:
for on-line manual pages.

Reviewed by: Doug Rabson (dfr@freebsd.org)
Obtained from: Whistle CVS tree