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