Index: sys/net/bpf.c =================================================================== RCS file: /cvs/src/sys/net/bpf.c,v retrieving revision 1.192 diff -u -p -r1.192 bpf.c --- sys/net/bpf.c 18 Jun 2020 23:32:00 -0000 1.192 +++ sys/net/bpf.c 17 Nov 2020 05:08:49 -0000 @@ -894,12 +894,21 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t /* * Get packet stats. */ + case BIOCGOSTATS: + { + struct bpf_ostat *bs = (struct bpf_ostat *)addr; + + bs->bs_recv = d->bd_rcount; + bs->bs_drop = d->bd_dcount; + break; + } case BIOCGSTATS: { struct bpf_stat *bs = (struct bpf_stat *)addr; bs->bs_recv = d->bd_rcount; bs->bs_drop = d->bd_dcount; + bs->bs_ifdrop = d->bd_icount; break; } @@ -1286,6 +1295,8 @@ _bpf_mtap(caddr_t arg, const struct mbuf struct bpf_insn *fcode = NULL; atomic_inc_long(&d->bd_rcount); + if (ISSET(mp->m_flags, M_PKTHDR)) + atomic_add_long(&d->bd_icount, mp->m_pkthdr.ph_drops); if (ISSET(d->bd_dirfilt, direction)) continue; Index: sys/net/bpf.h =================================================================== RCS file: /cvs/src/sys/net/bpf.h,v retrieving revision 1.70 diff -u -p -r1.70 bpf.h --- sys/net/bpf.h 3 Aug 2020 03:21:24 -0000 1.70 +++ sys/net/bpf.h 17 Nov 2020 05:08:49 -0000 @@ -70,6 +70,12 @@ struct bpf_program { struct bpf_stat { u_int bs_recv; /* number of packets received */ u_int bs_drop; /* number of packets dropped */ + u_int bs_ifdrop; /* number of packets dropped by interface */ +}; + +struct bpf_ostat { + u_int bs_recv; /* number of packets received */ + u_int bs_drop; /* number of packets dropped */ }; /* @@ -104,6 +110,7 @@ struct bpf_version { #define BIOCSETIF _IOW('B',108, struct ifreq) #define BIOCSRTIMEOUT _IOW('B',109, struct timeval) #define BIOCGRTIMEOUT _IOR('B',110, struct timeval) +#define BIOCGOSTATS _IOR('B',111, struct bpf_ostat) #define BIOCGSTATS _IOR('B',111, struct bpf_stat) #define BIOCIMMEDIATE _IOW('B',112, u_int) #define BIOCVERSION _IOR('B',113, struct bpf_version) Index: sys/net/bpfdesc.h =================================================================== RCS file: /cvs/src/sys/net/bpfdesc.h,v retrieving revision 1.41 diff -u -p -r1.41 bpfdesc.h --- sys/net/bpfdesc.h 13 May 2020 21:34:37 -0000 1.41 +++ sys/net/bpfdesc.h 17 Nov 2020 05:08:49 -0000 @@ -81,6 +81,7 @@ struct bpf_d { *bd_wfilter; /* write filter code */ u_long bd_rcount; /* number of packets received */ u_long bd_dcount; /* number of packets dropped */ + u_long bd_icount; /* number of packets dropped in hw */ u_char bd_promisc; /* true if listening promiscuously */ u_char bd_state; /* idle, waiting, or timed out */ Index: lib/libpcap/pcap-bpf.c =================================================================== RCS file: /cvs/src/lib/libpcap/pcap-bpf.c,v retrieving revision 1.37 diff -u -p -r1.37 pcap-bpf.c --- lib/libpcap/pcap-bpf.c 28 Jun 2019 13:32:42 -0000 1.37 +++ lib/libpcap/pcap-bpf.c 17 Nov 2020 05:08:49 -0000 @@ -63,6 +63,7 @@ pcap_stats(pcap_t *p, struct pcap_stat * ps->ps_recv = s.bs_recv; ps->ps_drop = s.bs_drop; + ps->ps_ifdrop = s.bs_ifdrop; return (0); }