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