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.
25 static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.99.2.2 2003/11/16 08:51:35 guy Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
53 static void nfs_printfh(const u_int32_t *, const u_int);
54 static void xid_map_enter(const struct rpc_msg *, const u_char *);
55 static int32_t xid_map_find(const struct rpc_msg *, const u_char *,
56 u_int32_t *, u_int32_t *);
57 static void interp_reply(const struct rpc_msg *, u_int32_t, u_int32_t, int);
58 static const u_int32_t *parse_post_op_attr(const u_int32_t *, int);
59 static void print_sattr3(const struct nfsv3_sattr *sa3, int verbose);
60 static int print_int64(const u_int32_t *dp, int how);
61 static void print_nfsaddr(const u_char *, const char *, const char *);
64 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
66 u_int32_t nfsv3_procid[NFS_NPROCS] = {
96 * NFS V2 and V3 status values.
98 * Some of these come from the RFCs for NFS V2 and V3, with the message
99 * strings taken from the FreeBSD C library "errlst.c".
101 * Others are errors that are not in the RFC but that I suspect some
102 * NFS servers could return; the values are FreeBSD errno values, as
103 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
104 * was primarily BSD-derived.
106 static struct tok status2str[] = {
107 { 1, "Operation not permitted" }, /* EPERM */
108 { 2, "No such file or directory" }, /* ENOENT */
109 { 5, "Input/output error" }, /* EIO */
110 { 6, "Device not configured" }, /* ENXIO */
111 { 11, "Resource deadlock avoided" }, /* EDEADLK */
112 { 12, "Cannot allocate memory" }, /* ENOMEM */
113 { 13, "Permission denied" }, /* EACCES */
114 { 17, "File exists" }, /* EEXIST */
115 { 18, "Cross-device link" }, /* EXDEV */
116 { 19, "Operation not supported by device" }, /* ENODEV */
117 { 20, "Not a directory" }, /* ENOTDIR */
118 { 21, "Is a directory" }, /* EISDIR */
119 { 22, "Invalid argument" }, /* EINVAL */
120 { 26, "Text file busy" }, /* ETXTBSY */
121 { 27, "File too large" }, /* EFBIG */
122 { 28, "No space left on device" }, /* ENOSPC */
123 { 30, "Read-only file system" }, /* EROFS */
124 { 31, "Too many links" }, /* EMLINK */
125 { 45, "Operation not supported" }, /* EOPNOTSUPP */
126 { 62, "Too many levels of symbolic links" }, /* ELOOP */
127 { 63, "File name too long" }, /* ENAMETOOLONG */
128 { 66, "Directory not empty" }, /* ENOTEMPTY */
129 { 69, "Disc quota exceeded" }, /* EDQUOT */
130 { 70, "Stale NFS file handle" }, /* ESTALE */
131 { 71, "Too many levels of remote in path" }, /* EREMOTE */
132 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
133 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
134 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
135 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
136 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
137 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
138 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
139 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
140 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
144 static struct tok nfsv3_writemodes[] = {
151 static struct tok type2str[] = {
163 * Print out a 64-bit integer. This appears to be different on each system,
164 * try to make the best of it. The integer stored as 2 consecutive XDR
165 * encoded 32-bit integers, to which a pointer is passed.
167 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
168 * integer datatype and can print it.
175 static int print_int64(const u_int32_t *dp, int how)
180 res = ((u_int64_t)EXTRACT_32BITS(&dp[0]) << 32) | (u_int64_t)EXTRACT_32BITS(&dp[1]);
183 printf(INT64_FORMAT, res);
186 printf(U_INT64_FORMAT, res);
189 printf(HEX_INT64_FORMAT, res);
197 high = EXTRACT_32BITS(&dp[0]);
204 printf("0x%x%08x", high, EXTRACT_32BITS(&dp[1]));
206 printf("0x%x", EXTRACT_32BITS(&dp[1]));
216 print_nfsaddr(const u_char *bp, const char *s, const char *d)
221 char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
223 #ifndef INET_ADDRSTRLEN
224 #define INET_ADDRSTRLEN 16
226 char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN];
229 srcaddr[0] = dstaddr[0] = '\0';
230 switch (IP_V((struct ip *)bp)) {
232 ip = (struct ip *)bp;
233 strlcpy(srcaddr, ipaddr_string(&ip->ip_src), sizeof(srcaddr));
234 strlcpy(dstaddr, ipaddr_string(&ip->ip_dst), sizeof(dstaddr));
238 ip6 = (struct ip6_hdr *)bp;
239 strlcpy(srcaddr, ip6addr_string(&ip6->ip6_src),
241 strlcpy(dstaddr, ip6addr_string(&ip6->ip6_dst),
246 strlcpy(srcaddr, "?", sizeof(srcaddr));
247 strlcpy(dstaddr, "?", sizeof(dstaddr));
251 (void)printf("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d);
254 static const u_int32_t *
255 parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3)
258 sa3->sa_modeset = EXTRACT_32BITS(dp);
260 if (sa3->sa_modeset) {
262 sa3->sa_mode = EXTRACT_32BITS(dp);
267 sa3->sa_uidset = EXTRACT_32BITS(dp);
269 if (sa3->sa_uidset) {
271 sa3->sa_uid = EXTRACT_32BITS(dp);
276 sa3->sa_gidset = EXTRACT_32BITS(dp);
278 if (sa3->sa_gidset) {
280 sa3->sa_gid = EXTRACT_32BITS(dp);
285 sa3->sa_sizeset = EXTRACT_32BITS(dp);
287 if (sa3->sa_sizeset) {
289 sa3->sa_size = EXTRACT_32BITS(dp);
294 sa3->sa_atimetype = EXTRACT_32BITS(dp);
296 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) {
298 sa3->sa_atime.nfsv3_sec = EXTRACT_32BITS(dp);
300 sa3->sa_atime.nfsv3_nsec = EXTRACT_32BITS(dp);
305 sa3->sa_mtimetype = EXTRACT_32BITS(dp);
307 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) {
309 sa3->sa_mtime.nfsv3_sec = EXTRACT_32BITS(dp);
311 sa3->sa_mtime.nfsv3_nsec = EXTRACT_32BITS(dp);
320 static int nfserr; /* true if we error rather than trunc */
323 print_sattr3(const struct nfsv3_sattr *sa3, int verbose)
326 printf(" mode %o", sa3->sa_mode);
328 printf(" uid %u", sa3->sa_uid);
330 printf(" gid %u", sa3->sa_gid);
332 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT)
333 printf(" atime %u.%06u", sa3->sa_atime.nfsv3_sec,
334 sa3->sa_atime.nfsv3_nsec);
335 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT)
336 printf(" mtime %u.%06u", sa3->sa_mtime.nfsv3_sec,
337 sa3->sa_mtime.nfsv3_nsec);
342 nfsreply_print(register const u_char *bp, u_int length,
343 register const u_char *bp2)
345 register const struct rpc_msg *rp;
346 u_int32_t proc, vers;
347 char srcid[20], dstid[20]; /*fits 32bit*/
349 nfserr = 0; /* assume no error */
350 rp = (const struct rpc_msg *)bp;
353 strlcpy(srcid, "nfs", sizeof(srcid));
354 snprintf(dstid, sizeof(dstid), "%u",
355 EXTRACT_32BITS(&rp->rm_xid));
357 snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
358 snprintf(dstid, sizeof(dstid), "%u",
359 EXTRACT_32BITS(&rp->rm_xid));
361 print_nfsaddr(bp2, srcid, dstid);
362 (void)printf("reply %s %d",
363 EXTRACT_32BITS(&rp->rm_reply.rp_stat) == MSG_ACCEPTED?
367 if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
368 interp_reply(rp, proc, vers, length);
372 * Return a pointer to the first file handle in the packet.
373 * If the packet was truncated, return 0.
375 static const u_int32_t *
376 parsereq(register const struct rpc_msg *rp, register u_int length)
378 register const u_int32_t *dp;
382 * find the start of the req data (if we captured it)
384 dp = (u_int32_t *)&rp->rm_call.cb_cred;
386 len = EXTRACT_32BITS(&dp[1]);
388 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
390 len = EXTRACT_32BITS(&dp[1]);
392 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
402 * Print out an NFS file handle and return a pointer to following word.
403 * If packet was truncated, return 0.
405 static const u_int32_t *
406 parsefh(register const u_int32_t *dp, int v3)
412 len = EXTRACT_32BITS(dp) / 4;
417 if (TTEST2(*dp, len * sizeof(*dp))) {
418 nfs_printfh(dp, len);
426 * Print out a file name and return pointer to 32-bit word past it.
427 * If packet was truncated, return 0.
429 static const u_int32_t *
430 parsefn(register const u_int32_t *dp)
432 register u_int32_t len;
433 register const u_char *cp;
435 /* Bail if we don't have the string length */
438 /* Fetch string length; convert to host order */
442 TCHECK2(*dp, ((len + 3) & ~3));
445 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
446 dp += ((len + 3) & ~3) / sizeof(*dp);
447 /* XXX seems like we should be checking the length */
449 (void) fn_printn(cp, len, NULL);
458 * Print out file handle and file name.
459 * Return pointer to 32-bit word past file name.
460 * If packet was truncated (or there was some other error), return 0.
462 static const u_int32_t *
463 parsefhn(register const u_int32_t *dp, int v3)
465 dp = parsefh(dp, v3);
469 return (parsefn(dp));
473 nfsreq_print(register const u_char *bp, u_int length,
474 register const u_char *bp2)
476 register const struct rpc_msg *rp;
477 register const u_int32_t *dp;
481 struct nfsv3_sattr sa3;
482 char srcid[20], dstid[20]; /*fits 32bit*/
484 nfserr = 0; /* assume no error */
485 rp = (const struct rpc_msg *)bp;
487 snprintf(srcid, sizeof(srcid), "%u",
488 EXTRACT_32BITS(&rp->rm_xid));
489 strlcpy(dstid, "nfs", sizeof(dstid));
491 snprintf(srcid, sizeof(srcid), "%u",
492 EXTRACT_32BITS(&rp->rm_xid));
493 snprintf(dstid, sizeof(dstid), "%u", NFS_PORT);
495 print_nfsaddr(bp2, srcid, dstid);
496 (void)printf("%d", length);
498 xid_map_enter(rp, bp2); /* record proc number for later on */
500 v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3);
501 proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
503 if (!v3 && proc < NFS_NPROCS)
504 proc = nfsv3_procid[proc];
514 case NFSPROC_GETATTR:
516 if ((dp = parsereq(rp, length)) != NULL &&
517 parsefh(dp, v3) != NULL)
521 case NFSPROC_SETATTR:
523 if ((dp = parsereq(rp, length)) != NULL &&
524 parsefh(dp, v3) != NULL)
530 if ((dp = parsereq(rp, length)) != NULL &&
531 parsefhn(dp, v3) != NULL)
537 if ((dp = parsereq(rp, length)) != NULL &&
538 (dp = parsefh(dp, v3)) != NULL) {
540 printf(" %04x", EXTRACT_32BITS(&dp[0]));
545 case NFSPROC_READLINK:
547 if ((dp = parsereq(rp, length)) != NULL &&
548 parsefh(dp, v3) != NULL)
554 if ((dp = parsereq(rp, length)) != NULL &&
555 (dp = parsefh(dp, v3)) != NULL) {
558 printf(" %u bytes @ ",
559 EXTRACT_32BITS(&dp[2]));
560 print_int64(dp, UNSIGNED);
563 printf(" %u bytes @ %u",
564 EXTRACT_32BITS(&dp[1]),
565 EXTRACT_32BITS(&dp[0]));
573 if ((dp = parsereq(rp, length)) != NULL &&
574 (dp = parsefh(dp, v3)) != NULL) {
577 printf(" %u bytes @ ",
578 EXTRACT_32BITS(&dp[4]));
579 print_int64(dp, UNSIGNED);
584 tok2str(nfsv3_writemodes,
585 NULL, EXTRACT_32BITS(dp)));
589 printf(" %u (%u) bytes @ %u (%u)",
590 EXTRACT_32BITS(&dp[3]),
591 EXTRACT_32BITS(&dp[2]),
592 EXTRACT_32BITS(&dp[1]),
593 EXTRACT_32BITS(&dp[0]));
601 if ((dp = parsereq(rp, length)) != NULL &&
602 parsefhn(dp, v3) != NULL)
608 if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0)
612 case NFSPROC_SYMLINK:
614 if ((dp = parsereq(rp, length)) != 0 &&
615 (dp = parsefhn(dp, v3)) != 0) {
616 fputs(" ->", stdout);
617 if (v3 && (dp = parse_sattr3(dp, &sa3)) == 0)
619 if (parsefn(dp) == 0)
622 print_sattr3(&sa3, vflag);
629 if ((dp = parsereq(rp, length)) != 0 &&
630 (dp = parsefhn(dp, v3)) != 0) {
632 type = (nfs_type)EXTRACT_32BITS(dp);
634 if ((dp = parse_sattr3(dp, &sa3)) == 0)
636 printf(" %s", tok2str(type2str, "unk-ft %d", type));
637 if (vflag && (type == NFCHR || type == NFBLK)) {
640 EXTRACT_32BITS(&dp[0]),
641 EXTRACT_32BITS(&dp[1]));
645 print_sattr3(&sa3, vflag);
652 if ((dp = parsereq(rp, length)) != NULL &&
653 parsefhn(dp, v3) != NULL)
659 if ((dp = parsereq(rp, length)) != NULL &&
660 parsefhn(dp, v3) != NULL)
666 if ((dp = parsereq(rp, length)) != NULL &&
667 (dp = parsefhn(dp, v3)) != NULL) {
668 fputs(" ->", stdout);
669 if (parsefhn(dp, v3) != NULL)
676 if ((dp = parsereq(rp, length)) != NULL &&
677 (dp = parsefh(dp, v3)) != NULL) {
678 fputs(" ->", stdout);
679 if (parsefhn(dp, v3) != NULL)
684 case NFSPROC_READDIR:
686 if ((dp = parsereq(rp, length)) != NULL &&
687 (dp = parsefh(dp, v3)) != NULL) {
691 * We shouldn't really try to interpret the
692 * offset cookie here.
694 printf(" %u bytes @ ",
695 EXTRACT_32BITS(&dp[4]));
696 print_int64(dp, SIGNED);
698 printf(" verf %08x%08x", dp[2],
703 * Print the offset as signed, since -1 is
704 * common, but offsets > 2^31 aren't.
706 printf(" %u bytes @ %d",
707 EXTRACT_32BITS(&dp[1]),
708 EXTRACT_32BITS(&dp[0]));
714 case NFSPROC_READDIRPLUS:
715 printf(" readdirplus");
716 if ((dp = parsereq(rp, length)) != NULL &&
717 (dp = parsefh(dp, v3)) != NULL) {
720 * We don't try to interpret the offset
723 printf(" %u bytes @ ", EXTRACT_32BITS(&dp[4]));
724 print_int64(dp, SIGNED);
726 printf(" max %u verf %08x%08x",
727 EXTRACT_32BITS(&dp[5]), dp[2], dp[3]);
734 if ((dp = parsereq(rp, length)) != NULL &&
735 parsefh(dp, v3) != NULL)
741 if ((dp = parsereq(rp, length)) != NULL &&
742 parsefh(dp, v3) != NULL)
746 case NFSPROC_PATHCONF:
748 if ((dp = parsereq(rp, length)) != NULL &&
749 parsefh(dp, v3) != NULL)
755 if ((dp = parsereq(rp, length)) != NULL &&
756 (dp = parsefh(dp, v3)) != NULL) {
757 printf(" %u bytes @ ", EXTRACT_32BITS(&dp[2]));
758 print_int64(dp, UNSIGNED);
764 printf(" proc-%u", EXTRACT_32BITS(&rp->rm_call.cb_proc));
770 fputs(" [|nfs]", stdout);
774 * Print out an NFS file handle.
775 * We assume packet was not truncated before the end of the
776 * file handle pointed to by dp.
778 * Note: new version (using portable file-handle parser) doesn't produce
779 * generation number. It probably could be made to do that, with some
780 * additional hacking on the parser code.
783 nfs_printfh(register const u_int32_t *dp, const u_int len)
787 const char *sfsname = NULL;
792 char const *sep = "";
795 for (i=0; i<len; i++) {
796 (void)printf("%s%x", sep, dp[i]);
803 Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
806 /* file system ID is ASCII, not numeric, for this server OS */
807 static char temp[NFSX_V3FHMAX+1];
809 /* Make sure string is null-terminated */
810 strncpy(temp, sfsname, NFSX_V3FHMAX);
811 temp[sizeof(temp) - 1] = '\0';
812 /* Remove trailing spaces */
813 spacep = strchr(temp, ' ');
817 (void)printf(" fh %s/", temp);
819 (void)printf(" fh %d,%d/",
820 fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
823 if(fsid.Fsid_dev.Minor == 257)
824 /* Print the undecoded handle */
825 (void)printf("%s", fsid.Opaque_Handle);
827 (void)printf("%ld", (long) ino);
831 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
832 * us to match up replies with requests and thus to know how to parse
836 struct xid_map_entry {
837 u_int32_t xid; /* transaction ID (net order) */
838 int ipver; /* IP version (4 or 6) */
840 struct in6_addr client; /* client IP address (net order) */
841 struct in6_addr server; /* server IP address (net order) */
843 struct in_addr client; /* client IP address (net order) */
844 struct in_addr server; /* server IP address (net order) */
846 u_int32_t proc; /* call proc number (host order) */
847 u_int32_t vers; /* program version (host order) */
851 * Map entries are kept in an array that we manage as a ring;
852 * new entries are always added at the tail of the ring. Initially,
853 * all the entries are zero and hence don't match anything.
856 #define XIDMAPSIZE 64
858 struct xid_map_entry xid_map[XIDMAPSIZE];
860 int xid_map_next = 0;
861 int xid_map_hint = 0;
864 xid_map_enter(const struct rpc_msg *rp, const u_char *bp)
866 struct ip *ip = NULL;
868 struct ip6_hdr *ip6 = NULL;
870 struct xid_map_entry *xmep;
872 switch (IP_V((struct ip *)bp)) {
874 ip = (struct ip *)bp;
878 ip6 = (struct ip6_hdr *)bp;
885 xmep = &xid_map[xid_map_next];
887 if (++xid_map_next >= XIDMAPSIZE)
890 xmep->xid = rp->rm_xid;
893 memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
894 memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
899 memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
900 memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
903 xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
904 xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
908 * Returns 0 and puts NFSPROC_xxx in proc return and
909 * version in vers return, or returns -1 on failure
912 xid_map_find(const struct rpc_msg *rp, const u_char *bp, u_int32_t *proc,
916 struct xid_map_entry *xmep;
917 u_int32_t xid = rp->rm_xid;
918 struct ip *ip = (struct ip *)bp;
920 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
924 /* Start searching from where we last left off */
929 if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
931 switch (xmep->ipver) {
933 if (memcmp(&ip->ip_src, &xmep->server,
934 sizeof(ip->ip_src)) != 0 ||
935 memcmp(&ip->ip_dst, &xmep->client,
936 sizeof(ip->ip_dst)) != 0) {
942 if (memcmp(&ip6->ip6_src, &xmep->server,
943 sizeof(ip6->ip6_src)) != 0 ||
944 memcmp(&ip6->ip6_dst, &xmep->client,
945 sizeof(ip6->ip6_dst)) != 0) {
962 if (++i >= XIDMAPSIZE)
964 } while (i != xid_map_hint);
971 * Routines for parsing reply packets
975 * Return a pointer to the beginning of the actual results.
976 * If the packet was truncated, return 0.
978 static const u_int32_t *
979 parserep(register const struct rpc_msg *rp, register u_int length)
981 register const u_int32_t *dp;
983 enum accept_stat astat;
987 * Here we find the address of the ar_verf credentials.
988 * Originally, this calculation was
989 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
990 * On the wire, the rp_acpt field starts immediately after
991 * the (32 bit) rp_stat field. However, rp_acpt (which is a
992 * "struct accepted_reply") contains a "struct opaque_auth",
993 * whose internal representation contains a pointer, so on a
994 * 64-bit machine the compiler inserts 32 bits of padding
995 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
996 * the internal representation to parse the on-the-wire
997 * representation. Instead, we skip past the rp_stat field,
998 * which is an "enum" and so occupies one 32-bit word.
1000 dp = ((const u_int32_t *)&rp->rm_reply) + 1;
1002 len = EXTRACT_32BITS(&dp[1]);
1006 * skip past the ar_verf credentials.
1008 dp += (len + (2*sizeof(u_int32_t) + 3)) / sizeof(u_int32_t);
1012 * now we can check the ar_stat field
1014 astat = EXTRACT_32BITS(dp);
1021 printf(" PROG_UNAVAIL");
1022 nfserr = 1; /* suppress trunc string */
1026 printf(" PROG_MISMATCH");
1027 nfserr = 1; /* suppress trunc string */
1031 printf(" PROC_UNAVAIL");
1032 nfserr = 1; /* suppress trunc string */
1036 printf(" GARBAGE_ARGS");
1037 nfserr = 1; /* suppress trunc string */
1041 printf(" SYSTEM_ERR");
1042 nfserr = 1; /* suppress trunc string */
1046 printf(" ar_stat %d", astat);
1047 nfserr = 1; /* suppress trunc string */
1050 /* successful return */
1051 TCHECK2(*dp, sizeof(astat));
1052 return ((u_int32_t *) (sizeof(astat) + ((char *)dp)));
1057 static const u_int32_t *
1058 parsestatus(const u_int32_t *dp, int *er)
1064 errnum = EXTRACT_32BITS(&dp[0]);
1069 printf(" ERROR: %s",
1070 tok2str(status2str, "unk %d", errnum));
1078 static const u_int32_t *
1079 parsefattr(const u_int32_t *dp, int verbose, int v3)
1081 const struct nfs_fattr *fap;
1083 fap = (const struct nfs_fattr *)dp;
1084 TCHECK(fap->fa_gid);
1086 printf(" %s %o ids %d/%d",
1087 tok2str(type2str, "unk-ft %d ",
1088 EXTRACT_32BITS(&fap->fa_type)),
1089 EXTRACT_32BITS(&fap->fa_mode),
1090 EXTRACT_32BITS(&fap->fa_uid),
1091 EXTRACT_32BITS(&fap->fa_gid));
1093 TCHECK(fap->fa3_size);
1095 print_int64((u_int32_t *)&fap->fa3_size, UNSIGNED);
1097 TCHECK(fap->fa2_size);
1098 printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size));
1101 /* print lots more stuff */
1104 TCHECK(fap->fa3_ctime);
1105 printf(" nlink %d rdev %d/%d",
1106 EXTRACT_32BITS(&fap->fa_nlink),
1107 EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
1108 EXTRACT_32BITS(&fap->fa3_rdev.specdata2));
1110 print_int64((u_int32_t *)&fap->fa3_fsid, HEX);
1112 print_int64((u_int32_t *)&fap->fa3_fileid, HEX);
1113 printf(" a/m/ctime %u.%06u",
1114 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec),
1115 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec));
1117 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec),
1118 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec));
1120 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec),
1121 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec));
1123 TCHECK(fap->fa2_ctime);
1124 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1125 EXTRACT_32BITS(&fap->fa_nlink),
1126 EXTRACT_32BITS(&fap->fa2_rdev),
1127 EXTRACT_32BITS(&fap->fa2_fsid),
1128 EXTRACT_32BITS(&fap->fa2_fileid));
1130 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec),
1131 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec));
1133 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec),
1134 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec));
1136 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec),
1137 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec));
1140 return ((const u_int32_t *)((unsigned char *)dp +
1141 (v3 ? NFSX_V3FATTR : NFSX_V2FATTR)));
1147 parseattrstat(const u_int32_t *dp, int verbose, int v3)
1151 dp = parsestatus(dp, &er);
1157 return (parsefattr(dp, verbose, v3) != NULL);
1161 parsediropres(const u_int32_t *dp)
1165 if (!(dp = parsestatus(dp, &er)))
1170 dp = parsefh(dp, 0);
1174 return (parsefattr(dp, vflag, 0) != NULL);
1178 parselinkres(const u_int32_t *dp, int v3)
1182 dp = parsestatus(dp, &er);
1187 if (v3 && !(dp = parse_post_op_attr(dp, vflag)))
1190 return (parsefn(dp) != NULL);
1194 parsestatfs(const u_int32_t *dp, int v3)
1196 const struct nfs_statfs *sfsp;
1199 dp = parsestatus(dp, &er);
1211 if (!(dp = parse_post_op_attr(dp, vflag)))
1215 TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
1217 sfsp = (const struct nfs_statfs *)dp;
1221 print_int64((u_int32_t *)&sfsp->sf_tbytes, UNSIGNED);
1223 print_int64((u_int32_t *)&sfsp->sf_fbytes, UNSIGNED);
1225 print_int64((u_int32_t *)&sfsp->sf_abytes, UNSIGNED);
1228 print_int64((u_int32_t *)&sfsp->sf_tfiles, UNSIGNED);
1230 print_int64((u_int32_t *)&sfsp->sf_ffiles, UNSIGNED);
1232 print_int64((u_int32_t *)&sfsp->sf_afiles, UNSIGNED);
1234 EXTRACT_32BITS(&sfsp->sf_invarsec));
1237 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1238 EXTRACT_32BITS(&sfsp->sf_tsize),
1239 EXTRACT_32BITS(&sfsp->sf_bsize),
1240 EXTRACT_32BITS(&sfsp->sf_blocks),
1241 EXTRACT_32BITS(&sfsp->sf_bfree),
1242 EXTRACT_32BITS(&sfsp->sf_bavail));
1251 parserddires(const u_int32_t *dp)
1255 dp = parsestatus(dp, &er);
1264 printf(" offset %x size %d ",
1265 EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1]));
1274 static const u_int32_t *
1275 parse_wcc_attr(const u_int32_t *dp)
1278 print_int64(dp, UNSIGNED);
1279 printf(" mtime %u.%06u ctime %u.%06u",
1280 EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
1281 EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5]));
1286 * Pre operation attributes. Print only if vflag > 1.
1288 static const u_int32_t *
1289 parse_pre_op_attr(const u_int32_t *dp, int verbose)
1292 if (!EXTRACT_32BITS(&dp[0]))
1297 return parse_wcc_attr(dp);
1299 /* If not verbose enough, just skip over wcc_attr */
1307 * Post operation attributes are printed if vflag >= 1
1309 static const u_int32_t *
1310 parse_post_op_attr(const u_int32_t *dp, int verbose)
1313 if (!EXTRACT_32BITS(&dp[0]))
1317 return parsefattr(dp, verbose, 1);
1319 return (dp + (NFSX_V3FATTR / sizeof (u_int32_t)));
1324 static const u_int32_t *
1325 parse_wcc_data(const u_int32_t *dp, int verbose)
1329 if (!(dp = parse_pre_op_attr(dp, verbose)))
1334 return parse_post_op_attr(dp, verbose);
1337 static const u_int32_t *
1338 parsecreateopres(const u_int32_t *dp, int verbose)
1342 if (!(dp = parsestatus(dp, &er)))
1345 dp = parse_wcc_data(dp, verbose);
1348 if (!EXTRACT_32BITS(&dp[0]))
1351 if (!(dp = parsefh(dp, 1)))
1354 if (!(dp = parse_post_op_attr(dp, verbose)))
1357 printf(" dir attr:");
1358 dp = parse_wcc_data(dp, verbose);
1368 parsewccres(const u_int32_t *dp, int verbose)
1372 if (!(dp = parsestatus(dp, &er)))
1374 return parse_wcc_data(dp, verbose) != 0;
1377 static const u_int32_t *
1378 parsev3rddirres(const u_int32_t *dp, int verbose)
1382 if (!(dp = parsestatus(dp, &er)))
1386 if (!(dp = parse_post_op_attr(dp, verbose)))
1392 printf(" verf %08x%08x", dp[0], dp[1]);
1401 parsefsinfo(const u_int32_t *dp)
1403 struct nfsv3_fsinfo *sfp;
1406 if (!(dp = parsestatus(dp, &er)))
1410 if (!(dp = parse_post_op_attr(dp, vflag)))
1415 sfp = (struct nfsv3_fsinfo *)dp;
1417 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1418 EXTRACT_32BITS(&sfp->fs_rtmax),
1419 EXTRACT_32BITS(&sfp->fs_rtpref),
1420 EXTRACT_32BITS(&sfp->fs_wtmax),
1421 EXTRACT_32BITS(&sfp->fs_wtpref),
1422 EXTRACT_32BITS(&sfp->fs_dtpref));
1424 printf(" rtmult %u wtmult %u maxfsz ",
1425 EXTRACT_32BITS(&sfp->fs_rtmult),
1426 EXTRACT_32BITS(&sfp->fs_wtmult));
1427 print_int64((u_int32_t *)&sfp->fs_maxfilesize, UNSIGNED);
1428 printf(" delta %u.%06u ",
1429 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
1430 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec));
1438 parsepathconf(const u_int32_t *dp)
1441 struct nfsv3_pathconf *spp;
1443 if (!(dp = parsestatus(dp, &er)))
1447 if (!(dp = parse_post_op_attr(dp, vflag)))
1452 spp = (struct nfsv3_pathconf *)dp;
1455 printf(" linkmax %u namemax %u %s %s %s %s",
1456 EXTRACT_32BITS(&spp->pc_linkmax),
1457 EXTRACT_32BITS(&spp->pc_namemax),
1458 EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
1459 EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
1460 EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
1461 EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : "");
1468 interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
1470 register const u_int32_t *dp;
1474 v3 = (vers == NFS_VER3);
1476 if (!v3 && proc < NFS_NPROCS)
1477 proc = nfsv3_procid[proc];
1489 case NFSPROC_GETATTR:
1491 dp = parserep(rp, length);
1492 if (dp != NULL && parseattrstat(dp, !qflag, v3) != 0)
1496 case NFSPROC_SETATTR:
1498 if (!(dp = parserep(rp, length)))
1501 if (parsewccres(dp, vflag))
1504 if (parseattrstat(dp, !qflag, 0) != 0)
1509 case NFSPROC_LOOKUP:
1511 if (!(dp = parserep(rp, length)))
1514 if (!(dp = parsestatus(dp, &er)))
1518 printf(" post dattr:");
1519 dp = parse_post_op_attr(dp, vflag);
1522 if (!(dp = parsefh(dp, v3)))
1524 if ((dp = parse_post_op_attr(dp, vflag)) &&
1526 printf(" post dattr:");
1527 dp = parse_post_op_attr(dp, vflag);
1533 if (parsediropres(dp) != 0)
1538 case NFSPROC_ACCESS:
1540 if (!(dp = parserep(rp, length)))
1542 if (!(dp = parsestatus(dp, &er)))
1546 if (!(dp = parse_post_op_attr(dp, vflag)))
1549 printf(" c %04x", EXTRACT_32BITS(&dp[0]));
1552 case NFSPROC_READLINK:
1553 printf(" readlink");
1554 dp = parserep(rp, length);
1555 if (dp != NULL && parselinkres(dp, v3) != 0)
1561 if (!(dp = parserep(rp, length)))
1564 if (!(dp = parsestatus(dp, &er)))
1566 if (!(dp = parse_post_op_attr(dp, vflag)))
1572 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1573 if (EXTRACT_32BITS(&dp[1]))
1578 if (parseattrstat(dp, vflag, 0) != 0)
1585 if (!(dp = parserep(rp, length)))
1588 if (!(dp = parsestatus(dp, &er)))
1590 if (!(dp = parse_wcc_data(dp, vflag)))
1596 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1600 tok2str(nfsv3_writemodes,
1601 NULL, EXTRACT_32BITS(&dp[1])));
1606 if (parseattrstat(dp, vflag, v3) != 0)
1611 case NFSPROC_CREATE:
1613 if (!(dp = parserep(rp, length)))
1616 if (parsecreateopres(dp, vflag) != 0)
1619 if (parsediropres(dp) != 0)
1626 if (!(dp = parserep(rp, length)))
1629 if (parsecreateopres(dp, vflag) != 0)
1632 if (parsediropres(dp) != 0)
1637 case NFSPROC_SYMLINK:
1639 if (!(dp = parserep(rp, length)))
1642 if (parsecreateopres(dp, vflag) != 0)
1645 if (parsestatus(dp, &er) != 0)
1652 if (!(dp = parserep(rp, length)))
1654 if (parsecreateopres(dp, vflag) != 0)
1658 case NFSPROC_REMOVE:
1660 if (!(dp = parserep(rp, length)))
1663 if (parsewccres(dp, vflag))
1666 if (parsestatus(dp, &er) != 0)
1673 if (!(dp = parserep(rp, length)))
1676 if (parsewccres(dp, vflag))
1679 if (parsestatus(dp, &er) != 0)
1684 case NFSPROC_RENAME:
1686 if (!(dp = parserep(rp, length)))
1689 if (!(dp = parsestatus(dp, &er)))
1693 if (!(dp = parse_wcc_data(dp, vflag)))
1696 if (!(dp = parse_wcc_data(dp, vflag)))
1701 if (parsestatus(dp, &er) != 0)
1708 if (!(dp = parserep(rp, length)))
1711 if (!(dp = parsestatus(dp, &er)))
1714 printf(" file POST:");
1715 if (!(dp = parse_post_op_attr(dp, vflag)))
1718 if (!(dp = parse_wcc_data(dp, vflag)))
1723 if (parsestatus(dp, &er) != 0)
1728 case NFSPROC_READDIR:
1730 if (!(dp = parserep(rp, length)))
1733 if (parsev3rddirres(dp, vflag))
1736 if (parserddires(dp) != 0)
1741 case NFSPROC_READDIRPLUS:
1742 printf(" readdirplus");
1743 if (!(dp = parserep(rp, length)))
1745 if (parsev3rddirres(dp, vflag))
1749 case NFSPROC_FSSTAT:
1751 dp = parserep(rp, length);
1752 if (dp != NULL && parsestatfs(dp, v3) != 0)
1756 case NFSPROC_FSINFO:
1758 dp = parserep(rp, length);
1759 if (dp != NULL && parsefsinfo(dp) != 0)
1763 case NFSPROC_PATHCONF:
1764 printf(" pathconf");
1765 dp = parserep(rp, length);
1766 if (dp != NULL && parsepathconf(dp) != 0)
1770 case NFSPROC_COMMIT:
1772 dp = parserep(rp, length);
1773 if (dp != NULL && parsewccres(dp, vflag) != 0)
1778 printf(" proc-%u", proc);
1783 fputs(" [|nfs]", stdout);