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.106.2.4 2007/06/15 23:17:40 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 void 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
;
301 strlcpy(srcid
, "nfs", sizeof(srcid
));
302 snprintf(dstid
, sizeof(dstid
), "%u",
303 EXTRACT_32BITS(&rp
->rm_xid
));
305 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
306 snprintf(dstid
, sizeof(dstid
), "%u",
307 EXTRACT_32BITS(&rp
->rm_xid
));
309 print_nfsaddr(bp2
, srcid
, dstid
);
310 reply_stat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_stat
);
311 switch (reply_stat
) {
313 case SUNRPC_MSG_ACCEPTED
:
314 (void)printf("reply ok %u", length
);
315 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
316 interp_reply(rp
, proc
, vers
, length
);
319 case SUNRPC_MSG_DENIED
:
320 (void)printf("reply ERR %u: ", length
);
321 rstat
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_stat
);
324 case SUNRPC_RPC_MISMATCH
:
325 rlow
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.low
);
326 rhigh
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_vers
.high
);
327 (void)printf("RPC Version mismatch (%u-%u)",
331 case SUNRPC_AUTH_ERROR
:
332 rwhy
= EXTRACT_32BITS(&rp
->rm_reply
.rp_reject
.rj_why
);
333 (void)printf("Auth ");
340 case SUNRPC_AUTH_BADCRED
:
341 (void)printf("Bogus Credentials (seal broken)");
344 case SUNRPC_AUTH_REJECTEDCRED
:
345 (void)printf("Rejected Credentials (client should begin new session)");
348 case SUNRPC_AUTH_BADVERF
:
349 (void)printf("Bogus Verifier (seal broken)");
352 case SUNRPC_AUTH_REJECTEDVERF
:
353 (void)printf("Verifier expired or was replayed");
356 case SUNRPC_AUTH_TOOWEAK
:
357 (void)printf("Credentials are too weak");
360 case SUNRPC_AUTH_INVALIDRESP
:
361 (void)printf("Bogus response verifier");
364 case SUNRPC_AUTH_FAILED
:
365 (void)printf("Unknown failure");
369 (void)printf("Invalid failure code %u",
376 (void)printf("Unknown reason for rejecting rpc message %u",
377 (unsigned int)rstat
);
383 (void)printf("reply Unknown rpc response code=%u %u",
390 * Return a pointer to the first file handle in the packet.
391 * If the packet was truncated, return 0.
393 static const u_int32_t
*
394 parsereq(register const struct sunrpc_msg
*rp
, register u_int length
)
396 register const u_int32_t
*dp
;
400 * find the start of the req data (if we captured it)
402 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
404 len
= EXTRACT_32BITS(&dp
[1]);
406 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
408 len
= EXTRACT_32BITS(&dp
[1]);
410 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
420 * Print out an NFS file handle and return a pointer to following word.
421 * If packet was truncated, return 0.
423 static const u_int32_t
*
424 parsefh(register const u_int32_t
*dp
, int v3
)
430 len
= EXTRACT_32BITS(dp
) / 4;
435 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
436 nfs_printfh(dp
, len
);
444 * Print out a file name and return pointer to 32-bit word past it.
445 * If packet was truncated, return 0.
447 static const u_int32_t
*
448 parsefn(register const u_int32_t
*dp
)
450 register u_int32_t len
;
451 register const u_char
*cp
;
453 /* Bail if we don't have the string length */
456 /* Fetch string length; convert to host order */
460 TCHECK2(*dp
, ((len
+ 3) & ~3));
463 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
464 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
466 if (fn_printn(cp
, len
, snapend
)) {
478 * Print out file handle and file name.
479 * Return pointer to 32-bit word past file name.
480 * If packet was truncated (or there was some other error), return 0.
482 static const u_int32_t
*
483 parsefhn(register const u_int32_t
*dp
, int v3
)
485 dp
= parsefh(dp
, v3
);
489 return (parsefn(dp
));
493 nfsreq_print(register const u_char
*bp
, u_int length
,
494 register const u_char
*bp2
)
496 register const struct sunrpc_msg
*rp
;
497 register const u_int32_t
*dp
;
501 struct nfsv3_sattr sa3
;
502 char srcid
[20], dstid
[20]; /*fits 32bit*/
504 nfserr
= 0; /* assume no error */
505 rp
= (const struct sunrpc_msg
*)bp
;
507 snprintf(srcid
, sizeof(srcid
), "%u",
508 EXTRACT_32BITS(&rp
->rm_xid
));
509 strlcpy(dstid
, "nfs", sizeof(dstid
));
511 snprintf(srcid
, sizeof(srcid
), "%u",
512 EXTRACT_32BITS(&rp
->rm_xid
));
513 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
515 print_nfsaddr(bp2
, srcid
, dstid
);
516 (void)printf("%d", length
);
518 xid_map_enter(rp
, bp2
); /* record proc number for later on */
520 v3
= (EXTRACT_32BITS(&rp
->rm_call
.cb_vers
) == NFS_VER3
);
521 proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
523 if (!v3
&& proc
< NFS_NPROCS
)
524 proc
= nfsv3_procid
[proc
];
534 case NFSPROC_GETATTR
:
536 if ((dp
= parsereq(rp
, length
)) != NULL
&&
537 parsefh(dp
, v3
) != NULL
)
541 case NFSPROC_SETATTR
:
543 if ((dp
= parsereq(rp
, length
)) != NULL
&&
544 parsefh(dp
, v3
) != NULL
)
550 if ((dp
= parsereq(rp
, length
)) != NULL
&&
551 parsefhn(dp
, v3
) != NULL
)
557 if ((dp
= parsereq(rp
, length
)) != NULL
&&
558 (dp
= parsefh(dp
, v3
)) != NULL
) {
560 printf(" %04x", EXTRACT_32BITS(&dp
[0]));
565 case NFSPROC_READLINK
:
567 if ((dp
= parsereq(rp
, length
)) != NULL
&&
568 parsefh(dp
, v3
) != NULL
)
574 if ((dp
= parsereq(rp
, length
)) != NULL
&&
575 (dp
= parsefh(dp
, v3
)) != NULL
) {
578 printf(" %u bytes @ %" PRIu64
,
579 EXTRACT_32BITS(&dp
[2]),
580 EXTRACT_64BITS(&dp
[0]));
583 printf(" %u bytes @ %u",
584 EXTRACT_32BITS(&dp
[1]),
585 EXTRACT_32BITS(&dp
[0]));
593 if ((dp
= parsereq(rp
, length
)) != NULL
&&
594 (dp
= parsefh(dp
, v3
)) != NULL
) {
597 printf(" %u (%u) bytes @ %" PRIu64
,
598 EXTRACT_32BITS(&dp
[4]),
599 EXTRACT_32BITS(&dp
[2]),
600 EXTRACT_64BITS(&dp
[0]));
605 tok2str(nfsv3_writemodes
,
606 NULL
, EXTRACT_32BITS(dp
)));
610 printf(" %u (%u) bytes @ %u (%u)",
611 EXTRACT_32BITS(&dp
[3]),
612 EXTRACT_32BITS(&dp
[2]),
613 EXTRACT_32BITS(&dp
[1]),
614 EXTRACT_32BITS(&dp
[0]));
622 if ((dp
= parsereq(rp
, length
)) != NULL
&&
623 parsefhn(dp
, v3
) != NULL
)
629 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
633 case NFSPROC_SYMLINK
:
635 if ((dp
= parsereq(rp
, length
)) != 0 &&
636 (dp
= parsefhn(dp
, v3
)) != 0) {
637 fputs(" ->", stdout
);
638 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
640 if (parsefn(dp
) == 0)
643 print_sattr3(&sa3
, vflag
);
650 if ((dp
= parsereq(rp
, length
)) != 0 &&
651 (dp
= parsefhn(dp
, v3
)) != 0) {
653 type
= (nfs_type
)EXTRACT_32BITS(dp
);
655 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
657 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
658 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
661 EXTRACT_32BITS(&dp
[0]),
662 EXTRACT_32BITS(&dp
[1]));
666 print_sattr3(&sa3
, vflag
);
673 if ((dp
= parsereq(rp
, length
)) != NULL
&&
674 parsefhn(dp
, v3
) != NULL
)
680 if ((dp
= parsereq(rp
, length
)) != NULL
&&
681 parsefhn(dp
, v3
) != NULL
)
687 if ((dp
= parsereq(rp
, length
)) != NULL
&&
688 (dp
= parsefhn(dp
, v3
)) != NULL
) {
689 fputs(" ->", stdout
);
690 if (parsefhn(dp
, v3
) != NULL
)
697 if ((dp
= parsereq(rp
, length
)) != NULL
&&
698 (dp
= parsefh(dp
, v3
)) != NULL
) {
699 fputs(" ->", stdout
);
700 if (parsefhn(dp
, v3
) != NULL
)
705 case NFSPROC_READDIR
:
707 if ((dp
= parsereq(rp
, length
)) != NULL
&&
708 (dp
= parsefh(dp
, v3
)) != NULL
) {
712 * We shouldn't really try to interpret the
713 * offset cookie here.
715 printf(" %u bytes @ %" PRId64
,
716 EXTRACT_32BITS(&dp
[4]),
717 EXTRACT_64BITS(&dp
[0]));
719 printf(" verf %08x%08x", dp
[2],
724 * Print the offset as signed, since -1 is
725 * common, but offsets > 2^31 aren't.
727 printf(" %u bytes @ %d",
728 EXTRACT_32BITS(&dp
[1]),
729 EXTRACT_32BITS(&dp
[0]));
735 case NFSPROC_READDIRPLUS
:
736 printf(" readdirplus");
737 if ((dp
= parsereq(rp
, length
)) != NULL
&&
738 (dp
= parsefh(dp
, v3
)) != NULL
) {
741 * We don't try to interpret the offset
744 printf(" %u bytes @ %" PRId64
,
745 EXTRACT_32BITS(&dp
[4]),
746 EXTRACT_64BITS(&dp
[0]));
749 printf(" max %u verf %08x%08x",
750 EXTRACT_32BITS(&dp
[5]), dp
[2], dp
[3]);
758 if ((dp
= parsereq(rp
, length
)) != NULL
&&
759 parsefh(dp
, v3
) != NULL
)
765 if ((dp
= parsereq(rp
, length
)) != NULL
&&
766 parsefh(dp
, v3
) != NULL
)
770 case NFSPROC_PATHCONF
:
772 if ((dp
= parsereq(rp
, length
)) != NULL
&&
773 parsefh(dp
, v3
) != NULL
)
779 if ((dp
= parsereq(rp
, length
)) != NULL
&&
780 (dp
= parsefh(dp
, v3
)) != NULL
) {
782 printf(" %u bytes @ %" PRIu64
,
783 EXTRACT_32BITS(&dp
[2]),
784 EXTRACT_64BITS(&dp
[0]));
790 printf(" proc-%u", EXTRACT_32BITS(&rp
->rm_call
.cb_proc
));
796 fputs(" [|nfs]", stdout
);
800 * Print out an NFS file handle.
801 * We assume packet was not truncated before the end of the
802 * file handle pointed to by dp.
804 * Note: new version (using portable file-handle parser) doesn't produce
805 * generation number. It probably could be made to do that, with some
806 * additional hacking on the parser code.
809 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
813 const char *sfsname
= NULL
;
818 char const *sep
= "";
821 for (i
=0; i
<len
; i
++) {
822 (void)printf("%s%x", sep
, dp
[i
]);
829 Parse_fh((const u_char
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
832 /* file system ID is ASCII, not numeric, for this server OS */
833 static char temp
[NFSX_V3FHMAX
+1];
835 /* Make sure string is null-terminated */
836 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
837 temp
[sizeof(temp
) - 1] = '\0';
838 /* Remove trailing spaces */
839 spacep
= strchr(temp
, ' ');
843 (void)printf(" fh %s/", temp
);
845 (void)printf(" fh %d,%d/",
846 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
849 if(fsid
.Fsid_dev
.Minor
== 257)
850 /* Print the undecoded handle */
851 (void)printf("%s", fsid
.Opaque_Handle
);
853 (void)printf("%ld", (long) ino
);
857 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
858 * us to match up replies with requests and thus to know how to parse
862 struct xid_map_entry
{
863 u_int32_t xid
; /* transaction ID (net order) */
864 int ipver
; /* IP version (4 or 6) */
866 struct in6_addr client
; /* client IP address (net order) */
867 struct in6_addr server
; /* server IP address (net order) */
869 struct in_addr client
; /* client IP address (net order) */
870 struct in_addr server
; /* server IP address (net order) */
872 u_int32_t proc
; /* call proc number (host order) */
873 u_int32_t vers
; /* program version (host order) */
877 * Map entries are kept in an array that we manage as a ring;
878 * new entries are always added at the tail of the ring. Initially,
879 * all the entries are zero and hence don't match anything.
882 #define XIDMAPSIZE 64
884 struct xid_map_entry xid_map
[XIDMAPSIZE
];
886 int xid_map_next
= 0;
887 int xid_map_hint
= 0;
890 xid_map_enter(const struct sunrpc_msg
*rp
, const u_char
*bp
)
892 struct ip
*ip
= NULL
;
894 struct ip6_hdr
*ip6
= NULL
;
896 struct xid_map_entry
*xmep
;
898 switch (IP_V((struct ip
*)bp
)) {
900 ip
= (struct ip
*)bp
;
904 ip6
= (struct ip6_hdr
*)bp
;
911 xmep
= &xid_map
[xid_map_next
];
913 if (++xid_map_next
>= XIDMAPSIZE
)
916 xmep
->xid
= rp
->rm_xid
;
919 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
920 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
925 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
926 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
929 xmep
->proc
= EXTRACT_32BITS(&rp
->rm_call
.cb_proc
);
930 xmep
->vers
= EXTRACT_32BITS(&rp
->rm_call
.cb_vers
);
934 * Returns 0 and puts NFSPROC_xxx in proc return and
935 * version in vers return, or returns -1 on failure
938 xid_map_find(const struct sunrpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
942 struct xid_map_entry
*xmep
;
943 u_int32_t xid
= rp
->rm_xid
;
944 struct ip
*ip
= (struct ip
*)bp
;
946 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
950 /* Start searching from where we last left off */
955 if (xmep
->ipver
!= IP_V(ip
) || xmep
->xid
!= xid
)
957 switch (xmep
->ipver
) {
959 if (memcmp(&ip
->ip_src
, &xmep
->server
,
960 sizeof(ip
->ip_src
)) != 0 ||
961 memcmp(&ip
->ip_dst
, &xmep
->client
,
962 sizeof(ip
->ip_dst
)) != 0) {
968 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
969 sizeof(ip6
->ip6_src
)) != 0 ||
970 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
971 sizeof(ip6
->ip6_dst
)) != 0) {
988 if (++i
>= XIDMAPSIZE
)
990 } while (i
!= xid_map_hint
);
997 * Routines for parsing reply packets
1001 * Return a pointer to the beginning of the actual results.
1002 * If the packet was truncated, return 0.
1004 static const u_int32_t
*
1005 parserep(register const struct sunrpc_msg
*rp
, register u_int length
)
1007 register const u_int32_t
*dp
;
1009 enum sunrpc_accept_stat astat
;
1013 * Here we find the address of the ar_verf credentials.
1014 * Originally, this calculation was
1015 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
1016 * On the wire, the rp_acpt field starts immediately after
1017 * the (32 bit) rp_stat field. However, rp_acpt (which is a
1018 * "struct accepted_reply") contains a "struct opaque_auth",
1019 * whose internal representation contains a pointer, so on a
1020 * 64-bit machine the compiler inserts 32 bits of padding
1021 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
1022 * the internal representation to parse the on-the-wire
1023 * representation. Instead, we skip past the rp_stat field,
1024 * which is an "enum" and so occupies one 32-bit word.
1026 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
1028 len
= EXTRACT_32BITS(&dp
[1]);
1032 * skip past the ar_verf credentials.
1034 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
1038 * now we can check the ar_stat field
1040 astat
= (enum sunrpc_accept_stat
) EXTRACT_32BITS(dp
);
1043 case SUNRPC_SUCCESS
:
1046 case SUNRPC_PROG_UNAVAIL
:
1047 printf(" PROG_UNAVAIL");
1048 nfserr
= 1; /* suppress trunc string */
1051 case SUNRPC_PROG_MISMATCH
:
1052 printf(" PROG_MISMATCH");
1053 nfserr
= 1; /* suppress trunc string */
1056 case SUNRPC_PROC_UNAVAIL
:
1057 printf(" PROC_UNAVAIL");
1058 nfserr
= 1; /* suppress trunc string */
1061 case SUNRPC_GARBAGE_ARGS
:
1062 printf(" GARBAGE_ARGS");
1063 nfserr
= 1; /* suppress trunc string */
1066 case SUNRPC_SYSTEM_ERR
:
1067 printf(" SYSTEM_ERR");
1068 nfserr
= 1; /* suppress trunc string */
1072 printf(" ar_stat %d", astat
);
1073 nfserr
= 1; /* suppress trunc string */
1076 /* successful return */
1077 TCHECK2(*dp
, sizeof(astat
));
1078 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
1083 static const u_int32_t
*
1084 parsestatus(const u_int32_t
*dp
, int *er
)
1090 errnum
= EXTRACT_32BITS(&dp
[0]);
1095 printf(" ERROR: %s",
1096 tok2str(status2str
, "unk %d", errnum
));
1104 static const u_int32_t
*
1105 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
1107 const struct nfs_fattr
*fap
;
1109 fap
= (const struct nfs_fattr
*)dp
;
1110 TCHECK(fap
->fa_gid
);
1112 printf(" %s %o ids %d/%d",
1113 tok2str(type2str
, "unk-ft %d ",
1114 EXTRACT_32BITS(&fap
->fa_type
)),
1115 EXTRACT_32BITS(&fap
->fa_mode
),
1116 EXTRACT_32BITS(&fap
->fa_uid
),
1117 EXTRACT_32BITS(&fap
->fa_gid
));
1119 TCHECK(fap
->fa3_size
);
1120 printf(" sz %" PRIu64
,
1121 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_size
));
1123 TCHECK(fap
->fa2_size
);
1124 printf(" sz %d", EXTRACT_32BITS(&fap
->fa2_size
));
1127 /* print lots more stuff */
1130 TCHECK(fap
->fa3_ctime
);
1131 printf(" nlink %d rdev %d/%d",
1132 EXTRACT_32BITS(&fap
->fa_nlink
),
1133 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata1
),
1134 EXTRACT_32BITS(&fap
->fa3_rdev
.specdata2
));
1135 printf(" fsid %" PRIx64
,
1136 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fsid
));
1137 printf(" fileid %" PRIx64
,
1138 EXTRACT_64BITS((u_int32_t
*)&fap
->fa3_fileid
));
1139 printf(" a/m/ctime %u.%06u",
1140 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_sec
),
1141 EXTRACT_32BITS(&fap
->fa3_atime
.nfsv3_nsec
));
1143 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_sec
),
1144 EXTRACT_32BITS(&fap
->fa3_mtime
.nfsv3_nsec
));
1146 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_sec
),
1147 EXTRACT_32BITS(&fap
->fa3_ctime
.nfsv3_nsec
));
1149 TCHECK(fap
->fa2_ctime
);
1150 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1151 EXTRACT_32BITS(&fap
->fa_nlink
),
1152 EXTRACT_32BITS(&fap
->fa2_rdev
),
1153 EXTRACT_32BITS(&fap
->fa2_fsid
),
1154 EXTRACT_32BITS(&fap
->fa2_fileid
));
1156 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_sec
),
1157 EXTRACT_32BITS(&fap
->fa2_atime
.nfsv2_usec
));
1159 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_sec
),
1160 EXTRACT_32BITS(&fap
->fa2_mtime
.nfsv2_usec
));
1162 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_sec
),
1163 EXTRACT_32BITS(&fap
->fa2_ctime
.nfsv2_usec
));
1166 return ((const u_int32_t
*)((unsigned char *)dp
+
1167 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1173 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1177 dp
= parsestatus(dp
, &er
);
1183 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1187 parsediropres(const u_int32_t
*dp
)
1191 if (!(dp
= parsestatus(dp
, &er
)))
1196 dp
= parsefh(dp
, 0);
1200 return (parsefattr(dp
, vflag
, 0) != NULL
);
1204 parselinkres(const u_int32_t
*dp
, int v3
)
1208 dp
= parsestatus(dp
, &er
);
1213 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1216 return (parsefn(dp
) != NULL
);
1220 parsestatfs(const u_int32_t
*dp
, int v3
)
1222 const struct nfs_statfs
*sfsp
;
1225 dp
= parsestatus(dp
, &er
);
1237 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1241 TCHECK2(*dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1243 sfsp
= (const struct nfs_statfs
*)dp
;
1246 printf(" tbytes %" PRIu64
" fbytes %" PRIu64
" abytes %" PRIu64
,
1247 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tbytes
),
1248 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_fbytes
),
1249 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_abytes
));
1251 printf(" tfiles %" PRIu64
" ffiles %" PRIu64
" afiles %" PRIu64
" invar %u",
1252 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_tfiles
),
1253 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_ffiles
),
1254 EXTRACT_64BITS((u_int32_t
*)&sfsp
->sf_afiles
),
1255 EXTRACT_32BITS(&sfsp
->sf_invarsec
));
1258 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1259 EXTRACT_32BITS(&sfsp
->sf_tsize
),
1260 EXTRACT_32BITS(&sfsp
->sf_bsize
),
1261 EXTRACT_32BITS(&sfsp
->sf_blocks
),
1262 EXTRACT_32BITS(&sfsp
->sf_bfree
),
1263 EXTRACT_32BITS(&sfsp
->sf_bavail
));
1272 parserddires(const u_int32_t
*dp
)
1276 dp
= parsestatus(dp
, &er
);
1285 printf(" offset %x size %d ",
1286 EXTRACT_32BITS(&dp
[0]), EXTRACT_32BITS(&dp
[1]));
1295 static const u_int32_t
*
1296 parse_wcc_attr(const u_int32_t
*dp
)
1298 printf(" sz %" PRIu64
, EXTRACT_64BITS(&dp
[0]));
1299 printf(" mtime %u.%06u ctime %u.%06u",
1300 EXTRACT_32BITS(&dp
[2]), EXTRACT_32BITS(&dp
[3]),
1301 EXTRACT_32BITS(&dp
[4]), EXTRACT_32BITS(&dp
[5]));
1306 * Pre operation attributes. Print only if vflag > 1.
1308 static const u_int32_t
*
1309 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1312 if (!EXTRACT_32BITS(&dp
[0]))
1317 return parse_wcc_attr(dp
);
1319 /* If not verbose enough, just skip over wcc_attr */
1327 * Post operation attributes are printed if vflag >= 1
1329 static const u_int32_t
*
1330 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1333 if (!EXTRACT_32BITS(&dp
[0]))
1337 return parsefattr(dp
, verbose
, 1);
1339 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1344 static const u_int32_t
*
1345 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1349 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1354 return parse_post_op_attr(dp
, verbose
);
1357 static const u_int32_t
*
1358 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1362 if (!(dp
= parsestatus(dp
, &er
)))
1365 dp
= parse_wcc_data(dp
, verbose
);
1368 if (!EXTRACT_32BITS(&dp
[0]))
1371 if (!(dp
= parsefh(dp
, 1)))
1374 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1377 printf(" dir attr:");
1378 dp
= parse_wcc_data(dp
, verbose
);
1388 parsewccres(const u_int32_t
*dp
, int verbose
)
1392 if (!(dp
= parsestatus(dp
, &er
)))
1394 return parse_wcc_data(dp
, verbose
) != 0;
1397 static const u_int32_t
*
1398 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1402 if (!(dp
= parsestatus(dp
, &er
)))
1406 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1412 printf(" verf %08x%08x", dp
[0], dp
[1]);
1421 parsefsinfo(const u_int32_t
*dp
)
1423 struct nfsv3_fsinfo
*sfp
;
1426 if (!(dp
= parsestatus(dp
, &er
)))
1430 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1435 sfp
= (struct nfsv3_fsinfo
*)dp
;
1437 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1438 EXTRACT_32BITS(&sfp
->fs_rtmax
),
1439 EXTRACT_32BITS(&sfp
->fs_rtpref
),
1440 EXTRACT_32BITS(&sfp
->fs_wtmax
),
1441 EXTRACT_32BITS(&sfp
->fs_wtpref
),
1442 EXTRACT_32BITS(&sfp
->fs_dtpref
));
1444 printf(" rtmult %u wtmult %u maxfsz %" PRIu64
,
1445 EXTRACT_32BITS(&sfp
->fs_rtmult
),
1446 EXTRACT_32BITS(&sfp
->fs_wtmult
),
1447 EXTRACT_64BITS((u_int32_t
*)&sfp
->fs_maxfilesize
));
1448 printf(" delta %u.%06u ",
1449 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_sec
),
1450 EXTRACT_32BITS(&sfp
->fs_timedelta
.nfsv3_nsec
));
1458 parsepathconf(const u_int32_t
*dp
)
1461 struct nfsv3_pathconf
*spp
;
1463 if (!(dp
= parsestatus(dp
, &er
)))
1467 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1472 spp
= (struct nfsv3_pathconf
*)dp
;
1475 printf(" linkmax %u namemax %u %s %s %s %s",
1476 EXTRACT_32BITS(&spp
->pc_linkmax
),
1477 EXTRACT_32BITS(&spp
->pc_namemax
),
1478 EXTRACT_32BITS(&spp
->pc_notrunc
) ? "notrunc" : "",
1479 EXTRACT_32BITS(&spp
->pc_chownrestricted
) ? "chownres" : "",
1480 EXTRACT_32BITS(&spp
->pc_caseinsensitive
) ? "igncase" : "",
1481 EXTRACT_32BITS(&spp
->pc_casepreserving
) ? "keepcase" : "");
1488 interp_reply(const struct sunrpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1490 register const u_int32_t
*dp
;
1494 v3
= (vers
== NFS_VER3
);
1496 if (!v3
&& proc
< NFS_NPROCS
)
1497 proc
= nfsv3_procid
[proc
];
1509 case NFSPROC_GETATTR
:
1511 dp
= parserep(rp
, length
);
1512 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1516 case NFSPROC_SETATTR
:
1518 if (!(dp
= parserep(rp
, length
)))
1521 if (parsewccres(dp
, vflag
))
1524 if (parseattrstat(dp
, !qflag
, 0) != 0)
1529 case NFSPROC_LOOKUP
:
1531 if (!(dp
= parserep(rp
, length
)))
1534 if (!(dp
= parsestatus(dp
, &er
)))
1538 printf(" post dattr:");
1539 dp
= parse_post_op_attr(dp
, vflag
);
1542 if (!(dp
= parsefh(dp
, v3
)))
1544 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1546 printf(" post dattr:");
1547 dp
= parse_post_op_attr(dp
, vflag
);
1553 if (parsediropres(dp
) != 0)
1558 case NFSPROC_ACCESS
:
1560 if (!(dp
= parserep(rp
, length
)))
1562 if (!(dp
= parsestatus(dp
, &er
)))
1566 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1569 printf(" c %04x", EXTRACT_32BITS(&dp
[0]));
1572 case NFSPROC_READLINK
:
1573 printf(" readlink");
1574 dp
= parserep(rp
, length
);
1575 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1581 if (!(dp
= parserep(rp
, length
)))
1584 if (!(dp
= parsestatus(dp
, &er
)))
1586 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1592 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1593 if (EXTRACT_32BITS(&dp
[1]))
1598 if (parseattrstat(dp
, vflag
, 0) != 0)
1605 if (!(dp
= parserep(rp
, length
)))
1608 if (!(dp
= parsestatus(dp
, &er
)))
1610 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1616 printf(" %u bytes", EXTRACT_32BITS(&dp
[0]));
1620 tok2str(nfsv3_writemodes
,
1621 NULL
, EXTRACT_32BITS(&dp
[1])));
1626 if (parseattrstat(dp
, vflag
, v3
) != 0)
1631 case NFSPROC_CREATE
:
1633 if (!(dp
= parserep(rp
, length
)))
1636 if (parsecreateopres(dp
, vflag
) != 0)
1639 if (parsediropres(dp
) != 0)
1646 if (!(dp
= parserep(rp
, length
)))
1649 if (parsecreateopres(dp
, vflag
) != 0)
1652 if (parsediropres(dp
) != 0)
1657 case NFSPROC_SYMLINK
:
1659 if (!(dp
= parserep(rp
, length
)))
1662 if (parsecreateopres(dp
, vflag
) != 0)
1665 if (parsestatus(dp
, &er
) != 0)
1672 if (!(dp
= parserep(rp
, length
)))
1674 if (parsecreateopres(dp
, vflag
) != 0)
1678 case NFSPROC_REMOVE
:
1680 if (!(dp
= parserep(rp
, length
)))
1683 if (parsewccres(dp
, vflag
))
1686 if (parsestatus(dp
, &er
) != 0)
1693 if (!(dp
= parserep(rp
, length
)))
1696 if (parsewccres(dp
, vflag
))
1699 if (parsestatus(dp
, &er
) != 0)
1704 case NFSPROC_RENAME
:
1706 if (!(dp
= parserep(rp
, length
)))
1709 if (!(dp
= parsestatus(dp
, &er
)))
1713 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1716 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1721 if (parsestatus(dp
, &er
) != 0)
1728 if (!(dp
= parserep(rp
, length
)))
1731 if (!(dp
= parsestatus(dp
, &er
)))
1734 printf(" file POST:");
1735 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1738 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1743 if (parsestatus(dp
, &er
) != 0)
1748 case NFSPROC_READDIR
:
1750 if (!(dp
= parserep(rp
, length
)))
1753 if (parsev3rddirres(dp
, vflag
))
1756 if (parserddires(dp
) != 0)
1761 case NFSPROC_READDIRPLUS
:
1762 printf(" readdirplus");
1763 if (!(dp
= parserep(rp
, length
)))
1765 if (parsev3rddirres(dp
, vflag
))
1769 case NFSPROC_FSSTAT
:
1771 dp
= parserep(rp
, length
);
1772 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1776 case NFSPROC_FSINFO
:
1778 dp
= parserep(rp
, length
);
1779 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1783 case NFSPROC_PATHCONF
:
1784 printf(" pathconf");
1785 dp
= parserep(rp
, length
);
1786 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1790 case NFSPROC_COMMIT
:
1792 dp
= parserep(rp
, length
);
1793 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1798 printf(" proc-%u", proc
);
1803 fputs(" [|nfs]", stdout
);