if_lagg_lacp.h revision 1.2.6.2 1 1.2.6.2 thorpej /* $NetBSD: if_lagg_lacp.h,v 1.2.6.2 2021/06/17 04:46:35 thorpej Exp $ */
2 1.2.6.2 thorpej
3 1.2.6.2 thorpej /*
4 1.2.6.2 thorpej * Copyright (c) 2021 Internet Initiative Japan Inc.
5 1.2.6.2 thorpej * All rights reserved.
6 1.2.6.2 thorpej *
7 1.2.6.2 thorpej * Redistribution and use in source and binary forms, with or without
8 1.2.6.2 thorpej * modification, are permitted provided that the following conditions
9 1.2.6.2 thorpej * are met:
10 1.2.6.2 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.2.6.2 thorpej * notice, this list of conditions and the following disclaimer.
12 1.2.6.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.6.2 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.2.6.2 thorpej * documentation and/or other materials provided with the distribution.
15 1.2.6.2 thorpej *
16 1.2.6.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.2.6.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.2.6.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.2.6.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.2.6.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.2.6.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.2.6.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.2.6.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.2.6.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.2.6.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.2.6.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
27 1.2.6.2 thorpej */
28 1.2.6.2 thorpej
29 1.2.6.2 thorpej #ifndef _NET_LAGG_IF_LAGG_LACP_H_
30 1.2.6.2 thorpej #define _NET_LAGG_IF_LAGG_LACP_H_
31 1.2.6.2 thorpej
32 1.2.6.2 thorpej /* timeout values (in sec) */
33 1.2.6.2 thorpej #define LACP_FAST_PERIODIC_TIME 1
34 1.2.6.2 thorpej #define LACP_SLOW_PERIODIC_TIME 30
35 1.2.6.2 thorpej #define LACP_SHORT_TIMEOUT_TIME (3 * LACP_FAST_PERIODIC_TIME)
36 1.2.6.2 thorpej #define LACP_LONG_TIMEOUT_TIME (3 * LACP_SLOW_PERIODIC_TIME)
37 1.2.6.2 thorpej #define LACP_CHURN_DETECTION_TIME 60
38 1.2.6.2 thorpej #define LACP_AGGREGATE_WAIT_TIME 2
39 1.2.6.2 thorpej #define LACP_TRANSIT_DELAY 3
40 1.2.6.2 thorpej
41 1.2.6.2 thorpej #define LACP_MAX_PORTS 16
42 1.2.6.2 thorpej #define LACP_SYSTEM_PRIO 0x8000U
43 1.2.6.2 thorpej #define LACP_PORT_PRIO LAGG_PORT_PRIO
44 1.2.6.2 thorpej
45 1.2.6.2 thorpej #define LACP_PARTNER_ADMIN_OPTIMISTIC (LACP_STATE_SYNC | \
46 1.2.6.2 thorpej LACP_STATE_AGGREGATION | \
47 1.2.6.2 thorpej LACP_STATE_COLLECTING | \
48 1.2.6.2 thorpej LACP_STATE_DISTRIBUTING)
49 1.2.6.2 thorpej #define LACP_PARTNER_ADMIN_STRICT 0
50 1.2.6.2 thorpej
51 1.2.6.2 thorpej #define SLOWPROTOCOLS_SUBTYPE_LACP 1
52 1.2.6.2 thorpej #define SLOWPROTOCOLS_SUBTYPE_MARKER 2
53 1.2.6.2 thorpej
54 1.2.6.2 thorpej struct slowprothdr {
55 1.2.6.2 thorpej uint8_t sph_subtype;
56 1.2.6.2 thorpej uint8_t sph_version;
57 1.2.6.2 thorpej } __packed;
58 1.2.6.2 thorpej
59 1.2.6.2 thorpej #define TLV_TYPE_TERMINATE 0
60 1.2.6.2 thorpej
61 1.2.6.2 thorpej #define LACP_TYPE_TERMINATE TLV_TYPE_TERMINATE
62 1.2.6.2 thorpej #define LACP_TYPE_ACTORINFO 1
63 1.2.6.2 thorpej #define LACP_TYPE_PARTNERINFO 2
64 1.2.6.2 thorpej #define LACP_TYPE_COLLECTORINFO 3
65 1.2.6.2 thorpej
66 1.2.6.2 thorpej #define MARKER_TYPE_TERMINATE TLV_TYPE_TERMINATE
67 1.2.6.2 thorpej #define MARKER_TYPE_INFO 1
68 1.2.6.2 thorpej #define MARKER_TYPE_RESPONSE 2
69 1.2.6.2 thorpej
70 1.2.6.2 thorpej struct tlvhdr {
71 1.2.6.2 thorpej uint8_t tlv_type;
72 1.2.6.2 thorpej uint8_t tlv_length;
73 1.2.6.2 thorpej } __packed;
74 1.2.6.2 thorpej
75 1.2.6.2 thorpej struct tlv {
76 1.2.6.2 thorpej uint8_t tlv_t;
77 1.2.6.2 thorpej uint8_t tlv_l;
78 1.2.6.2 thorpej void *tlv_v;
79 1.2.6.2 thorpej };
80 1.2.6.2 thorpej
81 1.2.6.2 thorpej static inline void
82 1.2.6.2 thorpej tlv_set(struct tlvhdr *th, uint8_t t, uint8_t l)
83 1.2.6.2 thorpej {
84 1.2.6.2 thorpej
85 1.2.6.2 thorpej th->tlv_type = t;
86 1.2.6.2 thorpej th->tlv_length = sizeof(*th) + l;
87 1.2.6.2 thorpej }
88 1.2.6.2 thorpej
89 1.2.6.2 thorpej struct lacpdu_peerinfo {
90 1.2.6.2 thorpej uint16_t lpi_system_prio;
91 1.2.6.2 thorpej uint8_t lpi_system_mac[LACP_MAC_LEN];
92 1.2.6.2 thorpej uint16_t lpi_key;
93 1.2.6.2 thorpej uint16_t lpi_port_prio;
94 1.2.6.2 thorpej uint16_t lpi_port_no;
95 1.2.6.2 thorpej uint8_t lpi_state;
96 1.2.6.2 thorpej uint8_t lpi_resv[3];
97 1.2.6.2 thorpej } __packed;
98 1.2.6.2 thorpej
99 1.2.6.2 thorpej struct lacpdu_collectorinfo {
100 1.2.6.2 thorpej uint16_t lci_maxdelay;
101 1.2.6.2 thorpej uint8_t lci_resv[12];
102 1.2.6.2 thorpej } __packed;
103 1.2.6.2 thorpej
104 1.2.6.2 thorpej struct lacpdu {
105 1.2.6.2 thorpej struct ether_header ldu_eh;
106 1.2.6.2 thorpej struct slowprothdr ldu_sph;
107 1.2.6.2 thorpej
108 1.2.6.2 thorpej struct tlvhdr ldu_tlv_actor;
109 1.2.6.2 thorpej struct lacpdu_peerinfo ldu_actor;
110 1.2.6.2 thorpej struct tlvhdr ldu_tlv_partner;
111 1.2.6.2 thorpej struct lacpdu_peerinfo ldu_partner;
112 1.2.6.2 thorpej
113 1.2.6.2 thorpej struct tlvhdr ldu_tlv_collector;
114 1.2.6.2 thorpej struct lacpdu_collectorinfo
115 1.2.6.2 thorpej ldu_collector;
116 1.2.6.2 thorpej
117 1.2.6.2 thorpej struct tlvhdr ldu_tlv_term;
118 1.2.6.2 thorpej uint8_t ldu_resv[50];
119 1.2.6.2 thorpej } __packed;
120 1.2.6.2 thorpej
121 1.2.6.2 thorpej struct markerdu_info {
122 1.2.6.2 thorpej uint16_t mi_rq_port;
123 1.2.6.2 thorpej uint8_t mi_rq_system[LACP_MAC_LEN];
124 1.2.6.2 thorpej uint32_t mi_rq_xid;
125 1.2.6.2 thorpej uint8_t mi_pad[2];
126 1.2.6.2 thorpej } __packed;
127 1.2.6.2 thorpej
128 1.2.6.2 thorpej struct markerdu {
129 1.2.6.2 thorpej struct ether_header mdu_eh;
130 1.2.6.2 thorpej struct slowprothdr mdu_sph;
131 1.2.6.2 thorpej
132 1.2.6.2 thorpej struct tlvhdr mdu_tlv_info;
133 1.2.6.2 thorpej struct markerdu_info mdu_info;
134 1.2.6.2 thorpej
135 1.2.6.2 thorpej struct tlvhdr mdu_tlv_term;
136 1.2.6.2 thorpej uint8_t mdu_resv[90];
137 1.2.6.2 thorpej } __packed;
138 1.2.6.2 thorpej
139 1.2.6.2 thorpej /*
140 1.2.6.2 thorpej * lacp media:
141 1.2.6.2 thorpej * 1byte
142 1.2.6.2 thorpej * +-------+-------+-------+-------+
143 1.2.6.2 thorpej * | media | speed |
144 1.2.6.2 thorpej * +-------+-------+-------+-------+
145 1.2.6.2 thorpej */
146 1.2.6.2 thorpej
147 1.2.6.2 thorpej enum lacp_linkspeed {
148 1.2.6.2 thorpej LACP_LINKSPEED_UNKNOWN = 0,
149 1.2.6.2 thorpej LACP_LINKSPEED_10,
150 1.2.6.2 thorpej LACP_LINKSPEED_100,
151 1.2.6.2 thorpej LACP_LINKSPEED_1000,
152 1.2.6.2 thorpej LACP_LINKSPEED_2500,
153 1.2.6.2 thorpej LACP_LINKSPEED_5000,
154 1.2.6.2 thorpej LACP_LINKSPEED_10G,
155 1.2.6.2 thorpej LACP_LINKSPEED_25G,
156 1.2.6.2 thorpej LACP_LINKSPEED_40G,
157 1.2.6.2 thorpej LACP_LINKSPEED_50G,
158 1.2.6.2 thorpej LACP_LINKSPEED_56G,
159 1.2.6.2 thorpej LACP_LINKSPEED_100G,
160 1.2.6.2 thorpej LACP_LINKSPEED_200G,
161 1.2.6.2 thorpej };
162 1.2.6.2 thorpej
163 1.2.6.2 thorpej #define LACP_MEDIA_OFFSET 24
164 1.2.6.2 thorpej #define LACP_MEDIA_MASK 0xff000000U
165 1.2.6.2 thorpej #define LACP_MEDIA_ETHER (__BIT(0) << LACP_MEDIA_OFFSET)
166 1.2.6.2 thorpej #define LACP_MEDIA_FDX (__BIT(1) << LACP_MEDIA_OFFSET)
167 1.2.6.2 thorpej #define LACP_MEDIA_DEFAULT (LACP_LINKSPEED_UNKNOWN | \
168 1.2.6.2 thorpej LACP_MEDIA_ETHER | LACP_MEDIA_FDX)
169 1.2.6.2 thorpej #endif
170