Re: Getting all ipv4 and ipv6 packet and byte counts on a router

From: Rodney W. Grimes <freebsd-rwg_at_gndrsh.dnsmgr.net>
Date: Wed, 03 Jun 2026 14:55:40 UTC
> I'm running 14.3 on my gateway router and I want to answer a simple question: How much
> ipv4 vs ipv6 traffic is entering and leaving the network via the external interface?
> 
> And by traffic I mean packets *and* bytes destined for the gateway router *and* for
> traffic forwarded via the router in both directions.
> 
> I looked at netstat(1) which pointed to netinet6/ip6_var.h and from that I deduce that
> link-level stats do not discriminate between v4/v6 and address-level stats only count
> traffic associated with a router address (I also double checked this by scanning for
> xo_emit() with "bytes" - no joy).
> 
> I don't read kernel well enough to check, but are v4/v6 packet&bytes counted separately on
> an interface basis? If so, how do I get at them in user space?
> 
> If not, do I need to write some bpf/pcap code to do the counting myself? This deployment
> happens to have CPU to burn so it's feasible, but it seems like a common requirement so
> sending packets into user-space just to collect these stats seems surprising. In any
> event, if someone can hit me over the head with a clue bat I'd appreciate it.

'ipfw count' is your friend here.

-- 
Rod Grimes                                                 rgrimes@freebsd.org