1 /* $NetBSD: svc.h,v 1.20 2002/11/08 00:10:44 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, MERCHANTIBILITY 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 * @(#)svc.h 1.27 94/04/25 SMI 33 */ 34 35 /* 36 * svc.h, Server-side remote procedure call interface. 37 * 38 * Copyright (C) 1986-1993 by Sun Microsystems, Inc. 39 */ 40 41 #ifndef _RPC_SVC_H_ 42 #define _RPC_SVC_H_ 43 #include <sys/cdefs.h> 44 45 #include <rpc/rpc_com.h> 46 47 /* 48 * This interface must manage two items concerning remote procedure calling: 49 * 50 * 1) An arbitrary number of transport connections upon which rpc requests 51 * are received. The two most notable transports are TCP and UDP; they are 52 * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; 53 * they in turn call xprt_register and xprt_unregister. 54 * 55 * 2) An arbitrary number of locally registered services. Services are 56 * described by the following four data: program number, version number, 57 * "service dispatch" function, a transport handle, and a boolean that 58 * indicates whether or not the exported program should be registered with a 59 * local binder service; if true the program's number and version and the 60 * port number from the transport handle are registered with the binder. 61 * These data are registered with the rpc svc system via svc_register. 62 * 63 * A service's dispatch function is called whenever an rpc request comes in 64 * on a transport. The request's program and version numbers must match 65 * those of the registered service. The dispatch function is passed two 66 * parameters, struct svc_req * and SVCXPRT *, defined below. 67 */ 68 69 /* 70 * Service control requests 71 */ 72 #define SVCGET_VERSQUIET 1 73 #define SVCSET_VERSQUIET 2 74 #define SVCGET_CONNMAXREC 3 75 #define SVCSET_CONNMAXREC 4 76 77 78 enum xprt_stat { 79 XPRT_DIED, 80 XPRT_MOREREQS, 81 XPRT_IDLE 82 }; 83 84 /* 85 * Server side transport handle 86 */ 87 typedef struct __rpc_svcxprt { 88 int xp_fd; 89 u_short xp_port; /* associated port number */ 90 const struct xp_ops { 91 /* receive incomming requests */ 92 bool_t (*xp_recv) __P((struct __rpc_svcxprt *, 93 struct rpc_msg *)); 94 /* get transport status */ 95 enum xprt_stat (*xp_stat) __P((struct __rpc_svcxprt *)); 96 /* get arguments */ 97 bool_t (*xp_getargs) __P((struct __rpc_svcxprt *, xdrproc_t, 98 caddr_t)); 99 /* send reply */ 100 bool_t (*xp_reply) __P((struct __rpc_svcxprt *, 101 struct rpc_msg *)); 102 /* free mem allocated for args */ 103 bool_t (*xp_freeargs) __P((struct __rpc_svcxprt *, xdrproc_t, 104 caddr_t)); 105 /* destroy this struct */ 106 void (*xp_destroy) __P((struct __rpc_svcxprt *)); 107 } *xp_ops; 108 int xp_addrlen; /* length of remote address */ 109 struct sockaddr_in xp_raddr; /* rem. addr. (backward ABI compat) */ 110 /* XXX - fvdl stick this here for ABI backward compat reasons */ 111 const struct xp_ops2 { 112 /* catch-all function */ 113 bool_t (*xp_control) __P((struct __rpc_svcxprt *, const u_int, 114 void *)); 115 } *xp_ops2; 116 char *xp_tp; /* transport provider device name */ 117 char *xp_netid; /* network token */ 118 struct netbuf xp_ltaddr; /* local transport address */ 119 struct netbuf xp_rtaddr; /* remote transport address */ 120 struct opaque_auth xp_verf; /* raw response verifier */ 121 void *xp_p1; /* private: for use by svc ops */ 122 void *xp_p2; /* private: for use by svc ops */ 123 void *xp_p3; /* private: for use by svc lib */ 124 int xp_type; /* transport type */ 125 } SVCXPRT; 126 127 /* 128 * Service request 129 */ 130 struct svc_req { 131 u_int32_t rq_prog; /* service program number */ 132 u_int32_t rq_vers; /* service protocol version */ 133 u_int32_t rq_proc; /* the desired procedure */ 134 struct opaque_auth rq_cred; /* raw creds from the wire */ 135 void *rq_clntcred; /* read only cooked cred */ 136 SVCXPRT *rq_xprt; /* associated transport */ 137 }; 138 139 /* 140 * Approved way of getting address of caller 141 */ 142 #define svc_getrpccaller(x) (&(x)->xp_rtaddr) 143 144 /* 145 * NetBSD-only definition to get the creds of the caller (AF_LOCAL). 146 */ 147 #define __svc_getcallercreds(x) ((struct sockcred *)(x)->xp_p2) 148 149 /* 150 * Operations defined on an SVCXPRT handle 151 * 152 * SVCXPRT *xprt; 153 * struct rpc_msg *msg; 154 * xdrproc_t xargs; 155 * caddr_t argsp; 156 */ 157 #define SVC_RECV(xprt, msg) \ 158 (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 159 #define svc_recv(xprt, msg) \ 160 (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 161 162 #define SVC_STAT(xprt) \ 163 (*(xprt)->xp_ops->xp_stat)(xprt) 164 #define svc_stat(xprt) \ 165 (*(xprt)->xp_ops->xp_stat)(xprt) 166 167 #define SVC_GETARGS(xprt, xargs, argsp) \ 168 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 169 #define svc_getargs(xprt, xargs, argsp) \ 170 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 171 172 #define SVC_REPLY(xprt, msg) \ 173 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 174 #define svc_reply(xprt, msg) \ 175 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 176 177 #define SVC_FREEARGS(xprt, xargs, argsp) \ 178 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 179 #define svc_freeargs(xprt, xargs, argsp) \ 180 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 181 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 187 #define SVC_CONTROL(xprt, rq, in) \ 188 (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in)) 189 190 /* 191 * Service registration 192 * 193 * svc_reg(xprt, prog, vers, dispatch, nconf) 194 * const SVCXPRT *xprt; 195 * const rpcprog_t prog; 196 * const rpcvers_t vers; 197 * const void (*dispatch)(...); 198 * const struct netconfig *nconf; 199 */ 200 201 __BEGIN_DECLS 202 extern bool_t svc_reg __P((SVCXPRT *, const rpcprog_t, const rpcvers_t, 203 void (*) __P((struct svc_req *, SVCXPRT *)), 204 const struct netconfig *)); 205 __END_DECLS 206 207 /* 208 * Service un-registration 209 * 210 * svc_unreg(prog, vers) 211 * const rpcprog_t prog; 212 * const rpcvers_t vers; 213 */ 214 215 __BEGIN_DECLS 216 extern void svc_unreg __P((const rpcprog_t, const rpcvers_t)); 217 __END_DECLS 218 219 /* 220 * Transport registration. 221 * 222 * xprt_register(xprt) 223 * SVCXPRT *xprt; 224 */ 225 __BEGIN_DECLS 226 extern void xprt_register __P((SVCXPRT *)); 227 __END_DECLS 228 229 /* 230 * Transport un-register 231 * 232 * xprt_unregister(xprt) 233 * SVCXPRT *xprt; 234 */ 235 __BEGIN_DECLS 236 extern void xprt_unregister __P((SVCXPRT *)); 237 __END_DECLS 238 239 240 /* 241 * When the service routine is called, it must first check to see if it 242 * knows about the procedure; if not, it should call svcerr_noproc 243 * and return. If so, it should deserialize its arguments via 244 * SVC_GETARGS (defined above). If the deserialization does not work, 245 * svcerr_decode should be called followed by a return. Successful 246 * decoding of the arguments should be followed the execution of the 247 * procedure's code and a call to svc_sendreply. 248 * 249 * Also, if the service refuses to execute the procedure due to too- 250 * weak authentication parameters, svcerr_weakauth should be called. 251 * Note: do not confuse access-control failure with weak authentication! 252 * 253 * NB: In pure implementations of rpc, the caller always waits for a reply 254 * msg. This message is sent when svc_sendreply is called. 255 * Therefore pure service implementations should always call 256 * svc_sendreply even if the function logically returns void; use 257 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows 258 * for the abuse of pure rpc via batched calling or pipelining. In the 259 * case of a batched call, svc_sendreply should NOT be called since 260 * this would send a return message, which is what batching tries to avoid. 261 * It is the service/protocol writer's responsibility to know which calls are 262 * batched and which are not. Warning: responding to batch calls may 263 * deadlock the caller and server processes! 264 */ 265 266 __BEGIN_DECLS 267 extern bool_t svc_sendreply __P((SVCXPRT *, xdrproc_t, char *)); 268 extern void svcerr_decode __P((SVCXPRT *)); 269 extern void svcerr_weakauth __P((SVCXPRT *)); 270 extern void svcerr_noproc __P((SVCXPRT *)); 271 extern void svcerr_progvers __P((SVCXPRT *, rpcvers_t, rpcvers_t)); 272 extern void svcerr_auth __P((SVCXPRT *, enum auth_stat)); 273 extern void svcerr_noprog __P((SVCXPRT *)); 274 extern void svcerr_systemerr __P((SVCXPRT *)); 275 extern int rpc_reg __P((rpcprog_t, rpcvers_t, rpcproc_t, 276 char *(*) __P((char *)), xdrproc_t, xdrproc_t, 277 char *)); 278 __END_DECLS 279 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 /* 292 * Global keeper of rpc service descriptors in use 293 * dynamic; must be inspected before each call to select 294 */ 295 extern int svc_maxfd; 296 #ifdef FD_SETSIZE 297 extern fd_set svc_fdset; 298 #define svc_fds svc_fdset.fds_bits[0] /* compatibility */ 299 #else 300 extern int svc_fds; 301 #endif /* def FD_SETSIZE */ 302 303 /* 304 * a small program implemented by the svc_rpc implementation itself; 305 * also see clnt.h for protocol numbers. 306 */ 307 __BEGIN_DECLS 308 extern void rpctest_service __P((void)); 309 __END_DECLS 310 311 __BEGIN_DECLS 312 extern void svc_getreq __P((int)); 313 extern void svc_getreqset __P((fd_set *)); 314 extern void svc_getreq_common __P((int)); 315 struct pollfd; 316 extern void svc_getreq_poll __P((struct pollfd *, int)); 317 318 extern void svc_run __P((void)); 319 extern void svc_exit __P((void)); 320 __END_DECLS 321 322 /* 323 * Socket to use on svcxxx_create call to get default socket 324 */ 325 #define RPC_ANYSOCK -1 326 #define RPC_ANYFD RPC_ANYSOCK 327 328 /* 329 * These are the existing service side transport implementations 330 */ 331 332 __BEGIN_DECLS 333 /* 334 * Transport independent svc_create routine. 335 */ 336 extern int svc_create __P((void (*) __P((struct svc_req *, SVCXPRT *)), 337 const rpcprog_t, const rpcvers_t, const char *)); 338 /* 339 * void (*dispatch)(...); -- dispatch routine 340 * const rpcprog_t prognum; -- program number 341 * const rpcvers_t versnum; -- version number 342 * const char *nettype; -- network type 343 */ 344 345 346 /* 347 * Generic server creation routine. It takes a netconfig structure 348 * instead of a nettype. 349 */ 350 351 extern SVCXPRT *svc_tp_create __P((void (*) __P((struct svc_req *, SVCXPRT *)), 352 const rpcprog_t, const rpcvers_t, 353 const struct netconfig *)); 354 /* 355 * void (*dispatch)(...); -- dispatch routine 356 * const rpcprog_t prognum; -- program number 357 * const rpcvers_t versnum; -- version number 358 * const struct netconfig *nconf; -- netconfig structure 359 */ 360 361 362 /* 363 * Generic TLI create routine 364 */ 365 extern SVCXPRT *svc_tli_create __P((const int, const struct netconfig *, 366 const struct t_bind *, const u_int, 367 const u_int)); 368 /* 369 * const int fd; -- connection end point 370 * const struct netconfig *nconf; -- netconfig structure for network 371 * const struct t_bind *bindaddr; -- local bind address 372 * const u_int sendsz; -- max sendsize 373 * const u_int recvsz; -- max recvsize 374 */ 375 376 /* 377 * Connectionless and connectionful create routines 378 */ 379 380 extern SVCXPRT *svc_vc_create __P((const int, const u_int, const u_int)); 381 /* 382 * const int fd; -- open connection end point 383 * const u_int sendsize; -- max send size 384 * const u_int recvsize; -- max recv size 385 */ 386 387 extern SVCXPRT *svc_dg_create __P((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 __P((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 * Memory based rpc (for speed check and testing) 408 */ 409 extern SVCXPRT *svc_raw_create __P((void)); 410 411 /* 412 * svc_dg_enable_cache() enables the cache on dg transports. 413 */ 414 int svc_dg_enablecache __P((SVCXPRT *, const u_int)); 415 416 __END_DECLS 417 418 419 /* for backward compatibility */ 420 #include <rpc/svc_soc.h> 421 422 #endif /* !_RPC_SVC_H_ */ 423