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: stable/11/sys/net/if_lagg.h 362366 2020-06-19 06:35:57Z rpokala $ 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 */ 50272159Sglebiustypedef enum { 51272159Sglebius LAGG_PROTO_NONE = 0, /* no lagg protocol defined */ 52272159Sglebius LAGG_PROTO_ROUNDROBIN, /* simple round robin */ 53272159Sglebius LAGG_PROTO_FAILOVER, /* active failover */ 54272159Sglebius LAGG_PROTO_LOADBALANCE, /* loadbalance */ 55272159Sglebius LAGG_PROTO_LACP, /* 802.3ad lacp */ 56272159Sglebius LAGG_PROTO_BROADCAST, /* broadcast */ 57272159Sglebius LAGG_PROTO_MAX, 58272159Sglebius} lagg_proto; 59168793Sthompsa 60168793Sthompsastruct lagg_protos { 61170599Sthompsa const char *lpr_name; 62272159Sglebius lagg_proto lpr_proto; 63168793Sthompsa}; 64168793Sthompsa 65168793Sthompsa#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 66168793Sthompsa#define LAGG_PROTOS { \ 67271732Saraujo { "failover", LAGG_PROTO_FAILOVER }, \ 68168793Sthompsa { "lacp", LAGG_PROTO_LACP }, \ 69168793Sthompsa { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 70271732Saraujo { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 71271732Saraujo { "broadcast", LAGG_PROTO_BROADCAST }, \ 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 139272446Shrsstruct lagg_reqopts { 140272446Shrs char ro_ifname[IFNAMSIZ]; /* name of the lagg */ 141272446Shrs 142272446Shrs int ro_opts; /* Option bitmap */ 143272446Shrs#define LAGG_OPT_NONE 0x00 144275358Shselasky#define LAGG_OPT_USE_FLOWID 0x01 /* enable use of flowid */ 145272446Shrs/* Pseudo flags which are used in ro_opts but not stored into sc_opts. */ 146275358Shselasky#define LAGG_OPT_FLOWIDSHIFT 0x02 /* set flowid shift */ 147272446Shrs#define LAGG_OPT_FLOWIDSHIFT_MASK 0x1f /* flowid is uint32_t */ 148272446Shrs#define LAGG_OPT_LACP_STRICT 0x10 /* LACP strict mode */ 149272446Shrs#define LAGG_OPT_LACP_TXTEST 0x20 /* LACP debug: txtest */ 150272446Shrs#define LAGG_OPT_LACP_RXTEST 0x40 /* LACP debug: rxtest */ 151362366Srpokala#define LAGG_OPT_LACP_FAST_TIMO 0x80 /* LACP fast timeout */ 152272446Shrs u_int ro_count; /* number of ports */ 153272446Shrs u_int ro_active; /* active port count */ 154272446Shrs u_int ro_flapping; /* number of flapping */ 155272446Shrs int ro_flowid_shift; /* shift the flowid */ 156294615Saraujo uint32_t ro_bkt; /* packet bucket for roundrobin */ 157272446Shrs}; 158272446Shrs 159272446Shrs#define SIOCGLAGGOPTS _IOWR('i', 152, struct lagg_reqopts) 160272446Shrs#define SIOCSLAGGOPTS _IOW('i', 153, struct lagg_reqopts) 161272446Shrs 162272547Shrs#define LAGG_OPT_BITS "\020\001USE_FLOWID\005LACP_STRICT" \ 163362366Srpokala "\006LACP_TXTEST\007LACP_RXTEST" \ 164362366Srpokala "\010LACP_FAST_TIMO" 165272547Shrs 166168793Sthompsa#ifdef _KERNEL 167249506Sglebius 168168793Sthompsa/* 169168793Sthompsa * Internal kernel part 170168793Sthompsa */ 171168793Sthompsa 172170599Sthompsa#define LAGG_PORTACTIVE(_tp) ( \ 173272179Sglebius ((_tp)->lp_ifp->if_link_state == LINK_STATE_UP) && \ 174170599Sthompsa ((_tp)->lp_ifp->if_flags & IFF_UP) \ 175168793Sthompsa) 176168793Sthompsa 177168793Sthompsastruct lagg_ifreq { 178168793Sthompsa union { 179168793Sthompsa struct ifreq ifreq; 180168793Sthompsa struct { 181168793Sthompsa char ifr_name[IFNAMSIZ]; 182168793Sthompsa struct sockaddr_storage ifr_ss; 183168793Sthompsa } ifreq_storage; 184168793Sthompsa } ifreq; 185168793Sthompsa}; 186168793Sthompsa 187170599Sthompsa#define sc_ifflags sc_ifp->if_flags /* flags */ 188170599Sthompsa#define sc_ifname sc_ifp->if_xname /* name */ 189168793Sthompsa 190168793Sthompsa/* Private data used by the loadbalancing protocol */ 191168793Sthompsastruct lagg_lb { 192168793Sthompsa u_int32_t lb_key; 193168793Sthompsa struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 194168793Sthompsa}; 195168793Sthompsa 196168793Sthompsastruct lagg_mc { 197269492Smav struct sockaddr_dl mc_addr; 198169327Sthompsa struct ifmultiaddr *mc_ifma; 199169327Sthompsa SLIST_ENTRY(lagg_mc) mc_entries; 200168793Sthompsa}; 201168793Sthompsa 202272211Smelifarostruct lagg_counters { 203272244Sglebius uint64_t val[IFCOUNTERS]; 204272211Smelifaro}; 205272211Smelifaro 206168793Sthompsastruct lagg_softc { 207168793Sthompsa struct ifnet *sc_ifp; /* virtual interface */ 208255038Sadrian struct rmlock sc_mtx; 209318329Smav struct sx sc_sx; 210168793Sthompsa int sc_proto; /* lagg protocol */ 211168793Sthompsa u_int sc_count; /* number of ports */ 212253314Sadrian u_int sc_active; /* active port count */ 213253314Sadrian u_int sc_flapping; /* number of flapping 214253314Sadrian * events */ 215168793Sthompsa struct lagg_port *sc_primary; /* primary port */ 216168793Sthompsa struct ifmedia sc_media; /* media config */ 217272175Sglebius void *sc_psc; /* protocol data */ 218172554Sthompsa uint32_t sc_seq; /* sequence counter */ 219232629Sthompsa uint32_t sc_flags; 220318329Smav int sc_destroying; /* destroying lagg */ 221168793Sthompsa 222168793Sthompsa SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 223168793Sthompsa SLIST_ENTRY(lagg_softc) sc_entries; 224168793Sthompsa 225203548Seri eventhandler_tag vlan_attach; 226203548Seri eventhandler_tag vlan_detach; 227249506Sglebius struct callout sc_callout; 228272386Shrs u_int sc_opts; 229260070Sscottl int flowid_shift; /* shift the flowid */ 230294615Saraujo uint32_t sc_bkt; /* packates bucket for roundrobin */ 231294615Saraujo uint32_t sc_bkt_count; /* packates bucket count for roundrobin */ 232272211Smelifaro struct lagg_counters detached_counters; /* detached ports sum */ 233168793Sthompsa}; 234168793Sthompsa 235168793Sthompsastruct lagg_port { 236168793Sthompsa struct ifnet *lp_ifp; /* physical interface */ 237170599Sthompsa struct lagg_softc *lp_softc; /* parent lagg */ 238168793Sthompsa uint8_t lp_lladdr[ETHER_ADDR_LEN]; 239168793Sthompsa 240168793Sthompsa u_char lp_iftype; /* interface type */ 241168793Sthompsa uint32_t lp_prio; /* port priority */ 242168793Sthompsa uint32_t lp_flags; /* port flags */ 243168793Sthompsa int lp_ifflags; /* saved ifp flags */ 244318329Smav int lp_ifcapenable; /* saved ifp capenable */ 245168793Sthompsa void *lh_cookie; /* if state hook */ 246272175Sglebius void *lp_psc; /* protocol data */ 247169328Sthompsa int lp_detaching; /* ifnet is detaching */ 248169327Sthompsa SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 249169327Sthompsa 250168793Sthompsa /* Redirected callbacks */ 251168793Sthompsa int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 252249925Sglebius int (*lp_output)(struct ifnet *, struct mbuf *, 253249925Sglebius const struct sockaddr *, struct route *); 254272211Smelifaro struct lagg_counters port_counters; /* ifp counters copy */ 255168793Sthompsa 256168793Sthompsa SLIST_ENTRY(lagg_port) lp_entries; 257168793Sthompsa}; 258168793Sthompsa 259255038Sadrian#define LAGG_LOCK_INIT(_sc) rm_init(&(_sc)->sc_mtx, "if_lagg rmlock") 260255038Sadrian#define LAGG_LOCK_DESTROY(_sc) rm_destroy(&(_sc)->sc_mtx) 261255038Sadrian#define LAGG_RLOCK(_sc, _p) rm_rlock(&(_sc)->sc_mtx, (_p)) 262255038Sadrian#define LAGG_WLOCK(_sc) rm_wlock(&(_sc)->sc_mtx) 263255038Sadrian#define LAGG_RUNLOCK(_sc, _p) rm_runlock(&(_sc)->sc_mtx, (_p)) 264255038Sadrian#define LAGG_WUNLOCK(_sc) rm_wunlock(&(_sc)->sc_mtx) 265255038Sadrian#define LAGG_RLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_RLOCKED) 266255038Sadrian#define LAGG_WLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_WLOCKED) 267290239Smelifaro#define LAGG_UNLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_UNLOCKED) 268168793Sthompsa 269318329Smav#define LAGG_SX_INIT(_sc) sx_init(&(_sc)->sc_sx, "if_lagg sx") 270318329Smav#define LAGG_SX_DESTROY(_sc) sx_destroy(&(_sc)->sc_sx) 271318329Smav#define LAGG_SLOCK(_sc) sx_slock(&(_sc)->sc_sx) 272318329Smav#define LAGG_XLOCK(_sc) sx_xlock(&(_sc)->sc_sx) 273318329Smav#define LAGG_SUNLOCK(_sc) sx_sunlock(&(_sc)->sc_sx) 274318329Smav#define LAGG_XUNLOCK(_sc) sx_xunlock(&(_sc)->sc_sx) 275318329Smav#define LAGG_SXLOCK_ASSERT(_sc) sx_assert(&(_sc)->sc_sx, SA_LOCKED) 276318329Smav#define LAGG_SLOCK_ASSERT(_sc) sx_assert(&(_sc)->sc_sx, SA_SLOCKED) 277318329Smav#define LAGG_XLOCK_ASSERT(_sc) sx_assert(&(_sc)->sc_sx, SA_XLOCKED) 278318329Smav 279168793Sthompsaextern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 280292402Ssmhextern void (*lagg_linkstate_p)(struct ifnet *, int ); 281168793Sthompsa 282168793Sthompsaint lagg_enqueue(struct ifnet *, struct mbuf *); 283168793Sthompsa 284253314SadrianSYSCTL_DECL(_net_link_lagg); 285253314Sadrian 286168793Sthompsa#endif /* _KERNEL */ 287168793Sthompsa 288168793Sthompsa#endif /* _NET_LAGG_H */ 289