if_lagg.h revision 169329
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 169329 2007-05-07 00:35:15Z 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 */ 37169228Sthompsa#define LAGG_PORT_COLLECTING 0x00000008 /* port is receiving frames */ 38169228Sthompsa#define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */ 39169227Sthompsa#define LAGG_PORT_DISABLED 0x00000020 /* port is disabled */ 40168793Sthompsa#define LAGG_PORT_GLOBAL 0x80000000 /* IOCTL: global flag */ 41168793Sthompsa#define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \ 42169227Sthompsa "\05DISTRIBUTING\06DISABLED" 43168793Sthompsa 44168793Sthompsa/* Supported lagg PROTOs */ 45168793Sthompsa#define LAGG_PROTO_NONE 0 /* no lagg protocol defined */ 46168793Sthompsa#define LAGG_PROTO_ROUNDROBIN 1 /* simple round robin */ 47168793Sthompsa#define LAGG_PROTO_FAILOVER 2 /* active failover */ 48168793Sthompsa#define LAGG_PROTO_LOADBALANCE 3 /* loadbalance */ 49168793Sthompsa#define LAGG_PROTO_LACP 4 /* 802.3ad lacp */ 50168793Sthompsa#define LAGG_PROTO_ETHERCHANNEL 5 /* Cisco FEC */ 51168793Sthompsa#define LAGG_PROTO_MAX 6 52168793Sthompsa 53168793Sthompsastruct lagg_protos { 54168793Sthompsa const char *tpr_name; 55168793Sthompsa int tpr_proto; 56168793Sthompsa}; 57168793Sthompsa 58168793Sthompsa#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 59168793Sthompsa#define LAGG_PROTOS { \ 60168793Sthompsa { "failover", LAGG_PROTO_FAILOVER }, \ 61168793Sthompsa { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 62168793Sthompsa { "lacp", LAGG_PROTO_LACP }, \ 63168793Sthompsa { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 64168793Sthompsa { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 65168793Sthompsa { "none", LAGG_PROTO_NONE }, \ 66168793Sthompsa { "default", LAGG_PROTO_DEFAULT } \ 67168793Sthompsa} 68168793Sthompsa 69168793Sthompsa/* 70168793Sthompsa * lagg ioctls. 71168793Sthompsa */ 72168793Sthompsa 73168793Sthompsa/* lagg port settings */ 74168793Sthompsastruct lagg_reqport { 75168793Sthompsa char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 76168793Sthompsa char rp_portname[IFNAMSIZ]; /* name of the port */ 77168793Sthompsa u_int32_t rp_prio; /* port priority */ 78168793Sthompsa u_int32_t rp_flags; /* port flags */ 79168793Sthompsa}; 80168793Sthompsa 81168793Sthompsa#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 82168793Sthompsa#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 83168793Sthompsa#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 84168793Sthompsa 85168793Sthompsa/* lagg, ports and options */ 86168793Sthompsastruct lagg_reqall { 87168793Sthompsa char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 88168793Sthompsa u_int ra_proto; /* lagg protocol */ 89168793Sthompsa 90168793Sthompsa size_t ra_size; /* size of buffer */ 91168793Sthompsa struct lagg_reqport *ra_port; /* allocated buffer */ 92168793Sthompsa int ra_ports; /* total port count */ 93168793Sthompsa}; 94168793Sthompsa 95168793Sthompsa#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 96168793Sthompsa#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 97168793Sthompsa 98168793Sthompsa#ifdef _KERNEL 99168793Sthompsa/* 100168793Sthompsa * Internal kernel part 101168793Sthompsa */ 102168793Sthompsa 103168793Sthompsa#define lp_ifname lp_ifp->if_xname /* interface name */ 104168793Sthompsa#define lp_link_state lp_ifp->if_link_state /* link state */ 105168793Sthompsa#define lp_capabilities lp_ifp->if_capabilities /* capabilities */ 106168793Sthompsa 107168793Sthompsa#define LAGG_PORTACTIVE(_tp) ( \ 108168793Sthompsa ((_tp)->lp_link_state == LINK_STATE_UP) && \ 109168793Sthompsa ((_tp)->lp_ifp->if_flags & IFF_UP) \ 110168793Sthompsa) 111168793Sthompsa 112168793Sthompsa#define mc_enm mc_u.mcu_enm 113168793Sthompsa 114168793Sthompsastruct lagg_ifreq { 115168793Sthompsa union { 116168793Sthompsa struct ifreq ifreq; 117168793Sthompsa struct { 118168793Sthompsa char ifr_name[IFNAMSIZ]; 119168793Sthompsa struct sockaddr_storage ifr_ss; 120168793Sthompsa } ifreq_storage; 121168793Sthompsa } ifreq; 122168793Sthompsa}; 123168793Sthompsa 124168793Sthompsa#define sc_ifflags sc_ifp->if_flags /* flags */ 125168793Sthompsa#define sc_ifname sc_ifp->if_xname /* name */ 126168793Sthompsa#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 127168793Sthompsa 128168793Sthompsa#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 129168793Sthompsa#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 130168793Sthompsa 131168793Sthompsa/* Private data used by the loadbalancing protocol */ 132168793Sthompsa#define LAGG_LB_MAXKEYS 8 133168793Sthompsastruct lagg_lb { 134168793Sthompsa u_int32_t lb_key; 135168793Sthompsa struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 136168793Sthompsa}; 137168793Sthompsa 138168793Sthompsastruct lagg_mc { 139169327Sthompsa struct ifmultiaddr *mc_ifma; 140169327Sthompsa SLIST_ENTRY(lagg_mc) mc_entries; 141168793Sthompsa}; 142168793Sthompsa 143169329Sthompsa/* List of interfaces to have the MAC address modified */ 144169329Sthompsastruct lagg_llq { 145169329Sthompsa struct ifnet *llq_ifp; 146169329Sthompsa uint8_t llq_lladdr[ETHER_ADDR_LEN]; 147169329Sthompsa SLIST_ENTRY(lagg_llq) llq_entries; 148169329Sthompsa}; 149169329Sthompsa 150168793Sthompsastruct lagg_softc { 151168793Sthompsa struct ifnet *sc_ifp; /* virtual interface */ 152168793Sthompsa struct mtx sc_mtx; 153168793Sthompsa int sc_proto; /* lagg protocol */ 154168793Sthompsa u_int sc_count; /* number of ports */ 155168793Sthompsa struct lagg_port *sc_primary; /* primary port */ 156168793Sthompsa struct ifmedia sc_media; /* media config */ 157168793Sthompsa caddr_t sc_psc; /* protocol data */ 158168793Sthompsa 159168793Sthompsa SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 160168793Sthompsa SLIST_ENTRY(lagg_softc) sc_entries; 161168793Sthompsa 162169329Sthompsa struct task sc_lladdr_task; 163169329Sthompsa SLIST_HEAD(__llqhd, lagg_llq) sc_llq_head; /* interfaces to program 164169329Sthompsa the lladdr on */ 165169329Sthompsa 166168793Sthompsa /* lagg protocol callbacks */ 167168793Sthompsa int (*sc_detach)(struct lagg_softc *); 168168793Sthompsa int (*sc_start)(struct lagg_softc *, struct mbuf *); 169168793Sthompsa struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *, 170168793Sthompsa struct mbuf *); 171168793Sthompsa int (*sc_port_create)(struct lagg_port *); 172168793Sthompsa void (*sc_port_destroy)(struct lagg_port *); 173168793Sthompsa void (*sc_linkstate)(struct lagg_port *); 174168793Sthompsa void (*sc_init)(struct lagg_softc *); 175168793Sthompsa void (*sc_stop)(struct lagg_softc *); 176168793Sthompsa void (*sc_lladdr)(struct lagg_softc *); 177168793Sthompsa}; 178168793Sthompsa 179168793Sthompsastruct lagg_port { 180168793Sthompsa struct ifnet *lp_ifp; /* physical interface */ 181168793Sthompsa struct lagg_softc *lp_lagg; /* parent lagg */ 182168793Sthompsa uint8_t lp_lladdr[ETHER_ADDR_LEN]; 183168793Sthompsa 184168793Sthompsa u_char lp_iftype; /* interface type */ 185168793Sthompsa uint32_t lp_prio; /* port priority */ 186168793Sthompsa uint32_t lp_flags; /* port flags */ 187168793Sthompsa int lp_ifflags; /* saved ifp flags */ 188168793Sthompsa void *lh_cookie; /* if state hook */ 189168793Sthompsa caddr_t lp_psc; /* protocol data */ 190169328Sthompsa int lp_detaching; /* ifnet is detaching */ 191168793Sthompsa 192169327Sthompsa SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 193169327Sthompsa 194168793Sthompsa /* Redirected callbacks */ 195168793Sthompsa int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 196168793Sthompsa int (*lp_output)(struct ifnet *, struct mbuf *, struct sockaddr *, 197168793Sthompsa struct rtentry *); 198168793Sthompsa 199168793Sthompsa SLIST_ENTRY(lagg_port) lp_entries; 200168793Sthompsa}; 201168793Sthompsa 202168793Sthompsa#define LAGG_LOCK_INIT(_tr) mtx_init(&(_tr)->sc_mtx, "if_lagg", NULL, \ 203168793Sthompsa MTX_DEF) 204168793Sthompsa#define LAGG_LOCK_DESTROY(_tr) mtx_destroy(&(_tr)->sc_mtx) 205168793Sthompsa#define LAGG_LOCK(_tr) mtx_lock(&(_tr)->sc_mtx) 206168793Sthompsa#define LAGG_UNLOCK(_tr) mtx_unlock(&(_tr)->sc_mtx) 207168793Sthompsa#define LAGG_LOCKED(_tr) mtx_owned(&(_tr)->sc_mtx) 208168793Sthompsa#define LAGG_LOCK_ASSERT(_tr) mtx_assert(&(_tr)->sc_mtx, MA_OWNED) 209168793Sthompsa 210168793Sthompsaextern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 211168793Sthompsaextern void (*lagg_linkstate_p)(struct ifnet *, int ); 212168793Sthompsa 213168793Sthompsaint lagg_enqueue(struct ifnet *, struct mbuf *); 214168793Sthompsauint32_t lagg_hashmbuf(struct mbuf *, uint32_t); 215168793Sthompsa 216168793Sthompsa#endif /* _KERNEL */ 217168793Sthompsa 218168793Sthompsa#endif /* _NET_LAGG_H */ 219