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