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: releng/10.2/sys/net/ieee8023ad_lacp.h 253687 2013-07-26 19:41:13Z adrian $
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 #define LACP_MAX_PORTS 32
196
197 struct lacp_portmap {
198 int pm_count;
199 struct lacp_port *pm_map[LACP_MAX_PORTS];
200 };
201
202 struct lacp_port {
203 TAILQ_ENTRY(lacp_port) lp_dist_q;
204 LIST_ENTRY(lacp_port) lp_next;
205 struct lacp_softc *lp_lsc;
206 struct lagg_port *lp_lagg;
207 struct ifnet *lp_ifp;
208 struct lacp_peerinfo lp_partner;
209 struct lacp_peerinfo lp_actor;
210 struct lacp_markerinfo lp_marker;
211 #define lp_state lp_actor.lip_state
212 #define lp_key lp_actor.lip_key
213 #define lp_systemid lp_actor.lip_systemid
214 struct timeval lp_last_lacpdu;
215 int lp_lacpdu_sent;
216 enum lacp_mux_state lp_mux_state;
217 enum lacp_selected lp_selected;
218 int lp_flags;
219 u_int lp_media; /* XXX redundant */
220 int lp_timer[LACP_NTIMER];
221 struct ifmultiaddr *lp_ifma;
222
223 struct lacp_aggregator *lp_aggregator;
224 };
225
226 struct lacp_aggregator {
227 TAILQ_ENTRY(lacp_aggregator) la_q;
228 int la_refcnt; /* num of ports which selected us */
229 int la_nports; /* num of distributing ports */
230 TAILQ_HEAD(, lacp_port) la_ports; /* distributing ports */
231 struct lacp_peerinfo la_partner;
232 struct lacp_peerinfo la_actor;
233 int la_pending; /* number of ports in wait_while */
234 };
235
236 struct lacp_softc {
237 struct lagg_softc *lsc_softc;
238 struct mtx lsc_mtx;
239 struct lacp_aggregator *lsc_active_aggregator;
240 TAILQ_HEAD(, lacp_aggregator) lsc_aggregators;
241 boolean_t lsc_suppress_distributing;
242 struct callout lsc_transit_callout;
243 struct callout lsc_callout;
244 LIST_HEAD(, lacp_port) lsc_ports;
245 struct lacp_portmap lsc_pmap[2];
246 volatile u_int lsc_activemap;
247 u_int32_t lsc_hashkey;
248 struct {
249 u_int32_t lsc_rx_test;
250 u_int32_t lsc_tx_test;
251 } lsc_debug;
252 u_int32_t lsc_strict_mode;
253 };
254
255 #define LACP_TYPE_ACTORINFO 1
256 #define LACP_TYPE_PARTNERINFO 2
257 #define LACP_TYPE_COLLECTORINFO 3
258
259 /* timeout values (in sec) */
260 #define LACP_FAST_PERIODIC_TIME (1)
261 #define LACP_SLOW_PERIODIC_TIME (30)
262 #define LACP_SHORT_TIMEOUT_TIME (3 * LACP_FAST_PERIODIC_TIME)
263 #define LACP_LONG_TIMEOUT_TIME (3 * LACP_SLOW_PERIODIC_TIME)
264 #define LACP_CHURN_DETECTION_TIME (60)
265 #define LACP_AGGREGATE_WAIT_TIME (2)
266 #define LACP_TRANSIT_DELAY 3000 /* in msec */
267
268 #define LACP_STATE_EQ(s1, s2, mask) \
269 ((((s1) ^ (s2)) & (mask)) == 0)
270
271 #define LACP_SYS_PRI(peer) (peer).lip_systemid.lsi_prio
272
273 #define LACP_PORT(_lp) ((struct lacp_port *)(_lp)->lp_psc)
274 #define LACP_SOFTC(_sc) ((struct lacp_softc *)(_sc)->sc_psc)
275
276 #define LACP_LOCK_INIT(_lsc) mtx_init(&(_lsc)->lsc_mtx, \
277 "lacp mtx", NULL, MTX_DEF)
278 #define LACP_LOCK_DESTROY(_lsc) mtx_destroy(&(_lsc)->lsc_mtx)
279 #define LACP_LOCK(_lsc) mtx_lock(&(_lsc)->lsc_mtx)
280 #define LACP_UNLOCK(_lsc) mtx_unlock(&(_lsc)->lsc_mtx)
281 #define LACP_LOCK_ASSERT(_lsc) mtx_assert(&(_lsc)->lsc_mtx, MA_OWNED)
282
283 struct mbuf *lacp_input(struct lagg_port *, struct mbuf *);
284 struct lagg_port *lacp_select_tx_port(struct lagg_softc *, struct mbuf *);
285 int lacp_attach(struct lagg_softc *);
286 int lacp_detach(struct lagg_softc *);
287 void lacp_init(struct lagg_softc *);
288 void lacp_stop(struct lagg_softc *);
289 int lacp_port_create(struct lagg_port *);
290 void lacp_port_destroy(struct lagg_port *);
291 void lacp_linkstate(struct lagg_port *);
292 void lacp_req(struct lagg_softc *, caddr_t);
293 void lacp_portreq(struct lagg_port *, caddr_t);
294
295 static __inline int
296 lacp_isactive(struct lagg_port *lgp)
297 {
298 struct lacp_port *lp = LACP_PORT(lgp);
299 struct lacp_softc *lsc = lp->lp_lsc;
300 struct lacp_aggregator *la = lp->lp_aggregator;
301
302 /* This port is joined to the active aggregator */
303 if (la != NULL && la == lsc->lsc_active_aggregator)
304 return (1);
305
306 return (0);
307 }
308
309 static __inline int
310 lacp_iscollecting(struct lagg_port *lgp)
311 {
312 struct lacp_port *lp = LACP_PORT(lgp);
313
314 return ((lp->lp_state & LACP_STATE_COLLECTING) != 0);
315 }
316
317 static __inline int
318 lacp_isdistributing(struct lagg_port *lgp)
319 {
320 struct lacp_port *lp = LACP_PORT(lgp);
321
322 return ((lp->lp_state & LACP_STATE_DISTRIBUTING) != 0);
323 }
324
325 /* following constants don't include terminating NUL */
326 #define LACP_MACSTR_MAX (2*6 + 5)
327 #define LACP_SYSTEMPRIOSTR_MAX (4)
328 #define LACP_SYSTEMIDSTR_MAX (LACP_SYSTEMPRIOSTR_MAX + 1 + LACP_MACSTR_MAX)
329 #define LACP_PORTPRIOSTR_MAX (4)
330 #define LACP_PORTNOSTR_MAX (4)
331 #define LACP_PORTIDSTR_MAX (LACP_PORTPRIOSTR_MAX + 1 + LACP_PORTNOSTR_MAX)
332 #define LACP_KEYSTR_MAX (4)
333 #define LACP_PARTNERSTR_MAX \
334 (1 + LACP_SYSTEMIDSTR_MAX + 1 + LACP_KEYSTR_MAX + 1 \
335 + LACP_PORTIDSTR_MAX + 1)
336 #define LACP_LAGIDSTR_MAX \
337 (1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1)
338 #define LACP_STATESTR_MAX (255) /* XXX */
Cache object: 173bc0f2f603a214fef49e64f236148f
|