[TEST/REVIEW] bridge(4) and ng_ether(4) interaction
Gleb Smirnoff
glebius at freebsd.org
Fri Oct 1 01:17:01 PDT 2004
On Fri, Oct 01, 2004 at 12:14:53PM +0400, Gleb Smirnoff wrote:
T> This patch is intended to fix interoperation
and the patch is in this message.
--
Totus tuus, Glebius.
GLEBIUS-RIPN GLEB-RIPE
-------------- next part --------------
Index: netgraph/ng_ether.c
===================================================================
RCS file: /home/ncvs/src/sys/netgraph/ng_ether.c,v
retrieving revision 1.38
diff -u -r1.38 ng_ether.c
--- netgraph/ng_ether.c 28 Jul 2004 06:54:55 -0000 1.38
+++ netgraph/ng_ether.c 6 Sep 2004 22:07:20 -0000
@@ -53,6 +53,7 @@
#include <sys/syslog.h>
#include <sys/socket.h>
+#include <net/bridge.h>
#include <net/if.h>
#include <net/if_types.h>
#include <net/if_arp.h>
@@ -552,6 +553,10 @@
m->m_pkthdr.rcvif = priv->ifp;
+ if (BDG_ACTIVE(priv->ifp) )
+ if ((m = bridge_in_ptr(priv->ifp, m)) == NULL)
+ return (0);
+
/* Route packet back in */
ether_demux(priv->ifp, m);
return (0);
Index: net/bridge.c
===================================================================
RCS file: /home/ncvs/src/sys/net/bridge.c,v
retrieving revision 1.83
diff -u -r1.83 bridge.c
--- net/bridge.c 27 Aug 2004 15:16:22 -0000 1.83
+++ net/bridge.c 6 Sep 2004 22:16:38 -0000
@@ -240,6 +240,7 @@
static int bdginit(void);
static void parse_bdg_cfg(void);
+static struct mbuf *bdg_forward(struct mbuf *, struct ifnet *);
static int bdg_ipf; /* IPFilter enabled in bridge */
SYSCTL_INT(_net_link_ether_bridge, OID_AUTO, ipf, CTLFLAG_RW,
@@ -760,13 +761,16 @@
* to fetch more of the packet, or simply drop it completely.
*/
-static struct ifnet *
-bridge_in(struct ifnet *ifp, struct ether_header *eh)
+static struct mbuf *
+bridge_in(struct ifnet *ifp, struct mbuf *m)
{
- int index;
+ struct ether_header *eh;
struct ifnet *dst, *old;
bdg_hash_table *bt; /* location in hash table */
int dropit = BDG_MUTED(ifp);
+ int index;
+
+ eh = mtod(m, struct ether_header *);
/*
* hash the source address
@@ -856,7 +860,28 @@
(dst <= BDG_FORWARD) ? bdg_dst_names[(uintptr_t)dst] :
dst->if_xname));
- return dst;
+ switch ((uintptr_t)dst) {
+ case (uintptr_t)BDG_DROP:
+ m_freem(m);
+ return (NULL);
+ case (uintptr_t)BDG_LOCAL:
+ return (m);
+ case (uintptr_t)BDG_BCAST:
+ case (uintptr_t)BDG_MCAST:
+ m = bdg_forward(m, dst);
+#ifdef DIAGNOSTIC /* glebius: am I right here? */
+ if (m == NULL) {
+ if_printf(ifp, "bridge dropped %s packet\n",
+ dst == BDG_BCAST ? "broadcast" : "multicast");
+ return (NULL);
+ }
+#endif
+ return (m);
+ default:
+ m = bdg_forward(m, dst);
+ }
+
+ return (NULL); /* not reached */
}
/*
Index: net/bridge.h
===================================================================
RCS file: /home/ncvs/src/sys/net/bridge.h,v
retrieving revision 1.12
diff -u -r1.12 bridge.h
--- net/bridge.h 15 Nov 2002 00:00:14 -0000 1.12
+++ net/bridge.h 6 Sep 2004 22:03:36 -0000
@@ -101,7 +101,7 @@
#define BDG_STAT(ifp, type) bdg_stats.s[ifp->if_index].p_in[(uintptr_t)type]++
#ifdef _KERNEL
-typedef struct ifnet *bridge_in_t(struct ifnet *, struct ether_header *);
+typedef struct mbuf *bridge_in_t(struct ifnet *, struct mbuf *);
/* bdg_forward frees the mbuf if necessary, returning null */
typedef struct mbuf *bdg_forward_t(struct mbuf *, struct ifnet *);
typedef void bdgtakeifaces_t(void);
Index: net/if_ethersubr.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_ethersubr.c,v
retrieving revision 1.177
diff -u -r1.177 if_ethersubr.c
--- net/if_ethersubr.c 27 Jul 2004 23:20:45 -0000 1.177
+++ net/if_ethersubr.c 6 Sep 2004 22:02:27 -0000
@@ -566,53 +566,9 @@
}
/* Check for bridging mode */
- if (BDG_ACTIVE(ifp) ) {
- struct ifnet *bif;
-
- /*
- * Check with bridging code to see how the packet
- * should be handled. Possibilities are:
- *
- * BDG_BCAST broadcast
- * BDG_MCAST multicast
- * BDG_LOCAL for local address, don't forward
- * BDG_DROP discard
- * ifp forward only to specified interface(s)
- *
- * Non-local destinations are handled by passing the
- * packet back to the bridge code.
- */
- bif = bridge_in_ptr(ifp, eh);
- if (bif == BDG_DROP) { /* discard packet */
- m_freem(m);
+ if (BDG_ACTIVE(ifp) )
+ if ((m = bridge_in_ptr(ifp, m)) == NULL)
return;
- }
- if (bif != BDG_LOCAL) { /* non-local, forward */
- m = bdg_forward_ptr(m, bif);
- /*
- * The bridge may consume the packet if it's not
- * supposed to be passed up or if a problem occurred
- * while doing its job. This is reflected by it
- * returning a NULL mbuf pointer.
- */
- if (m == NULL) {
- if (bif == BDG_BCAST || bif == BDG_MCAST)
- if_printf(ifp,
- "bridge dropped %s packet\n",
- bif == BDG_BCAST ? "broadcast" :
- "multicast");
- return;
- }
- /*
- * But in some cases the bridge may return the
- * packet for us to free; sigh.
- */
- if (bif != BDG_BCAST && bif != BDG_MCAST) {
- m_freem(m);
- return;
- }
- }
- }
ether_demux(ifp, m);
/* First chunk of an mbuf contains good entropy */
More information about the freebsd-net
mailing list