1 /* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */
4 * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org>
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.
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.
28 #define LAGG_MAX_PORTS 32 /* logically */
29 #define LAGG_MAX_NAMESIZE 32 /* name of a protocol */
30 #define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */
33 #define LAGG_F_HASHL2 0x00000001 /* hash layer 2 */
34 #define LAGG_F_HASHL3 0x00000002 /* hash layer 3 */
35 #define LAGG_F_HASHL4 0x00000004 /* hash layer 4 */
36 #define LAGG_F_HASHMASK 0x00000007
39 #define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */
40 #define LAGG_PORT_MASTER 0x00000001 /* primary port */
41 #define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */
42 #define LAGG_PORT_ACTIVE 0x00000004 /* port is active */
43 #define LAGG_PORT_COLLECTING 0x00000008 /* port is receiving frames */
44 #define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */
45 #define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \
48 /* Supported lagg PROTOs */
50 LAGG_PROTO_NONE = 0, /* no lagg protocol defined */
51 LAGG_PROTO_ROUNDROBIN, /* simple round robin */
52 LAGG_PROTO_FAILOVER, /* active failover */
53 LAGG_PROTO_LOADBALANCE, /* loadbalance */
54 LAGG_PROTO_LACP, /* 802.3ad lacp */
55 LAGG_PROTO_BROADCAST, /* broadcast */
64 #define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER
65 #define LAGG_PROTOS { \
66 { "failover", LAGG_PROTO_FAILOVER }, \
67 { "lacp", LAGG_PROTO_LACP }, \
68 { "loadbalance", LAGG_PROTO_LOADBALANCE }, \
69 { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \
70 { "broadcast", LAGG_PROTO_BROADCAST }, \
71 { "none", LAGG_PROTO_NONE }, \
72 { "default", LAGG_PROTO_DEFAULT } \
80 * LACP current operational parameters structure.
84 uint8_t actor_mac[ETHER_ADDR_LEN];
86 uint16_t actor_portprio;
87 uint16_t actor_portno;
89 uint16_t partner_prio;
90 uint8_t partner_mac[ETHER_ADDR_LEN];
92 uint16_t partner_portprio;
93 uint16_t partner_portno;
94 uint8_t partner_state;
97 /* lagg port settings */
99 char rp_ifname[IFNAMSIZ]; /* name of the lagg */
100 char rp_portname[IFNAMSIZ]; /* name of the port */
101 u_int32_t rp_prio; /* port priority */
102 u_int32_t rp_flags; /* port flags */
104 struct lacp_opreq rpsc_lacp;
106 #define rp_lacpreq rp_psc.rpsc_lacp
109 #define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport)
110 #define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport)
111 #define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport)
113 /* lagg, ports and options */
115 char ra_ifname[IFNAMSIZ]; /* name of the lagg */
116 u_int ra_proto; /* lagg protocol */
118 size_t ra_size; /* size of buffer */
119 struct lagg_reqport *ra_port; /* allocated buffer */
120 int ra_ports; /* total port count */
122 struct lacp_opreq rpsc_lacp;
124 #define ra_lacpreq ra_psc.rpsc_lacp
127 #define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall)
128 #define SIOCSLAGG _IOW('i', 144, struct lagg_reqall)
130 struct lagg_reqflags {
131 char rf_ifname[IFNAMSIZ]; /* name of the lagg */
132 uint32_t rf_flags; /* lagg protocol */
135 #define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags)
136 #define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags)
138 struct lagg_reqopts {
139 char ro_ifname[IFNAMSIZ]; /* name of the lagg */
141 int ro_opts; /* Option bitmap */
142 #define LAGG_OPT_NONE 0x00
143 #define LAGG_OPT_USE_FLOWID 0x01 /* enable use of flowid */
144 /* Pseudo flags which are used in ro_opts but not stored into sc_opts. */
145 #define LAGG_OPT_FLOWIDSHIFT 0x02 /* set flowid shift */
146 #define LAGG_OPT_USE_NUMA 0x04 /* enable use of numa */
147 #define LAGG_OPT_FLOWIDSHIFT_MASK 0x1f /* flowid is uint32_t */
148 #define LAGG_OPT_LACP_STRICT 0x10 /* LACP strict mode */
149 #define LAGG_OPT_LACP_TXTEST 0x20 /* LACP debug: txtest */
150 #define LAGG_OPT_LACP_RXTEST 0x40 /* LACP debug: rxtest */
151 #define LAGG_OPT_LACP_TIMEOUT 0x80 /* LACP timeout */
152 u_int ro_count; /* number of ports */
153 u_int ro_active; /* active port count */
154 u_int ro_flapping; /* number of flapping */
155 int ro_flowid_shift; /* shift the flowid */
156 uint32_t ro_bkt; /* packet bucket for roundrobin */
159 #define SIOCGLAGGOPTS _IOWR('i', 152, struct lagg_reqopts)
160 #define SIOCSLAGGOPTS _IOW('i', 153, struct lagg_reqopts)
162 #define LAGG_OPT_BITS "\020\001USE_FLOWID\003USE_NUMA" \
163 "\005LACP_STRICT\006LACP_TXTEST" \
169 * Internal kernel part
172 #define LAGG_PORTACTIVE(_tp) ( \
173 ((_tp)->lp_ifp->if_link_state == LINK_STATE_UP) && \
174 ((_tp)->lp_ifp->if_flags & IFF_UP) \
181 char ifr_name[IFNAMSIZ];
182 struct sockaddr_storage ifr_ss;
187 #define sc_ifflags sc_ifp->if_flags /* flags */
188 #define sc_ifname sc_ifp->if_xname /* name */
190 /* Private data used by the loadbalancing protocol */
193 struct lagg_port *lb_ports[LAGG_MAX_PORTS];
197 struct sockaddr_dl mc_addr;
198 struct ifmultiaddr *mc_ifma;
199 SLIST_ENTRY(lagg_mc) mc_entries;
202 struct lagg_counters {
203 uint64_t val[IFCOUNTERS];
207 struct ifnet *sc_ifp; /* virtual interface */
208 struct rmlock sc_mtx;
210 int sc_proto; /* lagg protocol */
211 u_int sc_count; /* number of ports */
212 u_int sc_active; /* active port count */
213 u_int sc_flapping; /* number of flapping
215 struct lagg_port *sc_primary; /* primary port */
216 struct ifmedia sc_media; /* media config */
217 void *sc_psc; /* protocol data */
218 uint32_t sc_seq; /* sequence counter */
220 int sc_destroying; /* destroying lagg */
222 CK_SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */
223 SLIST_ENTRY(lagg_softc) sc_entries;
225 eventhandler_tag vlan_attach;
226 eventhandler_tag vlan_detach;
227 struct callout sc_callout;
229 int flowid_shift; /* shift the flowid */
230 uint32_t sc_bkt; /* packates bucket for roundrobin */
231 uint32_t sc_bkt_count; /* packates bucket count for roundrobin */
232 struct lagg_counters detached_counters; /* detached ports sum */
236 struct ifnet *lp_ifp; /* physical interface */
237 struct lagg_softc *lp_softc; /* parent lagg */
238 uint8_t lp_lladdr[ETHER_ADDR_LEN];
240 u_char lp_iftype; /* interface type */
241 uint32_t lp_prio; /* port priority */
242 uint32_t lp_flags; /* port flags */
243 int lp_ifflags; /* saved ifp flags */
244 int lp_ifcapenable; /* saved ifp capenable */
245 void *lh_cookie; /* if state hook */
246 void *lp_psc; /* protocol data */
247 int lp_detaching; /* ifnet is detaching */
248 SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */
250 /* Redirected callbacks */
251 int (*lp_ioctl)(struct ifnet *, u_long, caddr_t);
252 int (*lp_output)(struct ifnet *, struct mbuf *,
253 const struct sockaddr *, struct route *);
254 struct lagg_counters port_counters; /* ifp counters copy */
256 CK_SLIST_ENTRY(lagg_port) lp_entries;
257 struct epoch_context lp_epoch_ctx;
260 extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *);
261 extern void (*lagg_linkstate_p)(struct ifnet *, int );
263 int lagg_enqueue(struct ifnet *, struct mbuf *);
265 SYSCTL_DECL(_net_link_lagg);
269 #endif /* _NET_LAGG_H */