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