From 0f9e55b1061457d40a93e39bf88ec59f010fc856 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 26 Mar 2011 15:15:34 -0700 Subject: [PATCH] kernel - Change mbuf allocation in tapwrite/tunwrite path to blocking * Tapwrite and tunwrite are called via userland, a blocking mbuf allocation is perfectly acceptable here and avoids dropping packets unnecessarily. * Fixes numerous spurious packet drops when using TAP or TUN, for example with openvpn. * Minor code cleanup in if_tap.c --- sys/net/tap/if_tap.c | 12 +++++++----- sys/net/tun/if_tun.c | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sys/net/tap/if_tap.c b/sys/net/tap/if_tap.c index 35152eaa2a..fb74f2785a 100644 --- a/sys/net/tap/if_tap.c +++ b/sys/net/tap/if_tap.c @@ -890,7 +890,7 @@ tapwrite(struct dev_write_args *ap) struct tap_softc *tp = dev->si_drv1; struct ifnet *ifp = &tp->tap_if; struct mbuf *top = NULL, **mp = NULL, *m = NULL; - int error = 0; + int error; size_t tlen, mlen; TAPDEBUG(ifp, "writing, minor = %#x\n", minor(tp->tap_dev)); @@ -913,20 +913,22 @@ tapwrite(struct dev_write_args *ap) tlen = uio->uio_resid; /* get a header mbuf */ - MGETHDR(m, MB_DONTWAIT, MT_DATA); + MGETHDR(m, MB_WAIT, MT_DATA); if (m == NULL) return (ENOBUFS); mlen = MHLEN; - top = 0; + top = NULL; mp = ⊤ - while ((error == 0) && (uio->uio_resid > 0)) { + error = 0; + + while (error == 0 && uio->uio_resid > 0) { m->m_len = (int)szmin(mlen, uio->uio_resid); error = uiomove(mtod(m, caddr_t), (size_t)m->m_len, uio); *mp = m; mp = &m->m_next; if (uio->uio_resid > 0) { - MGET(m, MB_DONTWAIT, MT_DATA); + MGET(m, MB_WAIT, MT_DATA); if (m == NULL) { error = ENOBUFS; break; diff --git a/sys/net/tun/if_tun.c b/sys/net/tun/if_tun.c index 54cb34fdff..4be909d078 100644 --- a/sys/net/tun/if_tun.c +++ b/sys/net/tun/if_tun.c @@ -602,12 +602,12 @@ tunwrite(struct dev_write_args *ap) tlen = uio->uio_resid; /* get a header mbuf */ - MGETHDR(m, MB_DONTWAIT, MT_DATA); + MGETHDR(m, MB_WAIT, MT_DATA); if (m == NULL) return ENOBUFS; mlen = MHLEN; - top = 0; + top = NULL; mp = ⊤ while (error == 0 && uio->uio_resid > 0) { m->m_len = (int)szmin(mlen, uio->uio_resid); @@ -615,7 +615,7 @@ tunwrite(struct dev_write_args *ap) *mp = m; mp = &m->m_next; if (uio->uio_resid > 0) { - MGET (m, MB_DONTWAIT, MT_DATA); + MGET (m, MB_WAIT, MT_DATA); if (m == 0) { error = ENOBUFS; break; -- 2.41.0