2007-08-08 16:27:56 +04:00
|
|
|
/* $NetBSD: nfs_syscalls.c,v 1.123 2007/08/08 12:27:56 yamt Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* 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_syscalls.c 8.5 (Berkeley) 3/30/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-10 13:59:08 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-08-08 16:27:56 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: nfs_syscalls.c,v 1.123 2007/08/08 12:27:56 yamt Exp $");
|
2001-11-10 13:59:08 +03:00
|
|
|
|
1998-02-19 03:54:13 +03:00
|
|
|
#include "fs_nfs.h"
|
2000-09-19 21:04:50 +04:00
|
|
|
#include "opt_nfs.h"
|
1998-06-26 02:17:36 +04:00
|
|
|
#include "opt_nfsserver.h"
|
1998-07-05 08:37:35 +04:00
|
|
|
#include "opt_iso.h"
|
2000-06-09 04:00:17 +04:00
|
|
|
#include "opt_inet.h"
|
2000-04-16 01:14:48 +04:00
|
|
|
#include "opt_compat_netbsd.h"
|
1998-02-19 03:54:13 +03:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/proc.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <sys/uio.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
2000-04-16 01:14:48 +04:00
|
|
|
#include <sys/signalvar.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/protosw.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/syslog.h>
|
1996-02-10 00:48:19 +03:00
|
|
|
#include <sys/filedesc.h>
|
2000-04-16 01:14:48 +04:00
|
|
|
#include <sys/kthread.h>
|
2006-05-15 01:31:52 +04:00
|
|
|
#include <sys/kauth.h>
|
1994-10-20 07:28:10 +03:00
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#ifdef ISO
|
|
|
|
#include <netiso/iso.h>
|
|
|
|
#endif
|
1996-02-18 14:53:36 +03:00
|
|
|
#include <nfs/xdr_subs.h>
|
1994-06-08 15:33:09 +04: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>
|
1996-02-18 14:53:36 +03:00
|
|
|
#include <nfs/nfsm_subs.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <nfs/nfsrvcache.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <nfs/nfsmount.h>
|
|
|
|
#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
|
|
|
|
|
|
|
/* Global defs. */
|
1996-02-18 14:53:36 +03:00
|
|
|
extern int32_t (*nfsrv3_procs[NFS_NPROCS]) __P((struct nfsrv_descript *,
|
|
|
|
struct nfssvc_sock *,
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *, struct mbuf **));
|
1996-02-18 14:53:36 +03:00
|
|
|
extern int nfsrvw_procrastinate;
|
2002-05-13 03:04:35 +04:00
|
|
|
|
2000-11-25 02:30:02 +03:00
|
|
|
struct nfssvc_sock *nfs_udpsock;
|
|
|
|
#ifdef ISO
|
|
|
|
struct nfssvc_sock *nfs_cltpsock;
|
|
|
|
#endif
|
2000-06-09 04:00:17 +04:00
|
|
|
#ifdef INET6
|
|
|
|
struct nfssvc_sock *nfs_udp6sock;
|
|
|
|
#endif
|
1994-06-08 15:33:09 +04:00
|
|
|
int nuidhash_max = NFS_MAXUIDHASH;
|
1996-02-10 00:48:19 +03:00
|
|
|
#ifdef NFSSERVER
|
|
|
|
static int nfs_numnfsd = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
static struct nfsdrt nfsdrt;
|
1996-02-10 00:48:19 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-06-25 18:37:50 +04:00
|
|
|
#ifdef NFSSERVER
|
2007-06-01 15:56:03 +04:00
|
|
|
kmutex_t nfsd_lock;
|
2002-05-13 03:04:35 +04:00
|
|
|
struct nfssvc_sockhead nfssvc_sockhead;
|
2007-06-01 15:56:03 +04:00
|
|
|
kcondvar_t nfsd_initcv;
|
2003-06-25 18:37:50 +04:00
|
|
|
struct nfssvc_sockhead nfssvc_sockpending;
|
2002-05-13 03:04:35 +04:00
|
|
|
struct nfsdhead nfsd_head;
|
2003-06-25 18:37:50 +04:00
|
|
|
struct nfsdidlehead nfsd_idle_head;
|
2002-05-13 03:04:35 +04:00
|
|
|
|
|
|
|
int nfssvc_sockhead_flag;
|
|
|
|
int nfsd_head_flag;
|
2003-06-25 18:37:50 +04:00
|
|
|
#endif
|
2002-05-13 03:04:35 +04:00
|
|
|
|
2003-02-01 09:23:35 +03:00
|
|
|
MALLOC_DEFINE(M_NFSUID, "NFS uid", "Nfs uid mapping structure");
|
|
|
|
|
1997-01-31 05:58:48 +03:00
|
|
|
#ifdef NFS
|
2007-08-08 16:27:56 +04:00
|
|
|
kmutex_t nfs_iodlist_lock;
|
2003-04-09 18:22:33 +04:00
|
|
|
struct nfs_iod nfs_asyncdaemon[NFS_MAXASYNCDAEMON];
|
2000-05-07 05:38:36 +04:00
|
|
|
int nfs_niothreads = -1; /* == "0, and has never been set" */
|
1996-12-03 03:22:43 +03:00
|
|
|
#endif
|
1996-02-18 14:53:36 +03:00
|
|
|
|
1996-02-10 00:48:19 +03:00
|
|
|
#ifdef NFSSERVER
|
2003-05-26 17:30:07 +04:00
|
|
|
static struct nfssvc_sock *nfsrv_sockalloc __P((void));
|
2004-06-10 16:59:57 +04:00
|
|
|
static void nfsrv_sockfree __P((struct nfssvc_sock *));
|
2006-01-03 15:30:01 +03:00
|
|
|
static void nfsd_rt __P((int, struct nfsrv_descript *, int));
|
1996-02-10 00:48:19 +03:00
|
|
|
#endif
|
1996-02-18 14:53:36 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* NFS server system calls
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1996-02-18 14:53:36 +03:00
|
|
|
* Nfs server pseudo system call for the nfsd's
|
1994-06-08 15:33:09 +04:00
|
|
|
* Based on the flag value it either:
|
|
|
|
* - adds a socket to the selection list
|
|
|
|
* - remains in the kernel as an nfsd
|
|
|
|
* - remains in the kernel as an nfsiod
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2006-11-09 12:53:57 +03:00
|
|
|
sys_nfssvc(struct lwp *l, void *v, register_t *retval)
|
1995-09-20 01:40:36 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct sys_nfssvc_args /* {
|
1994-10-20 07:28:10 +03:00
|
|
|
syscallarg(int) flag;
|
2007-03-04 08:59:00 +03:00
|
|
|
syscallarg(void *) argp;
|
1995-09-20 01:40:36 +04:00
|
|
|
} */ *uap = v;
|
1996-02-10 00:48:19 +03:00
|
|
|
int error;
|
|
|
|
#ifdef NFSSERVER
|
1993-03-21 12:45:37 +03:00
|
|
|
struct file *fp;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *nam;
|
|
|
|
struct nfsd_args nfsdarg;
|
|
|
|
struct nfsd_srvargs nfsd_srvargs, *nsd = &nfsd_srvargs;
|
|
|
|
struct nfsd *nfsd;
|
|
|
|
struct nfssvc_sock *slp;
|
1996-02-10 00:48:19 +03:00
|
|
|
struct nfsuid *nuidp;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Must be super user
|
|
|
|
*/
|
2006-07-24 02:06:03 +04:00
|
|
|
error = kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
|
2007-01-04 23:24:08 +03:00
|
|
|
NULL);
|
2003-12-07 21:58:11 +03:00
|
|
|
if (error)
|
1993-03-21 12:45:37 +03:00
|
|
|
return (error);
|
2005-11-25 23:01:38 +03:00
|
|
|
|
|
|
|
/* Initialize NFS server / client shared data. */
|
|
|
|
nfs_init();
|
|
|
|
|
2003-06-26 17:38:53 +04:00
|
|
|
#ifdef NFSSERVER
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
1994-08-17 18:43:47 +04:00
|
|
|
while (nfssvc_sockhead_flag & SLP_INIT) {
|
2007-06-01 15:56:03 +04:00
|
|
|
cv_wait(&nfsd_initcv, &nfsd_lock);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
2003-06-26 17:38:53 +04:00
|
|
|
#endif
|
1994-10-20 07:28:10 +03:00
|
|
|
if (SCARG(uap, flag) & NFSSVC_BIOD) {
|
2000-04-16 01:14:48 +04:00
|
|
|
#if defined(NFS) && defined(COMPAT_14)
|
2007-07-20 19:36:41 +04:00
|
|
|
error = kpause("nfsbiod", true, 0, NULL); /* dummy impl */
|
1996-02-18 14:53:36 +03:00
|
|
|
#else
|
|
|
|
error = ENOSYS;
|
|
|
|
#endif
|
1994-10-20 07:28:10 +03:00
|
|
|
} else if (SCARG(uap, flag) & NFSSVC_MNTD) {
|
1994-06-08 15:33:09 +04:00
|
|
|
error = ENOSYS;
|
1994-10-20 07:28:10 +03:00
|
|
|
} else if (SCARG(uap, flag) & NFSSVC_ADDSOCK) {
|
1994-06-08 15:33:09 +04:00
|
|
|
#ifndef NFSSERVER
|
|
|
|
error = ENOSYS;
|
1996-02-18 14:53:36 +03:00
|
|
|
#else
|
2007-03-04 08:59:00 +03:00
|
|
|
error = copyin(SCARG(uap, argp), (void *)&nfsdarg,
|
1996-02-18 14:53:36 +03:00
|
|
|
sizeof(nfsdarg));
|
1996-02-10 00:48:19 +03:00
|
|
|
if (error)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
1999-05-06 00:01:01 +04:00
|
|
|
/* getsock() will use the descriptor for us */
|
2006-07-24 02:06:03 +04:00
|
|
|
error = getsock(l->l_proc->p_fd, nfsdarg.sock, &fp);
|
1996-02-18 14:53:36 +03:00
|
|
|
if (error)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
/*
|
|
|
|
* Get the client address for connected sockets.
|
|
|
|
*/
|
|
|
|
if (nfsdarg.name == NULL || nfsdarg.namelen == 0)
|
|
|
|
nam = (struct mbuf *)0;
|
1996-02-10 00:48:19 +03:00
|
|
|
else {
|
|
|
|
error = sockargs(&nam, nfsdarg.name, nfsdarg.namelen,
|
1996-02-18 14:53:36 +03:00
|
|
|
MT_SONAME);
|
1999-05-06 00:01:01 +04:00
|
|
|
if (error) {
|
|
|
|
FILE_UNUSE(fp, NULL);
|
1996-02-10 00:48:19 +03:00
|
|
|
return (error);
|
1999-05-06 00:01:01 +04:00
|
|
|
}
|
1996-02-10 00:48:19 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
error = nfssvc_addsock(fp, nam);
|
1999-05-06 00:01:01 +04:00
|
|
|
FILE_UNUSE(fp, NULL);
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
#endif /* !NFSSERVER */
|
|
|
|
} else if (SCARG(uap, flag) & NFSSVC_SETEXPORTSLIST) {
|
|
|
|
#ifndef NFSSERVER
|
|
|
|
error = ENOSYS;
|
|
|
|
#else
|
|
|
|
struct export_args *args;
|
|
|
|
struct mountd_exports_list mel;
|
|
|
|
|
|
|
|
error = copyin(SCARG(uap, argp), &mel, sizeof(mel));
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
args = (struct export_args *)malloc(mel.mel_nexports *
|
|
|
|
sizeof(struct export_args), M_TEMP, M_WAITOK);
|
|
|
|
error = copyin(mel.mel_exports, args, mel.mel_nexports *
|
|
|
|
sizeof(struct export_args));
|
|
|
|
if (error != 0) {
|
|
|
|
free(args, M_TEMP);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
mel.mel_exports = args;
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
error = mountd_set_exports_list(&mel, l);
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
|
|
|
|
free(args, M_TEMP);
|
1994-06-08 15:33:09 +04:00
|
|
|
#endif /* !NFSSERVER */
|
|
|
|
} else {
|
|
|
|
#ifndef NFSSERVER
|
|
|
|
error = ENOSYS;
|
1996-02-18 14:53:36 +03:00
|
|
|
#else
|
2007-03-04 08:59:00 +03:00
|
|
|
error = copyin(SCARG(uap, argp), (void *)nsd, sizeof (*nsd));
|
1996-02-10 00:48:19 +03:00
|
|
|
if (error)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
1994-10-20 07:28:10 +03:00
|
|
|
if ((SCARG(uap, flag) & NFSSVC_AUTHIN) &&
|
1996-02-18 14:53:36 +03:00
|
|
|
((nfsd = nsd->nsd_nfsd)) != NULL &&
|
|
|
|
(nfsd->nfsd_slp->ns_flag & SLP_VALID)) {
|
|
|
|
slp = nfsd->nfsd_slp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First check to see if another nfsd has already
|
|
|
|
* added this credential.
|
|
|
|
*/
|
2006-05-15 01:31:52 +04:00
|
|
|
LIST_FOREACH(nuidp, NUIDHASH(slp, nsd->nsd_cr.cr_uid),
|
2003-04-02 19:14:19 +04:00
|
|
|
nu_hash) {
|
2006-05-18 16:44:45 +04:00
|
|
|
if (kauth_cred_geteuid(nuidp->nu_cr) ==
|
|
|
|
nsd->nsd_cr.cr_uid &&
|
1996-02-18 14:53:36 +03:00
|
|
|
(!nfsd->nfsd_nd->nd_nam2 ||
|
|
|
|
netaddr_match(NU_NETFAM(nuidp),
|
|
|
|
&nuidp->nu_haddr, nfsd->nfsd_nd->nd_nam2)))
|
1994-06-08 15:33:09 +04:00
|
|
|
break;
|
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nuidp) {
|
2006-05-18 16:44:45 +04:00
|
|
|
kauth_cred_hold(nuidp->nu_cr);
|
|
|
|
nfsd->nfsd_nd->nd_cr = nuidp->nu_cr;
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
|
|
|
|
} else {
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Nope, so we will.
|
|
|
|
*/
|
|
|
|
if (slp->ns_numuids < nuidhash_max) {
|
|
|
|
slp->ns_numuids++;
|
|
|
|
nuidp = (struct nfsuid *)
|
|
|
|
malloc(sizeof (struct nfsuid), M_NFSUID,
|
|
|
|
M_WAITOK);
|
|
|
|
} else
|
|
|
|
nuidp = (struct nfsuid *)0;
|
|
|
|
if ((slp->ns_flag & SLP_VALID) == 0) {
|
|
|
|
if (nuidp)
|
2007-03-04 08:59:00 +03:00
|
|
|
free((void *)nuidp, M_NFSUID);
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
|
|
|
if (nuidp == (struct nfsuid *)0) {
|
2003-04-02 19:14:19 +04:00
|
|
|
nuidp = TAILQ_FIRST(&slp->ns_uidlruhead);
|
1994-08-17 18:43:47 +04:00
|
|
|
LIST_REMOVE(nuidp, nu_hash);
|
|
|
|
TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp,
|
|
|
|
nu_lru);
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nuidp->nu_flag & NU_NAM)
|
|
|
|
m_freem(nuidp->nu_nam);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
nuidp->nu_flag = 0;
|
2006-10-22 17:07:15 +04:00
|
|
|
kauth_uucred_to_cred(nuidp->nu_cr,
|
|
|
|
&nsd->nsd_cr);
|
1996-02-18 14:53:36 +03:00
|
|
|
nuidp->nu_timestamp = nsd->nsd_timestamp;
|
2006-06-08 02:33:33 +04:00
|
|
|
nuidp->nu_expire = time_second + nsd->nsd_ttl;
|
1996-02-18 14:53:36 +03:00
|
|
|
/*
|
|
|
|
* and save the session key in nu_key.
|
|
|
|
*/
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(nuidp->nu_key, nsd->nsd_key,
|
|
|
|
sizeof(nsd->nsd_key));
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nfsd->nfsd_nd->nd_nam2) {
|
|
|
|
struct sockaddr_in *saddr;
|
|
|
|
|
|
|
|
saddr = mtod(nfsd->nfsd_nd->nd_nam2,
|
|
|
|
struct sockaddr_in *);
|
|
|
|
switch (saddr->sin_family) {
|
|
|
|
case AF_INET:
|
|
|
|
nuidp->nu_flag |= NU_INETADDR;
|
|
|
|
nuidp->nu_inetaddr =
|
|
|
|
saddr->sin_addr.s_addr;
|
|
|
|
break;
|
|
|
|
case AF_ISO:
|
|
|
|
default:
|
|
|
|
nuidp->nu_flag |= NU_NAM;
|
|
|
|
nuidp->nu_nam = m_copym(
|
|
|
|
nfsd->nfsd_nd->nd_nam2, 0,
|
|
|
|
M_COPYALL, M_WAIT);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
1994-08-17 18:43:47 +04:00
|
|
|
TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp,
|
1996-02-18 14:53:36 +03:00
|
|
|
nu_lru);
|
1994-08-17 18:43:47 +04:00
|
|
|
LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid),
|
1996-02-18 14:53:36 +03:00
|
|
|
nuidp, nu_hash);
|
2006-05-18 16:44:45 +04:00
|
|
|
kauth_cred_hold(nuidp->nu_cr);
|
|
|
|
nfsd->nfsd_nd->nd_cr = nuidp->nu_cr;
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-10-20 07:28:10 +03:00
|
|
|
if ((SCARG(uap, flag) & NFSSVC_AUTHINFAIL) &&
|
|
|
|
(nfsd = nsd->nsd_nfsd))
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsd->nfsd_flag |= NFSD_AUTHFAIL;
|
2003-01-18 11:51:40 +03:00
|
|
|
error = nfssvc_nfsd(nsd, SCARG(uap, argp), l);
|
1994-06-08 15:33:09 +04:00
|
|
|
#endif /* !NFSSERVER */
|
|
|
|
}
|
|
|
|
if (error == EINTR || error == ERESTART)
|
|
|
|
error = 0;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NFSSERVER
|
2003-02-01 09:23:35 +03:00
|
|
|
MALLOC_DEFINE(M_NFSD, "NFS daemon", "Nfs server daemon structure");
|
|
|
|
MALLOC_DEFINE(M_NFSSVC, "NFS srvsock", "Nfs server structure");
|
|
|
|
|
2003-05-26 17:30:07 +04:00
|
|
|
static struct nfssvc_sock *
|
|
|
|
nfsrv_sockalloc()
|
|
|
|
{
|
|
|
|
struct nfssvc_sock *slp;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2003-05-26 17:30:07 +04:00
|
|
|
slp = (struct nfssvc_sock *)
|
|
|
|
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
|
|
|
|
memset(slp, 0, sizeof (struct nfssvc_sock));
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_init(&slp->ns_lock, MUTEX_DRIVER, IPL_SOFTNET);
|
|
|
|
cv_init(&slp->ns_cv, "nfsdsock");
|
2003-05-26 17:30:07 +04:00
|
|
|
TAILQ_INIT(&slp->ns_uidlruhead);
|
2006-01-03 15:30:01 +03:00
|
|
|
LIST_INIT(&slp->ns_tq);
|
|
|
|
SIMPLEQ_INIT(&slp->ns_sendq);
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
2003-05-26 17:30:07 +04:00
|
|
|
TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain);
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
2003-05-26 17:30:07 +04:00
|
|
|
|
|
|
|
return slp;
|
|
|
|
}
|
|
|
|
|
2004-06-10 16:59:57 +04:00
|
|
|
static void
|
|
|
|
nfsrv_sockfree(struct nfssvc_sock *slp)
|
|
|
|
{
|
|
|
|
|
|
|
|
KASSERT(slp->ns_so == NULL);
|
|
|
|
KASSERT(slp->ns_fp == NULL);
|
2006-01-03 14:41:03 +03:00
|
|
|
KASSERT((slp->ns_flag & SLP_VALID) == 0);
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_destroy(&slp->ns_lock);
|
|
|
|
cv_destroy(&slp->ns_cv);
|
2004-06-10 16:59:57 +04:00
|
|
|
free(slp, M_NFSSVC);
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Adds a socket to the list for servicing by nfsds.
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1994-06-08 15:33:09 +04:00
|
|
|
nfssvc_addsock(fp, mynam)
|
|
|
|
struct file *fp;
|
|
|
|
struct mbuf *mynam;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
int siz;
|
|
|
|
struct nfssvc_sock *slp;
|
|
|
|
struct socket *so;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct nfssvc_sock *tslp;
|
|
|
|
int error, s;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
so = (struct socket *)fp->f_data;
|
1994-06-08 15:33:09 +04:00
|
|
|
tslp = (struct nfssvc_sock *)0;
|
|
|
|
/*
|
|
|
|
* Add it to the list, as required.
|
|
|
|
*/
|
|
|
|
if (so->so_proto->pr_protocol == IPPROTO_UDP) {
|
2000-06-09 04:00:17 +04:00
|
|
|
#ifdef INET6
|
|
|
|
if (so->so_proto->pr_domain->dom_family == AF_INET6)
|
|
|
|
tslp = nfs_udp6sock;
|
|
|
|
else
|
|
|
|
#endif
|
1994-06-08 15:33:09 +04:00
|
|
|
tslp = nfs_udpsock;
|
|
|
|
if (tslp->ns_flag & SLP_VALID) {
|
|
|
|
m_freem(mynam);
|
|
|
|
return (EPERM);
|
|
|
|
}
|
|
|
|
#ifdef ISO
|
|
|
|
} else if (so->so_proto->pr_protocol == ISOPROTO_CLTP) {
|
|
|
|
tslp = nfs_cltpsock;
|
|
|
|
if (tslp->ns_flag & SLP_VALID) {
|
|
|
|
m_freem(mynam);
|
|
|
|
return (EPERM);
|
|
|
|
}
|
|
|
|
#endif /* ISO */
|
|
|
|
}
|
|
|
|
if (so->so_type == SOCK_STREAM)
|
1996-02-18 14:53:36 +03:00
|
|
|
siz = NFS_MAXPACKET + sizeof (u_long);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1994-06-08 15:33:09 +04:00
|
|
|
siz = NFS_MAXPACKET;
|
2005-02-27 01:31:44 +03:00
|
|
|
error = soreserve(so, siz, siz);
|
1996-02-18 14:53:36 +03:00
|
|
|
if (error) {
|
1994-06-08 15:33:09 +04:00
|
|
|
m_freem(mynam);
|
|
|
|
return (error);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set protocol specific options { for now TCP only } and
|
|
|
|
* reserve some space. For datagram sockets, this can get called
|
|
|
|
* repeatedly for the same socket, but that isn't harmful.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
if (so->so_type == SOCK_STREAM) {
|
2003-02-26 09:31:08 +03:00
|
|
|
m = m_get(M_WAIT, MT_SOOPTS);
|
|
|
|
MCLAIM(m, &nfs_mowner);
|
1996-02-18 14:53:36 +03:00
|
|
|
*mtod(m, int32_t *) = 1;
|
|
|
|
m->m_len = sizeof(int32_t);
|
1993-03-21 12:45:37 +03:00
|
|
|
sosetopt(so, SOL_SOCKET, SO_KEEPALIVE, m);
|
|
|
|
}
|
2000-06-09 04:00:17 +04:00
|
|
|
if ((so->so_proto->pr_domain->dom_family == AF_INET
|
|
|
|
#ifdef INET6
|
|
|
|
|| so->so_proto->pr_domain->dom_family == AF_INET6
|
|
|
|
#endif
|
|
|
|
) &&
|
1994-06-08 15:33:09 +04:00
|
|
|
so->so_proto->pr_protocol == IPPROTO_TCP) {
|
2003-02-26 09:31:08 +03:00
|
|
|
m = m_get(M_WAIT, MT_SOOPTS);
|
|
|
|
MCLAIM(m, &nfs_mowner);
|
1996-02-18 14:53:36 +03:00
|
|
|
*mtod(m, int32_t *) = 1;
|
|
|
|
m->m_len = sizeof(int32_t);
|
1993-03-21 12:45:37 +03:00
|
|
|
sosetopt(so, IPPROTO_TCP, TCP_NODELAY, m);
|
|
|
|
}
|
|
|
|
so->so_rcv.sb_flags &= ~SB_NOINTR;
|
|
|
|
so->so_rcv.sb_timeo = 0;
|
|
|
|
so->so_snd.sb_flags &= ~SB_NOINTR;
|
|
|
|
so->so_snd.sb_timeo = 0;
|
2007-06-01 15:56:03 +04:00
|
|
|
if (tslp) {
|
1994-06-08 15:33:09 +04:00
|
|
|
slp = tslp;
|
2007-06-01 15:56:03 +04:00
|
|
|
} else {
|
2003-05-26 17:30:07 +04:00
|
|
|
slp = nfsrv_sockalloc();
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
slp->ns_so = so;
|
|
|
|
slp->ns_nam = mynam;
|
|
|
|
fp->f_count++;
|
|
|
|
slp->ns_fp = fp;
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
2007-03-04 08:59:00 +03:00
|
|
|
so->so_upcallarg = (void *)slp;
|
1994-06-08 15:33:09 +04:00
|
|
|
so->so_upcall = nfsrv_rcv;
|
1998-04-25 21:41:01 +04:00
|
|
|
so->so_rcv.sb_flags |= SB_UPCALL;
|
2007-06-01 15:56:03 +04:00
|
|
|
slp->ns_flag = SLP_VALID | SLP_NEEDQ;
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsrv_wakenfsd(slp);
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Called by nfssvc() for nfsds. Just loops around servicing rpc requests
|
|
|
|
* until it is killed by a signal.
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2003-01-18 11:51:40 +03:00
|
|
|
nfssvc_nfsd(nsd, argp, l)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct nfsd_srvargs *nsd;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *argp;
|
2003-01-18 11:51:40 +03:00
|
|
|
struct lwp *l;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
2006-06-08 02:33:33 +04:00
|
|
|
struct timeval tv;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
struct nfssvc_sock *slp;
|
1996-02-18 14:53:36 +03:00
|
|
|
struct nfsd *nfsd = nsd->nsd_nfsd;
|
|
|
|
struct nfsrv_descript *nd = NULL;
|
|
|
|
struct mbuf *mreq;
|
|
|
|
u_quad_t cur_usec;
|
2007-06-01 15:56:03 +04:00
|
|
|
int error = 0, cacherep, siz, sotype, writes_todo;
|
2003-01-18 11:51:40 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2007-06-01 15:56:03 +04:00
|
|
|
int s;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#ifndef nolint
|
|
|
|
cacherep = RC_DOIT;
|
|
|
|
writes_todo = 0;
|
|
|
|
#endif
|
2007-07-10 00:51:58 +04:00
|
|
|
uvm_lwp_hold(l);
|
2007-06-01 15:56:03 +04:00
|
|
|
if (nfsd == NULL) {
|
|
|
|
nsd->nsd_nfsd = nfsd =
|
1994-06-08 15:33:09 +04:00
|
|
|
malloc(sizeof (struct nfsd), M_NFSD, M_WAITOK);
|
2007-06-01 15:56:03 +04:00
|
|
|
memset(nfsd, 0, sizeof (struct nfsd));
|
|
|
|
cv_init(&nfsd->nfsd_cv, "nfsd");
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsd->nfsd_procp = p;
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
1996-02-18 14:53:36 +03:00
|
|
|
TAILQ_INSERT_TAIL(&nfsd_head, nfsd, nfsd_chain);
|
1994-06-08 15:33:09 +04:00
|
|
|
nfs_numnfsd++;
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_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
|
|
|
* Loop getting rpc requests until SIGKILL.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
for (;;) {
|
2007-06-01 18:43:17 +04:00
|
|
|
if ((curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
|
|
|
|
!= 0) {
|
|
|
|
preempt();
|
|
|
|
}
|
2006-01-03 14:41:03 +03:00
|
|
|
if (nfsd->nfsd_slp == NULL) {
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
2006-01-03 14:41:03 +03:00
|
|
|
while (nfsd->nfsd_slp == NULL &&
|
1994-08-17 18:43:47 +04:00
|
|
|
(nfsd_head_flag & NFSD_CHECKSLP) == 0) {
|
2003-06-25 18:37:50 +04:00
|
|
|
SLIST_INSERT_HEAD(&nfsd_idle_head, nfsd,
|
|
|
|
nfsd_idle);
|
2007-06-01 15:56:03 +04:00
|
|
|
error = cv_wait_sig(&nfsd->nfsd_cv, &nfsd_lock);
|
2003-06-25 18:37:50 +04:00
|
|
|
if (error) {
|
|
|
|
slp = nfsd->nfsd_slp;
|
|
|
|
nfsd->nfsd_slp = NULL;
|
|
|
|
if (!slp)
|
|
|
|
SLIST_REMOVE(&nfsd_idle_head,
|
|
|
|
nfsd, nfsd, nfsd_idle);
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
2003-06-25 18:37:50 +04:00
|
|
|
if (slp) {
|
|
|
|
nfsrv_wakenfsd(slp);
|
|
|
|
nfsrv_slpderef(slp);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
goto done;
|
2003-06-25 18:37:50 +04:00
|
|
|
}
|
2007-06-01 18:10:02 +04:00
|
|
|
KASSERT(nfsd->nfsd_slp != NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2006-01-03 14:41:03 +03:00
|
|
|
if (nfsd->nfsd_slp == NULL &&
|
1994-08-17 18:43:47 +04:00
|
|
|
(nfsd_head_flag & NFSD_CHECKSLP) != 0) {
|
2003-06-25 18:37:50 +04:00
|
|
|
slp = TAILQ_FIRST(&nfssvc_sockpending);
|
|
|
|
if (slp) {
|
2007-08-02 16:44:18 +04:00
|
|
|
KASSERT((slp->ns_flag & SLP_DOREC)
|
|
|
|
!= 0);
|
2003-06-25 18:37:50 +04:00
|
|
|
TAILQ_REMOVE(&nfssvc_sockpending, slp,
|
|
|
|
ns_pending);
|
|
|
|
slp->ns_flag &= ~SLP_DOREC;
|
|
|
|
slp->ns_sref++;
|
|
|
|
nfsd->nfsd_slp = slp;
|
|
|
|
} else
|
1994-08-17 18:43:47 +04:00
|
|
|
nfsd_head_flag &= ~NFSD_CHECKSLP;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2007-06-22 18:39:59 +04:00
|
|
|
KASSERT(nfsd->nfsd_slp == NULL ||
|
|
|
|
nfsd->nfsd_slp->ns_sref > 0);
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
2006-01-03 14:41:03 +03:00
|
|
|
if ((slp = nfsd->nfsd_slp) == NULL)
|
1994-06-08 15:33:09 +04:00
|
|
|
continue;
|
2007-06-22 18:39:59 +04:00
|
|
|
KASSERT(slp->ns_sref > 0);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (slp->ns_flag & SLP_VALID) {
|
2007-08-02 16:40:36 +04:00
|
|
|
if ((slp->ns_flag & SLP_NEEDQ) != 0) {
|
2006-01-03 14:41:03 +03:00
|
|
|
nfsrv_rcv(slp->ns_so, (void *)slp,
|
|
|
|
M_WAIT);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2007-08-02 16:40:36 +04:00
|
|
|
if ((slp->ns_flag & SLP_DISCONN) != 0) {
|
|
|
|
nfsrv_zapsock(slp);
|
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
error = nfsrv_dorec(slp, nfsd, &nd);
|
2006-06-08 02:33:33 +04:00
|
|
|
getmicrotime(&tv);
|
|
|
|
cur_usec = (u_quad_t)tv.tv_sec * 1000000 +
|
|
|
|
(u_quad_t)tv.tv_usec;
|
2003-04-02 19:14:19 +04:00
|
|
|
if (error && LIST_FIRST(&slp->ns_tq) &&
|
|
|
|
LIST_FIRST(&slp->ns_tq)->nd_time <=
|
|
|
|
cur_usec) {
|
1996-02-18 14:53:36 +03:00
|
|
|
error = 0;
|
|
|
|
cacherep = RC_DOIT;
|
|
|
|
writes_todo = 1;
|
|
|
|
} else
|
|
|
|
writes_todo = 0;
|
2006-01-03 14:41:03 +03:00
|
|
|
if (error == 0 && slp->ns_rec != NULL) {
|
|
|
|
nfsrv_wakenfsd(slp);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error = 0;
|
1996-02-18 14:53:36 +03:00
|
|
|
slp = nfsd->nfsd_slp;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2007-06-22 18:39:59 +04:00
|
|
|
KASSERT(slp != NULL);
|
|
|
|
KASSERT(nfsd->nfsd_slp == slp);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (error || (slp->ns_flag & SLP_VALID) == 0) {
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nd) {
|
2006-05-18 16:44:45 +04:00
|
|
|
nfsdreq_free(nd);
|
1996-02-18 14:53:36 +03:00
|
|
|
nd = NULL;
|
|
|
|
}
|
2006-01-03 14:41:03 +03:00
|
|
|
nfsd->nfsd_slp = NULL;
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsrv_slpderef(slp);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
2006-01-03 15:30:01 +03:00
|
|
|
sotype = slp->ns_so->so_type;
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nd) {
|
2006-06-08 02:33:33 +04:00
|
|
|
getmicrotime(&nd->nd_starttime);
|
2003-05-22 18:14:41 +04:00
|
|
|
if (nd->nd_nam2)
|
|
|
|
nd->nd_nam = nd->nd_nam2;
|
|
|
|
else
|
|
|
|
nd->nd_nam = slp->ns_nam;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2003-05-22 18:14:41 +04:00
|
|
|
/*
|
|
|
|
* Check to see if authorization is needed.
|
|
|
|
*/
|
|
|
|
if (nfsd->nfsd_flag & NFSD_NEEDAUTH) {
|
|
|
|
nfsd->nfsd_flag &= ~NFSD_NEEDAUTH;
|
|
|
|
nsd->nsd_haddr = mtod(nd->nd_nam,
|
|
|
|
struct sockaddr_in *)->sin_addr.s_addr;
|
|
|
|
nsd->nsd_authlen = nfsd->nfsd_authlen;
|
|
|
|
nsd->nsd_verflen = nfsd->nfsd_verflen;
|
|
|
|
if (!copyout(nfsd->nfsd_authstr,
|
|
|
|
nsd->nsd_authstr, nfsd->nfsd_authlen) &&
|
|
|
|
!copyout(nfsd->nfsd_verfstr,
|
|
|
|
nsd->nsd_verfstr, nfsd->nfsd_verflen) &&
|
|
|
|
!copyout(nsd, argp, sizeof (*nsd))) {
|
2007-07-10 00:51:58 +04:00
|
|
|
uvm_lwp_rele(l);
|
2003-05-22 18:14:41 +04:00
|
|
|
return (ENEEDAUTH);
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
cacherep = RC_DROPIT;
|
2003-05-22 18:14:41 +04:00
|
|
|
} else
|
|
|
|
cacherep = nfsrv_getcache(nd, slp, &mreq);
|
|
|
|
|
2006-12-27 15:10:09 +03:00
|
|
|
if (nfsd->nfsd_flag & NFSD_AUTHFAIL) {
|
2003-05-22 18:14:41 +04:00
|
|
|
nfsd->nfsd_flag &= ~NFSD_AUTHFAIL;
|
1994-06-08 15:33:09 +04:00
|
|
|
nd->nd_procnum = NFSPROC_NOOP;
|
2003-05-22 18:14:41 +04:00
|
|
|
nd->nd_repstat =
|
|
|
|
(NFSERR_AUTHERR | AUTH_TOOWEAK);
|
1994-06-08 15:33:09 +04:00
|
|
|
cacherep = RC_DOIT;
|
2003-05-22 18:14:41 +04:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
/*
|
|
|
|
* Loop to get all the write rpc relies that have been
|
|
|
|
* gathered together.
|
|
|
|
*/
|
|
|
|
do {
|
1999-05-04 20:08:02 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2003-05-22 18:14:41 +04:00
|
|
|
int lockcount;
|
1999-05-04 20:08:02 +04:00
|
|
|
#endif
|
2003-05-22 18:14:41 +04:00
|
|
|
switch (cacherep) {
|
|
|
|
case RC_DOIT:
|
1999-05-04 20:08:02 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/*
|
2003-05-22 18:14:41 +04:00
|
|
|
* NFS server procs should neither release
|
|
|
|
* locks already held, nor leave things
|
|
|
|
* locked. Catch this sooner, rather than
|
|
|
|
* later (when we try to relock something we
|
|
|
|
* already have locked). Careful inspection
|
|
|
|
* of the failing routine usually turns up the
|
|
|
|
* lock leak.. once we know what it is..
|
1999-05-04 20:08:02 +04:00
|
|
|
*/
|
2003-05-22 18:14:41 +04:00
|
|
|
lockcount = l->l_locks;
|
|
|
|
#endif
|
2005-08-03 10:25:11 +04:00
|
|
|
mreq = NULL;
|
2006-01-05 14:22:56 +03:00
|
|
|
netexport_rdlock();
|
2006-04-15 05:35:12 +04:00
|
|
|
if (writes_todo || nd == NULL ||
|
|
|
|
(!(nd->nd_flag & ND_NFSV3) &&
|
2003-05-22 18:14:41 +04:00
|
|
|
nd->nd_procnum == NFSPROC_WRITE &&
|
2006-12-27 15:10:09 +03:00
|
|
|
nfsrvw_procrastinate > 0))
|
2003-05-22 18:14:41 +04:00
|
|
|
error = nfsrv_writegather(&nd, slp,
|
2005-12-11 15:16:03 +03:00
|
|
|
l, &mreq);
|
2003-05-22 18:14:41 +04:00
|
|
|
else
|
|
|
|
error =
|
|
|
|
(*(nfsrv3_procs[nd->nd_procnum]))
|
2005-12-11 15:16:03 +03:00
|
|
|
(nd, slp, l, &mreq);
|
2006-01-05 14:22:56 +03:00
|
|
|
netexport_rdunlock();
|
2003-05-22 18:14:41 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (l->l_locks != lockcount) {
|
|
|
|
/*
|
|
|
|
* If you see this panic, audit
|
|
|
|
* nfsrv3_procs[nd->nd_procnum] for
|
|
|
|
* vnode locking errors (usually, it's
|
|
|
|
* due to forgetting to vput()
|
|
|
|
* something).
|
|
|
|
*/
|
2000-10-24 11:08:48 +04:00
|
|
|
#ifdef DEBUG
|
2003-05-22 18:14:41 +04:00
|
|
|
extern void printlockedvnodes(void);
|
|
|
|
printlockedvnodes();
|
2000-10-24 11:08:48 +04:00
|
|
|
#endif
|
2003-05-22 18:14:41 +04:00
|
|
|
printf("nfsd: locking botch in op %d"
|
|
|
|
" (before %d, after %d)\n",
|
|
|
|
nd ? nd->nd_procnum : -1,
|
|
|
|
lockcount, l->l_locks);
|
|
|
|
}
|
1999-05-04 20:08:02 +04:00
|
|
|
#endif
|
2005-08-03 10:25:11 +04:00
|
|
|
if (mreq == NULL) {
|
|
|
|
if (nd != NULL) {
|
|
|
|
if (nd->nd_nam2)
|
|
|
|
m_free(nd->nd_nam2);
|
|
|
|
if (nd->nd_mrep)
|
|
|
|
m_freem(nd->nd_mrep);
|
|
|
|
}
|
2003-05-22 18:14:41 +04:00
|
|
|
break;
|
2005-08-03 10:25:11 +04:00
|
|
|
}
|
2003-05-22 18:14:41 +04:00
|
|
|
if (error) {
|
2006-12-27 15:10:09 +03:00
|
|
|
nfsstats.srv_errs++;
|
2007-02-22 09:05:00 +03:00
|
|
|
nfsrv_updatecache(nd, false, mreq);
|
2003-05-22 18:14:41 +04:00
|
|
|
if (nd->nd_nam2)
|
|
|
|
m_freem(nd->nd_nam2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nfsstats.srvrpccnt[nd->nd_procnum]++;
|
2007-02-22 09:05:00 +03:00
|
|
|
nfsrv_updatecache(nd, true, mreq);
|
2003-05-22 18:14:41 +04:00
|
|
|
nd->nd_mrep = (struct mbuf *)0;
|
|
|
|
case RC_REPLY:
|
|
|
|
m = mreq;
|
|
|
|
siz = 0;
|
|
|
|
while (m) {
|
|
|
|
siz += m->m_len;
|
|
|
|
m = m->m_next;
|
|
|
|
}
|
|
|
|
if (siz <= 0 || siz > NFS_MAXPACKET) {
|
|
|
|
printf("mbuf siz=%d\n",siz);
|
|
|
|
panic("Bad nfs svc reply");
|
|
|
|
}
|
|
|
|
m = mreq;
|
|
|
|
m->m_pkthdr.len = siz;
|
|
|
|
m->m_pkthdr.rcvif = (struct ifnet *)0;
|
|
|
|
/*
|
|
|
|
* For stream protocols, prepend a Sun RPC
|
|
|
|
* Record Mark.
|
|
|
|
*/
|
|
|
|
if (sotype == SOCK_STREAM) {
|
|
|
|
M_PREPEND(m, NFSX_UNSIGNED, M_WAIT);
|
|
|
|
*mtod(m, u_int32_t *) =
|
|
|
|
htonl(0x80000000 | siz);
|
|
|
|
}
|
2006-01-03 15:30:01 +03:00
|
|
|
nd->nd_mreq = m;
|
|
|
|
if (nfsrtton) {
|
|
|
|
nfsd_rt(slp->ns_so->so_type, nd,
|
|
|
|
cacherep);
|
2003-05-22 18:14:41 +04:00
|
|
|
}
|
2006-01-03 15:30:01 +03:00
|
|
|
error = nfsdsock_sendreply(slp, nd);
|
|
|
|
nd = NULL;
|
2003-05-22 18:14:41 +04:00
|
|
|
if (error == EPIPE)
|
|
|
|
nfsrv_zapsock(slp);
|
|
|
|
if (error == EINTR || error == ERESTART) {
|
2007-06-12 13:30:49 +04:00
|
|
|
nfsd->nfsd_slp = NULL;
|
2003-05-22 18:14:41 +04:00
|
|
|
nfsrv_slpderef(slp);
|
|
|
|
goto done;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
2003-05-22 18:14:41 +04:00
|
|
|
case RC_DROPIT:
|
|
|
|
if (nfsrtton)
|
|
|
|
nfsd_rt(sotype, nd, cacherep);
|
1994-06-08 15:33:09 +04:00
|
|
|
m_freem(nd->nd_mrep);
|
2003-05-22 18:14:41 +04:00
|
|
|
m_freem(nd->nd_nam2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nd) {
|
2006-05-18 16:44:45 +04:00
|
|
|
nfsdreq_free(nd);
|
2003-05-22 18:14:41 +04:00
|
|
|
nd = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
|
2003-05-22 18:14:41 +04:00
|
|
|
/*
|
|
|
|
* Check to see if there are outstanding writes that
|
|
|
|
* need to be serviced.
|
|
|
|
*/
|
2006-06-08 02:33:33 +04:00
|
|
|
getmicrotime(&tv);
|
|
|
|
cur_usec = (u_quad_t)tv.tv_sec * 1000000 +
|
|
|
|
(u_quad_t)tv.tv_usec;
|
2003-05-22 18:14:41 +04:00
|
|
|
s = splsoftclock();
|
|
|
|
if (LIST_FIRST(&slp->ns_tq) &&
|
|
|
|
LIST_FIRST(&slp->ns_tq)->nd_time <= cur_usec) {
|
|
|
|
cacherep = RC_DOIT;
|
|
|
|
writes_todo = 1;
|
|
|
|
} else
|
|
|
|
writes_todo = 0;
|
|
|
|
splx(s);
|
1996-02-18 14:53:36 +03:00
|
|
|
} while (writes_todo);
|
|
|
|
if (nfsrv_dorec(slp, nfsd, &nd)) {
|
|
|
|
nfsd->nfsd_slp = NULL;
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsrv_slpderef(slp);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
done:
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
1996-02-18 14:53:36 +03:00
|
|
|
TAILQ_REMOVE(&nfsd_head, nfsd, nfsd_chain);
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
|
|
|
cv_destroy(&nfsd->nfsd_cv);
|
|
|
|
free(nfsd, M_NFSD);
|
|
|
|
nsd->nsd_nfsd = NULL;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (--nfs_numnfsd == 0)
|
2007-02-22 09:05:00 +03:00
|
|
|
nfsrv_init(true); /* Reinitialize everything */
|
2007-07-10 00:51:58 +04:00
|
|
|
uvm_lwp_rele(l);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Shut down a socket associated with an nfssvc_sock structure.
|
|
|
|
* Should be called with the send lock set, if required.
|
|
|
|
* The trick here is to increment the sref at the start, so that the nfsds
|
|
|
|
* will stop using it and clear ns_flag at the end so that it will not be
|
|
|
|
* reassigned during cleanup.
|
2004-03-17 13:42:37 +03:00
|
|
|
*
|
|
|
|
* called at splsoftnet.
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
void
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsrv_zapsock(slp)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfssvc_sock *slp;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsuid *nuidp, *nnuidp;
|
|
|
|
struct nfsrv_descript *nwp, *nnwp;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct socket *so;
|
2007-01-17 15:40:36 +03:00
|
|
|
struct mbuf *m;
|
1996-02-18 14:53:36 +03:00
|
|
|
int s;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2006-01-03 14:41:03 +03:00
|
|
|
if (nfsdsock_drain(slp)) {
|
2004-03-17 13:43:35 +03:00
|
|
|
return;
|
|
|
|
}
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
2004-03-17 13:42:37 +03:00
|
|
|
if (slp->ns_flag & SLP_DOREC) {
|
|
|
|
TAILQ_REMOVE(&nfssvc_sockpending, slp, ns_pending);
|
2007-08-02 16:42:17 +04:00
|
|
|
slp->ns_flag &= ~SLP_DOREC;
|
2004-03-17 13:42:37 +03:00
|
|
|
}
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
2004-06-10 16:59:57 +04:00
|
|
|
|
|
|
|
so = slp->ns_so;
|
|
|
|
KASSERT(so != NULL);
|
|
|
|
so->so_upcall = NULL;
|
|
|
|
so->so_upcallarg = NULL;
|
|
|
|
so->so_rcv.sb_flags &= ~SB_UPCALL;
|
|
|
|
soshutdown(so, SHUT_RDWR);
|
|
|
|
|
|
|
|
if (slp->ns_nam)
|
|
|
|
m_free(slp->ns_nam);
|
|
|
|
m_freem(slp->ns_raw);
|
2007-01-17 15:40:36 +03:00
|
|
|
m = slp->ns_rec;
|
|
|
|
while (m != NULL) {
|
|
|
|
struct mbuf *n;
|
|
|
|
|
|
|
|
n = m->m_nextpkt;
|
|
|
|
m_freem(m);
|
|
|
|
m = n;
|
|
|
|
}
|
2004-06-10 16:59:57 +04:00
|
|
|
for (nuidp = TAILQ_FIRST(&slp->ns_uidlruhead); nuidp != 0;
|
|
|
|
nuidp = nnuidp) {
|
|
|
|
nnuidp = TAILQ_NEXT(nuidp, nu_lru);
|
|
|
|
LIST_REMOVE(nuidp, nu_hash);
|
|
|
|
TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru);
|
|
|
|
if (nuidp->nu_flag & NU_NAM)
|
|
|
|
m_freem(nuidp->nu_nam);
|
2007-03-04 08:59:00 +03:00
|
|
|
free((void *)nuidp, M_NFSUID);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2004-06-10 16:59:57 +04:00
|
|
|
s = splsoftclock();
|
|
|
|
for (nwp = LIST_FIRST(&slp->ns_tq); nwp; nwp = nnwp) {
|
|
|
|
nnwp = LIST_NEXT(nwp, nd_tq);
|
|
|
|
LIST_REMOVE(nwp, nd_tq);
|
2006-05-18 16:44:45 +04:00
|
|
|
nfsdreq_free(nwp);
|
2004-06-10 16:59:57 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Derefence a server socket structure. If it has no more references and
|
|
|
|
* is no longer valid, you can throw it away.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfsrv_slpderef(slp)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfssvc_sock *slp;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
2007-06-22 18:39:59 +04:00
|
|
|
uint32_t ref;
|
2003-06-25 18:37:50 +04:00
|
|
|
|
2007-06-22 18:39:59 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
|
|
|
KASSERT(slp->ns_sref > 0);
|
|
|
|
ref = --slp->ns_sref;
|
|
|
|
mutex_exit(&nfsd_lock);
|
|
|
|
if (ref == 0 && (slp->ns_flag & SLP_VALID) == 0) {
|
2006-01-03 14:41:03 +03:00
|
|
|
struct file *fp;
|
2007-06-01 15:56:03 +04:00
|
|
|
|
|
|
|
mutex_enter(&nfsd_lock);
|
2007-08-02 16:46:03 +04:00
|
|
|
KASSERT((slp->ns_flag & SLP_DOREC) == 0);
|
1994-08-17 18:43:47 +04:00
|
|
|
TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
2006-01-03 14:41:03 +03:00
|
|
|
|
|
|
|
fp = slp->ns_fp;
|
|
|
|
if (fp != NULL) {
|
|
|
|
slp->ns_fp = NULL;
|
|
|
|
KASSERT(fp != NULL);
|
|
|
|
KASSERT(fp->f_data == slp->ns_so);
|
|
|
|
simple_lock(&fp->f_slock);
|
|
|
|
FILE_USE(fp);
|
|
|
|
closef(fp, (struct lwp *)0);
|
|
|
|
slp->ns_so = NULL;
|
|
|
|
}
|
|
|
|
|
2004-06-10 16:59:57 +04:00
|
|
|
nfsrv_sockfree(slp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the data structures for the server.
|
|
|
|
* Handshake with any new nfsds starting up to avoid any chance of
|
|
|
|
* corruption.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfsrv_init(terminating)
|
|
|
|
int terminating;
|
|
|
|
{
|
2003-06-25 18:37:50 +04:00
|
|
|
struct nfssvc_sock *slp;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2007-06-01 15:56:03 +04:00
|
|
|
if (!terminating) {
|
|
|
|
mutex_init(&nfsd_lock, MUTEX_DRIVER, IPL_SOFTNET);
|
|
|
|
cv_init(&nfsd_initcv, "nfsdinit");
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_enter(&nfsd_lock);
|
1994-08-17 18:43:47 +04:00
|
|
|
if (nfssvc_sockhead_flag & SLP_INIT)
|
1994-06-08 15:33:09 +04:00
|
|
|
panic("nfsd init");
|
1994-08-17 18:43:47 +04:00
|
|
|
nfssvc_sockhead_flag |= SLP_INIT;
|
2003-06-25 18:37:50 +04:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
if (terminating) {
|
2007-06-12 13:30:49 +04:00
|
|
|
KASSERT(SLIST_EMPTY(&nfsd_idle_head));
|
|
|
|
KASSERT(TAILQ_EMPTY(&nfsd_head));
|
2003-06-25 18:37:50 +04:00
|
|
|
while ((slp = TAILQ_FIRST(&nfssvc_sockhead)) != NULL) {
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
2006-01-03 14:41:03 +03:00
|
|
|
KASSERT(slp->ns_sref == 0);
|
|
|
|
slp->ns_sref++;
|
|
|
|
nfsrv_zapsock(slp);
|
|
|
|
nfsrv_slpderef(slp);
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2007-06-12 13:30:49 +04:00
|
|
|
KASSERT(TAILQ_EMPTY(&nfssvc_sockpending));
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsrv_cleancache(); /* And clear out server cache */
|
2003-06-25 18:37:50 +04:00
|
|
|
} else {
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_exit(&nfsd_lock);
|
1997-06-25 03:38:10 +04:00
|
|
|
nfs_pub.np_valid = 0;
|
2003-06-25 18:37:50 +04:00
|
|
|
}
|
1994-08-17 18:43:47 +04:00
|
|
|
|
|
|
|
TAILQ_INIT(&nfssvc_sockhead);
|
2003-06-25 18:37:50 +04:00
|
|
|
TAILQ_INIT(&nfssvc_sockpending);
|
1994-08-17 18:43:47 +04:00
|
|
|
|
|
|
|
TAILQ_INIT(&nfsd_head);
|
2003-06-25 18:37:50 +04:00
|
|
|
SLIST_INIT(&nfsd_idle_head);
|
1994-08-17 18:43:47 +04:00
|
|
|
nfsd_head_flag &= ~NFSD_CHECKSLP;
|
|
|
|
|
2003-05-26 17:30:07 +04:00
|
|
|
nfs_udpsock = nfsrv_sockalloc();
|
1994-08-17 18:43:47 +04:00
|
|
|
|
2000-06-09 04:00:17 +04:00
|
|
|
#ifdef INET6
|
2003-05-26 17:30:07 +04:00
|
|
|
nfs_udp6sock = nfsrv_sockalloc();
|
2000-06-09 04:00:17 +04:00
|
|
|
#endif
|
|
|
|
|
2000-11-25 02:30:02 +03:00
|
|
|
#ifdef ISO
|
2003-05-26 17:30:07 +04:00
|
|
|
nfs_cltpsock = nfsrv_sockalloc();
|
2000-11-25 02:30:02 +03:00
|
|
|
#endif
|
2003-06-25 18:37:50 +04:00
|
|
|
|
2007-06-01 15:56:03 +04:00
|
|
|
mutex_enter(&nfsd_lock);
|
|
|
|
nfssvc_sockhead_flag &= ~SLP_INIT;
|
|
|
|
cv_broadcast(&nfsd_initcv);
|
|
|
|
mutex_exit(&nfsd_lock);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add entries to the server monitor log.
|
|
|
|
*/
|
|
|
|
static void
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsd_rt(sotype, nd, cacherep)
|
1994-06-08 15:33:09 +04:00
|
|
|
int sotype;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsrv_descript *nd;
|
1994-06-08 15:33:09 +04:00
|
|
|
int cacherep;
|
|
|
|
{
|
2006-06-08 02:33:33 +04:00
|
|
|
struct timeval tv;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct drt *rt;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
rt = &nfsdrt.drt[nfsdrt.pos];
|
|
|
|
if (cacherep == RC_DOIT)
|
|
|
|
rt->flag = 0;
|
|
|
|
else if (cacherep == RC_REPLY)
|
|
|
|
rt->flag = DRT_CACHEREPLY;
|
|
|
|
else
|
|
|
|
rt->flag = DRT_CACHEDROP;
|
|
|
|
if (sotype == SOCK_STREAM)
|
|
|
|
rt->flag |= DRT_TCP;
|
2006-12-28 03:39:03 +03:00
|
|
|
if (nd->nd_flag & ND_NFSV3)
|
1996-02-18 14:53:36 +03:00
|
|
|
rt->flag |= DRT_NFSV3;
|
1994-06-08 15:33:09 +04:00
|
|
|
rt->proc = nd->nd_procnum;
|
1996-02-18 14:53:36 +03:00
|
|
|
if (mtod(nd->nd_nam, struct sockaddr *)->sa_family == AF_INET)
|
|
|
|
rt->ipadr = mtod(nd->nd_nam, struct sockaddr_in *)->sin_addr.s_addr;
|
1994-06-08 15:33:09 +04:00
|
|
|
else
|
1996-02-18 14:53:36 +03:00
|
|
|
rt->ipadr = INADDR_ANY;
|
2006-06-08 02:33:33 +04:00
|
|
|
getmicrotime(&tv);
|
|
|
|
rt->resptime = ((tv.tv_sec - nd->nd_starttime.tv_sec) * 1000000) +
|
|
|
|
(tv.tv_usec - nd->nd_starttime.tv_usec);
|
|
|
|
rt->tstamp = tv;
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ;
|
|
|
|
}
|
1993-04-11 00:19:19 +04:00
|
|
|
#endif /* NFSSERVER */
|
|
|
|
|
1997-01-31 05:58:48 +03:00
|
|
|
#ifdef NFS
|
1996-12-03 01:55:39 +03:00
|
|
|
|
|
|
|
int nfs_defect = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2000-04-16 01:14:48 +04:00
|
|
|
* Asynchronous I/O threads for client nfs.
|
1994-06-08 15:33:09 +04:00
|
|
|
* They do read-ahead and write-behind operations on the block I/O cache.
|
|
|
|
* Never returns unless it fails or gets killed.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2000-04-16 01:14:48 +04:00
|
|
|
|
2007-07-20 19:36:41 +04:00
|
|
|
static void
|
|
|
|
nfssvc_iod(void *arg)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2007-07-20 19:36:41 +04:00
|
|
|
struct lwp *l = curlwp;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct buf *bp;
|
2003-04-09 18:22:33 +04:00
|
|
|
int i;
|
|
|
|
struct nfs_iod *myiod;
|
1996-12-03 01:55:39 +03:00
|
|
|
struct nfsmount *nmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Assign my position or return error if too many already running
|
|
|
|
*/
|
2003-04-09 18:22:33 +04:00
|
|
|
myiod = NULL;
|
2007-08-08 16:27:56 +04:00
|
|
|
mutex_enter(&nfs_iodlist_lock);
|
|
|
|
for (i = 0; i < NFS_MAXASYNCDAEMON; i++) {
|
2007-07-20 19:36:41 +04:00
|
|
|
if (nfs_asyncdaemon[i].nid_lwp == NULL) {
|
2003-04-09 18:22:33 +04:00
|
|
|
myiod = &nfs_asyncdaemon[i];
|
2007-08-08 16:27:56 +04:00
|
|
|
myiod->nid_lwp = l;
|
|
|
|
nfs_numasync++;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
2007-08-08 16:27:56 +04:00
|
|
|
}
|
|
|
|
mutex_exit(&nfs_iodlist_lock);
|
2007-07-20 19:36:41 +04:00
|
|
|
if (myiod == NULL) {
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
myiod->nid_exiting = false;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
for (;;) {
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_enter(&myiod->nid_lock);
|
2007-02-22 09:05:00 +03:00
|
|
|
while (/*CONSTCOND*/ true) {
|
2003-05-07 20:18:53 +04:00
|
|
|
nmp = myiod->nid_mount;
|
|
|
|
if (nmp) {
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_enter(&nmp->nm_lock);
|
2003-05-07 20:18:53 +04:00
|
|
|
if (!TAILQ_EMPTY(&nmp->nm_bufq)) {
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_exit(&myiod->nid_lock);
|
2003-05-07 20:18:53 +04:00
|
|
|
break;
|
|
|
|
}
|
2003-05-07 20:18:17 +04:00
|
|
|
nmp->nm_bufqiods--;
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_exit(&nmp->nm_lock);
|
2003-05-07 20:18:53 +04:00
|
|
|
}
|
2007-07-20 19:36:41 +04:00
|
|
|
myiod->nid_want = true;
|
2003-05-07 20:18:17 +04:00
|
|
|
myiod->nid_mount = NULL;
|
2007-07-20 19:36:41 +04:00
|
|
|
if (myiod->nid_exiting) {
|
2003-05-07 20:18:53 +04:00
|
|
|
goto quit;
|
2007-04-30 14:30:51 +04:00
|
|
|
}
|
2007-07-20 19:36:41 +04:00
|
|
|
cv_wait(&myiod->nid_cv, &myiod->nid_lock);
|
1996-12-03 01:55:39 +03:00
|
|
|
}
|
2003-05-07 20:18:53 +04:00
|
|
|
|
|
|
|
while ((bp = TAILQ_FIRST(&nmp->nm_bufq)) != NULL) {
|
2003-05-07 20:18:17 +04:00
|
|
|
/* Take one off the front of the list */
|
|
|
|
TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist);
|
|
|
|
nmp->nm_bufqlen--;
|
2007-08-08 16:27:56 +04:00
|
|
|
if (nmp->nm_bufqlen < 2 * nmp->nm_bufqiods) {
|
2007-04-29 14:30:18 +04:00
|
|
|
cv_broadcast(&nmp->nm_aiocv);
|
2003-05-07 20:18:17 +04:00
|
|
|
}
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_exit(&nmp->nm_lock);
|
2007-08-08 16:27:56 +04:00
|
|
|
KERNEL_LOCK(1, l);
|
2005-07-07 06:05:03 +04:00
|
|
|
(void)nfs_doio(bp);
|
2007-08-08 16:27:56 +04:00
|
|
|
KERNEL_UNLOCK_ONE(l);
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_enter(&nmp->nm_lock);
|
2003-05-07 20:18:17 +04:00
|
|
|
/*
|
2005-09-12 00:19:31 +04:00
|
|
|
* If there are more than one iod on this mount,
|
|
|
|
* then defect so that the iods can be shared out
|
|
|
|
* fairly between the mounts
|
2003-05-07 20:18:17 +04:00
|
|
|
*/
|
|
|
|
if (nfs_defect && nmp->nm_bufqiods > 1) {
|
|
|
|
myiod->nid_mount = NULL;
|
|
|
|
nmp->nm_bufqiods--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-29 14:30:18 +04:00
|
|
|
mutex_exit(&nmp->nm_lock);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-05-07 20:18:53 +04:00
|
|
|
quit:
|
2007-07-20 19:36:41 +04:00
|
|
|
if (myiod != NULL) {
|
|
|
|
KASSERT(mutex_owned(&myiod->nid_lock));
|
|
|
|
KASSERT(myiod->nid_mount == NULL);
|
|
|
|
myiod->nid_want = false;
|
|
|
|
myiod->nid_mount = NULL;
|
|
|
|
mutex_exit(&myiod->nid_lock);
|
2007-08-08 16:27:56 +04:00
|
|
|
mutex_enter(&nfs_iodlist_lock);
|
|
|
|
myiod->nid_lwp = NULL;
|
2007-07-20 19:36:41 +04:00
|
|
|
nfs_numasync--;
|
2007-08-08 16:27:56 +04:00
|
|
|
mutex_exit(&nfs_iodlist_lock);
|
2007-06-19 17:13:37 +04:00
|
|
|
}
|
2000-04-16 01:14:48 +04:00
|
|
|
|
2007-07-20 19:36:41 +04:00
|
|
|
kthread_exit(0);
|
2003-05-07 20:18:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs_iodinit()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2007-08-08 16:27:56 +04:00
|
|
|
mutex_init(&nfs_iodlist_lock, MUTEX_DEFAULT, IPL_NONE);
|
2007-04-29 14:30:18 +04:00
|
|
|
for (i = 0; i < NFS_MAXASYNCDAEMON; i++) {
|
|
|
|
struct nfs_iod *nid = &nfs_asyncdaemon[i];
|
|
|
|
mutex_init(&nid->nid_lock, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
cv_init(&nid->nid_cv, "nfsiod");
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-04-11 00:19:19 +04:00
|
|
|
|
2000-04-16 01:14:48 +04:00
|
|
|
void
|
|
|
|
nfs_getset_niothreads(set)
|
|
|
|
int set;
|
|
|
|
{
|
|
|
|
int i, have, start;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2007-08-08 16:27:56 +04:00
|
|
|
mutex_enter(&nfs_iodlist_lock);
|
2000-04-16 01:14:48 +04:00
|
|
|
for (have = 0, i = 0; i < NFS_MAXASYNCDAEMON; i++)
|
2007-07-20 19:36:41 +04:00
|
|
|
if (nfs_asyncdaemon[i].nid_lwp != NULL)
|
2000-04-16 01:14:48 +04:00
|
|
|
have++;
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
/* clamp to sane range */
|
|
|
|
nfs_niothreads = max(0, min(nfs_niothreads, NFS_MAXASYNCDAEMON));
|
|
|
|
|
|
|
|
start = nfs_niothreads - have;
|
|
|
|
|
|
|
|
while (start > 0) {
|
2007-08-08 16:27:56 +04:00
|
|
|
kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
|
|
|
|
nfssvc_iod, NULL, NULL, "nfsio");
|
2000-04-16 01:14:48 +04:00
|
|
|
start--;
|
|
|
|
}
|
|
|
|
|
2007-07-20 19:36:41 +04:00
|
|
|
for (i = 0; (start < 0) && (i < NFS_MAXASYNCDAEMON); i++) {
|
|
|
|
struct nfs_iod *nid = &nfs_asyncdaemon[i];
|
|
|
|
|
|
|
|
if (nid->nid_lwp != NULL) {
|
|
|
|
mutex_enter(&nid->nid_lock);
|
|
|
|
nid->nid_exiting = true;
|
|
|
|
cv_signal(&nid->nid_cv);
|
|
|
|
mutex_exit(&nid->nid_lock);
|
2000-04-16 01:14:48 +04:00
|
|
|
start++;
|
|
|
|
}
|
2007-07-20 19:36:41 +04:00
|
|
|
}
|
2000-04-16 01:14:48 +04:00
|
|
|
} else {
|
2000-05-07 05:38:36 +04:00
|
|
|
if (nfs_niothreads >= 0)
|
|
|
|
nfs_niothreads = have;
|
2000-04-16 01:14:48 +04:00
|
|
|
}
|
2007-08-08 16:27:56 +04:00
|
|
|
mutex_exit(&nfs_iodlist_lock);
|
2000-04-16 01:14:48 +04:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Get an authorization string for the uid by having the mount_nfs sitting
|
|
|
|
* on this mount point porpous out of the kernel and do it.
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1996-02-18 14:53:36 +03:00
|
|
|
nfs_getauth(nmp, rep, cred, auth_str, auth_len, verf_str, verf_len, key)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsmount *nmp;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct nfsreq *rep;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t cred;
|
1994-06-08 15:33:09 +04:00
|
|
|
char **auth_str;
|
|
|
|
int *auth_len;
|
1996-02-18 14:53:36 +03:00
|
|
|
char *verf_str;
|
|
|
|
int *verf_len;
|
|
|
|
NFSKERBKEY_T key; /* return session key */
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
1997-10-10 05:53:17 +04:00
|
|
|
while ((nmp->nm_iflag & NFSMNT_WAITAUTH) == 0) {
|
|
|
|
nmp->nm_iflag |= NFSMNT_WANTAUTH;
|
2007-03-04 08:59:00 +03:00
|
|
|
(void) tsleep((void *)&nmp->nm_authtype, PSOCK,
|
1994-06-08 15:33:09 +04:00
|
|
|
"nfsauth1", 2 * hz);
|
2005-12-11 15:16:03 +03:00
|
|
|
error = nfs_sigintr(nmp, rep, rep->r_lwp);
|
1996-02-10 00:48:19 +03:00
|
|
|
if (error) {
|
1997-10-10 05:53:17 +04:00
|
|
|
nmp->nm_iflag &= ~NFSMNT_WANTAUTH;
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
1997-10-10 05:53:17 +04:00
|
|
|
nmp->nm_iflag &= ~(NFSMNT_WAITAUTH | NFSMNT_WANTAUTH);
|
1994-06-08 15:33:09 +04:00
|
|
|
nmp->nm_authstr = *auth_str = (char *)malloc(RPCAUTH_MAXSIZ, M_TEMP, M_WAITOK);
|
1996-02-18 14:53:36 +03:00
|
|
|
nmp->nm_authlen = RPCAUTH_MAXSIZ;
|
|
|
|
nmp->nm_verfstr = verf_str;
|
|
|
|
nmp->nm_verflen = *verf_len;
|
2006-05-15 01:31:52 +04:00
|
|
|
nmp->nm_authuid = kauth_cred_geteuid(cred);
|
2007-03-04 08:59:00 +03:00
|
|
|
wakeup((void *)&nmp->nm_authstr);
|
1993-04-11 00:19:19 +04:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* And wait for mount_nfs to do its stuff.
|
|
|
|
*/
|
1997-10-10 05:53:17 +04:00
|
|
|
while ((nmp->nm_iflag & NFSMNT_HASAUTH) == 0 && error == 0) {
|
2007-03-04 08:59:00 +03:00
|
|
|
(void) tsleep((void *)&nmp->nm_authlen, PSOCK,
|
1994-06-08 15:33:09 +04:00
|
|
|
"nfsauth2", 2 * hz);
|
2005-12-11 15:16:03 +03:00
|
|
|
error = nfs_sigintr(nmp, rep, rep->r_lwp);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1997-10-10 05:53:17 +04:00
|
|
|
if (nmp->nm_iflag & NFSMNT_AUTHERR) {
|
|
|
|
nmp->nm_iflag &= ~NFSMNT_AUTHERR;
|
1994-06-08 15:33:09 +04:00
|
|
|
error = EAUTH;
|
|
|
|
}
|
|
|
|
if (error)
|
2007-03-04 08:59:00 +03:00
|
|
|
free((void *)*auth_str, M_TEMP);
|
1994-06-08 15:33:09 +04:00
|
|
|
else {
|
|
|
|
*auth_len = nmp->nm_authlen;
|
1996-02-18 14:53:36 +03:00
|
|
|
*verf_len = nmp->nm_verflen;
|
2002-09-15 01:45:16 +04:00
|
|
|
memcpy(key, nmp->nm_key, sizeof (NFSKERBKEY_T));
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1997-10-10 05:53:17 +04:00
|
|
|
nmp->nm_iflag &= ~NFSMNT_HASAUTH;
|
|
|
|
nmp->nm_iflag |= NFSMNT_WAITAUTH;
|
|
|
|
if (nmp->nm_iflag & NFSMNT_WANTAUTH) {
|
|
|
|
nmp->nm_iflag &= ~NFSMNT_WANTAUTH;
|
2007-03-04 08:59:00 +03:00
|
|
|
wakeup((void *)&nmp->nm_authtype);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a nickname authenticator and verifier.
|
|
|
|
*/
|
|
|
|
int
|
2006-11-09 12:53:57 +03:00
|
|
|
nfs_getnickauth(struct nfsmount *nmp, kauth_cred_t cred, char **auth_str,
|
|
|
|
int *auth_len, char *verf_str, int verf_len)
|
1996-02-18 14:53:36 +03:00
|
|
|
{
|
2006-06-08 02:33:33 +04:00
|
|
|
struct timeval ktvin, ktvout, tv;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsuid *nuidp;
|
|
|
|
u_int32_t *nickp, *verfp;
|
1996-02-18 14:53:36 +03:00
|
|
|
|
2006-05-11 01:53:14 +04:00
|
|
|
memset(&ktvout, 0, sizeof ktvout); /* XXX gcc */
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (verf_len < (4 * NFSX_UNSIGNED))
|
|
|
|
panic("nfs_getnickauth verf too small");
|
|
|
|
#endif
|
2006-05-15 01:31:52 +04:00
|
|
|
LIST_FOREACH(nuidp, NMUIDHASH(nmp, kauth_cred_geteuid(cred)), nu_hash) {
|
|
|
|
if (kauth_cred_geteuid(nuidp->nu_cr) == kauth_cred_geteuid(cred))
|
1996-02-18 14:53:36 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-06-08 02:33:33 +04:00
|
|
|
if (!nuidp || nuidp->nu_expire < time_second)
|
1996-02-18 14:53:36 +03:00
|
|
|
return (EACCES);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move to the end of the lru list (end of lru == most recently used).
|
|
|
|
*/
|
|
|
|
TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, nu_lru);
|
|
|
|
TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp, nu_lru);
|
|
|
|
|
|
|
|
nickp = (u_int32_t *)malloc(2 * NFSX_UNSIGNED, M_TEMP, M_WAITOK);
|
|
|
|
*nickp++ = txdr_unsigned(RPCAKN_NICKNAME);
|
|
|
|
*nickp = txdr_unsigned(nuidp->nu_nickname);
|
|
|
|
*auth_str = (char *)nickp;
|
|
|
|
*auth_len = 2 * NFSX_UNSIGNED;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we must encrypt the verifier and package it up.
|
|
|
|
*/
|
|
|
|
verfp = (u_int32_t *)verf_str;
|
|
|
|
*verfp++ = txdr_unsigned(RPCAKN_NICKNAME);
|
2006-06-08 02:33:33 +04:00
|
|
|
getmicrotime(&tv);
|
|
|
|
if (tv.tv_sec > nuidp->nu_timestamp.tv_sec ||
|
|
|
|
(tv.tv_sec == nuidp->nu_timestamp.tv_sec &&
|
|
|
|
tv.tv_usec > nuidp->nu_timestamp.tv_usec))
|
|
|
|
nuidp->nu_timestamp = tv;
|
1996-02-18 14:53:36 +03:00
|
|
|
else
|
|
|
|
nuidp->nu_timestamp.tv_usec++;
|
|
|
|
ktvin.tv_sec = txdr_unsigned(nuidp->nu_timestamp.tv_sec);
|
|
|
|
ktvin.tv_usec = txdr_unsigned(nuidp->nu_timestamp.tv_usec);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now encrypt the timestamp verifier in ecb mode using the session
|
|
|
|
* key.
|
|
|
|
*/
|
|
|
|
#ifdef NFSKERB
|
|
|
|
XXX
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*verfp++ = ktvout.tv_sec;
|
|
|
|
*verfp++ = ktvout.tv_usec;
|
|
|
|
*verfp = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the current nickname in a hash list entry on the mount point.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfs_savenickauth(nmp, cred, len, key, mdp, dposp, mrep)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsmount *nmp;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t cred;
|
1996-02-18 14:53:36 +03:00
|
|
|
int len;
|
|
|
|
NFSKERBKEY_T key;
|
|
|
|
struct mbuf **mdp;
|
|
|
|
char **dposp;
|
|
|
|
struct mbuf *mrep;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsuid *nuidp;
|
|
|
|
u_int32_t *tl;
|
|
|
|
int32_t t1;
|
1996-02-18 14:53:36 +03:00
|
|
|
struct mbuf *md = *mdp;
|
|
|
|
struct timeval ktvin, ktvout;
|
|
|
|
u_int32_t nick;
|
|
|
|
char *dpos = *dposp, *cp2;
|
|
|
|
int deltasec, error = 0;
|
|
|
|
|
2006-05-11 01:53:14 +04:00
|
|
|
memset(&ktvout, 0, sizeof ktvout); /* XXX gcc */
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
if (len == (3 * NFSX_UNSIGNED)) {
|
|
|
|
nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
|
|
|
|
ktvin.tv_sec = *tl++;
|
|
|
|
ktvin.tv_usec = *tl++;
|
|
|
|
nick = fxdr_unsigned(u_int32_t, *tl);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decrypt the timestamp in ecb mode.
|
|
|
|
*/
|
|
|
|
#ifdef NFSKERB
|
|
|
|
XXX
|
|
|
|
#endif
|
|
|
|
ktvout.tv_sec = fxdr_unsigned(long, ktvout.tv_sec);
|
|
|
|
ktvout.tv_usec = fxdr_unsigned(long, ktvout.tv_usec);
|
2006-06-08 02:33:33 +04:00
|
|
|
deltasec = time_second - ktvout.tv_sec;
|
1996-02-18 14:53:36 +03:00
|
|
|
if (deltasec < 0)
|
|
|
|
deltasec = -deltasec;
|
|
|
|
/*
|
|
|
|
* If ok, add it to the hash list for the mount point.
|
|
|
|
*/
|
|
|
|
if (deltasec <= NFS_KERBCLOCKSKEW) {
|
|
|
|
if (nmp->nm_numuids < nuidhash_max) {
|
|
|
|
nmp->nm_numuids++;
|
|
|
|
nuidp = (struct nfsuid *)
|
|
|
|
malloc(sizeof (struct nfsuid), M_NFSUID,
|
|
|
|
M_WAITOK);
|
|
|
|
} else {
|
2003-04-02 19:14:19 +04:00
|
|
|
nuidp = TAILQ_FIRST(&nmp->nm_uidlruhead);
|
1996-02-18 14:53:36 +03:00
|
|
|
LIST_REMOVE(nuidp, nu_hash);
|
|
|
|
TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp,
|
|
|
|
nu_lru);
|
|
|
|
}
|
|
|
|
nuidp->nu_flag = 0;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_seteuid(nuidp->nu_cr, kauth_cred_geteuid(cred));
|
2006-06-08 02:33:33 +04:00
|
|
|
nuidp->nu_expire = time_second + NFS_KERBTTL;
|
1996-02-18 14:53:36 +03:00
|
|
|
nuidp->nu_timestamp = ktvout;
|
|
|
|
nuidp->nu_nickname = nick;
|
2002-09-15 01:45:16 +04:00
|
|
|
memcpy(nuidp->nu_key, key, sizeof (NFSKERBKEY_T));
|
1996-02-18 14:53:36 +03:00
|
|
|
TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp,
|
|
|
|
nu_lru);
|
2006-05-15 01:31:52 +04:00
|
|
|
LIST_INSERT_HEAD(NMUIDHASH(nmp, kauth_cred_geteuid(cred)),
|
1996-02-18 14:53:36 +03:00
|
|
|
nuidp, nu_hash);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
nfsm_adv(nfsm_rndup(len));
|
|
|
|
nfsmout:
|
|
|
|
*mdp = md;
|
|
|
|
*dposp = dpos;
|
|
|
|
return (error);
|
|
|
|
}
|
1997-01-31 05:58:48 +03:00
|
|
|
#endif /* NFS */
|