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