2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 * - definitions for the Link Aggregation Control Protocol (LACP) and
32 * the Link Aggregation Marker Protocol
36 * Modification History
38 * May 14, 2004 Dieter Siegmund (dieter@apple.com)
45 #include <sys/types.h>
48 ** Link Aggregation Control Protocol (LACP) definitions
50 #define LACPDU_VERSION_1 1
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
57 #define LACPDU_ACTOR_TLV_LENGTH 20
58 #define LACPDU_PARTNER_TLV_LENGTH 20
59 #define LACPDU_COLLECTOR_TLV_LENGTH 16
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
;
67 } lacp_system
, *lacp_system_ref
;
70 * LACP Actor/Partner TLV
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];
78 u_char lap_port_priority
[2];
81 u_char lap_reserved
[3];
82 } lacp_actor_partner_tlv
, *lacp_actor_partner_tlv_ref
;
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
;
96 * LACP Actor/Partner State bits
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
107 static __inline__ lacp_actor_partner_state
108 lacp_actor_partner_state_set_active_lacp(lacp_actor_partner_state state
)
110 return (state
| LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
);
113 static __inline__ lacp_actor_partner_state
114 lacp_actor_partner_state_set_passive_lacp(lacp_actor_partner_state state
)
116 return (state
&= ~LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
);
119 static __inline__
int
120 lacp_actor_partner_state_active_lacp(lacp_actor_partner_state state
)
122 return ((state
& LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
) != 0);
125 static __inline__ lacp_actor_partner_state
126 lacp_actor_partner_state_set_short_timeout(lacp_actor_partner_state state
)
128 return (state
| LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
);
131 static __inline__ lacp_actor_partner_state
132 lacp_actor_partner_state_set_long_timeout(lacp_actor_partner_state state
)
134 return (state
&= ~LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
);
137 static __inline__
int
138 lacp_actor_partner_state_short_timeout(lacp_actor_partner_state state
)
140 return ((state
& LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
) != 0);
143 static __inline__ lacp_actor_partner_state
144 lacp_actor_partner_state_set_aggregatable(lacp_actor_partner_state state
)
146 return (state
| LACP_ACTOR_PARTNER_STATE_AGGREGATION
);
149 static __inline__ lacp_actor_partner_state
150 lacp_actor_partner_state_set_individual(lacp_actor_partner_state state
)
152 return (state
&= ~LACP_ACTOR_PARTNER_STATE_AGGREGATION
);
155 static __inline__ lacp_actor_partner_state
156 lacp_actor_partner_state_aggregatable(lacp_actor_partner_state state
)
158 return ((state
& LACP_ACTOR_PARTNER_STATE_AGGREGATION
) != 0);
161 static __inline__ lacp_actor_partner_state
162 lacp_actor_partner_state_set_in_sync(lacp_actor_partner_state state
)
164 return (state
| LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
);
167 static __inline__ lacp_actor_partner_state
168 lacp_actor_partner_state_set_out_of_sync(lacp_actor_partner_state state
)
170 return (state
&= ~LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
);
173 static __inline__
int
174 lacp_actor_partner_state_in_sync(lacp_actor_partner_state state
)
176 return ((state
& LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
) != 0);
179 static __inline__ lacp_actor_partner_state
180 lacp_actor_partner_state_set_collecting(lacp_actor_partner_state state
)
182 return (state
| LACP_ACTOR_PARTNER_STATE_COLLECTING
);
185 static __inline__ lacp_actor_partner_state
186 lacp_actor_partner_state_set_not_collecting(lacp_actor_partner_state state
)
188 return (state
&= ~LACP_ACTOR_PARTNER_STATE_COLLECTING
);
191 static __inline__ lacp_actor_partner_state
192 lacp_actor_partner_state_collecting(lacp_actor_partner_state state
)
194 return ((state
& LACP_ACTOR_PARTNER_STATE_COLLECTING
) != 0);
197 static __inline__ lacp_actor_partner_state
198 lacp_actor_partner_state_set_distributing(lacp_actor_partner_state state
)
200 return (state
| LACP_ACTOR_PARTNER_STATE_DISTRIBUTING
);
203 static __inline__ lacp_actor_partner_state
204 lacp_actor_partner_state_set_not_distributing(lacp_actor_partner_state state
)
206 return (state
&= ~LACP_ACTOR_PARTNER_STATE_DISTRIBUTING
);
209 static __inline__ lacp_actor_partner_state
210 lacp_actor_partner_state_distributing(lacp_actor_partner_state state
)
212 return ((state
& LACP_ACTOR_PARTNER_STATE_DISTRIBUTING
) != 0);
215 static __inline__ lacp_actor_partner_state
216 lacp_actor_partner_state_set_defaulted(lacp_actor_partner_state state
)
218 return (state
| LACP_ACTOR_PARTNER_STATE_DEFAULTED
);
221 static __inline__ lacp_actor_partner_state
222 lacp_actor_partner_state_set_not_defaulted(lacp_actor_partner_state state
)
224 return (state
&= ~LACP_ACTOR_PARTNER_STATE_DEFAULTED
);
227 static __inline__ lacp_actor_partner_state
228 lacp_actor_partner_state_defaulted(lacp_actor_partner_state state
)
230 return ((state
& LACP_ACTOR_PARTNER_STATE_DEFAULTED
) != 0);
233 static __inline__ lacp_actor_partner_state
234 lacp_actor_partner_state_set_expired(lacp_actor_partner_state state
)
236 return (state
| LACP_ACTOR_PARTNER_STATE_EXPIRED
);
239 static __inline__ lacp_actor_partner_state
240 lacp_actor_partner_state_set_not_expired(lacp_actor_partner_state state
)
242 return (state
&= ~LACP_ACTOR_PARTNER_STATE_EXPIRED
);
245 static __inline__ lacp_actor_partner_state
246 lacp_actor_partner_state_expired(lacp_actor_partner_state state
)
248 return ((state
& LACP_ACTOR_PARTNER_STATE_EXPIRED
) != 0);
253 * LACP Actor/Partner TLV access functions
255 static __inline__
void
256 lacp_actor_partner_tlv_set_system_priority(lacp_actor_partner_tlv_ref tlv
,
257 lacp_system_priority system_priority
)
259 *((lacp_system_priority
*)tlv
->lap_system_priority
)
260 = (lacp_system_priority
)htons(system_priority
);
264 static __inline__ lacp_system_priority
265 lacp_actor_partner_tlv_get_system_priority(const lacp_actor_partner_tlv_ref tlv
)
267 return ((lacp_system_priority
)
268 ntohs(*((u_short
*)tlv
->lap_system_priority
)));
271 static __inline__
void
272 lacp_actor_partner_tlv_set_key(lacp_actor_partner_tlv_ref tlv
, lacp_key key
)
274 *((lacp_key
*)tlv
->lap_key
) = (lacp_key
)htons(key
);
278 static __inline__ lacp_key
279 lacp_actor_partner_tlv_get_key(const lacp_actor_partner_tlv_ref tlv
)
281 return ((lacp_key
)ntohs(*((u_short
*)tlv
->lap_key
)));
284 static __inline__
void
285 lacp_actor_partner_tlv_set_port_priority(lacp_actor_partner_tlv_ref tlv
,
286 lacp_port_priority port_priority
)
288 *((lacp_port_priority
*)tlv
->lap_port_priority
)
289 = (lacp_port_priority
)htons(port_priority
);
293 static __inline__ lacp_port_priority
294 lacp_actor_partner_tlv_get_port_priority(const lacp_actor_partner_tlv_ref tlv
)
296 return ((lacp_port_priority
)ntohs(*((u_short
*)tlv
->lap_port_priority
)));
299 static __inline__
void
300 lacp_actor_partner_tlv_set_port(lacp_actor_partner_tlv_ref tlv
, lacp_port port
)
302 *((lacp_port
*)tlv
->lap_port
) = (lacp_port
)htons(port
);
306 static __inline__ lacp_port
307 lacp_actor_partner_tlv_get_port(const lacp_actor_partner_tlv_ref tlv
)
309 return ((lacp_port
)ntohs(*((u_short
*)tlv
->lap_port
)));
313 * LACP Collector TLV access functions
315 static __inline__
void
316 lacp_collector_tlv_set_max_delay(lacp_collector_tlv_ref tlv
,
317 lacp_collector_max_delay delay
)
319 *((lacp_collector_max_delay
*)tlv
->lac_max_delay
)
320 = (lacp_collector_max_delay
)htons(delay
);
324 static __inline__ lacp_collector_max_delay
325 lacp_collector_tlv_get_max_delay(const lacp_collector_tlv_ref tlv
)
327 return ((lacp_collector_max_delay
)ntohs(*((u_short
*)tlv
->lac_max_delay
)));
330 typedef struct lacpdu_s
{
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
;
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
349 /* packet rate per second */
350 #define LACP_PACKET_RATE 3
353 ** Link Aggregation Marker Protocol definitions
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
360 #define LA_MARKER_TLV_LENGTH 16
361 #define LA_MARKER_RESPONSE_TLV_LENGTH 16
363 typedef u_int32_t la_marker_transaction_id
;
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];
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
;
380 static __inline__
void
381 la_marker_pdu_set_requestor_port(la_marker_pdu_ref lmpdu
, lacp_port port
)
383 *((lacp_port
*)lmpdu
->lm_requestor_port
) = (lacp_port
)htons(port
);
387 static __inline__ lacp_port
388 la_marker_pdu_get_requestor_port(la_marker_pdu_ref lmpdu
)
390 return ((lacp_port
)ntohs(*((lacp_port
*)lmpdu
->lm_requestor_port
)));
393 static __inline__
void
394 la_marker_pdu_set_requestor_transaction_id(la_marker_pdu_ref lmpdu
,
395 la_marker_transaction_id xid
)
397 *((la_marker_transaction_id
*)lmpdu
->lm_requestor_transaction_id
)
398 = (la_marker_transaction_id
)htonl(xid
);
402 static __inline__ la_marker_transaction_id
403 la_marker_pdu_get_requestor_transaction_id(la_marker_pdu_ref lmpdu
)
405 la_marker_transaction_id
* xid_p
;
407 xid_p
= (la_marker_transaction_id
*)lmpdu
->lm_requestor_transaction_id
;
408 return ((la_marker_transaction_id
)ntohl(*xid_p
));
411 static __inline__
void
412 la_marker_pdu_set_requestor_system(la_marker_pdu_ref lmpdu
, lacp_system sys
)
414 *((lacp_system_ref
)lmpdu
->lm_requestor_system
) = sys
;
418 static __inline__ lacp_system
419 la_marker_pdu_get_requestor_system(la_marker_pdu_ref lmpdu
)
421 return (*(lacp_system_ref
)(lmpdu
->lm_requestor_system
));
424 #endif /* _NET_LACP_H_ */