summaryrefslogtreecommitdiffstats
path: root/sys/net/if_lagg.h
blob: 716a2b749aea1bfaa7784418ae617348bf94e6ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*	$OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $	*/

/*
 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * $FreeBSD$
 */

#ifndef _NET_LAGG_H
#define _NET_LAGG_H

/*
 * Global definitions
 */

#define LAGG_MAX_PORTS		32	/* logically */
#define LAGG_MAX_NAMESIZE	32	/* name of a protocol */
#define LAGG_MAX_STACKING	4	/* maximum number of stacked laggs */

/* Port flags */
#define LAGG_PORT_SLAVE		0x00000000	/* normal enslaved port */
#define LAGG_PORT_MASTER	0x00000001	/* primary port */
#define LAGG_PORT_STACK		0x00000002	/* stacked lagg port */
#define LAGG_PORT_ACTIVE	0x00000004	/* port is active */
#define LAGG_PORT_COLLECTING	0x00000008	/* port is active */
#define LAGG_PORT_DISTRIBUTING	0x00000010	/* port is active */
#define LAGG_PORT_GLOBAL	0x80000000	/* IOCTL: global flag */
#define LAGG_PORT_BITS		"\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \
				  "\05DISTRIBUTING"

/* Supported lagg PROTOs */
#define	LAGG_PROTO_NONE		0	/* no lagg protocol defined */
#define	LAGG_PROTO_ROUNDROBIN	1	/* simple round robin */
#define	LAGG_PROTO_FAILOVER	2	/* active failover */
#define	LAGG_PROTO_LOADBALANCE	3	/* loadbalance */
#define	LAGG_PROTO_LACP		4	/* 802.3ad lacp */
#define	LAGG_PROTO_ETHERCHANNEL	5	/* Cisco FEC */
#define	LAGG_PROTO_MAX		6

struct lagg_protos {
	const char		*tpr_name;
	int			tpr_proto;
};

#define	LAGG_PROTO_DEFAULT	LAGG_PROTO_FAILOVER
#define LAGG_PROTOS	{						\
	{ "failover",		LAGG_PROTO_FAILOVER },			\
	{ "fec",		LAGG_PROTO_ETHERCHANNEL },		\
	{ "lacp",		LAGG_PROTO_LACP },			\
	{ "loadbalance",	LAGG_PROTO_LOADBALANCE },		\
	{ "roundrobin",		LAGG_PROTO_ROUNDROBIN },		\
	{ "none",		LAGG_PROTO_NONE },			\
	{ "default",		LAGG_PROTO_DEFAULT }			\
}

/*
 * lagg ioctls.
 */

/* lagg port settings */
struct lagg_reqport {
	char			rp_ifname[IFNAMSIZ];	/* name of the lagg */
	char			rp_portname[IFNAMSIZ];	/* name of the port */
	u_int32_t		rp_prio;		/* port priority */
	u_int32_t		rp_flags;		/* port flags */
};

#define SIOCGLAGGPORT		_IOWR('i', 140, struct lagg_reqport)
#define SIOCSLAGGPORT		 _IOW('i', 141, struct lagg_reqport)
#define SIOCSLAGGDELPORT	 _IOW('i', 142, struct lagg_reqport)

/* lagg, ports and options */
struct lagg_reqall {
	char			ra_ifname[IFNAMSIZ];	/* name of the lagg */
	u_int			ra_proto;		/* lagg protocol */

	size_t			ra_size;		/* size of buffer */
	struct lagg_reqport	*ra_port;		/* allocated buffer */
	int			ra_ports;		/* total port count */
};

#define SIOCGLAGG		_IOWR('i', 143, struct lagg_reqall)
#define SIOCSLAGG		 _IOW('i', 144, struct lagg_reqall)

#ifdef _KERNEL
/*
 * Internal kernel part
 */

#define lp_ifname		lp_ifp->if_xname	/* interface name */
#define lp_link_state		lp_ifp->if_link_state	/* link state */
#define lp_capabilities		lp_ifp->if_capabilities	/* capabilities */

#define LAGG_PORTACTIVE(_tp)	(					\
	((_tp)->lp_link_state == LINK_STATE_UP) &&			\
	((_tp)->lp_ifp->if_flags & IFF_UP)					\
)

#define mc_enm	mc_u.mcu_enm

struct lagg_ifreq {
	union {
		struct ifreq ifreq;
		struct {
			char ifr_name[IFNAMSIZ];
			struct sockaddr_storage ifr_ss;
		} ifreq_storage;
	} ifreq;
};

#define sc_ifflags		sc_ifp->if_flags		/* flags */
#define sc_ifname		sc_ifp->if_xname		/* name */
#define sc_capabilities		sc_ifp->if_capabilities	/* capabilities */

#define IFCAP_LAGG_MASK		0xffff0000	/* private capabilities */
#define IFCAP_LAGG_FULLDUPLEX	0x00010000	/* full duplex with >1 ports */

/* Private data used by the loadbalancing protocol */
#define LAGG_LB_MAXKEYS	8
struct lagg_lb {
	u_int32_t		lb_key;
	struct lagg_port	*lb_ports[LAGG_MAX_PORTS];
};

struct lagg_mc {
	union {
		struct ether_multi	*mcu_enm;
	} mc_u;
	struct sockaddr_storage		mc_addr;

	SLIST_ENTRY(lagg_mc)		mc_entries;
};

struct lagg_softc {
	struct ifnet			*sc_ifp;	/* virtual interface */
	struct mtx			sc_mtx;
	int				sc_proto;	/* lagg protocol */
	u_int				sc_count;	/* number of ports */
	struct lagg_port		*sc_primary;	/* primary port */
	struct ifmedia			sc_media;	/* media config */
	caddr_t				sc_psc;		/* protocol data */

	SLIST_HEAD(__tplhd, lagg_port)	sc_ports;	/* list of interfaces */
	SLIST_ENTRY(lagg_softc)	sc_entries;

	SLIST_HEAD(__mclhd, lagg_mc)	sc_mc_head;	/* multicast addresses */

	/* lagg protocol callbacks */
	int	(*sc_detach)(struct lagg_softc *);
	int	(*sc_start)(struct lagg_softc *, struct mbuf *);
	struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *,
		    struct mbuf *);
	int	(*sc_port_create)(struct lagg_port *);
	void	(*sc_port_destroy)(struct lagg_port *);
	void	(*sc_linkstate)(struct lagg_port *);
	void	(*sc_init)(struct lagg_softc *);
	void	(*sc_stop)(struct lagg_softc *);
	void	(*sc_lladdr)(struct lagg_softc *);
};

struct lagg_port {
	struct ifnet			*lp_ifp;	/* physical interface */
	struct lagg_softc		*lp_lagg;	/* parent lagg */
	uint8_t				lp_lladdr[ETHER_ADDR_LEN];

	u_char				lp_iftype;	/* interface type */
	uint32_t			lp_prio;	/* port priority */
	uint32_t			lp_flags;	/* port flags */
	int				lp_ifflags;	/* saved ifp flags */
	void				*lh_cookie;	/* if state hook */
	caddr_t				lp_psc;		/* protocol data */

	/* Redirected callbacks */
	int	(*lp_ioctl)(struct ifnet *, u_long, caddr_t);
	int	(*lp_output)(struct ifnet *, struct mbuf *, struct sockaddr *,
		     struct rtentry *);

	SLIST_ENTRY(lagg_port)		lp_entries;
};

#define LAGG_LOCK_INIT(_tr)	mtx_init(&(_tr)->sc_mtx, "if_lagg", NULL, \
				    MTX_DEF)
#define LAGG_LOCK_DESTROY(_tr)	mtx_destroy(&(_tr)->sc_mtx)
#define LAGG_LOCK(_tr)		mtx_lock(&(_tr)->sc_mtx)
#define LAGG_UNLOCK(_tr)	mtx_unlock(&(_tr)->sc_mtx)
#define LAGG_LOCKED(_tr)	mtx_owned(&(_tr)->sc_mtx)
#define LAGG_LOCK_ASSERT(_tr)	mtx_assert(&(_tr)->sc_mtx, MA_OWNED)

extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *);
extern void	(*lagg_linkstate_p)(struct ifnet *, int );

int		lagg_enqueue(struct ifnet *, struct mbuf *);
uint32_t	lagg_hashmbuf(struct mbuf *, uint32_t);

#endif /* _KERNEL */

#endif /* _NET_LAGG_H */
OpenPOWER on IntegriCloud