]>
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
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.94 2002-06-11 17:08:52 itojun Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
44 #include "interface.h"
45 #include "addrtoname.h"
55 static void nfs_printfh(const u_int32_t
*, const u_int
);
56 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
57 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
58 u_int32_t
*, u_int32_t
*);
59 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
60 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
61 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
62 static int print_int64(const u_int32_t
*dp
, int how
);
63 static void print_nfsaddr(const u_char
*, const char *, const char *);
66 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
68 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
98 * NFS V2 and V3 status values.
100 * Some of these come from the RFCs for NFS V2 and V3, with the message
101 * strings taken from the FreeBSD C library "errlst.c".
103 * Others are errors that are not in the RFC but that I suspect some
104 * NFS servers could return; the values are FreeBSD errno values, as
105 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
106 * was primarily BSD-derived.
108 static struct tok status2str
[] = {
109 { 1, "Operation not permitted" }, /* EPERM */
110 { 2, "No such file or directory" }, /* ENOENT */
111 { 5, "Input/output error" }, /* EIO */
112 { 6, "Device not configured" }, /* ENXIO */
113 { 11, "Resource deadlock avoided" }, /* EDEADLK */
114 { 12, "Cannot allocate memory" }, /* ENOMEM */
115 { 13, "Permission denied" }, /* EACCES */
116 { 17, "File exists" }, /* EEXIST */
117 { 18, "Cross-device link" }, /* EXDEV */
118 { 19, "Operation not supported by device" }, /* ENODEV */
119 { 20, "Not a directory" }, /* ENOTDIR */
120 { 21, "Is a directory" }, /* EISDIR */
121 { 22, "Invalid argument" }, /* EINVAL */
122 { 26, "Text file busy" }, /* ETXTBSY */
123 { 27, "File too large" }, /* EFBIG */
124 { 28, "No space left on device" }, /* ENOSPC */
125 { 30, "Read-only file system" }, /* EROFS */
126 { 31, "Too many links" }, /* EMLINK */
127 { 45, "Operation not supported" }, /* EOPNOTSUPP */
128 { 62, "Too many levels of symbolic links" }, /* ELOOP */
129 { 63, "File name too long" }, /* ENAMETOOLONG */
130 { 66, "Directory not empty" }, /* ENOTEMPTY */
131 { 69, "Disc quota exceeded" }, /* EDQUOT */
132 { 70, "Stale NFS file handle" }, /* ESTALE */
133 { 71, "Too many levels of remote in path" }, /* EREMOTE */
134 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
135 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
136 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
137 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
138 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
139 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
140 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
141 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
142 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
146 static struct tok nfsv3_writemodes
[] = {
153 static struct tok type2str
[] = {
165 * Print out a 64-bit integer. This appears to be different on each system,
166 * try to make the best of it. The integer stored as 2 consecutive XDR
167 * encoded 32-bit integers, to which a pointer is passed.
169 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
170 * integer datatype and can print it.
177 static int print_int64(const u_int32_t
*dp
, int how
)
182 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
185 printf(INT64_FORMAT
, res
);
188 printf(U_INT64_FORMAT
, res
);
191 printf(HEX_INT64_FORMAT
, res
);
201 printf("0x%x%08x", (u_int32_t
)ntohl(dp
[0]),
202 (u_int32_t
)ntohl(dp
[1]));
212 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
217 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
219 #ifndef INET_ADDRSTRLEN
220 #define INET_ADDRSTRLEN 16
222 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
225 srcaddr
[0] = dstaddr
[0] = '\0';
226 switch (IP_V((struct ip
*)bp
)) {
228 ip
= (struct ip
*)bp
;
229 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
230 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
234 ip6
= (struct ip6_hdr
*)bp
;
235 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
237 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
242 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
243 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
247 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
250 static const u_int32_t
*
251 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
254 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
256 sa3
->sa_mode
= ntohl(*dp
++);
260 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
262 sa3
->sa_uid
= ntohl(*dp
++);
266 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
268 sa3
->sa_gid
= ntohl(*dp
++);
272 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
274 sa3
->sa_size
= ntohl(*dp
++);
278 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
280 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
281 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
285 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
287 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
288 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
296 static int nfserr
; /* true if we error rather than trunc */
299 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
302 printf(" mode %o", sa3
->sa_mode
);
304 printf(" uid %u", sa3
->sa_uid
);
306 printf(" gid %u", sa3
->sa_gid
);
308 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
309 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
310 sa3
->sa_atime
.nfsv3_nsec
);
311 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
312 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
313 sa3
->sa_mtime
.nfsv3_nsec
);
318 nfsreply_print(register const u_char
*bp
, u_int length
,
319 register const u_char
*bp2
)
321 register const struct rpc_msg
*rp
;
322 u_int32_t proc
, vers
;
323 char srcid
[20], dstid
[20]; /*fits 32bit*/
325 nfserr
= 0; /* assume no error */
326 rp
= (const struct rpc_msg
*)bp
;
329 strlcpy(srcid
, "nfs", sizeof(srcid
));
330 snprintf(dstid
, sizeof(dstid
), "%u",
331 (u_int32_t
)ntohl(rp
->rm_xid
));
333 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
334 snprintf(dstid
, sizeof(dstid
), "%u",
335 (u_int32_t
)ntohl(rp
->rm_xid
));
337 print_nfsaddr(bp2
, srcid
, dstid
);
338 (void)printf("reply %s %d",
339 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
343 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
344 interp_reply(rp
, proc
, vers
, length
);
348 * Return a pointer to the first file handle in the packet.
349 * If the packet was truncated, return 0.
351 static const u_int32_t
*
352 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
354 register const u_int32_t
*dp
;
358 * find the start of the req data (if we captured it)
360 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
364 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
368 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
378 * Print out an NFS file handle and return a pointer to following word.
379 * If packet was truncated, return 0.
381 static const u_int32_t
*
382 parsefh(register const u_int32_t
*dp
, int v3
)
388 len
= (int)ntohl(*dp
) / 4;
393 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
394 nfs_printfh(dp
, len
);
402 * Print out a file name and return pointer to 32-bit word past it.
403 * If packet was truncated, return 0.
405 static const u_int32_t
*
406 parsefn(register const u_int32_t
*dp
)
408 register u_int32_t len
;
409 register const u_char
*cp
;
411 /* Bail if we don't have the string length */
414 /* Fetch string length; convert to host order */
418 TCHECK2(*dp
, ((len
+ 3) & ~3));
421 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
422 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
423 /* XXX seems like we should be checking the length */
425 (void) fn_printn(cp
, len
, NULL
);
434 * Print out file handle and file name.
435 * Return pointer to 32-bit word past file name.
436 * If packet was truncated (or there was some other error), return 0.
438 static const u_int32_t
*
439 parsefhn(register const u_int32_t
*dp
, int v3
)
441 dp
= parsefh(dp
, v3
);
445 return (parsefn(dp
));
449 nfsreq_print(register const u_char
*bp
, u_int length
,
450 register const u_char
*bp2
)
452 register const struct rpc_msg
*rp
;
453 register const u_int32_t
*dp
;
457 struct nfsv3_sattr sa3
;
458 char srcid
[20], dstid
[20]; /*fits 32bit*/
460 nfserr
= 0; /* assume no error */
461 rp
= (const struct rpc_msg
*)bp
;
463 snprintf(srcid
, sizeof(srcid
), "%u",
464 (u_int32_t
)ntohl(rp
->rm_xid
));
465 strlcpy(dstid
, "nfs", sizeof(dstid
));
467 snprintf(srcid
, sizeof(srcid
), "%u",
468 (u_int32_t
)ntohl(rp
->rm_xid
));
469 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
471 print_nfsaddr(bp2
, srcid
, dstid
);
472 (void)printf("%d", length
);
474 xid_map_enter(rp
, bp2
); /* record proc number for later on */
476 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
477 proc
= ntohl(rp
->rm_call
.cb_proc
);
479 if (!v3
&& proc
< NFS_NPROCS
)
480 proc
= nfsv3_procid
[proc
];
490 case NFSPROC_GETATTR
:
492 if ((dp
= parsereq(rp
, length
)) != NULL
&&
493 parsefh(dp
, v3
) != NULL
)
497 case NFSPROC_SETATTR
:
499 if ((dp
= parsereq(rp
, length
)) != NULL
&&
500 parsefh(dp
, v3
) != NULL
)
506 if ((dp
= parsereq(rp
, length
)) != NULL
&&
507 parsefhn(dp
, v3
) != NULL
)
513 if ((dp
= parsereq(rp
, length
)) != NULL
&&
514 (dp
= parsefh(dp
, v3
)) != NULL
) {
516 printf(" %04x", (u_int32_t
)ntohl(dp
[0]));
521 case NFSPROC_READLINK
:
523 if ((dp
= parsereq(rp
, length
)) != NULL
&&
524 parsefh(dp
, v3
) != NULL
)
530 if ((dp
= parsereq(rp
, length
)) != NULL
&&
531 (dp
= parsefh(dp
, v3
)) != NULL
) {
534 printf(" %u bytes @ ",
535 (u_int32_t
) ntohl(dp
[2]));
536 print_int64(dp
, UNSIGNED
);
539 printf(" %u bytes @ %u",
540 (u_int32_t
)ntohl(dp
[1]),
541 (u_int32_t
)ntohl(dp
[0]));
549 if ((dp
= parsereq(rp
, length
)) != NULL
&&
550 (dp
= parsefh(dp
, v3
)) != NULL
) {
553 printf(" %u bytes @ ",
554 (u_int32_t
) ntohl(dp
[4]));
555 print_int64(dp
, UNSIGNED
);
560 tok2str(nfsv3_writemodes
,
565 printf(" %u (%u) bytes @ %u (%u)",
566 (u_int32_t
)ntohl(dp
[3]),
567 (u_int32_t
)ntohl(dp
[2]),
568 (u_int32_t
)ntohl(dp
[1]),
569 (u_int32_t
)ntohl(dp
[0]));
577 if ((dp
= parsereq(rp
, length
)) != NULL
&&
578 parsefhn(dp
, v3
) != NULL
)
584 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
588 case NFSPROC_SYMLINK
:
590 if ((dp
= parsereq(rp
, length
)) != 0 &&
591 (dp
= parsefhn(dp
, v3
)) != 0) {
592 fputs(" ->", stdout
);
593 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
595 if (parsefn(dp
) == 0)
598 print_sattr3(&sa3
, vflag
);
605 if ((dp
= parsereq(rp
, length
)) != 0 &&
606 (dp
= parsefhn(dp
, v3
)) != 0) {
608 type
= (nfs_type
)ntohl(*dp
++);
609 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
611 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
612 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
615 (u_int32_t
)ntohl(dp
[0]),
616 (u_int32_t
)ntohl(dp
[1]));
620 print_sattr3(&sa3
, vflag
);
627 if ((dp
= parsereq(rp
, length
)) != NULL
&&
628 parsefhn(dp
, v3
) != NULL
)
634 if ((dp
= parsereq(rp
, length
)) != NULL
&&
635 parsefhn(dp
, v3
) != NULL
)
641 if ((dp
= parsereq(rp
, length
)) != NULL
&&
642 (dp
= parsefhn(dp
, v3
)) != NULL
) {
643 fputs(" ->", stdout
);
644 if (parsefhn(dp
, v3
) != NULL
)
651 if ((dp
= parsereq(rp
, length
)) != NULL
&&
652 (dp
= parsefh(dp
, v3
)) != NULL
) {
653 fputs(" ->", stdout
);
654 if (parsefhn(dp
, v3
) != NULL
)
659 case NFSPROC_READDIR
:
661 if ((dp
= parsereq(rp
, length
)) != NULL
&&
662 (dp
= parsefh(dp
, v3
)) != NULL
) {
666 * We shouldn't really try to interpret the
667 * offset cookie here.
669 printf(" %u bytes @ ",
670 (u_int32_t
) ntohl(dp
[4]));
671 print_int64(dp
, SIGNED
);
673 printf(" verf %08x%08x", dp
[2],
678 * Print the offset as signed, since -1 is
679 * common, but offsets > 2^31 aren't.
681 printf(" %u bytes @ %d",
682 (u_int32_t
)ntohl(dp
[1]),
683 (u_int32_t
)ntohl(dp
[0]));
689 case NFSPROC_READDIRPLUS
:
690 printf(" readdirplus");
691 if ((dp
= parsereq(rp
, length
)) != NULL
&&
692 (dp
= parsefh(dp
, v3
)) != NULL
) {
695 * We don't try to interpret the offset
698 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
699 print_int64(dp
, SIGNED
);
701 printf(" max %u verf %08x%08x",
702 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
709 if ((dp
= parsereq(rp
, length
)) != NULL
&&
710 parsefh(dp
, v3
) != NULL
)
716 if ((dp
= parsereq(rp
, length
)) != NULL
&&
717 parsefh(dp
, v3
) != NULL
)
721 case NFSPROC_PATHCONF
:
723 if ((dp
= parsereq(rp
, length
)) != NULL
&&
724 parsefh(dp
, v3
) != NULL
)
730 if ((dp
= parsereq(rp
, length
)) != NULL
&&
731 (dp
= parsefh(dp
, v3
)) != NULL
) {
732 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
733 print_int64(dp
, UNSIGNED
);
739 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
745 fputs(" [|nfs]", stdout
);
749 * Print out an NFS file handle.
750 * We assume packet was not truncated before the end of the
751 * file handle pointed to by dp.
753 * Note: new version (using portable file-handle parser) doesn't produce
754 * generation number. It probably could be made to do that, with some
755 * additional hacking on the parser code.
758 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
762 const char *sfsname
= NULL
;
765 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
768 /* file system ID is ASCII, not numeric, for this server OS */
769 static char temp
[NFSX_V3FHMAX
+1];
771 /* Make sure string is null-terminated */
772 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
773 temp
[sizeof(temp
) - 1] = '\0';
774 /* Remove trailing spaces */
775 spacep
= strchr(temp
, ' ');
779 (void)printf(" fh %s/", temp
);
781 (void)printf(" fh %d,%d/",
782 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
785 if(fsid
.Fsid_dev
.Minor
== 257 && uflag
)
786 /* Print the undecoded handle */
787 (void)printf("%s", fsid
.Opaque_Handle
);
789 (void)printf("%ld", (long) ino
);
793 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
794 * us to match up replies with requests and thus to know how to parse
798 struct xid_map_entry
{
799 u_int32_t xid
; /* transaction ID (net order) */
800 int ipver
; /* IP version (4 or 6) */
802 struct in6_addr client
; /* client IP address (net order) */
803 struct in6_addr server
; /* server IP address (net order) */
805 struct in_addr client
; /* client IP address (net order) */
806 struct in_addr server
; /* server IP address (net order) */
808 u_int32_t proc
; /* call proc number (host order) */
809 u_int32_t vers
; /* program version (host order) */
813 * Map entries are kept in an array that we manage as a ring;
814 * new entries are always added at the tail of the ring. Initially,
815 * all the entries are zero and hence don't match anything.
818 #define XIDMAPSIZE 64
820 struct xid_map_entry xid_map
[XIDMAPSIZE
];
822 int xid_map_next
= 0;
823 int xid_map_hint
= 0;
826 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
828 struct ip
*ip
= NULL
;
830 struct ip6_hdr
*ip6
= NULL
;
832 struct xid_map_entry
*xmep
;
834 switch (IP_V((struct ip
*)bp
)) {
836 ip
= (struct ip
*)bp
;
840 ip6
= (struct ip6_hdr
*)bp
;
847 xmep
= &xid_map
[xid_map_next
];
849 if (++xid_map_next
>= XIDMAPSIZE
)
852 xmep
->xid
= rp
->rm_xid
;
855 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
856 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
861 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
862 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
865 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
866 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
870 * Returns 0 and puts NFSPROC_xxx in proc return and
871 * version in vers return, or returns -1 on failure
874 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
878 struct xid_map_entry
*xmep
;
879 u_int32_t xid
= rp
->rm_xid
;
880 struct ip
*ip
= (struct ip
*)bp
;
882 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
886 /* Start searching from where we last left off */
891 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
893 switch (xmep
->ipver
) {
895 if (memcmp(&ip
->ip_src
, &xmep
->server
,
896 sizeof(ip
->ip_src
)) != 0 ||
897 memcmp(&ip
->ip_dst
, &xmep
->client
,
898 sizeof(ip
->ip_dst
)) != 0) {
904 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
905 sizeof(ip6
->ip6_src
)) != 0 ||
906 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
907 sizeof(ip6
->ip6_dst
)) != 0) {
924 if (++i
>= XIDMAPSIZE
)
926 } while (i
!= xid_map_hint
);
933 * Routines for parsing reply packets
937 * Return a pointer to the beginning of the actual results.
938 * If the packet was truncated, return 0.
940 static const u_int32_t
*
941 parserep(register const struct rpc_msg
*rp
, register u_int length
)
943 register const u_int32_t
*dp
;
945 enum accept_stat astat
;
949 * Here we find the address of the ar_verf credentials.
950 * Originally, this calculation was
951 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
952 * On the wire, the rp_acpt field starts immediately after
953 * the (32 bit) rp_stat field. However, rp_acpt (which is a
954 * "struct accepted_reply") contains a "struct opaque_auth",
955 * whose internal representation contains a pointer, so on a
956 * 64-bit machine the compiler inserts 32 bits of padding
957 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
958 * the internal representation to parse the on-the-wire
959 * representation. Instead, we skip past the rp_stat field,
960 * which is an "enum" and so occupies one 32-bit word.
962 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
968 * skip past the ar_verf credentials.
970 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
974 * now we can check the ar_stat field
976 astat
= ntohl(*(enum accept_stat
*)dp
);
983 printf(" PROG_UNAVAIL");
984 nfserr
= 1; /* suppress trunc string */
988 printf(" PROG_MISMATCH");
989 nfserr
= 1; /* suppress trunc string */
993 printf(" PROC_UNAVAIL");
994 nfserr
= 1; /* suppress trunc string */
998 printf(" GARBAGE_ARGS");
999 nfserr
= 1; /* suppress trunc string */
1003 printf(" SYSTEM_ERR");
1004 nfserr
= 1; /* suppress trunc string */
1008 printf(" ar_stat %d", astat
);
1009 nfserr
= 1; /* suppress trunc string */
1012 /* successful return */
1013 TCHECK2(*dp
, sizeof(astat
));
1014 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1019 static const u_int32_t
*
1020 parsestatus(const u_int32_t
*dp
, int *er
)
1026 errnum
= ntohl(dp
[0]);
1031 printf(" ERROR: %s",
1032 tok2str(status2str
, "unk %d", errnum
));
1040 static const u_int32_t
*
1041 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1043 const struct nfs_fattr
*fap
;
1045 fap
= (const struct nfs_fattr
*)dp
;
1046 TCHECK(fap
->fa_gid
);
1048 printf(" %s %o ids %d/%d",
1049 tok2str(type2str
, "unk-ft %d ",
1050 (u_int32_t
)ntohl(fap
->fa_type
)),
1051 (u_int32_t
)ntohl(fap
->fa_mode
),
1052 (u_int32_t
)ntohl(fap
->fa_uid
),
1053 (u_int32_t
) ntohl(fap
->fa_gid
));
1055 TCHECK(fap
->fa3_size
);
1057 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1060 TCHECK(fap
->fa2_size
);
1061 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1064 /* print lots more stuff */
1067 TCHECK(fap
->fa3_ctime
);
1068 printf("nlink %d rdev %d/%d ",
1069 (u_int32_t
)ntohl(fap
->fa_nlink
),
1070 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1071 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1073 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
1075 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
1076 printf(" a/m/ctime %u.%06u ",
1077 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1078 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1080 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1081 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1083 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1084 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1086 TCHECK(fap
->fa2_ctime
);
1087 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1088 (u_int32_t
) ntohl(fap
->fa_nlink
),
1089 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1090 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1091 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1093 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1094 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1096 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1097 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1099 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1100 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1103 return ((const u_int32_t
*)((unsigned char *)dp
+
1104 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1110 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1114 dp
= parsestatus(dp
, &er
);
1120 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1124 parsediropres(const u_int32_t
*dp
)
1128 if (!(dp
= parsestatus(dp
, &er
)))
1133 dp
= parsefh(dp
, 0);
1137 return (parsefattr(dp
, vflag
, 0) != NULL
);
1141 parselinkres(const u_int32_t
*dp
, int v3
)
1145 dp
= parsestatus(dp
, &er
);
1150 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1153 return (parsefn(dp
) != NULL
);
1157 parsestatfs(const u_int32_t
*dp
, int v3
)
1159 const struct nfs_statfs
*sfsp
;
1162 dp
= parsestatus(dp
, &er
);
1174 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1178 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1180 sfsp
= (const struct nfs_statfs
*)dp
;
1184 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1186 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1188 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1191 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1193 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1195 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1197 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1200 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1201 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1202 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1203 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1204 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1205 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1214 parserddires(const u_int32_t
*dp
)
1218 dp
= parsestatus(dp
, &er
);
1227 printf(" offset %x size %d ",
1228 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1237 static const u_int32_t
*
1238 parse_wcc_attr(const u_int32_t
*dp
)
1241 print_int64(dp
, UNSIGNED
);
1242 printf(" mtime %u.%06u ctime %u.%06u",
1243 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1244 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1249 * Pre operation attributes. Print only if vflag > 1.
1251 static const u_int32_t
*
1252 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1260 return parse_wcc_attr(dp
);
1262 /* If not verbose enough, just skip over wcc_attr */
1270 * Post operation attributes are printed if vflag >= 1
1272 static const u_int32_t
*
1273 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1280 return parsefattr(dp
, verbose
, 1);
1282 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1287 static const u_int32_t
*
1288 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1292 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1297 return parse_post_op_attr(dp
, verbose
);
1300 static const u_int32_t
*
1301 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1305 if (!(dp
= parsestatus(dp
, &er
)))
1308 dp
= parse_wcc_data(dp
, verbose
);
1314 if (!(dp
= parsefh(dp
, 1)))
1317 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1320 printf("dir attr:");
1321 dp
= parse_wcc_data(dp
, verbose
);
1331 parsewccres(const u_int32_t
*dp
, int verbose
)
1335 if (!(dp
= parsestatus(dp
, &er
)))
1337 return parse_wcc_data(dp
, verbose
) != 0;
1340 static const u_int32_t
*
1341 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1345 if (!(dp
= parsestatus(dp
, &er
)))
1349 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1355 printf(" verf %08x%08x", dp
[0], dp
[1]);
1364 parsefsinfo(const u_int32_t
*dp
)
1366 struct nfsv3_fsinfo
*sfp
;
1369 if (!(dp
= parsestatus(dp
, &er
)))
1373 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1378 sfp
= (struct nfsv3_fsinfo
*)dp
;
1380 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1381 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1382 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1383 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1384 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1385 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1387 printf(" rtmult %u wtmult %u maxfsz ",
1388 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1389 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1390 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1391 printf(" delta %u.%06u ",
1392 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1393 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1401 parsepathconf(const u_int32_t
*dp
)
1404 struct nfsv3_pathconf
*spp
;
1406 if (!(dp
= parsestatus(dp
, &er
)))
1410 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1415 spp
= (struct nfsv3_pathconf
*)dp
;
1418 printf(" linkmax %u namemax %u %s %s %s %s",
1419 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1420 (u_int32_t
) ntohl(spp
->pc_namemax
),
1421 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1422 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1423 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1424 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1431 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1433 register const u_int32_t
*dp
;
1437 v3
= (vers
== NFS_VER3
);
1439 if (!v3
&& proc
< NFS_NPROCS
)
1440 proc
= nfsv3_procid
[proc
];
1452 case NFSPROC_GETATTR
:
1454 dp
= parserep(rp
, length
);
1455 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1459 case NFSPROC_SETATTR
:
1461 if (!(dp
= parserep(rp
, length
)))
1464 if (parsewccres(dp
, vflag
))
1467 if (parseattrstat(dp
, !qflag
, 0) != 0)
1472 case NFSPROC_LOOKUP
:
1474 if (!(dp
= parserep(rp
, length
)))
1477 if (!(dp
= parsestatus(dp
, &er
)))
1481 printf(" post dattr:");
1482 dp
= parse_post_op_attr(dp
, vflag
);
1485 if (!(dp
= parsefh(dp
, v3
)))
1487 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1489 printf(" post dattr:");
1490 dp
= parse_post_op_attr(dp
, vflag
);
1496 if (parsediropres(dp
) != 0)
1501 case NFSPROC_ACCESS
:
1503 if (!(dp
= parserep(rp
, length
)))
1505 if (!(dp
= parsestatus(dp
, &er
)))
1509 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1512 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1515 case NFSPROC_READLINK
:
1516 printf(" readlink");
1517 dp
= parserep(rp
, length
);
1518 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1524 if (!(dp
= parserep(rp
, length
)))
1527 if (!(dp
= parsestatus(dp
, &er
)))
1529 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1535 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1541 if (parseattrstat(dp
, vflag
, 0) != 0)
1548 if (!(dp
= parserep(rp
, length
)))
1551 if (!(dp
= parsestatus(dp
, &er
)))
1553 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1559 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1563 tok2str(nfsv3_writemodes
,
1564 NULL
, ntohl(dp
[1])));
1569 if (parseattrstat(dp
, vflag
, v3
) != 0)
1574 case NFSPROC_CREATE
:
1576 if (!(dp
= parserep(rp
, length
)))
1579 if (parsecreateopres(dp
, vflag
) != 0)
1582 if (parsediropres(dp
) != 0)
1589 if (!(dp
= parserep(rp
, length
)))
1592 if (parsecreateopres(dp
, vflag
) != 0)
1595 if (parsediropres(dp
) != 0)
1600 case NFSPROC_SYMLINK
:
1602 if (!(dp
= parserep(rp
, length
)))
1605 if (parsecreateopres(dp
, vflag
) != 0)
1608 if (parsestatus(dp
, &er
) != 0)
1615 if (!(dp
= parserep(rp
, length
)))
1617 if (parsecreateopres(dp
, vflag
) != 0)
1621 case NFSPROC_REMOVE
:
1623 if (!(dp
= parserep(rp
, length
)))
1626 if (parsewccres(dp
, vflag
))
1629 if (parsestatus(dp
, &er
) != 0)
1636 if (!(dp
= parserep(rp
, length
)))
1639 if (parsewccres(dp
, vflag
))
1642 if (parsestatus(dp
, &er
) != 0)
1647 case NFSPROC_RENAME
:
1649 if (!(dp
= parserep(rp
, length
)))
1652 if (!(dp
= parsestatus(dp
, &er
)))
1656 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1659 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1664 if (parsestatus(dp
, &er
) != 0)
1671 if (!(dp
= parserep(rp
, length
)))
1674 if (!(dp
= parsestatus(dp
, &er
)))
1677 printf(" file POST:");
1678 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1681 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1686 if (parsestatus(dp
, &er
) != 0)
1691 case NFSPROC_READDIR
:
1693 if (!(dp
= parserep(rp
, length
)))
1696 if (parsev3rddirres(dp
, vflag
))
1699 if (parserddires(dp
) != 0)
1704 case NFSPROC_READDIRPLUS
:
1705 printf(" readdirplus");
1706 if (!(dp
= parserep(rp
, length
)))
1708 if (parsev3rddirres(dp
, vflag
))
1712 case NFSPROC_FSSTAT
:
1714 dp
= parserep(rp
, length
);
1715 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1719 case NFSPROC_FSINFO
:
1721 dp
= parserep(rp
, length
);
1722 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1726 case NFSPROC_PATHCONF
:
1727 printf(" pathconf");
1728 dp
= parserep(rp
, length
);
1729 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1733 case NFSPROC_COMMIT
:
1735 dp
= parserep(rp
, length
);
1736 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1741 printf(" proc-%u", proc
);
1746 fputs(" [|nfs]", stdout
);