if_lagg.h revision 169227
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 169227 2007-05-03 08:56:20Z thompsa $
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/* Port flags */
33#define LAGG_PORT_SLAVE		0x00000000	/* normal enslaved port */
34#define LAGG_PORT_MASTER	0x00000001	/* primary port */
35#define LAGG_PORT_STACK		0x00000002	/* stacked lagg port */
36#define LAGG_PORT_ACTIVE	0x00000004	/* port is active */
37#define LAGG_PORT_COLLECTING	0x00000008	/* port is active */
38#define LAGG_PORT_DISTRIBUTING	0x00000010	/* port is active */
39#define LAGG_PORT_DISABLED	0x00000020	/* port is disabled */
40#define LAGG_PORT_GLOBAL	0x80000000	/* IOCTL: global flag */
41#define LAGG_PORT_BITS		"\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \
42				  "\05DISTRIBUTING\06DISABLED"
43
44/* Supported lagg PROTOs */
45#define	LAGG_PROTO_NONE		0	/* no lagg protocol defined */
46#define	LAGG_PROTO_ROUNDROBIN	1	/* simple round robin */
47#define	LAGG_PROTO_FAILOVER	2	/* active failover */
48#define	LAGG_PROTO_LOADBALANCE	3	/* loadbalance */
49#define	LAGG_PROTO_LACP		4	/* 802.3ad lacp */
50#define	LAGG_PROTO_ETHERCHANNEL	5	/* Cisco FEC */
51#define	LAGG_PROTO_MAX		6
52
53struct lagg_protos {
54	const char		*tpr_name;
55	int			tpr_proto;
56};
57
58#define	LAGG_PROTO_DEFAULT	LAGG_PROTO_FAILOVER
59#define LAGG_PROTOS	{						\
60	{ "failover",		LAGG_PROTO_FAILOVER },			\
61	{ "fec",		LAGG_PROTO_ETHERCHANNEL },		\
62	{ "lacp",		LAGG_PROTO_LACP },			\
63	{ "loadbalance",	LAGG_PROTO_LOADBALANCE },		\
64	{ "roundrobin",		LAGG_PROTO_ROUNDROBIN },		\
65	{ "none",		LAGG_PROTO_NONE },			\
66	{ "default",		LAGG_PROTO_DEFAULT }			\
67}
68
69/*
70 * lagg ioctls.
71 */
72
73/* lagg port settings */
74struct lagg_reqport {
75	char			rp_ifname[IFNAMSIZ];	/* name of the lagg */
76	char			rp_portname[IFNAMSIZ];	/* name of the port */
77	u_int32_t		rp_prio;		/* port priority */
78	u_int32_t		rp_flags;		/* port flags */
79};
80
81#define SIOCGLAGGPORT		_IOWR('i', 140, struct lagg_reqport)
82#define SIOCSLAGGPORT		 _IOW('i', 141, struct lagg_reqport)
83#define SIOCSLAGGDELPORT	 _IOW('i', 142, struct lagg_reqport)
84
85/* lagg, ports and options */
86struct lagg_reqall {
87	char			ra_ifname[IFNAMSIZ];	/* name of the lagg */
88	u_int			ra_proto;		/* lagg protocol */
89
90	size_t			ra_size;		/* size of buffer */
91	struct lagg_reqport	*ra_port;		/* allocated buffer */
92	int			ra_ports;		/* total port count */
93};
94
95#define SIOCGLAGG		_IOWR('i', 143, struct lagg_reqall)
96#define SIOCSLAGG		 _IOW('i', 144, struct lagg_reqall)
97
98#ifdef _KERNEL
99/*
100 * Internal kernel part
101 */
102
103#define lp_ifname		lp_ifp->if_xname	/* interface name */
104#define lp_link_state		lp_ifp->if_link_state	/* link state */
105#define lp_capabilities		lp_ifp->if_capabilities	/* capabilities */
106
107#define LAGG_PORTACTIVE(_tp)	(					\
108	((_tp)->lp_link_state == LINK_STATE_UP) &&			\
109	((_tp)->lp_ifp->if_flags & IFF_UP)					\
110)
111
112#define mc_enm	mc_u.mcu_enm
113
114struct lagg_ifreq {
115	union {
116		struct ifreq ifreq;
117		struct {
118			char ifr_name[IFNAMSIZ];
119			struct sockaddr_storage ifr_ss;
120		} ifreq_storage;
121	} ifreq;
122};
123
124#define sc_ifflags		sc_ifp->if_flags		/* flags */
125#define sc_ifname		sc_ifp->if_xname		/* name */
126#define sc_capabilities		sc_ifp->if_capabilities	/* capabilities */
127
128#define IFCAP_LAGG_MASK		0xffff0000	/* private capabilities */
129#define IFCAP_LAGG_FULLDUPLEX	0x00010000	/* full duplex with >1 ports */
130
131/* Private data used by the loadbalancing protocol */
132#define LAGG_LB_MAXKEYS	8
133struct lagg_lb {
134	u_int32_t		lb_key;
135	struct lagg_port	*lb_ports[LAGG_MAX_PORTS];
136};
137
138struct lagg_mc {
139	union {
140		struct ether_multi	*mcu_enm;
141	} mc_u;
142	struct sockaddr_storage		mc_addr;
143
144	SLIST_ENTRY(lagg_mc)		mc_entries;
145};
146
147struct lagg_softc {
148	struct ifnet			*sc_ifp;	/* virtual interface */
149	struct mtx			sc_mtx;
150	int				sc_proto;	/* lagg protocol */
151	u_int				sc_count;	/* number of ports */
152	struct lagg_port		*sc_primary;	/* primary port */
153	struct ifmedia			sc_media;	/* media config */
154	caddr_t				sc_psc;		/* protocol data */
155
156	SLIST_HEAD(__tplhd, lagg_port)	sc_ports;	/* list of interfaces */
157	SLIST_ENTRY(lagg_softc)	sc_entries;
158
159	SLIST_HEAD(__mclhd, lagg_mc)	sc_mc_head;	/* multicast addresses */
160
161	/* lagg protocol callbacks */
162	int	(*sc_detach)(struct lagg_softc *);
163	int	(*sc_start)(struct lagg_softc *, struct mbuf *);
164	struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *,
165		    struct mbuf *);
166	int	(*sc_port_create)(struct lagg_port *);
167	void	(*sc_port_destroy)(struct lagg_port *);
168	void	(*sc_linkstate)(struct lagg_port *);
169	void	(*sc_init)(struct lagg_softc *);
170	void	(*sc_stop)(struct lagg_softc *);
171	void	(*sc_lladdr)(struct lagg_softc *);
172};
173
174struct lagg_port {
175	struct ifnet			*lp_ifp;	/* physical interface */
176	struct lagg_softc		*lp_lagg;	/* parent lagg */
177	uint8_t				lp_lladdr[ETHER_ADDR_LEN];
178
179	u_char				lp_iftype;	/* interface type */
180	uint32_t			lp_prio;	/* port priority */
181	uint32_t			lp_flags;	/* port flags */
182	int				lp_ifflags;	/* saved ifp flags */
183	void				*lh_cookie;	/* if state hook */
184	caddr_t				lp_psc;		/* protocol data */
185
186	/* Redirected callbacks */
187	int	(*lp_ioctl)(struct ifnet *, u_long, caddr_t);
188	int	(*lp_output)(struct ifnet *, struct mbuf *, struct sockaddr *,
189		     struct rtentry *);
190
191	SLIST_ENTRY(lagg_port)		lp_entries;
192};
193
194#define LAGG_LOCK_INIT(_tr)	mtx_init(&(_tr)->sc_mtx, "if_lagg", NULL, \
195				    MTX_DEF)
196#define LAGG_LOCK_DESTROY(_tr)	mtx_destroy(&(_tr)->sc_mtx)
197#define LAGG_LOCK(_tr)		mtx_lock(&(_tr)->sc_mtx)
198#define LAGG_UNLOCK(_tr)	mtx_unlock(&(_tr)->sc_mtx)
199#define LAGG_LOCKED(_tr)	mtx_owned(&(_tr)->sc_mtx)
200#define LAGG_LOCK_ASSERT(_tr)	mtx_assert(&(_tr)->sc_mtx, MA_OWNED)
201
202extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *);
203extern void	(*lagg_linkstate_p)(struct ifnet *, int );
204
205int		lagg_enqueue(struct ifnet *, struct mbuf *);
206uint32_t	lagg_hashmbuf(struct mbuf *, uint32_t);
207
208#endif /* _KERNEL */
209
210#endif /* _NET_LAGG_H */
211