]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-nfs.c
Clean up comments.
[tcpdump] / print-nfs.c
index 4fb7256fac993fa46f6cf77fc682ef7cb27db508..b02438be15a127dfc3153ffa45db368024776c46 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.77 2000-06-12 15:45:05 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.95 2002-08-01 08:53:21 risso Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-#if __STDC__
-struct mbuf;
-struct rtentry;
-#endif
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#ifdef INET6
-#include <netinet/ip6.h>
-#endif
+#include <tcpdump-stdinc.h>
 
 #include <rpc/rpc.h>
 
-#include <ctype.h>
 #include <pcap.h>
 #include <stdio.h>
 #include <string.h>
@@ -59,6 +42,11 @@ struct rtentry;
 #include "nfs.h"
 #include "nfsfh.h"
 
+#include "ip.h"
+#ifdef INET6
+#include "ip6.h"
+#endif
+
 static void nfs_printfh(const u_int32_t *, const u_int);
 static void xid_map_enter(const struct rpc_msg *, const u_char *);
 static int32_t xid_map_find(const struct rpc_msg *, const u_char *,
@@ -101,6 +89,55 @@ u_int32_t nfsv3_procid[NFS_NPROCS] = {
        NFSPROC_NOOP
 };
 
+/*
+ * NFS V2 and V3 status values.
+ *
+ * Some of these come from the RFCs for NFS V2 and V3, with the message
+ * strings taken from the FreeBSD C library "errlst.c".
+ *
+ * Others are errors that are not in the RFC but that I suspect some
+ * NFS servers could return; the values are FreeBSD errno values, as
+ * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
+ * was primarily BSD-derived.
+ */
+static struct tok status2str[] = {
+       { 1,     "Operation not permitted" },   /* EPERM */
+       { 2,     "No such file or directory" }, /* ENOENT */
+       { 5,     "Input/output error" },        /* EIO */
+       { 6,     "Device not configured" },     /* ENXIO */
+       { 11,    "Resource deadlock avoided" }, /* EDEADLK */
+       { 12,    "Cannot allocate memory" },    /* ENOMEM */
+       { 13,    "Permission denied" },         /* EACCES */
+       { 17,    "File exists" },               /* EEXIST */
+       { 18,    "Cross-device link" },         /* EXDEV */
+       { 19,    "Operation not supported by device" }, /* ENODEV */
+       { 20,    "Not a directory" },           /* ENOTDIR */
+       { 21,    "Is a directory" },            /* EISDIR */
+       { 22,    "Invalid argument" },          /* EINVAL */
+       { 26,    "Text file busy" },            /* ETXTBSY */
+       { 27,    "File too large" },            /* EFBIG */
+       { 28,    "No space left on device" },   /* ENOSPC */
+       { 30,    "Read-only file system" },     /* EROFS */
+       { 31,    "Too many links" },            /* EMLINK */
+       { 45,    "Operation not supported" },   /* EOPNOTSUPP */
+       { 62,    "Too many levels of symbolic links" }, /* ELOOP */
+       { 63,    "File name too long" },        /* ENAMETOOLONG */
+       { 66,    "Directory not empty" },       /* ENOTEMPTY */
+       { 69,    "Disc quota exceeded" },       /* EDQUOT */
+       { 70,    "Stale NFS file handle" },     /* ESTALE */
+       { 71,    "Too many levels of remote in path" }, /* EREMOTE */
+       { 99,    "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
+       { 10001, "Illegal NFS file handle" },   /* NFS3ERR_BADHANDLE */
+       { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
+       { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
+       { 10004, "Operation not supported" },   /* NFS3ERR_NOTSUPP */
+       { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
+       { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
+       { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
+       { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
+       { 0,     NULL }
+};
+
 static struct tok nfsv3_writemodes[] = {
        { 0,            "unstable" },
        { 1,            "datasync" },
@@ -126,7 +163,7 @@ static struct tok type2str[] = {
  *
  * 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
@@ -181,7 +218,7 @@ print_nfsaddr(const u_char *bp, const char *s, const char *d)
 #endif
 
        srcaddr[0] = dstaddr[0] = '\0';
-       switch (((struct ip *)bp)->ip_v) {
+       switch (IP_V((struct ip *)bp)) {
        case 4:
                ip = (struct ip *)bp;
                strlcpy(srcaddr, ipaddr_string(&ip->ip_src), sizeof(srcaddr));
@@ -409,7 +446,7 @@ nfsreq_print(register const u_char *bp, u_int length,
 {
        register const struct rpc_msg *rp;
        register const u_int32_t *dp;
-       nfstype type;
+       nfs_type type;
        int v3;
        u_int32_t proc;
        struct nfsv3_sattr sa3;
@@ -563,7 +600,7 @@ nfsreq_print(register const u_char *bp, u_int length,
                if ((dp = parsereq(rp, length)) != 0 &&
                    (dp = parsefhn(dp, v3)) != 0) {
                        TCHECK(*dp);
-                       type = (nfstype)ntohl(*dp++);
+                       type = (nfs_type)ntohl(*dp++);
                        if ((dp = parse_sattr3(dp, &sa3)) == 0)
                                break;
                        printf(" %s", tok2str(type2str, "unk-ft %d", type));
@@ -671,10 +708,16 @@ nfsreq_print(register const u_char *bp, u_int length,
 
        case NFSPROC_FSINFO:
                printf(" fsinfo");
+               if ((dp = parsereq(rp, length)) != NULL &&
+                   parsefh(dp, v3) != NULL)
+                       return;
                break;
 
        case NFSPROC_PATHCONF:
                printf(" pathconf");
+               if ((dp = parsereq(rp, length)) != NULL &&
+                   parsefh(dp, v3) != NULL)
+                       return;
                break;
 
        case NFSPROC_COMMIT:
@@ -711,9 +754,10 @@ nfs_printfh(register const u_int32_t *dp, const u_int len)
 {
        my_fsid fsid;
        ino_t ino;
-       char *sfsname = NULL;
+       const char *sfsname = NULL;
+       char *spacep;
 
-       Parse_fh((caddr_t*)dp, len, &fsid, &ino, NULL, &sfsname, 0);
+       Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
 
        if (sfsname) {
                /* file system ID is ASCII, not numeric, for this server OS */
@@ -723,9 +767,9 @@ nfs_printfh(register const u_int32_t *dp, const u_int len)
                strncpy(temp, sfsname, NFSX_V3FHMAX);
                temp[sizeof(temp) - 1] = '\0';
                /* Remove trailing spaces */
-               sfsname = strchr(temp, ' ');
-               if (sfsname)
-                       *sfsname = 0;
+               spacep = strchr(temp, ' ');
+               if (spacep)
+                       *spacep = '\0';
 
                (void)printf(" fh %s/", temp);
        } else {
@@ -734,7 +778,7 @@ nfs_printfh(register const u_int32_t *dp, const u_int len)
        }
 
        if(fsid.Fsid_dev.Minor == 257 && uflag)
-               /* Print the undecoded handle */ 
+               /* Print the undecoded handle */
                (void)printf("%s", fsid.Opaque_Handle);
        else
                (void)printf("%ld", (long) ino);
@@ -782,7 +826,7 @@ xid_map_enter(const struct rpc_msg *rp, const u_char *bp)
 #endif
        struct xid_map_entry *xmep;
 
-       switch (((struct ip *)bp)->ip_v) {
+       switch (IP_V((struct ip *)bp)) {
        case 4:
                ip = (struct ip *)bp;
                break;
@@ -828,18 +872,18 @@ xid_map_find(const struct rpc_msg *rp, const u_char *bp, u_int32_t *proc,
        int i;
        struct xid_map_entry *xmep;
        u_int32_t xid = rp->rm_xid;
-       struct ip *ip = (struct ip *)ip;
+       struct ip *ip = (struct ip *)bp;
 #ifdef INET6
        struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
 #endif
        int cmp;
 
        /* Start searching from where we last left off */
-       i = xid_map_hint; 
+       i = xid_map_hint;
        do {
                xmep = &xid_map[i];
                cmp = 1;
-               if (xmep->ipver != ip->ip_v || xmep->xid != xid)
+               if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
                        goto nextitem;
                switch (xmep->ipver) {
                case 4:
@@ -979,9 +1023,9 @@ parsestatus(const u_int32_t *dp, int *er)
                *er = errnum;
        if (errnum != 0) {
                if (!qflag)
-                       printf(" ERROR: %s", pcap_strerror(errnum));
+                       printf(" ERROR: %s",
+                           tok2str(status2str, "unk %d", errnum));
                nfserr = 1;
-               return (NULL);
        }
        return (dp + 1);
 trunc:
@@ -1063,8 +1107,10 @@ parseattrstat(const u_int32_t *dp, int verbose, int v3)
        int er;
 
        dp = parsestatus(dp, &er);
-       if (dp == NULL || er)
+       if (dp == NULL)
                return (0);
+       if (er)
+               return (1);
 
        return (parsefattr(dp, verbose, v3) != NULL);
 }
@@ -1074,8 +1120,10 @@ parsediropres(const u_int32_t *dp)
 {
        int er;
 
-       if (!(dp = parsestatus(dp, &er)) || er)
+       if (!(dp = parsestatus(dp, &er)))
                return (0);
+       if (er)
+               return (1);
 
        dp = parsefh(dp, 0);
        if (dp == NULL)
@@ -1090,8 +1138,10 @@ parselinkres(const u_int32_t *dp, int v3)
        int er;
 
        dp = parsestatus(dp, &er);
-       if (dp == NULL || er)
+       if (dp == NULL)
                return(0);
+       if (er)
+               return(1);
        if (v3 && !(dp = parse_post_op_attr(dp, vflag)))
                return (0);
        putchar(' ');
@@ -1105,8 +1155,10 @@ parsestatfs(const u_int32_t *dp, int v3)
        int er;
 
        dp = parsestatus(dp, &er);
-       if (dp == NULL || (!v3 && er))
+       if (dp == NULL)
                return (0);
+       if (!v3 && er)
+               return (1);
 
        if (qflag)
                return(1);
@@ -1118,7 +1170,7 @@ parsestatfs(const u_int32_t *dp, int v3)
                        return (0);
        }
 
-       TCHECK2(dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
+       TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
 
        sfsp = (const struct nfs_statfs *)dp;
 
@@ -1159,8 +1211,10 @@ parserddires(const u_int32_t *dp)
        int er;
 
        dp = parsestatus(dp, &er);
-       if (dp == 0 || er)
+       if (dp == NULL)
                return (0);
+       if (er)
+               return (1);
        if (qflag)
                return (1);
 
@@ -1196,7 +1250,7 @@ parse_pre_op_attr(const u_int32_t *dp, int verbose)
        if (!ntohl(dp[0]))
                return (dp + 1);
        dp++;
-       TCHECK2(dp, 24);
+       TCHECK2(*dp, 24);
        if (verbose > 1) {
                return parse_wcc_attr(dp);
        } else {
@@ -1333,9 +1387,9 @@ parsefsinfo(const u_int32_t *dp)
                       (u_int32_t) ntohl(sfp->fs_timedelta.nfsv3_sec),
                       (u_int32_t) ntohl(sfp->fs_timedelta.nfsv3_nsec));
        }
-       return (0);
-trunc:
        return (1);
+trunc:
+       return (0);
 }
 
 static int
@@ -1363,9 +1417,9 @@ parsepathconf(const u_int32_t *dp)
               ntohl(spp->pc_chownrestricted) ? "chownres" : "",
               ntohl(spp->pc_caseinsensitive) ? "igncase" : "",
               ntohl(spp->pc_casepreserving) ? "keepcase" : "");
-       return (0);
-trunc:
        return (1);
+trunc:
+       return (0);
 }
 
 static void
@@ -1441,7 +1495,8 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int lengt
 
        case NFSPROC_ACCESS:
                printf(" access");
-               dp = parserep(rp, length);
+               if (!(dp = parserep(rp, length)))
+                       break;
                if (!(dp = parsestatus(dp, &er)))
                        break;
                if (vflag)