Index: kern/uipc_mbuf.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v retrieving revision 1.197 diff -u -p -r1.197 uipc_mbuf.c --- kern/uipc_mbuf.c 3 Oct 2014 02:16:21 -0000 1.197 +++ kern/uipc_mbuf.c 10 Oct 2014 04:09:19 -0000 @@ -1309,6 +1309,35 @@ ml_dechain(struct mbuf_list *ml) return (m0); } +struct mbuf * +ml_filter(struct mbuf_list *ml, + int (*filter)(void *, const struct mbuf *), void *ctx) +{ + struct mbuf_list matches = MBUF_LIST_INITIALIZER(); + struct mbuf *m, *n; + struct mbuf **mp; + + mp = &ml->ml_head; + + for (m = ml->ml_head; m != NULL; m = n) { + n = m->m_nextpkt; + if ((*filter)(ctx, m)) { + *mp = n; + ml_enqueue(&matches, m); + } else { + mp = &m->m_nextpkt; + ml->ml_tail = m; + } + } + + /* fixup ml */ + if (ml->ml_head == NULL) + ml->ml_tail = NULL; + ml->ml_len -= ml_len(&matches); + + return (matches.ml_head); /* ml_dechain */ +} + /* * mbuf queues */ @@ -1382,6 +1411,19 @@ mq_dechain(struct mbuf_queue *mq) mtx_enter(&mq->mq_mtx); m0 = ml_dechain(&mq->mq_list); + mtx_leave(&mq->mq_mtx); + + return (m0); +} + +struct mbuf * +mq_filter(struct mbuf_queue *mq, + int (*filter)(void *, const struct mbuf *), void *ctx) +{ + struct mbuf *m0; + + mtx_enter(&mq->mq_mtx); + m0 = ml_filter(&mq->mq_list, filter, ctx); mtx_leave(&mq->mq_mtx); return (m0); Index: net/if.c =================================================================== RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.301 diff -u -p -r1.301 if.c --- net/if.c 30 Sep 2014 08:27:57 -0000 1.301 +++ net/if.c 10 Oct 2014 04:09:19 -0000 @@ -135,6 +135,8 @@ void if_attachdomain1(struct ifnet *); void if_attach_common(struct ifnet *); void if_detach_queues(struct ifnet *, struct ifqueue *); +int if_detach_filter(void *, const struct mbuf *); +void if_detach_mq(struct ifnet *, struct mbuf_queue *); void if_detached_start(struct ifnet *); int if_detached_ioctl(struct ifnet *, u_long, caddr_t); void if_detached_watchdog(struct ifnet *); @@ -563,10 +565,16 @@ do { \ } while (0) #ifdef INET IF_DETACH_QUEUES(arpintrq); - IF_DETACH_QUEUES(ipintrq); + { + extern struct mbuf_queue ipintrq; + if_detach_mq(ifp, &ipintrq); + } #endif #ifdef INET6 - IF_DETACH_QUEUES(ip6intrq); + { + extern struct mbuf_queue ip6intrq; + if_detach_mq(ifp, &ip6intrq); + } #endif #undef IF_DETACH_QUEUES @@ -649,6 +657,34 @@ if_detach_queues(struct ifnet *ifp, stru } } +int +if_detach_filter(void *ctx, const struct mbuf *m) +{ + struct ifnet *ifp = ctx; + +#ifdef DIAGNOSTIC + if (!ISSET(m->m_flags, M_PKTHDR)) + return (0); +#endif + + return (m->m_pkthdr.rcvif == ifp); +} + +void +if_detach_mq(struct ifnet *ifp, struct mbuf_queue *mq) +{ + struct mbuf *m0, *m; + + m0 = mq_filter(mq, if_detach_filter, ifp); + while (m0 != NULL) { + m = m0; + m0 = m->m_nextpkt; + + m->m_nextpkt = NULL; + m_freem(m); + } +} + /* * Create a clone network interface. */ @@ -2222,6 +2258,28 @@ sysctl_ifq(int *name, u_int namelen, voi &ifq->ifq_maxlen)); case IFQCTL_DROPS: return (sysctl_rdint(oldp, oldlenp, newp, ifq->ifq_drops)); + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ +} + +int +sysctl_mq(int *name, u_int namelen, void *oldp, size_t *oldlenp, + void *newp, size_t newlen, struct mbuf_queue *mq) +{ + /* All sysctl names at this level are terminal. */ + if (namelen != 1) + return (ENOTDIR); + + switch (name[0]) { + case IFQCTL_LEN: + return (sysctl_rdint(oldp, oldlenp, newp, mq_len(mq))); + case IFQCTL_MAXLEN: + return (sysctl_int(oldp, oldlenp, newp, newlen, + &mq->mq_maxlen)); /* XXX */ + case IFQCTL_DROPS: + return (sysctl_rdint(oldp, oldlenp, newp, mq_drops(mq))); default: return (EOPNOTSUPP); } Index: net/if_ethersubr.c =================================================================== RCS file: /cvs/src/sys/net/if_ethersubr.c,v retrieving revision 1.174 diff -u -p -r1.174 if_ethersubr.c --- net/if_ethersubr.c 12 Jul 2014 18:44:22 -0000 1.174 +++ net/if_ethersubr.c 10 Oct 2014 04:09:19 -0000 @@ -632,9 +632,9 @@ decapsulate: switch (etype) { #ifdef INET case ETHERTYPE_IP: - schednetisr(NETISR_IP); - inq = &ipintrq; - break; + if (mq_enqueue(&ipintrq, m) == 0) + schednetisr(NETISR_IP); + goto done; case ETHERTYPE_ARP: if (ifp->if_flags & IFF_NOARP) @@ -655,9 +655,9 @@ decapsulate: * Schedule IPv6 software interrupt for incoming IPv6 packet. */ case ETHERTYPE_IPV6: - schednetisr(NETISR_IPV6); - inq = &ip6intrq; - break; + if (mq_enqueue(&ip6intrq, m) == 0) + schednetisr(NETISR_IPV6); + goto done; #endif /* INET6 */ #if NPPPOE > 0 || defined(PIPEX) case ETHERTYPE_PPPOEDISC: @@ -700,9 +700,9 @@ decapsulate: #ifdef MPLS case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MCAST: - inq = &mplsintrq; - schednetisr(NETISR_MPLS); - break; + if (mq_enqueue(&mplsintrq, m) == 0) + schednetisr(NETISR_MPLS); + goto done; #endif default: if (llcfound || etype > ETHERMTU) Index: net/if_loop.c =================================================================== RCS file: /cvs/src/sys/net/if_loop.c,v retrieving revision 1.58 diff -u -p -r1.58 if_loop.c --- net/if_loop.c 7 Oct 2014 08:47:28 -0000 1.58 +++ net/if_loop.c 10 Oct 2014 04:09:19 -0000 @@ -206,8 +206,8 @@ int looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt) { - int s, isr; - struct ifqueue *ifq = 0; + int isr; + struct mbuf_queue *ifq; if ((m->m_flags & M_PKTHDR) == 0) panic("looutput: no header mbuf"); @@ -236,7 +236,7 @@ looutput(struct ifnet *ifp, struct mbuf case AF_INET: ifq = &ipintrq; isr = NETISR_IP; - break; + return (0); #endif #ifdef INET6 case AF_INET6: @@ -256,18 +256,14 @@ looutput(struct ifnet *ifp, struct mbuf m_freem(m); return (EAFNOSUPPORT); } - s = splnet(); - if (IF_QFULL(ifq)) { - IF_DROP(ifq); - m_freem(m); - splx(s); + + if (mq_enqueue(ifq, m) != 0) return (ENOBUFS); - } - IF_ENQUEUE(ifq, m); + schednetisr(isr); ifp->if_ipackets++; ifp->if_ibytes += m->m_pkthdr.len; - splx(s); + return (0); } Index: net/if_mpe.c =================================================================== RCS file: /cvs/src/sys/net/if_mpe.c,v retrieving revision 1.36 diff -u -p -r1.36 if_mpe.c --- net/if_mpe.c 7 Oct 2014 08:59:50 -0000 1.36 +++ net/if_mpe.c 10 Oct 2014 04:09:19 -0000 @@ -358,7 +358,7 @@ mpe_input(struct mbuf *m, struct ifnet * u_int8_t ttl) { struct ip *ip; - int s, hlen; + int hlen; /* label -> AF lookup */ @@ -395,10 +395,8 @@ mpe_input(struct mbuf *m, struct ifnet * if (ifp && ifp->if_bpf) bpf_mtap_af(ifp->if_bpf, AF_INET, m, BPF_DIRECTION_IN); #endif - s = splnet(); - IF_INPUT_ENQUEUE(&ipintrq, m); - schednetisr(NETISR_IP); - splx(s); + if (mq_enqueue(&ipintrq, m) == 0) + schednetisr(NETISR_IP); } #ifdef INET6 @@ -407,7 +405,6 @@ mpe_input6(struct mbuf *m, struct ifnet u_int8_t ttl) { struct ip6_hdr *ip6hdr; - int s; /* label -> AF lookup */ @@ -430,10 +427,9 @@ mpe_input6(struct mbuf *m, struct ifnet if (ifp && ifp->if_bpf) bpf_mtap_af(ifp->if_bpf, AF_INET6, m, BPF_DIRECTION_IN); #endif - s = splnet(); - IF_INPUT_ENQUEUE(&ip6intrq, m); - schednetisr(NETISR_IPV6); - splx(s); + + if (mq_enqueue(&ip6intrq, m) == 0) + schednetisr(NETISR_IPV6); } #endif /* INET6 */ Index: net/if_ppp.c =================================================================== RCS file: /cvs/src/sys/net/if_ppp.c,v retrieving revision 1.76 diff -u -p -r1.76 if_ppp.c --- net/if_ppp.c 22 Jul 2014 11:06:09 -0000 1.76 +++ net/if_ppp.c 10 Oct 2014 04:09:19 -0000 @@ -242,7 +242,7 @@ ppp_clone_create(struct if_clone *ifc, i sc->sc_if.if_output = pppoutput; sc->sc_if.if_start = ppp_ifstart; IFQ_SET_MAXLEN(&sc->sc_if.if_snd, IFQ_MAXLEN); - IFQ_SET_MAXLEN(&sc->sc_inq, IFQ_MAXLEN); + mq_init(&sc->sc_inq, IFQ_MAXLEN, IPL_NET); IFQ_SET_MAXLEN(&sc->sc_fastq, IFQ_MAXLEN); IFQ_SET_MAXLEN(&sc->sc_rawq, IFQ_MAXLEN); IFQ_SET_READY(&sc->sc_if.if_snd); @@ -339,12 +339,8 @@ pppdealloc(struct ppp_softc *sc) break; m_freem(m); } - for (;;) { - IF_DEQUEUE(&sc->sc_inq, m); - if (m == NULL) - break; + while ((m = mq_dequeue(&sc->sc_inq)) != NULL) m_freem(m); - } for (;;) { IF_DEQUEUE(&sc->sc_fastq, m); if (m == NULL) @@ -408,7 +404,7 @@ pppioctl(struct ppp_softc *sc, u_long cm switch (cmd) { case FIONREAD: - *(int *)data = IFQ_LEN(&sc->sc_inq); + *(int *)data = mq_len(&sc->sc_inq); break; case PPPIOCGUNIT: @@ -1236,7 +1232,7 @@ static void ppp_inproc(struct ppp_softc *sc, struct mbuf *m) { struct ifnet *ifp = &sc->sc_if; - struct ifqueue *inq; + struct mbuf_queue *inq; int s, ilen, xlen, proto, rv; u_char *cp, adrs, ctrl; struct mbuf *mp, *dmp = NULL; @@ -1471,10 +1467,10 @@ ppp_inproc(struct ppp_softc *sc, struct m_freem(m); return; } + m->m_pkthdr.len -= PPP_HDRLEN; m->m_data += PPP_HDRLEN; m->m_len -= PPP_HDRLEN; - schednetisr(NETISR_IP); inq = &ipintrq; break; #endif @@ -1491,29 +1487,27 @@ ppp_inproc(struct ppp_softc *sc, struct /* * Put the packet on the appropriate input queue. */ - s = splnet(); - if (IF_QFULL(inq)) { - IF_DROP(inq); - splx(s); + if (mq_enqueue(&sc->sc_inq, m) != 0) { if (sc->sc_flags & SC_DEBUG) printf("%s: input queue full\n", ifp->if_xname); ifp->if_iqdrops++; - if (!inq->ifq_congestion) - if_congestion(inq); - goto bad; + goto dropped; } - IF_ENQUEUE(inq, m); - splx(s); ifp->if_ipackets++; ifp->if_ibytes += ilen; if (rv) (*sc->sc_ctlp)(sc); +#ifdef INET + else + schednetisr(NETISR_IP); +#endif /* INET */ return; bad: m_freem(m); + dropped: sc->sc_if.if_ierrors++; sc->sc_stats.ppp_ierrors++; } Index: net/if_pppvar.h =================================================================== RCS file: /cvs/src/sys/net/if_pppvar.h,v retrieving revision 1.15 diff -u -p -r1.15 if_pppvar.h --- net/if_pppvar.h 7 Dec 2003 15:41:27 -0000 1.15 +++ net/if_pppvar.h 10 Oct 2014 04:09:19 -0000 @@ -98,7 +98,7 @@ struct ppp_softc { u_int16_t sc_mru; /* max receive unit */ pid_t sc_xfer; /* used in transferring unit */ struct ifqueue sc_rawq; /* received packets */ - struct ifqueue sc_inq; /* queue of input packets for daemon */ + struct mbuf_queue sc_inq; /* queue of input packets for daemon */ struct ifqueue sc_fastq; /* interactive output packet q */ struct mbuf *sc_togo; /* output packet ready to go */ struct mbuf *sc_npqueue; /* output packets not to be sent yet */ Index: net/if_pppx.c =================================================================== RCS file: /cvs/src/sys/net/if_pppx.c,v retrieving revision 1.34 diff -u -p -r1.34 if_pppx.c --- net/if_pppx.c 8 Sep 2014 06:24:13 -0000 1.34 +++ net/if_pppx.c 10 Oct 2014 04:09:19 -0000 @@ -319,9 +319,9 @@ pppxwrite(dev_t dev, struct uio *uio, in /* struct pppx_dev *pxd = pppx_dev2pxd(dev); */ struct pppx_hdr *th; struct mbuf *top, **mp, *m; - struct ifqueue *ifq; + struct mbuf_queue *ifq; int tlen, mlen; - int isr, s, error = 0; + int isr, error = 0; if (uio->uio_resid < sizeof(*th) || uio->uio_resid > MCLBYTES) return (EMSGSIZE); @@ -398,16 +398,10 @@ pppxwrite(dev_t dev, struct uio *uio, in return (EAFNOSUPPORT); } - s = splnet(); - if (IF_QFULL(ifq)) { - IF_DROP(ifq); - splx(s); - m_freem(top); + if (mq_enqueue(ifq, top) != 0) return (ENOBUFS); - } - IF_ENQUEUE(ifq, top); + schednetisr(isr); - splx(s); return (error); } Index: net/if_spppsubr.c =================================================================== RCS file: /cvs/src/sys/net/if_spppsubr.c,v retrieving revision 1.125 diff -u -p -r1.125 if_spppsubr.c --- net/if_spppsubr.c 22 Jul 2014 11:06:09 -0000 1.125 +++ net/if_spppsubr.c 10 Oct 2014 04:09:19 -0000 @@ -466,9 +466,10 @@ sppp_input(struct ifnet *ifp, struct mbu SPP_FMT "input packet is too small, %d bytes\n", SPP_ARGS(ifp), m->m_pkthdr.len); drop: + m_freem (m); + dropped: ++ifp->if_ierrors; ++ifp->if_iqdrops; - m_freem (m); return; } @@ -546,12 +547,16 @@ sppp_input(struct ifnet *ifp, struct mbu m_freem (m); return; case PPP_IP: - if (sp->state[IDX_IPCP] == STATE_OPENED) { - schednetisr (NETISR_IP); - inq = &ipintrq; - sp->pp_last_activity = tv.tv_sec; - } - break; + if (sp->state[IDX_IPCP] != STATE_OPENED || + !ISSET(ifp->if_flags, IFF_UP)) + goto drop; + + if (mq_enqueue(&ipintrq, m) != 0) + goto dropped; + + schednetisr (NETISR_IP); + sp->pp_last_activity = tv.tv_sec; + return; #endif #ifdef INET6 case PPP_IPV6CP: @@ -560,12 +565,15 @@ sppp_input(struct ifnet *ifp, struct mbu m_freem (m); return; case PPP_IPV6: - if (sp->state[IDX_IPV6CP] == STATE_OPENED) { - schednetisr (NETISR_IPV6); - inq = &ip6intrq; - sp->pp_last_activity = tv.tv_sec; - } - break; + if (sp->state[IDX_IPV6CP] != STATE_OPENED || + !ISSET(ifp->if_flags, IFF_UP)) + goto drop; + + if (mq_enqueue(&ip6intrq, m) != 0) + goto dropped; + + schednetisr (NETISR_IPV6); + return; #endif } break; @@ -591,15 +599,25 @@ sppp_input(struct ifnet *ifp, struct mbu return; #ifdef INET case ETHERTYPE_IP: - schednetisr (NETISR_IP); - inq = &ipintrq; - break; + if (!ISSET(ifp->if_flags, IFF_UP)) + goto drop; + + if (mq_enqueue(&ipintrq, m) != 0) + goto dropped; + + schednetisr(NETISR_IP); + return; #endif #ifdef INET6 case ETHERTYPE_IPV6: - schednetisr (NETISR_IPV6); - inq = &ip6intrq; - break; + if (!ISSET(ifp->if_flags, IFF_UP)) + goto drop; + + if (mq_enqueue(&ip6intrq, m) != 0) + goto dropped; + + schednetisr(NETISR_IPV6); + return; #endif } break; Index: net/if_tun.c =================================================================== RCS file: /cvs/src/sys/net/if_tun.c,v retrieving revision 1.128 diff -u -p -r1.128 if_tun.c --- net/if_tun.c 8 Sep 2014 06:24:13 -0000 1.128 +++ net/if_tun.c 10 Oct 2014 04:09:19 -0000 @@ -788,7 +788,7 @@ tunwrite(dev_t dev, struct uio *uio, int { struct tun_softc *tp; struct ifnet *ifp; - struct ifqueue *ifq; + struct mbuf_queue *ifq; u_int32_t *th; struct mbuf *top, **mp, *m; int isr; @@ -910,21 +910,15 @@ tunwrite(dev_t dev, struct uio *uio, int return (EAFNOSUPPORT); } - s = splnet(); - if (IF_QFULL(ifq)) { - IF_DROP(ifq); - splx(s); + if (mq_enqueue(ifq, top) != 0) { ifp->if_collisions++; - m_freem(top); - if (!ifq->ifq_congestion) - if_congestion(ifq); return (ENOBUFS); } - IF_ENQUEUE(ifq, top); schednetisr(isr); + ifp->if_ipackets++; ifp->if_ibytes += top->m_pkthdr.len; - splx(s); + return (error); } Index: net/if_var.h =================================================================== RCS file: /cvs/src/sys/net/if_var.h,v retrieving revision 1.12 diff -u -p -r1.12 if_var.h --- net/if_var.h 8 Jul 2014 04:02:14 -0000 1.12 +++ net/if_var.h 10 Oct 2014 04:09:19 -0000 @@ -69,6 +69,7 @@ #include struct mbuf; +struct mbuf_queue; struct proc; struct rtentry; struct socket; @@ -439,6 +440,8 @@ int if_clone_destroy(const char *); void if_congestion(struct ifqueue *); int sysctl_ifq(int *, u_int, void *, size_t *, void *, size_t, struct ifqueue *); +int sysctl_mq(int *, u_int, void *, size_t *, void *, size_t, + struct mbuf_queue *); int loioctl(struct ifnet *, u_long, caddr_t); void loopattach(int); Index: net/pf.c =================================================================== RCS file: /cvs/src/sys/net/pf.c,v retrieving revision 1.887 diff -u -p -r1.887 pf.c --- net/pf.c 27 Sep 2014 12:26:16 -0000 1.887 +++ net/pf.c 10 Oct 2014 04:09:19 -0000 @@ -222,7 +222,6 @@ int pf_compare_state_keys(struct pf_s struct pf_state *pf_find_state(struct pfi_kif *, struct pf_state_key_cmp *, u_int, struct mbuf *); int pf_src_connlimit(struct pf_state **); -int pf_check_congestion(struct ifqueue *); int pf_match_rcvif(struct mbuf *, struct pf_rule *); void pf_step_into_anchor(int *, struct pf_ruleset **, struct pf_rule **, struct pf_rule **); @@ -3111,7 +3110,6 @@ pf_test_rule(struct pf_pdesc *pd, struct struct tcphdr *th = pd->hdr.tcp; struct pf_state_key *skw = NULL, *sks = NULL; struct pf_rule_actions act; - struct ifqueue *ifq = &ipintrq; u_short reason; int rewrite = 0; int tag = -1; @@ -3126,16 +3124,6 @@ pf_test_rule(struct pf_pdesc *pd, struct act.rtableid = pd->rdomain; SLIST_INIT(&rules); -#ifdef INET6 - if (pd->af == AF_INET6) - ifq = &ip6intrq; -#endif - - if (pd->dir == PF_IN && pf_check_congestion(ifq)) { - REASON_SET(&reason, PFRES_CONGEST); - return (PF_DROP); - } - switch (pd->virtual_proto) { #ifdef INET case IPPROTO_ICMP: @@ -6718,15 +6706,6 @@ done: } return (action); -} - -int -pf_check_congestion(struct ifqueue *ifq) -{ - if (ifq->ifq_congestion) - return (1); - else - return (0); } void Index: net/pipex.c =================================================================== RCS file: /cvs/src/sys/net/pipex.c,v retrieving revision 1.55 diff -u -p -r1.55 pipex.c --- net/pipex.c 22 Jul 2014 11:06:10 -0000 1.55 +++ net/pipex.c 10 Oct 2014 04:09:19 -0000 @@ -1123,7 +1123,7 @@ pipex_ip_input(struct mbuf *m0, struct p { struct ifnet *ifp; struct ip *ip; - int s, len; + int len; int is_idle; /* change recvif */ @@ -1185,16 +1185,10 @@ pipex_ip_input(struct mbuf *m0, struct p bpf_mtap_af(ifp->if_bpf, AF_INET, m0, BPF_DIRECTION_IN); #endif - s = splnet(); - if (IF_QFULL(&ipintrq)) { - IF_DROP(&ipintrq); + if (mq_enqueue(&ipintrq, m0) != 0) { ifp->if_collisions++; - if (!ipintrq.ifq_congestion) - if_congestion(&ipintrq); - splx(s); - goto drop; + goto dropped; } - IF_ENQUEUE(&ipintrq, m0); schednetisr(NETISR_IP); ifp->if_ipackets++; @@ -1202,12 +1196,11 @@ pipex_ip_input(struct mbuf *m0, struct p session->stat.ipackets++; session->stat.ibytes += len; - splx(s); - return; drop: if (m0 != NULL) m_freem(m0); +dropped: session->stat.ierrors++; } @@ -1217,7 +1210,7 @@ pipex_ip6_input(struct mbuf *m0, struct { struct ifnet *ifp; struct ip6_hdr *ip6; - int s, len; + int len; /* change recvif */ m0->m_pkthdr.rcvif = session->pipex_iface->ifnet_this; @@ -1260,16 +1253,10 @@ pipex_ip6_input(struct mbuf *m0, struct bpf_mtap_af(ifp->if_bpf, AF_INET6, m0, BPF_DIRECTION_IN); #endif - s = splnet(); - if (IF_QFULL(&ip6intrq)) { - IF_DROP(&ip6intrq); + if (mq_enqueue(&ip6intrq, m0) != 0) { ifp->if_collisions++; - if (!ip6intrq.ifq_congestion) - if_congestion(&ip6intrq); - splx(s); - goto drop; + goto dropped; } - IF_ENQUEUE(&ip6intrq, m0); schednetisr(NETISR_IPV6); ifp->if_ipackets++; @@ -1277,12 +1264,8 @@ pipex_ip6_input(struct mbuf *m0, struct session->stat.ipackets++; session->stat.ibytes += len; - splx(s); - return; -drop: - if (m0 != NULL) - m_freem(m0); +dropped: session->stat.ierrors++; } #endif Index: net/ppp_tty.c =================================================================== RCS file: /cvs/src/sys/net/ppp_tty.c,v retrieving revision 1.29 diff -u -p -r1.29 ppp_tty.c --- net/ppp_tty.c 15 Sep 2014 19:08:21 -0000 1.29 +++ net/ppp_tty.c 10 Oct 2014 04:09:19 -0000 @@ -302,7 +302,7 @@ pppread(struct tty *tp, struct uio *uio, splx(s); return 0; } - if (!IF_IS_EMPTY(&sc->sc_inq)) + if (!mq_empty(&sc->sc_inq)) break; if ((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0 && (tp->t_state & TS_ISOPEN)) { @@ -324,7 +324,7 @@ pppread(struct tty *tp, struct uio *uio, getc(&tp->t_canq); /* Get the packet from the input queue */ - IF_DEQUEUE(&sc->sc_inq, m0); + m0 = mq_dequeue(&sc->sc_inq); splx(s); for (m = m0; m && uio->uio_resid; m = m->m_next) Index: netinet/in.h =================================================================== RCS file: /cvs/src/sys/netinet/in.h,v retrieving revision 1.109 diff -u -p -r1.109 in.h --- netinet/in.h 12 Jul 2014 16:25:08 -0000 1.109 +++ netinet/in.h 10 Oct 2014 04:09:19 -0000 @@ -779,7 +779,7 @@ __END_DECLS #ifdef _KERNEL extern int inetctlerrmap[]; -extern struct ifqueue ipintrq; /* ip packet input queue */ +extern struct mbuf_queue ipintrq; /* ip packet input queue */ extern struct in_addr zeroin_addr; int in_broadcast(struct in_addr, struct ifnet *, u_int); Index: netinet/ip_divert.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_divert.c,v retrieving revision 1.30 diff -u -p -r1.30 ip_divert.c --- netinet/ip_divert.c 8 Sep 2014 06:24:13 -0000 1.30 +++ netinet/ip_divert.c 10 Oct 2014 04:09:19 -0000 @@ -79,11 +79,10 @@ int divert_output(struct inpcb *inp, struct mbuf *m, struct mbuf *nam, struct mbuf *control) { - struct ifqueue *inq; struct sockaddr_in *sin; struct socket *so; struct ifaddr *ifa; - int s, error = 0, min_hdrlen = 0, dir; + int error = 0, min_hdrlen = 0, dir; struct ip *ip; u_int16_t off; @@ -146,8 +145,6 @@ divert_output(struct inpcb *inp, struct } m->m_pkthdr.rcvif = ifa->ifa_ifp; - inq = &ipintrq; - /* * Recalculate IP and protocol checksums for the inbound packet * since the userspace application may have modified the packet @@ -157,10 +154,8 @@ divert_output(struct inpcb *inp, struct ip->ip_sum = in_cksum(m, off); in_proto_cksum_out(m, NULL); - s = splnet(); - IF_INPUT_ENQUEUE(inq, m); - schednetisr(NETISR_IP); - splx(s); + if (mq_enqueue(&ipintrq, m) == 0) + schednetisr(NETISR_IP); } else { error = ip_output(m, NULL, &inp->inp_route, IP_ALLOWBROADCAST | IP_RAWOUTPUT, NULL, NULL, 0); Index: netinet/ip_ether.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_ether.c,v retrieving revision 1.69 diff -u -p -r1.69 ip_ether.c --- netinet/ip_ether.c 14 Sep 2014 14:17:26 -0000 1.69 +++ netinet/ip_ether.c 10 Oct 2014 04:09:19 -0000 @@ -284,8 +284,6 @@ void mplsip_decap(struct mbuf *m, int iphlen) { struct gif_softc *sc; - struct ifqueue *ifq; - int s; etheripstat.etherip_ipackets++; @@ -334,22 +332,14 @@ mplsip_decap(struct mbuf *m, int iphlen) pf_pkt_addr_changed(m); #endif - ifq = &mplsintrq; - s = splnet(); - if (IF_QFULL(ifq)) { - IF_DROP(ifq); - m_freem(m); + if (mq_enqueue(&mplsintrq, m) != 0) { etheripstat.etherip_qfull++; - splx(s); DPRINTF(("mplsip_input(): packet dropped because of full " "queue\n")); return; } - IF_ENQUEUE(ifq, m); schednetisr(NETISR_MPLS); - splx(s); - return; } #endif Index: netinet/ip_gre.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_gre.c,v retrieving revision 1.51 diff -u -p -r1.51 ip_gre.c --- netinet/ip_gre.c 14 Sep 2014 14:17:26 -0000 1.51 +++ netinet/ip_gre.c 10 Oct 2014 04:09:19 -0000 @@ -97,8 +97,8 @@ int gre_input2(struct mbuf *m, int hlen, u_char proto) { struct greip *gip; - int s; - struct ifqueue *ifq; + struct mbuf_queue *ifq; + int isr; struct gre_softc *sc; u_short flags; u_int af; @@ -157,14 +157,15 @@ gre_input2(struct mbuf *m, int hlen, u_c */ if (!gre_wccp) return (0); - case ETHERTYPE_IP: /* shouldn't need a schednetisr(), as */ - ifq = &ipintrq; /* we are in ip_input */ + case ETHERTYPE_IP: + ifq = &ipintrq; + isr = NETISR_IP; af = AF_INET; break; #ifdef INET6 case ETHERTYPE_IPV6: ifq = &ip6intrq; - schednetisr(NETISR_IPV6); + isr = NETISR_IPV6; af = AF_INET6; break; #endif @@ -177,7 +178,7 @@ gre_input2(struct mbuf *m, int hlen, u_c case ETHERTYPE_MPLS: case ETHERTYPE_MPLS_MCAST: ifq = &mplsintrq; - schednetisr(NETISR_MPLS); + isr = NETISR_MPLS; af = AF_MPLS; break; #endif @@ -205,9 +206,8 @@ gre_input2(struct mbuf *m, int hlen, u_c pf_pkt_addr_changed(m); #endif - s = splnet(); /* possible */ - IF_INPUT_ENQUEUE(ifq, m); - splx(s); + if (mq_enqueue(ifq, m) == 0) + schednetisr(isr); return (1); /* packet is done, no further processing needed */ } @@ -267,9 +267,8 @@ gre_mobile_input(struct mbuf *m, ...) { struct ip *ip; struct mobip_h *mip; - struct ifqueue *ifq; struct gre_softc *sc; - int hlen, s; + int hlen; va_list ap; u_char osrc = 0; int msiz; @@ -335,16 +334,13 @@ gre_mobile_input(struct mbuf *m, ...) ip->ip_sum = 0; ip->ip_sum = in_cksum(m,(ip->ip_hl << 2)); - ifq = &ipintrq; - #if NBPFILTER > 0 if (sc->sc_if.if_bpf) bpf_mtap_af(sc->sc_if.if_bpf, AF_INET, m, BPF_DIRECTION_IN); #endif - s = splnet(); /* possible */ - IF_INPUT_ENQUEUE(ifq, m); - splx(s); + if (mq_enqueue(&ipintrq, m) == 0) + schednetisr(NETISR_IP); } /* Index: netinet/ip_input.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_input.c,v retrieving revision 1.237 diff -u -p -r1.237 ip_input.c --- netinet/ip_input.c 30 Sep 2014 08:21:21 -0000 1.237 +++ netinet/ip_input.c 10 Oct 2014 04:09:19 -0000 @@ -114,7 +114,7 @@ int ip_frags = 0; int *ipctl_vars[IPCTL_MAXID] = IPCTL_VARS; struct in_ifaddrhead in_ifaddr; -struct ifqueue ipintrq; +struct mbuf_queue ipintrq = MBUF_QUEUE_INITIALIZER(IFQ_MAXLEN, IPL_NET); struct pool ipqent_pool; struct pool ipq_pool; @@ -172,7 +172,6 @@ ip_init(void) pr->pr_protocol < IPPROTO_MAX) ip_protox[pr->pr_protocol] = pr - inetsw; LIST_INIT(&ipq); - IFQ_SET_MAXLEN(&ipintrq, IFQ_MAXLEN); TAILQ_INIT(&in_ifaddr); if (ip_mtudisc != 0) ip_mtudisc_timeout_q = @@ -196,18 +195,8 @@ void ipintr(void) { struct mbuf *m; - int s; - for (;;) { - /* - * Get next datagram off input queue and get IP header - * in first mbuf. - */ - s = splnet(); - IF_DEQUEUE(&ipintrq, m); - splx(s); - if (m == NULL) - return; + while ((m = mq_dequeue(&ipintrq)) != NULL) { #ifdef DIAGNOSTIC if ((m->m_flags & M_PKTHDR) == 0) panic("ipintr no HDR"); @@ -1629,7 +1618,7 @@ ip_sysctl(int *name, u_int namelen, void ipsec_def_comp, sizeof(ipsec_def_comp))); case IPCTL_IFQUEUE: - return (sysctl_ifq(name + 1, namelen - 1, + return (sysctl_mq(name + 1, namelen - 1, oldp, oldlenp, newp, newlen, &ipintrq)); case IPCTL_STATS: if (newp != NULL) Index: netinet/ip_ipip.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_ipip.c,v retrieving revision 1.54 diff -u -p -r1.54 ip_ipip.c --- netinet/ip_ipip.c 14 Sep 2014 14:17:26 -0000 1.54 +++ netinet/ip_ipip.c 10 Oct 2014 04:09:19 -0000 @@ -147,7 +147,7 @@ ipip_input(struct mbuf *m, int iphlen, s struct sockaddr_in *sin; struct ifnet *ifp; struct ifaddr *ifa; - struct ifqueue *ifq = NULL; + struct mbuf_queue *ifq = NULL; struct ip *ipo; u_int rdomain; #ifdef INET6 @@ -155,7 +155,7 @@ ipip_input(struct mbuf *m, int iphlen, s struct ip6_hdr *ip6; #endif int isr; - int mode, hlen, s; + int mode, hlen; u_int8_t itos, otos; u_int8_t v; sa_family_t af; @@ -391,23 +391,14 @@ ipip_input(struct mbuf *m, int iphlen, s pf_pkt_addr_changed(m); #endif - s = splnet(); /* isn't it already? */ - if (IF_QFULL(ifq)) { - IF_DROP(ifq); - m_freem(m); + if (mq_enqueue(ifq, m) != 0) { ipipstat.ipips_qfull++; - splx(s); - DPRINTF(("ipip_input(): packet dropped because of full " "queue\n")); return; } - - IF_ENQUEUE(ifq, m); schednetisr(isr); - splx(s); - return; } int Index: netinet/ipsec_input.c =================================================================== RCS file: /cvs/src/sys/netinet/ipsec_input.c,v retrieving revision 1.122 diff -u -p -r1.122 ipsec_input.c --- netinet/ipsec_input.c 22 Jul 2014 11:06:10 -0000 1.122 +++ netinet/ipsec_input.c 10 Oct 2014 04:09:19 -0000 @@ -847,28 +847,20 @@ ah4_input(struct mbuf *m, ...) int ah4_input_cb(struct mbuf *m, ...) { - struct ifqueue *ifq = &ipintrq; - int s = splnet(); - /* * Interface pointer is already in first mbuf; chop off the * `outer' header and reschedule. */ - if (IF_QFULL(ifq)) { - IF_DROP(ifq); + if (mq_enqueue(&ipintrq, m) != 0) { ahstat.ahs_qfull++; - splx(s); - m_freem(m); DPRINTF(("ah4_input_cb(): dropped packet because of full " "IP queue\n")); return ENOBUFS; } - IF_ENQUEUE(ifq, m); schednetisr(NETISR_IP); - splx(s); return 0; } @@ -903,27 +895,19 @@ esp4_input(struct mbuf *m, ...) int esp4_input_cb(struct mbuf *m, ...) { - struct ifqueue *ifq = &ipintrq; - int s = splnet(); - /* * Interface pointer is already in first mbuf; chop off the * `outer' header and reschedule. */ - if (IF_QFULL(ifq)) { - IF_DROP(ifq); + if (mq_enqueue(&ipintrq, m) != 0) { espstat.esps_qfull++; - splx(s); - m_freem(m); DPRINTF(("esp4_input_cb(): dropped packet because of full " "IP queue\n")); return ENOBUFS; } - IF_ENQUEUE(ifq, m); schednetisr(NETISR_IP); - splx(s); return 0; } @@ -945,27 +929,18 @@ ipcomp4_input(struct mbuf *m, ...) int ipcomp4_input_cb(struct mbuf *m, ...) { - struct ifqueue *ifq = &ipintrq; - int s = splnet(); - /* * Interface pointer is already in first mbuf; chop off the * `outer' header and reschedule. */ - if (IF_QFULL(ifq)) { - IF_DROP(ifq); + if (mq_enqueue(&ipintrq, m) != 0) { ipcompstat.ipcomps_qfull++; - splx(s); - m_freem(m); DPRINTF(("ipcomp4_input_cb(): dropped packet because of full IP queue\n")); return ENOBUFS; } - IF_ENQUEUE(ifq, m); schednetisr(NETISR_IP); - splx(s); - return 0; } Index: netinet6/in6.h =================================================================== RCS file: /cvs/src/sys/netinet6/in6.h,v retrieving revision 1.75 diff -u -p -r1.75 in6.h --- netinet6/in6.h 31 Aug 2014 19:20:44 -0000 1.75 +++ netinet6/in6.h 10 Oct 2014 04:09:19 -0000 @@ -418,7 +418,7 @@ typedef __socklen_t socklen_t; /* length #ifdef _KERNEL extern u_char inet6ctlerrmap[]; -extern struct ifqueue ip6intrq; /* IP6 packet input queue */ +extern struct mbuf_queue ip6intrq; /* IP6 packet input queue */ extern struct in6_addr zeroin6_addr; extern unsigned long in6_maxmtu; Index: netinet6/ip6_divert.c =================================================================== RCS file: /cvs/src/sys/netinet6/ip6_divert.c,v retrieving revision 1.30 diff -u -p -r1.30 ip6_divert.c --- netinet6/ip6_divert.c 8 Sep 2014 06:24:13 -0000 1.30 +++ netinet6/ip6_divert.c 10 Oct 2014 04:09:19 -0000 @@ -83,11 +83,10 @@ int divert6_output(struct inpcb *inp, struct mbuf *m, struct mbuf *nam, struct mbuf *control) { - struct ifqueue *inq; struct sockaddr_in6 *sin6; struct socket *so; struct ifaddr *ifa; - int s, error = 0, min_hdrlen = 0, nxt = 0, off, dir; + int error = 0, min_hdrlen = 0, nxt = 0, off, dir; struct ip6_hdr *ip6; m->m_pkthdr.rcvif = NULL; @@ -156,19 +155,13 @@ divert6_output(struct inpcb *inp, struct } m->m_pkthdr.rcvif = ifa->ifa_ifp; - inq = &ip6intrq; - /* * Recalculate the protocol checksum for the inbound packet * since the userspace application may have modified the packet * prior to reinjection. */ in6_proto_cksum_out(m, NULL); - - s = splnet(); - IF_INPUT_ENQUEUE(inq, m); - schednetisr(NETISR_IPV6); - splx(s); + mq_enqueue(&ip6intrq, m); } else { error = ip6_output(m, NULL, &inp->inp_route6, IP_ALLOWBROADCAST | IP_RAWOUTPUT, NULL, NULL, NULL); Index: netinet6/ip6_input.c =================================================================== RCS file: /cvs/src/sys/netinet6/ip6_input.c,v retrieving revision 1.129 diff -u -p -r1.129 ip6_input.c --- netinet6/ip6_input.c 27 Sep 2014 12:26:16 -0000 1.129 +++ netinet6/ip6_input.c 10 Oct 2014 04:09:19 -0000 @@ -116,7 +116,7 @@ #endif struct in6_ifaddrhead in6_ifaddr; -struct ifqueue ip6intrq; +struct mbuf_queue ip6intrq = MBUF_QUEUE_INITIALIZER(IFQ_MAXLEN, IPL_NET); struct ip6stat ip6stat; @@ -147,7 +147,6 @@ ip6_init(void) pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW && pr->pr_protocol < IPPROTO_MAX) ip6_protox[pr->pr_protocol] = pr - inet6sw; - IFQ_SET_MAXLEN(&ip6intrq, IFQ_MAXLEN); TAILQ_INIT(&in6_ifaddr); ip6_randomid_init(); nd6_init(); @@ -171,17 +170,10 @@ ip6_init2(void *dummy) void ip6intr(void) { - int s; struct mbuf *m; - for (;;) { - s = splnet(); - IF_DEQUEUE(&ip6intrq, m); - splx(s); - if (m == NULL) - return; + while ((m = mq_dequeue(&ip6intrq)) != NULL) ip6_input(m); - } } extern struct route_in6 ip6_forward_rt; Index: netmpls/mpls.h =================================================================== RCS file: /cvs/src/sys/netmpls/mpls.h,v retrieving revision 1.28 diff -u -p -r1.28 mpls.h --- netmpls/mpls.h 24 Apr 2013 10:20:15 -0000 1.28 +++ netmpls/mpls.h 10 Oct 2014 04:09:19 -0000 @@ -166,7 +166,7 @@ void mpe_input6(struct mbuf *, struct if extern int mpls_raw_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); -extern struct ifqueue mplsintrq; /* MPLS input queue */ +extern struct mbuf_queue mplsintrq; /* MPLS input queue */ extern int mpls_defttl; extern int mpls_mapttl_ip; extern int mpls_mapttl_ip6; Index: netmpls/mpls_input.c =================================================================== RCS file: /cvs/src/sys/netmpls/mpls_input.c,v retrieving revision 1.38 diff -u -p -r1.38 mpls_input.c --- netmpls/mpls_input.c 22 Jul 2014 11:06:10 -0000 1.38 +++ netmpls/mpls_input.c 10 Oct 2014 04:09:19 -0000 @@ -44,7 +44,7 @@ #include -struct ifqueue mplsintrq; +struct mbuf_queue mplsintrq = MBUF_QUEUE_INITIALIZER(IFQ_MAXLEN, IPL_NET); #ifdef MPLS_DEBUG #define MPLS_LABEL_GET(l) ((ntohl((l) & MPLS_LABEL_MASK)) >> MPLS_LABEL_OFFSET) @@ -61,22 +61,14 @@ struct mbuf *mpls_do_error(struct mbuf * void mpls_init(void) { - IFQ_SET_MAXLEN(&mplsintrq, IFQ_MAXLEN); } void mplsintr(void) { struct mbuf *m; - int s; - for (;;) { - /* Get next datagram of input queue */ - s = splnet(); - IF_DEQUEUE(&mplsintrq, m); - splx(s); - if (m == NULL) - return; + while ((m = mq_dequeue(&mplsintrq)) != NULL) { #ifdef DIAGNOSTIC if ((m->m_flags & M_PKTHDR) == 0) panic("mplsintr no HDR"); @@ -95,7 +87,7 @@ mpls_input(struct mbuf *m) struct rtentry *rt = NULL; struct rt_mpls *rt_mpls; u_int8_t ttl; - int i, s, hasbos; + int i, hasbos; if (!ISSET(ifp->if_xflags, IFXF_MPLS)) { m_freem(m); @@ -162,10 +154,8 @@ mpls_input(struct mbuf *m) do_v4: if (mpls_ip_adjttl(m, ttl)) goto done; - s = splnet(); - IF_INPUT_ENQUEUE(&ipintrq, m); - schednetisr(NETISR_IP); - splx(s); + if (mq_enqueue(&ipintrq, m) == 0) + schednetisr(NETISR_IP); goto done; } continue; @@ -175,10 +165,8 @@ do_v4: do_v6: if (mpls_ip6_adjttl(m, ttl)) goto done; - s = splnet(); - IF_INPUT_ENQUEUE(&ip6intrq, m); - schednetisr(NETISR_IPV6); - splx(s); + if (mq_enqueue(&ip6intrq, m) == 0) + schednetisr(NETISR_IPV6); goto done; } continue; @@ -245,19 +233,15 @@ do_v6: case AF_INET: if (mpls_ip_adjttl(m, ttl)) break; - s = splnet(); - IF_INPUT_ENQUEUE(&ipintrq, m); - schednetisr(NETISR_IP); - splx(s); + if (mq_enqueue(&ipintrq, m) == 0) + schednetisr(NETISR_IP); break; #ifdef INET6 case AF_INET6: if (mpls_ip6_adjttl(m, ttl)) break; - s = splnet(); - IF_INPUT_ENQUEUE(&ip6intrq, m); - schednetisr(NETISR_IPV6); - splx(s); + if (mq_enqueue(&ip6intrq, m) == 0) + schednetisr(NETISR_IPV6); break; #endif default: Index: netmpls/mpls_raw.c =================================================================== RCS file: /cvs/src/sys/netmpls/mpls_raw.c,v retrieving revision 1.9 diff -u -p -r1.9 mpls_raw.c --- netmpls/mpls_raw.c 27 Mar 2013 02:00:08 -0000 1.9 +++ netmpls/mpls_raw.c 10 Oct 2014 04:09:19 -0000 @@ -134,7 +134,7 @@ mpls_sysctl(int *name, u_int namelen, vo switch (name[0]) { case MPLSCTL_IFQUEUE: - return (sysctl_ifq(name + 1, namelen - 1, + return (sysctl_mq(name + 1, namelen - 1, oldp, oldlenp, newp, newlen, &mplsintrq)); default: return sysctl_int_arr(mplsctl_vars, name, namelen, Index: sys/mbuf.h =================================================================== RCS file: /cvs/src/sys/sys/mbuf.h,v retrieving revision 1.183 diff -u -p -r1.183 mbuf.h --- sys/mbuf.h 3 Oct 2014 01:02:47 -0000 1.183 +++ sys/mbuf.h 10 Oct 2014 04:09:19 -0000 @@ -486,6 +486,8 @@ void ml_init(struct mbuf_list *); void ml_enqueue(struct mbuf_list *, struct mbuf *); struct mbuf * ml_dequeue(struct mbuf_list *); struct mbuf * ml_dechain(struct mbuf_list *); +struct mbuf * ml_filter(struct mbuf_list *, + int (*)(void *, const struct mbuf *), void *); #define ml_len(_ml) ((_ml)->ml_len) #define ml_empty(_ml) ((_ml)->ml_len == 0) @@ -513,6 +515,8 @@ struct mbuf * mq_dequeue(struct mbuf_qu int mq_enlist(struct mbuf_queue *, struct mbuf_list *); void mq_delist(struct mbuf_queue *, struct mbuf_list *); struct mbuf * mq_dechain(struct mbuf_queue *); +struct mbuf * mq_filter(struct mbuf_queue *, + int (*)(void *, const struct mbuf *), void *); #define mq_len(_mq) ml_len(&(_mq)->mq_list) #define mq_empty(_mq) ml_empty(&(_mq)->mq_list)