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