xref: /illumos-gate/usr/src/uts/common/sys/overlay_target.h (revision d48be21240dfd051b689384ce2b23479d757f2d8)
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) 2015 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 typedef struct overlay_target_point {
33 	uint8_t		otp_mac[ETHERADDRL];
34 	struct in6_addr	otp_ip;
35 	uint16_t	otp_port;
36 } overlay_target_point_t;
37 
38 #define	OVERLAY_TARG_IOCTL	(('o' << 24) | ('v' << 16) | ('t' << 8))
39 
40 #define	OVERLAY_TARG_INFO	(OVERLAY_TARG_IOCTL | 0x01)
41 
42 typedef enum overlay_targ_info_flags {
43 	OVERLAY_TARG_INFO_F_ACTIVE = 0x01,
44 	OVERLAY_TARG_INFO_F_DEGRADED = 0x02
45 } overlay_targ_info_flags_t;
46 
47 /*
48  * Get target information about an overlay device
49  */
50 typedef struct overlay_targ_info {
51 	datalink_id_t		oti_linkid;
52 	uint32_t		oti_needs;
53 	uint64_t		oti_flags;
54 	uint64_t		oti_vnetid;
55 } overlay_targ_info_t;
56 
57 /*
58  * Declare an association between a given varpd instance and a datalink.
59  */
60 #define	OVERLAY_TARG_ASSOCIATE	(OVERLAY_TARG_IOCTL | 0x02)
61 
62 typedef struct overlay_targ_associate {
63 	datalink_id_t		ota_linkid;
64 	uint32_t		ota_mode;
65 	uint64_t		ota_id;
66 	uint32_t		ota_provides;
67 	overlay_target_point_t	ota_point;
68 } overlay_targ_associate_t;
69 
70 /*
71  * Remove an association from a device. If the device has already been started,
72  * this implies OVERLAY_TARG_DEGRADE.
73  */
74 #define	OVERLAY_TARG_DISASSOCIATE	(OVERLAY_TARG_IOCTL | 0x3)
75 
76 /*
77  * Tells the kernel that while a varpd instance still exists, it basically isn't
78  * making any forward progress, so the device should consider itself degraded.
79  */
80 #define	OVERLAY_TARG_DEGRADE	(OVERLAY_TARG_IOCTL | 0x4)
81 
82 typedef struct overlay_targ_degrade {
83 	datalink_id_t	otd_linkid;
84 	uint32_t	otd_pad;
85 	char		otd_buf[OVERLAY_STATUS_BUFLEN];
86 } overlay_targ_degrade_t;
87 
88 /*
89  * Tells the kernel to remove the degraded status that it set on a device.
90  */
91 #define	OVERLAY_TARG_RESTORE	(OVERLAY_TARG_IOCTL | 0x5)
92 
93 typedef struct overlay_targ_id {
94 	datalink_id_t	otid_linkid;
95 } overlay_targ_id_t;
96 
97 /*
98  * The following ioctls are all used to support dynamic lookups from userland,
99  * generally serviced by varpd.
100  *
101  * The way this is designed to work is that user land will have threads sitting
102  * in OVERLAY_TARG_LOOKUP ioctls waiting to service requests. A thread will sit
103  * waiting for work for up to approximately one second of time before they will
104  * be sent back out to user land to give user land a chance to clean itself up
105  * or more generally, come back into the kernel for work. Once these threads
106  * return, they will have a request with which more action can be done. The
107  * following ioctls can all be used to answer the request.
108  *
109  *	OVERLAY_TARG_RESPOND - overlay_targ_resp_t
110  *
111  *		The overlay_targ_resp_t has the appropriate information from
112  *		which a reply can be generated. The information is filled into
113  *		an overlay_targ_point_t as appropriate based on the
114  *		overlay_plugin_dest_t type.
115  *
116  *
117  *	OVERLAY_TARG_DROP - overlay_targ_resp_t
118  *
119  *		The overlay_targ_resp_t should identify a request for which to
120  *		drop a packet.
121  *
122  *
123  *	OVERLAY_TARG_INJECT - overlay_targ_pkt_t
124  *
125  *		The overlay_targ_pkt_t injects a fully formed packet into the
126  *		virtual network. It may either be identified by its data link id
127  *		or by the request id. If both are specified, the
128  *		datalink id will be used. Note, that an injection is not
129  *		considered a reply and if this corresponds to a request, then
130  *		that individual packet must still be dropped.
131  *
132  *
133  *	OVERLAY_TARG_PKT - overlay_targ_pkt_t
134  *
135  *		This ioctl can be used to copy data from a given request into a
136  *		user buffer. This can be used in combination with
137  *		OVERLAY_TARG_INJECT to implement services such as a proxy-arp.
138  *
139  *
140  *	OVERLAY_TARG_RESEND - overlay_targ_pkt_t
141  *
142  *		This ioctl is similar to the OVERLAY_TARG_INJECT, except instead
143  *		of receiving it on the local mac handle, it queues it for
144  *		retransmission again. This is useful if you have a packet that
145  *		was originally destined for some broadcast or multicast address
146  *		that you now want to send to a unicast address.
147  */
148 #define	OVERLAY_TARG_LOOKUP	(OVERLAY_TARG_IOCTL | 0x10)
149 #define	OVERLAY_TARG_RESPOND	(OVERLAY_TARG_IOCTL | 0x11)
150 #define	OVERLAY_TARG_DROP	(OVERLAY_TARG_IOCTL | 0x12)
151 #define	OVERLAY_TARG_INJECT	(OVERLAY_TARG_IOCTL | 0x13)
152 #define	OVERLAY_TARG_PKT	(OVERLAY_TARG_IOCTL | 0x14)
153 #define	OVERLAY_TARG_RESEND	(OVERLAY_TARG_IOCTL | 0x15)
154 
155 typedef struct overlay_targ_lookup {
156 	uint64_t	otl_dlid;
157 	uint64_t	otl_reqid;
158 	uint64_t	otl_varpdid;
159 	uint64_t	otl_vnetid;
160 	uint64_t	otl_hdrsize;
161 	uint64_t	otl_pktsize;
162 	uint8_t		otl_srcaddr[ETHERADDRL];
163 	uint8_t		otl_dstaddr[ETHERADDRL];
164 	uint32_t	otl_dsttype;
165 	uint32_t	otl_sap;
166 	int32_t		otl_vlan;
167 } overlay_targ_lookup_t;
168 
169 typedef struct overlay_targ_resp {
170 	uint64_t	otr_reqid;
171 	overlay_target_point_t otr_answer;
172 } overlay_targ_resp_t;
173 
174 typedef struct overlay_targ_pkt {
175 	uint64_t	otp_linkid;
176 	uint64_t	otp_reqid;
177 	uint64_t	otp_size;
178 	void		*otp_buf;
179 } overlay_targ_pkt_t;
180 
181 #ifdef _KERNEL
182 
183 #pragma pack(4)
184 typedef struct overlay_targ_pkt32 {
185 	uint64_t	otp_linkid;
186 	uint64_t	otp_reqid;
187 	uint64_t	otp_size;
188 	caddr32_t	otp_buf;
189 } overlay_targ_pkt32_t;
190 #pragma pack()
191 
192 #endif /* _KERNEL */
193 
194 /*
195  * This provides a way to get a list of active overlay devices independently
196  * from dlmgmtd. At the end of the day the kernel always knows what will exist
197  * and this allows varpd which is an implementation of libdladm not to end up
198  * needing to call back into dlmgmtd via libdladm and create an unfortunate
199  * dependency cycle.
200  */
201 
202 #define	OVERLAY_TARG_LIST	(OVERLAY_TARG_IOCTL | 0x20)
203 
204 typedef struct overlay_targ_list {
205 	uint32_t	otl_nents;
206 	uint32_t	otl_ents[];
207 } overlay_targ_list_t;
208 
209 /*
210  * The following family of ioctls all manipulate the target cache of a given
211  * device.
212  *
213  *	OVERLAY_TARG_CACHE_GET - overlay_targ_cache_t
214  *
215  *		The overlay_targ_cache_t should be have its link identifier and
216  *		the desired mac address filled in. On return, it will fill in
217  *		the otc_dest member, if the entry exists in the table.
218  *
219  *
220  *	OVERLAY_TARG_CACHE_SET - overlay_targ_cache_t
221  *
222  *		The cache table entry of the mac address referred to by otc_mac
223  *		and otd_linkid will be filled in with the details provided by in
224  *		the otc_dest member.
225  *
226  *	OVERLAY_TARG_CACHE_REMOVE - overlay_targ_cache_t
227  *
228  *		Removes the cache entry identified by otc_mac from the table.
229  *		Note that this does not stop any in-flight lookups or deal with
230  *		any data that is awaiting a lookup.
231  *
232  *
233  *	OVERLAY_TARG_CACHE_FLUSH - overlay_targ_cache_t
234  *
235  *		Similar to OVERLAY_TARG_CACHE_REMOVE, but functions on the
236  *		entire table identified by otc_linkid. All other parameters are
237  *		ignored.
238  *
239  *
240  *	OVERLAY_TARG_CACHE_ITER - overlay_targ_cache_iter_t
241  *
242  *		Iterates over the contents of a target cache identified by
243  *		otci_linkid. Iteration is guaranteed to be exactly once for
244  *		items which are in the hashtable at the beginning and end of
245  *		iteration. For items which are added or removed after iteration
246  *		has begun, only at most once semantics are guaranteed. Consumers
247  *		should ensure that otci_marker is zeroed before starting
248  *		iteration and should preserve its contents across calls.
249  *
250  *		Before calling in, otci_count should be set to the number of
251  *		entries that space has been allocated for in otci_ents. The
252  *		value will be updated to indicate the total number written out.
253  */
254 
255 #define	OVERLAY_TARG_CACHE_GET		(OVERLAY_TARG_IOCTL | 0x30)
256 #define	OVERLAY_TARG_CACHE_SET		(OVERLAY_TARG_IOCTL | 0x31)
257 #define	OVERLAY_TARG_CACHE_REMOVE	(OVERLAY_TARG_IOCTL | 0x32)
258 #define	OVERLAY_TARG_CACHE_FLUSH	(OVERLAY_TARG_IOCTL | 0x33)
259 #define	OVERLAY_TARG_CACHE_ITER		(OVERLAY_TARG_IOCTL | 0x34)
260 
261 /*
262  * This is a pretty arbitrary number that we're constraining ourselves to
263  * for iteration. Basically the goal is to make sure that we can't have a user
264  * ask us to allocate too much memory on their behalf at any time. A more
265  * dynamic form may be necessary some day.
266  */
267 #define	OVERLAY_TARGET_ITER_MAX	500
268 
269 #define	OVERLAY_TARGET_CACHE_DROP	0x01
270 
271 typedef struct overlay_targ_cache_entry {
272 	uint8_t			otce_mac[ETHERADDRL];
273 	uint16_t		otce_flags;
274 	overlay_target_point_t	otce_dest;
275 } overlay_targ_cache_entry_t;
276 
277 typedef struct overlay_targ_cache {
278 	datalink_id_t			otc_linkid;
279 	overlay_targ_cache_entry_t	otc_entry;
280 } overlay_targ_cache_t;
281 
282 typedef struct overlay_targ_cache_iter {
283 	datalink_id_t			otci_linkid;
284 	uint32_t			otci_pad;
285 	uint64_t			otci_marker;
286 	uint16_t			otci_count;
287 	uint8_t				otci_pad2[3];
288 	overlay_targ_cache_entry_t	otci_ents[];
289 } overlay_targ_cache_iter_t;
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 
295 #endif /* _OVERLAY_TARGET_H */
296