xref: /titanic_50/usr/src/lib/libbc/inc/include/rpc/svc.h (revision 5d54f3d8999eac1762fe0a8c7177d20f1f201fae)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*5d54f3d8Smuffin  * Copyright 1984 Sun Microsystems, Inc.  All rights reserved.
24*5d54f3d8Smuffin  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _rpc_svc_h
287c478bd9Sstevel@tonic-gate #define	_rpc_svc_h
297c478bd9Sstevel@tonic-gate 
30*5d54f3d8Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*5d54f3d8Smuffin 
32*5d54f3d8Smuffin /*
33*5d54f3d8Smuffin  * svc.h, Server-side remote procedure call interface.
34*5d54f3d8Smuffin  */
35*5d54f3d8Smuffin 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * This interface must manage two items concerning remote procedure calling:
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * 1) An arbitrary number of transport connections upon which rpc requests
407c478bd9Sstevel@tonic-gate  * are received.  The two most notable transports are TCP and UDP;  they are
417c478bd9Sstevel@tonic-gate  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
427c478bd9Sstevel@tonic-gate  * they in turn call xprt_register and xprt_unregister.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * 2) An arbitrary number of locally registered services.  Services are
457c478bd9Sstevel@tonic-gate  * described by the following four data: program number, version number,
467c478bd9Sstevel@tonic-gate  * "service dispatch" function, a transport handle, and a boolean that
477c478bd9Sstevel@tonic-gate  * indicates whether or not the exported program should be registered with a
487c478bd9Sstevel@tonic-gate  * local binder service;  if true the program's number and version and the
497c478bd9Sstevel@tonic-gate  * port number from the transport handle are registered with the binder.
507c478bd9Sstevel@tonic-gate  * These data are registered with the rpc svc system via svc_register.
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * A service's dispatch function is called whenever an rpc request comes in
537c478bd9Sstevel@tonic-gate  * on a transport.  The request's program and version numbers must match
547c478bd9Sstevel@tonic-gate  * those of the registered service.  The dispatch function is passed two
557c478bd9Sstevel@tonic-gate  * parameters, struct svc_req * and SVCXPRT *, defined below.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate enum xprt_stat {
597c478bd9Sstevel@tonic-gate 	XPRT_DIED,
607c478bd9Sstevel@tonic-gate 	XPRT_MOREREQS,
617c478bd9Sstevel@tonic-gate 	XPRT_IDLE
627c478bd9Sstevel@tonic-gate };
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Server side transport handle
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate typedef struct {
687c478bd9Sstevel@tonic-gate 	int		xp_sock;
697c478bd9Sstevel@tonic-gate 	u_short		xp_port;	 /* associated port number */
707c478bd9Sstevel@tonic-gate 	struct xp_ops {
717c478bd9Sstevel@tonic-gate 	    bool_t	(*xp_recv)();	 /* receive incomming requests */
727c478bd9Sstevel@tonic-gate 	    enum xprt_stat (*xp_stat)(); /* get transport status */
737c478bd9Sstevel@tonic-gate 	    bool_t	(*xp_getargs)(); /* get arguments */
747c478bd9Sstevel@tonic-gate 	    bool_t	(*xp_reply)();	 /* send reply */
757c478bd9Sstevel@tonic-gate 	    bool_t	(*xp_freeargs)(); /* free mem allocated for args */
767c478bd9Sstevel@tonic-gate 	    void	(*xp_destroy)(); /* destroy this struct */
777c478bd9Sstevel@tonic-gate 	} *xp_ops;
787c478bd9Sstevel@tonic-gate 	int		xp_addrlen;	 /* length of remote address */
797c478bd9Sstevel@tonic-gate 	struct sockaddr_in xp_raddr;	 /* remote address */
807c478bd9Sstevel@tonic-gate 	struct opaque_auth xp_verf;	 /* raw response verifier */
817c478bd9Sstevel@tonic-gate 	caddr_t		xp_p1;		 /* private: for use by svc ops */
827c478bd9Sstevel@tonic-gate 	caddr_t		xp_p2;		 /* private: for use by svc ops */
837c478bd9Sstevel@tonic-gate 	caddr_t		xp_p3;		 /* private: for use by svc lib */
847c478bd9Sstevel@tonic-gate } SVCXPRT;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  *  Approved way of getting address of caller
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate #define	svc_getcaller(x) (&(x)->xp_raddr)
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Operations defined on an SVCXPRT handle
937c478bd9Sstevel@tonic-gate  *
947c478bd9Sstevel@tonic-gate  * SVCXPRT		*xprt;
957c478bd9Sstevel@tonic-gate  * struct rpc_msg	*msg;
967c478bd9Sstevel@tonic-gate  * xdrproc_t		 xargs;
977c478bd9Sstevel@tonic-gate  * caddr_t		 argsp;
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate #define	SVC_RECV(xprt, msg)				\
1007c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
1017c478bd9Sstevel@tonic-gate #define	svc_recv(xprt, msg)				\
1027c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	SVC_STAT(xprt)					\
1057c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_stat)(xprt)
1067c478bd9Sstevel@tonic-gate #define	svc_stat(xprt)					\
1077c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_stat)(xprt)
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #define	SVC_GETARGS(xprt, xargs, argsp)			\
1107c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
1117c478bd9Sstevel@tonic-gate #define	svc_getargs(xprt, xargs, argsp)			\
1127c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	SVC_REPLY(xprt, msg)				\
1157c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
1167c478bd9Sstevel@tonic-gate #define	svc_reply(xprt, msg)				\
1177c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	SVC_FREEARGS(xprt, xargs, argsp)		\
1207c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
1217c478bd9Sstevel@tonic-gate #define	svc_freeargs(xprt, xargs, argsp)		\
1227c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #define	SVC_DESTROY(xprt)				\
1257c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_destroy)(xprt)
1267c478bd9Sstevel@tonic-gate #define	svc_destroy(xprt)				\
1277c478bd9Sstevel@tonic-gate 	(*(xprt)->xp_ops->xp_destroy)(xprt)
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * Service request
1327c478bd9Sstevel@tonic-gate  */
1337c478bd9Sstevel@tonic-gate struct svc_req {
1347c478bd9Sstevel@tonic-gate 	u_long		rq_prog;	/* service program number */
1357c478bd9Sstevel@tonic-gate 	u_long		rq_vers;	/* service protocol version */
1367c478bd9Sstevel@tonic-gate 	u_long		rq_proc;	/* the desired procedure */
1377c478bd9Sstevel@tonic-gate 	struct opaque_auth rq_cred;	/* raw creds from the wire */
1387c478bd9Sstevel@tonic-gate 	caddr_t		rq_clntcred;	/* read only cooked cred */
1397c478bd9Sstevel@tonic-gate 	SVCXPRT	*rq_xprt;		/* associated transport */
1407c478bd9Sstevel@tonic-gate };
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * Service registration
1457c478bd9Sstevel@tonic-gate  *
1467c478bd9Sstevel@tonic-gate  * svc_register(xprt, prog, vers, dispatch, protocol)
1477c478bd9Sstevel@tonic-gate  *	SVCXPRT *xprt;
1487c478bd9Sstevel@tonic-gate  *	u_long prog;
1497c478bd9Sstevel@tonic-gate  *	u_long vers;
1507c478bd9Sstevel@tonic-gate  *	void (*dispatch)();
1517c478bd9Sstevel@tonic-gate  *	int protocol;   like TCP or UDP, zero means do not register
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate extern bool_t	svc_register();
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * Service un-registration
1577c478bd9Sstevel@tonic-gate  *
1587c478bd9Sstevel@tonic-gate  * svc_unregister(prog, vers)
1597c478bd9Sstevel@tonic-gate  *	u_long prog;
1607c478bd9Sstevel@tonic-gate  *	u_long vers;
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate extern void	svc_unregister();
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate  * Transport registration.
1667c478bd9Sstevel@tonic-gate  *
1677c478bd9Sstevel@tonic-gate  * xprt_register(xprt)
1687c478bd9Sstevel@tonic-gate  *	SVCXPRT *xprt;
1697c478bd9Sstevel@tonic-gate  */
1707c478bd9Sstevel@tonic-gate extern void	xprt_register();
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate  * Transport un-register
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  * xprt_unregister(xprt)
1767c478bd9Sstevel@tonic-gate  *	SVCXPRT *xprt;
1777c478bd9Sstevel@tonic-gate  */
1787c478bd9Sstevel@tonic-gate extern void	xprt_unregister();
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * When the service routine is called, it must first check to see if it
1857c478bd9Sstevel@tonic-gate  * knows about the procedure;  if not, it should call svcerr_noproc
1867c478bd9Sstevel@tonic-gate  * and return.  If so, it should deserialize its arguments via
1877c478bd9Sstevel@tonic-gate  * SVC_GETARGS (defined above).  If the deserialization does not work,
1887c478bd9Sstevel@tonic-gate  * svcerr_decode should be called followed by a return.  Successful
1897c478bd9Sstevel@tonic-gate  * decoding of the arguments should be followed the execution of the
1907c478bd9Sstevel@tonic-gate  * procedure's code and a call to svc_sendreply.
1917c478bd9Sstevel@tonic-gate  *
1927c478bd9Sstevel@tonic-gate  * Also, if the service refuses to execute the procedure due to too-
1937c478bd9Sstevel@tonic-gate  * weak authentication parameters, svcerr_weakauth should be called.
1947c478bd9Sstevel@tonic-gate  * Note: do not confuse access-control failure with weak authentication!
1957c478bd9Sstevel@tonic-gate  *
1967c478bd9Sstevel@tonic-gate  * NB: In pure implementations of rpc, the caller always waits for a reply
1977c478bd9Sstevel@tonic-gate  * msg.  This message is sent when svc_sendreply is called.
1987c478bd9Sstevel@tonic-gate  * Therefore pure service implementations should always call
1997c478bd9Sstevel@tonic-gate  * svc_sendreply even if the function logically returns void;  use
2007c478bd9Sstevel@tonic-gate  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
2017c478bd9Sstevel@tonic-gate  * for the abuse of pure rpc via batched calling or pipelining.  In the
2027c478bd9Sstevel@tonic-gate  * case of a batched call, svc_sendreply should NOT be called since
2037c478bd9Sstevel@tonic-gate  * this would send a return message, which is what batching tries to avoid.
2047c478bd9Sstevel@tonic-gate  * It is the service/protocol writer's responsibility to know which calls are
2057c478bd9Sstevel@tonic-gate  * batched and which are not.  Warning: responding to batch calls may
2067c478bd9Sstevel@tonic-gate  * deadlock the caller and server processes!
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate extern bool_t	svc_sendreply();
2107c478bd9Sstevel@tonic-gate extern void	svcerr_decode();
2117c478bd9Sstevel@tonic-gate extern void	svcerr_weakauth();
2127c478bd9Sstevel@tonic-gate extern void	svcerr_noproc();
2137c478bd9Sstevel@tonic-gate extern void	svcerr_progvers();
2147c478bd9Sstevel@tonic-gate extern void	svcerr_auth();
2157c478bd9Sstevel@tonic-gate extern void	svcerr_noprog();
2167c478bd9Sstevel@tonic-gate extern void	svcerr_systemerr();
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * Lowest level dispatching -OR- who owns this process anyway.
2207c478bd9Sstevel@tonic-gate  * Somebody has to wait for incoming requests and then call the correct
2217c478bd9Sstevel@tonic-gate  * service routine.  The routine svc_run does infinite waiting; i.e.,
2227c478bd9Sstevel@tonic-gate  * svc_run never returns.
2237c478bd9Sstevel@tonic-gate  * Since another (co-existant) package may wish to selectively wait for
2247c478bd9Sstevel@tonic-gate  * incoming calls or other events outside of the rpc architecture, the
2257c478bd9Sstevel@tonic-gate  * routine svc_getreq is provided.  It must be passed readfds, the
2267c478bd9Sstevel@tonic-gate  * "in-place" results of a select system call (see select, section 2).
2277c478bd9Sstevel@tonic-gate  */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate  * Global keeper of rpc service descriptors in use
2317c478bd9Sstevel@tonic-gate  * dynamic; must be inspected before each call to select
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate extern fd_set svc_fdset;
2347c478bd9Sstevel@tonic-gate #define	svc_fds svc_fdset.fds_bits[0]	/* compatibility */
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate  * a small program implemented by the svc_rpc implementation itself;
2387c478bd9Sstevel@tonic-gate  * also see clnt.h for protocol numbers.
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate extern void rpctest_service();
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate extern void	svc_getreq();
2437c478bd9Sstevel@tonic-gate extern void	svc_getreqset();	/* takes fdset instead of int */
2447c478bd9Sstevel@tonic-gate extern void	svc_run();		/* never returns */
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate  * Socket to use on svcxxx_create call to get default socket
2487c478bd9Sstevel@tonic-gate  */
2497c478bd9Sstevel@tonic-gate #define	RPC_ANYSOCK	-1
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  * These are the existing service side transport implementations
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate /*
2567c478bd9Sstevel@tonic-gate  * Memory based rpc for testing and timing.
2577c478bd9Sstevel@tonic-gate  */
2587c478bd9Sstevel@tonic-gate extern SVCXPRT *svcraw_create();
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate /*
2617c478bd9Sstevel@tonic-gate  * Udp based rpc.
2627c478bd9Sstevel@tonic-gate  */
2637c478bd9Sstevel@tonic-gate extern SVCXPRT *svcudp_create();
2647c478bd9Sstevel@tonic-gate extern SVCXPRT *svcudp_bufcreate();
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * Tcp based rpc.
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate extern SVCXPRT *svctcp_create();
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate /*
2727c478bd9Sstevel@tonic-gate  * Like svtcp_create(), except the routine takes any *open* UNIX file
2737c478bd9Sstevel@tonic-gate  * descriptor as its first input.
2747c478bd9Sstevel@tonic-gate  */
2757c478bd9Sstevel@tonic-gate SVCXPRT *svcfd_create();
2767c478bd9Sstevel@tonic-gate #else
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate /*
2797c478bd9Sstevel@tonic-gate  * Kernel udp based rpc.
2807c478bd9Sstevel@tonic-gate  */
2817c478bd9Sstevel@tonic-gate extern SVCXPRT *svckudp_create();
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate #endif /* !_rpc_svc_h */
285