]>
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.83 2000-09-23 08:54:35 guy Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
42 #include <netinet/ip6.h>
52 #include "interface.h"
53 #include "addrtoname.h"
60 static void nfs_printfh(const u_int32_t
*, const u_int
);
61 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
62 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
63 u_int32_t
*, u_int32_t
*);
64 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
65 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
66 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
67 static int print_int64(const u_int32_t
*dp
, int how
);
68 static void print_nfsaddr(const u_char
*, const char *, const char *);
71 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
73 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
103 * NFS V2 and V3 status values.
105 * Some of these come from the RFCs for NFS V2 and V3, with the message
106 * strings taken from the FreeBSD C library "errlst.c".
108 * Others are errors that are not in the RFC but that I suspect some
109 * NFS servers could return; the values are FreeBSD errno values, as
110 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
111 * was primarily BSD-derived.
113 static struct tok status2str
[] = {
114 { 1, "Operation not permitted" }, /* EPERM */
115 { 2, "No such file or directory" }, /* ENOENT */
116 { 5, "Input/output error" }, /* EIO */
117 { 6, "Device not configured" }, /* ENXIO */
118 { 11, "Resource deadlock avoided" }, /* EDEADLK */
119 { 12, "Cannot allocate memory" }, /* ENOMEM */
120 { 13, "Permission denied" }, /* EACCES */
121 { 17, "File exists" }, /* EEXIST */
122 { 18, "Cross-device link" }, /* EXDEV */
123 { 19, "Operation not supported by device" }, /* ENODEV */
124 { 20, "Not a directory" }, /* ENOTDIR */
125 { 21, "Is a directory" }, /* EISDIR */
126 { 22, "Invalid argument" }, /* EINVAL */
127 { 26, "Text file busy" }, /* ETXTBSY */
128 { 27, "File too large" }, /* EFBIG */
129 { 28, "No space left on device" }, /* ENOSPC */
130 { 30, "Read-only file system" }, /* EROFS */
131 { 31, "Too many links" }, /* EMLINK */
132 { 45, "Operation not supported" }, /* EOPNOTSUPP */
133 { 62, "Too many levels of symbolic links" }, /* ELOOP */
134 { 63, "File name too long" }, /* ENAMETOOLONG */
135 { 66, "Directory not empty" }, /* ENOTEMPTY */
136 { 69, "Disc quota exceeded" }, /* EDQUOT */
137 { 70, "Stale NFS file handle" }, /* ESTALE */
138 { 71, "Too many levels of remote in path" }, /* EREMOTE */
139 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
140 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
141 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
142 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
143 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
144 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
145 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
146 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
147 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
151 static struct tok nfsv3_writemodes
[] = {
158 static struct tok type2str
[] = {
170 * Print out a 64-bit integer. This appears to be different on each system,
171 * try to make the best of it. The integer stored as 2 consecutive XDR
172 * encoded 32-bit integers, to which a pointer is passed.
174 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
175 * integer datatype and can print it.
182 static int print_int64(const u_int32_t
*dp
, int how
)
187 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
190 printf(INT64_FORMAT
, res
);
193 printf(U_INT64_FORMAT
, res
);
196 printf(HEX_INT64_FORMAT
, res
);
206 printf("0x%x%08x", (u_int32_t
)ntohl(dp
[0]),
207 (u_int32_t
)ntohl(dp
[1]));
217 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
222 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
224 #ifndef INET_ADDRSTRLEN
225 #define INET_ADDRSTRLEN 16
227 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
230 srcaddr
[0] = dstaddr
[0] = '\0';
231 switch (((struct ip
*)bp
)->ip_v
) {
233 ip
= (struct ip
*)bp
;
234 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
235 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
239 ip6
= (struct ip6_hdr
*)bp
;
240 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
242 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
247 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
248 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
252 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
255 static const u_int32_t
*
256 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
259 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
261 sa3
->sa_mode
= ntohl(*dp
++);
265 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
267 sa3
->sa_uid
= ntohl(*dp
++);
271 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
273 sa3
->sa_gid
= ntohl(*dp
++);
277 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
279 sa3
->sa_size
= ntohl(*dp
++);
283 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
285 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
286 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
290 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
292 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
293 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
301 static int nfserr
; /* true if we error rather than trunc */
304 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
307 printf(" mode %o", sa3
->sa_mode
);
309 printf(" uid %u", sa3
->sa_uid
);
311 printf(" gid %u", sa3
->sa_gid
);
313 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
314 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
315 sa3
->sa_atime
.nfsv3_nsec
);
316 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
317 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
318 sa3
->sa_mtime
.nfsv3_nsec
);
323 nfsreply_print(register const u_char
*bp
, u_int length
,
324 register const u_char
*bp2
)
326 register const struct rpc_msg
*rp
;
327 u_int32_t proc
, vers
;
328 char srcid
[20], dstid
[20]; /*fits 32bit*/
330 nfserr
= 0; /* assume no error */
331 rp
= (const struct rpc_msg
*)bp
;
334 strlcpy(srcid
, "nfs", sizeof(srcid
));
335 snprintf(dstid
, sizeof(dstid
), "%u",
336 (u_int32_t
)ntohl(rp
->rm_xid
));
338 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
339 snprintf(dstid
, sizeof(dstid
), "%u",
340 (u_int32_t
)ntohl(rp
->rm_xid
));
342 print_nfsaddr(bp2
, srcid
, dstid
);
343 (void)printf("reply %s %d",
344 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
348 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
349 interp_reply(rp
, proc
, vers
, length
);
353 * Return a pointer to the first file handle in the packet.
354 * If the packet was truncated, return 0.
356 static const u_int32_t
*
357 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
359 register const u_int32_t
*dp
;
363 * find the start of the req data (if we captured it)
365 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
369 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
373 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
383 * Print out an NFS file handle and return a pointer to following word.
384 * If packet was truncated, return 0.
386 static const u_int32_t
*
387 parsefh(register const u_int32_t
*dp
, int v3
)
393 len
= (int)ntohl(*dp
) / 4;
398 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
399 nfs_printfh(dp
, len
);
407 * Print out a file name and return pointer to 32-bit word past it.
408 * If packet was truncated, return 0.
410 static const u_int32_t
*
411 parsefn(register const u_int32_t
*dp
)
413 register u_int32_t len
;
414 register const u_char
*cp
;
416 /* Bail if we don't have the string length */
419 /* Fetch string length; convert to host order */
423 TCHECK2(*dp
, ((len
+ 3) & ~3));
426 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
427 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
428 /* XXX seems like we should be checking the length */
430 (void) fn_printn(cp
, len
, NULL
);
439 * Print out file handle and file name.
440 * Return pointer to 32-bit word past file name.
441 * If packet was truncated (or there was some other error), return 0.
443 static const u_int32_t
*
444 parsefhn(register const u_int32_t
*dp
, int v3
)
446 dp
= parsefh(dp
, v3
);
450 return (parsefn(dp
));
454 nfsreq_print(register const u_char
*bp
, u_int length
,
455 register const u_char
*bp2
)
457 register const struct rpc_msg
*rp
;
458 register const u_int32_t
*dp
;
462 struct nfsv3_sattr sa3
;
463 char srcid
[20], dstid
[20]; /*fits 32bit*/
465 nfserr
= 0; /* assume no error */
466 rp
= (const struct rpc_msg
*)bp
;
468 snprintf(srcid
, sizeof(srcid
), "%u",
469 (u_int32_t
)ntohl(rp
->rm_xid
));
470 strlcpy(dstid
, "nfs", sizeof(dstid
));
472 snprintf(srcid
, sizeof(srcid
), "%u",
473 (u_int32_t
)ntohl(rp
->rm_xid
));
474 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
476 print_nfsaddr(bp2
, srcid
, dstid
);
477 (void)printf("%d", length
);
479 xid_map_enter(rp
, bp2
); /* record proc number for later on */
481 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
482 proc
= ntohl(rp
->rm_call
.cb_proc
);
484 if (!v3
&& proc
< NFS_NPROCS
)
485 proc
= nfsv3_procid
[proc
];
495 case NFSPROC_GETATTR
:
497 if ((dp
= parsereq(rp
, length
)) != NULL
&&
498 parsefh(dp
, v3
) != NULL
)
502 case NFSPROC_SETATTR
:
504 if ((dp
= parsereq(rp
, length
)) != NULL
&&
505 parsefh(dp
, v3
) != NULL
)
511 if ((dp
= parsereq(rp
, length
)) != NULL
&&
512 parsefhn(dp
, v3
) != NULL
)
518 if ((dp
= parsereq(rp
, length
)) != NULL
&&
519 (dp
= parsefh(dp
, v3
)) != NULL
) {
521 printf(" %04x", (u_int32_t
)ntohl(dp
[0]));
526 case NFSPROC_READLINK
:
528 if ((dp
= parsereq(rp
, length
)) != NULL
&&
529 parsefh(dp
, v3
) != NULL
)
535 if ((dp
= parsereq(rp
, length
)) != NULL
&&
536 (dp
= parsefh(dp
, v3
)) != NULL
) {
539 printf(" %u bytes @ ",
540 (u_int32_t
) ntohl(dp
[2]));
541 print_int64(dp
, UNSIGNED
);
544 printf(" %u bytes @ %u",
545 (u_int32_t
)ntohl(dp
[1]),
546 (u_int32_t
)ntohl(dp
[0]));
554 if ((dp
= parsereq(rp
, length
)) != NULL
&&
555 (dp
= parsefh(dp
, v3
)) != NULL
) {
558 printf(" %u bytes @ ",
559 (u_int32_t
) ntohl(dp
[4]));
560 print_int64(dp
, UNSIGNED
);
565 tok2str(nfsv3_writemodes
,
570 printf(" %u (%u) bytes @ %u (%u)",
571 (u_int32_t
)ntohl(dp
[3]),
572 (u_int32_t
)ntohl(dp
[2]),
573 (u_int32_t
)ntohl(dp
[1]),
574 (u_int32_t
)ntohl(dp
[0]));
582 if ((dp
= parsereq(rp
, length
)) != NULL
&&
583 parsefhn(dp
, v3
) != NULL
)
589 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
593 case NFSPROC_SYMLINK
:
595 if ((dp
= parsereq(rp
, length
)) != 0 &&
596 (dp
= parsefhn(dp
, v3
)) != 0) {
597 fputs(" ->", stdout
);
598 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
600 if (parsefn(dp
) == 0)
603 print_sattr3(&sa3
, vflag
);
610 if ((dp
= parsereq(rp
, length
)) != 0 &&
611 (dp
= parsefhn(dp
, v3
)) != 0) {
613 type
= (nfs_type
)ntohl(*dp
++);
614 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
616 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
617 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
620 (u_int32_t
)ntohl(dp
[0]),
621 (u_int32_t
)ntohl(dp
[1]));
625 print_sattr3(&sa3
, vflag
);
632 if ((dp
= parsereq(rp
, length
)) != NULL
&&
633 parsefhn(dp
, v3
) != NULL
)
639 if ((dp
= parsereq(rp
, length
)) != NULL
&&
640 parsefhn(dp
, v3
) != NULL
)
646 if ((dp
= parsereq(rp
, length
)) != NULL
&&
647 (dp
= parsefhn(dp
, v3
)) != NULL
) {
648 fputs(" ->", stdout
);
649 if (parsefhn(dp
, v3
) != NULL
)
656 if ((dp
= parsereq(rp
, length
)) != NULL
&&
657 (dp
= parsefh(dp
, v3
)) != NULL
) {
658 fputs(" ->", stdout
);
659 if (parsefhn(dp
, v3
) != NULL
)
664 case NFSPROC_READDIR
:
666 if ((dp
= parsereq(rp
, length
)) != NULL
&&
667 (dp
= parsefh(dp
, v3
)) != NULL
) {
671 * We shouldn't really try to interpret the
672 * offset cookie here.
674 printf(" %u bytes @ ",
675 (u_int32_t
) ntohl(dp
[4]));
676 print_int64(dp
, SIGNED
);
678 printf(" verf %08x%08x", dp
[2],
683 * Print the offset as signed, since -1 is
684 * common, but offsets > 2^31 aren't.
686 printf(" %u bytes @ %d",
687 (u_int32_t
)ntohl(dp
[1]),
688 (u_int32_t
)ntohl(dp
[0]));
694 case NFSPROC_READDIRPLUS
:
695 printf(" readdirplus");
696 if ((dp
= parsereq(rp
, length
)) != NULL
&&
697 (dp
= parsefh(dp
, v3
)) != NULL
) {
700 * We don't try to interpret the offset
703 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
704 print_int64(dp
, SIGNED
);
706 printf(" max %u verf %08x%08x",
707 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
714 if ((dp
= parsereq(rp
, length
)) != NULL
&&
715 parsefh(dp
, v3
) != NULL
)
723 case NFSPROC_PATHCONF
:
729 if ((dp
= parsereq(rp
, length
)) != NULL
&&
730 (dp
= parsefh(dp
, v3
)) != NULL
) {
731 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
732 print_int64(dp
, UNSIGNED
);
738 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
744 fputs(" [|nfs]", stdout
);
748 * Print out an NFS file handle.
749 * We assume packet was not truncated before the end of the
750 * file handle pointed to by dp.
752 * Note: new version (using portable file-handle parser) doesn't produce
753 * generation number. It probably could be made to do that, with some
754 * additional hacking on the parser code.
757 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
761 char *sfsname
= NULL
;
763 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
766 /* file system ID is ASCII, not numeric, for this server OS */
767 static char temp
[NFSX_V3FHMAX
+1];
769 /* Make sure string is null-terminated */
770 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
771 temp
[sizeof(temp
) - 1] = '\0';
772 /* Remove trailing spaces */
773 sfsname
= strchr(temp
, ' ');
777 (void)printf(" fh %s/", temp
);
779 (void)printf(" fh %d,%d/",
780 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
783 if(fsid
.Fsid_dev
.Minor
== 257 && uflag
)
784 /* Print the undecoded handle */
785 (void)printf("%s", fsid
.Opaque_Handle
);
787 (void)printf("%ld", (long) ino
);
791 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
792 * us to match up replies with requests and thus to know how to parse
796 struct xid_map_entry
{
797 u_int32_t xid
; /* transaction ID (net order) */
798 int ipver
; /* IP version (4 or 6) */
800 struct in6_addr client
; /* client IP address (net order) */
801 struct in6_addr server
; /* server IP address (net order) */
803 struct in_addr client
; /* client IP address (net order) */
804 struct in_addr server
; /* server IP address (net order) */
806 u_int32_t proc
; /* call proc number (host order) */
807 u_int32_t vers
; /* program version (host order) */
811 * Map entries are kept in an array that we manage as a ring;
812 * new entries are always added at the tail of the ring. Initially,
813 * all the entries are zero and hence don't match anything.
816 #define XIDMAPSIZE 64
818 struct xid_map_entry xid_map
[XIDMAPSIZE
];
820 int xid_map_next
= 0;
821 int xid_map_hint
= 0;
824 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
826 struct ip
*ip
= NULL
;
828 struct ip6_hdr
*ip6
= NULL
;
830 struct xid_map_entry
*xmep
;
832 switch (((struct ip
*)bp
)->ip_v
) {
834 ip
= (struct ip
*)bp
;
838 ip6
= (struct ip6_hdr
*)bp
;
845 xmep
= &xid_map
[xid_map_next
];
847 if (++xid_map_next
>= XIDMAPSIZE
)
850 xmep
->xid
= rp
->rm_xid
;
853 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
854 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
859 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
860 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
863 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
864 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
868 * Returns 0 and puts NFSPROC_xxx in proc return and
869 * version in vers return, or returns -1 on failure
872 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
876 struct xid_map_entry
*xmep
;
877 u_int32_t xid
= rp
->rm_xid
;
878 struct ip
*ip
= (struct ip
*)bp
;
880 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
884 /* Start searching from where we last left off */
889 if (xmep
->ipver
!= ip
->ip_v
|| xmep
->xid
!= xid
)
891 switch (xmep
->ipver
) {
893 if (memcmp(&ip
->ip_src
, &xmep
->server
,
894 sizeof(ip
->ip_src
)) != 0 ||
895 memcmp(&ip
->ip_dst
, &xmep
->client
,
896 sizeof(ip
->ip_dst
)) != 0) {
902 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
903 sizeof(ip6
->ip6_src
)) != 0 ||
904 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
905 sizeof(ip6
->ip6_dst
)) != 0) {
922 if (++i
>= XIDMAPSIZE
)
924 } while (i
!= xid_map_hint
);
931 * Routines for parsing reply packets
935 * Return a pointer to the beginning of the actual results.
936 * If the packet was truncated, return 0.
938 static const u_int32_t
*
939 parserep(register const struct rpc_msg
*rp
, register u_int length
)
941 register const u_int32_t
*dp
;
943 enum accept_stat astat
;
947 * Here we find the address of the ar_verf credentials.
948 * Originally, this calculation was
949 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
950 * On the wire, the rp_acpt field starts immediately after
951 * the (32 bit) rp_stat field. However, rp_acpt (which is a
952 * "struct accepted_reply") contains a "struct opaque_auth",
953 * whose internal representation contains a pointer, so on a
954 * 64-bit machine the compiler inserts 32 bits of padding
955 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
956 * the internal representation to parse the on-the-wire
957 * representation. Instead, we skip past the rp_stat field,
958 * which is an "enum" and so occupies one 32-bit word.
960 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
966 * skip past the ar_verf credentials.
968 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
972 * now we can check the ar_stat field
974 astat
= ntohl(*(enum accept_stat
*)dp
);
981 printf(" PROG_UNAVAIL");
982 nfserr
= 1; /* suppress trunc string */
986 printf(" PROG_MISMATCH");
987 nfserr
= 1; /* suppress trunc string */
991 printf(" PROC_UNAVAIL");
992 nfserr
= 1; /* suppress trunc string */
996 printf(" GARBAGE_ARGS");
997 nfserr
= 1; /* suppress trunc string */
1001 printf(" SYSTEM_ERR");
1002 nfserr
= 1; /* suppress trunc string */
1006 printf(" ar_stat %d", astat
);
1007 nfserr
= 1; /* suppress trunc string */
1010 /* successful return */
1011 TCHECK2(*dp
, sizeof(astat
));
1012 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1017 static const u_int32_t
*
1018 parsestatus(const u_int32_t
*dp
, int *er
)
1024 errnum
= ntohl(dp
[0]);
1029 printf(" ERROR: %s",
1030 tok2str(status2str
, "unk %d", errnum
));
1039 static const u_int32_t
*
1040 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1042 const struct nfs_fattr
*fap
;
1044 fap
= (const struct nfs_fattr
*)dp
;
1045 TCHECK(fap
->fa_gid
);
1047 printf(" %s %o ids %d/%d",
1048 tok2str(type2str
, "unk-ft %d ",
1049 (u_int32_t
)ntohl(fap
->fa_type
)),
1050 (u_int32_t
)ntohl(fap
->fa_mode
),
1051 (u_int32_t
)ntohl(fap
->fa_uid
),
1052 (u_int32_t
) ntohl(fap
->fa_gid
));
1054 TCHECK(fap
->fa3_size
);
1056 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1059 TCHECK(fap
->fa2_size
);
1060 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1063 /* print lots more stuff */
1066 TCHECK(fap
->fa3_ctime
);
1067 printf("nlink %d rdev %d/%d ",
1068 (u_int32_t
)ntohl(fap
->fa_nlink
),
1069 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1070 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1072 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
1074 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
1075 printf(" a/m/ctime %u.%06u ",
1076 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1077 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1079 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1080 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1082 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1083 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1085 TCHECK(fap
->fa2_ctime
);
1086 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1087 (u_int32_t
) ntohl(fap
->fa_nlink
),
1088 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1089 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1090 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1092 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1093 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1095 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1096 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1098 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1099 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1102 return ((const u_int32_t
*)((unsigned char *)dp
+
1103 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1109 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1113 dp
= parsestatus(dp
, &er
);
1114 if (dp
== NULL
|| er
)
1117 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1121 parsediropres(const u_int32_t
*dp
)
1125 if (!(dp
= parsestatus(dp
, &er
)) || er
)
1128 dp
= parsefh(dp
, 0);
1132 return (parsefattr(dp
, vflag
, 0) != NULL
);
1136 parselinkres(const u_int32_t
*dp
, int v3
)
1140 dp
= parsestatus(dp
, &er
);
1141 if (dp
== NULL
|| er
)
1143 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1146 return (parsefn(dp
) != NULL
);
1150 parsestatfs(const u_int32_t
*dp
, int v3
)
1152 const struct nfs_statfs
*sfsp
;
1155 dp
= parsestatus(dp
, &er
);
1156 if (dp
== NULL
|| (!v3
&& er
))
1165 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1169 TCHECK2(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1171 sfsp
= (const struct nfs_statfs
*)dp
;
1175 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1177 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1179 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1182 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1184 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1186 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1188 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1191 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1192 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1193 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1194 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1195 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1196 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1205 parserddires(const u_int32_t
*dp
)
1209 dp
= parsestatus(dp
, &er
);
1216 printf(" offset %x size %d ",
1217 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1226 static const u_int32_t
*
1227 parse_wcc_attr(const u_int32_t
*dp
)
1230 print_int64(dp
, UNSIGNED
);
1231 printf(" mtime %u.%06u ctime %u.%06u",
1232 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1233 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1238 * Pre operation attributes. Print only if vflag > 1.
1240 static const u_int32_t
*
1241 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1249 return parse_wcc_attr(dp
);
1251 /* If not verbose enough, just skip over wcc_attr */
1259 * Post operation attributes are printed if vflag >= 1
1261 static const u_int32_t
*
1262 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1269 return parsefattr(dp
, verbose
, 1);
1271 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1276 static const u_int32_t
*
1277 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1281 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1286 return parse_post_op_attr(dp
, verbose
);
1289 static const u_int32_t
*
1290 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1294 if (!(dp
= parsestatus(dp
, &er
)))
1297 dp
= parse_wcc_data(dp
, verbose
);
1303 if (!(dp
= parsefh(dp
, 1)))
1306 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1309 printf("dir attr:");
1310 dp
= parse_wcc_data(dp
, verbose
);
1320 parsewccres(const u_int32_t
*dp
, int verbose
)
1324 if (!(dp
= parsestatus(dp
, &er
)))
1326 return parse_wcc_data(dp
, verbose
) != 0;
1329 static const u_int32_t
*
1330 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1334 if (!(dp
= parsestatus(dp
, &er
)))
1338 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1344 printf(" verf %08x%08x", dp
[0], dp
[1]);
1353 parsefsinfo(const u_int32_t
*dp
)
1355 struct nfsv3_fsinfo
*sfp
;
1358 if (!(dp
= parsestatus(dp
, &er
)))
1362 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1367 sfp
= (struct nfsv3_fsinfo
*)dp
;
1369 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1370 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1371 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1372 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1373 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1374 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1376 printf(" rtmult %u wtmult %u maxfsz ",
1377 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1378 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1379 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1380 printf(" delta %u.%06u ",
1381 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1382 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1390 parsepathconf(const u_int32_t
*dp
)
1393 struct nfsv3_pathconf
*spp
;
1395 if (!(dp
= parsestatus(dp
, &er
)))
1399 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1404 spp
= (struct nfsv3_pathconf
*)dp
;
1407 printf(" linkmax %u namemax %u %s %s %s %s",
1408 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1409 (u_int32_t
) ntohl(spp
->pc_namemax
),
1410 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1411 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1412 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1413 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1420 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1422 register const u_int32_t
*dp
;
1426 v3
= (vers
== NFS_VER3
);
1428 if (!v3
&& proc
< NFS_NPROCS
)
1429 proc
= nfsv3_procid
[proc
];
1441 case NFSPROC_GETATTR
:
1443 dp
= parserep(rp
, length
);
1444 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1448 case NFSPROC_SETATTR
:
1450 if (!(dp
= parserep(rp
, length
)))
1453 if (parsewccres(dp
, vflag
))
1456 if (parseattrstat(dp
, !qflag
, 0) != 0)
1461 case NFSPROC_LOOKUP
:
1463 if (!(dp
= parserep(rp
, length
)))
1466 if (!(dp
= parsestatus(dp
, &er
)))
1470 printf(" post dattr:");
1471 dp
= parse_post_op_attr(dp
, vflag
);
1474 if (!(dp
= parsefh(dp
, v3
)))
1476 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1478 printf(" post dattr:");
1479 dp
= parse_post_op_attr(dp
, vflag
);
1485 if (parsediropres(dp
) != 0)
1490 case NFSPROC_ACCESS
:
1492 dp
= parserep(rp
, length
);
1493 if (!(dp
= parsestatus(dp
, &er
)))
1497 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1500 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1503 case NFSPROC_READLINK
:
1504 printf(" readlink");
1505 dp
= parserep(rp
, length
);
1506 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1512 if (!(dp
= parserep(rp
, length
)))
1515 if (!(dp
= parsestatus(dp
, &er
)))
1517 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1523 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1529 if (parseattrstat(dp
, vflag
, 0) != 0)
1536 if (!(dp
= parserep(rp
, length
)))
1539 if (!(dp
= parsestatus(dp
, &er
)))
1541 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1547 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1551 tok2str(nfsv3_writemodes
,
1552 NULL
, ntohl(dp
[1])));
1557 if (parseattrstat(dp
, vflag
, v3
) != 0)
1562 case NFSPROC_CREATE
:
1564 if (!(dp
= parserep(rp
, length
)))
1567 if (parsecreateopres(dp
, vflag
) != 0)
1570 if (parsediropres(dp
) != 0)
1577 if (!(dp
= parserep(rp
, length
)))
1580 if (parsecreateopres(dp
, vflag
) != 0)
1583 if (parsediropres(dp
) != 0)
1588 case NFSPROC_SYMLINK
:
1590 if (!(dp
= parserep(rp
, length
)))
1593 if (parsecreateopres(dp
, vflag
) != 0)
1596 if (parsestatus(dp
, &er
) != 0)
1603 if (!(dp
= parserep(rp
, length
)))
1605 if (parsecreateopres(dp
, vflag
) != 0)
1609 case NFSPROC_REMOVE
:
1611 if (!(dp
= parserep(rp
, length
)))
1614 if (parsewccres(dp
, vflag
))
1617 if (parsestatus(dp
, &er
) != 0)
1624 if (!(dp
= parserep(rp
, length
)))
1627 if (parsewccres(dp
, vflag
))
1630 if (parsestatus(dp
, &er
) != 0)
1635 case NFSPROC_RENAME
:
1637 if (!(dp
= parserep(rp
, length
)))
1640 if (!(dp
= parsestatus(dp
, &er
)))
1644 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1647 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1652 if (parsestatus(dp
, &er
) != 0)
1659 if (!(dp
= parserep(rp
, length
)))
1662 if (!(dp
= parsestatus(dp
, &er
)))
1665 printf(" file POST:");
1666 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1669 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1674 if (parsestatus(dp
, &er
) != 0)
1679 case NFSPROC_READDIR
:
1681 if (!(dp
= parserep(rp
, length
)))
1684 if (parsev3rddirres(dp
, vflag
))
1687 if (parserddires(dp
) != 0)
1692 case NFSPROC_READDIRPLUS
:
1693 printf(" readdirplus");
1694 if (!(dp
= parserep(rp
, length
)))
1696 if (parsev3rddirres(dp
, vflag
))
1700 case NFSPROC_FSSTAT
:
1702 dp
= parserep(rp
, length
);
1703 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1707 case NFSPROC_FSINFO
:
1709 dp
= parserep(rp
, length
);
1710 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1714 case NFSPROC_PATHCONF
:
1715 printf(" pathconf");
1716 dp
= parserep(rp
, length
);
1717 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1721 case NFSPROC_COMMIT
:
1723 dp
= parserep(rp
, length
);
1724 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1729 printf(" proc-%u", proc
);
1734 fputs(" [|nfs]", stdout
);