if_lagg.h revision 249506
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 249506 2013-04-15 13:00:42Z glebius $ 19168793Sthompsa */ 20168793Sthompsa 21168793Sthompsa#ifndef _NET_LAGG_H 22168793Sthompsa#define _NET_LAGG_H 23168793Sthompsa 24168793Sthompsa/* 25168793Sthompsa * Global definitions 26168793Sthompsa */ 27168793Sthompsa 28170599Sthompsa#define LAGG_MAX_PORTS 32 /* logically */ 29170599Sthompsa#define LAGG_MAX_NAMESIZE 32 /* name of a protocol */ 30170599Sthompsa#define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */ 31168793Sthompsa 32232629Sthompsa/* Lagg flags */ 33232629Sthompsa#define LAGG_F_HASHL2 0x00000001 /* hash layer 2 */ 34232629Sthompsa#define LAGG_F_HASHL3 0x00000002 /* hash layer 3 */ 35232629Sthompsa#define LAGG_F_HASHL4 0x00000004 /* hash layer 4 */ 36232629Sthompsa#define LAGG_F_HASHMASK 0x00000007 37232629Sthompsa 38168793Sthompsa/* Port flags */ 39170599Sthompsa#define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */ 40170599Sthompsa#define LAGG_PORT_MASTER 0x00000001 /* primary port */ 41170599Sthompsa#define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */ 42170599Sthompsa#define LAGG_PORT_ACTIVE 0x00000004 /* port is active */ 43170599Sthompsa#define LAGG_PORT_COLLECTING 0x00000008 /* port is receiving frames */ 44170599Sthompsa#define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */ 45170599Sthompsa#define LAGG_PORT_DISABLED 0x00000020 /* port is disabled */ 46170599Sthompsa#define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \ 47169227Sthompsa "\05DISTRIBUTING\06DISABLED" 48168793Sthompsa 49168793Sthompsa/* Supported lagg PROTOs */ 50168793Sthompsa#define LAGG_PROTO_NONE 0 /* no lagg protocol defined */ 51168793Sthompsa#define LAGG_PROTO_ROUNDROBIN 1 /* simple round robin */ 52168793Sthompsa#define LAGG_PROTO_FAILOVER 2 /* active failover */ 53168793Sthompsa#define LAGG_PROTO_LOADBALANCE 3 /* loadbalance */ 54168793Sthompsa#define LAGG_PROTO_LACP 4 /* 802.3ad lacp */ 55168793Sthompsa#define LAGG_PROTO_ETHERCHANNEL 5 /* Cisco FEC */ 56168793Sthompsa#define LAGG_PROTO_MAX 6 57168793Sthompsa 58168793Sthompsastruct lagg_protos { 59170599Sthompsa const char *lpr_name; 60170599Sthompsa int lpr_proto; 61168793Sthompsa}; 62168793Sthompsa 63168793Sthompsa#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 64168793Sthompsa#define LAGG_PROTOS { \ 65168793Sthompsa { "failover", LAGG_PROTO_FAILOVER }, \ 66168793Sthompsa { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 67168793Sthompsa { "lacp", LAGG_PROTO_LACP }, \ 68168793Sthompsa { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 69168793Sthompsa { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 70168793Sthompsa { "none", LAGG_PROTO_NONE }, \ 71168793Sthompsa { "default", LAGG_PROTO_DEFAULT } \ 72168793Sthompsa} 73168793Sthompsa 74168793Sthompsa/* 75168793Sthompsa * lagg ioctls. 76168793Sthompsa */ 77168793Sthompsa 78171247Sthompsa/* 79171247Sthompsa * LACP current operational parameters structure. 80171247Sthompsa */ 81171247Sthompsastruct lacp_opreq { 82171247Sthompsa uint16_t actor_prio; 83171247Sthompsa uint8_t actor_mac[ETHER_ADDR_LEN]; 84171247Sthompsa uint16_t actor_key; 85171247Sthompsa uint16_t actor_portprio; 86171247Sthompsa uint16_t actor_portno; 87171247Sthompsa uint8_t actor_state; 88171247Sthompsa uint16_t partner_prio; 89171247Sthompsa uint8_t partner_mac[ETHER_ADDR_LEN]; 90171247Sthompsa uint16_t partner_key; 91171247Sthompsa uint16_t partner_portprio; 92171247Sthompsa uint16_t partner_portno; 93171247Sthompsa uint8_t partner_state; 94171247Sthompsa}; 95171247Sthompsa 96168793Sthompsa/* lagg port settings */ 97168793Sthompsastruct lagg_reqport { 98168793Sthompsa char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 99168793Sthompsa char rp_portname[IFNAMSIZ]; /* name of the port */ 100168793Sthompsa u_int32_t rp_prio; /* port priority */ 101168793Sthompsa u_int32_t rp_flags; /* port flags */ 102171247Sthompsa union { 103171247Sthompsa struct lacp_opreq rpsc_lacp; 104171247Sthompsa } rp_psc; 105171247Sthompsa#define rp_lacpreq rp_psc.rpsc_lacp 106168793Sthompsa}; 107168793Sthompsa 108170599Sthompsa#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 109170599Sthompsa#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 110170599Sthompsa#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 111168793Sthompsa 112168793Sthompsa/* lagg, ports and options */ 113168793Sthompsastruct lagg_reqall { 114168793Sthompsa char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 115168793Sthompsa u_int ra_proto; /* lagg protocol */ 116168793Sthompsa 117168793Sthompsa size_t ra_size; /* size of buffer */ 118168793Sthompsa struct lagg_reqport *ra_port; /* allocated buffer */ 119168793Sthompsa int ra_ports; /* total port count */ 120171247Sthompsa union { 121171247Sthompsa struct lacp_opreq rpsc_lacp; 122171247Sthompsa } ra_psc; 123171247Sthompsa#define ra_lacpreq ra_psc.rpsc_lacp 124168793Sthompsa}; 125168793Sthompsa 126170599Sthompsa#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 127170599Sthompsa#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 128168793Sthompsa 129232629Sthompsastruct lagg_reqflags { 130232629Sthompsa char rf_ifname[IFNAMSIZ]; /* name of the lagg */ 131232629Sthompsa uint32_t rf_flags; /* lagg protocol */ 132232629Sthompsa}; 133232629Sthompsa 134232629Sthompsa#define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags) 135232629Sthompsa#define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags) 136232629Sthompsa 137168793Sthompsa#ifdef _KERNEL 138249506Sglebius 139249506Sglebius#include <sys/counter.h> 140249506Sglebius 141168793Sthompsa/* 142168793Sthompsa * Internal kernel part 143168793Sthompsa */ 144168793Sthompsa 145170599Sthompsa#define lp_ifname lp_ifp->if_xname /* interface name */ 146170599Sthompsa#define lp_link_state lp_ifp->if_link_state /* link state */ 147168793Sthompsa 148170599Sthompsa#define LAGG_PORTACTIVE(_tp) ( \ 149168793Sthompsa ((_tp)->lp_link_state == LINK_STATE_UP) && \ 150170599Sthompsa ((_tp)->lp_ifp->if_flags & IFF_UP) \ 151168793Sthompsa) 152168793Sthompsa 153168793Sthompsastruct lagg_ifreq { 154168793Sthompsa union { 155168793Sthompsa struct ifreq ifreq; 156168793Sthompsa struct { 157168793Sthompsa char ifr_name[IFNAMSIZ]; 158168793Sthompsa struct sockaddr_storage ifr_ss; 159168793Sthompsa } ifreq_storage; 160168793Sthompsa } ifreq; 161168793Sthompsa}; 162168793Sthompsa 163170599Sthompsa#define sc_ifflags sc_ifp->if_flags /* flags */ 164170599Sthompsa#define sc_ifname sc_ifp->if_xname /* name */ 165170599Sthompsa#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 166168793Sthompsa 167170599Sthompsa#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 168170599Sthompsa#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 169168793Sthompsa 170168793Sthompsa/* Private data used by the loadbalancing protocol */ 171168793Sthompsastruct lagg_lb { 172168793Sthompsa u_int32_t lb_key; 173168793Sthompsa struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 174168793Sthompsa}; 175168793Sthompsa 176168793Sthompsastruct lagg_mc { 177169327Sthompsa struct ifmultiaddr *mc_ifma; 178169327Sthompsa SLIST_ENTRY(lagg_mc) mc_entries; 179168793Sthompsa}; 180168793Sthompsa 181169329Sthompsa/* List of interfaces to have the MAC address modified */ 182169329Sthompsastruct lagg_llq { 183169329Sthompsa struct ifnet *llq_ifp; 184169329Sthompsa uint8_t llq_lladdr[ETHER_ADDR_LEN]; 185169329Sthompsa SLIST_ENTRY(lagg_llq) llq_entries; 186169329Sthompsa}; 187169329Sthompsa 188168793Sthompsastruct lagg_softc { 189168793Sthompsa struct ifnet *sc_ifp; /* virtual interface */ 190169569Sthompsa struct rwlock sc_mtx; 191168793Sthompsa int sc_proto; /* lagg protocol */ 192168793Sthompsa u_int sc_count; /* number of ports */ 193168793Sthompsa struct lagg_port *sc_primary; /* primary port */ 194168793Sthompsa struct ifmedia sc_media; /* media config */ 195168793Sthompsa caddr_t sc_psc; /* protocol data */ 196172554Sthompsa uint32_t sc_seq; /* sequence counter */ 197232629Sthompsa uint32_t sc_flags; 198168793Sthompsa 199249506Sglebius counter_u64_t sc_ipackets; 200249506Sglebius counter_u64_t sc_opackets; 201249506Sglebius counter_u64_t sc_ibytes; 202249506Sglebius counter_u64_t sc_obytes; 203249506Sglebius 204168793Sthompsa SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 205168793Sthompsa SLIST_ENTRY(lagg_softc) sc_entries; 206168793Sthompsa 207169329Sthompsa struct task sc_lladdr_task; 208169329Sthompsa SLIST_HEAD(__llqhd, lagg_llq) sc_llq_head; /* interfaces to program 209169329Sthompsa the lladdr on */ 210169329Sthompsa 211168793Sthompsa /* lagg protocol callbacks */ 212168793Sthompsa int (*sc_detach)(struct lagg_softc *); 213168793Sthompsa int (*sc_start)(struct lagg_softc *, struct mbuf *); 214168793Sthompsa struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *, 215168793Sthompsa struct mbuf *); 216168793Sthompsa int (*sc_port_create)(struct lagg_port *); 217168793Sthompsa void (*sc_port_destroy)(struct lagg_port *); 218168793Sthompsa void (*sc_linkstate)(struct lagg_port *); 219168793Sthompsa void (*sc_init)(struct lagg_softc *); 220168793Sthompsa void (*sc_stop)(struct lagg_softc *); 221168793Sthompsa void (*sc_lladdr)(struct lagg_softc *); 222171247Sthompsa void (*sc_req)(struct lagg_softc *, caddr_t); 223171247Sthompsa void (*sc_portreq)(struct lagg_port *, caddr_t); 224203548Seri eventhandler_tag vlan_attach; 225203548Seri eventhandler_tag vlan_detach; 226249506Sglebius struct callout sc_callout; 227232008Sthompsa struct sysctl_ctx_list ctx; /* sysctl variables */ 228232008Sthompsa int use_flowid; /* use M_FLOWID */ 229168793Sthompsa}; 230168793Sthompsa 231168793Sthompsastruct lagg_port { 232168793Sthompsa struct ifnet *lp_ifp; /* physical interface */ 233170599Sthompsa struct lagg_softc *lp_softc; /* parent lagg */ 234168793Sthompsa uint8_t lp_lladdr[ETHER_ADDR_LEN]; 235168793Sthompsa 236168793Sthompsa u_char lp_iftype; /* interface type */ 237168793Sthompsa uint32_t lp_prio; /* port priority */ 238168793Sthompsa uint32_t lp_flags; /* port flags */ 239168793Sthompsa int lp_ifflags; /* saved ifp flags */ 240168793Sthompsa void *lh_cookie; /* if state hook */ 241168793Sthompsa caddr_t lp_psc; /* protocol data */ 242169328Sthompsa int lp_detaching; /* ifnet is detaching */ 243168793Sthompsa 244169327Sthompsa SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 245169327Sthompsa 246168793Sthompsa /* Redirected callbacks */ 247168793Sthompsa int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 248168793Sthompsa int (*lp_output)(struct ifnet *, struct mbuf *, struct sockaddr *, 249191148Skmacy struct route *); 250168793Sthompsa 251168793Sthompsa SLIST_ENTRY(lagg_port) lp_entries; 252168793Sthompsa}; 253168793Sthompsa 254170599Sthompsa#define LAGG_LOCK_INIT(_sc) rw_init(&(_sc)->sc_mtx, "if_lagg rwlock") 255170599Sthompsa#define LAGG_LOCK_DESTROY(_sc) rw_destroy(&(_sc)->sc_mtx) 256170599Sthompsa#define LAGG_RLOCK(_sc) rw_rlock(&(_sc)->sc_mtx) 257170599Sthompsa#define LAGG_WLOCK(_sc) rw_wlock(&(_sc)->sc_mtx) 258170599Sthompsa#define LAGG_RUNLOCK(_sc) rw_runlock(&(_sc)->sc_mtx) 259170599Sthompsa#define LAGG_WUNLOCK(_sc) rw_wunlock(&(_sc)->sc_mtx) 260170599Sthompsa#define LAGG_RLOCK_ASSERT(_sc) rw_assert(&(_sc)->sc_mtx, RA_RLOCKED) 261170599Sthompsa#define LAGG_WLOCK_ASSERT(_sc) rw_assert(&(_sc)->sc_mtx, RA_WLOCKED) 262168793Sthompsa 263168793Sthompsaextern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 264168793Sthompsaextern void (*lagg_linkstate_p)(struct ifnet *, int ); 265168793Sthompsa 266168793Sthompsaint lagg_enqueue(struct ifnet *, struct mbuf *); 267232629Sthompsauint32_t lagg_hashmbuf(struct lagg_softc *, struct mbuf *, uint32_t); 268168793Sthompsa 269168793Sthompsa#endif /* _KERNEL */ 270168793Sthompsa 271168793Sthompsa#endif /* _NET_LAGG_H */ 272