]>
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
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.76 2000-06-10 05:26:42 itojun Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <netinet/if_ether.h>
43 #include <netinet/in_systm.h>
44 #include <netinet/ip.h>
46 #include <netinet/ip6.h>
56 #include "interface.h"
57 #include "addrtoname.h"
62 static void nfs_printfh(const u_int32_t
*, const u_int
);
63 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
64 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
65 u_int32_t
*, u_int32_t
*);
66 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
67 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
68 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
69 static int print_int64(const u_int32_t
*dp
, int how
);
70 static void print_nfsaddr(const u_char
*, const char *, const char *);
73 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
75 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
104 static struct tok nfsv3_writemodes
[] = {
111 static struct tok type2str
[] = {
123 * Print out a 64-bit integer. This appears to be different on each system,
124 * try to make the best of it. The integer stored as 2 consecutive XDR
125 * encoded 32-bit integers, to which a pointer is passed.
127 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
128 * integer datatype and can print it.
135 static int print_int64(const u_int32_t
*dp
, int how
)
140 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
143 printf(INT64_FORMAT
, res
);
146 printf(U_INT64_FORMAT
, res
);
149 printf(HEX_INT64_FORMAT
, res
);
159 printf("0x%x%08x", (u_int32_t
)ntohl(dp
[0]),
160 (u_int32_t
)ntohl(dp
[1]));
170 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
175 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
177 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
180 srcaddr
[0] = dstaddr
[0] = '\0';
181 switch (((struct ip
*)bp
)->ip_v
) {
183 ip
= (struct ip
*)bp
;
184 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
185 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
189 ip6
= (struct ip6_hdr
*)bp
;
190 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
192 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
197 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
198 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
202 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
205 static const u_int32_t
*
206 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
209 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
211 sa3
->sa_mode
= ntohl(*dp
++);
215 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
217 sa3
->sa_uid
= ntohl(*dp
++);
221 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
223 sa3
->sa_gid
= ntohl(*dp
++);
227 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
229 sa3
->sa_size
= ntohl(*dp
++);
233 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
235 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
236 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
240 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
242 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
243 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
251 static int nfserr
; /* true if we error rather than trunc */
254 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
257 printf(" mode %o", sa3
->sa_mode
);
259 printf(" uid %u", sa3
->sa_uid
);
261 printf(" gid %u", sa3
->sa_gid
);
263 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
264 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
265 sa3
->sa_atime
.nfsv3_nsec
);
266 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
267 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
268 sa3
->sa_mtime
.nfsv3_nsec
);
273 nfsreply_print(register const u_char
*bp
, u_int length
,
274 register const u_char
*bp2
)
276 register const struct rpc_msg
*rp
;
277 u_int32_t proc
, vers
;
278 char srcid
[20], dstid
[20]; /*fits 32bit*/
280 nfserr
= 0; /* assume no error */
281 rp
= (const struct rpc_msg
*)bp
;
284 strlcpy(srcid
, "nfs", sizeof(srcid
));
285 snprintf(dstid
, sizeof(dstid
), "%u",
286 (u_int32_t
)ntohl(rp
->rm_xid
));
288 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
289 snprintf(dstid
, sizeof(dstid
), "%u",
290 (u_int32_t
)ntohl(rp
->rm_xid
));
292 print_nfsaddr(bp2
, srcid
, dstid
);
293 (void)printf("reply %s %d",
294 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
298 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
299 interp_reply(rp
, proc
, vers
, length
);
303 * Return a pointer to the first file handle in the packet.
304 * If the packet was truncated, return 0.
306 static const u_int32_t
*
307 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
309 register const u_int32_t
*dp
;
313 * find the start of the req data (if we captured it)
315 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
319 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
323 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
333 * Print out an NFS file handle and return a pointer to following word.
334 * If packet was truncated, return 0.
336 static const u_int32_t
*
337 parsefh(register const u_int32_t
*dp
, int v3
)
343 len
= (int)ntohl(*dp
) / 4;
348 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
349 nfs_printfh(dp
, len
);
357 * Print out a file name and return pointer to 32-bit word past it.
358 * If packet was truncated, return 0.
360 static const u_int32_t
*
361 parsefn(register const u_int32_t
*dp
)
363 register u_int32_t len
;
364 register const u_char
*cp
;
366 /* Bail if we don't have the string length */
369 /* Fetch string length; convert to host order */
373 TCHECK2(*dp
, ((len
+ 3) & ~3));
376 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
377 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
378 /* XXX seems like we should be checking the length */
380 (void) fn_printn(cp
, len
, NULL
);
389 * Print out file handle and file name.
390 * Return pointer to 32-bit word past file name.
391 * If packet was truncated (or there was some other error), return 0.
393 static const u_int32_t
*
394 parsefhn(register const u_int32_t
*dp
, int v3
)
396 dp
= parsefh(dp
, v3
);
400 return (parsefn(dp
));
404 nfsreq_print(register const u_char
*bp
, u_int length
,
405 register const u_char
*bp2
)
407 register const struct rpc_msg
*rp
;
408 register const u_int32_t
*dp
;
412 struct nfsv3_sattr sa3
;
413 char srcid
[20], dstid
[20]; /*fits 32bit*/
415 nfserr
= 0; /* assume no error */
416 rp
= (const struct rpc_msg
*)bp
;
418 snprintf(srcid
, sizeof(srcid
), "%u",
419 (u_int32_t
)ntohl(rp
->rm_xid
));
420 strlcpy(dstid
, "nfs", sizeof(dstid
));
422 snprintf(srcid
, sizeof(srcid
), "%u",
423 (u_int32_t
)ntohl(rp
->rm_xid
));
424 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
426 print_nfsaddr(bp2
, srcid
, dstid
);
427 (void)printf("%d", length
);
429 xid_map_enter(rp
, bp2
); /* record proc number for later on */
431 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
432 proc
= ntohl(rp
->rm_call
.cb_proc
);
434 if (!v3
&& proc
< NFS_NPROCS
)
435 proc
= nfsv3_procid
[proc
];
445 case NFSPROC_GETATTR
:
447 if ((dp
= parsereq(rp
, length
)) != NULL
&&
448 parsefh(dp
, v3
) != NULL
)
452 case NFSPROC_SETATTR
:
454 if ((dp
= parsereq(rp
, length
)) != NULL
&&
455 parsefh(dp
, v3
) != NULL
)
461 if ((dp
= parsereq(rp
, length
)) != NULL
&&
462 parsefhn(dp
, v3
) != NULL
)
468 if ((dp
= parsereq(rp
, length
)) != NULL
&&
469 (dp
= parsefh(dp
, v3
)) != NULL
) {
471 printf(" %04x", (u_int32_t
)ntohl(dp
[0]));
476 case NFSPROC_READLINK
:
478 if ((dp
= parsereq(rp
, length
)) != NULL
&&
479 parsefh(dp
, v3
) != NULL
)
485 if ((dp
= parsereq(rp
, length
)) != NULL
&&
486 (dp
= parsefh(dp
, v3
)) != NULL
) {
489 printf(" %u bytes @ ",
490 (u_int32_t
) ntohl(dp
[2]));
491 print_int64(dp
, UNSIGNED
);
494 printf(" %u bytes @ %u",
495 (u_int32_t
)ntohl(dp
[1]),
496 (u_int32_t
)ntohl(dp
[0]));
504 if ((dp
= parsereq(rp
, length
)) != NULL
&&
505 (dp
= parsefh(dp
, v3
)) != NULL
) {
508 printf(" %u bytes @ ",
509 (u_int32_t
) ntohl(dp
[4]));
510 print_int64(dp
, UNSIGNED
);
515 tok2str(nfsv3_writemodes
,
520 printf(" %u (%u) bytes @ %u (%u)",
521 (u_int32_t
)ntohl(dp
[3]),
522 (u_int32_t
)ntohl(dp
[2]),
523 (u_int32_t
)ntohl(dp
[1]),
524 (u_int32_t
)ntohl(dp
[0]));
532 if ((dp
= parsereq(rp
, length
)) != NULL
&&
533 parsefhn(dp
, v3
) != NULL
)
539 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
543 case NFSPROC_SYMLINK
:
545 if ((dp
= parsereq(rp
, length
)) != 0 &&
546 (dp
= parsefhn(dp
, v3
)) != 0) {
547 fputs(" ->", stdout
);
548 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
550 if (parsefn(dp
) == 0)
553 print_sattr3(&sa3
, vflag
);
560 if ((dp
= parsereq(rp
, length
)) != 0 &&
561 (dp
= parsefhn(dp
, v3
)) != 0) {
563 type
= (nfstype
)ntohl(*dp
++);
564 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
566 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
567 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
570 (u_int32_t
)ntohl(dp
[0]),
571 (u_int32_t
)ntohl(dp
[1]));
575 print_sattr3(&sa3
, vflag
);
582 if ((dp
= parsereq(rp
, length
)) != NULL
&&
583 parsefhn(dp
, v3
) != NULL
)
589 if ((dp
= parsereq(rp
, length
)) != NULL
&&
590 parsefhn(dp
, v3
) != NULL
)
596 if ((dp
= parsereq(rp
, length
)) != NULL
&&
597 (dp
= parsefhn(dp
, v3
)) != NULL
) {
598 fputs(" ->", stdout
);
599 if (parsefhn(dp
, v3
) != NULL
)
606 if ((dp
= parsereq(rp
, length
)) != NULL
&&
607 (dp
= parsefh(dp
, v3
)) != NULL
) {
608 fputs(" ->", stdout
);
609 if (parsefhn(dp
, v3
) != NULL
)
614 case NFSPROC_READDIR
:
616 if ((dp
= parsereq(rp
, length
)) != NULL
&&
617 (dp
= parsefh(dp
, v3
)) != NULL
) {
621 * We shouldn't really try to interpret the
622 * offset cookie here.
624 printf(" %u bytes @ ",
625 (u_int32_t
) ntohl(dp
[4]));
626 print_int64(dp
, SIGNED
);
628 printf(" verf %08x%08x", dp
[2],
633 * Print the offset as signed, since -1 is
634 * common, but offsets > 2^31 aren't.
636 printf(" %u bytes @ %d",
637 (u_int32_t
)ntohl(dp
[1]),
638 (u_int32_t
)ntohl(dp
[0]));
644 case NFSPROC_READDIRPLUS
:
645 printf(" readdirplus");
646 if ((dp
= parsereq(rp
, length
)) != NULL
&&
647 (dp
= parsefh(dp
, v3
)) != NULL
) {
650 * We don't try to interpret the offset
653 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
654 print_int64(dp
, SIGNED
);
656 printf(" max %u verf %08x%08x",
657 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
664 if ((dp
= parsereq(rp
, length
)) != NULL
&&
665 parsefh(dp
, v3
) != NULL
)
673 case NFSPROC_PATHCONF
:
679 if ((dp
= parsereq(rp
, length
)) != NULL
&&
680 (dp
= parsefh(dp
, v3
)) != NULL
) {
681 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
682 print_int64(dp
, UNSIGNED
);
688 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
694 fputs(" [|nfs]", stdout
);
698 * Print out an NFS file handle.
699 * We assume packet was not truncated before the end of the
700 * file handle pointed to by dp.
702 * Note: new version (using portable file-handle parser) doesn't produce
703 * generation number. It probably could be made to do that, with some
704 * additional hacking on the parser code.
707 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
711 char *sfsname
= NULL
;
713 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
716 /* file system ID is ASCII, not numeric, for this server OS */
717 static char temp
[NFSX_V3FHMAX
+1];
719 /* Make sure string is null-terminated */
720 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
721 temp
[sizeof(temp
) - 1] = '\0';
722 /* Remove trailing spaces */
723 sfsname
= strchr(temp
, ' ');
727 (void)printf(" fh %s/", temp
);
729 (void)printf(" fh %d,%d/",
730 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
733 if(fsid
.Fsid_dev
.Minor
== 257 && uflag
)
734 /* Print the undecoded handle */
735 (void)printf("%s", fsid
.Opaque_Handle
);
737 (void)printf("%ld", (long) ino
);
741 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
742 * us to match up replies with requests and thus to know how to parse
746 struct xid_map_entry
{
747 u_int32_t xid
; /* transaction ID (net order) */
748 int ipver
; /* IP version (4 or 6) */
750 struct in6_addr client
; /* client IP address (net order) */
751 struct in6_addr server
; /* server IP address (net order) */
753 struct in_addr client
; /* client IP address (net order) */
754 struct in_addr server
; /* server IP address (net order) */
756 u_int32_t proc
; /* call proc number (host order) */
757 u_int32_t vers
; /* program version (host order) */
761 * Map entries are kept in an array that we manage as a ring;
762 * new entries are always added at the tail of the ring. Initially,
763 * all the entries are zero and hence don't match anything.
766 #define XIDMAPSIZE 64
768 struct xid_map_entry xid_map
[XIDMAPSIZE
];
770 int xid_map_next
= 0;
771 int xid_map_hint
= 0;
774 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
776 struct ip
*ip
= NULL
;
778 struct ip6_hdr
*ip6
= NULL
;
780 struct xid_map_entry
*xmep
;
782 switch (((struct ip
*)bp
)->ip_v
) {
784 ip
= (struct ip
*)bp
;
788 ip6
= (struct ip6_hdr
*)bp
;
795 xmep
= &xid_map
[xid_map_next
];
797 if (++xid_map_next
>= XIDMAPSIZE
)
800 xmep
->xid
= rp
->rm_xid
;
803 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
804 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
809 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
810 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
813 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
814 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
818 * Returns 0 and puts NFSPROC_xxx in proc return and
819 * version in vers return, or returns -1 on failure
822 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
826 struct xid_map_entry
*xmep
;
827 u_int32_t xid
= rp
->rm_xid
;
828 struct ip
*ip
= (struct ip
*)ip
;
830 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
834 /* Start searching from where we last left off */
839 if (xmep
->ipver
!= ip
->ip_v
|| xmep
->xid
!= xid
)
841 switch (xmep
->ipver
) {
843 if (memcmp(&ip
->ip_src
, &xmep
->server
,
844 sizeof(ip
->ip_src
)) != 0 ||
845 memcmp(&ip
->ip_dst
, &xmep
->client
,
846 sizeof(ip
->ip_dst
)) != 0) {
852 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
853 sizeof(ip6
->ip6_src
)) != 0 ||
854 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
855 sizeof(ip6
->ip6_dst
)) != 0) {
872 if (++i
>= XIDMAPSIZE
)
874 } while (i
!= xid_map_hint
);
881 * Routines for parsing reply packets
885 * Return a pointer to the beginning of the actual results.
886 * If the packet was truncated, return 0.
888 static const u_int32_t
*
889 parserep(register const struct rpc_msg
*rp
, register u_int length
)
891 register const u_int32_t
*dp
;
893 enum accept_stat astat
;
897 * Here we find the address of the ar_verf credentials.
898 * Originally, this calculation was
899 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
900 * On the wire, the rp_acpt field starts immediately after
901 * the (32 bit) rp_stat field. However, rp_acpt (which is a
902 * "struct accepted_reply") contains a "struct opaque_auth",
903 * whose internal representation contains a pointer, so on a
904 * 64-bit machine the compiler inserts 32 bits of padding
905 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
906 * the internal representation to parse the on-the-wire
907 * representation. Instead, we skip past the rp_stat field,
908 * which is an "enum" and so occupies one 32-bit word.
910 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
916 * skip past the ar_verf credentials.
918 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
922 * now we can check the ar_stat field
924 astat
= ntohl(*(enum accept_stat
*)dp
);
931 printf(" PROG_UNAVAIL");
932 nfserr
= 1; /* suppress trunc string */
936 printf(" PROG_MISMATCH");
937 nfserr
= 1; /* suppress trunc string */
941 printf(" PROC_UNAVAIL");
942 nfserr
= 1; /* suppress trunc string */
946 printf(" GARBAGE_ARGS");
947 nfserr
= 1; /* suppress trunc string */
951 printf(" SYSTEM_ERR");
952 nfserr
= 1; /* suppress trunc string */
956 printf(" ar_stat %d", astat
);
957 nfserr
= 1; /* suppress trunc string */
960 /* successful return */
961 TCHECK2(*dp
, sizeof(astat
));
962 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
967 static const u_int32_t
*
968 parsestatus(const u_int32_t
*dp
, int *er
)
974 errnum
= ntohl(dp
[0]);
979 printf(" ERROR: %s", pcap_strerror(errnum
));
988 static const u_int32_t
*
989 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
991 const struct nfs_fattr
*fap
;
993 fap
= (const struct nfs_fattr
*)dp
;
996 printf(" %s %o ids %d/%d",
997 tok2str(type2str
, "unk-ft %d ",
998 (u_int32_t
)ntohl(fap
->fa_type
)),
999 (u_int32_t
)ntohl(fap
->fa_mode
),
1000 (u_int32_t
)ntohl(fap
->fa_uid
),
1001 (u_int32_t
) ntohl(fap
->fa_gid
));
1003 TCHECK(fap
->fa3_size
);
1005 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1008 TCHECK(fap
->fa2_size
);
1009 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1012 /* print lots more stuff */
1015 TCHECK(fap
->fa3_ctime
);
1016 printf("nlink %d rdev %d/%d ",
1017 (u_int32_t
)ntohl(fap
->fa_nlink
),
1018 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1019 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1021 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
1023 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
1024 printf(" a/m/ctime %u.%06u ",
1025 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1026 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1028 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1029 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1031 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1032 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1034 TCHECK(fap
->fa2_ctime
);
1035 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1036 (u_int32_t
) ntohl(fap
->fa_nlink
),
1037 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1038 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1039 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1041 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1042 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1044 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1045 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1047 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1048 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1051 return ((const u_int32_t
*)((unsigned char *)dp
+
1052 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1058 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1062 dp
= parsestatus(dp
, &er
);
1063 if (dp
== NULL
|| er
)
1066 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1070 parsediropres(const u_int32_t
*dp
)
1074 if (!(dp
= parsestatus(dp
, &er
)) || er
)
1077 dp
= parsefh(dp
, 0);
1081 return (parsefattr(dp
, vflag
, 0) != NULL
);
1085 parselinkres(const u_int32_t
*dp
, int v3
)
1089 dp
= parsestatus(dp
, &er
);
1090 if (dp
== NULL
|| er
)
1092 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1095 return (parsefn(dp
) != NULL
);
1099 parsestatfs(const u_int32_t
*dp
, int v3
)
1101 const struct nfs_statfs
*sfsp
;
1104 dp
= parsestatus(dp
, &er
);
1105 if (dp
== NULL
|| (!v3
&& er
))
1114 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1118 TCHECK2(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1120 sfsp
= (const struct nfs_statfs
*)dp
;
1124 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1126 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1128 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1131 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1133 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1135 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1137 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1140 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1141 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1142 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1143 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1144 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1145 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1154 parserddires(const u_int32_t
*dp
)
1158 dp
= parsestatus(dp
, &er
);
1165 printf(" offset %x size %d ",
1166 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1175 static const u_int32_t
*
1176 parse_wcc_attr(const u_int32_t
*dp
)
1179 print_int64(dp
, UNSIGNED
);
1180 printf(" mtime %u.%06u ctime %u.%06u",
1181 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1182 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1187 * Pre operation attributes. Print only if vflag > 1.
1189 static const u_int32_t
*
1190 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1198 return parse_wcc_attr(dp
);
1200 /* If not verbose enough, just skip over wcc_attr */
1208 * Post operation attributes are printed if vflag >= 1
1210 static const u_int32_t
*
1211 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1218 return parsefattr(dp
, verbose
, 1);
1220 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1225 static const u_int32_t
*
1226 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1230 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1235 return parse_post_op_attr(dp
, verbose
);
1238 static const u_int32_t
*
1239 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1243 if (!(dp
= parsestatus(dp
, &er
)))
1246 dp
= parse_wcc_data(dp
, verbose
);
1252 if (!(dp
= parsefh(dp
, 1)))
1255 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1258 printf("dir attr:");
1259 dp
= parse_wcc_data(dp
, verbose
);
1269 parsewccres(const u_int32_t
*dp
, int verbose
)
1273 if (!(dp
= parsestatus(dp
, &er
)))
1275 return parse_wcc_data(dp
, verbose
) != 0;
1278 static const u_int32_t
*
1279 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1283 if (!(dp
= parsestatus(dp
, &er
)))
1287 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1293 printf(" verf %08x%08x", dp
[0], dp
[1]);
1302 parsefsinfo(const u_int32_t
*dp
)
1304 struct nfsv3_fsinfo
*sfp
;
1307 if (!(dp
= parsestatus(dp
, &er
)))
1311 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1316 sfp
= (struct nfsv3_fsinfo
*)dp
;
1318 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1319 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1320 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1321 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1322 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1323 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1325 printf(" rtmult %u wtmult %u maxfsz ",
1326 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1327 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1328 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1329 printf(" delta %u.%06u ",
1330 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1331 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1339 parsepathconf(const u_int32_t
*dp
)
1342 struct nfsv3_pathconf
*spp
;
1344 if (!(dp
= parsestatus(dp
, &er
)))
1348 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1353 spp
= (struct nfsv3_pathconf
*)dp
;
1356 printf(" linkmax %u namemax %u %s %s %s %s",
1357 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1358 (u_int32_t
) ntohl(spp
->pc_namemax
),
1359 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1360 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1361 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1362 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1369 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1371 register const u_int32_t
*dp
;
1375 v3
= (vers
== NFS_VER3
);
1377 if (!v3
&& proc
< NFS_NPROCS
)
1378 proc
= nfsv3_procid
[proc
];
1390 case NFSPROC_GETATTR
:
1392 dp
= parserep(rp
, length
);
1393 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1397 case NFSPROC_SETATTR
:
1399 if (!(dp
= parserep(rp
, length
)))
1402 if (parsewccres(dp
, vflag
))
1405 if (parseattrstat(dp
, !qflag
, 0) != 0)
1410 case NFSPROC_LOOKUP
:
1412 if (!(dp
= parserep(rp
, length
)))
1415 if (!(dp
= parsestatus(dp
, &er
)))
1419 printf(" post dattr:");
1420 dp
= parse_post_op_attr(dp
, vflag
);
1423 if (!(dp
= parsefh(dp
, v3
)))
1425 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1427 printf(" post dattr:");
1428 dp
= parse_post_op_attr(dp
, vflag
);
1434 if (parsediropres(dp
) != 0)
1439 case NFSPROC_ACCESS
:
1441 dp
= parserep(rp
, length
);
1442 if (!(dp
= parsestatus(dp
, &er
)))
1446 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1449 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1452 case NFSPROC_READLINK
:
1453 printf(" readlink");
1454 dp
= parserep(rp
, length
);
1455 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1461 if (!(dp
= parserep(rp
, length
)))
1464 if (!(dp
= parsestatus(dp
, &er
)))
1466 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1472 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1478 if (parseattrstat(dp
, vflag
, 0) != 0)
1485 if (!(dp
= parserep(rp
, length
)))
1488 if (!(dp
= parsestatus(dp
, &er
)))
1490 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1496 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1500 tok2str(nfsv3_writemodes
,
1501 NULL
, ntohl(dp
[1])));
1506 if (parseattrstat(dp
, vflag
, v3
) != 0)
1511 case NFSPROC_CREATE
:
1513 if (!(dp
= parserep(rp
, length
)))
1516 if (parsecreateopres(dp
, vflag
) != 0)
1519 if (parsediropres(dp
) != 0)
1526 if (!(dp
= parserep(rp
, length
)))
1529 if (parsecreateopres(dp
, vflag
) != 0)
1532 if (parsediropres(dp
) != 0)
1537 case NFSPROC_SYMLINK
:
1539 if (!(dp
= parserep(rp
, length
)))
1542 if (parsecreateopres(dp
, vflag
) != 0)
1545 if (parsestatus(dp
, &er
) != 0)
1552 if (!(dp
= parserep(rp
, length
)))
1554 if (parsecreateopres(dp
, vflag
) != 0)
1558 case NFSPROC_REMOVE
:
1560 if (!(dp
= parserep(rp
, length
)))
1563 if (parsewccres(dp
, vflag
))
1566 if (parsestatus(dp
, &er
) != 0)
1573 if (!(dp
= parserep(rp
, length
)))
1576 if (parsewccres(dp
, vflag
))
1579 if (parsestatus(dp
, &er
) != 0)
1584 case NFSPROC_RENAME
:
1586 if (!(dp
= parserep(rp
, length
)))
1589 if (!(dp
= parsestatus(dp
, &er
)))
1593 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1596 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1601 if (parsestatus(dp
, &er
) != 0)
1608 if (!(dp
= parserep(rp
, length
)))
1611 if (!(dp
= parsestatus(dp
, &er
)))
1614 printf(" file POST:");
1615 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1618 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1623 if (parsestatus(dp
, &er
) != 0)
1628 case NFSPROC_READDIR
:
1630 if (!(dp
= parserep(rp
, length
)))
1633 if (parsev3rddirres(dp
, vflag
))
1636 if (parserddires(dp
) != 0)
1641 case NFSPROC_READDIRPLUS
:
1642 printf(" readdirplus");
1643 if (!(dp
= parserep(rp
, length
)))
1645 if (parsev3rddirres(dp
, vflag
))
1649 case NFSPROC_FSSTAT
:
1651 dp
= parserep(rp
, length
);
1652 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1656 case NFSPROC_FSINFO
:
1658 dp
= parserep(rp
, length
);
1659 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1663 case NFSPROC_PATHCONF
:
1664 printf(" pathconf");
1665 dp
= parserep(rp
, length
);
1666 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1670 case NFSPROC_COMMIT
:
1672 dp
= parserep(rp
, length
);
1673 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1678 printf(" proc-%u", proc
);
1683 fputs(" [|nfs]", stdout
);