Home | History | Annotate | Download | only in netstat
History log of /src/usr.bin/netstat/bpf.c
RevisionDateAuthorComments
 1.18  18-Aug-2023  martin Rename local bpf_* functions to nsbpf_* to avoid conflicts with
new libpcap bpf_* functions
 1.17  19-Nov-2022  yamt netstat/bpf.c: Don't print garbage for stale pid
 1.16  01-Sep-2022  msaitoh KNF. No functional change.
 1.15  28-Aug-2020  ozaki-r netstat: strengthen against kernel changes

netstat uses sysctlbyname to get counter data from the kernel.
sysctlbyname fails with ENOMEM if actual counter data in the kernel is
larger than a passed buffer. netstat just skips showing counters of a
category if sysctlbyname fails, so if we added new counters of the
category to the kernel, nestat shows nothing for the category.

Fortunately sysctlbyname fills data as much as possible even if a passed
buffer is short. So we can allow netstat to show the filled data anyway
if sysctlbyname fails with ENOMEM.

Note that this backcompat mechanism works only if new counters are
appended, and doesn't work if new counters are inserted into the middle
or counters are moved.
 1.14  18-Aug-2019  kamil netstat: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname, sysctlgetmibinfo and sysctlnametomib.
 1.13  26-Jun-2018  msaitoh branches: 1.13.2; 1.13.4;
Fix a bug that BPF_D_OUT isn't printed correctly.
 1.12  26-Jun-2018  msaitoh Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.11  14-Dec-2012  msaitoh branches: 1.11.22; 1.11.28;
Fix memory leak.
 1.10  13-Dec-2010  pooka branches: 1.10.6; 1.10.8; 1.10.12;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.
 1.9  12-Apr-2009  lukem Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.
 1.8  28-Apr-2008  martin branches: 1.8.6; 1.8.8;
Remove clause 3 and 4 from TNF licenses
 1.7  24-Apr-2008  thorpej Note which things are not available by KVM, and print a nice message
stating so if someone specifically asks for it.
 1.6  22-Sep-2006  elad branches: 1.6.16;
PR/31347: Geoff C. Wing: netstat err message is ambiguous about cause
Applied patch, thanks!
 1.5  21-Nov-2005  rpaulo Convert 3 printf() calls into one puts().
 1.4  02-Sep-2005  rpaulo Place the sysctl code under an if block and print an error message if the
user tries to fetch information via kvm.

Discussed with Elad Efrat.
 1.3  02-Sep-2005  rpaulo Request process information using sysctl(3) and not kvm(3) since bpf(4)
statistics and peers are only available using the former.
 1.2  05-Aug-2005  elad Fix printing formats.
 1.1  04-Aug-2005  rpaulo Implemented the userland part of the BPF statistics and BPF peers,
net.bpf.stats and net.bpf.peers sysctls respectively. netstat(1) now
has an additional syntax:
netstat [-s] [-B] [-I Interface]

Only the super user can see a list of BPF peers with the following command:
# netstat -B
Active BPF peers
PID Int Recv Drop Capt Flags Bufsize Comm
4941 lo0 0 0 0 I--S- 262144 tcpdump
252 ex0 19668 0 5 I-RS- 32768 dhclient

And every user can see the BPF statistics with:
$ netstat -s -B
bpf:
19669 total packets received
5 total packets captured
0 total packets dropped

This idea came from FreeBSD (Christian S.J. Peron) but, currently, they
doen't have a userland utility in the base system to read the sysctls.

Reviewed by: christos@
 1.6.16.1  18-May-2008  yamt sync with head.
 1.8.8.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.8.6.1  13-Jan-2013  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1833):
usr.bin/netstat/bpf.c: revision 1.11
Fix memory leak.
 1.10.12.1  25-Feb-2013  tls resync with head
 1.10.8.1  25-Dec-2012  snj Pull up following revision(s) (requested by msaitoh in ticket #763):
usr.bin/netstat/bpf.c: revision 1.11
Fix memory leak.
 1.10.6.1  23-Jan-2013  yamt sync with head
 1.11.28.1  28-Jul-2018  pgoyette Sync with HEAD
 1.11.22.1  12-Sep-2022  martin Pull up the following, requested by msaitoh in ticket #1762:

usr.bin/netstat/atalk.c 1.18,1.20-1.21
usr.bin/netstat/bpf.c 1.16 via patch
usr.bin/netstat/fast_ipsec.c 1.24 via patch
usr.bin/netstat/if.c 1.97-1.99,1.101-1.104 via patch
usr.bin/netstat/inet.c 1.111,1.115-1.116 via patch
usr.bin/netstat/inet6.c 1.70,1.74-1.75,1.80-1.81 via patch
usr.bin/netstat/main.c 1.100,1.102-1.103
usr.bin/netstat/mbuf.c 1.34-1.35
usr.bin/netstat/mroute.c 1.26-1.27
usr.bin/netstat/mroute6.c 1.16
usr.bin/netstat/netstat.h 1.52-1.53
usr.bin/netstat/pfkey.c 1.4-1.5 via patch
usr.bin/netstat/pfsync.c 1.4-1.5 via patch
usr.bin/netstat/route.c 1.87-1.88
usr.bin/netstat/unix.c 1.36-1.37
usr.bin/netstat/vtw.c 1.11,1.13

- Add names of a few more ICMPv6 messages.
Also make the array be explicitly 256 entries long.
- sprintf() -> snprintf(), and adjust a buffer size to avoid any
potential for overflow.
- Add missing {IP,IP6}_STAT_NOIPSEC to netstat.
- Don't show any of the completely and utterly undocumented VTW info
if the feature isn't enabled.
- Print oqdrops correctly.
- netstat.1: Add various xrefs present in the body to "See Also".
- Limit maximum owner name to appease gcc.
- KNF. Style fixes.
 1.13.4.2  12-Sep-2022  martin Pull up the following, requested by msaitoh in ticket #1522:

usr.bin/netstat/atalk.c 1.18,1.20-1.21
usr.bin/netstat/bpf.c 1.16 via patch
usr.bin/netstat/fast_ipsec.c 1.24
usr.bin/netstat/if.c 1.97-1.99,1.101-1.104 via patch
usr.bin/netstat/inet.c 1.111,1.115-1.116 via patch
usr.bin/netstat/inet6.c 1.74-1.75,1.80-1.81 via patch
usr.bin/netstat/main.c 1.100-1.103
usr.bin/netstat/mbuf.c 1.35
usr.bin/netstat/mroute.c 1.26-1.27
usr.bin/netstat/mroute6.c 1.16
usr.bin/netstat/netstat.h 1.52-1.53
usr.bin/netstat/pfkey.c 1.4-1.5 via patch
usr.bin/netstat/pfsync.c 1.4-1.5 via patch
usr.bin/netstat/route.c 1.86-1.88
usr.bin/netstat/unix.c 1.36-1.37
usr.bin/netstat/vtw.c 1.11,1.13

- sprintf() -> snprintf(), and adjust a buffer size to avoid any
potential for overflow.
- Fix netstat -rs to print it correctly.
- Add missing {IP,IP6}_STAT_NOIPSEC to netstat.
- Don't show any of the completely and utterly undocumented VTW info
if the feature isn't enabled.
- Print oqdrops correctly.
- Remove Network ATM soft intr queue reporting, we don't have that
in the kernel anymore.
- netstat.1: Add various xrefs present in the body to "See Also".
- KNF. Style fixes.
 1.13.4.1  19-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #94):

usr.bin/netstat/netstat_rumpops.c: revision 1.2
usr.bin/netstat/netstat_hostops.c: revision 1.2
usr.bin/netstat/inet6.c: revision 1.73
usr.bin/netstat/bpf.c: revision 1.14
usr.bin/netstat/Makefile: revision 1.46
usr.bin/netstat/prog_ops.h: revision 1.3
usr.bin/netstat/pfsync.c: revision 1.2
usr.bin/netstat/pfkey.c: revision 1.2
usr.bin/netstat/fast_ipsec.c: revision 1.23
usr.bin/netstat/atalk.c: revision 1.17
usr.bin/netstat/inet.c: revision 1.110

netstat: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname, sysctlgetmibinfo and sysctlnametomib.
 1.13.2.1  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411

RSS XML Feed