]>
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.86 2000-10-03 02:54:59 itojun Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
38 #include <netinet/in.h>
40 #include <netinet/ip6.h>
50 #include "interface.h"
51 #include "addrtoname.h"
58 static void nfs_printfh(const u_int32_t
*, const u_int
);
59 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
60 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
61 u_int32_t
*, u_int32_t
*);
62 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
63 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
64 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
65 static int print_int64(const u_int32_t
*dp
, int how
);
66 static void print_nfsaddr(const u_char
*, const char *, const char *);
69 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
71 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
101 * NFS V2 and V3 status values.
103 * Some of these come from the RFCs for NFS V2 and V3, with the message
104 * strings taken from the FreeBSD C library "errlst.c".
106 * Others are errors that are not in the RFC but that I suspect some
107 * NFS servers could return; the values are FreeBSD errno values, as
108 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
109 * was primarily BSD-derived.
111 static struct tok status2str
[] = {
112 { 1, "Operation not permitted" }, /* EPERM */
113 { 2, "No such file or directory" }, /* ENOENT */
114 { 5, "Input/output error" }, /* EIO */
115 { 6, "Device not configured" }, /* ENXIO */
116 { 11, "Resource deadlock avoided" }, /* EDEADLK */
117 { 12, "Cannot allocate memory" }, /* ENOMEM */
118 { 13, "Permission denied" }, /* EACCES */
119 { 17, "File exists" }, /* EEXIST */
120 { 18, "Cross-device link" }, /* EXDEV */
121 { 19, "Operation not supported by device" }, /* ENODEV */
122 { 20, "Not a directory" }, /* ENOTDIR */
123 { 21, "Is a directory" }, /* EISDIR */
124 { 22, "Invalid argument" }, /* EINVAL */
125 { 26, "Text file busy" }, /* ETXTBSY */
126 { 27, "File too large" }, /* EFBIG */
127 { 28, "No space left on device" }, /* ENOSPC */
128 { 30, "Read-only file system" }, /* EROFS */
129 { 31, "Too many links" }, /* EMLINK */
130 { 45, "Operation not supported" }, /* EOPNOTSUPP */
131 { 62, "Too many levels of symbolic links" }, /* ELOOP */
132 { 63, "File name too long" }, /* ENAMETOOLONG */
133 { 66, "Directory not empty" }, /* ENOTEMPTY */
134 { 69, "Disc quota exceeded" }, /* EDQUOT */
135 { 70, "Stale NFS file handle" }, /* ESTALE */
136 { 71, "Too many levels of remote in path" }, /* EREMOTE */
137 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
138 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
139 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
140 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
141 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
142 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
143 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
144 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
145 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
149 static struct tok nfsv3_writemodes
[] = {
156 static struct tok type2str
[] = {
168 * Print out a 64-bit integer. This appears to be different on each system,
169 * try to make the best of it. The integer stored as 2 consecutive XDR
170 * encoded 32-bit integers, to which a pointer is passed.
172 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
173 * integer datatype and can print it.
180 static int print_int64(const u_int32_t
*dp
, int how
)
185 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
188 printf(INT64_FORMAT
, res
);
191 printf(U_INT64_FORMAT
, res
);
194 printf(HEX_INT64_FORMAT
, res
);
204 printf("0x%x%08x", (u_int32_t
)ntohl(dp
[0]),
205 (u_int32_t
)ntohl(dp
[1]));
215 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
220 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
222 #ifndef INET_ADDRSTRLEN
223 #define INET_ADDRSTRLEN 16
225 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
228 srcaddr
[0] = dstaddr
[0] = '\0';
229 switch (IP_V((struct ip
*)bp
)) {
231 ip
= (struct ip
*)bp
;
232 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
233 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
237 ip6
= (struct ip6_hdr
*)bp
;
238 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
240 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
245 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
246 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
250 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
253 static const u_int32_t
*
254 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
257 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
259 sa3
->sa_mode
= ntohl(*dp
++);
263 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
265 sa3
->sa_uid
= ntohl(*dp
++);
269 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
271 sa3
->sa_gid
= ntohl(*dp
++);
275 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
277 sa3
->sa_size
= ntohl(*dp
++);
281 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
283 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
284 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
288 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
290 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
291 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*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 (u_int32_t
)ntohl(rp
->rm_xid
));
336 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
337 snprintf(dstid
, sizeof(dstid
), "%u",
338 (u_int32_t
)ntohl(rp
->rm_xid
));
340 print_nfsaddr(bp2
, srcid
, dstid
);
341 (void)printf("reply %s %d",
342 ntohl(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
;
367 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
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
= (int)ntohl(*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 (u_int32_t
)ntohl(rp
->rm_xid
));
468 strlcpy(dstid
, "nfs", sizeof(dstid
));
470 snprintf(srcid
, sizeof(srcid
), "%u",
471 (u_int32_t
)ntohl(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
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
480 proc
= ntohl(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", (u_int32_t
)ntohl(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 (u_int32_t
) ntohl(dp
[2]));
539 print_int64(dp
, UNSIGNED
);
542 printf(" %u bytes @ %u",
543 (u_int32_t
)ntohl(dp
[1]),
544 (u_int32_t
)ntohl(dp
[0]));
552 if ((dp
= parsereq(rp
, length
)) != NULL
&&
553 (dp
= parsefh(dp
, v3
)) != NULL
) {
556 printf(" %u bytes @ ",
557 (u_int32_t
) ntohl(dp
[4]));
558 print_int64(dp
, UNSIGNED
);
563 tok2str(nfsv3_writemodes
,
568 printf(" %u (%u) bytes @ %u (%u)",
569 (u_int32_t
)ntohl(dp
[3]),
570 (u_int32_t
)ntohl(dp
[2]),
571 (u_int32_t
)ntohl(dp
[1]),
572 (u_int32_t
)ntohl(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
)ntohl(*dp
++);
612 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
614 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
615 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
618 (u_int32_t
)ntohl(dp
[0]),
619 (u_int32_t
)ntohl(dp
[1]));
623 print_sattr3(&sa3
, vflag
);
630 if ((dp
= parsereq(rp
, length
)) != NULL
&&
631 parsefhn(dp
, v3
) != NULL
)
637 if ((dp
= parsereq(rp
, length
)) != NULL
&&
638 parsefhn(dp
, v3
) != NULL
)
644 if ((dp
= parsereq(rp
, length
)) != NULL
&&
645 (dp
= parsefhn(dp
, v3
)) != NULL
) {
646 fputs(" ->", stdout
);
647 if (parsefhn(dp
, v3
) != NULL
)
654 if ((dp
= parsereq(rp
, length
)) != NULL
&&
655 (dp
= parsefh(dp
, v3
)) != NULL
) {
656 fputs(" ->", stdout
);
657 if (parsefhn(dp
, v3
) != NULL
)
662 case NFSPROC_READDIR
:
664 if ((dp
= parsereq(rp
, length
)) != NULL
&&
665 (dp
= parsefh(dp
, v3
)) != NULL
) {
669 * We shouldn't really try to interpret the
670 * offset cookie here.
672 printf(" %u bytes @ ",
673 (u_int32_t
) ntohl(dp
[4]));
674 print_int64(dp
, SIGNED
);
676 printf(" verf %08x%08x", dp
[2],
681 * Print the offset as signed, since -1 is
682 * common, but offsets > 2^31 aren't.
684 printf(" %u bytes @ %d",
685 (u_int32_t
)ntohl(dp
[1]),
686 (u_int32_t
)ntohl(dp
[0]));
692 case NFSPROC_READDIRPLUS
:
693 printf(" readdirplus");
694 if ((dp
= parsereq(rp
, length
)) != NULL
&&
695 (dp
= parsefh(dp
, v3
)) != NULL
) {
698 * We don't try to interpret the offset
701 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
702 print_int64(dp
, SIGNED
);
704 printf(" max %u verf %08x%08x",
705 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
712 if ((dp
= parsereq(rp
, length
)) != NULL
&&
713 parsefh(dp
, v3
) != NULL
)
721 case NFSPROC_PATHCONF
:
727 if ((dp
= parsereq(rp
, length
)) != NULL
&&
728 (dp
= parsefh(dp
, v3
)) != NULL
) {
729 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
730 print_int64(dp
, UNSIGNED
);
736 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
742 fputs(" [|nfs]", stdout
);
746 * Print out an NFS file handle.
747 * We assume packet was not truncated before the end of the
748 * file handle pointed to by dp.
750 * Note: new version (using portable file-handle parser) doesn't produce
751 * generation number. It probably could be made to do that, with some
752 * additional hacking on the parser code.
755 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
759 char *sfsname
= NULL
;
761 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
764 /* file system ID is ASCII, not numeric, for this server OS */
765 static char temp
[NFSX_V3FHMAX
+1];
767 /* Make sure string is null-terminated */
768 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
769 temp
[sizeof(temp
) - 1] = '\0';
770 /* Remove trailing spaces */
771 sfsname
= strchr(temp
, ' ');
775 (void)printf(" fh %s/", temp
);
777 (void)printf(" fh %d,%d/",
778 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
781 if(fsid
.Fsid_dev
.Minor
== 257 && uflag
)
782 /* Print the undecoded handle */
783 (void)printf("%s", fsid
.Opaque_Handle
);
785 (void)printf("%ld", (long) ino
);
789 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
790 * us to match up replies with requests and thus to know how to parse
794 struct xid_map_entry
{
795 u_int32_t xid
; /* transaction ID (net order) */
796 int ipver
; /* IP version (4 or 6) */
798 struct in6_addr client
; /* client IP address (net order) */
799 struct in6_addr server
; /* server IP address (net order) */
801 struct in_addr client
; /* client IP address (net order) */
802 struct in_addr server
; /* server IP address (net order) */
804 u_int32_t proc
; /* call proc number (host order) */
805 u_int32_t vers
; /* program version (host order) */
809 * Map entries are kept in an array that we manage as a ring;
810 * new entries are always added at the tail of the ring. Initially,
811 * all the entries are zero and hence don't match anything.
814 #define XIDMAPSIZE 64
816 struct xid_map_entry xid_map
[XIDMAPSIZE
];
818 int xid_map_next
= 0;
819 int xid_map_hint
= 0;
822 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
824 struct ip
*ip
= NULL
;
826 struct ip6_hdr
*ip6
= NULL
;
828 struct xid_map_entry
*xmep
;
830 switch (IP_V((struct ip
*)bp
)) {
832 ip
= (struct ip
*)bp
;
836 ip6
= (struct ip6_hdr
*)bp
;
843 xmep
= &xid_map
[xid_map_next
];
845 if (++xid_map_next
>= XIDMAPSIZE
)
848 xmep
->xid
= rp
->rm_xid
;
851 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
852 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
857 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
858 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
861 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
862 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
866 * Returns 0 and puts NFSPROC_xxx in proc return and
867 * version in vers return, or returns -1 on failure
870 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
874 struct xid_map_entry
*xmep
;
875 u_int32_t xid
= rp
->rm_xid
;
876 struct ip
*ip
= (struct ip
*)bp
;
878 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
882 /* Start searching from where we last left off */
887 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
889 switch (xmep
->ipver
) {
891 if (memcmp(&ip
->ip_src
, &xmep
->server
,
892 sizeof(ip
->ip_src
)) != 0 ||
893 memcmp(&ip
->ip_dst
, &xmep
->client
,
894 sizeof(ip
->ip_dst
)) != 0) {
900 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
901 sizeof(ip6
->ip6_src
)) != 0 ||
902 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
903 sizeof(ip6
->ip6_dst
)) != 0) {
920 if (++i
>= XIDMAPSIZE
)
922 } while (i
!= xid_map_hint
);
929 * Routines for parsing reply packets
933 * Return a pointer to the beginning of the actual results.
934 * If the packet was truncated, return 0.
936 static const u_int32_t
*
937 parserep(register const struct rpc_msg
*rp
, register u_int length
)
939 register const u_int32_t
*dp
;
941 enum accept_stat astat
;
945 * Here we find the address of the ar_verf credentials.
946 * Originally, this calculation was
947 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
948 * On the wire, the rp_acpt field starts immediately after
949 * the (32 bit) rp_stat field. However, rp_acpt (which is a
950 * "struct accepted_reply") contains a "struct opaque_auth",
951 * whose internal representation contains a pointer, so on a
952 * 64-bit machine the compiler inserts 32 bits of padding
953 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
954 * the internal representation to parse the on-the-wire
955 * representation. Instead, we skip past the rp_stat field,
956 * which is an "enum" and so occupies one 32-bit word.
958 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
964 * skip past the ar_verf credentials.
966 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
970 * now we can check the ar_stat field
972 astat
= ntohl(*(enum accept_stat
*)dp
);
979 printf(" PROG_UNAVAIL");
980 nfserr
= 1; /* suppress trunc string */
984 printf(" PROG_MISMATCH");
985 nfserr
= 1; /* suppress trunc string */
989 printf(" PROC_UNAVAIL");
990 nfserr
= 1; /* suppress trunc string */
994 printf(" GARBAGE_ARGS");
995 nfserr
= 1; /* suppress trunc string */
999 printf(" SYSTEM_ERR");
1000 nfserr
= 1; /* suppress trunc string */
1004 printf(" ar_stat %d", astat
);
1005 nfserr
= 1; /* suppress trunc string */
1008 /* successful return */
1009 TCHECK2(*dp
, sizeof(astat
));
1010 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1015 static const u_int32_t
*
1016 parsestatus(const u_int32_t
*dp
, int *er
)
1022 errnum
= ntohl(dp
[0]);
1027 printf(" ERROR: %s",
1028 tok2str(status2str
, "unk %d", errnum
));
1037 static const u_int32_t
*
1038 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1040 const struct nfs_fattr
*fap
;
1042 fap
= (const struct nfs_fattr
*)dp
;
1043 TCHECK(fap
->fa_gid
);
1045 printf(" %s %o ids %d/%d",
1046 tok2str(type2str
, "unk-ft %d ",
1047 (u_int32_t
)ntohl(fap
->fa_type
)),
1048 (u_int32_t
)ntohl(fap
->fa_mode
),
1049 (u_int32_t
)ntohl(fap
->fa_uid
),
1050 (u_int32_t
) ntohl(fap
->fa_gid
));
1052 TCHECK(fap
->fa3_size
);
1054 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1057 TCHECK(fap
->fa2_size
);
1058 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1061 /* print lots more stuff */
1064 TCHECK(fap
->fa3_ctime
);
1065 printf("nlink %d rdev %d/%d ",
1066 (u_int32_t
)ntohl(fap
->fa_nlink
),
1067 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1068 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1070 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
1072 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
1073 printf(" a/m/ctime %u.%06u ",
1074 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1075 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1077 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1078 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1080 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1081 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1083 TCHECK(fap
->fa2_ctime
);
1084 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1085 (u_int32_t
) ntohl(fap
->fa_nlink
),
1086 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1087 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1088 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1090 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1091 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1093 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1094 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1096 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1097 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1100 return ((const u_int32_t
*)((unsigned char *)dp
+
1101 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1107 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1111 dp
= parsestatus(dp
, &er
);
1112 if (dp
== NULL
|| er
)
1115 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1119 parsediropres(const u_int32_t
*dp
)
1123 if (!(dp
= parsestatus(dp
, &er
)) || er
)
1126 dp
= parsefh(dp
, 0);
1130 return (parsefattr(dp
, vflag
, 0) != NULL
);
1134 parselinkres(const u_int32_t
*dp
, int v3
)
1138 dp
= parsestatus(dp
, &er
);
1139 if (dp
== NULL
|| er
)
1141 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1144 return (parsefn(dp
) != NULL
);
1148 parsestatfs(const u_int32_t
*dp
, int v3
)
1150 const struct nfs_statfs
*sfsp
;
1153 dp
= parsestatus(dp
, &er
);
1154 if (dp
== NULL
|| (!v3
&& er
))
1163 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1167 TCHECK2(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1169 sfsp
= (const struct nfs_statfs
*)dp
;
1173 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1175 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1177 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1180 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1182 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1184 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1186 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1189 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1190 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1191 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1192 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1193 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1194 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1203 parserddires(const u_int32_t
*dp
)
1207 dp
= parsestatus(dp
, &er
);
1214 printf(" offset %x size %d ",
1215 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1224 static const u_int32_t
*
1225 parse_wcc_attr(const u_int32_t
*dp
)
1228 print_int64(dp
, UNSIGNED
);
1229 printf(" mtime %u.%06u ctime %u.%06u",
1230 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1231 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1236 * Pre operation attributes. Print only if vflag > 1.
1238 static const u_int32_t
*
1239 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1247 return parse_wcc_attr(dp
);
1249 /* If not verbose enough, just skip over wcc_attr */
1257 * Post operation attributes are printed if vflag >= 1
1259 static const u_int32_t
*
1260 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1267 return parsefattr(dp
, verbose
, 1);
1269 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1274 static const u_int32_t
*
1275 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1279 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1284 return parse_post_op_attr(dp
, verbose
);
1287 static const u_int32_t
*
1288 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1292 if (!(dp
= parsestatus(dp
, &er
)))
1295 dp
= parse_wcc_data(dp
, verbose
);
1301 if (!(dp
= parsefh(dp
, 1)))
1304 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1307 printf("dir attr:");
1308 dp
= parse_wcc_data(dp
, verbose
);
1318 parsewccres(const u_int32_t
*dp
, int verbose
)
1322 if (!(dp
= parsestatus(dp
, &er
)))
1324 return parse_wcc_data(dp
, verbose
) != 0;
1327 static const u_int32_t
*
1328 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1332 if (!(dp
= parsestatus(dp
, &er
)))
1336 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1342 printf(" verf %08x%08x", dp
[0], dp
[1]);
1351 parsefsinfo(const u_int32_t
*dp
)
1353 struct nfsv3_fsinfo
*sfp
;
1356 if (!(dp
= parsestatus(dp
, &er
)))
1360 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1365 sfp
= (struct nfsv3_fsinfo
*)dp
;
1367 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1368 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1369 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1370 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1371 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1372 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1374 printf(" rtmult %u wtmult %u maxfsz ",
1375 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1376 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1377 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1378 printf(" delta %u.%06u ",
1379 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1380 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1388 parsepathconf(const u_int32_t
*dp
)
1391 struct nfsv3_pathconf
*spp
;
1393 if (!(dp
= parsestatus(dp
, &er
)))
1397 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1402 spp
= (struct nfsv3_pathconf
*)dp
;
1405 printf(" linkmax %u namemax %u %s %s %s %s",
1406 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1407 (u_int32_t
) ntohl(spp
->pc_namemax
),
1408 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1409 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1410 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1411 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1418 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1420 register const u_int32_t
*dp
;
1424 v3
= (vers
== NFS_VER3
);
1426 if (!v3
&& proc
< NFS_NPROCS
)
1427 proc
= nfsv3_procid
[proc
];
1439 case NFSPROC_GETATTR
:
1441 dp
= parserep(rp
, length
);
1442 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1446 case NFSPROC_SETATTR
:
1448 if (!(dp
= parserep(rp
, length
)))
1451 if (parsewccres(dp
, vflag
))
1454 if (parseattrstat(dp
, !qflag
, 0) != 0)
1459 case NFSPROC_LOOKUP
:
1461 if (!(dp
= parserep(rp
, length
)))
1464 if (!(dp
= parsestatus(dp
, &er
)))
1468 printf(" post dattr:");
1469 dp
= parse_post_op_attr(dp
, vflag
);
1472 if (!(dp
= parsefh(dp
, v3
)))
1474 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1476 printf(" post dattr:");
1477 dp
= parse_post_op_attr(dp
, vflag
);
1483 if (parsediropres(dp
) != 0)
1488 case NFSPROC_ACCESS
:
1490 dp
= parserep(rp
, length
);
1491 if (!(dp
= parsestatus(dp
, &er
)))
1495 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1498 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1501 case NFSPROC_READLINK
:
1502 printf(" readlink");
1503 dp
= parserep(rp
, length
);
1504 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1510 if (!(dp
= parserep(rp
, length
)))
1513 if (!(dp
= parsestatus(dp
, &er
)))
1515 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1521 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1527 if (parseattrstat(dp
, vflag
, 0) != 0)
1534 if (!(dp
= parserep(rp
, length
)))
1537 if (!(dp
= parsestatus(dp
, &er
)))
1539 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1545 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1549 tok2str(nfsv3_writemodes
,
1550 NULL
, ntohl(dp
[1])));
1555 if (parseattrstat(dp
, vflag
, v3
) != 0)
1560 case NFSPROC_CREATE
:
1562 if (!(dp
= parserep(rp
, length
)))
1565 if (parsecreateopres(dp
, vflag
) != 0)
1568 if (parsediropres(dp
) != 0)
1575 if (!(dp
= parserep(rp
, length
)))
1578 if (parsecreateopres(dp
, vflag
) != 0)
1581 if (parsediropres(dp
) != 0)
1586 case NFSPROC_SYMLINK
:
1588 if (!(dp
= parserep(rp
, length
)))
1591 if (parsecreateopres(dp
, vflag
) != 0)
1594 if (parsestatus(dp
, &er
) != 0)
1601 if (!(dp
= parserep(rp
, length
)))
1603 if (parsecreateopres(dp
, vflag
) != 0)
1607 case NFSPROC_REMOVE
:
1609 if (!(dp
= parserep(rp
, length
)))
1612 if (parsewccres(dp
, vflag
))
1615 if (parsestatus(dp
, &er
) != 0)
1622 if (!(dp
= parserep(rp
, length
)))
1625 if (parsewccres(dp
, vflag
))
1628 if (parsestatus(dp
, &er
) != 0)
1633 case NFSPROC_RENAME
:
1635 if (!(dp
= parserep(rp
, length
)))
1638 if (!(dp
= parsestatus(dp
, &er
)))
1642 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1645 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1650 if (parsestatus(dp
, &er
) != 0)
1657 if (!(dp
= parserep(rp
, length
)))
1660 if (!(dp
= parsestatus(dp
, &er
)))
1663 printf(" file POST:");
1664 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1667 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1672 if (parsestatus(dp
, &er
) != 0)
1677 case NFSPROC_READDIR
:
1679 if (!(dp
= parserep(rp
, length
)))
1682 if (parsev3rddirres(dp
, vflag
))
1685 if (parserddires(dp
) != 0)
1690 case NFSPROC_READDIRPLUS
:
1691 printf(" readdirplus");
1692 if (!(dp
= parserep(rp
, length
)))
1694 if (parsev3rddirres(dp
, vflag
))
1698 case NFSPROC_FSSTAT
:
1700 dp
= parserep(rp
, length
);
1701 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1705 case NFSPROC_FSINFO
:
1707 dp
= parserep(rp
, length
);
1708 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1712 case NFSPROC_PATHCONF
:
1713 printf(" pathconf");
1714 dp
= parserep(rp
, length
);
1715 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1719 case NFSPROC_COMMIT
:
1721 dp
= parserep(rp
, length
);
1722 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1727 printf(" proc-%u", proc
);
1732 fputs(" [|nfs]", stdout
);