]>
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
[] _U_
=
24 "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.106.2.2 2005-05-06 07:57:18 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
51 static void nfs_printfh(const u_int32_t
*, const u_int
);
52 static void xid_map_enter(const struct sunrpc_msg
*, const u_char
*);
53 static int32_t xid_map_find(const struct sunrpc_msg
*, const u_char
*,
54 u_int32_t
*, u_int32_t
*);
55 static void interp_reply(const struct sunrpc_msg
*, u_int32_t
, u_int32_t
, int);
56 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
57 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
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_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
165 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
167 #ifndef INET_ADDRSTRLEN
168 #define INET_ADDRSTRLEN 16
170 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
173 srcaddr
[0] = dstaddr
[0] = '\0';
174 switch (IP_V((struct ip
*)bp
)) {
176 ip
= (struct ip
*)bp
;
177 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
178 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
182 ip6
= (struct ip6_hdr
*)bp
;
183 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
185 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
190 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
191 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
195 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
198 static const u_int32_t
*
199 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
202 sa3
->sa_modeset
= EXTRACT_32BITS(dp
);
204 if (sa3
->sa_modeset
) {
206 sa3
->sa_mode
= EXTRACT_32BITS(dp
);
211 sa3
->sa_uidset
= EXTRACT_32BITS(dp
);
213 if (sa3
->sa_uidset
) {
215 sa3
->sa_uid
= EXTRACT_32BITS(dp
);
220 sa3
->sa_gidset
= EXTRACT_32BITS(dp
);
222 if (sa3
->sa_gidset
) {
224 sa3
->sa_gid
= EXTRACT_32BITS(dp
);
229 sa3
->sa_sizeset
= EXTRACT_32BITS(dp
);
231 if (sa3
->sa_sizeset
) {
233 sa3
->sa_size
= EXTRACT_32BITS(dp
);
238 sa3
->sa_atimetype
= EXTRACT_32BITS(dp
);
240 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
) {
242 sa3
->sa_atime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
244 sa3
->sa_atime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
249 sa3
->sa_mtimetype
= EXTRACT_32BITS(dp
);
251 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
) {
253 sa3
->sa_mtime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
255 sa3
->sa_mtime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
264 static int nfserr
; /* true if we error rather than trunc */
267 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
270 printf(" mode %o", sa3
->sa_mode
);
272 printf(" uid %u", sa3
->sa_uid
);
274 printf(" gid %u", sa3
->sa_gid
);
276 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
277 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
278 sa3
->sa_atime
.nfsv3_nsec
);
279 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
280 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
281 sa3
->sa_mtime
.nfsv3_nsec
);
286 nfsreply_print(register const u_char
*bp
, u_int length
,
287 register const u_char
*bp2
)
289 register const struct sunrpc_msg
*rp
;
290 u_int32_t proc
, vers
;
291 char srcid
[20], dstid
[20]; /*fits 32bit*/
293 nfserr
= 0; /* assume no error */
294 rp
= (const struct sunrpc_msg
*)bp
;
297 strlcpy(srcid
, "nfs", sizeof(srcid
));
298 snprintf(dstid
, sizeof(dstid
), "%u",
299 EXTRACT_32BITS(&rp
->rm_xid
));
301 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
302 snprintf(dstid
, sizeof(dstid
), "%u",
303 EXTRACT_32BITS(&rp
->rm_xid
));
305 print_nfsaddr(bp2
, srcid
, dstid
);
306 (void)printf("reply %s %d",
307 EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
) == SUNRPC_MSG_ACCEPTED
?
311 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
312 interp_reply(rp
, proc
, vers
, length
);
316 * Return a pointer to the first file handle in the packet.
317 * If the packet was truncated, return 0.
319 static const u_int32_t
*
320 parsereq(register const struct sunrpc_msg
*rp
, register u_int length
)
322 register const u_int32_t
*dp
;
326 * find the start of the req data (if we captured it)
328 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
330 len
= EXTRACT_32BITS(&dp
[1]);
332 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
334 len
= EXTRACT_32BITS(&dp
[1]);
336 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
346 * Print out an NFS file handle and return a pointer to following word.
347 * If packet was truncated, return 0.
349 static const u_int32_t
*
350 parsefh(register const u_int32_t
*dp
, int v3
)
356 len
= EXTRACT_32BITS(dp
) / 4;
361 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
362 nfs_printfh(dp
, len
);
370 * Print out a file name and return pointer to 32-bit word past it.
371 * If packet was truncated, return 0.
373 static const u_int32_t
*
374 parsefn(register const u_int32_t
*dp
)
376 register u_int32_t len
;
377 register const u_char
*cp
;
379 /* Bail if we don't have the string length */
382 /* Fetch string length; convert to host order */
386 TCHECK2(*dp
, ((len
+ 3) & ~3));
389 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
390 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
392 if (fn_printn(cp
, len
, snapend
)) {
404 * Print out file handle and file name.
405 * Return pointer to 32-bit word past file name.
406 * If packet was truncated (or there was some other error), return 0.
408 static const u_int32_t
*
409 parsefhn(register const u_int32_t
*dp
, int v3
)
411 dp
= parsefh(dp
, v3
);
415 return (parsefn(dp
));
419 nfsreq_print(register const u_char
*bp
, u_int length
,
420 register const u_char
*bp2
)
422 register const struct sunrpc_msg
*rp
;
423 register const u_int32_t
*dp
;
427 struct nfsv3_sattr sa3
;
428 char srcid
[20], dstid
[20]; /*fits 32bit*/
430 nfserr
= 0; /* assume no error */
431 rp
= (const struct sunrpc_msg
*)bp
;
433 snprintf(srcid
, sizeof(srcid
), "%u",
434 EXTRACT_32BITS(&rp
->rm_xid
));
435 strlcpy(dstid
, "nfs", sizeof(dstid
));
437 snprintf(srcid
, sizeof(srcid
), "%u",
438 EXTRACT_32BITS(&rp
->rm_xid
));
439 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
441 print_nfsaddr(bp2
, srcid
, dstid
);
442 (void)printf("%d", length
);
444 xid_map_enter(rp
, bp2
); /* record proc number for later on */
446 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
447 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
449 if (!v3
&& proc
< NFS_NPROCS
)
450 proc
= nfsv3_procid
[proc
];
460 case NFSPROC_GETATTR
:
462 if ((dp
= parsereq(rp
, length
)) != NULL
&&
463 parsefh(dp
, v3
) != NULL
)
467 case NFSPROC_SETATTR
:
469 if ((dp
= parsereq(rp
, length
)) != NULL
&&
470 parsefh(dp
, v3
) != NULL
)
476 if ((dp
= parsereq(rp
, length
)) != NULL
&&
477 parsefhn(dp
, v3
) != NULL
)
483 if ((dp
= parsereq(rp
, length
)) != NULL
&&
484 (dp
= parsefh(dp
, v3
)) != NULL
) {
486 printf(" %04x", EXTRACT_32BITS(&dp
[0]));
491 case NFSPROC_READLINK
:
493 if ((dp
= parsereq(rp
, length
)) != NULL
&&
494 parsefh(dp
, v3
) != NULL
)
500 if ((dp
= parsereq(rp
, length
)) != NULL
&&
501 (dp
= parsefh(dp
, v3
)) != NULL
) {
504 printf(" %u bytes @ %" PRIu64
,
505 EXTRACT_32BITS(&dp
[2]),
506 EXTRACT_64BITS(&dp
[0]));
509 printf(" %u bytes @ %u",
510 EXTRACT_32BITS(&dp
[1]),
511 EXTRACT_32BITS(&dp
[0]));
519 if ((dp
= parsereq(rp
, length
)) != NULL
&&
520 (dp
= parsefh(dp
, v3
)) != NULL
) {
523 printf(" %u (%u) bytes @ %" PRIu64
,
524 EXTRACT_32BITS(&dp
[4]),
525 EXTRACT_32BITS(&dp
[2]),
526 EXTRACT_64BITS(&dp
[0]));
531 tok2str(nfsv3_writemodes
,
532 NULL
, EXTRACT_32BITS(dp
)));
536 printf(" %u (%u) bytes @ %u (%u)",
537 EXTRACT_32BITS(&dp
[3]),
538 EXTRACT_32BITS(&dp
[2]),
539 EXTRACT_32BITS(&dp
[1]),
540 EXTRACT_32BITS(&dp
[0]));
548 if ((dp
= parsereq(rp
, length
)) != NULL
&&
549 parsefhn(dp
, v3
) != NULL
)
555 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
559 case NFSPROC_SYMLINK
:
561 if ((dp
= parsereq(rp
, length
)) != 0 &&
562 (dp
= parsefhn(dp
, v3
)) != 0) {
563 fputs(" ->", stdout
);
564 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
566 if (parsefn(dp
) == 0)
569 print_sattr3(&sa3
, vflag
);
576 if ((dp
= parsereq(rp
, length
)) != 0 &&
577 (dp
= parsefhn(dp
, v3
)) != 0) {
579 type
= (nfs_type
)EXTRACT_32BITS(dp
);
581 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
583 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
584 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
587 EXTRACT_32BITS(&dp
[0]),
588 EXTRACT_32BITS(&dp
[1]));
592 print_sattr3(&sa3
, vflag
);
599 if ((dp
= parsereq(rp
, length
)) != NULL
&&
600 parsefhn(dp
, v3
) != NULL
)
606 if ((dp
= parsereq(rp
, length
)) != NULL
&&
607 parsefhn(dp
, v3
) != NULL
)
613 if ((dp
= parsereq(rp
, length
)) != NULL
&&
614 (dp
= parsefhn(dp
, v3
)) != NULL
) {
615 fputs(" ->", stdout
);
616 if (parsefhn(dp
, v3
) != NULL
)
623 if ((dp
= parsereq(rp
, length
)) != NULL
&&
624 (dp
= parsefh(dp
, v3
)) != NULL
) {
625 fputs(" ->", stdout
);
626 if (parsefhn(dp
, v3
) != NULL
)
631 case NFSPROC_READDIR
:
633 if ((dp
= parsereq(rp
, length
)) != NULL
&&
634 (dp
= parsefh(dp
, v3
)) != NULL
) {
638 * We shouldn't really try to interpret the
639 * offset cookie here.
641 printf(" %u bytes @ %" PRId64
,
642 EXTRACT_32BITS(&dp
[4]),
643 EXTRACT_64BITS(&dp
[0]));
645 printf(" verf %08x%08x", dp
[2],
650 * Print the offset as signed, since -1 is
651 * common, but offsets > 2^31 aren't.
653 printf(" %u bytes @ %d",
654 EXTRACT_32BITS(&dp
[1]),
655 EXTRACT_32BITS(&dp
[0]));
661 case NFSPROC_READDIRPLUS
:
662 printf(" readdirplus");
663 if ((dp
= parsereq(rp
, length
)) != NULL
&&
664 (dp
= parsefh(dp
, v3
)) != NULL
) {
667 * We don't try to interpret the offset
670 printf(" %u bytes @ %" PRId64
,
671 EXTRACT_32BITS(&dp
[4]),
672 EXTRACT_64BITS(&dp
[0]));
675 printf(" max %u verf %08x%08x",
676 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
684 if ((dp
= parsereq(rp
, length
)) != NULL
&&
685 parsefh(dp
, v3
) != NULL
)
691 if ((dp
= parsereq(rp
, length
)) != NULL
&&
692 parsefh(dp
, v3
) != NULL
)
696 case NFSPROC_PATHCONF
:
698 if ((dp
= parsereq(rp
, length
)) != NULL
&&
699 parsefh(dp
, v3
) != NULL
)
705 if ((dp
= parsereq(rp
, length
)) != NULL
&&
706 (dp
= parsefh(dp
, v3
)) != NULL
) {
708 printf(" %u bytes @ %" PRIu64
,
709 EXTRACT_32BITS(&dp
[2]),
710 EXTRACT_64BITS(&dp
[0]));
716 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
722 fputs(" [|nfs]", stdout
);
726 * Print out an NFS file handle.
727 * We assume packet was not truncated before the end of the
728 * file handle pointed to by dp.
730 * Note: new version (using portable file-handle parser) doesn't produce
731 * generation number. It probably could be made to do that, with some
732 * additional hacking on the parser code.
735 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
739 const char *sfsname
= NULL
;
744 char const *sep
= "";
747 for (i
=0; i
<len
; i
++) {
748 (void)printf("%s%x", sep
, dp
[i
]);
755 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
758 /* file system ID is ASCII, not numeric, for this server OS */
759 static char temp
[NFSX_V3FHMAX
+1];
761 /* Make sure string is null-terminated */
762 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
763 temp
[sizeof(temp
) - 1] = '\0';
764 /* Remove trailing spaces */
765 spacep
= strchr(temp
, ' ');
769 (void)printf(" fh %s/", temp
);
771 (void)printf(" fh %d,%d/",
772 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
775 if(fsid
.Fsid_dev
.Minor
== 257)
776 /* Print the undecoded handle */
777 (void)printf("%s", fsid
.Opaque_Handle
);
779 (void)printf("%ld", (long) ino
);
783 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
784 * us to match up replies with requests and thus to know how to parse
788 struct xid_map_entry
{
789 u_int32_t xid
; /* transaction ID (net order) */
790 int ipver
; /* IP version (4 or 6) */
792 struct in6_addr client
; /* client IP address (net order) */
793 struct in6_addr server
; /* server IP address (net order) */
795 struct in_addr client
; /* client IP address (net order) */
796 struct in_addr server
; /* server IP address (net order) */
798 u_int32_t proc
; /* call proc number (host order) */
799 u_int32_t vers
; /* program version (host order) */
803 * Map entries are kept in an array that we manage as a ring;
804 * new entries are always added at the tail of the ring. Initially,
805 * all the entries are zero and hence don't match anything.
808 #define XIDMAPSIZE 64
810 struct xid_map_entry xid_map
[XIDMAPSIZE
];
812 int xid_map_next
= 0;
813 int xid_map_hint
= 0;
816 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
818 struct ip
*ip
= NULL
;
820 struct ip6_hdr
*ip6
= NULL
;
822 struct xid_map_entry
*xmep
;
824 switch (IP_V((struct ip
*)bp
)) {
826 ip
= (struct ip
*)bp
;
830 ip6
= (struct ip6_hdr
*)bp
;
837 xmep
= &xid_map
[xid_map_next
];
839 if (++xid_map_next
>= XIDMAPSIZE
)
842 xmep
->xid
= rp
->rm_xid
;
845 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
846 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
851 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
852 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
855 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
856 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
860 * Returns 0 and puts NFSPROC_xxx in proc return and
861 * version in vers return, or returns -1 on failure
864 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
868 struct xid_map_entry
*xmep
;
869 u_int32_t xid
= rp
->rm_xid
;
870 struct ip
*ip
= (struct ip
*)bp
;
872 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
876 /* Start searching from where we last left off */
881 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
883 switch (xmep
->ipver
) {
885 if (memcmp(&ip
->ip_src
, &xmep
->server
,
886 sizeof(ip
->ip_src
)) != 0 ||
887 memcmp(&ip
->ip_dst
, &xmep
->client
,
888 sizeof(ip
->ip_dst
)) != 0) {
894 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
895 sizeof(ip6
->ip6_src
)) != 0 ||
896 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
897 sizeof(ip6
->ip6_dst
)) != 0) {
914 if (++i
>= XIDMAPSIZE
)
916 } while (i
!= xid_map_hint
);
923 * Routines for parsing reply packets
927 * Return a pointer to the beginning of the actual results.
928 * If the packet was truncated, return 0.
930 static const u_int32_t
*
931 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
933 register const u_int32_t
*dp
;
935 enum sunrpc_accept_stat astat
;
939 * Here we find the address of the ar_verf credentials.
940 * Originally, this calculation was
941 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
942 * On the wire, the rp_acpt field starts immediately after
943 * the (32 bit) rp_stat field. However, rp_acpt (which is a
944 * "struct accepted_reply") contains a "struct opaque_auth",
945 * whose internal representation contains a pointer, so on a
946 * 64-bit machine the compiler inserts 32 bits of padding
947 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
948 * the internal representation to parse the on-the-wire
949 * representation. Instead, we skip past the rp_stat field,
950 * which is an "enum" and so occupies one 32-bit word.
952 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
954 len
= EXTRACT_32BITS(&dp
[1]);
958 * skip past the ar_verf credentials.
960 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
964 * now we can check the ar_stat field
966 astat
= (enum sunrpc_accept_stat
) EXTRACT_32BITS(dp
);
972 case SUNRPC_PROG_UNAVAIL
:
973 printf(" PROG_UNAVAIL");
974 nfserr
= 1; /* suppress trunc string */
977 case SUNRPC_PROG_MISMATCH
:
978 printf(" PROG_MISMATCH");
979 nfserr
= 1; /* suppress trunc string */
982 case SUNRPC_PROC_UNAVAIL
:
983 printf(" PROC_UNAVAIL");
984 nfserr
= 1; /* suppress trunc string */
987 case SUNRPC_GARBAGE_ARGS
:
988 printf(" GARBAGE_ARGS");
989 nfserr
= 1; /* suppress trunc string */
992 case SUNRPC_SYSTEM_ERR
:
993 printf(" SYSTEM_ERR");
994 nfserr
= 1; /* suppress trunc string */
998 printf(" ar_stat %d", astat
);
999 nfserr
= 1; /* suppress trunc string */
1002 /* successful return */
1003 TCHECK2(*dp
, sizeof(astat
));
1004 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1009 static const u_int32_t
*
1010 parsestatus(const u_int32_t
*dp
, int *er
)
1016 errnum
= EXTRACT_32BITS(&dp
[0]);
1021 printf(" ERROR: %s",
1022 tok2str(status2str
, "unk %d", errnum
));
1030 static const u_int32_t
*
1031 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1033 const struct nfs_fattr
*fap
;
1035 fap
= (const struct nfs_fattr
*)dp
;
1036 TCHECK(fap
->fa_gid
);
1038 printf(" %s %o ids %d/%d",
1039 tok2str(type2str
, "unk-ft %d ",
1040 EXTRACT_32BITS(&fap
->fa_type
)),
1041 EXTRACT_32BITS(&fap
->fa_mode
),
1042 EXTRACT_32BITS(&fap
->fa_uid
),
1043 EXTRACT_32BITS(&fap
->fa_gid
));
1045 TCHECK(fap
->fa3_size
);
1046 printf(" sz %" PRIu64
,
1047 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1049 TCHECK(fap
->fa2_size
);
1050 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1053 /* print lots more stuff */
1056 TCHECK(fap
->fa3_ctime
);
1057 printf(" nlink %d rdev %d/%d",
1058 EXTRACT_32BITS(&fap
->fa_nlink
),
1059 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1060 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1061 printf(" fsid %" PRIx64
,
1062 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1063 printf(" fileid %" PRIx64
,
1064 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1065 printf(" a/m/ctime %u.%06u",
1066 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1067 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1069 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1070 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1072 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1073 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1075 TCHECK(fap
->fa2_ctime
);
1076 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1077 EXTRACT_32BITS(&fap
->fa_nlink
),
1078 EXTRACT_32BITS(&fap
->fa2_rdev
),
1079 EXTRACT_32BITS(&fap
->fa2_fsid
),
1080 EXTRACT_32BITS(&fap
->fa2_fileid
));
1082 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1083 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1085 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1086 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1088 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1089 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1092 return ((const u_int32_t
*)((unsigned char *)dp
+
1093 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1099 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1103 dp
= parsestatus(dp
, &er
);
1109 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1113 parsediropres(const u_int32_t
*dp
)
1117 if (!(dp
= parsestatus(dp
, &er
)))
1122 dp
= parsefh(dp
, 0);
1126 return (parsefattr(dp
, vflag
, 0) != NULL
);
1130 parselinkres(const u_int32_t
*dp
, int v3
)
1134 dp
= parsestatus(dp
, &er
);
1139 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1142 return (parsefn(dp
) != NULL
);
1146 parsestatfs(const u_int32_t
*dp
, int v3
)
1148 const struct nfs_statfs
*sfsp
;
1151 dp
= parsestatus(dp
, &er
);
1163 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1167 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1169 sfsp
= (const struct nfs_statfs
*)dp
;
1172 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1173 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1174 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1175 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1177 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1178 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1179 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1180 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1181 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1184 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1185 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1186 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1187 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1188 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1189 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1198 parserddires(const u_int32_t
*dp
)
1202 dp
= parsestatus(dp
, &er
);
1211 printf(" offset %x size %d ",
1212 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1221 static const u_int32_t
*
1222 parse_wcc_attr(const u_int32_t
*dp
)
1224 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1225 printf(" mtime %u.%06u ctime %u.%06u",
1226 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1227 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1232 * Pre operation attributes. Print only if vflag > 1.
1234 static const u_int32_t
*
1235 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1238 if (!EXTRACT_32BITS(&dp
[0]))
1243 return parse_wcc_attr(dp
);
1245 /* If not verbose enough, just skip over wcc_attr */
1253 * Post operation attributes are printed if vflag >= 1
1255 static const u_int32_t
*
1256 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1259 if (!EXTRACT_32BITS(&dp
[0]))
1263 return parsefattr(dp
, verbose
, 1);
1265 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1270 static const u_int32_t
*
1271 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1275 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1280 return parse_post_op_attr(dp
, verbose
);
1283 static const u_int32_t
*
1284 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1288 if (!(dp
= parsestatus(dp
, &er
)))
1291 dp
= parse_wcc_data(dp
, verbose
);
1294 if (!EXTRACT_32BITS(&dp
[0]))
1297 if (!(dp
= parsefh(dp
, 1)))
1300 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1303 printf(" dir attr:");
1304 dp
= parse_wcc_data(dp
, verbose
);
1314 parsewccres(const u_int32_t
*dp
, int verbose
)
1318 if (!(dp
= parsestatus(dp
, &er
)))
1320 return parse_wcc_data(dp
, verbose
) != 0;
1323 static const u_int32_t
*
1324 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1328 if (!(dp
= parsestatus(dp
, &er
)))
1332 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1338 printf(" verf %08x%08x", dp
[0], dp
[1]);
1347 parsefsinfo(const u_int32_t
*dp
)
1349 struct nfsv3_fsinfo
*sfp
;
1352 if (!(dp
= parsestatus(dp
, &er
)))
1356 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1361 sfp
= (struct nfsv3_fsinfo
*)dp
;
1363 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1364 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1365 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1366 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1367 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1368 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1370 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1371 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1372 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1373 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1374 printf(" delta %u.%06u ",
1375 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1376 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1384 parsepathconf(const u_int32_t
*dp
)
1387 struct nfsv3_pathconf
*spp
;
1389 if (!(dp
= parsestatus(dp
, &er
)))
1393 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1398 spp
= (struct nfsv3_pathconf
*)dp
;
1401 printf(" linkmax %u namemax %u %s %s %s %s",
1402 EXTRACT_32BITS(&spp
->pc_linkmax
),
1403 EXTRACT_32BITS(&spp
->pc_namemax
),
1404 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1405 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1406 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1407 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1414 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1416 register const u_int32_t
*dp
;
1420 v3
= (vers
== NFS_VER3
);
1422 if (!v3
&& proc
< NFS_NPROCS
)
1423 proc
= nfsv3_procid
[proc
];
1435 case NFSPROC_GETATTR
:
1437 dp
= parserep(rp
, length
);
1438 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1442 case NFSPROC_SETATTR
:
1444 if (!(dp
= parserep(rp
, length
)))
1447 if (parsewccres(dp
, vflag
))
1450 if (parseattrstat(dp
, !qflag
, 0) != 0)
1455 case NFSPROC_LOOKUP
:
1457 if (!(dp
= parserep(rp
, length
)))
1460 if (!(dp
= parsestatus(dp
, &er
)))
1464 printf(" post dattr:");
1465 dp
= parse_post_op_attr(dp
, vflag
);
1468 if (!(dp
= parsefh(dp
, v3
)))
1470 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1472 printf(" post dattr:");
1473 dp
= parse_post_op_attr(dp
, vflag
);
1479 if (parsediropres(dp
) != 0)
1484 case NFSPROC_ACCESS
:
1486 if (!(dp
= parserep(rp
, length
)))
1488 if (!(dp
= parsestatus(dp
, &er
)))
1492 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1495 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1498 case NFSPROC_READLINK
:
1499 printf(" readlink");
1500 dp
= parserep(rp
, length
);
1501 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1507 if (!(dp
= parserep(rp
, length
)))
1510 if (!(dp
= parsestatus(dp
, &er
)))
1512 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1518 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1519 if (EXTRACT_32BITS(&dp
[1]))
1524 if (parseattrstat(dp
, vflag
, 0) != 0)
1531 if (!(dp
= parserep(rp
, length
)))
1534 if (!(dp
= parsestatus(dp
, &er
)))
1536 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1542 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1546 tok2str(nfsv3_writemodes
,
1547 NULL
, EXTRACT_32BITS(&dp
[1])));
1552 if (parseattrstat(dp
, vflag
, v3
) != 0)
1557 case NFSPROC_CREATE
:
1559 if (!(dp
= parserep(rp
, length
)))
1562 if (parsecreateopres(dp
, vflag
) != 0)
1565 if (parsediropres(dp
) != 0)
1572 if (!(dp
= parserep(rp
, length
)))
1575 if (parsecreateopres(dp
, vflag
) != 0)
1578 if (parsediropres(dp
) != 0)
1583 case NFSPROC_SYMLINK
:
1585 if (!(dp
= parserep(rp
, length
)))
1588 if (parsecreateopres(dp
, vflag
) != 0)
1591 if (parsestatus(dp
, &er
) != 0)
1598 if (!(dp
= parserep(rp
, length
)))
1600 if (parsecreateopres(dp
, vflag
) != 0)
1604 case NFSPROC_REMOVE
:
1606 if (!(dp
= parserep(rp
, length
)))
1609 if (parsewccres(dp
, vflag
))
1612 if (parsestatus(dp
, &er
) != 0)
1619 if (!(dp
= parserep(rp
, length
)))
1622 if (parsewccres(dp
, vflag
))
1625 if (parsestatus(dp
, &er
) != 0)
1630 case NFSPROC_RENAME
:
1632 if (!(dp
= parserep(rp
, length
)))
1635 if (!(dp
= parsestatus(dp
, &er
)))
1639 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1642 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1647 if (parsestatus(dp
, &er
) != 0)
1654 if (!(dp
= parserep(rp
, length
)))
1657 if (!(dp
= parsestatus(dp
, &er
)))
1660 printf(" file POST:");
1661 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1664 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1669 if (parsestatus(dp
, &er
) != 0)
1674 case NFSPROC_READDIR
:
1676 if (!(dp
= parserep(rp
, length
)))
1679 if (parsev3rddirres(dp
, vflag
))
1682 if (parserddires(dp
) != 0)
1687 case NFSPROC_READDIRPLUS
:
1688 printf(" readdirplus");
1689 if (!(dp
= parserep(rp
, length
)))
1691 if (parsev3rddirres(dp
, vflag
))
1695 case NFSPROC_FSSTAT
:
1697 dp
= parserep(rp
, length
);
1698 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1702 case NFSPROC_FSINFO
:
1704 dp
= parserep(rp
, length
);
1705 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1709 case NFSPROC_PATHCONF
:
1710 printf(" pathconf");
1711 dp
= parserep(rp
, length
);
1712 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1716 case NFSPROC_COMMIT
:
1718 dp
= parserep(rp
, length
);
1719 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1724 printf(" proc-%u", proc
);
1729 fputs(" [|nfs]", stdout
);