1*9eb35c73Smpf /* $OpenBSD: trunklacp.h,v 1.2 2008/06/15 19:00:57 mpf Exp $ */ 2a14b8f16Smpf /* $NetBSD: ieee8023ad_impl.h,v 1.2 2005/12/10 23:21:39 elad Exp $ */ 3a14b8f16Smpf 4a14b8f16Smpf /* 5a14b8f16Smpf * Copyright (c)2005 YAMAMOTO Takashi, 6a14b8f16Smpf * All rights reserved. 7a14b8f16Smpf * 8a14b8f16Smpf * Redistribution and use in source and binary forms, with or without 9a14b8f16Smpf * modification, are permitted provided that the following conditions 10a14b8f16Smpf * are met: 11a14b8f16Smpf * 1. Redistributions of source code must retain the above copyright 12a14b8f16Smpf * notice, this list of conditions and the following disclaimer. 13a14b8f16Smpf * 2. Redistributions in binary form must reproduce the above copyright 14a14b8f16Smpf * notice, this list of conditions and the following disclaimer in the 15a14b8f16Smpf * documentation and/or other materials provided with the distribution. 16a14b8f16Smpf * 17a14b8f16Smpf * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18a14b8f16Smpf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19a14b8f16Smpf * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20a14b8f16Smpf * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21a14b8f16Smpf * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22a14b8f16Smpf * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23a14b8f16Smpf * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24a14b8f16Smpf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25a14b8f16Smpf * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26a14b8f16Smpf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27a14b8f16Smpf * SUCH DAMAGE. 28a14b8f16Smpf * 29a14b8f16Smpf * $FreeBSD: src/sys/net/ieee8023ad_lacp.h,v 1.11 2008/03/17 01:26:44 thompsa Exp $ 30a14b8f16Smpf */ 31a14b8f16Smpf 32a14b8f16Smpf /* 33a14b8f16Smpf * IEEE802.3ad LACP 34a14b8f16Smpf * 35a14b8f16Smpf * implementation details. 36a14b8f16Smpf */ 37a14b8f16Smpf 38a14b8f16Smpf #define LACP_TIMER_CURRENT_WHILE 0 39a14b8f16Smpf #define LACP_TIMER_PERIODIC 1 40a14b8f16Smpf #define LACP_TIMER_WAIT_WHILE 2 41a14b8f16Smpf #define LACP_NTIMER 3 42a14b8f16Smpf 43a14b8f16Smpf #define LACP_TIMER_ARM(port, timer, val) \ 44a14b8f16Smpf (port)->lp_timer[(timer)] = (val) 45a14b8f16Smpf #define LACP_TIMER_DISARM(port, timer) \ 46a14b8f16Smpf (port)->lp_timer[(timer)] = 0 47a14b8f16Smpf #define LACP_TIMER_ISARMED(port, timer) \ 48a14b8f16Smpf ((port)->lp_timer[(timer)] > 0) 49a14b8f16Smpf 50a14b8f16Smpf /* 51a14b8f16Smpf * IEEE802.3ad LACP 52a14b8f16Smpf * 53a14b8f16Smpf * protocol definitions. 54a14b8f16Smpf */ 55a14b8f16Smpf 56a14b8f16Smpf #define LACP_STATE_ACTIVITY (1<<0) 57a14b8f16Smpf #define LACP_STATE_TIMEOUT (1<<1) 58a14b8f16Smpf #define LACP_STATE_AGGREGATION (1<<2) 59a14b8f16Smpf #define LACP_STATE_SYNC (1<<3) 60a14b8f16Smpf #define LACP_STATE_COLLECTING (1<<4) 61a14b8f16Smpf #define LACP_STATE_DISTRIBUTING (1<<5) 62a14b8f16Smpf #define LACP_STATE_DEFAULTED (1<<6) 63a14b8f16Smpf #define LACP_STATE_EXPIRED (1<<7) 64a14b8f16Smpf 65a14b8f16Smpf #define LACP_PORT_NTT 0x00000001 66a14b8f16Smpf #define LACP_PORT_MARK 0x00000002 67a14b8f16Smpf 68a14b8f16Smpf #define LACP_STATE_BITS \ 69a14b8f16Smpf "\020" \ 70a14b8f16Smpf "\001ACTIVITY" \ 71a14b8f16Smpf "\002TIMEOUT" \ 72a14b8f16Smpf "\003AGGREGATION" \ 73a14b8f16Smpf "\004SYNC" \ 74a14b8f16Smpf "\005COLLECTING" \ 75a14b8f16Smpf "\006DISTRIBUTING" \ 76a14b8f16Smpf "\007DEFAULTED" \ 77a14b8f16Smpf "\010EXPIRED" 78a14b8f16Smpf 79a14b8f16Smpf /* 80a14b8f16Smpf * IEEE802.3 slow protocols 81a14b8f16Smpf * 82a14b8f16Smpf * protocol (on-wire) definitions. 83a14b8f16Smpf * 84a14b8f16Smpf * XXX should be elsewhere. 85a14b8f16Smpf */ 86a14b8f16Smpf 87a14b8f16Smpf #define SLOWPROTOCOLS_SUBTYPE_LACP 1 88a14b8f16Smpf #define SLOWPROTOCOLS_SUBTYPE_MARKER 2 89a14b8f16Smpf 90a14b8f16Smpf struct slowprothdr { 91*9eb35c73Smpf u_int8_t sph_subtype; 92*9eb35c73Smpf u_int8_t sph_version; 93a14b8f16Smpf } __packed; 94a14b8f16Smpf 95a14b8f16Smpf /* 96a14b8f16Smpf * TLV on-wire structure. 97a14b8f16Smpf */ 98a14b8f16Smpf 99a14b8f16Smpf struct tlvhdr { 100*9eb35c73Smpf u_int8_t tlv_type; 101*9eb35c73Smpf u_int8_t tlv_length; 102*9eb35c73Smpf /* u_int8_t tlv_value[]; */ 103a14b8f16Smpf } __packed; 104a14b8f16Smpf 105a14b8f16Smpf /* 106a14b8f16Smpf * ... and our implementation. 107a14b8f16Smpf */ 108a14b8f16Smpf 109a14b8f16Smpf #define TLV_SET(tlv, type, length) \ 110a14b8f16Smpf do { \ 111a14b8f16Smpf (tlv)->tlv_type = (type); \ 112a14b8f16Smpf (tlv)->tlv_length = sizeof(*tlv) + (length); \ 113a14b8f16Smpf } while (/*CONSTCOND*/0) 114a14b8f16Smpf 115a14b8f16Smpf struct tlv_template { 116*9eb35c73Smpf u_int8_t tmpl_type; 117*9eb35c73Smpf u_int8_t tmpl_length; 118a14b8f16Smpf }; 119a14b8f16Smpf 120a14b8f16Smpf struct lacp_systemid { 121*9eb35c73Smpf u_int16_t lsi_prio; 122*9eb35c73Smpf u_int8_t lsi_mac[6]; 123a14b8f16Smpf } __packed; 124a14b8f16Smpf 125a14b8f16Smpf struct lacp_portid { 126*9eb35c73Smpf u_int16_t lpi_prio; 127*9eb35c73Smpf u_int16_t lpi_portno; 128a14b8f16Smpf } __packed; 129a14b8f16Smpf 130a14b8f16Smpf struct lacp_peerinfo { 131a14b8f16Smpf struct lacp_systemid lip_systemid; 132*9eb35c73Smpf u_int16_t lip_key; 133a14b8f16Smpf struct lacp_portid lip_portid; 134*9eb35c73Smpf u_int8_t lip_state; 135*9eb35c73Smpf u_int8_t lip_resv[3]; 136a14b8f16Smpf } __packed; 137a14b8f16Smpf 138a14b8f16Smpf struct lacp_collectorinfo { 139*9eb35c73Smpf u_int16_t lci_maxdelay; 140*9eb35c73Smpf u_int8_t lci_resv[12]; 141a14b8f16Smpf } __packed; 142a14b8f16Smpf 143a14b8f16Smpf struct lacpdu { 144a14b8f16Smpf struct ether_header ldu_eh; 145a14b8f16Smpf struct slowprothdr ldu_sph; 146a14b8f16Smpf 147a14b8f16Smpf struct tlvhdr ldu_tlv_actor; 148a14b8f16Smpf struct lacp_peerinfo ldu_actor; 149a14b8f16Smpf struct tlvhdr ldu_tlv_partner; 150a14b8f16Smpf struct lacp_peerinfo ldu_partner; 151a14b8f16Smpf struct tlvhdr ldu_tlv_collector; 152a14b8f16Smpf struct lacp_collectorinfo ldu_collector; 153a14b8f16Smpf struct tlvhdr ldu_tlv_term; 154*9eb35c73Smpf u_int8_t ldu_resv[50]; 155a14b8f16Smpf } __packed; 156a14b8f16Smpf 157a14b8f16Smpf /* 158a14b8f16Smpf * IEEE802.3ad marker protocol 159a14b8f16Smpf * 160a14b8f16Smpf * protocol (on-wire) definitions. 161a14b8f16Smpf */ 162a14b8f16Smpf struct lacp_markerinfo { 163*9eb35c73Smpf u_int16_t mi_rq_port; 164*9eb35c73Smpf u_int8_t mi_rq_system[ETHER_ADDR_LEN]; 165*9eb35c73Smpf u_int32_t mi_rq_xid; 166*9eb35c73Smpf u_int8_t mi_pad[2]; 167a14b8f16Smpf } __packed; 168a14b8f16Smpf 169a14b8f16Smpf struct markerdu { 170a14b8f16Smpf struct ether_header mdu_eh; 171a14b8f16Smpf struct slowprothdr mdu_sph; 172a14b8f16Smpf 173a14b8f16Smpf struct tlvhdr mdu_tlv; 174a14b8f16Smpf struct lacp_markerinfo mdu_info; 175a14b8f16Smpf struct tlvhdr mdu_tlv_term; 176*9eb35c73Smpf u_int8_t mdu_resv[90]; 177a14b8f16Smpf } __packed; 178a14b8f16Smpf 179a14b8f16Smpf #define MARKER_TYPE_INFO 0x01 180a14b8f16Smpf #define MARKER_TYPE_RESPONSE 0x02 181a14b8f16Smpf 182a14b8f16Smpf enum lacp_selected { 183a14b8f16Smpf LACP_UNSELECTED, 184a14b8f16Smpf LACP_STANDBY, /* not used in this implementation */ 185a14b8f16Smpf LACP_SELECTED, 186a14b8f16Smpf }; 187a14b8f16Smpf 188a14b8f16Smpf enum lacp_mux_state { 189a14b8f16Smpf LACP_MUX_DETACHED, 190a14b8f16Smpf LACP_MUX_WAITING, 191a14b8f16Smpf LACP_MUX_ATTACHED, 192a14b8f16Smpf LACP_MUX_COLLECTING, 193a14b8f16Smpf LACP_MUX_DISTRIBUTING, 194a14b8f16Smpf }; 195a14b8f16Smpf 196a14b8f16Smpf #define LACP_MAX_PORTS 32 197a14b8f16Smpf 198a14b8f16Smpf struct lacp_portmap { 199a14b8f16Smpf int pm_count; 200a14b8f16Smpf struct lacp_port *pm_map[LACP_MAX_PORTS]; 201a14b8f16Smpf }; 202a14b8f16Smpf 203a14b8f16Smpf struct lacp_port { 204a14b8f16Smpf TAILQ_ENTRY(lacp_port) lp_dist_q; 205a14b8f16Smpf LIST_ENTRY(lacp_port) lp_next; 206a14b8f16Smpf struct lacp_softc *lp_lsc; 207a14b8f16Smpf struct trunk_port *lp_trunk; 208a14b8f16Smpf struct ifnet *lp_ifp; 209a14b8f16Smpf struct lacp_peerinfo lp_partner; 210a14b8f16Smpf struct lacp_peerinfo lp_actor; 211a14b8f16Smpf struct lacp_markerinfo lp_marker; 212a14b8f16Smpf #define lp_state lp_actor.lip_state 213a14b8f16Smpf #define lp_key lp_actor.lip_key 214a14b8f16Smpf #define lp_systemid lp_actor.lip_systemid 215a14b8f16Smpf struct timeval lp_last_lacpdu; 216a14b8f16Smpf int lp_lacpdu_sent; 217a14b8f16Smpf enum lacp_mux_state lp_mux_state; 218a14b8f16Smpf enum lacp_selected lp_selected; 219a14b8f16Smpf int lp_flags; 220a14b8f16Smpf u_int lp_media; /* XXX redundant */ 221a14b8f16Smpf int lp_timer[LACP_NTIMER]; 222a14b8f16Smpf struct ifmultiaddr *lp_ifma; 223a14b8f16Smpf 224a14b8f16Smpf struct lacp_aggregator *lp_aggregator; 225a14b8f16Smpf }; 226a14b8f16Smpf 227a14b8f16Smpf struct lacp_aggregator { 228a14b8f16Smpf TAILQ_ENTRY(lacp_aggregator) la_q; 229a14b8f16Smpf int la_refcnt; /* num of ports which selected us */ 230a14b8f16Smpf int la_nports; /* num of distributing ports */ 231a14b8f16Smpf TAILQ_HEAD(, lacp_port) la_ports; /* distributing ports */ 232a14b8f16Smpf struct lacp_peerinfo la_partner; 233a14b8f16Smpf struct lacp_peerinfo la_actor; 234a14b8f16Smpf int la_pending; /* number of ports in wait_while */ 235a14b8f16Smpf }; 236a14b8f16Smpf 237a14b8f16Smpf struct lacp_softc { 238a14b8f16Smpf struct trunk_softc *lsc_softc; 239a14b8f16Smpf struct lacp_aggregator *lsc_active_aggregator; 240a14b8f16Smpf TAILQ_HEAD(, lacp_aggregator) lsc_aggregators; 241a14b8f16Smpf int lsc_suppress_distributing; 242a14b8f16Smpf struct timeout lsc_transit_callout; 243a14b8f16Smpf struct timeout lsc_callout; 244a14b8f16Smpf LIST_HEAD(, lacp_port) lsc_ports; 245a14b8f16Smpf struct lacp_portmap lsc_pmap[2]; 246a14b8f16Smpf volatile u_int lsc_activemap; 247a14b8f16Smpf u_int32_t lsc_hashkey; 248a14b8f16Smpf }; 249a14b8f16Smpf 250a14b8f16Smpf #define LACP_TYPE_ACTORINFO 1 251a14b8f16Smpf #define LACP_TYPE_PARTNERINFO 2 252a14b8f16Smpf #define LACP_TYPE_COLLECTORINFO 3 253a14b8f16Smpf 254a14b8f16Smpf /* timeout values (in sec) */ 255a14b8f16Smpf #define LACP_FAST_PERIODIC_TIME (1) 256a14b8f16Smpf #define LACP_SLOW_PERIODIC_TIME (30) 257a14b8f16Smpf #define LACP_SHORT_TIMEOUT_TIME (3 * LACP_FAST_PERIODIC_TIME) 258a14b8f16Smpf #define LACP_LONG_TIMEOUT_TIME (3 * LACP_SLOW_PERIODIC_TIME) 259a14b8f16Smpf #define LACP_CHURN_DETECTION_TIME (60) 260a14b8f16Smpf #define LACP_AGGREGATE_WAIT_TIME (2) 261a14b8f16Smpf #define LACP_TRANSIT_DELAY 3000 /* in msec */ 262a14b8f16Smpf 263a14b8f16Smpf #define LACP_STATE_EQ(s1, s2, mask) \ 264a14b8f16Smpf ((((s1) ^ (s2)) & (mask)) == 0) 265a14b8f16Smpf 266a14b8f16Smpf #define LACP_SYS_PRI(peer) (peer).lip_systemid.lsi_prio 267a14b8f16Smpf 268a14b8f16Smpf #define LACP_PORT(_lp) ((struct lacp_port *)(_lp)->tp_psc) 269a14b8f16Smpf #define LACP_SOFTC(_sc) ((struct lacp_softc *)(_sc)->tr_psc) 270a14b8f16Smpf 271a14b8f16Smpf #define LACP_LOCK_INIT(_lsc) mtx_init(&(_lsc)->lsc_mtx, \ 272a14b8f16Smpf "lacp mtx", NULL, MTX_DEF) 273a14b8f16Smpf #define LACP_LOCK_DESTROY(_lsc) mtx_destroy(&(_lsc)->lsc_mtx) 274a14b8f16Smpf #define LACP_LOCK(_lsc) mtx_lock(&(_lsc)->lsc_mtx) 275a14b8f16Smpf #define LACP_UNLOCK(_lsc) mtx_unlock(&(_lsc)->lsc_mtx) 276a14b8f16Smpf #define LACP_LOCK_ASSERT(_lsc) mtx_assert(&(_lsc)->lsc_mtx, MA_OWNED) 277a14b8f16Smpf 278a14b8f16Smpf struct mbuf *lacp_input(struct trunk_port *, struct mbuf *); 279a14b8f16Smpf struct trunk_port *lacp_select_tx_port(struct trunk_softc *, struct mbuf *); 280a14b8f16Smpf int lacp_attach(struct trunk_softc *); 281a14b8f16Smpf int lacp_detach(struct trunk_softc *); 282a14b8f16Smpf void lacp_init(struct trunk_softc *); 283a14b8f16Smpf void lacp_stop(struct trunk_softc *); 284a14b8f16Smpf int lacp_port_create(struct trunk_port *); 285a14b8f16Smpf void lacp_port_destroy(struct trunk_port *); 286a14b8f16Smpf void lacp_linkstate(struct trunk_port *); 287a14b8f16Smpf void lacp_req(struct trunk_softc *, caddr_t); 288a14b8f16Smpf void lacp_portreq(struct trunk_port *, caddr_t); 289a14b8f16Smpf 290*9eb35c73Smpf int lacp_isactive(struct trunk_port *); 291*9eb35c73Smpf int lacp_iscollecting(struct trunk_port *); 292*9eb35c73Smpf int lacp_isdistributing(struct trunk_port *); 293a14b8f16Smpf 294a14b8f16Smpf /* following constants don't include terminating NUL */ 295a14b8f16Smpf #define LACP_MACSTR_MAX (2*6 + 5) 296a14b8f16Smpf #define LACP_SYSTEMPRIOSTR_MAX (4) 297a14b8f16Smpf #define LACP_SYSTEMIDSTR_MAX (LACP_SYSTEMPRIOSTR_MAX + 1 + LACP_MACSTR_MAX) 298a14b8f16Smpf #define LACP_PORTPRIOSTR_MAX (4) 299a14b8f16Smpf #define LACP_PORTNOSTR_MAX (4) 300a14b8f16Smpf #define LACP_PORTIDSTR_MAX (LACP_PORTPRIOSTR_MAX + 1 + LACP_PORTNOSTR_MAX) 301a14b8f16Smpf #define LACP_KEYSTR_MAX (4) 302a14b8f16Smpf #define LACP_PARTNERSTR_MAX \ 303a14b8f16Smpf (1 + LACP_SYSTEMIDSTR_MAX + 1 + LACP_KEYSTR_MAX + 1 \ 304a14b8f16Smpf + LACP_PORTIDSTR_MAX + 1) 305a14b8f16Smpf #define LACP_LAGIDSTR_MAX \ 306a14b8f16Smpf (1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1) 307a14b8f16Smpf #define LACP_STATESTR_MAX (255) /* XXX */ 308