On 12/05/15(Tue) 12:15, Martin Pieuchot wrote:
> On 07/05/15(Thu) 11:50, Martin Pieuchot wrote:
> > This diff is a first step towards removing all pseudo-driver #ifdef
> > in ether_output().  As for ether_input() the goal of this work is to
> > provide an elegant design to make it easier to turn pseudo-drivers
> > MP-safe.
> > 
> > So instead of including some bridge(4), vlan(4) and carp(4) specific
> > code in ether_output(), I'd like to split this function and call the
> > interesting chunks in bridge_output(), vlan_output() and carp_output().
> > 
> > The first step is to take the generic code enqueuing packets in its
> > own function: if_output().
> > 
> > Sadly if_start() is still required for hfsc_deferred().
> > 
> > Comments, ok?
> 
> I got one positive test report involving carp, gif, vether & bridge but
> nothing else.

Rafael Zalamena pointed a double if_opackets increment in vlan, diff
below fixes that.  This version also left the net80211 bits out because
wireless interfaces does no play well with IFXF_TXREADY hack...

> Anybody wants to comment or ok?

Index: sys/net/bridgestp.c
===================================================================
RCS file: /cvs/src/sys/net/bridgestp.c,v
retrieving revision 1.54
diff -u -p -r1.54 bridgestp.c
--- sys/net/bridgestp.c 12 May 2015 12:35:10 -0000      1.54
+++ sys/net/bridgestp.c 12 May 2015 12:40:47 -0000
@@ -353,7 +353,6 @@ bstp_transmit_tcn(struct bstp_state *bs,
        struct ifnet *ifp = bp->bp_ifp;
        struct ether_header *eh;
        struct mbuf *m;
-       int s, len, error;
 
        if (ifp == NULL || (ifp->if_flags & IFF_RUNNING) == 0)
                return;
@@ -378,16 +377,8 @@ bstp_transmit_tcn(struct bstp_state *bs,
        bpdu.tbu_bpdutype = BSTP_MSGTYPE_TCN;
        bcopy(&bpdu, mtod(m, caddr_t) + sizeof(*eh), sizeof(bpdu));
 
-       s = splnet();
        bp->bp_txcount++;
-       len = m->m_pkthdr.len;
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
-       if (error == 0) {
-               ifp->if_obytes += len;
-               ifp->if_omcasts++;
-               if_start(ifp);
-       }
-       splx(s);
+       if_output(ifp, m);
 }
 
 void
@@ -469,7 +460,7 @@ bstp_send_bpdu(struct bstp_state *bs, st
        struct ifnet *ifp = bp->bp_ifp;
        struct mbuf *m;
        struct ether_header *eh;
-       int s, len, error;
+       int s;
 
        s = splnet();
        if (ifp == NULL || (ifp->if_flags & IFF_RUNNING) == 0)
@@ -517,13 +508,7 @@ bstp_send_bpdu(struct bstp_state *bs, st
        m->m_pkthdr.pf.prio = BSTP_IFQ_PRIO;
 
        bp->bp_txcount++;
-       len = m->m_pkthdr.len;
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
-       if (error == 0) {
-               ifp->if_obytes += len;
-               ifp->if_omcasts++;
-               if_start(ifp);
-       }
+       if_output(ifp, m);
  done:
        splx(s);
 }
Index: sys/net/if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.330
diff -u -p -r1.330 if.c
--- sys/net/if.c        23 Apr 2015 09:45:24 -0000      1.330
+++ sys/net/if.c        12 May 2015 12:40:47 -0000
@@ -441,6 +441,35 @@ if_start(struct ifnet *ifp)
        }
 }
 
+int
+if_output(struct ifnet *ifp, struct mbuf *m)
+{
+       int s, error = 0;
+
+       s = splnet();
+
+       /*
+        * Queue message on interface, and start output if interface
+        * not yet active.
+        */
+       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
+       if (error) {
+               splx(s);
+               return (error);
+       }
+
+       ifp->if_obytes += m->m_pkthdr.len;
+       if (m->m_flags & M_MCAST)
+               ifp->if_omcasts++;
+
+       ifp->if_opackets++;
+       if_start(ifp);
+
+       splx(s);
+
+       return (0);
+}
+
 struct mbuf_queue if_input_queue = MBUF_QUEUE_INITIALIZER(8192, IPL_NET);
 struct task if_input_task = TASK_INITIALIZER(if_input_process, 
&if_input_queue);
 
Index: sys/net/if_bridge.c
===================================================================
RCS file: /cvs/src/sys/net/if_bridge.c,v
retrieving revision 1.237
diff -u -p -r1.237 if_bridge.c
--- sys/net/if_bridge.c 7 May 2015 01:55:43 -0000       1.237
+++ sys/net/if_bridge.c 12 May 2015 12:40:48 -0000
@@ -2693,7 +2693,6 @@ int
 bridge_ifenqueue(struct bridge_softc *sc, struct ifnet *ifp, struct mbuf *m)
 {
        int error, len;
-       short mflags;
 
 #if NGIF > 0
        /* Packet needs etherip encapsulation. */
@@ -2745,18 +2744,15 @@ bridge_ifenqueue(struct bridge_softc *sc
        }
 #endif
        len = m->m_pkthdr.len;
-       mflags = m->m_flags;
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
+
+       error = if_output(ifp, m);
        if (error) {
                sc->sc_if.if_oerrors++;
                return (error);
        }
+
        sc->sc_if.if_opackets++;
        sc->sc_if.if_obytes += len;
-       ifp->if_obytes += len;
-       if (mflags & M_MCAST)
-               ifp->if_omcasts++;
-       if_start(ifp);
 
        return (0);
 }
Index: sys/net/if_ethersubr.c
===================================================================
RCS file: /cvs/src/sys/net/if_ethersubr.c,v
retrieving revision 1.196
diff -u -p -r1.196 if_ethersubr.c
--- sys/net/if_ethersubr.c      11 May 2015 08:41:43 -0000      1.196
+++ sys/net/if_ethersubr.c      12 May 2015 12:40:48 -0000
@@ -256,14 +256,13 @@ ether_output(struct ifnet *ifp0, struct 
     struct rtentry *rt)
 {
        u_int16_t etype;
-       int s, len, error = 0;
+       int len, error = 0;
        u_char edst[ETHER_ADDR_LEN];
        u_char *esrc;
        struct mbuf *m = m0;
        struct mbuf *mcopy = NULL;
        struct ether_header *eh;
        struct arpcom *ac = (struct arpcom *)ifp0;
-       short mflags;
        struct ifnet *ifp = ifp0;
 
 #ifdef DIAGNOSTIC
@@ -418,30 +417,15 @@ ether_output(struct ifnet *ifp0, struct 
                }
        }
 #endif
-       mflags = m->m_flags;
+
        len = m->m_pkthdr.len;
-       s = splnet();
-       /*
-        * Queue message on interface, and start output if interface
-        * not yet active.
-        */
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
-       if (error) {
-               /* mbuf is already freed */
-               splx(s);
-               return (error);
-       }
-       ifp->if_obytes += len;
+
+       error = if_output(ifp, m);
 #if NCARP > 0
-       if (ifp != ifp0)
+       if (!error && ifp != ifp0)
                ifp0->if_obytes += len;
 #endif /* NCARP > 0 */
-       if (mflags & M_MCAST)
-               ifp->if_omcasts++;
-       if_start(ifp);
-       splx(s);
        return (error);
-
 bad:
        if (m)
                m_freem(m);
Index: sys/net/if_gif.c
===================================================================
RCS file: /cvs/src/sys/net/if_gif.c,v
retrieving revision 1.73
diff -u -p -r1.73 if_gif.c
--- sys/net/if_gif.c    14 Mar 2015 03:38:51 -0000      1.73
+++ sys/net/if_gif.c    12 May 2015 12:40:48 -0000
@@ -276,7 +276,6 @@ gif_output(struct ifnet *ifp, struct mbu
 {
        struct gif_softc *sc = (struct gif_softc*)ifp;
        int error = 0;
-       int s;
 
        if (!(ifp->if_flags & IFF_UP) ||
            sc->gif_psrc == NULL || sc->gif_pdst == NULL ||
@@ -316,19 +315,7 @@ gif_output(struct ifnet *ifp, struct mbu
        if ((error = gif_checkloop(ifp, m)))
                goto end;
 
-       /*
-        * Queue message on interface, and start output.
-        */
-       s = splnet();
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
-       if (error) {
-               /* mbuf is already freed */
-               splx(s);
-               goto end;
-       }
-       ifp->if_obytes += m->m_pkthdr.len;
-       if_start(ifp);
-       splx(s);
+       error = if_output(ifp, m);
 
 end:
        if (error)
Index: sys/net/if_mpe.c
===================================================================
RCS file: /cvs/src/sys/net/if_mpe.c,v
retrieving revision 1.43
diff -u -p -r1.43 if_mpe.c
--- sys/net/if_mpe.c    10 Apr 2015 13:58:20 -0000      1.43
+++ sys/net/if_mpe.c    12 May 2015 12:40:49 -0000
@@ -203,7 +203,6 @@ mpeoutput(struct ifnet *ifp, struct mbuf
        struct rtentry *rt)
 {
        struct shim_hdr shim;
-       int             s;
        int             error;
        int             off;
        u_int8_t        op = 0;
@@ -257,16 +256,7 @@ mpeoutput(struct ifnet *ifp, struct mbuf
 
        m_copyback(m, off, sizeof(shim), (caddr_t)&shim, M_NOWAIT);
 
-       s = splnet();
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
-       if (error) {
-               /* mbuf is already freed */
-               splx(s);
-               goto out;
-       }
-       if_start(ifp);
-       splx(s);
-
+       error = if_output(ifp, m);
 out:
        if (error)
                ifp->if_oerrors++;
Index: sys/net/if_pppx.c
===================================================================
RCS file: /cvs/src/sys/net/if_pppx.c,v
retrieving revision 1.37
diff -u -p -r1.37 if_pppx.c
--- sys/net/if_pppx.c   10 Apr 2015 13:58:20 -0000      1.37
+++ sys/net/if_pppx.c   12 May 2015 12:40:49 -0000
@@ -1034,7 +1034,7 @@ pppx_if_output(struct ifnet *ifp, struct
     struct rtentry *rt)
 {
        int error = 0;
-       int proto, s;
+       int proto;
 
        if (!ISSET(ifp->if_flags, IFF_UP)) {
                m_freem(m);
@@ -1059,15 +1059,7 @@ pppx_if_output(struct ifnet *ifp, struct
        }
        *mtod(m, int *) = proto;
 
-       s = splnet();
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
-       if (error) {
-               splx(s);
-               goto out;
-       }
-       if_start(ifp);
-       splx(s);
-
+       error = if_output(ifp, m);
 out:
        if (error)
                ifp->if_oerrors++;
Index: sys/net/if_spppsubr.c
===================================================================
RCS file: /cvs/src/sys/net/if_spppsubr.c,v
retrieving revision 1.132
diff -u -p -r1.132 if_spppsubr.c
--- sys/net/if_spppsubr.c       10 Apr 2015 13:58:20 -0000      1.132
+++ sys/net/if_spppsubr.c       12 May 2015 12:40:50 -0000
@@ -620,7 +620,7 @@ sppp_output(struct ifnet *ifp, struct mb
        struct sppp *sp = (struct sppp*) ifp;
        struct ppp_header *h;
        struct timeval tv;
-       int s, len, rv = 0;
+       int s, rv = 0;
        u_int16_t protocol;
 
 #ifdef DIAGNOSTIC
@@ -788,25 +788,19 @@ sppp_output(struct ifnet *ifp, struct mb
         * Queue message on interface, and start output if interface
         * not yet active.
         */
-       len = m->m_pkthdr.len;
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, rv);
-
+       rv = if_output(ifp, m);
        if (rv != 0) {
-               ++ifp->if_oerrors;
-               splx (s);
+               ifp->if_oerrors++;
                return (rv);
        }
 
-       if (!(ifp->if_flags & IFF_OACTIVE))
-               (*ifp->if_start) (ifp);
-
        /*
         * Count output packets and bytes.
         * The packet length includes header, FCS and 1 flag,
         * according to RFC 1333.
         */
-       ifp->if_obytes += len + sp->pp_framebytes;
-       splx (s);
+       ifp->if_obytes += sp->pp_framebytes;
+
        return (0);
 }
 
Index: sys/net/if_trunk.c
===================================================================
RCS file: /cvs/src/sys/net/if_trunk.c,v
retrieving revision 1.96
diff -u -p -r1.96 if_trunk.c
--- sys/net/if_trunk.c  11 May 2015 08:41:43 -0000      1.96
+++ sys/net/if_trunk.c  12 May 2015 12:40:50 -0000
@@ -962,29 +962,6 @@ trunk_start(struct ifnet *ifp)
        }
 }
 
-int
-trunk_enqueue(struct ifnet *ifp, struct mbuf *m)
-{
-       int len, error = 0;
-       u_short mflags;
-
-       splassert(IPL_NET);
-
-       /* Send mbuf */
-       mflags = m->m_flags;
-       len = m->m_pkthdr.len;
-       IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
-       if (error)
-               return (error);
-       if_start(ifp);
-
-       ifp->if_obytes += len;
-       if (mflags & M_MCAST)
-               ifp->if_omcasts++;
-
-       return (error);
-}
-
 u_int32_t
 trunk_hashmbuf(struct mbuf *m, SIPHASH_KEY *key)
 {
@@ -1317,7 +1294,7 @@ trunk_rr_start(struct trunk_softc *tr, s
        }
 
        /* Send mbuf */
-       if ((error = trunk_enqueue(tp->tp_if, m)) != 0)
+       if ((error = if_output(tp->tp_if, m)) != 0)
                return (error);
 
        /* Get next active port */
@@ -1373,7 +1350,7 @@ trunk_fail_start(struct trunk_softc *tr,
        }
 
        /* Send mbuf */
-       return (trunk_enqueue(tp->tp_if, m));
+       return (if_output(tp->tp_if, m));
 }
 
 int
@@ -1500,7 +1477,7 @@ trunk_lb_start(struct trunk_softc *tr, s
        }
 
        /* Send mbuf */
-       return (trunk_enqueue(tp->tp_if, m));
+       return (if_output(tp->tp_if, m));
 }
 
 int
@@ -1560,7 +1537,7 @@ trunk_bcast_start(struct trunk_softc *tr
                                break;
                        }
 
-                       ret = trunk_enqueue(last->tp_if, m);
+                       ret = if_output(last->tp_if, m);
                        if (ret != 0)
                                errors++;
                }
@@ -1571,7 +1548,7 @@ trunk_bcast_start(struct trunk_softc *tr
                return (ENOENT);
        }
 
-       ret = trunk_enqueue(last->tp_if, m0);
+       ret = if_output(last->tp_if, m0);
        if (ret != 0)
                errors++;
 
@@ -1645,7 +1622,7 @@ trunk_lacp_start(struct trunk_softc *tr,
        }
 
        /* Send mbuf */
-       return (trunk_enqueue(tp->tp_if, m));
+       return (if_output(tp->tp_if, m));
 }
 
 int
Index: sys/net/if_tun.c
===================================================================
RCS file: /cvs/src/sys/net/if_tun.c,v
retrieving revision 1.139
diff -u -p -r1.139 if_tun.c
--- sys/net/if_tun.c    30 Apr 2015 15:19:50 -0000      1.139
+++ sys/net/if_tun.c    12 May 2015 12:40:51 -0000
@@ -529,7 +529,7 @@ tun_output(struct ifnet *ifp, struct mbu
     struct rtentry *rt)
 {
        struct tun_softc        *tp = ifp->if_softc;
-       int                      s, len, error;
+       int                      s, error;
        u_int32_t               *af;
 
        if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
@@ -570,16 +570,13 @@ tun_output(struct ifnet *ifp, struct mbu
        }
 #endif
 
-       len = m0->m_pkthdr.len;
-       IFQ_ENQUEUE(&ifp->if_snd, m0, NULL, error);
+       error = if_output(ifp, m0);
        if (error) {
-               splx(s);
                ifp->if_collisions++;
                return (error);
        }
+
        splx(s);
-       ifp->if_opackets++;
-       ifp->if_obytes += len;
 
        tun_wakeup(tp);
        return (0);
Index: sys/net/if_var.h
===================================================================
RCS file: /cvs/src/sys/net/if_var.h,v
retrieving revision 1.25
diff -u -p -r1.25 if_var.h
--- sys/net/if_var.h    23 Apr 2015 09:45:24 -0000      1.25
+++ sys/net/if_var.h    12 May 2015 12:40:51 -0000
@@ -418,6 +418,7 @@ extern struct ifnet_head ifnet;
 extern struct ifnet *lo0ifp;
 
 void   if_start(struct ifnet *);
+int    if_output(struct ifnet *, struct mbuf *);
 void   if_input(struct ifnet *, struct mbuf_list *);
 
 void   ether_input_mbuf(struct ifnet *, struct mbuf *);
Index: sys/net/if_vlan.c
===================================================================
RCS file: /cvs/src/sys/net/if_vlan.c,v
retrieving revision 1.118
diff -u -p -r1.118 if_vlan.c
--- sys/net/if_vlan.c   22 Apr 2015 06:42:11 -0000      1.118
+++ sys/net/if_vlan.c   12 May 2015 12:40:51 -0000
@@ -192,7 +192,6 @@ vlan_start(struct ifnet *ifp)
        struct ifvlan   *ifv;
        struct ifnet    *p;
        struct mbuf     *m;
-       int              error;
 
        ifv = ifp->if_softc;
        p = ifv->ifv_p;
@@ -248,22 +247,10 @@ vlan_start(struct ifnet *ifp)
                }
 #endif /* NBPFILTER > 0 */
 
-               /*
-                * Send it, precisely as ether_output() would have.
-                * We are already running at splnet.
-                */
-               IFQ_ENQUEUE(&p->if_snd, m, NULL, error);
-               if (error) {
-                       /* mbuf is already freed */
+               if (if_output(p, m)) {
                        ifp->if_oerrors++;
                        continue;
                }
-               p->if_obytes += m->m_pkthdr.len;
-               if (m->m_flags & M_MCAST)
-                       p->if_omcasts++;
-
-               ifp->if_opackets++;
-               if_start(p);
        }
 }
 
Index: sys/net/trunklacp.c
===================================================================
RCS file: /cvs/src/sys/net/trunklacp.c,v
retrieving revision 1.20
diff -u -p -r1.20 trunklacp.c
--- sys/net/trunklacp.c 11 May 2015 08:41:43 -0000      1.20
+++ sys/net/trunklacp.c 12 May 2015 12:40:52 -0000
@@ -342,7 +342,7 @@ lacp_xmit_lacpdu(struct lacp_port *lp)
        struct trunk_port *tp = lp->lp_trunk;
        struct mbuf *m;
        struct lacpdu *du;
-       int error, s;
+       int error;
 
        m = m_gethdr(M_DONTWAIT, MT_DATA);
        if (m == NULL)
@@ -383,9 +383,7 @@ lacp_xmit_lacpdu(struct lacp_port *lp)
         * XXX should use higher priority queue.
         * otherwise network congestion can break aggregation.
         */
-       s = splnet();
-       error = trunk_enqueue(lp->lp_ifp, m);
-       splx(s);
+       error = if_output(lp->lp_ifp, m);
        return (error);
 }
 
@@ -395,7 +393,7 @@ lacp_xmit_marker(struct lacp_port *lp)
        struct trunk_port *tp = lp->lp_trunk;
        struct mbuf *m;
        struct markerdu *mdu;
-       int error, s;
+       int error;
 
        m = m_gethdr(M_DONTWAIT, MT_DATA);
        if (m == NULL)
@@ -425,9 +423,7 @@ lacp_xmit_marker(struct lacp_port *lp)
            ntohl(mdu->mdu_info.mi_rq_xid)));
 
        m->m_flags |= M_MCAST;
-       s = splnet();
-       error = trunk_enqueue(lp->lp_ifp, m);
-       splx(s);
+       error = if_output(lp->lp_ifp, m);
        return (error);
 }
 
@@ -1653,7 +1649,7 @@ lacp_marker_input(struct lacp_port *lp, 
                    &ethermulticastaddr_slowprotocols, ETHER_ADDR_LEN);
                memcpy(&mdu->mdu_eh.ether_shost,
                    tp->tp_lladdr, ETHER_ADDR_LEN);
-               error = trunk_enqueue(lp->lp_ifp, m);
+               error = if_output(lp->lp_ifp, m);
                break;
 
        case MARKER_TYPE_RESPONSE:

Reply via email to