]>
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.97 2002-09-05 00:00:16 guy 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
);
194 high
= (u_int32_t
)ntohl(dp
[0]);
201 printf("0x%x%08x", high
, (u_int32_t
)ntohl(dp
[1]));
203 printf("0x%x", (u_int32_t
)ntohl(dp
[1]));
213 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
218 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
220 #ifndef INET_ADDRSTRLEN
221 #define INET_ADDRSTRLEN 16
223 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
226 srcaddr
[0] = dstaddr
[0] = '\0';
227 switch (IP_V((struct ip
*)bp
)) {
229 ip
= (struct ip
*)bp
;
230 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
231 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
235 ip6
= (struct ip6_hdr
*)bp
;
236 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
238 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
243 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
244 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
248 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
251 static const u_int32_t
*
252 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
255 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
257 sa3
->sa_mode
= ntohl(*dp
++);
261 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
263 sa3
->sa_uid
= ntohl(*dp
++);
267 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
269 sa3
->sa_gid
= ntohl(*dp
++);
273 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
275 sa3
->sa_size
= ntohl(*dp
++);
279 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
281 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
282 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
286 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
288 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
289 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
297 static int nfserr
; /* true if we error rather than trunc */
300 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
303 printf(" mode %o", sa3
->sa_mode
);
305 printf(" uid %u", sa3
->sa_uid
);
307 printf(" gid %u", sa3
->sa_gid
);
309 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
310 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
311 sa3
->sa_atime
.nfsv3_nsec
);
312 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
313 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
314 sa3
->sa_mtime
.nfsv3_nsec
);
319 nfsreply_print(register const u_char
*bp
, u_int length
,
320 register const u_char
*bp2
)
322 register const struct rpc_msg
*rp
;
323 u_int32_t proc
, vers
;
324 char srcid
[20], dstid
[20]; /*fits 32bit*/
326 nfserr
= 0; /* assume no error */
327 rp
= (const struct rpc_msg
*)bp
;
330 strlcpy(srcid
, "nfs", sizeof(srcid
));
331 snprintf(dstid
, sizeof(dstid
), "%u",
332 (u_int32_t
)ntohl(rp
->rm_xid
));
334 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
335 snprintf(dstid
, sizeof(dstid
), "%u",
336 (u_int32_t
)ntohl(rp
->rm_xid
));
338 print_nfsaddr(bp2
, srcid
, dstid
);
339 (void)printf("reply %s %d",
340 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
344 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
345 interp_reply(rp
, proc
, vers
, length
);
349 * Return a pointer to the first file handle in the packet.
350 * If the packet was truncated, return 0.
352 static const u_int32_t
*
353 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
355 register const u_int32_t
*dp
;
359 * find the start of the req data (if we captured it)
361 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
365 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
369 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
379 * Print out an NFS file handle and return a pointer to following word.
380 * If packet was truncated, return 0.
382 static const u_int32_t
*
383 parsefh(register const u_int32_t
*dp
, int v3
)
389 len
= (int)ntohl(*dp
) / 4;
394 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
395 nfs_printfh(dp
, len
);
403 * Print out a file name and return pointer to 32-bit word past it.
404 * If packet was truncated, return 0.
406 static const u_int32_t
*
407 parsefn(register const u_int32_t
*dp
)
409 register u_int32_t len
;
410 register const u_char
*cp
;
412 /* Bail if we don't have the string length */
415 /* Fetch string length; convert to host order */
419 TCHECK2(*dp
, ((len
+ 3) & ~3));
422 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
423 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
424 /* XXX seems like we should be checking the length */
426 (void) fn_printn(cp
, len
, NULL
);
435 * Print out file handle and file name.
436 * Return pointer to 32-bit word past file name.
437 * If packet was truncated (or there was some other error), return 0.
439 static const u_int32_t
*
440 parsefhn(register const u_int32_t
*dp
, int v3
)
442 dp
= parsefh(dp
, v3
);
446 return (parsefn(dp
));
450 nfsreq_print(register const u_char
*bp
, u_int length
,
451 register const u_char
*bp2
)
453 register const struct rpc_msg
*rp
;
454 register const u_int32_t
*dp
;
458 struct nfsv3_sattr sa3
;
459 char srcid
[20], dstid
[20]; /*fits 32bit*/
461 nfserr
= 0; /* assume no error */
462 rp
= (const struct rpc_msg
*)bp
;
464 snprintf(srcid
, sizeof(srcid
), "%u",
465 (u_int32_t
)ntohl(rp
->rm_xid
));
466 strlcpy(dstid
, "nfs", sizeof(dstid
));
468 snprintf(srcid
, sizeof(srcid
), "%u",
469 (u_int32_t
)ntohl(rp
->rm_xid
));
470 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
472 print_nfsaddr(bp2
, srcid
, dstid
);
473 (void)printf("%d", length
);
475 xid_map_enter(rp
, bp2
); /* record proc number for later on */
477 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
478 proc
= ntohl(rp
->rm_call
.cb_proc
);
480 if (!v3
&& proc
< NFS_NPROCS
)
481 proc
= nfsv3_procid
[proc
];
491 case NFSPROC_GETATTR
:
493 if ((dp
= parsereq(rp
, length
)) != NULL
&&
494 parsefh(dp
, v3
) != NULL
)
498 case NFSPROC_SETATTR
:
500 if ((dp
= parsereq(rp
, length
)) != NULL
&&
501 parsefh(dp
, v3
) != NULL
)
507 if ((dp
= parsereq(rp
, length
)) != NULL
&&
508 parsefhn(dp
, v3
) != NULL
)
514 if ((dp
= parsereq(rp
, length
)) != NULL
&&
515 (dp
= parsefh(dp
, v3
)) != NULL
) {
517 printf(" %04x", (u_int32_t
)ntohl(dp
[0]));
522 case NFSPROC_READLINK
:
524 if ((dp
= parsereq(rp
, length
)) != NULL
&&
525 parsefh(dp
, v3
) != NULL
)
531 if ((dp
= parsereq(rp
, length
)) != NULL
&&
532 (dp
= parsefh(dp
, v3
)) != NULL
) {
535 printf(" %u bytes @ ",
536 (u_int32_t
) ntohl(dp
[2]));
537 print_int64(dp
, UNSIGNED
);
540 printf(" %u bytes @ %u",
541 (u_int32_t
)ntohl(dp
[1]),
542 (u_int32_t
)ntohl(dp
[0]));
550 if ((dp
= parsereq(rp
, length
)) != NULL
&&
551 (dp
= parsefh(dp
, v3
)) != NULL
) {
554 printf(" %u bytes @ ",
555 (u_int32_t
) ntohl(dp
[4]));
556 print_int64(dp
, UNSIGNED
);
561 tok2str(nfsv3_writemodes
,
566 printf(" %u (%u) bytes @ %u (%u)",
567 (u_int32_t
)ntohl(dp
[3]),
568 (u_int32_t
)ntohl(dp
[2]),
569 (u_int32_t
)ntohl(dp
[1]),
570 (u_int32_t
)ntohl(dp
[0]));
578 if ((dp
= parsereq(rp
, length
)) != NULL
&&
579 parsefhn(dp
, v3
) != NULL
)
585 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
589 case NFSPROC_SYMLINK
:
591 if ((dp
= parsereq(rp
, length
)) != 0 &&
592 (dp
= parsefhn(dp
, v3
)) != 0) {
593 fputs(" ->", stdout
);
594 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
596 if (parsefn(dp
) == 0)
599 print_sattr3(&sa3
, vflag
);
606 if ((dp
= parsereq(rp
, length
)) != 0 &&
607 (dp
= parsefhn(dp
, v3
)) != 0) {
609 type
= (nfs_type
)ntohl(*dp
++);
610 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
612 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
613 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
616 (u_int32_t
)ntohl(dp
[0]),
617 (u_int32_t
)ntohl(dp
[1]));
621 print_sattr3(&sa3
, vflag
);
628 if ((dp
= parsereq(rp
, length
)) != NULL
&&
629 parsefhn(dp
, v3
) != NULL
)
635 if ((dp
= parsereq(rp
, length
)) != NULL
&&
636 parsefhn(dp
, v3
) != NULL
)
642 if ((dp
= parsereq(rp
, length
)) != NULL
&&
643 (dp
= parsefhn(dp
, v3
)) != NULL
) {
644 fputs(" ->", stdout
);
645 if (parsefhn(dp
, v3
) != NULL
)
652 if ((dp
= parsereq(rp
, length
)) != NULL
&&
653 (dp
= parsefh(dp
, v3
)) != NULL
) {
654 fputs(" ->", stdout
);
655 if (parsefhn(dp
, v3
) != NULL
)
660 case NFSPROC_READDIR
:
662 if ((dp
= parsereq(rp
, length
)) != NULL
&&
663 (dp
= parsefh(dp
, v3
)) != NULL
) {
667 * We shouldn't really try to interpret the
668 * offset cookie here.
670 printf(" %u bytes @ ",
671 (u_int32_t
) ntohl(dp
[4]));
672 print_int64(dp
, SIGNED
);
674 printf(" verf %08x%08x", dp
[2],
679 * Print the offset as signed, since -1 is
680 * common, but offsets > 2^31 aren't.
682 printf(" %u bytes @ %d",
683 (u_int32_t
)ntohl(dp
[1]),
684 (u_int32_t
)ntohl(dp
[0]));
690 case NFSPROC_READDIRPLUS
:
691 printf(" readdirplus");
692 if ((dp
= parsereq(rp
, length
)) != NULL
&&
693 (dp
= parsefh(dp
, v3
)) != NULL
) {
696 * We don't try to interpret the offset
699 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
700 print_int64(dp
, SIGNED
);
702 printf(" max %u verf %08x%08x",
703 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
710 if ((dp
= parsereq(rp
, length
)) != NULL
&&
711 parsefh(dp
, v3
) != NULL
)
717 if ((dp
= parsereq(rp
, length
)) != NULL
&&
718 parsefh(dp
, v3
) != NULL
)
722 case NFSPROC_PATHCONF
:
724 if ((dp
= parsereq(rp
, length
)) != NULL
&&
725 parsefh(dp
, v3
) != NULL
)
731 if ((dp
= parsereq(rp
, length
)) != NULL
&&
732 (dp
= parsefh(dp
, v3
)) != NULL
) {
733 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
734 print_int64(dp
, UNSIGNED
);
740 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
746 fputs(" [|nfs]", stdout
);
750 * Print out an NFS file handle.
751 * We assume packet was not truncated before the end of the
752 * file handle pointed to by dp.
754 * Note: new version (using portable file-handle parser) doesn't produce
755 * generation number. It probably could be made to do that, with some
756 * additional hacking on the parser code.
759 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
763 const char *sfsname
= NULL
;
768 char const *sep
= "";
771 for (i
=0; i
<len
; i
++) {
772 (void)printf("%s%x", sep
, dp
[i
]);
779 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
782 /* file system ID is ASCII, not numeric, for this server OS */
783 static char temp
[NFSX_V3FHMAX
+1];
785 /* Make sure string is null-terminated */
786 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
787 temp
[sizeof(temp
) - 1] = '\0';
788 /* Remove trailing spaces */
789 spacep
= strchr(temp
, ' ');
793 (void)printf(" fh %s/", temp
);
795 (void)printf(" fh %d,%d/",
796 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
799 if(fsid
.Fsid_dev
.Minor
== 257)
800 /* Print the undecoded handle */
801 (void)printf("%s", fsid
.Opaque_Handle
);
803 (void)printf("%ld", (long) ino
);
807 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
808 * us to match up replies with requests and thus to know how to parse
812 struct xid_map_entry
{
813 u_int32_t xid
; /* transaction ID (net order) */
814 int ipver
; /* IP version (4 or 6) */
816 struct in6_addr client
; /* client IP address (net order) */
817 struct in6_addr server
; /* server IP address (net order) */
819 struct in_addr client
; /* client IP address (net order) */
820 struct in_addr server
; /* server IP address (net order) */
822 u_int32_t proc
; /* call proc number (host order) */
823 u_int32_t vers
; /* program version (host order) */
827 * Map entries are kept in an array that we manage as a ring;
828 * new entries are always added at the tail of the ring. Initially,
829 * all the entries are zero and hence don't match anything.
832 #define XIDMAPSIZE 64
834 struct xid_map_entry xid_map
[XIDMAPSIZE
];
836 int xid_map_next
= 0;
837 int xid_map_hint
= 0;
840 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
842 struct ip
*ip
= NULL
;
844 struct ip6_hdr
*ip6
= NULL
;
846 struct xid_map_entry
*xmep
;
848 switch (IP_V((struct ip
*)bp
)) {
850 ip
= (struct ip
*)bp
;
854 ip6
= (struct ip6_hdr
*)bp
;
861 xmep
= &xid_map
[xid_map_next
];
863 if (++xid_map_next
>= XIDMAPSIZE
)
866 xmep
->xid
= rp
->rm_xid
;
869 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
870 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
875 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
876 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
879 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
880 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
884 * Returns 0 and puts NFSPROC_xxx in proc return and
885 * version in vers return, or returns -1 on failure
888 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
892 struct xid_map_entry
*xmep
;
893 u_int32_t xid
= rp
->rm_xid
;
894 struct ip
*ip
= (struct ip
*)bp
;
896 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
900 /* Start searching from where we last left off */
905 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
907 switch (xmep
->ipver
) {
909 if (memcmp(&ip
->ip_src
, &xmep
->server
,
910 sizeof(ip
->ip_src
)) != 0 ||
911 memcmp(&ip
->ip_dst
, &xmep
->client
,
912 sizeof(ip
->ip_dst
)) != 0) {
918 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
919 sizeof(ip6
->ip6_src
)) != 0 ||
920 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
921 sizeof(ip6
->ip6_dst
)) != 0) {
938 if (++i
>= XIDMAPSIZE
)
940 } while (i
!= xid_map_hint
);
947 * Routines for parsing reply packets
951 * Return a pointer to the beginning of the actual results.
952 * If the packet was truncated, return 0.
954 static const u_int32_t
*
955 parserep(register const struct rpc_msg
*rp
, register u_int length
)
957 register const u_int32_t
*dp
;
959 enum accept_stat astat
;
963 * Here we find the address of the ar_verf credentials.
964 * Originally, this calculation was
965 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
966 * On the wire, the rp_acpt field starts immediately after
967 * the (32 bit) rp_stat field. However, rp_acpt (which is a
968 * "struct accepted_reply") contains a "struct opaque_auth",
969 * whose internal representation contains a pointer, so on a
970 * 64-bit machine the compiler inserts 32 bits of padding
971 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
972 * the internal representation to parse the on-the-wire
973 * representation. Instead, we skip past the rp_stat field,
974 * which is an "enum" and so occupies one 32-bit word.
976 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
982 * skip past the ar_verf credentials.
984 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
988 * now we can check the ar_stat field
990 astat
= ntohl(*(enum accept_stat
*)dp
);
997 printf(" PROG_UNAVAIL");
998 nfserr
= 1; /* suppress trunc string */
1002 printf(" PROG_MISMATCH");
1003 nfserr
= 1; /* suppress trunc string */
1007 printf(" PROC_UNAVAIL");
1008 nfserr
= 1; /* suppress trunc string */
1012 printf(" GARBAGE_ARGS");
1013 nfserr
= 1; /* suppress trunc string */
1017 printf(" SYSTEM_ERR");
1018 nfserr
= 1; /* suppress trunc string */
1022 printf(" ar_stat %d", astat
);
1023 nfserr
= 1; /* suppress trunc string */
1026 /* successful return */
1027 TCHECK2(*dp
, sizeof(astat
));
1028 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1033 static const u_int32_t
*
1034 parsestatus(const u_int32_t
*dp
, int *er
)
1040 errnum
= ntohl(dp
[0]);
1045 printf(" ERROR: %s",
1046 tok2str(status2str
, "unk %d", errnum
));
1054 static const u_int32_t
*
1055 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1057 const struct nfs_fattr
*fap
;
1059 fap
= (const struct nfs_fattr
*)dp
;
1060 TCHECK(fap
->fa_gid
);
1062 printf(" %s %o ids %d/%d",
1063 tok2str(type2str
, "unk-ft %d ",
1064 (u_int32_t
)ntohl(fap
->fa_type
)),
1065 (u_int32_t
)ntohl(fap
->fa_mode
),
1066 (u_int32_t
)ntohl(fap
->fa_uid
),
1067 (u_int32_t
) ntohl(fap
->fa_gid
));
1069 TCHECK(fap
->fa3_size
);
1071 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1074 TCHECK(fap
->fa2_size
);
1075 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1078 /* print lots more stuff */
1081 TCHECK(fap
->fa3_ctime
);
1082 printf("nlink %d rdev %d/%d ",
1083 (u_int32_t
)ntohl(fap
->fa_nlink
),
1084 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1085 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1087 print_int64((u_int32_t
*)&fap
->fa3_fsid
, HEX
);
1089 print_int64((u_int32_t
*)&fap
->fa3_fileid
, HEX
);
1090 printf(" a/m/ctime %u.%06u ",
1091 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1092 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1094 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1095 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1097 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1098 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1100 TCHECK(fap
->fa2_ctime
);
1101 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1102 (u_int32_t
) ntohl(fap
->fa_nlink
),
1103 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1104 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1105 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1107 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1108 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1110 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1111 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1113 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1114 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1117 return ((const u_int32_t
*)((unsigned char *)dp
+
1118 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1124 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1128 dp
= parsestatus(dp
, &er
);
1134 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1138 parsediropres(const u_int32_t
*dp
)
1142 if (!(dp
= parsestatus(dp
, &er
)))
1147 dp
= parsefh(dp
, 0);
1151 return (parsefattr(dp
, vflag
, 0) != NULL
);
1155 parselinkres(const u_int32_t
*dp
, int v3
)
1159 dp
= parsestatus(dp
, &er
);
1164 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1167 return (parsefn(dp
) != NULL
);
1171 parsestatfs(const u_int32_t
*dp
, int v3
)
1173 const struct nfs_statfs
*sfsp
;
1176 dp
= parsestatus(dp
, &er
);
1188 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1192 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1194 sfsp
= (const struct nfs_statfs
*)dp
;
1198 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1200 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1202 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1205 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1207 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1209 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1211 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1214 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1215 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1216 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1217 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1218 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1219 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1228 parserddires(const u_int32_t
*dp
)
1232 dp
= parsestatus(dp
, &er
);
1241 printf(" offset %x size %d ",
1242 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1251 static const u_int32_t
*
1252 parse_wcc_attr(const u_int32_t
*dp
)
1255 print_int64(dp
, UNSIGNED
);
1256 printf(" mtime %u.%06u ctime %u.%06u",
1257 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1258 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1263 * Pre operation attributes. Print only if vflag > 1.
1265 static const u_int32_t
*
1266 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1274 return parse_wcc_attr(dp
);
1276 /* If not verbose enough, just skip over wcc_attr */
1284 * Post operation attributes are printed if vflag >= 1
1286 static const u_int32_t
*
1287 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1294 return parsefattr(dp
, verbose
, 1);
1296 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1301 static const u_int32_t
*
1302 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1306 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1311 return parse_post_op_attr(dp
, verbose
);
1314 static const u_int32_t
*
1315 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1319 if (!(dp
= parsestatus(dp
, &er
)))
1322 dp
= parse_wcc_data(dp
, verbose
);
1328 if (!(dp
= parsefh(dp
, 1)))
1331 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1334 printf("dir attr:");
1335 dp
= parse_wcc_data(dp
, verbose
);
1345 parsewccres(const u_int32_t
*dp
, int verbose
)
1349 if (!(dp
= parsestatus(dp
, &er
)))
1351 return parse_wcc_data(dp
, verbose
) != 0;
1354 static const u_int32_t
*
1355 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1359 if (!(dp
= parsestatus(dp
, &er
)))
1363 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1369 printf(" verf %08x%08x", dp
[0], dp
[1]);
1378 parsefsinfo(const u_int32_t
*dp
)
1380 struct nfsv3_fsinfo
*sfp
;
1383 if (!(dp
= parsestatus(dp
, &er
)))
1387 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1392 sfp
= (struct nfsv3_fsinfo
*)dp
;
1394 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1395 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1396 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1397 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1398 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1399 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1401 printf(" rtmult %u wtmult %u maxfsz ",
1402 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1403 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1404 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1405 printf(" delta %u.%06u ",
1406 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1407 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1415 parsepathconf(const u_int32_t
*dp
)
1418 struct nfsv3_pathconf
*spp
;
1420 if (!(dp
= parsestatus(dp
, &er
)))
1424 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1429 spp
= (struct nfsv3_pathconf
*)dp
;
1432 printf(" linkmax %u namemax %u %s %s %s %s",
1433 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1434 (u_int32_t
) ntohl(spp
->pc_namemax
),
1435 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1436 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1437 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1438 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1445 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1447 register const u_int32_t
*dp
;
1451 v3
= (vers
== NFS_VER3
);
1453 if (!v3
&& proc
< NFS_NPROCS
)
1454 proc
= nfsv3_procid
[proc
];
1466 case NFSPROC_GETATTR
:
1468 dp
= parserep(rp
, length
);
1469 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1473 case NFSPROC_SETATTR
:
1475 if (!(dp
= parserep(rp
, length
)))
1478 if (parsewccres(dp
, vflag
))
1481 if (parseattrstat(dp
, !qflag
, 0) != 0)
1486 case NFSPROC_LOOKUP
:
1488 if (!(dp
= parserep(rp
, length
)))
1491 if (!(dp
= parsestatus(dp
, &er
)))
1495 printf(" post dattr:");
1496 dp
= parse_post_op_attr(dp
, vflag
);
1499 if (!(dp
= parsefh(dp
, v3
)))
1501 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1503 printf(" post dattr:");
1504 dp
= parse_post_op_attr(dp
, vflag
);
1510 if (parsediropres(dp
) != 0)
1515 case NFSPROC_ACCESS
:
1517 if (!(dp
= parserep(rp
, length
)))
1519 if (!(dp
= parsestatus(dp
, &er
)))
1523 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1526 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1529 case NFSPROC_READLINK
:
1530 printf(" readlink");
1531 dp
= parserep(rp
, length
);
1532 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1538 if (!(dp
= parserep(rp
, length
)))
1541 if (!(dp
= parsestatus(dp
, &er
)))
1543 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1549 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1555 if (parseattrstat(dp
, vflag
, 0) != 0)
1562 if (!(dp
= parserep(rp
, length
)))
1565 if (!(dp
= parsestatus(dp
, &er
)))
1567 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1573 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1577 tok2str(nfsv3_writemodes
,
1578 NULL
, ntohl(dp
[1])));
1583 if (parseattrstat(dp
, vflag
, v3
) != 0)
1588 case NFSPROC_CREATE
:
1590 if (!(dp
= parserep(rp
, length
)))
1593 if (parsecreateopres(dp
, vflag
) != 0)
1596 if (parsediropres(dp
) != 0)
1603 if (!(dp
= parserep(rp
, length
)))
1606 if (parsecreateopres(dp
, vflag
) != 0)
1609 if (parsediropres(dp
) != 0)
1614 case NFSPROC_SYMLINK
:
1616 if (!(dp
= parserep(rp
, length
)))
1619 if (parsecreateopres(dp
, vflag
) != 0)
1622 if (parsestatus(dp
, &er
) != 0)
1629 if (!(dp
= parserep(rp
, length
)))
1631 if (parsecreateopres(dp
, vflag
) != 0)
1635 case NFSPROC_REMOVE
:
1637 if (!(dp
= parserep(rp
, length
)))
1640 if (parsewccres(dp
, vflag
))
1643 if (parsestatus(dp
, &er
) != 0)
1650 if (!(dp
= parserep(rp
, length
)))
1653 if (parsewccres(dp
, vflag
))
1656 if (parsestatus(dp
, &er
) != 0)
1661 case NFSPROC_RENAME
:
1663 if (!(dp
= parserep(rp
, length
)))
1666 if (!(dp
= parsestatus(dp
, &er
)))
1670 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1673 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1678 if (parsestatus(dp
, &er
) != 0)
1685 if (!(dp
= parserep(rp
, length
)))
1688 if (!(dp
= parsestatus(dp
, &er
)))
1691 printf(" file POST:");
1692 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1695 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1700 if (parsestatus(dp
, &er
) != 0)
1705 case NFSPROC_READDIR
:
1707 if (!(dp
= parserep(rp
, length
)))
1710 if (parsev3rddirres(dp
, vflag
))
1713 if (parserddires(dp
) != 0)
1718 case NFSPROC_READDIRPLUS
:
1719 printf(" readdirplus");
1720 if (!(dp
= parserep(rp
, length
)))
1722 if (parsev3rddirres(dp
, vflag
))
1726 case NFSPROC_FSSTAT
:
1728 dp
= parserep(rp
, length
);
1729 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1733 case NFSPROC_FSINFO
:
1735 dp
= parserep(rp
, length
);
1736 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1740 case NFSPROC_PATHCONF
:
1741 printf(" pathconf");
1742 dp
= parserep(rp
, length
);
1743 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1747 case NFSPROC_COMMIT
:
1749 dp
= parserep(rp
, length
);
1750 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1755 printf(" proc-%u", proc
);
1760 fputs(" [|nfs]", stdout
);