xref: /freebsd/sys/net/if_lagg.h (revision ff6c5cf6)
118242d3bSAndrew Thompson /*	$OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $	*/
218242d3bSAndrew Thompson 
318242d3bSAndrew Thompson /*
418242d3bSAndrew Thompson  * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
518242d3bSAndrew Thompson  *
618242d3bSAndrew Thompson  * Permission to use, copy, modify, and distribute this software for any
718242d3bSAndrew Thompson  * purpose with or without fee is hereby granted, provided that the above
818242d3bSAndrew Thompson  * copyright notice and this permission notice appear in all copies.
918242d3bSAndrew Thompson  *
1018242d3bSAndrew Thompson  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1118242d3bSAndrew Thompson  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1218242d3bSAndrew Thompson  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1318242d3bSAndrew Thompson  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1418242d3bSAndrew Thompson  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1518242d3bSAndrew Thompson  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1618242d3bSAndrew Thompson  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1718242d3bSAndrew Thompson  *
1818242d3bSAndrew Thompson  * $FreeBSD$
1918242d3bSAndrew Thompson  */
2018242d3bSAndrew Thompson 
2118242d3bSAndrew Thompson #ifndef _NET_LAGG_H
2218242d3bSAndrew Thompson #define _NET_LAGG_H
2318242d3bSAndrew Thompson 
2418242d3bSAndrew Thompson /*
2518242d3bSAndrew Thompson  * Global definitions
2618242d3bSAndrew Thompson  */
2718242d3bSAndrew Thompson 
2818242d3bSAndrew Thompson #define LAGG_MAX_PORTS		32	/* logically */
2918242d3bSAndrew Thompson #define LAGG_MAX_NAMESIZE	32	/* name of a protocol */
3018242d3bSAndrew Thompson #define LAGG_MAX_STACKING	4	/* maximum number of stacked laggs */
3118242d3bSAndrew Thompson 
3218242d3bSAndrew Thompson /* Port flags */
3318242d3bSAndrew Thompson #define LAGG_PORT_SLAVE		0x00000000	/* normal enslaved port */
3418242d3bSAndrew Thompson #define LAGG_PORT_MASTER	0x00000001	/* primary port */
3518242d3bSAndrew Thompson #define LAGG_PORT_STACK		0x00000002	/* stacked lagg port */
3618242d3bSAndrew Thompson #define LAGG_PORT_ACTIVE	0x00000004	/* port is active */
37ff6c5cf6SAndrew Thompson #define LAGG_PORT_COLLECTING	0x00000008	/* port is receiving frames */
38ff6c5cf6SAndrew Thompson #define LAGG_PORT_DISTRIBUTING	0x00000010	/* port is sending frames */
39e3163ef6SAndrew Thompson #define LAGG_PORT_DISABLED	0x00000020	/* port is disabled */
4018242d3bSAndrew Thompson #define LAGG_PORT_GLOBAL	0x80000000	/* IOCTL: global flag */
4118242d3bSAndrew Thompson #define LAGG_PORT_BITS		"\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \
42e3163ef6SAndrew Thompson 				  "\05DISTRIBUTING\06DISABLED"
4318242d3bSAndrew Thompson 
4418242d3bSAndrew Thompson /* Supported lagg PROTOs */
4518242d3bSAndrew Thompson #define	LAGG_PROTO_NONE		0	/* no lagg protocol defined */
4618242d3bSAndrew Thompson #define	LAGG_PROTO_ROUNDROBIN	1	/* simple round robin */
4718242d3bSAndrew Thompson #define	LAGG_PROTO_FAILOVER	2	/* active failover */
4818242d3bSAndrew Thompson #define	LAGG_PROTO_LOADBALANCE	3	/* loadbalance */
4918242d3bSAndrew Thompson #define	LAGG_PROTO_LACP		4	/* 802.3ad lacp */
5018242d3bSAndrew Thompson #define	LAGG_PROTO_ETHERCHANNEL	5	/* Cisco FEC */
5118242d3bSAndrew Thompson #define	LAGG_PROTO_MAX		6
5218242d3bSAndrew Thompson 
5318242d3bSAndrew Thompson struct lagg_protos {
5418242d3bSAndrew Thompson 	const char		*tpr_name;
5518242d3bSAndrew Thompson 	int			tpr_proto;
5618242d3bSAndrew Thompson };
5718242d3bSAndrew Thompson 
5818242d3bSAndrew Thompson #define	LAGG_PROTO_DEFAULT	LAGG_PROTO_FAILOVER
5918242d3bSAndrew Thompson #define LAGG_PROTOS	{						\
6018242d3bSAndrew Thompson 	{ "failover",		LAGG_PROTO_FAILOVER },			\
6118242d3bSAndrew Thompson 	{ "fec",		LAGG_PROTO_ETHERCHANNEL },		\
6218242d3bSAndrew Thompson 	{ "lacp",		LAGG_PROTO_LACP },			\
6318242d3bSAndrew Thompson 	{ "loadbalance",	LAGG_PROTO_LOADBALANCE },		\
6418242d3bSAndrew Thompson 	{ "roundrobin",		LAGG_PROTO_ROUNDROBIN },		\
6518242d3bSAndrew Thompson 	{ "none",		LAGG_PROTO_NONE },			\
6618242d3bSAndrew Thompson 	{ "default",		LAGG_PROTO_DEFAULT }			\
6718242d3bSAndrew Thompson }
6818242d3bSAndrew Thompson 
6918242d3bSAndrew Thompson /*
7018242d3bSAndrew Thompson  * lagg ioctls.
7118242d3bSAndrew Thompson  */
7218242d3bSAndrew Thompson 
7318242d3bSAndrew Thompson /* lagg port settings */
7418242d3bSAndrew Thompson struct lagg_reqport {
7518242d3bSAndrew Thompson 	char			rp_ifname[IFNAMSIZ];	/* name of the lagg */
7618242d3bSAndrew Thompson 	char			rp_portname[IFNAMSIZ];	/* name of the port */
7718242d3bSAndrew Thompson 	u_int32_t		rp_prio;		/* port priority */
7818242d3bSAndrew Thompson 	u_int32_t		rp_flags;		/* port flags */
7918242d3bSAndrew Thompson };
8018242d3bSAndrew Thompson 
8118242d3bSAndrew Thompson #define SIOCGLAGGPORT		_IOWR('i', 140, struct lagg_reqport)
8218242d3bSAndrew Thompson #define SIOCSLAGGPORT		 _IOW('i', 141, struct lagg_reqport)
8318242d3bSAndrew Thompson #define SIOCSLAGGDELPORT	 _IOW('i', 142, struct lagg_reqport)
8418242d3bSAndrew Thompson 
8518242d3bSAndrew Thompson /* lagg, ports and options */
8618242d3bSAndrew Thompson struct lagg_reqall {
8718242d3bSAndrew Thompson 	char			ra_ifname[IFNAMSIZ];	/* name of the lagg */
8818242d3bSAndrew Thompson 	u_int			ra_proto;		/* lagg protocol */
8918242d3bSAndrew Thompson 
9018242d3bSAndrew Thompson 	size_t			ra_size;		/* size of buffer */
9118242d3bSAndrew Thompson 	struct lagg_reqport	*ra_port;		/* allocated buffer */
9218242d3bSAndrew Thompson 	int			ra_ports;		/* total port count */
9318242d3bSAndrew Thompson };
9418242d3bSAndrew Thompson 
9518242d3bSAndrew Thompson #define SIOCGLAGG		_IOWR('i', 143, struct lagg_reqall)
9618242d3bSAndrew Thompson #define SIOCSLAGG		 _IOW('i', 144, struct lagg_reqall)
9718242d3bSAndrew Thompson 
9818242d3bSAndrew Thompson #ifdef _KERNEL
9918242d3bSAndrew Thompson /*
10018242d3bSAndrew Thompson  * Internal kernel part
10118242d3bSAndrew Thompson  */
10218242d3bSAndrew Thompson 
10318242d3bSAndrew Thompson #define lp_ifname		lp_ifp->if_xname	/* interface name */
10418242d3bSAndrew Thompson #define lp_link_state		lp_ifp->if_link_state	/* link state */
10518242d3bSAndrew Thompson #define lp_capabilities		lp_ifp->if_capabilities	/* capabilities */
10618242d3bSAndrew Thompson 
10718242d3bSAndrew Thompson #define LAGG_PORTACTIVE(_tp)	(					\
10818242d3bSAndrew Thompson 	((_tp)->lp_link_state == LINK_STATE_UP) &&			\
10918242d3bSAndrew Thompson 	((_tp)->lp_ifp->if_flags & IFF_UP)					\
11018242d3bSAndrew Thompson )
11118242d3bSAndrew Thompson 
11218242d3bSAndrew Thompson #define mc_enm	mc_u.mcu_enm
11318242d3bSAndrew Thompson 
11418242d3bSAndrew Thompson struct lagg_ifreq {
11518242d3bSAndrew Thompson 	union {
11618242d3bSAndrew Thompson 		struct ifreq ifreq;
11718242d3bSAndrew Thompson 		struct {
11818242d3bSAndrew Thompson 			char ifr_name[IFNAMSIZ];
11918242d3bSAndrew Thompson 			struct sockaddr_storage ifr_ss;
12018242d3bSAndrew Thompson 		} ifreq_storage;
12118242d3bSAndrew Thompson 	} ifreq;
12218242d3bSAndrew Thompson };
12318242d3bSAndrew Thompson 
12418242d3bSAndrew Thompson #define sc_ifflags		sc_ifp->if_flags		/* flags */
12518242d3bSAndrew Thompson #define sc_ifname		sc_ifp->if_xname		/* name */
12618242d3bSAndrew Thompson #define sc_capabilities		sc_ifp->if_capabilities	/* capabilities */
12718242d3bSAndrew Thompson 
12818242d3bSAndrew Thompson #define IFCAP_LAGG_MASK		0xffff0000	/* private capabilities */
12918242d3bSAndrew Thompson #define IFCAP_LAGG_FULLDUPLEX	0x00010000	/* full duplex with >1 ports */
13018242d3bSAndrew Thompson 
13118242d3bSAndrew Thompson /* Private data used by the loadbalancing protocol */
13218242d3bSAndrew Thompson #define LAGG_LB_MAXKEYS	8
13318242d3bSAndrew Thompson struct lagg_lb {
13418242d3bSAndrew Thompson 	u_int32_t		lb_key;
13518242d3bSAndrew Thompson 	struct lagg_port	*lb_ports[LAGG_MAX_PORTS];
13618242d3bSAndrew Thompson };
13718242d3bSAndrew Thompson 
13818242d3bSAndrew Thompson struct lagg_mc {
13918242d3bSAndrew Thompson 	union {
14018242d3bSAndrew Thompson 		struct ether_multi	*mcu_enm;
14118242d3bSAndrew Thompson 	} mc_u;
14218242d3bSAndrew Thompson 	struct sockaddr_storage		mc_addr;
14318242d3bSAndrew Thompson 
14418242d3bSAndrew Thompson 	SLIST_ENTRY(lagg_mc)		mc_entries;
14518242d3bSAndrew Thompson };
14618242d3bSAndrew Thompson 
14718242d3bSAndrew Thompson struct lagg_softc {
14818242d3bSAndrew Thompson 	struct ifnet			*sc_ifp;	/* virtual interface */
14918242d3bSAndrew Thompson 	struct mtx			sc_mtx;
15018242d3bSAndrew Thompson 	int				sc_proto;	/* lagg protocol */
15118242d3bSAndrew Thompson 	u_int				sc_count;	/* number of ports */
15218242d3bSAndrew Thompson 	struct lagg_port		*sc_primary;	/* primary port */
15318242d3bSAndrew Thompson 	struct ifmedia			sc_media;	/* media config */
15418242d3bSAndrew Thompson 	caddr_t				sc_psc;		/* protocol data */
15518242d3bSAndrew Thompson 
15618242d3bSAndrew Thompson 	SLIST_HEAD(__tplhd, lagg_port)	sc_ports;	/* list of interfaces */
15718242d3bSAndrew Thompson 	SLIST_ENTRY(lagg_softc)	sc_entries;
15818242d3bSAndrew Thompson 
15918242d3bSAndrew Thompson 	SLIST_HEAD(__mclhd, lagg_mc)	sc_mc_head;	/* multicast addresses */
16018242d3bSAndrew Thompson 
16118242d3bSAndrew Thompson 	/* lagg protocol callbacks */
16218242d3bSAndrew Thompson 	int	(*sc_detach)(struct lagg_softc *);
16318242d3bSAndrew Thompson 	int	(*sc_start)(struct lagg_softc *, struct mbuf *);
16418242d3bSAndrew Thompson 	struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *,
16518242d3bSAndrew Thompson 		    struct mbuf *);
16618242d3bSAndrew Thompson 	int	(*sc_port_create)(struct lagg_port *);
16718242d3bSAndrew Thompson 	void	(*sc_port_destroy)(struct lagg_port *);
16818242d3bSAndrew Thompson 	void	(*sc_linkstate)(struct lagg_port *);
16918242d3bSAndrew Thompson 	void	(*sc_init)(struct lagg_softc *);
17018242d3bSAndrew Thompson 	void	(*sc_stop)(struct lagg_softc *);
17118242d3bSAndrew Thompson 	void	(*sc_lladdr)(struct lagg_softc *);
17218242d3bSAndrew Thompson };
17318242d3bSAndrew Thompson 
17418242d3bSAndrew Thompson struct lagg_port {
17518242d3bSAndrew Thompson 	struct ifnet			*lp_ifp;	/* physical interface */
17618242d3bSAndrew Thompson 	struct lagg_softc		*lp_lagg;	/* parent lagg */
17718242d3bSAndrew Thompson 	uint8_t				lp_lladdr[ETHER_ADDR_LEN];
17818242d3bSAndrew Thompson 
17918242d3bSAndrew Thompson 	u_char				lp_iftype;	/* interface type */
18018242d3bSAndrew Thompson 	uint32_t			lp_prio;	/* port priority */
18118242d3bSAndrew Thompson 	uint32_t			lp_flags;	/* port flags */
18218242d3bSAndrew Thompson 	int				lp_ifflags;	/* saved ifp flags */
18318242d3bSAndrew Thompson 	void				*lh_cookie;	/* if state hook */
18418242d3bSAndrew Thompson 	caddr_t				lp_psc;		/* protocol data */
18518242d3bSAndrew Thompson 
18618242d3bSAndrew Thompson 	/* Redirected callbacks */
18718242d3bSAndrew Thompson 	int	(*lp_ioctl)(struct ifnet *, u_long, caddr_t);
18818242d3bSAndrew Thompson 	int	(*lp_output)(struct ifnet *, struct mbuf *, struct sockaddr *,
18918242d3bSAndrew Thompson 		     struct rtentry *);
19018242d3bSAndrew Thompson 
19118242d3bSAndrew Thompson 	SLIST_ENTRY(lagg_port)		lp_entries;
19218242d3bSAndrew Thompson };
19318242d3bSAndrew Thompson 
19418242d3bSAndrew Thompson #define LAGG_LOCK_INIT(_tr)	mtx_init(&(_tr)->sc_mtx, "if_lagg", NULL, \
19518242d3bSAndrew Thompson 				    MTX_DEF)
19618242d3bSAndrew Thompson #define LAGG_LOCK_DESTROY(_tr)	mtx_destroy(&(_tr)->sc_mtx)
19718242d3bSAndrew Thompson #define LAGG_LOCK(_tr)		mtx_lock(&(_tr)->sc_mtx)
19818242d3bSAndrew Thompson #define LAGG_UNLOCK(_tr)	mtx_unlock(&(_tr)->sc_mtx)
19918242d3bSAndrew Thompson #define LAGG_LOCKED(_tr)	mtx_owned(&(_tr)->sc_mtx)
20018242d3bSAndrew Thompson #define LAGG_LOCK_ASSERT(_tr)	mtx_assert(&(_tr)->sc_mtx, MA_OWNED)
20118242d3bSAndrew Thompson 
20218242d3bSAndrew Thompson extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *);
20318242d3bSAndrew Thompson extern void	(*lagg_linkstate_p)(struct ifnet *, int );
20418242d3bSAndrew Thompson 
20518242d3bSAndrew Thompson int		lagg_enqueue(struct ifnet *, struct mbuf *);
20618242d3bSAndrew Thompson uint32_t	lagg_hashmbuf(struct mbuf *, uint32_t);
20718242d3bSAndrew Thompson 
20818242d3bSAndrew Thompson #endif /* _KERNEL */
20918242d3bSAndrew Thompson 
21018242d3bSAndrew Thompson #endif /* _NET_LAGG_H */
211