1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef _NET_TRUNK_H
20 #define _NET_TRUNK_H
21
22
23
24
25
26 #define TRUNK_MAX_PORTS 32
27 #define TRUNK_MAX_NAMESIZE 32
28 #define TRUNK_MAX_STACKING 4
29
30
31 #define TRUNK_PORT_SLAVE 0x00000000
32 #define TRUNK_PORT_MASTER 0x00000001
33 #define TRUNK_PORT_STACK 0x00000002
34 #define TRUNK_PORT_ACTIVE 0x00000004
35 #define TRUNK_PORT_GLOBAL 0x80000000
36 #define TRUNK_PORT_BITS \
37 "\20\01MASTER\02STACK\03ACTIVE"
38
39
40 enum trunk_proto {
41 TRUNK_PROTO_NONE = 0,
42 TRUNK_PROTO_ROUNDROBIN = 1,
43 TRUNK_PROTO_FAILOVER = 2,
44 TRUNK_PROTO_LOADBALANCE = 3,
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
64
65
66
67 struct trunk_reqport {
68 char rp_ifname[IFNAMSIZ];
69 char rp_portname[IFNAMSIZ];
70 u_int32_t rp_prio;
71 u_int32_t rp_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
79 struct trunk_reqall {
80 char ra_ifname[IFNAMSIZ];
81 u_int ra_proto;
82
83 size_t ra_size;
84 struct trunk_reqport *ra_port;
85 int ra_ports;
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
94
95 struct trunk_softc;
96 struct trunk_port {
97 struct ifnet *tp_if;
98 struct trunk_softc *tp_trunk;
99 u_int8_t tp_lladdr[ETHER_ADDR_LEN];
100 caddr_t tp_psc;
101
102 u_char tp_iftype;
103 u_int32_t tp_prio;
104 u_int32_t tp_flags;
105 void *lh_cookie;
106
107
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
115 #define tp_ifflags tp_if->if_flags
116 #define tp_link_state tp_if->if_link_state
117 #define tp_capabilities tp_if->if_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;
147 int tr_unit;
148 enum trunk_proto tr_proto;
149 u_int tr_count;
150 struct trunk_port *tr_primary;
151 struct ifmedia tr_media;
152 caddr_t tr_psc;
153
154 SLIST_HEAD(__tplhd, trunk_port) tr_ports;
155 SLIST_ENTRY(trunk_softc) tr_entries;
156
157 SLIST_HEAD(__mclhd, trunk_mc) tr_mc_head;
158
159
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
173 #define tr_ifname tr_ac.ac_if.if_xname
174 #define tr_capabilities tr_ac.ac_if.if_capabilities
175 #define tr_ifindex tr_ac.ac_if.if_index
176 #define tr_lladdr tr_ac.ac_enaddr
177
178 #define IFCAP_TRUNK_MASK 0xffff0000
179 #define IFCAP_TRUNK_FULLDUPLEX 0x00010000
180
181
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
194
195 #endif