2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 * - definitions for the Link Aggregation Control Protocol (LACP) and
26 * the Link Aggregation Marker Protocol
30 * Modification History
32 * May 14, 2004 Dieter Siegmund (dieter@apple.com)
39 #include <sys/types.h>
42 ** Link Aggregation Control Protocol (LACP) definitions
44 #define LACPDU_VERSION_1 1
46 #define LACPDU_TLV_TYPE_TERMINATOR 0x00
47 #define LACPDU_TLV_TYPE_ACTOR 0x01
48 #define LACPDU_TLV_TYPE_PARTNER 0x02
49 #define LACPDU_TLV_TYPE_COLLECTOR 0x03
51 #define LACPDU_ACTOR_TLV_LENGTH 20
52 #define LACPDU_PARTNER_TLV_LENGTH 20
53 #define LACPDU_COLLECTOR_TLV_LENGTH 16
55 typedef u_char lacp_actor_partner_state
;
56 typedef u_int16_t lacp_key
;
57 typedef u_int16_t lacp_system_priority
, lacp_port_priority
, lacp_port
;
58 typedef u_int16_t lacp_collector_max_delay
;
61 } lacp_system
, *lacp_system_ref
;
64 * LACP Actor/Partner TLV
66 typedef struct lacp_actor_partner_tlv_s
{
67 u_char lap_tlv_type
; /* 0x01 or 0x02 */
68 u_char lap_length
; /* 20 */
69 u_char lap_system_priority
[2];
72 u_char lap_port_priority
[2];
75 u_char lap_reserved
[3];
76 } lacp_actor_partner_tlv
, *lacp_actor_partner_tlv_ref
;
81 typedef struct lacp_collector_tlv_s
{
82 u_char lac_tlv_type
; /* 0x03 */
83 u_char lac_length
; /* 16 */
84 u_char lac_max_delay
[2];
85 u_char lac_reserved
[12];
86 } lacp_collector_tlv
, *lacp_collector_tlv_ref
;
90 * LACP Actor/Partner State bits
92 #define LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY 0x01
93 #define LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT 0x02
94 #define LACP_ACTOR_PARTNER_STATE_AGGREGATION 0x04
95 #define LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION 0x08
96 #define LACP_ACTOR_PARTNER_STATE_COLLECTING 0x10
97 #define LACP_ACTOR_PARTNER_STATE_DISTRIBUTING 0x20
98 #define LACP_ACTOR_PARTNER_STATE_DEFAULTED 0x40
99 #define LACP_ACTOR_PARTNER_STATE_EXPIRED 0x80
101 static __inline__ lacp_actor_partner_state
102 lacp_actor_partner_state_set_active_lacp(lacp_actor_partner_state state
)
104 return (state
| LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
);
107 static __inline__ lacp_actor_partner_state
108 lacp_actor_partner_state_set_passive_lacp(lacp_actor_partner_state state
)
110 return (state
&= ~LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
);
113 static __inline__
int
114 lacp_actor_partner_state_active_lacp(lacp_actor_partner_state state
)
116 return ((state
& LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY
) != 0);
119 static __inline__ lacp_actor_partner_state
120 lacp_actor_partner_state_set_short_timeout(lacp_actor_partner_state state
)
122 return (state
| LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
);
125 static __inline__ lacp_actor_partner_state
126 lacp_actor_partner_state_set_long_timeout(lacp_actor_partner_state state
)
128 return (state
&= ~LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
);
131 static __inline__
int
132 lacp_actor_partner_state_short_timeout(lacp_actor_partner_state state
)
134 return ((state
& LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT
) != 0);
137 static __inline__ lacp_actor_partner_state
138 lacp_actor_partner_state_set_aggregatable(lacp_actor_partner_state state
)
140 return (state
| LACP_ACTOR_PARTNER_STATE_AGGREGATION
);
143 static __inline__ lacp_actor_partner_state
144 lacp_actor_partner_state_set_individual(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_aggregatable(lacp_actor_partner_state state
)
152 return ((state
& LACP_ACTOR_PARTNER_STATE_AGGREGATION
) != 0);
155 static __inline__ lacp_actor_partner_state
156 lacp_actor_partner_state_set_in_sync(lacp_actor_partner_state state
)
158 return (state
| LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
);
161 static __inline__ lacp_actor_partner_state
162 lacp_actor_partner_state_set_out_of_sync(lacp_actor_partner_state state
)
164 return (state
&= ~LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
);
167 static __inline__
int
168 lacp_actor_partner_state_in_sync(lacp_actor_partner_state state
)
170 return ((state
& LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION
) != 0);
173 static __inline__ lacp_actor_partner_state
174 lacp_actor_partner_state_set_collecting(lacp_actor_partner_state state
)
176 return (state
| LACP_ACTOR_PARTNER_STATE_COLLECTING
);
179 static __inline__ lacp_actor_partner_state
180 lacp_actor_partner_state_set_not_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_collecting(lacp_actor_partner_state state
)
188 return ((state
& LACP_ACTOR_PARTNER_STATE_COLLECTING
) != 0);
191 static __inline__ lacp_actor_partner_state
192 lacp_actor_partner_state_set_distributing(lacp_actor_partner_state state
)
194 return (state
| LACP_ACTOR_PARTNER_STATE_DISTRIBUTING
);
197 static __inline__ lacp_actor_partner_state
198 lacp_actor_partner_state_set_not_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_distributing(lacp_actor_partner_state state
)
206 return ((state
& LACP_ACTOR_PARTNER_STATE_DISTRIBUTING
) != 0);
209 static __inline__ lacp_actor_partner_state
210 lacp_actor_partner_state_set_defaulted(lacp_actor_partner_state state
)
212 return (state
| LACP_ACTOR_PARTNER_STATE_DEFAULTED
);
215 static __inline__ lacp_actor_partner_state
216 lacp_actor_partner_state_set_not_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_defaulted(lacp_actor_partner_state state
)
224 return ((state
& LACP_ACTOR_PARTNER_STATE_DEFAULTED
) != 0);
227 static __inline__ lacp_actor_partner_state
228 lacp_actor_partner_state_set_expired(lacp_actor_partner_state state
)
230 return (state
| LACP_ACTOR_PARTNER_STATE_EXPIRED
);
233 static __inline__ lacp_actor_partner_state
234 lacp_actor_partner_state_set_not_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_expired(lacp_actor_partner_state state
)
242 return ((state
& LACP_ACTOR_PARTNER_STATE_EXPIRED
) != 0);
247 * LACP Actor/Partner TLV access functions
249 static __inline__
void
250 lacp_actor_partner_tlv_set_system_priority(lacp_actor_partner_tlv_ref tlv
,
251 lacp_system_priority system_priority
)
253 *((lacp_system_priority
*)tlv
->lap_system_priority
)
254 = (lacp_system_priority
)htons(system_priority
);
258 static __inline__ lacp_system_priority
259 lacp_actor_partner_tlv_get_system_priority(const lacp_actor_partner_tlv_ref tlv
)
261 return ((lacp_system_priority
)
262 ntohs(*((u_short
*)tlv
->lap_system_priority
)));
265 static __inline__
void
266 lacp_actor_partner_tlv_set_key(lacp_actor_partner_tlv_ref tlv
, lacp_key key
)
268 *((lacp_key
*)tlv
->lap_key
) = (lacp_key
)htons(key
);
272 static __inline__ lacp_key
273 lacp_actor_partner_tlv_get_key(const lacp_actor_partner_tlv_ref tlv
)
275 return ((lacp_key
)ntohs(*((u_short
*)tlv
->lap_key
)));
278 static __inline__
void
279 lacp_actor_partner_tlv_set_port_priority(lacp_actor_partner_tlv_ref tlv
,
280 lacp_port_priority port_priority
)
282 *((lacp_port_priority
*)tlv
->lap_port_priority
)
283 = (lacp_port_priority
)htons(port_priority
);
287 static __inline__ lacp_port_priority
288 lacp_actor_partner_tlv_get_port_priority(const lacp_actor_partner_tlv_ref tlv
)
290 return ((lacp_port_priority
)ntohs(*((u_short
*)tlv
->lap_port_priority
)));
293 static __inline__
void
294 lacp_actor_partner_tlv_set_port(lacp_actor_partner_tlv_ref tlv
, lacp_port port
)
296 *((lacp_port
*)tlv
->lap_port
) = (lacp_port
)htons(port
);
300 static __inline__ lacp_port
301 lacp_actor_partner_tlv_get_port(const lacp_actor_partner_tlv_ref tlv
)
303 return ((lacp_port
)ntohs(*((u_short
*)tlv
->lap_port
)));
307 * LACP Collector TLV access functions
309 static __inline__
void
310 lacp_collector_tlv_set_max_delay(lacp_collector_tlv_ref tlv
,
311 lacp_collector_max_delay delay
)
313 *((lacp_collector_max_delay
*)tlv
->lac_max_delay
)
314 = (lacp_collector_max_delay
)htons(delay
);
318 static __inline__ lacp_collector_max_delay
319 lacp_collector_tlv_get_max_delay(const lacp_collector_tlv_ref tlv
)
321 return ((lacp_collector_max_delay
)ntohs(*((u_short
*)tlv
->lac_max_delay
)));
324 typedef struct lacpdu_s
{
327 u_char la_actor_tlv
[LACPDU_ACTOR_TLV_LENGTH
];
328 u_char la_partner_tlv
[LACPDU_PARTNER_TLV_LENGTH
];
329 u_char la_collector_tlv
[LACPDU_COLLECTOR_TLV_LENGTH
];
330 u_char la_terminator_type
;
331 u_char la_terminator_length
;
332 u_char la_reserved
[50];
333 } lacpdu
, *lacpdu_ref
;
335 /* timer values in seconds */
336 #define LACP_FAST_PERIODIC_TIME 1
337 #define LACP_SLOW_PERIODIC_TIME 30
338 #define LACP_SHORT_TIMEOUT_TIME 3
339 #define LACP_LONG_TIMEOUT_TIME 90
340 #define LACP_CHURN_DETECTION_TIME 60
341 #define LACP_AGGREGATE_WAIT_TIME 2
343 /* packet rate per second */
344 #define LACP_PACKET_RATE 3
347 ** Link Aggregation Marker Protocol definitions
349 #define LA_MARKER_PDU_VERSION_1 1
350 #define LA_MARKER_TLV_TYPE_TERMINATOR 0x00
351 #define LA_MARKER_TLV_TYPE_MARKER 0x01
352 #define LA_MARKER_TLV_TYPE_MARKER_RESPONSE 0x02
354 #define LA_MARKER_TLV_LENGTH 16
355 #define LA_MARKER_RESPONSE_TLV_LENGTH 16
357 typedef u_int32_t la_marker_transaction_id
;
359 typedef struct la_marker_pdu_s
{
360 u_char lm_subtype
; /* 0x02 */
361 u_char lm_version
; /* 0x01 */
362 u_char lm_marker_tlv_type
; /* 0x01 or 0x02 */
363 u_char lm_marker_tlv_length
; /* 16 */
364 u_char lm_requestor_port
[2];
365 u_char lm_requestor_system
[6];
366 u_char lm_requestor_transaction_id
[4];
368 u_char lm_terminator_type
; /* 0x00 */
369 u_char lm_terminator_length
; /* 0 */
370 u_char lm_reserved
[90];
371 } la_marker_pdu
, *la_marker_pdu_ref
,
372 la_marker_response_pdu
, * la_marker_response_pdu_ref
;
374 static __inline__
void
375 la_marker_pdu_set_requestor_port(la_marker_pdu_ref lmpdu
, lacp_port port
)
377 *((lacp_port
*)lmpdu
->lm_requestor_port
) = (lacp_port
)htons(port
);
381 static __inline__ lacp_port
382 la_marker_pdu_get_requestor_port(la_marker_pdu_ref lmpdu
)
384 return ((lacp_port
)ntohs(*((lacp_port
*)lmpdu
->lm_requestor_port
)));
387 static __inline__
void
388 la_marker_pdu_set_requestor_transaction_id(la_marker_pdu_ref lmpdu
,
389 la_marker_transaction_id xid
)
391 *((la_marker_transaction_id
*)lmpdu
->lm_requestor_transaction_id
)
392 = (la_marker_transaction_id
)htonl(xid
);
396 static __inline__ la_marker_transaction_id
397 la_marker_pdu_get_requestor_transaction_id(la_marker_pdu_ref lmpdu
)
399 la_marker_transaction_id
* xid_p
;
401 xid_p
= (la_marker_transaction_id
*)lmpdu
->lm_requestor_transaction_id
;
402 return ((la_marker_transaction_id
)ntohl(*xid_p
));
405 static __inline__
void
406 la_marker_pdu_set_requestor_system(la_marker_pdu_ref lmpdu
, lacp_system sys
)
408 *((lacp_system_ref
)lmpdu
->lm_requestor_system
) = sys
;
412 static __inline__ lacp_system
413 la_marker_pdu_get_requestor_system(la_marker_pdu_ref lmpdu
)
415 return (*(lacp_system_ref
)(lmpdu
->lm_requestor_system
));
418 #endif /* _NET_LACP_H_ */