xref: /onnv-gate/usr/src/stand/lib/fs/nfs/clnt.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  * clnt.h - Client side remote procedure call interface.
27*0Sstevel@tonic-gate  * Stripped down sockets based client for boot.
28*0Sstevel@tonic-gate  */
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #ifndef _RPC_CLNT_H
31*0Sstevel@tonic-gate #define	_RPC_CLNT_H
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #include <sys/types.h>
36*0Sstevel@tonic-gate #include <rpc/clnt_stat.h>
37*0Sstevel@tonic-gate #include <rpc/auth.h>
38*0Sstevel@tonic-gate #include <netinet/in.h>
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #ifdef	__cplusplus
41*0Sstevel@tonic-gate extern "C" {
42*0Sstevel@tonic-gate #endif
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate /*
45*0Sstevel@tonic-gate  * Error info.
46*0Sstevel@tonic-gate  */
47*0Sstevel@tonic-gate struct rpc_err {
48*0Sstevel@tonic-gate 	enum clnt_stat re_status;
49*0Sstevel@tonic-gate 	union {
50*0Sstevel@tonic-gate 		int RE_errno;		/* realated system error */
51*0Sstevel@tonic-gate 		enum auth_stat RE_why;	/* why the auth error occurred */
52*0Sstevel@tonic-gate 	} ru;
53*0Sstevel@tonic-gate #define	re_errno	ru.RE_errno
54*0Sstevel@tonic-gate #define	re_why		ru.RE_why
55*0Sstevel@tonic-gate };
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate /*
59*0Sstevel@tonic-gate  * Client rpc handle.
60*0Sstevel@tonic-gate  * Created by individual implementations, see e.g. rpc_udp.c.
61*0Sstevel@tonic-gate  * Client is responsible for initializing auth, see e.g. auth_none.c.
62*0Sstevel@tonic-gate  */
63*0Sstevel@tonic-gate typedef struct __client {
64*0Sstevel@tonic-gate 	AUTH	*cl_auth;			/* authenticator */
65*0Sstevel@tonic-gate 	struct clnt_ops {
66*0Sstevel@tonic-gate 				/* call remote procedure */
67*0Sstevel@tonic-gate 		enum clnt_stat	(*cl_call)(struct __client *, rpcproc_t,
68*0Sstevel@tonic-gate 					xdrproc_t, caddr_t, xdrproc_t,
69*0Sstevel@tonic-gate 					caddr_t, struct timeval);
70*0Sstevel@tonic-gate 				/* abort a call */
71*0Sstevel@tonic-gate 		void		(*cl_abort)(/* various */);
72*0Sstevel@tonic-gate 				/* get specific error code */
73*0Sstevel@tonic-gate 		void		(*cl_geterr)(struct __client *,
74*0Sstevel@tonic-gate 					struct rpc_err *);
75*0Sstevel@tonic-gate 				/* frees results */
76*0Sstevel@tonic-gate 		bool_t		(*cl_freeres)(struct __client *, xdrproc_t,
77*0Sstevel@tonic-gate 					caddr_t);
78*0Sstevel@tonic-gate 				/* destroy this structure */
79*0Sstevel@tonic-gate 		void		(*cl_destroy)(struct __client *);
80*0Sstevel@tonic-gate 				/* the ioctl() of rpc */
81*0Sstevel@tonic-gate 		bool_t		(*cl_control)(struct __client *, int, char *);
82*0Sstevel@tonic-gate 	} *cl_ops;
83*0Sstevel@tonic-gate 	caddr_t			cl_private;	/* private stuff */
84*0Sstevel@tonic-gate } CLIENT;
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate /*
88*0Sstevel@tonic-gate  * client side rpc interface ops
89*0Sstevel@tonic-gate  *
90*0Sstevel@tonic-gate  * Parameter types are:
91*0Sstevel@tonic-gate  *
92*0Sstevel@tonic-gate  */
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate /*
95*0Sstevel@tonic-gate  * enum clnt_stat
96*0Sstevel@tonic-gate  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
97*0Sstevel@tonic-gate  * 	CLIENT *rh;
98*0Sstevel@tonic-gate  *	ulong_t proc;
99*0Sstevel@tonic-gate  *	xdrproc_t xargs;
100*0Sstevel@tonic-gate  *	caddr_t argsp;
101*0Sstevel@tonic-gate  *	xdrproc_t xres;
102*0Sstevel@tonic-gate  *	caddr_t resp;
103*0Sstevel@tonic-gate  *	struct timeval timeout;
104*0Sstevel@tonic-gate  */
105*0Sstevel@tonic-gate #define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)	\
106*0Sstevel@tonic-gate 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate /*
109*0Sstevel@tonic-gate  * void
110*0Sstevel@tonic-gate  * CLNT_ABORT(rh);
111*0Sstevel@tonic-gate  * 	CLIENT *rh;
112*0Sstevel@tonic-gate  */
113*0Sstevel@tonic-gate #define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate /*
116*0Sstevel@tonic-gate  * struct rpc_err
117*0Sstevel@tonic-gate  * CLNT_GETERR(rh);
118*0Sstevel@tonic-gate  * 	CLIENT *rh;
119*0Sstevel@tonic-gate  */
120*0Sstevel@tonic-gate #define	CLNT_GETERR(rh, errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate /*
123*0Sstevel@tonic-gate  * bool_t
124*0Sstevel@tonic-gate  * CLNT_FREERES(rh, xres, resp);
125*0Sstevel@tonic-gate  * 	CLIENT *rh;
126*0Sstevel@tonic-gate  *	xdrproc_t xres;
127*0Sstevel@tonic-gate  *	caddr_t resp;
128*0Sstevel@tonic-gate  */
129*0Sstevel@tonic-gate #define	CLNT_FREERES(rh, xres, resp) ((*(rh)->cl_ops->cl_freeres)\
130*0Sstevel@tonic-gate 	(rh, xres, resp))
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate /*
133*0Sstevel@tonic-gate  * bool_t
134*0Sstevel@tonic-gate  * CLNT_CONTROL(cl, request, info)
135*0Sstevel@tonic-gate  *	CLIENT *cl;
136*0Sstevel@tonic-gate  *	uint_t request;
137*0Sstevel@tonic-gate  *	char *info;
138*0Sstevel@tonic-gate  */
139*0Sstevel@tonic-gate #define	CLNT_CONTROL(cl, rq, in) ((*(cl)->cl_ops->cl_control)(cl, rq, in))
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate /*
142*0Sstevel@tonic-gate  * control operations that apply to both udp and tcp transports
143*0Sstevel@tonic-gate  */
144*0Sstevel@tonic-gate #define	CLSET_TIMEOUT		1   /* set timeout (timeval) */
145*0Sstevel@tonic-gate #define	CLGET_TIMEOUT		2   /* get timeout (timeval) */
146*0Sstevel@tonic-gate #define	CLGET_SERVER_ADDR	3   /* get server's address (sockaddr) */
147*0Sstevel@tonic-gate #define	CLGET_FD		6   /* get connections file descriptor */
148*0Sstevel@tonic-gate #define	CLSET_FD_CLOSE		8   /* close fd while clnt_destroy */
149*0Sstevel@tonic-gate #define	CLSET_FD_NCLOSE		9   /* Do not close fd while clnt_destroy */
150*0Sstevel@tonic-gate /*
151*0Sstevel@tonic-gate  * udp only control operations
152*0Sstevel@tonic-gate  */
153*0Sstevel@tonic-gate #define	CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
154*0Sstevel@tonic-gate #define	CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate /*
157*0Sstevel@tonic-gate  * void
158*0Sstevel@tonic-gate  * CLNT_DESTROY(rh);
159*0Sstevel@tonic-gate  * 	CLIENT *rh;
160*0Sstevel@tonic-gate  */
161*0Sstevel@tonic-gate #define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate /*
164*0Sstevel@tonic-gate  * By convention, procedure 0 takes null arguments and returns them
165*0Sstevel@tonic-gate  */
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate #define	NULLPROC ((ulong_t)0)
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate /*
170*0Sstevel@tonic-gate  * Below are the client handle creation routines for the various
171*0Sstevel@tonic-gate  * implementations of client side rpc.  They can return NULL if a
172*0Sstevel@tonic-gate  * creation failure occurs.
173*0Sstevel@tonic-gate  */
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate /*
176*0Sstevel@tonic-gate  * UDP based rpc.
177*0Sstevel@tonic-gate  * CLIENT *
178*0Sstevel@tonic-gate  * clntbudp_create(raddr, program, version, wait, sockp)
179*0Sstevel@tonic-gate  *	struct sockaddr_in *raddr;
180*0Sstevel@tonic-gate  *	ulong_t program;
181*0Sstevel@tonic-gate  *	ulong_t version;
182*0Sstevel@tonic-gate  *	struct timeval wait;
183*0Sstevel@tonic-gate  *	int *sockp;
184*0Sstevel@tonic-gate  *
185*0Sstevel@tonic-gate  * Same as above, but you specify max packet sizes.
186*0Sstevel@tonic-gate  * CLIENT *
187*0Sstevel@tonic-gate  * clntbudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
188*0Sstevel@tonic-gate  *	struct sockaddr_in *raddr;
189*0Sstevel@tonic-gate  *	ulong_t program;
190*0Sstevel@tonic-gate  *	ulong_t version;
191*0Sstevel@tonic-gate  *	struct timeval wait;
192*0Sstevel@tonic-gate  *	int *sockp;
193*0Sstevel@tonic-gate  *	uint_t sendsz;
194*0Sstevel@tonic-gate  *	uint_t recvsz;
195*0Sstevel@tonic-gate  */
196*0Sstevel@tonic-gate extern CLIENT *clntbudp_create(struct sockaddr_in *raddr, rpcprog_t program,
197*0Sstevel@tonic-gate 				rpcvers_t version, struct timeval wait,
198*0Sstevel@tonic-gate 				int *sockp);
199*0Sstevel@tonic-gate extern CLIENT *clntbudp_bufcreate(struct sockaddr_in *raddr, rpcprog_t program,
200*0Sstevel@tonic-gate 				rpcvers_t version, struct timeval wait,
201*0Sstevel@tonic-gate 				int *sockp, uint_t sendsz, uint_t recvsz);
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate /*
204*0Sstevel@tonic-gate  * TCP based rpc.
205*0Sstevel@tonic-gate  * CLIENT *
206*0Sstevel@tonic-gate  * clntbtcp_create(raddr, program, version, wait, sockp, sendsz, recvsz)
207*0Sstevel@tonic-gate  *	struct sockaddr_in *raddr;
208*0Sstevel@tonic-gate  *	ulong_t program;
209*0Sstevel@tonic-gate  *	ulong_t version;
210*0Sstevel@tonic-gate  *	struct timeval wait;
211*0Sstevel@tonic-gate  *	int *sockp;
212*0Sstevel@tonic-gate  *	uint_t sendsz;
213*0Sstevel@tonic-gate  *	uint_t recvsz;
214*0Sstevel@tonic-gate  *
215*0Sstevel@tonic-gate  */
216*0Sstevel@tonic-gate extern CLIENT *clntbtcp_create(struct sockaddr_in *raddr, rpcprog_t program,
217*0Sstevel@tonic-gate 				rpcvers_t version, struct timeval wait,
218*0Sstevel@tonic-gate 				int *sockp, uint_t sendsz, uint_t recvsz);
219*0Sstevel@tonic-gate /*
220*0Sstevel@tonic-gate  * If a creation fails, the following allows the user to figure out why.
221*0Sstevel@tonic-gate  */
222*0Sstevel@tonic-gate struct rpc_createerr {
223*0Sstevel@tonic-gate 	enum clnt_stat cf_stat;
224*0Sstevel@tonic-gate 	struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
225*0Sstevel@tonic-gate };
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate extern struct rpc_createerr rpc_createerr;
228*0Sstevel@tonic-gate 
229*0Sstevel@tonic-gate #define	UDPMSGSIZE	8800	/* rpc imposed limit on udp msg size */
230*0Sstevel@tonic-gate #define	RPCSMALLMSGSIZE	400	/* a more reasonable packet size */
231*0Sstevel@tonic-gate #define	TCPMSGSIZE	(32 * 1024) /* reasonably sized RPC/TCP msg */
232*0Sstevel@tonic-gate #ifdef	__cplusplus
233*0Sstevel@tonic-gate }
234*0Sstevel@tonic-gate #endif
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate #endif /* !_RPC_CLNT_H */
237