xref: /freebsd/sys/net/ieee8023ad_lacp.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1b47888ceSAndrew Thompson /*	$NetBSD: ieee8023ad_impl.h,v 1.2 2005/12/10 23:21:39 elad Exp $	*/
2b47888ceSAndrew Thompson 
3b47888ceSAndrew Thompson /*-
4*b61a5730SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
5fe267a55SPedro F. Giffuni  *
6b47888ceSAndrew Thompson  * Copyright (c)2005 YAMAMOTO Takashi,
7b47888ceSAndrew Thompson  * All rights reserved.
8b47888ceSAndrew Thompson  *
9b47888ceSAndrew Thompson  * Redistribution and use in source and binary forms, with or without
10b47888ceSAndrew Thompson  * modification, are permitted provided that the following conditions
11b47888ceSAndrew Thompson  * are met:
12b47888ceSAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
13b47888ceSAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
14b47888ceSAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
15b47888ceSAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
16b47888ceSAndrew Thompson  *    documentation and/or other materials provided with the distribution.
17b47888ceSAndrew Thompson  *
18b47888ceSAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19b47888ceSAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20b47888ceSAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21b47888ceSAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22b47888ceSAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23b47888ceSAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24b47888ceSAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25b47888ceSAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26b47888ceSAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27b47888ceSAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28b47888ceSAndrew Thompson  * SUCH DAMAGE.
29b47888ceSAndrew Thompson  */
30b47888ceSAndrew Thompson 
31b47888ceSAndrew Thompson /*
32b47888ceSAndrew Thompson  * IEEE802.3ad LACP
33b47888ceSAndrew Thompson  *
34b47888ceSAndrew Thompson  * implementation details.
35b47888ceSAndrew Thompson  */
36b47888ceSAndrew Thompson 
37b47888ceSAndrew Thompson #define	LACP_TIMER_CURRENT_WHILE	0
38b47888ceSAndrew Thompson #define	LACP_TIMER_PERIODIC		1
39b47888ceSAndrew Thompson #define	LACP_TIMER_WAIT_WHILE		2
40b47888ceSAndrew Thompson #define	LACP_NTIMER			3
41b47888ceSAndrew Thompson 
42b47888ceSAndrew Thompson #define	LACP_TIMER_ARM(port, timer, val) \
43b47888ceSAndrew Thompson 	(port)->lp_timer[(timer)] = (val)
44b47888ceSAndrew Thompson #define	LACP_TIMER_DISARM(port, timer) \
45b47888ceSAndrew Thompson 	(port)->lp_timer[(timer)] = 0
46b47888ceSAndrew Thompson #define	LACP_TIMER_ISARMED(port, timer) \
47b47888ceSAndrew Thompson 	((port)->lp_timer[(timer)] > 0)
48b47888ceSAndrew Thompson 
49b47888ceSAndrew Thompson /*
50b47888ceSAndrew Thompson  * IEEE802.3ad LACP
51b47888ceSAndrew Thompson  *
52b47888ceSAndrew Thompson  * protocol definitions.
53b47888ceSAndrew Thompson  */
54b47888ceSAndrew Thompson 
55b47888ceSAndrew Thompson #define	LACP_STATE_ACTIVITY	(1<<0)
56b47888ceSAndrew Thompson #define	LACP_STATE_TIMEOUT	(1<<1)
57b47888ceSAndrew Thompson #define	LACP_STATE_AGGREGATION	(1<<2)
58b47888ceSAndrew Thompson #define	LACP_STATE_SYNC		(1<<3)
59b47888ceSAndrew Thompson #define	LACP_STATE_COLLECTING	(1<<4)
60b47888ceSAndrew Thompson #define	LACP_STATE_DISTRIBUTING	(1<<5)
61b47888ceSAndrew Thompson #define	LACP_STATE_DEFAULTED	(1<<6)
62b47888ceSAndrew Thompson #define	LACP_STATE_EXPIRED	(1<<7)
63b47888ceSAndrew Thompson 
64b47888ceSAndrew Thompson #define	LACP_PORT_NTT		0x00000001
65998971a7SAndrew Thompson #define	LACP_PORT_MARK		0x00000002
66b47888ceSAndrew Thompson 
67b47888ceSAndrew Thompson #define	LACP_STATE_BITS		\
68b47888ceSAndrew Thompson 	"\020"			\
69b47888ceSAndrew Thompson 	"\001ACTIVITY"		\
70b47888ceSAndrew Thompson 	"\002TIMEOUT"		\
71b47888ceSAndrew Thompson 	"\003AGGREGATION"	\
72b47888ceSAndrew Thompson 	"\004SYNC"		\
73b47888ceSAndrew Thompson 	"\005COLLECTING"	\
74b47888ceSAndrew Thompson 	"\006DISTRIBUTING"	\
75b47888ceSAndrew Thompson 	"\007DEFAULTED"		\
76b47888ceSAndrew Thompson 	"\010EXPIRED"
77b47888ceSAndrew Thompson 
787eb756faSHiroki Sato #ifdef _KERNEL
79b47888ceSAndrew Thompson /*
80b47888ceSAndrew Thompson  * IEEE802.3 slow protocols
81b47888ceSAndrew Thompson  *
82b47888ceSAndrew Thompson  * protocol (on-wire) definitions.
83b47888ceSAndrew Thompson  *
84b47888ceSAndrew Thompson  * XXX should be elsewhere.
85b47888ceSAndrew Thompson  */
86b47888ceSAndrew Thompson 
87b47888ceSAndrew Thompson #define	SLOWPROTOCOLS_SUBTYPE_LACP	1
88b47888ceSAndrew Thompson #define	SLOWPROTOCOLS_SUBTYPE_MARKER	2
89b47888ceSAndrew Thompson 
90b47888ceSAndrew Thompson struct slowprothdr {
91b47888ceSAndrew Thompson 	uint8_t		sph_subtype;
92b47888ceSAndrew Thompson 	uint8_t		sph_version;
93b47888ceSAndrew Thompson } __packed;
94b47888ceSAndrew Thompson 
95b47888ceSAndrew Thompson /*
96b47888ceSAndrew Thompson  * TLV on-wire structure.
97b47888ceSAndrew Thompson  */
98b47888ceSAndrew Thompson 
99b47888ceSAndrew Thompson struct tlvhdr {
100b47888ceSAndrew Thompson 	uint8_t		tlv_type;
101b47888ceSAndrew Thompson 	uint8_t		tlv_length;
102b47888ceSAndrew Thompson 	/* uint8_t tlv_value[]; */
103b47888ceSAndrew Thompson } __packed;
104b47888ceSAndrew Thompson 
105b47888ceSAndrew Thompson /*
106b47888ceSAndrew Thompson  * ... and our implementation.
107b47888ceSAndrew Thompson  */
108b47888ceSAndrew Thompson 
109b47888ceSAndrew Thompson #define	TLV_SET(tlv, type, length) \
110b47888ceSAndrew Thompson 	do { \
111b47888ceSAndrew Thompson 		(tlv)->tlv_type = (type); \
112b47888ceSAndrew Thompson 		(tlv)->tlv_length = sizeof(*tlv) + (length); \
113b47888ceSAndrew Thompson 	} while (/*CONSTCOND*/0)
114b47888ceSAndrew Thompson 
115b47888ceSAndrew Thompson struct tlv_template {
116b47888ceSAndrew Thompson 	uint8_t			tmpl_type;
117b47888ceSAndrew Thompson 	uint8_t			tmpl_length;
118b47888ceSAndrew Thompson };
119b47888ceSAndrew Thompson 
120b47888ceSAndrew Thompson struct lacp_systemid {
121b47888ceSAndrew Thompson 	uint16_t		lsi_prio;
122b47888ceSAndrew Thompson 	uint8_t			lsi_mac[6];
123b47888ceSAndrew Thompson } __packed;
124b47888ceSAndrew Thompson 
125b47888ceSAndrew Thompson struct lacp_portid {
126b47888ceSAndrew Thompson 	uint16_t		lpi_prio;
127b47888ceSAndrew Thompson 	uint16_t		lpi_portno;
128b47888ceSAndrew Thompson } __packed;
129b47888ceSAndrew Thompson 
130b47888ceSAndrew Thompson struct lacp_peerinfo {
131b47888ceSAndrew Thompson 	struct lacp_systemid	lip_systemid;
132b47888ceSAndrew Thompson 	uint16_t		lip_key;
133b47888ceSAndrew Thompson 	struct lacp_portid	lip_portid;
134b47888ceSAndrew Thompson 	uint8_t			lip_state;
135b47888ceSAndrew Thompson 	uint8_t			lip_resv[3];
136b47888ceSAndrew Thompson } __packed;
137b47888ceSAndrew Thompson 
138b47888ceSAndrew Thompson struct lacp_collectorinfo {
139b47888ceSAndrew Thompson 	uint16_t		lci_maxdelay;
140b47888ceSAndrew Thompson 	uint8_t			lci_resv[12];
141b47888ceSAndrew Thompson } __packed;
142b47888ceSAndrew Thompson 
143b47888ceSAndrew Thompson struct lacpdu {
144b47888ceSAndrew Thompson 	struct ether_header	ldu_eh;
145b47888ceSAndrew Thompson 	struct slowprothdr	ldu_sph;
146b47888ceSAndrew Thompson 
147b47888ceSAndrew Thompson 	struct tlvhdr		ldu_tlv_actor;
148b47888ceSAndrew Thompson 	struct lacp_peerinfo	ldu_actor;
149b47888ceSAndrew Thompson 	struct tlvhdr		ldu_tlv_partner;
150b47888ceSAndrew Thompson 	struct lacp_peerinfo	ldu_partner;
151b47888ceSAndrew Thompson 	struct tlvhdr		ldu_tlv_collector;
152b47888ceSAndrew Thompson 	struct lacp_collectorinfo ldu_collector;
153b47888ceSAndrew Thompson 	struct tlvhdr		ldu_tlv_term;
154b47888ceSAndrew Thompson 	uint8_t			ldu_resv[50];
155b47888ceSAndrew Thompson } __packed;
156b47888ceSAndrew Thompson 
157998971a7SAndrew Thompson /*
158998971a7SAndrew Thompson  * IEEE802.3ad marker protocol
159998971a7SAndrew Thompson  *
160998971a7SAndrew Thompson  * protocol (on-wire) definitions.
161998971a7SAndrew Thompson  */
162998971a7SAndrew Thompson struct lacp_markerinfo {
163998971a7SAndrew Thompson 	uint16_t		mi_rq_port;
164998971a7SAndrew Thompson 	uint8_t			mi_rq_system[ETHER_ADDR_LEN];
165998971a7SAndrew Thompson 	uint32_t		mi_rq_xid;
166998971a7SAndrew Thompson 	uint8_t			mi_pad[2];
167998971a7SAndrew Thompson } __packed;
168998971a7SAndrew Thompson 
169998971a7SAndrew Thompson struct markerdu {
170998971a7SAndrew Thompson 	struct ether_header	mdu_eh;
171998971a7SAndrew Thompson 	struct slowprothdr	mdu_sph;
172998971a7SAndrew Thompson 
173998971a7SAndrew Thompson 	struct tlvhdr		mdu_tlv;
174998971a7SAndrew Thompson 	struct lacp_markerinfo	mdu_info;
175998971a7SAndrew Thompson 	struct tlvhdr		mdu_tlv_term;
176998971a7SAndrew Thompson 	uint8_t			mdu_resv[90];
177998971a7SAndrew Thompson } __packed;
178998971a7SAndrew Thompson 
179998971a7SAndrew Thompson #define	MARKER_TYPE_INFO	0x01
180998971a7SAndrew Thompson #define	MARKER_TYPE_RESPONSE	0x02
181b47888ceSAndrew Thompson 
182b47888ceSAndrew Thompson enum lacp_selected {
183b47888ceSAndrew Thompson 	LACP_UNSELECTED,
184b47888ceSAndrew Thompson 	LACP_STANDBY,	/* not used in this implementation */
185b47888ceSAndrew Thompson 	LACP_SELECTED,
186b47888ceSAndrew Thompson };
187b47888ceSAndrew Thompson 
188b47888ceSAndrew Thompson enum lacp_mux_state {
189b47888ceSAndrew Thompson 	LACP_MUX_DETACHED,
190b47888ceSAndrew Thompson 	LACP_MUX_WAITING,
191b47888ceSAndrew Thompson 	LACP_MUX_ATTACHED,
192b47888ceSAndrew Thompson 	LACP_MUX_COLLECTING,
193b47888ceSAndrew Thompson 	LACP_MUX_DISTRIBUTING,
194b47888ceSAndrew Thompson };
195b47888ceSAndrew Thompson 
1963de18008SAndrew Thompson #define	LACP_MAX_PORTS		32
1973de18008SAndrew Thompson 
19835961dceSAndrew Gallatin struct lacp_numa {
19935961dceSAndrew Gallatin 	int			count;
20035961dceSAndrew Gallatin 	struct lacp_port	*map[LACP_MAX_PORTS];
20135961dceSAndrew Gallatin };
20235961dceSAndrew Gallatin 
2033de18008SAndrew Thompson struct lacp_portmap {
2043de18008SAndrew Thompson 	int			pm_count;
20535961dceSAndrew Gallatin 	int			pm_num_dom;
20635961dceSAndrew Gallatin 	struct lacp_numa	pm_numa[MAXMEMDOM];
2073de18008SAndrew Thompson 	struct lacp_port	*pm_map[LACP_MAX_PORTS];
2083de18008SAndrew Thompson };
2093de18008SAndrew Thompson 
210b47888ceSAndrew Thompson struct lacp_port {
211b47888ceSAndrew Thompson 	TAILQ_ENTRY(lacp_port)	lp_dist_q;
212b47888ceSAndrew Thompson 	LIST_ENTRY(lacp_port)	lp_next;
213b47888ceSAndrew Thompson 	struct lacp_softc	*lp_lsc;
21418242d3bSAndrew Thompson 	struct lagg_port	*lp_lagg;
215b47888ceSAndrew Thompson 	struct ifnet		*lp_ifp;
216b47888ceSAndrew Thompson 	struct lacp_peerinfo	lp_partner;
217b47888ceSAndrew Thompson 	struct lacp_peerinfo	lp_actor;
218998971a7SAndrew Thompson 	struct lacp_markerinfo	lp_marker;
219b47888ceSAndrew Thompson #define	lp_state	lp_actor.lip_state
220b47888ceSAndrew Thompson #define	lp_key		lp_actor.lip_key
221998971a7SAndrew Thompson #define	lp_systemid	lp_actor.lip_systemid
222b47888ceSAndrew Thompson 	struct timeval		lp_last_lacpdu;
22300a80538SGreg Foster 	struct timeval		lp_last_lacpdu_rx;
224b47888ceSAndrew Thompson 	int			lp_lacpdu_sent;
225b47888ceSAndrew Thompson 	enum lacp_mux_state	lp_mux_state;
226b47888ceSAndrew Thompson 	enum lacp_selected	lp_selected;
227b47888ceSAndrew Thompson 	int			lp_flags;
228b47888ceSAndrew Thompson 	u_int			lp_media; /* XXX redundant */
229b47888ceSAndrew Thompson 	int			lp_timer[LACP_NTIMER];
230d74fd345SAndrew Thompson 	struct ifmultiaddr	*lp_ifma;
231b47888ceSAndrew Thompson 
232b47888ceSAndrew Thompson 	struct lacp_aggregator	*lp_aggregator;
233b47888ceSAndrew Thompson };
234b47888ceSAndrew Thompson 
235b47888ceSAndrew Thompson struct lacp_aggregator {
236b47888ceSAndrew Thompson 	TAILQ_ENTRY(lacp_aggregator)	la_q;
237b47888ceSAndrew Thompson 	int			la_refcnt; /* num of ports which selected us */
238b47888ceSAndrew Thompson 	int			la_nports; /* num of distributing ports  */
239b47888ceSAndrew Thompson 	TAILQ_HEAD(, lacp_port)	la_ports; /* distributing ports */
240b47888ceSAndrew Thompson 	struct lacp_peerinfo	la_partner;
241b47888ceSAndrew Thompson 	struct lacp_peerinfo	la_actor;
242ec32b37eSAndrew Thompson 	int			la_pending; /* number of ports in wait_while */
243b47888ceSAndrew Thompson };
244b47888ceSAndrew Thompson 
245b47888ceSAndrew Thompson struct lacp_softc {
246ec32b37eSAndrew Thompson 	struct lagg_softc	*lsc_softc;
2473de18008SAndrew Thompson 	struct mtx		lsc_mtx;
248b47888ceSAndrew Thompson 	struct lacp_aggregator	*lsc_active_aggregator;
249b47888ceSAndrew Thompson 	TAILQ_HEAD(, lacp_aggregator) lsc_aggregators;
250b47888ceSAndrew Thompson 	boolean_t		lsc_suppress_distributing;
251b47888ceSAndrew Thompson 	struct callout		lsc_transit_callout;
252b47888ceSAndrew Thompson 	struct callout		lsc_callout;
253b47888ceSAndrew Thompson 	LIST_HEAD(, lacp_port)	lsc_ports;
2543de18008SAndrew Thompson 	struct lacp_portmap	lsc_pmap[2];
2553de18008SAndrew Thompson 	volatile u_int		lsc_activemap;
256b47888ceSAndrew Thompson 	u_int32_t		lsc_hashkey;
25749de4f22SAdrian Chadd 	struct {
25849de4f22SAdrian Chadd 		u_int32_t	lsc_rx_test;
25949de4f22SAdrian Chadd 		u_int32_t	lsc_tx_test;
26049de4f22SAdrian Chadd 	} lsc_debug;
26149de4f22SAdrian Chadd 	u_int32_t		lsc_strict_mode;
2620e02b43aSHiren Panchasara 	boolean_t		lsc_fast_timeout; /* if set, fast timeout */
263b47888ceSAndrew Thompson };
264b47888ceSAndrew Thompson 
265b47888ceSAndrew Thompson #define	LACP_TYPE_ACTORINFO	1
266b47888ceSAndrew Thompson #define	LACP_TYPE_PARTNERINFO	2
267b47888ceSAndrew Thompson #define	LACP_TYPE_COLLECTORINFO	3
268b47888ceSAndrew Thompson 
269b47888ceSAndrew Thompson /* timeout values (in sec) */
270b47888ceSAndrew Thompson #define	LACP_FAST_PERIODIC_TIME		(1)
271b47888ceSAndrew Thompson #define	LACP_SLOW_PERIODIC_TIME		(30)
272b47888ceSAndrew Thompson #define	LACP_SHORT_TIMEOUT_TIME		(3 * LACP_FAST_PERIODIC_TIME)
273b47888ceSAndrew Thompson #define	LACP_LONG_TIMEOUT_TIME		(3 * LACP_SLOW_PERIODIC_TIME)
274b47888ceSAndrew Thompson #define	LACP_CHURN_DETECTION_TIME	(60)
275b47888ceSAndrew Thompson #define	LACP_AGGREGATE_WAIT_TIME	(2)
276998971a7SAndrew Thompson #define	LACP_TRANSIT_DELAY		3000	/* in msec */
277b47888ceSAndrew Thompson 
278b47888ceSAndrew Thompson #define	LACP_STATE_EQ(s1, s2, mask)	\
279b47888ceSAndrew Thompson 	((((s1) ^ (s2)) & (mask)) == 0)
280b47888ceSAndrew Thompson 
281fe45e65fSAndrew Thompson #define	LACP_SYS_PRI(peer)	(peer).lip_systemid.lsi_prio
282fe45e65fSAndrew Thompson 
28318242d3bSAndrew Thompson #define	LACP_PORT(_lp)	((struct lacp_port *)(_lp)->lp_psc)
28418242d3bSAndrew Thompson #define	LACP_SOFTC(_sc)	((struct lacp_softc *)(_sc)->sc_psc)
285b47888ceSAndrew Thompson 
2863de18008SAndrew Thompson #define LACP_LOCK_INIT(_lsc)		mtx_init(&(_lsc)->lsc_mtx, \
28769f04a82SAndrew Thompson 					    "lacp mtx", NULL, MTX_DEF)
28869f04a82SAndrew Thompson #define LACP_LOCK_DESTROY(_lsc)		mtx_destroy(&(_lsc)->lsc_mtx)
2893de18008SAndrew Thompson #define LACP_LOCK(_lsc)			mtx_lock(&(_lsc)->lsc_mtx)
2903de18008SAndrew Thompson #define LACP_UNLOCK(_lsc)		mtx_unlock(&(_lsc)->lsc_mtx)
2913de18008SAndrew Thompson #define LACP_LOCK_ASSERT(_lsc)		mtx_assert(&(_lsc)->lsc_mtx, MA_OWNED)
2923de18008SAndrew Thompson 
293af0084c9SAndrew Thompson struct mbuf	*lacp_input(struct lagg_port *, struct mbuf *);
2948732245dSAndrew Gallatin struct lagg_port *lacp_select_tx_port(struct lagg_softc *, struct mbuf *,
2958732245dSAndrew Gallatin     int *);
2968732245dSAndrew Gallatin struct lagg_port *lacp_select_tx_port_by_hash(struct lagg_softc *, uint32_t,
2978732245dSAndrew Gallatin     uint8_t, int *);
29809c7577eSGleb Smirnoff void		lacp_attach(struct lagg_softc *);
29909c7577eSGleb Smirnoff void		lacp_detach(void *);
30018242d3bSAndrew Thompson void		lacp_init(struct lagg_softc *);
30118242d3bSAndrew Thompson void		lacp_stop(struct lagg_softc *);
30218242d3bSAndrew Thompson int		lacp_port_create(struct lagg_port *);
30318242d3bSAndrew Thompson void		lacp_port_destroy(struct lagg_port *);
30418242d3bSAndrew Thompson void		lacp_linkstate(struct lagg_port *);
3056900d0d3SGleb Smirnoff void		lacp_req(struct lagg_softc *, void *);
3066900d0d3SGleb Smirnoff void		lacp_portreq(struct lagg_port *, void *);
307b47888ceSAndrew Thompson 
3085a8abd0aSZhenlei Huang static __inline bool
lacp_isactive(struct lagg_port * lgp)3093de18008SAndrew Thompson lacp_isactive(struct lagg_port *lgp)
3103de18008SAndrew Thompson {
3113de18008SAndrew Thompson 	struct lacp_port *lp = LACP_PORT(lgp);
3123de18008SAndrew Thompson 	struct lacp_softc *lsc = lp->lp_lsc;
3133de18008SAndrew Thompson 	struct lacp_aggregator *la = lp->lp_aggregator;
3143de18008SAndrew Thompson 
3153de18008SAndrew Thompson 	/* This port is joined to the active aggregator */
3165a8abd0aSZhenlei Huang 	return (la != NULL && la == lsc->lsc_active_aggregator);
3173de18008SAndrew Thompson }
3183de18008SAndrew Thompson 
3195a8abd0aSZhenlei Huang static __inline bool
lacp_iscollecting(struct lagg_port * lgp)3203de18008SAndrew Thompson lacp_iscollecting(struct lagg_port *lgp)
3213de18008SAndrew Thompson {
3223de18008SAndrew Thompson 	struct lacp_port *lp = LACP_PORT(lgp);
3233de18008SAndrew Thompson 
3245a8abd0aSZhenlei Huang 	return (lp->lp_state & LACP_STATE_COLLECTING);
3253de18008SAndrew Thompson }
3263de18008SAndrew Thompson 
3275a8abd0aSZhenlei Huang static __inline bool
lacp_isdistributing(struct lagg_port * lgp)3283de18008SAndrew Thompson lacp_isdistributing(struct lagg_port *lgp)
3293de18008SAndrew Thompson {
3303de18008SAndrew Thompson 	struct lacp_port *lp = LACP_PORT(lgp);
3313de18008SAndrew Thompson 
3325a8abd0aSZhenlei Huang 	return (lp->lp_state & LACP_STATE_DISTRIBUTING);
3333de18008SAndrew Thompson }
3343de18008SAndrew Thompson 
335b47888ceSAndrew Thompson /* following constants don't include terminating NUL */
336b47888ceSAndrew Thompson #define	LACP_MACSTR_MAX		(2*6 + 5)
337b47888ceSAndrew Thompson #define	LACP_SYSTEMPRIOSTR_MAX	(4)
338b47888ceSAndrew Thompson #define	LACP_SYSTEMIDSTR_MAX	(LACP_SYSTEMPRIOSTR_MAX + 1 + LACP_MACSTR_MAX)
339b47888ceSAndrew Thompson #define	LACP_PORTPRIOSTR_MAX	(4)
340b47888ceSAndrew Thompson #define	LACP_PORTNOSTR_MAX	(4)
341b47888ceSAndrew Thompson #define	LACP_PORTIDSTR_MAX	(LACP_PORTPRIOSTR_MAX + 1 + LACP_PORTNOSTR_MAX)
342b47888ceSAndrew Thompson #define	LACP_KEYSTR_MAX		(4)
343b47888ceSAndrew Thompson #define	LACP_PARTNERSTR_MAX	\
344b47888ceSAndrew Thompson 	(1 + LACP_SYSTEMIDSTR_MAX + 1 + LACP_KEYSTR_MAX + 1 \
345b47888ceSAndrew Thompson 	+ LACP_PORTIDSTR_MAX + 1)
346b47888ceSAndrew Thompson #define	LACP_LAGIDSTR_MAX	\
347b47888ceSAndrew Thompson 	(1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1)
348b47888ceSAndrew Thompson #define	LACP_STATESTR_MAX	(255) /* XXX */
3497eb756faSHiroki Sato #endif	/* _KERNEL */
350