if_lagg.h revision 168793
1168793Sthompsa/* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */ 2168793Sthompsa 3168793Sthompsa/* 4168793Sthompsa * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org> 5168793Sthompsa * 6168793Sthompsa * Permission to use, copy, modify, and distribute this software for any 7168793Sthompsa * purpose with or without fee is hereby granted, provided that the above 8168793Sthompsa * copyright notice and this permission notice appear in all copies. 9168793Sthompsa * 10168793Sthompsa * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11168793Sthompsa * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12168793Sthompsa * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13168793Sthompsa * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14168793Sthompsa * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15168793Sthompsa * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16168793Sthompsa * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17168793Sthompsa * 18168793Sthompsa * $FreeBSD: head/sys/net/if_lagg.h 168793 2007-04-17 00:35:11Z thompsa $ 19168793Sthompsa */ 20168793Sthompsa 21168793Sthompsa#ifndef _NET_LAGG_H 22168793Sthompsa#define _NET_LAGG_H 23168793Sthompsa 24168793Sthompsa/* 25168793Sthompsa * Global definitions 26168793Sthompsa */ 27168793Sthompsa 28168793Sthompsa#define LAGG_MAX_PORTS 32 /* logically */ 29168793Sthompsa#define LAGG_MAX_NAMESIZE 32 /* name of a protocol */ 30168793Sthompsa#define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */ 31168793Sthompsa 32168793Sthompsa/* Port flags */ 33168793Sthompsa#define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */ 34168793Sthompsa#define LAGG_PORT_MASTER 0x00000001 /* primary port */ 35168793Sthompsa#define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */ 36168793Sthompsa#define LAGG_PORT_ACTIVE 0x00000004 /* port is active */ 37168793Sthompsa#define LAGG_PORT_COLLECTING 0x00000008 /* port is active */ 38168793Sthompsa#define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is active */ 39168793Sthompsa#define LAGG_PORT_GLOBAL 0x80000000 /* IOCTL: global flag */ 40168793Sthompsa#define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \ 41168793Sthompsa "\05DISTRIBUTING" 42168793Sthompsa 43168793Sthompsa/* Supported lagg PROTOs */ 44168793Sthompsa#define LAGG_PROTO_NONE 0 /* no lagg protocol defined */ 45168793Sthompsa#define LAGG_PROTO_ROUNDROBIN 1 /* simple round robin */ 46168793Sthompsa#define LAGG_PROTO_FAILOVER 2 /* active failover */ 47168793Sthompsa#define LAGG_PROTO_LOADBALANCE 3 /* loadbalance */ 48168793Sthompsa#define LAGG_PROTO_LACP 4 /* 802.3ad lacp */ 49168793Sthompsa#define LAGG_PROTO_ETHERCHANNEL 5 /* Cisco FEC */ 50168793Sthompsa#define LAGG_PROTO_MAX 6 51168793Sthompsa 52168793Sthompsastruct lagg_protos { 53168793Sthompsa const char *tpr_name; 54168793Sthompsa int tpr_proto; 55168793Sthompsa}; 56168793Sthompsa 57168793Sthompsa#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 58168793Sthompsa#define LAGG_PROTOS { \ 59168793Sthompsa { "failover", LAGG_PROTO_FAILOVER }, \ 60168793Sthompsa { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 61168793Sthompsa { "lacp", LAGG_PROTO_LACP }, \ 62168793Sthompsa { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 63168793Sthompsa { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 64168793Sthompsa { "none", LAGG_PROTO_NONE }, \ 65168793Sthompsa { "default", LAGG_PROTO_DEFAULT } \ 66168793Sthompsa} 67168793Sthompsa 68168793Sthompsa/* 69168793Sthompsa * lagg ioctls. 70168793Sthompsa */ 71168793Sthompsa 72168793Sthompsa/* lagg port settings */ 73168793Sthompsastruct lagg_reqport { 74168793Sthompsa char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 75168793Sthompsa char rp_portname[IFNAMSIZ]; /* name of the port */ 76168793Sthompsa u_int32_t rp_prio; /* port priority */ 77168793Sthompsa u_int32_t rp_flags; /* port flags */ 78168793Sthompsa}; 79168793Sthompsa 80168793Sthompsa#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 81168793Sthompsa#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 82168793Sthompsa#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 83168793Sthompsa 84168793Sthompsa/* lagg, ports and options */ 85168793Sthompsastruct lagg_reqall { 86168793Sthompsa char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 87168793Sthompsa u_int ra_proto; /* lagg protocol */ 88168793Sthompsa 89168793Sthompsa size_t ra_size; /* size of buffer */ 90168793Sthompsa struct lagg_reqport *ra_port; /* allocated buffer */ 91168793Sthompsa int ra_ports; /* total port count */ 92168793Sthompsa}; 93168793Sthompsa 94168793Sthompsa#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 95168793Sthompsa#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 96168793Sthompsa 97168793Sthompsa#ifdef _KERNEL 98168793Sthompsa/* 99168793Sthompsa * Internal kernel part 100168793Sthompsa */ 101168793Sthompsa 102168793Sthompsa#define lp_ifname lp_ifp->if_xname /* interface name */ 103168793Sthompsa#define lp_link_state lp_ifp->if_link_state /* link state */ 104168793Sthompsa#define lp_capabilities lp_ifp->if_capabilities /* capabilities */ 105168793Sthompsa 106168793Sthompsa#define LAGG_PORTACTIVE(_tp) ( \ 107168793Sthompsa ((_tp)->lp_link_state == LINK_STATE_UP) && \ 108168793Sthompsa ((_tp)->lp_ifp->if_flags & IFF_UP) \ 109168793Sthompsa) 110168793Sthompsa 111168793Sthompsa#define mc_enm mc_u.mcu_enm 112168793Sthompsa 113168793Sthompsastruct lagg_ifreq { 114168793Sthompsa union { 115168793Sthompsa struct ifreq ifreq; 116168793Sthompsa struct { 117168793Sthompsa char ifr_name[IFNAMSIZ]; 118168793Sthompsa struct sockaddr_storage ifr_ss; 119168793Sthompsa } ifreq_storage; 120168793Sthompsa } ifreq; 121168793Sthompsa}; 122168793Sthompsa 123168793Sthompsa#define sc_ifflags sc_ifp->if_flags /* flags */ 124168793Sthompsa#define sc_ifname sc_ifp->if_xname /* name */ 125168793Sthompsa#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 126168793Sthompsa 127168793Sthompsa#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 128168793Sthompsa#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 129168793Sthompsa 130168793Sthompsa/* Private data used by the loadbalancing protocol */ 131168793Sthompsa#define LAGG_LB_MAXKEYS 8 132168793Sthompsastruct lagg_lb { 133168793Sthompsa u_int32_t lb_key; 134168793Sthompsa struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 135168793Sthompsa}; 136168793Sthompsa 137168793Sthompsastruct lagg_mc { 138168793Sthompsa union { 139168793Sthompsa struct ether_multi *mcu_enm; 140168793Sthompsa } mc_u; 141168793Sthompsa struct sockaddr_storage mc_addr; 142168793Sthompsa 143168793Sthompsa SLIST_ENTRY(lagg_mc) mc_entries; 144168793Sthompsa}; 145168793Sthompsa 146168793Sthompsastruct lagg_softc { 147168793Sthompsa struct ifnet *sc_ifp; /* virtual interface */ 148168793Sthompsa struct mtx sc_mtx; 149168793Sthompsa int sc_proto; /* lagg protocol */ 150168793Sthompsa u_int sc_count; /* number of ports */ 151168793Sthompsa struct lagg_port *sc_primary; /* primary port */ 152168793Sthompsa struct ifmedia sc_media; /* media config */ 153168793Sthompsa caddr_t sc_psc; /* protocol data */ 154168793Sthompsa 155168793Sthompsa SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 156168793Sthompsa SLIST_ENTRY(lagg_softc) sc_entries; 157168793Sthompsa 158168793Sthompsa SLIST_HEAD(__mclhd, lagg_mc) sc_mc_head; /* multicast addresses */ 159168793Sthompsa 160168793Sthompsa /* lagg protocol callbacks */ 161168793Sthompsa int (*sc_detach)(struct lagg_softc *); 162168793Sthompsa int (*sc_start)(struct lagg_softc *, struct mbuf *); 163168793Sthompsa struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *, 164168793Sthompsa struct mbuf *); 165168793Sthompsa int (*sc_port_create)(struct lagg_port *); 166168793Sthompsa void (*sc_port_destroy)(struct lagg_port *); 167168793Sthompsa void (*sc_linkstate)(struct lagg_port *); 168168793Sthompsa void (*sc_init)(struct lagg_softc *); 169168793Sthompsa void (*sc_stop)(struct lagg_softc *); 170168793Sthompsa void (*sc_lladdr)(struct lagg_softc *); 171168793Sthompsa}; 172168793Sthompsa 173168793Sthompsastruct lagg_port { 174168793Sthompsa struct ifnet *lp_ifp; /* physical interface */ 175168793Sthompsa struct lagg_softc *lp_lagg; /* parent lagg */ 176168793Sthompsa uint8_t lp_lladdr[ETHER_ADDR_LEN]; 177168793Sthompsa 178168793Sthompsa u_char lp_iftype; /* interface type */ 179168793Sthompsa uint32_t lp_prio; /* port priority */ 180168793Sthompsa uint32_t lp_flags; /* port flags */ 181168793Sthompsa int lp_ifflags; /* saved ifp flags */ 182168793Sthompsa void *lh_cookie; /* if state hook */ 183168793Sthompsa caddr_t lp_psc; /* protocol data */ 184168793Sthompsa 185168793Sthompsa /* Redirected callbacks */ 186168793Sthompsa int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 187168793Sthompsa int (*lp_output)(struct ifnet *, struct mbuf *, struct sockaddr *, 188168793Sthompsa struct rtentry *); 189168793Sthompsa 190168793Sthompsa SLIST_ENTRY(lagg_port) lp_entries; 191168793Sthompsa}; 192168793Sthompsa 193168793Sthompsa#define LAGG_LOCK_INIT(_tr) mtx_init(&(_tr)->sc_mtx, "if_lagg", NULL, \ 194168793Sthompsa MTX_DEF) 195168793Sthompsa#define LAGG_LOCK_DESTROY(_tr) mtx_destroy(&(_tr)->sc_mtx) 196168793Sthompsa#define LAGG_LOCK(_tr) mtx_lock(&(_tr)->sc_mtx) 197168793Sthompsa#define LAGG_UNLOCK(_tr) mtx_unlock(&(_tr)->sc_mtx) 198168793Sthompsa#define LAGG_LOCKED(_tr) mtx_owned(&(_tr)->sc_mtx) 199168793Sthompsa#define LAGG_LOCK_ASSERT(_tr) mtx_assert(&(_tr)->sc_mtx, MA_OWNED) 200168793Sthompsa 201168793Sthompsaextern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 202168793Sthompsaextern void (*lagg_linkstate_p)(struct ifnet *, int ); 203168793Sthompsa 204168793Sthompsaint lagg_enqueue(struct ifnet *, struct mbuf *); 205168793Sthompsauint32_t lagg_hashmbuf(struct mbuf *, uint32_t); 206168793Sthompsa 207168793Sthompsa#endif /* _KERNEL */ 208168793Sthompsa 209168793Sthompsa#endif /* _NET_LAGG_H */ 210