if_trunk.h revision 1.17
1/* $OpenBSD: if_trunk.h,v 1.17 2011/07/04 04:29:17 claudio Exp $ */ 2 3/* 4 * Copyright (c) 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19#ifndef _NET_TRUNK_H 20#define _NET_TRUNK_H 21 22/* 23 * Global definitions 24 */ 25 26#define TRUNK_MAX_PORTS 32 /* logically */ 27#define TRUNK_MAX_NAMESIZE 32 /* name of a protocol */ 28#define TRUNK_MAX_STACKING 4 /* maximum number of stacked trunks */ 29 30/* Port flags */ 31#define TRUNK_PORT_SLAVE 0x00000000 /* normal enslaved port */ 32#define TRUNK_PORT_MASTER 0x00000001 /* primary port */ 33#define TRUNK_PORT_STACK 0x00000002 /* stacked trunk port */ 34#define TRUNK_PORT_ACTIVE 0x00000004 /* port is active */ 35#define TRUNK_PORT_COLLECTING 0x00000008 /* port is receiving frames */ 36#define TRUNK_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */ 37#define TRUNK_PORT_DISABLED 0x00000020 /* port is disabled */ 38#define TRUNK_PORT_GLOBAL 0x80000000 /* IOCTL: global flag */ 39#define TRUNK_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE" \ 40 "\04COLLECTING\05DISTRIBUTING\06DISABLED" 41 42/* Supported trunk PROTOs */ 43enum trunk_proto { 44 TRUNK_PROTO_NONE = 0, /* no trunk protocol defined */ 45 TRUNK_PROTO_ROUNDROBIN = 1, /* simple round robin */ 46 TRUNK_PROTO_FAILOVER = 2, /* active failover */ 47 TRUNK_PROTO_LOADBALANCE = 3, /* loadbalance */ 48 TRUNK_PROTO_BROADCAST = 4, /* broadcast */ 49 TRUNK_PROTO_LACP = 5, /* 802.3ad LACP */ 50 TRUNK_PROTO_MAX = 6 51}; 52 53struct trunk_protos { 54 const char *tpr_name; 55 enum trunk_proto tpr_proto; 56}; 57 58#define TRUNK_PROTO_DEFAULT TRUNK_PROTO_ROUNDROBIN 59#define TRUNK_PROTOS { \ 60 { "roundrobin", TRUNK_PROTO_ROUNDROBIN }, \ 61 { "failover", TRUNK_PROTO_FAILOVER }, \ 62 { "lacp", TRUNK_PROTO_LACP }, \ 63 { "loadbalance", TRUNK_PROTO_LOADBALANCE }, \ 64 { "broadcast", TRUNK_PROTO_BROADCAST }, \ 65 { "none", TRUNK_PROTO_NONE }, \ 66 { "default", TRUNK_PROTO_DEFAULT } \ 67} 68 69/* 70 * Trunk ioctls. 71 */ 72 73/* 74 * LACP current operational parameters structure. 75 */ 76struct lacp_opreq { 77 u_int16_t actor_prio; 78 u_int8_t actor_mac[ETHER_ADDR_LEN]; 79 u_int16_t actor_key; 80 u_int16_t actor_portprio; 81 u_int16_t actor_portno; 82 u_int8_t actor_state; 83 u_int16_t partner_prio; 84 u_int8_t partner_mac[ETHER_ADDR_LEN]; 85 u_int16_t partner_key; 86 u_int16_t partner_portprio; 87 u_int16_t partner_portno; 88 u_int8_t partner_state; 89}; 90 91/* Trunk port settings */ 92struct trunk_reqport { 93 char rp_ifname[IFNAMSIZ]; /* name of the trunk */ 94 char rp_portname[IFNAMSIZ]; /* name of the port */ 95 u_int32_t rp_prio; /* port priority */ 96 u_int32_t rp_flags; /* port flags */ 97 union { 98 struct lacp_opreq rpsc_lacp; 99 } rp_psc; 100#define rp_lacpreq rp_psc.rpsc_lacp 101}; 102 103#define SIOCGTRUNKPORT _IOWR('i', 140, struct trunk_reqport) 104#define SIOCSTRUNKPORT _IOW('i', 141, struct trunk_reqport) 105#define SIOCSTRUNKDELPORT _IOW('i', 142, struct trunk_reqport) 106 107/* Trunk, ports and options */ 108struct trunk_reqall { 109 char ra_ifname[IFNAMSIZ]; /* name of the trunk */ 110 u_int ra_proto; /* trunk protocol */ 111 112 size_t ra_size; /* size of buffer */ 113 struct trunk_reqport *ra_port; /* allocated buffer */ 114 int ra_ports; /* total port count */ 115 union { 116 struct lacp_opreq rpsc_lacp; 117 } ra_psc; 118#define ra_lacpreq ra_psc.rpsc_lacp 119}; 120 121#define SIOCGTRUNK _IOWR('i', 143, struct trunk_reqall) 122#define SIOCSTRUNK _IOW('i', 144, struct trunk_reqall) 123 124#ifdef _KERNEL 125/* 126 * Internal kernel part 127 */ 128struct trunk_softc; 129struct trunk_port { 130 struct ifnet *tp_if; /* physical interface */ 131 struct trunk_softc *tp_trunk; /* parent trunk */ 132 u_int8_t tp_lladdr[ETHER_ADDR_LEN]; 133 caddr_t tp_psc; /* protocol data */ 134 135 u_char tp_iftype; /* interface type */ 136 u_int32_t tp_prio; /* port priority */ 137 u_int32_t tp_flags; /* port flags */ 138 void *lh_cookie; /* if state hook */ 139 140 /* Redirected callbacks */ 141 void (*tp_watchdog)(struct ifnet *); 142 int (*tp_ioctl)(struct ifnet *, u_long, caddr_t); 143 144 SLIST_ENTRY(trunk_port) tp_entries; 145}; 146 147#define tp_ifname tp_if->if_xname /* interface name */ 148#define tp_ifflags tp_if->if_flags /* interface flags */ 149#define tp_link_state tp_if->if_link_state /* link state */ 150#define tp_capabilities tp_if->if_capabilities /* capabilities */ 151 152#define TRUNK_PORTACTIVE(_tp) ( \ 153 LINK_STATE_IS_UP((_tp)->tp_link_state) && \ 154 (_tp)->tp_ifflags & IFF_UP) 155 156struct trunk_mc { 157 union { 158 struct ether_multi *mcu_enm; 159 } mc_u; 160 struct sockaddr_storage mc_addr; 161 162 SLIST_ENTRY(trunk_mc) mc_entries; 163}; 164 165#define mc_enm mc_u.mcu_enm 166 167struct trunk_ifreq { 168 union { 169 struct ifreq ifreq; 170 struct { 171 char ifr_name[IFNAMSIZ]; 172 struct sockaddr_storage ifr_ss; 173 } ifreq_storage; 174 } ifreq; 175}; 176 177struct trunk_softc { 178 struct arpcom tr_ac; /* virtual interface */ 179 int tr_unit; /* trunk unit */ 180 enum trunk_proto tr_proto; /* trunk protocol */ 181 u_int tr_count; /* number of ports */ 182 struct trunk_port *tr_primary; /* primary port */ 183 struct ifmedia tr_media; /* media config */ 184 caddr_t tr_psc; /* protocol data */ 185 186 SLIST_HEAD(__tplhd, trunk_port) tr_ports; /* list of interfaces */ 187 SLIST_ENTRY(trunk_softc) tr_entries; 188 189 SLIST_HEAD(__mclhd, trunk_mc) tr_mc_head; /* multicast addresses */ 190 191 /* Trunk protocol callbacks */ 192 int (*tr_detach)(struct trunk_softc *); 193 int (*tr_start)(struct trunk_softc *, struct mbuf *); 194 int (*tr_watchdog)(struct trunk_softc *); 195 int (*tr_input)(struct trunk_softc *, struct trunk_port *, 196 struct ether_header *, struct mbuf *); 197 int (*tr_port_create)(struct trunk_port *); 198 void (*tr_port_destroy)(struct trunk_port *); 199 void (*tr_linkstate)(struct trunk_port *); 200 void (*tr_init)(struct trunk_softc *); 201 void (*tr_stop)(struct trunk_softc *); 202 void (*tr_req)(struct trunk_softc *, caddr_t); 203 void (*tr_portreq)(struct trunk_port *, caddr_t); 204}; 205 206#define tr_ifflags tr_ac.ac_if.if_flags /* flags */ 207#define tr_ifname tr_ac.ac_if.if_xname /* name */ 208#define tr_capabilities tr_ac.ac_if.if_capabilities /* capabilities */ 209#define tr_ifindex tr_ac.ac_if.if_index /* int index */ 210#define tr_lladdr tr_ac.ac_enaddr /* lladdr */ 211 212#define IFCAP_TRUNK_MASK 0xffff0000 /* private capabilities */ 213#define IFCAP_TRUNK_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 214 215/* Private data used by the loadbalancing protocol */ 216#define TRUNK_LB_MAXKEYS 8 217struct trunk_lb { 218 u_int32_t lb_key; 219 struct trunk_port *lb_ports[TRUNK_MAX_PORTS]; 220}; 221 222void trunk_port_ifdetach(struct ifnet *); 223int trunk_input(struct ifnet *, struct ether_header *, 224 struct mbuf *); 225int trunk_enqueue(struct ifnet *, struct mbuf *); 226u_int32_t trunk_hashmbuf(struct mbuf *, u_int32_t); 227#endif /* _KERNEL */ 228 229#endif /* _NET_TRUNK_H */ 230