1 /* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $
2 * $FreeBSD: head/sys/net/if_lagg.h 255038 2013-08-29 19:35:14Z adrian $
6 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 #include <net/ethernet.h>
27 #include <net/route.h>
33 #define LAGG_MAX_PORTS 32 /* logically */
34 #define LAGG_MAX_NAMESIZE 32 /* name of a protocol */
35 #define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */
38 #define LAGG_F_HASHL2 0x00000001 /* hash layer 2 */
39 #define LAGG_F_HASHL3 0x00000002 /* hash layer 3 */
40 #define LAGG_F_HASHL4 0x00000004 /* hash layer 4 */
41 #define LAGG_F_HASHMASK 0x00000007
44 #define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */
45 #define LAGG_PORT_MASTER 0x00000001 /* primary port */
46 #define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */
47 #define LAGG_PORT_ACTIVE 0x00000004 /* port is active */
48 #define LAGG_PORT_COLLECTING 0x00000008 /* port is receiving frames */
49 #define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */
50 #define LAGG_PORT_DISABLED 0x00000020 /* port is disabled */
51 #define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \
52 "\05DISTRIBUTING\06DISABLED"
54 /* Supported lagg PROTOs */
55 #define LAGG_PROTO_NONE 0 /* no lagg protocol defined */
56 #define LAGG_PROTO_ROUNDROBIN 1 /* simple round robin */
57 #define LAGG_PROTO_FAILOVER 2 /* active failover */
58 #define LAGG_PROTO_LOADBALANCE 3 /* loadbalance */
59 #define LAGG_PROTO_LACP 4 /* 802.3ad lacp */
60 #define LAGG_PROTO_ETHERCHANNEL 5 /* Cisco FEC */
61 #define LAGG_PROTO_MAX 6
68 #define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER
69 #define LAGG_PROTOS { \
70 { "failover", LAGG_PROTO_FAILOVER }, \
71 { "fec", LAGG_PROTO_ETHERCHANNEL }, \
72 { "lacp", LAGG_PROTO_LACP }, \
73 { "loadbalance", LAGG_PROTO_LOADBALANCE }, \
74 { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \
75 { "none", LAGG_PROTO_NONE }, \
76 { "default", LAGG_PROTO_DEFAULT } \
84 * LACP current operational parameters structure.
88 uint8_t actor_mac
[ETHER_ADDR_LEN
];
90 uint16_t actor_portprio
;
91 uint16_t actor_portno
;
93 uint16_t partner_prio
;
94 uint8_t partner_mac
[ETHER_ADDR_LEN
];
96 uint16_t partner_portprio
;
97 uint16_t partner_portno
;
98 uint8_t partner_state
;
101 /* lagg port settings */
102 struct lagg_reqport
{
103 char rp_ifname
[IFNAMSIZ
]; /* name of the lagg */
104 char rp_portname
[IFNAMSIZ
]; /* name of the port */
105 u_int32_t rp_prio
; /* port priority */
106 u_int32_t rp_flags
; /* port flags */
108 struct lacp_opreq rpsc_lacp
;
110 #define rp_lacpreq rp_psc.rpsc_lacp
113 #define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport)
114 #define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport)
115 #define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport)
117 /* lagg, ports and options */
119 char ra_ifname
[IFNAMSIZ
]; /* name of the lagg */
120 u_int ra_proto
; /* lagg protocol */
122 size_t ra_size
; /* size of buffer */
123 struct lagg_reqport
*ra_port
; /* allocated buffer */
124 int ra_ports
; /* total port count */
126 struct lacp_opreq rpsc_lacp
;
128 #define ra_lacpreq ra_psc.rpsc_lacp
131 #define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall)
132 #define SIOCSLAGG _IOW('i', 144, struct lagg_reqall)
134 struct lagg_reqflags
{
135 char rf_ifname
[IFNAMSIZ
]; /* name of the lagg */
136 uint32_t rf_flags
; /* lagg protocol */
139 #define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags)
140 #define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags)
145 #include <sys/counter.h>
149 * Internal kernel part
152 #define lp_ifname lp_ifp->if_xname /* interface name */
153 #define lp_link_state lp_ifp->if_link_state /* link state */
155 #define LAGG_PORTACTIVE(_tp) ( \
156 ((_tp)->lp_link_state == LINK_STATE_UP) && \
157 ((_tp)->lp_ifp->if_flags & IFF_UP) \
164 char ifr_name
[IFNAMSIZ
];
165 struct sockaddr_storage ifr_ss
;
170 #define sc_ifflags sc_ifp->if_flags /* flags */
171 #define sc_ifname sc_ifp->if_xname /* name */
172 #define sc_capabilities sc_ifp->if_capabilities /* capabilities */
174 #define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */
175 #define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */
177 /* Private data used by the loadbalancing protocol */
180 struct lagg_port
*lb_ports
[LAGG_MAX_PORTS
];
184 struct ifmultiaddr
*mc_ifma
;
185 SLIST_ENTRY(lagg_mc
) mc_entries
;
188 /* List of interfaces to have the MAC address modified */
190 struct ifnet
*llq_ifp
;
191 uint8_t llq_lladdr
[ETHER_ADDR_LEN
];
192 SLIST_ENTRY(lagg_llq
) llq_entries
;
196 struct arpcom sc_arp
;
197 struct ifnet
*sc_ifp
; /* virtual interface */
199 struct lock sc_call_lock
;
200 int sc_proto
; /* lagg protocol */
201 u_int sc_count
; /* number of ports */
202 u_int sc_active
; /* active port count */
203 u_int sc_flapping
; /* number of flapping
205 struct lagg_port
*sc_primary
; /* primary port */
206 struct ifmedia sc_media
; /* media config */
207 caddr_t sc_psc
; /* protocol data */
208 uint32_t sc_seq
; /* sequence counter */
212 counter_u64_t sc_ipackets
;
213 counter_u64_t sc_opackets
;
214 counter_u64_t sc_ibytes
;
215 counter_u64_t sc_obytes
;
218 SLIST_HEAD(__tplhd
, lagg_port
) sc_ports
; /* list of interfaces */
219 SLIST_ENTRY(lagg_softc
) sc_entries
;
221 struct task sc_lladdr_task
;
222 SLIST_HEAD(__llqhd
, lagg_llq
) sc_llq_head
; /* interfaces to program
225 /* lagg protocol callbacks */
226 int (*sc_detach
)(struct lagg_softc
*);
227 int (*sc_start
)(struct lagg_softc
*, struct mbuf
*);
228 void (*sc_start_dispatch
)(netmsg_t msg
);
229 struct ifnet
*(*sc_select_tx_port
)(struct lagg_softc
*, struct mbuf
*);
230 struct mbuf
*(*sc_input
)(struct lagg_softc
*, struct lagg_port
*,
232 int (*sc_port_create
)(struct lagg_port
*);
233 void (*sc_port_destroy
)(struct lagg_port
*);
234 void (*sc_linkstate
)(struct lagg_port
*);
235 void (*sc_init
)(struct lagg_softc
*);
236 void (*sc_stop
)(struct lagg_softc
*);
237 void (*sc_lladdr
)(struct lagg_softc
*);
238 void (*sc_req
)(struct lagg_softc
*, caddr_t
);
239 void (*sc_portreq
)(struct lagg_port
*, caddr_t
);
240 eventhandler_tag vlan_attach
;
241 eventhandler_tag vlan_detach
;
242 struct callout sc_callout
;
243 struct sysctl_ctx_list ctx
; /* sysctl variables */
244 struct sysctl_oid
*sc_oid
; /* sysctl tree oid */
245 int use_flowid
; /* use M_FLOWID */
247 #define sc_if sc_arp.ac_if
250 struct ifnet
*lp_ifp
; /* physical interface */
251 struct lagg_softc
*lp_softc
; /* parent lagg */
252 uint8_t lp_lladdr
[ETHER_ADDR_LEN
];
254 u_char lp_iftype
; /* interface type */
255 uint32_t lp_prio
; /* port priority */
256 uint32_t lp_flags
; /* port flags */
257 int lp_ifflags
; /* saved ifp flags */
258 void *lh_cookie
; /* if state hook */
259 caddr_t lp_psc
; /* protocol data */
260 int lp_detaching
; /* ifnet is detaching */
262 SLIST_HEAD(__mclhd
, lagg_mc
) lp_mc_head
; /* multicast addresses */
264 /* Redirected callbacks */
265 int (*lp_ioctl
)(struct ifnet
*, u_long
, caddr_t
, struct ucred
*);
266 int (*lp_output
)(struct ifnet
*, struct mbuf
*,
267 struct sockaddr
*, struct rtentry
*);
269 SLIST_ENTRY(lagg_port
) lp_entries
;
272 #define LAGG_LOCK_INIT(_sc) lockinit(&(_sc)->sc_lock, "if_lagg rmlock", 0, LK_CANRECURSE)
273 #define LAGG_LOCK_DESTROY(_sc) lockuninit(&(_sc)->sc_lock)
274 #define LAGG_RLOCK(_sc) lockmgr(&(_sc)->sc_lock, LK_SHARED)
275 #define LAGG_WLOCK(_sc) lockmgr(&(_sc)->sc_lock, LK_EXCLUSIVE)
276 #define LAGG_RUNLOCK(_sc) lockmgr(&(_sc)->sc_lock, LK_RELEASE)
277 #define LAGG_WUNLOCK(_sc) lockmgr(&(_sc)->sc_lock, LK_RELEASE)
278 #define LAGG_RLOCK_ASSERT(_sc) KKASSERT(lockstatus(&(_sc)->sc_lock, curthread) == LK_SHARED)
279 #define LAGG_WLOCK_ASSERT(_sc) KKASSERT(lockstatus(&(_sc)->sc_lock, curthread) == LK_EXCLUSIVE)
281 #define LAGG_CALLOUT_LOCK_INIT(_sc) \
282 lockinit(&(_sc)->sc_call_lock, "if_lagg callout mutex", 0, 0)
283 #define LAGG_CALLOUT_LOCK_DESTROY(_sc) lockuninit(&(_sc)->sc_call_lock)
285 extern void (*lagg_input_p
)(struct ifnet
*, struct mbuf
*);
286 extern int (*lagg_output_p
)(struct ifnet
*, struct mbuf
*);
287 extern struct ifnet
*(lagg_interface_p
)(void *if_lagg
);
288 extern void (*lagg_linkstate_p
)(struct ifnet
*, int );
290 int lagg_enqueue(struct ifnet
*, struct mbuf
*);
291 uint32_t lagg_hashmbuf(struct lagg_softc
*, struct mbuf
*, uint32_t);
293 SYSCTL_DECL(_net_link_lagg
);
297 #endif /* _NET_LAGG_H */