2 * Copyright (c) 1998-2001 Luigi Rizzo
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * This code implements bridging in FreeBSD. It only acts on ethernet
30 * type of interfaces (others are still usable for routing).
31 * A bridging table holds the source MAC address/dest. interface for each
32 * known node. The table is indexed using an hash of the source address.
34 * Input packets are tapped near the beginning of ether_input(), and
35 * analysed by calling bridge_in(). Depending on the result, the packet
36 * can be forwarded to one or more output interfaces using bdg_forward(),
37 * and/or sent to the upper layer (e.g. in case of multicast).
39 * Output packets are intercepted near the end of ether_output(),
40 * the correct destination is selected calling bridge_dst_lookup(),
41 * and then forwarding is done using bdg_forward().
42 * Bridging is controlled by the sysctl variable net.link.ether.bridge
44 * The arp code is also modified to let a machine answer to requests
45 * irrespective of the port the request came from.
47 * In case of loops in the bridging topology, the bridge detects this
48 * event and temporarily mutes output bridging on one of the ports.
49 * Periodically, interfaces are unmuted by bdg_timeout().
50 * Muting is only implemented as a safety measure, and also as
51 * a mechanism to support a user-space implementation of the spanning
52 * tree algorithm. In the final release, unmuting will only occur
53 * because of explicit action of the user-level daemon.
55 * To build a bridging kernel, use the following option
57 * and then at runtime set the sysctl variable to enable bridging.
59 * Only one interface is supposed to have addresses set (but
60 * there are no problems in practice if you set addresses for more
61 * than one interface).
62 * Bridging will act before routing, but nothing prevents a machine
63 * from doing both (modulo bugs in the implementation...).
66 * - bridging is incompatible with multicast routing on the same
67 * machine. There is not an easy fix to this.
68 * - loop detection is still not very robust.
69 * - the interface of bdg_forward() could be improved.
72 #include <sys/param.h>
74 #include <sys/malloc.h>
75 #include <sys/systm.h>
76 #include <sys/socket.h> /* for net/if.h */
77 #include <sys/kernel.h>
78 #include <sys/sysctl.h>
81 #include <net/if_types.h>
82 #include <net/if_var.h>
84 #include <netinet/in.h> /* for struct arpcom */
85 #include <netinet/in_systm.h>
86 #include <netinet/in_var.h>
87 #include <netinet/ip.h>
88 #include <netinet/if_ether.h> /* for struct arpcom */
93 #if defined(IPFIREWALL)
94 #include <net/route.h>
95 #include <netinet/ip_fw.h>
97 #include <netinet/ip_dummynet.h>
101 #include <net/bridge.h>
104 * For debugging, you can use the following macros.
105 * remember, rdtsc() only works on Pentium-class machines
108 DDB(ticks = rdtsc();)
109 ... interesting code ...
110 DDB(bdg_fw_ticks += (u_long)(rdtsc() - ticks) ; bdg_fw_count++ ;)
118 static void bdginit(void *);
119 static void flush_table(void);
120 static void bdg_promisc_on(void);
121 static void parse_bdg_cfg(void);
123 static int bdg_initialized = 0;
125 static int bdg_ipfw = 0 ;
127 bdg_hash_table *bdg_table = NULL ;
130 * System initialization
133 SYSINIT(interfaces, SI_SUB_PROTO_IF, SI_ORDER_FIRST, bdginit, NULL)
135 static struct bdg_stats bdg_stats ;
136 struct bdg_softc *ifp2sc = NULL ;
137 /* XXX make it static of size BDG_MAX_PORTS */
139 #define IFP_CHK(ifp, x) \
140 if (ifp2sc[ifp->if_index].magic != 0xDEADBEEF) { x ; }
143 * turn off promisc mode, optionally clear the IFF_USED flag.
144 * The flag is turned on by parse_bdg_config
147 bdg_promisc_off(int clear_used)
150 TAILQ_FOREACH(ifp, &ifnet, if_link) {
151 if ( (ifp2sc[ifp->if_index].flags & IFF_BDG_PROMISC) ) {
154 ret = ifpromisc(ifp, 0);
156 ifp2sc[ifp->if_index].flags &= ~(IFF_BDG_PROMISC|IFF_MUTE) ;
157 DEB(printf(">> now %s%d promisc OFF if_flags 0x%x bdg_flags 0x%x\n",
158 ifp->if_name, ifp->if_unit,
159 ifp->if_flags, ifp2sc[ifp->if_index].flags);)
162 ifp2sc[ifp->if_index].flags &= ~(IFF_USED) ;
163 bdg_stats.s[ifp->if_index].name[0] = '\0';
169 * set promisc mode on the interfaces we use.
177 TAILQ_FOREACH(ifp, &ifnet, if_link) {
178 if ( !BDG_USED(ifp) )
180 if ( 0 == ( ifp->if_flags & IFF_UP) ) {
185 if ( !(ifp2sc[ifp->if_index].flags & IFF_BDG_PROMISC) ) {
188 ret = ifpromisc(ifp, 1);
190 ifp2sc[ifp->if_index].flags |= IFF_BDG_PROMISC ;
191 printf(">> now %s%d promisc ON if_flags 0x%x bdg_flags 0x%x\n",
192 ifp->if_name, ifp->if_unit,
193 ifp->if_flags, ifp2sc[ifp->if_index].flags);
195 if (BDG_MUTED(ifp)) {
196 printf(">> unmuting %s%d\n", ifp->if_name, ifp->if_unit);
203 sysctl_bdg(SYSCTL_HANDLER_ARGS)
205 int error, oldval = do_bridge ;
207 error = sysctl_handle_int(oidp,
208 oidp->oid_arg1, oidp->oid_arg2, req);
209 DEB( printf("called sysctl for bridge name %s arg2 %d val %d->%d\n",
210 oidp->oid_name, oidp->oid_arg2,
211 oldval, do_bridge); )
213 if (bdg_table == NULL)
215 if (oldval != do_bridge) {
216 bdg_promisc_off( 1 ); /* reset previously used interfaces */
226 static char bridge_cfg[256] = { "" } ;
229 * parse the config string, set IFF_USED, name and cluster_id
230 * for all interfaces found.
239 for (p= bridge_cfg; *p ; p++) {
240 /* interface names begin with [a-z] and continue up to ':' */
241 if (*p < 'a' || *p > 'z')
243 for ( beg = p ; *p && *p != ':' ; p++ )
245 if (*p == 0) /* end of string, ':' not found */
247 l = p - beg ; /* length of name string */
249 DEB(printf("-- match beg(%d) <%s> p <%s>\n", l, beg, p);)
250 for (cluster = 0 ; *p && *p >= '0' && *p <= '9' ; p++)
251 cluster = cluster*10 + (*p -'0');
253 * now search in bridge strings
255 for (i=0, b = ifp2sc ; i < if_index ; i++, b++) {
257 struct ifnet *ifp = b->ifp ;
261 sprintf(buf, "%s%d", ifp->if_name, ifp->if_unit);
262 if (!strncmp(beg, buf, l)) { /* XXX not correct for >10 if! */
263 b->cluster_id = htons(cluster) ;
264 b->flags |= IFF_USED ;
265 sprintf(bdg_stats.s[ifp->if_index].name,
266 "%s%d:%d", ifp->if_name, ifp->if_unit, cluster);
268 DEB(printf("--++ found %s\n",
269 bdg_stats.s[ifp->if_index].name);)
279 sysctl_bdg_cfg(SYSCTL_HANDLER_ARGS)
284 strcpy(oldval, bridge_cfg) ;
286 error = sysctl_handle_string(oidp,
287 bridge_cfg, oidp->oid_arg2, req);
289 printf("called sysctl for bridge name %s arg2 %d err %d val %s->%s\n",
290 oidp->oid_name, oidp->oid_arg2,
294 if (strcmp(oldval, bridge_cfg)) {
295 bdg_promisc_off( 1 ); /* reset previously-used interfaces */
297 parse_bdg_cfg(); /* and set new ones... */
299 bdg_promisc_on(); /* re-enable interfaces */
305 sysctl_refresh(SYSCTL_HANDLER_ARGS)
314 SYSCTL_DECL(_net_link_ether);
315 SYSCTL_PROC(_net_link_ether, OID_AUTO, bridge_cfg, CTLTYPE_STRING|CTLFLAG_RW,
316 &bridge_cfg, sizeof(bridge_cfg), &sysctl_bdg_cfg, "A",
317 "Bridge configuration");
319 SYSCTL_PROC(_net_link_ether, OID_AUTO, bridge, CTLTYPE_INT|CTLFLAG_RW,
320 &do_bridge, 0, &sysctl_bdg, "I", "Bridging");
322 SYSCTL_INT(_net_link_ether, OID_AUTO, bridge_ipfw, CTLFLAG_RW,
323 &bdg_ipfw,0,"Pass bridged pkts through firewall");
325 #define SY(parent, var, comment) \
327 SYSCTL_INT(parent, OID_AUTO, var, CTLFLAG_RW, &(var), 0, comment);
330 SYSCTL_INT(_net_link_ether, OID_AUTO, bridge_ipfw_drop,
331 CTLFLAG_RW, &bdg_ipfw_drops,0,"");
334 SYSCTL_INT(_net_link_ether, OID_AUTO, bridge_ipfw_collisions,
335 CTLFLAG_RW, &bdg_ipfw_colls,0,"");
337 SYSCTL_PROC(_net_link_ether, OID_AUTO, bridge_refresh, CTLTYPE_INT|CTLFLAG_WR,
338 NULL, 0, &sysctl_refresh, "I", "iface refresh");
340 #if 1 /* diagnostic vars */
342 SY(_net_link_ether, verbose, "Be verbose");
343 SY(_net_link_ether, bdg_split_pkts, "Packets split in bdg_forward");
345 SY(_net_link_ether, bdg_thru, "Packets through bridge");
347 SY(_net_link_ether, bdg_copied, "Packets copied in bdg_forward");
349 SY(_net_link_ether, bdg_copy, "Force copy in bdg_forward");
350 SY(_net_link_ether, bdg_predict, "Correctly predicted header location");
352 SY(_net_link_ether, bdg_fw_avg, "Cycle counter avg");
353 SY(_net_link_ether, bdg_fw_ticks, "Cycle counter item");
354 SY(_net_link_ether, bdg_fw_count, "Cycle counter count");
357 SYSCTL_STRUCT(_net_link_ether, PF_BDG, bdgstats,
358 CTLFLAG_RD, &bdg_stats , bdg_stats, "bridge statistics");
360 static int bdg_loops ;
363 * completely flush the bridge table.
370 if (bdg_table == NULL)
373 for (i=0; i< HASH_SIZE; i++)
374 bdg_table[i].name= NULL; /* clear table */
379 * called periodically to flush entries etc.
382 bdg_timeout(void *dummy)
384 static int slowtimer = 0 ;
387 static int age_index = 0 ; /* index of table position to age */
388 int l = age_index + HASH_SIZE/4 ;
390 * age entries in the forwarding table.
394 for (; age_index < l ; age_index++)
395 if (bdg_table[age_index].used)
396 bdg_table[age_index].used = 0 ;
397 else if (bdg_table[age_index].name) {
398 /* printf("xx flushing stale entry %d\n", age_index); */
399 bdg_table[age_index].name = NULL ;
401 if (age_index >= HASH_SIZE)
404 if (--slowtimer <= 0 ) {
407 bdg_promisc_on() ; /* we just need unmute, really */
411 timeout(bdg_timeout, (void *)0, 2*hz );
415 * local MAC addresses are held in a small array. This makes comparisons
418 bdg_addr bdg_addresses[BDG_MAX_PORTS];
422 * initialization of bridge code. This needs to be done after all
423 * interfaces have been configured.
430 if (bdg_table == NULL)
431 bdg_table = (struct hash_table *)
432 malloc(HASH_SIZE * sizeof(struct hash_table),
436 ifp2sc = malloc(BDG_MAX_PORTS * sizeof(struct bdg_softc),
437 M_IFADDR, M_WAITOK | M_ZERO);
439 bzero(&bdg_stats, sizeof(bdg_stats) );
451 bdg_addr *p = bdg_addresses ;
452 struct bdg_softc *bp;
454 if (!bdg_initialized)
460 printf("BRIDGE 010131, have %d interfaces\n", if_index);
461 for (i = 0 , ifp = TAILQ_FIRST(&ifnet) ; i < if_index ;
462 i++, ifp = TAILQ_NEXT(ifp, if_link))
463 if (ifp->if_type == IFT_ETHER) { /* ethernet ? */
464 bp = &ifp2sc[ifp->if_index] ;
465 ac = (struct arpcom *)ifp;
466 sprintf(bridge_cfg + strlen(bridge_cfg),
467 "%s%d:1,", ifp->if_name, ifp->if_unit);
468 printf("-- index %d %s type %d phy %d addrl %d addr %6D\n",
470 bdg_stats.s[ifp->if_index].name,
471 (int)ifp->if_type, (int) ifp->if_physical,
472 (int)ifp->if_addrlen,
473 ac->ac_enaddr, "." );
474 bcopy(ac->ac_enaddr, p->etheraddr, 6);
477 bp->flags = IFF_USED ;
478 bp->cluster_id = htons(1) ;
479 bp->magic = 0xDEADBEEF ;
481 sprintf(bdg_stats.s[ifp->if_index].name,
482 "%s%d:%d", ifp->if_name, ifp->if_unit,
483 ntohs(bp->cluster_id));
490 * bridge_in() is invoked to perform bridging decision on input packets.
493 * eh Ethernet header of the incoming packet.
495 * On Return: destination of packet, one of
496 * BDG_BCAST broadcast
497 * BDG_MCAST multicast
498 * BDG_LOCAL is only for a local address (do not forward)
499 * BDG_DROP drop the packet
500 * ifp ifp of the destination interface.
502 * Forwarding is not done directly to give a chance to some drivers
503 * to fetch more of the packet, or simply drop it completely.
507 bridge_in(struct ifnet *ifp, struct ether_header *eh)
510 struct ifnet *dst , *old ;
511 int dropit = BDG_MUTED(ifp) ;
514 * hash the source address
516 index= HASH_FN(eh->ether_shost);
517 bdg_table[index].used = 1 ;
518 old = bdg_table[index].name ;
519 if ( old ) { /* the entry is valid. */
520 IFP_CHK(old, printf("bridge_in-- reading table\n") );
522 if (!BDG_MATCH( eh->ether_shost, bdg_table[index].etheraddr) ) {
524 bdg_table[index].name = NULL ;
525 } else if (old != ifp) {
527 * found a loop. Either a machine has moved, or there
528 * is a misconfiguration/reconfiguration of the network.
529 * First, do not forward this packet!
530 * Record the relocation anyways; then, if loops persist,
531 * suspect a reconfiguration and disable forwarding
532 * from the old interface.
534 bdg_table[index].name = ifp ; /* relocate address */
535 printf("-- loop (%d) %6D to %s%d from %s%d (%s)\n",
536 bdg_loops, eh->ether_shost, ".",
537 ifp->if_name, ifp->if_unit,
538 old->if_name, old->if_unit,
539 BDG_MUTED(old) ? "muted":"active");
541 if ( !BDG_MUTED(old) ) {
542 if (++bdg_loops > 10)
549 * now write the source address into the table
551 if (bdg_table[index].name == NULL) {
552 DEB(printf("new addr %6D at %d for %s%d\n",
553 eh->ether_shost, ".", index, ifp->if_name, ifp->if_unit);)
554 bcopy(eh->ether_shost, bdg_table[index].etheraddr, 6);
555 bdg_table[index].name = ifp ;
557 dst = bridge_dst_lookup(eh);
559 * BDG_BCAST, BDG_MCAST, BDG_LOCAL, BDG_UNKNOWN, BDG_DROP, ifp.
560 * For muted interfaces, the first 3 are changed in BDG_LOCAL,
561 * and others to BDG_DROP. Also, for incoming packets, ifp is changed
562 * to BDG_DROP in case ifp == src . These mods are not necessary
563 * for outgoing packets from ether_output().
565 BDG_STAT(ifp, BDG_IN);
570 case (int)BDG_UNKNOWN:
575 if (dst == ifp || dropit )
576 BDG_STAT(ifp, BDG_DROP);
578 BDG_STAT(ifp, BDG_FORWARD);
583 if (dst == BDG_BCAST || dst == BDG_MCAST || dst == BDG_LOCAL)
588 return (dst == ifp ? BDG_DROP : dst ) ;
593 * Forward to dst, excluding src port and muted interfaces.
594 * If src == NULL, the pkt comes from ether_output, and dst is the real
595 * interface the packet is originally sent to. In this case we must forward
596 * it to the whole cluster. We never call bdg_forward ether_output on
597 * interfaces which are not part of a cluster.
599 * The packet is freed if possible (i.e. surely not of interest for
600 * the upper layer), otherwise a copy is left for use by the caller
603 * It would be more efficient to make bdg_forward() always consume
604 * the packet, leaving to the caller the task to check if it needs a copy
605 * and get one in case. As it is now, bdg_forward() can sometimes make
606 * a copy whereas it is not necessary.
608 * XXX be careful about eh, it can be a pointer into *m
611 bdg_forward(struct mbuf *m0, struct ether_header *const eh, struct ifnet *dst)
613 struct ifnet *src = m0->m_pkthdr.rcvif; /* could be NULL in output */
614 struct ifnet *ifp, *last = NULL ;
615 int shared = bdg_copy ; /* someone else is using the mbuf */
616 int once = 0; /* loop only once */
617 struct ifnet *real_dst = dst ; /* real dst from ether_output */
619 struct ip_fw_chain *rule = NULL ; /* did we match a firewall rule ? */
623 * XXX eh is usually a pointer within the mbuf (some ethernet drivers
624 * do that), so we better copy it before doing anything with the mbuf,
625 * or we might corrupt the header.
627 struct ether_header save_eh = *eh ;
629 DEB(quad_t ticks; ticks = rdtsc();)
631 #if defined(IPFIREWALL) && defined(DUMMYNET)
632 if (m0->m_type == MT_DUMMYNET) {
633 /* extract info from dummynet header */
634 rule = (struct ip_fw_chain *)(m0->m_data) ;
636 src = m0->m_pkthdr.rcvif;
637 shared = 0 ; /* For sure this is our own mbuf. */
640 bdg_thru++; /* only count once */
642 if (src == NULL) /* packet from ether_output */
643 dst = bridge_dst_lookup(eh);
645 if (dst == BDG_DROP) { /* this should not happen */
646 printf("xx bdg_forward for BDG_DROP\n");
650 if (dst == BDG_LOCAL) { /* this should not happen as well */
651 printf("xx ouch, bdg_forward for local pkt\n");
654 if (dst == BDG_BCAST || dst == BDG_MCAST || dst == BDG_UNKNOWN) {
655 ifp = TAILQ_FIRST(&ifnet) ; /* scan all ports */
657 if (dst != BDG_UNKNOWN) /* need a copy for the local stack */
663 if ( (u_int)(ifp) <= (u_int)BDG_FORWARD )
664 panic("bdg_forward: bad dst");
668 * Do filtering in a very similar way to what is done in ip_output.
669 * Only if firewall is loaded, enabled, and the packet is not
670 * from ether_output() (src==NULL, or we would filter it twice).
671 * Additional restrictions may apply e.g. non-IP, short packets,
672 * and pkts already gone through a pipe.
674 if (ip_fw_chk_ptr && bdg_ipfw != 0 && src != NULL) {
678 if (rule != NULL) /* dummynet packet, already partially processed */
679 goto forward; /* HACK! I should obey the fw_one_pass */
680 if (ntohs(save_eh.ether_type) != ETHERTYPE_IP)
681 goto forward ; /* not an IP packet, ipfw is not appropriate */
682 if (m0->m_pkthdr.len < sizeof(struct ip) )
683 goto forward ; /* header too short for an IP pkt, cannot filter */
685 * i need some amt of data to be contiguous, and in case others need
686 * the packet (shared==1) also better be in the first mbuf.
688 i = min(m0->m_pkthdr.len, max_protohdr) ;
689 if ( shared || m0->m_len < i) {
690 m0 = m_pullup(m0, i) ;
692 printf("-- bdg: pullup failed.\n") ;
698 * before calling the firewall, swap fields the same as IP does.
699 * here we assume the pkt is an IP one and the header is contiguous
701 ip = mtod(m0, struct ip *);
706 * The third parameter to the firewall code is the dst. interface.
707 * Since we apply checks only on input pkts we use NULL.
708 * The firewall knows this is a bridged packet as the cookie ptr
711 i = (*ip_fw_chk_ptr)(&ip, 0, NULL, NULL /* cookie */, &m0, &rule, NULL);
712 if ( (i & IP_FW_PORT_DENY_FLAG) || m0 == NULL) /* drop */
715 * If we get here, the firewall has passed the pkt, but the mbuf
716 * pointer might have changed. Restore ip and the fields NTOHS()'d.
718 ip = mtod(m0, struct ip *);
722 if (i == 0) /* a PASS rule. */
725 if (i & IP_FW_PORT_DYNT_FLAG) {
727 * Pass the pkt to dummynet, which consumes it.
728 * If shared, make a copy and keep the original.
729 * Need to prepend the ethernet header, optimize the common
730 * case of eh pointing already into the original mbuf.
734 m = m_copypacket(m0, M_DONTWAIT);
736 printf("bdg_fwd: copy(1) failed\n");
740 m = m0 ; /* pass the original to dummynet */
741 m0 = NULL ; /* and nothing back to the caller */
743 if ( (void *)(eh + 1) == (void *)m->m_data) {
744 m->m_data -= ETHER_HDR_LEN ;
745 m->m_len += ETHER_HDR_LEN ;
746 m->m_pkthdr.len += ETHER_HDR_LEN ;
749 M_PREPEND(m, ETHER_HDR_LEN, M_DONTWAIT);
750 if (!m && verbose) printf("M_PREPEND failed\n");
751 if (m == NULL) /* nope... */
753 bcopy(&save_eh, mtod(m, struct ether_header *), ETHER_HDR_LEN);
755 dummynet_io((i & 0xffff),DN_TO_BDG_FWD,m,real_dst,NULL,0,rule,0);
760 * XXX add divert/forward actions...
762 /* if none of the above matches, we have to drop the pkt */
764 printf("bdg_forward: No rules match, so dropping packet!\n");
768 #endif /* IPFIREWALL */
770 * Again, bring up the headers in case of shared bufs to avoid
771 * corruptions in the future.
774 int i = min(m0->m_pkthdr.len, max_protohdr) ;
776 m0 = m_pullup(m0, i) ;
778 printf("-- bdg: pullup2 failed.\n") ;
782 /* now real_dst is used to determine the cluster where to forward */
783 if (src != NULL) /* pkt comes from ether_input */
786 if (last) { /* need to forward packet leftover from previous loop */
788 if (shared == 0 && once ) { /* no need to copy */
790 m0 = NULL ; /* original is gone */
792 m = m_copypacket(m0, M_DONTWAIT);
794 printf("bdg_forward: sorry, m_copypacket failed!\n");
795 return m0 ; /* the original is still there... */
799 * Add header (optimized for the common case of eh pointing
800 * already into the mbuf) and execute last part of ether_output:
801 * queue pkt and start output if interface not yet active.
803 if ( (void *)(eh + 1) == (void *)m->m_data) {
804 m->m_data -= ETHER_HDR_LEN ;
805 m->m_len += ETHER_HDR_LEN ;
806 m->m_pkthdr.len += ETHER_HDR_LEN ;
809 M_PREPEND(m, ETHER_HDR_LEN, M_DONTWAIT);
810 if (!m && verbose) printf("M_PREPEND failed\n");
813 bcopy(&save_eh, mtod(m, struct ether_header *), ETHER_HDR_LEN);
815 if (! IF_HANDOFF(&last->if_snd, m, last)) {
817 BDG_MUTE(last); /* should I also mute ? */
820 BDG_STAT(last, BDG_OUT);
828 * If the interface is used for bridging, not muted, not full,
829 * up and running, is not the source interface, and belongs to
830 * the same cluster as the 'real_dst', then send here.
832 if ( BDG_USED(ifp) && !BDG_MUTED(ifp) && !_IF_QFULL(&ifp->if_snd) &&
833 (ifp->if_flags & (IFF_UP|IFF_RUNNING)) == (IFF_UP|IFF_RUNNING) &&
834 ifp != src && BDG_SAMECLUSTER(ifp, real_dst) )
836 ifp = TAILQ_NEXT(ifp, if_link) ;
840 DEB(bdg_fw_ticks += (u_long)(rdtsc() - ticks) ; bdg_fw_count++ ;
841 if (bdg_fw_count != 0) bdg_fw_avg = bdg_fw_ticks/bdg_fw_count; )