1 /* $NetBSD: clnt.h,v 1.22 2014/06/06 14:31:24 christos Exp $ */ 2 3 /* 4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 5 * unrestricted use provided that this legend is included on all tape 6 * media and as a part of the software program in whole or part. Users 7 * may copy or modify Sun RPC without charge, but are not authorized 8 * to license or distribute it to anyone else except as part of a product or 9 * program developed by the user. 10 * 11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 * 15 * Sun RPC is provided with no support and without any obligation on the 16 * part of Sun Microsystems, Inc. to assist in its use, correction, 17 * modification or enhancement. 18 * 19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 * OR ANY PART THEREOF. 22 * 23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 * or profits or other special, indirect and consequential damages, even if 25 * Sun has been advised of the possibility of such damages. 26 * 27 * Sun Microsystems, Inc. 28 * 2550 Garcia Avenue 29 * Mountain View, California 94043 30 * 31 * from: @(#)clnt.h 1.31 94/04/29 SMI 32 * @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC 33 */ 34 35 /* 36 * clnt.h - Client side remote procedure call interface. 37 * 38 * Copyright (C) 1984, Sun Microsystems, Inc. 39 */ 40 41 #ifndef _RPC_CLNT_H_ 42 #define _RPC_CLNT_H_ 43 #include <sys/cdefs.h> 44 45 #include <rpc/rpc_com.h> 46 47 /* 48 * Well-known IPV6 RPC broadcast address. 49 */ 50 #define RPCB_MULTICAST_ADDR "ff02::202" 51 52 /* 53 * Rpc calls return an enum clnt_stat. This should be looked at more, 54 * since each implementation is required to live with this (implementation 55 * independent) list of errors. 56 */ 57 enum clnt_stat { 58 RPC_SUCCESS=0, /* call succeeded */ 59 /* 60 * local errors 61 */ 62 RPC_CANTENCODEARGS=1, /* can't encode arguments */ 63 RPC_CANTDECODERES=2, /* can't decode results */ 64 RPC_CANTSEND=3, /* failure in sending call */ 65 RPC_CANTRECV=4, /* failure in receiving result */ 66 RPC_TIMEDOUT=5, /* call timed out */ 67 /* 68 * remote errors 69 */ 70 RPC_VERSMISMATCH=6, /* rpc versions not compatible */ 71 RPC_AUTHERROR=7, /* authentication error */ 72 RPC_PROGUNAVAIL=8, /* program not available */ 73 RPC_PROGVERSMISMATCH=9, /* program version mismatched */ 74 RPC_PROCUNAVAIL=10, /* procedure unavailable */ 75 RPC_CANTDECODEARGS=11, /* decode arguments error */ 76 RPC_SYSTEMERROR=12, /* generic "other problem" */ 77 78 /* 79 * rpc_call & clnt_create errors 80 */ 81 RPC_UNKNOWNHOST=13, /* unknown host name */ 82 RPC_UNKNOWNPROTO=17, /* unknown protocol */ 83 RPC_UNKNOWNADDR = 19, /* Remote address unknown */ 84 RPC_NOBROADCAST = 21, /* Broadcasting not supported */ 85 86 /* 87 * rpcbind errors 88 */ 89 RPC_RPCBFAILURE=14, /* the pmapper failed in its call */ 90 #define RPC_PMAPFAILURE RPC_RPCBFAILURE 91 RPC_PROGNOTREGISTERED=15, /* remote program is not registered */ 92 RPC_N2AXLATEFAILURE = 22, /* name -> addr translation failed */ 93 94 /* 95 * Misc error in the TLI library (provided for compatibility) 96 */ 97 RPC_TLIERROR = 20, 98 99 /* 100 * unspecified error 101 */ 102 RPC_FAILED=16, 103 104 /* 105 * asynchronous errors 106 */ 107 RPC_INPROGRESS = 24, 108 RPC_STALERACHANDLE = 25 109 }; 110 111 112 /* 113 * Error info. 114 */ 115 struct rpc_err { 116 enum clnt_stat re_status; 117 union { 118 int RE_errno; /* related system error */ 119 enum auth_stat RE_why; /* why the auth error occurred */ 120 struct { 121 rpcvers_t low; /* lowest version supported */ 122 rpcvers_t high; /* highest version supported */ 123 } RE_vers; 124 struct { /* maybe meaningful if RPC_FAILED */ 125 int32_t s1; 126 int32_t s2; 127 } RE_lb; /* life boot & debugging only */ 128 } ru; 129 #define re_errno ru.RE_errno 130 #define re_why ru.RE_why 131 #define re_vers ru.RE_vers 132 #define re_lb ru.RE_lb 133 }; 134 135 136 /* 137 * Client rpc handle. 138 * Created by individual implementations 139 * Client is responsible for initializing auth, see e.g. auth_none.c. 140 */ 141 typedef struct __rpc_client { 142 AUTH *cl_auth; /* authenticator */ 143 const struct clnt_ops { 144 /* call remote procedure */ 145 enum clnt_stat (*cl_call)(struct __rpc_client *, 146 rpcproc_t, xdrproc_t, const char *, 147 xdrproc_t, caddr_t, struct timeval); 148 /* abort a call */ 149 void (*cl_abort)(struct __rpc_client *); 150 /* get specific error code */ 151 void (*cl_geterr)(struct __rpc_client *, 152 struct rpc_err *); 153 /* frees results */ 154 bool_t (*cl_freeres)(struct __rpc_client *, 155 xdrproc_t, caddr_t); 156 /* destroy this structure */ 157 void (*cl_destroy)(struct __rpc_client *); 158 /* the ioctl() of rpc */ 159 bool_t (*cl_control)(struct __rpc_client *, u_int, 160 char *); 161 } *cl_ops; 162 void *cl_private; /* private stuff */ 163 char *cl_netid; /* network token */ 164 char *cl_tp; /* device name */ 165 } CLIENT; 166 167 168 /* 169 * Timers used for the pseudo-transport protocol when using datagrams 170 */ 171 struct rpc_timers { 172 u_short rt_srtt; /* smoothed round-trip time */ 173 u_short rt_deviate; /* estimated deviation */ 174 u_long rt_rtxcur; /* current (backed-off) rto */ 175 }; 176 177 /* 178 * Feedback values used for possible congestion and rate control 179 */ 180 #define FEEDBACK_REXMIT1 1 /* first retransmit */ 181 #define FEEDBACK_OK 2 /* no retransmits */ 182 183 /* Used to set version of portmapper used in broadcast */ 184 185 #define CLCR_SET_LOWVERS 3 186 #define CLCR_GET_LOWVERS 4 187 188 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ 189 190 /* 191 * client side rpc interface ops 192 * 193 * Parameter types are: 194 * 195 */ 196 197 /* 198 * enum clnt_stat 199 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) 200 * CLIENT *rh; 201 * rpcproc_t proc; 202 * xdrproc_t xargs; 203 * caddr_t argsp; 204 * xdrproc_t xres; 205 * caddr_t resp; 206 * struct timeval timeout; 207 */ 208 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ 209 ((*(rh)->cl_ops->cl_call)(rh, proc, (xdrproc_t)xargs, \ 210 (const char *)(const void *)(argsp), (xdrproc_t)xres, \ 211 (caddr_t)(void *)resp, secs)) 212 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ 213 ((*(rh)->cl_ops->cl_call)(rh, proc, (xdrproc_t)xargs, \ 214 (const char *)(const void *)(argsp), (xdrproc_t)xres, \ 215 (caddr_t)(void *)resp, secs)) 216 217 /* 218 * void 219 * CLNT_ABORT(rh); 220 * CLIENT *rh; 221 */ 222 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 223 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 224 225 /* 226 * struct rpc_err 227 * CLNT_GETERR(rh); 228 * CLIENT *rh; 229 */ 230 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 231 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 232 233 234 /* 235 * bool_t 236 * CLNT_FREERES(rh, xres, resp); 237 * CLIENT *rh; 238 * xdrproc_t xres; 239 * caddr_t resp; 240 */ 241 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) 242 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) 243 244 /* 245 * bool_t 246 * CLNT_CONTROL(cl, request, info) 247 * CLIENT *cl; 248 * u_int request; 249 * char *info; 250 */ 251 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) 252 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) 253 254 /* 255 * control operations that apply to both udp and tcp transports 256 */ 257 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */ 258 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */ 259 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ 260 #define CLGET_FD 6 /* get connections file descriptor */ 261 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */ 262 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */ 263 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */ 264 #define CLGET_XID 10 /* Get xid */ 265 #define CLSET_XID 11 /* Set xid */ 266 #define CLGET_VERS 12 /* Get version number */ 267 #define CLSET_VERS 13 /* Set version number */ 268 #define CLGET_PROG 14 /* Get program number */ 269 #define CLSET_PROG 15 /* Set program number */ 270 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */ 271 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */ 272 #define CLSET_POP_TIMOD 18 /* pop timod */ 273 /* 274 * Connectionless only control operations 275 */ 276 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ 277 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ 278 279 /* 280 * void 281 * CLNT_DESTROY(rh); 282 * CLIENT *rh; 283 */ 284 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 285 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 286 287 288 /* 289 * RPCTEST is a test program which is accessible on every rpc 290 * transport/port. It is used for testing, performance evaluation, 291 * and network administration. 292 */ 293 294 #define RPCTEST_PROGRAM ((rpcprog_t)1) 295 #define RPCTEST_VERSION ((rpcvers_t)1) 296 #define RPCTEST_NULL_PROC ((rpcproc_t)2) 297 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3) 298 299 /* 300 * By convention, procedure 0 takes null arguments and returns them 301 */ 302 303 #define NULLPROC ((rpcproc_t)0) 304 305 /* 306 * Below are the client handle creation routines for the various 307 * implementations of client side rpc. They can return NULL if a 308 * creation failure occurs. 309 */ 310 311 /* 312 * Generic client creation routine. Supported protocols are those that 313 * belong to the nettype namespace (/etc/netconfig). 314 * CLIENT * 315 * clnt_create(host, prog, vers, prot); 316 * const char *host; -- hostname 317 * const rpcprog_t prog; -- program number 318 * const rpcvers_t vers; -- version number 319 * const char *prot; -- protocol 320 */ 321 __BEGIN_DECLS 322 extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t, 323 const char *); 324 /* 325 * 326 * const char *hostname; -- hostname 327 * const rpcprog_t prog; -- program number 328 * const rpcvers_t vers; -- version number 329 * const char *nettype; -- network type 330 */ 331 332 /* 333 * Generic client creation routine. Supported protocols are which belong 334 * to the nettype name space. 335 */ 336 extern CLIENT *clnt_create_vers(const char *, const rpcprog_t, rpcvers_t *, 337 const rpcvers_t, const rpcvers_t, 338 const char *); 339 /* 340 * const char *host; -- hostname 341 * const rpcprog_t prog; -- program number 342 * rpcvers_t *vers_out; -- servers highest available version 343 * const rpcvers_t vers_low; -- low version number 344 * const rpcvers_t vers_high; -- high version number 345 * const char *nettype; -- network type 346 */ 347 348 349 /* 350 * Generic client creation routine. It takes a netconfig structure 351 * instead of nettype 352 */ 353 extern CLIENT *clnt_tp_create(const char *, const rpcprog_t, 354 const rpcvers_t, const struct netconfig *); 355 /* 356 * const char *hostname; -- hostname 357 * const rpcprog_t prog; -- program number 358 * const rpcvers_t vers; -- version number 359 * const struct netconfig *netconf; -- network config structure 360 */ 361 362 /* 363 * Generic TLI create routine. Only provided for compatibility. 364 */ 365 366 extern CLIENT *clnt_tli_create(const int, const struct netconfig *, 367 const struct netbuf *, const rpcprog_t, 368 const rpcvers_t, const u_int, const u_int); 369 /* 370 * const register int fd; -- fd 371 * const struct netconfig *nconf; -- netconfig structure 372 * const struct netbuf *svcaddr; -- servers address 373 * const u_long prog; -- program number 374 * const u_long vers; -- version number 375 * const u_int sendsz; -- send size 376 * const u_int recvsz; -- recv size 377 */ 378 379 /* 380 * Low level clnt create routine for connectionful transports, e.g. tcp. 381 */ 382 extern CLIENT *clnt_vc_create(const int, const struct netbuf *, 383 const rpcprog_t, const rpcvers_t, 384 const u_int, const u_int); 385 /* 386 * const int fd; -- open file descriptor 387 * const struct netbuf *svcaddr; -- servers address 388 * const rpcprog_t prog; -- program number 389 * const rpcvers_t vers; -- version number 390 * const u_int sendsz; -- buffer recv size 391 * const u_int recvsz; -- buffer send size 392 */ 393 394 /* 395 * Low level clnt create routine for connectionless transports, e.g. udp. 396 */ 397 extern CLIENT *clnt_dg_create(const int, const struct netbuf *, 398 const rpcprog_t, const rpcvers_t, 399 const u_int, const u_int); 400 /* 401 * const int fd; -- open file descriptor 402 * const struct netbuf *svcaddr; -- servers address 403 * const rpcprog_t program; -- program number 404 * const rpcvers_t version; -- version number 405 * const u_int sendsz; -- buffer recv size 406 * const u_int recvsz; -- buffer send size 407 */ 408 409 /* 410 * Memory based rpc (for speed check and testing) 411 * CLIENT * 412 * clnt_raw_create(prog, vers) 413 * u_long prog; 414 * u_long vers; 415 */ 416 extern CLIENT *clnt_raw_create (rpcprog_t, rpcvers_t); 417 418 __END_DECLS 419 420 421 /* 422 * Print why creation failed 423 */ 424 __BEGIN_DECLS 425 extern void clnt_pcreateerror (const char *); /* stderr */ 426 extern char *clnt_spcreateerror (const char *); /* string */ 427 __END_DECLS 428 429 /* 430 * Like clnt_perror(), but is more verbose in its output 431 */ 432 __BEGIN_DECLS 433 extern void clnt_perrno (enum clnt_stat); /* stderr */ 434 extern char *clnt_sperrno (enum clnt_stat); /* string */ 435 __END_DECLS 436 437 /* 438 * Print an English error message, given the client error code 439 */ 440 __BEGIN_DECLS 441 extern void clnt_perror (CLIENT *, const char *); /* stderr */ 442 extern char *clnt_sperror (CLIENT *, const char *); /* string */ 443 __END_DECLS 444 445 446 /* 447 * If a creation fails, the following allows the user to figure out why. 448 */ 449 struct rpc_createerr { 450 enum clnt_stat cf_stat; 451 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ 452 }; 453 454 __BEGIN_DECLS 455 extern struct rpc_createerr *__rpc_createerr(void); 456 __END_DECLS 457 #define rpc_createerr (*(__rpc_createerr())) 458 459 /* 460 * The simplified interface: 461 * enum clnt_stat 462 * rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype) 463 * const char *host; 464 * const rpcprog_t prognum; 465 * const rpcvers_t versnum; 466 * const rpcproc_t procnum; 467 * const xdrproc_t inproc, outproc; 468 * const char *in; 469 * char *out; 470 * const char *nettype; 471 */ 472 __BEGIN_DECLS 473 extern enum clnt_stat rpc_call(const char *, const rpcprog_t, 474 const rpcvers_t, const rpcproc_t, 475 const xdrproc_t, const char *, 476 const xdrproc_t, char *, const char *); 477 __END_DECLS 478 479 /* 480 * RPC broadcast interface 481 * The call is broadcasted to all locally connected nets. 482 * 483 * extern enum clnt_stat 484 * rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, 485 * eachresult, nettype) 486 * const rpcprog_t prog; -- program number 487 * const rpcvers_t vers; -- version number 488 * const rpcproc_t proc; -- procedure number 489 * const xdrproc_t xargs; -- xdr routine for args 490 * caddr_t argsp; -- pointer to args 491 * const xdrproc_t xresults; -- xdr routine for results 492 * caddr_t resultsp; -- pointer to results 493 * const resultproc_t eachresult; -- call with each result 494 * const char *nettype; -- Transport type 495 * 496 * For each valid response received, the procedure eachresult is called. 497 * Its form is: 498 * done = eachresult(resp, raddr, nconf) 499 * bool_t done; 500 * caddr_t resp; 501 * struct netbuf *raddr; 502 * struct netconfig *nconf; 503 * where resp points to the results of the call and raddr is the 504 * address if the responder to the broadcast. nconf is the transport 505 * on which the response was received. 506 * 507 * extern enum clnt_stat 508 * rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, 509 * eachresult, inittime, waittime, nettype) 510 * const rpcprog_t prog; -- program number 511 * const rpcvers_t vers; -- version number 512 * const rpcproc_t proc; -- procedure number 513 * const xdrproc_t xargs; -- xdr routine for args 514 * caddr_t argsp; -- pointer to args 515 * const xdrproc_t xresults; -- xdr routine for results 516 * caddr_t resultsp; -- pointer to results 517 * const resultproc_t eachresult; -- call with each result 518 * const int inittime; -- how long to wait initially 519 * const int waittime; -- maximum time to wait 520 * const char *nettype; -- Transport type 521 */ 522 523 typedef bool_t (*resultproc_t)(caddr_t, ...); 524 525 __BEGIN_DECLS 526 extern enum clnt_stat rpc_broadcast(const rpcprog_t, const rpcvers_t, 527 const rpcproc_t, const xdrproc_t, const char *, const xdrproc_t, caddr_t, 528 const resultproc_t, const char *); 529 extern enum clnt_stat rpc_broadcast_exp(const rpcprog_t, const rpcvers_t, 530 const rpcproc_t, const xdrproc_t, const char *, const xdrproc_t, caddr_t, 531 const resultproc_t, const int, const int, const char *); 532 __END_DECLS 533 534 /* For backward compatibility */ 535 #include <rpc/clnt_soc.h> 536 537 #endif /* !_RPC_CLNT_H_ */ 538