ieee8023ad_lacp.h revision 169569
1168561Sthompsa/* $NetBSD: ieee8023ad_impl.h,v 1.2 2005/12/10 23:21:39 elad Exp $ */ 2168561Sthompsa 3168561Sthompsa/*- 4168561Sthompsa * Copyright (c)2005 YAMAMOTO Takashi, 5168561Sthompsa * All rights reserved. 6168561Sthompsa * 7168561Sthompsa * Redistribution and use in source and binary forms, with or without 8168561Sthompsa * modification, are permitted provided that the following conditions 9168561Sthompsa * are met: 10168561Sthompsa * 1. Redistributions of source code must retain the above copyright 11168561Sthompsa * notice, this list of conditions and the following disclaimer. 12168561Sthompsa * 2. Redistributions in binary form must reproduce the above copyright 13168561Sthompsa * notice, this list of conditions and the following disclaimer in the 14168561Sthompsa * documentation and/or other materials provided with the distribution. 15168561Sthompsa * 16168561Sthompsa * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17168561Sthompsa * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18168561Sthompsa * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19168561Sthompsa * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20168561Sthompsa * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21168561Sthompsa * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22168561Sthompsa * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23168561Sthompsa * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24168561Sthompsa * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25168561Sthompsa * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26168561Sthompsa * SUCH DAMAGE. 27168561Sthompsa * 28168561Sthompsa * $FreeBSD: head/sys/net/ieee8023ad_lacp.h 169569 2007-05-15 07:41:46Z thompsa $ 29168561Sthompsa */ 30168561Sthompsa 31168561Sthompsa/* 32168561Sthompsa * IEEE802.3ad LACP 33168561Sthompsa * 34168561Sthompsa * implementation details. 35168561Sthompsa */ 36168561Sthompsa 37168561Sthompsa#define LACP_TIMER_CURRENT_WHILE 0 38168561Sthompsa#define LACP_TIMER_PERIODIC 1 39168561Sthompsa#define LACP_TIMER_WAIT_WHILE 2 40168561Sthompsa#define LACP_NTIMER 3 41168561Sthompsa 42168561Sthompsa#define LACP_TIMER_ARM(port, timer, val) \ 43168561Sthompsa (port)->lp_timer[(timer)] = (val) 44168561Sthompsa#define LACP_TIMER_DISARM(port, timer) \ 45168561Sthompsa (port)->lp_timer[(timer)] = 0 46168561Sthompsa#define LACP_TIMER_ISARMED(port, timer) \ 47168561Sthompsa ((port)->lp_timer[(timer)] > 0) 48168561Sthompsa 49168561Sthompsa/* 50168561Sthompsa * IEEE802.3ad LACP 51168561Sthompsa * 52168561Sthompsa * protocol definitions. 53168561Sthompsa */ 54168561Sthompsa 55168561Sthompsa#define LACP_STATE_ACTIVITY (1<<0) 56168561Sthompsa#define LACP_STATE_TIMEOUT (1<<1) 57168561Sthompsa#define LACP_STATE_AGGREGATION (1<<2) 58168561Sthompsa#define LACP_STATE_SYNC (1<<3) 59168561Sthompsa#define LACP_STATE_COLLECTING (1<<4) 60168561Sthompsa#define LACP_STATE_DISTRIBUTING (1<<5) 61168561Sthompsa#define LACP_STATE_DEFAULTED (1<<6) 62168561Sthompsa#define LACP_STATE_EXPIRED (1<<7) 63168561Sthompsa 64168561Sthompsa#define LACP_PORT_NTT 0x00000001 65168561Sthompsa#define LACP_PORT_PROMISC 0x00000004 66168561Sthompsa#define LACP_PORT_LADDRCHANGED 0x00000008 67168561Sthompsa#define LACP_PORT_ATTACHED 0x00000010 68168561Sthompsa#define LACP_PORT_LARVAL 0x00000020 69168561Sthompsa#define LACP_PORT_DETACHING 0x00000040 70168561Sthompsa 71168561Sthompsa#define LACP_STATE_BITS \ 72168561Sthompsa "\020" \ 73168561Sthompsa "\001ACTIVITY" \ 74168561Sthompsa "\002TIMEOUT" \ 75168561Sthompsa "\003AGGREGATION" \ 76168561Sthompsa "\004SYNC" \ 77168561Sthompsa "\005COLLECTING" \ 78168561Sthompsa "\006DISTRIBUTING" \ 79168561Sthompsa "\007DEFAULTED" \ 80168561Sthompsa "\010EXPIRED" 81168561Sthompsa 82168561Sthompsa/* 83168561Sthompsa * IEEE802.3 slow protocols 84168561Sthompsa * 85168561Sthompsa * protocol (on-wire) definitions. 86168561Sthompsa * 87168561Sthompsa * XXX should be elsewhere. 88168561Sthompsa */ 89168561Sthompsa 90168561Sthompsa#define SLOWPROTOCOLS_SUBTYPE_LACP 1 91168561Sthompsa#define SLOWPROTOCOLS_SUBTYPE_MARKER 2 92168561Sthompsa 93168561Sthompsastruct slowprothdr { 94168561Sthompsa uint8_t sph_subtype; 95168561Sthompsa uint8_t sph_version; 96168561Sthompsa} __packed; 97168561Sthompsa 98168561Sthompsa/* 99168561Sthompsa * TLV on-wire structure. 100168561Sthompsa */ 101168561Sthompsa 102168561Sthompsastruct tlvhdr { 103168561Sthompsa uint8_t tlv_type; 104168561Sthompsa uint8_t tlv_length; 105168561Sthompsa /* uint8_t tlv_value[]; */ 106168561Sthompsa} __packed; 107168561Sthompsa 108168561Sthompsa/* 109168561Sthompsa * ... and our implementation. 110168561Sthompsa */ 111168561Sthompsa 112168561Sthompsa#define TLV_SET(tlv, type, length) \ 113168561Sthompsa do { \ 114168561Sthompsa (tlv)->tlv_type = (type); \ 115168561Sthompsa (tlv)->tlv_length = sizeof(*tlv) + (length); \ 116168561Sthompsa } while (/*CONSTCOND*/0) 117168561Sthompsa 118168561Sthompsastruct tlv_template { 119168561Sthompsa uint8_t tmpl_type; 120168561Sthompsa uint8_t tmpl_length; 121168561Sthompsa}; 122168561Sthompsa 123168561Sthompsastruct lacp_systemid { 124168561Sthompsa uint16_t lsi_prio; 125168561Sthompsa uint8_t lsi_mac[6]; 126168561Sthompsa} __packed; 127168561Sthompsa 128168561Sthompsastruct lacp_portid { 129168561Sthompsa uint16_t lpi_prio; 130168561Sthompsa uint16_t lpi_portno; 131168561Sthompsa} __packed; 132168561Sthompsa 133168561Sthompsastruct lacp_peerinfo { 134168561Sthompsa struct lacp_systemid lip_systemid; 135168561Sthompsa uint16_t lip_key; 136168561Sthompsa struct lacp_portid lip_portid; 137168561Sthompsa uint8_t lip_state; 138168561Sthompsa uint8_t lip_resv[3]; 139168561Sthompsa} __packed; 140168561Sthompsa 141168561Sthompsastruct lacp_collectorinfo { 142168561Sthompsa uint16_t lci_maxdelay; 143168561Sthompsa uint8_t lci_resv[12]; 144168561Sthompsa} __packed; 145168561Sthompsa 146168561Sthompsastruct lacpdu { 147168561Sthompsa struct ether_header ldu_eh; 148168561Sthompsa struct slowprothdr ldu_sph; 149168561Sthompsa 150168561Sthompsa struct tlvhdr ldu_tlv_actor; 151168561Sthompsa struct lacp_peerinfo ldu_actor; 152168561Sthompsa struct tlvhdr ldu_tlv_partner; 153168561Sthompsa struct lacp_peerinfo ldu_partner; 154168561Sthompsa struct tlvhdr ldu_tlv_collector; 155168561Sthompsa struct lacp_collectorinfo ldu_collector; 156168561Sthompsa struct tlvhdr ldu_tlv_term; 157168561Sthompsa uint8_t ldu_resv[50]; 158168561Sthompsa} __packed; 159168561Sthompsa 160168561Sthompsa#define LACP_TRANSIT_DELAY 1000 /* in msec */ 161168561Sthompsa 162168561Sthompsaenum lacp_selected { 163168561Sthompsa LACP_UNSELECTED, 164168561Sthompsa LACP_STANDBY, /* not used in this implementation */ 165168561Sthompsa LACP_SELECTED, 166168561Sthompsa}; 167168561Sthompsa 168168561Sthompsaenum lacp_mux_state { 169168561Sthompsa LACP_MUX_DETACHED, 170168561Sthompsa LACP_MUX_WAITING, 171168561Sthompsa LACP_MUX_ATTACHED, 172168561Sthompsa LACP_MUX_COLLECTING, 173168561Sthompsa LACP_MUX_DISTRIBUTING, 174168561Sthompsa}; 175168561Sthompsa 176168561Sthompsastruct lacp_port { 177168561Sthompsa TAILQ_ENTRY(lacp_port) lp_dist_q; 178168561Sthompsa LIST_ENTRY(lacp_port) lp_next; 179168561Sthompsa struct lacp_softc *lp_lsc; 180168793Sthompsa struct lagg_port *lp_lagg; 181168561Sthompsa struct ifnet *lp_ifp; 182168561Sthompsa struct lacp_peerinfo lp_partner; 183168561Sthompsa struct lacp_peerinfo lp_actor; 184168561Sthompsa#define lp_state lp_actor.lip_state 185168561Sthompsa#define lp_key lp_actor.lip_key 186168561Sthompsa struct timeval lp_last_lacpdu; 187168561Sthompsa int lp_lacpdu_sent; 188168561Sthompsa enum lacp_mux_state lp_mux_state; 189168561Sthompsa enum lacp_selected lp_selected; 190168561Sthompsa int lp_flags; 191168561Sthompsa u_int lp_media; /* XXX redundant */ 192168561Sthompsa int lp_timer[LACP_NTIMER]; 193169327Sthompsa struct ifmultiaddr *lp_ifma; 194168561Sthompsa 195168561Sthompsa struct lacp_aggregator *lp_aggregator; 196168561Sthompsa}; 197168561Sthompsa 198168561Sthompsastruct lacp_aggregator { 199168561Sthompsa TAILQ_ENTRY(lacp_aggregator) la_q; 200168561Sthompsa int la_refcnt; /* num of ports which selected us */ 201168561Sthompsa int la_nports; /* num of distributing ports */ 202168561Sthompsa TAILQ_HEAD(, lacp_port) la_ports; /* distributing ports */ 203168561Sthompsa struct lacp_peerinfo la_partner; 204168561Sthompsa struct lacp_peerinfo la_actor; 205168561Sthompsa int la_pending; /* number of ports which is waiting wait_while */ 206168561Sthompsa}; 207168561Sthompsa 208168561Sthompsastruct lacp_softc { 209168793Sthompsa struct lagg_softc *lsc_lagg; 210168561Sthompsa struct lacp_aggregator *lsc_active_aggregator; 211168561Sthompsa TAILQ_HEAD(, lacp_aggregator) lsc_aggregators; 212168561Sthompsa boolean_t lsc_suppress_distributing; 213168561Sthompsa struct callout lsc_transit_callout; 214168561Sthompsa struct callout lsc_callout; 215168561Sthompsa LIST_HEAD(, lacp_port) lsc_ports; 216168561Sthompsa u_int32_t lsc_hashkey; 217169569Sthompsa struct task lsc_qtask; 218169569Sthompsa struct ifqueue lsc_queue; /* pdu input queue */ 219168561Sthompsa}; 220168561Sthompsa 221168561Sthompsa#define LACP_TYPE_ACTORINFO 1 222168561Sthompsa#define LACP_TYPE_PARTNERINFO 2 223168561Sthompsa#define LACP_TYPE_COLLECTORINFO 3 224168561Sthompsa 225168561Sthompsa/* timeout values (in sec) */ 226168561Sthompsa#define LACP_FAST_PERIODIC_TIME (1) 227168561Sthompsa#define LACP_SLOW_PERIODIC_TIME (30) 228168561Sthompsa#define LACP_SHORT_TIMEOUT_TIME (3 * LACP_FAST_PERIODIC_TIME) 229168561Sthompsa#define LACP_LONG_TIMEOUT_TIME (3 * LACP_SLOW_PERIODIC_TIME) 230168561Sthompsa#define LACP_CHURN_DETECTION_TIME (60) 231168561Sthompsa#define LACP_AGGREGATE_WAIT_TIME (2) 232168561Sthompsa 233168561Sthompsa/* 234168561Sthompsaint tlv_check(const void *, size_t, const struct tlvhdr *, 235168561Sthompsa const struct tlv_template *, boolean_t); 236168561Sthompsa*/ 237168561Sthompsa 238168561Sthompsa/* 239168561Sthompsa * IEEE802.3ad marker protocol 240168561Sthompsa * 241168561Sthompsa * protocol (on-wire) definitions. 242168561Sthompsa */ 243168561Sthompsa 244168561Sthompsastruct markerdu { 245168561Sthompsa struct ether_header mdu_eh; 246168561Sthompsa struct slowprothdr mdu_sph; 247168561Sthompsa 248168561Sthompsa struct tlvhdr mdu_tlv; 249168561Sthompsa uint16_t mdu_rq_port; 250168561Sthompsa uint8_t mdu_rq_system[6]; 251168561Sthompsa uint8_t mdu_rq_xid[4]; 252168561Sthompsa uint8_t mdu_pad[2]; 253168561Sthompsa 254168561Sthompsa struct tlvhdr mdu_tlv_term; 255168561Sthompsa uint8_t mdu_resv[90]; 256168561Sthompsa} __packed; 257168561Sthompsa 258168561Sthompsa#define MARKER_TYPE_INFO 1 259168561Sthompsa#define MARKER_TYPE_RESPONSE 2 260168561Sthompsa 261168561Sthompsa#define LACP_STATE_EQ(s1, s2, mask) \ 262168561Sthompsa ((((s1) ^ (s2)) & (mask)) == 0) 263168561Sthompsa 264168793Sthompsa#define LACP_PORT(_lp) ((struct lacp_port *)(_lp)->lp_psc) 265168793Sthompsa#define LACP_SOFTC(_sc) ((struct lacp_softc *)(_sc)->sc_psc) 266168561Sthompsa 267169569Sthompsavoid lacp_input(struct lagg_port *, struct mbuf *); 268168793Sthompsastruct lagg_port *lacp_select_tx_port(struct lagg_softc *, struct mbuf *); 269168793Sthompsaint lacp_attach(struct lagg_softc *); 270168793Sthompsaint lacp_detach(struct lagg_softc *); 271168793Sthompsavoid lacp_init(struct lagg_softc *); 272168793Sthompsavoid lacp_stop(struct lagg_softc *); 273168793Sthompsaint lacp_port_create(struct lagg_port *); 274168793Sthompsavoid lacp_port_destroy(struct lagg_port *); 275168793Sthompsavoid lacp_linkstate(struct lagg_port *); 276168793Sthompsaint lacp_port_isactive(struct lagg_port *); 277168561Sthompsa 278168561Sthompsa/* following constants don't include terminating NUL */ 279168561Sthompsa#define LACP_MACSTR_MAX (2*6 + 5) 280168561Sthompsa#define LACP_SYSTEMPRIOSTR_MAX (4) 281168561Sthompsa#define LACP_SYSTEMIDSTR_MAX (LACP_SYSTEMPRIOSTR_MAX + 1 + LACP_MACSTR_MAX) 282168561Sthompsa#define LACP_PORTPRIOSTR_MAX (4) 283168561Sthompsa#define LACP_PORTNOSTR_MAX (4) 284168561Sthompsa#define LACP_PORTIDSTR_MAX (LACP_PORTPRIOSTR_MAX + 1 + LACP_PORTNOSTR_MAX) 285168561Sthompsa#define LACP_KEYSTR_MAX (4) 286168561Sthompsa#define LACP_PARTNERSTR_MAX \ 287168561Sthompsa (1 + LACP_SYSTEMIDSTR_MAX + 1 + LACP_KEYSTR_MAX + 1 \ 288168561Sthompsa + LACP_PORTIDSTR_MAX + 1) 289168561Sthompsa#define LACP_LAGIDSTR_MAX \ 290168561Sthompsa (1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1) 291168561Sthompsa#define LACP_STATESTR_MAX (255) /* XXX */ 292