clnt.h 12 KB

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