From 88eff7ea9273a2554ac69757f1967109cfd82e03 Mon Sep 17 00:00:00 2001 From: fvdl Date: Sun, 7 Jul 1996 12:23:49 +0000 Subject: [PATCH] Start XIDs at a value based on the current time, not 0. This avoids nasty XID confusions with servers that cache them over a long period and with clients that reboot quickly. Problems: because of the sanity check that is done by comparing the system time with filesystem time, XIDs will start at 0 until root is mounted, which means it isn't completely safe for diskless setups. But it's clearly better than it was. It would also be cleaner if all XID handling (more generally, all RPC handling) within the kernel went through the same functions. --- sys/nfs/nfs_subs.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sys/nfs/nfs_subs.c b/sys/nfs/nfs_subs.c index b66aeccc8fd4..ea7bd004cb10 100644 --- a/sys/nfs/nfs_subs.c +++ b/sys/nfs/nfs_subs.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_subs.c,v 1.29 1996/07/01 10:22:47 fvdl Exp $ */ +/* $NetBSD: nfs_subs.c,v 1.30 1996/07/07 12:23:49 fvdl Exp $ */ /* * Copyright (c) 1989, 1993 @@ -55,6 +55,7 @@ #include #include #include +#include #include @@ -609,6 +610,8 @@ nfsm_rpchead(cr, nmflag, procid, auth_type, auth_len, auth_str, verf_len, register int i; struct mbuf *mreq, *mb2; int siz, grpsiz, authsiz; + struct timeval tv; + static u_int32_t base; authsiz = nfsm_rndup(auth_len); MGETHDR(mb, M_WAIT, MT_DATA); @@ -627,8 +630,22 @@ nfsm_rpchead(cr, nmflag, procid, auth_type, auth_len, auth_str, verf_len, * First the RPC header. */ nfsm_build(tl, u_int32_t *, 8 * NFSX_UNSIGNED); + + /* + * derive initial xid from system time + * XXX time is invalid if root not yet mounted + */ + if (!base && (rootvp)) { + microtime(&tv); + base = tv.tv_sec << 12; + nfs_xid = base; + } + /* + * Skip zero xid if it should ever happen. + */ if (++nfs_xid == 0) nfs_xid++; + *tl++ = *xidp = txdr_unsigned(nfs_xid); *tl++ = rpc_call; *tl++ = rpc_vers;