118242d3bSAndrew Thompson /* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */ 218242d3bSAndrew Thompson 318242d3bSAndrew Thompson /* 418242d3bSAndrew Thompson * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org> 518242d3bSAndrew Thompson * 618242d3bSAndrew Thompson * Permission to use, copy, modify, and distribute this software for any 718242d3bSAndrew Thompson * purpose with or without fee is hereby granted, provided that the above 818242d3bSAndrew Thompson * copyright notice and this permission notice appear in all copies. 918242d3bSAndrew Thompson * 1018242d3bSAndrew Thompson * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1118242d3bSAndrew Thompson * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1218242d3bSAndrew Thompson * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1318242d3bSAndrew Thompson * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1418242d3bSAndrew Thompson * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1518242d3bSAndrew Thompson * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1618242d3bSAndrew Thompson * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1718242d3bSAndrew Thompson */ 1818242d3bSAndrew Thompson 1918242d3bSAndrew Thompson #ifndef _NET_LAGG_H 2018242d3bSAndrew Thompson #define _NET_LAGG_H 2118242d3bSAndrew Thompson 2218242d3bSAndrew Thompson /* 2318242d3bSAndrew Thompson * Global definitions 2418242d3bSAndrew Thompson */ 2518242d3bSAndrew Thompson 2618242d3bSAndrew Thompson #define LAGG_MAX_PORTS 32 /* logically */ 2718242d3bSAndrew Thompson #define LAGG_MAX_NAMESIZE 32 /* name of a protocol */ 2818242d3bSAndrew Thompson #define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */ 2918242d3bSAndrew Thompson 3086f67641SAndrew Thompson /* Lagg flags */ 3186f67641SAndrew Thompson #define LAGG_F_HASHL2 0x00000001 /* hash layer 2 */ 3286f67641SAndrew Thompson #define LAGG_F_HASHL3 0x00000002 /* hash layer 3 */ 3386f67641SAndrew Thompson #define LAGG_F_HASHL4 0x00000004 /* hash layer 4 */ 3486f67641SAndrew Thompson #define LAGG_F_HASHMASK 0x00000007 3586f67641SAndrew Thompson 3618242d3bSAndrew Thompson /* Port flags */ 3718242d3bSAndrew Thompson #define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */ 3818242d3bSAndrew Thompson #define LAGG_PORT_MASTER 0x00000001 /* primary port */ 3918242d3bSAndrew Thompson #define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */ 4018242d3bSAndrew Thompson #define LAGG_PORT_ACTIVE 0x00000004 /* port is active */ 41ff6c5cf6SAndrew Thompson #define LAGG_PORT_COLLECTING 0x00000008 /* port is receiving frames */ 42ff6c5cf6SAndrew Thompson #define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */ 4318242d3bSAndrew Thompson #define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \ 44db5a36bdSMark Johnston "\05DISTRIBUTING" 4518242d3bSAndrew Thompson 4618242d3bSAndrew Thompson /* Supported lagg PROTOs */ 47b5e094cfSGleb Smirnoff typedef enum { 48b5e094cfSGleb Smirnoff LAGG_PROTO_NONE = 0, /* no lagg protocol defined */ 49b5e094cfSGleb Smirnoff LAGG_PROTO_ROUNDROBIN, /* simple round robin */ 50b5e094cfSGleb Smirnoff LAGG_PROTO_FAILOVER, /* active failover */ 51b5e094cfSGleb Smirnoff LAGG_PROTO_LOADBALANCE, /* loadbalance */ 52b5e094cfSGleb Smirnoff LAGG_PROTO_LACP, /* 802.3ad lacp */ 53b5e094cfSGleb Smirnoff LAGG_PROTO_BROADCAST, /* broadcast */ 54b5e094cfSGleb Smirnoff LAGG_PROTO_MAX, 55b5e094cfSGleb Smirnoff } lagg_proto; 5618242d3bSAndrew Thompson 5718242d3bSAndrew Thompson struct lagg_protos { 58ec32b37eSAndrew Thompson const char *lpr_name; 59b5e094cfSGleb Smirnoff lagg_proto lpr_proto; 6018242d3bSAndrew Thompson }; 6118242d3bSAndrew Thompson 6218242d3bSAndrew Thompson #define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 6318242d3bSAndrew Thompson #define LAGG_PROTOS { \ 6418242d3bSAndrew Thompson { "failover", LAGG_PROTO_FAILOVER }, \ 6518242d3bSAndrew Thompson { "lacp", LAGG_PROTO_LACP }, \ 6618242d3bSAndrew Thompson { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 6718242d3bSAndrew Thompson { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 6899cdd961SMarcelo Araujo { "broadcast", LAGG_PROTO_BROADCAST }, \ 6918242d3bSAndrew Thompson { "none", LAGG_PROTO_NONE }, \ 7018242d3bSAndrew Thompson { "default", LAGG_PROTO_DEFAULT } \ 7118242d3bSAndrew Thompson } 7218242d3bSAndrew Thompson 73a92c4bb6SHans Petter Selasky /* Supported lagg TYPEs */ 74a92c4bb6SHans Petter Selasky typedef enum { 75a92c4bb6SHans Petter Selasky LAGG_TYPE_ETHERNET = 0, /* ethernet (default) */ 76a92c4bb6SHans Petter Selasky LAGG_TYPE_INFINIBAND, /* infiniband */ 77a92c4bb6SHans Petter Selasky LAGG_TYPE_MAX, 78a92c4bb6SHans Petter Selasky } lagg_type; 79a92c4bb6SHans Petter Selasky 80a92c4bb6SHans Petter Selasky struct lagg_types { 81a92c4bb6SHans Petter Selasky const char *lt_name; 82a92c4bb6SHans Petter Selasky lagg_type lt_value; 83a92c4bb6SHans Petter Selasky }; 84a92c4bb6SHans Petter Selasky 85a92c4bb6SHans Petter Selasky #define LAGG_TYPE_DEFAULT LAGG_TYPE_ETHERNET 86a92c4bb6SHans Petter Selasky #define LAGG_TYPES { \ 87a92c4bb6SHans Petter Selasky { "ethernet", LAGG_TYPE_ETHERNET }, \ 88a92c4bb6SHans Petter Selasky { "infiniband", LAGG_TYPE_INFINIBAND }, \ 89a92c4bb6SHans Petter Selasky } 90a92c4bb6SHans Petter Selasky 91a92c4bb6SHans Petter Selasky /* 92a92c4bb6SHans Petter Selasky * lagg create clone params 93a92c4bb6SHans Petter Selasky */ 94a92c4bb6SHans Petter Selasky struct iflaggparam { 95a92c4bb6SHans Petter Selasky uint8_t lagg_type; /* see LAGG_TYPE_XXX */ 96a92c4bb6SHans Petter Selasky uint8_t reserved_8[3]; 97a92c4bb6SHans Petter Selasky uint32_t reserved_32[3]; 98a92c4bb6SHans Petter Selasky }; 99a92c4bb6SHans Petter Selasky 10018242d3bSAndrew Thompson /* 10118242d3bSAndrew Thompson * lagg ioctls. 10218242d3bSAndrew Thompson */ 10318242d3bSAndrew Thompson 104b3d37ca5SAndrew Thompson /* 105b3d37ca5SAndrew Thompson * LACP current operational parameters structure. 106b3d37ca5SAndrew Thompson */ 107b3d37ca5SAndrew Thompson struct lacp_opreq { 108b3d37ca5SAndrew Thompson uint16_t actor_prio; 109b3d37ca5SAndrew Thompson uint8_t actor_mac[ETHER_ADDR_LEN]; 110b3d37ca5SAndrew Thompson uint16_t actor_key; 111b3d37ca5SAndrew Thompson uint16_t actor_portprio; 112b3d37ca5SAndrew Thompson uint16_t actor_portno; 113b3d37ca5SAndrew Thompson uint8_t actor_state; 114b3d37ca5SAndrew Thompson uint16_t partner_prio; 115b3d37ca5SAndrew Thompson uint8_t partner_mac[ETHER_ADDR_LEN]; 116b3d37ca5SAndrew Thompson uint16_t partner_key; 117b3d37ca5SAndrew Thompson uint16_t partner_portprio; 118b3d37ca5SAndrew Thompson uint16_t partner_portno; 119b3d37ca5SAndrew Thompson uint8_t partner_state; 120b3d37ca5SAndrew Thompson }; 121b3d37ca5SAndrew Thompson 12218242d3bSAndrew Thompson /* lagg port settings */ 12318242d3bSAndrew Thompson struct lagg_reqport { 12418242d3bSAndrew Thompson char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 12518242d3bSAndrew Thompson char rp_portname[IFNAMSIZ]; /* name of the port */ 12618242d3bSAndrew Thompson u_int32_t rp_prio; /* port priority */ 12718242d3bSAndrew Thompson u_int32_t rp_flags; /* port flags */ 128b3d37ca5SAndrew Thompson union { 129b3d37ca5SAndrew Thompson struct lacp_opreq rpsc_lacp; 130b3d37ca5SAndrew Thompson } rp_psc; 131b3d37ca5SAndrew Thompson #define rp_lacpreq rp_psc.rpsc_lacp 13218242d3bSAndrew Thompson }; 13318242d3bSAndrew Thompson 13418242d3bSAndrew Thompson #define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 13518242d3bSAndrew Thompson #define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 13618242d3bSAndrew Thompson #define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 13718242d3bSAndrew Thompson 13818242d3bSAndrew Thompson /* lagg, ports and options */ 13918242d3bSAndrew Thompson struct lagg_reqall { 14018242d3bSAndrew Thompson char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 14118242d3bSAndrew Thompson u_int ra_proto; /* lagg protocol */ 14218242d3bSAndrew Thompson 14318242d3bSAndrew Thompson size_t ra_size; /* size of buffer */ 14418242d3bSAndrew Thompson struct lagg_reqport *ra_port; /* allocated buffer */ 14518242d3bSAndrew Thompson int ra_ports; /* total port count */ 146b3d37ca5SAndrew Thompson union { 147b3d37ca5SAndrew Thompson struct lacp_opreq rpsc_lacp; 148b3d37ca5SAndrew Thompson } ra_psc; 149b3d37ca5SAndrew Thompson #define ra_lacpreq ra_psc.rpsc_lacp 15018242d3bSAndrew Thompson }; 15118242d3bSAndrew Thompson 15218242d3bSAndrew Thompson #define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 15318242d3bSAndrew Thompson #define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 15418242d3bSAndrew Thompson 15586f67641SAndrew Thompson struct lagg_reqflags { 15686f67641SAndrew Thompson char rf_ifname[IFNAMSIZ]; /* name of the lagg */ 15786f67641SAndrew Thompson uint32_t rf_flags; /* lagg protocol */ 15886f67641SAndrew Thompson }; 15986f67641SAndrew Thompson 16086f67641SAndrew Thompson #define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags) 16186f67641SAndrew Thompson #define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags) 16286f67641SAndrew Thompson 1639732189cSHiroki Sato struct lagg_reqopts { 1649732189cSHiroki Sato char ro_ifname[IFNAMSIZ]; /* name of the lagg */ 1659732189cSHiroki Sato 1669732189cSHiroki Sato int ro_opts; /* Option bitmap */ 1679732189cSHiroki Sato #define LAGG_OPT_NONE 0x00 168c2529042SHans Petter Selasky #define LAGG_OPT_USE_FLOWID 0x01 /* enable use of flowid */ 1699732189cSHiroki Sato /* Pseudo flags which are used in ro_opts but not stored into sc_opts. */ 170c2529042SHans Petter Selasky #define LAGG_OPT_FLOWIDSHIFT 0x02 /* set flowid shift */ 17135961dceSAndrew Gallatin #define LAGG_OPT_USE_NUMA 0x04 /* enable use of numa */ 1729732189cSHiroki Sato #define LAGG_OPT_FLOWIDSHIFT_MASK 0x1f /* flowid is uint32_t */ 1739732189cSHiroki Sato #define LAGG_OPT_LACP_STRICT 0x10 /* LACP strict mode */ 1749732189cSHiroki Sato #define LAGG_OPT_LACP_TXTEST 0x20 /* LACP debug: txtest */ 1759732189cSHiroki Sato #define LAGG_OPT_LACP_RXTEST 0x40 /* LACP debug: rxtest */ 1762a73c8f5SRavi Pokala #define LAGG_OPT_LACP_FAST_TIMO 0x80 /* LACP fast timeout */ 177c23df8eaSMark Johnston #define LAGG_OPT_RR_LIMIT 0x100 /* RR stride */ 1789732189cSHiroki Sato u_int ro_count; /* number of ports */ 1799732189cSHiroki Sato u_int ro_active; /* active port count */ 1809732189cSHiroki Sato u_int ro_flapping; /* number of flapping */ 1819732189cSHiroki Sato int ro_flowid_shift; /* shift the flowid */ 182c104c299SMark Johnston uint32_t ro_bkt; /* stride for RR */ 1839732189cSHiroki Sato }; 1849732189cSHiroki Sato 1859732189cSHiroki Sato #define SIOCGLAGGOPTS _IOWR('i', 152, struct lagg_reqopts) 1869732189cSHiroki Sato #define SIOCSLAGGOPTS _IOW('i', 153, struct lagg_reqopts) 1879732189cSHiroki Sato 18835961dceSAndrew Gallatin #define LAGG_OPT_BITS "\020\001USE_FLOWID\003USE_NUMA" \ 18935961dceSAndrew Gallatin "\005LACP_STRICT\006LACP_TXTEST" \ 1902a73c8f5SRavi Pokala "\007LACP_RXTEST\010LACP_FAST_TIMO" 1916d478167SHiroki Sato 19218242d3bSAndrew Thompson #ifdef _KERNEL 193b64478a1SGleb Smirnoff 19418242d3bSAndrew Thompson /* 19518242d3bSAndrew Thompson * Internal kernel part 19618242d3bSAndrew Thompson */ 19718242d3bSAndrew Thompson 19818242d3bSAndrew Thompson #define LAGG_PORTACTIVE(_tp) ( \ 199eade13f9SGleb Smirnoff ((_tp)->lp_ifp->if_link_state == LINK_STATE_UP) && \ 20018242d3bSAndrew Thompson ((_tp)->lp_ifp->if_flags & IFF_UP) \ 20118242d3bSAndrew Thompson ) 20218242d3bSAndrew Thompson 20318242d3bSAndrew Thompson struct lagg_ifreq { 20418242d3bSAndrew Thompson union { 20518242d3bSAndrew Thompson struct ifreq ifreq; 20618242d3bSAndrew Thompson struct { 20718242d3bSAndrew Thompson char ifr_name[IFNAMSIZ]; 20818242d3bSAndrew Thompson struct sockaddr_storage ifr_ss; 20918242d3bSAndrew Thompson } ifreq_storage; 21018242d3bSAndrew Thompson } ifreq; 21118242d3bSAndrew Thompson }; 21218242d3bSAndrew Thompson 21318242d3bSAndrew Thompson #define sc_ifflags sc_ifp->if_flags /* flags */ 21418242d3bSAndrew Thompson #define sc_ifname sc_ifp->if_xname /* name */ 21518242d3bSAndrew Thompson 21618242d3bSAndrew Thompson /* Private data used by the loadbalancing protocol */ 21718242d3bSAndrew Thompson struct lagg_lb { 21818242d3bSAndrew Thompson u_int32_t lb_key; 21918242d3bSAndrew Thompson struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 22018242d3bSAndrew Thompson }; 22118242d3bSAndrew Thompson 22218242d3bSAndrew Thompson struct lagg_mc { 2232d222cb7SAlexander Motin struct sockaddr_dl mc_addr; 224d74fd345SAndrew Thompson struct ifmultiaddr *mc_ifma; 22518242d3bSAndrew Thompson SLIST_ENTRY(lagg_mc) mc_entries; 22618242d3bSAndrew Thompson }; 22718242d3bSAndrew Thompson 2287d6cc45cSAlexander V. Chernikov struct lagg_counters { 229112f50ffSGleb Smirnoff uint64_t val[IFCOUNTERS]; 2307d6cc45cSAlexander V. Chernikov }; 2317d6cc45cSAlexander V. Chernikov 23218242d3bSAndrew Thompson struct lagg_softc { 23318242d3bSAndrew Thompson struct ifnet *sc_ifp; /* virtual interface */ 234a92c4bb6SHans Petter Selasky struct mtx sc_mtx; /* watchdog mutex */ 2352f86d4b0SAlexander Motin struct sx sc_sx; 23618242d3bSAndrew Thompson int sc_proto; /* lagg protocol */ 23718242d3bSAndrew Thompson u_int sc_count; /* number of ports */ 23831402c27SAdrian Chadd u_int sc_active; /* active port count */ 23931402c27SAdrian Chadd u_int sc_flapping; /* number of flapping 24031402c27SAdrian Chadd * events */ 24118242d3bSAndrew Thompson struct lagg_port *sc_primary; /* primary port */ 24218242d3bSAndrew Thompson struct ifmedia sc_media; /* media config */ 2436900d0d3SGleb Smirnoff void *sc_psc; /* protocol data */ 244960dab09SAndrew Thompson uint32_t sc_seq; /* sequence counter */ 245c104c299SMark Johnston uint32_t sc_stride; /* stride for RR */ 24686f67641SAndrew Thompson uint32_t sc_flags; 2472f86d4b0SAlexander Motin int sc_destroying; /* destroying lagg */ 24818242d3bSAndrew Thompson 2490f8d79d9SMatt Macy CK_SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 25018242d3bSAndrew Thompson SLIST_ENTRY(lagg_softc) sc_entries; 25118242d3bSAndrew Thompson 252644da90dSErmal Luçi eventhandler_tag vlan_attach; 253644da90dSErmal Luçi eventhandler_tag vlan_detach; 254b64478a1SGleb Smirnoff struct callout sc_callout; 255939a050aSHiroki Sato u_int sc_opts; 2561a8959daSScott Long int flowid_shift; /* shift the flowid */ 2577d6cc45cSAlexander V. Chernikov struct lagg_counters detached_counters; /* detached ports sum */ 258a92c4bb6SHans Petter Selasky struct callout sc_watchdog; /* watchdog timer */ 25919ecb5e8SHans Petter Selasky #define LAGG_ADDR_LEN \ 26019ecb5e8SHans Petter Selasky MAX(INFINIBAND_ADDR_LEN, ETHER_ADDR_LEN) 26119ecb5e8SHans Petter Selasky uint8_t sc_bcast_addr[LAGG_ADDR_LEN]; 26218242d3bSAndrew Thompson }; 26318242d3bSAndrew Thompson 26418242d3bSAndrew Thompson struct lagg_port { 26518242d3bSAndrew Thompson struct ifnet *lp_ifp; /* physical interface */ 266ec32b37eSAndrew Thompson struct lagg_softc *lp_softc; /* parent lagg */ 267a92c4bb6SHans Petter Selasky uint8_t lp_lladdr[LAGG_ADDR_LEN]; 26818242d3bSAndrew Thompson 26918242d3bSAndrew Thompson u_char lp_iftype; /* interface type */ 27018242d3bSAndrew Thompson uint32_t lp_prio; /* port priority */ 27118242d3bSAndrew Thompson uint32_t lp_flags; /* port flags */ 27218242d3bSAndrew Thompson int lp_ifflags; /* saved ifp flags */ 2732f86d4b0SAlexander Motin int lp_ifcapenable; /* saved ifp capenable */ 274*713ceb99SAndrew Gallatin int lp_ifcapenable2;/* saved ifp capenable2 */ 27518242d3bSAndrew Thompson void *lh_cookie; /* if state hook */ 2766900d0d3SGleb Smirnoff void *lp_psc; /* protocol data */ 277108fe96aSAndrew Thompson int lp_detaching; /* ifnet is detaching */ 278d74fd345SAndrew Thompson SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 279d74fd345SAndrew Thompson 28018242d3bSAndrew Thompson /* Redirected callbacks */ 28118242d3bSAndrew Thompson int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 28247e8d432SGleb Smirnoff int (*lp_output)(struct ifnet *, struct mbuf *, 28347e8d432SGleb Smirnoff const struct sockaddr *, struct route *); 2847d6cc45cSAlexander V. Chernikov struct lagg_counters port_counters; /* ifp counters copy */ 28518242d3bSAndrew Thompson 2860f8d79d9SMatt Macy CK_SLIST_ENTRY(lagg_port) lp_entries; 28799031b8fSStephen Hurd struct epoch_context lp_epoch_ctx; 28818242d3bSAndrew Thompson }; 28918242d3bSAndrew Thompson 290a92c4bb6SHans Petter Selasky extern struct mbuf *(*lagg_input_ethernet_p)(struct ifnet *, struct mbuf *); 291a92c4bb6SHans Petter Selasky extern struct mbuf *(*lagg_input_infiniband_p)(struct ifnet *, struct mbuf *); 292d6e82913SSteven Hartland extern void (*lagg_linkstate_p)(struct ifnet *, int ); 29318242d3bSAndrew Thompson 29418242d3bSAndrew Thompson int lagg_enqueue(struct ifnet *, struct mbuf *); 29518242d3bSAndrew Thompson 29631402c27SAdrian Chadd SYSCTL_DECL(_net_link_lagg); 29731402c27SAdrian Chadd 29818242d3bSAndrew Thompson #endif /* _KERNEL */ 29918242d3bSAndrew Thompson 30018242d3bSAndrew Thompson #endif /* _NET_LAGG_H */ 301