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