]>
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.95 2002-08-01 08:53:21 risso Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
50 static void nfs_printfh(const u_int32_t
*, const u_int
);
51 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
52 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
53 u_int32_t
*, u_int32_t
*);
54 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
55 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
56 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
57 static int print_int64(const u_int32_t
*dp
, int how
);
58 static void print_nfsaddr(const u_char
*, const char *, const char *);
61 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
63 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
93 * NFS V2 and V3 status values.
95 * Some of these come from the RFCs for NFS V2 and V3, with the message
96 * strings taken from the FreeBSD C library "errlst.c".
98 * Others are errors that are not in the RFC but that I suspect some
99 * NFS servers could return; the values are FreeBSD errno values, as
100 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
101 * was primarily BSD-derived.
103 static struct tok status2str
[] = {
104 { 1, "Operation not permitted" }, /* EPERM */
105 { 2, "No such file or directory" }, /* ENOENT */
106 { 5, "Input/output error" }, /* EIO */
107 { 6, "Device not configured" }, /* ENXIO */
108 { 11, "Resource deadlock avoided" }, /* EDEADLK */
109 { 12, "Cannot allocate memory" }, /* ENOMEM */
110 { 13, "Permission denied" }, /* EACCES */
111 { 17, "File exists" }, /* EEXIST */
112 { 18, "Cross-device link" }, /* EXDEV */
113 { 19, "Operation not supported by device" }, /* ENODEV */
114 { 20, "Not a directory" }, /* ENOTDIR */
115 { 21, "Is a directory" }, /* EISDIR */
116 { 22, "Invalid argument" }, /* EINVAL */
117 { 26, "Text file busy" }, /* ETXTBSY */
118 { 27, "File too large" }, /* EFBIG */
119 { 28, "No space left on device" }, /* ENOSPC */
120 { 30, "Read-only file system" }, /* EROFS */
121 { 31, "Too many links" }, /* EMLINK */
122 { 45, "Operation not supported" }, /* EOPNOTSUPP */
123 { 62, "Too many levels of symbolic links" }, /* ELOOP */
124 { 63, "File name too long" }, /* ENAMETOOLONG */
125 { 66, "Directory not empty" }, /* ENOTEMPTY */
126 { 69, "Disc quota exceeded" }, /* EDQUOT */
127 { 70, "Stale NFS file handle" }, /* ESTALE */
128 { 71, "Too many levels of remote in path" }, /* EREMOTE */
129 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
130 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
131 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
132 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
133 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
134 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
135 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
136 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
137 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
141 static struct tok nfsv3_writemodes
[] = {
148 static struct tok type2str
[] = {
160 * Print out a 64-bit integer. This appears to be different on each system,
161 * try to make the best of it. The integer stored as 2 consecutive XDR
162 * encoded 32-bit integers, to which a pointer is passed.
164 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
165 * integer datatype and can print it.
172 static int print_int64(const u_int32_t
*dp
, int how
)
177 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
180 printf(INT64_FORMAT
, res
);
183 printf(U_INT64_FORMAT
, res
);
186 printf(HEX_INT64_FORMAT
, res
);
196 printf("0x%x%08x", (u_int32_t
)ntohl(dp
[0]),
197 (u_int32_t
)ntohl(dp
[1]));
207 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
212 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
214 #ifndef INET_ADDRSTRLEN
215 #define INET_ADDRSTRLEN 16
217 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
220 srcaddr
[0] = dstaddr
[0] = '\0';
221 switch (IP_V((struct ip
*)bp
)) {
223 ip
= (struct ip
*)bp
;
224 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
225 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
229 ip6
= (struct ip6_hdr
*)bp
;
230 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
232 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
237 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
238 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
242 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
245 static const u_int32_t
*
246 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
249 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
251 sa3
->sa_mode
= ntohl(*dp
++);
255 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
257 sa3
->sa_uid
= ntohl(*dp
++);
261 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
263 sa3
->sa_gid
= ntohl(*dp
++);
267 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
269 sa3
->sa_size
= ntohl(*dp
++);
273 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
275 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
276 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
280 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
282 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
283 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
291 static int nfserr
; /* true if we error rather than trunc */
294 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
297 printf(" mode %o", sa3
->sa_mode
);
299 printf(" uid %u", sa3
->sa_uid
);
301 printf(" gid %u", sa3
->sa_gid
);
303 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
304 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
305 sa3
->sa_atime
.nfsv3_nsec
);
306 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
307 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
308 sa3
->sa_mtime
.nfsv3_nsec
);
313 nfsreply_print(register const u_char
*bp
, u_int length
,
314 register const u_char
*bp2
)
316 register const struct rpc_msg
*rp
;
317 u_int32_t proc
, vers
;
318 char srcid
[20], dstid
[20]; /*fits 32bit*/
320 nfserr
= 0; /* assume no error */
321 rp
= (const struct rpc_msg
*)bp
;
324 strlcpy(srcid
, "nfs", sizeof(srcid
));
325 snprintf(dstid
, sizeof(dstid
), "%u",
326 (u_int32_t
)ntohl(rp
->rm_xid
));
328 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
329 snprintf(dstid
, sizeof(dstid
), "%u",
330 (u_int32_t
)ntohl(rp
->rm_xid
));
332 print_nfsaddr(bp2
, srcid
, dstid
);
333 (void)printf("reply %s %d",
334 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
338 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
339 interp_reply(rp
, proc
, vers
, length
);
343 * Return a pointer to the first file handle in the packet.
344 * If the packet was truncated, return 0.
346 static const u_int32_t
*
347 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
349 register const u_int32_t
*dp
;
353 * find the start of the req data (if we captured it)
355 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
359 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
363 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
373 * Print out an NFS file handle and return a pointer to following word.
374 * If packet was truncated, return 0.
376 static const u_int32_t
*
377 parsefh(register const u_int32_t
*dp
, int v3
)
383 len
= (int)ntohl(*dp
) / 4;
388 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
389 nfs_printfh(dp
, len
);
397 * Print out a file name and return pointer to 32-bit word past it.
398 * If packet was truncated, return 0.
400 static const u_int32_t
*
401 parsefn(register const u_int32_t
*dp
)
403 register u_int32_t len
;
404 register const u_char
*cp
;
406 /* Bail if we don't have the string length */
409 /* Fetch string length; convert to host order */
413 TCHECK2(*dp
, ((len
+ 3) & ~3));
416 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
417 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
418 /* XXX seems like we should be checking the length */
420 (void) fn_printn(cp
, len
, NULL
);
429 * Print out file handle and file name.
430 * Return pointer to 32-bit word past file name.
431 * If packet was truncated (or there was some other error), return 0.
433 static const u_int32_t
*
434 parsefhn(register const u_int32_t
*dp
, int v3
)
436 dp
= parsefh(dp
, v3
);
440 return (parsefn(dp
));
444 nfsreq_print(register const u_char
*bp
, u_int length
,
445 register const u_char
*bp2
)
447 register const struct rpc_msg
*rp
;
448 register const u_int32_t
*dp
;
452 struct nfsv3_sattr sa3
;
453 char srcid
[20], dstid
[20]; /*fits 32bit*/
455 nfserr
= 0; /* assume no error */
456 rp
= (const struct rpc_msg
*)bp
;
458 snprintf(srcid
, sizeof(srcid
), "%u",
459 (u_int32_t
)ntohl(rp
->rm_xid
));
460 strlcpy(dstid
, "nfs", sizeof(dstid
));
462 snprintf(srcid
, sizeof(srcid
), "%u",
463 (u_int32_t
)ntohl(rp
->rm_xid
));
464 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
466 print_nfsaddr(bp2
, srcid
, dstid
);
467 (void)printf("%d", length
);
469 xid_map_enter(rp
, bp2
); /* record proc number for later on */
471 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
472 proc
= ntohl(rp
->rm_call
.cb_proc
);
474 if (!v3
&& proc
< NFS_NPROCS
)
475 proc
= nfsv3_procid
[proc
];
485 case NFSPROC_GETATTR
:
487 if ((dp
= parsereq(rp
, length
)) != NULL
&&
488 parsefh(dp
, v3
) != NULL
)
492 case NFSPROC_SETATTR
:
494 if ((dp
= parsereq(rp
, length
)) != NULL
&&
495 parsefh(dp
, v3
) != NULL
)
501 if ((dp
= parsereq(rp
, length
)) != NULL
&&
502 parsefhn(dp
, v3
) != NULL
)
508 if ((dp
= parsereq(rp
, length
)) != NULL
&&
509 (dp
= parsefh(dp
, v3
)) != NULL
) {
511 printf(" %04x", (u_int32_t
)ntohl(dp
[0]));
516 case NFSPROC_READLINK
:
518 if ((dp
= parsereq(rp
, length
)) != NULL
&&
519 parsefh(dp
, v3
) != NULL
)
525 if ((dp
= parsereq(rp
, length
)) != NULL
&&
526 (dp
= parsefh(dp
, v3
)) != NULL
) {
529 printf(" %u bytes @ ",
530 (u_int32_t
) ntohl(dp
[2]));
531 print_int64(dp
, UNSIGNED
);
534 printf(" %u bytes @ %u",
535 (u_int32_t
)ntohl(dp
[1]),
536 (u_int32_t
)ntohl(dp
[0]));
544 if ((dp
= parsereq(rp
, length
)) != NULL
&&
545 (dp
= parsefh(dp
, v3
)) != NULL
) {
548 printf(" %u bytes @ ",
549 (u_int32_t
) ntohl(dp
[4]));
550 print_int64(dp
, UNSIGNED
);
555 tok2str(nfsv3_writemodes
,
560 printf(" %u (%u) bytes @ %u (%u)",
561 (u_int32_t
)ntohl(dp
[3]),
562 (u_int32_t
)ntohl(dp
[2]),
563 (u_int32_t
)ntohl(dp
[1]),
564 (u_int32_t
)ntohl(dp
[0]));
572 if ((dp
= parsereq(rp
, length
)) != NULL
&&
573 parsefhn(dp
, v3
) != NULL
)
579 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
583 case NFSPROC_SYMLINK
:
585 if ((dp
= parsereq(rp
, length
)) != 0 &&
586 (dp
= parsefhn(dp
, v3
)) != 0) {
587 fputs(" ->", stdout
);
588 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
590 if (parsefn(dp
) == 0)
593 print_sattr3(&sa3
, vflag
);
600 if ((dp
= parsereq(rp
, length
)) != 0 &&
601 (dp
= parsefhn(dp
, v3
)) != 0) {
603 type
= (nfs_type
)ntohl(*dp
++);
604 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
606 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
607 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
610 (u_int32_t
)ntohl(dp
[0]),
611 (u_int32_t
)ntohl(dp
[1]));
615 print_sattr3(&sa3
, vflag
);
622 if ((dp
= parsereq(rp
, length
)) != NULL
&&
623 parsefhn(dp
, v3
) != NULL
)
629 if ((dp
= parsereq(rp
, length
)) != NULL
&&
630 parsefhn(dp
, v3
) != NULL
)
636 if ((dp
= parsereq(rp
, length
)) != NULL
&&
637 (dp
= parsefhn(dp
, v3
)) != NULL
) {
638 fputs(" ->", stdout
);
639 if (parsefhn(dp
, v3
) != NULL
)
646 if ((dp
= parsereq(rp
, length
)) != NULL
&&
647 (dp
= parsefh(dp
, v3
)) != NULL
) {
648 fputs(" ->", stdout
);
649 if (parsefhn(dp
, v3
) != NULL
)
654 case NFSPROC_READDIR
:
656 if ((dp
= parsereq(rp
, length
)) != NULL
&&
657 (dp
= parsefh(dp
, v3
)) != NULL
) {
661 * We shouldn't really try to interpret the
662 * offset cookie here.
664 printf(" %u bytes @ ",
665 (u_int32_t
) ntohl(dp
[4]));
666 print_int64(dp
, SIGNED
);
668 printf(" verf %08x%08x", dp
[2],
673 * Print the offset as signed, since -1 is
674 * common, but offsets > 2^31 aren't.
676 printf(" %u bytes @ %d",
677 (u_int32_t
)ntohl(dp
[1]),
678 (u_int32_t
)ntohl(dp
[0]));
684 case NFSPROC_READDIRPLUS
:
685 printf(" readdirplus");
686 if ((dp
= parsereq(rp
, length
)) != NULL
&&
687 (dp
= parsefh(dp
, v3
)) != NULL
) {
690 * We don't try to interpret the offset
693 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
694 print_int64(dp
, SIGNED
);
696 printf(" max %u verf %08x%08x",
697 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
704 if ((dp
= parsereq(rp
, length
)) != NULL
&&
705 parsefh(dp
, v3
) != NULL
)
711 if ((dp
= parsereq(rp
, length
)) != NULL
&&
712 parsefh(dp
, v3
) != NULL
)
716 case NFSPROC_PATHCONF
:
718 if ((dp
= parsereq(rp
, length
)) != NULL
&&
719 parsefh(dp
, v3
) != NULL
)
725 if ((dp
= parsereq(rp
, length
)) != NULL
&&
726 (dp
= parsefh(dp
, v3
)) != NULL
) {
727 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
728 print_int64(dp
, UNSIGNED
);
734 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
740 fputs(" [|nfs]", stdout
);
744 * Print out an NFS file handle.
745 * We assume packet was not truncated before the end of the
746 * file handle pointed to by dp.
748 * Note: new version (using portable file-handle parser) doesn't produce
749 * generation number. It probably could be made to do that, with some
750 * additional hacking on the parser code.
753 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
757 const char *sfsname
= NULL
;
760 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
763 /* file system ID is ASCII, not numeric, for this server OS */
764 static char temp
[NFSX_V3FHMAX
+1];
766 /* Make sure string is null-terminated */
767 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
768 temp
[sizeof(temp
) - 1] = '\0';
769 /* Remove trailing spaces */
770 spacep
= strchr(temp
, ' ');
774 (void)printf(" fh %s/", temp
);
776 (void)printf(" fh %d,%d/",
777 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
780 if(fsid
.Fsid_dev
.Minor
== 257 && uflag
)
781 /* Print the undecoded handle */
782 (void)printf("%s", fsid
.Opaque_Handle
);
784 (void)printf("%ld", (long) ino
);
788 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
789 * us to match up replies with requests and thus to know how to parse
793 struct xid_map_entry
{
794 u_int32_t xid
; /* transaction ID (net order) */
795 int ipver
; /* IP version (4 or 6) */
797 struct in6_addr client
; /* client IP address (net order) */
798 struct in6_addr server
; /* server IP address (net order) */
800 struct in_addr client
; /* client IP address (net order) */
801 struct in_addr server
; /* server IP address (net order) */
803 u_int32_t proc
; /* call proc number (host order) */
804 u_int32_t vers
; /* program version (host order) */
808 * Map entries are kept in an array that we manage as a ring;
809 * new entries are always added at the tail of the ring. Initially,
810 * all the entries are zero and hence don't match anything.
813 #define XIDMAPSIZE 64
815 struct xid_map_entry xid_map
[XIDMAPSIZE
];
817 int xid_map_next
= 0;
818 int xid_map_hint
= 0;
821 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
823 struct ip
*ip
= NULL
;
825 struct ip6_hdr
*ip6
= NULL
;
827 struct xid_map_entry
*xmep
;
829 switch (IP_V((struct ip
*)bp
)) {
831 ip
= (struct ip
*)bp
;
835 ip6
= (struct ip6_hdr
*)bp
;
842 xmep
= &xid_map
[xid_map_next
];
844 if (++xid_map_next
>= XIDMAPSIZE
)
847 xmep
->xid
= rp
->rm_xid
;
850 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
851 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
856 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
857 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
860 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
861 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
865 * Returns 0 and puts NFSPROC_xxx in proc return and
866 * version in vers return, or returns -1 on failure
869 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
873 struct xid_map_entry
*xmep
;
874 u_int32_t xid
= rp
->rm_xid
;
875 struct ip
*ip
= (struct ip
*)bp
;
877 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
881 /* Start searching from where we last left off */
886 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
888 switch (xmep
->ipver
) {
890 if (memcmp(&ip
->ip_src
, &xmep
->server
,
891 sizeof(ip
->ip_src
)) != 0 ||
892 memcmp(&ip
->ip_dst
, &xmep
->client
,
893 sizeof(ip
->ip_dst
)) != 0) {
899 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
900 sizeof(ip6
->ip6_src
)) != 0 ||
901 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
902 sizeof(ip6
->ip6_dst
)) != 0) {
919 if (++i
>= XIDMAPSIZE
)
921 } while (i
!= xid_map_hint
);
928 * Routines for parsing reply packets
932 * Return a pointer to the beginning of the actual results.
933 * If the packet was truncated, return 0.
935 static const u_int32_t
*
936 parserep(register const struct rpc_msg
*rp
, register u_int length
)
938 register const u_int32_t
*dp
;
940 enum accept_stat astat
;
944 * Here we find the address of the ar_verf credentials.
945 * Originally, this calculation was
946 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
947 * On the wire, the rp_acpt field starts immediately after
948 * the (32 bit) rp_stat field. However, rp_acpt (which is a
949 * "struct accepted_reply") contains a "struct opaque_auth",
950 * whose internal representation contains a pointer, so on a
951 * 64-bit machine the compiler inserts 32 bits of padding
952 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
953 * the internal representation to parse the on-the-wire
954 * representation. Instead, we skip past the rp_stat field,
955 * which is an "enum" and so occupies one 32-bit word.
957 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
963 * skip past the ar_verf credentials.
965 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
969 * now we can check the ar_stat field
971 astat
= ntohl(*(enum accept_stat
*)dp
);
978 printf(" PROG_UNAVAIL");
979 nfserr
= 1; /* suppress trunc string */
983 printf(" PROG_MISMATCH");
984 nfserr
= 1; /* suppress trunc string */
988 printf(" PROC_UNAVAIL");
989 nfserr
= 1; /* suppress trunc string */
993 printf(" GARBAGE_ARGS");
994 nfserr
= 1; /* suppress trunc string */
998 printf(" SYSTEM_ERR");
999 nfserr
= 1; /* suppress trunc string */
1003 printf(" ar_stat %d", astat
);
1004 nfserr
= 1; /* suppress trunc string */
1007 /* successful return */
1008 TCHECK2(*dp
, sizeof(astat
));
1009 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1014 static const u_int32_t
*
1015 parsestatus(const u_int32_t
*dp
, int *er
)
1021 errnum
= ntohl(dp
[0]);
1026 printf(" ERROR: %s",
1027 tok2str(status2str
, "unk %d", errnum
));
1035 static const u_int32_t
*
1036 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1038 const struct nfs_fattr
*fap
;
1040 fap
= (const struct nfs_fattr
*)dp
;
1041 TCHECK(fap
->fa_gid
);
1043 printf(" %s %o ids %d/%d",
1044 tok2str(type2str
, "unk-ft %d ",
1045 (u_int32_t
)ntohl(fap
->fa_type
)),
1046 (u_int32_t
)ntohl(fap
->fa_mode
),
1047 (u_int32_t
)ntohl(fap
->fa_uid
),
1048 (u_int32_t
) ntohl(fap
->fa_gid
));
1050 TCHECK(fap
->fa3_size
);
1052 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1055 TCHECK(fap
->fa2_size
);
1056 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1059 /* print lots more stuff */
1062 TCHECK(fap
->fa3_ctime
);
1063 printf("nlink %d rdev %d/%d ",
1064 (u_int32_t
)ntohl(fap
->fa_nlink
),
1065 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1066 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1068 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
1070 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
1071 printf(" a/m/ctime %u.%06u ",
1072 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1073 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1075 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1076 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1078 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1079 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1081 TCHECK(fap
->fa2_ctime
);
1082 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1083 (u_int32_t
) ntohl(fap
->fa_nlink
),
1084 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1085 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1086 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1088 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1089 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1091 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1092 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1094 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1095 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1098 return ((const u_int32_t
*)((unsigned char *)dp
+
1099 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1105 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1109 dp
= parsestatus(dp
, &er
);
1115 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1119 parsediropres(const u_int32_t
*dp
)
1123 if (!(dp
= parsestatus(dp
, &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
);
1145 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1148 return (parsefn(dp
) != NULL
);
1152 parsestatfs(const u_int32_t
*dp
, int v3
)
1154 const struct nfs_statfs
*sfsp
;
1157 dp
= parsestatus(dp
, &er
);
1169 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1173 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1175 sfsp
= (const struct nfs_statfs
*)dp
;
1179 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1181 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1183 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1186 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1188 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1190 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1192 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1195 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1196 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1197 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1198 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1199 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1200 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1209 parserddires(const u_int32_t
*dp
)
1213 dp
= parsestatus(dp
, &er
);
1222 printf(" offset %x size %d ",
1223 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1232 static const u_int32_t
*
1233 parse_wcc_attr(const u_int32_t
*dp
)
1236 print_int64(dp
, UNSIGNED
);
1237 printf(" mtime %u.%06u ctime %u.%06u",
1238 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1239 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1244 * Pre operation attributes. Print only if vflag > 1.
1246 static const u_int32_t
*
1247 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1255 return parse_wcc_attr(dp
);
1257 /* If not verbose enough, just skip over wcc_attr */
1265 * Post operation attributes are printed if vflag >= 1
1267 static const u_int32_t
*
1268 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1275 return parsefattr(dp
, verbose
, 1);
1277 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1282 static const u_int32_t
*
1283 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1287 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1292 return parse_post_op_attr(dp
, verbose
);
1295 static const u_int32_t
*
1296 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1300 if (!(dp
= parsestatus(dp
, &er
)))
1303 dp
= parse_wcc_data(dp
, verbose
);
1309 if (!(dp
= parsefh(dp
, 1)))
1312 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1315 printf("dir attr:");
1316 dp
= parse_wcc_data(dp
, verbose
);
1326 parsewccres(const u_int32_t
*dp
, int verbose
)
1330 if (!(dp
= parsestatus(dp
, &er
)))
1332 return parse_wcc_data(dp
, verbose
) != 0;
1335 static const u_int32_t
*
1336 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1340 if (!(dp
= parsestatus(dp
, &er
)))
1344 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1350 printf(" verf %08x%08x", dp
[0], dp
[1]);
1359 parsefsinfo(const u_int32_t
*dp
)
1361 struct nfsv3_fsinfo
*sfp
;
1364 if (!(dp
= parsestatus(dp
, &er
)))
1368 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1373 sfp
= (struct nfsv3_fsinfo
*)dp
;
1375 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1376 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1377 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1378 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1379 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1380 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1382 printf(" rtmult %u wtmult %u maxfsz ",
1383 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1384 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1385 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1386 printf(" delta %u.%06u ",
1387 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1388 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1396 parsepathconf(const u_int32_t
*dp
)
1399 struct nfsv3_pathconf
*spp
;
1401 if (!(dp
= parsestatus(dp
, &er
)))
1405 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1410 spp
= (struct nfsv3_pathconf
*)dp
;
1413 printf(" linkmax %u namemax %u %s %s %s %s",
1414 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1415 (u_int32_t
) ntohl(spp
->pc_namemax
),
1416 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1417 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1418 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1419 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1426 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1428 register const u_int32_t
*dp
;
1432 v3
= (vers
== NFS_VER3
);
1434 if (!v3
&& proc
< NFS_NPROCS
)
1435 proc
= nfsv3_procid
[proc
];
1447 case NFSPROC_GETATTR
:
1449 dp
= parserep(rp
, length
);
1450 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1454 case NFSPROC_SETATTR
:
1456 if (!(dp
= parserep(rp
, length
)))
1459 if (parsewccres(dp
, vflag
))
1462 if (parseattrstat(dp
, !qflag
, 0) != 0)
1467 case NFSPROC_LOOKUP
:
1469 if (!(dp
= parserep(rp
, length
)))
1472 if (!(dp
= parsestatus(dp
, &er
)))
1476 printf(" post dattr:");
1477 dp
= parse_post_op_attr(dp
, vflag
);
1480 if (!(dp
= parsefh(dp
, v3
)))
1482 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1484 printf(" post dattr:");
1485 dp
= parse_post_op_attr(dp
, vflag
);
1491 if (parsediropres(dp
) != 0)
1496 case NFSPROC_ACCESS
:
1498 if (!(dp
= parserep(rp
, length
)))
1500 if (!(dp
= parsestatus(dp
, &er
)))
1504 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1507 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1510 case NFSPROC_READLINK
:
1511 printf(" readlink");
1512 dp
= parserep(rp
, length
);
1513 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1519 if (!(dp
= parserep(rp
, length
)))
1522 if (!(dp
= parsestatus(dp
, &er
)))
1524 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1530 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1536 if (parseattrstat(dp
, vflag
, 0) != 0)
1543 if (!(dp
= parserep(rp
, length
)))
1546 if (!(dp
= parsestatus(dp
, &er
)))
1548 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1554 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1558 tok2str(nfsv3_writemodes
,
1559 NULL
, ntohl(dp
[1])));
1564 if (parseattrstat(dp
, vflag
, v3
) != 0)
1569 case NFSPROC_CREATE
:
1571 if (!(dp
= parserep(rp
, length
)))
1574 if (parsecreateopres(dp
, vflag
) != 0)
1577 if (parsediropres(dp
) != 0)
1584 if (!(dp
= parserep(rp
, length
)))
1587 if (parsecreateopres(dp
, vflag
) != 0)
1590 if (parsediropres(dp
) != 0)
1595 case NFSPROC_SYMLINK
:
1597 if (!(dp
= parserep(rp
, length
)))
1600 if (parsecreateopres(dp
, vflag
) != 0)
1603 if (parsestatus(dp
, &er
) != 0)
1610 if (!(dp
= parserep(rp
, length
)))
1612 if (parsecreateopres(dp
, vflag
) != 0)
1616 case NFSPROC_REMOVE
:
1618 if (!(dp
= parserep(rp
, length
)))
1621 if (parsewccres(dp
, vflag
))
1624 if (parsestatus(dp
, &er
) != 0)
1631 if (!(dp
= parserep(rp
, length
)))
1634 if (parsewccres(dp
, vflag
))
1637 if (parsestatus(dp
, &er
) != 0)
1642 case NFSPROC_RENAME
:
1644 if (!(dp
= parserep(rp
, length
)))
1647 if (!(dp
= parsestatus(dp
, &er
)))
1651 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1654 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1659 if (parsestatus(dp
, &er
) != 0)
1666 if (!(dp
= parserep(rp
, length
)))
1669 if (!(dp
= parsestatus(dp
, &er
)))
1672 printf(" file POST:");
1673 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1676 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1681 if (parsestatus(dp
, &er
) != 0)
1686 case NFSPROC_READDIR
:
1688 if (!(dp
= parserep(rp
, length
)))
1691 if (parsev3rddirres(dp
, vflag
))
1694 if (parserddires(dp
) != 0)
1699 case NFSPROC_READDIRPLUS
:
1700 printf(" readdirplus");
1701 if (!(dp
= parserep(rp
, length
)))
1703 if (parsev3rddirres(dp
, vflag
))
1707 case NFSPROC_FSSTAT
:
1709 dp
= parserep(rp
, length
);
1710 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1714 case NFSPROC_FSINFO
:
1716 dp
= parserep(rp
, length
);
1717 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1721 case NFSPROC_PATHCONF
:
1722 printf(" pathconf");
1723 dp
= parserep(rp
, length
);
1724 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1728 case NFSPROC_COMMIT
:
1730 dp
= parserep(rp
, length
);
1731 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1736 printf(" proc-%u", proc
);
1741 fputs(" [|nfs]", stdout
);