xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/nfs/rpc/clnt.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  */
9 /* @(#)clnt.h	2.1 88/07/29 4.0 RPCSRC; from 1.31 88/02/08 SMI*/
10 /*
11  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
12  * unrestricted use provided that this legend is included on all tape
13  * media and as a part of the software program in whole or part.  Users
14  * may copy or modify Sun RPC without charge, but are not authorized
15  * to license or distribute it to anyone else except as part of a product or
16  * program developed by the user.
17  *
18  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
19  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
21  *
22  * Sun RPC is provided with no support and without any obligation on the
23  * part of Sun Microsystems, Inc. to assist in its use, correction,
24  * modification or enhancement.
25  *
26  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
27  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
28  * OR ANY PART THEREOF.
29  *
30  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
31  * or profits or other special, indirect and consequential damages, even if
32  * Sun has been advised of the possibility of such damages.
33  *
34  * Sun Microsystems, Inc.
35  * 2550 Garcia Avenue
36  * Mountain View, California  94043
37  */
38 
39 /*
40  * clnt.h - Client side remote procedure call interface.
41  *
42  * Copyright (C) 1984, Sun Microsystems, Inc.
43  */
44 
45 #ifndef _RPC_CLNT_H
46 #define _RPC_CLNT_H	1
47 
48 #include <rpc/types.h>
49 #include <rpc/auth.h>
50 #include <lwip/sockets.h>
51 
52 /*
53  * Rpc calls return an enum clnt_stat.  This should be looked at more,
54  * since each implementation is required to live with this (implementation
55  * independent) list of errors.
56  */
57 enum clnt_stat {
58 	RPC_SUCCESS=0,			/* call succeeded */
59 	/*
60 	 * local errors
61 	 */
62 	RPC_CANTENCODEARGS=1,		/* can't encode arguments */
63 	RPC_CANTDECODERES=2,		/* can't decode results */
64 	RPC_CANTSEND=3,			/* failure in sending call */
65 	RPC_CANTRECV=4,			/* failure in receiving result */
66 	RPC_TIMEDOUT=5,			/* call timed out */
67 	/*
68 	 * remote errors
69 	 */
70 	RPC_VERSMISMATCH=6,		/* rpc versions not compatible */
71 	RPC_AUTHERROR=7,		/* authentication error */
72 	RPC_PROGUNAVAIL=8,		/* program not available */
73 	RPC_PROGVERSMISMATCH=9,		/* program version mismatched */
74 	RPC_PROCUNAVAIL=10,		/* procedure unavailable */
75 	RPC_CANTDECODEARGS=11,		/* decode arguments error */
76 	RPC_SYSTEMERROR=12,		/* generic "other problem" */
77 	RPC_NOBROADCAST = 21,		/* Broadcasting not supported */
78 	/*
79 	 * callrpc & clnt_create errors
80 	 */
81 	RPC_UNKNOWNHOST=13,		/* unknown host name */
82 	RPC_UNKNOWNPROTO=17,		/* unknown protocol */
83 	RPC_UNKNOWNADDR = 19,		/* Remote address unknown */
84 
85 	/*
86 	 * rpcbind errors
87 	 */
88 	RPC_RPCBFAILURE=14,		/* portmapper failed in its call */
89 #define RPC_PMAPFAILURE RPC_RPCBFAILURE
90 	RPC_PROGNOTREGISTERED=15,	/* remote program is not registered */
91 	RPC_N2AXLATEFAILURE = 22,	/* Name to addr translation failed */
92 	/*
93 	 * unspecified error
94 	 */
95 	RPC_FAILED=16,
96 	RPC_INTR=18,
97 	RPC_TLIERROR=20,
98 	RPC_UDERROR=23,
99         /*
100          * asynchronous errors
101          */
102         RPC_INPROGRESS = 24,
103         RPC_STALERACHANDLE = 25
104 };
105 
106 
107 /*
108  * Error info.
109  */
110 struct rpc_err {
111   int re_status;
112   union {
113     int RE_errno;		/* related system error */
114     int RE_why;	/* why the auth error occurred */
115     struct {
116       unsigned long low;		/* lowest verion supported */
117       unsigned long high;		/* highest verion supported */
118     } RE_vers;
119     struct {			/* maybe meaningful if RPC_FAILED */
120       long s1;
121       long s2;
122     } RE_lb;			/* life boot & debugging only */
123   } ru;
124 #define	re_errno	ru.RE_errno
125 #define	re_why		ru.RE_why
126 #define	re_vers		ru.RE_vers
127 #define	re_lb		ru.RE_lb
128 };
129 
130 
131 /*
132  * Client rpc handle.
133  * Created by individual implementations, see e.g. rpc_udp.c.
134  * Client is responsible for initializing auth, see e.g. auth_none.c.
135  */
136 typedef struct CLIENT CLIENT;
137 struct CLIENT {
138   AUTH	*cl_auth;		 /* authenticator */
139   struct clnt_ops {
140     enum clnt_stat (*cl_call) (CLIENT *, unsigned long, xdrproc_t, char*, xdrproc_t,
141 			       char*, struct timeval);
142 			       	/* call remote procedure */
143     void (*cl_abort) (void);	/* abort a call */
144     void (*cl_geterr) (CLIENT *, struct rpc_err *);
145 				/* get specific error code */
146     bool_t (*cl_freeres) (CLIENT *, xdrproc_t, char*);
147 				/* frees results */
148     void (*cl_destroy) (CLIENT *); /* destroy this structure */
149     bool_t (*cl_control) (CLIENT *, int, char *);
150 				/* the ioctl() of rpc */
151   } *cl_ops;
152   char* cl_private;		/* private stuff */
153 };
154 
155 
156 /*
157  * client side rpc interface ops
158  *
159  * Parameter types are:
160  *
161  */
162 
163 /*
164  * enum clnt_stat
165  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
166  * 	CLIENT *rh;
167  *	unsigned long proc;
168  *	xdrproc_t xargs;
169  *	char* argsp;
170  *	xdrproc_t xres;
171  *	char* resp;
172  *	struct timeval timeout;
173  */
174 #define	CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)	\
175 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
176 #define	clnt_call(rh, proc, xargs, argsp, xres, resp, secs)	\
177 	((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
178 
179 /*
180  * void
181  * CLNT_ABORT(rh);
182  * 	CLIENT *rh;
183  */
184 #define	CLNT_ABORT(rh)	((*(rh)->cl_ops->cl_abort)(rh))
185 #define	clnt_abort(rh)	((*(rh)->cl_ops->cl_abort)(rh))
186 
187 /*
188  * struct rpc_err
189  * CLNT_GETERR(rh);
190  * 	CLIENT *rh;
191  */
192 #define	CLNT_GETERR(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
193 #define	clnt_geterr(rh,errp)	((*(rh)->cl_ops->cl_geterr)(rh, errp))
194 
195 
196 /*
197  * bool_t
198  * CLNT_FREERES(rh, xres, resp);
199  * 	CLIENT *rh;
200  *	xdrproc_t xres;
201  *	char* resp;
202  */
203 #define	CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
204 #define	clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
205 
206 /*
207  * bool_t
208  * CLNT_CONTROL(cl, request, info)
209  *      CLIENT *cl;
210  *      unsigned int request;
211  *      char *info;
212  */
213 #define	CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
214 #define	clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
215 
216 /*
217  * control operations that apply to all transports
218  *
219  * Note: options marked XXX are no-ops in this implementation of RPC.
220  * The are present in TI-RPC but can't be implemented here since they
221  * depend on the presence of STREAMS/TLI, which we don't have.
222  */
223 #define CLSET_TIMEOUT        1    /* set timeout (timeval) */
224 #define CLGET_TIMEOUT        2    /* get timeout (timeval) */
225 #define CLGET_SERVER_ADDR    3    /* get server's address (sockaddr) */
226 #define CLGET_FD             6    /* get connections file descriptor */
227 #define CLGET_SVC_ADDR       7    /* get server's address (netbuf)      XXX */
228 #define CLSET_FD_CLOSE       8    /* close fd while clnt_destroy */
229 #define CLSET_FD_NCLOSE      9    /* Do not close fd while clnt_destroy*/
230 #define CLGET_XID            10   /* Get xid */
231 #define CLSET_XID            11   /* Set xid */
232 #define CLGET_VERS           12   /* Get version number */
233 #define CLSET_VERS           13   /* Set version number */
234 #define CLGET_PROG           14   /* Get program number */
235 #define CLSET_PROG           15   /* Set program number */
236 #define CLSET_SVC_ADDR       16   /* get server's address (netbuf)      XXX */
237 #define CLSET_PUSH_TIMOD     17   /* push timod if not already present  XXX */
238 #define CLSET_POP_TIMOD      18   /* pop timod                          XXX */
239 /*
240  * Connectionless only control operations
241  */
242 #define CLSET_RETRY_TIMEOUT	4	/* set retry timeout (timeval) */
243 #define CLGET_RETRY_TIMEOUT	5	/* get retry timeout (timeval) */
244 
245 /*
246  * void
247  * CLNT_DESTROY(rh);
248  * 	CLIENT *rh;
249  */
250 #define	CLNT_DESTROY(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
251 #define	clnt_destroy(rh)	((*(rh)->cl_ops->cl_destroy)(rh))
252 
253 
254 /*
255  * RPCTEST is a test program which is accessible on every rpc
256  * transport/port.  It is used for testing, performance evaluation,
257  * and network administration.
258  */
259 
260 #define RPCTEST_PROGRAM		((unsigned long)1)
261 #define RPCTEST_VERSION		((unsigned long)1)
262 #define RPCTEST_NULL_PROC	((unsigned long)2)
263 #define RPCTEST_NULL_BATCH_PROC	((unsigned long)3)
264 
265 /*
266  * By convention, procedure 0 takes null arguments and returns them
267  */
268 
269 #define NULLPROC ((unsigned long)0)
270 
271 /*
272  * Below are the client handle creation routines for the various
273  * implementations of client side rpc.  They can return NULL if a
274  * creation failure occurs.
275  */
276 
277 /*
278  * Generic client creation routine. Supported protocols are "udp", "tcp" and
279  * "unix"
280  * CLIENT *
281  * clnt_create(host, prog, vers, prot)
282  *	char *host; 	-- hostname
283  *	unsigned long prog;	-- program number
284  *	u_ong vers;	-- version number
285  *	char *prot;	-- protocol
286  */
287 extern CLIENT *clnt_create (const char *__host, const unsigned long __prog,
288 			    const unsigned long __vers, const char *__prot)
289     ;
290 
291 /*
292  * UDP based rpc.
293  * CLIENT *
294  * clntudp_create(raddr, program, version, wait, sockp)
295  *	struct sockaddr_in *raddr;
296  *	unsigned long program;
297  *	unsigned long version;
298  *	struct timeval wait_resend;
299  *	int *sockp;
300  *
301  * Same as above, but you specify max packet sizes.
302  * CLIENT *
303  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
304  *	struct sockaddr_in *raddr;
305  *	unsigned long program;
306  *	unsigned long version;
307  *	struct timeval wait_resend;
308  *	int *sockp;
309  *	unsigned int sendsz;
310  *	unsigned int recvsz;
311  */
312 extern CLIENT *clntudp_create (struct sockaddr_in *__raddr, unsigned long __program,
313 			       unsigned long __version, struct timeval __wait_resend,
314 			       int *__sockp);
315 extern CLIENT *clntudp_bufcreate (struct sockaddr_in *__raddr,
316 				  unsigned long __program, unsigned long __version,
317 				  struct timeval __wait_resend, int *__sockp,
318 				  unsigned int __sendsz, unsigned int __recvsz);
319 
320 extern int callrpc (const char *__host, const unsigned long __prognum,
321 		    const unsigned long __versnum, const unsigned long __procnum,
322 		    const xdrproc_t __inproc, const char *__in,
323 		    const xdrproc_t __outproc, char *__out);
324 
325 #define UDPMSGSIZE	8800	/* rpc imposed limit on udp msg size */
326 #define RPCSMALLMSGSIZE	400	/* a more reasonable packet size */
327 
328 void clnt_perror(CLIENT *rpch, const char *s);
329 
330 #endif /* rpc/clnt.h */
331