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