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