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: releng/10.3/sys/net/if_lagg.h 287808 2015-09-15 05:19:10Z hiren $ 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 */ 50287723Shrstypedef enum { 51287723Shrs LAGG_PROTO_NONE = 0, /* no lagg protocol defined */ 52287723Shrs LAGG_PROTO_ROUNDROBIN, /* simple round robin */ 53287723Shrs LAGG_PROTO_FAILOVER, /* active failover */ 54287723Shrs LAGG_PROTO_LOADBALANCE, /* loadbalance */ 55287723Shrs LAGG_PROTO_LACP, /* 802.3ad lacp */ 56287723Shrs LAGG_PROTO_ETHERCHANNEL,/* Cisco FEC */ 57287723Shrs LAGG_PROTO_MAX, 58287723Shrs} lagg_proto; 59168793Sthompsa 60168793Sthompsastruct lagg_protos { 61170599Sthompsa const char *lpr_name; 62287723Shrs lagg_proto lpr_proto; 63168793Sthompsa}; 64168793Sthompsa 65168793Sthompsa#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 66168793Sthompsa#define LAGG_PROTOS { \ 67168793Sthompsa { "failover", LAGG_PROTO_FAILOVER }, \ 68168793Sthompsa { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 69168793Sthompsa { "lacp", LAGG_PROTO_LACP }, \ 70168793Sthompsa { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 71168793Sthompsa { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 72168793Sthompsa { "none", LAGG_PROTO_NONE }, \ 73168793Sthompsa { "default", LAGG_PROTO_DEFAULT } \ 74168793Sthompsa} 75168793Sthompsa 76168793Sthompsa/* 77168793Sthompsa * lagg ioctls. 78168793Sthompsa */ 79168793Sthompsa 80171247Sthompsa/* 81171247Sthompsa * LACP current operational parameters structure. 82171247Sthompsa */ 83171247Sthompsastruct lacp_opreq { 84171247Sthompsa uint16_t actor_prio; 85171247Sthompsa uint8_t actor_mac[ETHER_ADDR_LEN]; 86171247Sthompsa uint16_t actor_key; 87171247Sthompsa uint16_t actor_portprio; 88171247Sthompsa uint16_t actor_portno; 89171247Sthompsa uint8_t actor_state; 90171247Sthompsa uint16_t partner_prio; 91171247Sthompsa uint8_t partner_mac[ETHER_ADDR_LEN]; 92171247Sthompsa uint16_t partner_key; 93171247Sthompsa uint16_t partner_portprio; 94171247Sthompsa uint16_t partner_portno; 95171247Sthompsa uint8_t partner_state; 96171247Sthompsa}; 97171247Sthompsa 98168793Sthompsa/* lagg port settings */ 99168793Sthompsastruct lagg_reqport { 100168793Sthompsa char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 101168793Sthompsa char rp_portname[IFNAMSIZ]; /* name of the port */ 102168793Sthompsa u_int32_t rp_prio; /* port priority */ 103168793Sthompsa u_int32_t rp_flags; /* port flags */ 104171247Sthompsa union { 105171247Sthompsa struct lacp_opreq rpsc_lacp; 106171247Sthompsa } rp_psc; 107171247Sthompsa#define rp_lacpreq rp_psc.rpsc_lacp 108168793Sthompsa}; 109168793Sthompsa 110170599Sthompsa#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 111170599Sthompsa#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 112170599Sthompsa#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 113168793Sthompsa 114168793Sthompsa/* lagg, ports and options */ 115168793Sthompsastruct lagg_reqall { 116168793Sthompsa char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 117168793Sthompsa u_int ra_proto; /* lagg protocol */ 118168793Sthompsa 119168793Sthompsa size_t ra_size; /* size of buffer */ 120168793Sthompsa struct lagg_reqport *ra_port; /* allocated buffer */ 121168793Sthompsa int ra_ports; /* total port count */ 122171247Sthompsa union { 123171247Sthompsa struct lacp_opreq rpsc_lacp; 124171247Sthompsa } ra_psc; 125171247Sthompsa#define ra_lacpreq ra_psc.rpsc_lacp 126168793Sthompsa}; 127168793Sthompsa 128170599Sthompsa#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 129170599Sthompsa#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 130168793Sthompsa 131232629Sthompsastruct lagg_reqflags { 132232629Sthompsa char rf_ifname[IFNAMSIZ]; /* name of the lagg */ 133232629Sthompsa uint32_t rf_flags; /* lagg protocol */ 134232629Sthompsa}; 135232629Sthompsa 136232629Sthompsa#define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags) 137232629Sthompsa#define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags) 138232629Sthompsa 139287723Shrsstruct lagg_reqopts { 140287723Shrs char ro_ifname[IFNAMSIZ]; /* name of the lagg */ 141287723Shrs 142287723Shrs int ro_opts; /* Option bitmap */ 143287723Shrs#define LAGG_OPT_NONE 0x00 144287723Shrs#define LAGG_OPT_USE_FLOWID 0x01 /* use M_FLOWID */ 145287723Shrs/* Pseudo flags which are used in ro_opts but not stored into sc_opts. */ 146287723Shrs#define LAGG_OPT_FLOWIDSHIFT 0x02 /* Set flowid */ 147287723Shrs#define LAGG_OPT_FLOWIDSHIFT_MASK 0x1f /* flowid is uint32_t */ 148287723Shrs#define LAGG_OPT_LACP_STRICT 0x10 /* LACP strict mode */ 149287723Shrs#define LAGG_OPT_LACP_TXTEST 0x20 /* LACP debug: txtest */ 150287723Shrs#define LAGG_OPT_LACP_RXTEST 0x40 /* LACP debug: rxtest */ 151287808Shiren#define LAGG_OPT_LACP_TIMEOUT 0x80 /* LACP timeout */ 152287723Shrs u_int ro_count; /* number of ports */ 153287723Shrs u_int ro_active; /* active port count */ 154287723Shrs u_int ro_flapping; /* number of flapping */ 155287723Shrs int ro_flowid_shift; /* shift the flowid */ 156287723Shrs}; 157287723Shrs 158287723Shrs#define SIOCGLAGGOPTS _IOWR('i', 152, struct lagg_reqopts) 159287723Shrs#define SIOCSLAGGOPTS _IOW('i', 153, struct lagg_reqopts) 160287723Shrs 161287723Shrs#define LAGG_OPT_BITS "\020\001USE_FLOWID\005LACP_STRICT" \ 162287723Shrs "\006LACP_TXTEST\007LACP_RXTEST" 163287723Shrs 164168793Sthompsa#ifdef _KERNEL 165249506Sglebius 166249506Sglebius#include <sys/counter.h> 167249506Sglebius 168168793Sthompsa/* 169168793Sthompsa * Internal kernel part 170168793Sthompsa */ 171168793Sthompsa 172170599Sthompsa#define lp_ifname lp_ifp->if_xname /* interface name */ 173170599Sthompsa#define lp_link_state lp_ifp->if_link_state /* link state */ 174168793Sthompsa 175170599Sthompsa#define LAGG_PORTACTIVE(_tp) ( \ 176168793Sthompsa ((_tp)->lp_link_state == LINK_STATE_UP) && \ 177170599Sthompsa ((_tp)->lp_ifp->if_flags & IFF_UP) \ 178168793Sthompsa) 179168793Sthompsa 180168793Sthompsastruct lagg_ifreq { 181168793Sthompsa union { 182168793Sthompsa struct ifreq ifreq; 183168793Sthompsa struct { 184168793Sthompsa char ifr_name[IFNAMSIZ]; 185168793Sthompsa struct sockaddr_storage ifr_ss; 186168793Sthompsa } ifreq_storage; 187168793Sthompsa } ifreq; 188168793Sthompsa}; 189168793Sthompsa 190170599Sthompsa#define sc_ifflags sc_ifp->if_flags /* flags */ 191170599Sthompsa#define sc_ifname sc_ifp->if_xname /* name */ 192170599Sthompsa#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 193168793Sthompsa 194170599Sthompsa#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 195170599Sthompsa#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 196168793Sthompsa 197168793Sthompsa/* Private data used by the loadbalancing protocol */ 198168793Sthompsastruct lagg_lb { 199168793Sthompsa u_int32_t lb_key; 200168793Sthompsa struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 201168793Sthompsa}; 202168793Sthompsa 203168793Sthompsastruct lagg_mc { 204270136Smav struct sockaddr_dl mc_addr; 205169327Sthompsa struct ifmultiaddr *mc_ifma; 206169327Sthompsa SLIST_ENTRY(lagg_mc) mc_entries; 207168793Sthompsa}; 208168793Sthompsa 209169329Sthompsa/* List of interfaces to have the MAC address modified */ 210169329Sthompsastruct lagg_llq { 211169329Sthompsa struct ifnet *llq_ifp; 212169329Sthompsa uint8_t llq_lladdr[ETHER_ADDR_LEN]; 213287723Shrs uint8_t llq_primary; 214169329Sthompsa SLIST_ENTRY(lagg_llq) llq_entries; 215169329Sthompsa}; 216169329Sthompsa 217168793Sthompsastruct lagg_softc { 218168793Sthompsa struct ifnet *sc_ifp; /* virtual interface */ 219255038Sadrian struct rmlock sc_mtx; 220255038Sadrian struct mtx sc_call_mtx; 221168793Sthompsa int sc_proto; /* lagg protocol */ 222168793Sthompsa u_int sc_count; /* number of ports */ 223253314Sadrian u_int sc_active; /* active port count */ 224253314Sadrian u_int sc_flapping; /* number of flapping 225253314Sadrian * events */ 226168793Sthompsa struct lagg_port *sc_primary; /* primary port */ 227168793Sthompsa struct ifmedia sc_media; /* media config */ 228168793Sthompsa caddr_t sc_psc; /* protocol data */ 229172554Sthompsa uint32_t sc_seq; /* sequence counter */ 230232629Sthompsa uint32_t sc_flags; 231168793Sthompsa 232249506Sglebius counter_u64_t sc_ipackets; 233249506Sglebius counter_u64_t sc_opackets; 234249506Sglebius counter_u64_t sc_ibytes; 235249506Sglebius counter_u64_t sc_obytes; 236249506Sglebius 237168793Sthompsa SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 238168793Sthompsa SLIST_ENTRY(lagg_softc) sc_entries; 239168793Sthompsa 240169329Sthompsa struct task sc_lladdr_task; 241169329Sthompsa SLIST_HEAD(__llqhd, lagg_llq) sc_llq_head; /* interfaces to program 242169329Sthompsa the lladdr on */ 243169329Sthompsa 244168793Sthompsa /* lagg protocol callbacks */ 245168793Sthompsa int (*sc_detach)(struct lagg_softc *); 246168793Sthompsa int (*sc_start)(struct lagg_softc *, struct mbuf *); 247168793Sthompsa struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *, 248168793Sthompsa struct mbuf *); 249168793Sthompsa int (*sc_port_create)(struct lagg_port *); 250168793Sthompsa void (*sc_port_destroy)(struct lagg_port *); 251168793Sthompsa void (*sc_linkstate)(struct lagg_port *); 252168793Sthompsa void (*sc_init)(struct lagg_softc *); 253168793Sthompsa void (*sc_stop)(struct lagg_softc *); 254168793Sthompsa void (*sc_lladdr)(struct lagg_softc *); 255171247Sthompsa void (*sc_req)(struct lagg_softc *, caddr_t); 256171247Sthompsa void (*sc_portreq)(struct lagg_port *, caddr_t); 257203548Seri eventhandler_tag vlan_attach; 258203548Seri eventhandler_tag vlan_detach; 259249506Sglebius struct callout sc_callout; 260287723Shrs u_int sc_opts; 261281955Shiren int flowid_shift; /* set flowid shift*/ 262168793Sthompsa}; 263168793Sthompsa 264168793Sthompsastruct lagg_port { 265168793Sthompsa struct ifnet *lp_ifp; /* physical interface */ 266170599Sthompsa struct lagg_softc *lp_softc; /* parent lagg */ 267168793Sthompsa uint8_t lp_lladdr[ETHER_ADDR_LEN]; 268168793Sthompsa 269168793Sthompsa u_char lp_iftype; /* interface type */ 270168793Sthompsa uint32_t lp_prio; /* port priority */ 271168793Sthompsa uint32_t lp_flags; /* port flags */ 272168793Sthompsa int lp_ifflags; /* saved ifp flags */ 273168793Sthompsa void *lh_cookie; /* if state hook */ 274168793Sthompsa caddr_t lp_psc; /* protocol data */ 275169328Sthompsa int lp_detaching; /* ifnet is detaching */ 276168793Sthompsa 277169327Sthompsa SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 278169327Sthompsa 279168793Sthompsa /* Redirected callbacks */ 280168793Sthompsa int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 281249925Sglebius int (*lp_output)(struct ifnet *, struct mbuf *, 282249925Sglebius const struct sockaddr *, struct route *); 283168793Sthompsa 284168793Sthompsa SLIST_ENTRY(lagg_port) lp_entries; 285168793Sthompsa}; 286168793Sthompsa 287255038Sadrian#define LAGG_LOCK_INIT(_sc) rm_init(&(_sc)->sc_mtx, "if_lagg rmlock") 288255038Sadrian#define LAGG_LOCK_DESTROY(_sc) rm_destroy(&(_sc)->sc_mtx) 289255038Sadrian#define LAGG_RLOCK(_sc, _p) rm_rlock(&(_sc)->sc_mtx, (_p)) 290255038Sadrian#define LAGG_WLOCK(_sc) rm_wlock(&(_sc)->sc_mtx) 291255038Sadrian#define LAGG_RUNLOCK(_sc, _p) rm_runlock(&(_sc)->sc_mtx, (_p)) 292255038Sadrian#define LAGG_WUNLOCK(_sc) rm_wunlock(&(_sc)->sc_mtx) 293255038Sadrian#define LAGG_RLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_RLOCKED) 294255038Sadrian#define LAGG_WLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_WLOCKED) 295168793Sthompsa 296255038Sadrian#define LAGG_CALLOUT_LOCK_INIT(_sc) \ 297255038Sadrian mtx_init(&(_sc)->sc_call_mtx, "if_lagg callout mutex", NULL,\ 298255038Sadrian MTX_DEF) 299255038Sadrian#define LAGG_CALLOUT_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_call_mtx) 300255038Sadrian 301168793Sthompsaextern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 302168793Sthompsaextern void (*lagg_linkstate_p)(struct ifnet *, int ); 303168793Sthompsa 304168793Sthompsaint lagg_enqueue(struct ifnet *, struct mbuf *); 305232629Sthompsauint32_t lagg_hashmbuf(struct lagg_softc *, struct mbuf *, uint32_t); 306168793Sthompsa 307253314SadrianSYSCTL_DECL(_net_link_lagg); 308253314Sadrian 309168793Sthompsa#endif /* _KERNEL */ 310168793Sthompsa 311168793Sthompsa#endif /* _NET_LAGG_H */ 312