]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/lacp.h
xnu-1228.5.18.tar.gz
[apple/xnu.git] / bsd / net / lacp.h
CommitLineData
91447636 1/*
5d5c5d0d
A
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
91447636 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
91447636
A
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
61typedef u_char lacp_actor_partner_state;
62typedef u_int16_t lacp_key;
63typedef u_int16_t lacp_system_priority, lacp_port_priority, lacp_port;
64typedef u_int16_t lacp_collector_max_delay;
65typedef struct {
66 u_char system_id[6];
67} lacp_system, *lacp_system_ref;
68
69/*
70 * LACP Actor/Partner TLV
71 */
72typedef 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 */
87typedef 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
107static __inline__ lacp_actor_partner_state
108lacp_actor_partner_state_set_active_lacp(lacp_actor_partner_state state)
109{
110 return (state | LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY);
111}
112
113static __inline__ lacp_actor_partner_state
114lacp_actor_partner_state_set_passive_lacp(lacp_actor_partner_state state)
115{
116 return (state &= ~LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY);
117}
118
119static __inline__ int
120lacp_actor_partner_state_active_lacp(lacp_actor_partner_state state)
121{
122 return ((state & LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY) != 0);
123}
124
125static __inline__ lacp_actor_partner_state
126lacp_actor_partner_state_set_short_timeout(lacp_actor_partner_state state)
127{
128 return (state | LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT);
129}
130
131static __inline__ lacp_actor_partner_state
132lacp_actor_partner_state_set_long_timeout(lacp_actor_partner_state state)
133{
134 return (state &= ~LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT);
135}
136
137static __inline__ int
138lacp_actor_partner_state_short_timeout(lacp_actor_partner_state state)
139{
140 return ((state & LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT) != 0);
141}
142
143static __inline__ lacp_actor_partner_state
144lacp_actor_partner_state_set_aggregatable(lacp_actor_partner_state state)
145{
146 return (state | LACP_ACTOR_PARTNER_STATE_AGGREGATION);
147}
148
149static __inline__ lacp_actor_partner_state
150lacp_actor_partner_state_set_individual(lacp_actor_partner_state state)
151{
152 return (state &= ~LACP_ACTOR_PARTNER_STATE_AGGREGATION);
153}
154
155static __inline__ lacp_actor_partner_state
156lacp_actor_partner_state_aggregatable(lacp_actor_partner_state state)
157{
158 return ((state & LACP_ACTOR_PARTNER_STATE_AGGREGATION) != 0);
159}
160
161static __inline__ lacp_actor_partner_state
162lacp_actor_partner_state_set_in_sync(lacp_actor_partner_state state)
163{
164 return (state | LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION);
165}
166
167static __inline__ lacp_actor_partner_state
168lacp_actor_partner_state_set_out_of_sync(lacp_actor_partner_state state)
169{
170 return (state &= ~LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION);
171}
172
173static __inline__ int
174lacp_actor_partner_state_in_sync(lacp_actor_partner_state state)
175{
176 return ((state & LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION) != 0);
177}
178
179static __inline__ lacp_actor_partner_state
180lacp_actor_partner_state_set_collecting(lacp_actor_partner_state state)
181{
182 return (state | LACP_ACTOR_PARTNER_STATE_COLLECTING);
183}
184
185static __inline__ lacp_actor_partner_state
186lacp_actor_partner_state_set_not_collecting(lacp_actor_partner_state state)
187{
188 return (state &= ~LACP_ACTOR_PARTNER_STATE_COLLECTING);
189}
190
191static __inline__ lacp_actor_partner_state
192lacp_actor_partner_state_collecting(lacp_actor_partner_state state)
193{
194 return ((state & LACP_ACTOR_PARTNER_STATE_COLLECTING) != 0);
195}
196
197static __inline__ lacp_actor_partner_state
198lacp_actor_partner_state_set_distributing(lacp_actor_partner_state state)
199{
200 return (state | LACP_ACTOR_PARTNER_STATE_DISTRIBUTING);
201}
202
203static __inline__ lacp_actor_partner_state
204lacp_actor_partner_state_set_not_distributing(lacp_actor_partner_state state)
205{
206 return (state &= ~LACP_ACTOR_PARTNER_STATE_DISTRIBUTING);
207}
208
209static __inline__ lacp_actor_partner_state
210lacp_actor_partner_state_distributing(lacp_actor_partner_state state)
211{
212 return ((state & LACP_ACTOR_PARTNER_STATE_DISTRIBUTING) != 0);
213}
214
215static __inline__ lacp_actor_partner_state
216lacp_actor_partner_state_set_defaulted(lacp_actor_partner_state state)
217{
218 return (state | LACP_ACTOR_PARTNER_STATE_DEFAULTED);
219}
220
221static __inline__ lacp_actor_partner_state
222lacp_actor_partner_state_set_not_defaulted(lacp_actor_partner_state state)
223{
224 return (state &= ~LACP_ACTOR_PARTNER_STATE_DEFAULTED);
225}
226
227static __inline__ lacp_actor_partner_state
228lacp_actor_partner_state_defaulted(lacp_actor_partner_state state)
229{
230 return ((state & LACP_ACTOR_PARTNER_STATE_DEFAULTED) != 0);
231}
232
233static __inline__ lacp_actor_partner_state
234lacp_actor_partner_state_set_expired(lacp_actor_partner_state state)
235{
236 return (state | LACP_ACTOR_PARTNER_STATE_EXPIRED);
237}
238
239static __inline__ lacp_actor_partner_state
240lacp_actor_partner_state_set_not_expired(lacp_actor_partner_state state)
241{
242 return (state &= ~LACP_ACTOR_PARTNER_STATE_EXPIRED);
243}
244
245static __inline__ lacp_actor_partner_state
246lacp_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 */
255static __inline__ void
256lacp_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
264static __inline__ lacp_system_priority
265lacp_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
271static __inline__ void
272lacp_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
278static __inline__ lacp_key
279lacp_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
284static __inline__ void
285lacp_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
293static __inline__ lacp_port_priority
294lacp_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
299static __inline__ void
300lacp_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
306static __inline__ lacp_port
307lacp_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 */
315static __inline__ void
316lacp_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
324static __inline__ lacp_collector_max_delay
325lacp_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
330typedef 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
363typedef u_int32_t la_marker_transaction_id;
364
365typedef 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
380static __inline__ void
381la_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
387static __inline__ lacp_port
388la_marker_pdu_get_requestor_port(la_marker_pdu_ref lmpdu)
389{
390 return ((lacp_port)ntohs(*((lacp_port *)lmpdu->lm_requestor_port)));
391}
392
393static __inline__ void
394la_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
402static __inline__ la_marker_transaction_id
403la_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
411static __inline__ void
412la_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
418static __inline__ lacp_system
419la_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_ */