if_lagg.h revision 272179
1/*	$OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk 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: head/sys/net/if_lagg.h 272179 2014-09-26 13:02:29Z glebius $
19 */
20
21#ifndef _NET_LAGG_H
22#define _NET_LAGG_H
23
24/*
25 * Global definitions
26 */
27
28#define	LAGG_MAX_PORTS		32	/* logically */
29#define	LAGG_MAX_NAMESIZE	32	/* name of a protocol */
30#define	LAGG_MAX_STACKING	4	/* maximum number of stacked laggs */
31
32/* Lagg flags */
33#define	LAGG_F_HASHL2		0x00000001	/* hash layer 2 */
34#define	LAGG_F_HASHL3		0x00000002	/* hash layer 3 */
35#define	LAGG_F_HASHL4		0x00000004	/* hash layer 4 */
36#define	LAGG_F_HASHMASK		0x00000007
37
38/* Port flags */
39#define	LAGG_PORT_SLAVE		0x00000000	/* normal enslaved port */
40#define	LAGG_PORT_MASTER	0x00000001	/* primary port */
41#define	LAGG_PORT_STACK		0x00000002	/* stacked lagg port */
42#define	LAGG_PORT_ACTIVE	0x00000004	/* port is active */
43#define	LAGG_PORT_COLLECTING	0x00000008	/* port is receiving frames */
44#define	LAGG_PORT_DISTRIBUTING	0x00000010	/* port is sending frames */
45#define	LAGG_PORT_DISABLED	0x00000020	/* port is disabled */
46#define	LAGG_PORT_BITS		"\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \
47				  "\05DISTRIBUTING\06DISABLED"
48
49/* Supported lagg PROTOs */
50typedef enum {
51	LAGG_PROTO_NONE = 0,	/* no lagg protocol defined */
52	LAGG_PROTO_ROUNDROBIN,	/* simple round robin */
53	LAGG_PROTO_FAILOVER,	/* active failover */
54	LAGG_PROTO_LOADBALANCE,	/* loadbalance */
55	LAGG_PROTO_LACP,	/* 802.3ad lacp */
56	LAGG_PROTO_ETHERCHANNEL,/* Cisco FEC */
57	LAGG_PROTO_BROADCAST,	/* broadcast */
58	LAGG_PROTO_MAX,
59} lagg_proto;
60
61struct lagg_protos {
62	const char		*lpr_name;
63	lagg_proto		lpr_proto;
64};
65
66#define	LAGG_PROTO_DEFAULT	LAGG_PROTO_FAILOVER
67#define LAGG_PROTOS	{						\
68	{ "failover",		LAGG_PROTO_FAILOVER },		\
69	{ "fec",		LAGG_PROTO_ETHERCHANNEL },		\
70	{ "lacp",		LAGG_PROTO_LACP },			\
71	{ "loadbalance",	LAGG_PROTO_LOADBALANCE },		\
72	{ "roundrobin",	LAGG_PROTO_ROUNDROBIN },		\
73	{ "broadcast",	LAGG_PROTO_BROADCAST },		\
74	{ "none",		LAGG_PROTO_NONE },			\
75	{ "default",		LAGG_PROTO_DEFAULT }			\
76}
77
78/*
79 * lagg ioctls.
80 */
81
82/*
83 * LACP current operational parameters structure.
84 */
85struct lacp_opreq {
86	uint16_t		actor_prio;
87	uint8_t			actor_mac[ETHER_ADDR_LEN];
88	uint16_t		actor_key;
89	uint16_t		actor_portprio;
90	uint16_t		actor_portno;
91	uint8_t			actor_state;
92	uint16_t		partner_prio;
93	uint8_t			partner_mac[ETHER_ADDR_LEN];
94	uint16_t		partner_key;
95	uint16_t		partner_portprio;
96	uint16_t		partner_portno;
97	uint8_t			partner_state;
98};
99
100/* lagg port settings */
101struct lagg_reqport {
102	char			rp_ifname[IFNAMSIZ];	/* name of the lagg */
103	char			rp_portname[IFNAMSIZ];	/* name of the port */
104	u_int32_t		rp_prio;		/* port priority */
105	u_int32_t		rp_flags;		/* port flags */
106	union {
107		struct lacp_opreq rpsc_lacp;
108	} rp_psc;
109#define rp_lacpreq	rp_psc.rpsc_lacp
110};
111
112#define	SIOCGLAGGPORT		_IOWR('i', 140, struct lagg_reqport)
113#define	SIOCSLAGGPORT		 _IOW('i', 141, struct lagg_reqport)
114#define	SIOCSLAGGDELPORT	 _IOW('i', 142, struct lagg_reqport)
115
116/* lagg, ports and options */
117struct lagg_reqall {
118	char			ra_ifname[IFNAMSIZ];	/* name of the lagg */
119	u_int			ra_proto;		/* lagg protocol */
120
121	size_t			ra_size;		/* size of buffer */
122	struct lagg_reqport	*ra_port;		/* allocated buffer */
123	int			ra_ports;		/* total port count */
124	union {
125		struct lacp_opreq rpsc_lacp;
126	} ra_psc;
127#define ra_lacpreq	ra_psc.rpsc_lacp
128};
129
130#define	SIOCGLAGG		_IOWR('i', 143, struct lagg_reqall)
131#define	SIOCSLAGG		 _IOW('i', 144, struct lagg_reqall)
132
133struct lagg_reqflags {
134	char			rf_ifname[IFNAMSIZ];	/* name of the lagg */
135	uint32_t		rf_flags;		/* lagg protocol */
136};
137
138#define	SIOCGLAGGFLAGS		_IOWR('i', 145, struct lagg_reqflags)
139#define	SIOCSLAGGHASH		 _IOW('i', 146, struct lagg_reqflags)
140
141#ifdef _KERNEL
142
143#include <sys/counter.h>
144
145/*
146 * Internal kernel part
147 */
148
149#define	LAGG_PORTACTIVE(_tp)	(					\
150	((_tp)->lp_ifp->if_link_state == LINK_STATE_UP) &&		\
151	((_tp)->lp_ifp->if_flags & IFF_UP)				\
152)
153
154struct lagg_ifreq {
155	union {
156		struct ifreq ifreq;
157		struct {
158			char ifr_name[IFNAMSIZ];
159			struct sockaddr_storage ifr_ss;
160		} ifreq_storage;
161	} ifreq;
162};
163
164#define	sc_ifflags		sc_ifp->if_flags		/* flags */
165#define	sc_ifname		sc_ifp->if_xname		/* name */
166#define	sc_capabilities		sc_ifp->if_capabilities	/* capabilities */
167
168#define	IFCAP_LAGG_MASK		0xffff0000	/* private capabilities */
169#define	IFCAP_LAGG_FULLDUPLEX	0x00010000	/* full duplex with >1 ports */
170
171/* Private data used by the loadbalancing protocol */
172struct lagg_lb {
173	u_int32_t		lb_key;
174	struct lagg_port	*lb_ports[LAGG_MAX_PORTS];
175};
176
177struct lagg_mc {
178	struct sockaddr_dl	mc_addr;
179	struct ifmultiaddr      *mc_ifma;
180	SLIST_ENTRY(lagg_mc)	mc_entries;
181};
182
183/* List of interfaces to have the MAC address modified */
184struct lagg_llq {
185	struct ifnet		*llq_ifp;
186	uint8_t			llq_lladdr[ETHER_ADDR_LEN];
187	SLIST_ENTRY(lagg_llq)	llq_entries;
188};
189
190struct lagg_softc {
191	struct ifnet			*sc_ifp;	/* virtual interface */
192	struct rmlock			sc_mtx;
193	struct mtx			sc_call_mtx;
194	int				sc_proto;	/* lagg protocol */
195	u_int				sc_count;	/* number of ports */
196	u_int				sc_active;	/* active port count */
197	u_int				sc_flapping;	/* number of flapping
198							 * events */
199	struct lagg_port		*sc_primary;	/* primary port */
200	struct ifmedia			sc_media;	/* media config */
201	void				*sc_psc;	/* protocol data */
202	uint32_t			sc_seq;		/* sequence counter */
203	uint32_t			sc_flags;
204
205	counter_u64_t			sc_ipackets;
206	counter_u64_t			sc_opackets;
207	counter_u64_t			sc_ibytes;
208	counter_u64_t			sc_obytes;
209
210	SLIST_HEAD(__tplhd, lagg_port)	sc_ports;	/* list of interfaces */
211	SLIST_ENTRY(lagg_softc)	sc_entries;
212
213	struct task			sc_lladdr_task;
214	SLIST_HEAD(__llqhd, lagg_llq)	sc_llq_head;	/* interfaces to program
215							   the lladdr on */
216	eventhandler_tag vlan_attach;
217	eventhandler_tag vlan_detach;
218	struct callout			sc_callout;
219	struct sysctl_ctx_list		ctx;		/* sysctl variables */
220	struct sysctl_oid		*sc_oid;	/* sysctl tree oid */
221	int				use_flowid;	/* use M_FLOWID */
222	int				flowid_shift;	/* shift the flowid */
223};
224
225struct lagg_port {
226	struct ifnet			*lp_ifp;	/* physical interface */
227	struct lagg_softc		*lp_softc;	/* parent lagg */
228	uint8_t				lp_lladdr[ETHER_ADDR_LEN];
229
230	u_char				lp_iftype;	/* interface type */
231	uint32_t			lp_prio;	/* port priority */
232	uint32_t			lp_flags;	/* port flags */
233	int				lp_ifflags;	/* saved ifp flags */
234	void				*lh_cookie;	/* if state hook */
235	void				*lp_psc;	/* protocol data */
236	int				lp_detaching;	/* ifnet is detaching */
237
238	SLIST_HEAD(__mclhd, lagg_mc)	lp_mc_head;	/* multicast addresses */
239
240	/* Redirected callbacks */
241	int	(*lp_ioctl)(struct ifnet *, u_long, caddr_t);
242	int	(*lp_output)(struct ifnet *, struct mbuf *,
243		     const struct sockaddr *, struct route *);
244
245	SLIST_ENTRY(lagg_port)		lp_entries;
246};
247
248#define	LAGG_LOCK_INIT(_sc)	rm_init(&(_sc)->sc_mtx, "if_lagg rmlock")
249#define	LAGG_LOCK_DESTROY(_sc)	rm_destroy(&(_sc)->sc_mtx)
250#define	LAGG_RLOCK(_sc, _p)	rm_rlock(&(_sc)->sc_mtx, (_p))
251#define	LAGG_WLOCK(_sc)		rm_wlock(&(_sc)->sc_mtx)
252#define	LAGG_RUNLOCK(_sc, _p)	rm_runlock(&(_sc)->sc_mtx, (_p))
253#define	LAGG_WUNLOCK(_sc)	rm_wunlock(&(_sc)->sc_mtx)
254#define	LAGG_RLOCK_ASSERT(_sc)	rm_assert(&(_sc)->sc_mtx, RA_RLOCKED)
255#define	LAGG_WLOCK_ASSERT(_sc)	rm_assert(&(_sc)->sc_mtx, RA_WLOCKED)
256
257#define	LAGG_CALLOUT_LOCK_INIT(_sc)					\
258	    mtx_init(&(_sc)->sc_call_mtx, "if_lagg callout mutex", NULL,\
259	    MTX_DEF)
260#define	LAGG_CALLOUT_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->sc_call_mtx)
261
262extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *);
263extern void	(*lagg_linkstate_p)(struct ifnet *, int );
264
265int		lagg_enqueue(struct ifnet *, struct mbuf *);
266uint32_t	lagg_hashmbuf(struct lagg_softc *, struct mbuf *, uint32_t);
267
268SYSCTL_DECL(_net_link_lagg);
269
270#endif /* _KERNEL */
271
272#endif /* _NET_LAGG_H */
273