]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/lacp.h
xnu-792.24.17.tar.gz
[apple/xnu.git] / bsd / net / lacp.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * lacp.h
25 * - definitions for the Link Aggregation Control Protocol (LACP) and
26 * the Link Aggregation Marker Protocol
27 */
28
29 /*
30 * Modification History
31 *
32 * May 14, 2004 Dieter Siegmund (dieter@apple.com)
33 * - created
34 */
35
36 #ifndef _NET_LACP_H_
37 #define _NET_LACP_H_
38
39 #include <sys/types.h>
40
41 /**
42 ** Link Aggregation Control Protocol (LACP) definitions
43 **/
44 #define LACPDU_VERSION_1 1
45
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
50
51 #define LACPDU_ACTOR_TLV_LENGTH 20
52 #define LACPDU_PARTNER_TLV_LENGTH 20
53 #define LACPDU_COLLECTOR_TLV_LENGTH 16
54
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;
59 typedef struct {
60 u_char system_id[6];
61 } lacp_system, *lacp_system_ref;
62
63 /*
64 * LACP Actor/Partner TLV
65 */
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];
70 u_char lap_system[6];
71 u_char lap_key[2];
72 u_char lap_port_priority[2];
73 u_char lap_port[2];
74 u_char lap_state;
75 u_char lap_reserved[3];
76 } lacp_actor_partner_tlv, *lacp_actor_partner_tlv_ref;
77
78 /*
79 * LACP Collector TLV
80 */
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;
87
88
89 /*
90 * LACP Actor/Partner State bits
91 */
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
100
101 static __inline__ lacp_actor_partner_state
102 lacp_actor_partner_state_set_active_lacp(lacp_actor_partner_state state)
103 {
104 return (state | LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY);
105 }
106
107 static __inline__ lacp_actor_partner_state
108 lacp_actor_partner_state_set_passive_lacp(lacp_actor_partner_state state)
109 {
110 return (state &= ~LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY);
111 }
112
113 static __inline__ int
114 lacp_actor_partner_state_active_lacp(lacp_actor_partner_state state)
115 {
116 return ((state & LACP_ACTOR_PARTNER_STATE_LACP_ACTIVITY) != 0);
117 }
118
119 static __inline__ lacp_actor_partner_state
120 lacp_actor_partner_state_set_short_timeout(lacp_actor_partner_state state)
121 {
122 return (state | LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT);
123 }
124
125 static __inline__ lacp_actor_partner_state
126 lacp_actor_partner_state_set_long_timeout(lacp_actor_partner_state state)
127 {
128 return (state &= ~LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT);
129 }
130
131 static __inline__ int
132 lacp_actor_partner_state_short_timeout(lacp_actor_partner_state state)
133 {
134 return ((state & LACP_ACTOR_PARTNER_STATE_LACP_TIMEOUT) != 0);
135 }
136
137 static __inline__ lacp_actor_partner_state
138 lacp_actor_partner_state_set_aggregatable(lacp_actor_partner_state state)
139 {
140 return (state | LACP_ACTOR_PARTNER_STATE_AGGREGATION);
141 }
142
143 static __inline__ lacp_actor_partner_state
144 lacp_actor_partner_state_set_individual(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_aggregatable(lacp_actor_partner_state state)
151 {
152 return ((state & LACP_ACTOR_PARTNER_STATE_AGGREGATION) != 0);
153 }
154
155 static __inline__ lacp_actor_partner_state
156 lacp_actor_partner_state_set_in_sync(lacp_actor_partner_state state)
157 {
158 return (state | LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION);
159 }
160
161 static __inline__ lacp_actor_partner_state
162 lacp_actor_partner_state_set_out_of_sync(lacp_actor_partner_state state)
163 {
164 return (state &= ~LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION);
165 }
166
167 static __inline__ int
168 lacp_actor_partner_state_in_sync(lacp_actor_partner_state state)
169 {
170 return ((state & LACP_ACTOR_PARTNER_STATE_SYNCHRONIZATION) != 0);
171 }
172
173 static __inline__ lacp_actor_partner_state
174 lacp_actor_partner_state_set_collecting(lacp_actor_partner_state state)
175 {
176 return (state | LACP_ACTOR_PARTNER_STATE_COLLECTING);
177 }
178
179 static __inline__ lacp_actor_partner_state
180 lacp_actor_partner_state_set_not_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_collecting(lacp_actor_partner_state state)
187 {
188 return ((state & LACP_ACTOR_PARTNER_STATE_COLLECTING) != 0);
189 }
190
191 static __inline__ lacp_actor_partner_state
192 lacp_actor_partner_state_set_distributing(lacp_actor_partner_state state)
193 {
194 return (state | LACP_ACTOR_PARTNER_STATE_DISTRIBUTING);
195 }
196
197 static __inline__ lacp_actor_partner_state
198 lacp_actor_partner_state_set_not_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_distributing(lacp_actor_partner_state state)
205 {
206 return ((state & LACP_ACTOR_PARTNER_STATE_DISTRIBUTING) != 0);
207 }
208
209 static __inline__ lacp_actor_partner_state
210 lacp_actor_partner_state_set_defaulted(lacp_actor_partner_state state)
211 {
212 return (state | LACP_ACTOR_PARTNER_STATE_DEFAULTED);
213 }
214
215 static __inline__ lacp_actor_partner_state
216 lacp_actor_partner_state_set_not_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_defaulted(lacp_actor_partner_state state)
223 {
224 return ((state & LACP_ACTOR_PARTNER_STATE_DEFAULTED) != 0);
225 }
226
227 static __inline__ lacp_actor_partner_state
228 lacp_actor_partner_state_set_expired(lacp_actor_partner_state state)
229 {
230 return (state | LACP_ACTOR_PARTNER_STATE_EXPIRED);
231 }
232
233 static __inline__ lacp_actor_partner_state
234 lacp_actor_partner_state_set_not_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_expired(lacp_actor_partner_state state)
241 {
242 return ((state & LACP_ACTOR_PARTNER_STATE_EXPIRED) != 0);
243 }
244
245
246 /*
247 * LACP Actor/Partner TLV access functions
248 */
249 static __inline__ void
250 lacp_actor_partner_tlv_set_system_priority(lacp_actor_partner_tlv_ref tlv,
251 lacp_system_priority system_priority)
252 {
253 *((lacp_system_priority *)tlv->lap_system_priority)
254 = (lacp_system_priority)htons(system_priority);
255 return;
256 }
257
258 static __inline__ lacp_system_priority
259 lacp_actor_partner_tlv_get_system_priority(const lacp_actor_partner_tlv_ref tlv)
260 {
261 return ((lacp_system_priority)
262 ntohs(*((u_short *)tlv->lap_system_priority)));
263 }
264
265 static __inline__ void
266 lacp_actor_partner_tlv_set_key(lacp_actor_partner_tlv_ref tlv, lacp_key key)
267 {
268 *((lacp_key *)tlv->lap_key) = (lacp_key)htons(key);
269 return;
270 }
271
272 static __inline__ lacp_key
273 lacp_actor_partner_tlv_get_key(const lacp_actor_partner_tlv_ref tlv)
274 {
275 return ((lacp_key)ntohs(*((u_short *)tlv->lap_key)));
276 }
277
278 static __inline__ void
279 lacp_actor_partner_tlv_set_port_priority(lacp_actor_partner_tlv_ref tlv,
280 lacp_port_priority port_priority)
281 {
282 *((lacp_port_priority *)tlv->lap_port_priority)
283 = (lacp_port_priority)htons(port_priority);
284 return;
285 }
286
287 static __inline__ lacp_port_priority
288 lacp_actor_partner_tlv_get_port_priority(const lacp_actor_partner_tlv_ref tlv)
289 {
290 return ((lacp_port_priority)ntohs(*((u_short *)tlv->lap_port_priority)));
291 }
292
293 static __inline__ void
294 lacp_actor_partner_tlv_set_port(lacp_actor_partner_tlv_ref tlv, lacp_port port)
295 {
296 *((lacp_port *)tlv->lap_port) = (lacp_port)htons(port);
297 return;
298 }
299
300 static __inline__ lacp_port
301 lacp_actor_partner_tlv_get_port(const lacp_actor_partner_tlv_ref tlv)
302 {
303 return ((lacp_port)ntohs(*((u_short *)tlv->lap_port)));
304 }
305
306 /*
307 * LACP Collector TLV access functions
308 */
309 static __inline__ void
310 lacp_collector_tlv_set_max_delay(lacp_collector_tlv_ref tlv,
311 lacp_collector_max_delay delay)
312 {
313 *((lacp_collector_max_delay *)tlv->lac_max_delay)
314 = (lacp_collector_max_delay)htons(delay);
315 return;
316 }
317
318 static __inline__ lacp_collector_max_delay
319 lacp_collector_tlv_get_max_delay(const lacp_collector_tlv_ref tlv)
320 {
321 return ((lacp_collector_max_delay)ntohs(*((u_short *)tlv->lac_max_delay)));
322 }
323
324 typedef struct lacpdu_s {
325 u_char la_subtype;
326 u_char la_version;
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;
334
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
342
343 /* packet rate per second */
344 #define LACP_PACKET_RATE 3
345
346 /**
347 ** Link Aggregation Marker Protocol definitions
348 **/
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
353
354 #define LA_MARKER_TLV_LENGTH 16
355 #define LA_MARKER_RESPONSE_TLV_LENGTH 16
356
357 typedef u_int32_t la_marker_transaction_id;
358
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];
367 u_char lm_pad[2];
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;
373
374 static __inline__ void
375 la_marker_pdu_set_requestor_port(la_marker_pdu_ref lmpdu, lacp_port port)
376 {
377 *((lacp_port *)lmpdu->lm_requestor_port) = (lacp_port)htons(port);
378 return;
379 }
380
381 static __inline__ lacp_port
382 la_marker_pdu_get_requestor_port(la_marker_pdu_ref lmpdu)
383 {
384 return ((lacp_port)ntohs(*((lacp_port *)lmpdu->lm_requestor_port)));
385 }
386
387 static __inline__ void
388 la_marker_pdu_set_requestor_transaction_id(la_marker_pdu_ref lmpdu,
389 la_marker_transaction_id xid)
390 {
391 *((la_marker_transaction_id *)lmpdu->lm_requestor_transaction_id)
392 = (la_marker_transaction_id)htonl(xid);
393 return;
394 }
395
396 static __inline__ la_marker_transaction_id
397 la_marker_pdu_get_requestor_transaction_id(la_marker_pdu_ref lmpdu)
398 {
399 la_marker_transaction_id * xid_p;
400
401 xid_p = (la_marker_transaction_id *)lmpdu->lm_requestor_transaction_id;
402 return ((la_marker_transaction_id)ntohl(*xid_p));
403 }
404
405 static __inline__ void
406 la_marker_pdu_set_requestor_system(la_marker_pdu_ref lmpdu, lacp_system sys)
407 {
408 *((lacp_system_ref)lmpdu->lm_requestor_system) = sys;
409 return;
410 }
411
412 static __inline__ lacp_system
413 la_marker_pdu_get_requestor_system(la_marker_pdu_ref lmpdu)
414 {
415 return (*(lacp_system_ref)(lmpdu->lm_requestor_system));
416 }
417
418 #endif /* _NET_LACP_H_ */