summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2017-01-20 03:48:03 +0000
committerdlg <dlg@openbsd.org>2017-01-20 03:48:03 +0000
commitd071e2e37ff915f88f5f3d5251bcf5b281db1c2b (patch)
tree04a5388db75f79a83bd1632d639933c3a95cdf99
parentIn "%.*s" the * takes (int). gcc whines if you try to use the result (diff)
downloadwireguard-openbsd-d071e2e37ff915f88f5f3d5251bcf5b281db1c2b.tar.xz
wireguard-openbsd-d071e2e37ff915f88f5f3d5251bcf5b281db1c2b.zip
keep output packet counters on the ifq structure.
these copy what is counted on the output path on the ifnet struct, except ifq counts both packets and bytes when a packet is queued instead of just the bytes. all the counters are protected by the ifq mutex except for ifq_errors, which can be updated safely from inside a start routine because the ifq machinery serialises them. ok mpi@
-rw-r--r--sys/net/ifq.c19
-rw-r--r--sys/net/ifq.h10
2 files changed, 20 insertions, 9 deletions
diff --git a/sys/net/ifq.c b/sys/net/ifq.c
index ac820f09f3c..e92d6f09490 100644
--- a/sys/net/ifq.c
+++ b/sys/net/ifq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifq.c,v 1.4 2015/12/29 12:35:43 dlg Exp $ */
+/* $OpenBSD: ifq.c,v 1.5 2017/01/20 03:48:03 dlg Exp $ */
/*
* Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
@@ -172,7 +172,7 @@ ifq_init(struct ifqueue *ifq, struct ifnet *ifp)
ifq->ifq_if = ifp;
mtx_init(&ifq->ifq_mtx, IPL_NET);
- ifq->ifq_drops = 0;
+ ifq->ifq_qdrops = 0;
/* default to priq */
ifq->ifq_ops = &priq_ops;
@@ -214,7 +214,7 @@ ifq_attach(struct ifqueue *ifq, const struct ifq_ops *newops, void *opsarg)
while ((m = ml_dequeue(&ml)) != NULL) {
if (ifq->ifq_ops->ifqop_enq(ifq, m) != 0) {
- ifq->ifq_drops++;
+ ifq->ifq_qdrops++;
ml_enqueue(&free_ml, m);
} else
ifq->ifq_len++;
@@ -246,10 +246,15 @@ ifq_enqueue_try(struct ifqueue *ifq, struct mbuf *m)
mtx_enter(&ifq->ifq_mtx);
rv = ifq->ifq_ops->ifqop_enq(ifq, m);
- if (rv == 0)
+ if (rv == 0) {
ifq->ifq_len++;
- else
- ifq->ifq_drops++;
+
+ ifq->ifq_packets++;
+ ifq->ifq_bytes += m->m_pkthdr.len;
+ if (ISSET(m->m_flags, M_MCAST))
+ ifq->ifq_mcasts++;
+ } else
+ ifq->ifq_qdrops++;
mtx_leave(&ifq->ifq_mtx);
return (rv);
@@ -330,7 +335,7 @@ ifq_purge(struct ifqueue *ifq)
ifq->ifq_ops->ifqop_purge(ifq, &ml);
rv = ifq->ifq_len;
ifq->ifq_len = 0;
- ifq->ifq_drops += rv;
+ ifq->ifq_qdrops += rv;
mtx_leave(&ifq->ifq_mtx);
KASSERT(rv == ml_len(&ml));
diff --git a/sys/net/ifq.h b/sys/net/ifq.h
index 082c91864d0..cf53bc702b0 100644
--- a/sys/net/ifq.h
+++ b/sys/net/ifq.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifq.h,v 1.5 2016/01/20 17:27:16 mikeb Exp $ */
+/* $OpenBSD: ifq.h,v 1.6 2017/01/20 03:48:03 dlg Exp $ */
/*
* Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
@@ -28,12 +28,18 @@ struct ifqueue {
/* mbuf handling */
struct mutex ifq_mtx;
- uint64_t ifq_drops;
const struct ifq_ops *ifq_ops;
void *ifq_q;
unsigned int ifq_len;
unsigned int ifq_oactive;
+ /* statistics */
+ uint64_t ifq_packets;
+ uint64_t ifq_bytes;
+ uint64_t ifq_qdrops;
+ uint64_t ifq_errors;
+ uint64_t ifq_mcasts;
+
/* work serialisation */
struct mutex ifq_task_mtx;
struct task_list ifq_task_list;