]>
The Tcpdump Group git mirrors - tcpdump/blob - print-nfs.c
92308f8c8cd5e96dd323ebddd19954cb7b725beb
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>
32 #include "interface.h"
33 #include "addrtoname.h"
46 static const char tstr
[] = " [|nfs]";
48 static void nfs_printfh(const u_int32_t
*, const u_int
);
49 static int xid_map_enter(const struct sunrpc_msg
*, const u_char
*);
50 static int xid_map_find(const struct sunrpc_msg
*, const u_char
*,
51 u_int32_t
*, u_int32_t
*);
52 static void interp_reply(const struct sunrpc_msg
*, u_int32_t
, u_int32_t
, int);
53 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
54 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
55 static void print_nfsaddr(const u_char
*, const char *, const char *);
58 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
60 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
90 * NFS V2 and V3 status values.
92 * Some of these come from the RFCs for NFS V2 and V3, with the message
93 * strings taken from the FreeBSD C library "errlst.c".
95 * Others are errors that are not in the RFC but that I suspect some
96 * NFS servers could return; the values are FreeBSD errno values, as
97 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
98 * was primarily BSD-derived.
100 static const struct tok status2str
[] = {
101 { 1, "Operation not permitted" }, /* EPERM */
102 { 2, "No such file or directory" }, /* ENOENT */
103 { 5, "Input/output error" }, /* EIO */
104 { 6, "Device not configured" }, /* ENXIO */
105 { 11, "Resource deadlock avoided" }, /* EDEADLK */
106 { 12, "Cannot allocate memory" }, /* ENOMEM */
107 { 13, "Permission denied" }, /* EACCES */
108 { 17, "File exists" }, /* EEXIST */
109 { 18, "Cross-device link" }, /* EXDEV */
110 { 19, "Operation not supported by device" }, /* ENODEV */
111 { 20, "Not a directory" }, /* ENOTDIR */
112 { 21, "Is a directory" }, /* EISDIR */
113 { 22, "Invalid argument" }, /* EINVAL */
114 { 26, "Text file busy" }, /* ETXTBSY */
115 { 27, "File too large" }, /* EFBIG */
116 { 28, "No space left on device" }, /* ENOSPC */
117 { 30, "Read-only file system" }, /* EROFS */
118 { 31, "Too many links" }, /* EMLINK */
119 { 45, "Operation not supported" }, /* EOPNOTSUPP */
120 { 62, "Too many levels of symbolic links" }, /* ELOOP */
121 { 63, "File name too long" }, /* ENAMETOOLONG */
122 { 66, "Directory not empty" }, /* ENOTEMPTY */
123 { 69, "Disc quota exceeded" }, /* EDQUOT */
124 { 70, "Stale NFS file handle" }, /* ESTALE */
125 { 71, "Too many levels of remote in path" }, /* EREMOTE */
126 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
127 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
128 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
129 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
130 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
131 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
132 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
133 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
134 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
138 static const struct tok nfsv3_writemodes
[] = {
145 static const struct tok type2str
[] = {
157 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
162 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
164 #ifndef INET_ADDRSTRLEN
165 #define INET_ADDRSTRLEN 16
167 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
170 srcaddr
[0] = dstaddr
[0] = '\0';
171 switch (IP_V((struct ip
*)bp
)) {
173 ip
= (struct ip
*)bp
;
174 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
175 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
179 ip6
= (struct ip6_hdr
*)bp
;
180 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
182 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
187 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
188 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
192 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
195 static const u_int32_t
*
196 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
199 sa3
->sa_modeset
= EXTRACT_32BITS(dp
);
201 if (sa3
->sa_modeset
) {
203 sa3
->sa_mode
= EXTRACT_32BITS(dp
);
208 sa3
->sa_uidset
= EXTRACT_32BITS(dp
);
210 if (sa3
->sa_uidset
) {
212 sa3
->sa_uid
= EXTRACT_32BITS(dp
);
217 sa3
->sa_gidset
= EXTRACT_32BITS(dp
);
219 if (sa3
->sa_gidset
) {
221 sa3
->sa_gid
= EXTRACT_32BITS(dp
);
226 sa3
->sa_sizeset
= EXTRACT_32BITS(dp
);
228 if (sa3
->sa_sizeset
) {
230 sa3
->sa_size
= EXTRACT_32BITS(dp
);
235 sa3
->sa_atimetype
= EXTRACT_32BITS(dp
);
237 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
) {
239 sa3
->sa_atime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
241 sa3
->sa_atime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
246 sa3
->sa_mtimetype
= EXTRACT_32BITS(dp
);
248 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
) {
250 sa3
->sa_mtime
.nfsv3_sec
= EXTRACT_32BITS(dp
);
252 sa3
->sa_mtime
.nfsv3_nsec
= EXTRACT_32BITS(dp
);
261 static int nfserr
; /* true if we error rather than trunc */
264 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
267 printf(" mode %o", sa3
->sa_mode
);
269 printf(" uid %u", sa3
->sa_uid
);
271 printf(" gid %u", sa3
->sa_gid
);
273 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
274 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
275 sa3
->sa_atime
.nfsv3_nsec
);
276 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
277 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
278 sa3
->sa_mtime
.nfsv3_nsec
);
283 nfsreply_print(register const u_char
*bp
, u_int length
,
284 register const u_char
*bp2
)
286 register const struct sunrpc_msg
*rp
;
287 char srcid
[20], dstid
[20]; /*fits 32bit*/
289 nfserr
= 0; /* assume no error */
290 rp
= (const struct sunrpc_msg
*)bp
;
294 strlcpy(srcid
, "nfs", sizeof(srcid
));
295 snprintf(dstid
, sizeof(dstid
), "%u",
296 EXTRACT_32BITS(&rp
->rm_xid
));
298 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
299 snprintf(dstid
, sizeof(dstid
), "%u",
300 EXTRACT_32BITS(&rp
->rm_xid
));
302 print_nfsaddr(bp2
, srcid
, dstid
);
304 nfsreply_print_noaddr(bp
, length
, bp2
);
313 nfsreply_print_noaddr(register const u_char
*bp
, u_int length
,
314 register const u_char
*bp2
)
316 register const struct sunrpc_msg
*rp
;
317 u_int32_t proc
, vers
, reply_stat
;
318 enum sunrpc_reject_stat rstat
;
321 enum sunrpc_auth_stat rwhy
;
323 nfserr
= 0; /* assume no error */
324 rp
= (const struct sunrpc_msg
*)bp
;
326 TCHECK(rp
->rm_reply
.rp_stat
);
327 reply_stat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
);
328 switch (reply_stat
) {
330 case SUNRPC_MSG_ACCEPTED
:
331 (void)printf("reply ok %u", length
);
332 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
333 interp_reply(rp
, proc
, vers
, length
);
336 case SUNRPC_MSG_DENIED
:
337 (void)printf("reply ERR %u: ", length
);
338 TCHECK(rp
->rm_reply
.rp_reject
.rj_stat
);
339 rstat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_stat
);
342 case SUNRPC_RPC_MISMATCH
:
343 TCHECK(rp
->rm_reply
.rp_reject
.rj_vers
.high
);
344 rlow
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.low
);
345 rhigh
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.high
);
346 (void)printf("RPC Version mismatch (%u-%u)",
350 case SUNRPC_AUTH_ERROR
:
351 TCHECK(rp
->rm_reply
.rp_reject
.rj_why
);
352 rwhy
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_why
);
353 (void)printf("Auth ");
360 case SUNRPC_AUTH_BADCRED
:
361 (void)printf("Bogus Credentials (seal broken)");
364 case SUNRPC_AUTH_REJECTEDCRED
:
365 (void)printf("Rejected Credentials (client should begin new session)");
368 case SUNRPC_AUTH_BADVERF
:
369 (void)printf("Bogus Verifier (seal broken)");
372 case SUNRPC_AUTH_REJECTEDVERF
:
373 (void)printf("Verifier expired or was replayed");
376 case SUNRPC_AUTH_TOOWEAK
:
377 (void)printf("Credentials are too weak");
380 case SUNRPC_AUTH_INVALIDRESP
:
381 (void)printf("Bogus response verifier");
384 case SUNRPC_AUTH_FAILED
:
385 (void)printf("Unknown failure");
389 (void)printf("Invalid failure code %u",
396 (void)printf("Unknown reason for rejecting rpc message %u",
397 (unsigned int)rstat
);
403 (void)printf("reply Unknown rpc response code=%u %u",
415 * Return a pointer to the first file handle in the packet.
416 * If the packet was truncated, return 0.
418 static const u_int32_t
*
419 parsereq(register const struct sunrpc_msg
*rp
, register u_int length
)
421 register const u_int32_t
*dp
;
425 * find the start of the req data (if we captured it)
427 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
429 len
= EXTRACT_32BITS(&dp
[1]);
431 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
433 len
= EXTRACT_32BITS(&dp
[1]);
435 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
445 * Print out an NFS file handle and return a pointer to following word.
446 * If packet was truncated, return 0.
448 static const u_int32_t
*
449 parsefh(register const u_int32_t
*dp
, int v3
)
455 len
= EXTRACT_32BITS(dp
) / 4;
460 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
461 nfs_printfh(dp
, len
);
469 * Print out a file name and return pointer to 32-bit word past it.
470 * If packet was truncated, return 0.
472 static const u_int32_t
*
473 parsefn(register const u_int32_t
*dp
)
475 register u_int32_t len
;
476 register const u_char
*cp
;
478 /* Bail if we don't have the string length */
481 /* Fetch string length; convert to host order */
485 TCHECK2(*dp
, ((len
+ 3) & ~3));
488 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
489 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
491 if (fn_printn(cp
, len
, snapend
)) {
503 * Print out file handle and file name.
504 * Return pointer to 32-bit word past file name.
505 * If packet was truncated (or there was some other error), return 0.
507 static const u_int32_t
*
508 parsefhn(register const u_int32_t
*dp
, int v3
)
510 dp
= parsefh(dp
, v3
);
514 return (parsefn(dp
));
518 nfsreq_print(register const u_char
*bp
, u_int length
,
519 register const u_char
*bp2
)
521 register const struct sunrpc_msg
*rp
;
522 char srcid
[20], dstid
[20]; /*fits 32bit*/
524 nfserr
= 0; /* assume no error */
525 rp
= (const struct sunrpc_msg
*)bp
;
529 snprintf(srcid
, sizeof(srcid
), "%u",
530 EXTRACT_32BITS(&rp
->rm_xid
));
531 strlcpy(dstid
, "nfs", sizeof(dstid
));
533 snprintf(srcid
, sizeof(srcid
), "%u",
534 EXTRACT_32BITS(&rp
->rm_xid
));
535 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
537 print_nfsaddr(bp2
, srcid
, dstid
);
538 (void)printf("%d", length
);
540 nfsreq_print_noaddr(bp
, length
, bp2
);
549 nfsreq_print_noaddr(register const u_char
*bp
, u_int length
,
550 register const u_char
*bp2
)
552 register const struct sunrpc_msg
*rp
;
553 register const u_int32_t
*dp
;
557 u_int32_t access_flags
;
558 struct nfsv3_sattr sa3
;
560 nfserr
= 0; /* assume no error */
561 rp
= (const struct sunrpc_msg
*)bp
;
563 if (!xid_map_enter(rp
, bp2
)) /* record proc number for later on */
566 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
567 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
569 if (!v3
&& proc
< NFS_NPROCS
)
570 proc
= nfsv3_procid
[proc
];
580 case NFSPROC_GETATTR
:
582 if ((dp
= parsereq(rp
, length
)) != NULL
&&
583 parsefh(dp
, v3
) != NULL
)
587 case NFSPROC_SETATTR
:
589 if ((dp
= parsereq(rp
, length
)) != NULL
&&
590 parsefh(dp
, v3
) != NULL
)
596 if ((dp
= parsereq(rp
, length
)) != NULL
&&
597 parsefhn(dp
, v3
) != NULL
)
603 if ((dp
= parsereq(rp
, length
)) != NULL
&&
604 (dp
= parsefh(dp
, v3
)) != NULL
) {
606 access_flags
= EXTRACT_32BITS(&dp
[0]);
607 if (access_flags
& ~NFSV3ACCESS_FULL
) {
608 /* NFSV3ACCESS definitions aren't up to date */
609 printf(" %04x", access_flags
);
610 } else if ((access_flags
& NFSV3ACCESS_FULL
) == NFSV3ACCESS_FULL
) {
611 printf(" NFS_ACCESS_FULL");
613 char separator
= ' ';
614 if (access_flags
& NFSV3ACCESS_READ
) {
615 printf(" NFS_ACCESS_READ");
618 if (access_flags
& NFSV3ACCESS_LOOKUP
) {
619 printf("%cNFS_ACCESS_LOOKUP", separator
);
622 if (access_flags
& NFSV3ACCESS_MODIFY
) {
623 printf("%cNFS_ACCESS_MODIFY", separator
);
626 if (access_flags
& NFSV3ACCESS_EXTEND
) {
627 printf("%cNFS_ACCESS_EXTEND", separator
);
630 if (access_flags
& NFSV3ACCESS_DELETE
) {
631 printf("%cNFS_ACCESS_DELETE", separator
);
634 if (access_flags
& NFSV3ACCESS_EXECUTE
)
635 printf("%cNFS_ACCESS_EXECUTE", separator
);
641 case NFSPROC_READLINK
:
643 if ((dp
= parsereq(rp
, length
)) != NULL
&&
644 parsefh(dp
, v3
) != NULL
)
650 if ((dp
= parsereq(rp
, length
)) != NULL
&&
651 (dp
= parsefh(dp
, v3
)) != NULL
) {
654 printf(" %u bytes @ %" PRIu64
,
655 EXTRACT_32BITS(&dp
[2]),
656 EXTRACT_64BITS(&dp
[0]));
659 printf(" %u bytes @ %u",
660 EXTRACT_32BITS(&dp
[1]),
661 EXTRACT_32BITS(&dp
[0]));
669 if ((dp
= parsereq(rp
, length
)) != NULL
&&
670 (dp
= parsefh(dp
, v3
)) != NULL
) {
673 printf(" %u (%u) bytes @ %" PRIu64
,
674 EXTRACT_32BITS(&dp
[4]),
675 EXTRACT_32BITS(&dp
[2]),
676 EXTRACT_64BITS(&dp
[0]));
681 tok2str(nfsv3_writemodes
,
682 NULL
, EXTRACT_32BITS(dp
)));
686 printf(" %u (%u) bytes @ %u (%u)",
687 EXTRACT_32BITS(&dp
[3]),
688 EXTRACT_32BITS(&dp
[2]),
689 EXTRACT_32BITS(&dp
[1]),
690 EXTRACT_32BITS(&dp
[0]));
698 if ((dp
= parsereq(rp
, length
)) != NULL
&&
699 parsefhn(dp
, v3
) != NULL
)
705 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
709 case NFSPROC_SYMLINK
:
711 if ((dp
= parsereq(rp
, length
)) != 0 &&
712 (dp
= parsefhn(dp
, v3
)) != 0) {
713 fputs(" ->", stdout
);
714 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
716 if (parsefn(dp
) == 0)
719 print_sattr3(&sa3
, vflag
);
726 if ((dp
= parsereq(rp
, length
)) != 0 &&
727 (dp
= parsefhn(dp
, v3
)) != 0) {
729 type
= (nfs_type
)EXTRACT_32BITS(dp
);
731 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
733 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
734 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
737 EXTRACT_32BITS(&dp
[0]),
738 EXTRACT_32BITS(&dp
[1]));
742 print_sattr3(&sa3
, vflag
);
749 if ((dp
= parsereq(rp
, length
)) != NULL
&&
750 parsefhn(dp
, v3
) != NULL
)
756 if ((dp
= parsereq(rp
, length
)) != NULL
&&
757 parsefhn(dp
, v3
) != NULL
)
763 if ((dp
= parsereq(rp
, length
)) != NULL
&&
764 (dp
= parsefhn(dp
, v3
)) != NULL
) {
765 fputs(" ->", stdout
);
766 if (parsefhn(dp
, v3
) != NULL
)
773 if ((dp
= parsereq(rp
, length
)) != NULL
&&
774 (dp
= parsefh(dp
, v3
)) != NULL
) {
775 fputs(" ->", stdout
);
776 if (parsefhn(dp
, v3
) != NULL
)
781 case NFSPROC_READDIR
:
783 if ((dp
= parsereq(rp
, length
)) != NULL
&&
784 (dp
= parsefh(dp
, v3
)) != NULL
) {
788 * We shouldn't really try to interpret the
789 * offset cookie here.
791 printf(" %u bytes @ %" PRId64
,
792 EXTRACT_32BITS(&dp
[4]),
793 EXTRACT_64BITS(&dp
[0]));
795 printf(" verf %08x%08x", dp
[2],
800 * Print the offset as signed, since -1 is
801 * common, but offsets > 2^31 aren't.
803 printf(" %u bytes @ %d",
804 EXTRACT_32BITS(&dp
[1]),
805 EXTRACT_32BITS(&dp
[0]));
811 case NFSPROC_READDIRPLUS
:
812 printf(" readdirplus");
813 if ((dp
= parsereq(rp
, length
)) != NULL
&&
814 (dp
= parsefh(dp
, v3
)) != NULL
) {
817 * We don't try to interpret the offset
820 printf(" %u bytes @ %" PRId64
,
821 EXTRACT_32BITS(&dp
[4]),
822 EXTRACT_64BITS(&dp
[0]));
825 printf(" max %u verf %08x%08x",
826 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
834 if ((dp
= parsereq(rp
, length
)) != NULL
&&
835 parsefh(dp
, v3
) != NULL
)
841 if ((dp
= parsereq(rp
, length
)) != NULL
&&
842 parsefh(dp
, v3
) != NULL
)
846 case NFSPROC_PATHCONF
:
848 if ((dp
= parsereq(rp
, length
)) != NULL
&&
849 parsefh(dp
, v3
) != NULL
)
855 if ((dp
= parsereq(rp
, length
)) != NULL
&&
856 (dp
= parsefh(dp
, v3
)) != NULL
) {
858 printf(" %u bytes @ %" PRIu64
,
859 EXTRACT_32BITS(&dp
[2]),
860 EXTRACT_64BITS(&dp
[0]));
866 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
876 * Print out an NFS file handle.
877 * We assume packet was not truncated before the end of the
878 * file handle pointed to by dp.
880 * Note: new version (using portable file-handle parser) doesn't produce
881 * generation number. It probably could be made to do that, with some
882 * additional hacking on the parser code.
885 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
889 const char *sfsname
= NULL
;
894 char const *sep
= "";
897 for (i
=0; i
<len
; i
++) {
898 (void)printf("%s%x", sep
, dp
[i
]);
905 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
908 /* file system ID is ASCII, not numeric, for this server OS */
909 static char temp
[NFSX_V3FHMAX
+1];
911 /* Make sure string is null-terminated */
912 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
913 temp
[sizeof(temp
) - 1] = '\0';
914 /* Remove trailing spaces */
915 spacep
= strchr(temp
, ' ');
919 (void)printf(" fh %s/", temp
);
921 (void)printf(" fh %d,%d/",
922 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
925 if(fsid
.Fsid_dev
.Minor
== 257)
926 /* Print the undecoded handle */
927 (void)printf("%s", fsid
.Opaque_Handle
);
929 (void)printf("%ld", (long) ino
);
933 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
934 * us to match up replies with requests and thus to know how to parse
938 struct xid_map_entry
{
939 u_int32_t xid
; /* transaction ID (net order) */
940 int ipver
; /* IP version (4 or 6) */
942 struct in6_addr client
; /* client IP address (net order) */
943 struct in6_addr server
; /* server IP address (net order) */
945 struct in_addr client
; /* client IP address (net order) */
946 struct in_addr server
; /* server IP address (net order) */
948 u_int32_t proc
; /* call proc number (host order) */
949 u_int32_t vers
; /* program version (host order) */
953 * Map entries are kept in an array that we manage as a ring;
954 * new entries are always added at the tail of the ring. Initially,
955 * all the entries are zero and hence don't match anything.
958 #define XIDMAPSIZE 64
960 struct xid_map_entry xid_map
[XIDMAPSIZE
];
962 int xid_map_next
= 0;
963 int xid_map_hint
= 0;
966 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
968 struct ip
*ip
= NULL
;
970 struct ip6_hdr
*ip6
= NULL
;
972 struct xid_map_entry
*xmep
;
974 if (!TTEST(rp
->rm_call
.cb_vers
))
976 switch (IP_V((struct ip
*)bp
)) {
978 ip
= (struct ip
*)bp
;
982 ip6
= (struct ip6_hdr
*)bp
;
989 xmep
= &xid_map
[xid_map_next
];
991 if (++xid_map_next
>= XIDMAPSIZE
)
994 xmep
->xid
= rp
->rm_xid
;
997 UNALIGNED_MEMCPY(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
998 UNALIGNED_MEMCPY(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
1003 UNALIGNED_MEMCPY(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
1004 UNALIGNED_MEMCPY(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
1007 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
1008 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
1013 * Returns 0 and puts NFSPROC_xxx in proc return and
1014 * version in vers return, or returns -1 on failure
1017 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
1021 struct xid_map_entry
*xmep
;
1022 u_int32_t xid
= rp
->rm_xid
;
1023 struct ip
*ip
= (struct ip
*)bp
;
1025 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
1029 /* Start searching from where we last left off */
1034 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
1036 switch (xmep
->ipver
) {
1038 if (UNALIGNED_MEMCMP(&ip
->ip_src
, &xmep
->server
,
1039 sizeof(ip
->ip_src
)) != 0 ||
1040 UNALIGNED_MEMCMP(&ip
->ip_dst
, &xmep
->client
,
1041 sizeof(ip
->ip_dst
)) != 0) {
1047 if (UNALIGNED_MEMCMP(&ip6
->ip6_src
, &xmep
->server
,
1048 sizeof(ip6
->ip6_src
)) != 0 ||
1049 UNALIGNED_MEMCMP(&ip6
->ip6_dst
, &xmep
->client
,
1050 sizeof(ip6
->ip6_dst
)) != 0) {
1067 if (++i
>= XIDMAPSIZE
)
1069 } while (i
!= xid_map_hint
);
1076 * Routines for parsing reply packets
1080 * Return a pointer to the beginning of the actual results.
1081 * If the packet was truncated, return 0.
1083 static const u_int32_t
*
1084 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
1086 register const u_int32_t
*dp
;
1088 enum sunrpc_accept_stat astat
;
1092 * Here we find the address of the ar_verf credentials.
1093 * Originally, this calculation was
1094 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
1095 * On the wire, the rp_acpt field starts immediately after
1096 * the (32 bit) rp_stat field. However, rp_acpt (which is a
1097 * "struct accepted_reply") contains a "struct opaque_auth",
1098 * whose internal representation contains a pointer, so on a
1099 * 64-bit machine the compiler inserts 32 bits of padding
1100 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
1101 * the internal representation to parse the on-the-wire
1102 * representation. Instead, we skip past the rp_stat field,
1103 * which is an "enum" and so occupies one 32-bit word.
1105 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
1107 len
= EXTRACT_32BITS(&dp
[1]);
1111 * skip past the ar_verf credentials.
1113 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
1117 * now we can check the ar_stat field
1119 astat
= (enum sunrpc_accept_stat
) EXTRACT_32BITS(dp
);
1122 case SUNRPC_SUCCESS
:
1125 case SUNRPC_PROG_UNAVAIL
:
1126 printf(" PROG_UNAVAIL");
1127 nfserr
= 1; /* suppress trunc string */
1130 case SUNRPC_PROG_MISMATCH
:
1131 printf(" PROG_MISMATCH");
1132 nfserr
= 1; /* suppress trunc string */
1135 case SUNRPC_PROC_UNAVAIL
:
1136 printf(" PROC_UNAVAIL");
1137 nfserr
= 1; /* suppress trunc string */
1140 case SUNRPC_GARBAGE_ARGS
:
1141 printf(" GARBAGE_ARGS");
1142 nfserr
= 1; /* suppress trunc string */
1145 case SUNRPC_SYSTEM_ERR
:
1146 printf(" SYSTEM_ERR");
1147 nfserr
= 1; /* suppress trunc string */
1151 printf(" ar_stat %d", astat
);
1152 nfserr
= 1; /* suppress trunc string */
1155 /* successful return */
1156 TCHECK2(*dp
, sizeof(astat
));
1157 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1162 static const u_int32_t
*
1163 parsestatus(const u_int32_t
*dp
, int *er
)
1169 errnum
= EXTRACT_32BITS(&dp
[0]);
1174 printf(" ERROR: %s",
1175 tok2str(status2str
, "unk %d", errnum
));
1183 static const u_int32_t
*
1184 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1186 const struct nfs_fattr
*fap
;
1188 fap
= (const struct nfs_fattr
*)dp
;
1189 TCHECK(fap
->fa_gid
);
1191 printf(" %s %o ids %d/%d",
1192 tok2str(type2str
, "unk-ft %d ",
1193 EXTRACT_32BITS(&fap
->fa_type
)),
1194 EXTRACT_32BITS(&fap
->fa_mode
),
1195 EXTRACT_32BITS(&fap
->fa_uid
),
1196 EXTRACT_32BITS(&fap
->fa_gid
));
1198 TCHECK(fap
->fa3_size
);
1199 printf(" sz %" PRIu64
,
1200 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1202 TCHECK(fap
->fa2_size
);
1203 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1206 /* print lots more stuff */
1209 TCHECK(fap
->fa3_ctime
);
1210 printf(" nlink %d rdev %d/%d",
1211 EXTRACT_32BITS(&fap
->fa_nlink
),
1212 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1213 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1214 printf(" fsid %" PRIx64
,
1215 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1216 printf(" fileid %" PRIx64
,
1217 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1218 printf(" a/m/ctime %u.%06u",
1219 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1220 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1222 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1223 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1225 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1226 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1228 TCHECK(fap
->fa2_ctime
);
1229 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1230 EXTRACT_32BITS(&fap
->fa_nlink
),
1231 EXTRACT_32BITS(&fap
->fa2_rdev
),
1232 EXTRACT_32BITS(&fap
->fa2_fsid
),
1233 EXTRACT_32BITS(&fap
->fa2_fileid
));
1235 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1236 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1238 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1239 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1241 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1242 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1245 return ((const u_int32_t
*)((unsigned char *)dp
+
1246 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1252 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1256 dp
= parsestatus(dp
, &er
);
1262 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1266 parsediropres(const u_int32_t
*dp
)
1270 if (!(dp
= parsestatus(dp
, &er
)))
1275 dp
= parsefh(dp
, 0);
1279 return (parsefattr(dp
, vflag
, 0) != NULL
);
1283 parselinkres(const u_int32_t
*dp
, int v3
)
1287 dp
= parsestatus(dp
, &er
);
1292 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1295 return (parsefn(dp
) != NULL
);
1299 parsestatfs(const u_int32_t
*dp
, int v3
)
1301 const struct nfs_statfs
*sfsp
;
1304 dp
= parsestatus(dp
, &er
);
1316 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1320 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1322 sfsp
= (const struct nfs_statfs
*)dp
;
1325 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1326 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1327 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1328 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1330 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1331 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1332 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1333 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1334 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1337 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1338 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1339 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1340 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1341 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1342 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1351 parserddires(const u_int32_t
*dp
)
1355 dp
= parsestatus(dp
, &er
);
1364 printf(" offset %x size %d ",
1365 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1374 static const u_int32_t
*
1375 parse_wcc_attr(const u_int32_t
*dp
)
1377 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1378 printf(" mtime %u.%06u ctime %u.%06u",
1379 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1380 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1385 * Pre operation attributes. Print only if vflag > 1.
1387 static const u_int32_t
*
1388 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1391 if (!EXTRACT_32BITS(&dp
[0]))
1396 return parse_wcc_attr(dp
);
1398 /* If not verbose enough, just skip over wcc_attr */
1406 * Post operation attributes are printed if vflag >= 1
1408 static const u_int32_t
*
1409 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1412 if (!EXTRACT_32BITS(&dp
[0]))
1416 return parsefattr(dp
, verbose
, 1);
1418 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1423 static const u_int32_t
*
1424 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1428 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1433 return parse_post_op_attr(dp
, verbose
);
1436 static const u_int32_t
*
1437 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1441 if (!(dp
= parsestatus(dp
, &er
)))
1444 dp
= parse_wcc_data(dp
, verbose
);
1447 if (!EXTRACT_32BITS(&dp
[0]))
1450 if (!(dp
= parsefh(dp
, 1)))
1453 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1456 printf(" dir attr:");
1457 dp
= parse_wcc_data(dp
, verbose
);
1467 parsewccres(const u_int32_t
*dp
, int verbose
)
1471 if (!(dp
= parsestatus(dp
, &er
)))
1473 return parse_wcc_data(dp
, verbose
) != 0;
1476 static const u_int32_t
*
1477 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1481 if (!(dp
= parsestatus(dp
, &er
)))
1485 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1491 printf(" verf %08x%08x", dp
[0], dp
[1]);
1500 parsefsinfo(const u_int32_t
*dp
)
1502 struct nfsv3_fsinfo
*sfp
;
1505 if (!(dp
= parsestatus(dp
, &er
)))
1509 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1514 sfp
= (struct nfsv3_fsinfo
*)dp
;
1516 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1517 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1518 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1519 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1520 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1521 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1523 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1524 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1525 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1526 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1527 printf(" delta %u.%06u ",
1528 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1529 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1537 parsepathconf(const u_int32_t
*dp
)
1540 struct nfsv3_pathconf
*spp
;
1542 if (!(dp
= parsestatus(dp
, &er
)))
1546 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1551 spp
= (struct nfsv3_pathconf
*)dp
;
1554 printf(" linkmax %u namemax %u %s %s %s %s",
1555 EXTRACT_32BITS(&spp
->pc_linkmax
),
1556 EXTRACT_32BITS(&spp
->pc_namemax
),
1557 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1558 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1559 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1560 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1567 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1569 register const u_int32_t
*dp
;
1573 v3
= (vers
== NFS_VER3
);
1575 if (!v3
&& proc
< NFS_NPROCS
)
1576 proc
= nfsv3_procid
[proc
];
1588 case NFSPROC_GETATTR
:
1590 dp
= parserep(rp
, length
);
1591 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1595 case NFSPROC_SETATTR
:
1597 if (!(dp
= parserep(rp
, length
)))
1600 if (parsewccres(dp
, vflag
))
1603 if (parseattrstat(dp
, !qflag
, 0) != 0)
1608 case NFSPROC_LOOKUP
:
1610 if (!(dp
= parserep(rp
, length
)))
1613 if (!(dp
= parsestatus(dp
, &er
)))
1617 printf(" post dattr:");
1618 dp
= parse_post_op_attr(dp
, vflag
);
1621 if (!(dp
= parsefh(dp
, v3
)))
1623 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1625 printf(" post dattr:");
1626 dp
= parse_post_op_attr(dp
, vflag
);
1632 if (parsediropres(dp
) != 0)
1637 case NFSPROC_ACCESS
:
1639 if (!(dp
= parserep(rp
, length
)))
1641 if (!(dp
= parsestatus(dp
, &er
)))
1645 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1648 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1651 case NFSPROC_READLINK
:
1652 printf(" readlink");
1653 dp
= parserep(rp
, length
);
1654 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1660 if (!(dp
= parserep(rp
, length
)))
1663 if (!(dp
= parsestatus(dp
, &er
)))
1665 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1671 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1672 if (EXTRACT_32BITS(&dp
[1]))
1677 if (parseattrstat(dp
, vflag
, 0) != 0)
1684 if (!(dp
= parserep(rp
, length
)))
1687 if (!(dp
= parsestatus(dp
, &er
)))
1689 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1695 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1699 tok2str(nfsv3_writemodes
,
1700 NULL
, EXTRACT_32BITS(&dp
[1])));
1705 if (parseattrstat(dp
, vflag
, v3
) != 0)
1710 case NFSPROC_CREATE
:
1712 if (!(dp
= parserep(rp
, length
)))
1715 if (parsecreateopres(dp
, vflag
) != 0)
1718 if (parsediropres(dp
) != 0)
1725 if (!(dp
= parserep(rp
, length
)))
1728 if (parsecreateopres(dp
, vflag
) != 0)
1731 if (parsediropres(dp
) != 0)
1736 case NFSPROC_SYMLINK
:
1738 if (!(dp
= parserep(rp
, length
)))
1741 if (parsecreateopres(dp
, vflag
) != 0)
1744 if (parsestatus(dp
, &er
) != 0)
1751 if (!(dp
= parserep(rp
, length
)))
1753 if (parsecreateopres(dp
, vflag
) != 0)
1757 case NFSPROC_REMOVE
:
1759 if (!(dp
= parserep(rp
, length
)))
1762 if (parsewccres(dp
, vflag
))
1765 if (parsestatus(dp
, &er
) != 0)
1772 if (!(dp
= parserep(rp
, length
)))
1775 if (parsewccres(dp
, vflag
))
1778 if (parsestatus(dp
, &er
) != 0)
1783 case NFSPROC_RENAME
:
1785 if (!(dp
= parserep(rp
, length
)))
1788 if (!(dp
= parsestatus(dp
, &er
)))
1792 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1795 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1800 if (parsestatus(dp
, &er
) != 0)
1807 if (!(dp
= parserep(rp
, length
)))
1810 if (!(dp
= parsestatus(dp
, &er
)))
1813 printf(" file POST:");
1814 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1817 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1822 if (parsestatus(dp
, &er
) != 0)
1827 case NFSPROC_READDIR
:
1829 if (!(dp
= parserep(rp
, length
)))
1832 if (parsev3rddirres(dp
, vflag
))
1835 if (parserddires(dp
) != 0)
1840 case NFSPROC_READDIRPLUS
:
1841 printf(" readdirplus");
1842 if (!(dp
= parserep(rp
, length
)))
1844 if (parsev3rddirres(dp
, vflag
))
1848 case NFSPROC_FSSTAT
:
1850 dp
= parserep(rp
, length
);
1851 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1855 case NFSPROC_FSINFO
:
1857 dp
= parserep(rp
, length
);
1858 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1862 case NFSPROC_PATHCONF
:
1863 printf(" pathconf");
1864 dp
= parserep(rp
, length
);
1865 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1869 case NFSPROC_COMMIT
:
1871 dp
= parserep(rp
, length
);
1872 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1877 printf(" proc-%u", proc
);