/include/rpc/svc.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 474 lines · 170 code · 59 blank · 245 comment · 0 complexity · b5bd96220e77e3a98a5b43a2bf7c25f5 MD5 · raw file

  1. /* $NetBSD: svc.h,v 1.17 2000/06/02 22:57:56 fvdl Exp $ */
  2. /*
  3. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4. * unrestricted use provided that this legend is included on all tape
  5. * media and as a part of the software program in whole or part. Users
  6. * may copy or modify Sun RPC without charge, but are not authorized
  7. * to license or distribute it to anyone else except as part of a product or
  8. * program developed by the user.
  9. *
  10. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11. * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  12. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13. *
  14. * Sun RPC is provided with no support and without any obligation on the
  15. * part of Sun Microsystems, Inc. to assist in its use, correction,
  16. * modification or enhancement.
  17. *
  18. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20. * OR ANY PART THEREOF.
  21. *
  22. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23. * or profits or other special, indirect and consequential damages, even if
  24. * Sun has been advised of the possibility of such damages.
  25. *
  26. * Sun Microsystems, Inc.
  27. * 2550 Garcia Avenue
  28. * Mountain View, California 94043
  29. *
  30. * from: @(#)svc.h 1.35 88/12/17 SMI
  31. * from: @(#)svc.h 1.27 94/04/25 SMI
  32. * $FreeBSD$
  33. */
  34. /*
  35. * svc.h, Server-side remote procedure call interface.
  36. *
  37. * Copyright (C) 1986-1993 by Sun Microsystems, Inc.
  38. */
  39. #ifndef _RPC_SVC_H
  40. #define _RPC_SVC_H
  41. #include <sys/cdefs.h>
  42. /*
  43. * This interface must manage two items concerning remote procedure calling:
  44. *
  45. * 1) An arbitrary number of transport connections upon which rpc requests
  46. * are received. The two most notable transports are TCP and UDP; they are
  47. * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  48. * they in turn call xprt_register and xprt_unregister.
  49. *
  50. * 2) An arbitrary number of locally registered services. Services are
  51. * described by the following four data: program number, version number,
  52. * "service dispatch" function, a transport handle, and a boolean that
  53. * indicates whether or not the exported program should be registered with a
  54. * local binder service; if true the program's number and version and the
  55. * port number from the transport handle are registered with the binder.
  56. * These data are registered with the rpc svc system via svc_register.
  57. *
  58. * A service's dispatch function is called whenever an rpc request comes in
  59. * on a transport. The request's program and version numbers must match
  60. * those of the registered service. The dispatch function is passed two
  61. * parameters, struct svc_req * and SVCXPRT *, defined below.
  62. */
  63. /*
  64. * Service control requests
  65. */
  66. #define SVCGET_VERSQUIET 1
  67. #define SVCSET_VERSQUIET 2
  68. #define SVCGET_CONNMAXREC 3
  69. #define SVCSET_CONNMAXREC 4
  70. /*
  71. * Operations for rpc_control().
  72. */
  73. #define RPC_SVC_CONNMAXREC_SET 0 /* set max rec size, enable nonblock */
  74. #define RPC_SVC_CONNMAXREC_GET 1
  75. enum xprt_stat {
  76. XPRT_DIED,
  77. XPRT_MOREREQS,
  78. XPRT_IDLE
  79. };
  80. /*
  81. * Server side transport handle
  82. */
  83. typedef struct __rpc_svcxprt {
  84. int xp_fd;
  85. u_short xp_port; /* associated port number */
  86. const struct xp_ops {
  87. /* receive incoming requests */
  88. bool_t (*xp_recv)(struct __rpc_svcxprt *, struct rpc_msg *);
  89. /* get transport status */
  90. enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
  91. /* get arguments */
  92. bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t,
  93. void *);
  94. /* send reply */
  95. bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
  96. /* free mem allocated for args */
  97. bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t,
  98. void *);
  99. /* destroy this struct */
  100. void (*xp_destroy)(struct __rpc_svcxprt *);
  101. } *xp_ops;
  102. int xp_addrlen; /* length of remote address */
  103. struct sockaddr_in xp_raddr; /* remote addr. (backward ABI compat) */
  104. /* XXX - fvdl stick this here for ABI backward compat reasons */
  105. const struct xp_ops2 {
  106. /* catch-all function */
  107. bool_t (*xp_control)(struct __rpc_svcxprt *, const u_int,
  108. void *);
  109. } *xp_ops2;
  110. char *xp_tp; /* transport provider device name */
  111. char *xp_netid; /* network token */
  112. struct netbuf xp_ltaddr; /* local transport address */
  113. struct netbuf xp_rtaddr; /* remote transport address */
  114. struct opaque_auth xp_verf; /* raw response verifier */
  115. void *xp_p1; /* private: for use by svc ops */
  116. void *xp_p2; /* private: for use by svc ops */
  117. void *xp_p3; /* private: for use by svc lib */
  118. int xp_type; /* transport type */
  119. } SVCXPRT;
  120. /*
  121. * Interface to server-side authentication flavors.
  122. */
  123. typedef struct __rpc_svcauth {
  124. struct svc_auth_ops {
  125. int (*svc_ah_wrap)(struct __rpc_svcauth *, XDR *,
  126. xdrproc_t, caddr_t);
  127. int (*svc_ah_unwrap)(struct __rpc_svcauth *, XDR *,
  128. xdrproc_t, caddr_t);
  129. } *svc_ah_ops;
  130. void *svc_ah_private;
  131. } SVCAUTH;
  132. /*
  133. * Server transport extensions (accessed via xp_p3).
  134. */
  135. typedef struct __rpc_svcxprt_ext {
  136. int xp_flags; /* versquiet */
  137. SVCAUTH xp_auth; /* interface to auth methods */
  138. } SVCXPRT_EXT;
  139. /*
  140. * Service request
  141. */
  142. struct svc_req {
  143. u_int32_t rq_prog; /* service program number */
  144. u_int32_t rq_vers; /* service protocol version */
  145. u_int32_t rq_proc; /* the desired procedure */
  146. struct opaque_auth rq_cred; /* raw creds from the wire */
  147. void *rq_clntcred; /* read only cooked cred */
  148. SVCXPRT *rq_xprt; /* associated transport */
  149. };
  150. /*
  151. * Approved way of getting address of caller
  152. */
  153. #define svc_getrpccaller(x) (&(x)->xp_rtaddr)
  154. /*
  155. * Operations defined on an SVCXPRT handle
  156. *
  157. * SVCXPRT *xprt;
  158. * struct rpc_msg *msg;
  159. * xdrproc_t xargs;
  160. * void * argsp;
  161. */
  162. #define SVC_RECV(xprt, msg) \
  163. (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  164. #define svc_recv(xprt, msg) \
  165. (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  166. #define SVC_STAT(xprt) \
  167. (*(xprt)->xp_ops->xp_stat)(xprt)
  168. #define svc_stat(xprt) \
  169. (*(xprt)->xp_ops->xp_stat)(xprt)
  170. #define SVC_GETARGS(xprt, xargs, argsp) \
  171. (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  172. #define svc_getargs(xprt, xargs, argsp) \
  173. (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  174. #define SVC_REPLY(xprt, msg) \
  175. (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  176. #define svc_reply(xprt, msg) \
  177. (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  178. #define SVC_FREEARGS(xprt, xargs, argsp) \
  179. (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  180. #define svc_freeargs(xprt, xargs, argsp) \
  181. (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  182. #define SVC_DESTROY(xprt) \
  183. (*(xprt)->xp_ops->xp_destroy)(xprt)
  184. #define svc_destroy(xprt) \
  185. (*(xprt)->xp_ops->xp_destroy)(xprt)
  186. #define SVC_CONTROL(xprt, rq, in) \
  187. (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
  188. #define SVC_EXT(xprt) \
  189. ((SVCXPRT_EXT *) xprt->xp_p3)
  190. #define SVC_AUTH(xprt) \
  191. (SVC_EXT(xprt)->xp_auth)
  192. /*
  193. * Operations defined on an SVCAUTH handle
  194. */
  195. #define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere) \
  196. ((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere))
  197. #define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \
  198. ((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere))
  199. /*
  200. * Service registration
  201. *
  202. * svc_reg(xprt, prog, vers, dispatch, nconf)
  203. * const SVCXPRT *xprt;
  204. * const rpcprog_t prog;
  205. * const rpcvers_t vers;
  206. * const void (*dispatch)(struct svc_req *, SVCXPRT *);
  207. * const struct netconfig *nconf;
  208. */
  209. __BEGIN_DECLS
  210. extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
  211. void (*)(struct svc_req *, SVCXPRT *),
  212. const struct netconfig *);
  213. __END_DECLS
  214. /*
  215. * Service un-registration
  216. *
  217. * svc_unreg(prog, vers)
  218. * const rpcprog_t prog;
  219. * const rpcvers_t vers;
  220. */
  221. __BEGIN_DECLS
  222. extern void svc_unreg(const rpcprog_t, const rpcvers_t);
  223. __END_DECLS
  224. /*
  225. * Transport registration.
  226. *
  227. * xprt_register(xprt)
  228. * SVCXPRT *xprt;
  229. */
  230. __BEGIN_DECLS
  231. extern void xprt_register(SVCXPRT *);
  232. __END_DECLS
  233. /*
  234. * Transport un-register
  235. *
  236. * xprt_unregister(xprt)
  237. * SVCXPRT *xprt;
  238. */
  239. __BEGIN_DECLS
  240. extern void xprt_unregister(SVCXPRT *);
  241. __END_DECLS
  242. /*
  243. * When the service routine is called, it must first check to see if it
  244. * knows about the procedure; if not, it should call svcerr_noproc
  245. * and return. If so, it should deserialize its arguments via
  246. * SVC_GETARGS (defined above). If the deserialization does not work,
  247. * svcerr_decode should be called followed by a return. Successful
  248. * decoding of the arguments should be followed the execution of the
  249. * procedure's code and a call to svc_sendreply.
  250. *
  251. * Also, if the service refuses to execute the procedure due to too-
  252. * weak authentication parameters, svcerr_weakauth should be called.
  253. * Note: do not confuse access-control failure with weak authentication!
  254. *
  255. * NB: In pure implementations of rpc, the caller always waits for a reply
  256. * msg. This message is sent when svc_sendreply is called.
  257. * Therefore pure service implementations should always call
  258. * svc_sendreply even if the function logically returns void; use
  259. * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
  260. * for the abuse of pure rpc via batched calling or pipelining. In the
  261. * case of a batched call, svc_sendreply should NOT be called since
  262. * this would send a return message, which is what batching tries to avoid.
  263. * It is the service/protocol writer's responsibility to know which calls are
  264. * batched and which are not. Warning: responding to batch calls may
  265. * deadlock the caller and server processes!
  266. */
  267. __BEGIN_DECLS
  268. extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
  269. extern void svcerr_decode(SVCXPRT *);
  270. extern void svcerr_weakauth(SVCXPRT *);
  271. extern void svcerr_noproc(SVCXPRT *);
  272. extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
  273. extern void svcerr_auth(SVCXPRT *, enum auth_stat);
  274. extern void svcerr_noprog(SVCXPRT *);
  275. extern void svcerr_systemerr(SVCXPRT *);
  276. extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
  277. char *(*)(char *), xdrproc_t, xdrproc_t,
  278. char *);
  279. __END_DECLS
  280. /*
  281. * Lowest level dispatching -OR- who owns this process anyway.
  282. * Somebody has to wait for incoming requests and then call the correct
  283. * service routine. The routine svc_run does infinite waiting; i.e.,
  284. * svc_run never returns.
  285. * Since another (co-existent) package may wish to selectively wait for
  286. * incoming calls or other events outside of the rpc architecture, the
  287. * routine svc_getreq is provided. It must be passed readfds, the
  288. * "in-place" results of a select system call (see select, section 2).
  289. */
  290. /*
  291. * Global keeper of rpc service descriptors in use
  292. * dynamic; must be inspected before each call to select
  293. */
  294. extern int svc_maxfd;
  295. #ifdef FD_SETSIZE
  296. extern fd_set svc_fdset;
  297. #define svc_fds svc_fdset.fds_bits[0] /* compatibility */
  298. #else
  299. extern int svc_fds;
  300. #endif /* def FD_SETSIZE */
  301. /*
  302. * A set of null auth methods used by any authentication protocols
  303. * that don't need to inspect or modify the message body.
  304. */
  305. extern SVCAUTH _svc_auth_null;
  306. /*
  307. * a small program implemented by the svc_rpc implementation itself;
  308. * also see clnt.h for protocol numbers.
  309. */
  310. __BEGIN_DECLS
  311. extern void rpctest_service(void);
  312. __END_DECLS
  313. __BEGIN_DECLS
  314. extern SVCXPRT *svc_xprt_alloc(void);
  315. extern void svc_xprt_free(SVCXPRT *);
  316. extern void svc_getreq(int);
  317. extern void svc_getreqset(fd_set *);
  318. extern void svc_getreq_common(int);
  319. struct pollfd;
  320. extern void svc_getreq_poll(struct pollfd *, int);
  321. extern void svc_run(void);
  322. extern void svc_exit(void);
  323. __END_DECLS
  324. /*
  325. * Socket to use on svcxxx_create call to get default socket
  326. */
  327. #define RPC_ANYSOCK -1
  328. #define RPC_ANYFD RPC_ANYSOCK
  329. /*
  330. * These are the existing service side transport implementations
  331. */
  332. __BEGIN_DECLS
  333. /*
  334. * Transport independent svc_create routine.
  335. */
  336. extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
  337. const rpcprog_t, const rpcvers_t, const char *);
  338. /*
  339. * void (*dispatch)(struct svc_req *, SVCXPRT *);
  340. * const rpcprog_t prognum; -- program number
  341. * const rpcvers_t versnum; -- version number
  342. * const char *nettype; -- network type
  343. */
  344. /*
  345. * Generic server creation routine. It takes a netconfig structure
  346. * instead of a nettype.
  347. */
  348. extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
  349. const rpcprog_t, const rpcvers_t,
  350. const struct netconfig *);
  351. /*
  352. * void (*dispatch)(struct svc_req *, SVCXPRT *);
  353. * const rpcprog_t prognum; -- program number
  354. * const rpcvers_t versnum; -- version number
  355. * const struct netconfig *nconf; -- netconfig structure
  356. */
  357. /*
  358. * Generic TLI create routine
  359. */
  360. extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
  361. const struct t_bind *, const u_int,
  362. const u_int);
  363. /*
  364. * const int fd; -- connection end point
  365. * const struct netconfig *nconf; -- netconfig structure for network
  366. * const struct t_bind *bindaddr; -- local bind address
  367. * const u_int sendsz; -- max sendsize
  368. * const u_int recvsz; -- max recvsize
  369. */
  370. /*
  371. * Connectionless and connectionful create routines
  372. */
  373. extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
  374. /*
  375. * const int fd; -- open connection end point
  376. * const u_int sendsize; -- max send size
  377. * const u_int recvsize; -- max recv size
  378. */
  379. /*
  380. * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
  381. */
  382. extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
  383. extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
  384. /*
  385. * const int fd; -- open connection
  386. * const u_int sendsize; -- max send size
  387. * const u_int recvsize; -- max recv size
  388. */
  389. /*
  390. * the routine takes any *open* connection
  391. * descriptor as its first input and is used for open connections.
  392. */
  393. extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
  394. /*
  395. * const int fd; -- open connection end point
  396. * const u_int sendsize; -- max send size
  397. * const u_int recvsize; -- max recv size
  398. */
  399. /*
  400. * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
  401. */
  402. extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
  403. /*
  404. * Memory based rpc (for speed check and testing)
  405. */
  406. extern SVCXPRT *svc_raw_create(void);
  407. /*
  408. * svc_dg_enable_cache() enables the cache on dg transports.
  409. */
  410. int svc_dg_enablecache(SVCXPRT *, const u_int);
  411. int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
  412. __END_DECLS
  413. /* for backward compatibility */
  414. #include <rpc/svc_soc.h>
  415. #endif /* !_RPC_SVC_H */