]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/lacp.h
cd6feb24cbb05403f630ea6afda0ff9023a3062f
[apple/xnu.git] / bsd / net / lacp.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * lacp.h
26 * - definitions for the Link Aggregation Control Protocol (LACP) and
27 * the Link Aggregation Marker Protocol
28 */
29
30 /*
31 * Modification History
32 *
33 * May 14, 2004 Dieter Siegmund (dieter@apple.com)
34 * - created
35 */
36
37 #ifndef _NET_LACP_H_
38 #define _NET_LACP_H_
39
40 #include <sys/types.h>
41
42 /**
43 ** Link Aggregation Control Protocol (LACP) definitions
44 **/
45 #define LACPDU_VERSION_1 1
46
47 #define LACPDU_TLV_TYPE_TERMINATOR 0x00
48 #define LACPDU_TLV_TYPE_ACTOR 0x01
49 #define LACPDU_TLV_TYPE_PARTNER 0x02
50 #define LACPDU_TLV_TYPE_COLLECTOR 0x03
51
52 #define LACPDU_ACTOR_TLV_LENGTH 20
53 #define LACPDU_PARTNER_TLV_LENGTH 20
54 #define LACPDU_COLLECTOR_TLV_LENGTH 16
55
56 typedef u_char lacp_actor_partner_state;
57 typedef u_int16_t lacp_key;
58 typedef u_int16_t lacp_system_priority, lacp_port_priority, lacp_port;
59 typedef u_int16_t lacp_collector_max_delay;
60 typedef struct {
61 u_char system_id[6];
62 } lacp_system, *lacp_system_ref;
63
64 /*
65 * LACP Actor/Partner TLV
66 */
67 typedef struct lacp_actor_partner_tlv_s {
68 u_char lap_tlv_type; /* 0x01 or 0x02 */
69 u_char lap_length; /* 20 */
70 u_char lap_system_priority[2];
71 u_char lap_system[6];
72 u_char lap_key[2];
73 u_char lap_port_priority[2];
74 u_char lap_port[2];
75 u_char lap_state;
76 u_char lap_reserved[3];
77 } lacp_actor_partner_tlv, *lacp_actor_partner_tlv_ref;
78
79 /*
80 * LACP Collector TLV
81 */
82 typedef struct lacp_collector_tlv_s {
83 u_char lac_tlv_type; /* 0x03 */
84 u_char lac_length; /* 16 */
85 u_char lac_max_delay[2];
86 u_char lac_reserved[12];
87 } lacp_collector_tlv, *lacp_collector_tlv_ref;
88
89
90 /*
91 * LACP Actor/Partner State bits
92 */
93 #define LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY 0x01
94 #define LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT 0x02
95 #define LACP_ACTOR_PARTNER_STATE_AGGREGATION 0x04
96 #define LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION 0x08
97 #define LACP_ACTOR_PARTNER_STATE_COLLECTING 0x10
98 #define LACP_ACTOR_PARTNER_STATE_DISTRIBUTING 0x20
99 #define LACP_ACTOR_PARTNER_STATE_DEFAULTED 0x40
100 #define LACP_ACTOR_PARTNER_STATE_EXPIRED 0x80
101
102 static __inline__ lacp_actor_partner_state
103 lacp_actor_partner_state_set_active_lacp(lacp_actor_partner_state state)
104 {
105 return (state | LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY);
106 }
107
108 static __inline__ lacp_actor_partner_state
109 lacp_actor_partner_state_set_passive_lacp(lacp_actor_partner_state state)
110 {
111 return (state &= ~LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY);
112 }
113
114 static __inline__ int
115 lacp_actor_partner_state_active_lacp(lacp_actor_partner_state state)
116 {
117 return ((state & LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY) != 0);
118 }
119
120 static __inline__ lacp_actor_partner_state
121 lacp_actor_partner_state_set_short_timeout(lacp_actor_partner_state state)
122 {
123 return (state | LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT);
124 }
125
126 static __inline__ lacp_actor_partner_state
127 lacp_actor_partner_state_set_long_timeout(lacp_actor_partner_state state)
128 {
129 return (state &= ~LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT);
130 }
131
132 static __inline__ int
133 lacp_actor_partner_state_short_timeout(lacp_actor_partner_state state)
134 {
135 return ((state & LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT) != 0);
136 }
137
138 static __inline__ lacp_actor_partner_state
139 lacp_actor_partner_state_set_aggregatable(lacp_actor_partner_state state)
140 {
141 return (state | LACP_ACTOR_PARTNER_STATE_AGGREGATION);
142 }
143
144 static __inline__ lacp_actor_partner_state
145 lacp_actor_partner_state_set_individual(lacp_actor_partner_state state)
146 {
147 return (state &= ~LACP_ACTOR_PARTNER_STATE_AGGREGATION);
148 }
149
150 static __inline__ lacp_actor_partner_state
151 lacp_actor_partner_state_aggregatable(lacp_actor_partner_state state)
152 {
153 return ((state & LACP_ACTOR_PARTNER_STATE_AGGREGATION) != 0);
154 }
155
156 static __inline__ lacp_actor_partner_state
157 lacp_actor_partner_state_set_in_sync(lacp_actor_partner_state state)
158 {
159 return (state | LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION);
160 }
161
162 static __inline__ lacp_actor_partner_state
163 lacp_actor_partner_state_set_out_of_sync(lacp_actor_partner_state state)
164 {
165 return (state &= ~LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION);
166 }
167
168 static __inline__ int
169 lacp_actor_partner_state_in_sync(lacp_actor_partner_state state)
170 {
171 return ((state & LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION) != 0);
172 }
173
174 static __inline__ lacp_actor_partner_state
175 lacp_actor_partner_state_set_collecting(lacp_actor_partner_state state)
176 {
177 return (state | LACP_ACTOR_PARTNER_STATE_COLLECTING);
178 }
179
180 static __inline__ lacp_actor_partner_state
181 lacp_actor_partner_state_set_not_collecting(lacp_actor_partner_state state)
182 {
183 return (state &= ~LACP_ACTOR_PARTNER_STATE_COLLECTING);
184 }
185
186 static __inline__ lacp_actor_partner_state
187 lacp_actor_partner_state_collecting(lacp_actor_partner_state state)
188 {
189 return ((state & LACP_ACTOR_PARTNER_STATE_COLLECTING) != 0);
190 }
191
192 static __inline__ lacp_actor_partner_state
193 lacp_actor_partner_state_set_distributing(lacp_actor_partner_state state)
194 {
195 return (state | LACP_ACTOR_PARTNER_STATE_DISTRIBUTING);
196 }
197
198 static __inline__ lacp_actor_partner_state
199 lacp_actor_partner_state_set_not_distributing(lacp_actor_partner_state state)
200 {
201 return (state &= ~LACP_ACTOR_PARTNER_STATE_DISTRIBUTING);
202 }
203
204 static __inline__ lacp_actor_partner_state
205 lacp_actor_partner_state_distributing(lacp_actor_partner_state state)
206 {
207 return ((state & LACP_ACTOR_PARTNER_STATE_DISTRIBUTING) != 0);
208 }
209
210 static __inline__ lacp_actor_partner_state
211 lacp_actor_partner_state_set_defaulted(lacp_actor_partner_state state)
212 {
213 return (state | LACP_ACTOR_PARTNER_STATE_DEFAULTED);
214 }
215
216 static __inline__ lacp_actor_partner_state
217 lacp_actor_partner_state_set_not_defaulted(lacp_actor_partner_state state)
218 {
219 return (state &= ~LACP_ACTOR_PARTNER_STATE_DEFAULTED);
220 }
221
222 static __inline__ lacp_actor_partner_state
223 lacp_actor_partner_state_defaulted(lacp_actor_partner_state state)
224 {
225 return ((state & LACP_ACTOR_PARTNER_STATE_DEFAULTED) != 0);
226 }
227
228 static __inline__ lacp_actor_partner_state
229 lacp_actor_partner_state_set_expired(lacp_actor_partner_state state)
230 {
231 return (state | LACP_ACTOR_PARTNER_STATE_EXPIRED);
232 }
233
234 static __inline__ lacp_actor_partner_state
235 lacp_actor_partner_state_set_not_expired(lacp_actor_partner_state state)
236 {
237 return (state &= ~LACP_ACTOR_PARTNER_STATE_EXPIRED);
238 }
239
240 static __inline__ lacp_actor_partner_state
241 lacp_actor_partner_state_expired(lacp_actor_partner_state state)
242 {
243 return ((state & LACP_ACTOR_PARTNER_STATE_EXPIRED) != 0);
244 }
245
246
247 /*
248 * LACP Actor/Partner TLV access functions
249 */
250 static __inline__ void
251 lacp_actor_partner_tlv_set_system_priority(lacp_actor_partner_tlv_ref tlv,
252 lacp_system_priority system_priority)
253 {
254 *((lacp_system_priority *)tlv->lap_system_priority)
255 = (lacp_system_priority)htons(system_priority);
256 return;
257 }
258
259 static __inline__ lacp_system_priority
260 lacp_actor_partner_tlv_get_system_priority(const lacp_actor_partner_tlv_ref tlv)
261 {
262 return ((lacp_system_priority)
263 ntohs(*((u_short *)tlv->lap_system_priority)));
264 }
265
266 static __inline__ void
267 lacp_actor_partner_tlv_set_key(lacp_actor_partner_tlv_ref tlv, lacp_key key)
268 {
269 *((lacp_key *)tlv->lap_key) = (lacp_key)htons(key);
270 return;
271 }
272
273 static __inline__ lacp_key
274 lacp_actor_partner_tlv_get_key(const lacp_actor_partner_tlv_ref tlv)
275 {
276 return ((lacp_key)ntohs(*((u_short *)tlv->lap_key)));
277 }
278
279 static __inline__ void
280 lacp_actor_partner_tlv_set_port_priority(lacp_actor_partner_tlv_ref tlv,
281 lacp_port_priority port_priority)
282 {
283 *((lacp_port_priority *)tlv->lap_port_priority)
284 = (lacp_port_priority)htons(port_priority);
285 return;
286 }
287
288 static __inline__ lacp_port_priority
289 lacp_actor_partner_tlv_get_port_priority(const lacp_actor_partner_tlv_ref tlv)
290 {
291 return ((lacp_port_priority)ntohs(*((u_short *)tlv->lap_port_priority)));
292 }
293
294 static __inline__ void
295 lacp_actor_partner_tlv_set_port(lacp_actor_partner_tlv_ref tlv, lacp_port port)
296 {
297 *((lacp_port *)tlv->lap_port) = (lacp_port)htons(port);
298 return;
299 }
300
301 static __inline__ lacp_port
302 lacp_actor_partner_tlv_get_port(const lacp_actor_partner_tlv_ref tlv)
303 {
304 return ((lacp_port)ntohs(*((u_short *)tlv->lap_port)));
305 }
306
307 /*
308 * LACP Collector TLV access functions
309 */
310 static __inline__ void
311 lacp_collector_tlv_set_max_delay(lacp_collector_tlv_ref tlv,
312 lacp_collector_max_delay delay)
313 {
314 *((lacp_collector_max_delay *)tlv->lac_max_delay)
315 = (lacp_collector_max_delay)htons(delay);
316 return;
317 }
318
319 static __inline__ lacp_collector_max_delay
320 lacp_collector_tlv_get_max_delay(const lacp_collector_tlv_ref tlv)
321 {
322 return ((lacp_collector_max_delay)ntohs(*((u_short *)tlv->lac_max_delay)));
323 }
324
325 typedef struct lacpdu_s {
326 u_char la_subtype;
327 u_char la_version;
328 u_char la_actor_tlv[LACPDU_ACTOR_TLV_LENGTH];
329 u_char la_partner_tlv[LACPDU_PARTNER_TLV_LENGTH];
330 u_char la_collector_tlv[LACPDU_COLLECTOR_TLV_LENGTH];
331 u_char la_terminator_type;
332 u_char la_terminator_length;
333 u_char la_reserved[50];
334 } lacpdu, *lacpdu_ref;
335
336 /* timer values in seconds */
337 #define LACP_FAST_PERIODIC_TIME 1
338 #define LACP_SLOW_PERIODIC_TIME 30
339 #define LACP_SHORT_TIMEOUT_TIME 3
340 #define LACP_LONG_TIMEOUT_TIME 90
341 #define LACP_CHURN_DETECTION_TIME 60
342 #define LACP_AGGREGATE_WAIT_TIME 2
343
344 /* packet rate per second */
345 #define LACP_PACKET_RATE 3
346
347 /**
348 ** Link Aggregation Marker Protocol definitions
349 **/
350 #define LA_MARKER_PDU_VERSION_1 1
351 #define LA_MARKER_TLV_TYPE_TERMINATOR 0x00
352 #define LA_MARKER_TLV_TYPE_MARKER 0x01
353 #define LA_MARKER_TLV_TYPE_MARKER_RESPONSE 0x02
354
355 #define LA_MARKER_TLV_LENGTH 16
356 #define LA_MARKER_RESPONSE_TLV_LENGTH 16
357
358 typedef u_int32_t la_marker_transaction_id;
359
360 typedef struct la_marker_pdu_s {
361 u_char lm_subtype; /* 0x02 */
362 u_char lm_version; /* 0x01 */
363 u_char lm_marker_tlv_type; /* 0x01 or 0x02 */
364 u_char lm_marker_tlv_length; /* 16 */
365 u_char lm_requestor_port[2];
366 u_char lm_requestor_system[6];
367 u_char lm_requestor_transaction_id[4];
368 u_char lm_pad[2];
369 u_char lm_terminator_type; /* 0x00 */
370 u_char lm_terminator_length; /* 0 */
371 u_char lm_reserved[90];
372 } la_marker_pdu, *la_marker_pdu_ref,
373 la_marker_response_pdu, * la_marker_response_pdu_ref;
374
375 static __inline__ void
376 la_marker_pdu_set_requestor_port(la_marker_pdu_ref lmpdu, lacp_port port)
377 {
378 *((lacp_port *)lmpdu->lm_requestor_port) = (lacp_port)htons(port);
379 return;
380 }
381
382 static __inline__ lacp_port
383 la_marker_pdu_get_requestor_port(la_marker_pdu_ref lmpdu)
384 {
385 return ((lacp_port)ntohs(*((lacp_port *)lmpdu->lm_requestor_port)));
386 }
387
388 static __inline__ void
389 la_marker_pdu_set_requestor_transaction_id(la_marker_pdu_ref lmpdu,
390 la_marker_transaction_id xid)
391 {
392 *((la_marker_transaction_id *)lmpdu->lm_requestor_transaction_id)
393 = (la_marker_transaction_id)htonl(xid);
394 return;
395 }
396
397 static __inline__ la_marker_transaction_id
398 la_marker_pdu_get_requestor_transaction_id(la_marker_pdu_ref lmpdu)
399 {
400 la_marker_transaction_id * xid_p;
401
402 xid_p = (la_marker_transaction_id *)lmpdu->lm_requestor_transaction_id;
403 return ((la_marker_transaction_id)ntohl(*xid_p));
404 }
405
406 static __inline__ void
407 la_marker_pdu_set_requestor_system(la_marker_pdu_ref lmpdu, lacp_system sys)
408 {
409 *((lacp_system_ref)lmpdu->lm_requestor_system) = sys;
410 return;
411 }
412
413 static __inline__ lacp_system
414 la_marker_pdu_get_requestor_system(la_marker_pdu_ref lmpdu)
415 {
416 return (*(lacp_system_ref)(lmpdu->lm_requestor_system));
417 }
418
419 #endif /* _NET_LACP_H_ */