master
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
82enum xprt_stat {
83 XPRT_DIED,
84 XPRT_MOREREQS,
85 XPRT_IDLE
86};
87
88/*
89 * Server side transport handle
90 */
91typedef 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 */
133typedef 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 */
146typedef 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 */
154struct 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 * Approved way of getting address of callee
169 */
170#define svc_getrpccallee(x) (&(x)->xp_ltaddr)
171
172/*
173 * Operations defined on an SVCXPRT handle
174 *
175 * SVCXPRT *xprt;
176 * struct rpc_msg *msg;
177 * xdrproc_t xargs;
178 * void * argsp;
179 */
180#define SVC_RECV(xprt, msg) \
181 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
182#define svc_recv(xprt, msg) \
183 (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
184
185#define SVC_STAT(xprt) \
186 (*(xprt)->xp_ops->xp_stat)(xprt)
187#define svc_stat(xprt) \
188 (*(xprt)->xp_ops->xp_stat)(xprt)
189
190#define SVC_GETARGS(xprt, xargs, argsp) \
191 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
192#define svc_getargs(xprt, xargs, argsp) \
193 (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
194
195#define SVC_REPLY(xprt, msg) \
196 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
197#define svc_reply(xprt, msg) \
198 (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
199
200#define SVC_FREEARGS(xprt, xargs, argsp) \
201 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
202#define svc_freeargs(xprt, xargs, argsp) \
203 (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
204
205#define SVC_DESTROY(xprt) \
206 (*(xprt)->xp_ops->xp_destroy)(xprt)
207#define svc_destroy(xprt) \
208 (*(xprt)->xp_ops->xp_destroy)(xprt)
209
210#define SVC_CONTROL(xprt, rq, in) \
211 (*(xprt)->xp_ops2->xp_control)((xprt), (rq), (in))
212
213#define SVC_EXT(xprt) \
214 ((SVCXPRT_EXT *) xprt->xp_p3)
215
216#define SVC_AUTH(xprt) \
217 (SVC_EXT(xprt)->xp_auth)
218
219/*
220 * Operations defined on an SVCAUTH handle
221 */
222#define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere) \
223 ((auth)->svc_ah_ops->svc_ah_wrap(auth, xdrs, xfunc, xwhere))
224#define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \
225 ((auth)->svc_ah_ops->svc_ah_unwrap(auth, xdrs, xfunc, xwhere))
226
227/*
228 * Service registration
229 *
230 * svc_reg(xprt, prog, vers, dispatch, nconf)
231 * const SVCXPRT *xprt;
232 * const rpcprog_t prog;
233 * const rpcvers_t vers;
234 * const void (*dispatch)(struct svc_req *, SVCXPRT *);
235 * const struct netconfig *nconf;
236 */
237
238__BEGIN_DECLS
239extern bool_t svc_reg(SVCXPRT *, const rpcprog_t, const rpcvers_t,
240 void (*)(struct svc_req *, SVCXPRT *),
241 const struct netconfig *);
242__END_DECLS
243
244/*
245 * Service un-registration
246 *
247 * svc_unreg(prog, vers)
248 * const rpcprog_t prog;
249 * const rpcvers_t vers;
250 */
251
252__BEGIN_DECLS
253extern void svc_unreg(const rpcprog_t, const rpcvers_t);
254__END_DECLS
255
256/*
257 * Transport registration.
258 *
259 * xprt_register(xprt)
260 * SVCXPRT *xprt;
261 */
262__BEGIN_DECLS
263extern void xprt_register(SVCXPRT *);
264__END_DECLS
265
266/*
267 * Transport un-register
268 *
269 * xprt_unregister(xprt)
270 * SVCXPRT *xprt;
271 */
272__BEGIN_DECLS
273extern void xprt_unregister(SVCXPRT *);
274__END_DECLS
275
276
277/*
278 * When the service routine is called, it must first check to see if it
279 * knows about the procedure; if not, it should call svcerr_noproc
280 * and return. If so, it should deserialize its arguments via
281 * SVC_GETARGS (defined above). If the deserialization does not work,
282 * svcerr_decode should be called followed by a return. Successful
283 * decoding of the arguments should be followed the execution of the
284 * procedure's code and a call to svc_sendreply.
285 *
286 * Also, if the service refuses to execute the procedure due to too-
287 * weak authentication parameters, svcerr_weakauth should be called.
288 * Note: do not confuse access-control failure with weak authentication!
289 *
290 * NB: In pure implementations of rpc, the caller always waits for a reply
291 * msg. This message is sent when svc_sendreply is called.
292 * Therefore pure service implementations should always call
293 * svc_sendreply even if the function logically returns void; use
294 * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
295 * for the abuse of pure rpc via batched calling or pipelining. In the
296 * case of a batched call, svc_sendreply should NOT be called since
297 * this would send a return message, which is what batching tries to avoid.
298 * It is the service/protocol writer's responsibility to know which calls are
299 * batched and which are not. Warning: responding to batch calls may
300 * deadlock the caller and server processes!
301 */
302
303__BEGIN_DECLS
304extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, void *);
305extern void svcerr_decode(SVCXPRT *);
306extern void svcerr_weakauth(SVCXPRT *);
307extern void svcerr_noproc(SVCXPRT *);
308extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
309extern void svcerr_auth(SVCXPRT *, enum auth_stat);
310extern void svcerr_noprog(SVCXPRT *);
311extern void svcerr_systemerr(SVCXPRT *);
312extern int rpc_reg(rpcprog_t, rpcvers_t, rpcproc_t,
313 char *(*)(char *), xdrproc_t, xdrproc_t,
314 char *);
315__END_DECLS
316
317/*
318 * Lowest level dispatching -OR- who owns this process anyway.
319 * Somebody has to wait for incoming requests and then call the correct
320 * service routine. The routine svc_run does infinite waiting; i.e.,
321 * svc_run never returns.
322 * Since another (co-existent) package may wish to selectively wait for
323 * incoming calls or other events outside of the rpc architecture, the
324 * routine svc_getreq is provided. It must be passed readfds, the
325 * "in-place" results of a select system call (see select, section 2).
326 */
327
328/*
329 * Global keeper of rpc service descriptors in use
330 * dynamic; must be inspected before each call to select
331 */
332extern int svc_maxfd;
333#ifdef FD_SETSIZE
334extern fd_set svc_fdset;
335#define svc_fds svc_fdset.fds_bits[0] /* compatibility */
336#else
337extern int svc_fds;
338#endif /* def FD_SETSIZE */
339
340/*
341 * A set of null auth methods used by any authentication protocols
342 * that don't need to inspect or modify the message body.
343 */
344extern SVCAUTH _svc_auth_null;
345
346/*
347 * a small program implemented by the svc_rpc implementation itself;
348 * also see clnt.h for protocol numbers.
349 */
350__BEGIN_DECLS
351extern void rpctest_service(void);
352__END_DECLS
353
354__BEGIN_DECLS
355extern SVCXPRT *svc_xprt_alloc(void);
356extern void svc_xprt_free(SVCXPRT *);
357extern void svc_getreq(int);
358extern void svc_getreqset(fd_set *);
359extern void svc_getreq_common(int);
360struct pollfd;
361extern void svc_getreq_poll(struct pollfd *, int);
362
363extern void svc_run(void);
364extern void svc_exit(void);
365__END_DECLS
366
367/*
368 * Socket to use on svcxxx_create call to get default socket
369 */
370#define RPC_ANYSOCK -1
371#define RPC_ANYFD RPC_ANYSOCK
372
373/*
374 * These are the existing service side transport implementations
375 */
376
377__BEGIN_DECLS
378/*
379 * Transport independent svc_create routine.
380 */
381extern int svc_create(void (*)(struct svc_req *, SVCXPRT *),
382 const rpcprog_t, const rpcvers_t, const char *);
383/*
384 * void (*dispatch)(struct svc_req *, SVCXPRT *);
385 * const rpcprog_t prognum; -- program number
386 * const rpcvers_t versnum; -- version number
387 * const char *nettype; -- network type
388 */
389
390
391/*
392 * Generic server creation routine. It takes a netconfig structure
393 * instead of a nettype.
394 */
395
396extern SVCXPRT *svc_tp_create(void (*)(struct svc_req *, SVCXPRT *),
397 const rpcprog_t, const rpcvers_t,
398 const struct netconfig *);
399 /*
400 * void (*dispatch)(struct svc_req *, SVCXPRT *);
401 * const rpcprog_t prognum; -- program number
402 * const rpcvers_t versnum; -- version number
403 * const struct netconfig *nconf; -- netconfig structure
404 */
405
406
407/*
408 * Generic TLI create routine
409 */
410extern SVCXPRT *svc_tli_create(const int, const struct netconfig *,
411 const struct t_bind *, const u_int,
412 const u_int);
413/*
414 * const int fd; -- connection end point
415 * const struct netconfig *nconf; -- netconfig structure for network
416 * const struct t_bind *bindaddr; -- local bind address
417 * const u_int sendsz; -- max sendsize
418 * const u_int recvsz; -- max recvsize
419 */
420
421/*
422 * Connectionless and connectionful create routines
423 */
424
425extern SVCXPRT *svc_vc_create(const int, const u_int, const u_int);
426/*
427 * const int fd; -- open connection end point
428 * const u_int sendsize; -- max send size
429 * const u_int recvsize; -- max recv size
430 */
431
432/*
433 * Added for compatibility to old rpc 4.0. Obsoleted by svc_vc_create().
434 */
435extern SVCXPRT *svcunix_create(int, u_int, u_int, char *);
436
437extern SVCXPRT *svc_dg_create(const int, const u_int, const u_int);
438 /*
439 * const int fd; -- open connection
440 * const u_int sendsize; -- max send size
441 * const u_int recvsize; -- max recv size
442 */
443
444
445/*
446 * the routine takes any *open* connection
447 * descriptor as its first input and is used for open connections.
448 */
449extern SVCXPRT *svc_fd_create(const int, const u_int, const u_int);
450/*
451 * const int fd; -- open connection end point
452 * const u_int sendsize; -- max send size
453 * const u_int recvsize; -- max recv size
454 */
455
456/*
457 * Added for compatibility to old rpc 4.0. Obsoleted by svc_fd_create().
458 */
459extern SVCXPRT *svcunixfd_create(int, u_int, u_int);
460
461/*
462 * Memory based rpc (for speed check and testing)
463 */
464extern SVCXPRT *svc_raw_create(void);
465
466/*
467 * svc_dg_enable_cache() enables the cache on dg transports.
468 */
469int svc_dg_enablecache(SVCXPRT *, const u_int);
470
471int __rpc_get_local_uid(SVCXPRT *_transp, uid_t *_uid);
472
473__END_DECLS
474
475
476/* for backward compatibility */
477#include <rpc/svc_soc.h>
478
479#endif /* !_RPC_SVC_H */