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