]>
The Tcpdump Group git mirrors - tcpdump/blob - print-nfs.c
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.102 2004-04-17 08:56:14 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
51 static void nfs_printfh(const u_int32_t
*, const u_int
);
52 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
53 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
54 u_int32_t
*, u_int32_t
*);
55 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
56 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
57 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
58 static int print_int64(const u_int32_t
*dp
, int how
);
59 static void print_nfsaddr(const u_char
*, const char *, const char *);
62 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
64 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
94 * NFS V2 and V3 status values.
96 * Some of these come from the RFCs for NFS V2 and V3, with the message
97 * strings taken from the FreeBSD C library "errlst.c".
99 * Others are errors that are not in the RFC but that I suspect some
100 * NFS servers could return; the values are FreeBSD errno values, as
101 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
102 * was primarily BSD-derived.
104 static struct tok status2str
[] = {
105 { 1, "Operation not permitted" }, /* EPERM */
106 { 2, "No such file or directory" }, /* ENOENT */
107 { 5, "Input/output error" }, /* EIO */
108 { 6, "Device not configured" }, /* ENXIO */
109 { 11, "Resource deadlock avoided" }, /* EDEADLK */
110 { 12, "Cannot allocate memory" }, /* ENOMEM */
111 { 13, "Permission denied" }, /* EACCES */
112 { 17, "File exists" }, /* EEXIST */
113 { 18, "Cross-device link" }, /* EXDEV */
114 { 19, "Operation not supported by device" }, /* ENODEV */
115 { 20, "Not a directory" }, /* ENOTDIR */
116 { 21, "Is a directory" }, /* EISDIR */
117 { 22, "Invalid argument" }, /* EINVAL */
118 { 26, "Text file busy" }, /* ETXTBSY */
119 { 27, "File too large" }, /* EFBIG */
120 { 28, "No space left on device" }, /* ENOSPC */
121 { 30, "Read-only file system" }, /* EROFS */
122 { 31, "Too many links" }, /* EMLINK */
123 { 45, "Operation not supported" }, /* EOPNOTSUPP */
124 { 62, "Too many levels of symbolic links" }, /* ELOOP */
125 { 63, "File name too long" }, /* ENAMETOOLONG */
126 { 66, "Directory not empty" }, /* ENOTEMPTY */
127 { 69, "Disc quota exceeded" }, /* EDQUOT */
128 { 70, "Stale NFS file handle" }, /* ESTALE */
129 { 71, "Too many levels of remote in path" }, /* EREMOTE */
130 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
131 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
132 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
133 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
134 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
135 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
136 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
137 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
138 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
142 static struct tok nfsv3_writemodes
[] = {
149 static struct tok type2str
[] = {
161 * Print out a 64-bit integer. This appears to be different on each system,
162 * try to make the best of it. The integer stored as 2 consecutive XDR
163 * encoded 32-bit integers, to which a pointer is passed.
165 * We assume that PRId64, PRIu64, and PRIx64 are defined, and that
166 * u_int64_t is defined.
173 static int print_int64(const u_int32_t
*dp
, int how
)
177 res
= ((u_int64_t
)EXTRACT_32BITS(&dp
[0]) << 32) | (u_int64_t
)EXTRACT_32BITS(&dp
[1]);
180 printf("%" PRId64
, res
);
183 printf("%" PRIu64
, res
);
186 printf("%" PRIx64
, res
);
195 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
200 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
202 #ifndef INET_ADDRSTRLEN
203 #define INET_ADDRSTRLEN 16
205 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
208 srcaddr
[0] = dstaddr
[0] = '\0';
209 switch (IP_V((struct ip
*)bp
)) {
211 ip
= (struct ip
*)bp
;
212 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
213 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
217 ip6
= (struct ip6_hdr
*)bp
;
218 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
220 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
225 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
226 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
230 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
233 static const u_int32_t
*
234 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
237 sa3
->sa_modeset
= EXTRACT_32BITS(dp
);
239 if (sa3
->sa_modeset
) {
241 sa3
->sa_mode
= EXTRACT_32BITS(dp
);
246 sa3
->sa_uidset
= EXTRACT_32BITS(dp
);
248 if (sa3
->sa_uidset
) {
250 sa3
->sa_uid
= EXTRACT_32BITS(dp
);
255 sa3
->sa_gidset
= EXTRACT_32BITS(dp
);
257 if (sa3
->sa_gidset
) {
259 sa3
->sa_gid
= EXTRACT_32BITS(dp
);
264 sa3
->sa_sizeset
= EXTRACT_32BITS(dp
);
266 if (sa3
->sa_sizeset
) {
268 sa3
->sa_size
= EXTRACT_32BITS(dp
);
273 sa3
->sa_atimetype
= EXTRACT_32BITS(dp
);
275 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
) {
277 sa3
->sa_atime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
279 sa3
->sa_atime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
284 sa3
->sa_mtimetype
= EXTRACT_32BITS(dp
);
286 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
) {
288 sa3
->sa_mtime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
290 sa3
->sa_mtime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
299 static int nfserr
; /* true if we error rather than trunc */
302 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
305 printf(" mode %o", sa3
->sa_mode
);
307 printf(" uid %u", sa3
->sa_uid
);
309 printf(" gid %u", sa3
->sa_gid
);
311 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
312 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
313 sa3
->sa_atime
.nfsv3_nsec
);
314 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
315 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
316 sa3
->sa_mtime
.nfsv3_nsec
);
321 nfsreply_print(register const u_char
*bp
, u_int length
,
322 register const u_char
*bp2
)
324 register const struct rpc_msg
*rp
;
325 u_int32_t proc
, vers
;
326 char srcid
[20], dstid
[20]; /*fits 32bit*/
328 nfserr
= 0; /* assume no error */
329 rp
= (const struct rpc_msg
*)bp
;
332 strlcpy(srcid
, "nfs", sizeof(srcid
));
333 snprintf(dstid
, sizeof(dstid
), "%u",
334 EXTRACT_32BITS(&rp
->rm_xid
));
336 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
337 snprintf(dstid
, sizeof(dstid
), "%u",
338 EXTRACT_32BITS(&rp
->rm_xid
));
340 print_nfsaddr(bp2
, srcid
, dstid
);
341 (void)printf("reply %s %d",
342 EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
346 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
347 interp_reply(rp
, proc
, vers
, length
);
351 * Return a pointer to the first file handle in the packet.
352 * If the packet was truncated, return 0.
354 static const u_int32_t
*
355 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
357 register const u_int32_t
*dp
;
361 * find the start of the req data (if we captured it)
363 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
365 len
= EXTRACT_32BITS(&dp
[1]);
367 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
369 len
= EXTRACT_32BITS(&dp
[1]);
371 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
381 * Print out an NFS file handle and return a pointer to following word.
382 * If packet was truncated, return 0.
384 static const u_int32_t
*
385 parsefh(register const u_int32_t
*dp
, int v3
)
391 len
= EXTRACT_32BITS(dp
) / 4;
396 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
397 nfs_printfh(dp
, len
);
405 * Print out a file name and return pointer to 32-bit word past it.
406 * If packet was truncated, return 0.
408 static const u_int32_t
*
409 parsefn(register const u_int32_t
*dp
)
411 register u_int32_t len
;
412 register const u_char
*cp
;
414 /* Bail if we don't have the string length */
417 /* Fetch string length; convert to host order */
421 TCHECK2(*dp
, ((len
+ 3) & ~3));
424 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
425 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
426 /* XXX seems like we should be checking the length */
428 (void) fn_printn(cp
, len
, NULL
);
437 * Print out file handle and file name.
438 * Return pointer to 32-bit word past file name.
439 * If packet was truncated (or there was some other error), return 0.
441 static const u_int32_t
*
442 parsefhn(register const u_int32_t
*dp
, int v3
)
444 dp
= parsefh(dp
, v3
);
448 return (parsefn(dp
));
452 nfsreq_print(register const u_char
*bp
, u_int length
,
453 register const u_char
*bp2
)
455 register const struct rpc_msg
*rp
;
456 register const u_int32_t
*dp
;
460 struct nfsv3_sattr sa3
;
461 char srcid
[20], dstid
[20]; /*fits 32bit*/
463 nfserr
= 0; /* assume no error */
464 rp
= (const struct rpc_msg
*)bp
;
466 snprintf(srcid
, sizeof(srcid
), "%u",
467 EXTRACT_32BITS(&rp
->rm_xid
));
468 strlcpy(dstid
, "nfs", sizeof(dstid
));
470 snprintf(srcid
, sizeof(srcid
), "%u",
471 EXTRACT_32BITS(&rp
->rm_xid
));
472 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
474 print_nfsaddr(bp2
, srcid
, dstid
);
475 (void)printf("%d", length
);
477 xid_map_enter(rp
, bp2
); /* record proc number for later on */
479 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
480 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
482 if (!v3
&& proc
< NFS_NPROCS
)
483 proc
= nfsv3_procid
[proc
];
493 case NFSPROC_GETATTR
:
495 if ((dp
= parsereq(rp
, length
)) != NULL
&&
496 parsefh(dp
, v3
) != NULL
)
500 case NFSPROC_SETATTR
:
502 if ((dp
= parsereq(rp
, length
)) != NULL
&&
503 parsefh(dp
, v3
) != NULL
)
509 if ((dp
= parsereq(rp
, length
)) != NULL
&&
510 parsefhn(dp
, v3
) != NULL
)
516 if ((dp
= parsereq(rp
, length
)) != NULL
&&
517 (dp
= parsefh(dp
, v3
)) != NULL
) {
519 printf(" %04x", EXTRACT_32BITS(&dp
[0]));
524 case NFSPROC_READLINK
:
526 if ((dp
= parsereq(rp
, length
)) != NULL
&&
527 parsefh(dp
, v3
) != NULL
)
533 if ((dp
= parsereq(rp
, length
)) != NULL
&&
534 (dp
= parsefh(dp
, v3
)) != NULL
) {
537 printf(" %u bytes @ ",
538 EXTRACT_32BITS(&dp
[2]));
539 print_int64(dp
, UNSIGNED
);
542 printf(" %u bytes @ %u",
543 EXTRACT_32BITS(&dp
[1]),
544 EXTRACT_32BITS(&dp
[0]));
552 if ((dp
= parsereq(rp
, length
)) != NULL
&&
553 (dp
= parsefh(dp
, v3
)) != NULL
) {
556 printf(" %u bytes @ ",
557 EXTRACT_32BITS(&dp
[4]));
558 print_int64(dp
, UNSIGNED
);
563 tok2str(nfsv3_writemodes
,
564 NULL
, EXTRACT_32BITS(dp
)));
568 printf(" %u (%u) bytes @ %u (%u)",
569 EXTRACT_32BITS(&dp
[3]),
570 EXTRACT_32BITS(&dp
[2]),
571 EXTRACT_32BITS(&dp
[1]),
572 EXTRACT_32BITS(&dp
[0]));
580 if ((dp
= parsereq(rp
, length
)) != NULL
&&
581 parsefhn(dp
, v3
) != NULL
)
587 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
591 case NFSPROC_SYMLINK
:
593 if ((dp
= parsereq(rp
, length
)) != 0 &&
594 (dp
= parsefhn(dp
, v3
)) != 0) {
595 fputs(" ->", stdout
);
596 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
598 if (parsefn(dp
) == 0)
601 print_sattr3(&sa3
, vflag
);
608 if ((dp
= parsereq(rp
, length
)) != 0 &&
609 (dp
= parsefhn(dp
, v3
)) != 0) {
611 type
= (nfs_type
)EXTRACT_32BITS(dp
);
613 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
615 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
616 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
619 EXTRACT_32BITS(&dp
[0]),
620 EXTRACT_32BITS(&dp
[1]));
624 print_sattr3(&sa3
, vflag
);
631 if ((dp
= parsereq(rp
, length
)) != NULL
&&
632 parsefhn(dp
, v3
) != NULL
)
638 if ((dp
= parsereq(rp
, length
)) != NULL
&&
639 parsefhn(dp
, v3
) != NULL
)
645 if ((dp
= parsereq(rp
, length
)) != NULL
&&
646 (dp
= parsefhn(dp
, v3
)) != NULL
) {
647 fputs(" ->", stdout
);
648 if (parsefhn(dp
, v3
) != NULL
)
655 if ((dp
= parsereq(rp
, length
)) != NULL
&&
656 (dp
= parsefh(dp
, v3
)) != NULL
) {
657 fputs(" ->", stdout
);
658 if (parsefhn(dp
, v3
) != NULL
)
663 case NFSPROC_READDIR
:
665 if ((dp
= parsereq(rp
, length
)) != NULL
&&
666 (dp
= parsefh(dp
, v3
)) != NULL
) {
670 * We shouldn't really try to interpret the
671 * offset cookie here.
673 printf(" %u bytes @ ",
674 EXTRACT_32BITS(&dp
[4]));
675 print_int64(dp
, SIGNED
);
677 printf(" verf %08x%08x", dp
[2],
682 * Print the offset as signed, since -1 is
683 * common, but offsets > 2^31 aren't.
685 printf(" %u bytes @ %d",
686 EXTRACT_32BITS(&dp
[1]),
687 EXTRACT_32BITS(&dp
[0]));
693 case NFSPROC_READDIRPLUS
:
694 printf(" readdirplus");
695 if ((dp
= parsereq(rp
, length
)) != NULL
&&
696 (dp
= parsefh(dp
, v3
)) != NULL
) {
699 * We don't try to interpret the offset
702 printf(" %u bytes @ ", EXTRACT_32BITS(&dp
[4]));
703 print_int64(dp
, SIGNED
);
705 printf(" max %u verf %08x%08x",
706 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
713 if ((dp
= parsereq(rp
, length
)) != NULL
&&
714 parsefh(dp
, v3
) != NULL
)
720 if ((dp
= parsereq(rp
, length
)) != NULL
&&
721 parsefh(dp
, v3
) != NULL
)
725 case NFSPROC_PATHCONF
:
727 if ((dp
= parsereq(rp
, length
)) != NULL
&&
728 parsefh(dp
, v3
) != NULL
)
734 if ((dp
= parsereq(rp
, length
)) != NULL
&&
735 (dp
= parsefh(dp
, v3
)) != NULL
) {
736 printf(" %u bytes @ ", EXTRACT_32BITS(&dp
[2]));
737 print_int64(dp
, UNSIGNED
);
743 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
749 fputs(" [|nfs]", stdout
);
753 * Print out an NFS file handle.
754 * We assume packet was not truncated before the end of the
755 * file handle pointed to by dp.
757 * Note: new version (using portable file-handle parser) doesn't produce
758 * generation number. It probably could be made to do that, with some
759 * additional hacking on the parser code.
762 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
766 const char *sfsname
= NULL
;
771 char const *sep
= "";
774 for (i
=0; i
<len
; i
++) {
775 (void)printf("%s%x", sep
, dp
[i
]);
782 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
785 /* file system ID is ASCII, not numeric, for this server OS */
786 static char temp
[NFSX_V3FHMAX
+1];
788 /* Make sure string is null-terminated */
789 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
790 temp
[sizeof(temp
) - 1] = '\0';
791 /* Remove trailing spaces */
792 spacep
= strchr(temp
, ' ');
796 (void)printf(" fh %s/", temp
);
798 (void)printf(" fh %d,%d/",
799 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
802 if(fsid
.Fsid_dev
.Minor
== 257)
803 /* Print the undecoded handle */
804 (void)printf("%s", fsid
.Opaque_Handle
);
806 (void)printf("%ld", (long) ino
);
810 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
811 * us to match up replies with requests and thus to know how to parse
815 struct xid_map_entry
{
816 u_int32_t xid
; /* transaction ID (net order) */
817 int ipver
; /* IP version (4 or 6) */
819 struct in6_addr client
; /* client IP address (net order) */
820 struct in6_addr server
; /* server IP address (net order) */
822 struct in_addr client
; /* client IP address (net order) */
823 struct in_addr server
; /* server IP address (net order) */
825 u_int32_t proc
; /* call proc number (host order) */
826 u_int32_t vers
; /* program version (host order) */
830 * Map entries are kept in an array that we manage as a ring;
831 * new entries are always added at the tail of the ring. Initially,
832 * all the entries are zero and hence don't match anything.
835 #define XIDMAPSIZE 64
837 struct xid_map_entry xid_map
[XIDMAPSIZE
];
839 int xid_map_next
= 0;
840 int xid_map_hint
= 0;
843 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
845 struct ip
*ip
= NULL
;
847 struct ip6_hdr
*ip6
= NULL
;
849 struct xid_map_entry
*xmep
;
851 switch (IP_V((struct ip
*)bp
)) {
853 ip
= (struct ip
*)bp
;
857 ip6
= (struct ip6_hdr
*)bp
;
864 xmep
= &xid_map
[xid_map_next
];
866 if (++xid_map_next
>= XIDMAPSIZE
)
869 xmep
->xid
= rp
->rm_xid
;
872 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
873 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
878 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
879 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
882 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
883 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
887 * Returns 0 and puts NFSPROC_xxx in proc return and
888 * version in vers return, or returns -1 on failure
891 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
895 struct xid_map_entry
*xmep
;
896 u_int32_t xid
= rp
->rm_xid
;
897 struct ip
*ip
= (struct ip
*)bp
;
899 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
903 /* Start searching from where we last left off */
908 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
910 switch (xmep
->ipver
) {
912 if (memcmp(&ip
->ip_src
, &xmep
->server
,
913 sizeof(ip
->ip_src
)) != 0 ||
914 memcmp(&ip
->ip_dst
, &xmep
->client
,
915 sizeof(ip
->ip_dst
)) != 0) {
921 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
922 sizeof(ip6
->ip6_src
)) != 0 ||
923 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
924 sizeof(ip6
->ip6_dst
)) != 0) {
941 if (++i
>= XIDMAPSIZE
)
943 } while (i
!= xid_map_hint
);
950 * Routines for parsing reply packets
954 * Return a pointer to the beginning of the actual results.
955 * If the packet was truncated, return 0.
957 static const u_int32_t
*
958 parserep(register const struct rpc_msg
*rp
, register u_int length
)
960 register const u_int32_t
*dp
;
962 enum accept_stat astat
;
966 * Here we find the address of the ar_verf credentials.
967 * Originally, this calculation was
968 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
969 * On the wire, the rp_acpt field starts immediately after
970 * the (32 bit) rp_stat field. However, rp_acpt (which is a
971 * "struct accepted_reply") contains a "struct opaque_auth",
972 * whose internal representation contains a pointer, so on a
973 * 64-bit machine the compiler inserts 32 bits of padding
974 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
975 * the internal representation to parse the on-the-wire
976 * representation. Instead, we skip past the rp_stat field,
977 * which is an "enum" and so occupies one 32-bit word.
979 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
981 len
= EXTRACT_32BITS(&dp
[1]);
985 * skip past the ar_verf credentials.
987 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
991 * now we can check the ar_stat field
993 astat
= EXTRACT_32BITS(dp
);
1000 printf(" PROG_UNAVAIL");
1001 nfserr
= 1; /* suppress trunc string */
1005 printf(" PROG_MISMATCH");
1006 nfserr
= 1; /* suppress trunc string */
1010 printf(" PROC_UNAVAIL");
1011 nfserr
= 1; /* suppress trunc string */
1015 printf(" GARBAGE_ARGS");
1016 nfserr
= 1; /* suppress trunc string */
1020 printf(" SYSTEM_ERR");
1021 nfserr
= 1; /* suppress trunc string */
1025 printf(" ar_stat %d", astat
);
1026 nfserr
= 1; /* suppress trunc string */
1029 /* successful return */
1030 TCHECK2(*dp
, sizeof(astat
));
1031 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1036 static const u_int32_t
*
1037 parsestatus(const u_int32_t
*dp
, int *er
)
1043 errnum
= EXTRACT_32BITS(&dp
[0]);
1048 printf(" ERROR: %s",
1049 tok2str(status2str
, "unk %d", errnum
));
1057 static const u_int32_t
*
1058 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1060 const struct nfs_fattr
*fap
;
1062 fap
= (const struct nfs_fattr
*)dp
;
1063 TCHECK(fap
->fa_gid
);
1065 printf(" %s %o ids %d/%d",
1066 tok2str(type2str
, "unk-ft %d ",
1067 EXTRACT_32BITS(&fap
->fa_type
)),
1068 EXTRACT_32BITS(&fap
->fa_mode
),
1069 EXTRACT_32BITS(&fap
->fa_uid
),
1070 EXTRACT_32BITS(&fap
->fa_gid
));
1072 TCHECK(fap
->fa3_size
);
1074 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1076 TCHECK(fap
->fa2_size
);
1077 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1080 /* print lots more stuff */
1083 TCHECK(fap
->fa3_ctime
);
1084 printf(" nlink %d rdev %d/%d",
1085 EXTRACT_32BITS(&fap
->fa_nlink
),
1086 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1087 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1089 print_int64((u_int32_t
*)&fap
->fa3_fsid
, HEX
);
1091 print_int64((u_int32_t
*)&fap
->fa3_fileid
, HEX
);
1092 printf(" a/m/ctime %u.%06u",
1093 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1094 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1096 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1097 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1099 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1100 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1102 TCHECK(fap
->fa2_ctime
);
1103 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1104 EXTRACT_32BITS(&fap
->fa_nlink
),
1105 EXTRACT_32BITS(&fap
->fa2_rdev
),
1106 EXTRACT_32BITS(&fap
->fa2_fsid
),
1107 EXTRACT_32BITS(&fap
->fa2_fileid
));
1109 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1110 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1112 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1113 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1115 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1116 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1119 return ((const u_int32_t
*)((unsigned char *)dp
+
1120 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1126 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1130 dp
= parsestatus(dp
, &er
);
1136 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1140 parsediropres(const u_int32_t
*dp
)
1144 if (!(dp
= parsestatus(dp
, &er
)))
1149 dp
= parsefh(dp
, 0);
1153 return (parsefattr(dp
, vflag
, 0) != NULL
);
1157 parselinkres(const u_int32_t
*dp
, int v3
)
1161 dp
= parsestatus(dp
, &er
);
1166 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1169 return (parsefn(dp
) != NULL
);
1173 parsestatfs(const u_int32_t
*dp
, int v3
)
1175 const struct nfs_statfs
*sfsp
;
1178 dp
= parsestatus(dp
, &er
);
1190 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1194 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1196 sfsp
= (const struct nfs_statfs
*)dp
;
1200 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1202 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1204 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1207 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1209 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1211 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1213 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1216 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1217 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1218 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1219 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1220 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1221 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1230 parserddires(const u_int32_t
*dp
)
1234 dp
= parsestatus(dp
, &er
);
1243 printf(" offset %x size %d ",
1244 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1253 static const u_int32_t
*
1254 parse_wcc_attr(const u_int32_t
*dp
)
1257 print_int64(dp
, UNSIGNED
);
1258 printf(" mtime %u.%06u ctime %u.%06u",
1259 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1260 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1265 * Pre operation attributes. Print only if vflag > 1.
1267 static const u_int32_t
*
1268 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1271 if (!EXTRACT_32BITS(&dp
[0]))
1276 return parse_wcc_attr(dp
);
1278 /* If not verbose enough, just skip over wcc_attr */
1286 * Post operation attributes are printed if vflag >= 1
1288 static const u_int32_t
*
1289 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1292 if (!EXTRACT_32BITS(&dp
[0]))
1296 return parsefattr(dp
, verbose
, 1);
1298 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1303 static const u_int32_t
*
1304 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1308 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1313 return parse_post_op_attr(dp
, verbose
);
1316 static const u_int32_t
*
1317 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1321 if (!(dp
= parsestatus(dp
, &er
)))
1324 dp
= parse_wcc_data(dp
, verbose
);
1327 if (!EXTRACT_32BITS(&dp
[0]))
1330 if (!(dp
= parsefh(dp
, 1)))
1333 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1336 printf(" dir attr:");
1337 dp
= parse_wcc_data(dp
, verbose
);
1347 parsewccres(const u_int32_t
*dp
, int verbose
)
1351 if (!(dp
= parsestatus(dp
, &er
)))
1353 return parse_wcc_data(dp
, verbose
) != 0;
1356 static const u_int32_t
*
1357 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1361 if (!(dp
= parsestatus(dp
, &er
)))
1365 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1371 printf(" verf %08x%08x", dp
[0], dp
[1]);
1380 parsefsinfo(const u_int32_t
*dp
)
1382 struct nfsv3_fsinfo
*sfp
;
1385 if (!(dp
= parsestatus(dp
, &er
)))
1389 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1394 sfp
= (struct nfsv3_fsinfo
*)dp
;
1396 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1397 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1398 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1399 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1400 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1401 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1403 printf(" rtmult %u wtmult %u maxfsz ",
1404 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1405 EXTRACT_32BITS(&sfp
->fs_wtmult
));
1406 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1407 printf(" delta %u.%06u ",
1408 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1409 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1417 parsepathconf(const u_int32_t
*dp
)
1420 struct nfsv3_pathconf
*spp
;
1422 if (!(dp
= parsestatus(dp
, &er
)))
1426 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1431 spp
= (struct nfsv3_pathconf
*)dp
;
1434 printf(" linkmax %u namemax %u %s %s %s %s",
1435 EXTRACT_32BITS(&spp
->pc_linkmax
),
1436 EXTRACT_32BITS(&spp
->pc_namemax
),
1437 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1438 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1439 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1440 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1447 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1449 register const u_int32_t
*dp
;
1453 v3
= (vers
== NFS_VER3
);
1455 if (!v3
&& proc
< NFS_NPROCS
)
1456 proc
= nfsv3_procid
[proc
];
1468 case NFSPROC_GETATTR
:
1470 dp
= parserep(rp
, length
);
1471 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1475 case NFSPROC_SETATTR
:
1477 if (!(dp
= parserep(rp
, length
)))
1480 if (parsewccres(dp
, vflag
))
1483 if (parseattrstat(dp
, !qflag
, 0) != 0)
1488 case NFSPROC_LOOKUP
:
1490 if (!(dp
= parserep(rp
, length
)))
1493 if (!(dp
= parsestatus(dp
, &er
)))
1497 printf(" post dattr:");
1498 dp
= parse_post_op_attr(dp
, vflag
);
1501 if (!(dp
= parsefh(dp
, v3
)))
1503 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1505 printf(" post dattr:");
1506 dp
= parse_post_op_attr(dp
, vflag
);
1512 if (parsediropres(dp
) != 0)
1517 case NFSPROC_ACCESS
:
1519 if (!(dp
= parserep(rp
, length
)))
1521 if (!(dp
= parsestatus(dp
, &er
)))
1525 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1528 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1531 case NFSPROC_READLINK
:
1532 printf(" readlink");
1533 dp
= parserep(rp
, length
);
1534 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1540 if (!(dp
= parserep(rp
, length
)))
1543 if (!(dp
= parsestatus(dp
, &er
)))
1545 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1551 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1552 if (EXTRACT_32BITS(&dp
[1]))
1557 if (parseattrstat(dp
, vflag
, 0) != 0)
1564 if (!(dp
= parserep(rp
, length
)))
1567 if (!(dp
= parsestatus(dp
, &er
)))
1569 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1575 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1579 tok2str(nfsv3_writemodes
,
1580 NULL
, EXTRACT_32BITS(&dp
[1])));
1585 if (parseattrstat(dp
, vflag
, v3
) != 0)
1590 case NFSPROC_CREATE
:
1592 if (!(dp
= parserep(rp
, length
)))
1595 if (parsecreateopres(dp
, vflag
) != 0)
1598 if (parsediropres(dp
) != 0)
1605 if (!(dp
= parserep(rp
, length
)))
1608 if (parsecreateopres(dp
, vflag
) != 0)
1611 if (parsediropres(dp
) != 0)
1616 case NFSPROC_SYMLINK
:
1618 if (!(dp
= parserep(rp
, length
)))
1621 if (parsecreateopres(dp
, vflag
) != 0)
1624 if (parsestatus(dp
, &er
) != 0)
1631 if (!(dp
= parserep(rp
, length
)))
1633 if (parsecreateopres(dp
, vflag
) != 0)
1637 case NFSPROC_REMOVE
:
1639 if (!(dp
= parserep(rp
, length
)))
1642 if (parsewccres(dp
, vflag
))
1645 if (parsestatus(dp
, &er
) != 0)
1652 if (!(dp
= parserep(rp
, length
)))
1655 if (parsewccres(dp
, vflag
))
1658 if (parsestatus(dp
, &er
) != 0)
1663 case NFSPROC_RENAME
:
1665 if (!(dp
= parserep(rp
, length
)))
1668 if (!(dp
= parsestatus(dp
, &er
)))
1672 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1675 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1680 if (parsestatus(dp
, &er
) != 0)
1687 if (!(dp
= parserep(rp
, length
)))
1690 if (!(dp
= parsestatus(dp
, &er
)))
1693 printf(" file POST:");
1694 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1697 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1702 if (parsestatus(dp
, &er
) != 0)
1707 case NFSPROC_READDIR
:
1709 if (!(dp
= parserep(rp
, length
)))
1712 if (parsev3rddirres(dp
, vflag
))
1715 if (parserddires(dp
) != 0)
1720 case NFSPROC_READDIRPLUS
:
1721 printf(" readdirplus");
1722 if (!(dp
= parserep(rp
, length
)))
1724 if (parsev3rddirres(dp
, vflag
))
1728 case NFSPROC_FSSTAT
:
1730 dp
= parserep(rp
, length
);
1731 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1735 case NFSPROC_FSINFO
:
1737 dp
= parserep(rp
, length
);
1738 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1742 case NFSPROC_PATHCONF
:
1743 printf(" pathconf");
1744 dp
= parserep(rp
, length
);
1745 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1749 case NFSPROC_COMMIT
:
1751 dp
= parserep(rp
, length
);
1752 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1757 printf(" proc-%u", proc
);
1762 fputs(" [|nfs]", stdout
);