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 $ */
7 * the regents of the university of michigan
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.
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.
30 * Copyright (c) 1989, 1993
31 * The Regents of the University of California. All rights reserved.
33 * This code is derived from software contributed to Berkeley by
34 * Rick Macklem at The University of Guelph.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)nfsmount.h 8.3 (Berkeley) 3/30/95
67 #include <sys/types.h>
68 #include <sys/malloc.h>
70 #include <sys/mutex.h>
73 #define RPC_EXEC_CTX struct proc *
75 #define RPC_EXEC_CTX struct thread *
80 #define RPCDEBUG(args...) do{ \
81 if(rpcdebugon != 0){ \
82 printf("%s(): ", __func__);\
87 #define RPCDEBUG(args...)
91 #define RPC_TICKINTVL 10
94 /* from nfs/nfsproto.h */
95 #define RPC_MAXDATA 32768
96 #define RPC_MAXPKTHDR 404
97 #define RPC_MAXPACKET (RPC_MAXPKTHDR + RPC_MAXDATA)
99 #define RPCX_UNSIGNED 4
101 /* defines for rpcclnt's rc_flags
102 XXX these flags came from the NFSMNT_* flags in OpenBSD's sys/mount.h */
103 #define RPCCLNT_SOFT 0x001 /* soft mount (hard is details) */
104 #define RPCCLNT_INT 0x002 /* allow interrupts on hard mounts */
105 #define RPCCLNT_NOCONN 0x004 /* dont connect the socket (udp) */
106 #define RPCCLNT_DUMBTIMR 0x010
108 #define RPCCLNT_SNDLOCK 0x100
109 #define RPCCLNT_WANTSND 0x200
110 #define RPCCLNT_RCVLOCK 0x400
111 #define RPCCLNT_WANTRCV 0x800
114 /* Flag values for r_flags */
115 #define R_TIMING 0x01 /* timing request (in mntp) */
116 #define R_SENT 0x02 /* request has been sent */
117 #define R_SOFTTERM 0x04 /* soft mnt, too many retries */
118 #define R_INTR 0x08 /* intr mnt, signal pending */
119 #define R_SOCKERR 0x10 /* Fatal error on socket */
120 #define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */
121 #define R_MUSTRESEND 0x40 /* Must resend request */
122 #define R_GETONEREP 0x80 /* Probe for one reply only */
125 #define RPC_HZ (hz / rpcclnt_ticks) /* Ticks/sec */
126 #define RPC_TIMEO (1 * RPC_HZ) /* Default timeout = 1 second */
128 #define RPC_MAXREXMIT 100 /* Stop counting after this many */
131 #define RPCIGNORE_SOERROR(s, e) \
132 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
133 ((s) & PR_CONNREQUIRED) == 0)
135 #define RPCINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
136 sigmask(SIGHUP)|sigmask(SIGQUIT))
138 #define RPCMADV(m, s) (m)->m_data += (s)
140 #define RPCAUTH_ROOTCREDS NULL
142 #define RPCCLNTINT_SIGMASK(set) \
143 (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \
144 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \
145 SIGISMEMBER(set, SIGQUIT))
148 #define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v)))
149 #define txdr_unsigned(v) (htonl((int32_t)(v)))
153 * XXX should be per rpcclnt */
164 u_int32_t prog_version;
169 unsigned int auth_type;
173 TAILQ_ENTRY(rpctask) r_chain;
179 struct rpcclnt *r_rpcclnt;
182 int r_flags; /* flags on request, see below */
183 int r_retry; /* max retransmission count */
184 int r_rexmit; /* current retrans count */
185 int r_timer; /* tick counter on reply */
186 int r_procnum; /* NFS procedure number */
187 int r_rtt; /* RTT for rpc */
196 /* used only when reply == RPC_MSGDENIED and
197 * status == RPC_AUTHERR */
200 /* rpc mismatch info if reply == RPC_MSGDENIED and
201 * status == RPC_MISMATCH */
208 /* head of the mbuf chain */
211 /* mbuf and position of the verification opaque data
212 * note that this is only valid when stat.reply == RPC_MSGACCEPTED */
215 struct mbuf * verf_md;
218 /* mbuf and postion of the result of the rpc request */
219 struct mbuf * result_md;
225 * RPC Client connection context.
226 * One allocated on every NFS mount.
227 * Holds RPC specific information for mount.
229 /* XXX: please note that all pointer type variables are just set (not copied),
230 * so it is up to the user to free these values */
232 int rc_flag; /* For RPCCLNT_* flags */
234 int rc_wsize; /* Max size of the request data */
235 int rc_rsize; /* Max size of the response data */
236 struct sockaddr *rc_name;
237 struct socket *rc_so; /* Rpc socket */
238 int rc_sotype; /* Type of socket */
239 int rc_soproto; /* and protocol */
240 int rc_soflags; /* pr_flags for socket protocol */
242 int rc_timeo; /* Init timer for NFSMNT_DUMBTIMR */
243 int rc_retry; /* Max retries */
244 int rc_srtt[4]; /* Timers for rpcs */
246 int rc_sent; /* Request send count */
247 int rc_cwnd; /* Request send window */
248 int rc_timeouts; /* Request timeouts */
250 /* XXX: this is not being set!!!! */
251 int rc_deadthresh; /* Threshold of timeouts-->dead server*/
254 /* authentication: */
255 /* currently can be RPCAUTH_NULL, RPCAUTH_KERBV4, RPCAUTH_UNIX */
256 /* should be kept in XDR form */
257 int rc_authtype; /* Authenticator type */
262 int rc_authlen; /* and length */
263 char *rc_authstr; /* Authenticator string */
265 char *rc_verfstr; /* and the verifier */
269 struct rpc_auth * rc_auth; /* authentication */
272 /* stored in XDR form (network byte order) */
273 unsigned int rc_progid; /* program id */
274 unsigned int rc_progvers; /* program version */
276 /* name of server for log messages */
277 const char *rc_servername; /* for printing error messages */
279 struct rpc_program * rc_prog;
282 /* XXX: this should be removed */
283 int rc_proctlen; /* if == 0 then rc_proct == NULL */
288 extern struct pool rpcreply_pool;
289 extern struct pool rpcclnt_pool;
291 /* MALLOC_DECLARE(M_RPC); */
293 extern int rpcdebugon;
297 #define rpcclnt_get(X) \
299 (X) = pool_get(&rpcclnt_pool, PR_WAITOK); \
300 bzero((X), sizeof(struct rpcclnt)); \
303 #define rpcclnt_put(X) \
306 pool_put(&rpcclnt_pool, (X)); \
309 #else /* !__OpenBSD__ */
311 /* usage count for module (un)loading */
312 extern unsigned int rpcclnt_usage;
313 extern struct mtx rpcclnt_usage_mutex;
315 void rpcclnt_create(struct rpcclnt ** rpc);
316 void rpcclnt_destroy(struct rpcclnt * rpc);
318 #define rpcclnt_get(X) rpcclnt_create(&(X))
319 #define rpcclnt_put(X) rpcclnt_destroy(X)
322 struct rpcclnt_test_args {
325 int rpcclnt_test(struct thread *, struct rpcclnt_test_args *);
327 #define RPC_RETURN(X) do { RPCDEBUG("returning %d", X); return X; }while(0)
328 #endif /* RPCCLNT_TEST */
330 #endif /* !__OpenBSD__ */
332 void rpcclnt_init(void);
333 void rpcclnt_uninit(void);
335 int rpcclnt_setup(struct rpcclnt *, int, struct sockaddr *, int, int, int, int, const char *, int, int);
338 int rpcclnt_setup(struct rpcclnt *, struct rpc_program *, struct sockaddr *, int, int, struct rpc_auth *, int, int, int);
341 int rpcclnt_connect(struct rpcclnt *, RPC_EXEC_CTX td);
342 int rpcclnt_reconnect(struct rpctask *, RPC_EXEC_CTX td);
343 void rpcclnt_disconnect(struct rpcclnt *);
344 void rpcclnt_safedisconnect(struct rpcclnt *);
346 void rpcclnt_setauth(struct rpcclnt *, u_int32_t, u_int32_t, char *, u_int32_t, char *, struct ucred *);
347 int rpcclnt_request(struct rpcclnt *, struct mbuf *, int, RPC_EXEC_CTX, struct ucred *, struct rpc_reply *);
348 int rpcclnt_err(struct rpc_reply *);
350 int rpcclnt_cancelreqs(struct rpcclnt *);
351 int rpcclnt_sigintr(struct rpcclnt *, struct rpctask *, RPC_EXEC_CTX);
354 #endif /* _RPCCLNT_H_ */