From: dlg Date: Mon, 9 Jan 2023 03:37:44 +0000 (+0000) Subject: count the number times a packet was dropped by bpf as fdrops. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=52a758a031125f5ed45501df816cf873467e2bcc;p=openbsd count the number times a packet was dropped by bpf as fdrops. --- diff --git a/sys/net/ifq.c b/sys/net/ifq.c index 99777327d73..ce91a6569ee 100644 --- a/sys/net/ifq.c +++ b/sys/net/ifq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifq.c,v 1.47 2022/11/22 03:40:53 dlg Exp $ */ +/* $OpenBSD: ifq.c,v 1.48 2023/01/09 03:37:44 dlg Exp $ */ /* * Copyright (c) 2015 David Gwynne @@ -579,6 +579,7 @@ ifq_mfreeml(struct ifqueue *ifq, struct mbuf_list *ml) struct ifiq_kstat_data { struct kstat_kv kd_packets; struct kstat_kv kd_bytes; + struct kstat_kv kd_fdrops; struct kstat_kv kd_qdrops; struct kstat_kv kd_errors; struct kstat_kv kd_qlen; @@ -592,6 +593,8 @@ static const struct ifiq_kstat_data ifiq_kstat_tpl = { KSTAT_KV_T_COUNTER64, KSTAT_KV_U_PACKETS), KSTAT_KV_UNIT_INITIALIZER("bytes", KSTAT_KV_T_COUNTER64, KSTAT_KV_U_BYTES), + KSTAT_KV_UNIT_INITIALIZER("fdrops", + KSTAT_KV_T_COUNTER64, KSTAT_KV_U_PACKETS), KSTAT_KV_UNIT_INITIALIZER("qdrops", KSTAT_KV_T_COUNTER64, KSTAT_KV_U_PACKETS), KSTAT_KV_UNIT_INITIALIZER("errors", @@ -614,6 +617,7 @@ ifiq_kstat_copy(struct kstat *ks, void *dst) *kd = ifiq_kstat_tpl; kstat_kv_u64(&kd->kd_packets) = ifiq->ifiq_packets; kstat_kv_u64(&kd->kd_bytes) = ifiq->ifiq_bytes; + kstat_kv_u64(&kd->kd_fdrops) = ifiq->ifiq_fdrops; kstat_kv_u64(&kd->kd_qdrops) = ifiq->ifiq_qdrops; kstat_kv_u64(&kd->kd_errors) = ifiq->ifiq_errors; kstat_kv_u32(&kd->kd_qlen) = ml_len(&ifiq->ifiq_ml); @@ -641,6 +645,7 @@ ifiq_init(struct ifiqueue *ifiq, struct ifnet *ifp, unsigned int idx) ifiq->ifiq_packets = 0; ifiq->ifiq_bytes = 0; + ifiq->ifiq_fdrops = 0; ifiq->ifiq_qdrops = 0; ifiq->ifiq_errors = 0; @@ -684,6 +689,7 @@ ifiq_input(struct ifiqueue *ifiq, struct mbuf_list *ml) struct mbuf *m; uint64_t packets; uint64_t bytes = 0; + uint64_t fdrops = 0; unsigned int len; #if NBPFILTER > 0 caddr_t if_bpf; @@ -707,9 +713,10 @@ ifiq_input(struct ifiqueue *ifiq, struct mbuf_list *ml) ml_init(ml); while ((m = ml_dequeue(&ml0)) != NULL) { - if ((*ifp->if_bpf_mtap)(if_bpf, m, BPF_DIRECTION_IN)) + if ((*ifp->if_bpf_mtap)(if_bpf, m, BPF_DIRECTION_IN)) { m_freem(m); - else + fdrops++; + } else ml_enqueue(ml, m); } @@ -717,6 +724,7 @@ ifiq_input(struct ifiqueue *ifiq, struct mbuf_list *ml) mtx_enter(&ifiq->ifiq_mtx); ifiq->ifiq_packets += packets; ifiq->ifiq_bytes += bytes; + ifiq->ifiq_fdrops += fdrops; mtx_leave(&ifiq->ifiq_mtx); return (0); @@ -727,6 +735,7 @@ ifiq_input(struct ifiqueue *ifiq, struct mbuf_list *ml) mtx_enter(&ifiq->ifiq_mtx); ifiq->ifiq_packets += packets; ifiq->ifiq_bytes += bytes; + ifiq->ifiq_fdrops += fdrops; len = ml_len(&ifiq->ifiq_ml); if (__predict_true(!ISSET(ifp->if_xflags, IFXF_MONITOR))) { diff --git a/sys/net/ifq.h b/sys/net/ifq.h index 18c4dc555de..ac14eefe3c7 100644 --- a/sys/net/ifq.h +++ b/sys/net/ifq.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ifq.h,v 1.36 2023/01/04 03:47:10 dlg Exp $ */ +/* $OpenBSD: ifq.h,v 1.37 2023/01/09 03:37:44 dlg Exp $ */ /* * Copyright (c) 2015 David Gwynne @@ -90,6 +90,7 @@ struct ifiqueue { /* counters */ uint64_t ifiq_packets; uint64_t ifiq_bytes; + uint64_t ifiq_fdrops; uint64_t ifiq_qdrops; uint64_t ifiq_errors; uint64_t ifiq_mcasts;