xref: /titanic_41/usr/src/uts/common/inet/nca/ncadoorhdr.h (revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_INET_NCADOORHDR_H
28 #define	_INET_NCADOORHDR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #ifndef _KERNEL
37 #include <stddef.h>
38 #endif /* _KERNEL */
39 
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 
44 #define	ONE_KB				(1024)
45 #define	NCA_IO_MAX_SIZE			(256 * ONE_KB)
46 #define	NCA_IO_OFFSET			(sizeof (nca_io2_t))
47 
48 #define	NCA_IO_TRUE			1
49 #define	NCA_IO_FALSE			0
50 
51 /*
52  * Defines the data structures used by NCA and Webservers.
53  */
54 
55 typedef enum {
56 	/*
57 	 * NCA-to-HTTP-server protocol operation values:
58 	 */
59 	http_op		= 100,	/* NCA<>HTTP normal request/response */
60 	error_op	= 101,	/* NCA<-HTTP server error */
61 	error_retry_op	= 102,	/* NCA<-HTTP server transient error */
62 	resource_op	= 120,	/* NCA->HTTP server release resources */
63 	timeout_op	= 150,	/* NCA<-HTTP server timed out */
64 	door_attach_op	= 160,	/* NCA->HTTP NCA supports door fattach */
65 	/*
66 	 * NCA-to-Logging-server protocol operation values:
67 	 */
68 	log_op		= 10000,	/* NCA->Logger normal request */
69 	log_ok_op	= 10001,	/* NCA<-Logger request ok */
70 	log_error_op	= 10002,	/* NCA<-Logger request error */
71 	log_op_fiov	= 10003		/* NCA<>Logger file i/o vector */
72 } nca_op_t;
73 
74 typedef enum {
75 	NCA_HTTP_VERSION1 = 1001,	/* NCA-to-HTTP-server protocol */
76 	NCA_HTTP_VERSION2 = 1002,	/* NCA-to-HTTP-server protocol V2 */
77 	NCA_LOG_VERSION1 = 5001,	/* NCA-to-Logging-server protocol */
78 	NCA_LOG_VERSION2 = 5002		/* with in-kernel logging support */
79 	/*
80 	 * Note: Other version values are reserved for other client-to-server
81 	 * Solaris door base protocols and as these protocols may or may not
82 	 * be for use with NCA a new datatype (door_version_t ?) will be
83 	 * defined.
84 	 *
85 	 * Note: NCA_HTTP_VERSION1 has been deprecated, NCA_HTTP_VERSION2 must
86 	 * be used instead and is functionally a superset of (however, requires
87 	 * porting as some member names and symantics have changed).
88 	 */
89 } nca_version_t;
90 
91 #define	HTTP_ERR	(-1)
92 #define	HTTP_0_0	0x00000
93 #define	HTTP_0_9	0x00009
94 #define	HTTP_1_0	0x10000
95 #define	HTTP_1_1	0x10001
96 
97 typedef uint32_t	nca_tag_t;	/* Request id */
98 typedef uint32_t	nca_offset_t;	/* Offset */
99 
100 /*
101  * Use pack(4) to make sizeof(struct nca_direct_cd_s) the same
102  * on x86 and amd64.
103  */
104 
105 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
106 #pragma pack(4)
107 #endif
108 
109 typedef struct nca_direct_cd_s {	/* Direct i/o connection descriptor */
110 	uint64_t	cid;		/* The connection id */
111 	nca_tag_t	tag;		/* The connect tag */
112 } nca_direct_cd_t;
113 
114 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
115 #pragma pack()
116 #endif
117 
118 /*
119  * nca_io2_t.advisory values:
120  *
121  *    NCA_IO_ADVISE - on cache miss upcall/return or preempted downcall
122  *	advise that on susequent cache hit an advise upcall is required.
123  *
124  *    NCA_IO_ADVISE_REPLACE - on advisory upcall/return or unsolicited
125  *	downcall (for a ctag'ed object) replace the object data with
126  *	returned object data.
127  *
128  *    NCA_IO_ADVISE_FLUSH - on advisory upcall/return or unsolicited downcall
129  *	(for a ctag'ed object) flush the object from the cache.
130  *
131  *    NCA_IO_ADVISE_TEMP - on advisory upcall/return use the returned object
132  *	data instead of the cached object data, the cached object is unaltered.
133  *
134  *    NCA_IO_ADVISE_NONE - on cache miss upcall/return or preempted downcall
135  *	no advise is needed and on advisory upcall/return no advise was needed.
136  */
137 #define	NCA_IO_ADVISE		0x01
138 #define	NCA_IO_ADVISE_REPLACE	0x02
139 #define	NCA_IO_ADVISE_FLUSH	0x04
140 #define	NCA_IO_ADVISE_TEMP	0x08
141 #define	NCA_IO_ADVISE_NONE	0x00
142 
143 
144 /*
145  * nca_io2_t.direct_type values:
146  *
147  *  For upcall or downcall/return:
148  *
149  *    NCA_IO_DIRECT_NONE - none, any data is delivered via the optional
150  *	meta data specifiers data/data_len and/or trailer/trailer_len.
151  *
152  *    NCA_IO_DIRECT_FILENAME - file name, Invalid.
153  *
154  *    NCA_IO_DIRECT_SHMSEG - shared memory segment, Invalid.
155  *
156  *    NCA_IO_DIRECT_FILEDESC - file descriptor, Invalid.
157  *
158  *    NCA_IO_DIRECT_CTAG - cache tag(s), like NCA_IO_DIRECT_NONE any data
159  *	is delivered via the meta data specifiers data/data_len, in addition
160  *	the meta data specifiers direct/direct_len point to an array of ctag
161  *	uint64_t value(s) of previously returned ctag'ed response(s) for URI
162  *	relative pathnamed variant(s).
163  *
164  *    NCA_IO_DIRECT_SPLICE - splice of a connection is complete, on last
165  *	transaction for a connection (i.e. when both the call and return
166  *	nca_io2_t.more values are set to zero) indicates splice to the
167  *	previously named preempted connection is complete.
168  *
169  *    NCA_IO_DIRECT_TEE - tee of a connection is complete, on last
170  *	transaction for a connection (i.e. when both the call and return
171  *	nca_io2_t.more values are set to zero) indicates tee to the
172  *	previously named connection is complete.
173  *
174  *  For upcall/return or downcall:
175  *
176  *    NCA_IO_DIRECT_NONE - none, any data is delivered via the optional
177  *	meta data specifiers data/data_len and/or trailer/trailer_len.
178  *
179  *    NCA_IO_DIRECT_FILENAME - file name, data is read from the named file,
180  *	the meta data specifiers direct/direct_len point to a zero byte
181  *	terminated string containing the path to the named file.
182  *
183  *    NCA_IO_DIRECT_SHMSEG - shared memory segment, not implemented.
184  *
185  *    NCA_IO_DIRECT_FILEDESC - file descriptor, not implemented.
186  *
187  *    NCA_IO_DIRECT_CTAG - cache tag, data is to be gotten from the named
188  *	ctag value (a previously returned ctag'ed response).
189  *
190  *    NCA_IO_DIRECT_SPLICE - splice a connection, response data from the
191  *	current connection is output to the named connection (previously
192  *	preempted connection), the meta data specifiers direct/direct_len
193  *	point to a nca_direct_cd_t (a cid/tag pair connection descriptor)
194  *	used to specify the named connection. Note, no repsonse data is
195  * 	delivered to the current connection.
196  *
197  *    NCA_IO_DIRECT_TEE - tee a connection, response data from the current
198  *	connection is output to the named connection (previously preempted
199  *	connection), the meta data specifiers direct/direct_len	point to a
200  *	nca_direct_cd_t (a cid/tag pair connection descriptor) used to
201  *	specify the named connection. Note, response data is delivered to
202  *	the current connection as normal.
203  */
204 #define	NCA_IO_DIRECT_NONE	0
205 #define	NCA_IO_DIRECT_FILENAME	1
206 #define	NCA_IO_DIRECT_SHMSEG	2
207 #define	NCA_IO_DIRECT_FILEDESC	3
208 #define	NCA_IO_DIRECT_CTAG	4
209 #define	NCA_IO_DIRECT_SPLICE	5
210 #define	NCA_IO_DIRECT_TEE	6
211 #define	NCA_IO_DIRECT_FILE_FD	7
212 
213 /*
214  * NCA_HTTP_VERSION2 nca_io definition:
215  */
216 typedef struct nca_io2_s {
217 
218 	nca_version_t	version;	/* version number */
219 	nca_op_t	op;		/* type of operation */
220 	nca_tag_t	tag;		/* connect tag */
221 
222 	uint32_t	sid;		/* server instance id */
223 	uint64_t	ctag;		/* user cache tag */
224 
225 	uint64_t	tid;		/* caller's thread id */
226 	uint64_t	cid;		/* connection id */
227 
228 	uint8_t		more;		/* more chunks to follow */
229 	uint8_t		first;		/* first chunk for tag */
230 
231 	uint8_t		advisory;	/* ask before using cache */
232 	uint8_t		nocache;	/* don't cache */
233 
234 	uint8_t		preempt;	/* preempt subsequent upcall */
235 	uint8_t		direct_type;	/* direct specifier type */
236 
237 	uint8_t		shadow;		/* flag used by kernel when copyin */
238 	uint8_t		pad2;		/* padd to 32 bit align */
239 
240 	uint32_t	peer_len;	/* sockaddr of client */
241 	nca_offset_t	peer;		/* offset into meta data area */
242 
243 	uint32_t	local_len;	/* sockaddr of NCA server */
244 	nca_offset_t	local;		/* offset into meta data area */
245 
246 	uint32_t	data_len;	/* request/response data */
247 	nca_offset_t	data;		/* offset into meta data area */
248 
249 	uint32_t	direct_len;	/* direct data specifier */
250 	nca_offset_t	direct;		/* offset into meta data area */
251 
252 	uint32_t	trailer_len;	/* request/response trailer data */
253 	nca_offset_t	trailer;	/* offset into meta data area */
254 
255 	/*
256 	 * Following this structure is optional meta data, peer and local
257 	 * sockaddr, (header) data, direct data, and trailer data.
258 	 *
259 	 * All nca_offset_t's above are byte offsets from the begining of
260 	 * this structure. A meta data length specifier of zero indicates
261 	 * no meta data.
262 	 *
263 	 * Request (i.e. in-bound) data is specified by the data_len/data
264 	 * members only.
265 	 *
266 	 * Response (i.e. out-bound) data is specified by the data_len/data,
267 	 * direct_type/direct_len/direct, trailer_len/trailer members and is
268 	 * processed in-order.
269 	 *
270 	 * Note: sockaddr meta data are IPv4 addresses, future revisions
271 	 * of the NCA-to-HTTP-server protocol will support IPv6.  So, the
272 	 * length of the sockaddr meta data must be honored as it will be
273 	 * increased for future IPv6 support.
274 	 */
275 
276 } nca_io2_t;
277 
278 #define	DOWNCALLINFO_MAGIC	0x19121969
279 
280 typedef struct downcallinfo_s {
281 	uint32_t	dci_magic;
282 	nca_io2_t	*dci_iop;
283 	uio_t		*dci_uiop;
284 } downcallinfo_t;
285 
286 typedef enum {
287 	NCA_UNKNOWN,
288 	NCA_OPTIONS,
289 	NCA_GET,
290 	NCA_HEAD,
291 	NCA_POST,
292 	NCA_PUT,
293 	NCA_DELETE,
294 	NCA_TRACE,
295 
296 	NCA_RAW		/* Special case for active connections */
297 } nca_http_method_t;
298 
299 typedef enum {
300 	HS_OK = 200,
301 	HS_CREATED = 201,
302 	HS_ACCEPTED = 202,
303 	HS_PARTIAL_CONTENT = 206,
304 	HS_MOVED_PERMANENT = 301,
305 	HS_MOVED = 302,
306 	HS_NOT_MODIFIED = 304,
307 	HS_BAD_REQUEST = 400,
308 	HS_AUTH_REQUIRED = 401,
309 	HS_FORBIDDEN = 403,
310 	HS_NOT_FOUND = 404,
311 	HS_PRECONDITION_FAILED = 412,
312 	HS_SERVER_ERROR = 500,
313 	HS_NOT_IMPLEMENTED = 501,
314 	HS_SERVICE_UNAVAILABLE = 503,
315 	HS_CONNECTION_CLOSED = 1000
316 } nca_http_status_code;
317 
318 /* httpd (miss user space daemon) is attached to this door */
319 #define	MISS_DOOR_FILE	"/var/run/nca_httpd_1.door"
320 
321 /* httpd downcall door server name */
322 #define	DOWNCALL_DOOR_FILE	"/var/run/nca_httpd_1.down_door"
323 
324 #ifdef	__cplusplus
325 }
326 #endif
327 
328 #endif	/* _INET_NCADOORHDR_H */
329