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