summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2020-01-22 22:56:36 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2020-01-22 22:56:36 +0000
commit0776f8f50b2f12a72955e4a497faf8670fcb1c09 (patch)
tree14b2af1e76743b96029deca19125b19ff6046ad0
parent8bd20b6618138fa8619ecf34f7ac13527a9e365f (diff)
add ml_hdatalen and mq_hdatalen as workalikes of ifq_hdatalen.
this is so pppx(4) and the upcoming pppac(4) can give kq read data dn FIONREAD values that makes sense like the ones tun(4) and tap(4) provide with ifq_hdatalen.
-rw-r--r--sys/kern/uipc_mbuf.c27
-rw-r--r--sys/sys/mbuf.h4
2 files changed, 29 insertions, 2 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index 843904086a9..1f2de1f6b24 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.273 2019/10/22 18:45:02 bluhm Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.274 2020/01/22 22:56:35 dlg Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -1634,6 +1634,19 @@ ml_purge(struct mbuf_list *ml)
return (len);
}
+unsigned int
+ml_hdatalen(struct mbuf_list *ml)
+{
+ struct mbuf *m;
+
+ m = ml->ml_head;
+ if (m == NULL)
+ return (0);
+
+ KASSERT(ISSET(m->m_flags, M_PKTHDR));
+ return (m->m_pkthdr.len);
+}
+
/*
* mbuf queues
*/
@@ -1732,6 +1745,18 @@ mq_purge(struct mbuf_queue *mq)
return (ml_purge(&ml));
}
+unsigned int
+mq_hdatalen(struct mbuf_queue *mq)
+{
+ unsigned int hdatalen;
+
+ mtx_enter(&mq->mq_mtx);
+ hdatalen = ml_hdatalen(&mq->mq_list);
+ mtx_leave(&mq->mq_mtx);
+
+ return (hdatalen);
+}
+
int
sysctl_mq(int *name, u_int namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen, struct mbuf_queue *mq)
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index 4c33080404b..a54b003754d 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbuf.h,v 1.245 2019/07/16 17:39:02 bluhm Exp $ */
+/* $OpenBSD: mbuf.h,v 1.246 2020/01/22 22:56:35 dlg Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
@@ -511,6 +511,7 @@ struct mbuf * ml_dequeue(struct mbuf_list *);
void ml_enlist(struct mbuf_list *, struct mbuf_list *);
struct mbuf * ml_dechain(struct mbuf_list *);
unsigned int ml_purge(struct mbuf_list *);
+unsigned int ml_hdatalen(struct mbuf_list *);
#define ml_len(_ml) ((_ml)->ml_len)
#define ml_empty(_ml) ((_ml)->ml_len == 0)
@@ -537,6 +538,7 @@ int mq_enlist(struct mbuf_queue *, struct mbuf_list *);
void mq_delist(struct mbuf_queue *, struct mbuf_list *);
struct mbuf * mq_dechain(struct mbuf_queue *);
unsigned int mq_purge(struct mbuf_queue *);
+unsigned int mq_hdatalen(struct mbuf_queue *);
#define mq_len(_mq) ml_len(&(_mq)->mq_list)
#define mq_empty(_mq) ml_empty(&(_mq)->mq_list)