if_lagg.h revision 279891
190792Sgshapiro/* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */ 290792Sgshapiro 390792Sgshapiro/* 490792Sgshapiro * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org> 590792Sgshapiro * 690792Sgshapiro * Permission to use, copy, modify, and distribute this software for any 790792Sgshapiro * purpose with or without fee is hereby granted, provided that the above 890792Sgshapiro * copyright notice and this permission notice appear in all copies. 990792Sgshapiro * 1090792Sgshapiro * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1190792Sgshapiro * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1290792Sgshapiro * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1390792Sgshapiro * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1490792Sgshapiro * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1590792Sgshapiro * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1690792Sgshapiro * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1790792Sgshapiro * 1890792Sgshapiro * $FreeBSD: head/sys/net/if_lagg.h 279891 2015-03-11 16:02:24Z hselasky $ 1990792Sgshapiro */ 2090792Sgshapiro 2190792Sgshapiro#ifndef _NET_LAGG_H 2290792Sgshapiro#define _NET_LAGG_H 2390792Sgshapiro 2490792Sgshapiro/* 2590792Sgshapiro * Global definitions 2690792Sgshapiro */ 2790792Sgshapiro 2890792Sgshapiro#define LAGG_MAX_PORTS 32 /* logically */ 2990792Sgshapiro#define LAGG_MAX_NAMESIZE 32 /* name of a protocol */ 3090792Sgshapiro#define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */ 3190792Sgshapiro 3290792Sgshapiro/* Lagg flags */ 3390792Sgshapiro#define LAGG_F_HASHL2 0x00000001 /* hash layer 2 */ 3490792Sgshapiro#define LAGG_F_HASHL3 0x00000002 /* hash layer 3 */ 3590792Sgshapiro#define LAGG_F_HASHL4 0x00000004 /* hash layer 4 */ 3690792Sgshapiro#define LAGG_F_HASHMASK 0x00000007 3790792Sgshapiro 3890792Sgshapiro/* Port flags */ 3990792Sgshapiro#define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */ 4090792Sgshapiro#define LAGG_PORT_MASTER 0x00000001 /* primary port */ 4190792Sgshapiro#define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */ 4290792Sgshapiro#define LAGG_PORT_ACTIVE 0x00000004 /* port is active */ 4390792Sgshapiro#define LAGG_PORT_COLLECTING 0x00000008 /* port is receiving frames */ 4490792Sgshapiro#define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */ 4590792Sgshapiro#define LAGG_PORT_DISABLED 0x00000020 /* port is disabled */ 4690792Sgshapiro#define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \ 4790792Sgshapiro "\05DISTRIBUTING\06DISABLED" 4890792Sgshapiro 4990792Sgshapiro/* Supported lagg PROTOs */ 5090792Sgshapirotypedef enum { 5190792Sgshapiro LAGG_PROTO_NONE = 0, /* no lagg protocol defined */ 5290792Sgshapiro LAGG_PROTO_ROUNDROBIN, /* simple round robin */ 5390792Sgshapiro LAGG_PROTO_FAILOVER, /* active failover */ 5490792Sgshapiro LAGG_PROTO_LOADBALANCE, /* loadbalance */ 5590792Sgshapiro LAGG_PROTO_LACP, /* 802.3ad lacp */ 5690792Sgshapiro LAGG_PROTO_ETHERCHANNEL,/* Cisco FEC */ 5790792Sgshapiro LAGG_PROTO_BROADCAST, /* broadcast */ 5890792Sgshapiro LAGG_PROTO_MAX, 5990792Sgshapiro} lagg_proto; 6090792Sgshapiro 6190792Sgshapirostruct lagg_protos { 6290792Sgshapiro const char *lpr_name; 6390792Sgshapiro lagg_proto lpr_proto; 6490792Sgshapiro}; 6590792Sgshapiro 6690792Sgshapiro#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 6790792Sgshapiro#define LAGG_PROTOS { \ 6890792Sgshapiro { "failover", LAGG_PROTO_FAILOVER }, \ 6990792Sgshapiro { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 7090792Sgshapiro { "lacp", LAGG_PROTO_LACP }, \ 7190792Sgshapiro { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 7290792Sgshapiro { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 7390792Sgshapiro { "broadcast", LAGG_PROTO_BROADCAST }, \ 7490792Sgshapiro { "none", LAGG_PROTO_NONE }, \ 7590792Sgshapiro { "default", LAGG_PROTO_DEFAULT } \ 7690792Sgshapiro} 7790792Sgshapiro 7890792Sgshapiro/* 7990792Sgshapiro * lagg ioctls. 8090792Sgshapiro */ 8190792Sgshapiro 8290792Sgshapiro/* 8390792Sgshapiro * LACP current operational parameters structure. 8490792Sgshapiro */ 8590792Sgshapirostruct lacp_opreq { 8690792Sgshapiro uint16_t actor_prio; 8790792Sgshapiro uint8_t actor_mac[ETHER_ADDR_LEN]; 8890792Sgshapiro uint16_t actor_key; 8990792Sgshapiro uint16_t actor_portprio; 9090792Sgshapiro uint16_t actor_portno; 9190792Sgshapiro uint8_t actor_state; 9290792Sgshapiro uint16_t partner_prio; 9390792Sgshapiro uint8_t partner_mac[ETHER_ADDR_LEN]; 9490792Sgshapiro uint16_t partner_key; 9590792Sgshapiro uint16_t partner_portprio; 9690792Sgshapiro uint16_t partner_portno; 9790792Sgshapiro uint8_t partner_state; 9890792Sgshapiro}; 9990792Sgshapiro 10090792Sgshapiro/* lagg port settings */ 10190792Sgshapirostruct lagg_reqport { 10290792Sgshapiro char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 10390792Sgshapiro char rp_portname[IFNAMSIZ]; /* name of the port */ 10490792Sgshapiro u_int32_t rp_prio; /* port priority */ 10590792Sgshapiro u_int32_t rp_flags; /* port flags */ 10690792Sgshapiro union { 10790792Sgshapiro struct lacp_opreq rpsc_lacp; 10890792Sgshapiro } rp_psc; 10990792Sgshapiro#define rp_lacpreq rp_psc.rpsc_lacp 11090792Sgshapiro}; 11190792Sgshapiro 11290792Sgshapiro#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 11390792Sgshapiro#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 11490792Sgshapiro#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 11590792Sgshapiro 11690792Sgshapiro/* lagg, ports and options */ 11790792Sgshapirostruct lagg_reqall { 11890792Sgshapiro char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 11990792Sgshapiro u_int ra_proto; /* lagg protocol */ 12090792Sgshapiro 12190792Sgshapiro size_t ra_size; /* size of buffer */ 12290792Sgshapiro struct lagg_reqport *ra_port; /* allocated buffer */ 12390792Sgshapiro int ra_ports; /* total port count */ 12490792Sgshapiro union { 12590792Sgshapiro struct lacp_opreq rpsc_lacp; 12690792Sgshapiro } ra_psc; 12790792Sgshapiro#define ra_lacpreq ra_psc.rpsc_lacp 12890792Sgshapiro}; 12990792Sgshapiro 13090792Sgshapiro#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 13190792Sgshapiro#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 13290792Sgshapiro 13390792Sgshapirostruct lagg_reqflags { 13490792Sgshapiro char rf_ifname[IFNAMSIZ]; /* name of the lagg */ 13590792Sgshapiro uint32_t rf_flags; /* lagg protocol */ 13690792Sgshapiro}; 13790792Sgshapiro 13890792Sgshapiro#define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags) 13990792Sgshapiro#define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags) 14090792Sgshapiro 14190792Sgshapirostruct lagg_reqopts { 14290792Sgshapiro char ro_ifname[IFNAMSIZ]; /* name of the lagg */ 14390792Sgshapiro 14490792Sgshapiro int ro_opts; /* Option bitmap */ 14590792Sgshapiro#define LAGG_OPT_NONE 0x00 14690792Sgshapiro#define LAGG_OPT_USE_FLOWID 0x01 /* enable use of flowid */ 14790792Sgshapiro/* Pseudo flags which are used in ro_opts but not stored into sc_opts. */ 14890792Sgshapiro#define LAGG_OPT_FLOWIDSHIFT 0x02 /* set flowid shift */ 14990792Sgshapiro#define LAGG_OPT_FLOWIDSHIFT_MASK 0x1f /* flowid is uint32_t */ 15090792Sgshapiro#define LAGG_OPT_LACP_STRICT 0x10 /* LACP strict mode */ 15190792Sgshapiro#define LAGG_OPT_LACP_TXTEST 0x20 /* LACP debug: txtest */ 15290792Sgshapiro#define LAGG_OPT_LACP_RXTEST 0x40 /* LACP debug: rxtest */ 15390792Sgshapiro u_int ro_count; /* number of ports */ 15490792Sgshapiro u_int ro_active; /* active port count */ 15590792Sgshapiro u_int ro_flapping; /* number of flapping */ 15690792Sgshapiro int ro_flowid_shift; /* shift the flowid */ 15790792Sgshapiro}; 15890792Sgshapiro 15990792Sgshapiro#define SIOCGLAGGOPTS _IOWR('i', 152, struct lagg_reqopts) 16090792Sgshapiro#define SIOCSLAGGOPTS _IOW('i', 153, struct lagg_reqopts) 16190792Sgshapiro 16290792Sgshapiro#define LAGG_OPT_BITS "\020\001USE_FLOWID\005LACP_STRICT" \ 16390792Sgshapiro "\006LACP_TXTEST\007LACP_RXTEST" 16490792Sgshapiro 16590792Sgshapiro#ifdef _KERNEL 16690792Sgshapiro 16790792Sgshapiro/* 16890792Sgshapiro * Internal kernel part 16990792Sgshapiro */ 17090792Sgshapiro 17190792Sgshapiro#define LAGG_PORTACTIVE(_tp) ( \ 17290792Sgshapiro ((_tp)->lp_ifp->if_link_state == LINK_STATE_UP) && \ 17390792Sgshapiro ((_tp)->lp_ifp->if_flags & IFF_UP) \ 17490792Sgshapiro) 17590792Sgshapiro 17690792Sgshapirostruct lagg_ifreq { 17790792Sgshapiro union { 17890792Sgshapiro struct ifreq ifreq; 17990792Sgshapiro struct { 18090792Sgshapiro char ifr_name[IFNAMSIZ]; 18190792Sgshapiro struct sockaddr_storage ifr_ss; 18290792Sgshapiro } ifreq_storage; 18390792Sgshapiro } ifreq; 18490792Sgshapiro}; 18590792Sgshapiro 18690792Sgshapiro#define sc_ifflags sc_ifp->if_flags /* flags */ 18790792Sgshapiro#define sc_ifname sc_ifp->if_xname /* name */ 18890792Sgshapiro#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 18990792Sgshapiro 19090792Sgshapiro#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 19190792Sgshapiro#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 19290792Sgshapiro 19390792Sgshapiro/* Private data used by the loadbalancing protocol */ 19490792Sgshapirostruct lagg_lb { 19590792Sgshapiro u_int32_t lb_key; 19690792Sgshapiro struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 19790792Sgshapiro}; 19890792Sgshapiro 19990792Sgshapirostruct lagg_mc { 20090792Sgshapiro struct sockaddr_dl mc_addr; 20190792Sgshapiro struct ifmultiaddr *mc_ifma; 20290792Sgshapiro SLIST_ENTRY(lagg_mc) mc_entries; 20390792Sgshapiro}; 20490792Sgshapiro 20590792Sgshapiro/* List of interfaces to have the MAC address modified */ 20690792Sgshapirostruct lagg_llq { 20790792Sgshapiro struct ifnet *llq_ifp; 20890792Sgshapiro uint8_t llq_lladdr[ETHER_ADDR_LEN]; 20990792Sgshapiro uint8_t llq_primary; 21090792Sgshapiro SLIST_ENTRY(lagg_llq) llq_entries; 21190792Sgshapiro}; 21290792Sgshapiro 21390792Sgshapirostruct lagg_counters { 21490792Sgshapiro uint64_t val[IFCOUNTERS]; 21590792Sgshapiro}; 21690792Sgshapiro 21790792Sgshapirostruct lagg_softc { 21890792Sgshapiro struct ifnet *sc_ifp; /* virtual interface */ 21990792Sgshapiro struct rmlock sc_mtx; 22090792Sgshapiro int sc_proto; /* lagg protocol */ 22190792Sgshapiro u_int sc_count; /* number of ports */ 22290792Sgshapiro u_int sc_active; /* active port count */ 22390792Sgshapiro u_int sc_flapping; /* number of flapping 22490792Sgshapiro * events */ 22590792Sgshapiro struct lagg_port *sc_primary; /* primary port */ 22690792Sgshapiro struct ifmedia sc_media; /* media config */ 22790792Sgshapiro void *sc_psc; /* protocol data */ 22890792Sgshapiro uint32_t sc_seq; /* sequence counter */ 22990792Sgshapiro uint32_t sc_flags; 23090792Sgshapiro 23190792Sgshapiro SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 23290792Sgshapiro SLIST_ENTRY(lagg_softc) sc_entries; 23390792Sgshapiro 23490792Sgshapiro struct task sc_lladdr_task; 23590792Sgshapiro SLIST_HEAD(__llqhd, lagg_llq) sc_llq_head; /* interfaces to program 23690792Sgshapiro the lladdr on */ 23790792Sgshapiro eventhandler_tag vlan_attach; 23890792Sgshapiro eventhandler_tag vlan_detach; 23990792Sgshapiro struct callout sc_callout; 24090792Sgshapiro u_int sc_opts; 24190792Sgshapiro int flowid_shift; /* shift the flowid */ 24290792Sgshapiro struct lagg_counters detached_counters; /* detached ports sum */ 24390792Sgshapiro}; 24490792Sgshapiro 24590792Sgshapirostruct lagg_port { 24690792Sgshapiro struct ifnet *lp_ifp; /* physical interface */ 24790792Sgshapiro struct lagg_softc *lp_softc; /* parent lagg */ 24890792Sgshapiro uint8_t lp_lladdr[ETHER_ADDR_LEN]; 24990792Sgshapiro 25090792Sgshapiro u_char lp_iftype; /* interface type */ 25190792Sgshapiro uint32_t lp_prio; /* port priority */ 25290792Sgshapiro uint32_t lp_flags; /* port flags */ 25390792Sgshapiro int lp_ifflags; /* saved ifp flags */ 25490792Sgshapiro void *lh_cookie; /* if state hook */ 25590792Sgshapiro void *lp_psc; /* protocol data */ 25690792Sgshapiro int lp_detaching; /* ifnet is detaching */ 25790792Sgshapiro 25890792Sgshapiro SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 25990792Sgshapiro 26090792Sgshapiro /* Redirected callbacks */ 26190792Sgshapiro int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 26290792Sgshapiro int (*lp_output)(struct ifnet *, struct mbuf *, 26390792Sgshapiro const struct sockaddr *, struct route *); 26490792Sgshapiro struct lagg_counters port_counters; /* ifp counters copy */ 26590792Sgshapiro 26690792Sgshapiro SLIST_ENTRY(lagg_port) lp_entries; 26790792Sgshapiro}; 26890792Sgshapiro 26990792Sgshapiro#define LAGG_LOCK_INIT(_sc) rm_init(&(_sc)->sc_mtx, "if_lagg rmlock") 27090792Sgshapiro#define LAGG_LOCK_DESTROY(_sc) rm_destroy(&(_sc)->sc_mtx) 27190792Sgshapiro#define LAGG_RLOCK(_sc, _p) rm_rlock(&(_sc)->sc_mtx, (_p)) 27290792Sgshapiro#define LAGG_WLOCK(_sc) rm_wlock(&(_sc)->sc_mtx) 27390792Sgshapiro#define LAGG_RUNLOCK(_sc, _p) rm_runlock(&(_sc)->sc_mtx, (_p)) 27490792Sgshapiro#define LAGG_WUNLOCK(_sc) rm_wunlock(&(_sc)->sc_mtx) 27590792Sgshapiro#define LAGG_RLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_RLOCKED) 27690792Sgshapiro#define LAGG_WLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_WLOCKED) 27790792Sgshapiro 27890792Sgshapiroextern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 27990792Sgshapiroextern void (*lagg_linkstate_p)(struct ifnet *, int ); 28090792Sgshapiro 28190792Sgshapiroint lagg_enqueue(struct ifnet *, struct mbuf *); 28290792Sgshapiro 28390792SgshapiroSYSCTL_DECL(_net_link_lagg); 28490792Sgshapiro 28590792Sgshapiro#endif /* _KERNEL */ 28690792Sgshapiro 28790792Sgshapiro#endif /* _NET_LAGG_H */ 28890792Sgshapiro