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