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