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.106.2.2 2005/05/06 07:57:18 guy Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
53 static void nfs_printfh(const u_int32_t *, const u_int);
54 static void xid_map_enter(const struct sunrpc_msg *, const u_char *);
55 static int32_t xid_map_find(const struct sunrpc_msg *, const u_char *,
56 u_int32_t *, u_int32_t *);
57 static void interp_reply(const struct sunrpc_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 void print_nfsaddr(const u_char *, const char *, const char *);
63 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
65 u_int32_t nfsv3_procid[NFS_NPROCS] = {
95 * NFS V2 and V3 status values.
97 * Some of these come from the RFCs for NFS V2 and V3, with the message
98 * strings taken from the FreeBSD C library "errlst.c".
100 * Others are errors that are not in the RFC but that I suspect some
101 * NFS servers could return; the values are FreeBSD errno values, as
102 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
103 * was primarily BSD-derived.
105 static struct tok status2str[] = {
106 { 1, "Operation not permitted" }, /* EPERM */
107 { 2, "No such file or directory" }, /* ENOENT */
108 { 5, "Input/output error" }, /* EIO */
109 { 6, "Device not configured" }, /* ENXIO */
110 { 11, "Resource deadlock avoided" }, /* EDEADLK */
111 { 12, "Cannot allocate memory" }, /* ENOMEM */
112 { 13, "Permission denied" }, /* EACCES */
113 { 17, "File exists" }, /* EEXIST */
114 { 18, "Cross-device link" }, /* EXDEV */
115 { 19, "Operation not supported by device" }, /* ENODEV */
116 { 20, "Not a directory" }, /* ENOTDIR */
117 { 21, "Is a directory" }, /* EISDIR */
118 { 22, "Invalid argument" }, /* EINVAL */
119 { 26, "Text file busy" }, /* ETXTBSY */
120 { 27, "File too large" }, /* EFBIG */
121 { 28, "No space left on device" }, /* ENOSPC */
122 { 30, "Read-only file system" }, /* EROFS */
123 { 31, "Too many links" }, /* EMLINK */
124 { 45, "Operation not supported" }, /* EOPNOTSUPP */
125 { 62, "Too many levels of symbolic links" }, /* ELOOP */
126 { 63, "File name too long" }, /* ENAMETOOLONG */
127 { 66, "Directory not empty" }, /* ENOTEMPTY */
128 { 69, "Disc quota exceeded" }, /* EDQUOT */
129 { 70, "Stale NFS file handle" }, /* ESTALE */
130 { 71, "Too many levels of remote in path" }, /* EREMOTE */
131 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
132 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
133 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
134 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
135 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
136 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
137 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
138 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
139 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
143 static struct tok nfsv3_writemodes[] = {
150 static struct tok type2str[] = {
162 print_nfsaddr(const u_char *bp, const char *s, const char *d)
167 char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
169 #ifndef INET_ADDRSTRLEN
170 #define INET_ADDRSTRLEN 16
172 char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN];
175 srcaddr[0] = dstaddr[0] = '\0';
176 switch (IP_V((struct ip *)bp)) {
178 ip = (struct ip *)bp;
179 strlcpy(srcaddr, ipaddr_string(&ip->ip_src), sizeof(srcaddr));
180 strlcpy(dstaddr, ipaddr_string(&ip->ip_dst), sizeof(dstaddr));
184 ip6 = (struct ip6_hdr *)bp;
185 strlcpy(srcaddr, ip6addr_string(&ip6->ip6_src),
187 strlcpy(dstaddr, ip6addr_string(&ip6->ip6_dst),
192 strlcpy(srcaddr, "?", sizeof(srcaddr));
193 strlcpy(dstaddr, "?", sizeof(dstaddr));
197 (void)printf("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d);
200 static const u_int32_t *
201 parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3)
204 sa3->sa_modeset = EXTRACT_32BITS(dp);
206 if (sa3->sa_modeset) {
208 sa3->sa_mode = EXTRACT_32BITS(dp);
213 sa3->sa_uidset = EXTRACT_32BITS(dp);
215 if (sa3->sa_uidset) {
217 sa3->sa_uid = EXTRACT_32BITS(dp);
222 sa3->sa_gidset = EXTRACT_32BITS(dp);
224 if (sa3->sa_gidset) {
226 sa3->sa_gid = EXTRACT_32BITS(dp);
231 sa3->sa_sizeset = EXTRACT_32BITS(dp);
233 if (sa3->sa_sizeset) {
235 sa3->sa_size = EXTRACT_32BITS(dp);
240 sa3->sa_atimetype = EXTRACT_32BITS(dp);
242 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) {
244 sa3->sa_atime.nfsv3_sec = EXTRACT_32BITS(dp);
246 sa3->sa_atime.nfsv3_nsec = EXTRACT_32BITS(dp);
251 sa3->sa_mtimetype = EXTRACT_32BITS(dp);
253 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) {
255 sa3->sa_mtime.nfsv3_sec = EXTRACT_32BITS(dp);
257 sa3->sa_mtime.nfsv3_nsec = EXTRACT_32BITS(dp);
266 static int nfserr; /* true if we error rather than trunc */
269 print_sattr3(const struct nfsv3_sattr *sa3, int verbose)
272 printf(" mode %o", sa3->sa_mode);
274 printf(" uid %u", sa3->sa_uid);
276 printf(" gid %u", sa3->sa_gid);
278 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT)
279 printf(" atime %u.%06u", sa3->sa_atime.nfsv3_sec,
280 sa3->sa_atime.nfsv3_nsec);
281 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT)
282 printf(" mtime %u.%06u", sa3->sa_mtime.nfsv3_sec,
283 sa3->sa_mtime.nfsv3_nsec);
288 nfsreply_print(register const u_char *bp, u_int length,
289 register const u_char *bp2)
291 register const struct sunrpc_msg *rp;
292 u_int32_t proc, vers;
293 char srcid[20], dstid[20]; /*fits 32bit*/
295 nfserr = 0; /* assume no error */
296 rp = (const struct sunrpc_msg *)bp;
299 strlcpy(srcid, "nfs", sizeof(srcid));
300 snprintf(dstid, sizeof(dstid), "%u",
301 EXTRACT_32BITS(&rp->rm_xid));
303 snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
304 snprintf(dstid, sizeof(dstid), "%u",
305 EXTRACT_32BITS(&rp->rm_xid));
307 print_nfsaddr(bp2, srcid, dstid);
308 (void)printf("reply %s %d",
309 EXTRACT_32BITS(&rp->rm_reply.rp_stat) == SUNRPC_MSG_ACCEPTED?
313 if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
314 interp_reply(rp, proc, vers, length);
318 * Return a pointer to the first file handle in the packet.
319 * If the packet was truncated, return 0.
321 static const u_int32_t *
322 parsereq(register const struct sunrpc_msg *rp, register u_int length)
324 register const u_int32_t *dp;
328 * find the start of the req data (if we captured it)
330 dp = (u_int32_t *)&rp->rm_call.cb_cred;
332 len = EXTRACT_32BITS(&dp[1]);
334 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
336 len = EXTRACT_32BITS(&dp[1]);
338 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
348 * Print out an NFS file handle and return a pointer to following word.
349 * If packet was truncated, return 0.
351 static const u_int32_t *
352 parsefh(register const u_int32_t *dp, int v3)
358 len = EXTRACT_32BITS(dp) / 4;
363 if (TTEST2(*dp, len * sizeof(*dp))) {
364 nfs_printfh(dp, len);
372 * Print out a file name and return pointer to 32-bit word past it.
373 * If packet was truncated, return 0.
375 static const u_int32_t *
376 parsefn(register const u_int32_t *dp)
378 register u_int32_t len;
379 register const u_char *cp;
381 /* Bail if we don't have the string length */
384 /* Fetch string length; convert to host order */
388 TCHECK2(*dp, ((len + 3) & ~3));
391 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
392 dp += ((len + 3) & ~3) / sizeof(*dp);
394 if (fn_printn(cp, len, snapend)) {
406 * Print out file handle and file name.
407 * Return pointer to 32-bit word past file name.
408 * If packet was truncated (or there was some other error), return 0.
410 static const u_int32_t *
411 parsefhn(register const u_int32_t *dp, int v3)
413 dp = parsefh(dp, v3);
417 return (parsefn(dp));
421 nfsreq_print(register const u_char *bp, u_int length,
422 register const u_char *bp2)
424 register const struct sunrpc_msg *rp;
425 register const u_int32_t *dp;
429 struct nfsv3_sattr sa3;
430 char srcid[20], dstid[20]; /*fits 32bit*/
432 nfserr = 0; /* assume no error */
433 rp = (const struct sunrpc_msg *)bp;
435 snprintf(srcid, sizeof(srcid), "%u",
436 EXTRACT_32BITS(&rp->rm_xid));
437 strlcpy(dstid, "nfs", sizeof(dstid));
439 snprintf(srcid, sizeof(srcid), "%u",
440 EXTRACT_32BITS(&rp->rm_xid));
441 snprintf(dstid, sizeof(dstid), "%u", NFS_PORT);
443 print_nfsaddr(bp2, srcid, dstid);
444 (void)printf("%d", length);
446 xid_map_enter(rp, bp2); /* record proc number for later on */
448 v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3);
449 proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
451 if (!v3 && proc < NFS_NPROCS)
452 proc = nfsv3_procid[proc];
462 case NFSPROC_GETATTR:
464 if ((dp = parsereq(rp, length)) != NULL &&
465 parsefh(dp, v3) != NULL)
469 case NFSPROC_SETATTR:
471 if ((dp = parsereq(rp, length)) != NULL &&
472 parsefh(dp, v3) != NULL)
478 if ((dp = parsereq(rp, length)) != NULL &&
479 parsefhn(dp, v3) != NULL)
485 if ((dp = parsereq(rp, length)) != NULL &&
486 (dp = parsefh(dp, v3)) != NULL) {
488 printf(" %04x", EXTRACT_32BITS(&dp[0]));
493 case NFSPROC_READLINK:
495 if ((dp = parsereq(rp, length)) != NULL &&
496 parsefh(dp, v3) != NULL)
502 if ((dp = parsereq(rp, length)) != NULL &&
503 (dp = parsefh(dp, v3)) != NULL) {
506 printf(" %u bytes @ %" PRIu64,
507 EXTRACT_32BITS(&dp[2]),
508 EXTRACT_64BITS(&dp[0]));
511 printf(" %u bytes @ %u",
512 EXTRACT_32BITS(&dp[1]),
513 EXTRACT_32BITS(&dp[0]));
521 if ((dp = parsereq(rp, length)) != NULL &&
522 (dp = parsefh(dp, v3)) != NULL) {
525 printf(" %u (%u) bytes @ %" PRIu64,
526 EXTRACT_32BITS(&dp[4]),
527 EXTRACT_32BITS(&dp[2]),
528 EXTRACT_64BITS(&dp[0]));
533 tok2str(nfsv3_writemodes,
534 NULL, EXTRACT_32BITS(dp)));
538 printf(" %u (%u) bytes @ %u (%u)",
539 EXTRACT_32BITS(&dp[3]),
540 EXTRACT_32BITS(&dp[2]),
541 EXTRACT_32BITS(&dp[1]),
542 EXTRACT_32BITS(&dp[0]));
550 if ((dp = parsereq(rp, length)) != NULL &&
551 parsefhn(dp, v3) != NULL)
557 if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0)
561 case NFSPROC_SYMLINK:
563 if ((dp = parsereq(rp, length)) != 0 &&
564 (dp = parsefhn(dp, v3)) != 0) {
565 fputs(" ->", stdout);
566 if (v3 && (dp = parse_sattr3(dp, &sa3)) == 0)
568 if (parsefn(dp) == 0)
571 print_sattr3(&sa3, vflag);
578 if ((dp = parsereq(rp, length)) != 0 &&
579 (dp = parsefhn(dp, v3)) != 0) {
581 type = (nfs_type)EXTRACT_32BITS(dp);
583 if ((dp = parse_sattr3(dp, &sa3)) == 0)
585 printf(" %s", tok2str(type2str, "unk-ft %d", type));
586 if (vflag && (type == NFCHR || type == NFBLK)) {
589 EXTRACT_32BITS(&dp[0]),
590 EXTRACT_32BITS(&dp[1]));
594 print_sattr3(&sa3, vflag);
601 if ((dp = parsereq(rp, length)) != NULL &&
602 parsefhn(dp, v3) != NULL)
608 if ((dp = parsereq(rp, length)) != NULL &&
609 parsefhn(dp, v3) != NULL)
615 if ((dp = parsereq(rp, length)) != NULL &&
616 (dp = parsefhn(dp, v3)) != NULL) {
617 fputs(" ->", stdout);
618 if (parsefhn(dp, v3) != NULL)
625 if ((dp = parsereq(rp, length)) != NULL &&
626 (dp = parsefh(dp, v3)) != NULL) {
627 fputs(" ->", stdout);
628 if (parsefhn(dp, v3) != NULL)
633 case NFSPROC_READDIR:
635 if ((dp = parsereq(rp, length)) != NULL &&
636 (dp = parsefh(dp, v3)) != NULL) {
640 * We shouldn't really try to interpret the
641 * offset cookie here.
643 printf(" %u bytes @ %" PRId64,
644 EXTRACT_32BITS(&dp[4]),
645 EXTRACT_64BITS(&dp[0]));
647 printf(" verf %08x%08x", dp[2],
652 * Print the offset as signed, since -1 is
653 * common, but offsets > 2^31 aren't.
655 printf(" %u bytes @ %d",
656 EXTRACT_32BITS(&dp[1]),
657 EXTRACT_32BITS(&dp[0]));
663 case NFSPROC_READDIRPLUS:
664 printf(" readdirplus");
665 if ((dp = parsereq(rp, length)) != NULL &&
666 (dp = parsefh(dp, v3)) != NULL) {
669 * We don't try to interpret the offset
672 printf(" %u bytes @ %" PRId64,
673 EXTRACT_32BITS(&dp[4]),
674 EXTRACT_64BITS(&dp[0]));
677 printf(" max %u verf %08x%08x",
678 EXTRACT_32BITS(&dp[5]), dp[2], dp[3]);
686 if ((dp = parsereq(rp, length)) != NULL &&
687 parsefh(dp, v3) != NULL)
693 if ((dp = parsereq(rp, length)) != NULL &&
694 parsefh(dp, v3) != NULL)
698 case NFSPROC_PATHCONF:
700 if ((dp = parsereq(rp, length)) != NULL &&
701 parsefh(dp, v3) != NULL)
707 if ((dp = parsereq(rp, length)) != NULL &&
708 (dp = parsefh(dp, v3)) != NULL) {
710 printf(" %u bytes @ %" PRIu64,
711 EXTRACT_32BITS(&dp[2]),
712 EXTRACT_64BITS(&dp[0]));
718 printf(" proc-%u", EXTRACT_32BITS(&rp->rm_call.cb_proc));
724 fputs(" [|nfs]", stdout);
728 * Print out an NFS file handle.
729 * We assume packet was not truncated before the end of the
730 * file handle pointed to by dp.
732 * Note: new version (using portable file-handle parser) doesn't produce
733 * generation number. It probably could be made to do that, with some
734 * additional hacking on the parser code.
737 nfs_printfh(register const u_int32_t *dp, const u_int len)
741 const char *sfsname = NULL;
746 char const *sep = "";
749 for (i=0; i<len; i++) {
750 (void)printf("%s%x", sep, dp[i]);
757 Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
760 /* file system ID is ASCII, not numeric, for this server OS */
761 static char temp[NFSX_V3FHMAX+1];
763 /* Make sure string is null-terminated */
764 strncpy(temp, sfsname, NFSX_V3FHMAX);
765 temp[sizeof(temp) - 1] = '\0';
766 /* Remove trailing spaces */
767 spacep = strchr(temp, ' ');
771 (void)printf(" fh %s/", temp);
773 (void)printf(" fh %d,%d/",
774 fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
777 if(fsid.Fsid_dev.Minor == 257)
778 /* Print the undecoded handle */
779 (void)printf("%s", fsid.Opaque_Handle);
781 (void)printf("%ld", (long) ino);
785 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
786 * us to match up replies with requests and thus to know how to parse
790 struct xid_map_entry {
791 u_int32_t xid; /* transaction ID (net order) */
792 int ipver; /* IP version (4 or 6) */
794 struct in6_addr client; /* client IP address (net order) */
795 struct in6_addr server; /* server IP address (net order) */
797 struct in_addr client; /* client IP address (net order) */
798 struct in_addr server; /* server IP address (net order) */
800 u_int32_t proc; /* call proc number (host order) */
801 u_int32_t vers; /* program version (host order) */
805 * Map entries are kept in an array that we manage as a ring;
806 * new entries are always added at the tail of the ring. Initially,
807 * all the entries are zero and hence don't match anything.
810 #define XIDMAPSIZE 64
812 struct xid_map_entry xid_map[XIDMAPSIZE];
814 int xid_map_next = 0;
815 int xid_map_hint = 0;
818 xid_map_enter(const struct sunrpc_msg *rp, const u_char *bp)
820 struct ip *ip = NULL;
822 struct ip6_hdr *ip6 = NULL;
824 struct xid_map_entry *xmep;
826 switch (IP_V((struct ip *)bp)) {
828 ip = (struct ip *)bp;
832 ip6 = (struct ip6_hdr *)bp;
839 xmep = &xid_map[xid_map_next];
841 if (++xid_map_next >= XIDMAPSIZE)
844 xmep->xid = rp->rm_xid;
847 memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
848 memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
853 memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
854 memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
857 xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
858 xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
862 * Returns 0 and puts NFSPROC_xxx in proc return and
863 * version in vers return, or returns -1 on failure
866 xid_map_find(const struct sunrpc_msg *rp, const u_char *bp, u_int32_t *proc,
870 struct xid_map_entry *xmep;
871 u_int32_t xid = rp->rm_xid;
872 struct ip *ip = (struct ip *)bp;
874 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
878 /* Start searching from where we last left off */
883 if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
885 switch (xmep->ipver) {
887 if (memcmp(&ip->ip_src, &xmep->server,
888 sizeof(ip->ip_src)) != 0 ||
889 memcmp(&ip->ip_dst, &xmep->client,
890 sizeof(ip->ip_dst)) != 0) {
896 if (memcmp(&ip6->ip6_src, &xmep->server,
897 sizeof(ip6->ip6_src)) != 0 ||
898 memcmp(&ip6->ip6_dst, &xmep->client,
899 sizeof(ip6->ip6_dst)) != 0) {
916 if (++i >= XIDMAPSIZE)
918 } while (i != xid_map_hint);
925 * Routines for parsing reply packets
929 * Return a pointer to the beginning of the actual results.
930 * If the packet was truncated, return 0.
932 static const u_int32_t *
933 parserep(register const struct sunrpc_msg *rp, register u_int length)
935 register const u_int32_t *dp;
937 enum sunrpc_accept_stat astat;
941 * Here we find the address of the ar_verf credentials.
942 * Originally, this calculation was
943 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
944 * On the wire, the rp_acpt field starts immediately after
945 * the (32 bit) rp_stat field. However, rp_acpt (which is a
946 * "struct accepted_reply") contains a "struct opaque_auth",
947 * whose internal representation contains a pointer, so on a
948 * 64-bit machine the compiler inserts 32 bits of padding
949 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
950 * the internal representation to parse the on-the-wire
951 * representation. Instead, we skip past the rp_stat field,
952 * which is an "enum" and so occupies one 32-bit word.
954 dp = ((const u_int32_t *)&rp->rm_reply) + 1;
956 len = EXTRACT_32BITS(&dp[1]);
960 * skip past the ar_verf credentials.
962 dp += (len + (2*sizeof(u_int32_t) + 3)) / sizeof(u_int32_t);
966 * now we can check the ar_stat field
968 astat = (enum sunrpc_accept_stat) EXTRACT_32BITS(dp);
974 case SUNRPC_PROG_UNAVAIL:
975 printf(" PROG_UNAVAIL");
976 nfserr = 1; /* suppress trunc string */
979 case SUNRPC_PROG_MISMATCH:
980 printf(" PROG_MISMATCH");
981 nfserr = 1; /* suppress trunc string */
984 case SUNRPC_PROC_UNAVAIL:
985 printf(" PROC_UNAVAIL");
986 nfserr = 1; /* suppress trunc string */
989 case SUNRPC_GARBAGE_ARGS:
990 printf(" GARBAGE_ARGS");
991 nfserr = 1; /* suppress trunc string */
994 case SUNRPC_SYSTEM_ERR:
995 printf(" SYSTEM_ERR");
996 nfserr = 1; /* suppress trunc string */
1000 printf(" ar_stat %d", astat);
1001 nfserr = 1; /* suppress trunc string */
1004 /* successful return */
1005 TCHECK2(*dp, sizeof(astat));
1006 return ((u_int32_t *) (sizeof(astat) + ((char *)dp)));
1011 static const u_int32_t *
1012 parsestatus(const u_int32_t *dp, int *er)
1018 errnum = EXTRACT_32BITS(&dp[0]);
1023 printf(" ERROR: %s",
1024 tok2str(status2str, "unk %d", errnum));
1032 static const u_int32_t *
1033 parsefattr(const u_int32_t *dp, int verbose, int v3)
1035 const struct nfs_fattr *fap;
1037 fap = (const struct nfs_fattr *)dp;
1038 TCHECK(fap->fa_gid);
1040 printf(" %s %o ids %d/%d",
1041 tok2str(type2str, "unk-ft %d ",
1042 EXTRACT_32BITS(&fap->fa_type)),
1043 EXTRACT_32BITS(&fap->fa_mode),
1044 EXTRACT_32BITS(&fap->fa_uid),
1045 EXTRACT_32BITS(&fap->fa_gid));
1047 TCHECK(fap->fa3_size);
1048 printf(" sz %" PRIu64,
1049 EXTRACT_64BITS((u_int32_t *)&fap->fa3_size));
1051 TCHECK(fap->fa2_size);
1052 printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size));
1055 /* print lots more stuff */
1058 TCHECK(fap->fa3_ctime);
1059 printf(" nlink %d rdev %d/%d",
1060 EXTRACT_32BITS(&fap->fa_nlink),
1061 EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
1062 EXTRACT_32BITS(&fap->fa3_rdev.specdata2));
1063 printf(" fsid %" PRIx64,
1064 EXTRACT_64BITS((u_int32_t *)&fap->fa3_fsid));
1065 printf(" fileid %" PRIx64,
1066 EXTRACT_64BITS((u_int32_t *)&fap->fa3_fileid));
1067 printf(" a/m/ctime %u.%06u",
1068 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec),
1069 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec));
1071 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec),
1072 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec));
1074 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec),
1075 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec));
1077 TCHECK(fap->fa2_ctime);
1078 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1079 EXTRACT_32BITS(&fap->fa_nlink),
1080 EXTRACT_32BITS(&fap->fa2_rdev),
1081 EXTRACT_32BITS(&fap->fa2_fsid),
1082 EXTRACT_32BITS(&fap->fa2_fileid));
1084 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec),
1085 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec));
1087 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec),
1088 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec));
1090 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec),
1091 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec));
1094 return ((const u_int32_t *)((unsigned char *)dp +
1095 (v3 ? NFSX_V3FATTR : NFSX_V2FATTR)));
1101 parseattrstat(const u_int32_t *dp, int verbose, int v3)
1105 dp = parsestatus(dp, &er);
1111 return (parsefattr(dp, verbose, v3) != NULL);
1115 parsediropres(const u_int32_t *dp)
1119 if (!(dp = parsestatus(dp, &er)))
1124 dp = parsefh(dp, 0);
1128 return (parsefattr(dp, vflag, 0) != NULL);
1132 parselinkres(const u_int32_t *dp, int v3)
1136 dp = parsestatus(dp, &er);
1141 if (v3 && !(dp = parse_post_op_attr(dp, vflag)))
1144 return (parsefn(dp) != NULL);
1148 parsestatfs(const u_int32_t *dp, int v3)
1150 const struct nfs_statfs *sfsp;
1153 dp = parsestatus(dp, &er);
1165 if (!(dp = parse_post_op_attr(dp, vflag)))
1169 TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
1171 sfsp = (const struct nfs_statfs *)dp;
1174 printf(" tbytes %" PRIu64 " fbytes %" PRIu64 " abytes %" PRIu64,
1175 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_tbytes),
1176 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_fbytes),
1177 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_abytes));
1179 printf(" tfiles %" PRIu64 " ffiles %" PRIu64 " afiles %" PRIu64 " invar %u",
1180 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_tfiles),
1181 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_ffiles),
1182 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_afiles),
1183 EXTRACT_32BITS(&sfsp->sf_invarsec));
1186 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1187 EXTRACT_32BITS(&sfsp->sf_tsize),
1188 EXTRACT_32BITS(&sfsp->sf_bsize),
1189 EXTRACT_32BITS(&sfsp->sf_blocks),
1190 EXTRACT_32BITS(&sfsp->sf_bfree),
1191 EXTRACT_32BITS(&sfsp->sf_bavail));
1200 parserddires(const u_int32_t *dp)
1204 dp = parsestatus(dp, &er);
1213 printf(" offset %x size %d ",
1214 EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1]));
1223 static const u_int32_t *
1224 parse_wcc_attr(const u_int32_t *dp)
1226 printf(" sz %" PRIu64, EXTRACT_64BITS(&dp[0]));
1227 printf(" mtime %u.%06u ctime %u.%06u",
1228 EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
1229 EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5]));
1234 * Pre operation attributes. Print only if vflag > 1.
1236 static const u_int32_t *
1237 parse_pre_op_attr(const u_int32_t *dp, int verbose)
1240 if (!EXTRACT_32BITS(&dp[0]))
1245 return parse_wcc_attr(dp);
1247 /* If not verbose enough, just skip over wcc_attr */
1255 * Post operation attributes are printed if vflag >= 1
1257 static const u_int32_t *
1258 parse_post_op_attr(const u_int32_t *dp, int verbose)
1261 if (!EXTRACT_32BITS(&dp[0]))
1265 return parsefattr(dp, verbose, 1);
1267 return (dp + (NFSX_V3FATTR / sizeof (u_int32_t)));
1272 static const u_int32_t *
1273 parse_wcc_data(const u_int32_t *dp, int verbose)
1277 if (!(dp = parse_pre_op_attr(dp, verbose)))
1282 return parse_post_op_attr(dp, verbose);
1285 static const u_int32_t *
1286 parsecreateopres(const u_int32_t *dp, int verbose)
1290 if (!(dp = parsestatus(dp, &er)))
1293 dp = parse_wcc_data(dp, verbose);
1296 if (!EXTRACT_32BITS(&dp[0]))
1299 if (!(dp = parsefh(dp, 1)))
1302 if (!(dp = parse_post_op_attr(dp, verbose)))
1305 printf(" dir attr:");
1306 dp = parse_wcc_data(dp, verbose);
1316 parsewccres(const u_int32_t *dp, int verbose)
1320 if (!(dp = parsestatus(dp, &er)))
1322 return parse_wcc_data(dp, verbose) != 0;
1325 static const u_int32_t *
1326 parsev3rddirres(const u_int32_t *dp, int verbose)
1330 if (!(dp = parsestatus(dp, &er)))
1334 if (!(dp = parse_post_op_attr(dp, verbose)))
1340 printf(" verf %08x%08x", dp[0], dp[1]);
1349 parsefsinfo(const u_int32_t *dp)
1351 struct nfsv3_fsinfo *sfp;
1354 if (!(dp = parsestatus(dp, &er)))
1358 if (!(dp = parse_post_op_attr(dp, vflag)))
1363 sfp = (struct nfsv3_fsinfo *)dp;
1365 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1366 EXTRACT_32BITS(&sfp->fs_rtmax),
1367 EXTRACT_32BITS(&sfp->fs_rtpref),
1368 EXTRACT_32BITS(&sfp->fs_wtmax),
1369 EXTRACT_32BITS(&sfp->fs_wtpref),
1370 EXTRACT_32BITS(&sfp->fs_dtpref));
1372 printf(" rtmult %u wtmult %u maxfsz %" PRIu64,
1373 EXTRACT_32BITS(&sfp->fs_rtmult),
1374 EXTRACT_32BITS(&sfp->fs_wtmult),
1375 EXTRACT_64BITS((u_int32_t *)&sfp->fs_maxfilesize));
1376 printf(" delta %u.%06u ",
1377 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
1378 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec));
1386 parsepathconf(const u_int32_t *dp)
1389 struct nfsv3_pathconf *spp;
1391 if (!(dp = parsestatus(dp, &er)))
1395 if (!(dp = parse_post_op_attr(dp, vflag)))
1400 spp = (struct nfsv3_pathconf *)dp;
1403 printf(" linkmax %u namemax %u %s %s %s %s",
1404 EXTRACT_32BITS(&spp->pc_linkmax),
1405 EXTRACT_32BITS(&spp->pc_namemax),
1406 EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
1407 EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
1408 EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
1409 EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : "");
1416 interp_reply(const struct sunrpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
1418 register const u_int32_t *dp;
1422 v3 = (vers == NFS_VER3);
1424 if (!v3 && proc < NFS_NPROCS)
1425 proc = nfsv3_procid[proc];
1437 case NFSPROC_GETATTR:
1439 dp = parserep(rp, length);
1440 if (dp != NULL && parseattrstat(dp, !qflag, v3) != 0)
1444 case NFSPROC_SETATTR:
1446 if (!(dp = parserep(rp, length)))
1449 if (parsewccres(dp, vflag))
1452 if (parseattrstat(dp, !qflag, 0) != 0)
1457 case NFSPROC_LOOKUP:
1459 if (!(dp = parserep(rp, length)))
1462 if (!(dp = parsestatus(dp, &er)))
1466 printf(" post dattr:");
1467 dp = parse_post_op_attr(dp, vflag);
1470 if (!(dp = parsefh(dp, v3)))
1472 if ((dp = parse_post_op_attr(dp, vflag)) &&
1474 printf(" post dattr:");
1475 dp = parse_post_op_attr(dp, vflag);
1481 if (parsediropres(dp) != 0)
1486 case NFSPROC_ACCESS:
1488 if (!(dp = parserep(rp, length)))
1490 if (!(dp = parsestatus(dp, &er)))
1494 if (!(dp = parse_post_op_attr(dp, vflag)))
1497 printf(" c %04x", EXTRACT_32BITS(&dp[0]));
1500 case NFSPROC_READLINK:
1501 printf(" readlink");
1502 dp = parserep(rp, length);
1503 if (dp != NULL && parselinkres(dp, v3) != 0)
1509 if (!(dp = parserep(rp, length)))
1512 if (!(dp = parsestatus(dp, &er)))
1514 if (!(dp = parse_post_op_attr(dp, vflag)))
1520 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1521 if (EXTRACT_32BITS(&dp[1]))
1526 if (parseattrstat(dp, vflag, 0) != 0)
1533 if (!(dp = parserep(rp, length)))
1536 if (!(dp = parsestatus(dp, &er)))
1538 if (!(dp = parse_wcc_data(dp, vflag)))
1544 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1548 tok2str(nfsv3_writemodes,
1549 NULL, EXTRACT_32BITS(&dp[1])));
1554 if (parseattrstat(dp, vflag, v3) != 0)
1559 case NFSPROC_CREATE:
1561 if (!(dp = parserep(rp, length)))
1564 if (parsecreateopres(dp, vflag) != 0)
1567 if (parsediropres(dp) != 0)
1574 if (!(dp = parserep(rp, length)))
1577 if (parsecreateopres(dp, vflag) != 0)
1580 if (parsediropres(dp) != 0)
1585 case NFSPROC_SYMLINK:
1587 if (!(dp = parserep(rp, length)))
1590 if (parsecreateopres(dp, vflag) != 0)
1593 if (parsestatus(dp, &er) != 0)
1600 if (!(dp = parserep(rp, length)))
1602 if (parsecreateopres(dp, vflag) != 0)
1606 case NFSPROC_REMOVE:
1608 if (!(dp = parserep(rp, length)))
1611 if (parsewccres(dp, vflag))
1614 if (parsestatus(dp, &er) != 0)
1621 if (!(dp = parserep(rp, length)))
1624 if (parsewccres(dp, vflag))
1627 if (parsestatus(dp, &er) != 0)
1632 case NFSPROC_RENAME:
1634 if (!(dp = parserep(rp, length)))
1637 if (!(dp = parsestatus(dp, &er)))
1641 if (!(dp = parse_wcc_data(dp, vflag)))
1644 if (!(dp = parse_wcc_data(dp, vflag)))
1649 if (parsestatus(dp, &er) != 0)
1656 if (!(dp = parserep(rp, length)))
1659 if (!(dp = parsestatus(dp, &er)))
1662 printf(" file POST:");
1663 if (!(dp = parse_post_op_attr(dp, vflag)))
1666 if (!(dp = parse_wcc_data(dp, vflag)))
1671 if (parsestatus(dp, &er) != 0)
1676 case NFSPROC_READDIR:
1678 if (!(dp = parserep(rp, length)))
1681 if (parsev3rddirres(dp, vflag))
1684 if (parserddires(dp) != 0)
1689 case NFSPROC_READDIRPLUS:
1690 printf(" readdirplus");
1691 if (!(dp = parserep(rp, length)))
1693 if (parsev3rddirres(dp, vflag))
1697 case NFSPROC_FSSTAT:
1699 dp = parserep(rp, length);
1700 if (dp != NULL && parsestatfs(dp, v3) != 0)
1704 case NFSPROC_FSINFO:
1706 dp = parserep(rp, length);
1707 if (dp != NULL && parsefsinfo(dp) != 0)
1711 case NFSPROC_PATHCONF:
1712 printf(" pathconf");
1713 dp = parserep(rp, length);
1714 if (dp != NULL && parsepathconf(dp) != 0)
1718 case NFSPROC_COMMIT:
1720 dp = parserep(rp, length);
1721 if (dp != NULL && parsewccres(dp, vflag) != 0)
1726 printf(" proc-%u", proc);
1731 fputs(" [|nfs]", stdout);