]>
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 2005-01-05 08:16:45 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
);
391 /* XXX seems like we should be checking the length */
393 (void) fn_printn(cp
, len
, NULL
);
402 * Print out file handle and file name.
403 * Return pointer to 32-bit word past file name.
404 * If packet was truncated (or there was some other error), return 0.
406 static const u_int32_t
*
407 parsefhn(register const u_int32_t
*dp
, int v3
)
409 dp
= parsefh(dp
, v3
);
413 return (parsefn(dp
));
417 nfsreq_print(register const u_char
*bp
, u_int length
,
418 register const u_char
*bp2
)
420 register const struct sunrpc_msg
*rp
;
421 register const u_int32_t
*dp
;
425 struct nfsv3_sattr sa3
;
426 char srcid
[20], dstid
[20]; /*fits 32bit*/
428 nfserr
= 0; /* assume no error */
429 rp
= (const struct sunrpc_msg
*)bp
;
431 snprintf(srcid
, sizeof(srcid
), "%u",
432 EXTRACT_32BITS(&rp
->rm_xid
));
433 strlcpy(dstid
, "nfs", sizeof(dstid
));
435 snprintf(srcid
, sizeof(srcid
), "%u",
436 EXTRACT_32BITS(&rp
->rm_xid
));
437 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
439 print_nfsaddr(bp2
, srcid
, dstid
);
440 (void)printf("%d", length
);
442 xid_map_enter(rp
, bp2
); /* record proc number for later on */
444 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
445 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
447 if (!v3
&& proc
< NFS_NPROCS
)
448 proc
= nfsv3_procid
[proc
];
458 case NFSPROC_GETATTR
:
460 if ((dp
= parsereq(rp
, length
)) != NULL
&&
461 parsefh(dp
, v3
) != NULL
)
465 case NFSPROC_SETATTR
:
467 if ((dp
= parsereq(rp
, length
)) != NULL
&&
468 parsefh(dp
, v3
) != NULL
)
474 if ((dp
= parsereq(rp
, length
)) != NULL
&&
475 parsefhn(dp
, v3
) != NULL
)
481 if ((dp
= parsereq(rp
, length
)) != NULL
&&
482 (dp
= parsefh(dp
, v3
)) != NULL
) {
484 printf(" %04x", EXTRACT_32BITS(&dp
[0]));
489 case NFSPROC_READLINK
:
491 if ((dp
= parsereq(rp
, length
)) != NULL
&&
492 parsefh(dp
, v3
) != NULL
)
498 if ((dp
= parsereq(rp
, length
)) != NULL
&&
499 (dp
= parsefh(dp
, v3
)) != NULL
) {
502 printf(" %u bytes @ %" PRIu64
,
503 EXTRACT_32BITS(&dp
[2]),
504 EXTRACT_64BITS(&dp
[0]));
507 printf(" %u bytes @ %u",
508 EXTRACT_32BITS(&dp
[1]),
509 EXTRACT_32BITS(&dp
[0]));
517 if ((dp
= parsereq(rp
, length
)) != NULL
&&
518 (dp
= parsefh(dp
, v3
)) != NULL
) {
521 printf(" %u (%u) bytes @ %" PRIu64
,
522 EXTRACT_32BITS(&dp
[4]),
523 EXTRACT_32BITS(&dp
[2]),
524 EXTRACT_64BITS(&dp
[0]));
529 tok2str(nfsv3_writemodes
,
530 NULL
, EXTRACT_32BITS(dp
)));
534 printf(" %u (%u) bytes @ %u (%u)",
535 EXTRACT_32BITS(&dp
[3]),
536 EXTRACT_32BITS(&dp
[2]),
537 EXTRACT_32BITS(&dp
[1]),
538 EXTRACT_32BITS(&dp
[0]));
546 if ((dp
= parsereq(rp
, length
)) != NULL
&&
547 parsefhn(dp
, v3
) != NULL
)
553 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
557 case NFSPROC_SYMLINK
:
559 if ((dp
= parsereq(rp
, length
)) != 0 &&
560 (dp
= parsefhn(dp
, v3
)) != 0) {
561 fputs(" ->", stdout
);
562 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
564 if (parsefn(dp
) == 0)
567 print_sattr3(&sa3
, vflag
);
574 if ((dp
= parsereq(rp
, length
)) != 0 &&
575 (dp
= parsefhn(dp
, v3
)) != 0) {
577 type
= (nfs_type
)EXTRACT_32BITS(dp
);
579 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
581 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
582 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
585 EXTRACT_32BITS(&dp
[0]),
586 EXTRACT_32BITS(&dp
[1]));
590 print_sattr3(&sa3
, vflag
);
597 if ((dp
= parsereq(rp
, length
)) != NULL
&&
598 parsefhn(dp
, v3
) != NULL
)
604 if ((dp
= parsereq(rp
, length
)) != NULL
&&
605 parsefhn(dp
, v3
) != NULL
)
611 if ((dp
= parsereq(rp
, length
)) != NULL
&&
612 (dp
= parsefhn(dp
, v3
)) != NULL
) {
613 fputs(" ->", stdout
);
614 if (parsefhn(dp
, v3
) != NULL
)
621 if ((dp
= parsereq(rp
, length
)) != NULL
&&
622 (dp
= parsefh(dp
, v3
)) != NULL
) {
623 fputs(" ->", stdout
);
624 if (parsefhn(dp
, v3
) != NULL
)
629 case NFSPROC_READDIR
:
631 if ((dp
= parsereq(rp
, length
)) != NULL
&&
632 (dp
= parsefh(dp
, v3
)) != NULL
) {
636 * We shouldn't really try to interpret the
637 * offset cookie here.
639 printf(" %u bytes @ %" PRId64
,
640 EXTRACT_32BITS(&dp
[4]),
641 EXTRACT_64BITS(&dp
[0]));
643 printf(" verf %08x%08x", dp
[2],
648 * Print the offset as signed, since -1 is
649 * common, but offsets > 2^31 aren't.
651 printf(" %u bytes @ %d",
652 EXTRACT_32BITS(&dp
[1]),
653 EXTRACT_32BITS(&dp
[0]));
659 case NFSPROC_READDIRPLUS
:
660 printf(" readdirplus");
661 if ((dp
= parsereq(rp
, length
)) != NULL
&&
662 (dp
= parsefh(dp
, v3
)) != NULL
) {
665 * We don't try to interpret the offset
668 printf(" %u bytes @ %" PRId64
,
669 EXTRACT_32BITS(&dp
[4]),
670 EXTRACT_64BITS(&dp
[0]));
673 printf(" max %u verf %08x%08x",
674 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
682 if ((dp
= parsereq(rp
, length
)) != NULL
&&
683 parsefh(dp
, v3
) != NULL
)
689 if ((dp
= parsereq(rp
, length
)) != NULL
&&
690 parsefh(dp
, v3
) != NULL
)
694 case NFSPROC_PATHCONF
:
696 if ((dp
= parsereq(rp
, length
)) != NULL
&&
697 parsefh(dp
, v3
) != NULL
)
703 if ((dp
= parsereq(rp
, length
)) != NULL
&&
704 (dp
= parsefh(dp
, v3
)) != NULL
) {
706 printf(" %u bytes @ %" PRIu64
,
707 EXTRACT_32BITS(&dp
[2]),
708 EXTRACT_64BITS(&dp
[0]));
714 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
720 fputs(" [|nfs]", stdout
);
724 * Print out an NFS file handle.
725 * We assume packet was not truncated before the end of the
726 * file handle pointed to by dp.
728 * Note: new version (using portable file-handle parser) doesn't produce
729 * generation number. It probably could be made to do that, with some
730 * additional hacking on the parser code.
733 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
737 const char *sfsname
= NULL
;
742 char const *sep
= "";
745 for (i
=0; i
<len
; i
++) {
746 (void)printf("%s%x", sep
, dp
[i
]);
753 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
756 /* file system ID is ASCII, not numeric, for this server OS */
757 static char temp
[NFSX_V3FHMAX
+1];
759 /* Make sure string is null-terminated */
760 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
761 temp
[sizeof(temp
) - 1] = '\0';
762 /* Remove trailing spaces */
763 spacep
= strchr(temp
, ' ');
767 (void)printf(" fh %s/", temp
);
769 (void)printf(" fh %d,%d/",
770 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
773 if(fsid
.Fsid_dev
.Minor
== 257)
774 /* Print the undecoded handle */
775 (void)printf("%s", fsid
.Opaque_Handle
);
777 (void)printf("%ld", (long) ino
);
781 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
782 * us to match up replies with requests and thus to know how to parse
786 struct xid_map_entry
{
787 u_int32_t xid
; /* transaction ID (net order) */
788 int ipver
; /* IP version (4 or 6) */
790 struct in6_addr client
; /* client IP address (net order) */
791 struct in6_addr server
; /* server IP address (net order) */
793 struct in_addr client
; /* client IP address (net order) */
794 struct in_addr server
; /* server IP address (net order) */
796 u_int32_t proc
; /* call proc number (host order) */
797 u_int32_t vers
; /* program version (host order) */
801 * Map entries are kept in an array that we manage as a ring;
802 * new entries are always added at the tail of the ring. Initially,
803 * all the entries are zero and hence don't match anything.
806 #define XIDMAPSIZE 64
808 struct xid_map_entry xid_map
[XIDMAPSIZE
];
810 int xid_map_next
= 0;
811 int xid_map_hint
= 0;
814 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
816 struct ip
*ip
= NULL
;
818 struct ip6_hdr
*ip6
= NULL
;
820 struct xid_map_entry
*xmep
;
822 switch (IP_V((struct ip
*)bp
)) {
824 ip
= (struct ip
*)bp
;
828 ip6
= (struct ip6_hdr
*)bp
;
835 xmep
= &xid_map
[xid_map_next
];
837 if (++xid_map_next
>= XIDMAPSIZE
)
840 xmep
->xid
= rp
->rm_xid
;
843 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
844 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
849 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
850 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
853 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
854 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
858 * Returns 0 and puts NFSPROC_xxx in proc return and
859 * version in vers return, or returns -1 on failure
862 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
866 struct xid_map_entry
*xmep
;
867 u_int32_t xid
= rp
->rm_xid
;
868 struct ip
*ip
= (struct ip
*)bp
;
870 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
874 /* Start searching from where we last left off */
879 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
881 switch (xmep
->ipver
) {
883 if (memcmp(&ip
->ip_src
, &xmep
->server
,
884 sizeof(ip
->ip_src
)) != 0 ||
885 memcmp(&ip
->ip_dst
, &xmep
->client
,
886 sizeof(ip
->ip_dst
)) != 0) {
892 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
893 sizeof(ip6
->ip6_src
)) != 0 ||
894 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
895 sizeof(ip6
->ip6_dst
)) != 0) {
912 if (++i
>= XIDMAPSIZE
)
914 } while (i
!= xid_map_hint
);
921 * Routines for parsing reply packets
925 * Return a pointer to the beginning of the actual results.
926 * If the packet was truncated, return 0.
928 static const u_int32_t
*
929 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
931 register const u_int32_t
*dp
;
933 enum sunrpc_accept_stat astat
;
937 * Here we find the address of the ar_verf credentials.
938 * Originally, this calculation was
939 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
940 * On the wire, the rp_acpt field starts immediately after
941 * the (32 bit) rp_stat field. However, rp_acpt (which is a
942 * "struct accepted_reply") contains a "struct opaque_auth",
943 * whose internal representation contains a pointer, so on a
944 * 64-bit machine the compiler inserts 32 bits of padding
945 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
946 * the internal representation to parse the on-the-wire
947 * representation. Instead, we skip past the rp_stat field,
948 * which is an "enum" and so occupies one 32-bit word.
950 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
952 len
= EXTRACT_32BITS(&dp
[1]);
956 * skip past the ar_verf credentials.
958 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
962 * now we can check the ar_stat field
964 astat
= EXTRACT_32BITS(dp
);
970 case SUNRPC_PROG_UNAVAIL
:
971 printf(" PROG_UNAVAIL");
972 nfserr
= 1; /* suppress trunc string */
975 case SUNRPC_PROG_MISMATCH
:
976 printf(" PROG_MISMATCH");
977 nfserr
= 1; /* suppress trunc string */
980 case SUNRPC_PROC_UNAVAIL
:
981 printf(" PROC_UNAVAIL");
982 nfserr
= 1; /* suppress trunc string */
985 case SUNRPC_GARBAGE_ARGS
:
986 printf(" GARBAGE_ARGS");
987 nfserr
= 1; /* suppress trunc string */
990 case SUNRPC_SYSTEM_ERR
:
991 printf(" SYSTEM_ERR");
992 nfserr
= 1; /* suppress trunc string */
996 printf(" ar_stat %d", astat
);
997 nfserr
= 1; /* suppress trunc string */
1000 /* successful return */
1001 TCHECK2(*dp
, sizeof(astat
));
1002 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1007 static const u_int32_t
*
1008 parsestatus(const u_int32_t
*dp
, int *er
)
1014 errnum
= EXTRACT_32BITS(&dp
[0]);
1019 printf(" ERROR: %s",
1020 tok2str(status2str
, "unk %d", errnum
));
1028 static const u_int32_t
*
1029 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1031 const struct nfs_fattr
*fap
;
1033 fap
= (const struct nfs_fattr
*)dp
;
1034 TCHECK(fap
->fa_gid
);
1036 printf(" %s %o ids %d/%d",
1037 tok2str(type2str
, "unk-ft %d ",
1038 EXTRACT_32BITS(&fap
->fa_type
)),
1039 EXTRACT_32BITS(&fap
->fa_mode
),
1040 EXTRACT_32BITS(&fap
->fa_uid
),
1041 EXTRACT_32BITS(&fap
->fa_gid
));
1043 TCHECK(fap
->fa3_size
);
1044 printf(" sz %" PRIu64
,
1045 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1047 TCHECK(fap
->fa2_size
);
1048 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1051 /* print lots more stuff */
1054 TCHECK(fap
->fa3_ctime
);
1055 printf(" nlink %d rdev %d/%d",
1056 EXTRACT_32BITS(&fap
->fa_nlink
),
1057 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1058 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1059 printf(" fsid %" PRIx64
,
1060 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1061 printf(" fileid %" PRIx64
,
1062 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1063 printf(" a/m/ctime %u.%06u",
1064 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1065 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1067 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1068 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1070 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1071 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1073 TCHECK(fap
->fa2_ctime
);
1074 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1075 EXTRACT_32BITS(&fap
->fa_nlink
),
1076 EXTRACT_32BITS(&fap
->fa2_rdev
),
1077 EXTRACT_32BITS(&fap
->fa2_fsid
),
1078 EXTRACT_32BITS(&fap
->fa2_fileid
));
1080 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1081 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1083 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1084 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1086 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1087 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1090 return ((const u_int32_t
*)((unsigned char *)dp
+
1091 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1097 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1101 dp
= parsestatus(dp
, &er
);
1107 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1111 parsediropres(const u_int32_t
*dp
)
1115 if (!(dp
= parsestatus(dp
, &er
)))
1120 dp
= parsefh(dp
, 0);
1124 return (parsefattr(dp
, vflag
, 0) != NULL
);
1128 parselinkres(const u_int32_t
*dp
, int v3
)
1132 dp
= parsestatus(dp
, &er
);
1137 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1140 return (parsefn(dp
) != NULL
);
1144 parsestatfs(const u_int32_t
*dp
, int v3
)
1146 const struct nfs_statfs
*sfsp
;
1149 dp
= parsestatus(dp
, &er
);
1161 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1165 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1167 sfsp
= (const struct nfs_statfs
*)dp
;
1170 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1171 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1172 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1173 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1175 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1176 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1177 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1178 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1179 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1182 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1183 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1184 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1185 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1186 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1187 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1196 parserddires(const u_int32_t
*dp
)
1200 dp
= parsestatus(dp
, &er
);
1209 printf(" offset %x size %d ",
1210 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1219 static const u_int32_t
*
1220 parse_wcc_attr(const u_int32_t
*dp
)
1222 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1223 printf(" mtime %u.%06u ctime %u.%06u",
1224 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1225 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1230 * Pre operation attributes. Print only if vflag > 1.
1232 static const u_int32_t
*
1233 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1236 if (!EXTRACT_32BITS(&dp
[0]))
1241 return parse_wcc_attr(dp
);
1243 /* If not verbose enough, just skip over wcc_attr */
1251 * Post operation attributes are printed if vflag >= 1
1253 static const u_int32_t
*
1254 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1257 if (!EXTRACT_32BITS(&dp
[0]))
1261 return parsefattr(dp
, verbose
, 1);
1263 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1268 static const u_int32_t
*
1269 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1273 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1278 return parse_post_op_attr(dp
, verbose
);
1281 static const u_int32_t
*
1282 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1286 if (!(dp
= parsestatus(dp
, &er
)))
1289 dp
= parse_wcc_data(dp
, verbose
);
1292 if (!EXTRACT_32BITS(&dp
[0]))
1295 if (!(dp
= parsefh(dp
, 1)))
1298 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1301 printf(" dir attr:");
1302 dp
= parse_wcc_data(dp
, verbose
);
1312 parsewccres(const u_int32_t
*dp
, int verbose
)
1316 if (!(dp
= parsestatus(dp
, &er
)))
1318 return parse_wcc_data(dp
, verbose
) != 0;
1321 static const u_int32_t
*
1322 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1326 if (!(dp
= parsestatus(dp
, &er
)))
1330 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1336 printf(" verf %08x%08x", dp
[0], dp
[1]);
1345 parsefsinfo(const u_int32_t
*dp
)
1347 struct nfsv3_fsinfo
*sfp
;
1350 if (!(dp
= parsestatus(dp
, &er
)))
1354 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1359 sfp
= (struct nfsv3_fsinfo
*)dp
;
1361 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1362 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1363 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1364 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1365 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1366 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1368 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1369 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1370 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1371 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1372 printf(" delta %u.%06u ",
1373 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1374 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1382 parsepathconf(const u_int32_t
*dp
)
1385 struct nfsv3_pathconf
*spp
;
1387 if (!(dp
= parsestatus(dp
, &er
)))
1391 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1396 spp
= (struct nfsv3_pathconf
*)dp
;
1399 printf(" linkmax %u namemax %u %s %s %s %s",
1400 EXTRACT_32BITS(&spp
->pc_linkmax
),
1401 EXTRACT_32BITS(&spp
->pc_namemax
),
1402 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1403 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1404 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1405 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1412 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1414 register const u_int32_t
*dp
;
1418 v3
= (vers
== NFS_VER3
);
1420 if (!v3
&& proc
< NFS_NPROCS
)
1421 proc
= nfsv3_procid
[proc
];
1433 case NFSPROC_GETATTR
:
1435 dp
= parserep(rp
, length
);
1436 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1440 case NFSPROC_SETATTR
:
1442 if (!(dp
= parserep(rp
, length
)))
1445 if (parsewccres(dp
, vflag
))
1448 if (parseattrstat(dp
, !qflag
, 0) != 0)
1453 case NFSPROC_LOOKUP
:
1455 if (!(dp
= parserep(rp
, length
)))
1458 if (!(dp
= parsestatus(dp
, &er
)))
1462 printf(" post dattr:");
1463 dp
= parse_post_op_attr(dp
, vflag
);
1466 if (!(dp
= parsefh(dp
, v3
)))
1468 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1470 printf(" post dattr:");
1471 dp
= parse_post_op_attr(dp
, vflag
);
1477 if (parsediropres(dp
) != 0)
1482 case NFSPROC_ACCESS
:
1484 if (!(dp
= parserep(rp
, length
)))
1486 if (!(dp
= parsestatus(dp
, &er
)))
1490 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1493 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1496 case NFSPROC_READLINK
:
1497 printf(" readlink");
1498 dp
= parserep(rp
, length
);
1499 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1505 if (!(dp
= parserep(rp
, length
)))
1508 if (!(dp
= parsestatus(dp
, &er
)))
1510 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1516 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1517 if (EXTRACT_32BITS(&dp
[1]))
1522 if (parseattrstat(dp
, vflag
, 0) != 0)
1529 if (!(dp
= parserep(rp
, length
)))
1532 if (!(dp
= parsestatus(dp
, &er
)))
1534 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1540 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1544 tok2str(nfsv3_writemodes
,
1545 NULL
, EXTRACT_32BITS(&dp
[1])));
1550 if (parseattrstat(dp
, vflag
, v3
) != 0)
1555 case NFSPROC_CREATE
:
1557 if (!(dp
= parserep(rp
, length
)))
1560 if (parsecreateopres(dp
, vflag
) != 0)
1563 if (parsediropres(dp
) != 0)
1570 if (!(dp
= parserep(rp
, length
)))
1573 if (parsecreateopres(dp
, vflag
) != 0)
1576 if (parsediropres(dp
) != 0)
1581 case NFSPROC_SYMLINK
:
1583 if (!(dp
= parserep(rp
, length
)))
1586 if (parsecreateopres(dp
, vflag
) != 0)
1589 if (parsestatus(dp
, &er
) != 0)
1596 if (!(dp
= parserep(rp
, length
)))
1598 if (parsecreateopres(dp
, vflag
) != 0)
1602 case NFSPROC_REMOVE
:
1604 if (!(dp
= parserep(rp
, length
)))
1607 if (parsewccres(dp
, vflag
))
1610 if (parsestatus(dp
, &er
) != 0)
1617 if (!(dp
= parserep(rp
, length
)))
1620 if (parsewccres(dp
, vflag
))
1623 if (parsestatus(dp
, &er
) != 0)
1628 case NFSPROC_RENAME
:
1630 if (!(dp
= parserep(rp
, length
)))
1633 if (!(dp
= parsestatus(dp
, &er
)))
1637 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1640 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1645 if (parsestatus(dp
, &er
) != 0)
1652 if (!(dp
= parserep(rp
, length
)))
1655 if (!(dp
= parsestatus(dp
, &er
)))
1658 printf(" file POST:");
1659 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1662 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1667 if (parsestatus(dp
, &er
) != 0)
1672 case NFSPROC_READDIR
:
1674 if (!(dp
= parserep(rp
, length
)))
1677 if (parsev3rddirres(dp
, vflag
))
1680 if (parserddires(dp
) != 0)
1685 case NFSPROC_READDIRPLUS
:
1686 printf(" readdirplus");
1687 if (!(dp
= parserep(rp
, length
)))
1689 if (parsev3rddirres(dp
, vflag
))
1693 case NFSPROC_FSSTAT
:
1695 dp
= parserep(rp
, length
);
1696 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1700 case NFSPROC_FSINFO
:
1702 dp
= parserep(rp
, length
);
1703 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1707 case NFSPROC_PATHCONF
:
1708 printf(" pathconf");
1709 dp
= parserep(rp
, length
);
1710 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1714 case NFSPROC_COMMIT
:
1716 dp
= parserep(rp
, length
);
1717 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1722 printf(" proc-%u", proc
);
1727 fputs(" [|nfs]", stdout
);