kqueue stuff lets you provide some data when an event fires. generally things that you read and write (ie, file descriptors) provide how much data you can read or write. tun(4) provides how many packets you can read, and how many bytes you could write.
im arguing that the number of packets is inconsistent with everything else and should change. im also arguing we should calculate the maximum write userland can do better too. this is a very low impact change. i would bet that people use libevent, not kq directly, and libevent doesn't really provide a way to get to the kevent data. i just want to stop stumbling over the current code when im reading tun(4). ok? Index: if_tun.c =================================================================== RCS file: /cvs/src/sys/net/if_tun.c,v retrieving revision 1.189 diff -u -p -r1.189 if_tun.c --- if_tun.c 12 Sep 2019 01:28:29 -0000 1.189 +++ if_tun.c 12 Sep 2019 01:37:36 -0000 @@ -1008,9 +1008,6 @@ tun_dev_poll(struct tun_softc *tp, int e * * The tun driver uses an array of tun_softc's based on the minor number * of the device. kn->kn_hook gets set to the specific tun_softc. - * - * filt_tunread() sets kn->kn_data to the iface qsize - * filt_tunwrite() sets kn->kn_data to the MTU size */ int tunkqfilter(dev_t dev, struct knote *kn) @@ -1082,7 +1079,6 @@ filt_tunread(struct knote *kn, long hint { struct tun_softc *tp; struct ifnet *ifp; - unsigned int len; if (kn->kn_status & KN_DETACHED) { kn->kn_data = 0; @@ -1092,16 +1088,9 @@ filt_tunread(struct knote *kn, long hint tp = (struct tun_softc *)kn->kn_hook; ifp = &tp->tun_if; - len = IFQ_LEN(&ifp->if_snd); - if (len > 0) { - kn->kn_data = len; + kn->kn_data = ifq_hdatalen(&ifp->if_snd); - TUNDEBUG(("%s: tunkqread q=%d\n", ifp->if_xname, - IFQ_LEN(&ifp->if_snd))); - return (1); - } - TUNDEBUG(("%s: tunkqread waiting\n", ifp->if_xname)); - return (0); + return (kn->kn_data > 0); } void @@ -1131,7 +1120,7 @@ filt_tunwrite(struct knote *kn, long hin tp = (struct tun_softc *)kn->kn_hook; ifp = &tp->tun_if; - kn->kn_data = ifp->if_mtu; + kn->kn_data = ifp->if_hdrlen + ifp->if_hardmtu; return (1); }