if_trunk.h revision 1.6
1/* $OpenBSD: if_trunk.h,v 1.6 2005/12/18 17:59:59 reyk Exp $ */ 2 3/* 4 * Copyright (c) 2005 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_GLOBAL 0x80000000 /* IOCTL: global flag */ 36#define TRUNK_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE" 37 38/* Supported trunk PROTOs */ 39enum trunk_proto { 40 TRUNK_PROTO_NONE = 0, /* no trunk protocol defined */ 41 TRUNK_PROTO_ROUNDROBIN = 1, /* simple round robin */ 42 TRUNK_PROTO_FAILOVER = 2, /* active failover */ 43 TRUNK_PROTO_MAX = 3, 44}; 45 46struct trunk_protos { 47 const char *tpr_name; 48 enum trunk_proto tpr_proto; 49}; 50 51#define TRUNK_PROTO_DEFAULT TRUNK_PROTO_ROUNDROBIN 52#define TRUNK_PROTOS { \ 53 { "roundrobin", TRUNK_PROTO_ROUNDROBIN }, \ 54 { "failover", TRUNK_PROTO_FAILOVER }, \ 55 { "none", TRUNK_PROTO_NONE }, \ 56 { "default", TRUNK_PROTO_DEFAULT } \ 57} 58 59/* 60 * Trunk ioctls. 61 */ 62 63/* Trunk port settings */ 64struct trunk_reqport { 65 char rp_ifname[IFNAMSIZ]; /* name of the trunk */ 66 char rp_portname[IFNAMSIZ]; /* name of the port */ 67 u_int32_t rp_prio; /* port priority */ 68 u_int32_t rp_flags; /* port flags */ 69}; 70 71#define SIOCGTRUNKPORT _IOWR('i', 140, struct trunk_reqport) 72#define SIOCSTRUNKPORT _IOW('i', 141, struct trunk_reqport) 73#define SIOCSTRUNKDELPORT _IOW('i', 142, struct trunk_reqport) 74 75/* Trunk, ports and options */ 76struct trunk_reqall { 77 char ra_ifname[IFNAMSIZ]; /* name of the trunk */ 78 u_int ra_proto; /* trunk protocol */ 79 80 size_t ra_size; /* size of buffer */ 81 struct trunk_reqport *ra_port; /* allocated buffer */ 82 int ra_ports; /* total port count */ 83}; 84 85#define SIOCGTRUNK _IOWR('i', 143, struct trunk_reqall) 86#define SIOCSTRUNK _IOW('i', 144, struct trunk_reqall) 87 88#ifdef _KERNEL 89/* 90 * Internal kernel part 91 */ 92 93struct trunk_port { 94 struct ifnet *tp_if; /* physical interface */ 95 caddr_t tp_trunk; /* parent trunk */ 96 u_int8_t tp_lladdr[ETHER_ADDR_LEN]; 97 98 u_char tp_iftype; /* interface type */ 99 u_int32_t tp_prio; /* port priority */ 100 u_int32_t tp_flags; /* port flags */ 101 void *lh_cookie; /* if state hook */ 102 103 /* Redirected callbacks */ 104 void (*tp_watchdog)(struct ifnet *); 105 int (*tp_ioctl)(struct ifnet *, u_long, caddr_t); 106 107 SLIST_ENTRY(trunk_port) tp_entries; 108}; 109 110#define tp_ifname tp_if->if_xname /* interface name */ 111#define tp_link_state tp_if->if_link_state /* link state */ 112#define tp_capabilities tp_if->if_capabilities /* capabilities */ 113 114struct trunk_mc { 115 union { 116 struct ether_multi *mcu_enm; 117 } mc_u; 118 struct sockaddr_storage mc_addr; 119 120 SLIST_ENTRY(trunk_mc) mc_entries; 121}; 122 123#define mc_enm mc_u.mcu_enm 124 125struct trunk_ifreq { 126 union { 127 struct ifreq ifreq; 128 struct { 129 char ifr_name[IFNAMSIZ]; 130 struct sockaddr_storage ifr_ss; 131 } ifreq_storage; 132 } ifreq; 133}; 134 135struct trunk_softc { 136 struct arpcom tr_ac; /* virtual interface */ 137 int tr_unit; /* trunk unit */ 138 enum trunk_proto tr_proto; /* trunk protocol */ 139 u_int tr_count; /* number of ports */ 140 struct trunk_port *tr_primary; /* primary port */ 141 struct ifmedia tr_media; /* media config */ 142 caddr_t tr_psc; /* protocol data */ 143 144 SLIST_HEAD(__tplhd, trunk_port) tr_ports; /* list of interfaces */ 145 SLIST_ENTRY(trunk_softc) tr_entries; 146 147 SLIST_HEAD(__mclhd, trunk_mc) tr_mc_head; /* multicast addresses */ 148 149 /* Trunk protocol callbacks */ 150 int (*tr_detach)(struct trunk_softc *); 151 int (*tr_start)(struct trunk_softc *, struct mbuf *); 152 int (*tr_watchdog)(struct trunk_softc *); 153 int (*tr_input)(struct trunk_softc *, struct trunk_port *, 154 struct ether_header *, struct mbuf *); 155 int (*tr_port_create)(struct trunk_port *); 156 void (*tr_port_destroy)(struct trunk_port *); 157}; 158 159#define tr_ifflags tr_ac.ac_if.if_flags /* flags */ 160#define tr_ifname tr_ac.ac_if.if_xname /* name */ 161#define tr_capabilities tr_ac.ac_if.if_capabilities /* capabilities */ 162 163void trunk_port_ifdetach(struct ifnet *); 164int trunk_input(struct ifnet *, struct ether_header *, struct mbuf *); 165#endif /* _KERNEL */ 166 167#endif /* _NET_TRUNK_H */ 168