2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid[] _U_ =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.99.2.2 2003/11/16 08:51:35 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
51 static void nfs_printfh(const u_int32_t *, const u_int);
52 static void xid_map_enter(const struct rpc_msg *, const u_char *);
53 static int32_t xid_map_find(const struct rpc_msg *, const u_char *,
54 u_int32_t *, u_int32_t *);
55 static void interp_reply(const struct rpc_msg *, u_int32_t, u_int32_t, int);
56 static const u_int32_t *parse_post_op_attr(const u_int32_t *, int);
57 static void print_sattr3(const struct nfsv3_sattr *sa3, int verbose);
58 static int print_int64(const u_int32_t *dp, int how);
59 static void print_nfsaddr(const u_char *, const char *, const char *);
62 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
64 u_int32_t nfsv3_procid[NFS_NPROCS] = {
94 * NFS V2 and V3 status values.
96 * Some of these come from the RFCs for NFS V2 and V3, with the message
97 * strings taken from the FreeBSD C library "errlst.c".
99 * Others are errors that are not in the RFC but that I suspect some
100 * NFS servers could return; the values are FreeBSD errno values, as
101 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
102 * was primarily BSD-derived.
104 static struct tok status2str[] = {
105 { 1, "Operation not permitted" }, /* EPERM */
106 { 2, "No such file or directory" }, /* ENOENT */
107 { 5, "Input/output error" }, /* EIO */
108 { 6, "Device not configured" }, /* ENXIO */
109 { 11, "Resource deadlock avoided" }, /* EDEADLK */
110 { 12, "Cannot allocate memory" }, /* ENOMEM */
111 { 13, "Permission denied" }, /* EACCES */
112 { 17, "File exists" }, /* EEXIST */
113 { 18, "Cross-device link" }, /* EXDEV */
114 { 19, "Operation not supported by device" }, /* ENODEV */
115 { 20, "Not a directory" }, /* ENOTDIR */
116 { 21, "Is a directory" }, /* EISDIR */
117 { 22, "Invalid argument" }, /* EINVAL */
118 { 26, "Text file busy" }, /* ETXTBSY */
119 { 27, "File too large" }, /* EFBIG */
120 { 28, "No space left on device" }, /* ENOSPC */
121 { 30, "Read-only file system" }, /* EROFS */
122 { 31, "Too many links" }, /* EMLINK */
123 { 45, "Operation not supported" }, /* EOPNOTSUPP */
124 { 62, "Too many levels of symbolic links" }, /* ELOOP */
125 { 63, "File name too long" }, /* ENAMETOOLONG */
126 { 66, "Directory not empty" }, /* ENOTEMPTY */
127 { 69, "Disc quota exceeded" }, /* EDQUOT */
128 { 70, "Stale NFS file handle" }, /* ESTALE */
129 { 71, "Too many levels of remote in path" }, /* EREMOTE */
130 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
131 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
132 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
133 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
134 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
135 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
136 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
137 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
138 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
142 static struct tok nfsv3_writemodes[] = {
149 static struct tok type2str[] = {
161 * Print out a 64-bit integer. This appears to be different on each system,
162 * try to make the best of it. The integer stored as 2 consecutive XDR
163 * encoded 32-bit integers, to which a pointer is passed.
165 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
166 * integer datatype and can print it.
173 static int print_int64(const u_int32_t *dp, int how)
178 res = ((u_int64_t)EXTRACT_32BITS(&dp[0]) << 32) | (u_int64_t)EXTRACT_32BITS(&dp[1]);
181 printf(INT64_FORMAT, res);
184 printf(U_INT64_FORMAT, res);
187 printf(HEX_INT64_FORMAT, res);
195 high = EXTRACT_32BITS(&dp[0]);
202 printf("0x%x%08x", high, EXTRACT_32BITS(&dp[1]));
204 printf("0x%x", EXTRACT_32BITS(&dp[1]));
214 print_nfsaddr(const u_char *bp, const char *s, const char *d)
219 char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
221 #ifndef INET_ADDRSTRLEN
222 #define INET_ADDRSTRLEN 16
224 char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN];
227 srcaddr[0] = dstaddr[0] = '\0';
228 switch (IP_V((struct ip *)bp)) {
230 ip = (struct ip *)bp;
231 strlcpy(srcaddr, ipaddr_string(&ip->ip_src), sizeof(srcaddr));
232 strlcpy(dstaddr, ipaddr_string(&ip->ip_dst), sizeof(dstaddr));
236 ip6 = (struct ip6_hdr *)bp;
237 strlcpy(srcaddr, ip6addr_string(&ip6->ip6_src),
239 strlcpy(dstaddr, ip6addr_string(&ip6->ip6_dst),
244 strlcpy(srcaddr, "?", sizeof(srcaddr));
245 strlcpy(dstaddr, "?", sizeof(dstaddr));
249 (void)printf("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d);
252 static const u_int32_t *
253 parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3)
256 sa3->sa_modeset = EXTRACT_32BITS(dp);
258 if (sa3->sa_modeset) {
260 sa3->sa_mode = EXTRACT_32BITS(dp);
265 sa3->sa_uidset = EXTRACT_32BITS(dp);
267 if (sa3->sa_uidset) {
269 sa3->sa_uid = EXTRACT_32BITS(dp);
274 sa3->sa_gidset = EXTRACT_32BITS(dp);
276 if (sa3->sa_gidset) {
278 sa3->sa_gid = EXTRACT_32BITS(dp);
283 sa3->sa_sizeset = EXTRACT_32BITS(dp);
285 if (sa3->sa_sizeset) {
287 sa3->sa_size = EXTRACT_32BITS(dp);
292 sa3->sa_atimetype = EXTRACT_32BITS(dp);
294 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) {
296 sa3->sa_atime.nfsv3_sec = EXTRACT_32BITS(dp);
298 sa3->sa_atime.nfsv3_nsec = EXTRACT_32BITS(dp);
303 sa3->sa_mtimetype = EXTRACT_32BITS(dp);
305 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) {
307 sa3->sa_mtime.nfsv3_sec = EXTRACT_32BITS(dp);
309 sa3->sa_mtime.nfsv3_nsec = EXTRACT_32BITS(dp);
318 static int nfserr; /* true if we error rather than trunc */
321 print_sattr3(const struct nfsv3_sattr *sa3, int verbose)
324 printf(" mode %o", sa3->sa_mode);
326 printf(" uid %u", sa3->sa_uid);
328 printf(" gid %u", sa3->sa_gid);
330 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT)
331 printf(" atime %u.%06u", sa3->sa_atime.nfsv3_sec,
332 sa3->sa_atime.nfsv3_nsec);
333 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT)
334 printf(" mtime %u.%06u", sa3->sa_mtime.nfsv3_sec,
335 sa3->sa_mtime.nfsv3_nsec);
340 nfsreply_print(register const u_char *bp, u_int length,
341 register const u_char *bp2)
343 register const struct rpc_msg *rp;
344 u_int32_t proc, vers;
345 char srcid[20], dstid[20]; /*fits 32bit*/
347 nfserr = 0; /* assume no error */
348 rp = (const struct rpc_msg *)bp;
351 strlcpy(srcid, "nfs", sizeof(srcid));
352 snprintf(dstid, sizeof(dstid), "%u",
353 EXTRACT_32BITS(&rp->rm_xid));
355 snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
356 snprintf(dstid, sizeof(dstid), "%u",
357 EXTRACT_32BITS(&rp->rm_xid));
359 print_nfsaddr(bp2, srcid, dstid);
360 (void)printf("reply %s %d",
361 EXTRACT_32BITS(&rp->rm_reply.rp_stat) == MSG_ACCEPTED?
365 if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
366 interp_reply(rp, proc, vers, length);
370 * Return a pointer to the first file handle in the packet.
371 * If the packet was truncated, return 0.
373 static const u_int32_t *
374 parsereq(register const struct rpc_msg *rp, register u_int length)
376 register const u_int32_t *dp;
380 * find the start of the req data (if we captured it)
382 dp = (u_int32_t *)&rp->rm_call.cb_cred;
384 len = EXTRACT_32BITS(&dp[1]);
386 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
388 len = EXTRACT_32BITS(&dp[1]);
390 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
400 * Print out an NFS file handle and return a pointer to following word.
401 * If packet was truncated, return 0.
403 static const u_int32_t *
404 parsefh(register const u_int32_t *dp, int v3)
410 len = EXTRACT_32BITS(dp) / 4;
415 if (TTEST2(*dp, len * sizeof(*dp))) {
416 nfs_printfh(dp, len);
424 * Print out a file name and return pointer to 32-bit word past it.
425 * If packet was truncated, return 0.
427 static const u_int32_t *
428 parsefn(register const u_int32_t *dp)
430 register u_int32_t len;
431 register const u_char *cp;
433 /* Bail if we don't have the string length */
436 /* Fetch string length; convert to host order */
440 TCHECK2(*dp, ((len + 3) & ~3));
443 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
444 dp += ((len + 3) & ~3) / sizeof(*dp);
445 /* XXX seems like we should be checking the length */
447 (void) fn_printn(cp, len, NULL);
456 * Print out file handle and file name.
457 * Return pointer to 32-bit word past file name.
458 * If packet was truncated (or there was some other error), return 0.
460 static const u_int32_t *
461 parsefhn(register const u_int32_t *dp, int v3)
463 dp = parsefh(dp, v3);
467 return (parsefn(dp));
471 nfsreq_print(register const u_char *bp, u_int length,
472 register const u_char *bp2)
474 register const struct rpc_msg *rp;
475 register const u_int32_t *dp;
479 struct nfsv3_sattr sa3;
480 char srcid[20], dstid[20]; /*fits 32bit*/
482 nfserr = 0; /* assume no error */
483 rp = (const struct rpc_msg *)bp;
485 snprintf(srcid, sizeof(srcid), "%u",
486 EXTRACT_32BITS(&rp->rm_xid));
487 strlcpy(dstid, "nfs", sizeof(dstid));
489 snprintf(srcid, sizeof(srcid), "%u",
490 EXTRACT_32BITS(&rp->rm_xid));
491 snprintf(dstid, sizeof(dstid), "%u", NFS_PORT);
493 print_nfsaddr(bp2, srcid, dstid);
494 (void)printf("%d", length);
496 xid_map_enter(rp, bp2); /* record proc number for later on */
498 v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3);
499 proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
501 if (!v3 && proc < NFS_NPROCS)
502 proc = nfsv3_procid[proc];
512 case NFSPROC_GETATTR:
514 if ((dp = parsereq(rp, length)) != NULL &&
515 parsefh(dp, v3) != NULL)
519 case NFSPROC_SETATTR:
521 if ((dp = parsereq(rp, length)) != NULL &&
522 parsefh(dp, v3) != NULL)
528 if ((dp = parsereq(rp, length)) != NULL &&
529 parsefhn(dp, v3) != NULL)
535 if ((dp = parsereq(rp, length)) != NULL &&
536 (dp = parsefh(dp, v3)) != NULL) {
538 printf(" %04x", EXTRACT_32BITS(&dp[0]));
543 case NFSPROC_READLINK:
545 if ((dp = parsereq(rp, length)) != NULL &&
546 parsefh(dp, v3) != NULL)
552 if ((dp = parsereq(rp, length)) != NULL &&
553 (dp = parsefh(dp, v3)) != NULL) {
556 printf(" %u bytes @ ",
557 EXTRACT_32BITS(&dp[2]));
558 print_int64(dp, UNSIGNED);
561 printf(" %u bytes @ %u",
562 EXTRACT_32BITS(&dp[1]),
563 EXTRACT_32BITS(&dp[0]));
571 if ((dp = parsereq(rp, length)) != NULL &&
572 (dp = parsefh(dp, v3)) != NULL) {
575 printf(" %u bytes @ ",
576 EXTRACT_32BITS(&dp[4]));
577 print_int64(dp, UNSIGNED);
582 tok2str(nfsv3_writemodes,
583 NULL, EXTRACT_32BITS(dp)));
587 printf(" %u (%u) bytes @ %u (%u)",
588 EXTRACT_32BITS(&dp[3]),
589 EXTRACT_32BITS(&dp[2]),
590 EXTRACT_32BITS(&dp[1]),
591 EXTRACT_32BITS(&dp[0]));
599 if ((dp = parsereq(rp, length)) != NULL &&
600 parsefhn(dp, v3) != NULL)
606 if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0)
610 case NFSPROC_SYMLINK:
612 if ((dp = parsereq(rp, length)) != 0 &&
613 (dp = parsefhn(dp, v3)) != 0) {
614 fputs(" ->", stdout);
615 if (v3 && (dp = parse_sattr3(dp, &sa3)) == 0)
617 if (parsefn(dp) == 0)
620 print_sattr3(&sa3, vflag);
627 if ((dp = parsereq(rp, length)) != 0 &&
628 (dp = parsefhn(dp, v3)) != 0) {
630 type = (nfs_type)EXTRACT_32BITS(dp);
632 if ((dp = parse_sattr3(dp, &sa3)) == 0)
634 printf(" %s", tok2str(type2str, "unk-ft %d", type));
635 if (vflag && (type == NFCHR || type == NFBLK)) {
638 EXTRACT_32BITS(&dp[0]),
639 EXTRACT_32BITS(&dp[1]));
643 print_sattr3(&sa3, vflag);
650 if ((dp = parsereq(rp, length)) != NULL &&
651 parsefhn(dp, v3) != NULL)
657 if ((dp = parsereq(rp, length)) != NULL &&
658 parsefhn(dp, v3) != NULL)
664 if ((dp = parsereq(rp, length)) != NULL &&
665 (dp = parsefhn(dp, v3)) != NULL) {
666 fputs(" ->", stdout);
667 if (parsefhn(dp, v3) != NULL)
674 if ((dp = parsereq(rp, length)) != NULL &&
675 (dp = parsefh(dp, v3)) != NULL) {
676 fputs(" ->", stdout);
677 if (parsefhn(dp, v3) != NULL)
682 case NFSPROC_READDIR:
684 if ((dp = parsereq(rp, length)) != NULL &&
685 (dp = parsefh(dp, v3)) != NULL) {
689 * We shouldn't really try to interpret the
690 * offset cookie here.
692 printf(" %u bytes @ ",
693 EXTRACT_32BITS(&dp[4]));
694 print_int64(dp, SIGNED);
696 printf(" verf %08x%08x", dp[2],
701 * Print the offset as signed, since -1 is
702 * common, but offsets > 2^31 aren't.
704 printf(" %u bytes @ %d",
705 EXTRACT_32BITS(&dp[1]),
706 EXTRACT_32BITS(&dp[0]));
712 case NFSPROC_READDIRPLUS:
713 printf(" readdirplus");
714 if ((dp = parsereq(rp, length)) != NULL &&
715 (dp = parsefh(dp, v3)) != NULL) {
718 * We don't try to interpret the offset
721 printf(" %u bytes @ ", EXTRACT_32BITS(&dp[4]));
722 print_int64(dp, SIGNED);
724 printf(" max %u verf %08x%08x",
725 EXTRACT_32BITS(&dp[5]), dp[2], dp[3]);
732 if ((dp = parsereq(rp, length)) != NULL &&
733 parsefh(dp, v3) != NULL)
739 if ((dp = parsereq(rp, length)) != NULL &&
740 parsefh(dp, v3) != NULL)
744 case NFSPROC_PATHCONF:
746 if ((dp = parsereq(rp, length)) != NULL &&
747 parsefh(dp, v3) != NULL)
753 if ((dp = parsereq(rp, length)) != NULL &&
754 (dp = parsefh(dp, v3)) != NULL) {
755 printf(" %u bytes @ ", EXTRACT_32BITS(&dp[2]));
756 print_int64(dp, UNSIGNED);
762 printf(" proc-%u", EXTRACT_32BITS(&rp->rm_call.cb_proc));
768 fputs(" [|nfs]", stdout);
772 * Print out an NFS file handle.
773 * We assume packet was not truncated before the end of the
774 * file handle pointed to by dp.
776 * Note: new version (using portable file-handle parser) doesn't produce
777 * generation number. It probably could be made to do that, with some
778 * additional hacking on the parser code.
781 nfs_printfh(register const u_int32_t *dp, const u_int len)
785 const char *sfsname = NULL;
790 char const *sep = "";
793 for (i=0; i<len; i++) {
794 (void)printf("%s%x", sep, dp[i]);
801 Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
804 /* file system ID is ASCII, not numeric, for this server OS */
805 static char temp[NFSX_V3FHMAX+1];
807 /* Make sure string is null-terminated */
808 strncpy(temp, sfsname, NFSX_V3FHMAX);
809 temp[sizeof(temp) - 1] = '\0';
810 /* Remove trailing spaces */
811 spacep = strchr(temp, ' ');
815 (void)printf(" fh %s/", temp);
817 (void)printf(" fh %d,%d/",
818 fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
821 if(fsid.Fsid_dev.Minor == 257)
822 /* Print the undecoded handle */
823 (void)printf("%s", fsid.Opaque_Handle);
825 (void)printf("%ld", (long) ino);
829 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
830 * us to match up replies with requests and thus to know how to parse
834 struct xid_map_entry {
835 u_int32_t xid; /* transaction ID (net order) */
836 int ipver; /* IP version (4 or 6) */
838 struct in6_addr client; /* client IP address (net order) */
839 struct in6_addr server; /* server IP address (net order) */
841 struct in_addr client; /* client IP address (net order) */
842 struct in_addr server; /* server IP address (net order) */
844 u_int32_t proc; /* call proc number (host order) */
845 u_int32_t vers; /* program version (host order) */
849 * Map entries are kept in an array that we manage as a ring;
850 * new entries are always added at the tail of the ring. Initially,
851 * all the entries are zero and hence don't match anything.
854 #define XIDMAPSIZE 64
856 struct xid_map_entry xid_map[XIDMAPSIZE];
858 int xid_map_next = 0;
859 int xid_map_hint = 0;
862 xid_map_enter(const struct rpc_msg *rp, const u_char *bp)
864 struct ip *ip = NULL;
866 struct ip6_hdr *ip6 = NULL;
868 struct xid_map_entry *xmep;
870 switch (IP_V((struct ip *)bp)) {
872 ip = (struct ip *)bp;
876 ip6 = (struct ip6_hdr *)bp;
883 xmep = &xid_map[xid_map_next];
885 if (++xid_map_next >= XIDMAPSIZE)
888 xmep->xid = rp->rm_xid;
891 memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
892 memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
897 memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
898 memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
901 xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
902 xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
906 * Returns 0 and puts NFSPROC_xxx in proc return and
907 * version in vers return, or returns -1 on failure
910 xid_map_find(const struct rpc_msg *rp, const u_char *bp, u_int32_t *proc,
914 struct xid_map_entry *xmep;
915 u_int32_t xid = rp->rm_xid;
916 struct ip *ip = (struct ip *)bp;
918 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
922 /* Start searching from where we last left off */
927 if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
929 switch (xmep->ipver) {
931 if (memcmp(&ip->ip_src, &xmep->server,
932 sizeof(ip->ip_src)) != 0 ||
933 memcmp(&ip->ip_dst, &xmep->client,
934 sizeof(ip->ip_dst)) != 0) {
940 if (memcmp(&ip6->ip6_src, &xmep->server,
941 sizeof(ip6->ip6_src)) != 0 ||
942 memcmp(&ip6->ip6_dst, &xmep->client,
943 sizeof(ip6->ip6_dst)) != 0) {
960 if (++i >= XIDMAPSIZE)
962 } while (i != xid_map_hint);
969 * Routines for parsing reply packets
973 * Return a pointer to the beginning of the actual results.
974 * If the packet was truncated, return 0.
976 static const u_int32_t *
977 parserep(register const struct rpc_msg *rp, register u_int length)
979 register const u_int32_t *dp;
981 enum accept_stat astat;
985 * Here we find the address of the ar_verf credentials.
986 * Originally, this calculation was
987 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
988 * On the wire, the rp_acpt field starts immediately after
989 * the (32 bit) rp_stat field. However, rp_acpt (which is a
990 * "struct accepted_reply") contains a "struct opaque_auth",
991 * whose internal representation contains a pointer, so on a
992 * 64-bit machine the compiler inserts 32 bits of padding
993 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
994 * the internal representation to parse the on-the-wire
995 * representation. Instead, we skip past the rp_stat field,
996 * which is an "enum" and so occupies one 32-bit word.
998 dp = ((const u_int32_t *)&rp->rm_reply) + 1;
1000 len = EXTRACT_32BITS(&dp[1]);
1004 * skip past the ar_verf credentials.
1006 dp += (len + (2*sizeof(u_int32_t) + 3)) / sizeof(u_int32_t);
1010 * now we can check the ar_stat field
1012 astat = EXTRACT_32BITS(dp);
1019 printf(" PROG_UNAVAIL");
1020 nfserr = 1; /* suppress trunc string */
1024 printf(" PROG_MISMATCH");
1025 nfserr = 1; /* suppress trunc string */
1029 printf(" PROC_UNAVAIL");
1030 nfserr = 1; /* suppress trunc string */
1034 printf(" GARBAGE_ARGS");
1035 nfserr = 1; /* suppress trunc string */
1039 printf(" SYSTEM_ERR");
1040 nfserr = 1; /* suppress trunc string */
1044 printf(" ar_stat %d", astat);
1045 nfserr = 1; /* suppress trunc string */
1048 /* successful return */
1049 TCHECK2(*dp, sizeof(astat));
1050 return ((u_int32_t *) (sizeof(astat) + ((char *)dp)));
1055 static const u_int32_t *
1056 parsestatus(const u_int32_t *dp, int *er)
1062 errnum = EXTRACT_32BITS(&dp[0]);
1067 printf(" ERROR: %s",
1068 tok2str(status2str, "unk %d", errnum));
1076 static const u_int32_t *
1077 parsefattr(const u_int32_t *dp, int verbose, int v3)
1079 const struct nfs_fattr *fap;
1081 fap = (const struct nfs_fattr *)dp;
1082 TCHECK(fap->fa_gid);
1084 printf(" %s %o ids %d/%d",
1085 tok2str(type2str, "unk-ft %d ",
1086 EXTRACT_32BITS(&fap->fa_type)),
1087 EXTRACT_32BITS(&fap->fa_mode),
1088 EXTRACT_32BITS(&fap->fa_uid),
1089 EXTRACT_32BITS(&fap->fa_gid));
1091 TCHECK(fap->fa3_size);
1093 print_int64((u_int32_t *)&fap->fa3_size, UNSIGNED);
1095 TCHECK(fap->fa2_size);
1096 printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size));
1099 /* print lots more stuff */
1102 TCHECK(fap->fa3_ctime);
1103 printf(" nlink %d rdev %d/%d",
1104 EXTRACT_32BITS(&fap->fa_nlink),
1105 EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
1106 EXTRACT_32BITS(&fap->fa3_rdev.specdata2));
1108 print_int64((u_int32_t *)&fap->fa3_fsid, HEX);
1110 print_int64((u_int32_t *)&fap->fa3_fileid, HEX);
1111 printf(" a/m/ctime %u.%06u",
1112 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec),
1113 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec));
1115 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec),
1116 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec));
1118 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec),
1119 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec));
1121 TCHECK(fap->fa2_ctime);
1122 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1123 EXTRACT_32BITS(&fap->fa_nlink),
1124 EXTRACT_32BITS(&fap->fa2_rdev),
1125 EXTRACT_32BITS(&fap->fa2_fsid),
1126 EXTRACT_32BITS(&fap->fa2_fileid));
1128 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec),
1129 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec));
1131 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec),
1132 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec));
1134 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec),
1135 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec));
1138 return ((const u_int32_t *)((unsigned char *)dp +
1139 (v3 ? NFSX_V3FATTR : NFSX_V2FATTR)));
1145 parseattrstat(const u_int32_t *dp, int verbose, int v3)
1149 dp = parsestatus(dp, &er);
1155 return (parsefattr(dp, verbose, v3) != NULL);
1159 parsediropres(const u_int32_t *dp)
1163 if (!(dp = parsestatus(dp, &er)))
1168 dp = parsefh(dp, 0);
1172 return (parsefattr(dp, vflag, 0) != NULL);
1176 parselinkres(const u_int32_t *dp, int v3)
1180 dp = parsestatus(dp, &er);
1185 if (v3 && !(dp = parse_post_op_attr(dp, vflag)))
1188 return (parsefn(dp) != NULL);
1192 parsestatfs(const u_int32_t *dp, int v3)
1194 const struct nfs_statfs *sfsp;
1197 dp = parsestatus(dp, &er);
1209 if (!(dp = parse_post_op_attr(dp, vflag)))
1213 TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
1215 sfsp = (const struct nfs_statfs *)dp;
1219 print_int64((u_int32_t *)&sfsp->sf_tbytes, UNSIGNED);
1221 print_int64((u_int32_t *)&sfsp->sf_fbytes, UNSIGNED);
1223 print_int64((u_int32_t *)&sfsp->sf_abytes, UNSIGNED);
1226 print_int64((u_int32_t *)&sfsp->sf_tfiles, UNSIGNED);
1228 print_int64((u_int32_t *)&sfsp->sf_ffiles, UNSIGNED);
1230 print_int64((u_int32_t *)&sfsp->sf_afiles, UNSIGNED);
1232 EXTRACT_32BITS(&sfsp->sf_invarsec));
1235 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1236 EXTRACT_32BITS(&sfsp->sf_tsize),
1237 EXTRACT_32BITS(&sfsp->sf_bsize),
1238 EXTRACT_32BITS(&sfsp->sf_blocks),
1239 EXTRACT_32BITS(&sfsp->sf_bfree),
1240 EXTRACT_32BITS(&sfsp->sf_bavail));
1249 parserddires(const u_int32_t *dp)
1253 dp = parsestatus(dp, &er);
1262 printf(" offset %x size %d ",
1263 EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1]));
1272 static const u_int32_t *
1273 parse_wcc_attr(const u_int32_t *dp)
1276 print_int64(dp, UNSIGNED);
1277 printf(" mtime %u.%06u ctime %u.%06u",
1278 EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
1279 EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5]));
1284 * Pre operation attributes. Print only if vflag > 1.
1286 static const u_int32_t *
1287 parse_pre_op_attr(const u_int32_t *dp, int verbose)
1290 if (!EXTRACT_32BITS(&dp[0]))
1295 return parse_wcc_attr(dp);
1297 /* If not verbose enough, just skip over wcc_attr */
1305 * Post operation attributes are printed if vflag >= 1
1307 static const u_int32_t *
1308 parse_post_op_attr(const u_int32_t *dp, int verbose)
1311 if (!EXTRACT_32BITS(&dp[0]))
1315 return parsefattr(dp, verbose, 1);
1317 return (dp + (NFSX_V3FATTR / sizeof (u_int32_t)));
1322 static const u_int32_t *
1323 parse_wcc_data(const u_int32_t *dp, int verbose)
1327 if (!(dp = parse_pre_op_attr(dp, verbose)))
1332 return parse_post_op_attr(dp, verbose);
1335 static const u_int32_t *
1336 parsecreateopres(const u_int32_t *dp, int verbose)
1340 if (!(dp = parsestatus(dp, &er)))
1343 dp = parse_wcc_data(dp, verbose);
1346 if (!EXTRACT_32BITS(&dp[0]))
1349 if (!(dp = parsefh(dp, 1)))
1352 if (!(dp = parse_post_op_attr(dp, verbose)))
1355 printf(" dir attr:");
1356 dp = parse_wcc_data(dp, verbose);
1366 parsewccres(const u_int32_t *dp, int verbose)
1370 if (!(dp = parsestatus(dp, &er)))
1372 return parse_wcc_data(dp, verbose) != 0;
1375 static const u_int32_t *
1376 parsev3rddirres(const u_int32_t *dp, int verbose)
1380 if (!(dp = parsestatus(dp, &er)))
1384 if (!(dp = parse_post_op_attr(dp, verbose)))
1390 printf(" verf %08x%08x", dp[0], dp[1]);
1399 parsefsinfo(const u_int32_t *dp)
1401 struct nfsv3_fsinfo *sfp;
1404 if (!(dp = parsestatus(dp, &er)))
1408 if (!(dp = parse_post_op_attr(dp, vflag)))
1413 sfp = (struct nfsv3_fsinfo *)dp;
1415 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1416 EXTRACT_32BITS(&sfp->fs_rtmax),
1417 EXTRACT_32BITS(&sfp->fs_rtpref),
1418 EXTRACT_32BITS(&sfp->fs_wtmax),
1419 EXTRACT_32BITS(&sfp->fs_wtpref),
1420 EXTRACT_32BITS(&sfp->fs_dtpref));
1422 printf(" rtmult %u wtmult %u maxfsz ",
1423 EXTRACT_32BITS(&sfp->fs_rtmult),
1424 EXTRACT_32BITS(&sfp->fs_wtmult));
1425 print_int64((u_int32_t *)&sfp->fs_maxfilesize, UNSIGNED);
1426 printf(" delta %u.%06u ",
1427 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
1428 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec));
1436 parsepathconf(const u_int32_t *dp)
1439 struct nfsv3_pathconf *spp;
1441 if (!(dp = parsestatus(dp, &er)))
1445 if (!(dp = parse_post_op_attr(dp, vflag)))
1450 spp = (struct nfsv3_pathconf *)dp;
1453 printf(" linkmax %u namemax %u %s %s %s %s",
1454 EXTRACT_32BITS(&spp->pc_linkmax),
1455 EXTRACT_32BITS(&spp->pc_namemax),
1456 EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
1457 EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
1458 EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
1459 EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : "");
1466 interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
1468 register const u_int32_t *dp;
1472 v3 = (vers == NFS_VER3);
1474 if (!v3 && proc < NFS_NPROCS)
1475 proc = nfsv3_procid[proc];
1487 case NFSPROC_GETATTR:
1489 dp = parserep(rp, length);
1490 if (dp != NULL && parseattrstat(dp, !qflag, v3) != 0)
1494 case NFSPROC_SETATTR:
1496 if (!(dp = parserep(rp, length)))
1499 if (parsewccres(dp, vflag))
1502 if (parseattrstat(dp, !qflag, 0) != 0)
1507 case NFSPROC_LOOKUP:
1509 if (!(dp = parserep(rp, length)))
1512 if (!(dp = parsestatus(dp, &er)))
1516 printf(" post dattr:");
1517 dp = parse_post_op_attr(dp, vflag);
1520 if (!(dp = parsefh(dp, v3)))
1522 if ((dp = parse_post_op_attr(dp, vflag)) &&
1524 printf(" post dattr:");
1525 dp = parse_post_op_attr(dp, vflag);
1531 if (parsediropres(dp) != 0)
1536 case NFSPROC_ACCESS:
1538 if (!(dp = parserep(rp, length)))
1540 if (!(dp = parsestatus(dp, &er)))
1544 if (!(dp = parse_post_op_attr(dp, vflag)))
1547 printf(" c %04x", EXTRACT_32BITS(&dp[0]));
1550 case NFSPROC_READLINK:
1551 printf(" readlink");
1552 dp = parserep(rp, length);
1553 if (dp != NULL && parselinkres(dp, v3) != 0)
1559 if (!(dp = parserep(rp, length)))
1562 if (!(dp = parsestatus(dp, &er)))
1564 if (!(dp = parse_post_op_attr(dp, vflag)))
1570 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1571 if (EXTRACT_32BITS(&dp[1]))
1576 if (parseattrstat(dp, vflag, 0) != 0)
1583 if (!(dp = parserep(rp, length)))
1586 if (!(dp = parsestatus(dp, &er)))
1588 if (!(dp = parse_wcc_data(dp, vflag)))
1594 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1598 tok2str(nfsv3_writemodes,
1599 NULL, EXTRACT_32BITS(&dp[1])));
1604 if (parseattrstat(dp, vflag, v3) != 0)
1609 case NFSPROC_CREATE:
1611 if (!(dp = parserep(rp, length)))
1614 if (parsecreateopres(dp, vflag) != 0)
1617 if (parsediropres(dp) != 0)
1624 if (!(dp = parserep(rp, length)))
1627 if (parsecreateopres(dp, vflag) != 0)
1630 if (parsediropres(dp) != 0)
1635 case NFSPROC_SYMLINK:
1637 if (!(dp = parserep(rp, length)))
1640 if (parsecreateopres(dp, vflag) != 0)
1643 if (parsestatus(dp, &er) != 0)
1650 if (!(dp = parserep(rp, length)))
1652 if (parsecreateopres(dp, vflag) != 0)
1656 case NFSPROC_REMOVE:
1658 if (!(dp = parserep(rp, length)))
1661 if (parsewccres(dp, vflag))
1664 if (parsestatus(dp, &er) != 0)
1671 if (!(dp = parserep(rp, length)))
1674 if (parsewccres(dp, vflag))
1677 if (parsestatus(dp, &er) != 0)
1682 case NFSPROC_RENAME:
1684 if (!(dp = parserep(rp, length)))
1687 if (!(dp = parsestatus(dp, &er)))
1691 if (!(dp = parse_wcc_data(dp, vflag)))
1694 if (!(dp = parse_wcc_data(dp, vflag)))
1699 if (parsestatus(dp, &er) != 0)
1706 if (!(dp = parserep(rp, length)))
1709 if (!(dp = parsestatus(dp, &er)))
1712 printf(" file POST:");
1713 if (!(dp = parse_post_op_attr(dp, vflag)))
1716 if (!(dp = parse_wcc_data(dp, vflag)))
1721 if (parsestatus(dp, &er) != 0)
1726 case NFSPROC_READDIR:
1728 if (!(dp = parserep(rp, length)))
1731 if (parsev3rddirres(dp, vflag))
1734 if (parserddires(dp) != 0)
1739 case NFSPROC_READDIRPLUS:
1740 printf(" readdirplus");
1741 if (!(dp = parserep(rp, length)))
1743 if (parsev3rddirres(dp, vflag))
1747 case NFSPROC_FSSTAT:
1749 dp = parserep(rp, length);
1750 if (dp != NULL && parsestatfs(dp, v3) != 0)
1754 case NFSPROC_FSINFO:
1756 dp = parserep(rp, length);
1757 if (dp != NULL && parsefsinfo(dp) != 0)
1761 case NFSPROC_PATHCONF:
1762 printf(" pathconf");
1763 dp = parserep(rp, length);
1764 if (dp != NULL && parsepathconf(dp) != 0)
1768 case NFSPROC_COMMIT:
1770 dp = parserep(rp, length);
1771 if (dp != NULL && parsewccres(dp, vflag) != 0)
1776 printf(" proc-%u", proc);
1781 fputs(" [|nfs]", stdout);