1 /* $OpenBSD: clnt.h,v 1.11 2010/09/01 14:43:34 millert Exp $ */ 2 /* $NetBSD: clnt.h,v 1.6 1995/04/29 05:27:58 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 2010, Oracle America, Inc. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 16 * provided with the distribution. 17 * * Neither the name of the "Oracle America, Inc." nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 28 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * from: @(#)clnt.h 1.31 88/02/08 SMI 35 * @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC 36 */ 37 38 /* 39 * clnt.h - Client side remote procedure call interface. 40 */ 41 42 #ifndef _RPC_CLNT_H_ 43 #define _RPC_CLNT_H_ 44 #include <sys/cdefs.h> 45 46 /* 47 * Rpc calls return an enum clnt_stat. This should be looked at more, 48 * since each implementation is required to live with this (implementation 49 * independent) list of errors. 50 */ 51 enum clnt_stat { 52 RPC_SUCCESS=0, /* call succeeded */ 53 /* 54 * local errors 55 */ 56 RPC_CANTENCODEARGS=1, /* can't encode arguments */ 57 RPC_CANTDECODERES=2, /* can't decode results */ 58 RPC_CANTSEND=3, /* failure in sending call */ 59 RPC_CANTRECV=4, /* failure in receiving result */ 60 RPC_TIMEDOUT=5, /* call timed out */ 61 /* 62 * remote errors 63 */ 64 RPC_VERSMISMATCH=6, /* rpc versions not compatible */ 65 RPC_AUTHERROR=7, /* authentication error */ 66 RPC_PROGUNAVAIL=8, /* program not available */ 67 RPC_PROGVERSMISMATCH=9, /* program version mismatched */ 68 RPC_PROCUNAVAIL=10, /* procedure unavailable */ 69 RPC_CANTDECODEARGS=11, /* decode arguments error */ 70 RPC_SYSTEMERROR=12, /* generic "other problem" */ 71 72 /* 73 * callrpc & clnt_create errors 74 */ 75 RPC_UNKNOWNHOST=13, /* unknown host name */ 76 RPC_UNKNOWNPROTO=17, /* unknown protocol */ 77 78 /* 79 * _ create errors 80 */ 81 RPC_PMAPFAILURE=14, /* the pmapper failed in its call */ 82 RPC_PROGNOTREGISTERED=15, /* remote program is not registered */ 83 /* 84 * unspecified error 85 */ 86 RPC_FAILED=16 87 }; 88 89 90 /* 91 * Error info. 92 */ 93 struct rpc_err { 94 enum clnt_stat re_status; 95 union { 96 int RE_errno; /* related system error */ 97 enum auth_stat RE_why; /* why the auth error occurred */ 98 struct { 99 u_int32_t low; /* lowest verion supported */ 100 u_int32_t high; /* highest verion supported */ 101 } RE_vers; 102 struct { /* maybe meaningful if RPC_FAILED */ 103 int32_t s1; 104 int32_t s2; 105 } RE_lb; /* life boot & debugging only */ 106 } ru; 107 #define re_errno ru.RE_errno 108 #define re_why ru.RE_why 109 #define re_vers ru.RE_vers 110 #define re_lb ru.RE_lb 111 }; 112 113 114 /* 115 * Client rpc handle. 116 * Created by individual implementations, see e.g. rpc_udp.c. 117 * Client is responsible for initializing auth, see e.g. auth_none.c. 118 */ 119 typedef struct __rpc_client { 120 AUTH *cl_auth; /* authenticator */ 121 struct clnt_ops { 122 /* call remote procedure */ 123 enum clnt_stat (*cl_call)(struct __rpc_client *, 124 unsigned long, xdrproc_t, caddr_t, 125 xdrproc_t, caddr_t, struct timeval); 126 /* abort a call */ 127 void (*cl_abort)(struct __rpc_client *); 128 /* get specific error code */ 129 void (*cl_geterr)(struct __rpc_client *, 130 struct rpc_err *); 131 /* frees results */ 132 bool_t (*cl_freeres)(struct __rpc_client *, 133 xdrproc_t, caddr_t); 134 /* destroy this structure */ 135 void (*cl_destroy)(struct __rpc_client *); 136 /* the ioctl() of rpc */ 137 bool_t (*cl_control)(struct __rpc_client *, 138 unsigned int, void *); 139 } *cl_ops; 140 caddr_t cl_private; /* private stuff */ 141 } CLIENT; 142 143 144 /* 145 * client side rpc interface ops 146 * 147 * Parameter types are: 148 * 149 */ 150 151 /* 152 * enum clnt_stat 153 * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) 154 * CLIENT *rh; 155 * unsigned long proc; 156 * xdrproc_t xargs; 157 * caddr_t argsp; 158 * xdrproc_t xres; 159 * caddr_t resp; 160 * struct timeval timeout; 161 */ 162 #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ 163 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \ 164 xres, (caddr_t)resp, secs)) 165 #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ 166 ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \ 167 xres, (caddr_t)resp, secs)) 168 169 /* 170 * void 171 * CLNT_ABORT(rh); 172 * CLIENT *rh; 173 */ 174 #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 175 #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh)) 176 177 /* 178 * struct rpc_err 179 * CLNT_GETERR(rh); 180 * CLIENT *rh; 181 */ 182 #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 183 #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) 184 185 186 /* 187 * bool_t 188 * CLNT_FREERES(rh, xres, resp); 189 * CLIENT *rh; 190 * xdrproc_t xres; 191 * caddr_t resp; 192 */ 193 #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) 194 #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) 195 196 /* 197 * bool_t 198 * CLNT_CONTROL(cl, request, info) 199 * CLIENT *cl; 200 * unsigned int request; 201 * char *info; 202 */ 203 #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) 204 #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) 205 206 /* 207 * control operations that apply to both udp and tcp transports 208 */ 209 #define CLSET_TIMEOUT 1 /* set timeout (timeval) */ 210 #define CLGET_TIMEOUT 2 /* get timeout (timeval) */ 211 #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ 212 /* 213 * udp only control operations 214 */ 215 #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ 216 #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ 217 218 /* 219 * void 220 * CLNT_DESTROY(rh); 221 * CLIENT *rh; 222 */ 223 #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 224 #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) 225 226 227 /* 228 * RPCTEST is a test program which is accessable on every rpc 229 * transport/port. It is used for testing, performance evaluation, 230 * and network administration. 231 */ 232 233 #define RPCTEST_PROGRAM ((unsigned long)1) 234 #define RPCTEST_VERSION ((unsigned long)1) 235 #define RPCTEST_NULL_PROC ((unsigned long)2) 236 #define RPCTEST_NULL_BATCH_PROC ((unsigned long)3) 237 238 /* 239 * By convention, procedure 0 takes null arguments and returns them 240 */ 241 242 #define NULLPROC ((unsigned int)0) 243 244 /* 245 * Below are the client handle creation routines for the various 246 * implementations of client side rpc. They can return NULL if a 247 * creation failure occurs. 248 */ 249 250 /* 251 * Memory based rpc (for speed check and testing) 252 * CLIENT * 253 * clntraw_create(prog, vers) 254 * unsigned long prog; 255 * unsigned long vers; 256 */ 257 __BEGIN_DECLS 258 extern CLIENT *clntraw_create(unsigned long, unsigned long); 259 __END_DECLS 260 261 262 /* 263 * Generic client creation routine. Supported protocols are "udp" and "tcp" 264 * CLIENT * 265 * clnt_create(host, prog, vers, prot); 266 * char *host; -- hostname 267 * unsigned long prog; -- program number 268 * unsigned long vers; -- version number 269 * char *prot; -- protocol 270 */ 271 __BEGIN_DECLS 272 extern CLIENT *clnt_create(char *, unsigned long, unsigned long, char *); 273 __END_DECLS 274 275 276 /* 277 * TCP based rpc 278 * CLIENT * 279 * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) 280 * struct sockaddr_in *raddr; 281 * unsigned long prog; 282 * unsigned long version; 283 * int *sockp; 284 * unsigned int sendsz; 285 * unsigned int recvsz; 286 */ 287 __BEGIN_DECLS 288 extern CLIENT *clnttcp_create(struct sockaddr_in *, unsigned long, 289 unsigned long, int *, unsigned int, unsigned int); 290 __END_DECLS 291 292 293 /* 294 * UDP based rpc. 295 * CLIENT * 296 * clntudp_create(raddr, program, version, wait, sockp) 297 * struct sockaddr_in *raddr; 298 * unsigned long program; 299 * unsigned long version; 300 * struct timeval wait; 301 * int *sockp; 302 * 303 * Same as above, but you specify max packet sizes. 304 * CLIENT * 305 * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) 306 * struct sockaddr_in *raddr; 307 * unsigned long program; 308 * unsigned long version; 309 * struct timeval wait; 310 * int *sockp; 311 * unsigned int sendsz; 312 * unsigned int recvsz; 313 */ 314 __BEGIN_DECLS 315 extern CLIENT *clntudp_create(struct sockaddr_in *, unsigned long, 316 unsigned long, struct timeval, int *); 317 extern CLIENT *clntudp_bufcreate(struct sockaddr_in *, unsigned long, 318 unsigned long, struct timeval, int *, unsigned int, unsigned int); 319 __END_DECLS 320 321 322 /* 323 * Print why creation failed 324 */ 325 __BEGIN_DECLS 326 extern void clnt_pcreateerror(char *); /* stderr */ 327 extern char *clnt_spcreateerror(char *); /* string */ 328 __END_DECLS 329 330 /* 331 * Like clnt_perror(), but is more verbose in its output 332 */ 333 __BEGIN_DECLS 334 extern void clnt_perrno(enum clnt_stat); /* stderr */ 335 extern char *clnt_sperrno(enum clnt_stat); /* string */ 336 __END_DECLS 337 338 /* 339 * Print an English error message, given the client error code 340 */ 341 __BEGIN_DECLS 342 extern void clnt_perror(CLIENT *, char *); /* stderr */ 343 extern char *clnt_sperror(CLIENT *, char *); /* string */ 344 __END_DECLS 345 346 347 /* 348 * If a creation fails, the following allows the user to figure out why. 349 */ 350 struct rpc_createerr { 351 enum clnt_stat cf_stat; 352 struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ 353 }; 354 355 extern struct rpc_createerr rpc_createerr; 356 357 358 #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */ 359 #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ 360 361 #endif /* !_RPC_CLNT_H */ 362