]>
The Tcpdump Group git mirrors - tcpdump/blob - print-nfs.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] _U_
=
24 "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.111 2007-12-22 03:08:04 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
51 static 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 int 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 const 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 const struct tok nfsv3_writemodes
[] = {
148 static const 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 char srcid
[20], dstid
[20]; /*fits 32bit*/
292 nfserr
= 0; /* assume no error */
293 rp
= (const struct sunrpc_msg
*)bp
;
297 strlcpy(srcid
, "nfs", sizeof(srcid
));
298 snprintf(dstid
, sizeof(dstid
), "%u",
299 EXTRACT_32BITS(&rp
->rm_xid
));
301 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
302 snprintf(dstid
, sizeof(dstid
), "%u",
303 EXTRACT_32BITS(&rp
->rm_xid
));
305 print_nfsaddr(bp2
, srcid
, dstid
);
307 nfsreply_print_noaddr(bp
, length
, bp2
);
312 fputs(" [|nfs]", stdout
);
316 nfsreply_print_noaddr(register const u_char
*bp
, u_int length
,
317 register const u_char
*bp2
)
319 register const struct sunrpc_msg
*rp
;
320 u_int32_t proc
, vers
, reply_stat
;
321 enum sunrpc_reject_stat rstat
;
324 enum sunrpc_auth_stat rwhy
;
326 nfserr
= 0; /* assume no error */
327 rp
= (const struct sunrpc_msg
*)bp
;
329 TCHECK(rp
->rm_reply
.rp_stat
);
330 reply_stat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
);
331 switch (reply_stat
) {
333 case SUNRPC_MSG_ACCEPTED
:
334 (void)printf("reply ok %u", length
);
335 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
336 interp_reply(rp
, proc
, vers
, length
);
339 case SUNRPC_MSG_DENIED
:
340 (void)printf("reply ERR %u: ", length
);
341 TCHECK(rp
->rm_reply
.rp_reject
.rj_stat
);
342 rstat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_stat
);
345 case SUNRPC_RPC_MISMATCH
:
346 TCHECK(rp
->rm_reply
.rp_reject
.rj_vers
.high
);
347 rlow
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.low
);
348 rhigh
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.high
);
349 (void)printf("RPC Version mismatch (%u-%u)",
353 case SUNRPC_AUTH_ERROR
:
354 TCHECK(rp
->rm_reply
.rp_reject
.rj_why
);
355 rwhy
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_why
);
356 (void)printf("Auth ");
363 case SUNRPC_AUTH_BADCRED
:
364 (void)printf("Bogus Credentials (seal broken)");
367 case SUNRPC_AUTH_REJECTEDCRED
:
368 (void)printf("Rejected Credentials (client should begin new session)");
371 case SUNRPC_AUTH_BADVERF
:
372 (void)printf("Bogus Verifier (seal broken)");
375 case SUNRPC_AUTH_REJECTEDVERF
:
376 (void)printf("Verifier expired or was replayed");
379 case SUNRPC_AUTH_TOOWEAK
:
380 (void)printf("Credentials are too weak");
383 case SUNRPC_AUTH_INVALIDRESP
:
384 (void)printf("Bogus response verifier");
387 case SUNRPC_AUTH_FAILED
:
388 (void)printf("Unknown failure");
392 (void)printf("Invalid failure code %u",
399 (void)printf("Unknown reason for rejecting rpc message %u",
400 (unsigned int)rstat
);
406 (void)printf("reply Unknown rpc response code=%u %u",
414 fputs(" [|nfs]", stdout
);
418 * Return a pointer to the first file handle in the packet.
419 * If the packet was truncated, return 0.
421 static const u_int32_t
*
422 parsereq(register const struct sunrpc_msg
*rp
, register u_int length
)
424 register const u_int32_t
*dp
;
428 * find the start of the req data (if we captured it)
430 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
432 len
= EXTRACT_32BITS(&dp
[1]);
434 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
436 len
= EXTRACT_32BITS(&dp
[1]);
438 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
448 * Print out an NFS file handle and return a pointer to following word.
449 * If packet was truncated, return 0.
451 static const u_int32_t
*
452 parsefh(register const u_int32_t
*dp
, int v3
)
458 len
= EXTRACT_32BITS(dp
) / 4;
463 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
464 nfs_printfh(dp
, len
);
472 * Print out a file name and return pointer to 32-bit word past it.
473 * If packet was truncated, return 0.
475 static const u_int32_t
*
476 parsefn(register const u_int32_t
*dp
)
478 register u_int32_t len
;
479 register const u_char
*cp
;
481 /* Bail if we don't have the string length */
484 /* Fetch string length; convert to host order */
488 TCHECK2(*dp
, ((len
+ 3) & ~3));
491 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
492 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
494 if (fn_printn(cp
, len
, snapend
)) {
506 * Print out file handle and file name.
507 * Return pointer to 32-bit word past file name.
508 * If packet was truncated (or there was some other error), return 0.
510 static const u_int32_t
*
511 parsefhn(register const u_int32_t
*dp
, int v3
)
513 dp
= parsefh(dp
, v3
);
517 return (parsefn(dp
));
521 nfsreq_print(register const u_char
*bp
, u_int length
,
522 register const u_char
*bp2
)
524 register const struct sunrpc_msg
*rp
;
525 char srcid
[20], dstid
[20]; /*fits 32bit*/
527 nfserr
= 0; /* assume no error */
528 rp
= (const struct sunrpc_msg
*)bp
;
532 snprintf(srcid
, sizeof(srcid
), "%u",
533 EXTRACT_32BITS(&rp
->rm_xid
));
534 strlcpy(dstid
, "nfs", sizeof(dstid
));
536 snprintf(srcid
, sizeof(srcid
), "%u",
537 EXTRACT_32BITS(&rp
->rm_xid
));
538 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
540 print_nfsaddr(bp2
, srcid
, dstid
);
541 (void)printf("%d", length
);
543 nfsreq_print_noaddr(bp
, length
, bp2
);
548 fputs(" [|nfs]", stdout
);
552 nfsreq_print_noaddr(register const u_char
*bp
, u_int length
,
553 register const u_char
*bp2
)
555 register const struct sunrpc_msg
*rp
;
556 register const u_int32_t
*dp
;
560 u_int32_t access_flags
;
561 struct nfsv3_sattr sa3
;
563 nfserr
= 0; /* assume no error */
564 rp
= (const struct sunrpc_msg
*)bp
;
566 if (!xid_map_enter(rp
, bp2
)) /* record proc number for later on */
569 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
570 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
572 if (!v3
&& proc
< NFS_NPROCS
)
573 proc
= nfsv3_procid
[proc
];
583 case NFSPROC_GETATTR
:
585 if ((dp
= parsereq(rp
, length
)) != NULL
&&
586 parsefh(dp
, v3
) != NULL
)
590 case NFSPROC_SETATTR
:
592 if ((dp
= parsereq(rp
, length
)) != NULL
&&
593 parsefh(dp
, v3
) != NULL
)
599 if ((dp
= parsereq(rp
, length
)) != NULL
&&
600 parsefhn(dp
, v3
) != NULL
)
606 if ((dp
= parsereq(rp
, length
)) != NULL
&&
607 (dp
= parsefh(dp
, v3
)) != NULL
) {
609 access_flags
= EXTRACT_32BITS(&dp
[0]);
610 if (access_flags
& ~NFSV3ACCESS_FULL
) {
611 /* NFSV3ACCESS definitions aren't up to date */
612 printf(" %04x", access_flags
);
613 } else if ((access_flags
& NFSV3ACCESS_FULL
) == NFSV3ACCESS_FULL
) {
614 printf(" NFS_ACCESS_FULL");
616 char separator
= ' ';
617 if (access_flags
& NFSV3ACCESS_READ
) {
618 printf(" NFS_ACCESS_READ");
621 if (access_flags
& NFSV3ACCESS_LOOKUP
) {
622 printf("%cNFS_ACCESS_LOOKUP", separator
);
625 if (access_flags
& NFSV3ACCESS_MODIFY
) {
626 printf("%cNFS_ACCESS_MODIFY", separator
);
629 if (access_flags
& NFSV3ACCESS_EXTEND
) {
630 printf("%cNFS_ACCESS_EXTEND", separator
);
633 if (access_flags
& NFSV3ACCESS_DELETE
) {
634 printf("%cNFS_ACCESS_DELETE", separator
);
637 if (access_flags
& NFSV3ACCESS_EXECUTE
)
638 printf("%cNFS_ACCESS_EXECUTE", separator
);
644 case NFSPROC_READLINK
:
646 if ((dp
= parsereq(rp
, length
)) != NULL
&&
647 parsefh(dp
, v3
) != NULL
)
653 if ((dp
= parsereq(rp
, length
)) != NULL
&&
654 (dp
= parsefh(dp
, v3
)) != NULL
) {
657 printf(" %u bytes @ %" PRIu64
,
658 EXTRACT_32BITS(&dp
[2]),
659 EXTRACT_64BITS(&dp
[0]));
662 printf(" %u bytes @ %u",
663 EXTRACT_32BITS(&dp
[1]),
664 EXTRACT_32BITS(&dp
[0]));
672 if ((dp
= parsereq(rp
, length
)) != NULL
&&
673 (dp
= parsefh(dp
, v3
)) != NULL
) {
676 printf(" %u (%u) bytes @ %" PRIu64
,
677 EXTRACT_32BITS(&dp
[4]),
678 EXTRACT_32BITS(&dp
[2]),
679 EXTRACT_64BITS(&dp
[0]));
684 tok2str(nfsv3_writemodes
,
685 NULL
, EXTRACT_32BITS(dp
)));
689 printf(" %u (%u) bytes @ %u (%u)",
690 EXTRACT_32BITS(&dp
[3]),
691 EXTRACT_32BITS(&dp
[2]),
692 EXTRACT_32BITS(&dp
[1]),
693 EXTRACT_32BITS(&dp
[0]));
701 if ((dp
= parsereq(rp
, length
)) != NULL
&&
702 parsefhn(dp
, v3
) != NULL
)
708 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
712 case NFSPROC_SYMLINK
:
714 if ((dp
= parsereq(rp
, length
)) != 0 &&
715 (dp
= parsefhn(dp
, v3
)) != 0) {
716 fputs(" ->", stdout
);
717 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
719 if (parsefn(dp
) == 0)
722 print_sattr3(&sa3
, vflag
);
729 if ((dp
= parsereq(rp
, length
)) != 0 &&
730 (dp
= parsefhn(dp
, v3
)) != 0) {
732 type
= (nfs_type
)EXTRACT_32BITS(dp
);
734 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
736 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
737 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
740 EXTRACT_32BITS(&dp
[0]),
741 EXTRACT_32BITS(&dp
[1]));
745 print_sattr3(&sa3
, vflag
);
752 if ((dp
= parsereq(rp
, length
)) != NULL
&&
753 parsefhn(dp
, v3
) != NULL
)
759 if ((dp
= parsereq(rp
, length
)) != NULL
&&
760 parsefhn(dp
, v3
) != NULL
)
766 if ((dp
= parsereq(rp
, length
)) != NULL
&&
767 (dp
= parsefhn(dp
, v3
)) != NULL
) {
768 fputs(" ->", stdout
);
769 if (parsefhn(dp
, v3
) != NULL
)
776 if ((dp
= parsereq(rp
, length
)) != NULL
&&
777 (dp
= parsefh(dp
, v3
)) != NULL
) {
778 fputs(" ->", stdout
);
779 if (parsefhn(dp
, v3
) != NULL
)
784 case NFSPROC_READDIR
:
786 if ((dp
= parsereq(rp
, length
)) != NULL
&&
787 (dp
= parsefh(dp
, v3
)) != NULL
) {
791 * We shouldn't really try to interpret the
792 * offset cookie here.
794 printf(" %u bytes @ %" PRId64
,
795 EXTRACT_32BITS(&dp
[4]),
796 EXTRACT_64BITS(&dp
[0]));
798 printf(" verf %08x%08x", dp
[2],
803 * Print the offset as signed, since -1 is
804 * common, but offsets > 2^31 aren't.
806 printf(" %u bytes @ %d",
807 EXTRACT_32BITS(&dp
[1]),
808 EXTRACT_32BITS(&dp
[0]));
814 case NFSPROC_READDIRPLUS
:
815 printf(" readdirplus");
816 if ((dp
= parsereq(rp
, length
)) != NULL
&&
817 (dp
= parsefh(dp
, v3
)) != NULL
) {
820 * We don't try to interpret the offset
823 printf(" %u bytes @ %" PRId64
,
824 EXTRACT_32BITS(&dp
[4]),
825 EXTRACT_64BITS(&dp
[0]));
828 printf(" max %u verf %08x%08x",
829 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
837 if ((dp
= parsereq(rp
, length
)) != NULL
&&
838 parsefh(dp
, v3
) != NULL
)
844 if ((dp
= parsereq(rp
, length
)) != NULL
&&
845 parsefh(dp
, v3
) != NULL
)
849 case NFSPROC_PATHCONF
:
851 if ((dp
= parsereq(rp
, length
)) != NULL
&&
852 parsefh(dp
, v3
) != NULL
)
858 if ((dp
= parsereq(rp
, length
)) != NULL
&&
859 (dp
= parsefh(dp
, v3
)) != NULL
) {
861 printf(" %u bytes @ %" PRIu64
,
862 EXTRACT_32BITS(&dp
[2]),
863 EXTRACT_64BITS(&dp
[0]));
869 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
875 fputs(" [|nfs]", stdout
);
879 * Print out an NFS file handle.
880 * We assume packet was not truncated before the end of the
881 * file handle pointed to by dp.
883 * Note: new version (using portable file-handle parser) doesn't produce
884 * generation number. It probably could be made to do that, with some
885 * additional hacking on the parser code.
888 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
892 const char *sfsname
= NULL
;
897 char const *sep
= "";
900 for (i
=0; i
<len
; i
++) {
901 (void)printf("%s%x", sep
, dp
[i
]);
908 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
911 /* file system ID is ASCII, not numeric, for this server OS */
912 static char temp
[NFSX_V3FHMAX
+1];
914 /* Make sure string is null-terminated */
915 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
916 temp
[sizeof(temp
) - 1] = '\0';
917 /* Remove trailing spaces */
918 spacep
= strchr(temp
, ' ');
922 (void)printf(" fh %s/", temp
);
924 (void)printf(" fh %d,%d/",
925 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
928 if(fsid
.Fsid_dev
.Minor
== 257)
929 /* Print the undecoded handle */
930 (void)printf("%s", fsid
.Opaque_Handle
);
932 (void)printf("%ld", (long) ino
);
936 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
937 * us to match up replies with requests and thus to know how to parse
941 struct xid_map_entry
{
942 u_int32_t xid
; /* transaction ID (net order) */
943 int ipver
; /* IP version (4 or 6) */
945 struct in6_addr client
; /* client IP address (net order) */
946 struct in6_addr server
; /* server IP address (net order) */
948 struct in_addr client
; /* client IP address (net order) */
949 struct in_addr server
; /* server IP address (net order) */
951 u_int32_t proc
; /* call proc number (host order) */
952 u_int32_t vers
; /* program version (host order) */
956 * Map entries are kept in an array that we manage as a ring;
957 * new entries are always added at the tail of the ring. Initially,
958 * all the entries are zero and hence don't match anything.
961 #define XIDMAPSIZE 64
963 struct xid_map_entry xid_map
[XIDMAPSIZE
];
965 int xid_map_next
= 0;
966 int xid_map_hint
= 0;
969 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
971 struct ip
*ip
= NULL
;
973 struct ip6_hdr
*ip6
= NULL
;
975 struct xid_map_entry
*xmep
;
977 if (!TTEST(rp
->rm_call
.cb_vers
))
979 switch (IP_V((struct ip
*)bp
)) {
981 ip
= (struct ip
*)bp
;
985 ip6
= (struct ip6_hdr
*)bp
;
992 xmep
= &xid_map
[xid_map_next
];
994 if (++xid_map_next
>= XIDMAPSIZE
)
997 xmep
->xid
= rp
->rm_xid
;
1000 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
1001 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
1006 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
1007 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
1010 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
1011 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
1016 * Returns 0 and puts NFSPROC_xxx in proc return and
1017 * version in vers return, or returns -1 on failure
1020 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
1024 struct xid_map_entry
*xmep
;
1025 u_int32_t xid
= rp
->rm_xid
;
1026 struct ip
*ip
= (struct ip
*)bp
;
1028 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
1032 /* Start searching from where we last left off */
1037 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
1039 switch (xmep
->ipver
) {
1041 if (memcmp(&ip
->ip_src
, &xmep
->server
,
1042 sizeof(ip
->ip_src
)) != 0 ||
1043 memcmp(&ip
->ip_dst
, &xmep
->client
,
1044 sizeof(ip
->ip_dst
)) != 0) {
1050 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
1051 sizeof(ip6
->ip6_src
)) != 0 ||
1052 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
1053 sizeof(ip6
->ip6_dst
)) != 0) {
1070 if (++i
>= XIDMAPSIZE
)
1072 } while (i
!= xid_map_hint
);
1079 * Routines for parsing reply packets
1083 * Return a pointer to the beginning of the actual results.
1084 * If the packet was truncated, return 0.
1086 static const u_int32_t
*
1087 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
1089 register const u_int32_t
*dp
;
1091 enum sunrpc_accept_stat astat
;
1095 * Here we find the address of the ar_verf credentials.
1096 * Originally, this calculation was
1097 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
1098 * On the wire, the rp_acpt field starts immediately after
1099 * the (32 bit) rp_stat field. However, rp_acpt (which is a
1100 * "struct accepted_reply") contains a "struct opaque_auth",
1101 * whose internal representation contains a pointer, so on a
1102 * 64-bit machine the compiler inserts 32 bits of padding
1103 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
1104 * the internal representation to parse the on-the-wire
1105 * representation. Instead, we skip past the rp_stat field,
1106 * which is an "enum" and so occupies one 32-bit word.
1108 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
1110 len
= EXTRACT_32BITS(&dp
[1]);
1114 * skip past the ar_verf credentials.
1116 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
1120 * now we can check the ar_stat field
1122 astat
= (enum sunrpc_accept_stat
) EXTRACT_32BITS(dp
);
1125 case SUNRPC_SUCCESS
:
1128 case SUNRPC_PROG_UNAVAIL
:
1129 printf(" PROG_UNAVAIL");
1130 nfserr
= 1; /* suppress trunc string */
1133 case SUNRPC_PROG_MISMATCH
:
1134 printf(" PROG_MISMATCH");
1135 nfserr
= 1; /* suppress trunc string */
1138 case SUNRPC_PROC_UNAVAIL
:
1139 printf(" PROC_UNAVAIL");
1140 nfserr
= 1; /* suppress trunc string */
1143 case SUNRPC_GARBAGE_ARGS
:
1144 printf(" GARBAGE_ARGS");
1145 nfserr
= 1; /* suppress trunc string */
1148 case SUNRPC_SYSTEM_ERR
:
1149 printf(" SYSTEM_ERR");
1150 nfserr
= 1; /* suppress trunc string */
1154 printf(" ar_stat %d", astat
);
1155 nfserr
= 1; /* suppress trunc string */
1158 /* successful return */
1159 TCHECK2(*dp
, sizeof(astat
));
1160 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1165 static const u_int32_t
*
1166 parsestatus(const u_int32_t
*dp
, int *er
)
1172 errnum
= EXTRACT_32BITS(&dp
[0]);
1177 printf(" ERROR: %s",
1178 tok2str(status2str
, "unk %d", errnum
));
1186 static const u_int32_t
*
1187 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1189 const struct nfs_fattr
*fap
;
1191 fap
= (const struct nfs_fattr
*)dp
;
1192 TCHECK(fap
->fa_gid
);
1194 printf(" %s %o ids %d/%d",
1195 tok2str(type2str
, "unk-ft %d ",
1196 EXTRACT_32BITS(&fap
->fa_type
)),
1197 EXTRACT_32BITS(&fap
->fa_mode
),
1198 EXTRACT_32BITS(&fap
->fa_uid
),
1199 EXTRACT_32BITS(&fap
->fa_gid
));
1201 TCHECK(fap
->fa3_size
);
1202 printf(" sz %" PRIu64
,
1203 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1205 TCHECK(fap
->fa2_size
);
1206 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1209 /* print lots more stuff */
1212 TCHECK(fap
->fa3_ctime
);
1213 printf(" nlink %d rdev %d/%d",
1214 EXTRACT_32BITS(&fap
->fa_nlink
),
1215 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1216 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1217 printf(" fsid %" PRIx64
,
1218 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1219 printf(" fileid %" PRIx64
,
1220 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1221 printf(" a/m/ctime %u.%06u",
1222 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1223 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1225 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1226 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1228 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1229 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1231 TCHECK(fap
->fa2_ctime
);
1232 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1233 EXTRACT_32BITS(&fap
->fa_nlink
),
1234 EXTRACT_32BITS(&fap
->fa2_rdev
),
1235 EXTRACT_32BITS(&fap
->fa2_fsid
),
1236 EXTRACT_32BITS(&fap
->fa2_fileid
));
1238 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1239 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1241 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1242 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1244 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1245 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1248 return ((const u_int32_t
*)((unsigned char *)dp
+
1249 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1255 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1259 dp
= parsestatus(dp
, &er
);
1265 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1269 parsediropres(const u_int32_t
*dp
)
1273 if (!(dp
= parsestatus(dp
, &er
)))
1278 dp
= parsefh(dp
, 0);
1282 return (parsefattr(dp
, vflag
, 0) != NULL
);
1286 parselinkres(const u_int32_t
*dp
, int v3
)
1290 dp
= parsestatus(dp
, &er
);
1295 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1298 return (parsefn(dp
) != NULL
);
1302 parsestatfs(const u_int32_t
*dp
, int v3
)
1304 const struct nfs_statfs
*sfsp
;
1307 dp
= parsestatus(dp
, &er
);
1319 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1323 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1325 sfsp
= (const struct nfs_statfs
*)dp
;
1328 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1329 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1330 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1331 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1333 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1334 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1335 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1336 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1337 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1340 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1341 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1342 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1343 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1344 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1345 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1354 parserddires(const u_int32_t
*dp
)
1358 dp
= parsestatus(dp
, &er
);
1367 printf(" offset %x size %d ",
1368 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1377 static const u_int32_t
*
1378 parse_wcc_attr(const u_int32_t
*dp
)
1380 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1381 printf(" mtime %u.%06u ctime %u.%06u",
1382 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1383 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1388 * Pre operation attributes. Print only if vflag > 1.
1390 static const u_int32_t
*
1391 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1394 if (!EXTRACT_32BITS(&dp
[0]))
1399 return parse_wcc_attr(dp
);
1401 /* If not verbose enough, just skip over wcc_attr */
1409 * Post operation attributes are printed if vflag >= 1
1411 static const u_int32_t
*
1412 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1415 if (!EXTRACT_32BITS(&dp
[0]))
1419 return parsefattr(dp
, verbose
, 1);
1421 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1426 static const u_int32_t
*
1427 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1431 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1436 return parse_post_op_attr(dp
, verbose
);
1439 static const u_int32_t
*
1440 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1444 if (!(dp
= parsestatus(dp
, &er
)))
1447 dp
= parse_wcc_data(dp
, verbose
);
1450 if (!EXTRACT_32BITS(&dp
[0]))
1453 if (!(dp
= parsefh(dp
, 1)))
1456 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1459 printf(" dir attr:");
1460 dp
= parse_wcc_data(dp
, verbose
);
1470 parsewccres(const u_int32_t
*dp
, int verbose
)
1474 if (!(dp
= parsestatus(dp
, &er
)))
1476 return parse_wcc_data(dp
, verbose
) != 0;
1479 static const u_int32_t
*
1480 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1484 if (!(dp
= parsestatus(dp
, &er
)))
1488 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1494 printf(" verf %08x%08x", dp
[0], dp
[1]);
1503 parsefsinfo(const u_int32_t
*dp
)
1505 struct nfsv3_fsinfo
*sfp
;
1508 if (!(dp
= parsestatus(dp
, &er
)))
1512 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1517 sfp
= (struct nfsv3_fsinfo
*)dp
;
1519 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1520 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1521 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1522 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1523 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1524 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1526 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1527 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1528 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1529 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1530 printf(" delta %u.%06u ",
1531 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1532 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1540 parsepathconf(const u_int32_t
*dp
)
1543 struct nfsv3_pathconf
*spp
;
1545 if (!(dp
= parsestatus(dp
, &er
)))
1549 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1554 spp
= (struct nfsv3_pathconf
*)dp
;
1557 printf(" linkmax %u namemax %u %s %s %s %s",
1558 EXTRACT_32BITS(&spp
->pc_linkmax
),
1559 EXTRACT_32BITS(&spp
->pc_namemax
),
1560 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1561 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1562 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1563 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1570 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1572 register const u_int32_t
*dp
;
1576 v3
= (vers
== NFS_VER3
);
1578 if (!v3
&& proc
< NFS_NPROCS
)
1579 proc
= nfsv3_procid
[proc
];
1591 case NFSPROC_GETATTR
:
1593 dp
= parserep(rp
, length
);
1594 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1598 case NFSPROC_SETATTR
:
1600 if (!(dp
= parserep(rp
, length
)))
1603 if (parsewccres(dp
, vflag
))
1606 if (parseattrstat(dp
, !qflag
, 0) != 0)
1611 case NFSPROC_LOOKUP
:
1613 if (!(dp
= parserep(rp
, length
)))
1616 if (!(dp
= parsestatus(dp
, &er
)))
1620 printf(" post dattr:");
1621 dp
= parse_post_op_attr(dp
, vflag
);
1624 if (!(dp
= parsefh(dp
, v3
)))
1626 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1628 printf(" post dattr:");
1629 dp
= parse_post_op_attr(dp
, vflag
);
1635 if (parsediropres(dp
) != 0)
1640 case NFSPROC_ACCESS
:
1642 if (!(dp
= parserep(rp
, length
)))
1644 if (!(dp
= parsestatus(dp
, &er
)))
1648 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1651 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1654 case NFSPROC_READLINK
:
1655 printf(" readlink");
1656 dp
= parserep(rp
, length
);
1657 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1663 if (!(dp
= parserep(rp
, length
)))
1666 if (!(dp
= parsestatus(dp
, &er
)))
1668 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1674 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1675 if (EXTRACT_32BITS(&dp
[1]))
1680 if (parseattrstat(dp
, vflag
, 0) != 0)
1687 if (!(dp
= parserep(rp
, length
)))
1690 if (!(dp
= parsestatus(dp
, &er
)))
1692 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1698 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1702 tok2str(nfsv3_writemodes
,
1703 NULL
, EXTRACT_32BITS(&dp
[1])));
1708 if (parseattrstat(dp
, vflag
, v3
) != 0)
1713 case NFSPROC_CREATE
:
1715 if (!(dp
= parserep(rp
, length
)))
1718 if (parsecreateopres(dp
, vflag
) != 0)
1721 if (parsediropres(dp
) != 0)
1728 if (!(dp
= parserep(rp
, length
)))
1731 if (parsecreateopres(dp
, vflag
) != 0)
1734 if (parsediropres(dp
) != 0)
1739 case NFSPROC_SYMLINK
:
1741 if (!(dp
= parserep(rp
, length
)))
1744 if (parsecreateopres(dp
, vflag
) != 0)
1747 if (parsestatus(dp
, &er
) != 0)
1754 if (!(dp
= parserep(rp
, length
)))
1756 if (parsecreateopres(dp
, vflag
) != 0)
1760 case NFSPROC_REMOVE
:
1762 if (!(dp
= parserep(rp
, length
)))
1765 if (parsewccres(dp
, vflag
))
1768 if (parsestatus(dp
, &er
) != 0)
1775 if (!(dp
= parserep(rp
, length
)))
1778 if (parsewccres(dp
, vflag
))
1781 if (parsestatus(dp
, &er
) != 0)
1786 case NFSPROC_RENAME
:
1788 if (!(dp
= parserep(rp
, length
)))
1791 if (!(dp
= parsestatus(dp
, &er
)))
1795 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1798 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1803 if (parsestatus(dp
, &er
) != 0)
1810 if (!(dp
= parserep(rp
, length
)))
1813 if (!(dp
= parsestatus(dp
, &er
)))
1816 printf(" file POST:");
1817 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1820 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1825 if (parsestatus(dp
, &er
) != 0)
1830 case NFSPROC_READDIR
:
1832 if (!(dp
= parserep(rp
, length
)))
1835 if (parsev3rddirres(dp
, vflag
))
1838 if (parserddires(dp
) != 0)
1843 case NFSPROC_READDIRPLUS
:
1844 printf(" readdirplus");
1845 if (!(dp
= parserep(rp
, length
)))
1847 if (parsev3rddirres(dp
, vflag
))
1851 case NFSPROC_FSSTAT
:
1853 dp
= parserep(rp
, length
);
1854 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1858 case NFSPROC_FSINFO
:
1860 dp
= parserep(rp
, length
);
1861 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1865 case NFSPROC_PATHCONF
:
1866 printf(" pathconf");
1867 dp
= parserep(rp
, length
);
1868 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1872 case NFSPROC_COMMIT
:
1874 dp
= parserep(rp
, length
);
1875 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1880 printf(" proc-%u", proc
);
1885 fputs(" [|nfs]", stdout
);