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 void nfs_printfh(const u_int32_t
*, const u_int
);
52 static int xid_map_enter(const struct sunrpc_msg
*, const u_char
*);
53 static int32_t xid_map_find(const struct sunrpc_msg
*, const u_char
*,
54 u_int32_t
*, u_int32_t
*);
55 static void interp_reply(const struct sunrpc_msg
*, u_int32_t
, u_int32_t
, int);
56 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
57 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
58 static void print_nfsaddr(const u_char
*, const char *, const char *);
61 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
63 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
93 * NFS V2 and V3 status values.
95 * Some of these come from the RFCs for NFS V2 and V3, with the message
96 * strings taken from the FreeBSD C library "errlst.c".
98 * Others are errors that are not in the RFC but that I suspect some
99 * NFS servers could return; the values are FreeBSD errno values, as
100 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
101 * was primarily BSD-derived.
103 static struct tok status2str
[] = {
104 { 1, "Operation not permitted" }, /* EPERM */
105 { 2, "No such file or directory" }, /* ENOENT */
106 { 5, "Input/output error" }, /* EIO */
107 { 6, "Device not configured" }, /* ENXIO */
108 { 11, "Resource deadlock avoided" }, /* EDEADLK */
109 { 12, "Cannot allocate memory" }, /* ENOMEM */
110 { 13, "Permission denied" }, /* EACCES */
111 { 17, "File exists" }, /* EEXIST */
112 { 18, "Cross-device link" }, /* EXDEV */
113 { 19, "Operation not supported by device" }, /* ENODEV */
114 { 20, "Not a directory" }, /* ENOTDIR */
115 { 21, "Is a directory" }, /* EISDIR */
116 { 22, "Invalid argument" }, /* EINVAL */
117 { 26, "Text file busy" }, /* ETXTBSY */
118 { 27, "File too large" }, /* EFBIG */
119 { 28, "No space left on device" }, /* ENOSPC */
120 { 30, "Read-only file system" }, /* EROFS */
121 { 31, "Too many links" }, /* EMLINK */
122 { 45, "Operation not supported" }, /* EOPNOTSUPP */
123 { 62, "Too many levels of symbolic links" }, /* ELOOP */
124 { 63, "File name too long" }, /* ENAMETOOLONG */
125 { 66, "Directory not empty" }, /* ENOTEMPTY */
126 { 69, "Disc quota exceeded" }, /* EDQUOT */
127 { 70, "Stale NFS file handle" }, /* ESTALE */
128 { 71, "Too many levels of remote in path" }, /* EREMOTE */
129 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
130 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
131 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
132 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
133 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
134 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
135 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
136 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
137 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
141 static struct tok nfsv3_writemodes
[] = {
148 static struct tok type2str
[] = {
160 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
165 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
167 #ifndef INET_ADDRSTRLEN
168 #define INET_ADDRSTRLEN 16
170 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
173 srcaddr
[0] = dstaddr
[0] = '\0';
174 switch (IP_V((struct ip
*)bp
)) {
176 ip
= (struct ip
*)bp
;
177 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
178 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
182 ip6
= (struct ip6_hdr
*)bp
;
183 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
185 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
190 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
191 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
195 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
198 static const u_int32_t
*
199 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
202 sa3
->sa_modeset
= EXTRACT_32BITS(dp
);
204 if (sa3
->sa_modeset
) {
206 sa3
->sa_mode
= EXTRACT_32BITS(dp
);
211 sa3
->sa_uidset
= EXTRACT_32BITS(dp
);
213 if (sa3
->sa_uidset
) {
215 sa3
->sa_uid
= EXTRACT_32BITS(dp
);
220 sa3
->sa_gidset
= EXTRACT_32BITS(dp
);
222 if (sa3
->sa_gidset
) {
224 sa3
->sa_gid
= EXTRACT_32BITS(dp
);
229 sa3
->sa_sizeset
= EXTRACT_32BITS(dp
);
231 if (sa3
->sa_sizeset
) {
233 sa3
->sa_size
= EXTRACT_32BITS(dp
);
238 sa3
->sa_atimetype
= EXTRACT_32BITS(dp
);
240 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
) {
242 sa3
->sa_atime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
244 sa3
->sa_atime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
249 sa3
->sa_mtimetype
= EXTRACT_32BITS(dp
);
251 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
) {
253 sa3
->sa_mtime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
255 sa3
->sa_mtime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
264 static int nfserr
; /* true if we error rather than trunc */
267 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
270 printf(" mode %o", sa3
->sa_mode
);
272 printf(" uid %u", sa3
->sa_uid
);
274 printf(" gid %u", sa3
->sa_gid
);
276 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
277 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
278 sa3
->sa_atime
.nfsv3_nsec
);
279 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
280 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
281 sa3
->sa_mtime
.nfsv3_nsec
);
286 nfsreply_print(register const u_char
*bp
, u_int length
,
287 register const u_char
*bp2
)
289 register const struct sunrpc_msg
*rp
;
290 u_int32_t proc
, vers
, reply_stat
;
291 char srcid
[20], dstid
[20]; /*fits 32bit*/
292 enum sunrpc_reject_stat rstat
;
295 enum sunrpc_auth_stat rwhy
;
297 nfserr
= 0; /* assume no error */
298 rp
= (const struct sunrpc_msg
*)bp
;
302 strlcpy(srcid
, "nfs", sizeof(srcid
));
303 snprintf(dstid
, sizeof(dstid
), "%u",
304 EXTRACT_32BITS(&rp
->rm_xid
));
306 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
307 snprintf(dstid
, sizeof(dstid
), "%u",
308 EXTRACT_32BITS(&rp
->rm_xid
));
310 print_nfsaddr(bp2
, srcid
, dstid
);
311 TCHECK(rp
->rm_reply
.rp_stat
);
312 reply_stat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
);
313 switch (reply_stat
) {
315 case SUNRPC_MSG_ACCEPTED
:
316 (void)printf("reply ok %u", length
);
317 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
318 interp_reply(rp
, proc
, vers
, length
);
321 case SUNRPC_MSG_DENIED
:
322 (void)printf("reply ERR %u: ", length
);
323 TCHECK(rp
->rm_reply
.rp_reject
.rj_stat
);
324 rstat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_stat
);
327 case SUNRPC_RPC_MISMATCH
:
328 TCHECK(rp
->rm_reply
.rp_reject
.rj_vers
.high
);
329 rlow
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.low
);
330 rhigh
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.high
);
331 (void)printf("RPC Version mismatch (%u-%u)",
335 case SUNRPC_AUTH_ERROR
:
336 TCHECK(rp
->rm_reply
.rp_reject
.rj_why
);
337 rwhy
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_why
);
338 (void)printf("Auth ");
345 case SUNRPC_AUTH_BADCRED
:
346 (void)printf("Bogus Credentials (seal broken)");
349 case SUNRPC_AUTH_REJECTEDCRED
:
350 (void)printf("Rejected Credentials (client should begin new session)");
353 case SUNRPC_AUTH_BADVERF
:
354 (void)printf("Bogus Verifier (seal broken)");
357 case SUNRPC_AUTH_REJECTEDVERF
:
358 (void)printf("Verifier expired or was replayed");
361 case SUNRPC_AUTH_TOOWEAK
:
362 (void)printf("Credentials are too weak");
365 case SUNRPC_AUTH_INVALIDRESP
:
366 (void)printf("Bogus response verifier");
369 case SUNRPC_AUTH_FAILED
:
370 (void)printf("Unknown failure");
374 (void)printf("Invalid failure code %u",
381 (void)printf("Unknown reason for rejecting rpc message %u",
382 (unsigned int)rstat
);
388 (void)printf("reply Unknown rpc response code=%u %u",
396 fputs(" [|nfs]", stdout
);
400 * Return a pointer to the first file handle in the packet.
401 * If the packet was truncated, return 0.
403 static const u_int32_t
*
404 parsereq(register const struct sunrpc_msg
*rp
, register u_int length
)
406 register const u_int32_t
*dp
;
410 * find the start of the req data (if we captured it)
412 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
414 len
= EXTRACT_32BITS(&dp
[1]);
416 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
418 len
= EXTRACT_32BITS(&dp
[1]);
420 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
430 * Print out an NFS file handle and return a pointer to following word.
431 * If packet was truncated, return 0.
433 static const u_int32_t
*
434 parsefh(register const u_int32_t
*dp
, int v3
)
440 len
= EXTRACT_32BITS(dp
) / 4;
445 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
446 nfs_printfh(dp
, len
);
454 * Print out a file name and return pointer to 32-bit word past it.
455 * If packet was truncated, return 0.
457 static const u_int32_t
*
458 parsefn(register const u_int32_t
*dp
)
460 register u_int32_t len
;
461 register const u_char
*cp
;
463 /* Bail if we don't have the string length */
466 /* Fetch string length; convert to host order */
470 TCHECK2(*dp
, ((len
+ 3) & ~3));
473 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
474 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
476 if (fn_printn(cp
, len
, snapend
)) {
488 * Print out file handle and file name.
489 * Return pointer to 32-bit word past file name.
490 * If packet was truncated (or there was some other error), return 0.
492 static const u_int32_t
*
493 parsefhn(register const u_int32_t
*dp
, int v3
)
495 dp
= parsefh(dp
, v3
);
499 return (parsefn(dp
));
503 nfsreq_print(register const u_char
*bp
, u_int length
,
504 register const u_char
*bp2
)
506 register const struct sunrpc_msg
*rp
;
507 register const u_int32_t
*dp
;
511 u_int32_t access_flags
;
512 struct nfsv3_sattr sa3
;
513 char srcid
[20], dstid
[20]; /*fits 32bit*/
515 nfserr
= 0; /* assume no error */
516 rp
= (const struct sunrpc_msg
*)bp
;
520 snprintf(srcid
, sizeof(srcid
), "%u",
521 EXTRACT_32BITS(&rp
->rm_xid
));
522 strlcpy(dstid
, "nfs", sizeof(dstid
));
524 snprintf(srcid
, sizeof(srcid
), "%u",
525 EXTRACT_32BITS(&rp
->rm_xid
));
526 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
528 print_nfsaddr(bp2
, srcid
, dstid
);
529 (void)printf("%d", length
);
531 if (!xid_map_enter(rp
, bp2
)) /* record proc number for later on */
534 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
535 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
537 if (!v3
&& proc
< NFS_NPROCS
)
538 proc
= nfsv3_procid
[proc
];
548 case NFSPROC_GETATTR
:
550 if ((dp
= parsereq(rp
, length
)) != NULL
&&
551 parsefh(dp
, v3
) != NULL
)
555 case NFSPROC_SETATTR
:
557 if ((dp
= parsereq(rp
, length
)) != NULL
&&
558 parsefh(dp
, v3
) != NULL
)
564 if ((dp
= parsereq(rp
, length
)) != NULL
&&
565 parsefhn(dp
, v3
) != NULL
)
571 if ((dp
= parsereq(rp
, length
)) != NULL
&&
572 (dp
= parsefh(dp
, v3
)) != NULL
) {
574 access_flags
= EXTRACT_32BITS(&dp
[0]);
575 if (access_flags
& ~NFSV3ACCESS_FULL
) {
576 /* NFSV3ACCESS definitions aren't up to date */
577 printf(" %04x", access_flags
);
578 } else if ((access_flags
& NFSV3ACCESS_FULL
) == NFSV3ACCESS_FULL
) {
579 printf(" NFS_ACCESS_FULL");
581 char separator
= ' ';
582 if (access_flags
& NFSV3ACCESS_READ
) {
583 printf(" NFS_ACCESS_READ");
586 if (access_flags
& NFSV3ACCESS_LOOKUP
) {
587 printf("%cNFS_ACCESS_LOOKUP", separator
);
590 if (access_flags
& NFSV3ACCESS_MODIFY
) {
591 printf("%cNFS_ACCESS_MODIFY", separator
);
594 if (access_flags
& NFSV3ACCESS_EXTEND
) {
595 printf("%cNFS_ACCESS_EXTEND", separator
);
598 if (access_flags
& NFSV3ACCESS_DELETE
) {
599 printf("%cNFS_ACCESS_DELETE", separator
);
602 if (access_flags
& NFSV3ACCESS_EXECUTE
)
603 printf("%cNFS_ACCESS_EXECUTE", separator
);
609 case NFSPROC_READLINK
:
611 if ((dp
= parsereq(rp
, length
)) != NULL
&&
612 parsefh(dp
, v3
) != NULL
)
618 if ((dp
= parsereq(rp
, length
)) != NULL
&&
619 (dp
= parsefh(dp
, v3
)) != NULL
) {
622 printf(" %u bytes @ %" PRIu64
,
623 EXTRACT_32BITS(&dp
[2]),
624 EXTRACT_64BITS(&dp
[0]));
627 printf(" %u bytes @ %u",
628 EXTRACT_32BITS(&dp
[1]),
629 EXTRACT_32BITS(&dp
[0]));
637 if ((dp
= parsereq(rp
, length
)) != NULL
&&
638 (dp
= parsefh(dp
, v3
)) != NULL
) {
641 printf(" %u (%u) bytes @ %" PRIu64
,
642 EXTRACT_32BITS(&dp
[4]),
643 EXTRACT_32BITS(&dp
[2]),
644 EXTRACT_64BITS(&dp
[0]));
649 tok2str(nfsv3_writemodes
,
650 NULL
, EXTRACT_32BITS(dp
)));
654 printf(" %u (%u) bytes @ %u (%u)",
655 EXTRACT_32BITS(&dp
[3]),
656 EXTRACT_32BITS(&dp
[2]),
657 EXTRACT_32BITS(&dp
[1]),
658 EXTRACT_32BITS(&dp
[0]));
666 if ((dp
= parsereq(rp
, length
)) != NULL
&&
667 parsefhn(dp
, v3
) != NULL
)
673 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
677 case NFSPROC_SYMLINK
:
679 if ((dp
= parsereq(rp
, length
)) != 0 &&
680 (dp
= parsefhn(dp
, v3
)) != 0) {
681 fputs(" ->", stdout
);
682 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
684 if (parsefn(dp
) == 0)
687 print_sattr3(&sa3
, vflag
);
694 if ((dp
= parsereq(rp
, length
)) != 0 &&
695 (dp
= parsefhn(dp
, v3
)) != 0) {
697 type
= (nfs_type
)EXTRACT_32BITS(dp
);
699 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
701 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
702 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
705 EXTRACT_32BITS(&dp
[0]),
706 EXTRACT_32BITS(&dp
[1]));
710 print_sattr3(&sa3
, vflag
);
717 if ((dp
= parsereq(rp
, length
)) != NULL
&&
718 parsefhn(dp
, v3
) != NULL
)
724 if ((dp
= parsereq(rp
, length
)) != NULL
&&
725 parsefhn(dp
, v3
) != NULL
)
731 if ((dp
= parsereq(rp
, length
)) != NULL
&&
732 (dp
= parsefhn(dp
, v3
)) != NULL
) {
733 fputs(" ->", stdout
);
734 if (parsefhn(dp
, v3
) != NULL
)
741 if ((dp
= parsereq(rp
, length
)) != NULL
&&
742 (dp
= parsefh(dp
, v3
)) != NULL
) {
743 fputs(" ->", stdout
);
744 if (parsefhn(dp
, v3
) != NULL
)
749 case NFSPROC_READDIR
:
751 if ((dp
= parsereq(rp
, length
)) != NULL
&&
752 (dp
= parsefh(dp
, v3
)) != NULL
) {
756 * We shouldn't really try to interpret the
757 * offset cookie here.
759 printf(" %u bytes @ %" PRId64
,
760 EXTRACT_32BITS(&dp
[4]),
761 EXTRACT_64BITS(&dp
[0]));
763 printf(" verf %08x%08x", dp
[2],
768 * Print the offset as signed, since -1 is
769 * common, but offsets > 2^31 aren't.
771 printf(" %u bytes @ %d",
772 EXTRACT_32BITS(&dp
[1]),
773 EXTRACT_32BITS(&dp
[0]));
779 case NFSPROC_READDIRPLUS
:
780 printf(" readdirplus");
781 if ((dp
= parsereq(rp
, length
)) != NULL
&&
782 (dp
= parsefh(dp
, v3
)) != NULL
) {
785 * We don't try to interpret the offset
788 printf(" %u bytes @ %" PRId64
,
789 EXTRACT_32BITS(&dp
[4]),
790 EXTRACT_64BITS(&dp
[0]));
793 printf(" max %u verf %08x%08x",
794 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
802 if ((dp
= parsereq(rp
, length
)) != NULL
&&
803 parsefh(dp
, v3
) != NULL
)
809 if ((dp
= parsereq(rp
, length
)) != NULL
&&
810 parsefh(dp
, v3
) != NULL
)
814 case NFSPROC_PATHCONF
:
816 if ((dp
= parsereq(rp
, length
)) != NULL
&&
817 parsefh(dp
, v3
) != NULL
)
823 if ((dp
= parsereq(rp
, length
)) != NULL
&&
824 (dp
= parsefh(dp
, v3
)) != NULL
) {
826 printf(" %u bytes @ %" PRIu64
,
827 EXTRACT_32BITS(&dp
[2]),
828 EXTRACT_64BITS(&dp
[0]));
834 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
840 fputs(" [|nfs]", stdout
);
844 * Print out an NFS file handle.
845 * We assume packet was not truncated before the end of the
846 * file handle pointed to by dp.
848 * Note: new version (using portable file-handle parser) doesn't produce
849 * generation number. It probably could be made to do that, with some
850 * additional hacking on the parser code.
853 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
857 const char *sfsname
= NULL
;
862 char const *sep
= "";
865 for (i
=0; i
<len
; i
++) {
866 (void)printf("%s%x", sep
, dp
[i
]);
873 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
876 /* file system ID is ASCII, not numeric, for this server OS */
877 static char temp
[NFSX_V3FHMAX
+1];
879 /* Make sure string is null-terminated */
880 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
881 temp
[sizeof(temp
) - 1] = '\0';
882 /* Remove trailing spaces */
883 spacep
= strchr(temp
, ' ');
887 (void)printf(" fh %s/", temp
);
889 (void)printf(" fh %d,%d/",
890 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
893 if(fsid
.Fsid_dev
.Minor
== 257)
894 /* Print the undecoded handle */
895 (void)printf("%s", fsid
.Opaque_Handle
);
897 (void)printf("%ld", (long) ino
);
901 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
902 * us to match up replies with requests and thus to know how to parse
906 struct xid_map_entry
{
907 u_int32_t xid
; /* transaction ID (net order) */
908 int ipver
; /* IP version (4 or 6) */
910 struct in6_addr client
; /* client IP address (net order) */
911 struct in6_addr server
; /* server IP address (net order) */
913 struct in_addr client
; /* client IP address (net order) */
914 struct in_addr server
; /* server IP address (net order) */
916 u_int32_t proc
; /* call proc number (host order) */
917 u_int32_t vers
; /* program version (host order) */
921 * Map entries are kept in an array that we manage as a ring;
922 * new entries are always added at the tail of the ring. Initially,
923 * all the entries are zero and hence don't match anything.
926 #define XIDMAPSIZE 64
928 struct xid_map_entry xid_map
[XIDMAPSIZE
];
930 int xid_map_next
= 0;
931 int xid_map_hint
= 0;
934 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
936 struct ip
*ip
= NULL
;
938 struct ip6_hdr
*ip6
= NULL
;
940 struct xid_map_entry
*xmep
;
942 if (!TTEST(rp
->rm_call
.cb_vers
))
944 switch (IP_V((struct ip
*)bp
)) {
946 ip
= (struct ip
*)bp
;
950 ip6
= (struct ip6_hdr
*)bp
;
957 xmep
= &xid_map
[xid_map_next
];
959 if (++xid_map_next
>= XIDMAPSIZE
)
962 xmep
->xid
= rp
->rm_xid
;
965 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
966 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
971 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
972 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
975 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
976 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
981 * Returns 0 and puts NFSPROC_xxx in proc return and
982 * version in vers return, or returns -1 on failure
985 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
989 struct xid_map_entry
*xmep
;
990 u_int32_t xid
= rp
->rm_xid
;
991 struct ip
*ip
= (struct ip
*)bp
;
993 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
997 /* Start searching from where we last left off */
1002 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
1004 switch (xmep
->ipver
) {
1006 if (memcmp(&ip
->ip_src
, &xmep
->server
,
1007 sizeof(ip
->ip_src
)) != 0 ||
1008 memcmp(&ip
->ip_dst
, &xmep
->client
,
1009 sizeof(ip
->ip_dst
)) != 0) {
1015 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
1016 sizeof(ip6
->ip6_src
)) != 0 ||
1017 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
1018 sizeof(ip6
->ip6_dst
)) != 0) {
1035 if (++i
>= XIDMAPSIZE
)
1037 } while (i
!= xid_map_hint
);
1044 * Routines for parsing reply packets
1048 * Return a pointer to the beginning of the actual results.
1049 * If the packet was truncated, return 0.
1051 static const u_int32_t
*
1052 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
1054 register const u_int32_t
*dp
;
1056 enum sunrpc_accept_stat astat
;
1060 * Here we find the address of the ar_verf credentials.
1061 * Originally, this calculation was
1062 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
1063 * On the wire, the rp_acpt field starts immediately after
1064 * the (32 bit) rp_stat field. However, rp_acpt (which is a
1065 * "struct accepted_reply") contains a "struct opaque_auth",
1066 * whose internal representation contains a pointer, so on a
1067 * 64-bit machine the compiler inserts 32 bits of padding
1068 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
1069 * the internal representation to parse the on-the-wire
1070 * representation. Instead, we skip past the rp_stat field,
1071 * which is an "enum" and so occupies one 32-bit word.
1073 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
1075 len
= EXTRACT_32BITS(&dp
[1]);
1079 * skip past the ar_verf credentials.
1081 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
1085 * now we can check the ar_stat field
1087 astat
= (enum sunrpc_accept_stat
) EXTRACT_32BITS(dp
);
1090 case SUNRPC_SUCCESS
:
1093 case SUNRPC_PROG_UNAVAIL
:
1094 printf(" PROG_UNAVAIL");
1095 nfserr
= 1; /* suppress trunc string */
1098 case SUNRPC_PROG_MISMATCH
:
1099 printf(" PROG_MISMATCH");
1100 nfserr
= 1; /* suppress trunc string */
1103 case SUNRPC_PROC_UNAVAIL
:
1104 printf(" PROC_UNAVAIL");
1105 nfserr
= 1; /* suppress trunc string */
1108 case SUNRPC_GARBAGE_ARGS
:
1109 printf(" GARBAGE_ARGS");
1110 nfserr
= 1; /* suppress trunc string */
1113 case SUNRPC_SYSTEM_ERR
:
1114 printf(" SYSTEM_ERR");
1115 nfserr
= 1; /* suppress trunc string */
1119 printf(" ar_stat %d", astat
);
1120 nfserr
= 1; /* suppress trunc string */
1123 /* successful return */
1124 TCHECK2(*dp
, sizeof(astat
));
1125 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1130 static const u_int32_t
*
1131 parsestatus(const u_int32_t
*dp
, int *er
)
1137 errnum
= EXTRACT_32BITS(&dp
[0]);
1142 printf(" ERROR: %s",
1143 tok2str(status2str
, "unk %d", errnum
));
1151 static const u_int32_t
*
1152 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1154 const struct nfs_fattr
*fap
;
1156 fap
= (const struct nfs_fattr
*)dp
;
1157 TCHECK(fap
->fa_gid
);
1159 printf(" %s %o ids %d/%d",
1160 tok2str(type2str
, "unk-ft %d ",
1161 EXTRACT_32BITS(&fap
->fa_type
)),
1162 EXTRACT_32BITS(&fap
->fa_mode
),
1163 EXTRACT_32BITS(&fap
->fa_uid
),
1164 EXTRACT_32BITS(&fap
->fa_gid
));
1166 TCHECK(fap
->fa3_size
);
1167 printf(" sz %" PRIu64
,
1168 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1170 TCHECK(fap
->fa2_size
);
1171 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1174 /* print lots more stuff */
1177 TCHECK(fap
->fa3_ctime
);
1178 printf(" nlink %d rdev %d/%d",
1179 EXTRACT_32BITS(&fap
->fa_nlink
),
1180 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1181 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1182 printf(" fsid %" PRIx64
,
1183 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1184 printf(" fileid %" PRIx64
,
1185 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1186 printf(" a/m/ctime %u.%06u",
1187 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1188 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1190 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1191 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1193 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1194 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1196 TCHECK(fap
->fa2_ctime
);
1197 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1198 EXTRACT_32BITS(&fap
->fa_nlink
),
1199 EXTRACT_32BITS(&fap
->fa2_rdev
),
1200 EXTRACT_32BITS(&fap
->fa2_fsid
),
1201 EXTRACT_32BITS(&fap
->fa2_fileid
));
1203 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1204 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1206 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1207 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1209 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1210 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1213 return ((const u_int32_t
*)((unsigned char *)dp
+
1214 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1220 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1224 dp
= parsestatus(dp
, &er
);
1230 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1234 parsediropres(const u_int32_t
*dp
)
1238 if (!(dp
= parsestatus(dp
, &er
)))
1243 dp
= parsefh(dp
, 0);
1247 return (parsefattr(dp
, vflag
, 0) != NULL
);
1251 parselinkres(const u_int32_t
*dp
, int v3
)
1255 dp
= parsestatus(dp
, &er
);
1260 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1263 return (parsefn(dp
) != NULL
);
1267 parsestatfs(const u_int32_t
*dp
, int v3
)
1269 const struct nfs_statfs
*sfsp
;
1272 dp
= parsestatus(dp
, &er
);
1284 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1288 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1290 sfsp
= (const struct nfs_statfs
*)dp
;
1293 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1294 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1295 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1296 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1298 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1299 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1300 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1301 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1302 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1305 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1306 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1307 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1308 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1309 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1310 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1319 parserddires(const u_int32_t
*dp
)
1323 dp
= parsestatus(dp
, &er
);
1332 printf(" offset %x size %d ",
1333 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1342 static const u_int32_t
*
1343 parse_wcc_attr(const u_int32_t
*dp
)
1345 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1346 printf(" mtime %u.%06u ctime %u.%06u",
1347 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1348 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1353 * Pre operation attributes. Print only if vflag > 1.
1355 static const u_int32_t
*
1356 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1359 if (!EXTRACT_32BITS(&dp
[0]))
1364 return parse_wcc_attr(dp
);
1366 /* If not verbose enough, just skip over wcc_attr */
1374 * Post operation attributes are printed if vflag >= 1
1376 static const u_int32_t
*
1377 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1380 if (!EXTRACT_32BITS(&dp
[0]))
1384 return parsefattr(dp
, verbose
, 1);
1386 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1391 static const u_int32_t
*
1392 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1396 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1401 return parse_post_op_attr(dp
, verbose
);
1404 static const u_int32_t
*
1405 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1409 if (!(dp
= parsestatus(dp
, &er
)))
1412 dp
= parse_wcc_data(dp
, verbose
);
1415 if (!EXTRACT_32BITS(&dp
[0]))
1418 if (!(dp
= parsefh(dp
, 1)))
1421 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1424 printf(" dir attr:");
1425 dp
= parse_wcc_data(dp
, verbose
);
1435 parsewccres(const u_int32_t
*dp
, int verbose
)
1439 if (!(dp
= parsestatus(dp
, &er
)))
1441 return parse_wcc_data(dp
, verbose
) != 0;
1444 static const u_int32_t
*
1445 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1449 if (!(dp
= parsestatus(dp
, &er
)))
1453 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1459 printf(" verf %08x%08x", dp
[0], dp
[1]);
1468 parsefsinfo(const u_int32_t
*dp
)
1470 struct nfsv3_fsinfo
*sfp
;
1473 if (!(dp
= parsestatus(dp
, &er
)))
1477 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1482 sfp
= (struct nfsv3_fsinfo
*)dp
;
1484 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1485 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1486 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1487 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1488 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1489 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1491 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1492 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1493 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1494 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1495 printf(" delta %u.%06u ",
1496 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1497 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1505 parsepathconf(const u_int32_t
*dp
)
1508 struct nfsv3_pathconf
*spp
;
1510 if (!(dp
= parsestatus(dp
, &er
)))
1514 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1519 spp
= (struct nfsv3_pathconf
*)dp
;
1522 printf(" linkmax %u namemax %u %s %s %s %s",
1523 EXTRACT_32BITS(&spp
->pc_linkmax
),
1524 EXTRACT_32BITS(&spp
->pc_namemax
),
1525 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1526 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1527 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1528 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1535 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1537 register const u_int32_t
*dp
;
1541 v3
= (vers
== NFS_VER3
);
1543 if (!v3
&& proc
< NFS_NPROCS
)
1544 proc
= nfsv3_procid
[proc
];
1556 case NFSPROC_GETATTR
:
1558 dp
= parserep(rp
, length
);
1559 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1563 case NFSPROC_SETATTR
:
1565 if (!(dp
= parserep(rp
, length
)))
1568 if (parsewccres(dp
, vflag
))
1571 if (parseattrstat(dp
, !qflag
, 0) != 0)
1576 case NFSPROC_LOOKUP
:
1578 if (!(dp
= parserep(rp
, length
)))
1581 if (!(dp
= parsestatus(dp
, &er
)))
1585 printf(" post dattr:");
1586 dp
= parse_post_op_attr(dp
, vflag
);
1589 if (!(dp
= parsefh(dp
, v3
)))
1591 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1593 printf(" post dattr:");
1594 dp
= parse_post_op_attr(dp
, vflag
);
1600 if (parsediropres(dp
) != 0)
1605 case NFSPROC_ACCESS
:
1607 if (!(dp
= parserep(rp
, length
)))
1609 if (!(dp
= parsestatus(dp
, &er
)))
1613 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1616 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1619 case NFSPROC_READLINK
:
1620 printf(" readlink");
1621 dp
= parserep(rp
, length
);
1622 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1628 if (!(dp
= parserep(rp
, length
)))
1631 if (!(dp
= parsestatus(dp
, &er
)))
1633 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1639 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1640 if (EXTRACT_32BITS(&dp
[1]))
1645 if (parseattrstat(dp
, vflag
, 0) != 0)
1652 if (!(dp
= parserep(rp
, length
)))
1655 if (!(dp
= parsestatus(dp
, &er
)))
1657 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1663 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1667 tok2str(nfsv3_writemodes
,
1668 NULL
, EXTRACT_32BITS(&dp
[1])));
1673 if (parseattrstat(dp
, vflag
, v3
) != 0)
1678 case NFSPROC_CREATE
:
1680 if (!(dp
= parserep(rp
, length
)))
1683 if (parsecreateopres(dp
, vflag
) != 0)
1686 if (parsediropres(dp
) != 0)
1693 if (!(dp
= parserep(rp
, length
)))
1696 if (parsecreateopres(dp
, vflag
) != 0)
1699 if (parsediropres(dp
) != 0)
1704 case NFSPROC_SYMLINK
:
1706 if (!(dp
= parserep(rp
, length
)))
1709 if (parsecreateopres(dp
, vflag
) != 0)
1712 if (parsestatus(dp
, &er
) != 0)
1719 if (!(dp
= parserep(rp
, length
)))
1721 if (parsecreateopres(dp
, vflag
) != 0)
1725 case NFSPROC_REMOVE
:
1727 if (!(dp
= parserep(rp
, length
)))
1730 if (parsewccres(dp
, vflag
))
1733 if (parsestatus(dp
, &er
) != 0)
1740 if (!(dp
= parserep(rp
, length
)))
1743 if (parsewccres(dp
, vflag
))
1746 if (parsestatus(dp
, &er
) != 0)
1751 case NFSPROC_RENAME
:
1753 if (!(dp
= parserep(rp
, length
)))
1756 if (!(dp
= parsestatus(dp
, &er
)))
1760 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1763 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1768 if (parsestatus(dp
, &er
) != 0)
1775 if (!(dp
= parserep(rp
, length
)))
1778 if (!(dp
= parsestatus(dp
, &er
)))
1781 printf(" file POST:");
1782 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1785 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1790 if (parsestatus(dp
, &er
) != 0)
1795 case NFSPROC_READDIR
:
1797 if (!(dp
= parserep(rp
, length
)))
1800 if (parsev3rddirres(dp
, vflag
))
1803 if (parserddires(dp
) != 0)
1808 case NFSPROC_READDIRPLUS
:
1809 printf(" readdirplus");
1810 if (!(dp
= parserep(rp
, length
)))
1812 if (parsev3rddirres(dp
, vflag
))
1816 case NFSPROC_FSSTAT
:
1818 dp
= parserep(rp
, length
);
1819 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1823 case NFSPROC_FSINFO
:
1825 dp
= parserep(rp
, length
);
1826 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1830 case NFSPROC_PATHCONF
:
1831 printf(" pathconf");
1832 dp
= parserep(rp
, length
);
1833 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1837 case NFSPROC_COMMIT
:
1839 dp
= parserep(rp
, length
);
1840 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1845 printf(" proc-%u", proc
);
1850 fputs(" [|nfs]", stdout
);