]>
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.98 2002-12-11 07:14:05 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
51 static void nfs_printfh(const u_int32_t
*, const u_int
);
52 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
53 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
54 u_int32_t
*, u_int32_t
*);
55 static void interp_reply(const struct rpc_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 int print_int64(const u_int32_t
*dp
, int how
);
59 static void print_nfsaddr(const u_char
*, const char *, const char *);
62 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
64 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
94 * NFS V2 and V3 status values.
96 * Some of these come from the RFCs for NFS V2 and V3, with the message
97 * strings taken from the FreeBSD C library "errlst.c".
99 * Others are errors that are not in the RFC but that I suspect some
100 * NFS servers could return; the values are FreeBSD errno values, as
101 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
102 * was primarily BSD-derived.
104 static struct tok status2str
[] = {
105 { 1, "Operation not permitted" }, /* EPERM */
106 { 2, "No such file or directory" }, /* ENOENT */
107 { 5, "Input/output error" }, /* EIO */
108 { 6, "Device not configured" }, /* ENXIO */
109 { 11, "Resource deadlock avoided" }, /* EDEADLK */
110 { 12, "Cannot allocate memory" }, /* ENOMEM */
111 { 13, "Permission denied" }, /* EACCES */
112 { 17, "File exists" }, /* EEXIST */
113 { 18, "Cross-device link" }, /* EXDEV */
114 { 19, "Operation not supported by device" }, /* ENODEV */
115 { 20, "Not a directory" }, /* ENOTDIR */
116 { 21, "Is a directory" }, /* EISDIR */
117 { 22, "Invalid argument" }, /* EINVAL */
118 { 26, "Text file busy" }, /* ETXTBSY */
119 { 27, "File too large" }, /* EFBIG */
120 { 28, "No space left on device" }, /* ENOSPC */
121 { 30, "Read-only file system" }, /* EROFS */
122 { 31, "Too many links" }, /* EMLINK */
123 { 45, "Operation not supported" }, /* EOPNOTSUPP */
124 { 62, "Too many levels of symbolic links" }, /* ELOOP */
125 { 63, "File name too long" }, /* ENAMETOOLONG */
126 { 66, "Directory not empty" }, /* ENOTEMPTY */
127 { 69, "Disc quota exceeded" }, /* EDQUOT */
128 { 70, "Stale NFS file handle" }, /* ESTALE */
129 { 71, "Too many levels of remote in path" }, /* EREMOTE */
130 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
131 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
132 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
133 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
134 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
135 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
136 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
137 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
138 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
142 static struct tok nfsv3_writemodes
[] = {
149 static struct tok type2str
[] = {
161 * Print out a 64-bit integer. This appears to be different on each system,
162 * try to make the best of it. The integer stored as 2 consecutive XDR
163 * encoded 32-bit integers, to which a pointer is passed.
165 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
166 * integer datatype and can print it.
173 static int print_int64(const u_int32_t
*dp
, int how
)
178 res
= ((u_int64_t
)EXTRACT_32BITS(&dp
[0]) << 32) | (u_int64_t
)EXTRACT_32BITS(&dp
[1]);
181 printf(INT64_FORMAT
, res
);
184 printf(U_INT64_FORMAT
, res
);
187 printf(HEX_INT64_FORMAT
, res
);
195 high
= EXTRACT_32BITS(&dp
[0]);
202 printf("0x%x%08x", high
, EXTRACT_32BITS(&dp
[1]));
204 printf("0x%x", EXTRACT_32BITS(&dp
[1]));
214 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
219 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
221 #ifndef INET_ADDRSTRLEN
222 #define INET_ADDRSTRLEN 16
224 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
227 srcaddr
[0] = dstaddr
[0] = '\0';
228 switch (IP_V((struct ip
*)bp
)) {
230 ip
= (struct ip
*)bp
;
231 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
232 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
236 ip6
= (struct ip6_hdr
*)bp
;
237 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
239 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
244 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
245 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
249 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
252 static const u_int32_t
*
253 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
256 sa3
->sa_modeset
= EXTRACT_32BITS(dp
);
258 if (sa3
->sa_modeset
) {
260 sa3
->sa_mode
= EXTRACT_32BITS(dp
);
265 sa3
->sa_uidset
= EXTRACT_32BITS(dp
);
267 if (sa3
->sa_uidset
) {
269 sa3
->sa_uid
= EXTRACT_32BITS(dp
);
274 sa3
->sa_gidset
= EXTRACT_32BITS(dp
);
276 if (sa3
->sa_gidset
) {
278 sa3
->sa_gid
= EXTRACT_32BITS(dp
);
283 sa3
->sa_sizeset
= EXTRACT_32BITS(dp
);
285 if (sa3
->sa_sizeset
) {
287 sa3
->sa_size
= EXTRACT_32BITS(dp
);
292 sa3
->sa_atimetype
= EXTRACT_32BITS(dp
);
294 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
) {
296 sa3
->sa_atime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
298 sa3
->sa_atime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
303 sa3
->sa_mtimetype
= EXTRACT_32BITS(dp
);
305 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
) {
307 sa3
->sa_mtime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
309 sa3
->sa_mtime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
318 static int nfserr
; /* true if we error rather than trunc */
321 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
324 printf(" mode %o", sa3
->sa_mode
);
326 printf(" uid %u", sa3
->sa_uid
);
328 printf(" gid %u", sa3
->sa_gid
);
330 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
331 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
332 sa3
->sa_atime
.nfsv3_nsec
);
333 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
334 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
335 sa3
->sa_mtime
.nfsv3_nsec
);
340 nfsreply_print(register const u_char
*bp
, u_int length
,
341 register const u_char
*bp2
)
343 register const struct rpc_msg
*rp
;
344 u_int32_t proc
, vers
;
345 char srcid
[20], dstid
[20]; /*fits 32bit*/
347 nfserr
= 0; /* assume no error */
348 rp
= (const struct rpc_msg
*)bp
;
351 strlcpy(srcid
, "nfs", sizeof(srcid
));
352 snprintf(dstid
, sizeof(dstid
), "%u",
353 EXTRACT_32BITS(&rp
->rm_xid
));
355 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
356 snprintf(dstid
, sizeof(dstid
), "%u",
357 EXTRACT_32BITS(&rp
->rm_xid
));
359 print_nfsaddr(bp2
, srcid
, dstid
);
360 (void)printf("reply %s %d",
361 EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
365 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
366 interp_reply(rp
, proc
, vers
, length
);
370 * Return a pointer to the first file handle in the packet.
371 * If the packet was truncated, return 0.
373 static const u_int32_t
*
374 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
376 register const u_int32_t
*dp
;
380 * find the start of the req data (if we captured it)
382 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
384 len
= EXTRACT_32BITS(&dp
[1]);
386 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
388 len
= EXTRACT_32BITS(&dp
[1]);
390 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
400 * Print out an NFS file handle and return a pointer to following word.
401 * If packet was truncated, return 0.
403 static const u_int32_t
*
404 parsefh(register const u_int32_t
*dp
, int v3
)
410 len
= EXTRACT_32BITS(dp
) / 4;
415 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
416 nfs_printfh(dp
, len
);
424 * Print out a file name and return pointer to 32-bit word past it.
425 * If packet was truncated, return 0.
427 static const u_int32_t
*
428 parsefn(register const u_int32_t
*dp
)
430 register u_int32_t len
;
431 register const u_char
*cp
;
433 /* Bail if we don't have the string length */
436 /* Fetch string length; convert to host order */
440 TCHECK2(*dp
, ((len
+ 3) & ~3));
443 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
444 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
445 /* XXX seems like we should be checking the length */
447 (void) fn_printn(cp
, len
, NULL
);
456 * Print out file handle and file name.
457 * Return pointer to 32-bit word past file name.
458 * If packet was truncated (or there was some other error), return 0.
460 static const u_int32_t
*
461 parsefhn(register const u_int32_t
*dp
, int v3
)
463 dp
= parsefh(dp
, v3
);
467 return (parsefn(dp
));
471 nfsreq_print(register const u_char
*bp
, u_int length
,
472 register const u_char
*bp2
)
474 register const struct rpc_msg
*rp
;
475 register const u_int32_t
*dp
;
479 struct nfsv3_sattr sa3
;
480 char srcid
[20], dstid
[20]; /*fits 32bit*/
482 nfserr
= 0; /* assume no error */
483 rp
= (const struct rpc_msg
*)bp
;
485 snprintf(srcid
, sizeof(srcid
), "%u",
486 EXTRACT_32BITS(&rp
->rm_xid
));
487 strlcpy(dstid
, "nfs", sizeof(dstid
));
489 snprintf(srcid
, sizeof(srcid
), "%u",
490 EXTRACT_32BITS(&rp
->rm_xid
));
491 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
493 print_nfsaddr(bp2
, srcid
, dstid
);
494 (void)printf("%d", length
);
496 xid_map_enter(rp
, bp2
); /* record proc number for later on */
498 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
499 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
501 if (!v3
&& proc
< NFS_NPROCS
)
502 proc
= nfsv3_procid
[proc
];
512 case NFSPROC_GETATTR
:
514 if ((dp
= parsereq(rp
, length
)) != NULL
&&
515 parsefh(dp
, v3
) != NULL
)
519 case NFSPROC_SETATTR
:
521 if ((dp
= parsereq(rp
, length
)) != NULL
&&
522 parsefh(dp
, v3
) != NULL
)
528 if ((dp
= parsereq(rp
, length
)) != NULL
&&
529 parsefhn(dp
, v3
) != NULL
)
535 if ((dp
= parsereq(rp
, length
)) != NULL
&&
536 (dp
= parsefh(dp
, v3
)) != NULL
) {
538 printf(" %04x", EXTRACT_32BITS(&dp
[0]));
543 case NFSPROC_READLINK
:
545 if ((dp
= parsereq(rp
, length
)) != NULL
&&
546 parsefh(dp
, v3
) != NULL
)
552 if ((dp
= parsereq(rp
, length
)) != NULL
&&
553 (dp
= parsefh(dp
, v3
)) != NULL
) {
556 printf(" %u bytes @ ",
557 EXTRACT_32BITS(&dp
[2]));
558 print_int64(dp
, UNSIGNED
);
561 printf(" %u bytes @ %u",
562 EXTRACT_32BITS(&dp
[1]),
563 EXTRACT_32BITS(&dp
[0]));
571 if ((dp
= parsereq(rp
, length
)) != NULL
&&
572 (dp
= parsefh(dp
, v3
)) != NULL
) {
575 printf(" %u bytes @ ",
576 EXTRACT_32BITS(&dp
[4]));
577 print_int64(dp
, UNSIGNED
);
582 tok2str(nfsv3_writemodes
,
583 NULL
, EXTRACT_32BITS(dp
)));
587 printf(" %u (%u) bytes @ %u (%u)",
588 EXTRACT_32BITS(&dp
[3]),
589 EXTRACT_32BITS(&dp
[2]),
590 EXTRACT_32BITS(&dp
[1]),
591 EXTRACT_32BITS(&dp
[0]));
599 if ((dp
= parsereq(rp
, length
)) != NULL
&&
600 parsefhn(dp
, v3
) != NULL
)
606 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
610 case NFSPROC_SYMLINK
:
612 if ((dp
= parsereq(rp
, length
)) != 0 &&
613 (dp
= parsefhn(dp
, v3
)) != 0) {
614 fputs(" ->", stdout
);
615 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
617 if (parsefn(dp
) == 0)
620 print_sattr3(&sa3
, vflag
);
627 if ((dp
= parsereq(rp
, length
)) != 0 &&
628 (dp
= parsefhn(dp
, v3
)) != 0) {
630 type
= (nfs_type
)EXTRACT_32BITS(dp
);
632 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
634 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
635 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
638 EXTRACT_32BITS(&dp
[0]),
639 EXTRACT_32BITS(&dp
[1]));
643 print_sattr3(&sa3
, vflag
);
650 if ((dp
= parsereq(rp
, length
)) != NULL
&&
651 parsefhn(dp
, v3
) != NULL
)
657 if ((dp
= parsereq(rp
, length
)) != NULL
&&
658 parsefhn(dp
, v3
) != NULL
)
664 if ((dp
= parsereq(rp
, length
)) != NULL
&&
665 (dp
= parsefhn(dp
, v3
)) != NULL
) {
666 fputs(" ->", stdout
);
667 if (parsefhn(dp
, v3
) != NULL
)
674 if ((dp
= parsereq(rp
, length
)) != NULL
&&
675 (dp
= parsefh(dp
, v3
)) != NULL
) {
676 fputs(" ->", stdout
);
677 if (parsefhn(dp
, v3
) != NULL
)
682 case NFSPROC_READDIR
:
684 if ((dp
= parsereq(rp
, length
)) != NULL
&&
685 (dp
= parsefh(dp
, v3
)) != NULL
) {
689 * We shouldn't really try to interpret the
690 * offset cookie here.
692 printf(" %u bytes @ ",
693 EXTRACT_32BITS(&dp
[4]));
694 print_int64(dp
, SIGNED
);
696 printf(" verf %08x%08x", dp
[2],
701 * Print the offset as signed, since -1 is
702 * common, but offsets > 2^31 aren't.
704 printf(" %u bytes @ %d",
705 EXTRACT_32BITS(&dp
[1]),
706 EXTRACT_32BITS(&dp
[0]));
712 case NFSPROC_READDIRPLUS
:
713 printf(" readdirplus");
714 if ((dp
= parsereq(rp
, length
)) != NULL
&&
715 (dp
= parsefh(dp
, v3
)) != NULL
) {
718 * We don't try to interpret the offset
721 printf(" %u bytes @ ", EXTRACT_32BITS(&dp
[4]));
722 print_int64(dp
, SIGNED
);
724 printf(" max %u verf %08x%08x",
725 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
732 if ((dp
= parsereq(rp
, length
)) != NULL
&&
733 parsefh(dp
, v3
) != NULL
)
739 if ((dp
= parsereq(rp
, length
)) != NULL
&&
740 parsefh(dp
, v3
) != NULL
)
744 case NFSPROC_PATHCONF
:
746 if ((dp
= parsereq(rp
, length
)) != NULL
&&
747 parsefh(dp
, v3
) != NULL
)
753 if ((dp
= parsereq(rp
, length
)) != NULL
&&
754 (dp
= parsefh(dp
, v3
)) != NULL
) {
755 printf(" %u bytes @ ", EXTRACT_32BITS(&dp
[2]));
756 print_int64(dp
, UNSIGNED
);
762 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
768 fputs(" [|nfs]", stdout
);
772 * Print out an NFS file handle.
773 * We assume packet was not truncated before the end of the
774 * file handle pointed to by dp.
776 * Note: new version (using portable file-handle parser) doesn't produce
777 * generation number. It probably could be made to do that, with some
778 * additional hacking on the parser code.
781 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
785 const char *sfsname
= NULL
;
790 char const *sep
= "";
793 for (i
=0; i
<len
; i
++) {
794 (void)printf("%s%x", sep
, dp
[i
]);
801 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
804 /* file system ID is ASCII, not numeric, for this server OS */
805 static char temp
[NFSX_V3FHMAX
+1];
807 /* Make sure string is null-terminated */
808 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
809 temp
[sizeof(temp
) - 1] = '\0';
810 /* Remove trailing spaces */
811 spacep
= strchr(temp
, ' ');
815 (void)printf(" fh %s/", temp
);
817 (void)printf(" fh %d,%d/",
818 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
821 if(fsid
.Fsid_dev
.Minor
== 257)
822 /* Print the undecoded handle */
823 (void)printf("%s", fsid
.Opaque_Handle
);
825 (void)printf("%ld", (long) ino
);
829 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
830 * us to match up replies with requests and thus to know how to parse
834 struct xid_map_entry
{
835 u_int32_t xid
; /* transaction ID (net order) */
836 int ipver
; /* IP version (4 or 6) */
838 struct in6_addr client
; /* client IP address (net order) */
839 struct in6_addr server
; /* server IP address (net order) */
841 struct in_addr client
; /* client IP address (net order) */
842 struct in_addr server
; /* server IP address (net order) */
844 u_int32_t proc
; /* call proc number (host order) */
845 u_int32_t vers
; /* program version (host order) */
849 * Map entries are kept in an array that we manage as a ring;
850 * new entries are always added at the tail of the ring. Initially,
851 * all the entries are zero and hence don't match anything.
854 #define XIDMAPSIZE 64
856 struct xid_map_entry xid_map
[XIDMAPSIZE
];
858 int xid_map_next
= 0;
859 int xid_map_hint
= 0;
862 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
864 struct ip
*ip
= NULL
;
866 struct ip6_hdr
*ip6
= NULL
;
868 struct xid_map_entry
*xmep
;
870 switch (IP_V((struct ip
*)bp
)) {
872 ip
= (struct ip
*)bp
;
876 ip6
= (struct ip6_hdr
*)bp
;
883 xmep
= &xid_map
[xid_map_next
];
885 if (++xid_map_next
>= XIDMAPSIZE
)
888 xmep
->xid
= rp
->rm_xid
;
891 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
892 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
897 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
898 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
901 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
902 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
906 * Returns 0 and puts NFSPROC_xxx in proc return and
907 * version in vers return, or returns -1 on failure
910 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
914 struct xid_map_entry
*xmep
;
915 u_int32_t xid
= rp
->rm_xid
;
916 struct ip
*ip
= (struct ip
*)bp
;
918 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
922 /* Start searching from where we last left off */
927 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
929 switch (xmep
->ipver
) {
931 if (memcmp(&ip
->ip_src
, &xmep
->server
,
932 sizeof(ip
->ip_src
)) != 0 ||
933 memcmp(&ip
->ip_dst
, &xmep
->client
,
934 sizeof(ip
->ip_dst
)) != 0) {
940 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
941 sizeof(ip6
->ip6_src
)) != 0 ||
942 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
943 sizeof(ip6
->ip6_dst
)) != 0) {
960 if (++i
>= XIDMAPSIZE
)
962 } while (i
!= xid_map_hint
);
969 * Routines for parsing reply packets
973 * Return a pointer to the beginning of the actual results.
974 * If the packet was truncated, return 0.
976 static const u_int32_t
*
977 parserep(register const struct rpc_msg
*rp
, register u_int length
)
979 register const u_int32_t
*dp
;
981 enum accept_stat astat
;
985 * Here we find the address of the ar_verf credentials.
986 * Originally, this calculation was
987 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
988 * On the wire, the rp_acpt field starts immediately after
989 * the (32 bit) rp_stat field. However, rp_acpt (which is a
990 * "struct accepted_reply") contains a "struct opaque_auth",
991 * whose internal representation contains a pointer, so on a
992 * 64-bit machine the compiler inserts 32 bits of padding
993 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
994 * the internal representation to parse the on-the-wire
995 * representation. Instead, we skip past the rp_stat field,
996 * which is an "enum" and so occupies one 32-bit word.
998 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
1000 len
= EXTRACT_32BITS(&dp
[1]);
1004 * skip past the ar_verf credentials.
1006 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
1010 * now we can check the ar_stat field
1012 astat
= EXTRACT_32BITS(dp
);
1019 printf(" PROG_UNAVAIL");
1020 nfserr
= 1; /* suppress trunc string */
1024 printf(" PROG_MISMATCH");
1025 nfserr
= 1; /* suppress trunc string */
1029 printf(" PROC_UNAVAIL");
1030 nfserr
= 1; /* suppress trunc string */
1034 printf(" GARBAGE_ARGS");
1035 nfserr
= 1; /* suppress trunc string */
1039 printf(" SYSTEM_ERR");
1040 nfserr
= 1; /* suppress trunc string */
1044 printf(" ar_stat %d", astat
);
1045 nfserr
= 1; /* suppress trunc string */
1048 /* successful return */
1049 TCHECK2(*dp
, sizeof(astat
));
1050 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1055 static const u_int32_t
*
1056 parsestatus(const u_int32_t
*dp
, int *er
)
1062 errnum
= EXTRACT_32BITS(&dp
[0]);
1067 printf(" ERROR: %s",
1068 tok2str(status2str
, "unk %d", errnum
));
1076 static const u_int32_t
*
1077 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1079 const struct nfs_fattr
*fap
;
1081 fap
= (const struct nfs_fattr
*)dp
;
1082 TCHECK(fap
->fa_gid
);
1084 printf(" %s %o ids %d/%d",
1085 tok2str(type2str
, "unk-ft %d ",
1086 EXTRACT_32BITS(&fap
->fa_type
)),
1087 EXTRACT_32BITS(&fap
->fa_mode
),
1088 EXTRACT_32BITS(&fap
->fa_uid
),
1089 EXTRACT_32BITS(&fap
->fa_gid
));
1091 TCHECK(fap
->fa3_size
);
1093 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1096 TCHECK(fap
->fa2_size
);
1097 printf(" sz %d ", EXTRACT_32BITS(&fap
->fa2_size
));
1100 /* print lots more stuff */
1103 TCHECK(fap
->fa3_ctime
);
1104 printf("nlink %d rdev %d/%d ",
1105 EXTRACT_32BITS(&fap
->fa_nlink
),
1106 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1107 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1109 print_int64((u_int32_t
*)&fap
->fa3_fsid
, HEX
);
1111 print_int64((u_int32_t
*)&fap
->fa3_fileid
, HEX
);
1112 printf(" a/m/ctime %u.%06u ",
1113 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1114 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1116 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1117 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1119 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1120 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1122 TCHECK(fap
->fa2_ctime
);
1123 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1124 EXTRACT_32BITS(&fap
->fa_nlink
),
1125 EXTRACT_32BITS(&fap
->fa2_rdev
),
1126 EXTRACT_32BITS(&fap
->fa2_fsid
),
1127 EXTRACT_32BITS(&fap
->fa2_fileid
));
1129 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1130 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1132 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1133 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1135 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1136 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1139 return ((const u_int32_t
*)((unsigned char *)dp
+
1140 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1146 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1150 dp
= parsestatus(dp
, &er
);
1156 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1160 parsediropres(const u_int32_t
*dp
)
1164 if (!(dp
= parsestatus(dp
, &er
)))
1169 dp
= parsefh(dp
, 0);
1173 return (parsefattr(dp
, vflag
, 0) != NULL
);
1177 parselinkres(const u_int32_t
*dp
, int v3
)
1181 dp
= parsestatus(dp
, &er
);
1186 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1189 return (parsefn(dp
) != NULL
);
1193 parsestatfs(const u_int32_t
*dp
, int v3
)
1195 const struct nfs_statfs
*sfsp
;
1198 dp
= parsestatus(dp
, &er
);
1210 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1214 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1216 sfsp
= (const struct nfs_statfs
*)dp
;
1220 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1222 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1224 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1227 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1229 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1231 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1233 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1236 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1237 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1238 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1239 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1240 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1241 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1250 parserddires(const u_int32_t
*dp
)
1254 dp
= parsestatus(dp
, &er
);
1263 printf(" offset %x size %d ",
1264 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1273 static const u_int32_t
*
1274 parse_wcc_attr(const u_int32_t
*dp
)
1277 print_int64(dp
, UNSIGNED
);
1278 printf(" mtime %u.%06u ctime %u.%06u",
1279 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1280 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1285 * Pre operation attributes. Print only if vflag > 1.
1287 static const u_int32_t
*
1288 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1291 if (!EXTRACT_32BITS(&dp
[0]))
1296 return parse_wcc_attr(dp
);
1298 /* If not verbose enough, just skip over wcc_attr */
1306 * Post operation attributes are printed if vflag >= 1
1308 static const u_int32_t
*
1309 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1312 if (!EXTRACT_32BITS(&dp
[0]))
1316 return parsefattr(dp
, verbose
, 1);
1318 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1323 static const u_int32_t
*
1324 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1328 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1333 return parse_post_op_attr(dp
, verbose
);
1336 static const u_int32_t
*
1337 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1341 if (!(dp
= parsestatus(dp
, &er
)))
1344 dp
= parse_wcc_data(dp
, verbose
);
1347 if (!EXTRACT_32BITS(&dp
[0]))
1350 if (!(dp
= parsefh(dp
, 1)))
1353 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1356 printf("dir attr:");
1357 dp
= parse_wcc_data(dp
, verbose
);
1367 parsewccres(const u_int32_t
*dp
, int verbose
)
1371 if (!(dp
= parsestatus(dp
, &er
)))
1373 return parse_wcc_data(dp
, verbose
) != 0;
1376 static const u_int32_t
*
1377 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1381 if (!(dp
= parsestatus(dp
, &er
)))
1385 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1391 printf(" verf %08x%08x", dp
[0], dp
[1]);
1400 parsefsinfo(const u_int32_t
*dp
)
1402 struct nfsv3_fsinfo
*sfp
;
1405 if (!(dp
= parsestatus(dp
, &er
)))
1409 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1414 sfp
= (struct nfsv3_fsinfo
*)dp
;
1416 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1417 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1418 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1419 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1420 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1421 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1423 printf(" rtmult %u wtmult %u maxfsz ",
1424 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1425 EXTRACT_32BITS(&sfp
->fs_wtmult
));
1426 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1427 printf(" delta %u.%06u ",
1428 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1429 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1437 parsepathconf(const u_int32_t
*dp
)
1440 struct nfsv3_pathconf
*spp
;
1442 if (!(dp
= parsestatus(dp
, &er
)))
1446 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1451 spp
= (struct nfsv3_pathconf
*)dp
;
1454 printf(" linkmax %u namemax %u %s %s %s %s",
1455 EXTRACT_32BITS(&spp
->pc_linkmax
),
1456 EXTRACT_32BITS(&spp
->pc_namemax
),
1457 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1458 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1459 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1460 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1467 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1469 register const u_int32_t
*dp
;
1473 v3
= (vers
== NFS_VER3
);
1475 if (!v3
&& proc
< NFS_NPROCS
)
1476 proc
= nfsv3_procid
[proc
];
1488 case NFSPROC_GETATTR
:
1490 dp
= parserep(rp
, length
);
1491 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1495 case NFSPROC_SETATTR
:
1497 if (!(dp
= parserep(rp
, length
)))
1500 if (parsewccres(dp
, vflag
))
1503 if (parseattrstat(dp
, !qflag
, 0) != 0)
1508 case NFSPROC_LOOKUP
:
1510 if (!(dp
= parserep(rp
, length
)))
1513 if (!(dp
= parsestatus(dp
, &er
)))
1517 printf(" post dattr:");
1518 dp
= parse_post_op_attr(dp
, vflag
);
1521 if (!(dp
= parsefh(dp
, v3
)))
1523 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1525 printf(" post dattr:");
1526 dp
= parse_post_op_attr(dp
, vflag
);
1532 if (parsediropres(dp
) != 0)
1537 case NFSPROC_ACCESS
:
1539 if (!(dp
= parserep(rp
, length
)))
1541 if (!(dp
= parsestatus(dp
, &er
)))
1545 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1548 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1551 case NFSPROC_READLINK
:
1552 printf(" readlink");
1553 dp
= parserep(rp
, length
);
1554 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1560 if (!(dp
= parserep(rp
, length
)))
1563 if (!(dp
= parsestatus(dp
, &er
)))
1565 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1571 printf("%u bytes", EXTRACT_32BITS(&dp
[0]));
1572 if (EXTRACT_32BITS(&dp
[1]))
1577 if (parseattrstat(dp
, vflag
, 0) != 0)
1584 if (!(dp
= parserep(rp
, length
)))
1587 if (!(dp
= parsestatus(dp
, &er
)))
1589 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1595 printf("%u bytes", EXTRACT_32BITS(&dp
[0]));
1599 tok2str(nfsv3_writemodes
,
1600 NULL
, EXTRACT_32BITS(&dp
[1])));
1605 if (parseattrstat(dp
, vflag
, v3
) != 0)
1610 case NFSPROC_CREATE
:
1612 if (!(dp
= parserep(rp
, length
)))
1615 if (parsecreateopres(dp
, vflag
) != 0)
1618 if (parsediropres(dp
) != 0)
1625 if (!(dp
= parserep(rp
, length
)))
1628 if (parsecreateopres(dp
, vflag
) != 0)
1631 if (parsediropres(dp
) != 0)
1636 case NFSPROC_SYMLINK
:
1638 if (!(dp
= parserep(rp
, length
)))
1641 if (parsecreateopres(dp
, vflag
) != 0)
1644 if (parsestatus(dp
, &er
) != 0)
1651 if (!(dp
= parserep(rp
, length
)))
1653 if (parsecreateopres(dp
, vflag
) != 0)
1657 case NFSPROC_REMOVE
:
1659 if (!(dp
= parserep(rp
, length
)))
1662 if (parsewccres(dp
, vflag
))
1665 if (parsestatus(dp
, &er
) != 0)
1672 if (!(dp
= parserep(rp
, length
)))
1675 if (parsewccres(dp
, vflag
))
1678 if (parsestatus(dp
, &er
) != 0)
1683 case NFSPROC_RENAME
:
1685 if (!(dp
= parserep(rp
, length
)))
1688 if (!(dp
= parsestatus(dp
, &er
)))
1692 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1695 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1700 if (parsestatus(dp
, &er
) != 0)
1707 if (!(dp
= parserep(rp
, length
)))
1710 if (!(dp
= parsestatus(dp
, &er
)))
1713 printf(" file POST:");
1714 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1717 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1722 if (parsestatus(dp
, &er
) != 0)
1727 case NFSPROC_READDIR
:
1729 if (!(dp
= parserep(rp
, length
)))
1732 if (parsev3rddirres(dp
, vflag
))
1735 if (parserddires(dp
) != 0)
1740 case NFSPROC_READDIRPLUS
:
1741 printf(" readdirplus");
1742 if (!(dp
= parserep(rp
, length
)))
1744 if (parsev3rddirres(dp
, vflag
))
1748 case NFSPROC_FSSTAT
:
1750 dp
= parserep(rp
, length
);
1751 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1755 case NFSPROC_FSINFO
:
1757 dp
= parserep(rp
, length
);
1758 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1762 case NFSPROC_PATHCONF
:
1763 printf(" pathconf");
1764 dp
= parserep(rp
, length
);
1765 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1769 case NFSPROC_COMMIT
:
1771 dp
= parserep(rp
, length
);
1772 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1777 printf(" proc-%u", proc
);
1782 fputs(" [|nfs]", stdout
);