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