2009-02-04 23:36:54 +03:00
|
|
|
/* $NetBSD: nfs_socket.c,v 1.178 2009/02/04 20:36:54 ad Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1996-02-18 14:53:36 +03:00
|
|
|
* Copyright (c) 1989, 1991, 1993, 1995
|
1994-06-08 15:33:09 +04:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Rick Macklem at The University of Guelph.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1996-02-18 14:53:36 +03:00
|
|
|
* @(#)nfs_socket.c 8.5 (Berkeley) 3/30/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Socket operations for use by nfs
|
|
|
|
*/
|
|
|
|
|
2001-11-10 13:59:08 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-02-04 23:36:54 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: nfs_socket.c,v 1.178 2009/02/04 20:36:54 ad Exp $");
|
2001-11-10 13:59:08 +03:00
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
#ifdef _KERNEL_OPT
|
1998-02-19 03:54:13 +03:00
|
|
|
#include "fs_nfs.h"
|
2000-09-19 21:04:50 +04:00
|
|
|
#include "opt_nfs.h"
|
2003-06-23 15:00:59 +04:00
|
|
|
#include "opt_mbuftrace.h"
|
2008-11-19 21:35:57 +03:00
|
|
|
#endif
|
1998-02-19 03:54:13 +03:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2007-07-27 14:03:58 +04:00
|
|
|
#include <sys/evcnt.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/kernel.h>
|
2008-01-02 22:26:45 +03:00
|
|
|
#include <sys/kmem.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/tprintf.h>
|
1996-02-10 00:48:19 +03:00
|
|
|
#include <sys/namei.h>
|
1998-09-11 16:50:05 +04:00
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/signalvar.h>
|
2006-05-15 01:31:52 +04:00
|
|
|
#include <sys/kauth.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
1996-02-18 14:53:36 +03:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <nfs/rpcv2.h>
|
1996-02-18 14:53:36 +03:00
|
|
|
#include <nfs/nfsproto.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <nfs/nfs.h>
|
|
|
|
#include <nfs/xdr_subs.h>
|
|
|
|
#include <nfs/nfsm_subs.h>
|
|
|
|
#include <nfs/nfsmount.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <nfs/nfsnode.h>
|
|
|
|
#include <nfs/nfsrtt.h>
|
1996-02-10 00:48:19 +03:00
|
|
|
#include <nfs/nfs_var.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-02-26 09:31:08 +03:00
|
|
|
#ifdef MBUFTRACE
|
2006-10-11 01:49:14 +04:00
|
|
|
struct mowner nfs_mowner = MOWNER_INIT("nfs","");
|
2003-02-26 09:31:08 +03:00
|
|
|
#endif
|
2003-02-01 09:23:35 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Estimate rto for an nfs rpc sent via. an unreliable datagram.
|
|
|
|
* Use the mean and mean deviation of rtt for the appropriate type of rpc
|
|
|
|
* for the frequent rpcs and a default for the others.
|
|
|
|
* The justification for doing "other" this way is that these rpcs
|
|
|
|
* happen so infrequently that timer est. would probably be stale.
|
|
|
|
* Also, since many of these rpcs are
|
|
|
|
* non-idempotent, a conservative timeout is desired.
|
|
|
|
* getattr, lookup - A+2D
|
|
|
|
* read, write - A+4D
|
|
|
|
* other - nm_timeo
|
|
|
|
*/
|
|
|
|
#define NFS_RTO(n, t) \
|
|
|
|
((t) == 0 ? (n)->nm_timeo : \
|
|
|
|
((t) < 3 ? \
|
|
|
|
(((((n)->nm_srtt[t-1] + 3) >> 2) + (n)->nm_sdrtt[t-1] + 1) >> 1) : \
|
|
|
|
((((n)->nm_srtt[t-1] + 7) >> 3) + (n)->nm_sdrtt[t-1] + 1)))
|
|
|
|
#define NFS_SRTT(r) (r)->r_nmp->nm_srtt[proct[(r)->r_procnum] - 1]
|
|
|
|
#define NFS_SDRTT(r) (r)->r_nmp->nm_sdrtt[proct[(r)->r_procnum] - 1]
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* External data, mostly RPC constants in XDR form
|
|
|
|
*/
|
1995-12-20 02:07:11 +03:00
|
|
|
extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers,
|
1996-02-18 14:53:36 +03:00
|
|
|
rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr,
|
1994-06-08 15:33:09 +04:00
|
|
|
rpc_auth_kerb;
|
2006-12-27 15:10:09 +03:00
|
|
|
extern u_int32_t nfs_prog;
|
2002-12-02 02:02:10 +03:00
|
|
|
extern const int nfsv3_procid[NFS_NPROCS];
|
1996-02-18 14:53:36 +03:00
|
|
|
extern int nfs_ticks;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2008-11-23 11:22:07 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Avoid spamming the console with debugging messages. We only print
|
|
|
|
* the nfs timer and reply error debugs every 10 seconds.
|
|
|
|
*/
|
|
|
|
static const struct timeval nfs_err_interval = { 10, 0 };
|
|
|
|
static struct timeval nfs_reply_last_err_time;
|
|
|
|
static struct timeval nfs_timer_last_err_time;
|
|
|
|
#endif
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Defines which timer to use for the procnum.
|
|
|
|
* 0 - default
|
|
|
|
* 1 - getattr
|
|
|
|
* 2 - lookup
|
|
|
|
* 3 - read
|
|
|
|
* 4 - write
|
|
|
|
*/
|
2001-02-22 00:39:52 +03:00
|
|
|
static const int proct[NFS_NPROCS] = {
|
2005-11-21 12:39:02 +03:00
|
|
|
[NFSPROC_NULL] = 0,
|
|
|
|
[NFSPROC_GETATTR] = 1,
|
|
|
|
[NFSPROC_SETATTR] = 0,
|
|
|
|
[NFSPROC_LOOKUP] = 2,
|
|
|
|
[NFSPROC_ACCESS] = 1,
|
|
|
|
[NFSPROC_READLINK] = 3,
|
|
|
|
[NFSPROC_READ] = 3,
|
|
|
|
[NFSPROC_WRITE] = 4,
|
|
|
|
[NFSPROC_CREATE] = 0,
|
|
|
|
[NFSPROC_MKDIR] = 0,
|
|
|
|
[NFSPROC_SYMLINK] = 0,
|
|
|
|
[NFSPROC_MKNOD] = 0,
|
|
|
|
[NFSPROC_REMOVE] = 0,
|
|
|
|
[NFSPROC_RMDIR] = 0,
|
|
|
|
[NFSPROC_RENAME] = 0,
|
|
|
|
[NFSPROC_LINK] = 0,
|
|
|
|
[NFSPROC_READDIR] = 3,
|
|
|
|
[NFSPROC_READDIRPLUS] = 3,
|
|
|
|
[NFSPROC_FSSTAT] = 0,
|
|
|
|
[NFSPROC_FSINFO] = 0,
|
|
|
|
[NFSPROC_PATHCONF] = 0,
|
|
|
|
[NFSPROC_COMMIT] = 0,
|
|
|
|
[NFSPROC_NOOP] = 0,
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* There is a congestion window for outstanding rpcs maintained per mount
|
|
|
|
* point. The cwnd size is adjusted in roughly the way that:
|
|
|
|
* Van Jacobson, Congestion avoidance and Control, In "Proceedings of
|
|
|
|
* SIGCOMM '88". ACM, August 1988.
|
|
|
|
* describes for TCP. The cwnd size is chopped in half on a retransmit timeout
|
|
|
|
* and incremented by 1/cwnd when each rpc reply is received and a full cwnd
|
|
|
|
* of rpcs is in progress.
|
|
|
|
* (The sent count and cwnd are scaled for integer arith.)
|
|
|
|
* Variants of "slow start" were tried and were found to be too much of a
|
|
|
|
* performance hit (ave. rtt 3 times larger),
|
|
|
|
* I suspect due to the large rtt that nfs rpcs have.
|
|
|
|
*/
|
|
|
|
#define NFS_CWNDSCALE 256
|
|
|
|
#define NFS_MAXCWND (NFS_CWNDSCALE * 32)
|
2001-02-22 00:39:52 +03:00
|
|
|
static const int nfs_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256, };
|
1994-06-08 15:33:09 +04:00
|
|
|
int nfsrtton = 0;
|
|
|
|
struct nfsrtt nfsrtt;
|
2002-05-13 03:04:35 +04:00
|
|
|
struct nfsreqhead nfs_reqq;
|
2007-07-27 14:03:58 +04:00
|
|
|
static callout_t nfs_timer_ch;
|
|
|
|
static struct evcnt nfs_timer_ev;
|
|
|
|
static struct evcnt nfs_timer_start_ev;
|
|
|
|
static struct evcnt nfs_timer_stop_ev;
|
2008-11-19 21:35:57 +03:00
|
|
|
static kmutex_t nfs_timer_lock;
|
|
|
|
static bool (*nfs_timer_srvvec)(void);
|
2000-03-23 10:01:25 +03:00
|
|
|
|
2008-09-30 18:25:15 +04:00
|
|
|
#ifdef NFS
|
2007-04-29 14:30:18 +04:00
|
|
|
static int nfs_sndlock(struct nfsmount *, struct nfsreq *);
|
|
|
|
static void nfs_sndunlock(struct nfsmount *);
|
2008-09-30 18:25:15 +04:00
|
|
|
#endif
|
2007-04-29 14:30:18 +04:00
|
|
|
static int nfs_rcvlock(struct nfsmount *, struct nfsreq *);
|
|
|
|
static void nfs_rcvunlock(struct nfsmount *);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Initialize sockets and congestion for a new NFS connection.
|
|
|
|
* We do not free the sockaddr if error.
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
nfs_connect(nmp, rep, l)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsmount *nmp;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct nfsreq *rep;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct socket *so;
|
2008-04-24 15:38:36 +04:00
|
|
|
int error, rcvreserve, sndreserve;
|
1994-04-10 10:45:56 +04:00
|
|
|
struct sockaddr *saddr;
|
|
|
|
struct sockaddr_in *sin;
|
2000-06-09 04:00:17 +04:00
|
|
|
struct sockaddr_in6 *sin6;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *m;
|
2008-08-06 19:01:23 +04:00
|
|
|
int val;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
nmp->nm_so = (struct socket *)0;
|
1994-04-10 10:45:56 +04:00
|
|
|
saddr = mtod(nmp->nm_nam, struct sockaddr *);
|
2004-05-23 02:52:13 +04:00
|
|
|
error = socreate(saddr->sa_family, &nmp->nm_so,
|
2008-04-24 15:38:36 +04:00
|
|
|
nmp->nm_sotype, nmp->nm_soproto, l, NULL);
|
1996-02-10 00:48:19 +03:00
|
|
|
if (error)
|
1993-03-21 12:45:37 +03:00
|
|
|
goto bad;
|
|
|
|
so = nmp->nm_so;
|
2003-02-26 09:31:08 +03:00
|
|
|
#ifdef MBUFTRACE
|
|
|
|
so->so_mowner = &nfs_mowner;
|
|
|
|
so->so_rcv.sb_mowner = &nfs_mowner;
|
|
|
|
so->so_snd.sb_mowner = &nfs_mowner;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
nmp->nm_soflags = so->so_proto->pr_flags;
|
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/*
|
|
|
|
* Some servers require that the client port be a reserved port number.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (saddr->sa_family == AF_INET && (nmp->nm_flag & NFSMNT_RESVPORT)) {
|
2008-08-06 19:01:23 +04:00
|
|
|
val = IP_PORTRANGE_LOW;
|
|
|
|
|
|
|
|
if ((error = so_setsockopt(NULL, so, IPPROTO_IP, IP_PORTRANGE,
|
|
|
|
&val, sizeof(val))))
|
2002-02-27 06:46:36 +03:00
|
|
|
goto bad;
|
2003-02-26 09:31:08 +03:00
|
|
|
m = m_get(M_WAIT, MT_SONAME);
|
|
|
|
MCLAIM(m, so->so_mowner);
|
1993-03-21 21:04:42 +03:00
|
|
|
sin = mtod(m, struct sockaddr_in *);
|
|
|
|
sin->sin_len = m->m_len = sizeof (struct sockaddr_in);
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_addr.s_addr = INADDR_ANY;
|
2002-02-27 06:46:36 +03:00
|
|
|
sin->sin_port = 0;
|
2005-12-11 15:16:03 +03:00
|
|
|
error = sobind(so, m, &lwp0);
|
1993-03-21 21:04:42 +03:00
|
|
|
m_freem(m);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error)
|
|
|
|
goto bad;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
2000-06-09 04:00:17 +04:00
|
|
|
if (saddr->sa_family == AF_INET6 && (nmp->nm_flag & NFSMNT_RESVPORT)) {
|
2008-08-06 19:01:23 +04:00
|
|
|
val = IPV6_PORTRANGE_LOW;
|
|
|
|
|
|
|
|
if ((error = so_setsockopt(NULL, so, IPPROTO_IPV6,
|
|
|
|
IPV6_PORTRANGE, &val, sizeof(val))))
|
2002-02-27 06:46:36 +03:00
|
|
|
goto bad;
|
2003-02-26 09:31:08 +03:00
|
|
|
m = m_get(M_WAIT, MT_SONAME);
|
|
|
|
MCLAIM(m, so->so_mowner);
|
2000-06-09 04:00:17 +04:00
|
|
|
sin6 = mtod(m, struct sockaddr_in6 *);
|
2008-11-19 21:35:57 +03:00
|
|
|
memset(sin6, 0, sizeof(*sin6));
|
2000-06-09 04:00:17 +04:00
|
|
|
sin6->sin6_len = m->m_len = sizeof (struct sockaddr_in6);
|
|
|
|
sin6->sin6_family = AF_INET6;
|
2005-12-11 15:16:03 +03:00
|
|
|
error = sobind(so, m, &lwp0);
|
2000-06-09 04:00:17 +04:00
|
|
|
m_freem(m);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Protocols that do not require connections may be optionally left
|
|
|
|
* unconnected for servers that reply from a port other than NFS_PORT.
|
|
|
|
*/
|
2008-04-24 15:38:36 +04:00
|
|
|
solock(so);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (nmp->nm_flag & NFSMNT_NOCONN) {
|
|
|
|
if (nmp->nm_soflags & PR_CONNREQUIRED) {
|
2008-04-24 15:38:36 +04:00
|
|
|
sounlock(so);
|
1993-03-21 12:45:37 +03:00
|
|
|
error = ENOTCONN;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
} else {
|
2005-12-11 15:16:03 +03:00
|
|
|
error = soconnect(so, nmp->nm_nam, l);
|
2008-04-24 15:38:36 +04:00
|
|
|
if (error) {
|
|
|
|
sounlock(so);
|
1993-03-21 12:45:37 +03:00
|
|
|
goto bad;
|
2008-04-24 15:38:36 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the connection to complete. Cribbed from the
|
1994-06-08 15:33:09 +04:00
|
|
|
* connect system call but with the wait timing out so
|
|
|
|
* that interruptible mounts don't hang here for a long time.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
|
2009-01-21 09:59:29 +03:00
|
|
|
(void)sowait(so, false, 2 * hz);
|
1994-06-08 15:33:09 +04:00
|
|
|
if ((so->so_state & SS_ISCONNECTING) &&
|
|
|
|
so->so_error == 0 && rep &&
|
2005-12-11 15:16:03 +03:00
|
|
|
(error = nfs_sigintr(nmp, rep, rep->r_lwp)) != 0){
|
1994-06-08 15:33:09 +04:00
|
|
|
so->so_state &= ~SS_ISCONNECTING;
|
2008-04-24 15:38:36 +04:00
|
|
|
sounlock(so);
|
1994-06-08 15:33:09 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
if (so->so_error) {
|
|
|
|
error = so->so_error;
|
1994-06-08 15:33:09 +04:00
|
|
|
so->so_error = 0;
|
2008-04-24 15:38:36 +04:00
|
|
|
sounlock(so);
|
1993-03-21 12:45:37 +03:00
|
|
|
goto bad;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
if (nmp->nm_flag & (NFSMNT_SOFT | NFSMNT_INT)) {
|
|
|
|
so->so_rcv.sb_timeo = (5 * hz);
|
|
|
|
so->so_snd.sb_timeo = (5 * hz);
|
|
|
|
} else {
|
2004-05-23 12:08:48 +04:00
|
|
|
/*
|
|
|
|
* enable receive timeout to detect server crash and reconnect.
|
|
|
|
* otherwise, we can be stuck in soreceive forever.
|
|
|
|
*/
|
|
|
|
so->so_rcv.sb_timeo = (5 * hz);
|
1994-06-08 15:33:09 +04:00
|
|
|
so->so_snd.sb_timeo = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
if (nmp->nm_sotype == SOCK_DGRAM) {
|
1997-05-13 03:40:22 +04:00
|
|
|
sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * 2;
|
|
|
|
rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
|
|
|
|
NFS_MAXPKTHDR) * 2;
|
1994-06-08 15:33:09 +04:00
|
|
|
} else if (nmp->nm_sotype == SOCK_SEQPACKET) {
|
1996-02-25 20:47:26 +03:00
|
|
|
sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * 2;
|
|
|
|
rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
|
1996-02-25 18:30:01 +03:00
|
|
|
NFS_MAXPKTHDR) * 2;
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
2008-04-24 15:38:36 +04:00
|
|
|
sounlock(so);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nmp->nm_sotype != SOCK_STREAM)
|
|
|
|
panic("nfscon sotype");
|
1993-03-21 12:45:37 +03:00
|
|
|
if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
|
2008-08-06 19:01:23 +04:00
|
|
|
val = 1;
|
|
|
|
so_setsockopt(NULL, so, SOL_SOCKET, SO_KEEPALIVE, &val,
|
|
|
|
sizeof(val));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
if (so->so_proto->pr_protocol == IPPROTO_TCP) {
|
2008-08-06 19:01:23 +04:00
|
|
|
val = 1;
|
|
|
|
so_setsockopt(NULL, so, IPPROTO_TCP, TCP_NODELAY, &val,
|
|
|
|
sizeof(val));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-12-20 02:07:11 +03:00
|
|
|
sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR +
|
|
|
|
sizeof (u_int32_t)) * 2;
|
|
|
|
rcvreserve = (nmp->nm_rsize + NFS_MAXPKTHDR +
|
|
|
|
sizeof (u_int32_t)) * 2;
|
2008-04-24 15:38:36 +04:00
|
|
|
solock(so);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
error = soreserve(so, sndreserve, rcvreserve);
|
2008-04-24 15:38:36 +04:00
|
|
|
if (error) {
|
|
|
|
sounlock(so);
|
1994-06-08 15:33:09 +04:00
|
|
|
goto bad;
|
2008-04-24 15:38:36 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
so->so_rcv.sb_flags |= SB_NOINTR;
|
|
|
|
so->so_snd.sb_flags |= SB_NOINTR;
|
2008-04-24 15:38:36 +04:00
|
|
|
sounlock(so);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* Initialize other non-zero congestion variables */
|
1994-06-08 15:33:09 +04:00
|
|
|
nmp->nm_srtt[0] = nmp->nm_srtt[1] = nmp->nm_srtt[2] = nmp->nm_srtt[3] =
|
2001-10-14 02:59:16 +04:00
|
|
|
NFS_TIMEO << 3;
|
1994-06-08 15:33:09 +04:00
|
|
|
nmp->nm_sdrtt[0] = nmp->nm_sdrtt[1] = nmp->nm_sdrtt[2] =
|
2001-10-14 02:59:16 +04:00
|
|
|
nmp->nm_sdrtt[3] = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
nmp->nm_cwnd = NFS_MAXCWND / 2; /* Initial send window */
|
1993-03-21 12:45:37 +03:00
|
|
|
nmp->nm_sent = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
nmp->nm_timeouts = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
nfs_disconnect(nmp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconnect routine:
|
|
|
|
* Called when a connection is broken on a reliable protocol.
|
|
|
|
* - clean up the old socket
|
|
|
|
* - nfs_connect() again
|
|
|
|
* - set R_MUSTRESEND for all outstanding requests on mount point
|
|
|
|
* If this fails the mount point is DEAD!
|
1994-06-08 15:33:09 +04:00
|
|
|
* nb: Must be called with the nfs_sndlock() set on the mount point.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2007-10-21 12:23:19 +04:00
|
|
|
nfs_reconnect(struct nfsreq *rep)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsreq *rp;
|
|
|
|
struct nfsmount *nmp = rep->r_nmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
int error;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
nfs_disconnect(nmp);
|
2007-10-21 12:23:19 +04:00
|
|
|
while ((error = nfs_connect(nmp, rep, &lwp0)) != 0) {
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error == EINTR || error == ERESTART)
|
1993-03-21 12:45:37 +03:00
|
|
|
return (EINTR);
|
2007-08-05 13:40:39 +04:00
|
|
|
kpause("nfscn2", false, hz, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through outstanding request list and fix up all requests
|
|
|
|
* on old socket.
|
|
|
|
*/
|
2002-03-18 01:22:39 +03:00
|
|
|
TAILQ_FOREACH(rp, &nfs_reqq, r_chain) {
|
2004-05-23 12:08:48 +04:00
|
|
|
if (rp->r_nmp == nmp) {
|
|
|
|
if ((rp->r_flags & R_MUSTRESEND) == 0)
|
|
|
|
rp->r_flags |= R_MUSTRESEND | R_REXMITTED;
|
|
|
|
rp->r_rexmit = 0;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NFS disconnect. Clean up and unlink.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfs_disconnect(nmp)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsmount *nmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct socket *so;
|
1999-08-29 20:29:16 +04:00
|
|
|
int drain = 0;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (nmp->nm_so) {
|
|
|
|
so = nmp->nm_so;
|
|
|
|
nmp->nm_so = (struct socket *)0;
|
2008-04-24 15:38:36 +04:00
|
|
|
solock(so);
|
2006-12-06 12:13:46 +03:00
|
|
|
soshutdown(so, SHUT_RDWR);
|
2008-04-24 15:38:36 +04:00
|
|
|
sounlock(so);
|
1999-08-29 20:29:16 +04:00
|
|
|
drain = (nmp->nm_iflag & NFSMNT_DISMNT) != 0;
|
|
|
|
if (drain) {
|
1999-07-04 23:56:00 +04:00
|
|
|
/*
|
|
|
|
* soshutdown() above should wake up the current
|
|
|
|
* listener.
|
2002-01-22 12:37:59 +03:00
|
|
|
* Now wake up those waiting for the receive lock, and
|
1999-07-04 23:56:00 +04:00
|
|
|
* wait for them to go away unhappy, to prevent *nmp
|
|
|
|
* from evaporating while they're sleeping.
|
|
|
|
*/
|
2007-04-29 18:56:59 +04:00
|
|
|
mutex_enter(&nmp->nm_lock);
|
1999-07-04 23:56:00 +04:00
|
|
|
while (nmp->nm_waiters > 0) {
|
2007-04-29 14:30:18 +04:00
|
|
|
cv_broadcast(&nmp->nm_rcvcv);
|
|
|
|
cv_broadcast(&nmp->nm_sndcv);
|
2007-04-29 18:56:59 +04:00
|
|
|
cv_wait(&nmp->nm_disconcv, &nmp->nm_lock);
|
1999-07-04 23:56:00 +04:00
|
|
|
}
|
2007-04-29 18:56:59 +04:00
|
|
|
mutex_exit(&nmp->nm_lock);
|
1999-07-04 23:56:00 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
soclose(so);
|
|
|
|
}
|
1999-07-04 23:56:00 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1999-08-29 20:29:16 +04:00
|
|
|
if (drain && (nmp->nm_waiters > 0))
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("nfs_disconnect: waiters left after drain?");
|
1999-07-04 23:56:00 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1998-01-31 01:44:13 +03:00
|
|
|
void
|
|
|
|
nfs_safedisconnect(nmp)
|
|
|
|
struct nfsmount *nmp;
|
|
|
|
{
|
|
|
|
struct nfsreq dummyreq;
|
|
|
|
|
1998-08-10 00:51:08 +04:00
|
|
|
memset(&dummyreq, 0, sizeof(dummyreq));
|
1998-01-31 01:44:13 +03:00
|
|
|
dummyreq.r_nmp = nmp;
|
2007-04-29 14:30:18 +04:00
|
|
|
nfs_rcvlock(nmp, &dummyreq); /* XXX ignored error return */
|
1998-01-31 01:44:13 +03:00
|
|
|
nfs_disconnect(nmp);
|
2003-05-22 18:11:50 +04:00
|
|
|
nfs_rcvunlock(nmp);
|
1998-01-31 01:44:13 +03:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This is the nfs send routine. For connection based socket types, it
|
1994-06-08 15:33:09 +04:00
|
|
|
* must be called with an nfs_sndlock() on the socket.
|
1993-03-21 12:45:37 +03:00
|
|
|
* "rep == NULL" indicates that it has been called from a server.
|
1994-06-08 15:33:09 +04:00
|
|
|
* For the client side:
|
|
|
|
* - return EINTR if the RPC is terminated, 0 otherwise
|
|
|
|
* - set R_MUSTRESEND if the send fails for any reason
|
2000-06-27 21:52:28 +04:00
|
|
|
* - do any cleanup required by recoverable socket errors (? ? ?)
|
1994-06-08 15:33:09 +04:00
|
|
|
* For the server side:
|
|
|
|
* - return EINTR or ERESTART if interrupted by a signal
|
|
|
|
* - return EPIPE if a connection is lost for connection based sockets (TCP...)
|
2000-06-27 21:52:28 +04:00
|
|
|
* - do any cleanup required by recoverable socket errors (? ? ?)
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
nfs_send(so, nam, top, rep, l)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct socket *so;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mbuf *nam;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *top;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct nfsreq *rep;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
struct mbuf *sendnam;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error, soflags, flags;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
/* XXX nfs_doio()/nfs_request() calls with rep->r_lwp == NULL */
|
|
|
|
if (l == NULL && rep->r_lwp == NULL)
|
|
|
|
l = curlwp;
|
2004-05-23 02:52:13 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (rep) {
|
|
|
|
if (rep->r_flags & R_SOFTTERM) {
|
|
|
|
m_freem(top);
|
|
|
|
return (EINTR);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
if ((so = rep->r_nmp->nm_so) == NULL) {
|
|
|
|
rep->r_flags |= R_MUSTRESEND;
|
|
|
|
m_freem(top);
|
|
|
|
return (0);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
rep->r_flags &= ~R_MUSTRESEND;
|
|
|
|
soflags = rep->r_nmp->nm_soflags;
|
|
|
|
} else
|
|
|
|
soflags = so->so_proto->pr_flags;
|
|
|
|
if ((soflags & PR_CONNREQUIRED) || (so->so_state & SS_ISCONNECTED))
|
|
|
|
sendnam = (struct mbuf *)0;
|
|
|
|
else
|
|
|
|
sendnam = nam;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (so->so_type == SOCK_SEQPACKET)
|
|
|
|
flags = MSG_EOR;
|
|
|
|
else
|
|
|
|
flags = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2007-12-04 20:42:30 +03:00
|
|
|
error = (*so->so_send)(so, sendnam, NULL, top, NULL, flags, l);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error) {
|
|
|
|
if (rep) {
|
2000-09-20 02:21:21 +04:00
|
|
|
if (error == ENOBUFS && so->so_type == SOCK_DGRAM) {
|
|
|
|
/*
|
|
|
|
* We're too fast for the network/driver,
|
|
|
|
* and UDP isn't flowcontrolled.
|
|
|
|
* We need to resend. This is not fatal,
|
|
|
|
* just try again.
|
|
|
|
*
|
|
|
|
* Could be smarter here by doing some sort
|
|
|
|
* of a backoff, but this is rare.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_flags |= R_MUSTRESEND;
|
2000-09-20 02:21:21 +04:00
|
|
|
} else {
|
2004-03-11 01:36:42 +03:00
|
|
|
if (error != EPIPE)
|
|
|
|
log(LOG_INFO,
|
|
|
|
"nfs send error %d for %s\n",
|
|
|
|
error,
|
|
|
|
rep->r_nmp->nm_mountp->
|
|
|
|
mnt_stat.f_mntfromname);
|
2000-09-20 02:21:21 +04:00
|
|
|
/*
|
|
|
|
* Deal with errors for the client side.
|
|
|
|
*/
|
|
|
|
if (rep->r_flags & R_SOFTTERM)
|
|
|
|
error = EINTR;
|
|
|
|
else
|
|
|
|
rep->r_flags |= R_MUSTRESEND;
|
|
|
|
}
|
2001-05-10 00:02:32 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* See above. This error can happen under normal
|
|
|
|
* circumstances and the log is too noisy.
|
|
|
|
* The error will still show up in nfsstat.
|
|
|
|
*/
|
|
|
|
if (error != ENOBUFS || so->so_type != SOCK_DGRAM)
|
|
|
|
log(LOG_INFO, "nfsd send error %d\n", error);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
2000-06-27 21:52:28 +04:00
|
|
|
* Handle any recoverable (soft) socket errors here. (? ? ?)
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
|
|
|
if (error != EINTR && error != ERESTART &&
|
|
|
|
error != EWOULDBLOCK && error != EPIPE)
|
1993-03-21 12:45:37 +03:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-01-31 05:58:48 +03:00
|
|
|
#ifdef NFS
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Receive a Sun RPC Request/Reply. For SOCK_DGRAM, the work is all
|
|
|
|
* done by soreceive(), but for SOCK_STREAM we must deal with the Record
|
|
|
|
* Mark and consolidate the data into a new mbuf list.
|
|
|
|
* nb: Sometimes TCP passes the data up to soreceive() in long lists of
|
|
|
|
* small mbufs.
|
|
|
|
* For SOCK_STREAM we must be very careful to read an entire record once
|
|
|
|
* we have read any of it, even if the system call has been interrupted.
|
|
|
|
*/
|
2008-04-10 16:32:37 +04:00
|
|
|
static int
|
|
|
|
nfs_receive(struct nfsreq *rep, struct mbuf **aname, struct mbuf **mp,
|
|
|
|
struct lwp *l)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct socket *so;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct uio auio;
|
|
|
|
struct iovec aio;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *control;
|
1995-12-20 02:07:11 +03:00
|
|
|
u_int32_t len;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mbuf **getnam;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error, sotype, rcvflg;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up arguments for soreceive()
|
|
|
|
*/
|
|
|
|
*mp = (struct mbuf *)0;
|
|
|
|
*aname = (struct mbuf *)0;
|
1994-06-08 15:33:09 +04:00
|
|
|
sotype = rep->r_nmp->nm_sotype;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For reliable protocols, lock against other senders/receivers
|
|
|
|
* in case a reconnect is necessary.
|
|
|
|
* For SOCK_STREAM, first get the Record Mark to find out how much
|
|
|
|
* more there is to get.
|
|
|
|
* We must lock the socket against other receivers
|
|
|
|
* until we have an entire rpc request/reply.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (sotype != SOCK_DGRAM) {
|
2007-04-29 14:30:18 +04:00
|
|
|
error = nfs_sndlock(rep->r_nmp, rep);
|
1996-02-18 14:53:36 +03:00
|
|
|
if (error)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
1993-03-21 12:45:37 +03:00
|
|
|
tryagain:
|
|
|
|
/*
|
|
|
|
* Check for fatal errors and resending request.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Ugh: If a reconnect attempt just happened, nm_so
|
|
|
|
* would have changed. NULL indicates a failed
|
|
|
|
* attempt that has essentially shut down this
|
|
|
|
* mount point.
|
|
|
|
*/
|
|
|
|
if (rep->r_mrep || (rep->r_flags & R_SOFTTERM)) {
|
2007-04-29 14:30:18 +04:00
|
|
|
nfs_sndunlock(rep->r_nmp);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (EINTR);
|
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
so = rep->r_nmp->nm_so;
|
|
|
|
if (!so) {
|
2007-10-21 12:23:19 +04:00
|
|
|
error = nfs_reconnect(rep);
|
1996-02-18 14:53:36 +03:00
|
|
|
if (error) {
|
2007-04-29 14:30:18 +04:00
|
|
|
nfs_sndunlock(rep->r_nmp);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
goto tryagain;
|
|
|
|
}
|
|
|
|
while (rep->r_flags & R_MUSTRESEND) {
|
|
|
|
m = m_copym(rep->r_mreq, 0, M_COPYALL, M_WAIT);
|
|
|
|
nfsstats.rpcretries++;
|
2004-05-23 12:08:48 +04:00
|
|
|
rep->r_rtt = 0;
|
|
|
|
rep->r_flags &= ~R_TIMING;
|
2005-12-11 15:16:03 +03:00
|
|
|
error = nfs_send(so, rep->r_nmp->nm_nam, m, rep, l);
|
1996-02-10 00:48:19 +03:00
|
|
|
if (error) {
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error == EINTR || error == ERESTART ||
|
2007-10-21 12:23:19 +04:00
|
|
|
(error = nfs_reconnect(rep)) != 0) {
|
2007-04-29 14:30:18 +04:00
|
|
|
nfs_sndunlock(rep->r_nmp);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
goto tryagain;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
2007-04-29 14:30:18 +04:00
|
|
|
nfs_sndunlock(rep->r_nmp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (sotype == SOCK_STREAM) {
|
2007-03-04 08:59:00 +03:00
|
|
|
aio.iov_base = (void *) &len;
|
1995-12-20 02:07:11 +03:00
|
|
|
aio.iov_len = sizeof(u_int32_t);
|
1993-03-21 12:45:37 +03:00
|
|
|
auio.uio_iov = &aio;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_rw = UIO_READ;
|
|
|
|
auio.uio_offset = 0;
|
1995-12-20 02:07:11 +03:00
|
|
|
auio.uio_resid = sizeof(u_int32_t);
|
2006-03-01 15:38:10 +03:00
|
|
|
UIO_SETUP_SYSSPACE(&auio);
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
1994-06-08 15:33:09 +04:00
|
|
|
rcvflg = MSG_WAITALL;
|
1998-04-25 21:41:01 +04:00
|
|
|
error = (*so->so_receive)(so, (struct mbuf **)0, &auio,
|
1993-03-21 12:45:37 +03:00
|
|
|
(struct mbuf **)0, (struct mbuf **)0, &rcvflg);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error == EWOULDBLOCK && rep) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (rep->r_flags & R_SOFTTERM)
|
|
|
|
return (EINTR);
|
2004-05-23 12:08:48 +04:00
|
|
|
/*
|
|
|
|
* if it seems that the server died after it
|
|
|
|
* received our request, set EPIPE so that
|
|
|
|
* we'll reconnect and retransmit requests.
|
|
|
|
*/
|
|
|
|
if (rep->r_rexmit >= rep->r_nmp->nm_retry) {
|
|
|
|
nfsstats.rpctimeouts++;
|
|
|
|
error = EPIPE;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
} while (error == EWOULDBLOCK);
|
|
|
|
if (!error && auio.uio_resid > 0) {
|
1998-01-31 01:44:13 +03:00
|
|
|
/*
|
|
|
|
* Don't log a 0 byte receive; it means
|
|
|
|
* that the socket has been closed, and
|
|
|
|
* can happen during normal operation
|
|
|
|
* (forcible unmount or Solaris server).
|
|
|
|
*/
|
|
|
|
if (auio.uio_resid != sizeof (u_int32_t))
|
|
|
|
log(LOG_INFO,
|
1999-02-12 04:37:06 +03:00
|
|
|
"short receive (%lu/%lu) from nfs server %s\n",
|
|
|
|
(u_long)sizeof(u_int32_t) - auio.uio_resid,
|
|
|
|
(u_long)sizeof(u_int32_t),
|
1993-03-21 12:45:37 +03:00
|
|
|
rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
|
|
|
|
error = EPIPE;
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
goto errout;
|
|
|
|
len = ntohl(len) & ~0x80000000;
|
|
|
|
/*
|
|
|
|
* This is SERIOUS! We are out of sync with the sender
|
|
|
|
* and forcing a disconnect/reconnect is all I can do.
|
|
|
|
*/
|
|
|
|
if (len > NFS_MAXPACKET) {
|
1994-06-08 15:33:09 +04:00
|
|
|
log(LOG_ERR, "%s (%d) from nfs server %s\n",
|
|
|
|
"impossible packet length",
|
|
|
|
len,
|
|
|
|
rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
|
1993-03-21 12:45:37 +03:00
|
|
|
error = EFBIG;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
auio.uio_resid = len;
|
|
|
|
do {
|
|
|
|
rcvflg = MSG_WAITALL;
|
1998-04-25 21:41:01 +04:00
|
|
|
error = (*so->so_receive)(so, (struct mbuf **)0,
|
1993-03-21 12:45:37 +03:00
|
|
|
&auio, mp, (struct mbuf **)0, &rcvflg);
|
|
|
|
} while (error == EWOULDBLOCK || error == EINTR ||
|
|
|
|
error == ERESTART);
|
|
|
|
if (!error && auio.uio_resid > 0) {
|
1998-01-31 01:44:13 +03:00
|
|
|
if (len != auio.uio_resid)
|
|
|
|
log(LOG_INFO,
|
1999-02-12 04:37:06 +03:00
|
|
|
"short receive (%lu/%d) from nfs server %s\n",
|
|
|
|
(u_long)len - auio.uio_resid, len,
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
|
1993-03-21 12:45:37 +03:00
|
|
|
error = EPIPE;
|
|
|
|
}
|
|
|
|
} else {
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* NB: Since uio_resid is big, MSG_WAITALL is ignored
|
|
|
|
* and soreceive() will return when it has either a
|
|
|
|
* control msg or a data msg.
|
|
|
|
* We have no use for control msg., but must grab them
|
|
|
|
* and then throw them away so we know what is going
|
|
|
|
* on.
|
|
|
|
*/
|
|
|
|
auio.uio_resid = len = 100000000; /* Anything Big */
|
2006-03-01 15:38:10 +03:00
|
|
|
/* not need to setup uio_vmspace */
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
|
|
|
rcvflg = 0;
|
1998-04-25 21:41:01 +04:00
|
|
|
error = (*so->so_receive)(so, (struct mbuf **)0,
|
1994-06-08 15:33:09 +04:00
|
|
|
&auio, mp, &control, &rcvflg);
|
|
|
|
if (control)
|
|
|
|
m_freem(control);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (error == EWOULDBLOCK && rep) {
|
|
|
|
if (rep->r_flags & R_SOFTTERM)
|
|
|
|
return (EINTR);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
} while (error == EWOULDBLOCK ||
|
|
|
|
(!error && *mp == NULL && control));
|
|
|
|
if ((rcvflg & MSG_EOR) == 0)
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("Egad!!\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!error && *mp == NULL)
|
|
|
|
error = EPIPE;
|
|
|
|
len -= auio.uio_resid;
|
|
|
|
}
|
|
|
|
errout:
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error && error != EINTR && error != ERESTART) {
|
1993-03-21 12:45:37 +03:00
|
|
|
m_freem(*mp);
|
|
|
|
*mp = (struct mbuf *)0;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error != EPIPE)
|
1993-03-21 12:45:37 +03:00
|
|
|
log(LOG_INFO,
|
|
|
|
"receive error %d from nfs server %s\n",
|
|
|
|
error,
|
|
|
|
rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
|
2007-04-29 14:30:18 +04:00
|
|
|
error = nfs_sndlock(rep->r_nmp, rep);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (!error)
|
2007-10-21 12:23:19 +04:00
|
|
|
error = nfs_reconnect(rep);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!error)
|
|
|
|
goto tryagain;
|
1997-05-13 03:40:22 +04:00
|
|
|
else
|
2007-04-29 14:30:18 +04:00
|
|
|
nfs_sndunlock(rep->r_nmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
} else {
|
1994-06-08 15:33:09 +04:00
|
|
|
if ((so = rep->r_nmp->nm_so) == NULL)
|
|
|
|
return (EACCES);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (so->so_state & SS_ISCONNECTED)
|
|
|
|
getnam = (struct mbuf **)0;
|
|
|
|
else
|
|
|
|
getnam = aname;
|
|
|
|
auio.uio_resid = len = 1000000;
|
2006-03-01 15:38:10 +03:00
|
|
|
/* not need to setup uio_vmspace */
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
|
|
|
rcvflg = 0;
|
1998-04-25 21:41:01 +04:00
|
|
|
error = (*so->so_receive)(so, getnam, &auio, mp,
|
1993-03-21 12:45:37 +03:00
|
|
|
(struct mbuf **)0, &rcvflg);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error == EWOULDBLOCK &&
|
1993-03-21 12:45:37 +03:00
|
|
|
(rep->r_flags & R_SOFTTERM))
|
|
|
|
return (EINTR);
|
|
|
|
} while (error == EWOULDBLOCK);
|
|
|
|
len -= auio.uio_resid;
|
1999-07-04 23:56:00 +04:00
|
|
|
if (!error && *mp == NULL)
|
|
|
|
error = EPIPE;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
m_freem(*mp);
|
|
|
|
*mp = (struct mbuf *)0;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implement receipt of reply on a socket.
|
|
|
|
* We must search through the list of received datagrams matching them
|
|
|
|
* with outstanding requests using the xid, until ours is found.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2008-04-10 16:32:37 +04:00
|
|
|
static int
|
|
|
|
nfs_reply(struct nfsreq *myrep, struct lwp *lwp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsreq *rep;
|
|
|
|
struct nfsmount *nmp = myrep->r_nmp;
|
|
|
|
int32_t t1;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *mrep, *nam, *md;
|
1995-12-20 02:07:11 +03:00
|
|
|
u_int32_t rxid, *tl;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *dpos, *cp2;
|
1994-06-08 15:33:09 +04:00
|
|
|
int error;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop around until we get our own reply
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
/*
|
|
|
|
* Lock against other receivers so that I don't get stuck in
|
|
|
|
* sbwait() after someone else has received my reply for me.
|
|
|
|
* Also necessary for connection based protocols to avoid
|
|
|
|
* race conditions during a reconnect.
|
|
|
|
*/
|
2007-04-29 14:30:18 +04:00
|
|
|
error = nfs_rcvlock(nmp, myrep);
|
1997-04-08 21:57:16 +04:00
|
|
|
if (error == EALREADY)
|
|
|
|
return (0);
|
1996-02-18 14:53:36 +03:00
|
|
|
if (error)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Get the next Rpc reply off the socket
|
|
|
|
*/
|
2007-04-29 18:56:59 +04:00
|
|
|
|
|
|
|
mutex_enter(&nmp->nm_lock);
|
1999-07-04 23:56:00 +04:00
|
|
|
nmp->nm_waiters++;
|
2007-04-29 18:56:59 +04:00
|
|
|
mutex_exit(&nmp->nm_lock);
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
error = nfs_receive(myrep, &nam, &mrep, lwp);
|
2007-04-29 18:56:59 +04:00
|
|
|
|
|
|
|
mutex_enter(&nmp->nm_lock);
|
|
|
|
nmp->nm_waiters--;
|
|
|
|
cv_signal(&nmp->nm_disconcv);
|
|
|
|
mutex_exit(&nmp->nm_lock);
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error) {
|
2007-05-02 18:48:47 +04:00
|
|
|
nfs_rcvunlock(nmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-07-04 23:56:00 +04:00
|
|
|
if (nmp->nm_iflag & NFSMNT_DISMNT) {
|
|
|
|
/*
|
|
|
|
* Oops, we're going away now..
|
|
|
|
*/
|
|
|
|
return error;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2000-06-27 21:52:28 +04:00
|
|
|
* Ignore routing errors on connectionless protocols? ?
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
if (NFSIGNORE_SOERROR(nmp->nm_soflags, error)) {
|
|
|
|
nmp->nm_so->so_error = 0;
|
1997-05-13 03:40:22 +04:00
|
|
|
#ifdef DEBUG
|
2008-11-23 11:22:07 +03:00
|
|
|
if (ratecheck(&nfs_reply_last_err_time,
|
|
|
|
&nfs_err_interval))
|
|
|
|
printf("%s: ignoring error %d\n",
|
|
|
|
__func__, error);
|
1997-05-13 03:40:22 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nam)
|
|
|
|
m_freem(nam);
|
2005-02-27 01:31:44 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Get the xid and check that it is an rpc reply
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
md = mrep;
|
2007-03-04 08:59:00 +03:00
|
|
|
dpos = mtod(md, void *);
|
1995-12-20 02:07:11 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, 2*NFSX_UNSIGNED);
|
1994-06-08 15:33:09 +04:00
|
|
|
rxid = *tl++;
|
|
|
|
if (*tl != rpc_reply) {
|
2006-12-27 15:10:09 +03:00
|
|
|
nfsstats.rpcinvalid++;
|
|
|
|
m_freem(mrep);
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsmout:
|
2007-05-02 18:48:47 +04:00
|
|
|
nfs_rcvunlock(nmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Loop through the request list to match up the reply
|
|
|
|
* Iff no match, just drop the datagram
|
|
|
|
*/
|
2002-03-18 01:22:39 +03:00
|
|
|
TAILQ_FOREACH(rep, &nfs_reqq, r_chain) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (rep->r_mrep == NULL && rxid == rep->r_xid) {
|
|
|
|
/* Found it.. */
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_mrep = mrep;
|
|
|
|
rep->r_md = md;
|
|
|
|
rep->r_dpos = dpos;
|
|
|
|
if (nfsrtton) {
|
|
|
|
struct rttl *rt;
|
|
|
|
|
|
|
|
rt = &nfsrtt.rttl[nfsrtt.pos];
|
|
|
|
rt->proc = rep->r_procnum;
|
|
|
|
rt->rto = NFS_RTO(nmp, proct[rep->r_procnum]);
|
|
|
|
rt->sent = nmp->nm_sent;
|
|
|
|
rt->cwnd = nmp->nm_cwnd;
|
|
|
|
rt->srtt = nmp->nm_srtt[proct[rep->r_procnum] - 1];
|
|
|
|
rt->sdrtt = nmp->nm_sdrtt[proct[rep->r_procnum] - 1];
|
2004-04-21 05:05:31 +04:00
|
|
|
rt->fsid = nmp->nm_mountp->mnt_stat.f_fsidx;
|
2006-06-08 02:33:33 +04:00
|
|
|
getmicrotime(&rt->tstamp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rep->r_flags & R_TIMING)
|
|
|
|
rt->rtt = rep->r_rtt;
|
|
|
|
else
|
|
|
|
rt->rtt = 1000000;
|
|
|
|
nfsrtt.pos = (nfsrtt.pos + 1) % NFSRTTLOGSIZ;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Update congestion window.
|
|
|
|
* Do the additive increase of
|
|
|
|
* one rpc/rtt.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nmp->nm_cwnd <= nmp->nm_sent) {
|
|
|
|
nmp->nm_cwnd +=
|
|
|
|
(NFS_CWNDSCALE * NFS_CWNDSCALE +
|
|
|
|
(nmp->nm_cwnd >> 1)) / nmp->nm_cwnd;
|
|
|
|
if (nmp->nm_cwnd > NFS_MAXCWND)
|
|
|
|
nmp->nm_cwnd = NFS_MAXCWND;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_flags &= ~R_SENT;
|
|
|
|
nmp->nm_sent -= NFS_CWNDSCALE;
|
|
|
|
/*
|
|
|
|
* Update rtt using a gain of 0.125 on the mean
|
|
|
|
* and a gain of 0.25 on the deviation.
|
|
|
|
*/
|
|
|
|
if (rep->r_flags & R_TIMING) {
|
|
|
|
/*
|
|
|
|
* Since the timer resolution of
|
|
|
|
* NFS_HZ is so course, it can often
|
|
|
|
* result in r_rtt == 0. Since
|
|
|
|
* r_rtt == N means that the actual
|
|
|
|
* rtt is between N+dt and N+2-dt ticks,
|
|
|
|
* add 1.
|
|
|
|
*/
|
|
|
|
t1 = rep->r_rtt + 1;
|
|
|
|
t1 -= (NFS_SRTT(rep) >> 3);
|
|
|
|
NFS_SRTT(rep) += t1;
|
|
|
|
if (t1 < 0)
|
|
|
|
t1 = -t1;
|
|
|
|
t1 -= (NFS_SDRTT(rep) >> 2);
|
|
|
|
NFS_SDRTT(rep) += t1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
nmp->nm_timeouts = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-02 18:48:47 +04:00
|
|
|
nfs_rcvunlock(nmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* If not matched to a request, drop it.
|
|
|
|
* If it's mine, get out.
|
|
|
|
*/
|
1994-08-17 15:41:36 +04:00
|
|
|
if (rep == 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
nfsstats.rpcunexpected++;
|
1994-06-08 15:33:09 +04:00
|
|
|
m_freem(mrep);
|
|
|
|
} else if (rep == myrep) {
|
|
|
|
if (rep->r_mrep == NULL)
|
|
|
|
panic("nfsreply nil");
|
|
|
|
return (0);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nfs_request - goes something like this
|
|
|
|
* - fill in request struct
|
|
|
|
* - links it into list
|
|
|
|
* - calls nfs_send() for first transmit
|
|
|
|
* - calls nfs_receive() to get reply
|
|
|
|
* - break down rpc header and return with nfs reply pointed to
|
|
|
|
* by mrep or error
|
|
|
|
* nb: always frees up mreq mbuf list
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
nfs_request(np, mrest, procnum, lwp, cred, mrp, mdp, dposp, rexmitp)
|
2003-04-25 01:21:04 +04:00
|
|
|
struct nfsnode *np;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *mrest;
|
1993-03-21 12:45:37 +03:00
|
|
|
int procnum;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *lwp;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t cred;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mbuf **mrp;
|
|
|
|
struct mbuf **mdp;
|
2007-03-04 08:59:00 +03:00
|
|
|
char **dposp;
|
2004-05-10 14:40:42 +04:00
|
|
|
int *rexmitp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m, *mrep;
|
|
|
|
struct nfsreq *rep;
|
|
|
|
u_int32_t *tl;
|
|
|
|
int i;
|
2004-08-25 00:09:44 +04:00
|
|
|
struct nfsmount *nmp = VFSTONFS(np->n_vnode->v_mount);
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *md, *mheadend;
|
1996-02-18 14:53:36 +03:00
|
|
|
char nickv[RPCX_NICKVERF];
|
2006-12-27 15:10:09 +03:00
|
|
|
time_t waituntil;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *dpos, *cp2;
|
2000-09-27 22:36:03 +04:00
|
|
|
int t1, s, error = 0, mrest_len, auth_len, auth_type;
|
2003-08-16 22:08:27 +04:00
|
|
|
int trylater_delay = NFS_TRYLATERDEL, failed_auth = 0;
|
1996-02-18 14:53:36 +03:00
|
|
|
int verf_len, verf_type;
|
1995-12-20 02:07:11 +03:00
|
|
|
u_int32_t xid;
|
1996-02-18 14:53:36 +03:00
|
|
|
char *auth_str, *verf_str;
|
|
|
|
NFSKERBKEY_T key; /* save session key */
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t acred;
|
2004-08-25 00:09:44 +04:00
|
|
|
struct mbuf *mrest_backup = NULL;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t origcred = NULL; /* XXX: gcc */
|
2007-02-22 09:05:00 +03:00
|
|
|
bool retry_cred = true;
|
2007-02-22 01:59:35 +03:00
|
|
|
bool use_opencred = (np->n_flag & NUSEOPENCRED) != 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2004-05-10 14:40:42 +04:00
|
|
|
if (rexmitp != NULL)
|
|
|
|
*rexmitp = 0;
|
|
|
|
|
2006-05-15 01:31:52 +04:00
|
|
|
acred = kauth_cred_alloc();
|
|
|
|
|
2004-08-25 00:09:44 +04:00
|
|
|
tryagain_cred:
|
2000-12-27 19:35:37 +03:00
|
|
|
KASSERT(cred != NULL);
|
2008-01-02 22:26:45 +03:00
|
|
|
rep = kmem_alloc(sizeof(*rep), KM_SLEEP);
|
1993-03-21 12:45:37 +03:00
|
|
|
rep->r_nmp = nmp;
|
2007-05-28 20:47:38 +04:00
|
|
|
KASSERT(lwp == NULL || lwp == curlwp);
|
2005-12-11 15:16:03 +03:00
|
|
|
rep->r_lwp = lwp;
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_procnum = procnum;
|
|
|
|
i = 0;
|
|
|
|
m = mrest;
|
1993-03-21 12:45:37 +03:00
|
|
|
while (m) {
|
1994-06-08 15:33:09 +04:00
|
|
|
i += m->m_len;
|
1993-03-21 12:45:37 +03:00
|
|
|
m = m->m_next;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
mrest_len = i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the RPC header with authorization.
|
|
|
|
*/
|
|
|
|
kerbauth:
|
1996-02-18 14:53:36 +03:00
|
|
|
verf_str = auth_str = (char *)0;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nmp->nm_flag & NFSMNT_KERB) {
|
1996-02-18 14:53:36 +03:00
|
|
|
verf_str = nickv;
|
|
|
|
verf_len = sizeof (nickv);
|
|
|
|
auth_type = RPCAUTH_KERB4;
|
2007-03-04 08:59:00 +03:00
|
|
|
memset((void *)key, 0, sizeof (key));
|
1996-02-18 14:53:36 +03:00
|
|
|
if (failed_auth || nfs_getnickauth(nmp, cred, &auth_str,
|
|
|
|
&auth_len, verf_str, verf_len)) {
|
|
|
|
error = nfs_getauth(nmp, rep, cred, &auth_str,
|
|
|
|
&auth_len, verf_str, &verf_len, key);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error) {
|
2008-01-02 22:26:45 +03:00
|
|
|
kmem_free(rep, sizeof(*rep));
|
1994-06-08 15:33:09 +04:00
|
|
|
m_freem(mrest);
|
2006-05-28 10:47:58 +04:00
|
|
|
KASSERT(kauth_cred_getrefcnt(acred) == 1);
|
|
|
|
kauth_cred_free(acred);
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2007-02-22 09:05:00 +03:00
|
|
|
retry_cred = false;
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
2004-08-25 00:09:44 +04:00
|
|
|
/* AUTH_UNIX */
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* on the most unix filesystems, permission checks are
|
|
|
|
* done when the file is open(2)'ed.
|
|
|
|
* ie. once a file is successfully open'ed,
|
|
|
|
* following i/o operations never fail with EACCES.
|
|
|
|
* we try to follow the semantics as far as possible.
|
|
|
|
*
|
|
|
|
* note that we expect that the nfs server always grant
|
|
|
|
* accesses by the file's owner.
|
|
|
|
*/
|
|
|
|
origcred = cred;
|
2003-12-08 00:15:46 +03:00
|
|
|
switch (procnum) {
|
|
|
|
case NFSPROC_READ:
|
|
|
|
case NFSPROC_WRITE:
|
|
|
|
case NFSPROC_COMMIT:
|
2004-08-25 00:09:44 +04:00
|
|
|
uid = np->n_vattr->va_uid;
|
|
|
|
gid = np->n_vattr->va_gid;
|
2006-05-15 01:31:52 +04:00
|
|
|
if (kauth_cred_geteuid(cred) == uid &&
|
|
|
|
kauth_cred_getegid(cred) == gid) {
|
2007-02-22 09:05:00 +03:00
|
|
|
retry_cred = false;
|
2004-08-25 00:09:44 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (use_opencred)
|
|
|
|
break;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_setuid(acred, uid);
|
|
|
|
kauth_cred_seteuid(acred, uid);
|
|
|
|
kauth_cred_setsvuid(acred, uid);
|
|
|
|
kauth_cred_setgid(acred, gid);
|
|
|
|
kauth_cred_setegid(acred, gid);
|
|
|
|
kauth_cred_setsvgid(acred, gid);
|
|
|
|
cred = acred;
|
2003-12-08 00:15:46 +03:00
|
|
|
break;
|
2004-08-25 00:09:44 +04:00
|
|
|
default:
|
2007-02-22 09:05:00 +03:00
|
|
|
retry_cred = false;
|
2004-08-25 00:09:44 +04:00
|
|
|
break;
|
2003-12-08 00:15:46 +03:00
|
|
|
}
|
2004-08-25 00:09:44 +04:00
|
|
|
/*
|
|
|
|
* backup mbuf chain if we can need it later to retry.
|
|
|
|
*
|
|
|
|
* XXX maybe we can keep a direct reference to
|
|
|
|
* mrest without doing m_copym, but it's ...ugly.
|
|
|
|
*/
|
|
|
|
if (retry_cred)
|
|
|
|
mrest_backup = m_copym(mrest, 0, M_COPYALL, M_WAIT);
|
1994-06-08 15:33:09 +04:00
|
|
|
auth_type = RPCAUTH_UNIX;
|
2006-05-15 01:31:52 +04:00
|
|
|
/* XXX elad - ngroups */
|
|
|
|
auth_len = (((kauth_cred_ngroups(cred) > nmp->nm_numgrps) ?
|
|
|
|
nmp->nm_numgrps : kauth_cred_ngroups(cred)) << 2) +
|
1994-06-08 15:33:09 +04:00
|
|
|
5 * NFSX_UNSIGNED;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
m = nfsm_rpchead(cred, nmp->nm_flag, procnum, auth_type, auth_len,
|
|
|
|
auth_str, verf_len, verf_str, mrest, mrest_len, &mheadend, &xid);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (auth_str)
|
|
|
|
free(auth_str, M_TEMP);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* For stream protocols, insert a Sun RPC Record Mark.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nmp->nm_sotype == SOCK_STREAM) {
|
|
|
|
M_PREPEND(m, NFSX_UNSIGNED, M_WAIT);
|
1995-12-20 02:07:11 +03:00
|
|
|
*mtod(m, u_int32_t *) = htonl(0x80000000 |
|
1994-06-08 15:33:09 +04:00
|
|
|
(m->m_pkthdr.len - NFSX_UNSIGNED));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_mreq = m;
|
|
|
|
rep->r_xid = xid;
|
|
|
|
tryagain:
|
|
|
|
if (nmp->nm_flag & NFSMNT_SOFT)
|
|
|
|
rep->r_retry = nmp->nm_retry;
|
|
|
|
else
|
|
|
|
rep->r_retry = NFS_MAXREXMIT + 1; /* past clip limit */
|
|
|
|
rep->r_rtt = rep->r_rexmit = 0;
|
|
|
|
if (proct[procnum] > 0)
|
|
|
|
rep->r_flags = R_TIMING;
|
|
|
|
else
|
|
|
|
rep->r_flags = 0;
|
|
|
|
rep->r_mrep = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the client side RPC.
|
|
|
|
*/
|
|
|
|
nfsstats.rpcrequests++;
|
|
|
|
/*
|
|
|
|
* Chain request into list of outstanding requests. Be sure
|
|
|
|
* to put it LAST so timer finds oldest requests first.
|
|
|
|
*/
|
1997-02-22 05:59:08 +03:00
|
|
|
s = splsoftnet();
|
1994-08-17 15:41:36 +04:00
|
|
|
TAILQ_INSERT_TAIL(&nfs_reqq, rep, r_chain);
|
2007-07-27 14:03:58 +04:00
|
|
|
nfs_timer_start();
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* If backing off another request or avoiding congestion, don't
|
|
|
|
* send this one now but let timer do it. If not timing a request,
|
|
|
|
* do it now.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nmp->nm_so && (nmp->nm_sotype != SOCK_DGRAM ||
|
2008-03-28 17:29:57 +03:00
|
|
|
(nmp->nm_flag & NFSMNT_DUMBTIMR) || nmp->nm_sent < nmp->nm_cwnd)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
|
|
|
if (nmp->nm_soflags & PR_CONNREQUIRED)
|
2007-04-29 14:30:18 +04:00
|
|
|
error = nfs_sndlock(nmp, rep);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (!error) {
|
1999-07-30 13:46:24 +04:00
|
|
|
m = m_copym(rep->r_mreq, 0, M_COPYALL, M_WAIT);
|
2005-12-11 15:16:03 +03:00
|
|
|
error = nfs_send(nmp->nm_so, nmp->nm_nam, m, rep, lwp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nmp->nm_soflags & PR_CONNREQUIRED)
|
2007-04-29 14:30:18 +04:00
|
|
|
nfs_sndunlock(nmp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
if (!error && (rep->r_flags & R_MUSTRESEND) == 0) {
|
|
|
|
nmp->nm_sent += NFS_CWNDSCALE;
|
|
|
|
rep->r_flags |= R_SENT;
|
|
|
|
}
|
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_rtt = -1;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the reply from our send or the timer's.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (!error || error == EPIPE)
|
2005-12-11 15:16:03 +03:00
|
|
|
error = nfs_reply(rep, lwp);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* RPC done, unlink the request.
|
|
|
|
*/
|
1997-02-22 05:59:08 +03:00
|
|
|
s = splsoftnet();
|
1994-08-17 15:41:36 +04:00
|
|
|
TAILQ_REMOVE(&nfs_reqq, rep, r_chain);
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Decrement the outstanding request count.
|
|
|
|
*/
|
|
|
|
if (rep->r_flags & R_SENT) {
|
|
|
|
rep->r_flags &= ~R_SENT; /* paranoia */
|
|
|
|
nmp->nm_sent -= NFS_CWNDSCALE;
|
|
|
|
}
|
|
|
|
|
2004-05-10 14:40:42 +04:00
|
|
|
if (rexmitp != NULL) {
|
|
|
|
int rexmit;
|
|
|
|
|
|
|
|
if (nmp->nm_sotype != SOCK_DGRAM)
|
|
|
|
rexmit = (rep->r_flags & R_REXMITTED) != 0;
|
|
|
|
else
|
|
|
|
rexmit = rep->r_rexmit;
|
|
|
|
*rexmitp = rexmit;
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* If there was a successful reply and a tprintf msg.
|
|
|
|
* tprintf a response.
|
|
|
|
*/
|
|
|
|
if (!error && (rep->r_flags & R_TPRINTFMSG))
|
2005-12-11 15:16:03 +03:00
|
|
|
nfs_msg(rep->r_lwp, nmp->nm_mountp->mnt_stat.f_mntfromname,
|
1993-03-21 12:45:37 +03:00
|
|
|
"is alive again");
|
|
|
|
mrep = rep->r_mrep;
|
1994-06-08 15:33:09 +04:00
|
|
|
md = rep->r_md;
|
|
|
|
dpos = rep->r_dpos;
|
2004-08-25 00:09:44 +04:00
|
|
|
if (error)
|
|
|
|
goto nfsmout;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* break down the rpc header and check if ok
|
|
|
|
*/
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (*tl++ == rpc_msgdenied) {
|
|
|
|
if (*tl == rpc_mismatch)
|
|
|
|
error = EOPNOTSUPP;
|
1994-06-08 15:33:09 +04:00
|
|
|
else if ((nmp->nm_flag & NFSMNT_KERB) && *tl++ == rpc_autherr) {
|
1996-02-18 14:53:36 +03:00
|
|
|
if (!failed_auth) {
|
1994-06-08 15:33:09 +04:00
|
|
|
failed_auth++;
|
|
|
|
mheadend->m_next = (struct mbuf *)0;
|
|
|
|
m_freem(mrep);
|
|
|
|
m_freem(rep->r_mreq);
|
|
|
|
goto kerbauth;
|
|
|
|
} else
|
|
|
|
error = EAUTH;
|
|
|
|
} else
|
1993-03-21 12:45:37 +03:00
|
|
|
error = EACCES;
|
|
|
|
m_freem(mrep);
|
2004-08-25 00:09:44 +04:00
|
|
|
goto nfsmout;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1996-02-18 14:53:36 +03:00
|
|
|
* Grab any Kerberos verifier, otherwise just throw it away.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-18 14:53:36 +03:00
|
|
|
verf_type = fxdr_unsigned(int, *tl++);
|
|
|
|
i = fxdr_unsigned(int32_t, *tl);
|
|
|
|
if ((nmp->nm_flag & NFSMNT_KERB) && verf_type == RPCAUTH_KERB4) {
|
|
|
|
error = nfs_savenickauth(nmp, cred, i, key, &md, &dpos, mrep);
|
|
|
|
if (error)
|
|
|
|
goto nfsmout;
|
|
|
|
} else if (i > 0)
|
|
|
|
nfsm_adv(nfsm_rndup(i));
|
1995-12-20 02:07:11 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
|
1993-03-21 12:45:37 +03:00
|
|
|
/* 0 == ok */
|
|
|
|
if (*tl == 0) {
|
1995-12-20 02:07:11 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (*tl != 0) {
|
|
|
|
error = fxdr_unsigned(int, *tl);
|
2005-09-25 04:20:38 +04:00
|
|
|
switch (error) {
|
|
|
|
case NFSERR_PERM:
|
|
|
|
error = EPERM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_NOENT:
|
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
|
2005-09-25 06:48:40 +04:00
|
|
|
case NFSERR_IO:
|
2005-09-25 16:49:09 +04:00
|
|
|
error = EIO;
|
2005-09-25 06:48:40 +04:00
|
|
|
break;
|
|
|
|
|
2005-09-25 04:20:38 +04:00
|
|
|
case NFSERR_NXIO:
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_ACCES:
|
|
|
|
error = EACCES;
|
|
|
|
if (!retry_cred)
|
|
|
|
break;
|
2004-08-25 00:09:44 +04:00
|
|
|
m_freem(mrep);
|
|
|
|
m_freem(rep->r_mreq);
|
2008-01-02 22:26:45 +03:00
|
|
|
kmem_free(rep, sizeof(*rep));
|
2004-08-25 00:09:44 +04:00
|
|
|
use_opencred = !use_opencred;
|
2006-05-15 01:31:52 +04:00
|
|
|
if (mrest_backup == NULL) {
|
2005-09-25 04:20:38 +04:00
|
|
|
/* m_copym failure */
|
2006-05-28 10:47:58 +04:00
|
|
|
KASSERT(
|
|
|
|
kauth_cred_getrefcnt(acred) == 1);
|
|
|
|
kauth_cred_free(acred);
|
2005-09-25 04:20:38 +04:00
|
|
|
return ENOMEM;
|
2006-05-15 01:31:52 +04:00
|
|
|
}
|
2004-08-25 00:09:44 +04:00
|
|
|
mrest = mrest_backup;
|
|
|
|
mrest_backup = NULL;
|
|
|
|
cred = origcred;
|
|
|
|
error = 0;
|
2007-02-22 09:05:00 +03:00
|
|
|
retry_cred = false;
|
2004-08-25 00:09:44 +04:00
|
|
|
goto tryagain_cred;
|
2005-09-25 04:20:38 +04:00
|
|
|
|
|
|
|
case NFSERR_EXIST:
|
|
|
|
error = EEXIST;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_XDEV:
|
|
|
|
error = EXDEV;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_NODEV:
|
|
|
|
error = ENODEV;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_NOTDIR:
|
|
|
|
error = ENOTDIR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_ISDIR:
|
|
|
|
error = EISDIR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_INVAL:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_FBIG:
|
|
|
|
error = EFBIG;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_NOSPC:
|
|
|
|
error = ENOSPC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_ROFS:
|
|
|
|
error = EROFS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_MLINK:
|
|
|
|
error = EMLINK;
|
|
|
|
break;
|
|
|
|
|
2005-09-25 06:48:40 +04:00
|
|
|
case NFSERR_TIMEDOUT:
|
|
|
|
error = ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
|
2005-09-25 04:20:38 +04:00
|
|
|
case NFSERR_NAMETOL:
|
|
|
|
error = ENAMETOOLONG;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_NOTEMPTY:
|
|
|
|
error = ENOTEMPTY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_DQUOT:
|
|
|
|
error = EDQUOT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_STALE:
|
|
|
|
/*
|
|
|
|
* If the File Handle was stale, invalidate the
|
|
|
|
* lookup cache, just in case.
|
|
|
|
*/
|
|
|
|
error = ESTALE;
|
|
|
|
cache_purge(NFSTOV(np));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_REMOTE:
|
|
|
|
error = EREMOTE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_WFLUSH:
|
|
|
|
case NFSERR_BADHANDLE:
|
|
|
|
case NFSERR_NOT_SYNC:
|
|
|
|
case NFSERR_BAD_COOKIE:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_NOTSUPP:
|
|
|
|
error = ENOTSUP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_TOOSMALL:
|
|
|
|
case NFSERR_SERVERFAULT:
|
|
|
|
case NFSERR_BADTYPE:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NFSERR_TRYLATER:
|
|
|
|
if ((nmp->nm_flag & NFSMNT_NFSV3) == 0)
|
|
|
|
break;
|
1996-02-18 14:53:36 +03:00
|
|
|
m_freem(mrep);
|
1994-06-08 15:33:09 +04:00
|
|
|
error = 0;
|
2006-06-08 02:33:33 +04:00
|
|
|
waituntil = time_second + trylater_delay;
|
2006-12-27 15:10:09 +03:00
|
|
|
while (time_second < waituntil) {
|
2007-08-05 13:40:39 +04:00
|
|
|
kpause("nfstrylater", false, hz, NULL);
|
2006-12-27 15:10:09 +03:00
|
|
|
}
|
2003-08-16 22:08:27 +04:00
|
|
|
trylater_delay *= NFS_TRYLATERDELMUL;
|
|
|
|
if (trylater_delay > NFS_TRYLATERDELMAX)
|
|
|
|
trylater_delay = NFS_TRYLATERDELMAX;
|
2003-07-23 17:52:23 +04:00
|
|
|
/*
|
|
|
|
* RFC1813:
|
|
|
|
* The client should wait and then try
|
|
|
|
* the request with a new RPC transaction ID.
|
|
|
|
*/
|
|
|
|
nfs_renewxid(rep);
|
1994-06-08 15:33:09 +04:00
|
|
|
goto tryagain;
|
2005-09-25 04:20:38 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("Invalid rpc error code %d\n", error);
|
|
|
|
#endif
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nmp->nm_flag & NFSMNT_NFSV3) {
|
|
|
|
*mrp = mrep;
|
|
|
|
*mdp = md;
|
|
|
|
*dposp = dpos;
|
|
|
|
error |= NFSERR_RETERR;
|
|
|
|
} else
|
|
|
|
m_freem(mrep);
|
2004-08-25 00:09:44 +04:00
|
|
|
goto nfsmout;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2004-08-25 00:09:44 +04:00
|
|
|
/*
|
|
|
|
* note which credential worked to minimize number of retries.
|
|
|
|
*/
|
|
|
|
if (use_opencred)
|
|
|
|
np->n_flag |= NUSEOPENCRED;
|
|
|
|
else
|
|
|
|
np->n_flag &= ~NUSEOPENCRED;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
*mrp = mrep;
|
|
|
|
*mdp = md;
|
|
|
|
*dposp = dpos;
|
2004-08-25 00:09:44 +04:00
|
|
|
|
|
|
|
KASSERT(error == 0);
|
|
|
|
goto nfsmout;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
m_freem(mrep);
|
1994-06-08 15:33:09 +04:00
|
|
|
error = EPROTONOSUPPORT;
|
1993-03-21 12:45:37 +03:00
|
|
|
nfsmout:
|
2006-05-28 10:47:58 +04:00
|
|
|
KASSERT(kauth_cred_getrefcnt(acred) == 1);
|
|
|
|
kauth_cred_free(acred);
|
1996-02-18 14:53:36 +03:00
|
|
|
m_freem(rep->r_mreq);
|
2008-01-02 22:26:45 +03:00
|
|
|
kmem_free(rep, sizeof(*rep));
|
2004-08-25 00:09:44 +04:00
|
|
|
m_freem(mrest_backup);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (error);
|
|
|
|
}
|
1997-01-31 05:58:48 +03:00
|
|
|
#endif /* NFS */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Generate the rpc reply header
|
|
|
|
* siz arg. is used to decide if adding a cluster is worthwhile
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1996-02-18 14:53:36 +03:00
|
|
|
nfs_rephead(siz, nd, slp, err, cache, frev, mrq, mbp, bposp)
|
1994-06-08 15:33:09 +04:00
|
|
|
int siz;
|
1996-02-18 14:53:36 +03:00
|
|
|
struct nfsrv_descript *nd;
|
|
|
|
struct nfssvc_sock *slp;
|
1994-06-08 15:33:09 +04:00
|
|
|
int err;
|
|
|
|
int cache;
|
|
|
|
u_quad_t *frev;
|
|
|
|
struct mbuf **mrq;
|
|
|
|
struct mbuf **mbp;
|
2007-03-04 08:59:00 +03:00
|
|
|
char **bposp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
u_int32_t *tl;
|
|
|
|
struct mbuf *mreq;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *bpos;
|
2003-02-26 09:31:08 +03:00
|
|
|
struct mbuf *mb;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-02-26 09:31:08 +03:00
|
|
|
mreq = m_gethdr(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(mreq, &nfs_mowner);
|
1994-06-08 15:33:09 +04:00
|
|
|
mb = mreq;
|
|
|
|
/*
|
|
|
|
* If this is a big reply, use a cluster else
|
|
|
|
* try and leave leading space for the lower level headers.
|
|
|
|
*/
|
|
|
|
siz += RPC_REPLYSIZ;
|
1998-07-20 20:41:05 +04:00
|
|
|
if (siz >= max_datalen) {
|
2003-02-26 09:31:08 +03:00
|
|
|
m_clget(mreq, M_WAIT);
|
1994-06-08 15:33:09 +04:00
|
|
|
} else
|
|
|
|
mreq->m_data += max_hdr;
|
1995-12-20 02:07:11 +03:00
|
|
|
tl = mtod(mreq, u_int32_t *);
|
1996-02-18 14:53:36 +03:00
|
|
|
mreq->m_len = 6 * NFSX_UNSIGNED;
|
2007-03-04 08:59:00 +03:00
|
|
|
bpos = ((char *)tl) + mreq->m_len;
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = txdr_unsigned(nd->nd_retxid);
|
|
|
|
*tl++ = rpc_reply;
|
1996-02-18 14:53:36 +03:00
|
|
|
if (err == ERPCMISMATCH || (err & NFSERR_AUTHERR)) {
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = rpc_msgdenied;
|
1996-02-18 14:53:36 +03:00
|
|
|
if (err & NFSERR_AUTHERR) {
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = rpc_autherr;
|
1996-02-18 14:53:36 +03:00
|
|
|
*tl = txdr_unsigned(err & ~NFSERR_AUTHERR);
|
1994-06-08 15:33:09 +04:00
|
|
|
mreq->m_len -= NFSX_UNSIGNED;
|
|
|
|
bpos -= NFSX_UNSIGNED;
|
|
|
|
} else {
|
|
|
|
*tl++ = rpc_mismatch;
|
1996-02-18 14:53:36 +03:00
|
|
|
*tl++ = txdr_unsigned(RPC_VER2);
|
|
|
|
*tl = txdr_unsigned(RPC_VER2);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = rpc_msgaccepted;
|
1996-02-18 14:53:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For Kerberos authentication, we must send the nickname
|
|
|
|
* verifier back, otherwise just RPCAUTH_NULL.
|
|
|
|
*/
|
|
|
|
if (nd->nd_flag & ND_KERBFULL) {
|
2003-05-21 17:31:04 +04:00
|
|
|
struct nfsuid *nuidp;
|
|
|
|
struct timeval ktvin, ktvout;
|
1996-02-18 14:53:36 +03:00
|
|
|
|
2006-05-11 01:53:14 +04:00
|
|
|
memset(&ktvout, 0, sizeof ktvout); /* XXX gcc */
|
|
|
|
|
2006-05-18 16:44:45 +04:00
|
|
|
LIST_FOREACH(nuidp,
|
|
|
|
NUIDHASH(slp, kauth_cred_geteuid(nd->nd_cr)),
|
2003-05-21 17:31:04 +04:00
|
|
|
nu_hash) {
|
2006-05-18 16:44:45 +04:00
|
|
|
if (kauth_cred_geteuid(nuidp->nu_cr) ==
|
|
|
|
kauth_cred_geteuid(nd->nd_cr) &&
|
2003-05-21 17:31:04 +04:00
|
|
|
(!nd->nd_nam2 || netaddr_match(
|
|
|
|
NU_NETFAM(nuidp), &nuidp->nu_haddr,
|
|
|
|
nd->nd_nam2)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nuidp) {
|
|
|
|
ktvin.tv_sec =
|
|
|
|
txdr_unsigned(nuidp->nu_timestamp.tv_sec
|
|
|
|
- 1);
|
|
|
|
ktvin.tv_usec =
|
|
|
|
txdr_unsigned(nuidp->nu_timestamp.tv_usec);
|
1996-02-18 14:53:36 +03:00
|
|
|
|
2003-05-21 17:31:04 +04:00
|
|
|
/*
|
|
|
|
* Encrypt the timestamp in ecb mode using the
|
|
|
|
* session key.
|
|
|
|
*/
|
1996-02-18 14:53:36 +03:00
|
|
|
#ifdef NFSKERB
|
2003-05-21 17:31:04 +04:00
|
|
|
XXX
|
1996-02-18 14:53:36 +03:00
|
|
|
#endif
|
|
|
|
|
2003-05-21 17:31:04 +04:00
|
|
|
*tl++ = rpc_auth_kerb;
|
|
|
|
*tl++ = txdr_unsigned(3 * NFSX_UNSIGNED);
|
|
|
|
*tl = ktvout.tv_sec;
|
|
|
|
nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
|
|
|
|
*tl++ = ktvout.tv_usec;
|
2006-05-18 16:44:45 +04:00
|
|
|
*tl++ = txdr_unsigned(
|
|
|
|
kauth_cred_geteuid(nuidp->nu_cr));
|
2003-05-21 17:31:04 +04:00
|
|
|
} else {
|
|
|
|
*tl++ = 0;
|
|
|
|
*tl++ = 0;
|
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
} else {
|
|
|
|
*tl++ = 0;
|
|
|
|
*tl++ = 0;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
switch (err) {
|
|
|
|
case EPROGUNAVAIL:
|
|
|
|
*tl = txdr_unsigned(RPC_PROGUNAVAIL);
|
|
|
|
break;
|
|
|
|
case EPROGMISMATCH:
|
|
|
|
*tl = txdr_unsigned(RPC_PROGMISMATCH);
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
|
2006-12-27 15:10:09 +03:00
|
|
|
*tl++ = txdr_unsigned(2);
|
|
|
|
*tl = txdr_unsigned(3);
|
1994-06-08 15:33:09 +04:00
|
|
|
break;
|
|
|
|
case EPROCUNAVAIL:
|
|
|
|
*tl = txdr_unsigned(RPC_PROCUNAVAIL);
|
|
|
|
break;
|
1996-02-18 14:53:36 +03:00
|
|
|
case EBADRPC:
|
|
|
|
*tl = txdr_unsigned(RPC_GARBAGE);
|
|
|
|
break;
|
1994-06-08 15:33:09 +04:00
|
|
|
default:
|
|
|
|
*tl = 0;
|
1996-02-18 14:53:36 +03:00
|
|
|
if (err != NFSERR_RETVOID) {
|
1995-12-20 02:07:11 +03:00
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (err)
|
1996-02-18 14:53:36 +03:00
|
|
|
*tl = txdr_unsigned(nfsrv_errmap(nd, err));
|
1994-06-08 15:33:09 +04:00
|
|
|
else
|
1996-02-18 14:53:36 +03:00
|
|
|
*tl = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
break;
|
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1997-02-10 00:19:04 +03:00
|
|
|
if (mrq != NULL)
|
|
|
|
*mrq = mreq;
|
1993-03-21 12:45:37 +03:00
|
|
|
*mbp = mb;
|
|
|
|
*bposp = bpos;
|
1996-02-18 14:53:36 +03:00
|
|
|
if (err != 0 && err != NFSERR_RETVOID)
|
1993-03-21 12:45:37 +03:00
|
|
|
nfsstats.srvrpc_errs++;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-07-27 14:03:58 +04:00
|
|
|
static void
|
|
|
|
nfs_timer_schedule(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
callout_schedule(&nfs_timer_ch, nfs_ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs_timer_start(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (callout_pending(&nfs_timer_ch))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nfs_timer_start_ev.ev_count++;
|
|
|
|
nfs_timer_schedule();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs_timer_init(void)
|
|
|
|
{
|
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
mutex_init(&nfs_timer_lock, MUTEX_DEFAULT, IPL_NONE);
|
2007-07-27 14:03:58 +04:00
|
|
|
callout_init(&nfs_timer_ch, 0);
|
|
|
|
callout_setfunc(&nfs_timer_ch, nfs_timer, NULL);
|
|
|
|
evcnt_attach_dynamic(&nfs_timer_ev, EVCNT_TYPE_MISC, NULL,
|
|
|
|
"nfs", "timer");
|
|
|
|
evcnt_attach_dynamic(&nfs_timer_start_ev, EVCNT_TYPE_MISC, NULL,
|
|
|
|
"nfs", "timer start");
|
|
|
|
evcnt_attach_dynamic(&nfs_timer_stop_ev, EVCNT_TYPE_MISC, NULL,
|
|
|
|
"nfs", "timer stop");
|
|
|
|
}
|
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
void
|
|
|
|
nfs_timer_fini(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
callout_halt(&nfs_timer_ch, NULL);
|
|
|
|
callout_destroy(&nfs_timer_ch);
|
|
|
|
mutex_destroy(&nfs_timer_lock);
|
|
|
|
evcnt_detach(&nfs_timer_ev);
|
|
|
|
evcnt_detach(&nfs_timer_start_ev);
|
|
|
|
evcnt_detach(&nfs_timer_stop_ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs_timer_srvinit(bool (*func)(void))
|
|
|
|
{
|
|
|
|
|
|
|
|
nfs_timer_srvvec = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs_timer_srvfini(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
mutex_enter(&nfs_timer_lock);
|
|
|
|
nfs_timer_srvvec = NULL;
|
|
|
|
mutex_exit(&nfs_timer_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Nfs timer routine
|
|
|
|
* Scan the nfsreq list and retranmit any requests that have timed out
|
|
|
|
* To avoid retransmission attempts on STREAM sockets (in the future) make
|
|
|
|
* sure to set the r_retry field to 0 (implies nm_retry == 0).
|
|
|
|
*/
|
1993-09-07 01:25:20 +04:00
|
|
|
void
|
2006-11-09 12:53:57 +03:00
|
|
|
nfs_timer(void *arg)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsreq *rep;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct socket *so;
|
|
|
|
struct nfsmount *nmp;
|
|
|
|
int timeo;
|
2009-02-04 23:36:54 +03:00
|
|
|
int error;
|
2007-07-27 14:03:58 +04:00
|
|
|
bool more = false;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2007-07-27 14:03:58 +04:00
|
|
|
nfs_timer_ev.ev_count++;
|
2007-07-10 00:51:58 +04:00
|
|
|
|
2009-02-04 23:36:54 +03:00
|
|
|
mutex_enter(softnet_lock); /* XXX PR 40491 */
|
2002-03-18 01:22:39 +03:00
|
|
|
TAILQ_FOREACH(rep, &nfs_reqq, r_chain) {
|
2007-07-27 14:03:58 +04:00
|
|
|
more = true;
|
1993-03-21 12:45:37 +03:00
|
|
|
nmp = rep->r_nmp;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rep->r_mrep || (rep->r_flags & R_SOFTTERM))
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
2005-12-11 15:16:03 +03:00
|
|
|
if (nfs_sigintr(nmp, rep, rep->r_lwp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
rep->r_flags |= R_SOFTTERM;
|
|
|
|
continue;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rep->r_rtt >= 0) {
|
|
|
|
rep->r_rtt++;
|
|
|
|
if (nmp->nm_flag & NFSMNT_DUMBTIMR)
|
|
|
|
timeo = nmp->nm_timeo;
|
|
|
|
else
|
|
|
|
timeo = NFS_RTO(nmp, proct[rep->r_procnum]);
|
|
|
|
if (nmp->nm_timeouts > 0)
|
|
|
|
timeo *= nfs_backoff[nmp->nm_timeouts - 1];
|
2009-01-18 12:45:05 +03:00
|
|
|
if (timeo > NFS_MAXTIMEO)
|
|
|
|
timeo = NFS_MAXTIMEO;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rep->r_rtt <= timeo)
|
|
|
|
continue;
|
2003-08-16 22:09:14 +04:00
|
|
|
if (nmp->nm_timeouts <
|
|
|
|
(sizeof(nfs_backoff) / sizeof(nfs_backoff[0])))
|
1994-06-08 15:33:09 +04:00
|
|
|
nmp->nm_timeouts++;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check for server not responding
|
|
|
|
*/
|
|
|
|
if ((rep->r_flags & R_TPRINTFMSG) == 0 &&
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_rexmit > nmp->nm_deadthresh) {
|
2005-12-11 15:16:03 +03:00
|
|
|
nfs_msg(rep->r_lwp,
|
1993-03-21 12:45:37 +03:00
|
|
|
nmp->nm_mountp->mnt_stat.f_mntfromname,
|
|
|
|
"not responding");
|
|
|
|
rep->r_flags |= R_TPRINTFMSG;
|
|
|
|
}
|
|
|
|
if (rep->r_rexmit >= rep->r_retry) { /* too many */
|
|
|
|
nfsstats.rpctimeouts++;
|
|
|
|
rep->r_flags |= R_SOFTTERM;
|
|
|
|
continue;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nmp->nm_sotype != SOCK_DGRAM) {
|
|
|
|
if (++rep->r_rexmit > NFS_MAXREXMIT)
|
|
|
|
rep->r_rexmit = NFS_MAXREXMIT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((so = nmp->nm_so) == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is enough space and the window allows..
|
|
|
|
* Resend it
|
1994-06-08 15:33:09 +04:00
|
|
|
* Set r_rtt to -1 in case we fail to send it now.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2009-02-04 23:36:54 +03:00
|
|
|
/* solock(so); XXX PR 40491 */
|
1994-06-08 15:33:09 +04:00
|
|
|
rep->r_rtt = -1;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (sbspace(&so->so_snd) >= rep->r_mreq->m_pkthdr.len &&
|
1994-06-08 15:33:09 +04:00
|
|
|
((nmp->nm_flag & NFSMNT_DUMBTIMR) ||
|
|
|
|
(rep->r_flags & R_SENT) ||
|
|
|
|
nmp->nm_sent < nmp->nm_cwnd) &&
|
|
|
|
(m = m_copym(rep->r_mreq, 0, M_COPYALL, M_DONTWAIT))){
|
1997-11-17 02:23:20 +03:00
|
|
|
if (so->so_state & SS_ISCONNECTED)
|
1993-03-21 12:45:37 +03:00
|
|
|
error = (*so->so_proto->pr_usrreq)(so, PRU_SEND, m,
|
2005-12-11 15:16:03 +03:00
|
|
|
(struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
|
|
|
error = (*so->so_proto->pr_usrreq)(so, PRU_SEND, m,
|
2005-12-11 15:16:03 +03:00
|
|
|
nmp->nm_nam, (struct mbuf *)0, (struct lwp *)0);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (error) {
|
1997-02-05 00:33:19 +03:00
|
|
|
if (NFSIGNORE_SOERROR(nmp->nm_soflags, error)) {
|
1997-05-13 03:40:22 +04:00
|
|
|
#ifdef DEBUG
|
2008-11-23 11:22:07 +03:00
|
|
|
if (ratecheck(&nfs_timer_last_err_time,
|
|
|
|
&nfs_err_interval))
|
|
|
|
printf("%s: ignoring error "
|
|
|
|
"%d\n", __func__, error);
|
1997-05-13 03:40:22 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
so->so_error = 0;
|
1997-02-05 00:33:19 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Iff first send, start timing
|
|
|
|
* else turn timing off, backoff timer
|
|
|
|
* and divide congestion window by 2.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rep->r_flags & R_SENT) {
|
|
|
|
rep->r_flags &= ~R_TIMING;
|
|
|
|
if (++rep->r_rexmit > NFS_MAXREXMIT)
|
|
|
|
rep->r_rexmit = NFS_MAXREXMIT;
|
|
|
|
nmp->nm_cwnd >>= 1;
|
|
|
|
if (nmp->nm_cwnd < NFS_CWNDSCALE)
|
|
|
|
nmp->nm_cwnd = NFS_CWNDSCALE;
|
|
|
|
nfsstats.rpcretries++;
|
|
|
|
} else {
|
|
|
|
rep->r_flags |= R_SENT;
|
|
|
|
nmp->nm_sent += NFS_CWNDSCALE;
|
|
|
|
}
|
|
|
|
rep->r_rtt = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
2009-02-04 23:36:54 +03:00
|
|
|
/* sounlock(so); XXX PR 40491 */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2009-02-04 23:36:54 +03:00
|
|
|
mutex_exit(softnet_lock); /* XXX PR 40491 */
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
mutex_enter(&nfs_timer_lock);
|
|
|
|
if (nfs_timer_srvvec != NULL) {
|
|
|
|
more |= (*nfs_timer_srvvec)();
|
1996-02-18 14:53:36 +03:00
|
|
|
}
|
2008-11-19 21:35:57 +03:00
|
|
|
mutex_exit(&nfs_timer_lock);
|
|
|
|
|
2007-07-27 14:03:58 +04:00
|
|
|
if (more) {
|
|
|
|
nfs_timer_schedule();
|
|
|
|
} else {
|
|
|
|
nfs_timer_stop_ev.ev_count++;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Test for a termination condition pending on the process.
|
|
|
|
* This is used for NFSMNT_INT mounts.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
nfs_sigintr(nmp, rep, l)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct nfsmount *nmp;
|
|
|
|
struct nfsreq *rep;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
1998-09-11 16:50:05 +04:00
|
|
|
sigset_t ss;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
if (rep && (rep->r_flags & R_SOFTTERM))
|
|
|
|
return (EINTR);
|
|
|
|
if (!(nmp->nm_flag & NFSMNT_INT))
|
|
|
|
return (0);
|
2005-12-11 15:16:03 +03:00
|
|
|
if (l) {
|
2007-02-10 00:55:00 +03:00
|
|
|
sigpending1(l, &ss);
|
1998-09-11 16:50:05 +04:00
|
|
|
#if 0
|
2005-12-11 15:16:03 +03:00
|
|
|
sigminusset(&l->l_proc->p_sigctx.ps_sigignore, &ss);
|
1998-09-11 16:50:05 +04:00
|
|
|
#endif
|
|
|
|
if (sigismember(&ss, SIGINT) || sigismember(&ss, SIGTERM) ||
|
|
|
|
sigismember(&ss, SIGKILL) || sigismember(&ss, SIGHUP) ||
|
|
|
|
sigismember(&ss, SIGQUIT))
|
|
|
|
return (EINTR);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2008-09-30 18:25:15 +04:00
|
|
|
#ifdef NFS
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Lock a socket against others.
|
|
|
|
* Necessary for STREAM sockets to ensure you get an entire rpc request/reply
|
|
|
|
* and also to avoid race conditions between the processes with nfs requests
|
|
|
|
* in progress when a reconnect is necessary.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2007-04-29 14:30:18 +04:00
|
|
|
static int
|
|
|
|
nfs_sndlock(struct nfsmount *nmp, struct nfsreq *rep)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l;
|
2007-04-29 14:30:18 +04:00
|
|
|
int timeo = 0;
|
|
|
|
bool catch = false;
|
|
|
|
int error = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rep) {
|
2005-12-11 15:16:03 +03:00
|
|
|
l = rep->r_lwp;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rep->r_nmp->nm_flag & NFSMNT_INT)
|
2007-04-29 14:30:18 +04:00
|
|
|
catch = true;
|
1994-06-08 15:33:09 +04:00
|
|
|
} else
|
2007-04-29 14:30:18 +04:00
|
|
|
l = NULL;
|
|
|
|
mutex_enter(&nmp->nm_lock);
|
|
|
|
while ((nmp->nm_iflag & NFSMNT_SNDLOCK) != 0) {
|
|
|
|
if (rep && nfs_sigintr(rep->r_nmp, rep, l)) {
|
|
|
|
error = EINTR;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
if (catch) {
|
|
|
|
cv_timedwait_sig(&nmp->nm_sndcv, &nmp->nm_lock, timeo);
|
|
|
|
} else {
|
|
|
|
cv_timedwait(&nmp->nm_sndcv, &nmp->nm_lock, timeo);
|
|
|
|
}
|
|
|
|
if (catch) {
|
|
|
|
catch = false;
|
|
|
|
timeo = 2 * hz;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2007-04-29 14:30:18 +04:00
|
|
|
nmp->nm_iflag |= NFSMNT_SNDLOCK;
|
|
|
|
quit:
|
|
|
|
mutex_exit(&nmp->nm_lock);
|
|
|
|
return error;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlock the stream socket for others.
|
|
|
|
*/
|
2007-04-29 14:30:18 +04:00
|
|
|
static void
|
|
|
|
nfs_sndunlock(struct nfsmount *nmp)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_enter(&nmp->nm_lock);
|
|
|
|
if ((nmp->nm_iflag & NFSMNT_SNDLOCK) == 0)
|
1994-06-08 15:33:09 +04:00
|
|
|
panic("nfs sndunlock");
|
2007-04-29 14:30:18 +04:00
|
|
|
nmp->nm_iflag &= ~NFSMNT_SNDLOCK;
|
|
|
|
cv_signal(&nmp->nm_sndcv);
|
|
|
|
mutex_exit(&nmp->nm_lock);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2008-09-30 18:25:15 +04:00
|
|
|
#endif /* NFS */
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2007-04-29 14:30:18 +04:00
|
|
|
static int
|
|
|
|
nfs_rcvlock(struct nfsmount *nmp, struct nfsreq *rep)
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int *flagp = &nmp->nm_iflag;
|
2007-04-29 14:30:18 +04:00
|
|
|
int slptimeo = 0;
|
|
|
|
bool catch;
|
2003-05-22 18:11:50 +04:00
|
|
|
int error = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2007-04-29 14:30:18 +04:00
|
|
|
KASSERT(nmp == rep->r_nmp);
|
|
|
|
|
2007-05-02 20:19:55 +04:00
|
|
|
catch = (nmp->nm_flag & NFSMNT_INT) != 0;
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_enter(&nmp->nm_lock);
|
2007-05-02 18:48:47 +04:00
|
|
|
while (/* CONSTCOND */ true) {
|
1999-07-04 23:56:00 +04:00
|
|
|
if (*flagp & NFSMNT_DISMNT) {
|
2007-04-29 18:56:59 +04:00
|
|
|
cv_signal(&nmp->nm_disconcv);
|
2003-05-22 18:11:50 +04:00
|
|
|
error = EIO;
|
2007-05-02 18:48:47 +04:00
|
|
|
break;
|
1999-07-04 23:56:00 +04:00
|
|
|
}
|
1997-04-08 21:57:16 +04:00
|
|
|
/* If our reply was received while we were sleeping,
|
|
|
|
* then just return without taking the lock to avoid a
|
|
|
|
* situation where a single iod could 'capture' the
|
|
|
|
* receive lock.
|
|
|
|
*/
|
2003-05-22 18:11:50 +04:00
|
|
|
if (rep->r_mrep != NULL) {
|
|
|
|
error = EALREADY;
|
2007-05-02 18:48:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nfs_sigintr(rep->r_nmp, rep, rep->r_lwp)) {
|
|
|
|
error = EINTR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((*flagp & NFSMNT_RCVLOCK) == 0) {
|
|
|
|
*flagp |= NFSMNT_RCVLOCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (catch) {
|
|
|
|
cv_timedwait_sig(&nmp->nm_rcvcv, &nmp->nm_lock,
|
|
|
|
slptimeo);
|
|
|
|
} else {
|
|
|
|
cv_timedwait(&nmp->nm_rcvcv, &nmp->nm_lock,
|
|
|
|
slptimeo);
|
2003-05-22 18:11:50 +04:00
|
|
|
}
|
2007-04-29 14:30:18 +04:00
|
|
|
if (catch) {
|
|
|
|
catch = false;
|
1994-06-08 15:33:09 +04:00
|
|
|
slptimeo = 2 * hz;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_exit(&nmp->nm_lock);
|
2003-05-22 18:11:50 +04:00
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Unlock the stream socket for others.
|
|
|
|
*/
|
2007-04-29 14:30:18 +04:00
|
|
|
static void
|
|
|
|
nfs_rcvunlock(struct nfsmount *nmp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_enter(&nmp->nm_lock);
|
|
|
|
if ((nmp->nm_iflag & NFSMNT_RCVLOCK) == 0)
|
1994-06-08 15:33:09 +04:00
|
|
|
panic("nfs rcvunlock");
|
2007-04-29 14:30:18 +04:00
|
|
|
nmp->nm_iflag &= ~NFSMNT_RCVLOCK;
|
2007-05-02 18:48:47 +04:00
|
|
|
cv_broadcast(&nmp->nm_rcvcv);
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_exit(&nmp->nm_lock);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Parse an RPC request
|
|
|
|
* - verify it
|
2006-05-18 16:44:45 +04:00
|
|
|
* - allocate and fill in the cred.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1996-02-18 14:53:36 +03:00
|
|
|
nfs_getreq(nd, nfsd, has_header)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsrv_descript *nd;
|
1996-02-18 14:53:36 +03:00
|
|
|
struct nfsd *nfsd;
|
1994-06-08 15:33:09 +04:00
|
|
|
int has_header;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int len, i;
|
|
|
|
u_int32_t *tl;
|
|
|
|
int32_t t1;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct uio uio;
|
|
|
|
struct iovec iov;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *dpos, *cp2, *cp;
|
1995-12-20 02:07:11 +03:00
|
|
|
u_int32_t nfsvers, auth_type;
|
1996-02-18 14:53:36 +03:00
|
|
|
uid_t nickuid;
|
2006-12-27 15:10:09 +03:00
|
|
|
int error = 0, ticklen;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *mrep, *md;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsuid *nuidp;
|
1996-02-18 14:53:36 +03:00
|
|
|
struct timeval tvin, tvout;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2006-05-11 01:53:14 +04:00
|
|
|
memset(&tvout, 0, sizeof tvout); /* XXX gcc */
|
|
|
|
|
2006-05-18 16:44:45 +04:00
|
|
|
KASSERT(nd->nd_cr == NULL);
|
1994-06-08 15:33:09 +04:00
|
|
|
mrep = nd->nd_mrep;
|
|
|
|
md = nd->nd_md;
|
|
|
|
dpos = nd->nd_dpos;
|
|
|
|
if (has_header) {
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, 10 * NFSX_UNSIGNED);
|
|
|
|
nd->nd_retxid = fxdr_unsigned(u_int32_t, *tl++);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (*tl++ != rpc_call) {
|
|
|
|
m_freem(mrep);
|
|
|
|
return (EBADRPC);
|
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
} else
|
|
|
|
nfsm_dissect(tl, u_int32_t *, 8 * NFSX_UNSIGNED);
|
1994-06-08 15:33:09 +04:00
|
|
|
nd->nd_repstat = 0;
|
1996-02-18 14:53:36 +03:00
|
|
|
nd->nd_flag = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (*tl++ != rpc_vers) {
|
|
|
|
nd->nd_repstat = ERPCMISMATCH;
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
if (*tl != nfs_prog) {
|
2006-12-27 15:10:09 +03:00
|
|
|
nd->nd_repstat = EPROGUNAVAIL;
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
tl++;
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsvers = fxdr_unsigned(u_int32_t, *tl++);
|
2006-12-27 15:10:09 +03:00
|
|
|
if (nfsvers < NFS_VER2 || nfsvers > NFS_VER3) {
|
1994-06-08 15:33:09 +04:00
|
|
|
nd->nd_repstat = EPROGMISMATCH;
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
|
|
|
}
|
2006-12-27 15:10:09 +03:00
|
|
|
if (nfsvers == NFS_VER3)
|
1996-02-18 14:53:36 +03:00
|
|
|
nd->nd_flag = ND_NFSV3;
|
|
|
|
nd->nd_procnum = fxdr_unsigned(u_int32_t, *tl++);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nd->nd_procnum == NFSPROC_NULL)
|
|
|
|
return (0);
|
2006-12-27 15:10:09 +03:00
|
|
|
if (nd->nd_procnum > NFSPROC_COMMIT ||
|
|
|
|
(!nd->nd_flag && nd->nd_procnum > NFSV2PROC_STATFS)) {
|
1994-06-08 15:33:09 +04:00
|
|
|
nd->nd_repstat = EPROCUNAVAIL;
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
if ((nd->nd_flag & ND_NFSV3) == 0)
|
|
|
|
nd->nd_procnum = nfsv3_procid[nd->nd_procnum];
|
1994-06-08 15:33:09 +04:00
|
|
|
auth_type = *tl++;
|
|
|
|
len = fxdr_unsigned(int, *tl++);
|
|
|
|
if (len < 0 || len > RPCAUTH_MAXSIZ) {
|
|
|
|
m_freem(mrep);
|
|
|
|
return (EBADRPC);
|
|
|
|
}
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
nd->nd_flag &= ~ND_KERBAUTH;
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Handle auth_unix or auth_kerb.
|
|
|
|
*/
|
|
|
|
if (auth_type == rpc_auth_unix) {
|
2006-05-15 01:31:52 +04:00
|
|
|
uid_t uid;
|
2008-01-02 22:26:45 +03:00
|
|
|
gid_t gid;
|
2006-05-15 01:31:52 +04:00
|
|
|
|
2006-05-18 16:44:45 +04:00
|
|
|
nd->nd_cr = kauth_cred_alloc();
|
1994-06-08 15:33:09 +04:00
|
|
|
len = fxdr_unsigned(int, *++tl);
|
|
|
|
if (len < 0 || len > NFS_MAXNAMLEN) {
|
|
|
|
m_freem(mrep);
|
2006-05-18 16:44:45 +04:00
|
|
|
error = EBADRPC;
|
|
|
|
goto errout;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
nfsm_adv(nfsm_rndup(len));
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
|
2006-05-15 01:31:52 +04:00
|
|
|
|
|
|
|
uid = fxdr_unsigned(uid_t, *tl++);
|
|
|
|
gid = fxdr_unsigned(gid_t, *tl++);
|
|
|
|
kauth_cred_setuid(nd->nd_cr, uid);
|
|
|
|
kauth_cred_seteuid(nd->nd_cr, uid);
|
2006-07-15 09:54:10 +04:00
|
|
|
kauth_cred_setsvuid(nd->nd_cr, uid);
|
|
|
|
kauth_cred_setgid(nd->nd_cr, gid);
|
|
|
|
kauth_cred_setegid(nd->nd_cr, gid);
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_setsvgid(nd->nd_cr, gid);
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
len = fxdr_unsigned(int, *tl);
|
|
|
|
if (len < 0 || len > RPCAUTH_UNIXGIDS) {
|
|
|
|
m_freem(mrep);
|
2006-05-18 16:44:45 +04:00
|
|
|
error = EBADRPC;
|
|
|
|
goto errout;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_dissect(tl, u_int32_t *, (len + 2) * NFSX_UNSIGNED);
|
2006-05-15 01:31:52 +04:00
|
|
|
|
2008-01-02 22:26:45 +03:00
|
|
|
if (len > 0) {
|
|
|
|
size_t grbuf_size = min(len, NGROUPS) * sizeof(gid_t);
|
|
|
|
gid_t *grbuf = kmem_alloc(grbuf_size, KM_SLEEP);
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (i < NGROUPS) /* XXX elad */
|
|
|
|
grbuf[i] = fxdr_unsigned(gid_t, *tl++);
|
|
|
|
else
|
|
|
|
tl++;
|
|
|
|
}
|
|
|
|
kauth_cred_setgroups(nd->nd_cr, grbuf,
|
|
|
|
min(len, NGROUPS), -1, UIO_SYSSPACE);
|
|
|
|
kmem_free(grbuf, grbuf_size);
|
2006-05-15 01:31:52 +04:00
|
|
|
}
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
len = fxdr_unsigned(int, *++tl);
|
|
|
|
if (len < 0 || len > RPCAUTH_MAXSIZ) {
|
1994-06-08 15:33:09 +04:00
|
|
|
m_freem(mrep);
|
2006-05-18 16:44:45 +04:00
|
|
|
error = EBADRPC;
|
|
|
|
goto errout;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
if (len > 0)
|
|
|
|
nfsm_adv(nfsm_rndup(len));
|
|
|
|
} else if (auth_type == rpc_auth_kerb) {
|
|
|
|
switch (fxdr_unsigned(int, *tl++)) {
|
|
|
|
case RPCAKN_FULLNAME:
|
|
|
|
ticklen = fxdr_unsigned(int, *tl);
|
|
|
|
*((u_int32_t *)nfsd->nfsd_authstr) = *tl;
|
|
|
|
uio.uio_resid = nfsm_rndup(ticklen) + NFSX_UNSIGNED;
|
|
|
|
nfsd->nfsd_authlen = uio.uio_resid + NFSX_UNSIGNED;
|
|
|
|
if (uio.uio_resid > (len - 2 * NFSX_UNSIGNED)) {
|
|
|
|
m_freem(mrep);
|
2006-05-18 16:44:45 +04:00
|
|
|
error = EBADRPC;
|
|
|
|
goto errout;
|
1996-02-18 14:53:36 +03:00
|
|
|
}
|
|
|
|
uio.uio_offset = 0;
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
2006-03-01 15:38:10 +03:00
|
|
|
UIO_SETUP_SYSSPACE(&uio);
|
2007-03-04 08:59:00 +03:00
|
|
|
iov.iov_base = (void *)&nfsd->nfsd_authstr[4];
|
1996-02-18 14:53:36 +03:00
|
|
|
iov.iov_len = RPCAUTH_MAXSIZ - 4;
|
|
|
|
nfsm_mtouio(&uio, uio.uio_resid);
|
|
|
|
nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
|
|
|
|
if (*tl++ != rpc_auth_kerb ||
|
|
|
|
fxdr_unsigned(int, *tl) != 4 * NFSX_UNSIGNED) {
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("Bad kerb verifier\n");
|
1996-02-18 14:53:36 +03:00
|
|
|
nd->nd_repstat = (NFSERR_AUTHERR|AUTH_BADVERF);
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
|
|
|
}
|
2007-03-04 08:59:00 +03:00
|
|
|
nfsm_dissect(cp, void *, 4 * NFSX_UNSIGNED);
|
1996-02-18 14:53:36 +03:00
|
|
|
tl = (u_int32_t *)cp;
|
|
|
|
if (fxdr_unsigned(int, *tl) != RPCAKN_FULLNAME) {
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("Not fullname kerb verifier\n");
|
1996-02-18 14:53:36 +03:00
|
|
|
nd->nd_repstat = (NFSERR_AUTHERR|AUTH_BADVERF);
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
cp += NFSX_UNSIGNED;
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(nfsd->nfsd_verfstr, cp, 3 * NFSX_UNSIGNED);
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsd->nfsd_verflen = 3 * NFSX_UNSIGNED;
|
|
|
|
nd->nd_flag |= ND_KERBFULL;
|
|
|
|
nfsd->nfsd_flag |= NFSD_NEEDAUTH;
|
|
|
|
break;
|
|
|
|
case RPCAKN_NICKNAME:
|
|
|
|
if (len != 2 * NFSX_UNSIGNED) {
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("Kerb nickname short\n");
|
1996-02-18 14:53:36 +03:00
|
|
|
nd->nd_repstat = (NFSERR_AUTHERR|AUTH_BADCRED);
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
nickuid = fxdr_unsigned(uid_t, *tl);
|
|
|
|
nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
|
|
|
|
if (*tl++ != rpc_auth_kerb ||
|
|
|
|
fxdr_unsigned(int, *tl) != 3 * NFSX_UNSIGNED) {
|
1996-10-13 05:39:03 +04:00
|
|
|
printf("Kerb nick verifier bad\n");
|
1996-02-18 14:53:36 +03:00
|
|
|
nd->nd_repstat = (NFSERR_AUTHERR|AUTH_BADVERF);
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
|
|
|
|
tvin.tv_sec = *tl++;
|
|
|
|
tvin.tv_usec = *tl;
|
|
|
|
|
2003-04-02 19:14:19 +04:00
|
|
|
LIST_FOREACH(nuidp, NUIDHASH(nfsd->nfsd_slp, nickuid),
|
|
|
|
nu_hash) {
|
2006-05-15 01:31:52 +04:00
|
|
|
if (kauth_cred_geteuid(nuidp->nu_cr) == nickuid &&
|
1996-02-18 14:53:36 +03:00
|
|
|
(!nd->nd_nam2 ||
|
|
|
|
netaddr_match(NU_NETFAM(nuidp),
|
|
|
|
&nuidp->nu_haddr, nd->nd_nam2)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!nuidp) {
|
|
|
|
nd->nd_repstat =
|
|
|
|
(NFSERR_AUTHERR|AUTH_REJECTCRED);
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
/*
|
|
|
|
* Now, decrypt the timestamp using the session key
|
|
|
|
* and validate it.
|
|
|
|
*/
|
|
|
|
#ifdef NFSKERB
|
|
|
|
XXX
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tvout.tv_sec = fxdr_unsigned(long, tvout.tv_sec);
|
|
|
|
tvout.tv_usec = fxdr_unsigned(long, tvout.tv_usec);
|
2006-06-08 02:33:33 +04:00
|
|
|
if (nuidp->nu_expire < time_second ||
|
1996-02-18 14:53:36 +03:00
|
|
|
nuidp->nu_timestamp.tv_sec > tvout.tv_sec ||
|
|
|
|
(nuidp->nu_timestamp.tv_sec == tvout.tv_sec &&
|
|
|
|
nuidp->nu_timestamp.tv_usec > tvout.tv_usec)) {
|
|
|
|
nuidp->nu_expire = 0;
|
|
|
|
nd->nd_repstat =
|
|
|
|
(NFSERR_AUTHERR|AUTH_REJECTVERF);
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
|
|
|
}
|
2006-05-18 16:44:45 +04:00
|
|
|
kauth_cred_hold(nuidp->nu_cr);
|
|
|
|
nd->nd_cr = nuidp->nu_cr;
|
1996-02-18 14:53:36 +03:00
|
|
|
nd->nd_flag |= ND_KERBNICK;
|
2006-05-18 16:44:45 +04:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
} else {
|
|
|
|
nd->nd_repstat = (NFSERR_AUTHERR | AUTH_REJECTCRED);
|
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
|
|
|
return (0);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nd->nd_md = md;
|
|
|
|
nd->nd_dpos = dpos;
|
2006-05-18 16:44:45 +04:00
|
|
|
KASSERT((nd->nd_cr == NULL && (nfsd->nfsd_flag & NFSD_NEEDAUTH) != 0)
|
|
|
|
|| (nd->nd_cr != NULL && (nfsd->nfsd_flag & NFSD_NEEDAUTH) == 0));
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
|
|
|
nfsmout:
|
2006-05-18 16:44:45 +04:00
|
|
|
errout:
|
|
|
|
KASSERT(error != 0);
|
|
|
|
if (nd->nd_cr != NULL) {
|
|
|
|
kauth_cred_free(nd->nd_cr);
|
|
|
|
nd->nd_cr = NULL;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
nfs_msg(l, server, msg)
|
|
|
|
struct lwp *l;
|
2005-05-30 00:58:13 +04:00
|
|
|
const char *server, *msg;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
tpr_t tpr;
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
if (l)
|
|
|
|
tpr = tprintf_open(l->l_proc);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
|
|
|
tpr = NULL;
|
|
|
|
tprintf(tpr, "nfs server %s: %s\n", server, msg);
|
|
|
|
tprintf_close(tpr);
|
1996-02-18 14:53:36 +03:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
static struct pool nfs_srvdesc_pool;
|
2007-12-04 20:42:30 +03:00
|
|
|
|
|
|
|
void
|
2008-11-19 21:35:57 +03:00
|
|
|
nfsdreq_init(void)
|
2007-12-04 20:42:30 +03:00
|
|
|
{
|
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
pool_init(&nfs_srvdesc_pool, sizeof(struct nfsrv_descript),
|
|
|
|
0, 0, 0, "nfsrvdescpl", &pool_allocator_nointr, IPL_NONE);
|
2007-12-04 20:42:30 +03:00
|
|
|
}
|
2006-05-19 17:53:11 +04:00
|
|
|
|
|
|
|
void
|
2008-11-19 21:35:57 +03:00
|
|
|
nfsdreq_fini(void)
|
2006-05-19 17:53:11 +04:00
|
|
|
{
|
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
pool_destroy(&nfs_srvdesc_pool);
|
2006-05-19 17:53:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct nfsrv_descript *
|
|
|
|
nfsdreq_alloc(void)
|
|
|
|
{
|
|
|
|
struct nfsrv_descript *nd;
|
|
|
|
|
|
|
|
nd = pool_get(&nfs_srvdesc_pool, PR_WAITOK);
|
|
|
|
nd->nd_cr = NULL;
|
|
|
|
return nd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfsdreq_free(struct nfsrv_descript *nd)
|
|
|
|
{
|
|
|
|
kauth_cred_t cr;
|
|
|
|
|
|
|
|
cr = nd->nd_cr;
|
|
|
|
if (cr != NULL) {
|
|
|
|
kauth_cred_free(cr);
|
|
|
|
}
|
|
|
|
pool_put(&nfs_srvdesc_pool, nd);
|
|
|
|
}
|