10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 22*722Smuffin /* 23*722Smuffin * Copyright 1984 Sun Microsystems, Inc. All rights reserved. 24*722Smuffin * Use is subject to license terms. 25*722Smuffin */ 26*722Smuffin 27*722Smuffin #ifndef _rpc_svc_h 28*722Smuffin #define _rpc_svc_h 29*722Smuffin 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * svc.h, Server-side remote procedure call interface. 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate 360Sstevel@tonic-gate /* 370Sstevel@tonic-gate * This interface must manage two items concerning remote procedure calling: 380Sstevel@tonic-gate * 390Sstevel@tonic-gate * 1) An arbitrary number of transport connections upon which rpc requests 400Sstevel@tonic-gate * are received. The two most notable transports are TCP and UDP; they are 410Sstevel@tonic-gate * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; 420Sstevel@tonic-gate * they in turn call xprt_register and xprt_unregister. 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * 2) An arbitrary number of locally registered services. Services are 450Sstevel@tonic-gate * described by the following four data: program number, version number, 460Sstevel@tonic-gate * "service dispatch" function, a transport handle, and a boolean that 470Sstevel@tonic-gate * indicates whether or not the exported program should be registered with a 480Sstevel@tonic-gate * local binder service; if true the program's number and version and the 490Sstevel@tonic-gate * port number from the transport handle are registered with the binder. 500Sstevel@tonic-gate * These data are registered with the rpc svc system via svc_register. 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * A service's dispatch function is called whenever an rpc request comes in 530Sstevel@tonic-gate * on a transport. The request's program and version numbers must match 540Sstevel@tonic-gate * those of the registered service. The dispatch function is passed two 550Sstevel@tonic-gate * parameters, struct svc_req * and SVCXPRT *, defined below. 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate 580Sstevel@tonic-gate enum xprt_stat { 590Sstevel@tonic-gate XPRT_DIED, 600Sstevel@tonic-gate XPRT_MOREREQS, 610Sstevel@tonic-gate XPRT_IDLE 620Sstevel@tonic-gate }; 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * Server side transport handle 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate typedef struct { 680Sstevel@tonic-gate int xp_sock; 690Sstevel@tonic-gate u_short xp_port; /* associated port number */ 700Sstevel@tonic-gate struct xp_ops { 710Sstevel@tonic-gate bool_t (*xp_recv)(); /* receive incomming requests */ 720Sstevel@tonic-gate enum xprt_stat (*xp_stat)(); /* get transport status */ 730Sstevel@tonic-gate bool_t (*xp_getargs)(); /* get arguments */ 740Sstevel@tonic-gate bool_t (*xp_reply)(); /* send reply */ 750Sstevel@tonic-gate bool_t (*xp_freeargs)(); /* free mem allocated for args */ 760Sstevel@tonic-gate void (*xp_destroy)(); /* destroy this struct */ 770Sstevel@tonic-gate } *xp_ops; 780Sstevel@tonic-gate int xp_addrlen; /* length of remote address */ 790Sstevel@tonic-gate struct sockaddr_in xp_raddr; /* remote address */ 800Sstevel@tonic-gate struct opaque_auth xp_verf; /* raw response verifier */ 810Sstevel@tonic-gate caddr_t xp_p1; /* private: for use by svc ops */ 820Sstevel@tonic-gate caddr_t xp_p2; /* private: for use by svc ops */ 830Sstevel@tonic-gate caddr_t xp_p3; /* private: for use by svc lib */ 840Sstevel@tonic-gate } SVCXPRT; 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* 870Sstevel@tonic-gate * Approved way of getting address of caller 880Sstevel@tonic-gate */ 890Sstevel@tonic-gate #define svc_getcaller(x) (&(x)->xp_raddr) 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * Operations defined on an SVCXPRT handle 930Sstevel@tonic-gate * 940Sstevel@tonic-gate * SVCXPRT *xprt; 950Sstevel@tonic-gate * struct rpc_msg *msg; 960Sstevel@tonic-gate * xdrproc_t xargs; 970Sstevel@tonic-gate * caddr_t argsp; 980Sstevel@tonic-gate */ 990Sstevel@tonic-gate #define SVC_RECV(xprt, msg) \ 1000Sstevel@tonic-gate (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 1010Sstevel@tonic-gate #define svc_recv(xprt, msg) \ 1020Sstevel@tonic-gate (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate #define SVC_STAT(xprt) \ 1050Sstevel@tonic-gate (*(xprt)->xp_ops->xp_stat)(xprt) 1060Sstevel@tonic-gate #define svc_stat(xprt) \ 1070Sstevel@tonic-gate (*(xprt)->xp_ops->xp_stat)(xprt) 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate #define SVC_GETARGS(xprt, xargs, argsp) \ 1100Sstevel@tonic-gate (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 1110Sstevel@tonic-gate #define svc_getargs(xprt, xargs, argsp) \ 1120Sstevel@tonic-gate (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate #define SVC_REPLY(xprt, msg) \ 1150Sstevel@tonic-gate (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 1160Sstevel@tonic-gate #define svc_reply(xprt, msg) \ 1170Sstevel@tonic-gate (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #define SVC_FREEARGS(xprt, xargs, argsp) \ 1200Sstevel@tonic-gate (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 1210Sstevel@tonic-gate #define svc_freeargs(xprt, xargs, argsp) \ 1220Sstevel@tonic-gate (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate #define SVC_DESTROY(xprt) \ 1250Sstevel@tonic-gate (*(xprt)->xp_ops->xp_destroy)(xprt) 1260Sstevel@tonic-gate #define svc_destroy(xprt) \ 1270Sstevel@tonic-gate (*(xprt)->xp_ops->xp_destroy)(xprt) 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate /* 1310Sstevel@tonic-gate * Service request 1320Sstevel@tonic-gate */ 1330Sstevel@tonic-gate struct svc_req { 1340Sstevel@tonic-gate u_long rq_prog; /* service program number */ 1350Sstevel@tonic-gate u_long rq_vers; /* service protocol version */ 1360Sstevel@tonic-gate u_long rq_proc; /* the desired procedure */ 1370Sstevel@tonic-gate struct opaque_auth rq_cred; /* raw creds from the wire */ 1380Sstevel@tonic-gate caddr_t rq_clntcred; /* read only cooked cred */ 1390Sstevel@tonic-gate SVCXPRT *rq_xprt; /* associated transport */ 1400Sstevel@tonic-gate }; 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate /* 1440Sstevel@tonic-gate * Service registration 1450Sstevel@tonic-gate * 1460Sstevel@tonic-gate * svc_register(xprt, prog, vers, dispatch, protocol) 1470Sstevel@tonic-gate * SVCXPRT *xprt; 1480Sstevel@tonic-gate * u_long prog; 1490Sstevel@tonic-gate * u_long vers; 1500Sstevel@tonic-gate * void (*dispatch)(); 1510Sstevel@tonic-gate * int protocol; like TCP or UDP, zero means do not register 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate extern bool_t svc_register(); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * Service un-registration 1570Sstevel@tonic-gate * 1580Sstevel@tonic-gate * svc_unregister(prog, vers) 1590Sstevel@tonic-gate * u_long prog; 1600Sstevel@tonic-gate * u_long vers; 1610Sstevel@tonic-gate */ 1620Sstevel@tonic-gate extern void svc_unregister(); 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* 1650Sstevel@tonic-gate * Transport registration. 1660Sstevel@tonic-gate * 1670Sstevel@tonic-gate * xprt_register(xprt) 1680Sstevel@tonic-gate * SVCXPRT *xprt; 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate extern void xprt_register(); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate /* 1730Sstevel@tonic-gate * Transport un-register 1740Sstevel@tonic-gate * 1750Sstevel@tonic-gate * xprt_unregister(xprt) 1760Sstevel@tonic-gate * SVCXPRT *xprt; 1770Sstevel@tonic-gate */ 1780Sstevel@tonic-gate extern void xprt_unregister(); 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate /* 1840Sstevel@tonic-gate * When the service routine is called, it must first check to see if it 1850Sstevel@tonic-gate * knows about the procedure; if not, it should call svcerr_noproc 1860Sstevel@tonic-gate * and return. If so, it should deserialize its arguments via 1870Sstevel@tonic-gate * SVC_GETARGS (defined above). If the deserialization does not work, 1880Sstevel@tonic-gate * svcerr_decode should be called followed by a return. Successful 1890Sstevel@tonic-gate * decoding of the arguments should be followed the execution of the 1900Sstevel@tonic-gate * procedure's code and a call to svc_sendreply. 1910Sstevel@tonic-gate * 1920Sstevel@tonic-gate * Also, if the service refuses to execute the procedure due to too- 1930Sstevel@tonic-gate * weak authentication parameters, svcerr_weakauth should be called. 1940Sstevel@tonic-gate * Note: do not confuse access-control failure with weak authentication! 1950Sstevel@tonic-gate * 1960Sstevel@tonic-gate * NB: In pure implementations of rpc, the caller always waits for a reply 1970Sstevel@tonic-gate * msg. This message is sent when svc_sendreply is called. 1980Sstevel@tonic-gate * Therefore pure service implementations should always call 1990Sstevel@tonic-gate * svc_sendreply even if the function logically returns void; use 2000Sstevel@tonic-gate * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows 2010Sstevel@tonic-gate * for the abuse of pure rpc via batched calling or pipelining. In the 2020Sstevel@tonic-gate * case of a batched call, svc_sendreply should NOT be called since 2030Sstevel@tonic-gate * this would send a return message, which is what batching tries to avoid. 2040Sstevel@tonic-gate * It is the service/protocol writer's responsibility to know which calls are 2050Sstevel@tonic-gate * batched and which are not. Warning: responding to batch calls may 2060Sstevel@tonic-gate * deadlock the caller and server processes! 2070Sstevel@tonic-gate */ 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate extern bool_t svc_sendreply(); 2100Sstevel@tonic-gate extern void svcerr_decode(); 2110Sstevel@tonic-gate extern void svcerr_weakauth(); 2120Sstevel@tonic-gate extern void svcerr_noproc(); 2130Sstevel@tonic-gate extern void svcerr_progvers(); 2140Sstevel@tonic-gate extern void svcerr_auth(); 2150Sstevel@tonic-gate extern void svcerr_noprog(); 2160Sstevel@tonic-gate extern void svcerr_systemerr(); 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate /* 2190Sstevel@tonic-gate * Lowest level dispatching -OR- who owns this process anyway. 2200Sstevel@tonic-gate * Somebody has to wait for incoming requests and then call the correct 2210Sstevel@tonic-gate * service routine. The routine svc_run does infinite waiting; i.e., 2220Sstevel@tonic-gate * svc_run never returns. 2230Sstevel@tonic-gate * Since another (co-existant) package may wish to selectively wait for 2240Sstevel@tonic-gate * incoming calls or other events outside of the rpc architecture, the 2250Sstevel@tonic-gate * routine svc_getreq is provided. It must be passed readfds, the 2260Sstevel@tonic-gate * "in-place" results of a select system call (see select, section 2). 2270Sstevel@tonic-gate */ 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate /* 2300Sstevel@tonic-gate * Global keeper of rpc service descriptors in use 2310Sstevel@tonic-gate * dynamic; must be inspected before each call to select 2320Sstevel@tonic-gate */ 2330Sstevel@tonic-gate extern fd_set svc_fdset; 2340Sstevel@tonic-gate #define svc_fds svc_fdset.fds_bits[0] /* compatibility */ 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate /* 2370Sstevel@tonic-gate * a small program implemented by the svc_rpc implementation itself; 2380Sstevel@tonic-gate * also see clnt.h for protocol numbers. 2390Sstevel@tonic-gate */ 2400Sstevel@tonic-gate extern void rpctest_service(); 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate extern void svc_getreq(); 2430Sstevel@tonic-gate extern void svc_getreqset(); /* takes fdset instead of int */ 2440Sstevel@tonic-gate extern void svc_run(); /* never returns */ 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate /* 2470Sstevel@tonic-gate * Socket to use on svcxxx_create call to get default socket 2480Sstevel@tonic-gate */ 2490Sstevel@tonic-gate #define RPC_ANYSOCK -1 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate /* 2520Sstevel@tonic-gate * These are the existing service side transport implementations 2530Sstevel@tonic-gate */ 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate /* 2560Sstevel@tonic-gate * Memory based rpc for testing and timing. 2570Sstevel@tonic-gate */ 2580Sstevel@tonic-gate extern SVCXPRT *svcraw_create(); 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate /* 2610Sstevel@tonic-gate * Udp based rpc. 2620Sstevel@tonic-gate */ 2630Sstevel@tonic-gate extern SVCXPRT *svcudp_create(); 2640Sstevel@tonic-gate extern SVCXPRT *svcudp_bufcreate(); 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* 2670Sstevel@tonic-gate * Tcp based rpc. 2680Sstevel@tonic-gate */ 2690Sstevel@tonic-gate extern SVCXPRT *svctcp_create(); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * Like svtcp_create(), except the routine takes any *open* UNIX file 2730Sstevel@tonic-gate * descriptor as its first input. 2740Sstevel@tonic-gate */ 2750Sstevel@tonic-gate SVCXPRT *svcfd_create(); 2760Sstevel@tonic-gate #else 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate /* 2790Sstevel@tonic-gate * Kernel udp based rpc. 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate extern SVCXPRT *svckudp_create(); 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate 284*722Smuffin #endif /* !_rpc_svc_h */ 285