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>
49 ** Link Aggregation Control Protocol (LACP) definitions
51 #define LACPDU_VERSION_1 1
53 #define LACPDU_TLV_TYPE_TERMINATOR 0x00
54 #define LACPDU_TLV_TYPE_ACTOR 0x01
55 #define LACPDU_TLV_TYPE_PARTNER 0x02
56 #define LACPDU_TLV_TYPE_COLLECTOR 0x03
58 #define LACPDU_ACTOR_TLV_LENGTH 20
59 #define LACPDU_PARTNER_TLV_LENGTH 20
60 #define LACPDU_COLLECTOR_TLV_LENGTH 16
62 typedef u_char lacp_actor_partner_state
;
63 typedef u_int16_t lacp_key
;
64 typedef u_int16_t lacp_system_priority
, lacp_port_priority
, lacp_port
;
65 typedef u_int16_t lacp_collector_max_delay
;
68 } lacp_system
, *lacp_system_ref
;
71 * LACP Actor/Partner TLV
73 typedef struct lacp_actor_partner_tlv_s
{
74 u_char lap_tlv_type
; /* 0x01 or 0x02 */
75 u_char lap_length
; /* 20 */
76 u_char lap_system_priority
[2];
79 u_char lap_port_priority
[2];
82 u_char lap_reserved
[3];
83 } lacp_actor_partner_tlv
, *lacp_actor_partner_tlv_ref
;
88 typedef struct lacp_collector_tlv_s
{
89 u_char lac_tlv_type
; /* 0x03 */
90 u_char lac_length
; /* 16 */
91 u_char lac_max_delay
[2];
92 u_char lac_reserved
[12];
93 } lacp_collector_tlv
, *lacp_collector_tlv_ref
;
97 * LACP Actor/Partner State bits
99 #define LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY 0x01
100 #define LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT 0x02
101 #define LACP_ACTOR_PARTNER_STATE_AGGREGATION 0x04
102 #define LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION 0x08
103 #define LACP_ACTOR_PARTNER_STATE_COLLECTING 0x10
104 #define LACP_ACTOR_PARTNER_STATE_DISTRIBUTING 0x20
105 #define LACP_ACTOR_PARTNER_STATE_DEFAULTED 0x40
106 #define LACP_ACTOR_PARTNER_STATE_EXPIRED 0x80
108 static __inline__ lacp_actor_partner_state
109 lacp_actor_partner_state_set_active_lacp(lacp_actor_partner_state state
)
111 return (state
| LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
);
114 static __inline__ lacp_actor_partner_state
115 lacp_actor_partner_state_set_passive_lacp(lacp_actor_partner_state state
)
117 return (state
&= ~LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
);
120 static __inline__
int
121 lacp_actor_partner_state_active_lacp(lacp_actor_partner_state state
)
123 return ((state
& LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
) != 0);
126 static __inline__ lacp_actor_partner_state
127 lacp_actor_partner_state_set_short_timeout(lacp_actor_partner_state state
)
129 return (state
| LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
);
132 static __inline__ lacp_actor_partner_state
133 lacp_actor_partner_state_set_long_timeout(lacp_actor_partner_state state
)
135 return (state
&= ~LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
);
138 static __inline__
int
139 lacp_actor_partner_state_short_timeout(lacp_actor_partner_state state
)
141 return ((state
& LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
) != 0);
144 static __inline__ lacp_actor_partner_state
145 lacp_actor_partner_state_set_aggregatable(lacp_actor_partner_state state
)
147 return (state
| LACP_ACTOR_PARTNER_STATE_AGGREGATION
);
150 static __inline__ lacp_actor_partner_state
151 lacp_actor_partner_state_set_individual(lacp_actor_partner_state state
)
153 return (state
&= ~LACP_ACTOR_PARTNER_STATE_AGGREGATION
);
156 static __inline__ lacp_actor_partner_state
157 lacp_actor_partner_state_aggregatable(lacp_actor_partner_state state
)
159 return ((state
& LACP_ACTOR_PARTNER_STATE_AGGREGATION
) != 0);
162 static __inline__ lacp_actor_partner_state
163 lacp_actor_partner_state_set_in_sync(lacp_actor_partner_state state
)
165 return (state
| LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
);
168 static __inline__ lacp_actor_partner_state
169 lacp_actor_partner_state_set_out_of_sync(lacp_actor_partner_state state
)
171 return (state
&= ~LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
);
174 static __inline__
int
175 lacp_actor_partner_state_in_sync(lacp_actor_partner_state state
)
177 return ((state
& LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
) != 0);
180 static __inline__ lacp_actor_partner_state
181 lacp_actor_partner_state_set_collecting(lacp_actor_partner_state state
)
183 return (state
| LACP_ACTOR_PARTNER_STATE_COLLECTING
);
186 static __inline__ lacp_actor_partner_state
187 lacp_actor_partner_state_set_not_collecting(lacp_actor_partner_state state
)
189 return (state
&= ~LACP_ACTOR_PARTNER_STATE_COLLECTING
);
192 static __inline__ lacp_actor_partner_state
193 lacp_actor_partner_state_collecting(lacp_actor_partner_state state
)
195 return ((state
& LACP_ACTOR_PARTNER_STATE_COLLECTING
) != 0);
198 static __inline__ lacp_actor_partner_state
199 lacp_actor_partner_state_set_distributing(lacp_actor_partner_state state
)
201 return (state
| LACP_ACTOR_PARTNER_STATE_DISTRIBUTING
);
204 static __inline__ lacp_actor_partner_state
205 lacp_actor_partner_state_set_not_distributing(lacp_actor_partner_state state
)
207 return (state
&= ~LACP_ACTOR_PARTNER_STATE_DISTRIBUTING
);
210 static __inline__ lacp_actor_partner_state
211 lacp_actor_partner_state_distributing(lacp_actor_partner_state state
)
213 return ((state
& LACP_ACTOR_PARTNER_STATE_DISTRIBUTING
) != 0);
216 static __inline__ lacp_actor_partner_state
217 lacp_actor_partner_state_set_defaulted(lacp_actor_partner_state state
)
219 return (state
| LACP_ACTOR_PARTNER_STATE_DEFAULTED
);
222 static __inline__ lacp_actor_partner_state
223 lacp_actor_partner_state_set_not_defaulted(lacp_actor_partner_state state
)
225 return (state
&= ~LACP_ACTOR_PARTNER_STATE_DEFAULTED
);
228 static __inline__ lacp_actor_partner_state
229 lacp_actor_partner_state_defaulted(lacp_actor_partner_state state
)
231 return ((state
& LACP_ACTOR_PARTNER_STATE_DEFAULTED
) != 0);
234 static __inline__ lacp_actor_partner_state
235 lacp_actor_partner_state_set_expired(lacp_actor_partner_state state
)
237 return (state
| LACP_ACTOR_PARTNER_STATE_EXPIRED
);
240 static __inline__ lacp_actor_partner_state
241 lacp_actor_partner_state_set_not_expired(lacp_actor_partner_state state
)
243 return (state
&= ~LACP_ACTOR_PARTNER_STATE_EXPIRED
);
246 static __inline__ lacp_actor_partner_state
247 lacp_actor_partner_state_expired(lacp_actor_partner_state state
)
249 return ((state
& LACP_ACTOR_PARTNER_STATE_EXPIRED
) != 0);
253 * Function: lacp_uint16_set
255 * Set a field in a structure that's at least 16 bits to the given
256 * value, putting it into network byte order
258 static __inline__
void
259 lacp_uint16_set(uint8_t * field
, uint16_t value
)
261 uint16_t tmp_value
= htons(value
);
262 memcpy((void *)field
, (void *)&tmp_value
, sizeof(uint16_t));
267 * Function: lacp_uint16_get
269 * Get a field in a structure that's at least 16 bits, converting
270 * to host byte order.
272 static __inline__
uint16_t
273 lacp_uint16_get(const uint8_t * field
)
276 memcpy((void *)&tmp_field
, (const void *)field
, sizeof(uint16_t));
277 return (ntohs(tmp_field
));
281 * Function: lacp_uint32_set
283 * Set a field in a structure that's at least 32 bits to the given
284 * value, putting it into network byte order
286 static __inline__
void
287 lacp_uint32_set(uint8_t * field
, uint32_t value
)
289 uint32_t tmp_value
= htonl(value
);
290 memcpy((void *)field
, (void *)&tmp_value
, sizeof(uint32_t));
295 * Function: lacp_uint32_get
297 * Get a field in a structure that's at least 32 bits, converting
298 * to host byte order.
300 static __inline__
uint32_t
301 lacp_uint32_get(const uint8_t * field
)
304 memcpy((void *)&tmp_field
, (const void *)field
, sizeof(uint32_t));
305 return (ntohl(tmp_field
));
309 * LACP Actor/Partner TLV access functions
311 static __inline__
void
312 lacp_actor_partner_tlv_set_system_priority(lacp_actor_partner_tlv_ref tlv
,
313 lacp_system_priority system_priority
)
315 lacp_uint16_set(tlv
->lap_system_priority
, system_priority
);
319 static __inline__ lacp_system_priority
320 lacp_actor_partner_tlv_get_system_priority(const lacp_actor_partner_tlv_ref tlv
)
322 return (lacp_system_priority
)lacp_uint16_get(tlv
->lap_system_priority
);
325 static __inline__
void
326 lacp_actor_partner_tlv_set_key(lacp_actor_partner_tlv_ref tlv
, lacp_key key
)
328 lacp_uint16_set(tlv
->lap_key
, key
);
332 static __inline__ lacp_key
333 lacp_actor_partner_tlv_get_key(const lacp_actor_partner_tlv_ref tlv
)
335 return (lacp_key
)lacp_uint16_get(tlv
->lap_key
);
338 static __inline__
void
339 lacp_actor_partner_tlv_set_port_priority(lacp_actor_partner_tlv_ref tlv
,
340 lacp_port_priority port_priority
)
342 lacp_uint16_set(tlv
->lap_port_priority
, port_priority
);
346 static __inline__ lacp_port_priority
347 lacp_actor_partner_tlv_get_port_priority(const lacp_actor_partner_tlv_ref tlv
)
349 return (lacp_port_priority
)lacp_uint16_get(tlv
->lap_port_priority
);
352 static __inline__
void
353 lacp_actor_partner_tlv_set_port(lacp_actor_partner_tlv_ref tlv
, lacp_port port
)
355 lacp_uint16_set(tlv
->lap_port
, port
);
359 static __inline__ lacp_port
360 lacp_actor_partner_tlv_get_port(const lacp_actor_partner_tlv_ref tlv
)
362 return (lacp_port
)lacp_uint16_get(tlv
->lap_port
);
366 * LACP Collector TLV access functions
368 static __inline__
void
369 lacp_collector_tlv_set_max_delay(lacp_collector_tlv_ref tlv
,
370 lacp_collector_max_delay delay
)
372 lacp_uint16_set(tlv
->lac_max_delay
, delay
);
376 static __inline__ lacp_collector_max_delay
377 lacp_collector_tlv_get_max_delay(const lacp_collector_tlv_ref tlv
)
379 return (lacp_collector_max_delay
)lacp_uint16_get(tlv
->lac_max_delay
);
382 typedef struct lacpdu_s
{
385 u_char la_actor_tlv
[LACPDU_ACTOR_TLV_LENGTH
];
386 u_char la_partner_tlv
[LACPDU_PARTNER_TLV_LENGTH
];
387 u_char la_collector_tlv
[LACPDU_COLLECTOR_TLV_LENGTH
];
388 u_char la_terminator_type
;
389 u_char la_terminator_length
;
390 u_char la_reserved
[50];
391 } lacpdu
, *lacpdu_ref
;
393 /* timer values in seconds */
394 #define LACP_FAST_PERIODIC_TIME 1
395 #define LACP_SLOW_PERIODIC_TIME 30
396 #define LACP_SHORT_TIMEOUT_TIME 3
397 #define LACP_LONG_TIMEOUT_TIME 90
398 #define LACP_CHURN_DETECTION_TIME 60
399 #define LACP_AGGREGATE_WAIT_TIME 2
401 /* packet rate per second */
402 #define LACP_PACKET_RATE 3
405 ** Link Aggregation Marker Protocol definitions
407 #define LA_MARKER_PDU_VERSION_1 1
408 #define LA_MARKER_TLV_TYPE_TERMINATOR 0x00
409 #define LA_MARKER_TLV_TYPE_MARKER 0x01
410 #define LA_MARKER_TLV_TYPE_MARKER_RESPONSE 0x02
412 #define LA_MARKER_TLV_LENGTH 16
413 #define LA_MARKER_RESPONSE_TLV_LENGTH 16
415 typedef u_int32_t la_marker_transaction_id
;
417 typedef struct la_marker_pdu_s
{
418 u_char lm_subtype
; /* 0x02 */
419 u_char lm_version
; /* 0x01 */
420 u_char lm_marker_tlv_type
; /* 0x01 or 0x02 */
421 u_char lm_marker_tlv_length
; /* 16 */
422 u_char lm_requestor_port
[2];
423 u_char lm_requestor_system
[6];
424 u_char lm_requestor_transaction_id
[4];
426 u_char lm_terminator_type
; /* 0x00 */
427 u_char lm_terminator_length
; /* 0 */
428 u_char lm_reserved
[90];
429 } la_marker_pdu
, *la_marker_pdu_ref
,
430 la_marker_response_pdu
, * la_marker_response_pdu_ref
;
432 static __inline__
void
433 la_marker_pdu_set_requestor_port(la_marker_pdu_ref lmpdu
, lacp_port port
)
435 lacp_uint16_set(lmpdu
->lm_requestor_port
, port
);
439 static __inline__ lacp_port
440 la_marker_pdu_get_requestor_port(la_marker_pdu_ref lmpdu
)
442 return (lacp_port
)lacp_uint16_get(lmpdu
->lm_requestor_port
);
445 static __inline__
void
446 la_marker_pdu_set_requestor_transaction_id(la_marker_pdu_ref lmpdu
,
447 la_marker_transaction_id xid
)
449 lacp_uint32_set(lmpdu
->lm_requestor_transaction_id
, xid
);
453 static __inline__ la_marker_transaction_id
454 la_marker_pdu_get_requestor_transaction_id(la_marker_pdu_ref lmpdu
)
456 return (la_marker_transaction_id
)lacp_uint32_get(lmpdu
->lm_requestor_transaction_id
);
459 static __inline__
void
460 la_marker_pdu_set_requestor_system(la_marker_pdu_ref lmpdu
, lacp_system sys
)
462 *((lacp_system_ref
)lmpdu
->lm_requestor_system
) = sys
;
466 static __inline__ lacp_system
467 la_marker_pdu_get_requestor_system(la_marker_pdu_ref lmpdu
)
469 return (*(lacp_system_ref
)(lmpdu
->lm_requestor_system
));
472 #endif /* _NET_LACP_H_ */