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