1/* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */ 2 3/* 4 * Copyright (c) 2005, 2006 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 *
| 1/* $OpenBSD: if_trunk.h,v 1.11 2007/01/31 06:20:19 reyk Exp $ */ 2 3/* 4 * Copyright (c) 2005, 2006 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 *
|
62}; 63 64#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 65#define LAGG_PROTOS { \ 66 { "failover", LAGG_PROTO_FAILOVER }, \ 67 { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 68 { "lacp", LAGG_PROTO_LACP }, \ 69 { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 70 { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 71 { "broadcast", LAGG_PROTO_BROADCAST }, \ 72 { "none", LAGG_PROTO_NONE }, \ 73 { "default", LAGG_PROTO_DEFAULT } \ 74} 75 76/* 77 * lagg ioctls. 78 */ 79 80/* 81 * LACP current operational parameters structure. 82 */ 83struct lacp_opreq { 84 uint16_t actor_prio; 85 uint8_t actor_mac[ETHER_ADDR_LEN]; 86 uint16_t actor_key; 87 uint16_t actor_portprio; 88 uint16_t actor_portno; 89 uint8_t actor_state; 90 uint16_t partner_prio; 91 uint8_t partner_mac[ETHER_ADDR_LEN]; 92 uint16_t partner_key; 93 uint16_t partner_portprio; 94 uint16_t partner_portno; 95 uint8_t partner_state; 96}; 97 98/* lagg port settings */ 99struct lagg_reqport { 100 char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 101 char rp_portname[IFNAMSIZ]; /* name of the port */ 102 u_int32_t rp_prio; /* port priority */ 103 u_int32_t rp_flags; /* port flags */ 104 union { 105 struct lacp_opreq rpsc_lacp; 106 } rp_psc; 107#define rp_lacpreq rp_psc.rpsc_lacp 108}; 109 110#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 111#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 112#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 113 114/* lagg, ports and options */ 115struct lagg_reqall { 116 char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 117 u_int ra_proto; /* lagg protocol */ 118 119 size_t ra_size; /* size of buffer */ 120 struct lagg_reqport *ra_port; /* allocated buffer */ 121 int ra_ports; /* total port count */ 122 union { 123 struct lacp_opreq rpsc_lacp; 124 } ra_psc; 125#define ra_lacpreq ra_psc.rpsc_lacp 126}; 127 128#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 129#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 130 131struct lagg_reqflags { 132 char rf_ifname[IFNAMSIZ]; /* name of the lagg */ 133 uint32_t rf_flags; /* lagg protocol */ 134}; 135 136#define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags) 137#define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags) 138 139#ifdef _KERNEL 140 141#include <sys/counter.h> 142 143/* 144 * Internal kernel part 145 */ 146 147#define lp_ifname lp_ifp->if_xname /* interface name */ 148#define lp_link_state lp_ifp->if_link_state /* link state */ 149 150#define LAGG_PORTACTIVE(_tp) ( \ 151 ((_tp)->lp_link_state == LINK_STATE_UP) && \ 152 ((_tp)->lp_ifp->if_flags & IFF_UP) \ 153) 154 155struct lagg_ifreq { 156 union { 157 struct ifreq ifreq; 158 struct { 159 char ifr_name[IFNAMSIZ]; 160 struct sockaddr_storage ifr_ss; 161 } ifreq_storage; 162 } ifreq; 163}; 164 165#define sc_ifflags sc_ifp->if_flags /* flags */ 166#define sc_ifname sc_ifp->if_xname /* name */ 167#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 168 169#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 170#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 171 172/* Private data used by the loadbalancing protocol */ 173struct lagg_lb { 174 u_int32_t lb_key; 175 struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 176}; 177 178struct lagg_mc { 179 struct sockaddr_dl mc_addr; 180 struct ifmultiaddr *mc_ifma; 181 SLIST_ENTRY(lagg_mc) mc_entries; 182}; 183 184/* List of interfaces to have the MAC address modified */ 185struct lagg_llq { 186 struct ifnet *llq_ifp; 187 uint8_t llq_lladdr[ETHER_ADDR_LEN]; 188 SLIST_ENTRY(lagg_llq) llq_entries; 189}; 190 191struct lagg_softc { 192 struct ifnet *sc_ifp; /* virtual interface */ 193 struct rmlock sc_mtx; 194 struct mtx sc_call_mtx; 195 int sc_proto; /* lagg protocol */ 196 u_int sc_count; /* number of ports */ 197 u_int sc_active; /* active port count */ 198 u_int sc_flapping; /* number of flapping 199 * events */ 200 struct lagg_port *sc_primary; /* primary port */ 201 struct ifmedia sc_media; /* media config */ 202 caddr_t sc_psc; /* protocol data */ 203 uint32_t sc_seq; /* sequence counter */ 204 uint32_t sc_flags; 205 206 counter_u64_t sc_ipackets; 207 counter_u64_t sc_opackets; 208 counter_u64_t sc_ibytes; 209 counter_u64_t sc_obytes; 210 211 SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 212 SLIST_ENTRY(lagg_softc) sc_entries; 213 214 struct task sc_lladdr_task; 215 SLIST_HEAD(__llqhd, lagg_llq) sc_llq_head; /* interfaces to program 216 the lladdr on */ 217 218 /* lagg protocol callbacks */ 219 void (*sc_detach)(struct lagg_softc *); 220 int (*sc_start)(struct lagg_softc *, struct mbuf *); 221 struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *, 222 struct mbuf *); 223 int (*sc_port_create)(struct lagg_port *); 224 void (*sc_port_destroy)(struct lagg_port *); 225 void (*sc_linkstate)(struct lagg_port *); 226 void (*sc_init)(struct lagg_softc *); 227 void (*sc_stop)(struct lagg_softc *); 228 void (*sc_lladdr)(struct lagg_softc *); 229 void (*sc_req)(struct lagg_softc *, caddr_t); 230 void (*sc_portreq)(struct lagg_port *, caddr_t); 231 eventhandler_tag vlan_attach; 232 eventhandler_tag vlan_detach; 233 struct callout sc_callout; 234 struct sysctl_ctx_list ctx; /* sysctl variables */ 235 struct sysctl_oid *sc_oid; /* sysctl tree oid */ 236 int use_flowid; /* use M_FLOWID */ 237 int flowid_shift; /* shift the flowid */ 238}; 239 240struct lagg_port { 241 struct ifnet *lp_ifp; /* physical interface */ 242 struct lagg_softc *lp_softc; /* parent lagg */ 243 uint8_t lp_lladdr[ETHER_ADDR_LEN]; 244 245 u_char lp_iftype; /* interface type */ 246 uint32_t lp_prio; /* port priority */ 247 uint32_t lp_flags; /* port flags */ 248 int lp_ifflags; /* saved ifp flags */ 249 void *lh_cookie; /* if state hook */ 250 caddr_t lp_psc; /* protocol data */ 251 int lp_detaching; /* ifnet is detaching */ 252 253 SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 254 255 /* Redirected callbacks */ 256 int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 257 int (*lp_output)(struct ifnet *, struct mbuf *, 258 const struct sockaddr *, struct route *); 259 260 SLIST_ENTRY(lagg_port) lp_entries; 261}; 262 263#define LAGG_LOCK_INIT(_sc) rm_init(&(_sc)->sc_mtx, "if_lagg rmlock") 264#define LAGG_LOCK_DESTROY(_sc) rm_destroy(&(_sc)->sc_mtx) 265#define LAGG_RLOCK(_sc, _p) rm_rlock(&(_sc)->sc_mtx, (_p)) 266#define LAGG_WLOCK(_sc) rm_wlock(&(_sc)->sc_mtx) 267#define LAGG_RUNLOCK(_sc, _p) rm_runlock(&(_sc)->sc_mtx, (_p)) 268#define LAGG_WUNLOCK(_sc) rm_wunlock(&(_sc)->sc_mtx) 269#define LAGG_RLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_RLOCKED) 270#define LAGG_WLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_WLOCKED) 271 272#define LAGG_CALLOUT_LOCK_INIT(_sc) \ 273 mtx_init(&(_sc)->sc_call_mtx, "if_lagg callout mutex", NULL,\ 274 MTX_DEF) 275#define LAGG_CALLOUT_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_call_mtx) 276 277extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 278extern void (*lagg_linkstate_p)(struct ifnet *, int ); 279 280int lagg_enqueue(struct ifnet *, struct mbuf *); 281uint32_t lagg_hashmbuf(struct lagg_softc *, struct mbuf *, uint32_t); 282 283SYSCTL_DECL(_net_link_lagg); 284 285#endif /* _KERNEL */ 286 287#endif /* _NET_LAGG_H */
| 64}; 65 66#define LAGG_PROTO_DEFAULT LAGG_PROTO_FAILOVER 67#define LAGG_PROTOS { \ 68 { "failover", LAGG_PROTO_FAILOVER }, \ 69 { "fec", LAGG_PROTO_ETHERCHANNEL }, \ 70 { "lacp", LAGG_PROTO_LACP }, \ 71 { "loadbalance", LAGG_PROTO_LOADBALANCE }, \ 72 { "roundrobin", LAGG_PROTO_ROUNDROBIN }, \ 73 { "broadcast", LAGG_PROTO_BROADCAST }, \ 74 { "none", LAGG_PROTO_NONE }, \ 75 { "default", LAGG_PROTO_DEFAULT } \ 76} 77 78/* 79 * lagg ioctls. 80 */ 81 82/* 83 * LACP current operational parameters structure. 84 */ 85struct lacp_opreq { 86 uint16_t actor_prio; 87 uint8_t actor_mac[ETHER_ADDR_LEN]; 88 uint16_t actor_key; 89 uint16_t actor_portprio; 90 uint16_t actor_portno; 91 uint8_t actor_state; 92 uint16_t partner_prio; 93 uint8_t partner_mac[ETHER_ADDR_LEN]; 94 uint16_t partner_key; 95 uint16_t partner_portprio; 96 uint16_t partner_portno; 97 uint8_t partner_state; 98}; 99 100/* lagg port settings */ 101struct lagg_reqport { 102 char rp_ifname[IFNAMSIZ]; /* name of the lagg */ 103 char rp_portname[IFNAMSIZ]; /* name of the port */ 104 u_int32_t rp_prio; /* port priority */ 105 u_int32_t rp_flags; /* port flags */ 106 union { 107 struct lacp_opreq rpsc_lacp; 108 } rp_psc; 109#define rp_lacpreq rp_psc.rpsc_lacp 110}; 111 112#define SIOCGLAGGPORT _IOWR('i', 140, struct lagg_reqport) 113#define SIOCSLAGGPORT _IOW('i', 141, struct lagg_reqport) 114#define SIOCSLAGGDELPORT _IOW('i', 142, struct lagg_reqport) 115 116/* lagg, ports and options */ 117struct lagg_reqall { 118 char ra_ifname[IFNAMSIZ]; /* name of the lagg */ 119 u_int ra_proto; /* lagg protocol */ 120 121 size_t ra_size; /* size of buffer */ 122 struct lagg_reqport *ra_port; /* allocated buffer */ 123 int ra_ports; /* total port count */ 124 union { 125 struct lacp_opreq rpsc_lacp; 126 } ra_psc; 127#define ra_lacpreq ra_psc.rpsc_lacp 128}; 129 130#define SIOCGLAGG _IOWR('i', 143, struct lagg_reqall) 131#define SIOCSLAGG _IOW('i', 144, struct lagg_reqall) 132 133struct lagg_reqflags { 134 char rf_ifname[IFNAMSIZ]; /* name of the lagg */ 135 uint32_t rf_flags; /* lagg protocol */ 136}; 137 138#define SIOCGLAGGFLAGS _IOWR('i', 145, struct lagg_reqflags) 139#define SIOCSLAGGHASH _IOW('i', 146, struct lagg_reqflags) 140 141#ifdef _KERNEL 142 143#include <sys/counter.h> 144 145/* 146 * Internal kernel part 147 */ 148 149#define lp_ifname lp_ifp->if_xname /* interface name */ 150#define lp_link_state lp_ifp->if_link_state /* link state */ 151 152#define LAGG_PORTACTIVE(_tp) ( \ 153 ((_tp)->lp_link_state == LINK_STATE_UP) && \ 154 ((_tp)->lp_ifp->if_flags & IFF_UP) \ 155) 156 157struct lagg_ifreq { 158 union { 159 struct ifreq ifreq; 160 struct { 161 char ifr_name[IFNAMSIZ]; 162 struct sockaddr_storage ifr_ss; 163 } ifreq_storage; 164 } ifreq; 165}; 166 167#define sc_ifflags sc_ifp->if_flags /* flags */ 168#define sc_ifname sc_ifp->if_xname /* name */ 169#define sc_capabilities sc_ifp->if_capabilities /* capabilities */ 170 171#define IFCAP_LAGG_MASK 0xffff0000 /* private capabilities */ 172#define IFCAP_LAGG_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ 173 174/* Private data used by the loadbalancing protocol */ 175struct lagg_lb { 176 u_int32_t lb_key; 177 struct lagg_port *lb_ports[LAGG_MAX_PORTS]; 178}; 179 180struct lagg_mc { 181 struct sockaddr_dl mc_addr; 182 struct ifmultiaddr *mc_ifma; 183 SLIST_ENTRY(lagg_mc) mc_entries; 184}; 185 186/* List of interfaces to have the MAC address modified */ 187struct lagg_llq { 188 struct ifnet *llq_ifp; 189 uint8_t llq_lladdr[ETHER_ADDR_LEN]; 190 SLIST_ENTRY(lagg_llq) llq_entries; 191}; 192 193struct lagg_softc { 194 struct ifnet *sc_ifp; /* virtual interface */ 195 struct rmlock sc_mtx; 196 struct mtx sc_call_mtx; 197 int sc_proto; /* lagg protocol */ 198 u_int sc_count; /* number of ports */ 199 u_int sc_active; /* active port count */ 200 u_int sc_flapping; /* number of flapping 201 * events */ 202 struct lagg_port *sc_primary; /* primary port */ 203 struct ifmedia sc_media; /* media config */ 204 caddr_t sc_psc; /* protocol data */ 205 uint32_t sc_seq; /* sequence counter */ 206 uint32_t sc_flags; 207 208 counter_u64_t sc_ipackets; 209 counter_u64_t sc_opackets; 210 counter_u64_t sc_ibytes; 211 counter_u64_t sc_obytes; 212 213 SLIST_HEAD(__tplhd, lagg_port) sc_ports; /* list of interfaces */ 214 SLIST_ENTRY(lagg_softc) sc_entries; 215 216 struct task sc_lladdr_task; 217 SLIST_HEAD(__llqhd, lagg_llq) sc_llq_head; /* interfaces to program 218 the lladdr on */ 219 220 /* lagg protocol callbacks */ 221 void (*sc_detach)(struct lagg_softc *); 222 int (*sc_start)(struct lagg_softc *, struct mbuf *); 223 struct mbuf *(*sc_input)(struct lagg_softc *, struct lagg_port *, 224 struct mbuf *); 225 int (*sc_port_create)(struct lagg_port *); 226 void (*sc_port_destroy)(struct lagg_port *); 227 void (*sc_linkstate)(struct lagg_port *); 228 void (*sc_init)(struct lagg_softc *); 229 void (*sc_stop)(struct lagg_softc *); 230 void (*sc_lladdr)(struct lagg_softc *); 231 void (*sc_req)(struct lagg_softc *, caddr_t); 232 void (*sc_portreq)(struct lagg_port *, caddr_t); 233 eventhandler_tag vlan_attach; 234 eventhandler_tag vlan_detach; 235 struct callout sc_callout; 236 struct sysctl_ctx_list ctx; /* sysctl variables */ 237 struct sysctl_oid *sc_oid; /* sysctl tree oid */ 238 int use_flowid; /* use M_FLOWID */ 239 int flowid_shift; /* shift the flowid */ 240}; 241 242struct lagg_port { 243 struct ifnet *lp_ifp; /* physical interface */ 244 struct lagg_softc *lp_softc; /* parent lagg */ 245 uint8_t lp_lladdr[ETHER_ADDR_LEN]; 246 247 u_char lp_iftype; /* interface type */ 248 uint32_t lp_prio; /* port priority */ 249 uint32_t lp_flags; /* port flags */ 250 int lp_ifflags; /* saved ifp flags */ 251 void *lh_cookie; /* if state hook */ 252 caddr_t lp_psc; /* protocol data */ 253 int lp_detaching; /* ifnet is detaching */ 254 255 SLIST_HEAD(__mclhd, lagg_mc) lp_mc_head; /* multicast addresses */ 256 257 /* Redirected callbacks */ 258 int (*lp_ioctl)(struct ifnet *, u_long, caddr_t); 259 int (*lp_output)(struct ifnet *, struct mbuf *, 260 const struct sockaddr *, struct route *); 261 262 SLIST_ENTRY(lagg_port) lp_entries; 263}; 264 265#define LAGG_LOCK_INIT(_sc) rm_init(&(_sc)->sc_mtx, "if_lagg rmlock") 266#define LAGG_LOCK_DESTROY(_sc) rm_destroy(&(_sc)->sc_mtx) 267#define LAGG_RLOCK(_sc, _p) rm_rlock(&(_sc)->sc_mtx, (_p)) 268#define LAGG_WLOCK(_sc) rm_wlock(&(_sc)->sc_mtx) 269#define LAGG_RUNLOCK(_sc, _p) rm_runlock(&(_sc)->sc_mtx, (_p)) 270#define LAGG_WUNLOCK(_sc) rm_wunlock(&(_sc)->sc_mtx) 271#define LAGG_RLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_RLOCKED) 272#define LAGG_WLOCK_ASSERT(_sc) rm_assert(&(_sc)->sc_mtx, RA_WLOCKED) 273 274#define LAGG_CALLOUT_LOCK_INIT(_sc) \ 275 mtx_init(&(_sc)->sc_call_mtx, "if_lagg callout mutex", NULL,\ 276 MTX_DEF) 277#define LAGG_CALLOUT_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_call_mtx) 278 279extern struct mbuf *(*lagg_input_p)(struct ifnet *, struct mbuf *); 280extern void (*lagg_linkstate_p)(struct ifnet *, int ); 281 282int lagg_enqueue(struct ifnet *, struct mbuf *); 283uint32_t lagg_hashmbuf(struct lagg_softc *, struct mbuf *, uint32_t); 284 285SYSCTL_DECL(_net_link_lagg); 286 287#endif /* _KERNEL */ 288 289#endif /* _NET_LAGG_H */
|