]>
The Tcpdump Group git mirrors - tcpdump/blob - print-nfs.c
395107bfecac36e956c04eea5e5578a7e9cedaa3
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.82 2000-09-23 08:03:38 guy Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
43 #include <netinet/ip6.h>
53 #include "interface.h"
54 #include "addrtoname.h"
59 static void nfs_printfh(const u_int32_t
*, const u_int
);
60 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
61 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
62 u_int32_t
*, u_int32_t
*);
63 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
64 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
65 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
66 static int print_int64(const u_int32_t
*dp
, int how
);
67 static void print_nfsaddr(const u_char
*, const char *, const char *);
70 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
72 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
102 * NFS V2 and V3 status values.
104 * Some of these come from the RFCs for NFS V2 and V3, with the message
105 * strings taken from the FreeBSD C library "errlst.c".
107 * Others are errors that are not in the RFC but that I suspect some
108 * NFS servers could return; the values are FreeBSD errno values, as
109 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
110 * was primarily BSD-derived.
112 static struct tok status2str
[] = {
113 { 1, "Operation not permitted" }, /* EPERM */
114 { 2, "No such file or directory" }, /* ENOENT */
115 { 5, "Input/output error" }, /* EIO */
116 { 6, "Device not configured" }, /* ENXIO */
117 { 11, "Resource deadlock avoided" }, /* EDEADLK */
118 { 12, "Cannot allocate memory" }, /* ENOMEM */
119 { 13, "Permission denied" }, /* EACCES */
120 { 17, "File exists" }, /* EEXIST */
121 { 18, "Cross-device link" }, /* EXDEV */
122 { 19, "Operation not supported by device" }, /* ENODEV */
123 { 20, "Not a directory" }, /* ENOTDIR */
124 { 21, "Is a directory" }, /* EISDIR */
125 { 22, "Invalid argument" }, /* EINVAL */
126 { 26, "Text file busy" }, /* ETXTBSY */
127 { 27, "File too large" }, /* EFBIG */
128 { 28, "No space left on device" }, /* ENOSPC */
129 { 30, "Read-only file system" }, /* EROFS */
130 { 31, "Too many links" }, /* EMLINK */
131 { 45, "Operation not supported" }, /* EOPNOTSUPP */
132 { 62, "Too many levels of symbolic links" }, /* ELOOP */
133 { 63, "File name too long" }, /* ENAMETOOLONG */
134 { 66, "Directory not empty" }, /* ENOTEMPTY */
135 { 69, "Disc quota exceeded" }, /* EDQUOT */
136 { 70, "Stale NFS file handle" }, /* ESTALE */
137 { 71, "Too many levels of remote in path" }, /* EREMOTE */
138 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
139 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
140 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
141 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
142 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
143 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
144 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
145 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
146 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
150 static struct tok nfsv3_writemodes
[] = {
157 static struct tok type2str
[] = {
169 * Print out a 64-bit integer. This appears to be different on each system,
170 * try to make the best of it. The integer stored as 2 consecutive XDR
171 * encoded 32-bit integers, to which a pointer is passed.
173 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
174 * integer datatype and can print it.
181 static int print_int64(const u_int32_t
*dp
, int how
)
186 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
189 printf(INT64_FORMAT
, res
);
192 printf(U_INT64_FORMAT
, res
);
195 printf(HEX_INT64_FORMAT
, res
);
205 printf("0x%x%08x", (u_int32_t
)ntohl(dp
[0]),
206 (u_int32_t
)ntohl(dp
[1]));
216 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
221 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
223 #ifndef INET_ADDRSTRLEN
224 #define INET_ADDRSTRLEN 16
226 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
229 srcaddr
[0] = dstaddr
[0] = '\0';
230 switch (((struct ip
*)bp
)->ip_v
) {
232 ip
= (struct ip
*)bp
;
233 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
234 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
238 ip6
= (struct ip6_hdr
*)bp
;
239 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
241 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
246 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
247 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
251 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
254 static const u_int32_t
*
255 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
258 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
260 sa3
->sa_mode
= ntohl(*dp
++);
264 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
266 sa3
->sa_uid
= ntohl(*dp
++);
270 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
272 sa3
->sa_gid
= ntohl(*dp
++);
276 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
278 sa3
->sa_size
= ntohl(*dp
++);
282 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
284 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
285 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
289 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
291 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
292 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
300 static int nfserr
; /* true if we error rather than trunc */
303 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
306 printf(" mode %o", sa3
->sa_mode
);
308 printf(" uid %u", sa3
->sa_uid
);
310 printf(" gid %u", sa3
->sa_gid
);
312 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
313 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
314 sa3
->sa_atime
.nfsv3_nsec
);
315 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
316 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
317 sa3
->sa_mtime
.nfsv3_nsec
);
322 nfsreply_print(register const u_char
*bp
, u_int length
,
323 register const u_char
*bp2
)
325 register const struct rpc_msg
*rp
;
326 u_int32_t proc
, vers
;
327 char srcid
[20], dstid
[20]; /*fits 32bit*/
329 nfserr
= 0; /* assume no error */
330 rp
= (const struct rpc_msg
*)bp
;
333 strlcpy(srcid
, "nfs", sizeof(srcid
));
334 snprintf(dstid
, sizeof(dstid
), "%u",
335 (u_int32_t
)ntohl(rp
->rm_xid
));
337 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
338 snprintf(dstid
, sizeof(dstid
), "%u",
339 (u_int32_t
)ntohl(rp
->rm_xid
));
341 print_nfsaddr(bp2
, srcid
, dstid
);
342 (void)printf("reply %s %d",
343 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
347 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
348 interp_reply(rp
, proc
, vers
, length
);
352 * Return a pointer to the first file handle in the packet.
353 * If the packet was truncated, return 0.
355 static const u_int32_t
*
356 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
358 register const u_int32_t
*dp
;
362 * find the start of the req data (if we captured it)
364 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
368 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
372 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
382 * Print out an NFS file handle and return a pointer to following word.
383 * If packet was truncated, return 0.
385 static const u_int32_t
*
386 parsefh(register const u_int32_t
*dp
, int v3
)
392 len
= (int)ntohl(*dp
) / 4;
397 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
398 nfs_printfh(dp
, len
);
406 * Print out a file name and return pointer to 32-bit word past it.
407 * If packet was truncated, return 0.
409 static const u_int32_t
*
410 parsefn(register const u_int32_t
*dp
)
412 register u_int32_t len
;
413 register const u_char
*cp
;
415 /* Bail if we don't have the string length */
418 /* Fetch string length; convert to host order */
422 TCHECK2(*dp
, ((len
+ 3) & ~3));
425 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
426 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
427 /* XXX seems like we should be checking the length */
429 (void) fn_printn(cp
, len
, NULL
);
438 * Print out file handle and file name.
439 * Return pointer to 32-bit word past file name.
440 * If packet was truncated (or there was some other error), return 0.
442 static const u_int32_t
*
443 parsefhn(register const u_int32_t
*dp
, int v3
)
445 dp
= parsefh(dp
, v3
);
449 return (parsefn(dp
));
453 nfsreq_print(register const u_char
*bp
, u_int length
,
454 register const u_char
*bp2
)
456 register const struct rpc_msg
*rp
;
457 register const u_int32_t
*dp
;
461 struct nfsv3_sattr sa3
;
462 char srcid
[20], dstid
[20]; /*fits 32bit*/
464 nfserr
= 0; /* assume no error */
465 rp
= (const struct rpc_msg
*)bp
;
467 snprintf(srcid
, sizeof(srcid
), "%u",
468 (u_int32_t
)ntohl(rp
->rm_xid
));
469 strlcpy(dstid
, "nfs", sizeof(dstid
));
471 snprintf(srcid
, sizeof(srcid
), "%u",
472 (u_int32_t
)ntohl(rp
->rm_xid
));
473 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
475 print_nfsaddr(bp2
, srcid
, dstid
);
476 (void)printf("%d", length
);
478 xid_map_enter(rp
, bp2
); /* record proc number for later on */
480 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
481 proc
= ntohl(rp
->rm_call
.cb_proc
);
483 if (!v3
&& proc
< NFS_NPROCS
)
484 proc
= nfsv3_procid
[proc
];
494 case NFSPROC_GETATTR
:
496 if ((dp
= parsereq(rp
, length
)) != NULL
&&
497 parsefh(dp
, v3
) != NULL
)
501 case NFSPROC_SETATTR
:
503 if ((dp
= parsereq(rp
, length
)) != NULL
&&
504 parsefh(dp
, v3
) != NULL
)
510 if ((dp
= parsereq(rp
, length
)) != NULL
&&
511 parsefhn(dp
, v3
) != NULL
)
517 if ((dp
= parsereq(rp
, length
)) != NULL
&&
518 (dp
= parsefh(dp
, v3
)) != NULL
) {
520 printf(" %04x", (u_int32_t
)ntohl(dp
[0]));
525 case NFSPROC_READLINK
:
527 if ((dp
= parsereq(rp
, length
)) != NULL
&&
528 parsefh(dp
, v3
) != NULL
)
534 if ((dp
= parsereq(rp
, length
)) != NULL
&&
535 (dp
= parsefh(dp
, v3
)) != NULL
) {
538 printf(" %u bytes @ ",
539 (u_int32_t
) ntohl(dp
[2]));
540 print_int64(dp
, UNSIGNED
);
543 printf(" %u bytes @ %u",
544 (u_int32_t
)ntohl(dp
[1]),
545 (u_int32_t
)ntohl(dp
[0]));
553 if ((dp
= parsereq(rp
, length
)) != NULL
&&
554 (dp
= parsefh(dp
, v3
)) != NULL
) {
557 printf(" %u bytes @ ",
558 (u_int32_t
) ntohl(dp
[4]));
559 print_int64(dp
, UNSIGNED
);
564 tok2str(nfsv3_writemodes
,
569 printf(" %u (%u) bytes @ %u (%u)",
570 (u_int32_t
)ntohl(dp
[3]),
571 (u_int32_t
)ntohl(dp
[2]),
572 (u_int32_t
)ntohl(dp
[1]),
573 (u_int32_t
)ntohl(dp
[0]));
581 if ((dp
= parsereq(rp
, length
)) != NULL
&&
582 parsefhn(dp
, v3
) != NULL
)
588 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
592 case NFSPROC_SYMLINK
:
594 if ((dp
= parsereq(rp
, length
)) != 0 &&
595 (dp
= parsefhn(dp
, v3
)) != 0) {
596 fputs(" ->", stdout
);
597 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
599 if (parsefn(dp
) == 0)
602 print_sattr3(&sa3
, vflag
);
609 if ((dp
= parsereq(rp
, length
)) != 0 &&
610 (dp
= parsefhn(dp
, v3
)) != 0) {
612 type
= (nfs_type
)ntohl(*dp
++);
613 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
615 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
616 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
619 (u_int32_t
)ntohl(dp
[0]),
620 (u_int32_t
)ntohl(dp
[1]));
624 print_sattr3(&sa3
, vflag
);
631 if ((dp
= parsereq(rp
, length
)) != NULL
&&
632 parsefhn(dp
, v3
) != NULL
)
638 if ((dp
= parsereq(rp
, length
)) != NULL
&&
639 parsefhn(dp
, v3
) != NULL
)
645 if ((dp
= parsereq(rp
, length
)) != NULL
&&
646 (dp
= parsefhn(dp
, v3
)) != NULL
) {
647 fputs(" ->", stdout
);
648 if (parsefhn(dp
, v3
) != NULL
)
655 if ((dp
= parsereq(rp
, length
)) != NULL
&&
656 (dp
= parsefh(dp
, v3
)) != NULL
) {
657 fputs(" ->", stdout
);
658 if (parsefhn(dp
, v3
) != NULL
)
663 case NFSPROC_READDIR
:
665 if ((dp
= parsereq(rp
, length
)) != NULL
&&
666 (dp
= parsefh(dp
, v3
)) != NULL
) {
670 * We shouldn't really try to interpret the
671 * offset cookie here.
673 printf(" %u bytes @ ",
674 (u_int32_t
) ntohl(dp
[4]));
675 print_int64(dp
, SIGNED
);
677 printf(" verf %08x%08x", dp
[2],
682 * Print the offset as signed, since -1 is
683 * common, but offsets > 2^31 aren't.
685 printf(" %u bytes @ %d",
686 (u_int32_t
)ntohl(dp
[1]),
687 (u_int32_t
)ntohl(dp
[0]));
693 case NFSPROC_READDIRPLUS
:
694 printf(" readdirplus");
695 if ((dp
= parsereq(rp
, length
)) != NULL
&&
696 (dp
= parsefh(dp
, v3
)) != NULL
) {
699 * We don't try to interpret the offset
702 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
703 print_int64(dp
, SIGNED
);
705 printf(" max %u verf %08x%08x",
706 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
713 if ((dp
= parsereq(rp
, length
)) != NULL
&&
714 parsefh(dp
, v3
) != NULL
)
722 case NFSPROC_PATHCONF
:
728 if ((dp
= parsereq(rp
, length
)) != NULL
&&
729 (dp
= parsefh(dp
, v3
)) != NULL
) {
730 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
731 print_int64(dp
, UNSIGNED
);
737 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
743 fputs(" [|nfs]", stdout
);
747 * Print out an NFS file handle.
748 * We assume packet was not truncated before the end of the
749 * file handle pointed to by dp.
751 * Note: new version (using portable file-handle parser) doesn't produce
752 * generation number. It probably could be made to do that, with some
753 * additional hacking on the parser code.
756 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
760 char *sfsname
= NULL
;
762 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
765 /* file system ID is ASCII, not numeric, for this server OS */
766 static char temp
[NFSX_V3FHMAX
+1];
768 /* Make sure string is null-terminated */
769 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
770 temp
[sizeof(temp
) - 1] = '\0';
771 /* Remove trailing spaces */
772 sfsname
= strchr(temp
, ' ');
776 (void)printf(" fh %s/", temp
);
778 (void)printf(" fh %d,%d/",
779 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
782 if(fsid
.Fsid_dev
.Minor
== 257 && uflag
)
783 /* Print the undecoded handle */
784 (void)printf("%s", fsid
.Opaque_Handle
);
786 (void)printf("%ld", (long) ino
);
790 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
791 * us to match up replies with requests and thus to know how to parse
795 struct xid_map_entry
{
796 u_int32_t xid
; /* transaction ID (net order) */
797 int ipver
; /* IP version (4 or 6) */
799 struct in6_addr client
; /* client IP address (net order) */
800 struct in6_addr server
; /* server IP address (net order) */
802 struct in_addr client
; /* client IP address (net order) */
803 struct in_addr server
; /* server IP address (net order) */
805 u_int32_t proc
; /* call proc number (host order) */
806 u_int32_t vers
; /* program version (host order) */
810 * Map entries are kept in an array that we manage as a ring;
811 * new entries are always added at the tail of the ring. Initially,
812 * all the entries are zero and hence don't match anything.
815 #define XIDMAPSIZE 64
817 struct xid_map_entry xid_map
[XIDMAPSIZE
];
819 int xid_map_next
= 0;
820 int xid_map_hint
= 0;
823 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
825 struct ip
*ip
= NULL
;
827 struct ip6_hdr
*ip6
= NULL
;
829 struct xid_map_entry
*xmep
;
831 switch (((struct ip
*)bp
)->ip_v
) {
833 ip
= (struct ip
*)bp
;
837 ip6
= (struct ip6_hdr
*)bp
;
844 xmep
= &xid_map
[xid_map_next
];
846 if (++xid_map_next
>= XIDMAPSIZE
)
849 xmep
->xid
= rp
->rm_xid
;
852 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
853 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
858 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
859 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
862 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
863 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
867 * Returns 0 and puts NFSPROC_xxx in proc return and
868 * version in vers return, or returns -1 on failure
871 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
875 struct xid_map_entry
*xmep
;
876 u_int32_t xid
= rp
->rm_xid
;
877 struct ip
*ip
= (struct ip
*)bp
;
879 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
883 /* Start searching from where we last left off */
888 if (xmep
->ipver
!= ip
->ip_v
|| xmep
->xid
!= xid
)
890 switch (xmep
->ipver
) {
892 if (memcmp(&ip
->ip_src
, &xmep
->server
,
893 sizeof(ip
->ip_src
)) != 0 ||
894 memcmp(&ip
->ip_dst
, &xmep
->client
,
895 sizeof(ip
->ip_dst
)) != 0) {
901 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
902 sizeof(ip6
->ip6_src
)) != 0 ||
903 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
904 sizeof(ip6
->ip6_dst
)) != 0) {
921 if (++i
>= XIDMAPSIZE
)
923 } while (i
!= xid_map_hint
);
930 * Routines for parsing reply packets
934 * Return a pointer to the beginning of the actual results.
935 * If the packet was truncated, return 0.
937 static const u_int32_t
*
938 parserep(register const struct rpc_msg
*rp
, register u_int length
)
940 register const u_int32_t
*dp
;
942 enum accept_stat astat
;
946 * Here we find the address of the ar_verf credentials.
947 * Originally, this calculation was
948 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
949 * On the wire, the rp_acpt field starts immediately after
950 * the (32 bit) rp_stat field. However, rp_acpt (which is a
951 * "struct accepted_reply") contains a "struct opaque_auth",
952 * whose internal representation contains a pointer, so on a
953 * 64-bit machine the compiler inserts 32 bits of padding
954 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
955 * the internal representation to parse the on-the-wire
956 * representation. Instead, we skip past the rp_stat field,
957 * which is an "enum" and so occupies one 32-bit word.
959 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
965 * skip past the ar_verf credentials.
967 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
971 * now we can check the ar_stat field
973 astat
= ntohl(*(enum accept_stat
*)dp
);
980 printf(" PROG_UNAVAIL");
981 nfserr
= 1; /* suppress trunc string */
985 printf(" PROG_MISMATCH");
986 nfserr
= 1; /* suppress trunc string */
990 printf(" PROC_UNAVAIL");
991 nfserr
= 1; /* suppress trunc string */
995 printf(" GARBAGE_ARGS");
996 nfserr
= 1; /* suppress trunc string */
1000 printf(" SYSTEM_ERR");
1001 nfserr
= 1; /* suppress trunc string */
1005 printf(" ar_stat %d", astat
);
1006 nfserr
= 1; /* suppress trunc string */
1009 /* successful return */
1010 TCHECK2(*dp
, sizeof(astat
));
1011 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1016 static const u_int32_t
*
1017 parsestatus(const u_int32_t
*dp
, int *er
)
1023 errnum
= ntohl(dp
[0]);
1028 printf(" ERROR: %s",
1029 tok2str(status2str
, "unk %d", errnum
));
1038 static const u_int32_t
*
1039 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1041 const struct nfs_fattr
*fap
;
1043 fap
= (const struct nfs_fattr
*)dp
;
1044 TCHECK(fap
->fa_gid
);
1046 printf(" %s %o ids %d/%d",
1047 tok2str(type2str
, "unk-ft %d ",
1048 (u_int32_t
)ntohl(fap
->fa_type
)),
1049 (u_int32_t
)ntohl(fap
->fa_mode
),
1050 (u_int32_t
)ntohl(fap
->fa_uid
),
1051 (u_int32_t
) ntohl(fap
->fa_gid
));
1053 TCHECK(fap
->fa3_size
);
1055 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1058 TCHECK(fap
->fa2_size
);
1059 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1062 /* print lots more stuff */
1065 TCHECK(fap
->fa3_ctime
);
1066 printf("nlink %d rdev %d/%d ",
1067 (u_int32_t
)ntohl(fap
->fa_nlink
),
1068 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1069 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1071 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
1073 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
1074 printf(" a/m/ctime %u.%06u ",
1075 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1076 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1078 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1079 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1081 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1082 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1084 TCHECK(fap
->fa2_ctime
);
1085 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1086 (u_int32_t
) ntohl(fap
->fa_nlink
),
1087 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1088 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1089 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1091 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1092 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1094 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1095 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1097 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1098 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1101 return ((const u_int32_t
*)((unsigned char *)dp
+
1102 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1108 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1112 dp
= parsestatus(dp
, &er
);
1113 if (dp
== NULL
|| er
)
1116 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1120 parsediropres(const u_int32_t
*dp
)
1124 if (!(dp
= parsestatus(dp
, &er
)) || er
)
1127 dp
= parsefh(dp
, 0);
1131 return (parsefattr(dp
, vflag
, 0) != NULL
);
1135 parselinkres(const u_int32_t
*dp
, int v3
)
1139 dp
= parsestatus(dp
, &er
);
1140 if (dp
== NULL
|| er
)
1142 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1145 return (parsefn(dp
) != NULL
);
1149 parsestatfs(const u_int32_t
*dp
, int v3
)
1151 const struct nfs_statfs
*sfsp
;
1154 dp
= parsestatus(dp
, &er
);
1155 if (dp
== NULL
|| (!v3
&& er
))
1164 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1168 TCHECK2(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1170 sfsp
= (const struct nfs_statfs
*)dp
;
1174 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1176 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1178 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1181 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1183 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1185 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1187 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1190 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1191 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1192 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1193 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1194 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1195 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1204 parserddires(const u_int32_t
*dp
)
1208 dp
= parsestatus(dp
, &er
);
1215 printf(" offset %x size %d ",
1216 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1225 static const u_int32_t
*
1226 parse_wcc_attr(const u_int32_t
*dp
)
1229 print_int64(dp
, UNSIGNED
);
1230 printf(" mtime %u.%06u ctime %u.%06u",
1231 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1232 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1237 * Pre operation attributes. Print only if vflag > 1.
1239 static const u_int32_t
*
1240 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1248 return parse_wcc_attr(dp
);
1250 /* If not verbose enough, just skip over wcc_attr */
1258 * Post operation attributes are printed if vflag >= 1
1260 static const u_int32_t
*
1261 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1268 return parsefattr(dp
, verbose
, 1);
1270 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1275 static const u_int32_t
*
1276 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1280 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1285 return parse_post_op_attr(dp
, verbose
);
1288 static const u_int32_t
*
1289 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1293 if (!(dp
= parsestatus(dp
, &er
)))
1296 dp
= parse_wcc_data(dp
, verbose
);
1302 if (!(dp
= parsefh(dp
, 1)))
1305 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1308 printf("dir attr:");
1309 dp
= parse_wcc_data(dp
, verbose
);
1319 parsewccres(const u_int32_t
*dp
, int verbose
)
1323 if (!(dp
= parsestatus(dp
, &er
)))
1325 return parse_wcc_data(dp
, verbose
) != 0;
1328 static const u_int32_t
*
1329 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1333 if (!(dp
= parsestatus(dp
, &er
)))
1337 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1343 printf(" verf %08x%08x", dp
[0], dp
[1]);
1352 parsefsinfo(const u_int32_t
*dp
)
1354 struct nfsv3_fsinfo
*sfp
;
1357 if (!(dp
= parsestatus(dp
, &er
)))
1361 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1366 sfp
= (struct nfsv3_fsinfo
*)dp
;
1368 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1369 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1370 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1371 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1372 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1373 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1375 printf(" rtmult %u wtmult %u maxfsz ",
1376 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1377 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1378 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1379 printf(" delta %u.%06u ",
1380 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1381 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1389 parsepathconf(const u_int32_t
*dp
)
1392 struct nfsv3_pathconf
*spp
;
1394 if (!(dp
= parsestatus(dp
, &er
)))
1398 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1403 spp
= (struct nfsv3_pathconf
*)dp
;
1406 printf(" linkmax %u namemax %u %s %s %s %s",
1407 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1408 (u_int32_t
) ntohl(spp
->pc_namemax
),
1409 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1410 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1411 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1412 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1419 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1421 register const u_int32_t
*dp
;
1425 v3
= (vers
== NFS_VER3
);
1427 if (!v3
&& proc
< NFS_NPROCS
)
1428 proc
= nfsv3_procid
[proc
];
1440 case NFSPROC_GETATTR
:
1442 dp
= parserep(rp
, length
);
1443 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1447 case NFSPROC_SETATTR
:
1449 if (!(dp
= parserep(rp
, length
)))
1452 if (parsewccres(dp
, vflag
))
1455 if (parseattrstat(dp
, !qflag
, 0) != 0)
1460 case NFSPROC_LOOKUP
:
1462 if (!(dp
= parserep(rp
, length
)))
1465 if (!(dp
= parsestatus(dp
, &er
)))
1469 printf(" post dattr:");
1470 dp
= parse_post_op_attr(dp
, vflag
);
1473 if (!(dp
= parsefh(dp
, v3
)))
1475 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1477 printf(" post dattr:");
1478 dp
= parse_post_op_attr(dp
, vflag
);
1484 if (parsediropres(dp
) != 0)
1489 case NFSPROC_ACCESS
:
1491 dp
= parserep(rp
, length
);
1492 if (!(dp
= parsestatus(dp
, &er
)))
1496 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1499 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1502 case NFSPROC_READLINK
:
1503 printf(" readlink");
1504 dp
= parserep(rp
, length
);
1505 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1511 if (!(dp
= parserep(rp
, length
)))
1514 if (!(dp
= parsestatus(dp
, &er
)))
1516 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1522 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1528 if (parseattrstat(dp
, vflag
, 0) != 0)
1535 if (!(dp
= parserep(rp
, length
)))
1538 if (!(dp
= parsestatus(dp
, &er
)))
1540 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1546 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1550 tok2str(nfsv3_writemodes
,
1551 NULL
, ntohl(dp
[1])));
1556 if (parseattrstat(dp
, vflag
, v3
) != 0)
1561 case NFSPROC_CREATE
:
1563 if (!(dp
= parserep(rp
, length
)))
1566 if (parsecreateopres(dp
, vflag
) != 0)
1569 if (parsediropres(dp
) != 0)
1576 if (!(dp
= parserep(rp
, length
)))
1579 if (parsecreateopres(dp
, vflag
) != 0)
1582 if (parsediropres(dp
) != 0)
1587 case NFSPROC_SYMLINK
:
1589 if (!(dp
= parserep(rp
, length
)))
1592 if (parsecreateopres(dp
, vflag
) != 0)
1595 if (parsestatus(dp
, &er
) != 0)
1602 if (!(dp
= parserep(rp
, length
)))
1604 if (parsecreateopres(dp
, vflag
) != 0)
1608 case NFSPROC_REMOVE
:
1610 if (!(dp
= parserep(rp
, length
)))
1613 if (parsewccres(dp
, vflag
))
1616 if (parsestatus(dp
, &er
) != 0)
1623 if (!(dp
= parserep(rp
, length
)))
1626 if (parsewccres(dp
, vflag
))
1629 if (parsestatus(dp
, &er
) != 0)
1634 case NFSPROC_RENAME
:
1636 if (!(dp
= parserep(rp
, length
)))
1639 if (!(dp
= parsestatus(dp
, &er
)))
1643 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1646 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1651 if (parsestatus(dp
, &er
) != 0)
1658 if (!(dp
= parserep(rp
, length
)))
1661 if (!(dp
= parsestatus(dp
, &er
)))
1664 printf(" file POST:");
1665 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1668 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1673 if (parsestatus(dp
, &er
) != 0)
1678 case NFSPROC_READDIR
:
1680 if (!(dp
= parserep(rp
, length
)))
1683 if (parsev3rddirres(dp
, vflag
))
1686 if (parserddires(dp
) != 0)
1691 case NFSPROC_READDIRPLUS
:
1692 printf(" readdirplus");
1693 if (!(dp
= parserep(rp
, length
)))
1695 if (parsev3rddirres(dp
, vflag
))
1699 case NFSPROC_FSSTAT
:
1701 dp
= parserep(rp
, length
);
1702 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1706 case NFSPROC_FSINFO
:
1708 dp
= parserep(rp
, length
);
1709 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1713 case NFSPROC_PATHCONF
:
1714 printf(" pathconf");
1715 dp
= parserep(rp
, length
);
1716 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1720 case NFSPROC_COMMIT
:
1722 dp
= parserep(rp
, length
);
1723 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1728 printf(" proc-%u", proc
);
1733 fputs(" [|nfs]", stdout
);