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[] =
24 "@(#) $Header: print-nfs.c,v 1.65 97/08/17 13:24:22 leres Exp $ (LBL)";
27 #include <sys/param.h>
29 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <net/ethernet.h>
35 #include <netinet/in_systm.h>
36 #include <netinet/ip.h>
37 #include <netinet/ip_var.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "extract.h" /* must come after interface.h */
53 static void nfs_printfh(const u_int32_t *, const int);
54 static void xid_map_enter(const struct rpc_msg *, const struct ip *);
55 static int32_t xid_map_find(const struct rpc_msg *, const struct ip *, 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);
60 static int nfserr; /* true if we error rather than trunc */
63 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
65 u_int32_t nfsv3_procid[NFS_NPROCS] = {
94 const char *nfsv3_writemodes[NFSV3WRITE_NMODES] = {
100 static struct tok type2str[] = {
112 * Print out a 64-bit integer. This appears to be different on each system,
113 * try to make the best of it. The integer stored as 2 consecutive XDR
114 * encoded 32-bit integers, to which a pointer is passed.
116 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
117 * integer datatype and can print it.
124 #define INT64_FORMAT "%qd"
125 #define U_INT64_FORMAT "%qu"
126 #define HEX_INT64_FORMAT "%qx"
128 int print_int64(const u_int32_t *dp, int how)
133 res = ((u_int64_t)ntohl(dp[0]) << 32) | (u_int64_t)ntohl(dp[1]);
136 printf(INT64_FORMAT, res);
139 printf(U_INT64_FORMAT, res);
142 printf(HEX_INT64_FORMAT, res);
149 * XXX - throw upper 32 bits away.
150 * Could also go for hex: printf("0x%x%x", dp[0], dp[1]);
153 printf("%ld", (int)dp[1]);
155 printf("%lu", (unsigned int)dp[1]);
160 static const u_int32_t *
161 parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3)
163 register const u_int32_t *ep = (u_int32_t *)snapend;
167 if ((sa3->sa_modeset = ntohl(*dp++))) {
170 sa3->sa_mode = ntohl(*dp++);
175 if ((sa3->sa_uidset = ntohl(*dp++))) {
178 sa3->sa_uid = ntohl(*dp++);
183 if ((sa3->sa_gidset = ntohl(*dp++))) {
186 sa3->sa_gid = ntohl(*dp++);
191 if ((sa3->sa_sizeset = ntohl(*dp++))) {
194 sa3->sa_size = ntohl(*dp++);
199 if ((sa3->sa_atimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) {
202 sa3->sa_atime.nfsv3_sec = ntohl(*dp++);
203 sa3->sa_atime.nfsv3_nsec = ntohl(*dp++);
208 if ((sa3->sa_mtimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) {
211 sa3->sa_mtime.nfsv3_sec = ntohl(*dp++);
212 sa3->sa_mtime.nfsv3_nsec = ntohl(*dp++);
219 print_sattr3(const struct nfsv3_sattr *sa3, int verbose)
222 printf(" mode %o", sa3->sa_mode);
224 printf(" uid %u", sa3->sa_uid);
226 printf(" gid %u", sa3->sa_gid);
228 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT)
229 printf(" atime %u.%06u", sa3->sa_atime.nfsv3_sec,
230 sa3->sa_atime.nfsv3_nsec);
231 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT)
232 printf(" mtime %u.%06u", sa3->sa_mtime.nfsv3_sec,
233 sa3->sa_mtime.nfsv3_nsec);
238 nfsreply_print(register const u_char *bp, u_int length,
239 register const u_char *bp2)
241 register const struct rpc_msg *rp;
242 register const struct ip *ip;
243 u_int32_t proc, vers;
245 nfserr = 0; /* assume no error */
246 rp = (const struct rpc_msg *)bp;
247 ip = (const struct ip *)bp2;
250 (void)printf("%s.nfs > %s.%u: reply %s %d",
251 ipaddr_string(&ip->ip_src),
252 ipaddr_string(&ip->ip_dst),
253 (u_int32_t)ntohl(rp->rm_xid),
254 ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED?
258 (void)printf("%s.%u > %s.%u: reply %s %d",
259 ipaddr_string(&ip->ip_src),
261 ipaddr_string(&ip->ip_dst),
262 (u_int32_t)ntohl(rp->rm_xid),
263 ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED?
267 if (xid_map_find(rp, ip, &proc, &vers) >= 0)
268 interp_reply(rp, proc, vers, length);
272 * Return a pointer to the first file handle in the packet.
273 * If the packet was truncated, return NULL.
275 static const u_int32_t *
276 parsereq(register const struct rpc_msg *rp, register int length)
278 register const u_int32_t *dp;
282 * find the start of the req data (if we captured it)
284 dp = (u_int32_t *)&rp->rm_call.cb_cred;
288 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
292 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
302 * Print out an NFS file handle and return a pointer to following word.
303 * If packet was truncated, return NULL.
305 static const u_int32_t *
306 parsefh(register const u_int32_t *dp, int v3)
312 len = (int)ntohl(*dp) / 4;
317 if (TTEST2(*dp, len * sizeof(*dp))) {
318 nfs_printfh(dp, len);
326 * Print out a file name and return pointer to 32-bit word past it.
327 * If packet was truncated, return NULL.
329 static const u_int32_t *
330 parsefn(register const u_int32_t *dp)
332 register u_int32_t len;
333 register const u_char *cp;
335 /* Bail if we don't have the string length */
336 if ((u_char *)dp > snapend - sizeof(*dp))
339 /* Fetch string length; convert to host order */
344 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
345 dp += ((len + 3) & ~3) / sizeof(*dp);
346 if ((u_char *)dp > snapend)
348 /* XXX seems like we should be checking the length */
350 (void) fn_printn(cp, len, NULL);
357 * Print out file handle and file name.
358 * Return pointer to 32-bit word past file name.
359 * If packet was truncated (or there was some other error), return NULL.
361 static const u_int32_t *
362 parsefhn(register const u_int32_t *dp, int v3)
364 dp = parsefh(dp, v3);
368 return (parsefn(dp));
372 nfsreq_print(register const u_char *bp, u_int length,
373 register const u_char *bp2)
375 register const struct rpc_msg *rp;
376 register const struct ip *ip;
377 register const u_int32_t *dp;
380 struct nfsv3_sattr sa3;
382 nfserr = 0; /* assume no error */
383 rp = (const struct rpc_msg *)bp;
384 ip = (const struct ip *)bp2;
386 (void)printf("%s.%u > %s.nfs: %d",
387 ipaddr_string(&ip->ip_src),
388 (u_int32_t)ntohl(rp->rm_xid),
389 ipaddr_string(&ip->ip_dst),
392 (void)printf("%s.%u > %s.%u: %d",
393 ipaddr_string(&ip->ip_src),
394 (u_int32_t)ntohl(rp->rm_xid),
395 ipaddr_string(&ip->ip_dst),
399 xid_map_enter(rp, ip); /* record proc number for later on */
401 v3 = (ntohl(rp->rm_call.cb_vers) == NFS_VER3);
402 proc = ntohl(rp->rm_call.cb_proc);
404 if (!v3 && proc < NFS_NPROCS)
405 proc = nfsv3_procid[proc];
415 case NFSPROC_GETATTR:
417 if ((dp = parsereq(rp, length)) != NULL && parsefh(dp, v3) != NULL)
421 case NFSPROC_SETATTR:
423 if ((dp = parsereq(rp, length)) != NULL && parsefh(dp, v3) != NULL)
429 if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp, v3) != NULL)
435 if ((dp = parsereq(rp, length)) != NULL &&
436 (dp = parsefh(dp, v3)) != NULL) {
438 printf(" %04lx", ntohl(dp[0]));
443 case NFSPROC_READLINK:
445 if ((dp = parsereq(rp, length)) != NULL && parsefh(dp, v3) != NULL)
451 if ((dp = parsereq(rp, length)) != NULL &&
452 (dp = parsefh(dp, v3)) != NULL) {
454 TCHECK2(*dp, 3 * sizeof(*dp));
455 printf(" %lu bytes @ ", ntohl(dp[2]));
456 print_int64(dp, UNSIGNED);
458 TCHECK2(*dp, 2 * sizeof(*dp));
459 printf(" %lu bytes @ %lu",
460 ntohl(dp[1]), ntohl(dp[0]));
468 if ((dp = parsereq(rp, length)) != NULL &&
469 (dp = parsefh(dp, v3)) != NULL) {
471 TCHECK2(*dp, 3 * sizeof(*dp));
472 printf(" %lu bytes @ ", ntohl(dp[4]));
473 print_int64(dp, UNSIGNED);
476 TCHECK2(*dp, sizeof(*dp));
478 nfsv3_writemodes[ntohl(*dp)]);
481 TCHECK2(*dp, 4 * sizeof(*dp));
482 printf(" %lu (%lu) bytes @ %lu (%lu)",
483 ntohl(dp[3]), ntohl(dp[2]),
484 ntohl(dp[1]), ntohl(dp[0]));
492 if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp, v3) != NULL)
498 if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp, v3) != NULL)
502 case NFSPROC_SYMLINK:
504 if ((dp = parsereq(rp, length)) != NULL &&
505 (dp = parsefhn(dp, v3)) != NULL) {
506 fputs(" -> ", stdout);
507 if (v3 && (dp = parse_sattr3(dp, &sa3)) == NULL)
509 if (parsefn(dp) == NULL)
512 print_sattr3(&sa3, vflag);
519 if ((dp = parsereq(rp, length)) != NULL &&
520 (dp = parsefhn(dp, v3)) != NULL) {
521 if (dp + 1 > (u_int32_t *)snapend)
523 type = (nfstype)ntohl(*dp++);
524 if ((dp = parse_sattr3(dp, &sa3)) == NULL)
526 printf(" %s", tok2str(type2str, "unk-ft %d", type));
527 if (vflag && (type == NFCHR || type == NFBLK)) {
528 if (dp + 2 > (u_int32_t *)snapend)
530 printf(" %lu/%lu", ntohl(dp[0]), ntohl(dp[1]));
534 print_sattr3(&sa3, vflag);
541 if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp, v3) != NULL)
547 if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp, v3) != NULL)
553 if ((dp = parsereq(rp, length)) != NULL &&
554 (dp = parsefhn(dp, v3)) != NULL) {
555 fputs(" ->", stdout);
556 if (parsefhn(dp, v3) != NULL)
563 if ((dp = parsereq(rp, length)) != NULL &&
564 (dp = parsefh(dp, v3)) != NULL) {
565 fputs(" ->", stdout);
566 if (parsefhn(dp, v3) != NULL)
571 case NFSPROC_READDIR:
573 if ((dp = parsereq(rp, length)) != NULL &&
574 (dp = parsefh(dp, v3)) != NULL) {
578 * We shouldn't really try to interpret the
579 * offset cookie here.
581 printf(" %lu bytes @ ", ntohl(dp[4]));
582 print_int64(dp, SIGNED);
584 printf(" verf %08x%08x", dp[2],
587 TCHECK2(*dp, 2 * sizeof(*dp));
589 * Print the offset as signed, since -1 is
590 * common, but offsets > 2^31 aren't.
592 printf(" %lu bytes @ %ld", ntohl(dp[1]),
599 case NFSPROC_READDIRPLUS:
600 printf(" readdirplus");
601 if ((dp = parsereq(rp, length)) != NULL &&
602 (dp = parsefh(dp, v3)) != NULL) {
605 * We don't try to interpret the offset
608 printf(" %lu bytes @ ", ntohl(dp[4]));
609 print_int64(dp, SIGNED);
611 printf(" max %lu verf %08x%08x",
612 ntohl(dp[5]), dp[2], dp[3]);
619 if ((dp = parsereq(rp, length)) != NULL && parsefh(dp, v3) != NULL)
627 case NFSPROC_PATHCONF:
633 if ((dp = parsereq(rp, length)) != NULL &&
634 (dp = parsefh(dp, v3)) != NULL) {
635 printf(" %lu bytes @ ", ntohl(dp[2]));
636 print_int64(dp, UNSIGNED);
642 printf(" proc-%lu", ntohl(rp->rm_call.cb_proc));
647 fputs(" [|nfs]", stdout);
651 * Print out an NFS file handle.
652 * We assume packet was not truncated before the end of the
653 * file handle pointed to by dp.
655 * Note: new version (using portable file-handle parser) doesn't produce
656 * generation number. It probably could be made to do that, with some
657 * additional hacking on the parser code.
660 nfs_printfh(register const u_int32_t *dp, const int len)
664 char *sfsname = NULL;
666 Parse_fh((caddr_t *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
669 /* file system ID is ASCII, not numeric, for this server OS */
670 static char temp[NFSX_V3FHMAX+1];
672 /* Make sure string is null-terminated */
673 strncpy(temp, sfsname, NFSX_V3FHMAX);
674 /* Remove trailing spaces */
675 sfsname = strchr(temp, ' ');
679 (void)printf(" fh %s/%u", temp, (u_int32_t)ino);
681 (void)printf(" fh %u,%u/%u",
682 fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor, (u_int32_t)ino);
687 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
688 * us to match up replies with requests and thus to know how to parse
692 struct xid_map_entry {
693 u_int32_t xid; /* transaction ID (net order) */
694 struct in_addr client; /* client IP address (net order) */
695 struct in_addr server; /* server IP address (net order) */
696 u_int32_t proc; /* call proc number (host order) */
697 u_int32_t vers; /* program version (host order) */
701 * Map entries are kept in an array that we manage as a ring;
702 * new entries are always added at the tail of the ring. Initially,
703 * all the entries are zero and hence don't match anything.
706 #define XIDMAPSIZE 64
708 struct xid_map_entry xid_map[XIDMAPSIZE];
710 int xid_map_next = 0;
711 int xid_map_hint = 0;
714 xid_map_enter(const struct rpc_msg *rp, const struct ip *ip)
716 struct xid_map_entry *xmep;
718 xmep = &xid_map[xid_map_next];
720 if (++xid_map_next >= XIDMAPSIZE)
723 xmep->xid = rp->rm_xid;
724 xmep->client = ip->ip_src;
725 xmep->server = ip->ip_dst;
726 xmep->proc = ntohl(rp->rm_call.cb_proc);
727 xmep->vers = ntohl(rp->rm_call.cb_vers);
731 * Returns 0 and puts NFSPROC_xxx in proc return and
732 * version in vers return, or returns -1 on failure
735 xid_map_find(const struct rpc_msg *rp, const struct ip *ip, u_int32_t *proc,
739 struct xid_map_entry *xmep;
740 u_int32_t xid = rp->rm_xid;
741 u_int32_t clip = ip->ip_dst.s_addr;
742 u_int32_t sip = ip->ip_src.s_addr;
744 /* Start searching from where we last left off */
748 if (xmep->xid == xid && xmep->client.s_addr == clip &&
749 xmep->server.s_addr == sip) {
756 if (++i >= XIDMAPSIZE)
758 } while (i != xid_map_hint);
765 * Routines for parsing reply packets
769 * Return a pointer to the beginning of the actual results.
770 * If the packet was truncated, return NULL.
772 static const u_int32_t *
773 parserep(register const struct rpc_msg *rp, register int length)
775 register const u_int32_t *dp;
777 enum accept_stat astat;
781 * Here we find the address of the ar_verf credentials.
782 * Originally, this calculation was
783 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
784 * On the wire, the rp_acpt field starts immediately after
785 * the (32 bit) rp_stat field. However, rp_acpt (which is a
786 * "struct accepted_reply") contains a "struct opaque_auth",
787 * whose internal representation contains a pointer, so on a
788 * 64-bit machine the compiler inserts 32 bits of padding
789 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
790 * the internal representation to parse the on-the-wire
791 * representation. Instead, we skip past the rp_stat field,
792 * which is an "enum" and so occupies one 32-bit word.
794 dp = ((const u_int32_t *)&rp->rm_reply) + 1;
800 * skip past the ar_verf credentials.
802 dp += (len + (2*sizeof(u_int32_t) + 3)) / sizeof(u_int32_t);
806 * now we can check the ar_stat field
808 astat = ntohl(*(enum accept_stat *)dp);
815 printf(" PROG_UNAVAIL");
816 nfserr = 1; /* suppress trunc string */
820 printf(" PROG_MISMATCH");
821 nfserr = 1; /* suppress trunc string */
825 printf(" PROC_UNAVAIL");
826 nfserr = 1; /* suppress trunc string */
830 printf(" GARBAGE_ARGS");
831 nfserr = 1; /* suppress trunc string */
835 printf(" SYSTEM_ERR");
836 nfserr = 1; /* suppress trunc string */
840 printf(" ar_stat %d", astat);
841 nfserr = 1; /* suppress trunc string */
844 /* successful return */
845 if ((sizeof(astat) + ((u_char *)dp)) < snapend)
846 return ((u_int32_t *) (sizeof(astat) + ((char *)dp)));
853 static const u_int32_t *
854 parsestatus(const u_int32_t *dp, int *er)
859 errnum = ntohl(dp[0]);
864 printf(" ERROR: %s", pcap_strerror(errnum));
873 static const u_int32_t *
874 parsefattr(const u_int32_t *dp, int verbose, int v3)
876 const struct nfs_fattr *fap;
878 fap = (const struct nfs_fattr *)dp;
881 printf(" %s %lo ids %ld/%ld",
882 tok2str(type2str, "unk-ft %d ", ntohl(fap->fa_type)),
883 ntohl(fap->fa_mode), ntohl(fap->fa_uid),
886 TCHECK(fap->fa3_size);
888 print_int64((u_int32_t *)&fap->fa3_size, UNSIGNED);
891 TCHECK(fap->fa2_size);
892 printf(" sz %ld ", ntohl(fap->fa2_size));
895 /* print lots more stuff */
898 TCHECK(fap->fa3_ctime);
899 printf("nlink %ld rdev %ld/%ld ",
900 ntohl(fap->fa_nlink),
901 ntohl(fap->fa3_rdev.specdata1),
902 ntohl(fap->fa3_rdev.specdata2));
904 print_int64((u_int32_t *)&fap->fa2_fsid, HEX);
906 print_int64((u_int32_t *)&fap->fa2_fileid, HEX);
907 printf(" a/m/ctime %lu.%06lu ",
908 ntohl(fap->fa3_atime.nfsv3_sec),
909 ntohl(fap->fa3_atime.nfsv3_nsec));
911 ntohl(fap->fa3_mtime.nfsv3_sec),
912 ntohl(fap->fa3_mtime.nfsv3_nsec));
914 ntohl(fap->fa3_ctime.nfsv3_sec),
915 ntohl(fap->fa3_ctime.nfsv3_nsec));
917 TCHECK(fap->fa2_ctime);
918 printf("nlink %ld rdev %lx fsid %lx nodeid %lx a/m/ctime ",
919 ntohl(fap->fa_nlink), ntohl(fap->fa2_rdev),
920 ntohl(fap->fa2_fsid), ntohl(fap->fa2_fileid));
922 ntohl(fap->fa2_atime.nfsv2_sec),
923 ntohl(fap->fa2_atime.nfsv2_usec));
925 ntohl(fap->fa2_mtime.nfsv2_sec),
926 ntohl(fap->fa2_mtime.nfsv2_usec));
928 ntohl(fap->fa2_ctime.nfsv2_sec),
929 ntohl(fap->fa2_ctime.nfsv2_usec));
932 return ((const u_int32_t *)((unsigned char *)dp +
933 (v3 ? NFSX_V3FATTR : NFSX_V2FATTR)));
939 parseattrstat(const u_int32_t *dp, int verbose, int v3)
943 dp = parsestatus(dp, &er);
944 if (dp == NULL || er)
947 return (parsefattr(dp, verbose, v3) != NULL);
951 parsediropres(const u_int32_t *dp)
955 dp = parsestatus(dp, &er);
956 if (dp == NULL || er)
963 return (parsefattr(dp, vflag, 0) != NULL);
967 parselinkres(const u_int32_t *dp, int v3)
971 dp = parsestatus(dp, &er);
972 if (dp == NULL || er)
975 if (v3 && ((dp = parse_post_op_attr(dp, vflag)) != NULL))
979 return (parsefn(dp) != NULL);
983 parsestatfs(const u_int32_t *dp, int v3)
985 const struct nfs_statfs *sfsp;
988 dp = parsestatus(dp, &er);
989 if (dp == NULL || (!v3 && er))
998 if ((dp = parse_post_op_attr(dp, vflag)) == NULL)
1002 TCHECK2(dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
1004 sfsp = (const struct nfs_statfs *)dp;
1008 print_int64((u_int32_t *)&sfsp->sf_tbytes, UNSIGNED);
1010 print_int64((u_int32_t *)&sfsp->sf_fbytes, UNSIGNED);
1012 print_int64((u_int32_t *)&sfsp->sf_abytes, UNSIGNED);
1015 print_int64((u_int32_t *)&sfsp->sf_tfiles, UNSIGNED);
1017 print_int64((u_int32_t *)&sfsp->sf_ffiles, UNSIGNED);
1019 print_int64((u_int32_t *)&sfsp->sf_afiles, UNSIGNED);
1020 printf(" invar %lu", ntohl(sfsp->sf_invarsec));
1023 printf(" tsize %ld bsize %ld blocks %ld bfree %ld bavail %ld",
1024 ntohl(sfsp->sf_tsize), ntohl(sfsp->sf_bsize),
1025 ntohl(sfsp->sf_blocks), ntohl(sfsp->sf_bfree),
1026 ntohl(sfsp->sf_bavail));
1035 parserddires(const u_int32_t *dp)
1039 dp = parsestatus(dp, &er);
1040 if (dp == NULL || er)
1046 printf(" offset %lx size %ld ", ntohl(dp[0]), ntohl(dp[1]));
1055 static const u_int32_t *
1056 parse_wcc_attr(const u_int32_t *dp)
1059 print_int64(dp, UNSIGNED);
1060 printf(" mtime %lu.%06lu ctime %lu.%06lu", ntohl(dp[2]), ntohl(dp[3]),
1061 ntohl(dp[4]), ntohl(dp[5]));
1066 * Pre operation attributes. Print only if vflag > 1.
1068 static const u_int32_t *
1069 parse_pre_op_attr(const u_int32_t *dp, int verbose)
1077 return parse_wcc_attr(dp);
1079 /* If not verbose enough, just skip over wcc_attr */
1087 * Post operation attributes are printed if vflag >= 1
1089 static const u_int32_t *
1090 parse_post_op_attr(const u_int32_t *dp, int verbose)
1097 return parsefattr(dp, verbose, 1);
1099 return (dp + (NFSX_V3FATTR / sizeof (u_int32_t)));
1104 static const u_int32_t *
1105 parse_wcc_data(const u_int32_t *dp, int verbose)
1109 if ((dp = parse_pre_op_attr(dp, verbose)) == NULL)
1114 return parse_post_op_attr(dp, verbose);
1117 static const u_int32_t *
1118 parsecreateopres(const u_int32_t *dp, int verbose)
1122 if ((dp = parsestatus(dp, &er)) == NULL)
1125 dp = parse_wcc_data(dp, verbose);
1131 if ((dp = parsefh(dp, 1)) == NULL)
1134 if ((dp = parse_post_op_attr(dp, verbose)) == NULL)
1137 printf("dir attr:");
1138 dp = parse_wcc_data(dp, verbose);
1148 parsewccres(const u_int32_t *dp, int verbose)
1152 if ((dp = parsestatus(dp, &er)) == NULL)
1154 return parse_wcc_data(dp, verbose) != NULL;
1157 static const u_int32_t *
1158 parsev3rddirres(const u_int32_t *dp, int verbose)
1162 if ((dp = parsestatus(dp, &er)) == NULL)
1166 if ((dp = parse_post_op_attr(dp, verbose)) == NULL)
1172 printf(" verf %08x%08x", dp[0], dp[1]);
1181 parsefsinfo(const u_int32_t *dp)
1183 struct nfsv3_fsinfo *sfp;
1186 if ((dp = parsestatus(dp, &er)) == NULL)
1190 if ((dp = parse_post_op_attr(dp, vflag)) == NULL)
1195 sfp = (struct nfsv3_fsinfo *)dp;
1197 printf(" rtmax %lu rtpref %lu wtmax %lu wtpref %lu dtpref %lu",
1198 ntohl(sfp->fs_rtmax), ntohl(sfp->fs_rtpref),
1199 ntohl(sfp->fs_wtmax), ntohl(sfp->fs_wtpref),
1200 ntohl(sfp->fs_dtpref));
1202 printf(" rtmult %lu wtmult %lu maxfsz ",
1203 ntohl(sfp->fs_rtmult), ntohl(sfp->fs_wtmult));
1204 print_int64((u_int32_t *)&sfp->fs_maxfilesize, UNSIGNED);
1205 printf(" delta %lu.%06lu ", ntohl(sfp->fs_timedelta.nfsv3_sec),
1206 ntohl(sfp->fs_timedelta.nfsv3_nsec));
1214 parsepathconf(const u_int32_t *dp)
1217 struct nfsv3_pathconf *spp;
1219 if ((dp = parsestatus(dp, &er)) == NULL)
1223 if ((dp = parse_post_op_attr(dp, vflag)) == NULL)
1228 spp = (struct nfsv3_pathconf *)dp;
1231 printf(" linkmax %lu namemax %lu %s %s %s %s",
1232 ntohl(spp->pc_linkmax),
1233 ntohl(spp->pc_namemax),
1234 ntohl(spp->pc_notrunc) ? "notrunc" : "",
1235 ntohl(spp->pc_chownrestricted) ? "chownres" : "",
1236 ntohl(spp->pc_caseinsensitive) ? "igncase" : "",
1237 ntohl(spp->pc_casepreserving) ? "keepcase" : "");
1244 interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
1246 register const u_int32_t *dp;
1251 v3 = (vers == NFS_VER3);
1253 if (!v3 && proc < NFS_NPROCS)
1254 proc = nfsv3_procid[proc];
1266 case NFSPROC_GETATTR:
1268 dp = parserep(rp, length);
1269 if (dp != NULL && parseattrstat(dp, !qflag, v3) != 0)
1273 case NFSPROC_SETATTR:
1275 if ((dp = parserep(rp, length)) == NULL)
1278 if (parsewccres(dp, vflag) != 0)
1281 if (parseattrstat(dp, !qflag, 0) != 0)
1286 case NFSPROC_LOOKUP:
1288 if ((dp = parserep(rp, length)) == NULL)
1291 if ((dp = parsestatus(dp, &er)) == NULL)
1295 printf(" post dattr:");
1296 dp = parse_post_op_attr(dp, vflag);
1299 if ((dp = parsefh(dp, v3)) == NULL)
1301 if (((dp = parse_post_op_attr(dp, vflag)) != NULL) &&
1303 printf(" post dattr:");
1304 dp = parse_post_op_attr(dp, vflag);
1310 if (parsediropres(dp) != 0)
1315 case NFSPROC_ACCESS:
1317 dp = parserep(rp, length);
1318 if ((dp = parsestatus(dp, &er)) == NULL)
1322 if ((dp = parse_post_op_attr(dp, vflag)) == NULL)
1325 printf(" c %04lx", ntohl(dp[0]));
1328 case NFSPROC_READLINK:
1329 printf(" readlink");
1330 dp = parserep(rp, length);
1331 if (dp != NULL && parselinkres(dp, v3) != 0)
1337 if ((dp = parserep(rp, length)) == NULL)
1340 if ((dp = parsestatus(dp, &er)) == NULL)
1342 if ((dp = parse_post_op_attr(dp, vflag)) == NULL)
1348 printf("%lu bytes", ntohl(dp[0]));
1354 if (parseattrstat(dp, vflag, 0) != 0)
1361 if ((dp = parserep(rp, length)) == NULL)
1364 if ((dp = parsestatus(dp, &er)) == NULL)
1366 if ((dp = parse_wcc_data(dp, vflag)) == NULL)
1372 printf("%lu bytes", ntohl(dp[0]));
1376 nfsv3_writemodes[ntohl(dp[1])]);
1381 if (parseattrstat(dp, vflag, v3) != 0)
1386 case NFSPROC_CREATE:
1388 if ((dp = parserep(rp, length)) == NULL)
1391 if (parsecreateopres(dp, vflag) != NULL)
1394 if (parsediropres(dp) != 0)
1401 if ((dp = parserep(rp, length)) == NULL)
1404 if (parsecreateopres(dp, vflag) != NULL)
1407 if (parsediropres(dp) != 0)
1412 case NFSPROC_SYMLINK:
1414 if ((dp = parserep(rp, length)) == NULL)
1417 if (parsecreateopres(dp, vflag) != NULL)
1420 if (parsestatus(dp, &er) != NULL)
1427 if ((dp = parserep(rp, length)) == NULL)
1429 if (parsecreateopres(dp, vflag) != NULL)
1433 case NFSPROC_REMOVE:
1435 if ((dp = parserep(rp, length)) == NULL)
1438 if (parsewccres(dp, vflag) != 0)
1441 if (parsestatus(dp, &er) != NULL)
1448 if ((dp = parserep(rp, length)) == NULL)
1451 if (parsewccres(dp, vflag) != 0)
1454 if (parsestatus(dp, &er) != NULL)
1459 case NFSPROC_RENAME:
1461 if ((dp = parserep(rp, length)) == NULL)
1464 if ((dp = parsestatus(dp, &er)) == NULL)
1468 if ((dp = parse_wcc_data(dp, vflag)) == NULL)
1471 if ((dp = parse_wcc_data(dp, vflag)) == NULL)
1476 if (parsestatus(dp, &er) != NULL)
1483 if ((dp = parserep(rp, length)) == NULL)
1486 if ((dp = parsestatus(dp, &er)) == NULL)
1489 printf(" file POST:");
1490 if ((dp = parse_post_op_attr(dp, vflag)) == NULL)
1493 if ((dp = parse_wcc_data(dp, vflag)) == NULL)
1498 if (parsestatus(dp, &er) != NULL)
1503 case NFSPROC_READDIR:
1505 if ((dp = parserep(rp, length)) == NULL)
1508 if (parsev3rddirres(dp, vflag) != NULL)
1511 if (parserddires(dp) != 0)
1516 case NFSPROC_READDIRPLUS:
1517 printf(" readdirplus");
1518 if ((dp = parserep(rp, length)) == NULL)
1520 if (parsev3rddirres(dp, vflag) != NULL)
1524 case NFSPROC_FSSTAT:
1526 dp = parserep(rp, length);
1527 if (dp != NULL && parsestatfs(dp, v3) != NULL)
1531 case NFSPROC_FSINFO:
1533 dp = parserep(rp, length);
1534 if (dp != NULL && parsefsinfo(dp) != NULL)
1538 case NFSPROC_PATHCONF:
1539 printf(" pathconf");
1540 dp = parserep(rp, length);
1541 if (dp != NULL && parsepathconf(dp) != 0)
1545 case NFSPROC_COMMIT:
1547 dp = parserep(rp, length);
1548 if (dp != NULL && parsewccres(dp, vflag) != 0)
1553 printf(" proc-%u", proc);
1559 fputs(" [|nfs]", stdout);