1/* 2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 * unrestricted use provided that this legend is included on all tape 4 * media and as a part of the software program in whole or part. Users 5 * may copy or modify Sun RPC without charge, but are not authorized 6 * to license or distribute it to anyone else except as part of a product or 7 * program developed by the user. 8 * 9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 * 13 * Sun RPC is provided with no support and without any obligation on the 14 * part of Sun Microsystems, Inc. to assist in its use, correction, 15 * modification or enhancement. 16 * 17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 * OR ANY PART THEREOF. 20 * 21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 * or profits or other special, indirect and consequential damages, even if 23 * Sun has been advised of the possibility of such damages. 24 * 25 * Sun Microsystems, Inc. 26 * 2550 Garcia Avenue 27 * Mountain View, California 94043 28 */ 29 30/* fixincludes should not add extern "C" to this file */ 31/* 32 * Rpc additions to <sys/types.h> 33 */ 34 35#ifndef RPCXDRTYPES_H 36#define RPCXDRTYPES_H 37 38/* 39 * XDR provides a conventional way for converting between C data 40 * types and an external bit-string representation. Library supplied 41 * routines provide for the conversion on built-in C data types. These 42 * routines and utility routines defined here are used to help implement 43 * a type encode/decode routine for each user-defined type. 44 * 45 * Each data type provides a single procedure which takes two arguments: 46 * 47 * bool_t 48 * xdrproc(xdrs, argresp) 49 * XDR *xdrs; 50 * <type> *argresp; 51 * 52 * xdrs is an instance of a XDR handle, to which or from which the data 53 * type is to be converted. argresp is a pointer to the structure to be 54 * converted. The XDR handle contains an operation field which indicates 55 * which of the operations (ENCODE, DECODE * or FREE) is to be performed. 56 * 57 * XDR_DECODE may allocate space if the pointer argresp is null. This 58 * data can be freed with the XDR_FREE operation. 59 * 60 * We write only one procedure per data type to make it easy 61 * to keep the encode and decode procedures for a data type consistent. 62 * In many cases the same code performs all operations on a user defined type, 63 * because all the hard work is done in the component type routines. 64 * decode as a series of calls on the nested data types. 65 */ 66 67#ifdef __cplusplus 68extern "C" { 69#endif 70 71/* The version of ONCRPC supported */ 72#define RPC_MSG_VERSION ((u_long) 2) 73 74#include <inttypes.h> 75#include <string.h> 76#include <pthread.h> 77 78typedef int bool_t; /* This has to be a long, as it is used for XDR boolean too, which is a 4-byte value */ 79typedef unsigned long rpcprog_t; 80typedef unsigned long rpcproc_t; 81typedef unsigned long rpcvers_t; 82typedef unsigned long rpcprot_t; 83typedef uint64_t uint64; 84typedef uint32_t uint32; 85typedef uint16_t uint16; 86typedef uint8_t uint8; 87typedef int32_t int32; 88typedef int16_t int16; 89typedef int8_t int8; 90typedef int32_t enum_t; 91typedef int64_t quad_t; 92typedef uint64_t u_quad_t; 93//typedef uint16_t u_short; /* defined in kernel_headers */ 94#define TRUE 1 95#define FALSE 0 96static inline void* mem_alloc(size_t size) { return malloc(size); } 97static inline void mem_free(void* ptr) { free(ptr); } 98 99/* 100 * Xdr operations. XDR_ENCODE causes the type to be encoded into the 101 * stream. XDR_DECODE causes the type to be extracted from the stream. 102 * XDR_FREE can be used to release the space allocated by an XDR_DECODE 103 * request. 104 */ 105enum xdr_op { 106 XDR_ENCODE = 0, 107 XDR_DECODE = 1, 108 XDR_FREE = 2 109}; 110 111/* 112 * This is the number of bytes per unit of external data. 113 */ 114#define BYTES_PER_XDR_UNIT (4) 115 116/* 117 * The XDR handle. 118 * Contains operation which is being applied to the stream, 119 * an operations vector for the particular implementation (e.g. see xdr_mem.c), 120 * and two private fields for the use of the particular implementation. 121 */ 122typedef struct xdr_struct XDR; 123/* 124 * A xdrproc_t exists for each data type which is to be encoded or decoded. 125 * 126 * The second argument to the xdrproc_t is a pointer to an opaque pointer. 127 * The opaque pointer generally points to a structure of the data type 128 * to be decoded. If this pointer is 0, then the type routines should 129 * allocate dynamic storage of the appropriate size and return it. 130 * bool_t (*xdrproc_t)(XDR *, caddr_t *); 131 */ 132typedef bool_t (*xdrproc_t) (XDR *, void *,...); 133 134 135#define ONCRPC_CONTROL_GET_MTU (1) 136#define ONCRPC_CONTROL_GET_TX_QUOTA (2) 137#define ONCRPC_CONTROL_GET_RX_BUFFER_SIZE (3) 138#define ONCRPC_CONTROL_REGISTER_SERVER (4) 139#define ONCRPC_CONTROL_UNREGISTER_SERVER (5) 140#define ONCRPC_CONTROL_GET_DEST (6) 141#define ONCRPC_CONTROL_OPEN_XPORT (7) 142#define ONCRPC_CONTROL_CLOSE_XPORT (8) 143#define ONCRPC_CONTROL_SET_DEST (9) 144#define ONCRPC_CONTROL_GET_SOURCE_ADDR (10) 145 146typedef struct oncrpc_prog_ver_struct 147{ 148 rpcprog_t prog; 149 rpcvers_t ver; 150 void (*dispatch)(); 151} oncrpc_prog_ver_type; 152 153typedef uint64 oncrpc_addr_type; 154 155typedef struct { 156 oncrpc_addr_type addr; 157 oncrpc_prog_ver_type prog_ver; 158} oncrpc_control_get_dest_type; 159 160typedef struct { 161 oncrpc_addr_type addr; 162} oncrpc_control_get_source_type; 163 164typedef struct{ 165 oncrpc_prog_ver_type prog_ver; 166} oncrpc_control_register_server_type; 167 168typedef struct{ 169 oncrpc_prog_ver_type prog_ver; 170} oncrpc_control_unregister_server_type; 171 172typedef struct{ 173 oncrpc_addr_type dest; 174} oncrpc_control_set_dest_type; 175 176typedef struct{ 177 unsigned int xp; 178 unsigned int port; 179} oncrpc_control_open_xport_type; 180 181#define NULL_xdrproc_t ((xdrproc_t)0) 182 183/* 184 * Support struct for discriminated unions. 185 * You create an array of xdrdiscrim structures, terminated with 186 * a entry with a null procedure pointer. The xdr_union routine gets 187 * the discriminant value and then searches the array of structures 188 * for a matching value. If a match is found the associated xdr routine 189 * is called to handle that part of the union. If there is 190 * no match, then a default routine may be called. 191 * If there is no match and no default routine it is an error. 192 */ 193struct xdr_discrim 194{ 195 int value; 196 xdrproc_t proc; 197}; 198 199/* Message enums */ 200typedef enum { 201 RPC_MSG_CALL=0, 202 RPC_MSG_REPLY=1, 203 RPC_MSG_UNDEF = 2, 204} rpc_msg_e_type; 205 206typedef enum { 207 RPC_MSG_ACCEPTED=0, 208 RPC_MSG_DENIED=1 209} rpc_reply_stat_e_type; 210 211typedef enum { 212 RPC_ACCEPT_SUCCESS = 0, 213 RPC_PROG_UNAVAIL = 1, 214 RPC_PROG_MISMATCH = 2, 215 RPC_PROC_UNAVAIL = 3, 216 RPC_GARBAGE_ARGS = 4, 217 RPC_SYSTEM_ERR = 5, 218 RPC_PROG_LOCKED = 6 219} rpc_accept_stat_e_type; 220 221typedef enum { 222 RPC_MISMATCH=0, 223 RPC_AUTH_ERROR=1 224} rpc_reject_stat_e_type ; 225 226/* Auth types */ 227 228/* 229 * Status returned from authentication check 230 */ 231typedef enum { 232 AUTH_OK=0, 233 /* 234 * failed at remote end 235 */ 236 AUTH_BADCRED=1, /* bogus credentials (seal broken) */ 237 AUTH_REJECTEDCRED=2, /* client should begin new session */ 238 AUTH_BADVERF=3, /* bogus verifier (seal broken) */ 239 AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */ 240 AUTH_TOOWEAK=5, /* rejected due to security reasons */ 241 /* 242 * failed locally 243 */ 244 AUTH_INVALIDRESP=6, /* bogus response verifier */ 245 AUTH_FAILED=7 /* some unknown reason */ 246} auth_stat; 247 248typedef enum { 249 AUTH_NONE =0, /* no authentication */ 250 AUTH_NULL =0, /* backward compatibility */ 251 AUTH_SYS =1, /* unix style (uid, gids) */ 252 AUTH_UNIX =1, 253 AUTH_SHORT =2 /* short hand unix style */ 254} oncrpc_auth_types; 255/* 256 * Authentication info. Opaque to client. 257 */ 258typedef struct opaque_auth { 259 oncrpc_auth_types oa_flavor; /* flavor of auth */ 260 caddr_t oa_base; /* address of more auth stuff */ 261 u_int oa_length; /* not to exceed MAX_AUTH_BYTES */ 262} opaque_auth; 263 264#define MAX_AUTH_BYTES 400 265#define MAXNETNAMELEN 255 /* maximum length of network user's name */ 266 267/* Error types */ 268/* 269 * Reply header to an rpc request that was accepted by the server. 270 * Note: there could be an error even though the request was 271 * accepted. 272 */ 273struct rpc_accepted_reply_header 274{ 275 opaque_auth verf; 276 rpc_accept_stat_e_type stat; 277 union 278 { 279 struct 280 { 281 uint32 low; 282 uint32 high; 283 } versions; 284 } u; 285}; 286 287/* 288 * Reply to an rpc request that was denied by the server. 289 */ 290struct rpc_denied_reply 291{ 292 rpc_reject_stat_e_type stat; 293 union 294 { 295 struct 296 { 297 uint32 low; 298 uint32 high; 299 } versions; 300 auth_stat why; /* why authentication did not work */ 301 } u; 302}; 303 304/* 305 * RPC reply header structure. The reply header contains error codes in 306 * case of errors in the server side or the RPC call being rejected. 307 */ 308typedef struct rpc_reply_header 309{ 310 rpc_reply_stat_e_type stat; 311 union 312 { 313 struct rpc_accepted_reply_header ar; 314 struct rpc_denied_reply dr; 315 } u; 316} rpc_reply_header; 317 318/* XDR memory wrapper structure */ 319typedef struct oncrpcxdr_mem_struct { 320 struct oncrpcxdr_mem_struct *next; 321 322#ifdef IMAGE_APPS_PROC 323 /* make structure size 8-bytes so we 324 keep 8-byte alignment */ 325 uint32 padding; 326#endif 327} oncrpcxdr_mem_s_type; 328 329// TODO - keep XPORT objects on queue to help track down memory leaks 330 331/*=========================================================================== 332 Defining the XPORT structure 333 ===========================================================================*/ 334 335#define XPORT_FLAG_XPORT_ALLOCED 0x0001 336 337/*=========================================================================== 338 Defining the XDR structure 339 ===========================================================================*/ 340 341typedef struct xdr_struct xdr_s_type; 342 343/* Call back definition for non-blocking RPC calls */ 344typedef void (*rpc_reply_cb_type)(xdr_s_type *xdr, void *data); 345 346/* Entry points that must be provided by xdr */ 347struct xdr_ops_struct { 348 /* Transport control functions */ 349 void (*xdr_destroy) (xdr_s_type *xdr); 350 bool_t (*xdr_control) (xdr_s_type *xdr, int request, void *info); 351 352 /* Incoming message control functions */ 353 bool_t (*read) (xdr_s_type *xdr); 354 bool_t (*msg_done) (xdr_s_type *xdr); 355 356 /* Outgoing message control functions */ 357 bool_t (*msg_start) (xdr_s_type *xdr, rpc_msg_e_type rpc_msg_type); 358 bool_t (*msg_abort) (xdr_s_type *xdr); 359 bool_t (*msg_send) (xdr_s_type *xdr); 360 361 /* Message data functions */ 362 bool_t (*send_int8) (xdr_s_type *xdr, const int8 *value); 363 bool_t (*send_uint8) (xdr_s_type *xdr, const uint8 *value); 364 bool_t (*send_int16) (xdr_s_type *xdr, const int16 *value); 365 bool_t (*send_uint16) (xdr_s_type *xdr, const uint16 *value); 366 bool_t (*send_int32) (xdr_s_type *xdr, const int32 *value); 367 bool_t (*send_uint32) (xdr_s_type *xdr, const uint32 *value); 368 bool_t (*send_bytes) (xdr_s_type *xdr, const uint8 *buf, uint32 len); 369 370 bool_t (*recv_int8) (xdr_s_type *xdr, int8 *value); 371 bool_t (*recv_uint8) (xdr_s_type *xdr, uint8 *value); 372 bool_t (*recv_int16) (xdr_s_type *xdr, int16 *value); 373 bool_t (*recv_uint16) (xdr_s_type *xdr, uint16 *value); 374 bool_t (*recv_int32) (xdr_s_type *xdr, int32 *value); 375 bool_t (*recv_uint32) (xdr_s_type *xdr, uint32 *value); 376 bool_t (*recv_bytes) (xdr_s_type *xdr, uint8 *buf, uint32 len); 377}; 378 379typedef struct xdr_ops_struct xdr_ops_s_type; 380 381/*=========================================================================== 382 XDR structure definition - provides a generic interface to each 383 supported transport. The xdr structure is used both for clients and 384 for servers. 385 ===========================================================================*/ 386 387#define RPCROUTER_MSGSIZE_MAX (2048) 388 389struct xdr_struct { 390 const xdr_ops_s_type *xops; 391 enum xdr_op x_op; /* used for ENCODE and DECODE */ 392 uint32 x_prog; /* program number */ 393 uint32 x_vers; /* program version */ 394 uint32 x_proc; /* for debug output */ 395 396 opaque_auth verf; /* verf to send back */ 397 uint32 xid; 398 int fd; 399 int is_client; 400 401 /* RPC-call message (if XDR is a client) or RPC-reply message (if 402 XDR is a server). */ 403 404 uint8 out_msg[RPCROUTER_MSGSIZE_MAX]; 405 int out_next; 406 407 /* Reply message or incoming-call message. For a client XDR, this 408 buffer always contains the reply received in response to an RPC 409 call. For a server XDR, this buffer always contains an incoming 410 RPC call. 411 */ 412 uint8 in_msg[RPCROUTER_MSGSIZE_MAX]; 413 int in_next; 414 int in_len; 415}; 416 417// Transport flag definitions 418#define XDR_FLAG_XDR_ALLOCED 0x0001 419#define XDR_FLAG_DEDICATED 0x0002 420#define XDR_FLAG_DESTROYING 0x0004 421#define XDR_FLAG_RETRY 0x0008 422 423 424/// @todo FIXME this goes with the callback stuff in oncrpcxdr.c. Move 425/// elsewhere and pick better symbol names. 426typedef struct rpc_cb_data_type { 427 void * cb_handler; 428 uint32 cb_id; 429 rpcprot_t protocol; 430 oncrpc_addr_type cb_source; 431} rpc_cb_data_type; 432 433#ifdef __cplusplus 434} 435#endif 436 437#endif /* _RPC_XDR_TYPES_H */ 438