a packet on the sending queue of an interface.
Tested by many, thanks a lot!
ok dlg@, claudio@
-/* $OpenBSD: bridgestp.c,v 1.54 2015/05/12 12:35:10 mpi Exp $ */
+/* $OpenBSD: bridgestp.c,v 1.55 2015/05/15 10:15:13 mpi Exp $ */
/*
* Copyright (c) 2000 Jason L. Wright (jason@thought.net)
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;
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
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)
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);
}
-/* $OpenBSD: if.c,v 1.330 2015/04/23 09:45:24 dlg Exp $ */
+/* $OpenBSD: if.c,v 1.331 2015/05/15 10:15:13 mpi Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
}
}
+int
+if_output(struct ifnet *ifp, struct mbuf *m)
+{
+ int s, length, error = 0;
+ unsigned short mflags;
+
+ length = m->m_pkthdr.len;
+ mflags = m->m_flags;
+
+ 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 += length;
+ if (mflags & 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);
-/* $OpenBSD: if_bridge.c,v 1.237 2015/05/07 01:55:43 jsg Exp $ */
+/* $OpenBSD: if_bridge.c,v 1.238 2015/05/15 10:15:13 mpi Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
bridge_ifenqueue(struct bridge_softc *sc, struct ifnet *ifp, struct mbuf *m)
{
int error, len;
- short mflags;
#if NGIF > 0
/* Packet needs etherip encapsulation. */
}
#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);
}
-/* $OpenBSD: if_ethersubr.c,v 1.197 2015/05/13 08:16:01 mpi Exp $ */
+/* $OpenBSD: if_ethersubr.c,v 1.198 2015/05/15 10:15:13 mpi Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */
/*
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
}
}
#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);
-/* $OpenBSD: if_gif.c,v 1.73 2015/03/14 03:38:51 jsg Exp $ */
+/* $OpenBSD: if_gif.c,v 1.74 2015/05/15 10:15:13 mpi Exp $ */
/* $KAME: if_gif.c,v 1.43 2001/02/20 08:51:07 itojun Exp $ */
/*
{
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 ||
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)
-/* $OpenBSD: if_mpe.c,v 1.43 2015/04/10 13:58:20 dlg Exp $ */
+/* $OpenBSD: if_mpe.c,v 1.44 2015/05/15 10:15:13 mpi Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@spootnik.org>
struct rtentry *rt)
{
struct shim_hdr shim;
- int s;
int error;
int off;
u_int8_t op = 0;
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++;
-/* $OpenBSD: if_pppx.c,v 1.37 2015/04/10 13:58:20 dlg Exp $ */
+/* $OpenBSD: if_pppx.c,v 1.38 2015/05/15 10:15:13 mpi Exp $ */
/*
* Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org>
struct rtentry *rt)
{
int error = 0;
- int proto, s;
+ int proto;
if (!ISSET(ifp->if_flags, IFF_UP)) {
m_freem(m);
}
*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++;
-/* $OpenBSD: if_spppsubr.c,v 1.132 2015/04/10 13:58:20 dlg Exp $ */
+/* $OpenBSD: if_spppsubr.c,v 1.133 2015/05/15 10:15:13 mpi Exp $ */
/*
* Synchronous PPP/Cisco link level subroutines.
* Keepalive protocol implemented in both Cisco and PPP modes.
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
* 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);
}
-/* $OpenBSD: if_trunk.c,v 1.98 2015/05/14 10:55:28 mpi Exp $ */
+/* $OpenBSD: if_trunk.c,v 1.99 2015/05/15 10:15:13 mpi Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org>
}
}
-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)
{
}
/* 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 */
}
/* Send mbuf */
- return (trunk_enqueue(tp->tp_if, m));
+ return (if_output(tp->tp_if, m));
}
int
}
/* Send mbuf */
- return (trunk_enqueue(tp->tp_if, m));
+ return (if_output(tp->tp_if, m));
}
int
break;
}
- ret = trunk_enqueue(last->tp_if, m);
+ ret = if_output(last->tp_if, m);
if (ret != 0)
errors++;
}
return (ENOENT);
}
- ret = trunk_enqueue(last->tp_if, m0);
+ ret = if_output(last->tp_if, m0);
if (ret != 0)
errors++;
}
/* Send mbuf */
- return (trunk_enqueue(tp->tp_if, m));
+ return (if_output(tp->tp_if, m));
}
int
-/* $OpenBSD: if_tun.c,v 1.139 2015/04/30 15:19:50 mpi Exp $ */
+/* $OpenBSD: if_tun.c,v 1.140 2015/05/15 10:15:13 mpi Exp $ */
/* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */
/*
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)) {
}
#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);
-/* $OpenBSD: if_var.h,v 1.25 2015/04/23 09:45:24 dlg Exp $ */
+/* $OpenBSD: if_var.h,v 1.26 2015/05/15 10:15:13 mpi Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
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 *);
-/* $OpenBSD: if_vlan.c,v 1.118 2015/04/22 06:42:11 mpi Exp $ */
+/* $OpenBSD: if_vlan.c,v 1.119 2015/05/15 10:15:13 mpi Exp $ */
/*
* Copyright 1998 Massachusetts Institute of Technology
struct ifvlan *ifv;
struct ifnet *p;
struct mbuf *m;
- int error;
ifv = ifp->if_softc;
p = ifv->ifv_p;
}
#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);
}
}
-/* $OpenBSD: trunklacp.c,v 1.20 2015/05/11 08:41:43 mpi Exp $ */
+/* $OpenBSD: trunklacp.c,v 1.21 2015/05/15 10:15:13 mpi Exp $ */
/* $NetBSD: ieee8023ad_lacp.c,v 1.3 2005/12/11 12:24:54 christos Exp $ */
/* $FreeBSD:ieee8023ad_lacp.c,v 1.15 2008/03/16 19:25:30 thompsa Exp $ */
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)
* 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);
}
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)
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);
}
ðermulticastaddr_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: