if_lagg.c (8a73c85db358c0975599e79648a13b212c3d3180) if_lagg.c (f3e7afe2d7b262ab55ab818445d4dfdb6e0c70a9)
1/* $OpenBSD: if_trunk.c,v 1.30 2007/01/31 06:20:19 reyk Exp $ */
2
3/*
4 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
5 * Copyright (c) 2007 Andrew Thompson <thompsa@FreeBSD.org>
6 * Copyright (c) 2014, 2016 Marcelo Araujo <araujo@FreeBSD.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any

--- 9 unchanged lines hidden (view full) ---

18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21#include <sys/cdefs.h>
22__FBSDID("$FreeBSD$");
23
24#include "opt_inet.h"
25#include "opt_inet6.h"
1/* $OpenBSD: if_trunk.c,v 1.30 2007/01/31 06:20:19 reyk Exp $ */
2
3/*
4 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
5 * Copyright (c) 2007 Andrew Thompson <thompsa@FreeBSD.org>
6 * Copyright (c) 2014, 2016 Marcelo Araujo <araujo@FreeBSD.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any

--- 9 unchanged lines hidden (view full) ---

18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21#include <sys/cdefs.h>
22__FBSDID("$FreeBSD$");
23
24#include "opt_inet.h"
25#include "opt_inet6.h"
26#include "opt_ratelimit.h"
26
27#include <sys/param.h>
28#include <sys/kernel.h>
29#include <sys/malloc.h>
30#include <sys/mbuf.h>
31#include <sys/queue.h>
32#include <sys/socket.h>
33#include <sys/sockio.h>

--- 79 unchanged lines hidden (view full) ---

113static void lagg_port_ifdetach(void *arg __unused, struct ifnet *);
114#ifdef LAGG_PORT_STACKING
115static int lagg_port_checkstacking(struct lagg_softc *);
116#endif
117static void lagg_port2req(struct lagg_port *, struct lagg_reqport *);
118static void lagg_init(void *);
119static void lagg_stop(struct lagg_softc *);
120static int lagg_ioctl(struct ifnet *, u_long, caddr_t);
27
28#include <sys/param.h>
29#include <sys/kernel.h>
30#include <sys/malloc.h>
31#include <sys/mbuf.h>
32#include <sys/queue.h>
33#include <sys/socket.h>
34#include <sys/sockio.h>

--- 79 unchanged lines hidden (view full) ---

114static void lagg_port_ifdetach(void *arg __unused, struct ifnet *);
115#ifdef LAGG_PORT_STACKING
116static int lagg_port_checkstacking(struct lagg_softc *);
117#endif
118static void lagg_port2req(struct lagg_port *, struct lagg_reqport *);
119static void lagg_init(void *);
120static void lagg_stop(struct lagg_softc *);
121static int lagg_ioctl(struct ifnet *, u_long, caddr_t);
122#ifdef RATELIMIT
123static int lagg_snd_tag_alloc(struct ifnet *,
124 union if_snd_tag_alloc_params *,
125 struct m_snd_tag **);
126#endif
121static int lagg_ether_setmulti(struct lagg_softc *);
122static int lagg_ether_cmdmulti(struct lagg_port *, int);
123static int lagg_setflag(struct lagg_port *, int, int,
124 int (*func)(struct ifnet *, int));
125static int lagg_setflags(struct lagg_port *, int status);
126static uint64_t lagg_get_counter(struct ifnet *ifp, ift_counter cnt);
127static int lagg_transmit(struct ifnet *, struct mbuf *);
128static void lagg_qflush(struct ifnet *);

--- 369 unchanged lines hidden (view full) ---

498 if_initname(ifp, laggname, unit);
499 ifp->if_softc = sc;
500 ifp->if_transmit = lagg_transmit;
501 ifp->if_qflush = lagg_qflush;
502 ifp->if_init = lagg_init;
503 ifp->if_ioctl = lagg_ioctl;
504 ifp->if_get_counter = lagg_get_counter;
505 ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
127static int lagg_ether_setmulti(struct lagg_softc *);
128static int lagg_ether_cmdmulti(struct lagg_port *, int);
129static int lagg_setflag(struct lagg_port *, int, int,
130 int (*func)(struct ifnet *, int));
131static int lagg_setflags(struct lagg_port *, int status);
132static uint64_t lagg_get_counter(struct ifnet *ifp, ift_counter cnt);
133static int lagg_transmit(struct ifnet *, struct mbuf *);
134static void lagg_qflush(struct ifnet *);

--- 369 unchanged lines hidden (view full) ---

504 if_initname(ifp, laggname, unit);
505 ifp->if_softc = sc;
506 ifp->if_transmit = lagg_transmit;
507 ifp->if_qflush = lagg_qflush;
508 ifp->if_init = lagg_init;
509 ifp->if_ioctl = lagg_ioctl;
510 ifp->if_get_counter = lagg_get_counter;
511 ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
512#ifdef RATELIMIT
513 ifp->if_snd_tag_alloc = lagg_snd_tag_alloc;
514 ifp->if_capenable = ifp->if_capabilities = IFCAP_HWSTATS | IFCAP_TXRTLMT;
515#else
506 ifp->if_capenable = ifp->if_capabilities = IFCAP_HWSTATS;
516 ifp->if_capenable = ifp->if_capabilities = IFCAP_HWSTATS;
517#endif
507
508 /*
509 * Attach as an ordinary ethernet device, children will be attached
510 * as special device IFT_IEEE8023ADLAG.
511 */
512 ether_ifattach(ifp, eaddr);
513
514 sc->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,

--- 1029 unchanged lines hidden (view full) ---

1544
1545 default:
1546 error = ether_ioctl(ifp, cmd, data);
1547 break;
1548 }
1549 return (error);
1550}
1551
518
519 /*
520 * Attach as an ordinary ethernet device, children will be attached
521 * as special device IFT_IEEE8023ADLAG.
522 */
523 ether_ifattach(ifp, eaddr);
524
525 sc->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,

--- 1029 unchanged lines hidden (view full) ---

1555
1556 default:
1557 error = ether_ioctl(ifp, cmd, data);
1558 break;
1559 }
1560 return (error);
1561}
1562
1563#ifdef RATELIMIT
1552static int
1564static int
1565lagg_snd_tag_alloc(struct ifnet *ifp,
1566 union if_snd_tag_alloc_params *params,
1567 struct m_snd_tag **ppmt)
1568{
1569 struct lagg_softc *sc = (struct lagg_softc *)ifp->if_softc;
1570 struct lagg_port *lp;
1571 struct lagg_lb *lb;
1572 uint32_t p;
1573
1574 switch (sc->sc_proto) {
1575 case LAGG_PROTO_FAILOVER:
1576 lp = lagg_link_active(sc, sc->sc_primary);
1577 break;
1578 case LAGG_PROTO_LOADBALANCE:
1579 if ((sc->sc_opts & LAGG_OPT_USE_FLOWID) == 0 ||
1580 params->hdr.flowtype == M_HASHTYPE_NONE)
1581 return (EOPNOTSUPP);
1582 p = params->hdr.flowid >> sc->flowid_shift;
1583 p %= sc->sc_count;
1584 lb = (struct lagg_lb *)sc->sc_psc;
1585 lp = lb->lb_ports[p];
1586 lp = lagg_link_active(sc, lp);
1587 break;
1588 case LAGG_PROTO_LACP:
1589 if ((sc->sc_opts & LAGG_OPT_USE_FLOWID) == 0 ||
1590 params->hdr.flowtype == M_HASHTYPE_NONE)
1591 return (EOPNOTSUPP);
1592 lp = lacp_select_tx_port_by_hash(sc, params->hdr.flowid);
1593 break;
1594 default:
1595 return (EOPNOTSUPP);
1596 }
1597 if (lp == NULL)
1598 return (EOPNOTSUPP);
1599 ifp = lp->lp_ifp;
1600 if (ifp == NULL || ifp->if_snd_tag_alloc == NULL ||
1601 (ifp->if_capenable & IFCAP_TXRTLMT) == 0)
1602 return (EOPNOTSUPP);
1603
1604 /* forward allocation request */
1605 return (ifp->if_snd_tag_alloc(ifp, params, ppmt));
1606}
1607#endif
1608
1609static int
1553lagg_ether_setmulti(struct lagg_softc *sc)
1554{
1555 struct lagg_port *lp;
1556
1557 LAGG_WLOCK_ASSERT(sc);
1558
1559 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
1560 /* First, remove any existing filter entries. */

--- 680 unchanged lines hidden ---
1610lagg_ether_setmulti(struct lagg_softc *sc)
1611{
1612 struct lagg_port *lp;
1613
1614 LAGG_WLOCK_ASSERT(sc);
1615
1616 SLIST_FOREACH(lp, &sc->sc_ports, lp_entries) {
1617 /* First, remove any existing filter entries. */

--- 680 unchanged lines hidden ---