FreeBSD/Linux Kernel Cross Reference
sys/rpc/rpcclnt.h
1 /* $FreeBSD: releng/5.2/sys/rpc/rpcclnt.h 122698 2003-11-14 20:54:10Z alfred $ */
2 /* $OpenBSD: nfsmount.h,v 1.11 2002/03/14 01:27:13 millert Exp $ */
3 /* $NetBSD: nfsmount.h,v 1.10 1996/02/18 11:54:03 fvdl Exp $ */
4
5 /*
6 * copyright (c) 2003
7 * the regents of the university of michigan
8 * all rights reserved
9 *
10 * permission is granted to use, copy, create derivative works and redistribute
11 * this software and such derivative works for any purpose, so long as the name
12 * of the university of michigan is not used in any advertising or publicity
13 * pertaining to the use or distribution of this software without specific,
14 * written prior authorization. if the above copyright notice or any other
15 * identification of the university of michigan is included in any copy of any
16 * portion of this software, then the disclaimer below must also be included.
17 *
18 * this software is provided as is, without representation from the university
19 * of michigan as to its fitness for any purpose, and without warranty by the
20 * university of michigan of any kind, either express or implied, including
21 * without limitation the implied warranties of merchantability and fitness for
22 * a particular purpose. the regents of the university of michigan shall not be
23 * liable for any damages, including special, indirect, incidental, or
24 * consequential damages, with respect to any claim arising out of or in
25 * connection with the use of the software, even if it has been or is hereafter
26 * advised of the possibility of such damages.
27 */
28
29 /*
30 * Copyright (c) 1989, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * This code is derived from software contributed to Berkeley by
34 * Rick Macklem at The University of Guelph.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * @(#)nfsmount.h 8.3 (Berkeley) 3/30/95
65 */
66
67
68 #ifndef _RPCCLNT_H_
69 #define _RPCCLNT_H_
70
71 #include <sys/types.h>
72 #include <sys/malloc.h>
73 #include <sys/lock.h>
74 #include <sys/mutex.h>
75
76 #ifdef __OpenBSD__
77 #define RPC_EXEC_CTX struct proc *
78 #else
79 #define RPC_EXEC_CTX struct thread *
80 #endif
81
82
83 #ifdef RPCCLNT_DEBUG
84 #define RPCDEBUG(args...) do{ \
85 if(rpcdebugon != 0){ \
86 printf("%s(): ", __FUNCTION__);\
87 printf(args); \
88 printf("\n"); \
89 }}while(0)
90 #else
91 #define RPCDEBUG(args...)
92 #endif
93
94 /* from nfs/nfs.h */
95 #define RPC_TICKINTVL 5
96
97
98 /* from nfs/nfsproto.h */
99 #define RPC_MAXDATA 32768
100 #define RPC_MAXPKTHDR 404
101 #define RPC_MAXPACKET (RPC_MAXPKTHDR + RPC_MAXDATA)
102
103 #define RPCX_UNSIGNED 4
104
105 /* defines for rpcclnt's rc_flags
106 XXX these flags came from the NFSMNT_* flags in OpenBSD's sys/mount.h */
107 #define RPCCLNT_SOFT 0x001 /* soft mount (hard is details) */
108 #define RPCCLNT_INT 0x002 /* allow interrupts on hard mounts */
109 #define RPCCLNT_NOCONN 0x004 /* dont connect the socket (udp) */
110 #define RPCCLNT_DUMBTIMR 0x010
111
112 #define RPCCLNT_SNDLOCK 0x100
113 #define RPCCLNT_WANTSND 0x200
114 #define RPCCLNT_RCVLOCK 0x400
115 #define RPCCLNT_WANTRCV 0x800
116
117
118 /* Flag values for r_flags */
119 #define R_TIMING 0x01 /* timing request (in mntp) */
120 #define R_SENT 0x02 /* request has been sent */
121 #define R_SOFTTERM 0x04 /* soft mnt, too many retries */
122 #define R_INTR 0x08 /* intr mnt, signal pending */
123 #define R_SOCKERR 0x10 /* Fatal error on socket */
124 #define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */
125 #define R_MUSTRESEND 0x40 /* Must resend request */
126 #define R_GETONEREP 0x80 /* Probe for one reply only */
127
128
129 #define RPC_HZ (hz / rpcclnt_ticks) /* Ticks/sec */
130 #define RPC_TIMEO (1 * RPC_HZ) /* Default timeout = 1 second */
131
132 #define RPC_MAXREXMIT 100 /* Stop counting after this many */
133
134
135 #define RPCIGNORE_SOERROR(s, e) \
136 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
137 ((s) & PR_CONNREQUIRED) == 0)
138
139 #define RPCINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
140 sigmask(SIGHUP)|sigmask(SIGQUIT))
141
142 #define RPCMADV(m, s) (m)->m_data += (s)
143
144 #define RPCAUTH_ROOTCREDS NULL
145
146 #define RPCCLNTINT_SIGMASK(set) \
147 (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \
148 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \
149 SIGISMEMBER(set, SIGQUIT))
150
151
152 #define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v)))
153 #define txdr_unsigned(v) (htonl((int32_t)(v)))
154
155
156 /* global rpcstats
157 * XXX should be per rpcclnt */
158 struct rpcstats {
159 int rpcretries;
160 int rpcrequests;
161 int rpctimeouts;
162 int rpcunexpected;
163 int rpcinvalid;
164 };
165
166 struct rpc_program {
167 u_int32_t prog_id;
168 u_int32_t prog_version;
169 char * prog_name;
170 };
171
172 struct rpc_auth {
173 unsigned int auth_type;
174 };
175
176 struct rpctask {
177 TAILQ_ENTRY(rpctask) r_chain;
178 struct mbuf *r_mreq;
179 struct mbuf *r_mrep;
180 struct mbuf *r_md;
181 caddr_t r_dpos;
182
183 struct rpcclnt *r_rpcclnt;
184
185 u_int32_t r_xid;
186 int r_flags; /* flags on request, see below */
187 int r_retry; /* max retransmission count */
188 int r_rexmit; /* current retrans count */
189 int r_timer; /* tick counter on reply */
190 int r_procnum; /* NFS procedure number */
191 int r_rtt; /* RTT for rpc */
192 RPC_EXEC_CTX r_td;
193 };
194
195 struct rpc_reply {
196 struct {
197 u_int32_t type;
198 u_int32_t status;
199
200 /* used only when reply == RPC_MSGDENIED and
201 * status == RPC_AUTHERR */
202 u_int32_t autherr;
203
204 /* rpc mismatch info if reply == RPC_MSGDENIED and
205 * status == RPC_MISMATCH */
206 struct {
207 u_int32_t low;
208 u_int32_t high;
209 } mismatch_info;
210 } stat;
211
212 /* head of the mbuf chain */
213 struct mbuf * mrep;
214
215 /* mbuf and position of the verification opaque data
216 * note that this is only valid when stat.reply == RPC_MSGACCEPTED */
217 u_int32_t verf_type;
218 u_int32_t verf_size;
219 struct mbuf * verf_md;
220 caddr_t verf_dpos;
221
222 /* mbuf and postion of the result of the rpc request */
223 struct mbuf * result_md;
224 caddr_t result_dpos;
225 };
226
227
228 /*
229 * RPC Client connection context.
230 * One allocated on every NFS mount.
231 * Holds RPC specific information for mount.
232 */
233 /* XXX: please note that all pointer type variables are just set (not copied),
234 * so it is up to the user to free these values */
235 struct rpcclnt {
236 int rc_flag; /* For RPCCLNT_* flags */
237
238 int rc_wsize; /* Max size of the request data */
239 int rc_rsize; /* Max size of the response data */
240 struct sockaddr *rc_name;
241 struct socket *rc_so; /* Rpc socket */
242 int rc_sotype; /* Type of socket */
243 int rc_soproto; /* and protocol */
244 int rc_soflags; /* pr_flags for socket protocol */
245
246 int rc_timeo; /* Init timer for NFSMNT_DUMBTIMR */
247 int rc_retry; /* Max retries */
248 int rc_srtt[4]; /* Timers for rpcs */
249 int rc_sdrtt[4];
250 int rc_sent; /* Request send count */
251 int rc_cwnd; /* Request send window */
252 int rc_timeouts; /* Request timeouts */
253
254 /* XXX: this is not being set!!!! */
255 int rc_deadthresh; /* Threshold of timeouts-->dead server*/
256
257
258 /* authentication: */
259 /* currently can be RPCAUTH_NULL, RPCAUTH_KERBV4, RPCAUTH_UNIX */
260 /* should be kept in XDR form */
261 int rc_authtype; /* Authenticator type */
262
263
264 #if 0
265 /* RPCAUTH_KERB4 */
266 int rc_authlen; /* and length */
267 char *rc_authstr; /* Authenticator string */
268 int rc_verflen;
269 char *rc_verfstr; /* and the verifier */
270 #endif
271
272 /* RPCAUTH_UNIX*/
273 struct rpc_auth * rc_auth; /* authentication */
274
275 #if 0
276 /* stored in XDR form (network byte order) */
277 unsigned int rc_progid; /* program id */
278 unsigned int rc_progvers; /* program version */
279
280 /* name of server for log messages */
281 const char *rc_servername; /* for printing error messages */
282 #else
283 struct rpc_program * rc_prog;
284 #endif
285
286 /* XXX: this should be removed */
287 int rc_proctlen; /* if == 0 then rc_proct == NULL */
288 int * rc_proct;
289 };
290
291 #ifdef __OpenBSD__
292 extern struct pool rpcreply_pool;
293 extern struct pool rpcclnt_pool;
294 #else
295 /* MALLOC_DECLARE(M_RPC); */
296 #endif
297 extern int rpcdebugon;
298
299
300 #ifdef __OpenBSD__
301 #define rpcclnt_get(X) \
302 do { \
303 (X) = pool_get(&rpcclnt_pool, PR_WAITOK); \
304 bzero((X), sizeof(struct rpcclnt)); \
305 }while(0)
306
307 #define rpcclnt_put(X) \
308 do { \
309 if ((X) != NULL){ \
310 pool_put(&rpcclnt_pool, (X)); \
311 }}while(0)
312
313 #else /* !__OpenBSD__ */
314
315 /* usage count for module (un)loading */
316 extern unsigned int rpcclnt_usage;
317 extern struct mtx rpcclnt_usage_mutex;
318
319 void rpcclnt_create(struct rpcclnt ** rpc);
320 void rpcclnt_destroy(struct rpcclnt * rpc);
321
322 #define rpcclnt_get(X) rpcclnt_create(&(X))
323 #define rpcclnt_put(X) rpcclnt_destroy(X)
324
325 #ifdef RPCCLNT_TEST
326 struct rpcclnt_test_args {
327 int nothing;
328 };
329 int rpcclnt_test(struct thread *, struct rpcclnt_test_args *);
330
331 #define RPC_RETURN(X) do { RPCDEBUG("returning %d", X); return X; }while(0)
332 #endif /* RPCCLNT_TEST */
333
334 #endif /* !__OpenBSD__ */
335
336 void rpcclnt_init(void);
337 void rpcclnt_uninit(void);
338 #if 0
339 int rpcclnt_setup(struct rpcclnt *, int, struct sockaddr *, int, int, int, int, const char *, int, int);
340 #endif
341
342 int rpcclnt_setup(struct rpcclnt *, struct rpc_program *, struct sockaddr *, int, int, struct rpc_auth *, int, int, int);
343
344
345 int rpcclnt_connect(struct rpcclnt *, RPC_EXEC_CTX td);
346 int rpcclnt_reconnect(struct rpctask *, RPC_EXEC_CTX td);
347 void rpcclnt_disconnect(struct rpcclnt *);
348 void rpcclnt_safedisconnect(struct rpcclnt *);
349
350 void rpcclnt_setauth(struct rpcclnt *, u_int32_t, u_int32_t, char *, u_int32_t, char *, struct ucred *);
351 int rpcclnt_request(struct rpcclnt *, struct mbuf *, int, RPC_EXEC_CTX, struct ucred *, struct rpc_reply *);
352 int rpcclnt_err(struct rpc_reply *);
353
354 int rpcclnt_cancelreqs(struct rpcclnt *);
355 int rpcclnt_sigintr(struct rpcclnt *, struct rpctask *, RPC_EXEC_CTX);
356
357
358 #endif /* _RPCCLNT_H_ */
Cache object: 1d00fa73a6aa15b8bf7ffbbaa5398b14
|