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