1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright (c) 2018 Joyent, Inc.
14 */
15
16 #ifndef _OVERLAY_TARGET_H
17 #define _OVERLAY_TARGET_H
18
19 /*
20 * Overlay device varpd ioctl interface (/dev/overlay)
21 */
22
23 #include <sys/types.h>
24 #include <sys/ethernet.h>
25 #include <netinet/in.h>
26 #include <sys/overlay_common.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /*
33 * The overlay_target_point_t structure represents the destination where
34 * encapsulated frames are sent. Currently supported virtualization protocls
35 * (i.e. vxlan) only use otp_ip and otp_port, but other methods might use
36 * a L2 address instead of an L3 address to represent a destination.
37 */
38 typedef struct overlay_target_point {
39 uint8_t otp_mac[ETHERADDRL];
40 struct in6_addr otp_ip;
41 uint16_t otp_port;
42 } overlay_target_point_t;
43
44 /*
45 * The overlay_target_route_t represents the information necessary to send
46 * packets to remote (routed) destinations. Note: we currently only include
47 * the L3 address prefix lengths since overlay can deduce the subnet address
48 * from the original VL3 IP in the request + the prefix length in the reply.
49 */
50 typedef struct overlay_target_route {
51 uint64_t otr_vnet;
52 uint16_t otr_vlan;
53 uint8_t otr_srcmac[ETHERADDRL];
54 uint32_t otr_dcid;
55 uint8_t otr_src_prefixlen;
56 uint8_t otr_dst_prefixlen;
57 } overlay_target_route_t;
58
59 #define OVERLAY_TARG_IOCTL (('o' << 24) | ('v' << 16) | ('t' << 8))
60
61 #define OVERLAY_TARG_INFO (OVERLAY_TARG_IOCTL | 0x01)
62
63 typedef enum overlay_targ_info_flags {
64 OVERLAY_TARG_INFO_F_ACTIVE = 0x01,
65 OVERLAY_TARG_INFO_F_DEGRADED = 0x02
66 } overlay_targ_info_flags_t;
67
68 /*
69 * Get target information about an overlay device
70 */
71 typedef struct overlay_targ_info {
72 datalink_id_t oti_linkid;
73 uint32_t oti_needs;
74 uint64_t oti_flags;
75 uint64_t oti_vnetid;
76 uint32_t oti_dcid;
77 } overlay_targ_info_t;
78
79 /*
80 * Declare an association between a given varpd instance and a datalink.
81 */
82 #define OVERLAY_TARG_ASSOCIATE (OVERLAY_TARG_IOCTL | 0x02)
83
84 typedef struct overlay_targ_associate {
85 datalink_id_t ota_linkid;
86 uint32_t ota_mode;
87 uint64_t ota_id;
88 uint32_t ota_provides;
89 overlay_target_point_t ota_point;
90 } overlay_targ_associate_t;
91
92 /*
93 * Remove an association from a device. If the device has already been started,
94 * this implies OVERLAY_TARG_DEGRADE.
95 */
96 #define OVERLAY_TARG_DISASSOCIATE (OVERLAY_TARG_IOCTL | 0x3)
97
98 /*
99 * Tells the kernel that while a varpd instance still exists, it basically isn't
100 * making any forward progress, so the device should consider itself degraded.
101 */
102 #define OVERLAY_TARG_DEGRADE (OVERLAY_TARG_IOCTL | 0x4)
103
104 typedef struct overlay_targ_degrade {
105 datalink_id_t otd_linkid;
106 uint32_t otd_pad;
107 char otd_buf[OVERLAY_STATUS_BUFLEN];
108 } overlay_targ_degrade_t;
109
110 /*
111 * Tells the kernel to remove the degraded status that it set on a device.
112 */
113 #define OVERLAY_TARG_RESTORE (OVERLAY_TARG_IOCTL | 0x5)
114
115 typedef struct overlay_targ_id {
116 datalink_id_t otid_linkid;
117 } overlay_targ_id_t;
118
119 /*
120 * The following ioctls are all used to support dynamic lookups from userland,
121 * generally serviced by varpd.
122 *
123 * The way this is designed to work is that user land will have threads sitting
124 * in OVERLAY_TARG_LOOKUP ioctls waiting to service requests. A thread will sit
125 * waiting for work for up to approximately one second of time before they will
126 * be sent back out to user land to give user land a chance to clean itself up
127 * or more generally, come back into the kernel for work. Once these threads
128 * return, they will have a request with which more action can be done. The
129 * following ioctls can all be used to answer the request.
130 *
131 * OVERLAY_TARG_RESPOND - overlay_targ_resp_t
132 *
133 * The overlay_targ_resp_t has the appropriate information from
134 * which a reply can be generated. The information is filled into
135 * an overlay_targ_point_t as appropriate based on the
136 * overlay_plugin_dest_t type.
137 *
138 *
139 * OVERLAY_TARG_DROP - overlay_targ_resp_t
140 *
141 * The overlay_targ_resp_t should identify a request for which to
142 * drop a packet.
143 *
144 *
145 * OVERLAY_TARG_INJECT - overlay_targ_pkt_t
146 *
147 * The overlay_targ_pkt_t injects a fully formed packet into the
148 * virtual network. It may either be identified by its data link id
149 * or by the request id. If both are specified, the
150 * datalink id will be used. Note, that an injection is not
151 * considered a reply and if this corresponds to a requeset, then
152 * that individual packet must still be dropped.
153 *
154 *
155 * OVERLAY_TARG_PKT - overlay_targ_pkt_t
156 *
157 * This ioctl can be used to copy data from a given request into a
158 * user buffer. This can be used in combination with
159 * OVERLAY_TARG_INJECT to implement services such as a proxy-arp.
160 *
161 *
162 * OVERLAY_TARG_RESEND - overlay_targ_pkt_t
163 *
164 * This ioctl is similar to the OVERLAY_TARG_INJECT, except instead
165 * of receiving it on the local mac handle, it queues it for
166 * retransmission again. This is useful if you have a packet that
167 * was originally destined for some broadcast or multicast address
168 * that you now want to send to a unicast address.
169 */
170 #define OVERLAY_TARG_LOOKUP (OVERLAY_TARG_IOCTL | 0x10)
171 #define OVERLAY_TARG_RESPOND (OVERLAY_TARG_IOCTL | 0x11)
172 #define OVERLAY_TARG_DROP (OVERLAY_TARG_IOCTL | 0x12)
173 #define OVERLAY_TARG_INJECT (OVERLAY_TARG_IOCTL | 0x13)
174 #define OVERLAY_TARG_PKT (OVERLAY_TARG_IOCTL | 0x14)
175 #define OVERLAY_TARG_RESEND (OVERLAY_TARG_IOCTL | 0x15)
176
177 typedef struct overlay_targ_l2 {
178 uint8_t otl2_srcaddr[ETHERADDRL];
179 uint8_t otl2_dstaddr[ETHERADDRL];
180 uint32_t otl2_dsttype;
181 uint32_t otl2_sap;
182 } overlay_targ_l2_t;
183
184 typedef struct overlay_targ_l3 {
185 struct in6_addr otl3_srcip;
186 struct in6_addr otl3_dstip;
187 } overlay_targ_l3_t;
188
189 typedef struct overlay_targ_lookup {
190 uint64_t otl_dlid;
191 uint64_t otl_reqid;
192 uint64_t otl_varpdid;
193 uint64_t otl_vnetid;
194 uint64_t otl_hdrsize;
195 uint64_t otl_pktsize;
196 union {
197 overlay_targ_l2_t otlu_l2;
198 overlay_targ_l3_t otlu_l3;
199 } otl_addru;
200 int32_t otl_vlan;
201 boolean_t otl_l3req;
202 } overlay_targ_lookup_t;
203
204
205 typedef struct overlay_targ_resp {
206 uint64_t otr_reqid;
207 overlay_target_point_t otr_answer;
208 overlay_target_route_t otr_route; /* Ignored for VL2->UL3 requests */
209 } overlay_targ_resp_t;
210
211 typedef struct overlay_targ_pkt {
212 uint64_t otp_linkid;
213 uint64_t otp_reqid;
214 uint64_t otp_size;
215 void *otp_buf;
216 } overlay_targ_pkt_t;
217
218 #ifdef _KERNEL
219
220 typedef struct overlay_targ_pkt32 {
221 uint64_t otp_linkid;
222 uint64_t otp_reqid;
223 uint64_t otp_size;
224 caddr32_t otp_buf;
225 } overlay_targ_pkt32_t;
226
227 #endif /* _KERNEL */
228
229 /*
230 * This provides a way to get a list of active overlay devices independently
231 * from dlmgmtd. At the end of the day the kernel always knows what will exist
232 * and this allows varpd which is an implementation of libdladm not to end up
233 * needing to call back into dlmgmtd via libdladm and create an unfortunate
234 * dependency cycle.
235 */
236
237 #define OVERLAY_TARG_LIST (OVERLAY_TARG_IOCTL | 0x20)
238
239 typedef struct overlay_targ_list {
240 uint32_t otl_nents;
241 uint32_t otl_ents[];
242 } overlay_targ_list_t;
243
244 /*
245 * The following family of ioctls all manipulate the target cache of a given
246 * device.
247 *
248 * OVERLAY_TARG_CACHE_GET - overlay_targ_cache_t
249 *
250 * The overlay_targ_cache_t should be have its link identifier and
251 * the desired mac address filled in. On return, it will fill in
252 * the otc_dest member, if the entry exists in the table.
253 *
254 *
255 * OVERLAY_TARG_CACHE_SET - overlay_targ_cache_t
256 *
257 * The cache table entry of the mac address referred to by otc_mac
258 * and otd_linkid will be filled in with the details provided by in
259 * the otc_dest member.
260 *
261 * OVERLAY_TARG_CACHE_REMOVE - overlay_targ_cache_t
262 *
263 * Removes the cache entry identified by otc_mac from the table.
264 * Note that this does not stop any in-flight lookups or deal with
265 * any data that is awaiting a lookup.
266 *
267 *
268 * OVERLAY_TARG_CACHE_FLUSH - overlay_targ_cache_t
269 *
270 * Similar to OVERLAY_TARG_CACHE_REMOVE, but functions on the
271 * entire table identified by otc_linkid. All other parameters are
272 * ignored.
273 *
274 *
275 * OVERLAY_TARG_CACHE_ITER - overlay_targ_cache_iter_t
276 *
277 * Iterates over the contents of a target cache identified by
278 * otci_linkid. Iteration is guaranteed to be exactly once for
279 * items which are in the hashtable at the beginning and end of
280 * iteration. For items which are added or removed after iteration
281 * has begun, only at most once semantics are guaranteed. Consumers
282 * should ensure that otci_marker is zeroed before starting
283 * iteration and should preserve its contents across calls.
284 *
285 * Before calling in, otci_count should be set to the number of
286 * entries that space has been allocated for in otci_ents. The
287 * value will be updated to indicate the total number written out.
288 */
289
290 #define OVERLAY_TARG_CACHE_GET (OVERLAY_TARG_IOCTL | 0x30)
291 #define OVERLAY_TARG_CACHE_SET (OVERLAY_TARG_IOCTL | 0x31)
292 #define OVERLAY_TARG_CACHE_REMOVE (OVERLAY_TARG_IOCTL | 0x32)
293 #define OVERLAY_TARG_CACHE_FLUSH (OVERLAY_TARG_IOCTL | 0x33)
294 #define OVERLAY_TARG_CACHE_ITER (OVERLAY_TARG_IOCTL | 0x34)
295
296 /*
297 * This is a pretty arbitrary number that we're constraining ourselves to
298 * for iteration. Basically the goal is to make sure that we can't have a user
299 * ask us to allocate too much memory on their behalf at any time. A more
300 * dynamic form may be necessary some day.
301 */
302 #define OVERLAY_TARGET_ITER_MAX 500
303
304 #define OVERLAY_TARGET_CACHE_DROP 0x01
305 #define OVERLAY_TARGET_CACHE_ROUTER 0x02
306
307 typedef struct overlay_targ_cache_entry {
308 uint8_t otce_mac[ETHERADDRL];
309 uint16_t otce_flags;
310 uint32_t otce_dcid;
311 overlay_target_point_t otce_dest;
312 } overlay_targ_cache_entry_t;
313
314 typedef struct overlay_targ_cache {
315 datalink_id_t otc_linkid;
316 overlay_targ_cache_entry_t otc_entry;
317 } overlay_targ_cache_t;
318
319 typedef struct overlay_targ_cache_iter {
320 datalink_id_t otci_linkid;
321 uint32_t otci_pad;
322 uint64_t otci_marker;
323 uint16_t otci_count;
324 overlay_targ_cache_entry_t otci_ents[];
325 } overlay_targ_cache_iter_t;
326
327 #ifdef __cplusplus
328 }
329 #endif
330
331 #endif /* _OVERLAY_TARGET_H */