Annotation of sys/net/if_trunk.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: if_trunk.h,v 1.12 2007/04/26 08:57:59 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: */
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 \
37: "\20\01MASTER\02STACK\03ACTIVE"
38:
39: /* Supported trunk PROTOs */
40: enum trunk_proto {
41: TRUNK_PROTO_NONE = 0, /* no trunk protocol defined */
42: TRUNK_PROTO_ROUNDROBIN = 1, /* simple round robin */
43: TRUNK_PROTO_FAILOVER = 2, /* active failover */
44: TRUNK_PROTO_LOADBALANCE = 3, /* loadbalance */
45: TRUNK_PROTO_MAX = 4
46: };
47:
48: struct trunk_protos {
49: const char *tpr_name;
50: enum trunk_proto tpr_proto;
51: };
52:
53: #define TRUNK_PROTO_DEFAULT TRUNK_PROTO_ROUNDROBIN
54: #define TRUNK_PROTOS { \
55: { "roundrobin", TRUNK_PROTO_ROUNDROBIN }, \
56: { "failover", TRUNK_PROTO_FAILOVER }, \
57: { "loadbalance", TRUNK_PROTO_LOADBALANCE }, \
58: { "none", TRUNK_PROTO_NONE }, \
59: { "default", TRUNK_PROTO_DEFAULT } \
60: }
61:
62: /*
63: * Trunk ioctls.
64: */
65:
66: /* Trunk port settings */
67: struct trunk_reqport {
68: char rp_ifname[IFNAMSIZ]; /* name of the trunk */
69: char rp_portname[IFNAMSIZ]; /* name of the port */
70: u_int32_t rp_prio; /* port priority */
71: u_int32_t rp_flags; /* port flags */
72: };
73:
74: #define SIOCGTRUNKPORT _IOWR('i', 140, struct trunk_reqport)
75: #define SIOCSTRUNKPORT _IOW('i', 141, struct trunk_reqport)
76: #define SIOCSTRUNKDELPORT _IOW('i', 142, struct trunk_reqport)
77:
78: /* Trunk, ports and options */
79: struct trunk_reqall {
80: char ra_ifname[IFNAMSIZ]; /* name of the trunk */
81: u_int ra_proto; /* trunk protocol */
82:
83: size_t ra_size; /* size of buffer */
84: struct trunk_reqport *ra_port; /* allocated buffer */
85: int ra_ports; /* total port count */
86: };
87:
88: #define SIOCGTRUNK _IOWR('i', 143, struct trunk_reqall)
89: #define SIOCSTRUNK _IOW('i', 144, struct trunk_reqall)
90:
91: #ifdef _KERNEL
92: /*
93: * Internal kernel part
94: */
95: struct trunk_softc;
96: struct trunk_port {
97: struct ifnet *tp_if; /* physical interface */
98: struct trunk_softc *tp_trunk; /* parent trunk */
99: u_int8_t tp_lladdr[ETHER_ADDR_LEN];
100: caddr_t tp_psc; /* protocol data */
101:
102: u_char tp_iftype; /* interface type */
103: u_int32_t tp_prio; /* port priority */
104: u_int32_t tp_flags; /* port flags */
105: void *lh_cookie; /* if state hook */
106:
107: /* Redirected callbacks */
108: void (*tp_watchdog)(struct ifnet *);
109: int (*tp_ioctl)(struct ifnet *, u_long, caddr_t);
110:
111: SLIST_ENTRY(trunk_port) tp_entries;
112: };
113:
114: #define tp_ifname tp_if->if_xname /* interface name */
115: #define tp_ifflags tp_if->if_flags /* interface flags */
116: #define tp_link_state tp_if->if_link_state /* link state */
117: #define tp_capabilities tp_if->if_capabilities /* capabilities */
118:
119: #define TRUNK_PORTACTIVE(_tp) ( \
120: (LINK_STATE_IS_UP((_tp)->tp_link_state)) && \
121: ((_tp)->tp_ifflags & IFF_UP) \
122: )
123:
124: struct trunk_mc {
125: union {
126: struct ether_multi *mcu_enm;
127: } mc_u;
128: struct sockaddr_storage mc_addr;
129:
130: SLIST_ENTRY(trunk_mc) mc_entries;
131: };
132:
133: #define mc_enm mc_u.mcu_enm
134:
135: struct trunk_ifreq {
136: union {
137: struct ifreq ifreq;
138: struct {
139: char ifr_name[IFNAMSIZ];
140: struct sockaddr_storage ifr_ss;
141: } ifreq_storage;
142: } ifreq;
143: };
144:
145: struct trunk_softc {
146: struct arpcom tr_ac; /* virtual interface */
147: int tr_unit; /* trunk unit */
148: enum trunk_proto tr_proto; /* trunk protocol */
149: u_int tr_count; /* number of ports */
150: struct trunk_port *tr_primary; /* primary port */
151: struct ifmedia tr_media; /* media config */
152: caddr_t tr_psc; /* protocol data */
153:
154: SLIST_HEAD(__tplhd, trunk_port) tr_ports; /* list of interfaces */
155: SLIST_ENTRY(trunk_softc) tr_entries;
156:
157: SLIST_HEAD(__mclhd, trunk_mc) tr_mc_head; /* multicast addresses */
158:
159: /* Trunk protocol callbacks */
160: int (*tr_detach)(struct trunk_softc *);
161: int (*tr_start)(struct trunk_softc *, struct mbuf *);
162: int (*tr_watchdog)(struct trunk_softc *);
163: int (*tr_input)(struct trunk_softc *, struct trunk_port *,
164: struct ether_header *, struct mbuf *);
165: int (*tr_port_create)(struct trunk_port *);
166: void (*tr_port_destroy)(struct trunk_port *);
167: void (*tr_linkstate)(struct trunk_port *);
168: void (*tr_init)(struct trunk_softc *);
169: void (*tr_stop)(struct trunk_softc *);
170: };
171:
172: #define tr_ifflags tr_ac.ac_if.if_flags /* flags */
173: #define tr_ifname tr_ac.ac_if.if_xname /* name */
174: #define tr_capabilities tr_ac.ac_if.if_capabilities /* capabilities */
175: #define tr_ifindex tr_ac.ac_if.if_index /* int index */
176: #define tr_lladdr tr_ac.ac_enaddr /* lladdr */
177:
178: #define IFCAP_TRUNK_MASK 0xffff0000 /* private capabilities */
179: #define IFCAP_TRUNK_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */
180:
181: /* Private data used by the loadbalancing protocol */
182: #define TRUNK_LB_MAXKEYS 8
183: struct trunk_lb {
184: u_int32_t lb_key;
185: struct trunk_port *lb_ports[TRUNK_MAX_PORTS];
186: };
187:
188: void trunk_port_ifdetach(struct ifnet *);
189: int trunk_input(struct ifnet *, struct ether_header *,
190: struct mbuf *);
191: int trunk_enqueue(struct ifnet *, struct mbuf *);
192: u_int32_t trunk_hashmbuf(struct mbuf *, u_int32_t);
193: #endif /* _KERNEL */
194:
195: #endif /* _NET_TRUNK_H */
CVSweb