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.110.2.1 2007-12-22 03:08:45 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 int 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, reply_stat;
293 char srcid[20], dstid[20]; /*fits 32bit*/
294 enum sunrpc_reject_stat rstat;
297 enum sunrpc_auth_stat rwhy;
299 nfserr = 0; /* assume no error */
300 rp = (const struct sunrpc_msg *)bp;
304 strlcpy(srcid, "nfs", sizeof(srcid));
305 snprintf(dstid, sizeof(dstid), "%u",
306 EXTRACT_32BITS(&rp->rm_xid));
308 snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
309 snprintf(dstid, sizeof(dstid), "%u",
310 EXTRACT_32BITS(&rp->rm_xid));
312 print_nfsaddr(bp2, srcid, dstid);
313 TCHECK(rp->rm_reply.rp_stat);
314 reply_stat = EXTRACT_32BITS(&rp->rm_reply.rp_stat);
315 switch (reply_stat) {
317 case SUNRPC_MSG_ACCEPTED:
318 (void)printf("reply ok %u", length);
319 if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
320 interp_reply(rp, proc, vers, length);
323 case SUNRPC_MSG_DENIED:
324 (void)printf("reply ERR %u: ", length);
325 TCHECK(rp->rm_reply.rp_reject.rj_stat);
326 rstat = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_stat);
329 case SUNRPC_RPC_MISMATCH:
330 TCHECK(rp->rm_reply.rp_reject.rj_vers.high);
331 rlow = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_vers.low);
332 rhigh = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_vers.high);
333 (void)printf("RPC Version mismatch (%u-%u)",
337 case SUNRPC_AUTH_ERROR:
338 TCHECK(rp->rm_reply.rp_reject.rj_why);
339 rwhy = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_why);
340 (void)printf("Auth ");
347 case SUNRPC_AUTH_BADCRED:
348 (void)printf("Bogus Credentials (seal broken)");
351 case SUNRPC_AUTH_REJECTEDCRED:
352 (void)printf("Rejected Credentials (client should begin new session)");
355 case SUNRPC_AUTH_BADVERF:
356 (void)printf("Bogus Verifier (seal broken)");
359 case SUNRPC_AUTH_REJECTEDVERF:
360 (void)printf("Verifier expired or was replayed");
363 case SUNRPC_AUTH_TOOWEAK:
364 (void)printf("Credentials are too weak");
367 case SUNRPC_AUTH_INVALIDRESP:
368 (void)printf("Bogus response verifier");
371 case SUNRPC_AUTH_FAILED:
372 (void)printf("Unknown failure");
376 (void)printf("Invalid failure code %u",
383 (void)printf("Unknown reason for rejecting rpc message %u",
384 (unsigned int)rstat);
390 (void)printf("reply Unknown rpc response code=%u %u",
398 fputs(" [|nfs]", stdout);
402 * Return a pointer to the first file handle in the packet.
403 * If the packet was truncated, return 0.
405 static const u_int32_t *
406 parsereq(register const struct sunrpc_msg *rp, register u_int length)
408 register const u_int32_t *dp;
412 * find the start of the req data (if we captured it)
414 dp = (u_int32_t *)&rp->rm_call.cb_cred;
416 len = EXTRACT_32BITS(&dp[1]);
418 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
420 len = EXTRACT_32BITS(&dp[1]);
422 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
432 * Print out an NFS file handle and return a pointer to following word.
433 * If packet was truncated, return 0.
435 static const u_int32_t *
436 parsefh(register const u_int32_t *dp, int v3)
442 len = EXTRACT_32BITS(dp) / 4;
447 if (TTEST2(*dp, len * sizeof(*dp))) {
448 nfs_printfh(dp, len);
456 * Print out a file name and return pointer to 32-bit word past it.
457 * If packet was truncated, return 0.
459 static const u_int32_t *
460 parsefn(register const u_int32_t *dp)
462 register u_int32_t len;
463 register const u_char *cp;
465 /* Bail if we don't have the string length */
468 /* Fetch string length; convert to host order */
472 TCHECK2(*dp, ((len + 3) & ~3));
475 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
476 dp += ((len + 3) & ~3) / sizeof(*dp);
478 if (fn_printn(cp, len, snapend)) {
490 * Print out file handle and file name.
491 * Return pointer to 32-bit word past file name.
492 * If packet was truncated (or there was some other error), return 0.
494 static const u_int32_t *
495 parsefhn(register const u_int32_t *dp, int v3)
497 dp = parsefh(dp, v3);
501 return (parsefn(dp));
505 nfsreq_print(register const u_char *bp, u_int length,
506 register const u_char *bp2)
508 register const struct sunrpc_msg *rp;
509 register const u_int32_t *dp;
513 struct nfsv3_sattr sa3;
514 char srcid[20], dstid[20]; /*fits 32bit*/
516 nfserr = 0; /* assume no error */
517 rp = (const struct sunrpc_msg *)bp;
521 snprintf(srcid, sizeof(srcid), "%u",
522 EXTRACT_32BITS(&rp->rm_xid));
523 strlcpy(dstid, "nfs", sizeof(dstid));
525 snprintf(srcid, sizeof(srcid), "%u",
526 EXTRACT_32BITS(&rp->rm_xid));
527 snprintf(dstid, sizeof(dstid), "%u", NFS_PORT);
529 print_nfsaddr(bp2, srcid, dstid);
530 (void)printf("%d", length);
532 if (!xid_map_enter(rp, bp2)) /* record proc number for later on */
535 v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3);
536 proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
538 if (!v3 && proc < NFS_NPROCS)
539 proc = nfsv3_procid[proc];
549 case NFSPROC_GETATTR:
551 if ((dp = parsereq(rp, length)) != NULL &&
552 parsefh(dp, v3) != NULL)
556 case NFSPROC_SETATTR:
558 if ((dp = parsereq(rp, length)) != NULL &&
559 parsefh(dp, v3) != NULL)
565 if ((dp = parsereq(rp, length)) != NULL &&
566 parsefhn(dp, v3) != NULL)
572 if ((dp = parsereq(rp, length)) != NULL &&
573 (dp = parsefh(dp, v3)) != NULL) {
575 printf(" %04x", EXTRACT_32BITS(&dp[0]));
580 case NFSPROC_READLINK:
582 if ((dp = parsereq(rp, length)) != NULL &&
583 parsefh(dp, v3) != NULL)
589 if ((dp = parsereq(rp, length)) != NULL &&
590 (dp = parsefh(dp, v3)) != NULL) {
593 printf(" %u bytes @ %" PRIu64,
594 EXTRACT_32BITS(&dp[2]),
595 EXTRACT_64BITS(&dp[0]));
598 printf(" %u bytes @ %u",
599 EXTRACT_32BITS(&dp[1]),
600 EXTRACT_32BITS(&dp[0]));
608 if ((dp = parsereq(rp, length)) != NULL &&
609 (dp = parsefh(dp, v3)) != NULL) {
612 printf(" %u (%u) bytes @ %" PRIu64,
613 EXTRACT_32BITS(&dp[4]),
614 EXTRACT_32BITS(&dp[2]),
615 EXTRACT_64BITS(&dp[0]));
620 tok2str(nfsv3_writemodes,
621 NULL, EXTRACT_32BITS(dp)));
625 printf(" %u (%u) bytes @ %u (%u)",
626 EXTRACT_32BITS(&dp[3]),
627 EXTRACT_32BITS(&dp[2]),
628 EXTRACT_32BITS(&dp[1]),
629 EXTRACT_32BITS(&dp[0]));
637 if ((dp = parsereq(rp, length)) != NULL &&
638 parsefhn(dp, v3) != NULL)
644 if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0)
648 case NFSPROC_SYMLINK:
650 if ((dp = parsereq(rp, length)) != 0 &&
651 (dp = parsefhn(dp, v3)) != 0) {
652 fputs(" ->", stdout);
653 if (v3 && (dp = parse_sattr3(dp, &sa3)) == 0)
655 if (parsefn(dp) == 0)
658 print_sattr3(&sa3, vflag);
665 if ((dp = parsereq(rp, length)) != 0 &&
666 (dp = parsefhn(dp, v3)) != 0) {
668 type = (nfs_type)EXTRACT_32BITS(dp);
670 if ((dp = parse_sattr3(dp, &sa3)) == 0)
672 printf(" %s", tok2str(type2str, "unk-ft %d", type));
673 if (vflag && (type == NFCHR || type == NFBLK)) {
676 EXTRACT_32BITS(&dp[0]),
677 EXTRACT_32BITS(&dp[1]));
681 print_sattr3(&sa3, vflag);
688 if ((dp = parsereq(rp, length)) != NULL &&
689 parsefhn(dp, v3) != NULL)
695 if ((dp = parsereq(rp, length)) != NULL &&
696 parsefhn(dp, v3) != NULL)
702 if ((dp = parsereq(rp, length)) != NULL &&
703 (dp = parsefhn(dp, v3)) != NULL) {
704 fputs(" ->", stdout);
705 if (parsefhn(dp, v3) != NULL)
712 if ((dp = parsereq(rp, length)) != NULL &&
713 (dp = parsefh(dp, v3)) != NULL) {
714 fputs(" ->", stdout);
715 if (parsefhn(dp, v3) != NULL)
720 case NFSPROC_READDIR:
722 if ((dp = parsereq(rp, length)) != NULL &&
723 (dp = parsefh(dp, v3)) != NULL) {
727 * We shouldn't really try to interpret the
728 * offset cookie here.
730 printf(" %u bytes @ %" PRId64,
731 EXTRACT_32BITS(&dp[4]),
732 EXTRACT_64BITS(&dp[0]));
734 printf(" verf %08x%08x", dp[2],
739 * Print the offset as signed, since -1 is
740 * common, but offsets > 2^31 aren't.
742 printf(" %u bytes @ %d",
743 EXTRACT_32BITS(&dp[1]),
744 EXTRACT_32BITS(&dp[0]));
750 case NFSPROC_READDIRPLUS:
751 printf(" readdirplus");
752 if ((dp = parsereq(rp, length)) != NULL &&
753 (dp = parsefh(dp, v3)) != NULL) {
756 * We don't try to interpret the offset
759 printf(" %u bytes @ %" PRId64,
760 EXTRACT_32BITS(&dp[4]),
761 EXTRACT_64BITS(&dp[0]));
764 printf(" max %u verf %08x%08x",
765 EXTRACT_32BITS(&dp[5]), dp[2], dp[3]);
773 if ((dp = parsereq(rp, length)) != NULL &&
774 parsefh(dp, v3) != NULL)
780 if ((dp = parsereq(rp, length)) != NULL &&
781 parsefh(dp, v3) != NULL)
785 case NFSPROC_PATHCONF:
787 if ((dp = parsereq(rp, length)) != NULL &&
788 parsefh(dp, v3) != NULL)
794 if ((dp = parsereq(rp, length)) != NULL &&
795 (dp = parsefh(dp, v3)) != NULL) {
797 printf(" %u bytes @ %" PRIu64,
798 EXTRACT_32BITS(&dp[2]),
799 EXTRACT_64BITS(&dp[0]));
805 printf(" proc-%u", EXTRACT_32BITS(&rp->rm_call.cb_proc));
811 fputs(" [|nfs]", stdout);
815 * Print out an NFS file handle.
816 * We assume packet was not truncated before the end of the
817 * file handle pointed to by dp.
819 * Note: new version (using portable file-handle parser) doesn't produce
820 * generation number. It probably could be made to do that, with some
821 * additional hacking on the parser code.
824 nfs_printfh(register const u_int32_t *dp, const u_int len)
828 const char *sfsname = NULL;
833 char const *sep = "";
836 for (i=0; i<len; i++) {
837 (void)printf("%s%x", sep, dp[i]);
844 Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
847 /* file system ID is ASCII, not numeric, for this server OS */
848 static char temp[NFSX_V3FHMAX+1];
850 /* Make sure string is null-terminated */
851 strncpy(temp, sfsname, NFSX_V3FHMAX);
852 temp[sizeof(temp) - 1] = '\0';
853 /* Remove trailing spaces */
854 spacep = strchr(temp, ' ');
858 (void)printf(" fh %s/", temp);
860 (void)printf(" fh %d,%d/",
861 fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
864 if(fsid.Fsid_dev.Minor == 257)
865 /* Print the undecoded handle */
866 (void)printf("%s", fsid.Opaque_Handle);
868 (void)printf("%ld", (long) ino);
872 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
873 * us to match up replies with requests and thus to know how to parse
877 struct xid_map_entry {
878 u_int32_t xid; /* transaction ID (net order) */
879 int ipver; /* IP version (4 or 6) */
881 struct in6_addr client; /* client IP address (net order) */
882 struct in6_addr server; /* server IP address (net order) */
884 struct in_addr client; /* client IP address (net order) */
885 struct in_addr server; /* server IP address (net order) */
887 u_int32_t proc; /* call proc number (host order) */
888 u_int32_t vers; /* program version (host order) */
892 * Map entries are kept in an array that we manage as a ring;
893 * new entries are always added at the tail of the ring. Initially,
894 * all the entries are zero and hence don't match anything.
897 #define XIDMAPSIZE 64
899 struct xid_map_entry xid_map[XIDMAPSIZE];
901 int xid_map_next = 0;
902 int xid_map_hint = 0;
905 xid_map_enter(const struct sunrpc_msg *rp, const u_char *bp)
907 struct ip *ip = NULL;
909 struct ip6_hdr *ip6 = NULL;
911 struct xid_map_entry *xmep;
913 if (!TTEST(rp->rm_call.cb_vers))
915 switch (IP_V((struct ip *)bp)) {
917 ip = (struct ip *)bp;
921 ip6 = (struct ip6_hdr *)bp;
928 xmep = &xid_map[xid_map_next];
930 if (++xid_map_next >= XIDMAPSIZE)
933 xmep->xid = rp->rm_xid;
936 memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
937 memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
942 memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
943 memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
946 xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
947 xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
952 * Returns 0 and puts NFSPROC_xxx in proc return and
953 * version in vers return, or returns -1 on failure
956 xid_map_find(const struct sunrpc_msg *rp, const u_char *bp, u_int32_t *proc,
960 struct xid_map_entry *xmep;
961 u_int32_t xid = rp->rm_xid;
962 struct ip *ip = (struct ip *)bp;
964 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
968 /* Start searching from where we last left off */
973 if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
975 switch (xmep->ipver) {
977 if (memcmp(&ip->ip_src, &xmep->server,
978 sizeof(ip->ip_src)) != 0 ||
979 memcmp(&ip->ip_dst, &xmep->client,
980 sizeof(ip->ip_dst)) != 0) {
986 if (memcmp(&ip6->ip6_src, &xmep->server,
987 sizeof(ip6->ip6_src)) != 0 ||
988 memcmp(&ip6->ip6_dst, &xmep->client,
989 sizeof(ip6->ip6_dst)) != 0) {
1006 if (++i >= XIDMAPSIZE)
1008 } while (i != xid_map_hint);
1015 * Routines for parsing reply packets
1019 * Return a pointer to the beginning of the actual results.
1020 * If the packet was truncated, return 0.
1022 static const u_int32_t *
1023 parserep(register const struct sunrpc_msg *rp, register u_int length)
1025 register const u_int32_t *dp;
1027 enum sunrpc_accept_stat astat;
1031 * Here we find the address of the ar_verf credentials.
1032 * Originally, this calculation was
1033 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
1034 * On the wire, the rp_acpt field starts immediately after
1035 * the (32 bit) rp_stat field. However, rp_acpt (which is a
1036 * "struct accepted_reply") contains a "struct opaque_auth",
1037 * whose internal representation contains a pointer, so on a
1038 * 64-bit machine the compiler inserts 32 bits of padding
1039 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
1040 * the internal representation to parse the on-the-wire
1041 * representation. Instead, we skip past the rp_stat field,
1042 * which is an "enum" and so occupies one 32-bit word.
1044 dp = ((const u_int32_t *)&rp->rm_reply) + 1;
1046 len = EXTRACT_32BITS(&dp[1]);
1050 * skip past the ar_verf credentials.
1052 dp += (len + (2*sizeof(u_int32_t) + 3)) / sizeof(u_int32_t);
1056 * now we can check the ar_stat field
1058 astat = (enum sunrpc_accept_stat) EXTRACT_32BITS(dp);
1061 case SUNRPC_SUCCESS:
1064 case SUNRPC_PROG_UNAVAIL:
1065 printf(" PROG_UNAVAIL");
1066 nfserr = 1; /* suppress trunc string */
1069 case SUNRPC_PROG_MISMATCH:
1070 printf(" PROG_MISMATCH");
1071 nfserr = 1; /* suppress trunc string */
1074 case SUNRPC_PROC_UNAVAIL:
1075 printf(" PROC_UNAVAIL");
1076 nfserr = 1; /* suppress trunc string */
1079 case SUNRPC_GARBAGE_ARGS:
1080 printf(" GARBAGE_ARGS");
1081 nfserr = 1; /* suppress trunc string */
1084 case SUNRPC_SYSTEM_ERR:
1085 printf(" SYSTEM_ERR");
1086 nfserr = 1; /* suppress trunc string */
1090 printf(" ar_stat %d", astat);
1091 nfserr = 1; /* suppress trunc string */
1094 /* successful return */
1095 TCHECK2(*dp, sizeof(astat));
1096 return ((u_int32_t *) (sizeof(astat) + ((char *)dp)));
1101 static const u_int32_t *
1102 parsestatus(const u_int32_t *dp, int *er)
1108 errnum = EXTRACT_32BITS(&dp[0]);
1113 printf(" ERROR: %s",
1114 tok2str(status2str, "unk %d", errnum));
1122 static const u_int32_t *
1123 parsefattr(const u_int32_t *dp, int verbose, int v3)
1125 const struct nfs_fattr *fap;
1127 fap = (const struct nfs_fattr *)dp;
1128 TCHECK(fap->fa_gid);
1130 printf(" %s %o ids %d/%d",
1131 tok2str(type2str, "unk-ft %d ",
1132 EXTRACT_32BITS(&fap->fa_type)),
1133 EXTRACT_32BITS(&fap->fa_mode),
1134 EXTRACT_32BITS(&fap->fa_uid),
1135 EXTRACT_32BITS(&fap->fa_gid));
1137 TCHECK(fap->fa3_size);
1138 printf(" sz %" PRIu64,
1139 EXTRACT_64BITS((u_int32_t *)&fap->fa3_size));
1141 TCHECK(fap->fa2_size);
1142 printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size));
1145 /* print lots more stuff */
1148 TCHECK(fap->fa3_ctime);
1149 printf(" nlink %d rdev %d/%d",
1150 EXTRACT_32BITS(&fap->fa_nlink),
1151 EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
1152 EXTRACT_32BITS(&fap->fa3_rdev.specdata2));
1153 printf(" fsid %" PRIx64,
1154 EXTRACT_64BITS((u_int32_t *)&fap->fa3_fsid));
1155 printf(" fileid %" PRIx64,
1156 EXTRACT_64BITS((u_int32_t *)&fap->fa3_fileid));
1157 printf(" a/m/ctime %u.%06u",
1158 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec),
1159 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec));
1161 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec),
1162 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec));
1164 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec),
1165 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec));
1167 TCHECK(fap->fa2_ctime);
1168 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1169 EXTRACT_32BITS(&fap->fa_nlink),
1170 EXTRACT_32BITS(&fap->fa2_rdev),
1171 EXTRACT_32BITS(&fap->fa2_fsid),
1172 EXTRACT_32BITS(&fap->fa2_fileid));
1174 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec),
1175 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec));
1177 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec),
1178 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec));
1180 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec),
1181 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec));
1184 return ((const u_int32_t *)((unsigned char *)dp +
1185 (v3 ? NFSX_V3FATTR : NFSX_V2FATTR)));
1191 parseattrstat(const u_int32_t *dp, int verbose, int v3)
1195 dp = parsestatus(dp, &er);
1201 return (parsefattr(dp, verbose, v3) != NULL);
1205 parsediropres(const u_int32_t *dp)
1209 if (!(dp = parsestatus(dp, &er)))
1214 dp = parsefh(dp, 0);
1218 return (parsefattr(dp, vflag, 0) != NULL);
1222 parselinkres(const u_int32_t *dp, int v3)
1226 dp = parsestatus(dp, &er);
1231 if (v3 && !(dp = parse_post_op_attr(dp, vflag)))
1234 return (parsefn(dp) != NULL);
1238 parsestatfs(const u_int32_t *dp, int v3)
1240 const struct nfs_statfs *sfsp;
1243 dp = parsestatus(dp, &er);
1255 if (!(dp = parse_post_op_attr(dp, vflag)))
1259 TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
1261 sfsp = (const struct nfs_statfs *)dp;
1264 printf(" tbytes %" PRIu64 " fbytes %" PRIu64 " abytes %" PRIu64,
1265 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_tbytes),
1266 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_fbytes),
1267 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_abytes));
1269 printf(" tfiles %" PRIu64 " ffiles %" PRIu64 " afiles %" PRIu64 " invar %u",
1270 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_tfiles),
1271 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_ffiles),
1272 EXTRACT_64BITS((u_int32_t *)&sfsp->sf_afiles),
1273 EXTRACT_32BITS(&sfsp->sf_invarsec));
1276 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1277 EXTRACT_32BITS(&sfsp->sf_tsize),
1278 EXTRACT_32BITS(&sfsp->sf_bsize),
1279 EXTRACT_32BITS(&sfsp->sf_blocks),
1280 EXTRACT_32BITS(&sfsp->sf_bfree),
1281 EXTRACT_32BITS(&sfsp->sf_bavail));
1290 parserddires(const u_int32_t *dp)
1294 dp = parsestatus(dp, &er);
1303 printf(" offset %x size %d ",
1304 EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1]));
1313 static const u_int32_t *
1314 parse_wcc_attr(const u_int32_t *dp)
1316 printf(" sz %" PRIu64, EXTRACT_64BITS(&dp[0]));
1317 printf(" mtime %u.%06u ctime %u.%06u",
1318 EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
1319 EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5]));
1324 * Pre operation attributes. Print only if vflag > 1.
1326 static const u_int32_t *
1327 parse_pre_op_attr(const u_int32_t *dp, int verbose)
1330 if (!EXTRACT_32BITS(&dp[0]))
1335 return parse_wcc_attr(dp);
1337 /* If not verbose enough, just skip over wcc_attr */
1345 * Post operation attributes are printed if vflag >= 1
1347 static const u_int32_t *
1348 parse_post_op_attr(const u_int32_t *dp, int verbose)
1351 if (!EXTRACT_32BITS(&dp[0]))
1355 return parsefattr(dp, verbose, 1);
1357 return (dp + (NFSX_V3FATTR / sizeof (u_int32_t)));
1362 static const u_int32_t *
1363 parse_wcc_data(const u_int32_t *dp, int verbose)
1367 if (!(dp = parse_pre_op_attr(dp, verbose)))
1372 return parse_post_op_attr(dp, verbose);
1375 static const u_int32_t *
1376 parsecreateopres(const u_int32_t *dp, int verbose)
1380 if (!(dp = parsestatus(dp, &er)))
1383 dp = parse_wcc_data(dp, verbose);
1386 if (!EXTRACT_32BITS(&dp[0]))
1389 if (!(dp = parsefh(dp, 1)))
1392 if (!(dp = parse_post_op_attr(dp, verbose)))
1395 printf(" dir attr:");
1396 dp = parse_wcc_data(dp, verbose);
1406 parsewccres(const u_int32_t *dp, int verbose)
1410 if (!(dp = parsestatus(dp, &er)))
1412 return parse_wcc_data(dp, verbose) != 0;
1415 static const u_int32_t *
1416 parsev3rddirres(const u_int32_t *dp, int verbose)
1420 if (!(dp = parsestatus(dp, &er)))
1424 if (!(dp = parse_post_op_attr(dp, verbose)))
1430 printf(" verf %08x%08x", dp[0], dp[1]);
1439 parsefsinfo(const u_int32_t *dp)
1441 struct nfsv3_fsinfo *sfp;
1444 if (!(dp = parsestatus(dp, &er)))
1448 if (!(dp = parse_post_op_attr(dp, vflag)))
1453 sfp = (struct nfsv3_fsinfo *)dp;
1455 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1456 EXTRACT_32BITS(&sfp->fs_rtmax),
1457 EXTRACT_32BITS(&sfp->fs_rtpref),
1458 EXTRACT_32BITS(&sfp->fs_wtmax),
1459 EXTRACT_32BITS(&sfp->fs_wtpref),
1460 EXTRACT_32BITS(&sfp->fs_dtpref));
1462 printf(" rtmult %u wtmult %u maxfsz %" PRIu64,
1463 EXTRACT_32BITS(&sfp->fs_rtmult),
1464 EXTRACT_32BITS(&sfp->fs_wtmult),
1465 EXTRACT_64BITS((u_int32_t *)&sfp->fs_maxfilesize));
1466 printf(" delta %u.%06u ",
1467 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
1468 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec));
1476 parsepathconf(const u_int32_t *dp)
1479 struct nfsv3_pathconf *spp;
1481 if (!(dp = parsestatus(dp, &er)))
1485 if (!(dp = parse_post_op_attr(dp, vflag)))
1490 spp = (struct nfsv3_pathconf *)dp;
1493 printf(" linkmax %u namemax %u %s %s %s %s",
1494 EXTRACT_32BITS(&spp->pc_linkmax),
1495 EXTRACT_32BITS(&spp->pc_namemax),
1496 EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
1497 EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
1498 EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
1499 EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : "");
1506 interp_reply(const struct sunrpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
1508 register const u_int32_t *dp;
1512 v3 = (vers == NFS_VER3);
1514 if (!v3 && proc < NFS_NPROCS)
1515 proc = nfsv3_procid[proc];
1527 case NFSPROC_GETATTR:
1529 dp = parserep(rp, length);
1530 if (dp != NULL && parseattrstat(dp, !qflag, v3) != 0)
1534 case NFSPROC_SETATTR:
1536 if (!(dp = parserep(rp, length)))
1539 if (parsewccres(dp, vflag))
1542 if (parseattrstat(dp, !qflag, 0) != 0)
1547 case NFSPROC_LOOKUP:
1549 if (!(dp = parserep(rp, length)))
1552 if (!(dp = parsestatus(dp, &er)))
1556 printf(" post dattr:");
1557 dp = parse_post_op_attr(dp, vflag);
1560 if (!(dp = parsefh(dp, v3)))
1562 if ((dp = parse_post_op_attr(dp, vflag)) &&
1564 printf(" post dattr:");
1565 dp = parse_post_op_attr(dp, vflag);
1571 if (parsediropres(dp) != 0)
1576 case NFSPROC_ACCESS:
1578 if (!(dp = parserep(rp, length)))
1580 if (!(dp = parsestatus(dp, &er)))
1584 if (!(dp = parse_post_op_attr(dp, vflag)))
1587 printf(" c %04x", EXTRACT_32BITS(&dp[0]));
1590 case NFSPROC_READLINK:
1591 printf(" readlink");
1592 dp = parserep(rp, length);
1593 if (dp != NULL && parselinkres(dp, v3) != 0)
1599 if (!(dp = parserep(rp, length)))
1602 if (!(dp = parsestatus(dp, &er)))
1604 if (!(dp = parse_post_op_attr(dp, vflag)))
1610 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1611 if (EXTRACT_32BITS(&dp[1]))
1616 if (parseattrstat(dp, vflag, 0) != 0)
1623 if (!(dp = parserep(rp, length)))
1626 if (!(dp = parsestatus(dp, &er)))
1628 if (!(dp = parse_wcc_data(dp, vflag)))
1634 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1638 tok2str(nfsv3_writemodes,
1639 NULL, EXTRACT_32BITS(&dp[1])));
1644 if (parseattrstat(dp, vflag, v3) != 0)
1649 case NFSPROC_CREATE:
1651 if (!(dp = parserep(rp, length)))
1654 if (parsecreateopres(dp, vflag) != 0)
1657 if (parsediropres(dp) != 0)
1664 if (!(dp = parserep(rp, length)))
1667 if (parsecreateopres(dp, vflag) != 0)
1670 if (parsediropres(dp) != 0)
1675 case NFSPROC_SYMLINK:
1677 if (!(dp = parserep(rp, length)))
1680 if (parsecreateopres(dp, vflag) != 0)
1683 if (parsestatus(dp, &er) != 0)
1690 if (!(dp = parserep(rp, length)))
1692 if (parsecreateopres(dp, vflag) != 0)
1696 case NFSPROC_REMOVE:
1698 if (!(dp = parserep(rp, length)))
1701 if (parsewccres(dp, vflag))
1704 if (parsestatus(dp, &er) != 0)
1711 if (!(dp = parserep(rp, length)))
1714 if (parsewccres(dp, vflag))
1717 if (parsestatus(dp, &er) != 0)
1722 case NFSPROC_RENAME:
1724 if (!(dp = parserep(rp, length)))
1727 if (!(dp = parsestatus(dp, &er)))
1731 if (!(dp = parse_wcc_data(dp, vflag)))
1734 if (!(dp = parse_wcc_data(dp, vflag)))
1739 if (parsestatus(dp, &er) != 0)
1746 if (!(dp = parserep(rp, length)))
1749 if (!(dp = parsestatus(dp, &er)))
1752 printf(" file POST:");
1753 if (!(dp = parse_post_op_attr(dp, vflag)))
1756 if (!(dp = parse_wcc_data(dp, vflag)))
1761 if (parsestatus(dp, &er) != 0)
1766 case NFSPROC_READDIR:
1768 if (!(dp = parserep(rp, length)))
1771 if (parsev3rddirres(dp, vflag))
1774 if (parserddires(dp) != 0)
1779 case NFSPROC_READDIRPLUS:
1780 printf(" readdirplus");
1781 if (!(dp = parserep(rp, length)))
1783 if (parsev3rddirres(dp, vflag))
1787 case NFSPROC_FSSTAT:
1789 dp = parserep(rp, length);
1790 if (dp != NULL && parsestatfs(dp, v3) != 0)
1794 case NFSPROC_FSINFO:
1796 dp = parserep(rp, length);
1797 if (dp != NULL && parsefsinfo(dp) != 0)
1801 case NFSPROC_PATHCONF:
1802 printf(" pathconf");
1803 dp = parserep(rp, length);
1804 if (dp != NULL && parsepathconf(dp) != 0)
1808 case NFSPROC_COMMIT:
1810 dp = parserep(rp, length);
1811 if (dp != NULL && parsewccres(dp, vflag) != 0)
1816 printf(" proc-%u", proc);
1821 fputs(" [|nfs]", stdout);