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