Bug 190281 - netstat -s -i only shows ip6 statistics
Summary: netstat -s -i only shows ip6 statistics
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.2-RELEASE
Hardware: Any Any
: Normal Affects Many People
Assignee: Tom Jones
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-26 21:30 UTC by Allan Jude
Modified: 2020-07-11 16:49 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Allan Jude freebsd_committer freebsd_triage 2014-05-26 21:30:01 UTC
'netstat -s -i' should show protocol statistics per interface. However it only shows ip6 statistics

'netstat -s' works as intended (shows the sum of each statistic, both ipv4 and ipv6, for all interfaces)

'netstat -s -4' works as intended (shows system-wide ipv4 statistics)

'netstat -s -i -4' returns nothing



Note 'netstat -s -s' suppresses 0 values

#netstat -s | wc -l
     348
#netstat -s -s | wc -l
     120
#netstat -s -s -i | wc -l
      18
#netstat -s -s -I igb0 | wc -l
       6
#netstat -s -s -i -4 | wc -l
       0

'netstat -s -s -i' should return the same more more lines than 'netstat -s -s', since it will break the statistics down per-interface

How-To-Repeat: netstat -s -i -4
Comment 1 bycn82 2014-06-17 15:07:50 UTC
command "netstat -i" will show the "per interface statistic" information, but currently, actually according to the source, developers only implemented the "ip6_ifstats" and "icmp6_ifstats", two methods only and they are for INET6, 
so "netstat -s -i -4" will get nothing, 
and "netstat -s -i -6" will be the same as "netstat -s -i"
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:51:36 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"
Comment 3 Marie Helene Kvello-Aune 2018-06-18 19:23:21 UTC
I decided to look at this today, and to my surprise, I found that netstat doesn't implement per-interface statistics for IPv4 at all.

In usr.bin/netstat/main.c, line 105-106:
{ N_RIPCBINFO,	N_IPSTAT,	1,	protopr,
  ip_stats,	NULL,		"ip",	1,	IPPROTO_RAW },

The 6th argument is supposed to be the function which prints per-interface statistics.

The equivelant lines for IPv6 (line 141-142):
{ N_RIPCBINFO,	N_IP6STAT,	1,	protopr,
  ip6_stats,	ip6_ifstats,	"ip6",	1,	IPPROTO_RAW },

ip6_stats and ip6_ifstats are implemented in usr.bin/netstat/inet6.c.
ip_stats (but no ip_ifstats) is implemented in usr.bin/netstat/inet.c.

tl;dr: someone has to implement functions to print the IPv4 information as well.
Comment 4 Marie Helene Kvello-Aune 2018-06-18 19:24:31 UTC
... And I just realized I didn't see the comment by Eitan Adler before starting to dig into this. Oops.