]>
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.111 2007-12-22 03:08:04 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
51 static const char tstr
[] = " [|nfs]";
53 static void nfs_printfh(const u_int32_t
*, const u_int
);
54 static int xid_map_enter(const struct sunrpc_msg
*, const u_char
*);
55 static int xid_map_find(const struct sunrpc_msg
*, const u_char
*,
56 u_int32_t
*, u_int32_t
*);
57 static void interp_reply(const struct sunrpc_msg
*, u_int32_t
, u_int32_t
, int);
58 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
59 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
60 static void print_nfsaddr(const u_char
*, const char *, const char *);
63 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
65 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
95 * NFS V2 and V3 status values.
97 * Some of these come from the RFCs for NFS V2 and V3, with the message
98 * strings taken from the FreeBSD C library "errlst.c".
100 * Others are errors that are not in the RFC but that I suspect some
101 * NFS servers could return; the values are FreeBSD errno values, as
102 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
103 * was primarily BSD-derived.
105 static const struct tok status2str
[] = {
106 { 1, "Operation not permitted" }, /* EPERM */
107 { 2, "No such file or directory" }, /* ENOENT */
108 { 5, "Input/output error" }, /* EIO */
109 { 6, "Device not configured" }, /* ENXIO */
110 { 11, "Resource deadlock avoided" }, /* EDEADLK */
111 { 12, "Cannot allocate memory" }, /* ENOMEM */
112 { 13, "Permission denied" }, /* EACCES */
113 { 17, "File exists" }, /* EEXIST */
114 { 18, "Cross-device link" }, /* EXDEV */
115 { 19, "Operation not supported by device" }, /* ENODEV */
116 { 20, "Not a directory" }, /* ENOTDIR */
117 { 21, "Is a directory" }, /* EISDIR */
118 { 22, "Invalid argument" }, /* EINVAL */
119 { 26, "Text file busy" }, /* ETXTBSY */
120 { 27, "File too large" }, /* EFBIG */
121 { 28, "No space left on device" }, /* ENOSPC */
122 { 30, "Read-only file system" }, /* EROFS */
123 { 31, "Too many links" }, /* EMLINK */
124 { 45, "Operation not supported" }, /* EOPNOTSUPP */
125 { 62, "Too many levels of symbolic links" }, /* ELOOP */
126 { 63, "File name too long" }, /* ENAMETOOLONG */
127 { 66, "Directory not empty" }, /* ENOTEMPTY */
128 { 69, "Disc quota exceeded" }, /* EDQUOT */
129 { 70, "Stale NFS file handle" }, /* ESTALE */
130 { 71, "Too many levels of remote in path" }, /* EREMOTE */
131 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
132 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
133 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
134 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
135 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
136 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
137 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
138 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
139 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
143 static const struct tok nfsv3_writemodes
[] = {
150 static const struct tok type2str
[] = {
162 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
167 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
169 #ifndef INET_ADDRSTRLEN
170 #define INET_ADDRSTRLEN 16
172 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
175 srcaddr
[0] = dstaddr
[0] = '\0';
176 switch (IP_V((struct ip
*)bp
)) {
178 ip
= (struct ip
*)bp
;
179 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
180 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
184 ip6
= (struct ip6_hdr
*)bp
;
185 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
187 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
192 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
193 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
197 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
200 static const u_int32_t
*
201 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
204 sa3
->sa_modeset
= EXTRACT_32BITS(dp
);
206 if (sa3
->sa_modeset
) {
208 sa3
->sa_mode
= EXTRACT_32BITS(dp
);
213 sa3
->sa_uidset
= EXTRACT_32BITS(dp
);
215 if (sa3
->sa_uidset
) {
217 sa3
->sa_uid
= EXTRACT_32BITS(dp
);
222 sa3
->sa_gidset
= EXTRACT_32BITS(dp
);
224 if (sa3
->sa_gidset
) {
226 sa3
->sa_gid
= EXTRACT_32BITS(dp
);
231 sa3
->sa_sizeset
= EXTRACT_32BITS(dp
);
233 if (sa3
->sa_sizeset
) {
235 sa3
->sa_size
= EXTRACT_32BITS(dp
);
240 sa3
->sa_atimetype
= EXTRACT_32BITS(dp
);
242 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
) {
244 sa3
->sa_atime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
246 sa3
->sa_atime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
251 sa3
->sa_mtimetype
= EXTRACT_32BITS(dp
);
253 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
) {
255 sa3
->sa_mtime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
257 sa3
->sa_mtime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
266 static int nfserr
; /* true if we error rather than trunc */
269 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
272 printf(" mode %o", sa3
->sa_mode
);
274 printf(" uid %u", sa3
->sa_uid
);
276 printf(" gid %u", sa3
->sa_gid
);
278 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
279 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
280 sa3
->sa_atime
.nfsv3_nsec
);
281 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
282 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
283 sa3
->sa_mtime
.nfsv3_nsec
);
288 nfsreply_print(register const u_char
*bp
, u_int length
,
289 register const u_char
*bp2
)
291 register const struct sunrpc_msg
*rp
;
292 char srcid
[20], dstid
[20]; /*fits 32bit*/
294 nfserr
= 0; /* assume no error */
295 rp
= (const struct sunrpc_msg
*)bp
;
299 strlcpy(srcid
, "nfs", sizeof(srcid
));
300 snprintf(dstid
, sizeof(dstid
), "%u",
301 EXTRACT_32BITS(&rp
->rm_xid
));
303 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
304 snprintf(dstid
, sizeof(dstid
), "%u",
305 EXTRACT_32BITS(&rp
->rm_xid
));
307 print_nfsaddr(bp2
, srcid
, dstid
);
309 nfsreply_print_noaddr(bp
, length
, bp2
);
318 nfsreply_print_noaddr(register const u_char
*bp
, u_int length
,
319 register const u_char
*bp2
)
321 register const struct sunrpc_msg
*rp
;
322 u_int32_t proc
, vers
, reply_stat
;
323 enum sunrpc_reject_stat rstat
;
326 enum sunrpc_auth_stat rwhy
;
328 nfserr
= 0; /* assume no error */
329 rp
= (const struct sunrpc_msg
*)bp
;
331 TCHECK(rp
->rm_reply
.rp_stat
);
332 reply_stat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
);
333 switch (reply_stat
) {
335 case SUNRPC_MSG_ACCEPTED
:
336 (void)printf("reply ok %u", length
);
337 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
338 interp_reply(rp
, proc
, vers
, length
);
341 case SUNRPC_MSG_DENIED
:
342 (void)printf("reply ERR %u: ", length
);
343 TCHECK(rp
->rm_reply
.rp_reject
.rj_stat
);
344 rstat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_stat
);
347 case SUNRPC_RPC_MISMATCH
:
348 TCHECK(rp
->rm_reply
.rp_reject
.rj_vers
.high
);
349 rlow
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.low
);
350 rhigh
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.high
);
351 (void)printf("RPC Version mismatch (%u-%u)",
355 case SUNRPC_AUTH_ERROR
:
356 TCHECK(rp
->rm_reply
.rp_reject
.rj_why
);
357 rwhy
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_why
);
358 (void)printf("Auth ");
365 case SUNRPC_AUTH_BADCRED
:
366 (void)printf("Bogus Credentials (seal broken)");
369 case SUNRPC_AUTH_REJECTEDCRED
:
370 (void)printf("Rejected Credentials (client should begin new session)");
373 case SUNRPC_AUTH_BADVERF
:
374 (void)printf("Bogus Verifier (seal broken)");
377 case SUNRPC_AUTH_REJECTEDVERF
:
378 (void)printf("Verifier expired or was replayed");
381 case SUNRPC_AUTH_TOOWEAK
:
382 (void)printf("Credentials are too weak");
385 case SUNRPC_AUTH_INVALIDRESP
:
386 (void)printf("Bogus response verifier");
389 case SUNRPC_AUTH_FAILED
:
390 (void)printf("Unknown failure");
394 (void)printf("Invalid failure code %u",
401 (void)printf("Unknown reason for rejecting rpc message %u",
402 (unsigned int)rstat
);
408 (void)printf("reply Unknown rpc response code=%u %u",
420 * Return a pointer to the first file handle in the packet.
421 * If the packet was truncated, return 0.
423 static const u_int32_t
*
424 parsereq(register const struct sunrpc_msg
*rp
, register u_int length
)
426 register const u_int32_t
*dp
;
430 * find the start of the req data (if we captured it)
432 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
434 len
= EXTRACT_32BITS(&dp
[1]);
436 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
438 len
= EXTRACT_32BITS(&dp
[1]);
440 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
450 * Print out an NFS file handle and return a pointer to following word.
451 * If packet was truncated, return 0.
453 static const u_int32_t
*
454 parsefh(register const u_int32_t
*dp
, int v3
)
460 len
= EXTRACT_32BITS(dp
) / 4;
465 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
466 nfs_printfh(dp
, len
);
474 * Print out a file name and return pointer to 32-bit word past it.
475 * If packet was truncated, return 0.
477 static const u_int32_t
*
478 parsefn(register const u_int32_t
*dp
)
480 register u_int32_t len
;
481 register const u_char
*cp
;
483 /* Bail if we don't have the string length */
486 /* Fetch string length; convert to host order */
490 TCHECK2(*dp
, ((len
+ 3) & ~3));
493 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
494 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
496 if (fn_printn(cp
, len
, snapend
)) {
508 * Print out file handle and file name.
509 * Return pointer to 32-bit word past file name.
510 * If packet was truncated (or there was some other error), return 0.
512 static const u_int32_t
*
513 parsefhn(register const u_int32_t
*dp
, int v3
)
515 dp
= parsefh(dp
, v3
);
519 return (parsefn(dp
));
523 nfsreq_print(register const u_char
*bp
, u_int length
,
524 register const u_char
*bp2
)
526 register const struct sunrpc_msg
*rp
;
527 char srcid
[20], dstid
[20]; /*fits 32bit*/
529 nfserr
= 0; /* assume no error */
530 rp
= (const struct sunrpc_msg
*)bp
;
534 snprintf(srcid
, sizeof(srcid
), "%u",
535 EXTRACT_32BITS(&rp
->rm_xid
));
536 strlcpy(dstid
, "nfs", sizeof(dstid
));
538 snprintf(srcid
, sizeof(srcid
), "%u",
539 EXTRACT_32BITS(&rp
->rm_xid
));
540 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
542 print_nfsaddr(bp2
, srcid
, dstid
);
543 (void)printf("%d", length
);
545 nfsreq_print_noaddr(bp
, length
, bp2
);
554 nfsreq_print_noaddr(register const u_char
*bp
, u_int length
,
555 register const u_char
*bp2
)
557 register const struct sunrpc_msg
*rp
;
558 register const u_int32_t
*dp
;
562 u_int32_t access_flags
;
563 struct nfsv3_sattr sa3
;
565 nfserr
= 0; /* assume no error */
566 rp
= (const struct sunrpc_msg
*)bp
;
568 if (!xid_map_enter(rp
, bp2
)) /* record proc number for later on */
571 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
572 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
574 if (!v3
&& proc
< NFS_NPROCS
)
575 proc
= nfsv3_procid
[proc
];
585 case NFSPROC_GETATTR
:
587 if ((dp
= parsereq(rp
, length
)) != NULL
&&
588 parsefh(dp
, v3
) != NULL
)
592 case NFSPROC_SETATTR
:
594 if ((dp
= parsereq(rp
, length
)) != NULL
&&
595 parsefh(dp
, v3
) != NULL
)
601 if ((dp
= parsereq(rp
, length
)) != NULL
&&
602 parsefhn(dp
, v3
) != NULL
)
608 if ((dp
= parsereq(rp
, length
)) != NULL
&&
609 (dp
= parsefh(dp
, v3
)) != NULL
) {
611 access_flags
= EXTRACT_32BITS(&dp
[0]);
612 if (access_flags
& ~NFSV3ACCESS_FULL
) {
613 /* NFSV3ACCESS definitions aren't up to date */
614 printf(" %04x", access_flags
);
615 } else if ((access_flags
& NFSV3ACCESS_FULL
) == NFSV3ACCESS_FULL
) {
616 printf(" NFS_ACCESS_FULL");
618 char separator
= ' ';
619 if (access_flags
& NFSV3ACCESS_READ
) {
620 printf(" NFS_ACCESS_READ");
623 if (access_flags
& NFSV3ACCESS_LOOKUP
) {
624 printf("%cNFS_ACCESS_LOOKUP", separator
);
627 if (access_flags
& NFSV3ACCESS_MODIFY
) {
628 printf("%cNFS_ACCESS_MODIFY", separator
);
631 if (access_flags
& NFSV3ACCESS_EXTEND
) {
632 printf("%cNFS_ACCESS_EXTEND", separator
);
635 if (access_flags
& NFSV3ACCESS_DELETE
) {
636 printf("%cNFS_ACCESS_DELETE", separator
);
639 if (access_flags
& NFSV3ACCESS_EXECUTE
)
640 printf("%cNFS_ACCESS_EXECUTE", separator
);
646 case NFSPROC_READLINK
:
648 if ((dp
= parsereq(rp
, length
)) != NULL
&&
649 parsefh(dp
, v3
) != NULL
)
655 if ((dp
= parsereq(rp
, length
)) != NULL
&&
656 (dp
= parsefh(dp
, v3
)) != NULL
) {
659 printf(" %u bytes @ %" PRIu64
,
660 EXTRACT_32BITS(&dp
[2]),
661 EXTRACT_64BITS(&dp
[0]));
664 printf(" %u bytes @ %u",
665 EXTRACT_32BITS(&dp
[1]),
666 EXTRACT_32BITS(&dp
[0]));
674 if ((dp
= parsereq(rp
, length
)) != NULL
&&
675 (dp
= parsefh(dp
, v3
)) != NULL
) {
678 printf(" %u (%u) bytes @ %" PRIu64
,
679 EXTRACT_32BITS(&dp
[4]),
680 EXTRACT_32BITS(&dp
[2]),
681 EXTRACT_64BITS(&dp
[0]));
686 tok2str(nfsv3_writemodes
,
687 NULL
, EXTRACT_32BITS(dp
)));
691 printf(" %u (%u) bytes @ %u (%u)",
692 EXTRACT_32BITS(&dp
[3]),
693 EXTRACT_32BITS(&dp
[2]),
694 EXTRACT_32BITS(&dp
[1]),
695 EXTRACT_32BITS(&dp
[0]));
703 if ((dp
= parsereq(rp
, length
)) != NULL
&&
704 parsefhn(dp
, v3
) != NULL
)
710 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
714 case NFSPROC_SYMLINK
:
716 if ((dp
= parsereq(rp
, length
)) != 0 &&
717 (dp
= parsefhn(dp
, v3
)) != 0) {
718 fputs(" ->", stdout
);
719 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
721 if (parsefn(dp
) == 0)
724 print_sattr3(&sa3
, vflag
);
731 if ((dp
= parsereq(rp
, length
)) != 0 &&
732 (dp
= parsefhn(dp
, v3
)) != 0) {
734 type
= (nfs_type
)EXTRACT_32BITS(dp
);
736 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
738 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
739 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
742 EXTRACT_32BITS(&dp
[0]),
743 EXTRACT_32BITS(&dp
[1]));
747 print_sattr3(&sa3
, vflag
);
754 if ((dp
= parsereq(rp
, length
)) != NULL
&&
755 parsefhn(dp
, v3
) != NULL
)
761 if ((dp
= parsereq(rp
, length
)) != NULL
&&
762 parsefhn(dp
, v3
) != NULL
)
768 if ((dp
= parsereq(rp
, length
)) != NULL
&&
769 (dp
= parsefhn(dp
, v3
)) != NULL
) {
770 fputs(" ->", stdout
);
771 if (parsefhn(dp
, v3
) != NULL
)
778 if ((dp
= parsereq(rp
, length
)) != NULL
&&
779 (dp
= parsefh(dp
, v3
)) != NULL
) {
780 fputs(" ->", stdout
);
781 if (parsefhn(dp
, v3
) != NULL
)
786 case NFSPROC_READDIR
:
788 if ((dp
= parsereq(rp
, length
)) != NULL
&&
789 (dp
= parsefh(dp
, v3
)) != NULL
) {
793 * We shouldn't really try to interpret the
794 * offset cookie here.
796 printf(" %u bytes @ %" PRId64
,
797 EXTRACT_32BITS(&dp
[4]),
798 EXTRACT_64BITS(&dp
[0]));
800 printf(" verf %08x%08x", dp
[2],
805 * Print the offset as signed, since -1 is
806 * common, but offsets > 2^31 aren't.
808 printf(" %u bytes @ %d",
809 EXTRACT_32BITS(&dp
[1]),
810 EXTRACT_32BITS(&dp
[0]));
816 case NFSPROC_READDIRPLUS
:
817 printf(" readdirplus");
818 if ((dp
= parsereq(rp
, length
)) != NULL
&&
819 (dp
= parsefh(dp
, v3
)) != NULL
) {
822 * We don't try to interpret the offset
825 printf(" %u bytes @ %" PRId64
,
826 EXTRACT_32BITS(&dp
[4]),
827 EXTRACT_64BITS(&dp
[0]));
830 printf(" max %u verf %08x%08x",
831 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
839 if ((dp
= parsereq(rp
, length
)) != NULL
&&
840 parsefh(dp
, v3
) != NULL
)
846 if ((dp
= parsereq(rp
, length
)) != NULL
&&
847 parsefh(dp
, v3
) != NULL
)
851 case NFSPROC_PATHCONF
:
853 if ((dp
= parsereq(rp
, length
)) != NULL
&&
854 parsefh(dp
, v3
) != NULL
)
860 if ((dp
= parsereq(rp
, length
)) != NULL
&&
861 (dp
= parsefh(dp
, v3
)) != NULL
) {
863 printf(" %u bytes @ %" PRIu64
,
864 EXTRACT_32BITS(&dp
[2]),
865 EXTRACT_64BITS(&dp
[0]));
871 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
881 * Print out an NFS file handle.
882 * We assume packet was not truncated before the end of the
883 * file handle pointed to by dp.
885 * Note: new version (using portable file-handle parser) doesn't produce
886 * generation number. It probably could be made to do that, with some
887 * additional hacking on the parser code.
890 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
894 const char *sfsname
= NULL
;
899 char const *sep
= "";
902 for (i
=0; i
<len
; i
++) {
903 (void)printf("%s%x", sep
, dp
[i
]);
910 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
913 /* file system ID is ASCII, not numeric, for this server OS */
914 static char temp
[NFSX_V3FHMAX
+1];
916 /* Make sure string is null-terminated */
917 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
918 temp
[sizeof(temp
) - 1] = '\0';
919 /* Remove trailing spaces */
920 spacep
= strchr(temp
, ' ');
924 (void)printf(" fh %s/", temp
);
926 (void)printf(" fh %d,%d/",
927 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
930 if(fsid
.Fsid_dev
.Minor
== 257)
931 /* Print the undecoded handle */
932 (void)printf("%s", fsid
.Opaque_Handle
);
934 (void)printf("%ld", (long) ino
);
938 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
939 * us to match up replies with requests and thus to know how to parse
943 struct xid_map_entry
{
944 u_int32_t xid
; /* transaction ID (net order) */
945 int ipver
; /* IP version (4 or 6) */
947 struct in6_addr client
; /* client IP address (net order) */
948 struct in6_addr server
; /* server IP address (net order) */
950 struct in_addr client
; /* client IP address (net order) */
951 struct in_addr server
; /* server IP address (net order) */
953 u_int32_t proc
; /* call proc number (host order) */
954 u_int32_t vers
; /* program version (host order) */
958 * Map entries are kept in an array that we manage as a ring;
959 * new entries are always added at the tail of the ring. Initially,
960 * all the entries are zero and hence don't match anything.
963 #define XIDMAPSIZE 64
965 struct xid_map_entry xid_map
[XIDMAPSIZE
];
967 int xid_map_next
= 0;
968 int xid_map_hint
= 0;
971 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
973 struct ip
*ip
= NULL
;
975 struct ip6_hdr
*ip6
= NULL
;
977 struct xid_map_entry
*xmep
;
979 if (!TTEST(rp
->rm_call
.cb_vers
))
981 switch (IP_V((struct ip
*)bp
)) {
983 ip
= (struct ip
*)bp
;
987 ip6
= (struct ip6_hdr
*)bp
;
994 xmep
= &xid_map
[xid_map_next
];
996 if (++xid_map_next
>= XIDMAPSIZE
)
999 xmep
->xid
= rp
->rm_xid
;
1002 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
1003 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
1008 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
1009 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
1012 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
1013 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
1018 * Returns 0 and puts NFSPROC_xxx in proc return and
1019 * version in vers return, or returns -1 on failure
1022 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
1026 struct xid_map_entry
*xmep
;
1027 u_int32_t xid
= rp
->rm_xid
;
1028 struct ip
*ip
= (struct ip
*)bp
;
1030 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
1034 /* Start searching from where we last left off */
1039 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
1041 switch (xmep
->ipver
) {
1043 if (memcmp(&ip
->ip_src
, &xmep
->server
,
1044 sizeof(ip
->ip_src
)) != 0 ||
1045 memcmp(&ip
->ip_dst
, &xmep
->client
,
1046 sizeof(ip
->ip_dst
)) != 0) {
1052 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
1053 sizeof(ip6
->ip6_src
)) != 0 ||
1054 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
1055 sizeof(ip6
->ip6_dst
)) != 0) {
1072 if (++i
>= XIDMAPSIZE
)
1074 } while (i
!= xid_map_hint
);
1081 * Routines for parsing reply packets
1085 * Return a pointer to the beginning of the actual results.
1086 * If the packet was truncated, return 0.
1088 static const u_int32_t
*
1089 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
1091 register const u_int32_t
*dp
;
1093 enum sunrpc_accept_stat astat
;
1097 * Here we find the address of the ar_verf credentials.
1098 * Originally, this calculation was
1099 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
1100 * On the wire, the rp_acpt field starts immediately after
1101 * the (32 bit) rp_stat field. However, rp_acpt (which is a
1102 * "struct accepted_reply") contains a "struct opaque_auth",
1103 * whose internal representation contains a pointer, so on a
1104 * 64-bit machine the compiler inserts 32 bits of padding
1105 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
1106 * the internal representation to parse the on-the-wire
1107 * representation. Instead, we skip past the rp_stat field,
1108 * which is an "enum" and so occupies one 32-bit word.
1110 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
1112 len
= EXTRACT_32BITS(&dp
[1]);
1116 * skip past the ar_verf credentials.
1118 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
1122 * now we can check the ar_stat field
1124 astat
= (enum sunrpc_accept_stat
) EXTRACT_32BITS(dp
);
1127 case SUNRPC_SUCCESS
:
1130 case SUNRPC_PROG_UNAVAIL
:
1131 printf(" PROG_UNAVAIL");
1132 nfserr
= 1; /* suppress trunc string */
1135 case SUNRPC_PROG_MISMATCH
:
1136 printf(" PROG_MISMATCH");
1137 nfserr
= 1; /* suppress trunc string */
1140 case SUNRPC_PROC_UNAVAIL
:
1141 printf(" PROC_UNAVAIL");
1142 nfserr
= 1; /* suppress trunc string */
1145 case SUNRPC_GARBAGE_ARGS
:
1146 printf(" GARBAGE_ARGS");
1147 nfserr
= 1; /* suppress trunc string */
1150 case SUNRPC_SYSTEM_ERR
:
1151 printf(" SYSTEM_ERR");
1152 nfserr
= 1; /* suppress trunc string */
1156 printf(" ar_stat %d", astat
);
1157 nfserr
= 1; /* suppress trunc string */
1160 /* successful return */
1161 TCHECK2(*dp
, sizeof(astat
));
1162 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1167 static const u_int32_t
*
1168 parsestatus(const u_int32_t
*dp
, int *er
)
1174 errnum
= EXTRACT_32BITS(&dp
[0]);
1179 printf(" ERROR: %s",
1180 tok2str(status2str
, "unk %d", errnum
));
1188 static const u_int32_t
*
1189 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1191 const struct nfs_fattr
*fap
;
1193 fap
= (const struct nfs_fattr
*)dp
;
1194 TCHECK(fap
->fa_gid
);
1196 printf(" %s %o ids %d/%d",
1197 tok2str(type2str
, "unk-ft %d ",
1198 EXTRACT_32BITS(&fap
->fa_type
)),
1199 EXTRACT_32BITS(&fap
->fa_mode
),
1200 EXTRACT_32BITS(&fap
->fa_uid
),
1201 EXTRACT_32BITS(&fap
->fa_gid
));
1203 TCHECK(fap
->fa3_size
);
1204 printf(" sz %" PRIu64
,
1205 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1207 TCHECK(fap
->fa2_size
);
1208 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1211 /* print lots more stuff */
1214 TCHECK(fap
->fa3_ctime
);
1215 printf(" nlink %d rdev %d/%d",
1216 EXTRACT_32BITS(&fap
->fa_nlink
),
1217 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1218 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1219 printf(" fsid %" PRIx64
,
1220 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1221 printf(" fileid %" PRIx64
,
1222 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1223 printf(" a/m/ctime %u.%06u",
1224 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1225 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1227 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1228 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1230 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1231 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1233 TCHECK(fap
->fa2_ctime
);
1234 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1235 EXTRACT_32BITS(&fap
->fa_nlink
),
1236 EXTRACT_32BITS(&fap
->fa2_rdev
),
1237 EXTRACT_32BITS(&fap
->fa2_fsid
),
1238 EXTRACT_32BITS(&fap
->fa2_fileid
));
1240 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1241 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1243 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1244 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1246 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1247 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1250 return ((const u_int32_t
*)((unsigned char *)dp
+
1251 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1257 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1261 dp
= parsestatus(dp
, &er
);
1267 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1271 parsediropres(const u_int32_t
*dp
)
1275 if (!(dp
= parsestatus(dp
, &er
)))
1280 dp
= parsefh(dp
, 0);
1284 return (parsefattr(dp
, vflag
, 0) != NULL
);
1288 parselinkres(const u_int32_t
*dp
, int v3
)
1292 dp
= parsestatus(dp
, &er
);
1297 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1300 return (parsefn(dp
) != NULL
);
1304 parsestatfs(const u_int32_t
*dp
, int v3
)
1306 const struct nfs_statfs
*sfsp
;
1309 dp
= parsestatus(dp
, &er
);
1321 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1325 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1327 sfsp
= (const struct nfs_statfs
*)dp
;
1330 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1331 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1332 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1333 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1335 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1336 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1337 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1338 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1339 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1342 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1343 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1344 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1345 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1346 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1347 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1356 parserddires(const u_int32_t
*dp
)
1360 dp
= parsestatus(dp
, &er
);
1369 printf(" offset %x size %d ",
1370 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1379 static const u_int32_t
*
1380 parse_wcc_attr(const u_int32_t
*dp
)
1382 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1383 printf(" mtime %u.%06u ctime %u.%06u",
1384 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1385 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1390 * Pre operation attributes. Print only if vflag > 1.
1392 static const u_int32_t
*
1393 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1396 if (!EXTRACT_32BITS(&dp
[0]))
1401 return parse_wcc_attr(dp
);
1403 /* If not verbose enough, just skip over wcc_attr */
1411 * Post operation attributes are printed if vflag >= 1
1413 static const u_int32_t
*
1414 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1417 if (!EXTRACT_32BITS(&dp
[0]))
1421 return parsefattr(dp
, verbose
, 1);
1423 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1428 static const u_int32_t
*
1429 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1433 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1438 return parse_post_op_attr(dp
, verbose
);
1441 static const u_int32_t
*
1442 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1446 if (!(dp
= parsestatus(dp
, &er
)))
1449 dp
= parse_wcc_data(dp
, verbose
);
1452 if (!EXTRACT_32BITS(&dp
[0]))
1455 if (!(dp
= parsefh(dp
, 1)))
1458 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1461 printf(" dir attr:");
1462 dp
= parse_wcc_data(dp
, verbose
);
1472 parsewccres(const u_int32_t
*dp
, int verbose
)
1476 if (!(dp
= parsestatus(dp
, &er
)))
1478 return parse_wcc_data(dp
, verbose
) != 0;
1481 static const u_int32_t
*
1482 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1486 if (!(dp
= parsestatus(dp
, &er
)))
1490 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1496 printf(" verf %08x%08x", dp
[0], dp
[1]);
1505 parsefsinfo(const u_int32_t
*dp
)
1507 struct nfsv3_fsinfo
*sfp
;
1510 if (!(dp
= parsestatus(dp
, &er
)))
1514 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1519 sfp
= (struct nfsv3_fsinfo
*)dp
;
1521 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1522 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1523 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1524 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1525 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1526 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1528 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1529 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1530 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1531 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1532 printf(" delta %u.%06u ",
1533 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1534 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1542 parsepathconf(const u_int32_t
*dp
)
1545 struct nfsv3_pathconf
*spp
;
1547 if (!(dp
= parsestatus(dp
, &er
)))
1551 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1556 spp
= (struct nfsv3_pathconf
*)dp
;
1559 printf(" linkmax %u namemax %u %s %s %s %s",
1560 EXTRACT_32BITS(&spp
->pc_linkmax
),
1561 EXTRACT_32BITS(&spp
->pc_namemax
),
1562 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1563 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1564 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1565 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1572 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1574 register const u_int32_t
*dp
;
1578 v3
= (vers
== NFS_VER3
);
1580 if (!v3
&& proc
< NFS_NPROCS
)
1581 proc
= nfsv3_procid
[proc
];
1593 case NFSPROC_GETATTR
:
1595 dp
= parserep(rp
, length
);
1596 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1600 case NFSPROC_SETATTR
:
1602 if (!(dp
= parserep(rp
, length
)))
1605 if (parsewccres(dp
, vflag
))
1608 if (parseattrstat(dp
, !qflag
, 0) != 0)
1613 case NFSPROC_LOOKUP
:
1615 if (!(dp
= parserep(rp
, length
)))
1618 if (!(dp
= parsestatus(dp
, &er
)))
1622 printf(" post dattr:");
1623 dp
= parse_post_op_attr(dp
, vflag
);
1626 if (!(dp
= parsefh(dp
, v3
)))
1628 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1630 printf(" post dattr:");
1631 dp
= parse_post_op_attr(dp
, vflag
);
1637 if (parsediropres(dp
) != 0)
1642 case NFSPROC_ACCESS
:
1644 if (!(dp
= parserep(rp
, length
)))
1646 if (!(dp
= parsestatus(dp
, &er
)))
1650 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1653 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1656 case NFSPROC_READLINK
:
1657 printf(" readlink");
1658 dp
= parserep(rp
, length
);
1659 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1665 if (!(dp
= parserep(rp
, length
)))
1668 if (!(dp
= parsestatus(dp
, &er
)))
1670 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1676 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1677 if (EXTRACT_32BITS(&dp
[1]))
1682 if (parseattrstat(dp
, vflag
, 0) != 0)
1689 if (!(dp
= parserep(rp
, length
)))
1692 if (!(dp
= parsestatus(dp
, &er
)))
1694 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1700 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1704 tok2str(nfsv3_writemodes
,
1705 NULL
, EXTRACT_32BITS(&dp
[1])));
1710 if (parseattrstat(dp
, vflag
, v3
) != 0)
1715 case NFSPROC_CREATE
:
1717 if (!(dp
= parserep(rp
, length
)))
1720 if (parsecreateopres(dp
, vflag
) != 0)
1723 if (parsediropres(dp
) != 0)
1730 if (!(dp
= parserep(rp
, length
)))
1733 if (parsecreateopres(dp
, vflag
) != 0)
1736 if (parsediropres(dp
) != 0)
1741 case NFSPROC_SYMLINK
:
1743 if (!(dp
= parserep(rp
, length
)))
1746 if (parsecreateopres(dp
, vflag
) != 0)
1749 if (parsestatus(dp
, &er
) != 0)
1756 if (!(dp
= parserep(rp
, length
)))
1758 if (parsecreateopres(dp
, vflag
) != 0)
1762 case NFSPROC_REMOVE
:
1764 if (!(dp
= parserep(rp
, length
)))
1767 if (parsewccres(dp
, vflag
))
1770 if (parsestatus(dp
, &er
) != 0)
1777 if (!(dp
= parserep(rp
, length
)))
1780 if (parsewccres(dp
, vflag
))
1783 if (parsestatus(dp
, &er
) != 0)
1788 case NFSPROC_RENAME
:
1790 if (!(dp
= parserep(rp
, length
)))
1793 if (!(dp
= parsestatus(dp
, &er
)))
1797 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1800 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1805 if (parsestatus(dp
, &er
) != 0)
1812 if (!(dp
= parserep(rp
, length
)))
1815 if (!(dp
= parsestatus(dp
, &er
)))
1818 printf(" file POST:");
1819 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1822 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1827 if (parsestatus(dp
, &er
) != 0)
1832 case NFSPROC_READDIR
:
1834 if (!(dp
= parserep(rp
, length
)))
1837 if (parsev3rddirres(dp
, vflag
))
1840 if (parserddires(dp
) != 0)
1845 case NFSPROC_READDIRPLUS
:
1846 printf(" readdirplus");
1847 if (!(dp
= parserep(rp
, length
)))
1849 if (parsev3rddirres(dp
, vflag
))
1853 case NFSPROC_FSSTAT
:
1855 dp
= parserep(rp
, length
);
1856 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1860 case NFSPROC_FSINFO
:
1862 dp
= parserep(rp
, length
);
1863 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1867 case NFSPROC_PATHCONF
:
1868 printf(" pathconf");
1869 dp
= parserep(rp
, length
);
1870 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1874 case NFSPROC_COMMIT
:
1876 dp
= parserep(rp
, length
);
1877 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1882 printf(" proc-%u", proc
);