if_lagg.h revision 169328
1/* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */ 2 3/* 4 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 * $FreeBSD: head/sys/net/if_lagg.h 169328 2007-05-07 00:28:55Z thompsa $ 19 */ 20 21#ifndef _NET_LAGG_H 22#define _NET_LAGG_H 23 24/* 25 * Global definitions 26 */ 27 28#define LAGG_MAX_PORTS 32 /* logically */ 29#define LAGG_MAX_NAMESIZE 32 /* name of a protocol */ 30#define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */ 31 32/* Port flags */ 33#define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */ 34#define LAGG_PORT_MASTER 0x00000001 /* primary port */ 35#define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */ 36#define LAGG_PORT_ACTIVE 0x00000004 /* port is active */ 37#define LAGG_PORT_COLLECTING 0x00000008 /* port is receiving frames */ 38#define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */ 39#define LAGG_PORT_DISABLED 0x00000020 /* port is disabled */ 40#define LAGG_PORT_GLOBAL 0x80000000 /* IOCTL: global flag */ 41#define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \ 42 "\05DISTRIBUTING\06DISABLED" 43 44/* Supported lagg PROTOs */ 45#define LAGG_PROTO_NONE 0 /* no lagg protocol defined */ 46#define LAGG_PROTO_ROUNDROBIN 1 /* simple round robin */ 47#define LAGG_PROTO_FAILOVER 2 /* active failover */ 48#define LAGG_PROTO_LOADBALANCE 3 /* loadbalance */ 49#define LAGG_PROTO_LACP 4 /* 802.3ad lacp */ 50#define LAGG_PROTO_ETHERCHANNEL 5 /* Cisco FEC */ 51#define LAGG_PROTO_MAX 6 52 53struct lagg_protos { 54 const char *tpr_name; 55 int tpr_proto; 56}; 57 58#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 59#define LAGG_PROTOS { \ 60 { "failover", LAGG_PROTO_FAILOVER }, \ 61 { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 62 { "lacp", LAGG_PROTO_LACP }, \ 63 { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 64 { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 65 { "none", LAGG_PROTO_NONE }, \ 66 { "default", LAGG_PROTO_DEFAULT } \ 67} 68 69/* 70 * lagg ioctls. 71 */ 72 73/* lagg port settings */ 74struct lagg_reqport { 75 char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 76 char rp_portname[IFNAMSIZ]; /* name of the port */ 77 u_int32_t rp_prio; /* port priority */ 78 u_int32_t rp_flags; /* port flags */ 79}; 80 81#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 82#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 83#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 84 85/* lagg, ports and options */ 86struct lagg_reqall { 87 char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 88 u_int ra_proto; /* lagg protocol */ 89 90 size_t ra_size; /* size of buffer */ 91 struct lagg_reqport *ra_port; /* allocated buffer */ 92 int ra_ports; /* total port count */ 93}; 94 95#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 96#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 97 98#ifdef _KERNEL 99/* 100 * Internal kernel part 101 */ 102 103#define lp_ifname lp_ifp->if_xname /* interface name */ 104#define lp_link_state lp_ifp->if_link_state /* link state */ 105#define lp_capabilities lp_ifp->if_capabilities /* capabilities */ 106 107#define LAGG_PORTACTIVE(_tp) ( \ 108 ((_tp)->lp_link_state == LINK_STATE_UP) && \ 109 ((_tp)->lp_ifp->if_flags & IFF_UP) \ 110) 111 112#define mc_enm mc_u.mcu_enm 113 114struct lagg_ifreq { 115 union { 116 struct ifreq ifreq; 117 struct { 118 char ifr_name[IFNAMSIZ]; 119 struct sockaddr_storage ifr_ss; 120 } ifreq_storage; 121 } ifreq; 122}; 123 124#define sc_ifflags sc_ifp->if_flags /* flags */ 125#define sc_ifname sc_ifp->if_xname /* name */ 126#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 127 128#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 129#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 130 131/* Private data used by the loadbalancing protocol */ 132#define LAGG_LB_MAXKEYS 8 133struct lagg_lb { 134 u_int32_t lb_key; 135 struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 136}; 137 138struct lagg_mc { 139 struct ifmultiaddr *mc_ifma; 140 SLIST_ENTRY(lagg_mc) mc_entries; 141}; 142 143struct lagg_softc { 144 struct ifnet *sc_ifp; /* virtual interface */ 145 struct mtx sc_mtx; 146 int sc_proto; /* lagg protocol */ 147 u_int sc_count; /* number of ports */ 148 struct lagg_port *sc_primary; /* primary port */ 149 struct ifmedia sc_media; /* media config */ 150 caddr_t sc_psc; /* protocol data */ 151 152 SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 153 SLIST_ENTRY(lagg_softc) sc_entries; 154 155 /* lagg protocol callbacks */ 156 int (*sc_detach)(struct lagg_softc *); 157 int (*sc_start)(struct lagg_softc *, struct mbuf *); 158 struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *, 159 struct mbuf *); 160 int (*sc_port_create)(struct lagg_port *); 161 void (*sc_port_destroy)(struct lagg_port *); 162 void (*sc_linkstate)(struct lagg_port *); 163 void (*sc_init)(struct lagg_softc *); 164 void (*sc_stop)(struct lagg_softc *); 165 void (*sc_lladdr)(struct lagg_softc *); 166}; 167 168struct lagg_port { 169 struct ifnet *lp_ifp; /* physical interface */ 170 struct lagg_softc *lp_lagg; /* parent lagg */ 171 uint8_t lp_lladdr[ETHER_ADDR_LEN]; 172 173 u_char lp_iftype; /* interface type */ 174 uint32_t lp_prio; /* port priority */ 175 uint32_t lp_flags; /* port flags */ 176 int lp_ifflags; /* saved ifp flags */ 177 void *lh_cookie; /* if state hook */ 178 caddr_t lp_psc; /* protocol data */ 179 int lp_detaching; /* ifnet is detaching */ 180 181 SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 182 183 /* Redirected callbacks */ 184 int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 185 int (*lp_output)(struct ifnet *, struct mbuf *, struct sockaddr *, 186 struct rtentry *); 187 188 SLIST_ENTRY(lagg_port) lp_entries; 189}; 190 191#define LAGG_LOCK_INIT(_tr) mtx_init(&(_tr)->sc_mtx, "if_lagg", NULL, \ 192 MTX_DEF) 193#define LAGG_LOCK_DESTROY(_tr) mtx_destroy(&(_tr)->sc_mtx) 194#define LAGG_LOCK(_tr) mtx_lock(&(_tr)->sc_mtx) 195#define LAGG_UNLOCK(_tr) mtx_unlock(&(_tr)->sc_mtx) 196#define LAGG_LOCKED(_tr) mtx_owned(&(_tr)->sc_mtx) 197#define LAGG_LOCK_ASSERT(_tr) mtx_assert(&(_tr)->sc_mtx, MA_OWNED) 198 199extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 200extern void (*lagg_linkstate_p)(struct ifnet *, int ); 201 202int lagg_enqueue(struct ifnet *, struct mbuf *); 203uint32_t lagg_hashmbuf(struct mbuf *, uint32_t); 204 205#endif /* _KERNEL */ 206 207#endif /* _NET_LAGG_H */ 208