From owner-freebsd-net@FreeBSD.ORG Fri Oct 1 08:17:00 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EAED616A4CE for ; Fri, 1 Oct 2004 08:17:00 +0000 (GMT) Received: from cell.sick.ru (cell.sick.ru [217.72.144.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id 21DBB43D3F for ; Fri, 1 Oct 2004 08:17:00 +0000 (GMT) (envelope-from glebius@freebsd.org) Received: from cell.sick.ru (glebius@localhost [127.0.0.1]) by cell.sick.ru (8.12.11/8.12.8) with ESMTP id i918Gwf4050639 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 1 Oct 2004 12:16:59 +0400 (MSD) (envelope-from glebius@freebsd.org) Received: (from glebius@localhost) by cell.sick.ru (8.12.11/8.12.11/Submit) id i918GwQd050638 for net@freebsd.org; Fri, 1 Oct 2004 12:16:58 +0400 (MSD) (envelope-from glebius@freebsd.org) X-Authentication-Warning: cell.sick.ru: glebius set sender to glebius@freebsd.org using -f Date: Fri, 1 Oct 2004 12:16:58 +0400 From: Gleb Smirnoff To: net@freebsd.org Message-ID: <20041001081658.GF49512@cell.sick.ru> References: <20041001081453.GE49512@cell.sick.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="IJpNTDwzlM2Ie8A6" Content-Disposition: inline In-Reply-To: <20041001081453.GE49512@cell.sick.ru> User-Agent: Mutt/1.5.6i Subject: Re: [TEST/REVIEW] bridge(4) and ng_ether(4) interaction X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Oct 2004 08:17:01 -0000 --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline 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 --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=koi8-r Content-Disposition: attachment; filename="ng_ether+bridge.patch2" 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 #include +#include #include #include #include @@ -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 */ --IJpNTDwzlM2Ie8A6--