summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2020-06-21 05:37:26 +0000
committerdlg <dlg@openbsd.org>2020-06-21 05:37:26 +0000
commit6281916f49597dc1fbe9d42916a18886ab02a325 (patch)
tree0d10130fd404cdb3d2e0db0cdf955958f615829c
parentwrap a long line. no functional change. (diff)
downloadwireguard-openbsd-6281916f49597dc1fbe9d42916a18886ab02a325.tar.xz
wireguard-openbsd-6281916f49597dc1fbe9d42916a18886ab02a325.zip
add mq_push. it's like mq_enqueue, but drops from the head, not the tail.
from Matt Dunwoodie and Jason A. Donenfeld
-rw-r--r--sys/kern/uipc_mbuf.c21
-rw-r--r--sys/sys/mbuf.h3
2 files changed, 22 insertions, 2 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index 1f2de1f6b24..13342359099 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.274 2020/01/22 22:56:35 dlg Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.275 2020/06/21 05:37:26 dlg Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -1660,6 +1660,25 @@ mq_init(struct mbuf_queue *mq, u_int maxlen, int ipl)
}
int
+mq_push(struct mbuf_queue *mq, struct mbuf *m)
+{
+ struct mbuf *dropped = NULL;
+
+ mtx_enter(&mq->mq_mtx);
+ if (mq_len(mq) >= mq->mq_maxlen) {
+ mq->mq_drops++;
+ dropped = ml_dequeue(&mq->mq_list);
+ }
+ ml_enqueue(&mq->mq_list, m);
+ mtx_leave(&mq->mq_mtx);
+
+ if (dropped)
+ m_freem(dropped);
+
+ return (dropped != NULL);
+}
+
+int
mq_enqueue(struct mbuf_queue *mq, struct mbuf *m)
{
int dropped = 0;
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index f63f7356f88..f5a1077169e 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbuf.h,v 1.247 2020/06/17 06:45:22 dlg Exp $ */
+/* $OpenBSD: mbuf.h,v 1.248 2020/06/21 05:37:26 dlg Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
@@ -529,6 +529,7 @@ unsigned int ml_hdatalen(struct mbuf_list *);
{ MUTEX_INITIALIZER(_ipl), MBUF_LIST_INITIALIZER(), (_maxlen), 0 }
void mq_init(struct mbuf_queue *, u_int, int);
+int mq_push(struct mbuf_queue *, struct mbuf *);
int mq_enqueue(struct mbuf_queue *, struct mbuf *);
struct mbuf * mq_dequeue(struct mbuf_queue *);
int mq_enlist(struct mbuf_queue *, struct mbuf_list *);