summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-05-15 10:15:14 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-05-15 10:15:14 +0000
commit0fa2da2a749fe5fda3337a2a56bfc0033d13c456 (patch)
tree58c75f2038d7c8ecaac55a3ea51c0025e92fedbd
parentca841eaed417bbf7a3c98537c1c58da366438e19 (diff)
Introduce if_output(), a function do to the last steps before enqueuing
a packet on the sending queue of an interface. Tested by many, thanks a lot! ok dlg@, claudio@
-rw-r--r--sys/net/bridgestp.c23
-rw-r--r--sys/net/if.c35
-rw-r--r--sys/net/if_bridge.c12
-rw-r--r--sys/net/if_ethersubr.c28
-rw-r--r--sys/net/if_gif.c17
-rw-r--r--sys/net/if_mpe.c14
-rw-r--r--sys/net/if_pppx.c14
-rw-r--r--sys/net/if_spppsubr.c18
-rw-r--r--sys/net/if_trunk.c37
-rw-r--r--sys/net/if_tun.c11
-rw-r--r--sys/net/if_var.h3
-rw-r--r--sys/net/if_vlan.c17
-rw-r--r--sys/net/trunklacp.c16
13 files changed, 82 insertions, 163 deletions
diff --git a/sys/net/bridgestp.c b/sys/net/bridgestp.c
index e4b09da504a..74504acd6ba 100644
--- a/sys/net/bridgestp.c
+++ b/sys/net/bridgestp.c
@@ -1,4 +1,4 @@
-/* $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)
@@ -353,7 +353,6 @@ bstp_transmit_tcn(struct bstp_state *bs, struct bstp_port *bp)
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, struct bstp_port *bp)
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, struct bstp_port *bp,
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, struct bstp_port *bp,
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);
}
diff --git a/sys/net/if.c b/sys/net/if.c
index 28e2596ca37..6fca91012a2 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -441,6 +441,39 @@ if_start(struct ifnet *ifp)
}
}
+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);
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index 001133a5e4f..44aeb85ad25 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -1,4 +1,4 @@
-/* $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)
@@ -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, struct ifnet *ifp, struct mbuf *m)
}
#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);
}
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 4262c49e6d7..1cf0d1cc37c 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -249,14 +249,13 @@ ether_output(struct ifnet *ifp0, struct mbuf *m0, struct sockaddr *dst,
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
@@ -404,30 +403,15 @@ ether_output(struct ifnet *ifp0, struct mbuf *m0, struct sockaddr *dst,
}
}
#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);
diff --git a/sys/net/if_gif.c b/sys/net/if_gif.c
index a60d2cdf731..3c70d959dca 100644
--- a/sys/net/if_gif.c
+++ b/sys/net/if_gif.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -276,7 +276,6 @@ gif_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
{
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 mbuf *m, struct sockaddr *dst,
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)
diff --git a/sys/net/if_mpe.c b/sys/net/if_mpe.c
index a868a27cf28..f2a7bde7d6d 100644
--- a/sys/net/if_mpe.c
+++ b/sys/net/if_mpe.c
@@ -1,4 +1,4 @@
-/* $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>
@@ -203,7 +203,6 @@ mpeoutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
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, struct sockaddr *dst,
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++;
diff --git a/sys/net/if_pppx.c b/sys/net/if_pppx.c
index 00de01c7498..eb4d0f15109 100644
--- a/sys/net/if_pppx.c
+++ b/sys/net/if_pppx.c
@@ -1,4 +1,4 @@
-/* $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>
@@ -1034,7 +1034,7 @@ pppx_if_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
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 mbuf *m, struct sockaddr *dst,
}
*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++;
diff --git a/sys/net/if_spppsubr.c b/sys/net/if_spppsubr.c
index 0c6b9fb4a0d..ea4cf3a9106 100644
--- a/sys/net/if_spppsubr.c
+++ b/sys/net/if_spppsubr.c
@@ -1,4 +1,4 @@
-/* $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.
@@ -620,7 +620,7 @@ sppp_output(struct ifnet *ifp, struct mbuf *m,
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 mbuf *m,
* 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);
}
diff --git a/sys/net/if_trunk.c b/sys/net/if_trunk.c
index 2997d2e8927..845d6f78755 100644
--- a/sys/net/if_trunk.c
+++ b/sys/net/if_trunk.c
@@ -1,4 +1,4 @@
-/* $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>
@@ -971,29 +971,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)
{
@@ -1326,7 +1303,7 @@ trunk_rr_start(struct trunk_softc *tr, struct mbuf *m)
}
/* 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 */
@@ -1382,7 +1359,7 @@ trunk_fail_start(struct trunk_softc *tr, struct mbuf *m)
}
/* Send mbuf */
- return (trunk_enqueue(tp->tp_if, m));
+ return (if_output(tp->tp_if, m));
}
int
@@ -1509,7 +1486,7 @@ trunk_lb_start(struct trunk_softc *tr, struct mbuf *m)
}
/* Send mbuf */
- return (trunk_enqueue(tp->tp_if, m));
+ return (if_output(tp->tp_if, m));
}
int
@@ -1569,7 +1546,7 @@ trunk_bcast_start(struct trunk_softc *tr, struct mbuf *m0)
break;
}
- ret = trunk_enqueue(last->tp_if, m);
+ ret = if_output(last->tp_if, m);
if (ret != 0)
errors++;
}
@@ -1580,7 +1557,7 @@ trunk_bcast_start(struct trunk_softc *tr, struct mbuf *m0)
return (ENOENT);
}
- ret = trunk_enqueue(last->tp_if, m0);
+ ret = if_output(last->tp_if, m0);
if (ret != 0)
errors++;
@@ -1654,7 +1631,7 @@ trunk_lacp_start(struct trunk_softc *tr, struct mbuf *m)
}
/* Send mbuf */
- return (trunk_enqueue(tp->tp_if, m));
+ return (if_output(tp->tp_if, m));
}
int
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c
index 5bb0bb26ca8..5316d6d2485 100644
--- a/sys/net/if_tun.c
+++ b/sys/net/if_tun.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -529,7 +529,7 @@ tun_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst,
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 mbuf *m0, struct sockaddr *dst,
}
#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);
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 6c84dd2e183..a226f62bf4b 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -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 *);
diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index 84f98f43983..825c36d90ab 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -1,4 +1,4 @@
-/* $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
@@ -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);
}
}
diff --git a/sys/net/trunklacp.c b/sys/net/trunklacp.c
index 2798db0c613..6e707d54dad 100644
--- a/sys/net/trunklacp.c
+++ b/sys/net/trunklacp.c
@@ -1,4 +1,4 @@
-/* $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 $ */
@@ -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, struct mbuf *m)
&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: