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