From 3d1447fe2f0f4d3a88c329b97edb0016b046bc51 Mon Sep 17 00:00:00 2001 From: David Gwynne Date: Sun, 17 Nov 2024 23:21:46 +0000 Subject: include tun_hdr in the length reported by FIONREAD and kq if it's enabled. --- sys/net/if_tun.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'sys') diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index a1a84104066..aaef6111ee3 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_tun.c,v 1.247 2024/11/17 00:25:07 dlg Exp $ */ +/* $OpenBSD: if_tun.c,v 1.248 2024/11/17 23:21:45 dlg Exp $ */ /* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */ /* @@ -681,6 +681,19 @@ tun_del_capabilities(struct tun_softc *sc) return (0); } +static int +tun_hdatalen(struct tun_softc *sc) +{ + struct ifnet *ifp = &sc->sc_if; + int len; + + len = ifq_hdatalen(&ifp->if_snd); + if (len > 0 && ISSET(sc->sc_flags, TUN_HDR)) + len += sizeof(struct tun_hdr); + + return (len); +} + int tun_dev_ioctl(dev_t dev, u_long cmd, void *data) { @@ -753,7 +766,7 @@ tun_dev_ioctl(dev_t dev, u_long cmd, void *data) sc->sc_flags &= ~TUN_ASYNC; break; case FIONREAD: - *(int *)data = ifq_hdatalen(&sc->sc_if.if_snd); + *(int *)data = tun_hdatalen(sc); break; case FIOSETOWN: case TIOCSPGRP: @@ -1103,11 +1116,10 @@ int filt_tunread(struct knote *kn, long hint) { struct tun_softc *sc = kn->kn_hook; - struct ifnet *ifp = &sc->sc_if; MUTEX_ASSERT_LOCKED(&sc->sc_mtx); - kn->kn_data = ifq_hdatalen(&ifp->if_snd); + kn->kn_data = tun_hdatalen(sc); return (kn->kn_data > 0); } -- cgit v1.2.3