1 /* $NetBSD: clnt.h,v 1.14 2000/06/02 22:57:55 fvdl Exp $ */ 2 3 /*- 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 * Copyright (c) 2010, Oracle America, Inc. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are met: 11 * - Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright notice, 14 * this list of conditions and the following disclaimer in the documentation 15 * and/or other materials provided with the distribution. 16 * - Neither the name of the "Oracle America, Inc." nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * clnt.h - Client side remote procedure call interface. 35 * 36 * Copyright (c) 1986-1991,1994-1999 by Sun Microsystems, Inc. 37 * All rights reserved. 38 */ 39 40 #ifndef _RPC_CLNT_H_ 41 #define _RPC_CLNT_H_ 42 #include <rpc/clnt_stat.h> 43 #include <sys/cdefs.h> 44 #include <sys/refcount.h> 45 #include <rpc/netconfig.h> 46 #include <sys/un.h> 47 48 /* 49 * Well-known IPV6 RPC broadcast address. 50 */ 51 #define RPCB_MULTICAST_ADDR "ff02::202" 52 53 /* 54 * the following errors are in general unrecoverable. The caller 55 * should give up rather than retry. 56 */ 57 #define IS_UNRECOVERABLE_RPC(s) (((s) == RPC_AUTHERROR) || \ 58 ((s) == RPC_CANTENCODEARGS) || \ 59 ((s) == RPC_CANTDECODERES) || \ 60 ((s) == RPC_VERSMISMATCH) || \ 61 ((s) == RPC_PROCUNAVAIL) || \ 62 ((s) == RPC_PROGUNAVAIL) || \ 63 ((s) == RPC_PROGVERSMISMATCH) || \ 64 ((s) == RPC_CANTDECODEARGS)) 65 66 /* 67 * Error info. 68 */ 69 struct rpc_err { 70 enum clnt_stat re_status; 71 union { 72 int RE_errno; /* related system error */ 73 enum auth_stat RE_why; /* why the auth error occurred */ 74 struct { 75 rpcvers_t low; /* lowest version supported */ 76 rpcvers_t high; /* highest version supported */ 77 } RE_vers; 78 struct { /* maybe meaningful if RPC_FAILED */ 79 int32_t s1; 80 int32_t s2; 81 } RE_lb; /* life boot & debugging only */ 82 } ru; 83 #define re_errno ru.RE_errno 84 #define re_why ru.RE_why 85 #define re_vers ru.RE_vers 86 #define re_lb ru.RE_lb 87 }; 88 89 /* 90 * Functions of this type may be used to receive notification when RPC 91 * calls have to be re-transmitted etc. 92 */ 93 typedef void rpc_feedback(int cmd, int procnum, void *); 94 95 /* 96 * Timers used for the pseudo-transport protocol when using datagrams 97 */ 98 struct rpc_timers { 99 u_short rt_srtt; /* smoothed round-trip time */ 100 u_short rt_deviate; /* estimated deviation */ 101 u_long rt_rtxcur; /* current (backed-off) rto */ 102 }; 103 104 /* 105 * A structure used with CLNT_CALL_EXT to pass extra information used 106 * while processing an RPC call. 107 */ 108 struct rpc_callextra { 109 AUTH *rc_auth; /* auth handle to use for this call */ 110 rpc_feedback *rc_feedback; /* callback for retransmits etc. */ 111 void *rc_feedback_arg; /* argument for callback */ 112 struct rpc_timers *rc_timers; /* optional RTT timers */ 113 struct rpc_err rc_err; /* detailed call status */ 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 volatile u_int cl_refs; /* reference count */ 123 AUTH *cl_auth; /* authenticator */ 124 const struct clnt_ops { 125 /* call remote procedure */ 126 enum clnt_stat (*cl_call)(struct __rpc_client *, 127 struct rpc_callextra *, rpcproc_t, 128 struct mbuf *, struct mbuf **, struct timeval); 129 /* abort a call */ 130 void (*cl_abort)(struct __rpc_client *); 131 /* get specific error code */ 132 void (*cl_geterr)(struct __rpc_client *, 133 struct rpc_err *); 134 /* frees results */ 135 bool_t (*cl_freeres)(struct __rpc_client *, 136 xdrproc_t, void *); 137 /* close the connection and terminate pending RPCs */ 138 void (*cl_close)(struct __rpc_client *); 139 /* destroy this structure */ 140 void (*cl_destroy)(struct __rpc_client *); 141 /* the ioctl() of rpc */ 142 bool_t (*cl_control)(struct __rpc_client *, u_int, 143 void *); 144 } *cl_ops; 145 void *cl_private; /* private stuff */ 146 char *cl_netid; /* network token */ 147 char *cl_tp; /* device name */ 148 } CLIENT; 149 150 /* 151 * Feedback values used for possible congestion and rate control 152 */ 153 #define FEEDBACK_OK 1 /* no retransmits */ 154 #define FEEDBACK_REXMIT1 2 /* first retransmit */ 155 #define FEEDBACK_REXMIT2 3 /* second and subsequent retransmit */ 156 #define FEEDBACK_RECONNECT 4 /* client reconnect */ 157 158 /* Used to set version of portmapper used in broadcast */ 159 160 #define CLCR_SET_LOWVERS 3 161 #define CLCR_GET_LOWVERS 4 162 163 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ 164 165 /* 166 * client side rpc interface ops 167 * 168 * Parameter types are: 169 * 170 */ 171 172 #define CLNT_ACQUIRE(rh) \ 173 refcount_acquire(&(rh)->cl_refs) 174 #define CLNT_RELEASE(rh) \ 175 if (refcount_release(&(rh)->cl_refs)) \ 176 CLNT_DESTROY(rh) 177 178 /* 179 * void 180 * CLNT_CLOSE(rh); 181 * CLIENT *rh; 182 */ 183 #define CLNT_CLOSE(rh) ((*(rh)->cl_ops->cl_close)(rh)) 184 185 enum clnt_stat clnt_call_private(CLIENT *, struct rpc_callextra *, rpcproc_t, 186 xdrproc_t, void *, xdrproc_t, void *, struct timeval); 187 188 /* 189 * enum clnt_stat 190 * CLNT_CALL_MBUF(rh, ext, proc, mreq, mrepp, timeout) 191 * CLIENT *rh; 192 * struct rpc_callextra *ext; 193 * rpcproc_t proc; 194 * struct mbuf *mreq; 195 * struct mbuf **mrepp; 196 * struct timeval timeout; 197 * 198 * Call arguments in mreq which is consumed by the call (even if there 199 * is an error). Results returned in *mrepp. 200 */ 201 #define CLNT_CALL_MBUF(rh, ext, proc, mreq, mrepp, secs) \ 202 ((*(rh)->cl_ops->cl_call)(rh, ext, proc, mreq, mrepp, secs)) 203 204 /* 205 * enum clnt_stat 206 * CLNT_CALL_EXT(rh, ext, proc, xargs, argsp, xres, resp, timeout) 207 * CLIENT *rh; 208 * struct rpc_callextra *ext; 209 * rpcproc_t proc; 210 * xdrproc_t xargs; 211 * void *argsp; 212 * xdrproc_t xres; 213 * void *resp; 214 * struct timeval timeout; 215 */ 216 #define CLNT_CALL_EXT(rh, ext, proc, xargs, argsp, xres, resp, secs) \ 217 clnt_call_private(rh, ext, proc, xargs, \ 218 argsp, xres, resp, secs) 219 220 /* 221 * enum clnt_stat 222 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) 223 * CLIENT *rh; 224 * rpcproc_t proc; 225 * xdrproc_t xargs; 226 * void *argsp; 227 * xdrproc_t xres; 228 * void *resp; 229 * struct timeval timeout; 230 */ 231 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ 232 clnt_call_private(rh, NULL, proc, xargs, \ 233 argsp, xres, resp, secs) 234 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ 235 clnt_call_private(rh, NULL, proc, xargs, \ 236 argsp, xres, resp, secs) 237 238 /* 239 * void 240 * CLNT_ABORT(rh); 241 * CLIENT *rh; 242 */ 243 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 244 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 245 246 /* 247 * struct rpc_err 248 * CLNT_GETERR(rh); 249 * CLIENT *rh; 250 */ 251 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 252 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 253 254 255 /* 256 * bool_t 257 * CLNT_FREERES(rh, xres, resp); 258 * CLIENT *rh; 259 * xdrproc_t xres; 260 * void *resp; 261 */ 262 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) 263 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) 264 265 /* 266 * bool_t 267 * CLNT_CONTROL(cl, request, info) 268 * CLIENT *cl; 269 * u_int request; 270 * char *info; 271 */ 272 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) 273 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) 274 275 /* 276 * control operations that apply to both udp and tcp transports 277 */ 278 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */ 279 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */ 280 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ 281 #define CLGET_FD 6 /* get connections file descriptor */ 282 #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) */ 283 #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */ 284 #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy */ 285 #define CLGET_XID 10 /* Get xid */ 286 #define CLSET_XID 11 /* Set xid */ 287 #define CLGET_VERS 12 /* Get version number */ 288 #define CLSET_VERS 13 /* Set version number */ 289 #define CLGET_PROG 14 /* Get program number */ 290 #define CLSET_PROG 15 /* Set program number */ 291 #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) */ 292 #define CLSET_PUSH_TIMOD 17 /* push timod if not already present */ 293 #define CLSET_POP_TIMOD 18 /* pop timod */ 294 /* 295 * Connectionless only control operations 296 */ 297 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ 298 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ 299 #define CLSET_ASYNC 19 300 #define CLSET_CONNECT 20 /* Use connect() for UDP. (int) */ 301 302 /* 303 * Kernel control operations. The default msleep string is "rpcrecv", 304 * and sleeps are non-interruptible by default. 305 */ 306 #define CLSET_WAITCHAN 21 /* set string to use in msleep call */ 307 #define CLGET_WAITCHAN 22 /* get string used in msleep call */ 308 #define CLSET_INTERRUPTIBLE 23 /* set interruptible flag */ 309 #define CLGET_INTERRUPTIBLE 24 /* set interruptible flag */ 310 #define CLSET_RETRIES 25 /* set retry count for reconnect */ 311 #define CLGET_RETRIES 26 /* get retry count for reconnect */ 312 #define CLSET_PRIVPORT 27 /* set privileged source port flag */ 313 #define CLGET_PRIVPORT 28 /* get privileged source port flag */ 314 #define CLSET_BACKCHANNEL 29 /* set backchannel for socket */ 315 #define CLSET_TLS 30 /* set TLS for socket */ 316 #define CLSET_BLOCKRCV 31 /* Temporarily block reception */ 317 #define CLSET_TLSCERTNAME 32 /* TLS certificate file name */ 318 /* Structure used as the argument for CLSET_RECONUPCALL. */ 319 struct rpc_reconupcall { 320 void (*call)(CLIENT *, void *, struct ucred *); 321 void *arg; 322 }; 323 #define CLSET_RECONUPCALL 33 /* Reconnect upcall */ 324 325 /* 326 * void 327 * CLNT_DESTROY(rh); 328 * CLIENT *rh; 329 */ 330 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 331 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 332 333 334 /* 335 * RPCTEST is a test program which is accessible on every rpc 336 * transport/port. It is used for testing, performance evaluation, 337 * and network administration. 338 */ 339 340 #define RPCTEST_PROGRAM ((rpcprog_t)1) 341 #define RPCTEST_VERSION ((rpcvers_t)1) 342 #define RPCTEST_NULL_PROC ((rpcproc_t)2) 343 #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3) 344 345 /* 346 * By convention, procedure 0 takes null arguments and returns them 347 */ 348 349 #define NULLPROC ((rpcproc_t)0) 350 351 /* 352 * Below are the client handle creation routines for the various 353 * implementations of client side rpc. They can return NULL if a 354 * creation failure occurs. 355 */ 356 357 /* 358 * Generic client creation routine. Supported protocols are those that 359 * belong to the nettype namespace (/etc/netconfig). 360 */ 361 __BEGIN_DECLS 362 /* 363 * struct socket *so; -- socket 364 * struct sockaddr *svcaddr; -- servers address 365 * rpcprog_t prog; -- program number 366 * rpcvers_t vers; -- version number 367 * size_t sendsz; -- buffer recv size 368 * size_t recvsz; -- buffer send size 369 */ 370 extern CLIENT *clnt_dg_create(struct socket *so, 371 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version, 372 size_t sendsz, size_t recvsz); 373 374 /* 375 * struct socket *so; -- socket 376 * struct sockaddr *svcaddr; -- servers address 377 * rpcprog_t prog; -- program number 378 * rpcvers_t vers; -- version number 379 * size_t sendsz; -- buffer recv size 380 * size_t recvsz; -- buffer send size 381 * int intrflag; -- is it interruptible 382 */ 383 extern CLIENT *clnt_vc_create(struct socket *so, 384 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version, 385 size_t sendsz, size_t recvsz, int intrflag); 386 387 /* 388 * struct netconfig *nconf; -- network type 389 * struct sockaddr *svcaddr; -- servers address 390 * rpcprog_t prog; -- program number 391 * rpcvers_t vers; -- version number 392 * size_t sendsz; -- buffer recv size 393 * size_t recvsz; -- buffer send size 394 */ 395 extern CLIENT *clnt_reconnect_create(struct netconfig *nconf, 396 struct sockaddr *svcaddr, rpcprog_t program, rpcvers_t version, 397 size_t sendsz, size_t recvsz); 398 __END_DECLS 399 400 401 /* 402 * Print why creation failed 403 */ 404 __BEGIN_DECLS 405 extern void clnt_pcreateerror(const char *); /* stderr */ 406 extern char *clnt_spcreateerror(const char *); /* string */ 407 __END_DECLS 408 409 /* 410 * Like clnt_perror(), but is more verbose in its output 411 */ 412 __BEGIN_DECLS 413 extern void clnt_perrno(enum clnt_stat); /* stderr */ 414 extern char *clnt_sperrno(enum clnt_stat); /* string */ 415 __END_DECLS 416 417 /* 418 * Print an English error message, given the client error code 419 */ 420 __BEGIN_DECLS 421 extern void clnt_perror(CLIENT *, const char *); /* stderr */ 422 extern char *clnt_sperror(CLIENT *, const char *); /* string */ 423 __END_DECLS 424 425 426 /* 427 * If a creation fails, the following allows the user to figure out why. 428 */ 429 struct rpc_createerr { 430 enum clnt_stat cf_stat; 431 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ 432 }; 433 434 extern struct rpc_createerr rpc_createerr; 435 436 #endif /* !_RPC_CLNT_H_ */ 437