if_lagg.h revision 168793
1119815Smarcel/* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */ 2158124Smarcel 3119815Smarcel/* 4119815Smarcel * Copyright (c) 2005, 2006 Reyk Floeter <reyk@openbsd.org> 5119815Smarcel * 6119815Smarcel * Permission to use, copy, modify, and distribute this software for any 7119815Smarcel * purpose with or without fee is hereby granted, provided that the above 8119815Smarcel * copyright notice and this permission notice appear in all copies. 9119815Smarcel * 10119815Smarcel * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11119815Smarcel * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12119815Smarcel * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13119815Smarcel * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14119815Smarcel * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15119815Smarcel * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16119815Smarcel * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17119815Smarcel * 18119815Smarcel * $FreeBSD: head/sys/net/if_lagg.h 168793 2007-04-17 00:35:11Z thompsa $ 19119815Smarcel */ 20119815Smarcel 21119815Smarcel#ifndef _NET_LAGG_H 22119815Smarcel#define _NET_LAGG_H 23119815Smarcel 24119815Smarcel/* 25119815Smarcel * Global definitions 26119815Smarcel */ 27119815Smarcel 28119815Smarcel#define LAGG_MAX_PORTS 32 /* logically */ 29119815Smarcel#define LAGG_MAX_NAMESIZE 32 /* name of a protocol */ 30119815Smarcel#define LAGG_MAX_STACKING 4 /* maximum number of stacked laggs */ 31119815Smarcel 32119815Smarcel/* Port flags */ 33119815Smarcel#define LAGG_PORT_SLAVE 0x00000000 /* normal enslaved port */ 34119815Smarcel#define LAGG_PORT_MASTER 0x00000001 /* primary port */ 35119815Smarcel#define LAGG_PORT_STACK 0x00000002 /* stacked lagg port */ 36158124Smarcel#define LAGG_PORT_ACTIVE 0x00000004 /* port is active */ 37119815Smarcel#define LAGG_PORT_COLLECTING 0x00000008 /* port is active */ 38119815Smarcel#define LAGG_PORT_DISTRIBUTING 0x00000010 /* port is active */ 39119815Smarcel#define LAGG_PORT_GLOBAL 0x80000000 /* IOCTL: global flag */ 40119815Smarcel#define LAGG_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE\04COLLECTING" \ 41158124Smarcel "\05DISTRIBUTING" 42119815Smarcel 43119815Smarcel/* Supported lagg PROTOs */ 44119815Smarcel#define LAGG_PROTO_NONE 0 /* no lagg protocol defined */ 45119815Smarcel#define LAGG_PROTO_ROUNDROBIN 1 /* simple round robin */ 46119815Smarcel#define LAGG_PROTO_FAILOVER 2 /* active failover */ 47119815Smarcel#define LAGG_PROTO_LOADBALANCE 3 /* loadbalance */ 48119815Smarcel#define LAGG_PROTO_LACP 4 /* 802.3ad lacp */ 49119815Smarcel#define LAGG_PROTO_ETHERCHANNEL 5 /* Cisco FEC */ 50119815Smarcel#define LAGG_PROTO_MAX 6 51119815Smarcel 52119815Smarcelstruct lagg_protos { 53158124Smarcel const char *tpr_name; 54158124Smarcel int tpr_proto; 55158124Smarcel}; 56119815Smarcel 57119815Smarcel#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 58119815Smarcel#define LAGG_PROTOS { \ 59119815Smarcel { "failover", LAGG_PROTO_FAILOVER }, \ 60119815Smarcel { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 61119815Smarcel { "lacp", LAGG_PROTO_LACP }, \ 62119815Smarcel { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 63119815Smarcel { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 64119815Smarcel { "none", LAGG_PROTO_NONE }, \ 65119815Smarcel { "default", LAGG_PROTO_DEFAULT } \ 66119815Smarcel} 67119815Smarcel 68119815Smarcel/* 69119815Smarcel * lagg ioctls. 70158124Smarcel */ 71119815Smarcel 72119815Smarcel/* lagg port settings */ 73119815Smarcelstruct lagg_reqport { 74119815Smarcel char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 75158124Smarcel char rp_portname[IFNAMSIZ]; /* name of the port */ 76119815Smarcel u_int32_t rp_prio; /* port priority */ 77158124Smarcel u_int32_t rp_flags; /* port flags */ 78119815Smarcel}; 79119815Smarcel 80158124Smarcel#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 81158124Smarcel#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 82158124Smarcel#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 83119815Smarcel 84158124Smarcel/* lagg, ports and options */ 85119815Smarcelstruct lagg_reqall { 86119815Smarcel char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 87119815Smarcel u_int ra_proto; /* lagg protocol */ 88 89 size_t ra_size; /* size of buffer */ 90 struct lagg_reqport *ra_port; /* allocated buffer */ 91 int ra_ports; /* total port count */ 92}; 93 94#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 95#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 96 97#ifdef _KERNEL 98/* 99 * Internal kernel part 100 */ 101 102#define lp_ifname lp_ifp->if_xname /* interface name */ 103#define lp_link_state lp_ifp->if_link_state /* link state */ 104#define lp_capabilities lp_ifp->if_capabilities /* capabilities */ 105 106#define LAGG_PORTACTIVE(_tp) ( \ 107 ((_tp)->lp_link_state == LINK_STATE_UP) && \ 108 ((_tp)->lp_ifp->if_flags & IFF_UP) \ 109) 110 111#define mc_enm mc_u.mcu_enm 112 113struct lagg_ifreq { 114 union { 115 struct ifreq ifreq; 116 struct { 117 char ifr_name[IFNAMSIZ]; 118 struct sockaddr_storage ifr_ss; 119 } ifreq_storage; 120 } ifreq; 121}; 122 123#define sc_ifflags sc_ifp->if_flags /* flags */ 124#define sc_ifname sc_ifp->if_xname /* name */ 125#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 126 127#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 128#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 129 130/* Private data used by the loadbalancing protocol */ 131#define LAGG_LB_MAXKEYS 8 132struct lagg_lb { 133 u_int32_t lb_key; 134 struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 135}; 136 137struct lagg_mc { 138 union { 139 struct ether_multi *mcu_enm; 140 } mc_u; 141 struct sockaddr_storage mc_addr; 142 143 SLIST_ENTRY(lagg_mc) mc_entries; 144}; 145 146struct lagg_softc { 147 struct ifnet *sc_ifp; /* virtual interface */ 148 struct mtx sc_mtx; 149 int sc_proto; /* lagg protocol */ 150 u_int sc_count; /* number of ports */ 151 struct lagg_port *sc_primary; /* primary port */ 152 struct ifmedia sc_media; /* media config */ 153 caddr_t sc_psc; /* protocol data */ 154 155 SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 156 SLIST_ENTRY(lagg_softc) sc_entries; 157 158 SLIST_HEAD(__mclhd, lagg_mc) sc_mc_head; /* multicast addresses */ 159 160 /* lagg protocol callbacks */ 161 int (*sc_detach)(struct lagg_softc *); 162 int (*sc_start)(struct lagg_softc *, struct mbuf *); 163 struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *, 164 struct mbuf *); 165 int (*sc_port_create)(struct lagg_port *); 166 void (*sc_port_destroy)(struct lagg_port *); 167 void (*sc_linkstate)(struct lagg_port *); 168 void (*sc_init)(struct lagg_softc *); 169 void (*sc_stop)(struct lagg_softc *); 170 void (*sc_lladdr)(struct lagg_softc *); 171}; 172 173struct lagg_port { 174 struct ifnet *lp_ifp; /* physical interface */ 175 struct lagg_softc *lp_lagg; /* parent lagg */ 176 uint8_t lp_lladdr[ETHER_ADDR_LEN]; 177 178 u_char lp_iftype; /* interface type */ 179 uint32_t lp_prio; /* port priority */ 180 uint32_t lp_flags; /* port flags */ 181 int lp_ifflags; /* saved ifp flags */ 182 void *lh_cookie; /* if state hook */ 183 caddr_t lp_psc; /* protocol data */ 184 185 /* Redirected callbacks */ 186 int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 187 int (*lp_output)(struct ifnet *, struct mbuf *, struct sockaddr *, 188 struct rtentry *); 189 190 SLIST_ENTRY(lagg_port) lp_entries; 191}; 192 193#define LAGG_LOCK_INIT(_tr) mtx_init(&(_tr)->sc_mtx, "if_lagg", NULL, \ 194 MTX_DEF) 195#define LAGG_LOCK_DESTROY(_tr) mtx_destroy(&(_tr)->sc_mtx) 196#define LAGG_LOCK(_tr) mtx_lock(&(_tr)->sc_mtx) 197#define LAGG_UNLOCK(_tr) mtx_unlock(&(_tr)->sc_mtx) 198#define LAGG_LOCKED(_tr) mtx_owned(&(_tr)->sc_mtx) 199#define LAGG_LOCK_ASSERT(_tr) mtx_assert(&(_tr)->sc_mtx, MA_OWNED) 200 201extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 202extern void (*lagg_linkstate_p)(struct ifnet *, int ); 203 204int lagg_enqueue(struct ifnet *, struct mbuf *); 205uint32_t lagg_hashmbuf(struct mbuf *, uint32_t); 206 207#endif /* _KERNEL */ 208 209#endif /* _NET_LAGG_H */ 210