From: visa Date: Wed, 31 May 2017 13:05:43 +0000 (+0000) Subject: Use mbuf_queue to properly serialize access to pflow output queue. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b52009cb2a2959efe436c1a8c49c494b9dac3bde;p=openbsd Use mbuf_queue to properly serialize access to pflow output queue. Input from mpi@, jmatthew@; OK mpi@, henning@, benno@ --- diff --git a/sys/net/if_pflow.c b/sys/net/if_pflow.c index 6af8a72f084..912f8f105a9 100644 --- a/sys/net/if_pflow.c +++ b/sys/net/if_pflow.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pflow.c,v 1.79 2017/05/30 21:57:39 benno Exp $ */ +/* $OpenBSD: if_pflow.c,v 1.80 2017/05/31 13:05:43 visa Exp $ */ /* * Copyright (c) 2011 Florian Obser @@ -128,11 +128,13 @@ pflow_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, void pflow_output_process(void *arg) { + struct mbuf_list ml; struct pflow_softc *sc = arg; struct mbuf *m; + mq_delist(&sc->sc_outputqueue, &ml); KERNEL_LOCK(); - while ((m = ml_dequeue(&sc->sc_outputqueue)) != NULL) { + while ((m = ml_dequeue(&ml)) != NULL) { pflow_sendout_mbuf(sc, m); } KERNEL_UNLOCK(); @@ -256,7 +258,7 @@ pflow_clone_create(struct if_clone *ifc, int unit) ifp->if_hdrlen = PFLOW_HDRLEN; ifp->if_flags = IFF_UP; ifp->if_flags &= ~IFF_RUNNING; /* not running, need receiver */ - ml_init(&pflowif->sc_outputqueue); + mq_init(&pflowif->sc_outputqueue, 8192, IPL_SOFTNET); pflow_setmtu(pflowif, ETHERMTU); pflow_init_timeouts(pflowif); if_attach(ifp); @@ -287,7 +289,7 @@ pflow_clone_destroy(struct ifnet *ifp) timeout_del(&sc->sc_tmo_tmpl); pflow_flush(sc); task_del(softnettq, &sc->sc_outputtask); - ml_purge(&sc->sc_outputqueue); + mq_purge(&sc->sc_outputqueue); m_freem(sc->send_nam); if (sc->so != NULL) { error = soclose(sc->so); @@ -1085,8 +1087,8 @@ pflow_sendout_v5(struct pflow_softc *sc) getnanotime(&tv); h->time_sec = htonl(tv.tv_sec); /* XXX 2038 */ h->time_nanosec = htonl(tv.tv_nsec); - ml_enqueue(&sc->sc_outputqueue, m); - task_add(softnettq, &sc->sc_outputtask); + if (mq_enqueue(&sc->sc_outputqueue, m) == 0) + task_add(softnettq, &sc->sc_outputtask); return (0); } @@ -1147,8 +1149,8 @@ pflow_sendout_ipfix(struct pflow_softc *sc, sa_family_t af) h10->flow_sequence = htonl(sc->sc_sequence); sc->sc_sequence += count; h10->observation_dom = htonl(PFLOW_ENGINE_TYPE); - ml_enqueue(&sc->sc_outputqueue, m); - task_add(softnettq, &sc->sc_outputtask); + if (mq_enqueue(&sc->sc_outputqueue, m) == 0) + task_add(softnettq, &sc->sc_outputtask); return (0); } @@ -1189,8 +1191,8 @@ pflow_sendout_ipfix_tmpl(struct pflow_softc *sc) h10->observation_dom = htonl(PFLOW_ENGINE_TYPE); timeout_add_sec(&sc->sc_tmo_tmpl, PFLOW_TMPL_TIMEOUT); - ml_enqueue(&sc->sc_outputqueue, m); - task_add(softnettq, &sc->sc_outputtask); + if (mq_enqueue(&sc->sc_outputqueue, m) == 0) + task_add(softnettq, &sc->sc_outputtask); return (0); } diff --git a/sys/net/if_pflow.h b/sys/net/if_pflow.h index b85a0e3f13e..0c4b76cdf88 100644 --- a/sys/net/if_pflow.h +++ b/sys/net/if_pflow.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pflow.h,v 1.16 2017/05/27 21:06:06 benno Exp $ */ +/* $OpenBSD: if_pflow.h,v 1.17 2017/05/31 13:05:43 visa Exp $ */ /* * Copyright (c) 2008 Henning Brauer @@ -184,7 +184,7 @@ struct pflow_softc { struct timeout sc_tmo; struct timeout sc_tmo6; struct timeout sc_tmo_tmpl; - struct mbuf_list sc_outputqueue; + struct mbuf_queue sc_outputqueue; struct task sc_outputtask; struct socket *so; struct mbuf *send_nam;