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