Index: sys/net/if_tun.c =================================================================== RCS file: /cvs/src/sys/net/if_tun.c,v retrieving revision 1.181 diff -u -p -r1.181 if_tun.c --- sys/net/if_tun.c 24 Feb 2018 07:20:04 -0000 1.181 +++ sys/net/if_tun.c 29 Oct 2018 02:03:44 -0000 @@ -667,8 +667,7 @@ tun_dev_ioctl(struct tun_softc *tp, u_lo tp->tun_flags &= ~TUN_ASYNC; break; case FIONREAD: - *(int *)data = ifq_empty(&tp->tun_if.if_snd) ? - 0 : tp->tun_if.if_mtu; + *(int *)data = ifq_hdatalen(&tp->tun_if.if_snd); break; case TIOCSPGRP: tp->tun_pgid = *(int *)data; Index: sys/net/ifq.c =================================================================== RCS file: /cvs/src/sys/net/ifq.c,v retrieving revision 1.22 diff -u -p -r1.22 ifq.c --- sys/net/ifq.c 25 Jan 2018 14:04:36 -0000 1.22 +++ sys/net/ifq.c 29 Oct 2018 02:03:44 -0000 @@ -357,6 +357,21 @@ ifq_dequeue(struct ifqueue *ifq) return (m); } +int +ifq_hdatalen(struct ifqueue *ifq) +{ + struct mbuf *m; + int len = 0; + + m = ifq_deq_begin(ifq); + if (m != NULL) { + len = m->m_pkthdr.len; + ifq_deq_commit(ifq, m); + } + + return (len); +} + unsigned int ifq_purge(struct ifqueue *ifq) { Index: sys/net/ifq.h =================================================================== RCS file: /cvs/src/sys/net/ifq.h,v retrieving revision 1.20 diff -u -p -r1.20 ifq.h --- sys/net/ifq.h 4 Jan 2018 11:02:57 -0000 1.20 +++ sys/net/ifq.h 29 Oct 2018 02:03:44 -0000 @@ -409,6 +409,7 @@ struct mbuf *ifq_deq_begin(struct ifqueu void ifq_deq_commit(struct ifqueue *, struct mbuf *); void ifq_deq_rollback(struct ifqueue *, struct mbuf *); struct mbuf *ifq_dequeue(struct ifqueue *); +int ifq_hdatalen(struct ifqueue *); void ifq_mfreem(struct ifqueue *, struct mbuf *); void ifq_mfreeml(struct ifqueue *, struct mbuf_list *); unsigned int ifq_purge(struct ifqueue *); Index: share/man/man9/ifq_enqueue.9 =================================================================== RCS file: /cvs/src/share/man/man9/ifq_enqueue.9,v retrieving revision 1.9 diff -u -p -r1.9 ifq_enqueue.9 --- share/man/man9/ifq_enqueue.9 10 Dec 2015 06:58:56 -0000 1.9 +++ share/man/man9/ifq_enqueue.9 29 Oct 2018 02:03:44 -0000 @@ -23,6 +23,7 @@ .Nm ifq_purge , .Nm ifq_len , .Nm ifq_empty , +.Nm ifq_hdatalen , .Nm ifq_set_oactive , .Nm ifq_clr_oactive , .Nm ifq_is_oactive , @@ -41,6 +42,8 @@ .Fn ifq_len "struct ifqueue *ifq" .Ft unsigned int .Fn ifq_empty "struct ifqueue *ifq" +.Ft int +.Fn ifq_hdatalen "struct ifqueue *ifq" .Ft void .Fn ifq_set_oactive "struct ifqueue *ifq" .Ft void @@ -87,6 +90,10 @@ or Return if the interface send queue .Fa ifq is empty. +.It Fn ifq_hdatalen "struct ifqueue *ifq" +Return the number of bytes in the mbuf at the head of the interface +send queue +.Fa ifq . .It Fn ifq_set_oactive "struct ifqueue *ifq" .Fn ifq_set_oactive is called by the relevant driver to mark the hardware associated @@ -125,6 +132,7 @@ returns. .Fn ifq_purge , .Fn ifq_len , .Fn ifq_empty , +.Fn ifq_hdatalen , .Fn ifq_set_oactive , .Fn ifq_clr_oactive , .Fn ifq_is_oactive , @@ -152,6 +160,9 @@ returns the number of mbufs on the queue .Pp .Fn ifq_empty returns a non-zero value if the queue is empty, otherwise 0. +.Pp +.Fn ifq_hdatalen +returns the size of a packet on the queue, or 0 if the queue is empty; .Pp .Fn ifq_is_oactive returns a non-zero value if the hardware associated with the interface