ieee8023ad_lacp.h revision 169739
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 169739 2007-05-19 07:47:04Z 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 65169739Sthompsa#define LACP_PORT_MARK 0x00000002 66168561Sthompsa#define LACP_PORT_PROMISC 0x00000004 67168561Sthompsa#define LACP_PORT_LADDRCHANGED 0x00000008 68168561Sthompsa#define LACP_PORT_ATTACHED 0x00000010 69168561Sthompsa#define LACP_PORT_LARVAL 0x00000020 70168561Sthompsa#define LACP_PORT_DETACHING 0x00000040 71168561Sthompsa 72168561Sthompsa#define LACP_STATE_BITS \ 73168561Sthompsa "\020" \ 74168561Sthompsa "\001ACTIVITY" \ 75168561Sthompsa "\002TIMEOUT" \ 76168561Sthompsa "\003AGGREGATION" \ 77168561Sthompsa "\004SYNC" \ 78168561Sthompsa "\005COLLECTING" \ 79168561Sthompsa "\006DISTRIBUTING" \ 80168561Sthompsa "\007DEFAULTED" \ 81168561Sthompsa "\010EXPIRED" 82168561Sthompsa 83168561Sthompsa/* 84168561Sthompsa * IEEE802.3 slow protocols 85168561Sthompsa * 86168561Sthompsa * protocol (on-wire) definitions. 87168561Sthompsa * 88168561Sthompsa * XXX should be elsewhere. 89168561Sthompsa */ 90168561Sthompsa 91168561Sthompsa#define SLOWPROTOCOLS_SUBTYPE_LACP 1 92168561Sthompsa#define SLOWPROTOCOLS_SUBTYPE_MARKER 2 93168561Sthompsa 94168561Sthompsastruct slowprothdr { 95168561Sthompsa uint8_t sph_subtype; 96168561Sthompsa uint8_t sph_version; 97168561Sthompsa} __packed; 98168561Sthompsa 99168561Sthompsa/* 100168561Sthompsa * TLV on-wire structure. 101168561Sthompsa */ 102168561Sthompsa 103168561Sthompsastruct tlvhdr { 104168561Sthompsa uint8_t tlv_type; 105168561Sthompsa uint8_t tlv_length; 106168561Sthompsa /* uint8_t tlv_value[]; */ 107168561Sthompsa} __packed; 108168561Sthompsa 109168561Sthompsa/* 110168561Sthompsa * ... and our implementation. 111168561Sthompsa */ 112168561Sthompsa 113168561Sthompsa#define TLV_SET(tlv, type, length) \ 114168561Sthompsa do { \ 115168561Sthompsa (tlv)->tlv_type = (type); \ 116168561Sthompsa (tlv)->tlv_length = sizeof(*tlv) + (length); \ 117168561Sthompsa } while (/*CONSTCOND*/0) 118168561Sthompsa 119168561Sthompsastruct tlv_template { 120168561Sthompsa uint8_t tmpl_type; 121168561Sthompsa uint8_t tmpl_length; 122168561Sthompsa}; 123168561Sthompsa 124168561Sthompsastruct lacp_systemid { 125168561Sthompsa uint16_t lsi_prio; 126168561Sthompsa uint8_t lsi_mac[6]; 127168561Sthompsa} __packed; 128168561Sthompsa 129168561Sthompsastruct lacp_portid { 130168561Sthompsa uint16_t lpi_prio; 131168561Sthompsa uint16_t lpi_portno; 132168561Sthompsa} __packed; 133168561Sthompsa 134168561Sthompsastruct lacp_peerinfo { 135168561Sthompsa struct lacp_systemid lip_systemid; 136168561Sthompsa uint16_t lip_key; 137168561Sthompsa struct lacp_portid lip_portid; 138168561Sthompsa uint8_t lip_state; 139168561Sthompsa uint8_t lip_resv[3]; 140168561Sthompsa} __packed; 141168561Sthompsa 142168561Sthompsastruct lacp_collectorinfo { 143168561Sthompsa uint16_t lci_maxdelay; 144168561Sthompsa uint8_t lci_resv[12]; 145168561Sthompsa} __packed; 146168561Sthompsa 147168561Sthompsastruct lacpdu { 148168561Sthompsa struct ether_header ldu_eh; 149168561Sthompsa struct slowprothdr ldu_sph; 150168561Sthompsa 151168561Sthompsa struct tlvhdr ldu_tlv_actor; 152168561Sthompsa struct lacp_peerinfo ldu_actor; 153168561Sthompsa struct tlvhdr ldu_tlv_partner; 154168561Sthompsa struct lacp_peerinfo ldu_partner; 155168561Sthompsa struct tlvhdr ldu_tlv_collector; 156168561Sthompsa struct lacp_collectorinfo ldu_collector; 157168561Sthompsa struct tlvhdr ldu_tlv_term; 158168561Sthompsa uint8_t ldu_resv[50]; 159168561Sthompsa} __packed; 160168561Sthompsa 161169739Sthompsa/* 162169739Sthompsa * IEEE802.3ad marker protocol 163169739Sthompsa * 164169739Sthompsa * protocol (on-wire) definitions. 165169739Sthompsa */ 166169739Sthompsastruct lacp_markerinfo { 167169739Sthompsa uint16_t mi_rq_port; 168169739Sthompsa uint8_t mi_rq_system[ETHER_ADDR_LEN]; 169169739Sthompsa uint32_t mi_rq_xid; 170169739Sthompsa uint8_t mi_pad[2]; 171169739Sthompsa} __packed; 172168561Sthompsa 173169739Sthompsastruct markerdu { 174169739Sthompsa struct ether_header mdu_eh; 175169739Sthompsa struct slowprothdr mdu_sph; 176169739Sthompsa 177169739Sthompsa struct tlvhdr mdu_tlv; 178169739Sthompsa struct lacp_markerinfo mdu_info; 179169739Sthompsa struct tlvhdr mdu_tlv_term; 180169739Sthompsa uint8_t mdu_resv[90]; 181169739Sthompsa} __packed; 182169739Sthompsa 183169739Sthompsa#define MARKER_TYPE_INFO 0x01 184169739Sthompsa#define MARKER_TYPE_RESPONSE 0x02 185169739Sthompsa 186168561Sthompsaenum lacp_selected { 187168561Sthompsa LACP_UNSELECTED, 188168561Sthompsa LACP_STANDBY, /* not used in this implementation */ 189168561Sthompsa LACP_SELECTED, 190168561Sthompsa}; 191168561Sthompsa 192168561Sthompsaenum lacp_mux_state { 193168561Sthompsa LACP_MUX_DETACHED, 194168561Sthompsa LACP_MUX_WAITING, 195168561Sthompsa LACP_MUX_ATTACHED, 196168561Sthompsa LACP_MUX_COLLECTING, 197168561Sthompsa LACP_MUX_DISTRIBUTING, 198168561Sthompsa}; 199168561Sthompsa 200168561Sthompsastruct lacp_port { 201168561Sthompsa TAILQ_ENTRY(lacp_port) lp_dist_q; 202168561Sthompsa LIST_ENTRY(lacp_port) lp_next; 203168561Sthompsa struct lacp_softc *lp_lsc; 204168793Sthompsa struct lagg_port *lp_lagg; 205168561Sthompsa struct ifnet *lp_ifp; 206168561Sthompsa struct lacp_peerinfo lp_partner; 207168561Sthompsa struct lacp_peerinfo lp_actor; 208169739Sthompsa struct lacp_markerinfo lp_marker; 209168561Sthompsa#define lp_state lp_actor.lip_state 210168561Sthompsa#define lp_key lp_actor.lip_key 211169739Sthompsa#define lp_systemid lp_actor.lip_systemid 212168561Sthompsa struct timeval lp_last_lacpdu; 213168561Sthompsa int lp_lacpdu_sent; 214168561Sthompsa enum lacp_mux_state lp_mux_state; 215168561Sthompsa enum lacp_selected lp_selected; 216168561Sthompsa int lp_flags; 217168561Sthompsa u_int lp_media; /* XXX redundant */ 218168561Sthompsa int lp_timer[LACP_NTIMER]; 219169327Sthompsa struct ifmultiaddr *lp_ifma; 220168561Sthompsa 221168561Sthompsa struct lacp_aggregator *lp_aggregator; 222168561Sthompsa}; 223168561Sthompsa 224168561Sthompsastruct lacp_aggregator { 225168561Sthompsa TAILQ_ENTRY(lacp_aggregator) la_q; 226168561Sthompsa int la_refcnt; /* num of ports which selected us */ 227168561Sthompsa int la_nports; /* num of distributing ports */ 228168561Sthompsa TAILQ_HEAD(, lacp_port) la_ports; /* distributing ports */ 229168561Sthompsa struct lacp_peerinfo la_partner; 230168561Sthompsa struct lacp_peerinfo la_actor; 231168561Sthompsa int la_pending; /* number of ports which is waiting wait_while */ 232168561Sthompsa}; 233168561Sthompsa 234168561Sthompsastruct lacp_softc { 235168793Sthompsa struct lagg_softc *lsc_lagg; 236168561Sthompsa struct lacp_aggregator *lsc_active_aggregator; 237168561Sthompsa TAILQ_HEAD(, lacp_aggregator) lsc_aggregators; 238168561Sthompsa boolean_t lsc_suppress_distributing; 239168561Sthompsa struct callout lsc_transit_callout; 240168561Sthompsa struct callout lsc_callout; 241168561Sthompsa LIST_HEAD(, lacp_port) lsc_ports; 242168561Sthompsa u_int32_t lsc_hashkey; 243169569Sthompsa struct task lsc_qtask; 244169569Sthompsa struct ifqueue lsc_queue; /* pdu input queue */ 245168561Sthompsa}; 246168561Sthompsa 247168561Sthompsa#define LACP_TYPE_ACTORINFO 1 248168561Sthompsa#define LACP_TYPE_PARTNERINFO 2 249168561Sthompsa#define LACP_TYPE_COLLECTORINFO 3 250168561Sthompsa 251168561Sthompsa/* timeout values (in sec) */ 252168561Sthompsa#define LACP_FAST_PERIODIC_TIME (1) 253168561Sthompsa#define LACP_SLOW_PERIODIC_TIME (30) 254168561Sthompsa#define LACP_SHORT_TIMEOUT_TIME (3 * LACP_FAST_PERIODIC_TIME) 255168561Sthompsa#define LACP_LONG_TIMEOUT_TIME (3 * LACP_SLOW_PERIODIC_TIME) 256168561Sthompsa#define LACP_CHURN_DETECTION_TIME (60) 257168561Sthompsa#define LACP_AGGREGATE_WAIT_TIME (2) 258169739Sthompsa#define LACP_TRANSIT_DELAY 3000 /* in msec */ 259168561Sthompsa 260168561Sthompsa/* 261168561Sthompsaint tlv_check(const void *, size_t, const struct tlvhdr *, 262168561Sthompsa const struct tlv_template *, boolean_t); 263168561Sthompsa*/ 264168561Sthompsa 265168561Sthompsa#define LACP_STATE_EQ(s1, s2, mask) \ 266168561Sthompsa ((((s1) ^ (s2)) & (mask)) == 0) 267168561Sthompsa 268168793Sthompsa#define LACP_PORT(_lp) ((struct lacp_port *)(_lp)->lp_psc) 269168793Sthompsa#define LACP_SOFTC(_sc) ((struct lacp_softc *)(_sc)->sc_psc) 270168561Sthompsa 271169569Sthompsavoid lacp_input(struct lagg_port *, struct mbuf *); 272168793Sthompsastruct lagg_port *lacp_select_tx_port(struct lagg_softc *, struct mbuf *); 273168793Sthompsaint lacp_attach(struct lagg_softc *); 274168793Sthompsaint lacp_detach(struct lagg_softc *); 275168793Sthompsavoid lacp_init(struct lagg_softc *); 276168793Sthompsavoid lacp_stop(struct lagg_softc *); 277168793Sthompsaint lacp_port_create(struct lagg_port *); 278168793Sthompsavoid lacp_port_destroy(struct lagg_port *); 279168793Sthompsavoid lacp_linkstate(struct lagg_port *); 280168793Sthompsaint lacp_port_isactive(struct lagg_port *); 281168561Sthompsa 282168561Sthompsa/* following constants don't include terminating NUL */ 283168561Sthompsa#define LACP_MACSTR_MAX (2*6 + 5) 284168561Sthompsa#define LACP_SYSTEMPRIOSTR_MAX (4) 285168561Sthompsa#define LACP_SYSTEMIDSTR_MAX (LACP_SYSTEMPRIOSTR_MAX + 1 + LACP_MACSTR_MAX) 286168561Sthompsa#define LACP_PORTPRIOSTR_MAX (4) 287168561Sthompsa#define LACP_PORTNOSTR_MAX (4) 288168561Sthompsa#define LACP_PORTIDSTR_MAX (LACP_PORTPRIOSTR_MAX + 1 + LACP_PORTNOSTR_MAX) 289168561Sthompsa#define LACP_KEYSTR_MAX (4) 290168561Sthompsa#define LACP_PARTNERSTR_MAX \ 291168561Sthompsa (1 + LACP_SYSTEMIDSTR_MAX + 1 + LACP_KEYSTR_MAX + 1 \ 292168561Sthompsa + LACP_PORTIDSTR_MAX + 1) 293168561Sthompsa#define LACP_LAGIDSTR_MAX \ 294168561Sthompsa (1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1) 295168561Sthompsa#define LACP_STATESTR_MAX (255) /* XXX */ 296