2 * Copyright 2001 Wasabi Systems, Inc.
5 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project by
18 * Wasabi Systems, Inc.
19 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
20 * or promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
37 * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by Jason L. Wright
51 * 4. The name of the author may not be used to endorse or promote products
52 * derived from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
56 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
57 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
58 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
59 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
60 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
62 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
63 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE.
66 * $OpenBSD: if_bridge.c,v 1.60 2001/06/15 03:38:33 itojun Exp $
67 * $NetBSD: if_bridge.c,v 1.31 2005/06/01 19:45:34 jdc Exp $
68 * $FreeBSD: src/sys/net/if_bridge.c,v 1.26 2005/10/13 23:05:55 thompsa Exp $
69 * $DragonFly: src/sys/net/bridge/if_bridge.c,v 1.51 2008/11/15 12:34:38 sephe Exp $
73 * Network interface bridge support.
77 * - Currently only supports Ethernet-like interfaces (Ethernet,
78 * 802.11, VLANs on Ethernet, etc.) Figure out a nice way
79 * to bridge other types of interfaces (FDDI-FDDI, and maybe
80 * consider heterogenous bridges).
83 * Bridge's route information is duplicated to each CPUs:
86 * +-----------+ +-----------+ +-----------+ +-----------+
87 * | rtnode | | rtnode | | rtnode | | rtnode |
89 * | dst eaddr | | dst eaddr | | dst eaddr | | dst eaddr |
90 * +-----------+ +-----------+ +-----------+ +-----------+
93 * | | +----------+ | |
97 * +-------------->| timeout |<-------------+
101 * We choose to put timeout and dst_ifp into shared part, so updating
102 * them will be cheaper than using message forwarding. Also there is
103 * not need to use spinlock to protect the updating: timeout and dst_ifp
104 * is not related and specific field's updating order has no importance.
105 * The cache pollution by the share part should not be heavy: in a stable
106 * setup, dst_ifp probably will be not changed in rtnode's life time,
107 * while timeout is refreshed once per second; most of the time, timeout
108 * and dst_ifp are read-only accessed.
111 * Bridge route information installation on bridge_input path:
113 * CPU0 CPU1 CPU2 CPU3
120 * ifnet0<-----------------------+
123 * rtnode exists?(Y)free nmsg :
154 * The netmsgs forwarded between protocol threads and ifnet threads are
155 * allocated with (M_WAITOK|M_NULLOK), so it will not fail under most
156 * cases (route information is too precious to be not installed :).
157 * Since multiple threads may try to install route information for the
158 * same dst eaddr, we look up route information in ifnet0. However, this
159 * looking up only need to be performed on ifnet0, which is the start
160 * point of the route information installation process.
163 * Bridge route information deleting/flushing:
165 * CPU0 CPU1 CPU2 CPU3
169 * find suitable rtnodes,
170 * mark their rtinfo dead
172 * | domsg <------------------------------------------+
175 * V fwdmsg fwdmsg fwdmsg |
176 * ifnet0 --------> ifnet1 --------> ifnet2 --------> ifnet3
177 * delete rtnodes delete rtnodes delete rtnodes delete rtnodes
178 * w/ dead rtinfo w/ dead rtinfo w/ dead rtinfo w/ dead rtinfo
181 * All deleting/flushing operations are serialized by netisr0, so each
182 * operation only reaps the route information marked dead by itself.
185 * Bridge route information adding/deleting/flushing:
186 * Since all operation is serialized by the fixed message flow between
187 * ifnet threads, it is not possible to create corrupted per-cpu route
191 #include "opt_inet.h"
192 #include "opt_inet6.h"
194 #include <sys/param.h>
195 #include <sys/mbuf.h>
196 #include <sys/malloc.h>
197 #include <sys/protosw.h>
198 #include <sys/systm.h>
199 #include <sys/time.h>
200 #include <sys/socket.h> /* for net/if.h */
201 #include <sys/sockio.h>
202 #include <sys/ctype.h> /* string functions */
203 #include <sys/kernel.h>
204 #include <sys/random.h>
205 #include <sys/sysctl.h>
206 #include <sys/module.h>
207 #include <sys/proc.h>
208 #include <sys/lock.h>
209 #include <sys/thread.h>
210 #include <sys/thread2.h>
211 #include <sys/mpipe.h>
215 #include <net/if_dl.h>
216 #include <net/if_types.h>
217 #include <net/if_var.h>
218 #include <net/pfil.h>
219 #include <net/ifq_var.h>
220 #include <net/if_clone.h>
222 #include <netinet/in.h> /* for struct arpcom */
223 #include <netinet/in_systm.h>
224 #include <netinet/in_var.h>
225 #include <netinet/ip.h>
226 #include <netinet/ip_var.h>
228 #include <netinet/ip6.h>
229 #include <netinet6/ip6_var.h>
231 #include <netinet/if_ether.h> /* for struct arpcom */
232 #include <net/bridge/if_bridgevar.h>
233 #include <net/if_llc.h>
234 #include <net/netmsg2.h>
236 #include <net/route.h>
237 #include <sys/in_cksum.h>
240 * Size of the route hash table. Must be a power of two.
242 #ifndef BRIDGE_RTHASH_SIZE
243 #define BRIDGE_RTHASH_SIZE 1024
246 #define BRIDGE_RTHASH_MASK (BRIDGE_RTHASH_SIZE - 1)
249 * Maximum number of addresses to cache.
251 #ifndef BRIDGE_RTABLE_MAX
252 #define BRIDGE_RTABLE_MAX 100
256 * Spanning tree defaults.
258 #define BSTP_DEFAULT_MAX_AGE (20 * 256)
259 #define BSTP_DEFAULT_HELLO_TIME (2 * 256)
260 #define BSTP_DEFAULT_FORWARD_DELAY (15 * 256)
261 #define BSTP_DEFAULT_HOLD_TIME (1 * 256)
262 #define BSTP_DEFAULT_BRIDGE_PRIORITY 0x8000
263 #define BSTP_DEFAULT_PORT_PRIORITY 0x80
264 #define BSTP_DEFAULT_PATH_COST 55
267 * Timeout (in seconds) for entries learned dynamically.
269 #ifndef BRIDGE_RTABLE_TIMEOUT
270 #define BRIDGE_RTABLE_TIMEOUT (20 * 60) /* same as ARP */
274 * Number of seconds between walks of the route list.
276 #ifndef BRIDGE_RTABLE_PRUNE_PERIOD
277 #define BRIDGE_RTABLE_PRUNE_PERIOD (5 * 60)
281 * List of capabilities to mask on the member interface.
283 #define BRIDGE_IFCAPS_MASK IFCAP_TXCSUM
285 typedef int (*bridge_ctl_t)(struct bridge_softc *, void *);
287 struct netmsg_brctl {
288 struct netmsg bc_nmsg;
289 bridge_ctl_t bc_func;
290 struct bridge_softc *bc_sc;
294 struct netmsg_brsaddr {
295 struct netmsg br_nmsg;
296 struct bridge_softc *br_softc;
297 struct ifnet *br_dst_if;
298 struct bridge_rtinfo *br_rtinfo;
300 uint8_t br_dst[ETHER_ADDR_LEN];
304 eventhandler_tag bridge_detach_cookie = NULL;
306 extern struct mbuf *(*bridge_input_p)(struct ifnet *, struct mbuf *);
307 extern int (*bridge_output_p)(struct ifnet *, struct mbuf *);
308 extern void (*bridge_dn_p)(struct mbuf *, struct ifnet *);
310 static int bridge_rtable_prune_period = BRIDGE_RTABLE_PRUNE_PERIOD;
312 static int bridge_clone_create(struct if_clone *, int);
313 static void bridge_clone_destroy(struct ifnet *);
315 static int bridge_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
316 static void bridge_mutecaps(struct bridge_iflist *, int);
317 static void bridge_ifdetach(void *arg __unused, struct ifnet *);
318 static void bridge_init(void *);
319 static void bridge_stop(struct ifnet *);
320 static void bridge_start(struct ifnet *);
321 static struct mbuf *bridge_input(struct ifnet *, struct mbuf *);
322 static int bridge_output(struct ifnet *, struct mbuf *);
324 static void bridge_forward(struct bridge_softc *, struct mbuf *m);
326 static void bridge_timer_handler(struct netmsg *);
327 static void bridge_timer(void *);
329 static void bridge_broadcast(struct bridge_softc *, struct ifnet *,
331 static void bridge_span(struct bridge_softc *, struct mbuf *);
333 static int bridge_rtupdate(struct bridge_softc *, const uint8_t *,
334 struct ifnet *, uint8_t);
335 static struct ifnet *bridge_rtlookup(struct bridge_softc *, const uint8_t *);
336 static void bridge_rtreap(struct bridge_softc *);
337 static void bridge_rttrim(struct bridge_softc *);
338 static int bridge_rtage_finddead(struct bridge_softc *);
339 static void bridge_rtage(struct bridge_softc *);
340 static void bridge_rtflush(struct bridge_softc *, int);
341 static int bridge_rtdaddr(struct bridge_softc *, const uint8_t *);
342 static int bridge_rtsaddr(struct bridge_softc *, const uint8_t *,
343 struct ifnet *, uint8_t);
344 static void bridge_rtmsg_sync(struct bridge_softc *sc);
345 static void bridge_rtreap_handler(struct netmsg *);
346 static void bridge_rtinstall_handler(struct netmsg *);
347 static int bridge_rtinstall_oncpu(struct bridge_softc *, const uint8_t *,
348 struct ifnet *, int, uint8_t, struct bridge_rtinfo **);
350 static void bridge_rtable_init(struct bridge_softc *);
351 static void bridge_rtable_fini(struct bridge_softc *);
353 static int bridge_rtnode_addr_cmp(const uint8_t *, const uint8_t *);
354 static struct bridge_rtnode *bridge_rtnode_lookup(struct bridge_softc *,
356 static void bridge_rtnode_insert(struct bridge_softc *,
357 struct bridge_rtnode *);
358 static void bridge_rtnode_destroy(struct bridge_softc *,
359 struct bridge_rtnode *);
361 static struct bridge_iflist *bridge_lookup_member(struct bridge_softc *,
363 static struct bridge_iflist *bridge_lookup_member_if(struct bridge_softc *,
365 static void bridge_delete_member(struct bridge_softc *,
366 struct bridge_iflist *, int);
367 static void bridge_delete_span(struct bridge_softc *,
368 struct bridge_iflist *);
370 static int bridge_control(struct bridge_softc *, u_long,
371 bridge_ctl_t, void *);
372 static int bridge_ioctl_init(struct bridge_softc *, void *);
373 static int bridge_ioctl_stop(struct bridge_softc *, void *);
374 static int bridge_ioctl_add(struct bridge_softc *, void *);
375 static int bridge_ioctl_del(struct bridge_softc *, void *);
376 static int bridge_ioctl_gifflags(struct bridge_softc *, void *);
377 static int bridge_ioctl_sifflags(struct bridge_softc *, void *);
378 static int bridge_ioctl_scache(struct bridge_softc *, void *);
379 static int bridge_ioctl_gcache(struct bridge_softc *, void *);
380 static int bridge_ioctl_gifs(struct bridge_softc *, void *);
381 static int bridge_ioctl_rts(struct bridge_softc *, void *);
382 static int bridge_ioctl_saddr(struct bridge_softc *, void *);
383 static int bridge_ioctl_sto(struct bridge_softc *, void *);
384 static int bridge_ioctl_gto(struct bridge_softc *, void *);
385 static int bridge_ioctl_daddr(struct bridge_softc *, void *);
386 static int bridge_ioctl_flush(struct bridge_softc *, void *);
387 static int bridge_ioctl_gpri(struct bridge_softc *, void *);
388 static int bridge_ioctl_spri(struct bridge_softc *, void *);
389 static int bridge_ioctl_ght(struct bridge_softc *, void *);
390 static int bridge_ioctl_sht(struct bridge_softc *, void *);
391 static int bridge_ioctl_gfd(struct bridge_softc *, void *);
392 static int bridge_ioctl_sfd(struct bridge_softc *, void *);
393 static int bridge_ioctl_gma(struct bridge_softc *, void *);
394 static int bridge_ioctl_sma(struct bridge_softc *, void *);
395 static int bridge_ioctl_sifprio(struct bridge_softc *, void *);
396 static int bridge_ioctl_sifcost(struct bridge_softc *, void *);
397 static int bridge_ioctl_addspan(struct bridge_softc *, void *);
398 static int bridge_ioctl_delspan(struct bridge_softc *, void *);
399 static int bridge_pfil(struct mbuf **, struct ifnet *, struct ifnet *,
401 static int bridge_ip_checkbasic(struct mbuf **mp);
403 static int bridge_ip6_checkbasic(struct mbuf **mp);
405 static int bridge_fragment(struct ifnet *, struct mbuf *,
406 struct ether_header *, int, struct llc *);
407 static void bridge_enqueue_internal(struct ifnet *, struct mbuf *m,
409 static void bridge_enqueue_handler(struct netmsg *);
410 static void bridge_pfil_enqueue_handler(struct netmsg *);
411 static void bridge_pfil_enqueue(struct ifnet *, struct mbuf *, int);
412 static void bridge_handoff(struct ifnet *, struct mbuf *);
414 SYSCTL_DECL(_net_link);
415 SYSCTL_NODE(_net_link, IFT_BRIDGE, bridge, CTLFLAG_RW, 0, "Bridge");
417 static int pfil_onlyip = 1; /* only pass IP[46] packets when pfil is enabled */
418 static int pfil_bridge = 1; /* run pfil hooks on the bridge interface */
419 static int pfil_member = 1; /* run pfil hooks on the member interface */
420 SYSCTL_INT(_net_link_bridge, OID_AUTO, pfil_onlyip, CTLFLAG_RW,
421 &pfil_onlyip, 0, "Only pass IP packets when pfil is enabled");
422 SYSCTL_INT(_net_link_bridge, OID_AUTO, pfil_bridge, CTLFLAG_RW,
423 &pfil_bridge, 0, "Packet filter on the bridge interface");
424 SYSCTL_INT(_net_link_bridge, OID_AUTO, pfil_member, CTLFLAG_RW,
425 &pfil_member, 0, "Packet filter on the member interface");
427 struct bridge_control_arg {
429 struct ifbreq ifbreq;
430 struct ifbifconf ifbifconf;
431 struct ifbareq ifbareq;
432 struct ifbaconf ifbaconf;
433 struct ifbrparam ifbrparam;
440 struct bridge_control {
441 bridge_ctl_t bc_func;
446 #define BC_F_COPYIN 0x01 /* copy arguments in */
447 #define BC_F_COPYOUT 0x02 /* copy arguments out */
448 #define BC_F_SUSER 0x04 /* do super-user check */
450 const struct bridge_control bridge_control_table[] = {
451 { bridge_ioctl_add, sizeof(struct ifbreq),
452 BC_F_COPYIN|BC_F_SUSER },
453 { bridge_ioctl_del, sizeof(struct ifbreq),
454 BC_F_COPYIN|BC_F_SUSER },
456 { bridge_ioctl_gifflags, sizeof(struct ifbreq),
457 BC_F_COPYIN|BC_F_COPYOUT },
458 { bridge_ioctl_sifflags, sizeof(struct ifbreq),
459 BC_F_COPYIN|BC_F_SUSER },
461 { bridge_ioctl_scache, sizeof(struct ifbrparam),
462 BC_F_COPYIN|BC_F_SUSER },
463 { bridge_ioctl_gcache, sizeof(struct ifbrparam),
466 { bridge_ioctl_gifs, sizeof(struct ifbifconf),
467 BC_F_COPYIN|BC_F_COPYOUT },
468 { bridge_ioctl_rts, sizeof(struct ifbaconf),
469 BC_F_COPYIN|BC_F_COPYOUT },
471 { bridge_ioctl_saddr, sizeof(struct ifbareq),
472 BC_F_COPYIN|BC_F_SUSER },
474 { bridge_ioctl_sto, sizeof(struct ifbrparam),
475 BC_F_COPYIN|BC_F_SUSER },
476 { bridge_ioctl_gto, sizeof(struct ifbrparam),
479 { bridge_ioctl_daddr, sizeof(struct ifbareq),
480 BC_F_COPYIN|BC_F_SUSER },
482 { bridge_ioctl_flush, sizeof(struct ifbreq),
483 BC_F_COPYIN|BC_F_SUSER },
485 { bridge_ioctl_gpri, sizeof(struct ifbrparam),
487 { bridge_ioctl_spri, sizeof(struct ifbrparam),
488 BC_F_COPYIN|BC_F_SUSER },
490 { bridge_ioctl_ght, sizeof(struct ifbrparam),
492 { bridge_ioctl_sht, sizeof(struct ifbrparam),
493 BC_F_COPYIN|BC_F_SUSER },
495 { bridge_ioctl_gfd, sizeof(struct ifbrparam),
497 { bridge_ioctl_sfd, sizeof(struct ifbrparam),
498 BC_F_COPYIN|BC_F_SUSER },
500 { bridge_ioctl_gma, sizeof(struct ifbrparam),
502 { bridge_ioctl_sma, sizeof(struct ifbrparam),
503 BC_F_COPYIN|BC_F_SUSER },
505 { bridge_ioctl_sifprio, sizeof(struct ifbreq),
506 BC_F_COPYIN|BC_F_SUSER },
508 { bridge_ioctl_sifcost, sizeof(struct ifbreq),
509 BC_F_COPYIN|BC_F_SUSER },
511 { bridge_ioctl_addspan, sizeof(struct ifbreq),
512 BC_F_COPYIN|BC_F_SUSER },
513 { bridge_ioctl_delspan, sizeof(struct ifbreq),
514 BC_F_COPYIN|BC_F_SUSER },
516 static const int bridge_control_table_size =
517 sizeof(bridge_control_table) / sizeof(bridge_control_table[0]);
519 LIST_HEAD(, bridge_softc) bridge_list;
521 struct if_clone bridge_cloner = IF_CLONE_INITIALIZER("bridge",
523 bridge_clone_destroy, 0, IF_MAXUNIT);
526 bridge_modevent(module_t mod, int type, void *data)
530 LIST_INIT(&bridge_list);
531 if_clone_attach(&bridge_cloner);
532 bridge_input_p = bridge_input;
533 bridge_output_p = bridge_output;
534 bridge_detach_cookie = EVENTHANDLER_REGISTER(
535 ifnet_detach_event, bridge_ifdetach, NULL,
536 EVENTHANDLER_PRI_ANY);
538 bstp_linkstate_p = bstp_linkstate;
542 if (!LIST_EMPTY(&bridge_list))
544 EVENTHANDLER_DEREGISTER(ifnet_detach_event,
545 bridge_detach_cookie);
546 if_clone_detach(&bridge_cloner);
547 bridge_input_p = NULL;
548 bridge_output_p = NULL;
550 bstp_linkstate_p = NULL;
559 static moduledata_t bridge_mod = {
565 DECLARE_MODULE(if_bridge, bridge_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
569 * bridge_clone_create:
571 * Create a new bridge instance.
574 bridge_clone_create(struct if_clone *ifc, int unit)
576 struct bridge_softc *sc;
580 sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
581 ifp = sc->sc_ifp = &sc->sc_if;
583 sc->sc_brtmax = BRIDGE_RTABLE_MAX;
584 sc->sc_brttimeout = BRIDGE_RTABLE_TIMEOUT;
585 sc->sc_bridge_max_age = BSTP_DEFAULT_MAX_AGE;
586 sc->sc_bridge_hello_time = BSTP_DEFAULT_HELLO_TIME;
587 sc->sc_bridge_forward_delay = BSTP_DEFAULT_FORWARD_DELAY;
588 sc->sc_bridge_priority = BSTP_DEFAULT_BRIDGE_PRIORITY;
589 sc->sc_hold_time = BSTP_DEFAULT_HOLD_TIME;
591 /* Initialize our routing table. */
592 bridge_rtable_init(sc);
594 callout_init(&sc->sc_brcallout);
595 netmsg_init(&sc->sc_brtimemsg, &netisr_adone_rport,
596 MSGF_DROPABLE | MSGF_PRIORITY, bridge_timer_handler);
597 sc->sc_brtimemsg.nm_lmsg.u.ms_resultp = sc;
599 callout_init(&sc->sc_bstpcallout);
600 netmsg_init(&sc->sc_bstptimemsg, &netisr_adone_rport,
601 MSGF_DROPABLE | MSGF_PRIORITY, bstp_tick_handler);
602 sc->sc_bstptimemsg.nm_lmsg.u.ms_resultp = sc;
604 LIST_INIT(&sc->sc_iflist);
605 LIST_INIT(&sc->sc_spanlist);
608 if_initname(ifp, ifc->ifc_name, unit);
609 ifp->if_mtu = ETHERMTU;
610 ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST;
611 ifp->if_ioctl = bridge_ioctl;
612 ifp->if_start = bridge_start;
613 ifp->if_init = bridge_init;
614 ifp->if_type = IFT_BRIDGE;
615 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
616 ifp->if_snd.ifq_maxlen = ifqmaxlen;
617 ifq_set_ready(&ifp->if_snd);
618 ifp->if_hdrlen = ETHER_HDR_LEN;
621 * Generate a random ethernet address and use the private AC:DE:48
625 int rnd = karc4random();
626 bcopy(&rnd, &eaddr[0], 4); /* ETHER_ADDR_LEN == 6 */
628 bcopy(&rnd, &eaddr[2], 4); /* ETHER_ADDR_LEN == 6 */
630 eaddr[0] &= ~1; /* clear multicast bit */
631 eaddr[0] |= 2; /* set the LAA bit */
633 ether_ifattach(ifp, eaddr, NULL);
634 /* Now undo some of the damage... */
635 ifp->if_baudrate = 0;
636 ifp->if_type = IFT_BRIDGE;
638 crit_enter(); /* XXX MP */
639 LIST_INSERT_HEAD(&bridge_list, sc, sc_list);
646 bridge_delete_dispatch(struct netmsg *nmsg)
648 struct lwkt_msg *lmsg = &nmsg->nm_lmsg;
649 struct bridge_softc *sc = lmsg->u.ms_resultp;
650 struct ifnet *bifp = sc->sc_ifp;
651 struct bridge_iflist *bif;
653 lwkt_serialize_enter(bifp->if_serializer);
655 while ((bif = LIST_FIRST(&sc->sc_iflist)) != NULL)
656 bridge_delete_member(sc, bif, 0);
658 while ((bif = LIST_FIRST(&sc->sc_spanlist)) != NULL)
659 bridge_delete_span(sc, bif);
661 lwkt_serialize_exit(bifp->if_serializer);
663 lwkt_replymsg(lmsg, 0);
667 * bridge_clone_destroy:
669 * Destroy a bridge instance.
672 bridge_clone_destroy(struct ifnet *ifp)
674 struct bridge_softc *sc = ifp->if_softc;
675 struct lwkt_msg *lmsg;
678 lwkt_serialize_enter(ifp->if_serializer);
681 ifp->if_flags &= ~IFF_UP;
683 lwkt_serialize_exit(ifp->if_serializer);
685 netmsg_init(&nmsg, &curthread->td_msgport, 0, bridge_delete_dispatch);
686 lmsg = &nmsg.nm_lmsg;
687 lmsg->u.ms_resultp = sc;
688 lwkt_domsg(BRIDGE_CFGPORT, lmsg, 0);
690 crit_enter(); /* XXX MP */
691 LIST_REMOVE(sc, sc_list);
696 /* Tear down the routing table. */
697 bridge_rtable_fini(sc);
705 * Handle a control request from the operator.
708 bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
710 struct bridge_softc *sc = ifp->if_softc;
711 struct bridge_control_arg args;
712 struct ifdrv *ifd = (struct ifdrv *) data;
713 const struct bridge_control *bc;
716 ASSERT_SERIALIZED(ifp->if_serializer);
725 if (ifd->ifd_cmd >= bridge_control_table_size) {
729 bc = &bridge_control_table[ifd->ifd_cmd];
731 if (cmd == SIOCGDRVSPEC &&
732 (bc->bc_flags & BC_F_COPYOUT) == 0) {
735 } else if (cmd == SIOCSDRVSPEC &&
736 (bc->bc_flags & BC_F_COPYOUT)) {
741 if (bc->bc_flags & BC_F_SUSER) {
742 error = suser_cred(cr, NULL_CRED_OKAY);
747 if (ifd->ifd_len != bc->bc_argsize ||
748 ifd->ifd_len > sizeof(args.bca_u)) {
753 memset(&args, 0, sizeof(args));
754 if (bc->bc_flags & BC_F_COPYIN) {
755 error = copyin(ifd->ifd_data, &args.bca_u,
761 error = bridge_control(sc, cmd, bc->bc_func, &args);
763 KKASSERT(args.bca_len == 0 && args.bca_kptr == NULL);
767 if (bc->bc_flags & BC_F_COPYOUT) {
768 error = copyout(&args, ifd->ifd_data, ifd->ifd_len);
769 if (args.bca_len != 0) {
770 KKASSERT(args.bca_kptr != NULL);
772 error = copyout(args.bca_kptr,
773 args.bca_uptr, args.bca_len);
775 kfree(args.bca_kptr, M_TEMP);
777 KKASSERT(args.bca_kptr == NULL);
780 KKASSERT(args.bca_len == 0 && args.bca_kptr == NULL);
785 if (!(ifp->if_flags & IFF_UP) &&
786 (ifp->if_flags & IFF_RUNNING)) {
788 * If interface is marked down and it is running,
792 } else if ((ifp->if_flags & IFF_UP) &&
793 !(ifp->if_flags & IFF_RUNNING)) {
795 * If interface is marked up and it is stopped, then
803 /* Do not allow the MTU to be changed on the bridge */
808 error = ether_ioctl(ifp, cmd, data);
817 * Clear or restore unwanted capabilities on the member interface
820 bridge_mutecaps(struct bridge_iflist *bif, int mute)
822 struct ifnet *ifp = bif->bif_ifp;
826 if (ifp->if_ioctl == NULL)
829 bzero(&ifr, sizeof(ifr));
830 ifr.ifr_reqcap = ifp->if_capenable;
833 /* mask off and save capabilities */
834 bif->bif_mutecap = ifr.ifr_reqcap & BRIDGE_IFCAPS_MASK;
835 if (bif->bif_mutecap != 0)
836 ifr.ifr_reqcap &= ~BRIDGE_IFCAPS_MASK;
838 /* restore muted capabilities */
839 ifr.ifr_reqcap |= bif->bif_mutecap;
842 if (bif->bif_mutecap != 0) {
843 lwkt_serialize_enter(ifp->if_serializer);
844 error = ifp->if_ioctl(ifp, SIOCSIFCAP, (caddr_t)&ifr, NULL);
845 lwkt_serialize_exit(ifp->if_serializer);
850 * bridge_lookup_member:
852 * Lookup a bridge member interface.
854 static struct bridge_iflist *
855 bridge_lookup_member(struct bridge_softc *sc, const char *name)
857 struct bridge_iflist *bif;
860 LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
862 if (strcmp(ifp->if_xname, name) == 0)
870 * bridge_lookup_member_if:
872 * Lookup a bridge member interface by ifnet*.
874 static struct bridge_iflist *
875 bridge_lookup_member_if(struct bridge_softc *sc, struct ifnet *member_ifp)
877 struct bridge_iflist *bif;
879 LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
880 if (bif->bif_ifp == member_ifp)
888 * bridge_delete_member:
890 * Delete the specified member interface.
893 bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif,
896 struct ifnet *ifs = bif->bif_ifp;
897 struct ifnet *bifp = sc->sc_ifp;
899 ASSERT_SERIALIZED(bifp->if_serializer);
901 ifs->if_bridge = NULL;
904 * Release bridge interface's serializer:
905 * - To avoid possible dead lock.
906 * - netmsg_service_sync will block current thread.
908 lwkt_serialize_exit(bifp->if_serializer);
911 * Make sure that all protocol threads see 'ifs' if_bridge change.
913 netmsg_service_sync();
916 switch (ifs->if_type) {
920 * Take the interface out of promiscuous mode.
923 bridge_mutecaps(bif, 0);
930 panic("bridge_delete_member: impossible");
935 /* See the comment in bridge_ioctl_stop() */
936 bridge_rtmsg_sync(sc);
938 bridge_rtdelete(sc, ifs, IFBF_FLUSHALL);
940 lwkt_serialize_enter(bifp->if_serializer);
942 LIST_REMOVE(bif, bif_next);
944 kfree(bif, M_DEVBUF);
946 if (sc->sc_ifp->if_flags & IFF_RUNNING)
947 bstp_initialization(sc);
951 * bridge_delete_span:
953 * Delete the specified span interface.
956 bridge_delete_span(struct bridge_softc *sc, struct bridge_iflist *bif)
958 KASSERT(bif->bif_ifp->if_bridge == NULL,
959 ("%s: not a span interface", __func__));
961 LIST_REMOVE(bif, bif_next);
962 kfree(bif, M_DEVBUF);
966 bridge_ioctl_init(struct bridge_softc *sc, void *arg __unused)
968 struct ifnet *ifp = sc->sc_ifp;
970 if (ifp->if_flags & IFF_RUNNING)
973 callout_reset(&sc->sc_brcallout, bridge_rtable_prune_period * hz,
976 ifp->if_flags |= IFF_RUNNING;
977 bstp_initialization(sc);
982 bridge_ioctl_stop(struct bridge_softc *sc, void *arg __unused)
984 struct ifnet *ifp = sc->sc_ifp;
985 struct lwkt_msg *lmsg;
987 if ((ifp->if_flags & IFF_RUNNING) == 0)
990 callout_stop(&sc->sc_brcallout);
993 lmsg = &sc->sc_brtimemsg.nm_lmsg;
994 if ((lmsg->ms_flags & MSGF_DONE) == 0) {
995 /* Pending to be processed; drop it */
1002 ifp->if_flags &= ~IFF_RUNNING;
1004 lwkt_serialize_exit(ifp->if_serializer);
1006 /* Let everyone know that we are stopped */
1007 netmsg_service_sync();
1010 * Sync ifnetX msgports in the order we forward rtnode
1011 * installation message. This is used to make sure that
1012 * all rtnode installation messages sent by bridge_rtupdate()
1013 * during above netmsg_service_sync() are flushed.
1015 bridge_rtmsg_sync(sc);
1017 bridge_rtflush(sc, IFBF_FLUSHDYN);
1019 lwkt_serialize_enter(ifp->if_serializer);
1024 bridge_ioctl_add(struct bridge_softc *sc, void *arg)
1026 struct ifbreq *req = arg;
1027 struct bridge_iflist *bif = NULL;
1028 struct ifnet *ifs, *bifp;
1032 ASSERT_SERIALIZED(bifp->if_serializer);
1034 ifs = ifunit(req->ifbr_ifsname);
1038 /* If it's in the span list, it can't be a member. */
1039 LIST_FOREACH(bif, &sc->sc_spanlist, bif_next)
1040 if (ifs == bif->bif_ifp)
1043 /* Allow the first Ethernet member to define the MTU */
1044 if (ifs->if_type != IFT_GIF) {
1045 if (LIST_EMPTY(&sc->sc_iflist)) {
1046 bifp->if_mtu = ifs->if_mtu;
1047 } else if (bifp->if_mtu != ifs->if_mtu) {
1048 if_printf(bifp, "invalid MTU for %s\n", ifs->if_xname);
1053 if (ifs->if_bridge == sc)
1056 if (ifs->if_bridge != NULL)
1059 bif = kmalloc(sizeof(*bif), M_DEVBUF, M_WAITOK|M_ZERO);
1061 bif->bif_flags = IFBIF_LEARNING | IFBIF_DISCOVER;
1062 bif->bif_priority = BSTP_DEFAULT_PORT_PRIORITY;
1063 bif->bif_path_cost = BSTP_DEFAULT_PATH_COST;
1065 switch (ifs->if_type) {
1069 * Release bridge interface's serializer to
1070 * avoid possible dead lock.
1072 lwkt_serialize_exit(bifp->if_serializer);
1075 * Place the interface into promiscuous mode.
1077 error = ifpromisc(ifs, 1);
1079 lwkt_serialize_enter(bifp->if_serializer);
1083 bridge_mutecaps(bif, 1);
1085 lwkt_serialize_enter(bifp->if_serializer);
1088 case IFT_GIF: /* :^) */
1096 LIST_INSERT_HEAD(&sc->sc_iflist, bif, bif_next);
1098 if (bifp->if_flags & IFF_RUNNING)
1099 bstp_initialization(sc);
1104 * Everything has been setup, so let the member interface
1105 * deliver packets to this bridge on its input/output path.
1107 ifs->if_bridge = sc;
1111 kfree(bif, M_DEVBUF);
1117 bridge_ioctl_del(struct bridge_softc *sc, void *arg)
1119 struct ifbreq *req = arg;
1120 struct bridge_iflist *bif;
1122 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
1126 bridge_delete_member(sc, bif, 0);
1132 bridge_ioctl_gifflags(struct bridge_softc *sc, void *arg)
1134 struct ifbreq *req = arg;
1135 struct bridge_iflist *bif;
1137 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
1141 req->ifbr_ifsflags = bif->bif_flags;
1142 req->ifbr_state = bif->bif_state;
1143 req->ifbr_priority = bif->bif_priority;
1144 req->ifbr_path_cost = bif->bif_path_cost;
1145 req->ifbr_portno = bif->bif_ifp->if_index & 0xff;
1151 bridge_ioctl_sifflags(struct bridge_softc *sc, void *arg)
1153 struct ifbreq *req = arg;
1154 struct bridge_iflist *bif;
1156 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
1160 if (req->ifbr_ifsflags & IFBIF_SPAN)
1161 /* SPAN is readonly */
1164 if (req->ifbr_ifsflags & IFBIF_STP) {
1165 switch (bif->bif_ifp->if_type) {
1167 /* These can do spanning tree. */
1171 /* Nothing else can. */
1176 bif->bif_flags = req->ifbr_ifsflags;
1178 if (sc->sc_ifp->if_flags & IFF_RUNNING)
1179 bstp_initialization(sc);
1185 bridge_ioctl_scache(struct bridge_softc *sc, void *arg)
1187 struct ifbrparam *param = arg;
1188 struct ifnet *ifp = sc->sc_ifp;
1190 sc->sc_brtmax = param->ifbrp_csize;
1192 lwkt_serialize_exit(ifp->if_serializer);
1194 lwkt_serialize_enter(ifp->if_serializer);
1200 bridge_ioctl_gcache(struct bridge_softc *sc, void *arg)
1202 struct ifbrparam *param = arg;
1204 param->ifbrp_csize = sc->sc_brtmax;
1210 bridge_ioctl_gifs(struct bridge_softc *sc, void *arg)
1212 struct bridge_control_arg *bc_arg = arg;
1213 struct ifbifconf *bifc = arg;
1214 struct bridge_iflist *bif;
1215 struct ifbreq *breq;
1219 LIST_FOREACH(bif, &sc->sc_iflist, bif_next)
1221 LIST_FOREACH(bif, &sc->sc_spanlist, bif_next)
1224 if (bifc->ifbic_len == 0) {
1225 bifc->ifbic_len = sizeof(*breq) * count;
1227 } else if (count == 0 || bifc->ifbic_len < sizeof(*breq)) {
1228 bifc->ifbic_len = 0;
1232 len = min(bifc->ifbic_len, sizeof(*breq) * count);
1233 KKASSERT(len >= sizeof(*breq));
1235 breq = kmalloc(len, M_TEMP, M_INTWAIT | M_NULLOK | M_ZERO);
1237 bifc->ifbic_len = 0;
1240 bc_arg->bca_kptr = breq;
1243 LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
1244 if (len < sizeof(*breq))
1247 strlcpy(breq->ifbr_ifsname, bif->bif_ifp->if_xname,
1248 sizeof(breq->ifbr_ifsname));
1249 breq->ifbr_ifsflags = bif->bif_flags;
1250 breq->ifbr_state = bif->bif_state;
1251 breq->ifbr_priority = bif->bif_priority;
1252 breq->ifbr_path_cost = bif->bif_path_cost;
1253 breq->ifbr_portno = bif->bif_ifp->if_index & 0xff;
1256 len -= sizeof(*breq);
1258 LIST_FOREACH(bif, &sc->sc_spanlist, bif_next) {
1259 if (len < sizeof(*breq))
1262 strlcpy(breq->ifbr_ifsname, bif->bif_ifp->if_xname,
1263 sizeof(breq->ifbr_ifsname));
1264 breq->ifbr_ifsflags = bif->bif_flags;
1265 breq->ifbr_state = bif->bif_state;
1266 breq->ifbr_priority = bif->bif_priority;
1267 breq->ifbr_path_cost = bif->bif_path_cost;
1268 breq->ifbr_portno = bif->bif_ifp->if_index & 0xff;
1271 len -= sizeof(*breq);
1274 bifc->ifbic_len = sizeof(*breq) * count;
1275 KKASSERT(bifc->ifbic_len > 0);
1277 bc_arg->bca_len = bifc->ifbic_len;
1278 bc_arg->bca_uptr = bifc->ifbic_req;
1283 bridge_ioctl_rts(struct bridge_softc *sc, void *arg)
1285 struct bridge_control_arg *bc_arg = arg;
1286 struct ifbaconf *bac = arg;
1287 struct bridge_rtnode *brt;
1288 struct ifbareq *bareq;
1292 LIST_FOREACH(brt, &sc->sc_rtlists[mycpuid], brt_list)
1295 if (bac->ifbac_len == 0) {
1296 bac->ifbac_len = sizeof(*bareq) * count;
1298 } else if (count == 0 || bac->ifbac_len < sizeof(*bareq)) {
1303 len = min(bac->ifbac_len, sizeof(*bareq) * count);
1304 KKASSERT(len >= sizeof(*bareq));
1306 bareq = kmalloc(len, M_TEMP, M_INTWAIT | M_NULLOK | M_ZERO);
1307 if (bareq == NULL) {
1311 bc_arg->bca_kptr = bareq;
1314 LIST_FOREACH(brt, &sc->sc_rtlists[mycpuid], brt_list) {
1315 struct bridge_rtinfo *bri = brt->brt_info;
1316 unsigned long expire;
1318 if (len < sizeof(*bareq))
1321 strlcpy(bareq->ifba_ifsname, bri->bri_ifp->if_xname,
1322 sizeof(bareq->ifba_ifsname));
1323 memcpy(bareq->ifba_dst, brt->brt_addr, sizeof(brt->brt_addr));
1324 expire = bri->bri_expire;
1325 if ((bri->bri_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC &&
1326 time_second < expire)
1327 bareq->ifba_expire = expire - time_second;
1329 bareq->ifba_expire = 0;
1330 bareq->ifba_flags = bri->bri_flags;
1333 len -= sizeof(*bareq);
1336 bac->ifbac_len = sizeof(*bareq) * count;
1337 KKASSERT(bac->ifbac_len > 0);
1339 bc_arg->bca_len = bac->ifbac_len;
1340 bc_arg->bca_uptr = bac->ifbac_req;
1345 bridge_ioctl_saddr(struct bridge_softc *sc, void *arg)
1347 struct ifbareq *req = arg;
1348 struct bridge_iflist *bif;
1349 struct ifnet *ifp = sc->sc_ifp;
1352 ASSERT_SERIALIZED(ifp->if_serializer);
1354 bif = bridge_lookup_member(sc, req->ifba_ifsname);
1358 lwkt_serialize_exit(ifp->if_serializer);
1359 error = bridge_rtsaddr(sc, req->ifba_dst, bif->bif_ifp,
1361 lwkt_serialize_enter(ifp->if_serializer);
1366 bridge_ioctl_sto(struct bridge_softc *sc, void *arg)
1368 struct ifbrparam *param = arg;
1370 sc->sc_brttimeout = param->ifbrp_ctime;
1376 bridge_ioctl_gto(struct bridge_softc *sc, void *arg)
1378 struct ifbrparam *param = arg;
1380 param->ifbrp_ctime = sc->sc_brttimeout;
1386 bridge_ioctl_daddr(struct bridge_softc *sc, void *arg)
1388 struct ifbareq *req = arg;
1389 struct ifnet *ifp = sc->sc_ifp;
1392 lwkt_serialize_exit(ifp->if_serializer);
1393 error = bridge_rtdaddr(sc, req->ifba_dst);
1394 lwkt_serialize_enter(ifp->if_serializer);
1399 bridge_ioctl_flush(struct bridge_softc *sc, void *arg)
1401 struct ifbreq *req = arg;
1402 struct ifnet *ifp = sc->sc_ifp;
1404 lwkt_serialize_exit(ifp->if_serializer);
1405 bridge_rtflush(sc, req->ifbr_ifsflags);
1406 lwkt_serialize_enter(ifp->if_serializer);
1412 bridge_ioctl_gpri(struct bridge_softc *sc, void *arg)
1414 struct ifbrparam *param = arg;
1416 param->ifbrp_prio = sc->sc_bridge_priority;
1422 bridge_ioctl_spri(struct bridge_softc *sc, void *arg)
1424 struct ifbrparam *param = arg;
1426 sc->sc_bridge_priority = param->ifbrp_prio;
1428 if (sc->sc_ifp->if_flags & IFF_RUNNING)
1429 bstp_initialization(sc);
1435 bridge_ioctl_ght(struct bridge_softc *sc, void *arg)
1437 struct ifbrparam *param = arg;
1439 param->ifbrp_hellotime = sc->sc_bridge_hello_time >> 8;
1445 bridge_ioctl_sht(struct bridge_softc *sc, void *arg)
1447 struct ifbrparam *param = arg;
1449 if (param->ifbrp_hellotime == 0)
1451 sc->sc_bridge_hello_time = param->ifbrp_hellotime << 8;
1453 if (sc->sc_ifp->if_flags & IFF_RUNNING)
1454 bstp_initialization(sc);
1460 bridge_ioctl_gfd(struct bridge_softc *sc, void *arg)
1462 struct ifbrparam *param = arg;
1464 param->ifbrp_fwddelay = sc->sc_bridge_forward_delay >> 8;
1470 bridge_ioctl_sfd(struct bridge_softc *sc, void *arg)
1472 struct ifbrparam *param = arg;
1474 if (param->ifbrp_fwddelay == 0)
1476 sc->sc_bridge_forward_delay = param->ifbrp_fwddelay << 8;
1478 if (sc->sc_ifp->if_flags & IFF_RUNNING)
1479 bstp_initialization(sc);
1485 bridge_ioctl_gma(struct bridge_softc *sc, void *arg)
1487 struct ifbrparam *param = arg;
1489 param->ifbrp_maxage = sc->sc_bridge_max_age >> 8;
1495 bridge_ioctl_sma(struct bridge_softc *sc, void *arg)
1497 struct ifbrparam *param = arg;
1499 if (param->ifbrp_maxage == 0)
1501 sc->sc_bridge_max_age = param->ifbrp_maxage << 8;
1503 if (sc->sc_ifp->if_flags & IFF_RUNNING)
1504 bstp_initialization(sc);
1510 bridge_ioctl_sifprio(struct bridge_softc *sc, void *arg)
1512 struct ifbreq *req = arg;
1513 struct bridge_iflist *bif;
1515 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
1519 bif->bif_priority = req->ifbr_priority;
1521 if (sc->sc_ifp->if_flags & IFF_RUNNING)
1522 bstp_initialization(sc);
1528 bridge_ioctl_sifcost(struct bridge_softc *sc, void *arg)
1530 struct ifbreq *req = arg;
1531 struct bridge_iflist *bif;
1533 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
1537 bif->bif_path_cost = req->ifbr_path_cost;
1539 if (sc->sc_ifp->if_flags & IFF_RUNNING)
1540 bstp_initialization(sc);
1546 bridge_ioctl_addspan(struct bridge_softc *sc, void *arg)
1548 struct ifbreq *req = arg;
1549 struct bridge_iflist *bif = NULL;
1552 ifs = ifunit(req->ifbr_ifsname);
1556 LIST_FOREACH(bif, &sc->sc_spanlist, bif_next)
1557 if (ifs == bif->bif_ifp)
1560 if (ifs->if_bridge != NULL)
1563 switch (ifs->if_type) {
1572 bif = kmalloc(sizeof(*bif), M_DEVBUF, M_WAITOK|M_ZERO);
1575 bif->bif_flags = IFBIF_SPAN;
1577 LIST_INSERT_HEAD(&sc->sc_spanlist, bif, bif_next);
1583 bridge_ioctl_delspan(struct bridge_softc *sc, void *arg)
1585 struct ifbreq *req = arg;
1586 struct bridge_iflist *bif;
1589 ifs = ifunit(req->ifbr_ifsname);
1593 LIST_FOREACH(bif, &sc->sc_spanlist, bif_next)
1594 if (ifs == bif->bif_ifp)
1600 bridge_delete_span(sc, bif);
1606 bridge_ifdetach_dispatch(struct netmsg *nmsg)
1608 struct lwkt_msg *lmsg = &nmsg->nm_lmsg;
1609 struct ifnet *ifp, *bifp;
1610 struct bridge_softc *sc;
1611 struct bridge_iflist *bif;
1613 ifp = lmsg->u.ms_resultp;
1614 sc = ifp->if_bridge;
1616 /* Check if the interface is a bridge member */
1620 lwkt_serialize_enter(bifp->if_serializer);
1622 bif = bridge_lookup_member_if(sc, ifp);
1624 bridge_delete_member(sc, bif, 1);
1626 /* XXX Why bif will be NULL? */
1629 lwkt_serialize_exit(bifp->if_serializer);
1633 crit_enter(); /* XXX MP */
1635 /* Check if the interface is a span port */
1636 LIST_FOREACH(sc, &bridge_list, sc_list) {
1639 lwkt_serialize_enter(bifp->if_serializer);
1641 LIST_FOREACH(bif, &sc->sc_spanlist, bif_next)
1642 if (ifp == bif->bif_ifp) {
1643 bridge_delete_span(sc, bif);
1647 lwkt_serialize_exit(bifp->if_serializer);
1653 lwkt_replymsg(lmsg, 0);
1659 * Detach an interface from a bridge. Called when a member
1660 * interface is detaching.
1663 bridge_ifdetach(void *arg __unused, struct ifnet *ifp)
1665 struct lwkt_msg *lmsg;
1668 netmsg_init(&nmsg, &curthread->td_msgport, 0, bridge_ifdetach_dispatch);
1669 lmsg = &nmsg.nm_lmsg;
1670 lmsg->u.ms_resultp = ifp;
1672 lwkt_domsg(BRIDGE_CFGPORT, lmsg, 0);
1678 * Initialize a bridge interface.
1681 bridge_init(void *xsc)
1683 bridge_control(xsc, SIOCSIFFLAGS, bridge_ioctl_init, NULL);
1689 * Stop the bridge interface.
1692 bridge_stop(struct ifnet *ifp)
1694 bridge_control(ifp->if_softc, SIOCSIFFLAGS, bridge_ioctl_stop, NULL);
1698 bridge_enqueue_internal(struct ifnet *dst_ifp, struct mbuf *m,
1699 netisr_fn_t handler)
1701 struct netmsg_packet *nmp;
1703 int cpu = mycpu->gd_cpuid;
1705 nmp = &m->m_hdr.mh_netmsg;
1706 netmsg_init(&nmp->nm_netmsg, &netisr_apanic_rport, 0, handler);
1708 nmp->nm_netmsg.nm_lmsg.u.ms_resultp = dst_ifp;
1710 port = cpu_portfn(cpu);
1711 lwkt_sendmsg(port, &nmp->nm_netmsg.nm_lmsg);
1715 bridge_pfil_enqueue(struct ifnet *dst_ifp, struct mbuf *m,
1718 netisr_fn_t handler;
1720 if (runfilt && (inet_pfil_hook.ph_hashooks > 0
1722 || inet6_pfil_hook.ph_hashooks > 0
1725 handler = bridge_pfil_enqueue_handler;
1727 handler = bridge_enqueue_handler;
1729 bridge_enqueue_internal(dst_ifp, m, handler);
1735 * Enqueue a packet on a bridge member interface.
1739 bridge_enqueue(struct ifnet *dst_ifp, struct mbuf *m)
1741 bridge_enqueue_internal(dst_ifp, m, bridge_enqueue_handler);
1747 * Send output from a bridge member interface. This
1748 * performs the bridging function for locally originated
1751 * The mbuf has the Ethernet header already attached. We must
1752 * enqueue or free the mbuf before returning.
1755 bridge_output(struct ifnet *ifp, struct mbuf *m)
1757 struct bridge_softc *sc = ifp->if_bridge;
1758 struct ether_header *eh;
1759 struct ifnet *dst_if;
1761 ASSERT_NOT_SERIALIZED(ifp->if_serializer);
1764 * Make sure that we are still a member of a bridge interface.
1771 if (m->m_len < ETHER_HDR_LEN) {
1772 m = m_pullup(m, ETHER_HDR_LEN);
1777 /* Serialize our bridge interface. */
1778 lwkt_serialize_enter(sc->sc_ifp->if_serializer);
1780 eh = mtod(m, struct ether_header *);
1783 * If bridge is down, but the original output interface is up,
1784 * go ahead and send out that interface. Otherwise, the packet
1787 if ((sc->sc_ifp->if_flags & IFF_RUNNING) == 0) {
1793 * If the packet is a multicast, or we don't know a better way to
1794 * get there, send to all interfaces.
1796 if (ETHER_IS_MULTICAST(eh->ether_dhost))
1799 dst_if = bridge_rtlookup(sc, eh->ether_dhost);
1800 if (dst_if == NULL) {
1801 struct bridge_iflist *bif;
1807 LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
1808 dst_if = bif->bif_ifp;
1809 if ((dst_if->if_flags & IFF_RUNNING) == 0)
1813 * If this is not the original output interface,
1814 * and the interface is participating in spanning
1815 * tree, make sure the port is in a state that
1816 * allows forwarding.
1818 if (dst_if != ifp &&
1819 (bif->bif_flags & IFBIF_STP) != 0) {
1820 switch (bif->bif_state) {
1821 case BSTP_IFSTATE_BLOCKING:
1822 case BSTP_IFSTATE_LISTENING:
1823 case BSTP_IFSTATE_DISABLED:
1828 if (LIST_NEXT(bif, bif_next) == NULL) {
1832 mc = m_copypacket(m, MB_DONTWAIT);
1834 sc->sc_ifp->if_oerrors++;
1838 bridge_enqueue(dst_if, mc);
1842 lwkt_serialize_exit(sc->sc_ifp->if_serializer);
1848 * XXX Spanning tree consideration here?
1852 lwkt_serialize_exit(sc->sc_ifp->if_serializer);
1853 if ((dst_if->if_flags & IFF_RUNNING) == 0)
1856 bridge_enqueue(dst_if, m);
1863 * Start output on a bridge.
1867 bridge_start(struct ifnet *ifp)
1869 struct bridge_softc *sc = ifp->if_softc;
1871 ASSERT_SERIALIZED(ifp->if_serializer);
1873 ifp->if_flags |= IFF_OACTIVE;
1875 struct ifnet *dst_if = NULL;
1876 struct ether_header *eh;
1879 m = ifq_dequeue(&ifp->if_snd, NULL);
1883 if (m->m_len < sizeof(*eh)) {
1884 m = m_pullup(m, sizeof(*eh));
1890 eh = mtod(m, struct ether_header *);
1895 if ((m->m_flags & (M_BCAST|M_MCAST)) == 0)
1896 dst_if = bridge_rtlookup(sc, eh->ether_dhost);
1899 bridge_broadcast(sc, ifp, m, 0);
1901 bridge_enqueue(dst_if, m);
1903 ifp->if_flags &= ~IFF_OACTIVE;
1909 * The forwarding function of the bridge.
1912 bridge_forward(struct bridge_softc *sc, struct mbuf *m)
1914 struct bridge_iflist *bif;
1915 struct ifnet *src_if, *dst_if, *ifp;
1916 struct ether_header *eh;
1918 src_if = m->m_pkthdr.rcvif;
1921 ASSERT_SERIALIZED(ifp->if_serializer);
1924 ifp->if_ibytes += m->m_pkthdr.len;
1927 * Look up the bridge_iflist.
1929 bif = bridge_lookup_member_if(sc, src_if);
1931 /* Interface is not a bridge member (anymore?) */
1936 if (bif->bif_flags & IFBIF_STP) {
1937 switch (bif->bif_state) {
1938 case BSTP_IFSTATE_BLOCKING:
1939 case BSTP_IFSTATE_LISTENING:
1940 case BSTP_IFSTATE_DISABLED:
1946 eh = mtod(m, struct ether_header *);
1949 * If the interface is learning, and the source
1950 * address is valid and not multicast, record
1953 if ((bif->bif_flags & IFBIF_LEARNING) != 0 &&
1954 ETHER_IS_MULTICAST(eh->ether_shost) == 0 &&
1955 (eh->ether_shost[0] == 0 &&
1956 eh->ether_shost[1] == 0 &&
1957 eh->ether_shost[2] == 0 &&
1958 eh->ether_shost[3] == 0 &&
1959 eh->ether_shost[4] == 0 &&
1960 eh->ether_shost[5] == 0) == 0)
1961 bridge_rtupdate(sc, eh->ether_shost, src_if, IFBAF_DYNAMIC);
1963 if ((bif->bif_flags & IFBIF_STP) != 0 &&
1964 bif->bif_state == BSTP_IFSTATE_LEARNING) {
1970 * At this point, the port either doesn't participate
1971 * in spanning tree or it is in the forwarding state.
1975 * If the packet is unicast, destined for someone on
1976 * "this" side of the bridge, drop it.
1978 if ((m->m_flags & (M_BCAST|M_MCAST)) == 0) {
1979 dst_if = bridge_rtlookup(sc, eh->ether_dhost);
1980 if (src_if == dst_if) {
1985 /* ...forward it to all interfaces. */
1986 sc->sc_ifp->if_imcasts++;
1990 if (dst_if == NULL) {
1991 bridge_broadcast(sc, src_if, m, 1);
1996 * At this point, we're dealing with a unicast frame
1997 * going to a different interface.
1999 if ((dst_if->if_flags & IFF_RUNNING) == 0) {
2003 bif = bridge_lookup_member_if(sc, dst_if);
2005 /* Not a member of the bridge (anymore?) */
2010 if (bif->bif_flags & IFBIF_STP) {
2011 switch (bif->bif_state) {
2012 case BSTP_IFSTATE_DISABLED:
2013 case BSTP_IFSTATE_BLOCKING:
2019 lwkt_serialize_exit(ifp->if_serializer);
2021 /* run the packet filter */
2022 if (inet_pfil_hook.ph_hashooks > 0
2024 || inet6_pfil_hook.ph_hashooks > 0
2027 if (bridge_pfil(&m, ifp, src_if, PFIL_IN) != 0)
2032 if (bridge_pfil(&m, ifp, dst_if, PFIL_OUT) != 0)
2037 bridge_handoff(dst_if, m);
2040 * ifp's serializer was held on entry and is expected to be held
2044 lwkt_serialize_enter(ifp->if_serializer);
2050 * Receive input from a member interface. Queue the packet for
2051 * bridging if it is not for us.
2053 static struct mbuf *
2054 bridge_input(struct ifnet *ifp, struct mbuf *m)
2056 struct bridge_softc *sc = ifp->if_bridge;
2057 struct bridge_iflist *bif;
2058 struct ifnet *bifp, *new_ifp;
2059 struct ether_header *eh;
2060 struct mbuf *mc, *mc2;
2063 * Make sure that we are still a member of a bridge interface.
2071 lwkt_serialize_enter(bifp->if_serializer);
2073 if ((bifp->if_flags & IFF_RUNNING) == 0)
2077 * Implement support for bridge monitoring. If this flag has been
2078 * set on this interface, discard the packet once we push it through
2079 * the bpf(4) machinery, but before we do, increment the byte and
2080 * packet counters associated with this interface.
2082 if ((bifp->if_flags & IFF_MONITOR) != 0) {
2083 m->m_pkthdr.rcvif = bifp;
2085 bifp->if_ipackets++;
2086 bifp->if_ibytes += m->m_pkthdr.len;
2092 eh = mtod(m, struct ether_header *);
2094 m->m_flags &= ~M_PROTO1; /* XXX Hack - loop prevention */
2096 if (memcmp(eh->ether_dhost, IF_LLADDR(bifp), ETHER_ADDR_LEN) == 0) {
2098 * If the packet is for us, set the packets source as the
2099 * bridge, and return the packet back to ifnet.if_input for
2102 KASSERT(bifp->if_bridge == NULL,
2103 ("loop created in bridge_input"));
2109 * Tap all packets arriving on the bridge, no matter if
2110 * they are local destinations or not. In is in.
2114 bif = bridge_lookup_member_if(sc, ifp);
2120 if (m->m_flags & (M_BCAST | M_MCAST)) {
2121 /* Tap off 802.1D packets; they do not get forwarded. */
2122 if (memcmp(eh->ether_dhost, bstp_etheraddr,
2123 ETHER_ADDR_LEN) == 0) {
2124 m = bstp_input(sc, bif, m);
2126 ("attempt to deliver 802.1D packet\n"));
2130 if (bif->bif_flags & IFBIF_STP) {
2131 switch (bif->bif_state) {
2132 case BSTP_IFSTATE_BLOCKING:
2133 case BSTP_IFSTATE_LISTENING:
2134 case BSTP_IFSTATE_DISABLED:
2140 * Make a deep copy of the packet and enqueue the copy
2141 * for bridge processing; return the original packet for
2144 mc = m_dup(m, MB_DONTWAIT);
2148 bridge_forward(sc, mc);
2151 * Reinject the mbuf as arriving on the bridge so we have a
2152 * chance at claiming multicast packets. We can not loop back
2153 * here from ether_input as a bridge is never a member of a
2156 KASSERT(bifp->if_bridge == NULL,
2157 ("loop created in bridge_input"));
2158 mc2 = m_dup(m, MB_DONTWAIT);
2161 /* Keep the layer3 header aligned */
2162 int i = min(mc2->m_pkthdr.len, max_protohdr);
2163 mc2 = m_copyup(mc2, i, ETHER_ALIGN);
2167 mc2->m_pkthdr.rcvif = bifp;
2168 bifp->if_ipackets++;
2169 bifp->if_input(bifp, mc2);
2172 /* Return the original packet for local processing. */
2176 if (bif->bif_flags & IFBIF_STP) {
2177 switch (bif->bif_state) {
2178 case BSTP_IFSTATE_BLOCKING:
2179 case BSTP_IFSTATE_LISTENING:
2180 case BSTP_IFSTATE_DISABLED:
2186 * Unicast. Make sure it's not for us.
2188 LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
2189 if (bif->bif_ifp->if_type != IFT_ETHER)
2192 /* It is destined for us. */
2193 if (memcmp(IF_LLADDR(bif->bif_ifp), eh->ether_dhost,
2194 ETHER_ADDR_LEN) == 0) {
2195 if (bif->bif_flags & IFBIF_LEARNING) {
2196 bridge_rtupdate(sc, eh->ether_shost,
2197 ifp, IFBAF_DYNAMIC);
2200 if (bif->bif_ifp != ifp) {
2201 /* XXX loop prevention */
2202 m->m_flags |= M_PROTO1;
2203 new_ifp = bif->bif_ifp;
2208 /* We just received a packet that we sent out. */
2209 if (memcmp(IF_LLADDR(bif->bif_ifp), eh->ether_shost,
2210 ETHER_ADDR_LEN) == 0) {
2217 /* Perform the bridge forwarding function. */
2218 bridge_forward(sc, m);
2221 lwkt_serialize_exit(bifp->if_serializer);
2223 if (new_ifp != NULL) {
2224 lwkt_serialize_enter(new_ifp->if_serializer);
2226 m->m_pkthdr.rcvif = new_ifp;
2227 new_ifp->if_ipackets++;
2228 new_ifp->if_input(new_ifp, m);
2231 lwkt_serialize_exit(new_ifp->if_serializer);
2239 * Send a frame to all interfaces that are members of
2240 * the bridge, except for the one on which the packet
2244 bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if,
2245 struct mbuf *m, int runfilt)
2247 struct bridge_iflist *bif;
2249 struct ifnet *dst_if, *bifp;
2254 ASSERT_SERIALIZED(bifp->if_serializer);
2256 /* run the packet filter */
2257 if (runfilt && (inet_pfil_hook.ph_hashooks > 0
2259 || inet6_pfil_hook.ph_hashooks > 0
2262 lwkt_serialize_exit(bifp->if_serializer);
2264 /* Filter on the bridge interface before broadcasting */
2266 if (bridge_pfil(&m, bifp, src_if, PFIL_IN) != 0)
2271 if (bridge_pfil(&m, bifp, NULL, PFIL_OUT) != 0)
2274 lwkt_serialize_enter(bifp->if_serializer);
2279 LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
2280 dst_if = bif->bif_ifp;
2281 if (dst_if == src_if)
2284 if (bif->bif_flags & IFBIF_STP) {
2285 switch (bif->bif_state) {
2286 case BSTP_IFSTATE_BLOCKING:
2287 case BSTP_IFSTATE_DISABLED:
2292 if ((bif->bif_flags & IFBIF_DISCOVER) == 0 &&
2293 (m->m_flags & (M_BCAST|M_MCAST)) == 0)
2296 if ((dst_if->if_flags & IFF_RUNNING) == 0)
2299 if (LIST_NEXT(bif, bif_next) == NULL) {
2303 mc = m_copypacket(m, MB_DONTWAIT);
2305 sc->sc_ifp->if_oerrors++;
2309 bridge_pfil_enqueue(dst_if, mc, runfilt);
2318 * Duplicate a packet out one or more interfaces that are in span mode,
2319 * the original mbuf is unmodified.
2322 bridge_span(struct bridge_softc *sc, struct mbuf *m)
2324 struct bridge_iflist *bif;
2325 struct ifnet *dst_if;
2328 if (LIST_EMPTY(&sc->sc_spanlist))
2331 LIST_FOREACH(bif, &sc->sc_spanlist, bif_next) {
2332 dst_if = bif->bif_ifp;
2334 if ((dst_if->if_flags & IFF_RUNNING) == 0)
2337 mc = m_copypacket(m, MB_DONTWAIT);
2339 sc->sc_ifp->if_oerrors++;
2343 bridge_enqueue(dst_if, mc);
2348 bridge_rtmsg_sync_handler(struct netmsg *nmsg)
2350 ifnet_forwardmsg(&nmsg->nm_lmsg, mycpuid + 1);
2354 bridge_rtmsg_sync(struct bridge_softc *sc)
2358 ASSERT_NOT_SERIALIZED(sc->sc_ifp->if_serializer);
2360 netmsg_init(&nmsg, &curthread->td_msgport, 0,
2361 bridge_rtmsg_sync_handler);
2362 ifnet_domsg(&nmsg.nm_lmsg, 0);
2365 static __inline void
2366 bridge_rtinfo_update(struct bridge_rtinfo *bri, struct ifnet *dst_if,
2367 int setflags, uint8_t flags, uint32_t timeo)
2369 if ((bri->bri_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC &&
2370 bri->bri_ifp != dst_if)
2371 bri->bri_ifp = dst_if;
2372 if ((flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC &&
2373 bri->bri_expire != time_second + timeo)
2374 bri->bri_expire = time_second + timeo;
2376 bri->bri_flags = flags;
2380 bridge_rtinstall_oncpu(struct bridge_softc *sc, const uint8_t *dst,
2381 struct ifnet *dst_if, int setflags, uint8_t flags,
2382 struct bridge_rtinfo **bri0)
2384 struct bridge_rtnode *brt;
2385 struct bridge_rtinfo *bri;
2388 brt = bridge_rtnode_lookup(sc, dst);
2391 * rtnode for 'dst' already exists. We inform the
2392 * caller about this by leaving bri0 as NULL. The
2393 * caller will terminate the intallation upon getting
2394 * NULL bri0. However, we still need to update the
2397 KKASSERT(*bri0 == NULL);
2400 bridge_rtinfo_update(brt->brt_info, dst_if, setflags,
2401 flags, sc->sc_brttimeout);
2406 * We only need to check brtcnt on CPU0, since if limit
2407 * is to be exceeded, ENOSPC is returned. Caller knows
2408 * this and will terminate the installation.
2410 if (sc->sc_brtcnt >= sc->sc_brtmax)
2413 KKASSERT(*bri0 == NULL);
2414 bri = kmalloc(sizeof(struct bridge_rtinfo), M_DEVBUF,
2419 bri->bri_flags = IFBAF_DYNAMIC;
2420 bridge_rtinfo_update(bri, dst_if, setflags, flags,
2424 KKASSERT(bri != NULL);
2427 brt = kmalloc(sizeof(struct bridge_rtnode), M_DEVBUF,
2429 memcpy(brt->brt_addr, dst, ETHER_ADDR_LEN);
2430 brt->brt_info = bri;
2432 bridge_rtnode_insert(sc, brt);
2437 bridge_rtinstall_handler(struct netmsg *nmsg)
2439 struct netmsg_brsaddr *brmsg = (struct netmsg_brsaddr *)nmsg;
2442 error = bridge_rtinstall_oncpu(brmsg->br_softc,
2443 brmsg->br_dst, brmsg->br_dst_if,
2444 brmsg->br_setflags, brmsg->br_flags,
2447 KKASSERT(mycpuid == 0 && brmsg->br_rtinfo == NULL);
2448 lwkt_replymsg(&nmsg->nm_lmsg, error);
2450 } else if (brmsg->br_rtinfo == NULL) {
2451 /* rtnode already exists for 'dst' */
2452 KKASSERT(mycpuid == 0);
2453 lwkt_replymsg(&nmsg->nm_lmsg, 0);
2456 ifnet_forwardmsg(&nmsg->nm_lmsg, mycpuid + 1);
2462 * Add/Update a bridge routing entry.
2465 bridge_rtupdate(struct bridge_softc *sc, const uint8_t *dst,
2466 struct ifnet *dst_if, uint8_t flags)
2468 struct bridge_rtnode *brt;
2471 * A route for this destination might already exist. If so,
2472 * update it, otherwise create a new one.
2474 if ((brt = bridge_rtnode_lookup(sc, dst)) == NULL) {
2475 struct netmsg_brsaddr *brmsg;
2477 if (sc->sc_brtcnt >= sc->sc_brtmax)
2480 brmsg = kmalloc(sizeof(*brmsg), M_LWKTMSG, M_WAITOK | M_NULLOK);
2484 netmsg_init(&brmsg->br_nmsg, &netisr_afree_rport, 0,
2485 bridge_rtinstall_handler);
2486 memcpy(brmsg->br_dst, dst, ETHER_ADDR_LEN);
2487 brmsg->br_dst_if = dst_if;
2488 brmsg->br_flags = flags;
2489 brmsg->br_setflags = 0;
2490 brmsg->br_softc = sc;
2491 brmsg->br_rtinfo = NULL;
2493 ifnet_sendmsg(&brmsg->br_nmsg.nm_lmsg, 0);
2496 bridge_rtinfo_update(brt->brt_info, dst_if, 0, flags,
2502 bridge_rtsaddr(struct bridge_softc *sc, const uint8_t *dst,
2503 struct ifnet *dst_if, uint8_t flags)
2505 struct netmsg_brsaddr brmsg;
2507 ASSERT_NOT_SERIALIZED(sc->sc_ifp->if_serializer);
2509 netmsg_init(&brmsg.br_nmsg, &curthread->td_msgport, MSGF_PRIORITY,
2510 bridge_rtinstall_handler);
2511 memcpy(brmsg.br_dst, dst, ETHER_ADDR_LEN);
2512 brmsg.br_dst_if = dst_if;
2513 brmsg.br_flags = flags;
2514 brmsg.br_setflags = 1;
2515 brmsg.br_softc = sc;
2516 brmsg.br_rtinfo = NULL;
2518 return ifnet_domsg(&brmsg.br_nmsg.nm_lmsg, 0);
2524 * Lookup the destination interface for an address.
2526 static struct ifnet *
2527 bridge_rtlookup(struct bridge_softc *sc, const uint8_t *addr)
2529 struct bridge_rtnode *brt;
2531 if ((brt = bridge_rtnode_lookup(sc, addr)) == NULL)
2533 return brt->brt_info->bri_ifp;
2537 bridge_rtreap_handler(struct netmsg *nmsg)
2539 struct bridge_softc *sc = nmsg->nm_lmsg.u.ms_resultp;
2540 struct bridge_rtnode *brt, *nbrt;
2542 LIST_FOREACH_MUTABLE(brt, &sc->sc_rtlists[mycpuid], brt_list, nbrt) {
2543 if (brt->brt_info->bri_dead)
2544 bridge_rtnode_destroy(sc, brt);
2546 ifnet_forwardmsg(&nmsg->nm_lmsg, mycpuid + 1);
2550 bridge_rtreap(struct bridge_softc *sc)
2554 ASSERT_NOT_SERIALIZED(sc->sc_ifp->if_serializer);
2556 netmsg_init(&nmsg, &curthread->td_msgport, 0, bridge_rtreap_handler);
2557 nmsg.nm_lmsg.u.ms_resultp = sc;
2559 ifnet_domsg(&nmsg.nm_lmsg, 0);
2565 * Trim the routine table so that we have a number
2566 * of routing entries less than or equal to the
2570 bridge_rttrim(struct bridge_softc *sc)
2572 struct bridge_rtnode *brt;
2575 ASSERT_NOT_SERIALIZED(sc->sc_ifp->if_serializer);
2577 /* Make sure we actually need to do this. */
2578 if (sc->sc_brtcnt <= sc->sc_brtmax)
2582 * Find out how many rtnodes are dead
2584 dead = bridge_rtage_finddead(sc);
2585 KKASSERT(dead <= sc->sc_brtcnt);
2587 if (sc->sc_brtcnt - dead <= sc->sc_brtmax) {
2588 /* Enough dead rtnodes are found */
2594 * Kill some dynamic rtnodes to meet the brtmax
2596 LIST_FOREACH(brt, &sc->sc_rtlists[mycpuid], brt_list) {
2597 struct bridge_rtinfo *bri = brt->brt_info;
2599 if (bri->bri_dead) {
2601 * We have counted this rtnode in
2602 * bridge_rtage_finddead()
2607 if ((bri->bri_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC) {
2610 KKASSERT(dead <= sc->sc_brtcnt);
2612 if (sc->sc_brtcnt - dead <= sc->sc_brtmax) {
2613 /* Enough rtnodes are collected */
2625 * Aging timer for the bridge.
2628 bridge_timer(void *arg)
2630 struct bridge_softc *sc = arg;
2631 struct lwkt_msg *lmsg;
2633 KKASSERT(mycpuid == BRIDGE_CFGCPU);
2637 if (callout_pending(&sc->sc_brcallout) ||
2638 !callout_active(&sc->sc_brcallout)) {
2642 callout_deactivate(&sc->sc_brcallout);
2644 lmsg = &sc->sc_brtimemsg.nm_lmsg;
2645 KKASSERT(lmsg->ms_flags & MSGF_DONE);
2646 lwkt_sendmsg(BRIDGE_CFGPORT, lmsg);
2652 bridge_timer_handler(struct netmsg *nmsg)
2654 struct bridge_softc *sc = nmsg->nm_lmsg.u.ms_resultp;
2656 KKASSERT(&curthread->td_msgport == BRIDGE_CFGPORT);
2660 lwkt_replymsg(&nmsg->nm_lmsg, 0);
2664 if (sc->sc_ifp->if_flags & IFF_RUNNING) {
2665 callout_reset(&sc->sc_brcallout,
2666 bridge_rtable_prune_period * hz, bridge_timer, sc);
2671 bridge_rtage_finddead(struct bridge_softc *sc)
2673 struct bridge_rtnode *brt;
2676 LIST_FOREACH(brt, &sc->sc_rtlists[mycpuid], brt_list) {
2677 struct bridge_rtinfo *bri = brt->brt_info;
2679 if ((bri->bri_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC &&
2680 time_second >= bri->bri_expire) {
2683 KKASSERT(dead <= sc->sc_brtcnt);
2692 * Perform an aging cycle.
2695 bridge_rtage(struct bridge_softc *sc)
2697 ASSERT_NOT_SERIALIZED(sc->sc_ifp->if_serializer);
2699 if (bridge_rtage_finddead(sc))
2706 * Remove all dynamic addresses from the bridge.
2709 bridge_rtflush(struct bridge_softc *sc, int full)
2711 struct bridge_rtnode *brt;
2714 ASSERT_NOT_SERIALIZED(sc->sc_ifp->if_serializer);
2717 LIST_FOREACH(brt, &sc->sc_rtlists[mycpuid], brt_list) {
2718 struct bridge_rtinfo *bri = brt->brt_info;
2721 (bri->bri_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC) {
2733 * Remove an address from the table.
2736 bridge_rtdaddr(struct bridge_softc *sc, const uint8_t *addr)
2738 struct bridge_rtnode *brt;
2740 ASSERT_NOT_SERIALIZED(sc->sc_ifp->if_serializer);
2742 if ((brt = bridge_rtnode_lookup(sc, addr)) == NULL)
2745 /* TODO: add a cheaper delete operation */
2746 brt->brt_info->bri_dead = 1;
2754 * Delete routes to a speicifc member interface.
2757 bridge_rtdelete(struct bridge_softc *sc, struct ifnet *ifp, int full)
2759 struct bridge_rtnode *brt;
2762 ASSERT_NOT_SERIALIZED(sc->sc_ifp->if_serializer);
2765 LIST_FOREACH(brt, &sc->sc_rtlists[mycpuid], brt_list) {
2766 struct bridge_rtinfo *bri = brt->brt_info;
2768 if (bri->bri_ifp == ifp &&
2770 (bri->bri_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC)) {
2780 * bridge_rtable_init:
2782 * Initialize the route table for this bridge.
2785 bridge_rtable_init(struct bridge_softc *sc)
2790 * Initialize per-cpu hash tables
2792 sc->sc_rthashs = kmalloc(sizeof(*sc->sc_rthashs) * ncpus,
2793 M_DEVBUF, M_WAITOK);
2794 for (cpu = 0; cpu < ncpus; ++cpu) {
2797 sc->sc_rthashs[cpu] =
2798 kmalloc(sizeof(struct bridge_rtnode_head) * BRIDGE_RTHASH_SIZE,
2799 M_DEVBUF, M_WAITOK);
2801 for (i = 0; i < BRIDGE_RTHASH_SIZE; i++)
2802 LIST_INIT(&sc->sc_rthashs[cpu][i]);
2804 sc->sc_rthash_key = karc4random();
2807 * Initialize per-cpu lists
2809 sc->sc_rtlists = kmalloc(sizeof(struct bridge_rtnode_head) * ncpus,
2810 M_DEVBUF, M_WAITOK);
2811 for (cpu = 0; cpu < ncpus; ++cpu)
2812 LIST_INIT(&sc->sc_rtlists[cpu]);
2816 * bridge_rtable_fini:
2818 * Deconstruct the route table for this bridge.
2821 bridge_rtable_fini(struct bridge_softc *sc)
2826 * Free per-cpu hash tables
2828 for (cpu = 0; cpu < ncpus; ++cpu)
2829 kfree(sc->sc_rthashs[cpu], M_DEVBUF);
2830 kfree(sc->sc_rthashs, M_DEVBUF);
2833 * Free per-cpu lists
2835 kfree(sc->sc_rtlists, M_DEVBUF);
2839 * The following hash function is adapted from "Hash Functions" by Bob Jenkins
2840 * ("Algorithm Alley", Dr. Dobbs Journal, September 1997).
2842 #define mix(a, b, c) \
2844 a -= b; a -= c; a ^= (c >> 13); \
2845 b -= c; b -= a; b ^= (a << 8); \
2846 c -= a; c -= b; c ^= (b >> 13); \
2847 a -= b; a -= c; a ^= (c >> 12); \
2848 b -= c; b -= a; b ^= (a << 16); \
2849 c -= a; c -= b; c ^= (b >> 5); \
2850 a -= b; a -= c; a ^= (c >> 3); \
2851 b -= c; b -= a; b ^= (a << 10); \
2852 c -= a; c -= b; c ^= (b >> 15); \
2853 } while (/*CONSTCOND*/0)
2855 static __inline uint32_t
2856 bridge_rthash(struct bridge_softc *sc, const uint8_t *addr)
2858 uint32_t a = 0x9e3779b9, b = 0x9e3779b9, c = sc->sc_rthash_key;
2869 return (c & BRIDGE_RTHASH_MASK);
2875 bridge_rtnode_addr_cmp(const uint8_t *a, const uint8_t *b)
2879 for (i = 0, d = 0; i < ETHER_ADDR_LEN && d == 0; i++) {
2880 d = ((int)a[i]) - ((int)b[i]);
2887 * bridge_rtnode_lookup:
2889 * Look up a bridge route node for the specified destination.
2891 static struct bridge_rtnode *
2892 bridge_rtnode_lookup(struct bridge_softc *sc, const uint8_t *addr)
2894 struct bridge_rtnode *brt;
2898 hash = bridge_rthash(sc, addr);
2899 LIST_FOREACH(brt, &sc->sc_rthashs[mycpuid][hash], brt_hash) {
2900 dir = bridge_rtnode_addr_cmp(addr, brt->brt_addr);
2911 * bridge_rtnode_insert:
2913 * Insert the specified bridge node into the route table.
2914 * Caller has to make sure that rtnode does not exist.
2917 bridge_rtnode_insert(struct bridge_softc *sc, struct bridge_rtnode *brt)
2919 struct bridge_rtnode *lbrt;
2923 hash = bridge_rthash(sc, brt->brt_addr);
2925 lbrt = LIST_FIRST(&sc->sc_rthashs[mycpuid][hash]);
2927 LIST_INSERT_HEAD(&sc->sc_rthashs[mycpuid][hash], brt, brt_hash);
2932 dir = bridge_rtnode_addr_cmp(brt->brt_addr, lbrt->brt_addr);
2933 KASSERT(dir != 0, ("rtnode already exist\n"));
2936 LIST_INSERT_BEFORE(lbrt, brt, brt_hash);
2939 if (LIST_NEXT(lbrt, brt_hash) == NULL) {
2940 LIST_INSERT_AFTER(lbrt, brt, brt_hash);
2943 lbrt = LIST_NEXT(lbrt, brt_hash);
2944 } while (lbrt != NULL);
2946 panic("no suitable position found for rtnode\n");
2948 LIST_INSERT_HEAD(&sc->sc_rtlists[mycpuid], brt, brt_list);
2951 * Update the brtcnt.
2952 * We only need to do it once and we do it on CPU0.
2959 * bridge_rtnode_destroy:
2961 * Destroy a bridge rtnode.
2964 bridge_rtnode_destroy(struct bridge_softc *sc, struct bridge_rtnode *brt)
2966 LIST_REMOVE(brt, brt_hash);
2967 LIST_REMOVE(brt, brt_list);
2969 if (mycpuid + 1 == ncpus) {
2970 /* Free rtinfo associated with rtnode on the last cpu */
2971 kfree(brt->brt_info, M_DEVBUF);
2973 kfree(brt, M_DEVBUF);
2976 /* Update brtcnt only on CPU0 */
2982 bridge_post_pfil(struct mbuf *m)
2984 if (m->m_pkthdr.fw_flags & IPFORWARD_MBUF_TAGGED)
2988 if (m->m_pkthdr.fw_flags & DUMMYNET_MBUF_TAGGED)
2995 * Send bridge packets through pfil if they are one of the types pfil can deal
2996 * with, or if they are ARP or REVARP. (pfil will pass ARP and REVARP without
2997 * question.) If *bifp or *ifp are NULL then packet filtering is skipped for
3001 bridge_pfil(struct mbuf **mp, struct ifnet *bifp, struct ifnet *ifp, int dir)
3003 int snap, error, i, hlen;
3004 struct ether_header *eh1, eh2;
3007 u_int16_t ether_type;
3010 error = -1; /* Default error if not error == 0 */
3012 if (pfil_bridge == 0 && pfil_member == 0)
3013 return (0); /* filtering is disabled */
3015 i = min((*mp)->m_pkthdr.len, max_protohdr);
3016 if ((*mp)->m_len < i) {
3017 *mp = m_pullup(*mp, i);
3019 kprintf("%s: m_pullup failed\n", __func__);
3024 eh1 = mtod(*mp, struct ether_header *);
3025 ether_type = ntohs(eh1->ether_type);
3028 * Check for SNAP/LLC.
3030 if (ether_type < ETHERMTU) {
3031 struct llc *llc2 = (struct llc *)(eh1 + 1);
3033 if ((*mp)->m_len >= ETHER_HDR_LEN + 8 &&
3034 llc2->llc_dsap == LLC_SNAP_LSAP &&
3035 llc2->llc_ssap == LLC_SNAP_LSAP &&
3036 llc2->llc_control == LLC_UI) {
3037 ether_type = htons(llc2->llc_un.type_snap.ether_type);
3043 * If we're trying to filter bridge traffic, don't look at anything
3044 * other than IP and ARP traffic. If the filter doesn't understand
3045 * IPv6, don't allow IPv6 through the bridge either. This is lame
3046 * since if we really wanted, say, an AppleTalk filter, we are hosed,
3047 * but of course we don't have an AppleTalk filter to begin with.
3048 * (Note that since pfil doesn't understand ARP it will pass *ALL*
3051 switch (ether_type) {
3053 case ETHERTYPE_REVARP:
3054 return (0); /* Automatically pass */
3057 case ETHERTYPE_IPV6:
3062 * Check to see if the user wants to pass non-ip
3063 * packets, these will not be checked by pfil(9) and
3064 * passed unconditionally so the default is to drop.
3070 /* Strip off the Ethernet header and keep a copy. */
3071 m_copydata(*mp, 0, ETHER_HDR_LEN, (caddr_t) &eh2);
3072 m_adj(*mp, ETHER_HDR_LEN);
3074 /* Strip off snap header, if present */
3076 m_copydata(*mp, 0, sizeof(struct llc), (caddr_t) &llc1);
3077 m_adj(*mp, sizeof(struct llc));
3081 * Check the IP header for alignment and errors
3083 if (dir == PFIL_IN) {
3084 switch (ether_type) {
3086 error = bridge_ip_checkbasic(mp);
3089 case ETHERTYPE_IPV6:
3090 error = bridge_ip6_checkbasic(mp);
3103 * Run the packet through pfil
3109 * before calling the firewall, swap fields the same as
3110 * IP does. here we assume the header is contiguous
3112 ip = mtod(*mp, struct ip *);
3114 ip->ip_len = ntohs(ip->ip_len);
3115 ip->ip_off = ntohs(ip->ip_off);
3118 * Run pfil on the member interface and the bridge, both can
3119 * be skipped by clearing pfil_member or pfil_bridge.
3122 * in_if -> bridge_if -> out_if
3124 if (pfil_bridge && dir == PFIL_OUT && bifp != NULL) {
3125 error = pfil_run_hooks(&inet_pfil_hook, mp, bifp, dir);
3126 if (*mp == NULL || error != 0) /* filter may consume */
3128 error = bridge_post_pfil(*mp);
3133 if (pfil_member && ifp != NULL) {
3134 error = pfil_run_hooks(&inet_pfil_hook, mp, ifp, dir);
3135 if (*mp == NULL || error != 0) /* filter may consume */
3137 error = bridge_post_pfil(*mp);
3142 if (pfil_bridge && dir == PFIL_IN && bifp != NULL) {
3143 error = pfil_run_hooks(&inet_pfil_hook, mp, bifp, dir);
3144 if (*mp == NULL || error != 0) /* filter may consume */
3146 error = bridge_post_pfil(*mp);
3151 /* check if we need to fragment the packet */
3152 if (pfil_member && ifp != NULL && dir == PFIL_OUT) {
3153 i = (*mp)->m_pkthdr.len;
3154 if (i > ifp->if_mtu) {
3155 error = bridge_fragment(ifp, *mp, &eh2, snap,
3161 /* Recalculate the ip checksum and restore byte ordering */
3162 ip = mtod(*mp, struct ip *);
3163 hlen = ip->ip_hl << 2;
3164 if (hlen < sizeof(struct ip))
3166 if (hlen > (*mp)->m_len) {
3167 if ((*mp = m_pullup(*mp, hlen)) == 0)
3169 ip = mtod(*mp, struct ip *);
3173 ip->ip_len = htons(ip->ip_len);
3174 ip->ip_off = htons(ip->ip_off);
3176 if (hlen == sizeof(struct ip))
3177 ip->ip_sum = in_cksum_hdr(ip);
3179 ip->ip_sum = in_cksum(*mp, hlen);
3183 case ETHERTYPE_IPV6 :
3184 if (pfil_bridge && dir == PFIL_OUT && bifp != NULL)
3185 error = pfil_run_hooks(&inet6_pfil_hook, mp, bifp,
3188 if (*mp == NULL || error != 0) /* filter may consume */
3191 if (pfil_member && ifp != NULL)
3192 error = pfil_run_hooks(&inet6_pfil_hook, mp, ifp,
3195 if (*mp == NULL || error != 0) /* filter may consume */
3198 if (pfil_bridge && dir == PFIL_IN && bifp != NULL)
3199 error = pfil_run_hooks(&inet6_pfil_hook, mp, bifp,
3216 * Finally, put everything back the way it was and return
3219 M_PREPEND(*mp, sizeof(struct llc), MB_DONTWAIT);
3222 bcopy(&llc1, mtod(*mp, caddr_t), sizeof(struct llc));
3225 M_PREPEND(*mp, ETHER_HDR_LEN, MB_DONTWAIT);
3228 bcopy(&eh2, mtod(*mp, caddr_t), ETHER_HDR_LEN);
3239 * Perform basic checks on header size since
3240 * pfil assumes ip_input has already processed
3241 * it for it. Cut-and-pasted from ip_input.c.
3242 * Given how simple the IPv6 version is,
3243 * does the IPv4 version really need to be
3246 * XXX Should we update ipstat here, or not?
3247 * XXX Right now we update ipstat but not
3251 bridge_ip_checkbasic(struct mbuf **mp)
3253 struct mbuf *m = *mp;
3261 if (IP_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) {
3262 if ((m = m_copyup(m, sizeof(struct ip),
3263 (max_linkhdr + 3) & ~3)) == NULL) {
3264 /* XXXJRT new stat, please */
3265 ipstat.ips_toosmall++;
3270 #ifndef __predict_false
3271 #define __predict_false(x) x
3273 if (__predict_false(m->m_len < sizeof (struct ip))) {
3274 if ((m = m_pullup(m, sizeof (struct ip))) == NULL) {
3275 ipstat.ips_toosmall++;
3279 ip = mtod(m, struct ip *);
3280 if (ip == NULL) goto bad;
3282 if (ip->ip_v != IPVERSION) {
3283 ipstat.ips_badvers++;
3286 hlen = ip->ip_hl << 2;
3287 if (hlen < sizeof(struct ip)) { /* minimum header length */
3288 ipstat.ips_badhlen++;
3291 if (hlen > m->m_len) {
3292 if ((m = m_pullup(m, hlen)) == 0) {
3293 ipstat.ips_badhlen++;
3296 ip = mtod(m, struct ip *);
3297 if (ip == NULL) goto bad;
3300 if (m->m_pkthdr.csum_flags & CSUM_IP_CHECKED) {
3301 sum = !(m->m_pkthdr.csum_flags & CSUM_IP_VALID);
3303 if (hlen == sizeof(struct ip)) {
3304 sum = in_cksum_hdr(ip);
3306 sum = in_cksum(m, hlen);
3310 ipstat.ips_badsum++;
3314 /* Retrieve the packet length. */
3315 len = ntohs(ip->ip_len);
3318 * Check for additional length bogosity
3321 ipstat.ips_badlen++;
3326 * Check that the amount of data in the buffers
3327 * is as at least much as the IP header would have us expect.
3328 * Drop packet if shorter than we expect.
3330 if (m->m_pkthdr.len < len) {
3331 ipstat.ips_tooshort++;
3335 /* Checks out, proceed */
3346 * Same as above, but for IPv6.
3347 * Cut-and-pasted from ip6_input.c.
3348 * XXX Should we update ip6stat, or not?
3351 bridge_ip6_checkbasic(struct mbuf **mp)
3353 struct mbuf *m = *mp;
3354 struct ip6_hdr *ip6;
3357 * If the IPv6 header is not aligned, slurp it up into a new
3358 * mbuf with space for link headers, in the event we forward
3359 * it. Otherwise, if it is aligned, make sure the entire base
3360 * IPv6 header is in the first mbuf of the chain.
3363 if (IP6_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) {
3364 struct ifnet *inifp = m->m_pkthdr.rcvif;
3365 if ((m = m_copyup(m, sizeof(struct ip6_hdr),
3366 (max_linkhdr + 3) & ~3)) == NULL) {
3367 /* XXXJRT new stat, please */
3368 ip6stat.ip6s_toosmall++;
3369 in6_ifstat_inc(inifp, ifs6_in_hdrerr);
3374 if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
3375 struct ifnet *inifp = m->m_pkthdr.rcvif;
3376 if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
3377 ip6stat.ip6s_toosmall++;
3378 in6_ifstat_inc(inifp, ifs6_in_hdrerr);
3383 ip6 = mtod(m, struct ip6_hdr *);
3385 if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
3386 ip6stat.ip6s_badvers++;
3387 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
3391 /* Checks out, proceed */
3404 * Return a fragmented mbuf chain.
3407 bridge_fragment(struct ifnet *ifp, struct mbuf *m, struct ether_header *eh,
3408 int snap, struct llc *llc)
3414 if (m->m_len < sizeof(struct ip) &&
3415 (m = m_pullup(m, sizeof(struct ip))) == NULL)
3417 ip = mtod(m, struct ip *);
3419 error = ip_fragment(ip, &m, ifp->if_mtu, ifp->if_hwassist,
3424 /* walk the chain and re-add the Ethernet header */
3425 for (m0 = m; m0; m0 = m0->m_nextpkt) {
3428 M_PREPEND(m0, sizeof(struct llc), MB_DONTWAIT);
3433 bcopy(llc, mtod(m0, caddr_t),
3434 sizeof(struct llc));
3436 M_PREPEND(m0, ETHER_HDR_LEN, MB_DONTWAIT);
3441 bcopy(eh, mtod(m0, caddr_t), ETHER_HDR_LEN);
3447 ipstat.ips_fragmented++;
3458 bridge_enqueue_handler(struct netmsg *nmsg)
3460 struct netmsg_packet *nmp;
3461 struct ifnet *dst_ifp;
3464 nmp = (struct netmsg_packet *)nmsg;
3466 dst_ifp = nmp->nm_netmsg.nm_lmsg.u.ms_resultp;
3468 bridge_handoff(dst_ifp, m);
3472 bridge_pfil_enqueue_handler(struct netmsg *nmsg)
3474 struct netmsg_packet *nmp;
3475 struct ifnet *dst_ifp;
3478 nmp = (struct netmsg_packet *)nmsg;
3480 dst_ifp = nmp->nm_netmsg.nm_lmsg.u.ms_resultp;
3483 * Filter on the output interface. Pass a NULL bridge interface
3484 * pointer so we do not redundantly filter on the bridge for
3485 * each interface we broadcast on.
3487 if (inet_pfil_hook.ph_hashooks > 0
3489 || inet6_pfil_hook.ph_hashooks > 0
3492 if (bridge_pfil(&m, NULL, dst_ifp, PFIL_OUT) != 0)
3497 bridge_handoff(dst_ifp, m);
3501 bridge_handoff(struct ifnet *dst_ifp, struct mbuf *m)
3505 lwkt_serialize_enter(dst_ifp->if_serializer);
3507 /* We may be sending a fragment so traverse the mbuf */
3509 struct altq_pktattr pktattr;
3512 m->m_nextpkt = NULL;
3514 if (ifq_is_enabled(&dst_ifp->if_snd))
3515 altq_etherclassify(&dst_ifp->if_snd, m, &pktattr);
3517 ifq_handoff(dst_ifp, m, &pktattr);
3520 lwkt_serialize_exit(dst_ifp->if_serializer);
3524 bridge_control_dispatch(struct netmsg *nmsg)
3526 struct netmsg_brctl *bc_msg = (struct netmsg_brctl *)nmsg;
3527 struct ifnet *bifp = bc_msg->bc_sc->sc_ifp;
3530 lwkt_serialize_enter(bifp->if_serializer);
3531 error = bc_msg->bc_func(bc_msg->bc_sc, bc_msg->bc_arg);
3532 lwkt_serialize_exit(bifp->if_serializer);
3534 lwkt_replymsg(&nmsg->nm_lmsg, error);
3538 bridge_control(struct bridge_softc *sc, u_long cmd,
3539 bridge_ctl_t bc_func, void *bc_arg)
3541 struct ifnet *bifp = sc->sc_ifp;
3542 struct netmsg_brctl bc_msg;
3543 struct netmsg *nmsg;
3546 ASSERT_SERIALIZED(bifp->if_serializer);
3548 bzero(&bc_msg, sizeof(bc_msg));
3549 nmsg = &bc_msg.bc_nmsg;
3551 netmsg_init(nmsg, &curthread->td_msgport, 0, bridge_control_dispatch);
3552 bc_msg.bc_func = bc_func;
3554 bc_msg.bc_arg = bc_arg;
3556 lwkt_serialize_exit(bifp->if_serializer);
3557 error = lwkt_domsg(BRIDGE_CFGPORT, &nmsg->nm_lmsg, 0);
3558 lwkt_serialize_enter(bifp->if_serializer);