1 /* $OpenBSD: if_trunk.c,v 1.30 2007/01/31 06:20:19 reyk Exp $ */
4 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
5 * Copyright (c) 2007 Andrew Thompson <thompsa@FreeBSD.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/cdefs.h>
21 __FBSDID("$FreeBSD$");
24 #include "opt_inet6.h"
26 #include <sys/param.h>
27 #include <sys/kernel.h>
28 #include <sys/malloc.h>
30 #include <sys/queue.h>
31 #include <sys/socket.h>
32 #include <sys/sockio.h>
33 #include <sys/sysctl.h>
34 #include <sys/module.h>
36 #include <sys/systm.h>
40 #include <sys/rwlock.h>
41 #include <sys/taskqueue.h>
42 #include <sys/eventhandler.h>
44 #include <net/ethernet.h>
46 #include <net/if_clone.h>
47 #include <net/if_arp.h>
48 #include <net/if_dl.h>
49 #include <net/if_llc.h>
50 #include <net/if_media.h>
51 #include <net/if_types.h>
52 #include <net/if_var.h>
56 #include <netinet/in.h>
57 #include <netinet/in_systm.h>
58 #include <netinet/if_ether.h>
59 #include <netinet/ip.h>
63 #include <netinet/ip6.h>
66 #include <net/if_vlan_var.h>
67 #include <net/if_lagg.h>
68 #include <net/ieee8023ad_lacp.h>
70 /* Special flags we should propagate to the lagg ports. */
73 int (*func)(struct ifnet *, int);
75 {IFF_PROMISC, ifpromisc},
76 {IFF_ALLMULTI, if_allmulti},
80 SLIST_HEAD(__trhead, lagg_softc) lagg_list; /* list of laggs */
81 static struct mtx lagg_list_mtx;
82 eventhandler_tag lagg_detach_cookie = NULL;
84 static int lagg_clone_create(struct if_clone *, int, caddr_t);
85 static void lagg_clone_destroy(struct ifnet *);
86 static void lagg_lladdr(struct lagg_softc *, uint8_t *);
87 static void lagg_capabilities(struct lagg_softc *);
88 static void lagg_port_lladdr(struct lagg_port *, uint8_t *);
89 static void lagg_port_setlladdr(void *, int);
90 static int lagg_port_create(struct lagg_softc *, struct ifnet *);
91 static int lagg_port_destroy(struct lagg_port *, int);
92 static struct mbuf *lagg_input(struct ifnet *, struct mbuf *);
93 static void lagg_linkstate(struct lagg_softc *);
94 static void lagg_port_state(struct ifnet *, int);
95 static int lagg_port_ioctl(struct ifnet *, u_long, caddr_t);
96 static int lagg_port_output(struct ifnet *, struct mbuf *,
97 struct sockaddr *, struct route *);
98 static void lagg_port_ifdetach(void *arg __unused, struct ifnet *);
99 static int lagg_port_checkstacking(struct lagg_softc *);
100 static void lagg_port2req(struct lagg_port *, struct lagg_reqport *);
101 static void lagg_init(void *);
102 static void lagg_stop(struct lagg_softc *);
103 static int lagg_ioctl(struct ifnet *, u_long, caddr_t);
104 static int lagg_ether_setmulti(struct lagg_softc *);
105 static int lagg_ether_cmdmulti(struct lagg_port *, int);
106 static int lagg_setflag(struct lagg_port *, int, int,
107 int (*func)(struct ifnet *, int));
108 static int lagg_setflags(struct lagg_port *, int status);
109 static void lagg_start(struct ifnet *);
110 static int lagg_media_change(struct ifnet *);
111 static void lagg_media_status(struct ifnet *, struct ifmediareq *);
112 static struct lagg_port *lagg_link_active(struct lagg_softc *,
114 static const void *lagg_gethdr(struct mbuf *, u_int, u_int, void *);
116 IFC_SIMPLE_DECLARE(lagg, 0);
118 /* Simple round robin */
119 static int lagg_rr_attach(struct lagg_softc *);
120 static int lagg_rr_detach(struct lagg_softc *);
121 static int lagg_rr_start(struct lagg_softc *, struct mbuf *);
122 static struct mbuf *lagg_rr_input(struct lagg_softc *, struct lagg_port *,
125 /* Active failover */
126 static int lagg_fail_attach(struct lagg_softc *);
127 static int lagg_fail_detach(struct lagg_softc *);
128 static int lagg_fail_start(struct lagg_softc *, struct mbuf *);
129 static struct mbuf *lagg_fail_input(struct lagg_softc *, struct lagg_port *,
133 static int lagg_lb_attach(struct lagg_softc *);
134 static int lagg_lb_detach(struct lagg_softc *);
135 static int lagg_lb_port_create(struct lagg_port *);
136 static void lagg_lb_port_destroy(struct lagg_port *);
137 static int lagg_lb_start(struct lagg_softc *, struct mbuf *);
138 static struct mbuf *lagg_lb_input(struct lagg_softc *, struct lagg_port *,
140 static int lagg_lb_porttable(struct lagg_softc *, struct lagg_port *);
143 static int lagg_lacp_attach(struct lagg_softc *);
144 static int lagg_lacp_detach(struct lagg_softc *);
145 static int lagg_lacp_start(struct lagg_softc *, struct mbuf *);
146 static struct mbuf *lagg_lacp_input(struct lagg_softc *, struct lagg_port *,
148 static void lagg_lacp_lladdr(struct lagg_softc *);
150 /* lagg protocol table */
151 static const struct {
153 int (*ti_attach)(struct lagg_softc *);
155 { LAGG_PROTO_ROUNDROBIN, lagg_rr_attach },
156 { LAGG_PROTO_FAILOVER, lagg_fail_attach },
157 { LAGG_PROTO_LOADBALANCE, lagg_lb_attach },
158 { LAGG_PROTO_ETHERCHANNEL, lagg_lb_attach },
159 { LAGG_PROTO_LACP, lagg_lacp_attach },
160 { LAGG_PROTO_NONE, NULL }
163 SYSCTL_DECL(_net_link);
164 SYSCTL_NODE(_net_link, OID_AUTO, lagg, CTLFLAG_RW, 0, "Link Aggregation");
166 static int lagg_failover_rx_all = 0; /* Allow input on any failover links */
167 SYSCTL_INT(_net_link_lagg, OID_AUTO, failover_rx_all, CTLFLAG_RW,
168 &lagg_failover_rx_all, 0,
169 "Accept input from any interface in a failover lagg");
172 lagg_modevent(module_t mod, int type, void *data)
177 mtx_init(&lagg_list_mtx, "if_lagg list", NULL, MTX_DEF);
178 SLIST_INIT(&lagg_list);
179 if_clone_attach(&lagg_cloner);
180 lagg_input_p = lagg_input;
181 lagg_linkstate_p = lagg_port_state;
182 lagg_detach_cookie = EVENTHANDLER_REGISTER(
183 ifnet_departure_event, lagg_port_ifdetach, NULL,
184 EVENTHANDLER_PRI_ANY);
187 EVENTHANDLER_DEREGISTER(ifnet_departure_event,
189 if_clone_detach(&lagg_cloner);
191 lagg_linkstate_p = NULL;
192 mtx_destroy(&lagg_list_mtx);
200 static moduledata_t lagg_mod = {
206 DECLARE_MODULE(if_lagg, lagg_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
208 #if __FreeBSD_version >= 800000
210 * This routine is run via an vlan
214 lagg_register_vlan(void *arg, struct ifnet *ifp, u_int16_t vtag)
216 struct lagg_softc *sc = ifp->if_softc;
217 struct lagg_port *lp;
219 if (ifp->if_softc != arg) /* Not our event */
223 if (!SLIST_EMPTY(&sc->sc_ports)) {
224 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
225 EVENTHANDLER_INVOKE(vlan_config, lp->lp_ifp, vtag);
231 * This routine is run via an vlan
235 lagg_unregister_vlan(void *arg, struct ifnet *ifp, u_int16_t vtag)
237 struct lagg_softc *sc = ifp->if_softc;
238 struct lagg_port *lp;
240 if (ifp->if_softc != arg) /* Not our event */
244 if (!SLIST_EMPTY(&sc->sc_ports)) {
245 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
246 EVENTHANDLER_INVOKE(vlan_unconfig, lp->lp_ifp, vtag);
253 lagg_clone_create(struct if_clone *ifc, int unit, caddr_t params)
255 struct lagg_softc *sc;
258 static const u_char eaddr[6]; /* 00:00:00:00:00:00 */
260 sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
261 ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
267 sc->sc_proto = LAGG_PROTO_NONE;
268 for (i = 0; lagg_protos[i].ti_proto != LAGG_PROTO_NONE; i++) {
269 if (lagg_protos[i].ti_proto == LAGG_PROTO_DEFAULT) {
270 sc->sc_proto = lagg_protos[i].ti_proto;
271 if ((error = lagg_protos[i].ti_attach(sc)) != 0) {
272 if_free_type(ifp, IFT_ETHER);
280 SLIST_INIT(&sc->sc_ports);
281 TASK_INIT(&sc->sc_lladdr_task, 0, lagg_port_setlladdr, sc);
283 /* Initialise pseudo media types */
284 ifmedia_init(&sc->sc_media, 0, lagg_media_change,
286 ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL);
287 ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO);
289 if_initname(ifp, ifc->ifc_name, unit);
290 ifp->if_type = IFT_ETHER;
292 ifp->if_start = lagg_start;
293 ifp->if_init = lagg_init;
294 ifp->if_ioctl = lagg_ioctl;
295 ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
297 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
298 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
299 IFQ_SET_READY(&ifp->if_snd);
302 * Attach as an ordinary ethernet device, childs will be attached
303 * as special device IFT_IEEE8023ADLAG.
305 ether_ifattach(ifp, eaddr);
307 #if __FreeBSD_version >= 800000
308 sc->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
309 lagg_register_vlan, sc, EVENTHANDLER_PRI_FIRST);
310 sc->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
311 lagg_unregister_vlan, sc, EVENTHANDLER_PRI_FIRST);
314 /* Insert into the global list of laggs */
315 mtx_lock(&lagg_list_mtx);
316 SLIST_INSERT_HEAD(&lagg_list, sc, sc_entries);
317 mtx_unlock(&lagg_list_mtx);
323 lagg_clone_destroy(struct ifnet *ifp)
325 struct lagg_softc *sc = (struct lagg_softc *)ifp->if_softc;
326 struct lagg_port *lp;
331 ifp->if_flags &= ~IFF_UP;
333 #if __FreeBSD_version >= 800000
334 EVENTHANDLER_DEREGISTER(vlan_config, sc->vlan_attach);
335 EVENTHANDLER_DEREGISTER(vlan_unconfig, sc->vlan_detach);
338 /* Shutdown and remove lagg ports */
339 while ((lp = SLIST_FIRST(&sc->sc_ports)) != NULL)
340 lagg_port_destroy(lp, 1);
341 /* Unhook the aggregation protocol */
342 (*sc->sc_detach)(sc);
346 ifmedia_removeall(&sc->sc_media);
348 if_free_type(ifp, IFT_ETHER);
350 mtx_lock(&lagg_list_mtx);
351 SLIST_REMOVE(&lagg_list, sc, lagg_softc, sc_entries);
352 mtx_unlock(&lagg_list_mtx);
354 taskqueue_drain(taskqueue_swi, &sc->sc_lladdr_task);
355 LAGG_LOCK_DESTROY(sc);
360 lagg_lladdr(struct lagg_softc *sc, uint8_t *lladdr)
362 struct ifnet *ifp = sc->sc_ifp;
364 if (memcmp(lladdr, IF_LLADDR(ifp), ETHER_ADDR_LEN) == 0)
367 bcopy(lladdr, IF_LLADDR(ifp), ETHER_ADDR_LEN);
368 /* Let the protocol know the MAC has changed */
369 if (sc->sc_lladdr != NULL)
370 (*sc->sc_lladdr)(sc);
371 EVENTHANDLER_INVOKE(iflladdr_event, ifp);
375 lagg_capabilities(struct lagg_softc *sc)
377 struct lagg_port *lp;
378 int cap = ~0, ena = ~0;
381 LAGG_WLOCK_ASSERT(sc);
383 /* Get capabilities from the lagg ports */
384 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
385 cap &= lp->lp_ifp->if_capabilities;
386 ena &= lp->lp_ifp->if_capenable;
387 hwa &= lp->lp_ifp->if_hwassist;
389 cap = (cap == ~0 ? 0 : cap);
390 ena = (ena == ~0 ? 0 : ena);
391 hwa = (hwa == ~0 ? 0 : hwa);
393 if (sc->sc_ifp->if_capabilities != cap ||
394 sc->sc_ifp->if_capenable != ena ||
395 sc->sc_ifp->if_hwassist != hwa) {
396 sc->sc_ifp->if_capabilities = cap;
397 sc->sc_ifp->if_capenable = ena;
398 sc->sc_ifp->if_hwassist = hwa;
399 getmicrotime(&sc->sc_ifp->if_lastchange);
401 if (sc->sc_ifflags & IFF_DEBUG)
402 if_printf(sc->sc_ifp,
403 "capabilities 0x%08x enabled 0x%08x\n", cap, ena);
408 lagg_port_lladdr(struct lagg_port *lp, uint8_t *lladdr)
410 struct lagg_softc *sc = lp->lp_softc;
411 struct ifnet *ifp = lp->lp_ifp;
412 struct lagg_llq *llq;
415 LAGG_WLOCK_ASSERT(sc);
417 if (lp->lp_detaching ||
418 memcmp(lladdr, IF_LLADDR(ifp), ETHER_ADDR_LEN) == 0)
421 /* Check to make sure its not already queued to be changed */
422 SLIST_FOREACH(llq, &sc->sc_llq_head, llq_entries) {
423 if (llq->llq_ifp == ifp) {
430 llq = malloc(sizeof(struct lagg_llq), M_DEVBUF, M_NOWAIT);
431 if (llq == NULL) /* XXX what to do */
435 /* Update the lladdr even if pending, it may have changed */
437 bcopy(lladdr, llq->llq_lladdr, ETHER_ADDR_LEN);
440 SLIST_INSERT_HEAD(&sc->sc_llq_head, llq, llq_entries);
442 taskqueue_enqueue(taskqueue_swi, &sc->sc_lladdr_task);
446 * Set the interface MAC address from a taskqueue to avoid a LOR.
449 lagg_port_setlladdr(void *arg, int pending)
451 struct lagg_softc *sc = (struct lagg_softc *)arg;
452 struct lagg_llq *llq, *head;
456 /* Grab a local reference of the queue and remove it from the softc */
458 head = SLIST_FIRST(&sc->sc_llq_head);
459 SLIST_FIRST(&sc->sc_llq_head) = NULL;
463 * Traverse the queue and set the lladdr on each ifp. It is safe to do
464 * unlocked as we have the only reference to it.
466 for (llq = head; llq != NULL; llq = head) {
469 /* Set the link layer address */
470 error = if_setlladdr(ifp, llq->llq_lladdr, ETHER_ADDR_LEN);
472 printf("%s: setlladdr failed on %s\n", __func__,
475 head = SLIST_NEXT(llq, llq_entries);
481 lagg_port_create(struct lagg_softc *sc, struct ifnet *ifp)
483 struct lagg_softc *sc_ptr;
484 struct lagg_port *lp;
487 LAGG_WLOCK_ASSERT(sc);
489 /* Limit the maximal number of lagg ports */
490 if (sc->sc_count >= LAGG_MAX_PORTS)
493 /* Check if port has already been associated to a lagg */
494 if (ifp->if_lagg != NULL)
497 /* XXX Disallow non-ethernet interfaces (this should be any of 802) */
498 if (ifp->if_type != IFT_ETHER)
499 return (EPROTONOSUPPORT);
501 /* Allow the first Ethernet member to define the MTU */
502 if (SLIST_EMPTY(&sc->sc_ports))
503 sc->sc_ifp->if_mtu = ifp->if_mtu;
504 else if (sc->sc_ifp->if_mtu != ifp->if_mtu) {
505 if_printf(sc->sc_ifp, "invalid MTU for %s\n",
510 if ((lp = malloc(sizeof(struct lagg_port),
511 M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
514 /* Check if port is a stacked lagg */
515 mtx_lock(&lagg_list_mtx);
516 SLIST_FOREACH(sc_ptr, &lagg_list, sc_entries) {
517 if (ifp == sc_ptr->sc_ifp) {
518 mtx_unlock(&lagg_list_mtx);
521 /* XXX disable stacking for the moment, its untested
522 lp->lp_flags |= LAGG_PORT_STACK;
523 if (lagg_port_checkstacking(sc_ptr) >=
525 mtx_unlock(&lagg_list_mtx);
532 mtx_unlock(&lagg_list_mtx);
534 /* Change the interface type */
535 lp->lp_iftype = ifp->if_type;
536 ifp->if_type = IFT_IEEE8023ADLAG;
538 lp->lp_ioctl = ifp->if_ioctl;
539 ifp->if_ioctl = lagg_port_ioctl;
540 lp->lp_output = ifp->if_output;
541 ifp->if_output = lagg_port_output;
546 /* Save port link layer address */
547 bcopy(IF_LLADDR(ifp), lp->lp_lladdr, ETHER_ADDR_LEN);
549 if (SLIST_EMPTY(&sc->sc_ports)) {
551 lagg_lladdr(sc, IF_LLADDR(ifp));
553 /* Update link layer address for this port */
554 lagg_port_lladdr(lp, IF_LLADDR(sc->sc_ifp));
557 /* Insert into the list of ports */
558 SLIST_INSERT_HEAD(&sc->sc_ports, lp, lp_entries);
561 /* Update lagg capabilities */
562 lagg_capabilities(sc);
565 /* Add multicast addresses and interface flags to this port */
566 lagg_ether_cmdmulti(lp, 1);
567 lagg_setflags(lp, 1);
569 if (sc->sc_port_create != NULL)
570 error = (*sc->sc_port_create)(lp);
572 /* remove the port again, without calling sc_port_destroy */
573 lagg_port_destroy(lp, 0);
581 lagg_port_checkstacking(struct lagg_softc *sc)
583 struct lagg_softc *sc_ptr;
584 struct lagg_port *lp;
587 LAGG_WLOCK_ASSERT(sc);
589 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
590 if (lp->lp_flags & LAGG_PORT_STACK) {
591 sc_ptr = (struct lagg_softc *)lp->lp_ifp->if_softc;
592 m = MAX(m, lagg_port_checkstacking(sc_ptr));
600 lagg_port_destroy(struct lagg_port *lp, int runpd)
602 struct lagg_softc *sc = lp->lp_softc;
603 struct lagg_port *lp_ptr;
604 struct lagg_llq *llq;
605 struct ifnet *ifp = lp->lp_ifp;
607 LAGG_WLOCK_ASSERT(sc);
609 if (runpd && sc->sc_port_destroy != NULL)
610 (*sc->sc_port_destroy)(lp);
613 * Remove multicast addresses and interface flags from this port and
614 * reset the MAC address, skip if the interface is being detached.
616 if (!lp->lp_detaching) {
617 lagg_ether_cmdmulti(lp, 0);
618 lagg_setflags(lp, 0);
619 lagg_port_lladdr(lp, lp->lp_lladdr);
622 /* Restore interface */
623 ifp->if_type = lp->lp_iftype;
624 ifp->if_ioctl = lp->lp_ioctl;
625 ifp->if_output = lp->lp_output;
628 /* Finally, remove the port from the lagg */
629 SLIST_REMOVE(&sc->sc_ports, lp, lagg_port, lp_entries);
632 /* Update the primary interface */
633 if (lp == sc->sc_primary) {
634 uint8_t lladdr[ETHER_ADDR_LEN];
636 if ((lp_ptr = SLIST_FIRST(&sc->sc_ports)) == NULL) {
637 bzero(&lladdr, ETHER_ADDR_LEN);
639 bcopy(lp_ptr->lp_lladdr,
640 lladdr, ETHER_ADDR_LEN);
642 lagg_lladdr(sc, lladdr);
643 sc->sc_primary = lp_ptr;
645 /* Update link layer address for each port */
646 SLIST_FOREACH(lp_ptr, &sc->sc_ports, lp_entries)
647 lagg_port_lladdr(lp_ptr, lladdr);
650 /* Remove any pending lladdr changes from the queue */
651 if (lp->lp_detaching) {
652 SLIST_FOREACH(llq, &sc->sc_llq_head, llq_entries) {
653 if (llq->llq_ifp == ifp) {
654 SLIST_REMOVE(&sc->sc_llq_head, llq, lagg_llq,
657 break; /* Only appears once */
663 if_printf(ifp, "%s: lp_ifflags unclean\n", __func__);
667 /* Update lagg capabilities */
668 lagg_capabilities(sc);
675 lagg_port_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
677 struct lagg_reqport *rp = (struct lagg_reqport *)data;
678 struct lagg_softc *sc;
679 struct lagg_port *lp = NULL;
682 /* Should be checked by the caller */
683 if (ifp->if_type != IFT_IEEE8023ADLAG ||
684 (lp = ifp->if_lagg) == NULL || (sc = lp->lp_softc) == NULL)
689 if (rp->rp_portname[0] == '\0' ||
690 ifunit(rp->rp_portname) != ifp) {
696 if ((lp = ifp->if_lagg) == NULL || lp->lp_softc != sc) {
702 lagg_port2req(lp, rp);
707 if (lp->lp_ioctl == NULL) {
711 error = (*lp->lp_ioctl)(ifp, cmd, data);
715 /* Update lagg interface capabilities */
717 lagg_capabilities(sc);
722 /* Do not allow the MTU to be changed once joined */
733 if (lp->lp_ioctl != NULL)
734 return ((*lp->lp_ioctl)(ifp, cmd, data));
740 lagg_port_output(struct ifnet *ifp, struct mbuf *m,
741 struct sockaddr *dst, struct route *ro)
743 struct lagg_port *lp = ifp->if_lagg;
744 struct ether_header *eh;
747 switch (dst->sa_family) {
748 case pseudo_AF_HDRCMPLT:
750 eh = (struct ether_header *)dst->sa_data;
751 type = eh->ether_type;
756 * Only allow ethernet types required to initiate or maintain the link,
757 * aggregated frames take a different path.
759 switch (ntohs(type)) {
760 case ETHERTYPE_PAE: /* EAPOL PAE/802.1x */
761 return ((*lp->lp_output)(ifp, m, dst, ro));
764 /* drop any other frames */
770 lagg_port_ifdetach(void *arg __unused, struct ifnet *ifp)
772 struct lagg_port *lp;
773 struct lagg_softc *sc;
775 if ((lp = ifp->if_lagg) == NULL)
781 lp->lp_detaching = 1;
782 lagg_port_destroy(lp, 1);
787 lagg_port2req(struct lagg_port *lp, struct lagg_reqport *rp)
789 struct lagg_softc *sc = lp->lp_softc;
791 strlcpy(rp->rp_ifname, sc->sc_ifname, sizeof(rp->rp_ifname));
792 strlcpy(rp->rp_portname, lp->lp_ifp->if_xname, sizeof(rp->rp_portname));
793 rp->rp_prio = lp->lp_prio;
794 rp->rp_flags = lp->lp_flags;
795 if (sc->sc_portreq != NULL)
796 (*sc->sc_portreq)(lp, (caddr_t)&rp->rp_psc);
798 /* Add protocol specific flags */
799 switch (sc->sc_proto) {
800 case LAGG_PROTO_FAILOVER:
801 if (lp == sc->sc_primary)
802 rp->rp_flags |= LAGG_PORT_MASTER;
803 if (lp == lagg_link_active(sc, sc->sc_primary))
804 rp->rp_flags |= LAGG_PORT_ACTIVE;
807 case LAGG_PROTO_ROUNDROBIN:
808 case LAGG_PROTO_LOADBALANCE:
809 case LAGG_PROTO_ETHERCHANNEL:
810 if (LAGG_PORTACTIVE(lp))
811 rp->rp_flags |= LAGG_PORT_ACTIVE;
814 case LAGG_PROTO_LACP:
815 /* LACP has a different definition of active */
816 if (lacp_isactive(lp))
817 rp->rp_flags |= LAGG_PORT_ACTIVE;
818 if (lacp_iscollecting(lp))
819 rp->rp_flags |= LAGG_PORT_COLLECTING;
820 if (lacp_isdistributing(lp))
821 rp->rp_flags |= LAGG_PORT_DISTRIBUTING;
830 struct lagg_softc *sc = (struct lagg_softc *)xsc;
831 struct lagg_port *lp;
832 struct ifnet *ifp = sc->sc_ifp;
834 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
839 ifp->if_drv_flags |= IFF_DRV_RUNNING;
840 /* Update the port lladdrs */
841 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
842 lagg_port_lladdr(lp, IF_LLADDR(ifp));
844 if (sc->sc_init != NULL)
851 lagg_stop(struct lagg_softc *sc)
853 struct ifnet *ifp = sc->sc_ifp;
855 LAGG_WLOCK_ASSERT(sc);
857 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
860 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
862 if (sc->sc_stop != NULL)
867 lagg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
869 struct lagg_softc *sc = (struct lagg_softc *)ifp->if_softc;
870 struct lagg_reqall *ra = (struct lagg_reqall *)data;
871 struct lagg_reqport *rp = (struct lagg_reqport *)data, rpbuf;
872 struct ifreq *ifr = (struct ifreq *)data;
873 struct lagg_port *lp;
875 struct thread *td = curthread;
877 int count, buflen, len, error = 0;
879 bzero(&rpbuf, sizeof(rpbuf));
885 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
887 buflen = count * sizeof(struct lagg_reqport);
890 outbuf = malloc(buflen, M_TEMP, M_WAITOK | M_ZERO);
893 ra->ra_proto = sc->sc_proto;
894 if (sc->sc_req != NULL)
895 (*sc->sc_req)(sc, (caddr_t)&ra->ra_psc);
899 len = min(ra->ra_size, buflen);
900 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
901 if (len < sizeof(rpbuf))
904 lagg_port2req(lp, &rpbuf);
905 memcpy(buf, &rpbuf, sizeof(rpbuf));
907 buf += sizeof(rpbuf);
908 len -= sizeof(rpbuf);
911 ra->ra_ports = count;
912 ra->ra_size = count * sizeof(rpbuf);
913 error = copyout(outbuf, ra->ra_port, ra->ra_size);
914 free(outbuf, M_TEMP);
917 error = priv_check(td, PRIV_NET_LAGG);
920 if (ra->ra_proto >= LAGG_PROTO_MAX) {
921 error = EPROTONOSUPPORT;
924 if (sc->sc_proto != LAGG_PROTO_NONE) {
926 error = sc->sc_detach(sc);
927 /* Reset protocol and pointers */
928 sc->sc_proto = LAGG_PROTO_NONE;
929 sc->sc_detach = NULL;
932 sc->sc_port_create = NULL;
933 sc->sc_port_destroy = NULL;
934 sc->sc_linkstate = NULL;
937 sc->sc_lladdr = NULL;
939 sc->sc_portreq = NULL;
944 for (int i = 0; i < (sizeof(lagg_protos) /
945 sizeof(lagg_protos[0])); i++) {
946 if (lagg_protos[i].ti_proto == ra->ra_proto) {
947 if (sc->sc_ifflags & IFF_DEBUG)
948 printf("%s: using proto %u\n",
950 lagg_protos[i].ti_proto);
952 sc->sc_proto = lagg_protos[i].ti_proto;
953 if (sc->sc_proto != LAGG_PROTO_NONE)
954 error = lagg_protos[i].ti_attach(sc);
959 error = EPROTONOSUPPORT;
962 if (rp->rp_portname[0] == '\0' ||
963 (tpif = ifunit(rp->rp_portname)) == NULL) {
969 if ((lp = (struct lagg_port *)tpif->if_lagg) == NULL ||
970 lp->lp_softc != sc) {
976 lagg_port2req(lp, rp);
980 error = priv_check(td, PRIV_NET_LAGG);
983 if (rp->rp_portname[0] == '\0' ||
984 (tpif = ifunit(rp->rp_portname)) == NULL) {
989 error = lagg_port_create(sc, tpif);
992 case SIOCSLAGGDELPORT:
993 error = priv_check(td, PRIV_NET_LAGG);
996 if (rp->rp_portname[0] == '\0' ||
997 (tpif = ifunit(rp->rp_portname)) == NULL) {
1003 if ((lp = (struct lagg_port *)tpif->if_lagg) == NULL ||
1004 lp->lp_softc != sc) {
1010 error = lagg_port_destroy(lp, 1);
1014 /* Set flags on ports too */
1016 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
1017 lagg_setflags(lp, 1);
1021 if (!(ifp->if_flags & IFF_UP) &&
1022 (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1024 * If interface is marked down and it is running,
1025 * then stop and disable it.
1030 } else if ((ifp->if_flags & IFF_UP) &&
1031 !(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1033 * If interface is marked up and it is stopped, then
1036 (*ifp->if_init)(sc);
1042 error = lagg_ether_setmulti(sc);
1047 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
1052 /* Do not allow the MTU or caps to be directly changed */
1057 error = ether_ioctl(ifp, cmd, data);
1064 lagg_ether_setmulti(struct lagg_softc *sc)
1066 struct lagg_port *lp;
1068 LAGG_WLOCK_ASSERT(sc);
1070 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
1071 /* First, remove any existing filter entries. */
1072 lagg_ether_cmdmulti(lp, 0);
1073 /* copy all addresses from the lagg interface to the port */
1074 lagg_ether_cmdmulti(lp, 1);
1080 lagg_ether_cmdmulti(struct lagg_port *lp, int set)
1082 struct lagg_softc *sc = lp->lp_softc;
1083 struct ifnet *ifp = lp->lp_ifp;
1084 struct ifnet *scifp = sc->sc_ifp;
1086 struct ifmultiaddr *ifma, *rifma = NULL;
1087 struct sockaddr_dl sdl;
1090 LAGG_WLOCK_ASSERT(sc);
1092 bzero((char *)&sdl, sizeof(sdl));
1093 sdl.sdl_len = sizeof(sdl);
1094 sdl.sdl_family = AF_LINK;
1095 sdl.sdl_type = IFT_ETHER;
1096 sdl.sdl_alen = ETHER_ADDR_LEN;
1097 sdl.sdl_index = ifp->if_index;
1100 TAILQ_FOREACH(ifma, &scifp->if_multiaddrs, ifma_link) {
1101 if (ifma->ifma_addr->sa_family != AF_LINK)
1103 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
1104 LLADDR(&sdl), ETHER_ADDR_LEN);
1106 error = if_addmulti(ifp, (struct sockaddr *)&sdl, &rifma);
1109 mc = malloc(sizeof(struct lagg_mc), M_DEVBUF, M_NOWAIT);
1112 mc->mc_ifma = rifma;
1113 SLIST_INSERT_HEAD(&lp->lp_mc_head, mc, mc_entries);
1116 while ((mc = SLIST_FIRST(&lp->lp_mc_head)) != NULL) {
1117 SLIST_REMOVE(&lp->lp_mc_head, mc, lagg_mc, mc_entries);
1118 if_delmulti_ifma(mc->mc_ifma);
1125 /* Handle a ref counted flag that should be set on the lagg port as well */
1127 lagg_setflag(struct lagg_port *lp, int flag, int status,
1128 int (*func)(struct ifnet *, int))
1130 struct lagg_softc *sc = lp->lp_softc;
1131 struct ifnet *scifp = sc->sc_ifp;
1132 struct ifnet *ifp = lp->lp_ifp;
1135 LAGG_WLOCK_ASSERT(sc);
1137 status = status ? (scifp->if_flags & flag) : 0;
1138 /* Now "status" contains the flag value or 0 */
1141 * See if recorded ports status is different from what
1142 * we want it to be. If it is, flip it. We record ports
1143 * status in lp_ifflags so that we won't clear ports flag
1144 * we haven't set. In fact, we don't clear or set ports
1145 * flags directly, but get or release references to them.
1146 * That's why we can be sure that recorded flags still are
1147 * in accord with actual ports flags.
1149 if (status != (lp->lp_ifflags & flag)) {
1150 error = (*func)(ifp, status);
1153 lp->lp_ifflags &= ~flag;
1154 lp->lp_ifflags |= status;
1160 * Handle IFF_* flags that require certain changes on the lagg port
1161 * if "status" is true, update ports flags respective to the lagg
1162 * if "status" is false, forcedly clear the flags set on port.
1165 lagg_setflags(struct lagg_port *lp, int status)
1169 for (i = 0; lagg_pflags[i].flag; i++) {
1170 error = lagg_setflag(lp, lagg_pflags[i].flag,
1171 status, lagg_pflags[i].func);
1179 lagg_start(struct ifnet *ifp)
1181 struct lagg_softc *sc = (struct lagg_softc *)ifp->if_softc;
1186 /* We need a Tx algorithm and at least one port */
1187 if (sc->sc_proto == LAGG_PROTO_NONE || sc->sc_count == 0) {
1188 IF_DRAIN(&ifp->if_snd);
1193 for (;; error = 0) {
1194 IFQ_DEQUEUE(&ifp->if_snd, m);
1198 ETHER_BPF_MTAP(ifp, m);
1200 error = (*sc->sc_start)(sc, m);
1209 static struct mbuf *
1210 lagg_input(struct ifnet *ifp, struct mbuf *m)
1212 struct lagg_port *lp = ifp->if_lagg;
1213 struct lagg_softc *sc = lp->lp_softc;
1214 struct ifnet *scifp = sc->sc_ifp;
1216 if ((scifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
1217 (lp->lp_flags & LAGG_PORT_DISABLED) ||
1218 sc->sc_proto == LAGG_PROTO_NONE) {
1224 ETHER_BPF_MTAP(scifp, m);
1226 m = (*sc->sc_input)(sc, lp, m);
1229 scifp->if_ipackets++;
1230 scifp->if_ibytes += m->m_pkthdr.len;
1232 if (scifp->if_flags & IFF_MONITOR) {
1243 lagg_media_change(struct ifnet *ifp)
1245 struct lagg_softc *sc = (struct lagg_softc *)ifp->if_softc;
1247 if (sc->sc_ifflags & IFF_DEBUG)
1248 printf("%s\n", __func__);
1255 lagg_media_status(struct ifnet *ifp, struct ifmediareq *imr)
1257 struct lagg_softc *sc = (struct lagg_softc *)ifp->if_softc;
1258 struct lagg_port *lp;
1260 imr->ifm_status = IFM_AVALID;
1261 imr->ifm_active = IFM_ETHER | IFM_AUTO;
1264 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
1265 if (LAGG_PORTACTIVE(lp))
1266 imr->ifm_status |= IFM_ACTIVE;
1272 lagg_linkstate(struct lagg_softc *sc)
1274 struct lagg_port *lp;
1275 int new_link = LINK_STATE_DOWN;
1278 /* Our link is considered up if at least one of our ports is active */
1279 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
1280 if (lp->lp_link_state == LINK_STATE_UP) {
1281 new_link = LINK_STATE_UP;
1285 if_link_state_change(sc->sc_ifp, new_link);
1287 /* Update if_baudrate to reflect the max possible speed */
1288 switch (sc->sc_proto) {
1289 case LAGG_PROTO_FAILOVER:
1290 sc->sc_ifp->if_baudrate = sc->sc_primary != NULL ?
1291 sc->sc_primary->lp_ifp->if_baudrate : 0;
1293 case LAGG_PROTO_ROUNDROBIN:
1294 case LAGG_PROTO_LOADBALANCE:
1295 case LAGG_PROTO_ETHERCHANNEL:
1297 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
1298 speed += lp->lp_ifp->if_baudrate;
1299 sc->sc_ifp->if_baudrate = speed;
1301 case LAGG_PROTO_LACP:
1302 /* LACP updates if_baudrate itself */
1308 lagg_port_state(struct ifnet *ifp, int state)
1310 struct lagg_port *lp = (struct lagg_port *)ifp->if_lagg;
1311 struct lagg_softc *sc = NULL;
1320 if (sc->sc_linkstate != NULL)
1321 (*sc->sc_linkstate)(lp);
1326 lagg_link_active(struct lagg_softc *sc, struct lagg_port *lp)
1328 struct lagg_port *lp_next, *rval = NULL;
1329 // int new_link = LINK_STATE_DOWN;
1331 LAGG_RLOCK_ASSERT(sc);
1333 * Search a port which reports an active link state.
1338 if (LAGG_PORTACTIVE(lp)) {
1342 if ((lp_next = SLIST_NEXT(lp, lp_entries)) != NULL &&
1343 LAGG_PORTACTIVE(lp_next)) {
1349 SLIST_FOREACH(lp_next, &sc->sc_ports, lp_entries) {
1350 if (LAGG_PORTACTIVE(lp_next)) {
1359 * The IEEE 802.1D standard assumes that a lagg with
1360 * multiple ports is always full duplex. This is valid
1361 * for load sharing laggs and if at least two links
1362 * are active. Unfortunately, checking the latter would
1363 * be too expensive at this point.
1365 if ((sc->sc_capabilities & IFCAP_LAGG_FULLDUPLEX) &&
1367 new_link = LINK_STATE_FULL_DUPLEX;
1369 new_link = rval->lp_link_state;
1377 lagg_gethdr(struct mbuf *m, u_int off, u_int len, void *buf)
1379 if (m->m_pkthdr.len < (off + len)) {
1381 } else if (m->m_len < (off + len)) {
1382 m_copydata(m, off, len, buf);
1385 return (mtod(m, char *) + off);
1389 lagg_hashmbuf(struct mbuf *m, uint32_t key)
1394 struct ether_header *eh;
1395 struct ether_vlan_header vlanbuf;
1396 const struct ether_vlan_header *vlan;
1398 const struct ip *ip;
1402 const struct ip6_hdr *ip6;
1403 struct ip6_hdr ip6buf;
1410 eh = mtod(m, struct ether_header *);
1411 etype = ntohs(eh->ether_type);
1412 p = hash32_buf(&eh->ether_shost, ETHER_ADDR_LEN, key);
1413 p = hash32_buf(&eh->ether_dhost, ETHER_ADDR_LEN, p);
1415 /* Special handling for encapsulating VLAN frames */
1416 if (m->m_flags & M_VLANTAG) {
1417 p = hash32_buf(&m->m_pkthdr.ether_vtag,
1418 sizeof(m->m_pkthdr.ether_vtag), p);
1419 } else if (etype == ETHERTYPE_VLAN) {
1420 vlan = lagg_gethdr(m, off, sizeof(*vlan), &vlanbuf);
1424 p = hash32_buf(&vlan->evl_tag, sizeof(vlan->evl_tag), p);
1425 etype = ntohs(vlan->evl_proto);
1426 off += sizeof(*vlan) - sizeof(*eh);
1432 ip = lagg_gethdr(m, off, sizeof(*ip), &ipbuf);
1436 p = hash32_buf(&ip->ip_src, sizeof(struct in_addr), p);
1437 p = hash32_buf(&ip->ip_dst, sizeof(struct in_addr), p);
1441 case ETHERTYPE_IPV6:
1442 ip6 = lagg_gethdr(m, off, sizeof(*ip6), &ip6buf);
1446 p = hash32_buf(&ip6->ip6_src, sizeof(struct in6_addr), p);
1447 p = hash32_buf(&ip6->ip6_dst, sizeof(struct in6_addr), p);
1448 flow = ip6->ip6_flow & IPV6_FLOWLABEL_MASK;
1449 p = hash32_buf(&flow, sizeof(flow), p); /* IPv6 flow label */
1458 lagg_enqueue(struct ifnet *ifp, struct mbuf *m)
1461 return (ifp->if_transmit)(ifp, m);
1465 * Simple round robin aggregation
1469 lagg_rr_attach(struct lagg_softc *sc)
1471 sc->sc_detach = lagg_rr_detach;
1472 sc->sc_start = lagg_rr_start;
1473 sc->sc_input = lagg_rr_input;
1474 sc->sc_port_create = NULL;
1475 sc->sc_capabilities = IFCAP_LAGG_FULLDUPLEX;
1482 lagg_rr_detach(struct lagg_softc *sc)
1488 lagg_rr_start(struct lagg_softc *sc, struct mbuf *m)
1490 struct lagg_port *lp;
1493 p = atomic_fetchadd_32(&sc->sc_seq, 1);
1495 lp = SLIST_FIRST(&sc->sc_ports);
1497 lp = SLIST_NEXT(lp, lp_entries);
1500 * Check the port's link state. This will return the next active
1501 * port if the link is down or the port is NULL.
1503 if ((lp = lagg_link_active(sc, lp)) == NULL) {
1509 return (lagg_enqueue(lp->lp_ifp, m));
1512 static struct mbuf *
1513 lagg_rr_input(struct lagg_softc *sc, struct lagg_port *lp, struct mbuf *m)
1515 struct ifnet *ifp = sc->sc_ifp;
1517 /* Just pass in the packet to our lagg device */
1518 m->m_pkthdr.rcvif = ifp;
1528 lagg_fail_attach(struct lagg_softc *sc)
1530 sc->sc_detach = lagg_fail_detach;
1531 sc->sc_start = lagg_fail_start;
1532 sc->sc_input = lagg_fail_input;
1533 sc->sc_port_create = NULL;
1534 sc->sc_port_destroy = NULL;
1540 lagg_fail_detach(struct lagg_softc *sc)
1546 lagg_fail_start(struct lagg_softc *sc, struct mbuf *m)
1548 struct lagg_port *lp;
1550 /* Use the master port if active or the next available port */
1551 if ((lp = lagg_link_active(sc, sc->sc_primary)) == NULL) {
1557 return (lagg_enqueue(lp->lp_ifp, m));
1560 static struct mbuf *
1561 lagg_fail_input(struct lagg_softc *sc, struct lagg_port *lp, struct mbuf *m)
1563 struct ifnet *ifp = sc->sc_ifp;
1564 struct lagg_port *tmp_tp;
1566 if (lp == sc->sc_primary || lagg_failover_rx_all) {
1567 m->m_pkthdr.rcvif = ifp;
1571 if (!LAGG_PORTACTIVE(sc->sc_primary)) {
1572 tmp_tp = lagg_link_active(sc, sc->sc_primary);
1574 * If tmp_tp is null, we've recieved a packet when all
1575 * our links are down. Weird, but process it anyways.
1577 if ((tmp_tp == NULL || tmp_tp == lp)) {
1578 m->m_pkthdr.rcvif = ifp;
1592 lagg_lb_attach(struct lagg_softc *sc)
1594 struct lagg_port *lp;
1597 if ((lb = (struct lagg_lb *)malloc(sizeof(struct lagg_lb),
1598 M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
1601 sc->sc_detach = lagg_lb_detach;
1602 sc->sc_start = lagg_lb_start;
1603 sc->sc_input = lagg_lb_input;
1604 sc->sc_port_create = lagg_lb_port_create;
1605 sc->sc_port_destroy = lagg_lb_port_destroy;
1606 sc->sc_capabilities = IFCAP_LAGG_FULLDUPLEX;
1608 lb->lb_key = arc4random();
1609 sc->sc_psc = (caddr_t)lb;
1611 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
1612 lagg_lb_port_create(lp);
1618 lagg_lb_detach(struct lagg_softc *sc)
1620 struct lagg_lb *lb = (struct lagg_lb *)sc->sc_psc;
1627 lagg_lb_porttable(struct lagg_softc *sc, struct lagg_port *lp)
1629 struct lagg_lb *lb = (struct lagg_lb *)sc->sc_psc;
1630 struct lagg_port *lp_next;
1633 bzero(&lb->lb_ports, sizeof(lb->lb_ports));
1634 SLIST_FOREACH(lp_next, &sc->sc_ports, lp_entries) {
1637 if (i >= LAGG_MAX_PORTS)
1639 if (sc->sc_ifflags & IFF_DEBUG)
1640 printf("%s: port %s at index %d\n",
1641 sc->sc_ifname, lp_next->lp_ifname, i);
1642 lb->lb_ports[i++] = lp_next;
1649 lagg_lb_port_create(struct lagg_port *lp)
1651 struct lagg_softc *sc = lp->lp_softc;
1652 return (lagg_lb_porttable(sc, NULL));
1656 lagg_lb_port_destroy(struct lagg_port *lp)
1658 struct lagg_softc *sc = lp->lp_softc;
1659 lagg_lb_porttable(sc, lp);
1663 lagg_lb_start(struct lagg_softc *sc, struct mbuf *m)
1665 struct lagg_lb *lb = (struct lagg_lb *)sc->sc_psc;
1666 struct lagg_port *lp = NULL;
1669 if (m->m_flags & M_FLOWID)
1670 p = m->m_pkthdr.flowid;
1672 p = lagg_hashmbuf(m, lb->lb_key);
1674 lp = lb->lb_ports[p];
1677 * Check the port's link state. This will return the next active
1678 * port if the link is down or the port is NULL.
1680 if ((lp = lagg_link_active(sc, lp)) == NULL) {
1686 return (lagg_enqueue(lp->lp_ifp, m));
1689 static struct mbuf *
1690 lagg_lb_input(struct lagg_softc *sc, struct lagg_port *lp, struct mbuf *m)
1692 struct ifnet *ifp = sc->sc_ifp;
1694 /* Just pass in the packet to our lagg device */
1695 m->m_pkthdr.rcvif = ifp;
1705 lagg_lacp_attach(struct lagg_softc *sc)
1707 struct lagg_port *lp;
1710 sc->sc_detach = lagg_lacp_detach;
1711 sc->sc_port_create = lacp_port_create;
1712 sc->sc_port_destroy = lacp_port_destroy;
1713 sc->sc_linkstate = lacp_linkstate;
1714 sc->sc_start = lagg_lacp_start;
1715 sc->sc_input = lagg_lacp_input;
1716 sc->sc_init = lacp_init;
1717 sc->sc_stop = lacp_stop;
1718 sc->sc_lladdr = lagg_lacp_lladdr;
1719 sc->sc_req = lacp_req;
1720 sc->sc_portreq = lacp_portreq;
1722 error = lacp_attach(sc);
1726 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
1727 lacp_port_create(lp);
1733 lagg_lacp_detach(struct lagg_softc *sc)
1735 struct lagg_port *lp;
1738 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
1739 lacp_port_destroy(lp);
1741 /* unlocking is safe here */
1743 error = lacp_detach(sc);
1750 lagg_lacp_lladdr(struct lagg_softc *sc)
1752 struct lagg_port *lp;
1754 /* purge all the lacp ports */
1755 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
1756 lacp_port_destroy(lp);
1758 /* add them back in */
1759 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries)
1760 lacp_port_create(lp);
1764 lagg_lacp_start(struct lagg_softc *sc, struct mbuf *m)
1766 struct lagg_port *lp;
1768 lp = lacp_select_tx_port(sc, m);
1775 return (lagg_enqueue(lp->lp_ifp, m));
1778 static struct mbuf *
1779 lagg_lacp_input(struct lagg_softc *sc, struct lagg_port *lp, struct mbuf *m)
1781 struct ifnet *ifp = sc->sc_ifp;
1782 struct ether_header *eh;
1785 eh = mtod(m, struct ether_header *);
1786 etype = ntohs(eh->ether_type);
1788 /* Tap off LACP control messages */
1789 if (etype == ETHERTYPE_SLOW) {
1790 m = lacp_input(lp, m);
1796 * If the port is not collecting or not in the active aggregator then
1799 if (lacp_iscollecting(lp) == 0 || lacp_isactive(lp) == 0) {
1804 m->m_pkthdr.rcvif = ifp;