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