diff options
author | dfr <dfr@FreeBSD.org> | 1996-07-18 14:53:04 +0000 |
---|---|---|
committer | dfr <dfr@FreeBSD.org> | 1996-07-18 14:53:04 +0000 |
commit | c79e9e34b5daad1ba280439b95ec4d08843ea517 (patch) | |
tree | 74e8895f3eaedc8d1beee1254ea66f9d1759e561 /usr.sbin | |
parent | df5a608d7089211a0e5057437ab5f5982b25d3eb (diff) | |
download | FreeBSD-src-c79e9e34b5daad1ba280439b95ec4d08843ea517.zip FreeBSD-src-c79e9e34b5daad1ba280439b95ec4d08843ea517.tar.gz |
Import fixes from NetBSD to print NFSv3 packets.
Obtained from: NetBSD
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/tcpdump/tcpdump/nfs.h | 446 | ||||
-rw-r--r-- | usr.sbin/tcpdump/tcpdump/nfsfh.h | 4 | ||||
-rw-r--r-- | usr.sbin/tcpdump/tcpdump/nfsv2.h | 260 | ||||
-rw-r--r-- | usr.sbin/tcpdump/tcpdump/os.h | 9 | ||||
-rw-r--r-- | usr.sbin/tcpdump/tcpdump/parsenfsfh.c | 5 | ||||
-rw-r--r-- | usr.sbin/tcpdump/tcpdump/print-nfs.c | 1121 | ||||
-rw-r--r-- | usr.sbin/tcpdump/tcpdump/print-udp.c | 4 |
7 files changed, 1360 insertions, 489 deletions
diff --git a/usr.sbin/tcpdump/tcpdump/nfs.h b/usr.sbin/tcpdump/tcpdump/nfs.h new file mode 100644 index 0000000..e6931c2 --- /dev/null +++ b/usr.sbin/tcpdump/tcpdump/nfs.h @@ -0,0 +1,446 @@ +/* $NetBSD: nfs.h,v 1.1 1996/05/23 22:49:53 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * 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. + * + * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95 + */ + +/* + * nfs definitions as per the Version 2 and 3 specs + */ + +/* + * Constants as defined in the Sun NFS Version 2 and 3 specs. + * "NFS: Network File System Protocol Specification" RFC1094 + * and in the "NFS: Network File System Version 3 Protocol + * Specification" + */ + +#define NFS_PORT 2049 +#define NFS_PROG 100003 +#define NFS_VER2 2 +#define NFS_VER3 3 +#define NFS_V2MAXDATA 8192 +#define NFS_MAXDGRAMDATA 16384 +#define NFS_MAXDATA 32768 +#define NFS_MAXPATHLEN 1024 +#define NFS_MAXNAMLEN 255 +#define NFS_MAXPKTHDR 404 +#define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA) +#define NFS_MINPACKET 20 +#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ + +/* Stat numbers for rpc returns (version 2 and 3) */ +#define NFS_OK 0 +#define NFSERR_PERM 1 +#define NFSERR_NOENT 2 +#define NFSERR_IO 5 +#define NFSERR_NXIO 6 +#define NFSERR_ACCES 13 +#define NFSERR_EXIST 17 +#define NFSERR_XDEV 18 /* Version 3 only */ +#define NFSERR_NODEV 19 +#define NFSERR_NOTDIR 20 +#define NFSERR_ISDIR 21 +#define NFSERR_INVAL 22 /* Version 3 only */ +#define NFSERR_FBIG 27 +#define NFSERR_NOSPC 28 +#define NFSERR_ROFS 30 +#define NFSERR_MLINK 31 /* Version 3 only */ +#define NFSERR_NAMETOL 63 +#define NFSERR_NOTEMPTY 66 +#define NFSERR_DQUOT 69 +#define NFSERR_STALE 70 +#define NFSERR_REMOTE 71 /* Version 3 only */ +#define NFSERR_WFLUSH 99 /* Version 2 only */ +#define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */ +#define NFSERR_NOT_SYNC 10002 +#define NFSERR_BAD_COOKIE 10003 +#define NFSERR_NOTSUPP 10004 +#define NFSERR_TOOSMALL 10005 +#define NFSERR_SERVERFAULT 10006 +#define NFSERR_BADTYPE 10007 +#define NFSERR_JUKEBOX 10008 +#define NFSERR_TRYLATER NFSERR_JUKEBOX +#define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */ + +#define NFSERR_RETVOID 0x20000000 /* Return void, not error */ +#define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */ +#define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */ + +/* Sizes in bytes of various nfs rpc components */ +#define NFSX_UNSIGNED 4 + +/* specific to NFS Version 2 */ +#define NFSX_V2FH 32 +#define NFSX_V2FATTR 68 +#define NFSX_V2SATTR 32 +#define NFSX_V2COOKIE 4 +#define NFSX_V2STATFS 20 + +/* specific to NFS Version 3 */ +#if 0 +#define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */ +#endif +#define NFSX_V3FHMAX 64 /* max. allowed by protocol */ +#define NFSX_V3FATTR 84 +#define NFSX_V3SATTR 60 /* max. all fields filled in */ +#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr)) +#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED) +#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED) +#define NFSX_V3COOKIEVERF 8 +#define NFSX_V3WRITEVERF 8 +#define NFSX_V3CREATEVERF 8 +#define NFSX_V3STATFS 52 +#define NFSX_V3FSINFO 48 +#define NFSX_V3PATHCONF 24 + +/* variants for both versions */ +#define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \ + NFSX_V2FH) +#define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH) +#define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR) +#define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \ + NFSX_V2FATTR) +#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0) +#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR) +#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR) +#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0) +#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0) +#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \ + (2 * NFSX_UNSIGNED)) +#define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS) + +/* nfs rpc procedure numbers (before version mapping) */ +#define NFSPROC_NULL 0 +#define NFSPROC_GETATTR 1 +#define NFSPROC_SETATTR 2 +#define NFSPROC_LOOKUP 3 +#define NFSPROC_ACCESS 4 +#define NFSPROC_READLINK 5 +#define NFSPROC_READ 6 +#define NFSPROC_WRITE 7 +#define NFSPROC_CREATE 8 +#define NFSPROC_MKDIR 9 +#define NFSPROC_SYMLINK 10 +#define NFSPROC_MKNOD 11 +#define NFSPROC_REMOVE 12 +#define NFSPROC_RMDIR 13 +#define NFSPROC_RENAME 14 +#define NFSPROC_LINK 15 +#define NFSPROC_READDIR 16 +#define NFSPROC_READDIRPLUS 17 +#define NFSPROC_FSSTAT 18 +#define NFSPROC_FSINFO 19 +#define NFSPROC_PATHCONF 20 +#define NFSPROC_COMMIT 21 + +/* And leasing (nqnfs) procedure numbers (must be last) */ +#define NQNFSPROC_GETLEASE 22 +#define NQNFSPROC_VACATED 23 +#define NQNFSPROC_EVICTED 24 + +#define NFSPROC_NOOP 25 +#define NFS_NPROCS 26 + +/* Actual Version 2 procedure numbers */ +#define NFSV2PROC_NULL 0 +#define NFSV2PROC_GETATTR 1 +#define NFSV2PROC_SETATTR 2 +#define NFSV2PROC_NOOP 3 +#define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_LOOKUP 4 +#define NFSV2PROC_READLINK 5 +#define NFSV2PROC_READ 6 +#define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_WRITE 8 +#define NFSV2PROC_CREATE 9 +#define NFSV2PROC_REMOVE 10 +#define NFSV2PROC_RENAME 11 +#define NFSV2PROC_LINK 12 +#define NFSV2PROC_SYMLINK 13 +#define NFSV2PROC_MKDIR 14 +#define NFSV2PROC_RMDIR 15 +#define NFSV2PROC_READDIR 16 +#define NFSV2PROC_STATFS 17 + +/* + * Constants used by the Version 3 protocol for various RPCs + */ +#define NFSV3SATTRTIME_DONTCHANGE 0 +#define NFSV3SATTRTIME_TOSERVER 1 +#define NFSV3SATTRTIME_TOCLIENT 2 + +#define NFSV3ATTRTIME_NMODES 3 + +#define NFSV3ACCESS_READ 0x01 +#define NFSV3ACCESS_LOOKUP 0x02 +#define NFSV3ACCESS_MODIFY 0x04 +#define NFSV3ACCESS_EXTEND 0x08 +#define NFSV3ACCESS_DELETE 0x10 +#define NFSV3ACCESS_EXECUTE 0x20 + +#define NFSV3WRITE_UNSTABLE 0 +#define NFSV3WRITE_DATASYNC 1 +#define NFSV3WRITE_FILESYNC 2 + +#define NFSV3WRITE_NMODES 3 + +#define NFSV3CREATE_UNCHECKED 0 +#define NFSV3CREATE_GUARDED 1 +#define NFSV3CREATE_EXCLUSIVE 2 + +#define NFSV3CREATE_NMODES 3 + +#define NFSV3FSINFO_LINK 0x01 +#define NFSV3FSINFO_SYMLINK 0x02 +#define NFSV3FSINFO_HOMOGENEOUS 0x08 +#define NFSV3FSINFO_CANSETTIME 0x10 + +/* Conversion macros */ +#define vtonfsv2_mode(t,m) \ + txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ + MAKEIMODE((t), (m))) +#define vtonfsv3_mode(m) txdr_unsigned((m) & 07777) +#define nfstov_mode(a) (fxdr_unsigned(u_int16_t, (a))&07777) +#define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))]) +#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))]) +#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32,(a))&0x7] +#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32,(a))&0x7] + +/* File types */ +typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5, + NFSOCK=6, NFFIFO=7 } nfstype; + +/* Structs for common parts of the rpc's */ +/* + * File Handle (32 bytes for version 2), variable up to 64 for version 3. + * File Handles of up to NFS_SMALLFH in size are stored directly in the + * nfs node, whereas larger ones are malloc'd. (This never happens when + * NFS_SMALLFH is set to 64.) + * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4. + */ +#ifndef NFS_SMALLFH +#define NFS_SMALLFH 64 +#endif +union nfsfh { +/* fhandle_t fh_generic; */ + u_char fh_bytes[NFS_SMALLFH]; +}; +typedef union nfsfh nfsfh_t; + +struct nfsv2_time { + u_int32 nfsv2_sec; + u_int32 nfsv2_usec; +}; +typedef struct nfsv2_time nfstime2; + +struct nfsv3_time { + u_int32 nfsv3_sec; + u_int32 nfsv3_nsec; +}; +typedef struct nfsv3_time nfstime3; + +/* + * Quads are defined as arrays of 2 longs to ensure dense packing for the + * protocol and to facilitate xdr conversion. + */ +struct nfs_uquad { + u_int32 nfsuquad[2]; +}; +typedef struct nfs_uquad nfsuint64; + +/* + * Used to convert between two u_longs and a u_quad_t. + */ +union nfs_quadconvert { + u_int32 lval[2]; + u_quad_t qval; +}; +typedef union nfs_quadconvert nfsquad_t; + +/* + * NFS Version 3 special file number. + */ +struct nfsv3_spec { + u_int32 specdata1; + u_int32 specdata2; +}; +typedef struct nfsv3_spec nfsv3spec; + +/* + * File attributes and setable attributes. These structures cover both + * NFS version 2 and the version 3 protocol. Note that the union is only + * used so that one pointer can refer to both variants. These structures + * go out on the wire and must be densely packed, so no quad data types + * are used. (all fields are longs or u_longs or structures of same) + * NB: You can't do sizeof(struct nfs_fattr), you must use the + * NFSX_FATTR(v3) macro. + */ +struct nfs_fattr { + u_int32 fa_type; + u_int32 fa_mode; + u_int32 fa_nlink; + u_int32 fa_uid; + u_int32 fa_gid; + union { + struct { + u_int32 nfsv2fa_size; + u_int32 nfsv2fa_blocksize; + u_int32 nfsv2fa_rdev; + u_int32 nfsv2fa_blocks; + u_int32 nfsv2fa_fsid; + u_int32 nfsv2fa_fileid; + nfstime2 nfsv2fa_atime; + nfstime2 nfsv2fa_mtime; + nfstime2 nfsv2fa_ctime; + } fa_nfsv2; + struct { + nfsuint64 nfsv3fa_size; + nfsuint64 nfsv3fa_used; + nfsv3spec nfsv3fa_rdev; + nfsuint64 nfsv3fa_fsid; + nfsuint64 nfsv3fa_fileid; + nfstime3 nfsv3fa_atime; + nfstime3 nfsv3fa_mtime; + nfstime3 nfsv3fa_ctime; + } fa_nfsv3; + } fa_un; +}; + +/* and some ugly defines for accessing union components */ +#define fa2_size fa_un.fa_nfsv2.nfsv2fa_size +#define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize +#define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev +#define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks +#define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid +#define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid +#define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime +#define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime +#define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime +#define fa3_size fa_un.fa_nfsv3.nfsv3fa_size +#define fa3_used fa_un.fa_nfsv3.nfsv3fa_used +#define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev +#define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid +#define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid +#define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime +#define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime +#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime + +struct nfsv2_sattr { + u_int32 sa_mode; + u_int32 sa_uid; + u_int32 sa_gid; + u_int32 sa_size; + nfstime2 sa_atime; + nfstime2 sa_mtime; +}; + +/* + * NFS Version 3 sattr structure for the new node creation case. + */ +struct nfsv3_sattr { + u_int32 sa_modeset; + u_int32 sa_mode; + u_int32 sa_uidset; + u_int32 sa_uid; + u_int32 sa_gidset; + u_int32 sa_gid; + u_int32 sa_sizeset; + u_int32 sa_size; + u_int32 sa_atimetype; + nfstime3 sa_atime; + u_int32 sa_mtimetype; + nfstime3 sa_mtime; +}; + +struct nfs_statfs { + union { + struct { + u_int32 nfsv2sf_tsize; + u_int32 nfsv2sf_bsize; + u_int32 nfsv2sf_blocks; + u_int32 nfsv2sf_bfree; + u_int32 nfsv2sf_bavail; + } sf_nfsv2; + struct { + nfsuint64 nfsv3sf_tbytes; + nfsuint64 nfsv3sf_fbytes; + nfsuint64 nfsv3sf_abytes; + nfsuint64 nfsv3sf_tfiles; + nfsuint64 nfsv3sf_ffiles; + nfsuint64 nfsv3sf_afiles; + u_int32 nfsv3sf_invarsec; + } sf_nfsv3; + } sf_un; +}; + +#define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize +#define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize +#define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks +#define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree +#define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail +#define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes +#define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes +#define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes +#define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles +#define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles +#define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles +#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec + +struct nfsv3_fsinfo { + u_int32 fs_rtmax; + u_int32 fs_rtpref; + u_int32 fs_rtmult; + u_int32 fs_wtmax; + u_int32 fs_wtpref; + u_int32 fs_wtmult; + u_int32 fs_dtpref; + nfsuint64 fs_maxfilesize; + nfstime3 fs_timedelta; + u_int32 fs_properties; +}; + +struct nfsv3_pathconf { + u_int32 pc_linkmax; + u_int32 pc_namemax; + u_int32 pc_notrunc; + u_int32 pc_chownrestricted; + u_int32 pc_caseinsensitive; + u_int32 pc_casepreserving; +}; diff --git a/usr.sbin/tcpdump/tcpdump/nfsfh.h b/usr.sbin/tcpdump/tcpdump/nfsfh.h index 36296c3..545d76e 100644 --- a/usr.sbin/tcpdump/tcpdump/nfsfh.h +++ b/usr.sbin/tcpdump/tcpdump/nfsfh.h @@ -1,5 +1,5 @@ /* - * $Header: nfsfh.h,v 1.3 94/06/12 14:32:58 leres Exp $ + * $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/nfsfh.h,v 1.1 1995/03/08 12:52:19 olah Exp $ * * nfsfh.h - NFS file handle definitions (for portable use) * @@ -31,4 +31,4 @@ typedef struct { #define fsid_eq(a,b) ((a.fsid_code == b.fsid_code) &&\ dev_eq(a.fsid_dev, b.fsid_dev)) -extern void Parse_fh(caddr_t *, my_fsid *, ino_t *, char **, char **, int); +extern void Parse_fh(caddr_t *, int, my_fsid *, ino_t *, char **, char **, int); diff --git a/usr.sbin/tcpdump/tcpdump/nfsv2.h b/usr.sbin/tcpdump/tcpdump/nfsv2.h deleted file mode 100644 index ff55d31..0000000 --- a/usr.sbin/tcpdump/tcpdump/nfsv2.h +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) 1994 - * The Regents of the University of California. All rights reserved. - * - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * 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. - * - * @(#)nfsv2.h 7.11 (Berkeley) 9/30/92 - */ - -/* - * nfs definitions as per the version 2 specs - */ - -/* - * Constants as defined in the Sun NFS Version 2 spec. - * "NFS: Network File System Protocol Specification" RFC1094 - */ - -#define NFS_PORT 2049 -#define NFS_PROG 100003 -#define NFS_VER2 2 -#define NFS_MAXDGRAMDATA 8192 -#define NFS_MAXDATA 32768 -#define NFS_MAXPATHLEN 1024 -#define NFS_MAXNAMLEN 255 -#define NFS_FHSIZE 32 -#define NFS_MAXPKTHDR 404 -#define NFS_MAXPACKET (NFS_MAXPKTHDR+NFS_MAXDATA) -#define NFS_MINPACKET 20 -#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ - -/* Stat numbers for rpc returns */ -#define NFS_OK 0 -#define NFSERR_PERM 1 -#define NFSERR_NOENT 2 -#define NFSERR_IO 5 -#define NFSERR_NXIO 6 -#define NFSERR_ACCES 13 -#define NFSERR_EXIST 17 -#define NFSERR_NODEV 19 -#define NFSERR_NOTDIR 20 -#define NFSERR_ISDIR 21 -#define NFSERR_FBIG 27 -#define NFSERR_NOSPC 28 -#define NFSERR_ROFS 30 -#define NFSERR_NAMETOL 63 -#define NFSERR_NOTEMPTY 66 -#define NFSERR_DQUOT 69 -#define NFSERR_STALE 70 -#define NFSERR_WFLUSH 99 - -/* Sizes in bytes of various nfs rpc components */ -#define NFSX_FH 32 -#define NFSX_UNSIGNED 4 -#define NFSX_NFSFATTR 68 -#define NFSX_NQFATTR 92 -#define NFSX_NFSSATTR 32 -#define NFSX_NQSATTR 44 -#define NFSX_COOKIE 4 -#define NFSX_NFSSTATFS 20 -#define NFSX_NQSTATFS 28 -#define NFSX_FATTR(isnq) ((isnq) ? NFSX_NQFATTR : NFSX_NFSFATTR) -#define NFSX_SATTR(isnq) ((isnq) ? NFSX_NQSATTR : NFSX_NFSSATTR) -#define NFSX_STATFS(isnq) ((isnq) ? NFSX_NQSTATFS : NFSX_NFSSTATFS) - -/* nfs rpc procedure numbers */ -#define NFSPROC_NULL 0 -#define NFSPROC_GETATTR 1 -#define NFSPROC_SETATTR 2 -#define NFSPROC_NOOP 3 -#define NFSPROC_ROOT NFSPROC_NOOP /* Obsolete */ -#define NFSPROC_LOOKUP 4 -#define NFSPROC_READLINK 5 -#define NFSPROC_READ 6 -#define NFSPROC_WRITECACHE NFSPROC_NOOP /* Obsolete */ -#define NFSPROC_WRITE 8 -#define NFSPROC_CREATE 9 -#define NFSPROC_REMOVE 10 -#define NFSPROC_RENAME 11 -#define NFSPROC_LINK 12 -#define NFSPROC_SYMLINK 13 -#define NFSPROC_MKDIR 14 -#define NFSPROC_RMDIR 15 -#define NFSPROC_READDIR 16 -#define NFSPROC_STATFS 17 - -/* NQ nfs numbers */ -#define NQNFSPROC_READDIRLOOK 18 -#define NQNFSPROC_GETLEASE 19 -#define NQNFSPROC_VACATED 20 -#define NQNFSPROC_EVICTED 21 -#define NQNFSPROC_ACCESS 22 - -#define NFS_NPROCS 23 -/* Conversion macros */ -extern int vttoif_tab[]; -#define vtonfs_mode(t,m) \ - txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ - MAKEIMODE((t), (m))) -#define nfstov_mode(a) (fxdr_unsigned(u_short, (a))&07777) -#define vtonfs_type(a) txdr_unsigned(nfs_type[((long)(a))]) -#define nfstov_type(a) ntov_type[fxdr_unsigned(u_long,(a))&0x7] - -/* File types */ -typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5 } nfstype; - -/* Structs for common parts of the rpc's */ -struct nfsv2_time { - u_long nfs_sec; - u_long nfs_usec; -}; - -struct nqnfs_time { - u_long nq_sec; - u_long nq_nsec; -}; - -/* - * File attributes and setable attributes. These structures cover both - * NFS version 2 and the NQNFS protocol. Note that the union is only - * used to that one pointer can refer to both variants. These structures - * go out on the wire and must be densely packed, so no quad data types - * are used. (all fields are longs or u_longs or structures of same) - * NB: You can't do sizeof(struct nfsv2_fattr), you must use the - * NFSX_FATTR(isnq) macro. - */ -struct nfsv2_fattr { - u_long fa_type; - u_long fa_mode; - u_long fa_nlink; - u_long fa_uid; - u_long fa_gid; - union { - struct { - u_long nfsfa_size; - u_long nfsfa_blocksize; - u_long nfsfa_rdev; - u_long nfsfa_blocks; - u_long nfsfa_fsid; - u_long nfsfa_fileid; - struct nfsv2_time nfsfa_atime; - struct nfsv2_time nfsfa_mtime; - struct nfsv2_time nfsfa_ctime; - } fa_nfsv2; - struct { - struct { - u_long nqfa_qsize[2]; - } nqfa_size; - u_long nqfa_blocksize; - u_long nqfa_rdev; - struct { - u_long nqfa_qbytes[2]; - } nqfa_bytes; - u_long nqfa_fsid; - u_long nqfa_fileid; - struct nqnfs_time nqfa_atime; - struct nqnfs_time nqfa_mtime; - struct nqnfs_time nqfa_ctime; - u_long nqfa_flags; - u_long nqfa_gen; - struct { - u_long nqfa_qfilerev[2]; - } nqfa_filerev; - } fa_nqnfs; - } fa_un; -}; - -/* and some ugly defines for accessing union components */ -#define fa_nfssize fa_un.fa_nfsv2.nfsfa_size -#define fa_nfsblocksize fa_un.fa_nfsv2.nfsfa_blocksize -#define fa_nfsrdev fa_un.fa_nfsv2.nfsfa_rdev -#define fa_nfsblocks fa_un.fa_nfsv2.nfsfa_blocks -#define fa_nfsfsid fa_un.fa_nfsv2.nfsfa_fsid -#define fa_nfsfileid fa_un.fa_nfsv2.nfsfa_fileid -#define fa_nfsatime fa_un.fa_nfsv2.nfsfa_atime -#define fa_nfsmtime fa_un.fa_nfsv2.nfsfa_mtime -#define fa_nfsctime fa_un.fa_nfsv2.nfsfa_ctime -#define fa_nqsize fa_un.fa_nqnfs.nqfa_size -#define fa_nqblocksize fa_un.fa_nqnfs.nqfa_blocksize -#define fa_nqrdev fa_un.fa_nqnfs.nqfa_rdev -#define fa_nqbytes fa_un.fa_nqnfs.nqfa_bytes -#define fa_nqfsid fa_un.fa_nqnfs.nqfa_fsid -#define fa_nqfileid fa_un.fa_nqnfs.nqfa_fileid -#define fa_nqatime fa_un.fa_nqnfs.nqfa_atime -#define fa_nqmtime fa_un.fa_nqnfs.nqfa_mtime -#define fa_nqctime fa_un.fa_nqnfs.nqfa_ctime -#define fa_nqflags fa_un.fa_nqnfs.nqfa_flags -#define fa_nqgen fa_un.fa_nqnfs.nqfa_gen -#define fa_nqfilerev fa_un.fa_nqnfs.nqfa_filerev - -struct nfsv2_sattr { - u_long sa_mode; - u_long sa_uid; - u_long sa_gid; - union { - struct { - u_long nfssa_size; - struct nfsv2_time nfssa_atime; - struct nfsv2_time nfssa_mtime; - } sa_nfsv2; - struct { - struct { - u_long nqsa_qsize[2]; - } nqsa_size; - struct nqnfs_time nqsa_atime; - struct nqnfs_time nqsa_mtime; - u_long nqsa_flags; - u_long nqsa_rdev; - } sa_nqnfs; - } sa_un; -}; - -/* and some ugly defines for accessing the unions */ -#define sa_nfssize sa_un.sa_nfsv2.nfssa_size -#define sa_nfsatime sa_un.sa_nfsv2.nfssa_atime -#define sa_nfsmtime sa_un.sa_nfsv2.nfssa_mtime -#define sa_nqsize sa_un.sa_nqnfs.nqsa_size -#define sa_nqatime sa_un.sa_nqnfs.nqsa_atime -#define sa_nqmtime sa_un.sa_nqnfs.nqsa_mtime -#define sa_nqflags sa_un.sa_nqnfs.nqsa_flags -#define sa_nqrdev sa_un.sa_nqnfs.nqsa_rdev - -struct nfsv2_statfs { - u_long sf_tsize; - u_long sf_bsize; - u_long sf_blocks; - u_long sf_bfree; - u_long sf_bavail; - u_long sf_files; /* Nqnfs only */ - u_long sf_ffree; /* ditto */ -}; diff --git a/usr.sbin/tcpdump/tcpdump/os.h b/usr.sbin/tcpdump/tcpdump/os.h index 1bd9d5c..799e36e 100644 --- a/usr.sbin/tcpdump/tcpdump/os.h +++ b/usr.sbin/tcpdump/tcpdump/os.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: os-bsd.h,v 1.18 94/06/14 20:15:17 leres Exp $ (LBL) + * @(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/os.h,v 1.2 1995/03/08 12:52:21 olah Exp $ (LBL) */ #include <sys/param.h> @@ -58,3 +58,10 @@ #ifndef RIPCMD_POLLENTRY #define RIPCMD_POLLENTRY 6 #endif + +typedef int64_t int64; +typedef u_int64_t u_int64; + +#define INT64_FORMAT "%qd" +#define U_INT64_FORMAT "%qu" +#define HEX_INT64_FORMAT "%qx" diff --git a/usr.sbin/tcpdump/tcpdump/parsenfsfh.c b/usr.sbin/tcpdump/tcpdump/parsenfsfh.c index 4acb82b..78464bb 100644 --- a/usr.sbin/tcpdump/tcpdump/parsenfsfh.c +++ b/usr.sbin/tcpdump/tcpdump/parsenfsfh.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid = "$Header: parsenfsfh.c,v 1.5 94/01/13 19:06:41 leres Exp $"; +static char *RCSid = "$Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/parsenfsfh.c,v 1.1 1995/03/08 12:52:23 olah Exp $"; #endif /* @@ -81,8 +81,9 @@ typedef unsigned int u_int32x; static int is_UCX(unsigned char *); void -Parse_fh(fh, fsidp, inop, osnamep, fsnamep, ourself) +Parse_fh(fh, len, fsidp, inop, osnamep, fsnamep, ourself) register caddr_t *fh; +int len; my_fsid *fsidp; ino_t *inop; char **osnamep; /* if non-NULL, return OS name here */ diff --git a/usr.sbin/tcpdump/tcpdump/print-nfs.c b/usr.sbin/tcpdump/tcpdump/print-nfs.c index 51226ed..b120674 100644 --- a/usr.sbin/tcpdump/tcpdump/print-nfs.c +++ b/usr.sbin/tcpdump/tcpdump/print-nfs.c @@ -21,7 +21,7 @@ #ifndef lint static char rcsid[] = - "@(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-nfs.c,v 1.3 1995/03/08 12:52:36 olah Exp $ (LBL)"; + "@(#) $Header: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-nfs.c,v 1.4 1995/08/23 05:18:54 pst Exp $ (LBL)"; #endif #include <sys/param.h> @@ -40,12 +40,8 @@ static char rcsid[] = #ifdef SOLARIS #include <tiuser.h> #endif -#include <rpc/types.h> -#include <rpc/xdr.h> -#include <rpc/auth.h> -#include <rpc/auth_unix.h> -#include <rpc/svc.h> -#include <rpc/rpc_msg.h> +#include <rpc/rpc.h> +#include <rpc/pmap_prot.h> #include <ctype.h> #include <stdio.h> @@ -56,13 +52,187 @@ static char rcsid[] = #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ -#include "nfsv2.h" +#include "nfs.h" #include "nfsfh.h" -static void nfs_printfh(const u_int32 *); +static void nfs_printfh(const u_int32 *, const int); static void xid_map_enter(const struct rpc_msg *, const struct ip *); -static int32 xid_map_find(const struct rpc_msg *, const struct ip *); -static void interp_reply(const struct rpc_msg *, u_int32, int); +static int32 xid_map_find(const struct rpc_msg *, const struct ip *, u_int32 *, + u_int32 *); +static void interp_reply(const struct rpc_msg *, u_int32, u_int32, int); +static const u_int32 *parse_post_op_attr(const u_int32 *, int); + +/* + * Mapping of old NFS Version 2 RPC numbers to generic numbers. + */ +u_int32 nfsv3_procid[NFS_NPROCS] = { + NFSPROC_NULL, + NFSPROC_GETATTR, + NFSPROC_SETATTR, + NFSPROC_NOOP, + NFSPROC_LOOKUP, + NFSPROC_READLINK, + NFSPROC_READ, + NFSPROC_NOOP, + NFSPROC_WRITE, + NFSPROC_CREATE, + NFSPROC_REMOVE, + NFSPROC_RENAME, + NFSPROC_LINK, + NFSPROC_SYMLINK, + NFSPROC_MKDIR, + NFSPROC_RMDIR, + NFSPROC_READDIR, + NFSPROC_FSSTAT, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP +}; + +const char *nfsv3_writemodes[NFSV3WRITE_NMODES] = { + "unstable", + "datasync", + "filesync" +}; + +static struct token type2str[] = { + { NFNON, "NON" }, + { NFREG, "REG" }, + { NFDIR, "DIR" }, + { NFBLK, "BLK" }, + { NFCHR, "CHR" }, + { NFLNK, "LNK" }, + { NFFIFO, "FIFO" }, + { 0, NULL } +}; + +/* + * Print out a 64-bit integer. This appears to be different on each system, + * try to make the best of it. The integer stored as 2 consecutive XDR + * encoded 32-bit integers, to which a pointer is passed. + * + * Assume that a system that has INT64_FORMAT defined, has a 64-bit + * integer datatype and can print it. + */ + +#define UNSIGNED 0 +#define SIGNED 1 +#define HEX 2 + +int print_int64(const u_int32 *dp, int how) +{ + static char buf[32]; +#ifdef INT64_FORMAT + u_int64 res; + + res = ((u_int64)ntohl(dp[0]) << 32) | (u_int64)ntohl(dp[1]); + switch (how) { + case SIGNED: + printf(INT64_FORMAT, res); + break; + case UNSIGNED: + printf(U_INT64_FORMAT, res); + break; + case HEX: + printf(HEX_INT64_FORMAT, res); + break; + default: + return (0); + } +#else + /* + * XXX - throw upper 32 bits away. + * Could also go for hex: printf("0x%x%x", dp[0], dp[1]); + */ + if (sign) + printf("%ld", (int)dp[1]); + else + printf("%lu", (unsigned int)dp[1]); +#endif + return 1; +} + +static const u_int32 * +parse_sattr3(const u_int32 *dp, struct nfsv3_sattr *sa3) +{ + register const u_int32 *ep = (u_int32 *)snapend; + + if (dp + 1 > ep) + return (0); + if ((sa3->sa_modeset = ntohl(*dp++))) { + if (dp + 1 > ep) + return (0); + sa3->sa_mode = ntohl(*dp++); + } + + if (dp + 1 > ep) + return (0); + if ((sa3->sa_uidset = ntohl(*dp++))) { + if (dp + 1 > ep) + return (0); + sa3->sa_uid = ntohl(*dp++); + } + + if (dp + 1 > ep) + return (0); + if ((sa3->sa_gidset = ntohl(*dp++))) { + if (dp + 1 > ep) + return (0); + sa3->sa_gid = ntohl(*dp++); + } + + if (dp + 1 > ep) + return (0); + if ((sa3->sa_sizeset = ntohl(*dp++))) { + if (dp + 1 > ep) + return (0); + sa3->sa_size = ntohl(*dp++); + } + + if (dp + 1 > ep) + return (0); + if ((sa3->sa_atimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) { + if (dp + 2 > ep) + return (0); + sa3->sa_atime.nfsv3_sec = ntohl(*dp++); + sa3->sa_atime.nfsv3_nsec = ntohl(*dp++); + } + + if (dp + 1 > ep) + return (0); + if ((sa3->sa_mtimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) { + if (dp + 2 > ep) + return (0); + sa3->sa_mtime.nfsv3_sec = ntohl(*dp++); + sa3->sa_mtime.nfsv3_nsec = ntohl(*dp++); + } + + return dp; +} + +void +print_sattr3(const struct nfsv3_sattr *sa3, int verbose) +{ + if (sa3->sa_modeset) + printf(" mode %o", sa3->sa_mode); + if (sa3->sa_uidset) + printf(" uid %u", sa3->sa_uid); + if (sa3->sa_gidset) + printf(" gid %u", sa3->sa_gid); + if (verbose > 1) { + if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) + printf(" atime %u.%06u", sa3->sa_atime.nfsv3_sec, + sa3->sa_atime.nfsv3_nsec); + if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) + printf(" mtime %u.%06u", sa3->sa_mtime.nfsv3_sec, + sa3->sa_mtime.nfsv3_nsec); + } +} void nfsreply_print(register const u_char *bp, int length, @@ -70,7 +240,7 @@ nfsreply_print(register const u_char *bp, int length, { register const struct rpc_msg *rp; register const struct ip *ip; - int32 proc; + u_int32 proc, vers; rp = (const struct rpc_msg *)bp; ip = (const struct ip *)bp2; @@ -93,9 +263,8 @@ nfsreply_print(register const u_char *bp, int length, "ok":"ERR", length); - proc = xid_map_find(rp, ip); - if (proc >= 0) - interp_reply(rp, (u_int32)proc, length); + if (xid_map_find(rp, ip, &proc, &vers) >= 0) + interp_reply(rp, proc, vers, length); } /* @@ -133,11 +302,21 @@ parsereq(register const struct rpc_msg *rp, register int length) * If packet was truncated, return 0. */ static const u_int32 * -parsefh(register const u_int32 *dp) +parsefh(register const u_int32 *dp, int v3) { - if (dp + 8 <= (u_int32 *)snapend) { - nfs_printfh(dp); - return (dp + 8); + int len; + + if (v3) { + if (dp + 1 > (u_int32 *)snapend) + return (0); + len = (int)ntohl(*dp) / 4; + dp++; + } else + len = NFSX_V2FH / 4; + + if (dp + len <= (u_int32 *)snapend) { + nfs_printfh(dp, len); + return (dp + len); } return (0); } @@ -177,9 +356,9 @@ parsefn(register const u_int32 *dp) * If packet was truncated (or there was some other error), return 0. */ static const u_int32 * -parsefhn(register const u_int32 *dp) +parsefhn(register const u_int32 *dp, int v3) { - dp = parsefh(dp); + dp = parsefh(dp, v3); if (dp == 0) return (0); putchar(' '); @@ -193,6 +372,9 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) register const struct ip *ip; register const u_int32 *dp; register const u_char *ep; + nfstype type; + int proc, v3; + struct nfsv3_sattr sa3; #define TCHECK(p, l) if ((u_char *)(p) > ep - l) break @@ -215,101 +397,162 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) xid_map_enter(rp, ip); /* record proc number for later on */ - switch (ntohl(rp->rm_call.cb_proc)) { -#ifdef NFSPROC_NOOP + v3 = (ntohl(rp->rm_call.cb_vers) == NFS_VER3); + proc = ntohl(rp->rm_call.cb_proc); + + if (!v3 && proc < NFS_NPROCS) + proc = nfsv3_procid[proc]; + + switch (proc) { case NFSPROC_NOOP: printf(" nop"); return; -#else -#define NFSPROC_NOOP -1 -#endif case NFSPROC_NULL: printf(" null"); return; case NFSPROC_GETATTR: printf(" getattr"); - if ((dp = parsereq(rp, length)) != 0 && parsefh(dp) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefh(dp, v3) != 0) return; break; case NFSPROC_SETATTR: printf(" setattr"); - if ((dp = parsereq(rp, length)) != 0 && parsefh(dp) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefh(dp, v3) != 0) return; break; -#if NFSPROC_ROOT != NFSPROC_NOOP - case NFSPROC_ROOT: - printf(" root"); - break; -#endif case NFSPROC_LOOKUP: printf(" lookup"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) + return; + break; + + case NFSPROC_ACCESS: + printf(" access"); + if ((dp = parsereq(rp, length)) != 0 && + (dp = parsefh(dp, v3)) != 0) { + TCHECK(dp, 4); + printf(" %04x", ntohl(dp[0])); return; + } break; case NFSPROC_READLINK: printf(" readlink"); - if ((dp = parsereq(rp, length)) != 0 && parsefh(dp) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefh(dp, v3) != 0) return; break; case NFSPROC_READ: printf(" read"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp)) != 0) { - TCHECK(dp, 3 * sizeof(*dp)); - printf(" %lu bytes @ %lu", - ntohl(dp[1]), ntohl(dp[0])); + (dp = parsefh(dp, v3)) != 0) { + if (v3) { + TCHECK(dp, 3 * sizeof(*dp)); + printf(" %lu bytes @ ", ntohl(dp[2])); + print_int64(dp, UNSIGNED); + } else { + TCHECK(dp, 2 * sizeof(*dp)); + printf(" %lu bytes @ %lu", + ntohl(dp[1]), ntohl(dp[0])); + } return; } break; -#if NFSPROC_WRITECACHE != NFSPROC_NOOP - case NFSPROC_WRITECACHE: - printf(" writecache"); - if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp)) != 0) { - TCHECK(dp, 4 * sizeof(*dp)); - printf(" %lu (%lu) bytes @ %lu (%lu)", - ntohl(dp[3]), ntohl(dp[2]), - ntohl(dp[1]), ntohl(dp[0])); - return; - } - break; -#endif case NFSPROC_WRITE: printf(" write"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp)) != 0) { - TCHECK(dp, 4 * sizeof(*dp)); - printf(" %lu (%lu) bytes @ %lu (%lu)", - ntohl(dp[3]), ntohl(dp[2]), - ntohl(dp[1]), ntohl(dp[0])); + (dp = parsefh(dp, v3)) != 0) { + if (v3) { + TCHECK(dp, 3 * sizeof(*dp)); + printf(" %lu bytes @ ", ntohl(dp[4])); + print_int64(dp, UNSIGNED); + if (vflag) { + dp += 3; + TCHECK(dp, sizeof(*dp)); + printf(" <%s>", + nfsv3_writemodes[ntohl(*dp)]); + } + } else { + TCHECK(dp, 4 * sizeof(*dp)); + printf(" %lu (%lu) bytes @ %lu (%lu)", + ntohl(dp[3]), ntohl(dp[2]), + ntohl(dp[1]), ntohl(dp[0])); + } return; } break; case NFSPROC_CREATE: printf(" create"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) + return; + break; + + case NFSPROC_MKDIR: + printf(" mkdir"); + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) return; break; + case NFSPROC_SYMLINK: + printf(" symlink"); + if ((dp = parsereq(rp, length)) != 0 && + (dp = parsefhn(dp, v3)) != 0) { + fputs(" -> ", stdout); + if (v3 && (dp = parse_sattr3(dp, &sa3)) == 0) + break; + if (parsefn(dp) == 0) + break; + if (v3 && vflag) + print_sattr3(&sa3, vflag); + return; + } + break; + + case NFSPROC_MKNOD: + printf(" mknod"); + if ((dp = parsereq(rp, length)) != 0 && + (dp = parsefhn(dp, v3)) != 0) { + if (dp + 1 > (u_int32 *)snapend) + break; + type = (nfstype)ntohl(*dp++); + if ((dp = parse_sattr3(dp, &sa3)) == 0) + break; + printf(" %s", tok2str(type2str, "unk-ft %d", type)); + if (vflag && (type == NFCHR || type == NFBLK)) { + if (dp + 2 > (u_int32 *)snapend) + break; + printf(" %u/%u", ntohl(dp[0]), ntohl(dp[1])); + dp += 2; + } + if (vflag) + print_sattr3(&sa3, vflag); + return; + } + break; + case NFSPROC_REMOVE: printf(" remove"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) + return; + break; + + case NFSPROC_RMDIR: + printf(" rmdir"); + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) return; break; case NFSPROC_RENAME: printf(" rename"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefhn(dp)) != 0) { + (dp = parsefhn(dp, v3)) != 0) { fputs(" ->", stdout); - if (parsefhn(dp) != 0) + if (parsefhn(dp, v3) != 0) return; } break; @@ -317,53 +560,81 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) case NFSPROC_LINK: printf(" link"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp)) != 0) { + (dp = parsefh(dp, v3)) != 0) { fputs(" ->", stdout); - if (parsefhn(dp) != 0) + if (parsefhn(dp, v3) != 0) return; } break; - case NFSPROC_SYMLINK: - printf(" symlink"); + case NFSPROC_READDIR: + printf(" readdir"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefhn(dp)) != 0) { - fputs(" -> ", stdout); - if (parsefn(dp) != 0) - return; + (dp = parsefh(dp, v3)) != 0) { + if (v3) { + TCHECK(dp, 20); + /* + * We shouldn't really try to interpret the + * offset cookie here. + */ + printf(" %lu bytes @ ", ntohl(dp[4])); + print_int64(dp, SIGNED); + if (vflag) + printf(" verf %08lx%08lx", dp[2], + dp[3]); + } else { + TCHECK(dp, 2 * sizeof(*dp)); + /* + * Print the offset as signed, since -1 is + * common, but offsets > 2^31 aren't. + */ + printf(" %lu bytes @ %ld", ntohl(dp[1]), + ntohl(dp[0])); + } + return; } break; - case NFSPROC_MKDIR: - printf(" mkdir"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) + case NFSPROC_READDIRPLUS: + printf(" readdirplus"); + if ((dp = parsereq(rp, length)) != 0 && + (dp = parsefh(dp, v3)) != 0) { + TCHECK(dp, 20); + /* + * We don't try to interpret the offset + * cookie here. + */ + printf(" %lu bytes @ ", ntohl(dp[4])); + print_int64(dp, SIGNED); + if (vflag) + printf(" max %lu verf %08lx%08lx", + ntohl(dp[5]), dp[2], dp[3]); return; + } break; - case NFSPROC_RMDIR: - printf(" rmdir"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) + case NFSPROC_FSSTAT: + printf(" fsstat"); + if ((dp = parsereq(rp, length)) != 0 && parsefh(dp, v3) != 0) return; break; - case NFSPROC_READDIR: - printf(" readdir"); - if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp)) != 0) { - TCHECK(dp, 2 * sizeof(*dp)); - /* - * Print the offset as signed, since -1 is common, - * but offsets > 2^31 aren't. - */ - printf(" %lu bytes @ %ld", ntohl(dp[1]), ntohl(dp[0])); - return; - } + case NFSPROC_FSINFO: + printf(" fsinfo"); break; - case NFSPROC_STATFS: - printf(" statfs"); - if ((dp = parsereq(rp, length)) != 0 && parsefh(dp) != 0) + case NFSPROC_PATHCONF: + printf(" pathconf"); + break; + + case NFSPROC_COMMIT: + printf(" commit"); + if ((dp = parsereq(rp, length)) != 0 && + (dp = parsefh(dp, v3)) != 0) { + printf(" %lu bytes @ ", ntohl(dp[2])); + print_int64(dp, UNSIGNED); return; + } break; default: @@ -371,7 +642,6 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) return; } fputs(" [|nfs]", stdout); -#undef TCHECK } /* @@ -384,20 +654,20 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) * additional hacking on the parser code. */ static void -nfs_printfh(register const u_int32 *dp) +nfs_printfh(register const u_int32 *dp, const int len) { my_fsid fsid; ino_t ino; char *sfsname = NULL; - Parse_fh((caddr_t*)dp, &fsid, &ino, NULL, &sfsname, 0); + Parse_fh((caddr_t*)dp, len, &fsid, &ino, NULL, &sfsname, 0); if (sfsname) { /* file system ID is ASCII, not numeric, for this server OS */ - static char temp[NFS_FHSIZE+1]; + static char temp[NFSX_V3FHMAX+1]; /* Make sure string is null-terminated */ - strncpy(temp, sfsname, NFS_FHSIZE); + strncpy(temp, sfsname, NFSX_V3FHMAX); /* Remove trailing spaces */ sfsname = strchr(temp, ' '); if (sfsname) @@ -423,6 +693,7 @@ struct xid_map_entry { struct in_addr client; /* client IP address (net order) */ struct in_addr server; /* server IP address (net order) */ u_int32 proc; /* call proc number (host order) */ + u_int32 vers; /* program version (host order) */ }; /* @@ -452,11 +723,13 @@ xid_map_enter(const struct rpc_msg *rp, const struct ip *ip) xmep->client = ip->ip_src; xmep->server = ip->ip_dst; xmep->proc = ntohl(rp->rm_call.cb_proc); + xmep->vers = ntohl(rp->rm_call.cb_vers); } /* Returns NFSPROC_xxx or -1 on failure */ -static int32 -xid_map_find(const struct rpc_msg *rp, const struct ip *ip) +static int +xid_map_find(const struct rpc_msg *rp, const struct ip *ip, u_int32 *proc, + u_int32 *vers) { int i; struct xid_map_entry *xmep; @@ -472,7 +745,9 @@ xid_map_find(const struct rpc_msg *rp, const struct ip *ip) xmep->server.s_addr == sip) { /* match */ xid_map_hint = i; - return ((int32)xmep->proc); + *proc = xmep->proc; + *vers = xmep->vers; + return 0; } if (++i >= XIDMAPSIZE) i = 0; @@ -568,143 +843,189 @@ parserep(register const struct rpc_msg *rp, register int length) #define T2CHECK(p, l) if ((u_char *)(p) > ((u_char *)snapend) - l) return(0) -#if defined(BSD) && (BSD >= 199103) -#define strerr strerror -#else /* * Not all systems have strerror(). */ static char * strerr(int errno) { - extern int sys_nerr; - /* Conflicts with declaration in <stdio.h> */ - extern char *sys_errlist[]; - if (errno < sys_nerr) - return (sys_errlist[errno]); - return (0); + return (strerror(errno)); } -#endif static const u_int32 * -parsestatus(const u_int32 *dp) +parsestatus(const u_int32 *dp, int *er) { int errno; T2CHECK(dp, 4); errno = ntohl(dp[0]); - if (errno != 0) { + if (er) + *er = errno; + if (errno != 0 && !qflag) { char *errmsg; - if (qflag) - return(0); - errmsg = strerr(errno); if (errmsg) - printf(" ERROR: %s", errmsg); + printf(" ERROR: '%s'", errmsg); else printf(" ERROR: %d", errno); - return(0); } return (dp + 1); } -static struct token type2str[] = { - { NFNON, "NON" }, - { NFREG, "REG" }, - { NFDIR, "DIR" }, - { NFBLK, "BLK" }, - { NFCHR, "CHR" }, - { NFLNK, "LNK" }, - { 0, NULL } -}; - static const u_int32 * -parsefattr(const u_int32 *dp, int verbose) +parsefattr(const u_int32 *dp, int verbose, int v3) { - const struct nfsv2_fattr *fap; + const struct nfs_fattr *fap; - T2CHECK(dp, 4); + T2CHECK(dp, 5 * sizeof(*dp)); - fap = (const struct nfsv2_fattr *)dp; - if (verbose) - printf(" %s %o ids %d/%d sz %d ", + fap = (const struct nfs_fattr *)dp; + if (verbose) { + printf(" %s %o ids %d/%d", tok2str(type2str, "unk-ft %d ", ntohl(fap->fa_type)), ntohl(fap->fa_mode), ntohl(fap->fa_uid), - ntohl(fap->fa_gid), ntohl(fap->fa_nfssize)); + ntohl(fap->fa_gid)); + if (v3) { + T2CHECK(dp, 7 * sizeof(*dp)); + printf(" sz "); + print_int64((u_int32 *)&fap->fa3_size, UNSIGNED); + putchar(' '); + } + else { + T2CHECK(dp, 6 * sizeof(*dp)); + printf(" sz %d ", ntohl(fap->fa2_size)); + } + } /* print lots more stuff */ if (verbose > 1) { - printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ", - ntohl(fap->fa_nlink), ntohl(fap->fa_nfsrdev), - ntohl(fap->fa_nfsfsid), ntohl(fap->fa_nfsfileid)); - printf("%d.%06d ", - ntohl(fap->fa_nfsatime.nfs_sec), - ntohl(fap->fa_nfsatime.nfs_usec)); - printf("%d.%06d ", - ntohl(fap->fa_nfsmtime.nfs_sec), - ntohl(fap->fa_nfsmtime.nfs_usec)); - printf("%d.%06d ", - ntohl(fap->fa_nfsctime.nfs_sec), - ntohl(fap->fa_nfsctime.nfs_usec)); + if (v3) { + T2CHECK(dp, 64); + printf("nlink %d rdev %d/%d ", + ntohl(fap->fa_nlink), + ntohl(fap->fa3_rdev.specdata1), + ntohl(fap->fa3_rdev.specdata2)); + printf("fsid "); + print_int64((u_int32 *)&fap->fa2_fsid, HEX); + printf(" nodeid "); + print_int64((u_int32 *)&fap->fa2_fileid, HEX); + printf(" a/m/ctime %u.%06u ", + ntohl(fap->fa3_atime.nfsv3_sec), + ntohl(fap->fa3_atime.nfsv3_nsec)); + printf("%u.%06u ", + ntohl(fap->fa3_mtime.nfsv3_sec), + ntohl(fap->fa3_mtime.nfsv3_nsec)); + printf("%u.%06u ", + ntohl(fap->fa3_ctime.nfsv3_sec), + ntohl(fap->fa3_ctime.nfsv3_nsec)); + } else { + T2CHECK(dp, 48); + printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ", + ntohl(fap->fa_nlink), ntohl(fap->fa2_rdev), + ntohl(fap->fa2_fsid), ntohl(fap->fa2_fileid)); + printf("%u.%06u ", + ntohl(fap->fa2_atime.nfsv2_sec), + ntohl(fap->fa2_atime.nfsv2_usec)); + printf("%u.%06u ", + ntohl(fap->fa2_mtime.nfsv2_sec), + ntohl(fap->fa2_mtime.nfsv2_usec)); + printf("%u.%06u ", + ntohl(fap->fa2_ctime.nfsv2_sec), + ntohl(fap->fa2_ctime.nfsv2_usec)); + } } - return ((const u_int32 *)&fap[1]); + return ((const u_int32 *)((unsigned char *)dp + + (v3 ? NFSX_V3FATTR : NFSX_V2FATTR))); } static int -parseattrstat(const u_int32 *dp, int verbose) +parseattrstat(const u_int32 *dp, int verbose, int v3) { - dp = parsestatus(dp); - if (dp == NULL) + int er; + + dp = parsestatus(dp, &er); + if (dp == NULL || er) return (0); - return ((int)parsefattr(dp, verbose)); + return ((long)parsefattr(dp, verbose, v3)); } static int parsediropres(const u_int32 *dp) { - dp = parsestatus(dp); - if (dp == NULL) + int er; + + if (!(dp = parsestatus(dp, &er)) || er) return (0); - dp = parsefh(dp); + dp = parsefh(dp, 0); if (dp == NULL) return (0); - return (parsefattr(dp, vflag) != NULL); + return (parsefattr(dp, vflag, 0) != NULL); } static int -parselinkres(const u_int32 *dp) +parselinkres(const u_int32 *dp, int v3) { - dp = parsestatus(dp); - if (dp == NULL) - return(0); + int er; + dp = parsestatus(dp, &er); + if (dp == NULL || er) + return(0); + if (v3 && !(dp = parse_post_op_attr(dp, vflag))) + return (0); putchar(' '); return (parsefn(dp) != NULL); } static int -parsestatfs(const u_int32 *dp) +parsestatfs(const u_int32 *dp, int v3) { - const struct nfsv2_statfs *sfsp; + const struct nfs_statfs *sfsp; + int er; - dp = parsestatus(dp); - if (dp == NULL) + dp = parsestatus(dp, &er); + if (dp == NULL || (!v3 && er)) return(0); if (qflag) return(1); - T2CHECK(dp, 20); + if (v3) { + if (vflag) + printf(" POST:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + return (0); + } - sfsp = (const struct nfsv2_statfs *)dp; - printf(" tsize %d bsize %d blocks %d bfree %d bavail %d", - ntohl(sfsp->sf_tsize), ntohl(sfsp->sf_bsize), - ntohl(sfsp->sf_blocks), ntohl(sfsp->sf_bfree), - ntohl(sfsp->sf_bavail)); + T2CHECK(dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS)); + + sfsp = (const struct nfs_statfs *)dp; + + if (v3) { + printf(" tbytes "); + print_int64((u_int32 *)&sfsp->sf_tbytes, UNSIGNED); + printf(" fbytes "); + print_int64((u_int32 *)&sfsp->sf_fbytes, UNSIGNED); + printf(" abytes "); + print_int64((u_int32 *)&sfsp->sf_abytes, UNSIGNED); + if (vflag) { + printf(" tfiles "); + print_int64((u_int32 *)&sfsp->sf_tfiles, UNSIGNED); + printf(" ffiles "); + print_int64((u_int32 *)&sfsp->sf_ffiles, UNSIGNED); + printf(" afiles "); + print_int64((u_int32 *)&sfsp->sf_afiles, UNSIGNED); + printf(" invar %lu", ntohl(sfsp->sf_invarsec)); + } + } else { + printf(" tsize %d bsize %d blocks %d bfree %d bavail %d", + ntohl(sfsp->sf_tsize), ntohl(sfsp->sf_bsize), + ntohl(sfsp->sf_blocks), ntohl(sfsp->sf_bfree), + ntohl(sfsp->sf_bavail)); + } return (1); } @@ -712,8 +1033,10 @@ parsestatfs(const u_int32 *dp) static int parserddires(const u_int32 *dp) { - dp = parsestatus(dp); - if (dp == 0) + int er; + + dp = parsestatus(dp, &er); + if (dp == 0 || er) return (0); if (qflag) return (1); @@ -726,20 +1049,203 @@ parserddires(const u_int32 *dp) return (1); } +static const u_int32 * +parse_wcc_attr(const u_int32 *dp) +{ + printf(" sz "); + print_int64(dp, UNSIGNED); + printf(" mtime %u.%06u ctime %u.%06u", ntohl(dp[2]), ntohl(dp[3]), + ntohl(dp[4]), ntohl(dp[5])); + return (dp + 6); +} + +/* + * Pre operation attributes. Print only if vflag > 1. + */ +static const u_int32 * +parse_pre_op_attr(const u_int32 *dp, int verbose) +{ + T2CHECK(dp, 4); + if (!ntohl(dp[0])) + return (dp + 1); + dp++; + T2CHECK(dp, 24); + if (verbose > 1) { + return parse_wcc_attr(dp); + } else { + /* If not verbose enough, just skip over wcc_attr */ + return (dp + 6); + } +} + +/* + * Post operation attributes are printed if vflag >= 1 + */ +static const u_int32 * +parse_post_op_attr(const u_int32 *dp, int verbose) +{ + T2CHECK(dp, 4); + if (!ntohl(dp[0])) + return (dp + 1); + dp++; + if (verbose) { + return parsefattr(dp, verbose, 1); + } else + return (dp + (NFSX_V3FATTR / sizeof (u_int32))); +} + +static const u_int32 * +parse_wcc_data(const u_int32 *dp, int verbose) +{ + if (verbose > 1) + printf(" PRE:"); + if (!(dp = parse_pre_op_attr(dp, verbose))) + return (0); + + if (verbose) + printf(" POST:"); + return parse_post_op_attr(dp, verbose); +} + +static const u_int32 * +parsecreateopres(const u_int32 *dp, int verbose) +{ + int er; + + if (!(dp = parsestatus(dp, &er))) + return (0); + if (er) + dp = parse_wcc_data(dp, verbose); + else { + T2CHECK(dp, 4); + if (!ntohl(dp[0])) + return (dp + 1); + dp++; + if (!(dp = parsefh(dp, 1))) + return (0); + if (verbose) { + if (!(dp = parse_post_op_attr(dp, verbose))) + return (0); + if (vflag > 1) { + printf("dir attr:"); + dp = parse_wcc_data(dp, verbose); + } + } + } + return (dp); +} + +static int +parsewccres(const u_int32 *dp, int verbose) +{ + int er; + + if (!(dp = parsestatus(dp, &er))) + return (0); + return parse_wcc_data(dp, verbose) != 0; +} + +static const u_int32 * +parsev3rddirres(const u_int32 *dp, int verbose) +{ + int er; + + if (!(dp = parsestatus(dp, &er))) + return (0); + if (vflag) + printf(" POST:"); + if (!(dp = parse_post_op_attr(dp, verbose))) + return (0); + if (er) + return dp; + if (vflag) { + T2CHECK(dp, 8); + printf(" verf %08lx%08lx", dp[0], dp[1]); + dp += 2; + } + return dp; +} + +static int +parsefsinfo(const u_int32 *dp) +{ + struct nfsv3_fsinfo *sfp; + int er; + + if (!(dp = parsestatus(dp, &er))) + return (0); + if (vflag) + printf(" POST:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + return (0); + if (er) + return (1); + + T2CHECK(dp, sizeof (struct nfsv3_fsinfo)); + + sfp = (struct nfsv3_fsinfo *)dp; + printf(" rtmax %lu rtpref %lu wtmax %lu wtpref %lu dtpref %lu", + ntohl(sfp->fs_rtmax), ntohl(sfp->fs_rtpref), + ntohl(sfp->fs_wtmax), ntohl(sfp->fs_wtpref), + ntohl(sfp->fs_dtpref)); + if (vflag) { + printf(" rtmult %lu wtmult %lu maxfsz ", + ntohl(sfp->fs_rtmult), ntohl(sfp->fs_wtmult)); + print_int64((u_int32 *)&sfp->fs_maxfilesize, UNSIGNED); + printf(" delta %u.%06u ", ntohl(sfp->fs_timedelta.nfsv3_sec), + ntohl(sfp->fs_timedelta.nfsv3_nsec)); + } + return (1); +} + +static int +parsepathconf(const u_int32 *dp) +{ + int er; + struct nfsv3_pathconf *spp; + + if (!(dp = parsestatus(dp, &er))) + return (0); + if (vflag) + printf(" POST:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + return (0); + if (er) + return (1); + + T2CHECK(dp, sizeof (struct nfsv3_pathconf)); + + spp = (struct nfsv3_pathconf *)dp; + + printf(" linkmax %lu namemax %lu %s %s %s %s", + ntohl(spp->pc_linkmax), + ntohl(spp->pc_namemax), + ntohl(spp->pc_notrunc) ? "notrunc" : "", + ntohl(spp->pc_chownrestricted) ? "chownres" : "", + ntohl(spp->pc_caseinsensitive) ? "igncase" : "", + ntohl(spp->pc_casepreserving) ? "keepcase" : ""); + return (0); +} + static void -interp_reply(const struct rpc_msg *rp, u_int32 proc, int length) +interp_reply(const struct rpc_msg *rp, u_int32 proc, u_int32 vers, int length) { register const u_int32 *dp; + register int v3; + register const u_char *ep = snapend; + int er; + + v3 = (vers == NFS_VER3); + + if (!v3 && proc < NFS_NPROCS) + proc = nfsv3_procid[proc]; switch (proc) { -#ifdef NFSPROC_NOOP case NFSPROC_NOOP: printf(" nop"); return; -#else -#define NFSPROC_NOOP -1 -#endif + case NFSPROC_NULL: printf(" null"); return; @@ -747,115 +1253,286 @@ interp_reply(const struct rpc_msg *rp, u_int32 proc, int length) case NFSPROC_GETATTR: printf(" getattr"); dp = parserep(rp, length); - if (dp != 0 && parseattrstat(dp, !qflag) != 0) + if (dp != 0 && parseattrstat(dp, !qflag, v3) != 0) return; break; case NFSPROC_SETATTR: printf(" setattr"); - dp = parserep(rp, length); - if (dp != 0 && parseattrstat(dp, !qflag) != 0) + if (!(dp = parserep(rp, length))) return; + if (v3) { + if (parsewccres(dp, vflag)) + return; + } else { + if (parseattrstat(dp, !qflag, 0) != 0) + return; + } break; -#if NFSPROC_ROOT != NFSPROC_NOOP - case NFSPROC_ROOT: - printf(" root"); - break; -#endif case NFSPROC_LOOKUP: printf(" lookup"); - dp = parserep(rp, length); - if (dp != 0 && parsediropres(dp) != 0) - return; + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (er) { + if (vflag > 1) { + printf(" post dattr:"); + dp = parse_post_op_attr(dp, vflag); + } + } else { + if (!(dp = parsefh(dp, v3))) + break; + if ((dp = parse_post_op_attr(dp, vflag)) && + vflag > 1) { + printf(" post dattr:"); + dp = parse_post_op_attr(dp, vflag); + } + } + if (dp) + return; + } else { + if (parsediropres(dp) != 0) + return; + } break; + case NFSPROC_ACCESS: + printf(" access"); + dp = parserep(rp, length); + if (!(dp = parsestatus(dp, &er))) + break; + if (vflag) + printf(" attr:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + break; + if (!er) + printf(" c %04x", ntohl(dp[0])); + return; + case NFSPROC_READLINK: printf(" readlink"); dp = parserep(rp, length); - if (dp != 0 && parselinkres(dp) != 0) + if (dp != 0 && parselinkres(dp, v3) != 0) return; break; case NFSPROC_READ: printf(" read"); - dp = parserep(rp, length); - if (dp != 0 && parseattrstat(dp, vflag) != 0) + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (!(dp = parse_post_op_attr(dp, vflag))) + break; + if (er) + return; + if (vflag) { + TCHECK(dp, 8); + printf("%lu bytes", ntohl(dp[0])); + if (ntohl(dp[1])) + printf(" EOF"); + } return; + } else { + if (parseattrstat(dp, vflag, 0) != 0) + return; + } break; -#if NFSPROC_WRITECACHE != NFSPROC_NOOP - case NFSPROC_WRITECACHE: - printf(" writecache"); - break; -#endif case NFSPROC_WRITE: printf(" write"); - dp = parserep(rp, length); - if (dp != 0 && parseattrstat(dp, vflag) != 0) - return; + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (!(dp = parse_wcc_data(dp, vflag))) + break; + if (er) + return; + if (vflag) { + TCHECK(dp, 4); + printf("%lu bytes", ntohl(dp[0])); + if (vflag > 1) { + TCHECK(dp, 4); + printf(" <%s>", + nfsv3_writemodes[ntohl(dp[1])]); + } + return; + } + } else { + if (parseattrstat(dp, vflag, v3) != 0) + return; + } break; case NFSPROC_CREATE: printf(" create"); - dp = parserep(rp, length); - if (dp != 0 && parsediropres(dp) != 0) + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsecreateopres(dp, vflag) != 0) + return; + } else { + if (parsediropres(dp) != 0) + return; + } + break; + + case NFSPROC_MKDIR: + printf(" mkdir"); + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsecreateopres(dp, vflag) != 0) + return; + } else { + if (parsediropres(dp) != 0) + return; + } + break; + + case NFSPROC_SYMLINK: + printf(" symlink"); + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsecreateopres(dp, vflag) != 0) + return; + } else { + if (parsestatus(dp, &er) != 0) + return; + } + break; + + case NFSPROC_MKNOD: + printf(" mknod"); + if (!(dp = parserep(rp, length))) + break; + if (parsecreateopres(dp, vflag) != 0) return; break; case NFSPROC_REMOVE: printf(" remove"); - dp = parserep(rp, length); - if (dp != 0 && parsestatus(dp) != 0) - return; + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsewccres(dp, vflag)) + return; + } else { + if (parsestatus(dp, &er) != 0) + return; + } + break; + + case NFSPROC_RMDIR: + printf(" rmdir"); + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsewccres(dp, vflag)) + return; + } else { + if (parsestatus(dp, &er) != 0) + return; + } break; case NFSPROC_RENAME: printf(" rename"); - dp = parserep(rp, length); - if (dp != 0 && parsestatus(dp) != 0) + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (vflag) { + printf(" from:"); + if (!(dp = parse_wcc_data(dp, vflag))) + break; + printf(" to:"); + if (!(dp = parse_wcc_data(dp, vflag))) + break; + } return; + } else { + if (parsestatus(dp, &er) != 0) + return; + } break; case NFSPROC_LINK: printf(" link"); - dp = parserep(rp, length); - if (dp != 0 && parsestatus(dp) != 0) - return; + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (vflag) { + printf(" file POST:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + break; + printf(" dir:"); + if (!(dp = parse_wcc_data(dp, vflag))) + break; + return; + } + } else { + if (parsestatus(dp, &er) != 0) + return; + } break; - case NFSPROC_SYMLINK: - printf(" symlink"); - dp = parserep(rp, length); - if (dp != 0 && parsestatus(dp) != 0) + case NFSPROC_READDIR: + printf(" readdir"); + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsev3rddirres(dp, vflag)) + return; + } else { + if (parserddires(dp) != 0) + return; + } + break; + + case NFSPROC_READDIRPLUS: + printf(" readdirplus"); + if (!(dp = parserep(rp, length))) + break; + if (parsev3rddirres(dp, vflag)) return; break; - case NFSPROC_MKDIR: - printf(" mkdir"); + case NFSPROC_FSSTAT: + printf(" fsstat"); dp = parserep(rp, length); - if (dp != 0 && parsediropres(dp) != 0) + if (dp != 0 && parsestatfs(dp, v3) != 0) return; break; - case NFSPROC_RMDIR: - printf(" rmdir"); + case NFSPROC_FSINFO: + printf(" fsinfo"); dp = parserep(rp, length); - if (dp != 0 && parsestatus(dp) != 0) + if (dp != 0 && parsefsinfo(dp) != 0) return; break; - case NFSPROC_READDIR: - printf(" readdir"); + case NFSPROC_PATHCONF: + printf(" pathconf"); dp = parserep(rp, length); - if (dp != 0 && parserddires(dp) != 0) + if (dp != 0 && parsepathconf(dp) != 0) return; break; - case NFSPROC_STATFS: - printf(" statfs"); + case NFSPROC_COMMIT: + printf(" commit"); dp = parserep(rp, length); - if (dp != 0 && parsestatfs(dp) != 0) + if (dp != 0 && parsewccres(dp, vflag) != 0) return; break; diff --git a/usr.sbin/tcpdump/tcpdump/print-udp.c b/usr.sbin/tcpdump/tcpdump/print-udp.c index ed78e60..d6c597c 100644 --- a/usr.sbin/tcpdump/tcpdump/print-udp.c +++ b/usr.sbin/tcpdump/tcpdump/print-udp.c @@ -21,7 +21,7 @@ #ifndef lint static char rcsid[] = - "$Id: /home/ncvs/src/usr.sbin/tcpdump/tcpdump/print-udp.c,v 1.3 1995/03/08 12:52:45 olah Exp $"; + "$Id: print-udp.c,v 1.4 1995/08/29 19:48:11 wollman Exp $"; #endif #include <sys/param.h> @@ -57,7 +57,7 @@ static char rcsid[] = #include "addrtoname.h" #include "appletalk.h" -#include "nfsv2.h" +#include "nfs.h" #include "bootp.h" extern int packettype; |