]>
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 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 struct nfsv3_sattr sa3
;
512 char srcid
[20], dstid
[20]; /*fits 32bit*/
514 nfserr
= 0; /* assume no error */
515 rp
= (const struct sunrpc_msg
*)bp
;
519 snprintf(srcid
, sizeof(srcid
), "%u",
520 EXTRACT_32BITS(&rp
->rm_xid
));
521 strlcpy(dstid
, "nfs", sizeof(dstid
));
523 snprintf(srcid
, sizeof(srcid
), "%u",
524 EXTRACT_32BITS(&rp
->rm_xid
));
525 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
527 print_nfsaddr(bp2
, srcid
, dstid
);
528 (void)printf("%d", length
);
530 if (!xid_map_enter(rp
, bp2
)) /* record proc number for later on */
533 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
534 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
536 if (!v3
&& proc
< NFS_NPROCS
)
537 proc
= nfsv3_procid
[proc
];
547 case NFSPROC_GETATTR
:
549 if ((dp
= parsereq(rp
, length
)) != NULL
&&
550 parsefh(dp
, v3
) != NULL
)
554 case NFSPROC_SETATTR
:
556 if ((dp
= parsereq(rp
, length
)) != NULL
&&
557 parsefh(dp
, v3
) != NULL
)
563 if ((dp
= parsereq(rp
, length
)) != NULL
&&
564 parsefhn(dp
, v3
) != NULL
)
570 if ((dp
= parsereq(rp
, length
)) != NULL
&&
571 (dp
= parsefh(dp
, v3
)) != NULL
) {
573 printf(" %04x", EXTRACT_32BITS(&dp
[0]));
578 case NFSPROC_READLINK
:
580 if ((dp
= parsereq(rp
, length
)) != NULL
&&
581 parsefh(dp
, v3
) != NULL
)
587 if ((dp
= parsereq(rp
, length
)) != NULL
&&
588 (dp
= parsefh(dp
, v3
)) != NULL
) {
591 printf(" %u bytes @ %" PRIu64
,
592 EXTRACT_32BITS(&dp
[2]),
593 EXTRACT_64BITS(&dp
[0]));
596 printf(" %u bytes @ %u",
597 EXTRACT_32BITS(&dp
[1]),
598 EXTRACT_32BITS(&dp
[0]));
606 if ((dp
= parsereq(rp
, length
)) != NULL
&&
607 (dp
= parsefh(dp
, v3
)) != NULL
) {
610 printf(" %u (%u) bytes @ %" PRIu64
,
611 EXTRACT_32BITS(&dp
[4]),
612 EXTRACT_32BITS(&dp
[2]),
613 EXTRACT_64BITS(&dp
[0]));
618 tok2str(nfsv3_writemodes
,
619 NULL
, EXTRACT_32BITS(dp
)));
623 printf(" %u (%u) bytes @ %u (%u)",
624 EXTRACT_32BITS(&dp
[3]),
625 EXTRACT_32BITS(&dp
[2]),
626 EXTRACT_32BITS(&dp
[1]),
627 EXTRACT_32BITS(&dp
[0]));
635 if ((dp
= parsereq(rp
, length
)) != NULL
&&
636 parsefhn(dp
, v3
) != NULL
)
642 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
646 case NFSPROC_SYMLINK
:
648 if ((dp
= parsereq(rp
, length
)) != 0 &&
649 (dp
= parsefhn(dp
, v3
)) != 0) {
650 fputs(" ->", stdout
);
651 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
653 if (parsefn(dp
) == 0)
656 print_sattr3(&sa3
, vflag
);
663 if ((dp
= parsereq(rp
, length
)) != 0 &&
664 (dp
= parsefhn(dp
, v3
)) != 0) {
666 type
= (nfs_type
)EXTRACT_32BITS(dp
);
668 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
670 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
671 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
674 EXTRACT_32BITS(&dp
[0]),
675 EXTRACT_32BITS(&dp
[1]));
679 print_sattr3(&sa3
, vflag
);
686 if ((dp
= parsereq(rp
, length
)) != NULL
&&
687 parsefhn(dp
, v3
) != NULL
)
693 if ((dp
= parsereq(rp
, length
)) != NULL
&&
694 parsefhn(dp
, v3
) != NULL
)
700 if ((dp
= parsereq(rp
, length
)) != NULL
&&
701 (dp
= parsefhn(dp
, v3
)) != NULL
) {
702 fputs(" ->", stdout
);
703 if (parsefhn(dp
, v3
) != NULL
)
710 if ((dp
= parsereq(rp
, length
)) != NULL
&&
711 (dp
= parsefh(dp
, v3
)) != NULL
) {
712 fputs(" ->", stdout
);
713 if (parsefhn(dp
, v3
) != NULL
)
718 case NFSPROC_READDIR
:
720 if ((dp
= parsereq(rp
, length
)) != NULL
&&
721 (dp
= parsefh(dp
, v3
)) != NULL
) {
725 * We shouldn't really try to interpret the
726 * offset cookie here.
728 printf(" %u bytes @ %" PRId64
,
729 EXTRACT_32BITS(&dp
[4]),
730 EXTRACT_64BITS(&dp
[0]));
732 printf(" verf %08x%08x", dp
[2],
737 * Print the offset as signed, since -1 is
738 * common, but offsets > 2^31 aren't.
740 printf(" %u bytes @ %d",
741 EXTRACT_32BITS(&dp
[1]),
742 EXTRACT_32BITS(&dp
[0]));
748 case NFSPROC_READDIRPLUS
:
749 printf(" readdirplus");
750 if ((dp
= parsereq(rp
, length
)) != NULL
&&
751 (dp
= parsefh(dp
, v3
)) != NULL
) {
754 * We don't try to interpret the offset
757 printf(" %u bytes @ %" PRId64
,
758 EXTRACT_32BITS(&dp
[4]),
759 EXTRACT_64BITS(&dp
[0]));
762 printf(" max %u verf %08x%08x",
763 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
771 if ((dp
= parsereq(rp
, length
)) != NULL
&&
772 parsefh(dp
, v3
) != NULL
)
778 if ((dp
= parsereq(rp
, length
)) != NULL
&&
779 parsefh(dp
, v3
) != NULL
)
783 case NFSPROC_PATHCONF
:
785 if ((dp
= parsereq(rp
, length
)) != NULL
&&
786 parsefh(dp
, v3
) != NULL
)
792 if ((dp
= parsereq(rp
, length
)) != NULL
&&
793 (dp
= parsefh(dp
, v3
)) != NULL
) {
795 printf(" %u bytes @ %" PRIu64
,
796 EXTRACT_32BITS(&dp
[2]),
797 EXTRACT_64BITS(&dp
[0]));
803 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
809 fputs(" [|nfs]", stdout
);
813 * Print out an NFS file handle.
814 * We assume packet was not truncated before the end of the
815 * file handle pointed to by dp.
817 * Note: new version (using portable file-handle parser) doesn't produce
818 * generation number. It probably could be made to do that, with some
819 * additional hacking on the parser code.
822 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
826 const char *sfsname
= NULL
;
831 char const *sep
= "";
834 for (i
=0; i
<len
; i
++) {
835 (void)printf("%s%x", sep
, dp
[i
]);
842 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
845 /* file system ID is ASCII, not numeric, for this server OS */
846 static char temp
[NFSX_V3FHMAX
+1];
848 /* Make sure string is null-terminated */
849 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
850 temp
[sizeof(temp
) - 1] = '\0';
851 /* Remove trailing spaces */
852 spacep
= strchr(temp
, ' ');
856 (void)printf(" fh %s/", temp
);
858 (void)printf(" fh %d,%d/",
859 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
862 if(fsid
.Fsid_dev
.Minor
== 257)
863 /* Print the undecoded handle */
864 (void)printf("%s", fsid
.Opaque_Handle
);
866 (void)printf("%ld", (long) ino
);
870 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
871 * us to match up replies with requests and thus to know how to parse
875 struct xid_map_entry
{
876 u_int32_t xid
; /* transaction ID (net order) */
877 int ipver
; /* IP version (4 or 6) */
879 struct in6_addr client
; /* client IP address (net order) */
880 struct in6_addr server
; /* server IP address (net order) */
882 struct in_addr client
; /* client IP address (net order) */
883 struct in_addr server
; /* server IP address (net order) */
885 u_int32_t proc
; /* call proc number (host order) */
886 u_int32_t vers
; /* program version (host order) */
890 * Map entries are kept in an array that we manage as a ring;
891 * new entries are always added at the tail of the ring. Initially,
892 * all the entries are zero and hence don't match anything.
895 #define XIDMAPSIZE 64
897 struct xid_map_entry xid_map
[XIDMAPSIZE
];
899 int xid_map_next
= 0;
900 int xid_map_hint
= 0;
903 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
905 struct ip
*ip
= NULL
;
907 struct ip6_hdr
*ip6
= NULL
;
909 struct xid_map_entry
*xmep
;
911 if (!TTEST(rp
->rm_call
.cb_vers
))
913 switch (IP_V((struct ip
*)bp
)) {
915 ip
= (struct ip
*)bp
;
919 ip6
= (struct ip6_hdr
*)bp
;
926 xmep
= &xid_map
[xid_map_next
];
928 if (++xid_map_next
>= XIDMAPSIZE
)
931 xmep
->xid
= rp
->rm_xid
;
934 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
935 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
940 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
941 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
944 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
945 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
950 * Returns 0 and puts NFSPROC_xxx in proc return and
951 * version in vers return, or returns -1 on failure
954 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
958 struct xid_map_entry
*xmep
;
959 u_int32_t xid
= rp
->rm_xid
;
960 struct ip
*ip
= (struct ip
*)bp
;
962 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
966 /* Start searching from where we last left off */
971 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
973 switch (xmep
->ipver
) {
975 if (memcmp(&ip
->ip_src
, &xmep
->server
,
976 sizeof(ip
->ip_src
)) != 0 ||
977 memcmp(&ip
->ip_dst
, &xmep
->client
,
978 sizeof(ip
->ip_dst
)) != 0) {
984 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
985 sizeof(ip6
->ip6_src
)) != 0 ||
986 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
987 sizeof(ip6
->ip6_dst
)) != 0) {
1004 if (++i
>= XIDMAPSIZE
)
1006 } while (i
!= xid_map_hint
);
1013 * Routines for parsing reply packets
1017 * Return a pointer to the beginning of the actual results.
1018 * If the packet was truncated, return 0.
1020 static const u_int32_t
*
1021 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
1023 register const u_int32_t
*dp
;
1025 enum sunrpc_accept_stat astat
;
1029 * Here we find the address of the ar_verf credentials.
1030 * Originally, this calculation was
1031 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
1032 * On the wire, the rp_acpt field starts immediately after
1033 * the (32 bit) rp_stat field. However, rp_acpt (which is a
1034 * "struct accepted_reply") contains a "struct opaque_auth",
1035 * whose internal representation contains a pointer, so on a
1036 * 64-bit machine the compiler inserts 32 bits of padding
1037 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
1038 * the internal representation to parse the on-the-wire
1039 * representation. Instead, we skip past the rp_stat field,
1040 * which is an "enum" and so occupies one 32-bit word.
1042 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
1044 len
= EXTRACT_32BITS(&dp
[1]);
1048 * skip past the ar_verf credentials.
1050 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
1054 * now we can check the ar_stat field
1056 astat
= (enum sunrpc_accept_stat
) EXTRACT_32BITS(dp
);
1059 case SUNRPC_SUCCESS
:
1062 case SUNRPC_PROG_UNAVAIL
:
1063 printf(" PROG_UNAVAIL");
1064 nfserr
= 1; /* suppress trunc string */
1067 case SUNRPC_PROG_MISMATCH
:
1068 printf(" PROG_MISMATCH");
1069 nfserr
= 1; /* suppress trunc string */
1072 case SUNRPC_PROC_UNAVAIL
:
1073 printf(" PROC_UNAVAIL");
1074 nfserr
= 1; /* suppress trunc string */
1077 case SUNRPC_GARBAGE_ARGS
:
1078 printf(" GARBAGE_ARGS");
1079 nfserr
= 1; /* suppress trunc string */
1082 case SUNRPC_SYSTEM_ERR
:
1083 printf(" SYSTEM_ERR");
1084 nfserr
= 1; /* suppress trunc string */
1088 printf(" ar_stat %d", astat
);
1089 nfserr
= 1; /* suppress trunc string */
1092 /* successful return */
1093 TCHECK2(*dp
, sizeof(astat
));
1094 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1099 static const u_int32_t
*
1100 parsestatus(const u_int32_t
*dp
, int *er
)
1106 errnum
= EXTRACT_32BITS(&dp
[0]);
1111 printf(" ERROR: %s",
1112 tok2str(status2str
, "unk %d", errnum
));
1120 static const u_int32_t
*
1121 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1123 const struct nfs_fattr
*fap
;
1125 fap
= (const struct nfs_fattr
*)dp
;
1126 TCHECK(fap
->fa_gid
);
1128 printf(" %s %o ids %d/%d",
1129 tok2str(type2str
, "unk-ft %d ",
1130 EXTRACT_32BITS(&fap
->fa_type
)),
1131 EXTRACT_32BITS(&fap
->fa_mode
),
1132 EXTRACT_32BITS(&fap
->fa_uid
),
1133 EXTRACT_32BITS(&fap
->fa_gid
));
1135 TCHECK(fap
->fa3_size
);
1136 printf(" sz %" PRIu64
,
1137 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1139 TCHECK(fap
->fa2_size
);
1140 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1143 /* print lots more stuff */
1146 TCHECK(fap
->fa3_ctime
);
1147 printf(" nlink %d rdev %d/%d",
1148 EXTRACT_32BITS(&fap
->fa_nlink
),
1149 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1150 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1151 printf(" fsid %" PRIx64
,
1152 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1153 printf(" fileid %" PRIx64
,
1154 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1155 printf(" a/m/ctime %u.%06u",
1156 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1157 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1159 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1160 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1162 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1163 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1165 TCHECK(fap
->fa2_ctime
);
1166 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1167 EXTRACT_32BITS(&fap
->fa_nlink
),
1168 EXTRACT_32BITS(&fap
->fa2_rdev
),
1169 EXTRACT_32BITS(&fap
->fa2_fsid
),
1170 EXTRACT_32BITS(&fap
->fa2_fileid
));
1172 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1173 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1175 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1176 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1178 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1179 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1182 return ((const u_int32_t
*)((unsigned char *)dp
+
1183 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1189 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1193 dp
= parsestatus(dp
, &er
);
1199 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1203 parsediropres(const u_int32_t
*dp
)
1207 if (!(dp
= parsestatus(dp
, &er
)))
1212 dp
= parsefh(dp
, 0);
1216 return (parsefattr(dp
, vflag
, 0) != NULL
);
1220 parselinkres(const u_int32_t
*dp
, int v3
)
1224 dp
= parsestatus(dp
, &er
);
1229 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1232 return (parsefn(dp
) != NULL
);
1236 parsestatfs(const u_int32_t
*dp
, int v3
)
1238 const struct nfs_statfs
*sfsp
;
1241 dp
= parsestatus(dp
, &er
);
1253 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1257 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1259 sfsp
= (const struct nfs_statfs
*)dp
;
1262 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1263 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1264 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1265 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1267 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1268 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1269 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1270 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1271 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1274 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1275 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1276 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1277 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1278 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1279 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1288 parserddires(const u_int32_t
*dp
)
1292 dp
= parsestatus(dp
, &er
);
1301 printf(" offset %x size %d ",
1302 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1311 static const u_int32_t
*
1312 parse_wcc_attr(const u_int32_t
*dp
)
1314 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1315 printf(" mtime %u.%06u ctime %u.%06u",
1316 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1317 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1322 * Pre operation attributes. Print only if vflag > 1.
1324 static const u_int32_t
*
1325 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1328 if (!EXTRACT_32BITS(&dp
[0]))
1333 return parse_wcc_attr(dp
);
1335 /* If not verbose enough, just skip over wcc_attr */
1343 * Post operation attributes are printed if vflag >= 1
1345 static const u_int32_t
*
1346 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1349 if (!EXTRACT_32BITS(&dp
[0]))
1353 return parsefattr(dp
, verbose
, 1);
1355 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1360 static const u_int32_t
*
1361 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1365 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1370 return parse_post_op_attr(dp
, verbose
);
1373 static const u_int32_t
*
1374 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1378 if (!(dp
= parsestatus(dp
, &er
)))
1381 dp
= parse_wcc_data(dp
, verbose
);
1384 if (!EXTRACT_32BITS(&dp
[0]))
1387 if (!(dp
= parsefh(dp
, 1)))
1390 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1393 printf(" dir attr:");
1394 dp
= parse_wcc_data(dp
, verbose
);
1404 parsewccres(const u_int32_t
*dp
, int verbose
)
1408 if (!(dp
= parsestatus(dp
, &er
)))
1410 return parse_wcc_data(dp
, verbose
) != 0;
1413 static const u_int32_t
*
1414 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1418 if (!(dp
= parsestatus(dp
, &er
)))
1422 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1428 printf(" verf %08x%08x", dp
[0], dp
[1]);
1437 parsefsinfo(const u_int32_t
*dp
)
1439 struct nfsv3_fsinfo
*sfp
;
1442 if (!(dp
= parsestatus(dp
, &er
)))
1446 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1451 sfp
= (struct nfsv3_fsinfo
*)dp
;
1453 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1454 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1455 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1456 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1457 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1458 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1460 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1461 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1462 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1463 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1464 printf(" delta %u.%06u ",
1465 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1466 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1474 parsepathconf(const u_int32_t
*dp
)
1477 struct nfsv3_pathconf
*spp
;
1479 if (!(dp
= parsestatus(dp
, &er
)))
1483 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1488 spp
= (struct nfsv3_pathconf
*)dp
;
1491 printf(" linkmax %u namemax %u %s %s %s %s",
1492 EXTRACT_32BITS(&spp
->pc_linkmax
),
1493 EXTRACT_32BITS(&spp
->pc_namemax
),
1494 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1495 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1496 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1497 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1504 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1506 register const u_int32_t
*dp
;
1510 v3
= (vers
== NFS_VER3
);
1512 if (!v3
&& proc
< NFS_NPROCS
)
1513 proc
= nfsv3_procid
[proc
];
1525 case NFSPROC_GETATTR
:
1527 dp
= parserep(rp
, length
);
1528 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1532 case NFSPROC_SETATTR
:
1534 if (!(dp
= parserep(rp
, length
)))
1537 if (parsewccres(dp
, vflag
))
1540 if (parseattrstat(dp
, !qflag
, 0) != 0)
1545 case NFSPROC_LOOKUP
:
1547 if (!(dp
= parserep(rp
, length
)))
1550 if (!(dp
= parsestatus(dp
, &er
)))
1554 printf(" post dattr:");
1555 dp
= parse_post_op_attr(dp
, vflag
);
1558 if (!(dp
= parsefh(dp
, v3
)))
1560 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1562 printf(" post dattr:");
1563 dp
= parse_post_op_attr(dp
, vflag
);
1569 if (parsediropres(dp
) != 0)
1574 case NFSPROC_ACCESS
:
1576 if (!(dp
= parserep(rp
, length
)))
1578 if (!(dp
= parsestatus(dp
, &er
)))
1582 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1585 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1588 case NFSPROC_READLINK
:
1589 printf(" readlink");
1590 dp
= parserep(rp
, length
);
1591 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1597 if (!(dp
= parserep(rp
, length
)))
1600 if (!(dp
= parsestatus(dp
, &er
)))
1602 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1608 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1609 if (EXTRACT_32BITS(&dp
[1]))
1614 if (parseattrstat(dp
, vflag
, 0) != 0)
1621 if (!(dp
= parserep(rp
, length
)))
1624 if (!(dp
= parsestatus(dp
, &er
)))
1626 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1632 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1636 tok2str(nfsv3_writemodes
,
1637 NULL
, EXTRACT_32BITS(&dp
[1])));
1642 if (parseattrstat(dp
, vflag
, v3
) != 0)
1647 case NFSPROC_CREATE
:
1649 if (!(dp
= parserep(rp
, length
)))
1652 if (parsecreateopres(dp
, vflag
) != 0)
1655 if (parsediropres(dp
) != 0)
1662 if (!(dp
= parserep(rp
, length
)))
1665 if (parsecreateopres(dp
, vflag
) != 0)
1668 if (parsediropres(dp
) != 0)
1673 case NFSPROC_SYMLINK
:
1675 if (!(dp
= parserep(rp
, length
)))
1678 if (parsecreateopres(dp
, vflag
) != 0)
1681 if (parsestatus(dp
, &er
) != 0)
1688 if (!(dp
= parserep(rp
, length
)))
1690 if (parsecreateopres(dp
, vflag
) != 0)
1694 case NFSPROC_REMOVE
:
1696 if (!(dp
= parserep(rp
, length
)))
1699 if (parsewccres(dp
, vflag
))
1702 if (parsestatus(dp
, &er
) != 0)
1709 if (!(dp
= parserep(rp
, length
)))
1712 if (parsewccres(dp
, vflag
))
1715 if (parsestatus(dp
, &er
) != 0)
1720 case NFSPROC_RENAME
:
1722 if (!(dp
= parserep(rp
, length
)))
1725 if (!(dp
= parsestatus(dp
, &er
)))
1729 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1732 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1737 if (parsestatus(dp
, &er
) != 0)
1744 if (!(dp
= parserep(rp
, length
)))
1747 if (!(dp
= parsestatus(dp
, &er
)))
1750 printf(" file POST:");
1751 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1754 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1759 if (parsestatus(dp
, &er
) != 0)
1764 case NFSPROC_READDIR
:
1766 if (!(dp
= parserep(rp
, length
)))
1769 if (parsev3rddirres(dp
, vflag
))
1772 if (parserddires(dp
) != 0)
1777 case NFSPROC_READDIRPLUS
:
1778 printf(" readdirplus");
1779 if (!(dp
= parserep(rp
, length
)))
1781 if (parsev3rddirres(dp
, vflag
))
1785 case NFSPROC_FSSTAT
:
1787 dp
= parserep(rp
, length
);
1788 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1792 case NFSPROC_FSINFO
:
1794 dp
= parserep(rp
, length
);
1795 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1799 case NFSPROC_PATHCONF
:
1800 printf(" pathconf");
1801 dp
= parserep(rp
, length
);
1802 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1806 case NFSPROC_COMMIT
:
1808 dp
= parserep(rp
, length
);
1809 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1814 printf(" proc-%u", proc
);
1819 fputs(" [|nfs]", stdout
);