xref: /netbsd/sys/net/lagg/if_lagg.h (revision 79157b22)
1 /*	$NetBSD: if_lagg.h,v 1.3 2021/11/08 06:29:16 yamaguchi Exp $	*/
2 
3 /*
4  * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  * $FreeBSD$
19  */
20 
21 /*
22  * Copyright (c) 2021 Internet Initiative Japan Inc.
23  * All rights reserved.
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  * 1. Redistributions of source code must retain the above copyright
29  *    notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  *    notice, this list of conditions and the following disclaimer in the
32  *    documentation and/or other materials provided with the distribution.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
35  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
38  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #ifndef _NET_LAGG_IF_LAGG_H_
48 #define _NET_LAGG_IF_LAGG_H_
49 
50 typedef enum {
51 	LAGG_PROTO_NONE = 0,
52 	LAGG_PROTO_LACP,	/* 802.1ax lacp */
53 	LAGG_PROTO_FAILOVER,
54 	LAGG_PROTO_LOADBALANCE,
55 	LAGG_PROTO_MAX,
56 } lagg_proto;
57 
58 /* IEEE802.3ad LACP protocol definitions.*/
59 #define LACP_STATE_ACTIVITY	__BIT(0)
60 #define LACP_STATE_TIMEOUT	__BIT(1)
61 #define LACP_STATE_AGGREGATION	__BIT(2)
62 #define LACP_STATE_SYNC		__BIT(3)
63 #define LACP_STATE_COLLECTING	__BIT(4)
64 #define LACP_STATE_DISTRIBUTING	__BIT(5)
65 #define LACP_STATE_DEFAULTED	__BIT(6)
66 #define LACP_STATE_EXPIRED	__BIT(7)
67 #define LACP_STATE_BITS		\
68 	"\020"			\
69 	"\001ACTIVITY"		\
70 	"\002TIMEOUT"		\
71 	"\003AGGREGATION"	\
72 	"\004SYNC"		\
73 	"\005COLLECTING"	\
74 	"\006DISTRIBUTING"	\
75 	"\007DEFAULTED"		\
76 	"\010EXPIRED"
77 #define LACP_STATESTR_LEN	256
78 #define LACP_MAC_LEN		ETHER_ADDR_LEN
79 
80 enum lagg_ioctl_lacp {
81 	LAGGIOC_LACPSETFLAGS = 1,
82 	LAGGIOC_LACPCLRFLAGS,
83 	LAGGIOC_LACPSETMAXPORTS,
84 	LAGGIOC_LACPCLRMAXPORTS,
85 };
86 
87 #define LAGGREQLACP_OPTIMISTIC		__BIT(0)
88 #define LAGGREQLACP_DUMPDU		__BIT(1)
89 #define LAGGREQLACP_STOPDU		__BIT(2)
90 #define LAGGREQLACP_MULTILS		__BIT(3)
91 #define LAGGREQLACP_BITS		\
92 	"\020"				\
93 	"\001OPTIMISTIC"		\
94 	"\002DUMPDU"			\
95 	"\003STOPDU"			\
96 	"\004MULTILS"
97 
98 struct laggreq_lacp {
99 	uint32_t	 command;
100 	uint32_t	 flags;
101 	size_t		 maxports;
102 
103 	uint16_t	 actor_prio;
104 	uint8_t		 actor_mac[LACP_MAC_LEN];
105 	uint16_t	 actor_key;
106 	uint16_t	 partner_prio;
107 	uint8_t		 partner_mac[LACP_MAC_LEN];
108 	uint16_t	 partner_key;
109 };
110 
111 enum lagg_ioctl_fail {
112 	LAGGIOC_FAILSETFLAGS = 1,
113 	LAGGIOC_FAILCLRFLAGS
114 };
115 
116 #define LAGGREQFAIL_RXALL		__BIT(0)
117 
118 struct laggreq_fail {
119 	uint32_t	 command;
120 	uint32_t	 flags;
121 };
122 
123 struct laggreqproto {
124 	union {
125 		struct laggreq_lacp	 proto_lacp;
126 		struct laggreq_fail	 proto_fail;
127 	} rp_proto;
128 #define rp_lacp	rp_proto.proto_lacp
129 #define rp_fail	rp_proto.proto_fail
130 };
131 
132 #define LAGG_PORT_SLAVE		0
133 #define LAGG_PORT_MASTER	__BIT(0)
134 #define LAGG_PORT_STACK		__BIT(1)
135 #define LAGG_PORT_ACTIVE	__BIT(2)
136 #define LAGG_PORT_COLLECTING	__BIT(3)
137 #define LAGG_PORT_DISTRIBUTING	__BIT(4)
138 #define LAGG_PORT_STANDBY	__BIT(5)
139 #define LAGG_PORT_BITS			\
140 	"\020"				\
141 	"\001MASTER"			\
142 	"\002STACK"			\
143 	"\003ACTIVE"			\
144 	"\004COLLECTING"		\
145 	"\005DISTRIBUTING"		\
146 	"\006STANDBY"
147 #define LACP_PORTSTR_LEN	256
148 
149 struct laggreq_lacpport {
150 	uint16_t	 partner_prio;
151 	uint8_t		 partner_mac[LACP_MAC_LEN];
152 	uint16_t	 partner_key;
153 
154 	uint16_t	 actor_portprio;
155 	uint16_t	 actor_portno;
156 	uint8_t		 actor_state;
157 	uint16_t	 partner_portprio;
158 	uint16_t	 partner_portno;
159 	uint8_t		 partner_state;
160 };
161 
162 struct laggreqport {
163 	char		 rp_portname[IFNAMSIZ];
164 	uint32_t	 rp_prio;
165 	uint32_t	 rp_flags;
166 
167 	union {
168 		struct laggreq_lacpport	 port_lacp;
169 	} rp_port;
170 #define rp_lacpport	rp_port.port_lacp
171 };
172 
173 enum lagg_ioctl {
174 	LAGGIOC_NOCMD,
175 	LAGGIOC_SETPROTO = 1,
176 	LAGGIOC_SETPROTOOPT,
177 	LAGGIOC_ADDPORT,
178 	LAGGIOC_DELPORT,
179 	LAGGIOC_SETPORTPRI,
180 };
181 
182 struct lagg_req {
183 	uint32_t		 lrq_ioctl;
184 	lagg_proto		 lrq_proto;
185 	size_t			 lrq_nports;
186 	struct laggreqproto	 lrq_reqproto;
187 	struct laggreqport	 lrq_reqports[1];
188 };
189 
190 #define	SIOCGLAGG		SIOCGIFGENERIC
191 #define	SIOCSLAGG		SIOCSIFGENERIC
192 #endif
193