]>
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.
26 #include <tcpdump-stdinc.h>
31 #include "interface.h"
32 #include "addrtoname.h"
45 static const char tstr
[] = " [|nfs]";
47 static void nfs_printfh(const u_int32_t
*, const u_int
);
48 static int xid_map_enter(const struct sunrpc_msg
*, const u_char
*);
49 static int xid_map_find(const struct sunrpc_msg
*, const u_char
*,
50 u_int32_t
*, u_int32_t
*);
51 static void interp_reply(const struct sunrpc_msg
*, u_int32_t
, u_int32_t
, int);
52 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
53 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
54 static void print_nfsaddr(const u_char
*, const char *, const char *);
57 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
59 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
89 * NFS V2 and V3 status values.
91 * Some of these come from the RFCs for NFS V2 and V3, with the message
92 * strings taken from the FreeBSD C library "errlst.c".
94 * Others are errors that are not in the RFC but that I suspect some
95 * NFS servers could return; the values are FreeBSD errno values, as
96 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
97 * was primarily BSD-derived.
99 static const struct tok status2str
[] = {
100 { 1, "Operation not permitted" }, /* EPERM */
101 { 2, "No such file or directory" }, /* ENOENT */
102 { 5, "Input/output error" }, /* EIO */
103 { 6, "Device not configured" }, /* ENXIO */
104 { 11, "Resource deadlock avoided" }, /* EDEADLK */
105 { 12, "Cannot allocate memory" }, /* ENOMEM */
106 { 13, "Permission denied" }, /* EACCES */
107 { 17, "File exists" }, /* EEXIST */
108 { 18, "Cross-device link" }, /* EXDEV */
109 { 19, "Operation not supported by device" }, /* ENODEV */
110 { 20, "Not a directory" }, /* ENOTDIR */
111 { 21, "Is a directory" }, /* EISDIR */
112 { 22, "Invalid argument" }, /* EINVAL */
113 { 26, "Text file busy" }, /* ETXTBSY */
114 { 27, "File too large" }, /* EFBIG */
115 { 28, "No space left on device" }, /* ENOSPC */
116 { 30, "Read-only file system" }, /* EROFS */
117 { 31, "Too many links" }, /* EMLINK */
118 { 45, "Operation not supported" }, /* EOPNOTSUPP */
119 { 62, "Too many levels of symbolic links" }, /* ELOOP */
120 { 63, "File name too long" }, /* ENAMETOOLONG */
121 { 66, "Directory not empty" }, /* ENOTEMPTY */
122 { 69, "Disc quota exceeded" }, /* EDQUOT */
123 { 70, "Stale NFS file handle" }, /* ESTALE */
124 { 71, "Too many levels of remote in path" }, /* EREMOTE */
125 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
126 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
127 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
128 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
129 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
130 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
131 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
132 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
133 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
137 static const struct tok nfsv3_writemodes
[] = {
144 static const struct tok type2str
[] = {
156 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
161 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
163 #ifndef INET_ADDRSTRLEN
164 #define INET_ADDRSTRLEN 16
166 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
169 srcaddr
[0] = dstaddr
[0] = '\0';
170 switch (IP_V((struct ip
*)bp
)) {
172 ip
= (struct ip
*)bp
;
173 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
174 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
178 ip6
= (struct ip6_hdr
*)bp
;
179 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
181 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
186 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
187 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
191 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
194 static const u_int32_t
*
195 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
198 sa3
->sa_modeset
= EXTRACT_32BITS(dp
);
200 if (sa3
->sa_modeset
) {
202 sa3
->sa_mode
= EXTRACT_32BITS(dp
);
207 sa3
->sa_uidset
= EXTRACT_32BITS(dp
);
209 if (sa3
->sa_uidset
) {
211 sa3
->sa_uid
= EXTRACT_32BITS(dp
);
216 sa3
->sa_gidset
= EXTRACT_32BITS(dp
);
218 if (sa3
->sa_gidset
) {
220 sa3
->sa_gid
= EXTRACT_32BITS(dp
);
225 sa3
->sa_sizeset
= EXTRACT_32BITS(dp
);
227 if (sa3
->sa_sizeset
) {
229 sa3
->sa_size
= EXTRACT_32BITS(dp
);
234 sa3
->sa_atimetype
= EXTRACT_32BITS(dp
);
236 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
) {
238 sa3
->sa_atime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
240 sa3
->sa_atime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
245 sa3
->sa_mtimetype
= EXTRACT_32BITS(dp
);
247 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
) {
249 sa3
->sa_mtime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
251 sa3
->sa_mtime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
260 static int nfserr
; /* true if we error rather than trunc */
263 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
266 printf(" mode %o", sa3
->sa_mode
);
268 printf(" uid %u", sa3
->sa_uid
);
270 printf(" gid %u", sa3
->sa_gid
);
272 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
273 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
274 sa3
->sa_atime
.nfsv3_nsec
);
275 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
276 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
277 sa3
->sa_mtime
.nfsv3_nsec
);
282 nfsreply_print(register const u_char
*bp
, u_int length
,
283 register const u_char
*bp2
)
285 register const struct sunrpc_msg
*rp
;
286 char srcid
[20], dstid
[20]; /*fits 32bit*/
288 nfserr
= 0; /* assume no error */
289 rp
= (const struct sunrpc_msg
*)bp
;
293 strlcpy(srcid
, "nfs", sizeof(srcid
));
294 snprintf(dstid
, sizeof(dstid
), "%u",
295 EXTRACT_32BITS(&rp
->rm_xid
));
297 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
298 snprintf(dstid
, sizeof(dstid
), "%u",
299 EXTRACT_32BITS(&rp
->rm_xid
));
301 print_nfsaddr(bp2
, srcid
, dstid
);
303 nfsreply_print_noaddr(bp
, length
, bp2
);
312 nfsreply_print_noaddr(register const u_char
*bp
, u_int length
,
313 register const u_char
*bp2
)
315 register const struct sunrpc_msg
*rp
;
316 u_int32_t proc
, vers
, reply_stat
;
317 enum sunrpc_reject_stat rstat
;
320 enum sunrpc_auth_stat rwhy
;
322 nfserr
= 0; /* assume no error */
323 rp
= (const struct sunrpc_msg
*)bp
;
325 TCHECK(rp
->rm_reply
.rp_stat
);
326 reply_stat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
);
327 switch (reply_stat
) {
329 case SUNRPC_MSG_ACCEPTED
:
330 (void)printf("reply ok %u", length
);
331 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
332 interp_reply(rp
, proc
, vers
, length
);
335 case SUNRPC_MSG_DENIED
:
336 (void)printf("reply ERR %u: ", length
);
337 TCHECK(rp
->rm_reply
.rp_reject
.rj_stat
);
338 rstat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_stat
);
341 case SUNRPC_RPC_MISMATCH
:
342 TCHECK(rp
->rm_reply
.rp_reject
.rj_vers
.high
);
343 rlow
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.low
);
344 rhigh
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.high
);
345 (void)printf("RPC Version mismatch (%u-%u)",
349 case SUNRPC_AUTH_ERROR
:
350 TCHECK(rp
->rm_reply
.rp_reject
.rj_why
);
351 rwhy
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_why
);
352 (void)printf("Auth ");
359 case SUNRPC_AUTH_BADCRED
:
360 (void)printf("Bogus Credentials (seal broken)");
363 case SUNRPC_AUTH_REJECTEDCRED
:
364 (void)printf("Rejected Credentials (client should begin new session)");
367 case SUNRPC_AUTH_BADVERF
:
368 (void)printf("Bogus Verifier (seal broken)");
371 case SUNRPC_AUTH_REJECTEDVERF
:
372 (void)printf("Verifier expired or was replayed");
375 case SUNRPC_AUTH_TOOWEAK
:
376 (void)printf("Credentials are too weak");
379 case SUNRPC_AUTH_INVALIDRESP
:
380 (void)printf("Bogus response verifier");
383 case SUNRPC_AUTH_FAILED
:
384 (void)printf("Unknown failure");
388 (void)printf("Invalid failure code %u",
395 (void)printf("Unknown reason for rejecting rpc message %u",
396 (unsigned int)rstat
);
402 (void)printf("reply Unknown rpc response code=%u %u",
414 * Return a pointer to the first file handle in the packet.
415 * If the packet was truncated, return 0.
417 static const u_int32_t
*
418 parsereq(register const struct sunrpc_msg
*rp
, register u_int length
)
420 register const u_int32_t
*dp
;
424 * find the start of the req data (if we captured it)
426 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
428 len
= EXTRACT_32BITS(&dp
[1]);
430 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
432 len
= EXTRACT_32BITS(&dp
[1]);
434 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
444 * Print out an NFS file handle and return a pointer to following word.
445 * If packet was truncated, return 0.
447 static const u_int32_t
*
448 parsefh(register const u_int32_t
*dp
, int v3
)
454 len
= EXTRACT_32BITS(dp
) / 4;
459 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
460 nfs_printfh(dp
, len
);
468 * Print out a file name and return pointer to 32-bit word past it.
469 * If packet was truncated, return 0.
471 static const u_int32_t
*
472 parsefn(register const u_int32_t
*dp
)
474 register u_int32_t len
;
475 register const u_char
*cp
;
477 /* Bail if we don't have the string length */
480 /* Fetch string length; convert to host order */
484 TCHECK2(*dp
, ((len
+ 3) & ~3));
487 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
488 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
490 if (fn_printn(cp
, len
, snapend
)) {
502 * Print out file handle and file name.
503 * Return pointer to 32-bit word past file name.
504 * If packet was truncated (or there was some other error), return 0.
506 static const u_int32_t
*
507 parsefhn(register const u_int32_t
*dp
, int v3
)
509 dp
= parsefh(dp
, v3
);
513 return (parsefn(dp
));
517 nfsreq_print(register const u_char
*bp
, u_int length
,
518 register const u_char
*bp2
)
520 register const struct sunrpc_msg
*rp
;
521 char srcid
[20], dstid
[20]; /*fits 32bit*/
523 nfserr
= 0; /* assume no error */
524 rp
= (const struct sunrpc_msg
*)bp
;
528 snprintf(srcid
, sizeof(srcid
), "%u",
529 EXTRACT_32BITS(&rp
->rm_xid
));
530 strlcpy(dstid
, "nfs", sizeof(dstid
));
532 snprintf(srcid
, sizeof(srcid
), "%u",
533 EXTRACT_32BITS(&rp
->rm_xid
));
534 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
536 print_nfsaddr(bp2
, srcid
, dstid
);
538 nfsreq_print_noaddr(bp
, length
, bp2
);
547 nfsreq_print_noaddr(register const u_char
*bp
, u_int length
,
548 register const u_char
*bp2
)
550 register const struct sunrpc_msg
*rp
;
551 register const u_int32_t
*dp
;
555 u_int32_t access_flags
;
556 struct nfsv3_sattr sa3
;
558 (void)printf("%d", length
);
559 nfserr
= 0; /* assume no error */
560 rp
= (const struct sunrpc_msg
*)bp
;
562 if (!xid_map_enter(rp
, bp2
)) /* record proc number for later on */
565 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
566 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
568 if (!v3
&& proc
< NFS_NPROCS
)
569 proc
= nfsv3_procid
[proc
];
579 case NFSPROC_GETATTR
:
581 if ((dp
= parsereq(rp
, length
)) != NULL
&&
582 parsefh(dp
, v3
) != NULL
)
586 case NFSPROC_SETATTR
:
588 if ((dp
= parsereq(rp
, length
)) != NULL
&&
589 parsefh(dp
, v3
) != NULL
)
595 if ((dp
= parsereq(rp
, length
)) != NULL
&&
596 parsefhn(dp
, v3
) != NULL
)
602 if ((dp
= parsereq(rp
, length
)) != NULL
&&
603 (dp
= parsefh(dp
, v3
)) != NULL
) {
605 access_flags
= EXTRACT_32BITS(&dp
[0]);
606 if (access_flags
& ~NFSV3ACCESS_FULL
) {
607 /* NFSV3ACCESS definitions aren't up to date */
608 printf(" %04x", access_flags
);
609 } else if ((access_flags
& NFSV3ACCESS_FULL
) == NFSV3ACCESS_FULL
) {
610 printf(" NFS_ACCESS_FULL");
612 char separator
= ' ';
613 if (access_flags
& NFSV3ACCESS_READ
) {
614 printf(" NFS_ACCESS_READ");
617 if (access_flags
& NFSV3ACCESS_LOOKUP
) {
618 printf("%cNFS_ACCESS_LOOKUP", separator
);
621 if (access_flags
& NFSV3ACCESS_MODIFY
) {
622 printf("%cNFS_ACCESS_MODIFY", separator
);
625 if (access_flags
& NFSV3ACCESS_EXTEND
) {
626 printf("%cNFS_ACCESS_EXTEND", separator
);
629 if (access_flags
& NFSV3ACCESS_DELETE
) {
630 printf("%cNFS_ACCESS_DELETE", separator
);
633 if (access_flags
& NFSV3ACCESS_EXECUTE
)
634 printf("%cNFS_ACCESS_EXECUTE", separator
);
640 case NFSPROC_READLINK
:
642 if ((dp
= parsereq(rp
, length
)) != NULL
&&
643 parsefh(dp
, v3
) != NULL
)
649 if ((dp
= parsereq(rp
, length
)) != NULL
&&
650 (dp
= parsefh(dp
, v3
)) != NULL
) {
653 printf(" %u bytes @ %" PRIu64
,
654 EXTRACT_32BITS(&dp
[2]),
655 EXTRACT_64BITS(&dp
[0]));
658 printf(" %u bytes @ %u",
659 EXTRACT_32BITS(&dp
[1]),
660 EXTRACT_32BITS(&dp
[0]));
668 if ((dp
= parsereq(rp
, length
)) != NULL
&&
669 (dp
= parsefh(dp
, v3
)) != NULL
) {
672 printf(" %u (%u) bytes @ %" PRIu64
,
673 EXTRACT_32BITS(&dp
[4]),
674 EXTRACT_32BITS(&dp
[2]),
675 EXTRACT_64BITS(&dp
[0]));
680 tok2str(nfsv3_writemodes
,
681 NULL
, EXTRACT_32BITS(dp
)));
685 printf(" %u (%u) bytes @ %u (%u)",
686 EXTRACT_32BITS(&dp
[3]),
687 EXTRACT_32BITS(&dp
[2]),
688 EXTRACT_32BITS(&dp
[1]),
689 EXTRACT_32BITS(&dp
[0]));
697 if ((dp
= parsereq(rp
, length
)) != NULL
&&
698 parsefhn(dp
, v3
) != NULL
)
704 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
708 case NFSPROC_SYMLINK
:
710 if ((dp
= parsereq(rp
, length
)) != 0 &&
711 (dp
= parsefhn(dp
, v3
)) != 0) {
712 fputs(" ->", stdout
);
713 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
715 if (parsefn(dp
) == 0)
718 print_sattr3(&sa3
, vflag
);
725 if ((dp
= parsereq(rp
, length
)) != 0 &&
726 (dp
= parsefhn(dp
, v3
)) != 0) {
728 type
= (nfs_type
)EXTRACT_32BITS(dp
);
730 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
732 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
733 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
736 EXTRACT_32BITS(&dp
[0]),
737 EXTRACT_32BITS(&dp
[1]));
741 print_sattr3(&sa3
, vflag
);
748 if ((dp
= parsereq(rp
, length
)) != NULL
&&
749 parsefhn(dp
, v3
) != NULL
)
755 if ((dp
= parsereq(rp
, length
)) != NULL
&&
756 parsefhn(dp
, v3
) != NULL
)
762 if ((dp
= parsereq(rp
, length
)) != NULL
&&
763 (dp
= parsefhn(dp
, v3
)) != NULL
) {
764 fputs(" ->", stdout
);
765 if (parsefhn(dp
, v3
) != NULL
)
772 if ((dp
= parsereq(rp
, length
)) != NULL
&&
773 (dp
= parsefh(dp
, v3
)) != NULL
) {
774 fputs(" ->", stdout
);
775 if (parsefhn(dp
, v3
) != NULL
)
780 case NFSPROC_READDIR
:
782 if ((dp
= parsereq(rp
, length
)) != NULL
&&
783 (dp
= parsefh(dp
, v3
)) != NULL
) {
787 * We shouldn't really try to interpret the
788 * offset cookie here.
790 printf(" %u bytes @ %" PRId64
,
791 EXTRACT_32BITS(&dp
[4]),
792 EXTRACT_64BITS(&dp
[0]));
794 printf(" verf %08x%08x", dp
[2],
799 * Print the offset as signed, since -1 is
800 * common, but offsets > 2^31 aren't.
802 printf(" %u bytes @ %d",
803 EXTRACT_32BITS(&dp
[1]),
804 EXTRACT_32BITS(&dp
[0]));
810 case NFSPROC_READDIRPLUS
:
811 printf(" readdirplus");
812 if ((dp
= parsereq(rp
, length
)) != NULL
&&
813 (dp
= parsefh(dp
, v3
)) != NULL
) {
816 * We don't try to interpret the offset
819 printf(" %u bytes @ %" PRId64
,
820 EXTRACT_32BITS(&dp
[4]),
821 EXTRACT_64BITS(&dp
[0]));
824 printf(" max %u verf %08x%08x",
825 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
833 if ((dp
= parsereq(rp
, length
)) != NULL
&&
834 parsefh(dp
, v3
) != NULL
)
840 if ((dp
= parsereq(rp
, length
)) != NULL
&&
841 parsefh(dp
, v3
) != NULL
)
845 case NFSPROC_PATHCONF
:
847 if ((dp
= parsereq(rp
, length
)) != NULL
&&
848 parsefh(dp
, v3
) != NULL
)
854 if ((dp
= parsereq(rp
, length
)) != NULL
&&
855 (dp
= parsefh(dp
, v3
)) != NULL
) {
857 printf(" %u bytes @ %" PRIu64
,
858 EXTRACT_32BITS(&dp
[2]),
859 EXTRACT_64BITS(&dp
[0]));
865 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
875 * Print out an NFS file handle.
876 * We assume packet was not truncated before the end of the
877 * file handle pointed to by dp.
879 * Note: new version (using portable file-handle parser) doesn't produce
880 * generation number. It probably could be made to do that, with some
881 * additional hacking on the parser code.
884 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
888 const char *sfsname
= NULL
;
893 char const *sep
= "";
896 for (i
=0; i
<len
; i
++) {
897 (void)printf("%s%x", sep
, dp
[i
]);
904 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
907 /* file system ID is ASCII, not numeric, for this server OS */
908 static char temp
[NFSX_V3FHMAX
+1];
910 /* Make sure string is null-terminated */
911 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
912 temp
[sizeof(temp
) - 1] = '\0';
913 /* Remove trailing spaces */
914 spacep
= strchr(temp
, ' ');
918 (void)printf(" fh %s/", temp
);
920 (void)printf(" fh %d,%d/",
921 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
924 if(fsid
.Fsid_dev
.Minor
== 257)
925 /* Print the undecoded handle */
926 (void)printf("%s", fsid
.Opaque_Handle
);
928 (void)printf("%ld", (long) ino
);
932 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
933 * us to match up replies with requests and thus to know how to parse
937 struct xid_map_entry
{
938 u_int32_t xid
; /* transaction ID (net order) */
939 int ipver
; /* IP version (4 or 6) */
941 struct in6_addr client
; /* client IP address (net order) */
942 struct in6_addr server
; /* server IP address (net order) */
944 struct in_addr client
; /* client IP address (net order) */
945 struct in_addr server
; /* server IP address (net order) */
947 u_int32_t proc
; /* call proc number (host order) */
948 u_int32_t vers
; /* program version (host order) */
952 * Map entries are kept in an array that we manage as a ring;
953 * new entries are always added at the tail of the ring. Initially,
954 * all the entries are zero and hence don't match anything.
957 #define XIDMAPSIZE 64
959 struct xid_map_entry xid_map
[XIDMAPSIZE
];
961 int xid_map_next
= 0;
962 int xid_map_hint
= 0;
965 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
967 struct ip
*ip
= NULL
;
969 struct ip6_hdr
*ip6
= NULL
;
971 struct xid_map_entry
*xmep
;
973 if (!TTEST(rp
->rm_call
.cb_vers
))
975 switch (IP_V((struct ip
*)bp
)) {
977 ip
= (struct ip
*)bp
;
981 ip6
= (struct ip6_hdr
*)bp
;
988 xmep
= &xid_map
[xid_map_next
];
990 if (++xid_map_next
>= XIDMAPSIZE
)
993 xmep
->xid
= rp
->rm_xid
;
996 UNALIGNED_MEMCPY(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
997 UNALIGNED_MEMCPY(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
1002 UNALIGNED_MEMCPY(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
1003 UNALIGNED_MEMCPY(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
1006 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
1007 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
1012 * Returns 0 and puts NFSPROC_xxx in proc return and
1013 * version in vers return, or returns -1 on failure
1016 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
1020 struct xid_map_entry
*xmep
;
1021 u_int32_t xid
= rp
->rm_xid
;
1022 struct ip
*ip
= (struct ip
*)bp
;
1024 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
1028 /* Start searching from where we last left off */
1033 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
1035 switch (xmep
->ipver
) {
1037 if (UNALIGNED_MEMCMP(&ip
->ip_src
, &xmep
->server
,
1038 sizeof(ip
->ip_src
)) != 0 ||
1039 UNALIGNED_MEMCMP(&ip
->ip_dst
, &xmep
->client
,
1040 sizeof(ip
->ip_dst
)) != 0) {
1046 if (UNALIGNED_MEMCMP(&ip6
->ip6_src
, &xmep
->server
,
1047 sizeof(ip6
->ip6_src
)) != 0 ||
1048 UNALIGNED_MEMCMP(&ip6
->ip6_dst
, &xmep
->client
,
1049 sizeof(ip6
->ip6_dst
)) != 0) {
1066 if (++i
>= XIDMAPSIZE
)
1068 } while (i
!= xid_map_hint
);
1075 * Routines for parsing reply packets
1079 * Return a pointer to the beginning of the actual results.
1080 * If the packet was truncated, return 0.
1082 static const u_int32_t
*
1083 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
1085 register const u_int32_t
*dp
;
1087 enum sunrpc_accept_stat astat
;
1091 * Here we find the address of the ar_verf credentials.
1092 * Originally, this calculation was
1093 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
1094 * On the wire, the rp_acpt field starts immediately after
1095 * the (32 bit) rp_stat field. However, rp_acpt (which is a
1096 * "struct accepted_reply") contains a "struct opaque_auth",
1097 * whose internal representation contains a pointer, so on a
1098 * 64-bit machine the compiler inserts 32 bits of padding
1099 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
1100 * the internal representation to parse the on-the-wire
1101 * representation. Instead, we skip past the rp_stat field,
1102 * which is an "enum" and so occupies one 32-bit word.
1104 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
1106 len
= EXTRACT_32BITS(&dp
[1]);
1110 * skip past the ar_verf credentials.
1112 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
1116 * now we can check the ar_stat field
1118 astat
= (enum sunrpc_accept_stat
) EXTRACT_32BITS(dp
);
1121 case SUNRPC_SUCCESS
:
1124 case SUNRPC_PROG_UNAVAIL
:
1125 printf(" PROG_UNAVAIL");
1126 nfserr
= 1; /* suppress trunc string */
1129 case SUNRPC_PROG_MISMATCH
:
1130 printf(" PROG_MISMATCH");
1131 nfserr
= 1; /* suppress trunc string */
1134 case SUNRPC_PROC_UNAVAIL
:
1135 printf(" PROC_UNAVAIL");
1136 nfserr
= 1; /* suppress trunc string */
1139 case SUNRPC_GARBAGE_ARGS
:
1140 printf(" GARBAGE_ARGS");
1141 nfserr
= 1; /* suppress trunc string */
1144 case SUNRPC_SYSTEM_ERR
:
1145 printf(" SYSTEM_ERR");
1146 nfserr
= 1; /* suppress trunc string */
1150 printf(" ar_stat %d", astat
);
1151 nfserr
= 1; /* suppress trunc string */
1154 /* successful return */
1155 TCHECK2(*dp
, sizeof(astat
));
1156 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1161 static const u_int32_t
*
1162 parsestatus(const u_int32_t
*dp
, int *er
)
1168 errnum
= EXTRACT_32BITS(&dp
[0]);
1173 printf(" ERROR: %s",
1174 tok2str(status2str
, "unk %d", errnum
));
1182 static const u_int32_t
*
1183 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1185 const struct nfs_fattr
*fap
;
1187 fap
= (const struct nfs_fattr
*)dp
;
1188 TCHECK(fap
->fa_gid
);
1190 printf(" %s %o ids %d/%d",
1191 tok2str(type2str
, "unk-ft %d ",
1192 EXTRACT_32BITS(&fap
->fa_type
)),
1193 EXTRACT_32BITS(&fap
->fa_mode
),
1194 EXTRACT_32BITS(&fap
->fa_uid
),
1195 EXTRACT_32BITS(&fap
->fa_gid
));
1197 TCHECK(fap
->fa3_size
);
1198 printf(" sz %" PRIu64
,
1199 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1201 TCHECK(fap
->fa2_size
);
1202 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1205 /* print lots more stuff */
1208 TCHECK(fap
->fa3_ctime
);
1209 printf(" nlink %d rdev %d/%d",
1210 EXTRACT_32BITS(&fap
->fa_nlink
),
1211 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1212 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1213 printf(" fsid %" PRIx64
,
1214 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1215 printf(" fileid %" PRIx64
,
1216 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1217 printf(" a/m/ctime %u.%06u",
1218 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1219 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1221 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1222 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1224 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1225 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1227 TCHECK(fap
->fa2_ctime
);
1228 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1229 EXTRACT_32BITS(&fap
->fa_nlink
),
1230 EXTRACT_32BITS(&fap
->fa2_rdev
),
1231 EXTRACT_32BITS(&fap
->fa2_fsid
),
1232 EXTRACT_32BITS(&fap
->fa2_fileid
));
1234 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1235 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1237 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1238 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1240 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1241 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1244 return ((const u_int32_t
*)((unsigned char *)dp
+
1245 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1251 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1255 dp
= parsestatus(dp
, &er
);
1261 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1265 parsediropres(const u_int32_t
*dp
)
1269 if (!(dp
= parsestatus(dp
, &er
)))
1274 dp
= parsefh(dp
, 0);
1278 return (parsefattr(dp
, vflag
, 0) != NULL
);
1282 parselinkres(const u_int32_t
*dp
, int v3
)
1286 dp
= parsestatus(dp
, &er
);
1291 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1294 return (parsefn(dp
) != NULL
);
1298 parsestatfs(const u_int32_t
*dp
, int v3
)
1300 const struct nfs_statfs
*sfsp
;
1303 dp
= parsestatus(dp
, &er
);
1315 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1319 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1321 sfsp
= (const struct nfs_statfs
*)dp
;
1324 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1325 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1326 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1327 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1329 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1330 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1331 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1332 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1333 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1336 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1337 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1338 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1339 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1340 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1341 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1350 parserddires(const u_int32_t
*dp
)
1354 dp
= parsestatus(dp
, &er
);
1363 printf(" offset %x size %d ",
1364 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1373 static const u_int32_t
*
1374 parse_wcc_attr(const u_int32_t
*dp
)
1376 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1377 printf(" mtime %u.%06u ctime %u.%06u",
1378 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1379 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1384 * Pre operation attributes. Print only if vflag > 1.
1386 static const u_int32_t
*
1387 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1390 if (!EXTRACT_32BITS(&dp
[0]))
1395 return parse_wcc_attr(dp
);
1397 /* If not verbose enough, just skip over wcc_attr */
1405 * Post operation attributes are printed if vflag >= 1
1407 static const u_int32_t
*
1408 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1411 if (!EXTRACT_32BITS(&dp
[0]))
1415 return parsefattr(dp
, verbose
, 1);
1417 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1422 static const u_int32_t
*
1423 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1427 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1432 return parse_post_op_attr(dp
, verbose
);
1435 static const u_int32_t
*
1436 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1440 if (!(dp
= parsestatus(dp
, &er
)))
1443 dp
= parse_wcc_data(dp
, verbose
);
1446 if (!EXTRACT_32BITS(&dp
[0]))
1449 if (!(dp
= parsefh(dp
, 1)))
1452 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1455 printf(" dir attr:");
1456 dp
= parse_wcc_data(dp
, verbose
);
1466 parsewccres(const u_int32_t
*dp
, int verbose
)
1470 if (!(dp
= parsestatus(dp
, &er
)))
1472 return parse_wcc_data(dp
, verbose
) != 0;
1475 static const u_int32_t
*
1476 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1480 if (!(dp
= parsestatus(dp
, &er
)))
1484 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1490 printf(" verf %08x%08x", dp
[0], dp
[1]);
1499 parsefsinfo(const u_int32_t
*dp
)
1501 struct nfsv3_fsinfo
*sfp
;
1504 if (!(dp
= parsestatus(dp
, &er
)))
1508 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1513 sfp
= (struct nfsv3_fsinfo
*)dp
;
1515 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1516 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1517 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1518 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1519 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1520 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1522 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1523 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1524 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1525 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1526 printf(" delta %u.%06u ",
1527 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1528 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1536 parsepathconf(const u_int32_t
*dp
)
1539 struct nfsv3_pathconf
*spp
;
1541 if (!(dp
= parsestatus(dp
, &er
)))
1545 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1550 spp
= (struct nfsv3_pathconf
*)dp
;
1553 printf(" linkmax %u namemax %u %s %s %s %s",
1554 EXTRACT_32BITS(&spp
->pc_linkmax
),
1555 EXTRACT_32BITS(&spp
->pc_namemax
),
1556 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1557 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1558 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1559 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1566 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1568 register const u_int32_t
*dp
;
1572 v3
= (vers
== NFS_VER3
);
1574 if (!v3
&& proc
< NFS_NPROCS
)
1575 proc
= nfsv3_procid
[proc
];
1587 case NFSPROC_GETATTR
:
1589 dp
= parserep(rp
, length
);
1590 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1594 case NFSPROC_SETATTR
:
1596 if (!(dp
= parserep(rp
, length
)))
1599 if (parsewccres(dp
, vflag
))
1602 if (parseattrstat(dp
, !qflag
, 0) != 0)
1607 case NFSPROC_LOOKUP
:
1609 if (!(dp
= parserep(rp
, length
)))
1612 if (!(dp
= parsestatus(dp
, &er
)))
1616 printf(" post dattr:");
1617 dp
= parse_post_op_attr(dp
, vflag
);
1620 if (!(dp
= parsefh(dp
, v3
)))
1622 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1624 printf(" post dattr:");
1625 dp
= parse_post_op_attr(dp
, vflag
);
1631 if (parsediropres(dp
) != 0)
1636 case NFSPROC_ACCESS
:
1638 if (!(dp
= parserep(rp
, length
)))
1640 if (!(dp
= parsestatus(dp
, &er
)))
1644 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1647 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1650 case NFSPROC_READLINK
:
1651 printf(" readlink");
1652 dp
= parserep(rp
, length
);
1653 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1659 if (!(dp
= parserep(rp
, length
)))
1662 if (!(dp
= parsestatus(dp
, &er
)))
1664 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1670 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1671 if (EXTRACT_32BITS(&dp
[1]))
1676 if (parseattrstat(dp
, vflag
, 0) != 0)
1683 if (!(dp
= parserep(rp
, length
)))
1686 if (!(dp
= parsestatus(dp
, &er
)))
1688 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1694 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1698 tok2str(nfsv3_writemodes
,
1699 NULL
, EXTRACT_32BITS(&dp
[1])));
1704 if (parseattrstat(dp
, vflag
, v3
) != 0)
1709 case NFSPROC_CREATE
:
1711 if (!(dp
= parserep(rp
, length
)))
1714 if (parsecreateopres(dp
, vflag
) != 0)
1717 if (parsediropres(dp
) != 0)
1724 if (!(dp
= parserep(rp
, length
)))
1727 if (parsecreateopres(dp
, vflag
) != 0)
1730 if (parsediropres(dp
) != 0)
1735 case NFSPROC_SYMLINK
:
1737 if (!(dp
= parserep(rp
, length
)))
1740 if (parsecreateopres(dp
, vflag
) != 0)
1743 if (parsestatus(dp
, &er
) != 0)
1750 if (!(dp
= parserep(rp
, length
)))
1752 if (parsecreateopres(dp
, vflag
) != 0)
1756 case NFSPROC_REMOVE
:
1758 if (!(dp
= parserep(rp
, length
)))
1761 if (parsewccres(dp
, vflag
))
1764 if (parsestatus(dp
, &er
) != 0)
1771 if (!(dp
= parserep(rp
, length
)))
1774 if (parsewccres(dp
, vflag
))
1777 if (parsestatus(dp
, &er
) != 0)
1782 case NFSPROC_RENAME
:
1784 if (!(dp
= parserep(rp
, length
)))
1787 if (!(dp
= parsestatus(dp
, &er
)))
1791 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1794 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1799 if (parsestatus(dp
, &er
) != 0)
1806 if (!(dp
= parserep(rp
, length
)))
1809 if (!(dp
= parsestatus(dp
, &er
)))
1812 printf(" file POST:");
1813 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1816 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1821 if (parsestatus(dp
, &er
) != 0)
1826 case NFSPROC_READDIR
:
1828 if (!(dp
= parserep(rp
, length
)))
1831 if (parsev3rddirres(dp
, vflag
))
1834 if (parserddires(dp
) != 0)
1839 case NFSPROC_READDIRPLUS
:
1840 printf(" readdirplus");
1841 if (!(dp
= parserep(rp
, length
)))
1843 if (parsev3rddirres(dp
, vflag
))
1847 case NFSPROC_FSSTAT
:
1849 dp
= parserep(rp
, length
);
1850 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1854 case NFSPROC_FSINFO
:
1856 dp
= parserep(rp
, length
);
1857 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1861 case NFSPROC_PATHCONF
:
1862 printf(" pathconf");
1863 dp
= parserep(rp
, length
);
1864 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1868 case NFSPROC_COMMIT
:
1870 dp
= parserep(rp
, length
);
1871 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1876 printf(" proc-%u", proc
);