From vak@hanoi.cronyx.ru Wed Dec  1 05:20:41 1999
Return-Path: <vak@hanoi.cronyx.ru>
Received: from hanoi.cronyx.ru (hanoi-gw.cronyx.ru [144.206.181.253])
	by hub.freebsd.org (Postfix) with ESMTP id 443AF14D48
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  1 Dec 1999 05:20:23 -0800 (PST)
	(envelope-from vak@hanoi.cronyx.ru)
Received: by hanoi.cronyx.ru id QAA00490;
  (8.9.3/vak/2.1) Wed, 1 Dec 1999 16:21:18 +0300 (MSK)
Message-Id: <199912011321.QAA00490@hanoi.cronyx.ru>
Date: Wed, 1 Dec 1999 16:21:18 +0300 (MSK)
From: vak@cronyx.ru
Sender: vak@hanoi.cronyx.ru
To: FreeBSD-gnats-submit@freebsd.org
Subject: patch to add bridging to if_vr.c
X-Send-Pr-Version: 3.2

>Number:         15206
>Category:       kern
>Synopsis:       Ethernet driver if_vr.c (VIA Technologies)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    archie
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec  1 05:40:03 PST 1999
>Closed-Date:    Mon Sep 18 13:36:56 PDT 2000
>Last-Modified:  Mon Sep 18 13:37:56 PDT 2000
>Originator:     Serge V.Vakulenko
>Release:        FreeBSD 3.3-RELEASE i386
>Organization:
Cronyx Engineering Ltd.
>Environment:

FreeBSD router with two D-Link DFE-530 Ethernet adapters installed.

>Description:

Bridging does not work properly.
The bridge functionality is missing in the driver.

>How-To-Repeat:

Enable BRIDGE option in the kernel and enable
sysctl -w net.link.ether.bridge=1
in /etc/rc.local. Try ping across the bridge.

>Fix:
	
--- if_vr33.c	Wed Dec  1 16:08:38 1999
+++ if_vr.c	Wed Dec  1 16:00:23 1999
@@ -79,6 +79,11 @@
 #include <net/bpf.h>
 #endif
 
+#include "opt_bdg.h"
+#ifdef BRIDGE
+#include <net/bridge.h>
+#endif
+
 #include <vm/vm.h>              /* for vtophys */
 #include <vm/pmap.h>            /* for vtophys */
 #include <machine/clock.h>      /* for DELAY */
@@ -1318,22 +1323,43 @@
 		m->m_pkthdr.len = m->m_len = total_len;
 #if NBPFILTER > 0
 		/*
-		 * Handle BPF listeners. Let the BPF user see the packet, but
-		 * don't pass it up to the ether_input() layer unless it's
-		 * a broadcast packet, multicast packet, matches our ethernet
-		 * address or the interface is in promiscuous mode.
+		 * Handle BPF listeners. Let the BPF user see the packet.
 		 */
-		if (ifp->if_bpf) {
+		if (ifp->if_bpf)
 			bpf_mtap(ifp, m);
-			if (ifp->if_flags & IFF_PROMISC &&
-				(bcmp(eh->ether_dhost, sc->arpcom.ac_enaddr,
-						ETHER_ADDR_LEN) &&
-					(eh->ether_dhost[0] & 1) == 0)) {
+#endif
+#ifdef BRIDGE /* see code in if_ed.c */
+		if (do_bridge) {
+			struct ifnet *bdg_ifp ;
+			bdg_ifp = bridge_in(m);
+			if (bdg_ifp == BDG_DROP) {
 				m_freem(m);
 				continue;
 			}
+			if (bdg_ifp != BDG_LOCAL)
+				bdg_forward(&m, bdg_ifp);
+			if (bdg_ifp != BDG_LOCAL && bdg_ifp != BDG_BCAST &&
+                            bdg_ifp != BDG_MCAST) {
+				/* not local and not multicast, just drop it */
+				if (m)
+					m_freem(m);
+				continue;
+			}
+			/* all others accepted locally */
 		}
 #endif
+		/*
+		 * Don't pass it up to the ether_input() layer unless it's
+		 * a broadcast packet, multicast packet, matches our ethernet
+		 * address or the interface is in promiscuous mode.
+		 */
+		if (ifp->if_flags & IFF_PROMISC &&
+			(bcmp(eh->ether_dhost, sc->arpcom.ac_enaddr,
+					ETHER_ADDR_LEN) &&
+				(eh->ether_dhost[0] & 1) == 0)) {
+			m_freem(m);
+			continue;
+		}
 		/* Remove header from mbuf and pass it on. */
 		m_adj(m, sizeof(struct ether_header));
 		ether_input(ifp, eh, m);

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: johan 
State-Changed-When: Mon Aug 14 11:40:58 PDT 2000 
State-Changed-Why:  
From rev 1.28 of this file 
"Move code to handle BPF and bridging for incoming Ethernet packets out 
of the individual drivers and into the common routine ether_input(). 
Also, remove the (incomplete) hack for matching ethernet headers 
in the ip_fw code. 

The good news: net result of 1016 lines removed, and this should make 
bridging now work with *all* Ethernet drivers. 

The bad news: it's nearly impossible to test every driver, especially 
for bridging, and I was unable to get much testing help on the mailing 
lists." 

Please try the bridging in FreeBSD 4.1-RELEASE (it has been MFC:d) 
and report back if it works with this driver. 





Responsible-Changed-From-To: freebsd-bugs->archie 
Responsible-Changed-By: johan 
Responsible-Changed-When: Mon Aug 14 11:40:58 PDT 2000 
Responsible-Changed-Why:  
Archie will be interested in the feedback and this is also 
a MFC to 3.x reminder. If it is not possible to MFC maybe 
you can apply the suggested patch for 3.x. 
Forget the MFC part this has benn fixed in rev 1.7.2.4. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15206 

From: "Serge Vakulenko" <vak@cronyx.ru>
To: johan@freebsd.org, freebsd-bugs@freebsd.org, archie@freebsd.org
Cc:  
Subject: Re: kern/15206: Ethernet driver if_vr.c (VIA Technologies)
Date: Tue, 29 Aug 2000 12:51:37 +0400

 > The good news: net result of 1016 lines removed, and this should make
 > bridging now work with *all* Ethernet drivers.
 >
 > The bad news: it's nearly impossible to test every driver, especially
 > for bridging, and I was unable to get much testing help on the mailing
 > lists."
 >
 > Please try the bridging in FreeBSD 4.1-RELEASE (it has been MFC:d)
 > and report back if it works with this driver.
 
 Sorry, I cannot try it wight now, and probably would not in a reasonable
 amount of time.
 My FreeBSD-based bridge works now under a heavy load, 24 hours/day,
 and I cannot use it for experiments...
 ___
 Serge Vakulenko
 
 
 
 To Unsubscribe: send mail to majordomo@FreeBSD.org
 with "unsubscribe freebsd-bugs" in the body of the message
 
 
State-Changed-From-To: feedback->closed 
State-Changed-By: archie 
State-Changed-When: Mon Sep 18 13:36:56 PDT 2000 
State-Changed-Why:  
FreeBSD 3.x not supported any more. If problem persists in 4.1-stable 
after upgrading please refile another PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15206 
>Unformatted:
