xref: /titanic_41/usr/src/uts/common/rpc/xdr.h (revision 5e2c3ae0c70f6eb4a42ae670882aabac983cb5f1)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
22  * Use is subject to license terms.
23  *
24  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
25  */
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28 /*
29  * Portions of this source code were derived from Berkeley
30  * 4.3 BSD under license from the Regents of the University of
31  * California.
32  */
33 
34 /*
35  * xdr.h, External Data Representation Serialization Routines.
36  *
37  */
38 
39 #ifndef _RPC_XDR_H
40 #define	_RPC_XDR_H
41 
42 #include <sys/byteorder.h>	/* For all ntoh* and hton*() kind of macros */
43 #include <rpc/types.h>	/* For all ntoh* and hton*() kind of macros */
44 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
45 #include <stdio.h> /* defines FILE *, used in ANSI C function prototypes */
46 #else	/* _KERNEL */
47 #include <sys/stream.h>
48 #endif	/* _KERNEL */
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /*
55  * XDR provides a conventional way for converting between C data
56  * types and an external bit-string representation.  Library supplied
57  * routines provide for the conversion on built-in C data types.  These
58  * routines and utility routines defined here are used to help implement
59  * a type encode/decode routine for each user-defined type.
60  *
61  * Each data type provides a single procedure which takes two arguments:
62  *
63  *	bool_t
64  *	xdrproc(xdrs, argresp)
65  *		XDR *xdrs;
66  *		<type> *argresp;
67  *
68  * xdrs is an instance of a XDR handle, to which or from which the data
69  * type is to be converted.  argresp is a pointer to the structure to be
70  * converted.  The XDR handle contains an operation field which indicates
71  * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
72  *
73  * XDR_DECODE may allocate space if the pointer argresp is null.  This
74  * data can be freed with the XDR_FREE operation.
75  *
76  * We write only one procedure per data type to make it easy
77  * to keep the encode and decode procedures for a data type consistent.
78  * In many cases the same code performs all operations on a user defined type,
79  * because all the hard work is done in the component type routines.
80  * decode as a series of calls on the nested data types.
81  */
82 
83 /*
84  * Xdr operations.  XDR_ENCODE causes the type to be encoded into the
85  * stream.  XDR_DECODE causes the type to be extracted from the stream.
86  * XDR_FREE can be used to release the space allocated by an XDR_DECODE
87  * request.
88  */
89 enum xdr_op {
90 	XDR_ENCODE = 0,
91 	XDR_DECODE = 1,
92 	XDR_FREE = 2
93 };
94 
95 /*
96  * This is the number of bytes per unit of external data.
97  */
98 #define	BYTES_PER_XDR_UNIT	(4)
99 #define	RNDUP(x)  ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
100 		    * BYTES_PER_XDR_UNIT)
101 
102 /*
103  * The XDR handle.
104  * Contains operation which is being applied to the stream,
105  * an operations vector for the paticular implementation (e.g. see xdr_mem.c),
106  * and two private fields for the use of the particular impelementation.
107  *
108  * PSARC 2003/523 Contract Private Interface
109  * XDR
110  * Changes must be reviewed by Solaris File Sharing
111  * Changes must be communicated to contract-2003-523@sun.com
112  */
113 typedef struct XDR {
114 	enum xdr_op	x_op;	/* operation; fast additional param */
115 	struct xdr_ops *x_ops;
116 	caddr_t 	x_public; /* users' data */
117 	caddr_t		x_private; /* pointer to private data */
118 	caddr_t 	x_base;	/* private used for position info */
119 	int		x_handy; /* extra private word */
120 } XDR;
121 
122 /*
123  * PSARC 2003/523 Contract Private Interface
124  * xdr_ops
125  * Changes must be reviewed by Solaris File Sharing
126  * Changes must be communicated to contract-2003-523@sun.com
127  */
128 struct xdr_ops {
129 #ifdef __STDC__
130 #if !defined(_KERNEL)
131 		bool_t	(*x_getlong)(struct XDR *, long *);
132 		/* get a long from underlying stream */
133 		bool_t	(*x_putlong)(struct XDR *, long *);
134 		/* put a long to " */
135 #endif /* KERNEL */
136 		bool_t	(*x_getbytes)(struct XDR *, caddr_t, int);
137 		/* get some bytes from " */
138 		bool_t	(*x_putbytes)(struct XDR *, caddr_t, int);
139 		/* put some bytes to " */
140 		uint_t	(*x_getpostn)(struct XDR *);
141 		/* returns bytes off from beginning */
142 		bool_t  (*x_setpostn)(struct XDR *, uint_t);
143 		/* lets you reposition the stream */
144 		rpc_inline_t *(*x_inline)(struct XDR *, int);
145 		/* buf quick ptr to buffered data */
146 		void	(*x_destroy)(struct XDR *);
147 		/* free privates of this xdr_stream */
148 		bool_t	(*x_control)(struct XDR *, int, void *);
149 #if defined(_LP64) || defined(_KERNEL)
150 		bool_t	(*x_getint32)(struct XDR *, int32_t *);
151 		/* get a int from underlying stream */
152 		bool_t	(*x_putint32)(struct XDR *, int32_t *);
153 		/* put an int to " */
154 #endif /* _LP64 || _KERNEL */
155 #else
156 #if !defined(_KERNEL)
157 		bool_t	(*x_getlong)();	/* get a long from underlying stream */
158 		bool_t	(*x_putlong)();	/* put a long to " */
159 #endif /* KERNEL */
160 		bool_t	(*x_getbytes)(); /* get some bytes from " */
161 		bool_t	(*x_putbytes)(); /* put some bytes to " */
162 		uint_t	(*x_getpostn)(); /* returns bytes off from beginning */
163 		bool_t  (*x_setpostn)(); /* lets you reposition the stream */
164 		rpc_inline_t *(*x_inline)();
165 				/* buf quick ptr to buffered data */
166 		void	(*x_destroy)();	/* free privates of this xdr_stream */
167 		bool_t	(*x_control)();
168 #if defined(_LP64) || defined(_KERNEL)
169 		bool_t	(*x_getint32)();
170 		bool_t	(*x_putint32)();
171 #endif /* _LP64 || defined(_KERNEL) */
172 #endif
173 };
174 
175 /*
176  * Operations defined on a XDR handle
177  *
178  * XDR		*xdrs;
179  * long		*longp;
180  * caddr_t	 addr;
181  * uint_t	 len;
182  * uint_t	 pos;
183  */
184 #if !defined(_KERNEL)
185 #define	XDR_GETLONG(xdrs, longp)			\
186 	(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
187 #define	xdr_getlong(xdrs, longp)			\
188 	(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
189 
190 #define	XDR_PUTLONG(xdrs, longp)			\
191 	(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
192 #define	xdr_putlong(xdrs, longp)			\
193 	(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
194 #endif /* KERNEL */
195 
196 
197 #if !defined(_LP64) && !defined(_KERNEL)
198 
199 /*
200  * For binary compatability on ILP32 we do not change the shape
201  * of the XDR structure and the GET/PUTINT32 functions just use
202  * the get/putlong vectors which operate on identically-sized
203  * units of data.
204  */
205 
206 #define	XDR_GETINT32(xdrs, int32p)			\
207 	(*(xdrs)->x_ops->x_getlong)(xdrs, (long *)int32p)
208 #define	xdr_getint32(xdrs, int32p)			\
209 	(*(xdrs)->x_ops->x_getlong)(xdrs, (long *)int32p)
210 
211 #define	XDR_PUTINT32(xdrs, int32p)			\
212 	(*(xdrs)->x_ops->x_putlong)(xdrs, (long *)int32p)
213 #define	xdr_putint32(xdrs, int32p)			\
214 	(*(xdrs)->x_ops->x_putlong)(xdrs, (long *)int32p)
215 
216 #else /* !_LP64 && !_KERNEL */
217 
218 #define	XDR_GETINT32(xdrs, int32p)			\
219 	(*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
220 #define	xdr_getint32(xdrs, int32p)			\
221 	(*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
222 
223 #define	XDR_PUTINT32(xdrs, int32p)			\
224 	(*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
225 #define	xdr_putint32(xdrs, int32p)			\
226 	(*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
227 
228 #endif /* !_LP64 && !_KERNEL */
229 
230 #define	XDR_GETBYTES(xdrs, addr, len)			\
231 	(*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
232 #define	xdr_getbytes(xdrs, addr, len)			\
233 	(*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
234 
235 #define	XDR_PUTBYTES(xdrs, addr, len)			\
236 	(*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
237 #define	xdr_putbytes(xdrs, addr, len)			\
238 	(*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
239 
240 #define	XDR_GETPOS(xdrs)				\
241 	(*(xdrs)->x_ops->x_getpostn)(xdrs)
242 #define	xdr_getpos(xdrs)				\
243 	(*(xdrs)->x_ops->x_getpostn)(xdrs)
244 
245 #define	XDR_SETPOS(xdrs, pos)				\
246 	(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
247 #define	xdr_setpos(xdrs, pos)				\
248 	(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
249 
250 #define	XDR_INLINE(xdrs, len)				\
251 	(*(xdrs)->x_ops->x_inline)(xdrs, len)
252 #define	xdr_inline(xdrs, len)				\
253 	(*(xdrs)->x_ops->x_inline)(xdrs, len)
254 
255 #define	XDR_DESTROY(xdrs)				\
256 	(*(xdrs)->x_ops->x_destroy)(xdrs)
257 #define	xdr_destroy(xdrs)				\
258 	(*(xdrs)->x_ops->x_destroy)(xdrs)
259 
260 #define	XDR_CONTROL(xdrs, req, op)			\
261 	(*(xdrs)->x_ops->x_control)(xdrs, req, op)
262 #define	xdr_control(xdrs, req, op)			\
263 	(*(xdrs)->x_ops->x_control)(xdrs, req, op)
264 
265 /*
266  * Support struct for discriminated unions.
267  * You create an array of xdrdiscrim structures, terminated with
268  * a entry with a null procedure pointer.  The xdr_union routine gets
269  * the discriminant value and then searches the array of structures
270  * for a matching value.  If a match is found the associated xdr routine
271  * is called to handle that part of the union.  If there is
272  * no match, then a default routine may be called.
273  * If there is no match and no default routine it is an error.
274  */
275 
276 
277 /*
278  * A xdrproc_t exists for each data type which is to be encoded or decoded.
279  *
280  * The second argument to the xdrproc_t is a pointer to an opaque pointer.
281  * The opaque pointer generally points to a structure of the data type
282  * to be decoded.  If this pointer is 0, then the type routines should
283  * allocate dynamic storage of the appropriate size and return it.
284  * bool_t	(*xdrproc_t)(XDR *, void *);
285  */
286 #ifdef __cplusplus
287 typedef bool_t (*xdrproc_t)(XDR *, void *);
288 #else
289 #ifdef __STDC__
290 typedef bool_t (*xdrproc_t)(); /* For Backward compatibility */
291 #else
292 typedef	bool_t (*xdrproc_t)();
293 #endif
294 #endif
295 
296 #define	NULL_xdrproc_t ((xdrproc_t)0)
297 
298 #if defined(_LP64) || defined(_I32LPx)
299 #define	xdr_rpcvers(xdrs, versp)	xdr_u_int(xdrs, versp)
300 #define	xdr_rpcprog(xdrs, progp)	xdr_u_int(xdrs, progp)
301 #define	xdr_rpcproc(xdrs, procp)	xdr_u_int(xdrs, procp)
302 #define	xdr_rpcprot(xdrs, protp)	xdr_u_int(xdrs, protp)
303 #define	xdr_rpcport(xdrs, portp)	xdr_u_int(xdrs, portp)
304 #else
305 #define	xdr_rpcvers(xdrs, versp)	xdr_u_long(xdrs, versp)
306 #define	xdr_rpcprog(xdrs, progp)	xdr_u_long(xdrs, progp)
307 #define	xdr_rpcproc(xdrs, procp)	xdr_u_long(xdrs, procp)
308 #define	xdr_rpcprot(xdrs, protp)	xdr_u_long(xdrs, protp)
309 #define	xdr_rpcport(xdrs, portp)	xdr_u_long(xdrs, portp)
310 #endif
311 
312 struct xdr_discrim {
313 	int	value;
314 	xdrproc_t proc;
315 };
316 
317 /*
318  * In-line routines for fast encode/decode of primitve data types.
319  * Caveat emptor: these use single memory cycles to get the
320  * data from the underlying buffer, and will fail to operate
321  * properly if the data is not aligned.  The standard way to use these
322  * is to say:
323  *	if ((buf = XDR_INLINE(xdrs, count)) == NULL)
324  *		return (FALSE);
325  *	<<< macro calls >>>
326  * where ``count'' is the number of bytes of data occupied
327  * by the primitive data types.
328  *
329  * N.B. and frozen for all time: each data type here uses 4 bytes
330  * of external representation.
331  */
332 
333 #define	IXDR_GET_INT32(buf)		((int32_t)ntohl((uint32_t)*(buf)++))
334 #define	IXDR_PUT_INT32(buf, v)		(*(buf)++ = (int32_t)htonl((uint32_t)v))
335 #define	IXDR_GET_U_INT32(buf)		((uint32_t)IXDR_GET_INT32(buf))
336 #define	IXDR_PUT_U_INT32(buf, v)	IXDR_PUT_INT32((buf), ((int32_t)(v)))
337 
338 #if !defined(_KERNEL) && !defined(_LP64)
339 
340 #define	IXDR_GET_LONG(buf)		((long)ntohl((ulong_t)*(buf)++))
341 #define	IXDR_PUT_LONG(buf, v)		(*(buf)++ = (long)htonl((ulong_t)v))
342 #define	IXDR_GET_U_LONG(buf)		((ulong_t)IXDR_GET_LONG(buf))
343 #define	IXDR_PUT_U_LONG(buf, v)		IXDR_PUT_LONG((buf), ((long)(v)))
344 
345 #define	IXDR_GET_BOOL(buf)		((bool_t)IXDR_GET_LONG(buf))
346 #define	IXDR_GET_ENUM(buf, t)		((t)IXDR_GET_LONG(buf))
347 #define	IXDR_GET_SHORT(buf)		((short)IXDR_GET_LONG(buf))
348 #define	IXDR_GET_U_SHORT(buf)		((ushort_t)IXDR_GET_LONG(buf))
349 
350 #define	IXDR_PUT_BOOL(buf, v)		IXDR_PUT_LONG((buf), ((long)(v)))
351 #define	IXDR_PUT_ENUM(buf, v)		IXDR_PUT_LONG((buf), ((long)(v)))
352 #define	IXDR_PUT_SHORT(buf, v)		IXDR_PUT_LONG((buf), ((long)(v)))
353 #define	IXDR_PUT_U_SHORT(buf, v)	IXDR_PUT_LONG((buf), ((long)(v)))
354 
355 #else
356 
357 #define	IXDR_GET_BOOL(buf)		((bool_t)IXDR_GET_INT32(buf))
358 #define	IXDR_GET_ENUM(buf, t)		((t)IXDR_GET_INT32(buf))
359 #define	IXDR_GET_SHORT(buf)		((short)IXDR_GET_INT32(buf))
360 #define	IXDR_GET_U_SHORT(buf)		((ushort_t)IXDR_GET_INT32(buf))
361 
362 #define	IXDR_PUT_BOOL(buf, v)		IXDR_PUT_INT32((buf), ((int)(v)))
363 #define	IXDR_PUT_ENUM(buf, v)		IXDR_PUT_INT32((buf), ((int)(v)))
364 #define	IXDR_PUT_SHORT(buf, v)		IXDR_PUT_INT32((buf), ((int)(v)))
365 #define	IXDR_PUT_U_SHORT(buf, v)	IXDR_PUT_INT32((buf), ((int)(v)))
366 
367 #endif
368 
369 #ifndef _LITTLE_ENDIAN
370 #define	IXDR_GET_HYPER(buf, v)	{ \
371 			*((int32_t *)(&v)) = ntohl(*(uint32_t *)buf++); \
372 			*((int32_t *)(((char *)&v) + BYTES_PER_XDR_UNIT)) \
373 			= ntohl(*(uint32_t *)buf++); \
374 			}
375 #define	IXDR_PUT_HYPER(buf, v)	{ \
376 			*(buf)++ = (int32_t)htonl(*(uint32_t *) \
377 				((char *)&v)); \
378 			*(buf)++ = \
379 				(int32_t)htonl(*(uint32_t *)(((char *)&v) \
380 				+ BYTES_PER_XDR_UNIT)); \
381 			}
382 #else
383 
384 #define	IXDR_GET_HYPER(buf, v)	{ \
385 			*((int32_t *)(((char *)&v) + \
386 				BYTES_PER_XDR_UNIT)) \
387 				= ntohl(*(uint32_t *)buf++); \
388 			*((int32_t *)(&v)) = \
389 				ntohl(*(uint32_t *)buf++); \
390 			}
391 
392 #define	IXDR_PUT_HYPER(buf, v)	{ \
393 			*(buf)++ = \
394 				(int32_t)htonl(*(uint32_t *)(((char *)&v) + \
395 				BYTES_PER_XDR_UNIT)); \
396 			*(buf)++ = \
397 				(int32_t)htonl(*(uint32_t *)((char *)&v)); \
398 			}
399 #endif
400 #define	IXDR_GET_U_HYPER(buf, v)	IXDR_GET_HYPER(buf, v)
401 #define	IXDR_PUT_U_HYPER(buf, v)	IXDR_PUT_HYPER(buf, v)
402 
403 
404 /*
405  * These are the "generic" xdr routines.
406  */
407 #ifdef __STDC__
408 extern bool_t	xdr_void(void);
409 extern bool_t	xdr_int(XDR *, int *);
410 extern bool_t	xdr_u_int(XDR *, uint_t *);
411 extern bool_t	xdr_long(XDR *, long *);
412 extern bool_t	xdr_u_long(XDR *, ulong_t *);
413 extern bool_t	xdr_short(XDR *, short *);
414 extern bool_t	xdr_u_short(XDR *, ushort_t *);
415 extern bool_t	xdr_bool(XDR *, bool_t *);
416 extern bool_t	xdr_enum(XDR *, enum_t *);
417 extern bool_t	xdr_array(XDR *, caddr_t *, uint_t *, const uint_t,
418 		    const uint_t, const xdrproc_t);
419 extern bool_t	xdr_bytes(XDR *, char **, uint_t *, const uint_t);
420 extern bool_t	xdr_opaque(XDR *, caddr_t, const uint_t);
421 extern bool_t	xdr_string(XDR *, char **, const uint_t);
422 extern bool_t	xdr_union(XDR *, enum_t *, char *,
423 		    const struct xdr_discrim *, const xdrproc_t);
424 extern bool_t	xdr_vector(XDR *, char *, const uint_t, const uint_t,
425     const xdrproc_t);
426 extern unsigned int  xdr_sizeof(xdrproc_t, void *);
427 
428 extern bool_t   xdr_hyper(XDR *, longlong_t *);
429 extern bool_t   xdr_longlong_t(XDR *, longlong_t *);
430 extern bool_t   xdr_u_hyper(XDR *, u_longlong_t *);
431 extern bool_t   xdr_u_longlong_t(XDR *, u_longlong_t *);
432 
433 extern bool_t	xdr_char(XDR *, char *);
434 extern bool_t	xdr_u_char(XDR *, uchar_t *);
435 extern bool_t	xdr_wrapstring(XDR *, char **);
436 extern bool_t	xdr_reference(XDR *, caddr_t *, uint_t, const xdrproc_t);
437 extern bool_t	xdr_pointer(XDR *, char **, uint_t, const xdrproc_t);
438 extern void	xdr_free(xdrproc_t, char *);
439 extern bool_t	xdr_time_t(XDR *, time_t *);
440 
441 extern bool_t	xdr_int8_t(XDR *, int8_t *);
442 extern bool_t	xdr_uint8_t(XDR *, uint8_t *);
443 extern bool_t	xdr_int16_t(XDR *, int16_t *);
444 extern bool_t	xdr_uint16_t(XDR *, uint16_t *);
445 extern bool_t	xdr_int32_t(XDR *, int32_t *);
446 extern bool_t	xdr_uint32_t(XDR *, uint32_t *);
447 #if defined(_INT64_TYPE)
448 extern bool_t	xdr_int64_t(XDR *, int64_t *);
449 extern bool_t	xdr_uint64_t(XDR *, uint64_t *);
450 #endif
451 
452 #ifndef _KERNEL
453 extern bool_t	xdr_float(XDR *, float *);
454 extern bool_t	xdr_double(XDR *, double *);
455 extern bool_t	xdr_quadruple(XDR *, long double *);
456 #endif /* !_KERNEL */
457 #else
458 extern bool_t	xdr_void();
459 extern bool_t	xdr_int();
460 extern bool_t	xdr_u_int();
461 extern bool_t	xdr_long();
462 extern bool_t	xdr_u_long();
463 extern bool_t	xdr_short();
464 extern bool_t	xdr_u_short();
465 extern bool_t	xdr_bool();
466 extern bool_t	xdr_enum();
467 extern bool_t	xdr_array();
468 extern bool_t	xdr_bytes();
469 extern bool_t	xdr_opaque();
470 extern bool_t	xdr_string();
471 extern bool_t	xdr_union();
472 extern bool_t	xdr_vector();
473 
474 extern bool_t   xdr_hyper();
475 extern bool_t   xdr_longlong_t();
476 extern bool_t   xdr_u_hyper();
477 extern bool_t   xdr_u_longlong_t();
478 extern bool_t	xdr_char();
479 extern bool_t	xdr_u_char();
480 extern bool_t	xdr_reference();
481 extern bool_t	xdr_pointer();
482 extern void	xdr_free();
483 extern bool_t	xdr_wrapstring();
484 extern bool_t	xdr_time_t();
485 
486 extern bool_t	xdr_int8_t();
487 extern bool_t	xdr_uint8_t();
488 extern bool_t	xdr_int16_t();
489 extern bool_t	xdr_uint16_t();
490 extern bool_t	xdr_int32_t();
491 extern bool_t	xdr_uint32_t();
492 #if defined(_INT64_TYPE)
493 extern bool_t	xdr_int64_t();
494 extern bool_t	xdr_uint64_t();
495 #endif
496 
497 #ifndef _KERNEL
498 extern bool_t	xdr_float();
499 extern bool_t	xdr_double();
500 extern bool_t   xdr_quadruple();
501 #endif /* !_KERNEL */
502 #endif
503 
504 /*
505  * Common opaque bytes objects used by many rpc protocols;
506  * declared here due to commonality.
507  */
508 #define	MAX_NETOBJ_SZ 1024
509 struct netobj {
510 	uint_t	n_len;
511 	char	*n_bytes;
512 };
513 typedef struct netobj netobj;
514 
515 #ifdef __STDC__
516 extern bool_t   xdr_netobj(XDR *, netobj *);
517 #else
518 extern bool_t   xdr_netobj();
519 #endif
520 
521 /*
522  * These are XDR control operators
523  */
524 
525 #define	XDR_GET_BYTES_AVAIL 1
526 
527 struct xdr_bytesrec {
528 	bool_t xc_is_last_record;
529 	size_t xc_num_avail;
530 };
531 
532 typedef struct xdr_bytesrec xdr_bytesrec;
533 
534 /*
535  * These are the request arguments to XDR_CONTROL.
536  *
537  * XDR_PEEK - returns the contents of the next XDR unit on the XDR stream.
538  * XDR_SKIPBYTES - skips the next N bytes in the XDR stream.
539  * XDR_RDMAGET - for xdr implementation over RDMA, gets private flags from
540  *		 the XDR stream being moved over RDMA
541  * XDR_RDMANOCHUNK - for xdr implementaion over RDMA, sets private flags in
542  *                   the XDR stream moving over RDMA.
543  */
544 #ifdef _KERNEL
545 #define	XDR_PEEK		2
546 #define	XDR_SKIPBYTES		3
547 #define	XDR_RDMA_GET_FLAGS	4
548 #define	XDR_RDMA_SET_FLAGS	5
549 #define	XDR_RDMA_ADD_CHUNK	6
550 #define	XDR_RDMA_GET_CHUNK_LEN	7
551 #define	XDR_RDMA_SET_WLIST	8
552 #define	XDR_RDMA_GET_WLIST	9
553 #define	XDR_RDMA_GET_WCINFO	10
554 #define	XDR_RDMA_GET_RLIST	11
555 #endif
556 
557 /*
558  * These are the public routines for the various implementations of
559  * xdr streams.
560  */
561 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
562 #ifdef __STDC__
563 extern void   xdrmem_create(XDR *, const caddr_t, const uint_t, const enum
564 xdr_op);
565 	/* XDR using memory buffers */
566 extern void   xdrstdio_create(XDR *, FILE *, const enum xdr_op);
567 /* XDR using stdio library */
568 extern void   xdrrec_create(XDR *, const uint_t, const uint_t, const caddr_t,
569 int (*) (void *, caddr_t, int), int (*) (void *, caddr_t, int));
570 /* XDR pseudo records for tcp */
571 extern bool_t xdrrec_endofrecord(XDR *, bool_t);
572 /* make end of xdr record */
573 extern bool_t xdrrec_skiprecord(XDR *);
574 /* move to beginning of next record */
575 extern bool_t xdrrec_eof(XDR *);
576 extern uint_t xdrrec_readbytes(XDR *, caddr_t, uint_t);
577 /* true if no more input */
578 #else
579 extern void   xdrmem_create();
580 extern void   xdrstdio_create();
581 extern void   xdrrec_create();
582 extern bool_t xdrrec_endofrecord();
583 extern bool_t xdrrec_skiprecord();
584 extern bool_t xdrrec_eof();
585 extern uint_t xdrrec_readbytes();
586 #endif
587 #else
588 
589 #define	DLEN(mp) (mp->b_cont ? msgdsize(mp) : (mp->b_wptr - mp->b_rptr))
590 
591 extern void	xdrmem_create(XDR *, caddr_t, uint_t, enum xdr_op);
592 extern void	xdrmblk_init(XDR *, mblk_t *, enum xdr_op, int);
593 extern bool_t	xdrmblk_getmblk(XDR *, mblk_t **, uint_t *);
594 extern bool_t	xdrmblk_putmblk(XDR *, mblk_t *, uint_t);
595 extern struct xdr_ops xdrmblk_ops;
596 extern struct xdr_ops xdrrdmablk_ops;
597 extern struct xdr_ops xdrrdma_ops;
598 
599 struct rpc_msg;
600 extern bool_t	xdr_callmsg(XDR *, struct rpc_msg *);
601 extern bool_t	xdr_replymsg_body(XDR *, struct rpc_msg *);
602 extern bool_t	xdr_replymsg_hdr(XDR *, struct rpc_msg *);
603 
604 #endif /* !_KERNEL */
605 
606 #ifdef __cplusplus
607 }
608 #endif
609 
610 #endif	/* !_RPC_XDR_H */
611