summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2015-06-25 09:20:20 +0000
committermpi <mpi@openbsd.org>2015-06-25 09:20:20 +0000
commit70e025bbd9ba25c202cf068b104745bb75fdc572 (patch)
tree879c2647a649631a7ea0500f4dd6918599547f1b /sys
parentCheck for correct rdomain in if_output() rather than in ether_output(). (diff)
downloadwireguard-openbsd-70e025bbd9ba25c202cf068b104745bb75fdc572.tar.xz
wireguard-openbsd-70e025bbd9ba25c202cf068b104745bb75fdc572.zip
Move brige(4)'s output hook outside of ether_output().
This fix some weird bridge(4) configurations involving pseudo-drivers stacked on top of interfaces in a bridge. Also simplifies the loop prevention logic to match bridge's input path. Instead of using a tag per port/bridge simply flag output mbufs to make sure only one copy per bridge go through bridge_output(). ok bluhm@, claudio@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if.c8
-rw-r--r--sys/net/if_bridge.c6
-rw-r--r--sys/net/if_ethersubr.c43
-rw-r--r--sys/sys/mbuf.h3
4 files changed, 13 insertions, 47 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index fd6270eba91..a4a480bbb75 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.344 2015/06/25 09:10:15 mpi Exp $ */
+/* $OpenBSD: if.c,v 1.345 2015/06/25 09:20:20 mpi Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -455,6 +455,12 @@ if_output(struct ifnet *ifp, struct mbuf *m)
}
#endif
+#if NBRIDGE > 0
+ if (ifp->if_bridgeport && (m->m_flags & M_PROTO1) == 0)
+ return (bridge_output(ifp, m, NULL, NULL));
+ m->m_flags &= ~M_PROTO1; /* Loop prevention */
+#endif
+
length = m->m_pkthdr.len;
mflags = m->m_flags;
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index 122dab66d59..62b7cb9eefa 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bridge.c,v 1.246 2015/06/24 09:40:54 mpi Exp $ */
+/* $OpenBSD: if_bridge.c,v 1.247 2015/06/25 09:20:20 mpi Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
@@ -2603,10 +2603,12 @@ bridge_ifenqueue(struct bridge_softc *sc, struct ifnet *ifp, struct mbuf *m)
{
int error, len;
+ /* Loop prevention. */
+ m->m_flags |= M_PROTO1;
+
#if NGIF > 0
/* Packet needs etherip encapsulation. */
if (ifp->if_type == IFT_GIF) {
- m->m_flags |= M_PROTO1;
/* Count packets input into the gif from outside */
ifp->if_ipackets++;
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 5de5e25c998..6470788889b 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ethersubr.c,v 1.208 2015/06/25 09:10:15 mpi Exp $ */
+/* $OpenBSD: if_ethersubr.c,v 1.209 2015/06/25 09:20:20 mpi Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */
/*
@@ -268,47 +268,6 @@ ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
memcpy(eh->ether_dhost, edst, sizeof(eh->ether_dhost));
memcpy(eh->ether_shost, esrc, sizeof(eh->ether_shost));
-#if NBRIDGE > 0
- /*
- * Interfaces that are bridgeports need special handling for output.
- */
- if (ifp->if_bridgeport) {
- struct m_tag *mtag;
-
- /*
- * Check if this packet has already been sent out through
- * this bridgeport, in which case we simply send it out
- * without further bridge processing.
- */
- for (mtag = m_tag_find(m, PACKET_TAG_BRIDGE, NULL); mtag;
- mtag = m_tag_find(m, PACKET_TAG_BRIDGE, mtag)) {
-#ifdef DEBUG
- /* Check that the information is there */
- if (mtag->m_tag_len != sizeof(caddr_t)) {
- error = EINVAL;
- goto bad;
- }
-#endif
- if (!memcmp(&ifp->if_bridgeport, mtag + 1,
- sizeof(caddr_t)))
- break;
- }
- if (mtag == NULL) {
- /* Attach a tag so we can detect loops */
- mtag = m_tag_get(PACKET_TAG_BRIDGE, sizeof(caddr_t),
- M_NOWAIT);
- if (mtag == NULL) {
- error = ENOBUFS;
- goto bad;
- }
- memcpy(mtag + 1, &ifp->if_bridgeport, sizeof(caddr_t));
- m_tag_prepend(m, mtag);
- error = bridge_output(ifp, m, NULL, NULL);
- return (error);
- }
- }
-#endif
-
return (if_output(ifp, m));
bad:
if (m)
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index af6054af78d..ce3c7f3b011 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbuf.h,v 1.192 2015/06/16 11:09:40 mpi Exp $ */
+/* $OpenBSD: mbuf.h,v 1.193 2015/06/25 09:20:20 mpi Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
@@ -454,7 +454,6 @@ struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
/* Packet tag types */
#define PACKET_TAG_IPSEC_IN_DONE 0x0001 /* IPsec applied, in */
#define PACKET_TAG_IPSEC_OUT_DONE 0x0002 /* IPsec applied, out */
-#define PACKET_TAG_BRIDGE 0x0020 /* Bridge processing done */
#define PACKET_TAG_GIF 0x0040 /* GIF processing done */
#define PACKET_TAG_GRE 0x0080 /* GRE processing done */
#define PACKET_TAG_DLT 0x0100 /* data link layer type */