]>
The Tcpdump Group git mirrors - tcpdump/blob - print-nfs.c
a6b88715ff7dc599f2d6a7d5e414781926303288
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.78 2000-07-01 03:39:06 assar Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/if_ether.h>
41 #include <netinet/in_systm.h>
42 #include <netinet/ip.h>
44 #include <netinet/ip6.h>
54 #include "interface.h"
55 #include "addrtoname.h"
60 static void nfs_printfh(const u_int32_t
*, const u_int
);
61 static void xid_map_enter(const struct rpc_msg
*, const u_char
*);
62 static int32_t xid_map_find(const struct rpc_msg
*, const u_char
*,
63 u_int32_t
*, u_int32_t
*);
64 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
65 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
66 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
67 static int print_int64(const u_int32_t
*dp
, int how
);
68 static void print_nfsaddr(const u_char
*, const char *, const char *);
71 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
73 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
102 static struct tok nfsv3_writemodes
[] = {
109 static struct tok type2str
[] = {
121 * Print out a 64-bit integer. This appears to be different on each system,
122 * try to make the best of it. The integer stored as 2 consecutive XDR
123 * encoded 32-bit integers, to which a pointer is passed.
125 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
126 * integer datatype and can print it.
133 static int print_int64(const u_int32_t
*dp
, int how
)
138 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
141 printf(INT64_FORMAT
, res
);
144 printf(U_INT64_FORMAT
, res
);
147 printf(HEX_INT64_FORMAT
, res
);
157 printf("0x%x%08x", (u_int32_t
)ntohl(dp
[0]),
158 (u_int32_t
)ntohl(dp
[1]));
168 print_nfsaddr(const u_char
*bp
, const char *s
, const char *d
)
173 char srcaddr
[INET6_ADDRSTRLEN
], dstaddr
[INET6_ADDRSTRLEN
];
175 #ifndef INET_ADDRSTRLEN
176 #define INET_ADDRSTRLEN 16
178 char srcaddr
[INET_ADDRSTRLEN
], dstaddr
[INET_ADDRSTRLEN
];
181 srcaddr
[0] = dstaddr
[0] = '\0';
182 switch (((struct ip
*)bp
)->ip_v
) {
184 ip
= (struct ip
*)bp
;
185 strlcpy(srcaddr
, ipaddr_string(&ip
->ip_src
), sizeof(srcaddr
));
186 strlcpy(dstaddr
, ipaddr_string(&ip
->ip_dst
), sizeof(dstaddr
));
190 ip6
= (struct ip6_hdr
*)bp
;
191 strlcpy(srcaddr
, ip6addr_string(&ip6
->ip6_src
),
193 strlcpy(dstaddr
, ip6addr_string(&ip6
->ip6_dst
),
198 strlcpy(srcaddr
, "?", sizeof(srcaddr
));
199 strlcpy(dstaddr
, "?", sizeof(dstaddr
));
203 (void)printf("%s.%s > %s.%s: ", srcaddr
, s
, dstaddr
, d
);
206 static const u_int32_t
*
207 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
210 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
212 sa3
->sa_mode
= ntohl(*dp
++);
216 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
218 sa3
->sa_uid
= ntohl(*dp
++);
222 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
224 sa3
->sa_gid
= ntohl(*dp
++);
228 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
230 sa3
->sa_size
= ntohl(*dp
++);
234 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
236 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
237 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
241 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
243 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
244 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
252 static int nfserr
; /* true if we error rather than trunc */
255 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
258 printf(" mode %o", sa3
->sa_mode
);
260 printf(" uid %u", sa3
->sa_uid
);
262 printf(" gid %u", sa3
->sa_gid
);
264 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
265 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
266 sa3
->sa_atime
.nfsv3_nsec
);
267 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
268 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
269 sa3
->sa_mtime
.nfsv3_nsec
);
274 nfsreply_print(register const u_char
*bp
, u_int length
,
275 register const u_char
*bp2
)
277 register const struct rpc_msg
*rp
;
278 u_int32_t proc
, vers
;
279 char srcid
[20], dstid
[20]; /*fits 32bit*/
281 nfserr
= 0; /* assume no error */
282 rp
= (const struct rpc_msg
*)bp
;
285 strlcpy(srcid
, "nfs", sizeof(srcid
));
286 snprintf(dstid
, sizeof(dstid
), "%u",
287 (u_int32_t
)ntohl(rp
->rm_xid
));
289 snprintf(srcid
, sizeof(srcid
), "%u", NFS_PORT
);
290 snprintf(dstid
, sizeof(dstid
), "%u",
291 (u_int32_t
)ntohl(rp
->rm_xid
));
293 print_nfsaddr(bp2
, srcid
, dstid
);
294 (void)printf("reply %s %d",
295 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
299 if (xid_map_find(rp
, bp2
, &proc
, &vers
) >= 0)
300 interp_reply(rp
, proc
, vers
, length
);
304 * Return a pointer to the first file handle in the packet.
305 * If the packet was truncated, return 0.
307 static const u_int32_t
*
308 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
310 register const u_int32_t
*dp
;
314 * find the start of the req data (if we captured it)
316 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
320 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
324 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
334 * Print out an NFS file handle and return a pointer to following word.
335 * If packet was truncated, return 0.
337 static const u_int32_t
*
338 parsefh(register const u_int32_t
*dp
, int v3
)
344 len
= (int)ntohl(*dp
) / 4;
349 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
350 nfs_printfh(dp
, len
);
358 * Print out a file name and return pointer to 32-bit word past it.
359 * If packet was truncated, return 0.
361 static const u_int32_t
*
362 parsefn(register const u_int32_t
*dp
)
364 register u_int32_t len
;
365 register const u_char
*cp
;
367 /* Bail if we don't have the string length */
370 /* Fetch string length; convert to host order */
374 TCHECK2(*dp
, ((len
+ 3) & ~3));
377 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
378 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
379 /* XXX seems like we should be checking the length */
381 (void) fn_printn(cp
, len
, NULL
);
390 * Print out file handle and file name.
391 * Return pointer to 32-bit word past file name.
392 * If packet was truncated (or there was some other error), return 0.
394 static const u_int32_t
*
395 parsefhn(register const u_int32_t
*dp
, int v3
)
397 dp
= parsefh(dp
, v3
);
401 return (parsefn(dp
));
405 nfsreq_print(register const u_char
*bp
, u_int length
,
406 register const u_char
*bp2
)
408 register const struct rpc_msg
*rp
;
409 register const u_int32_t
*dp
;
413 struct nfsv3_sattr sa3
;
414 char srcid
[20], dstid
[20]; /*fits 32bit*/
416 nfserr
= 0; /* assume no error */
417 rp
= (const struct rpc_msg
*)bp
;
419 snprintf(srcid
, sizeof(srcid
), "%u",
420 (u_int32_t
)ntohl(rp
->rm_xid
));
421 strlcpy(dstid
, "nfs", sizeof(dstid
));
423 snprintf(srcid
, sizeof(srcid
), "%u",
424 (u_int32_t
)ntohl(rp
->rm_xid
));
425 snprintf(dstid
, sizeof(dstid
), "%u", NFS_PORT
);
427 print_nfsaddr(bp2
, srcid
, dstid
);
428 (void)printf("%d", length
);
430 xid_map_enter(rp
, bp2
); /* record proc number for later on */
432 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
433 proc
= ntohl(rp
->rm_call
.cb_proc
);
435 if (!v3
&& proc
< NFS_NPROCS
)
436 proc
= nfsv3_procid
[proc
];
446 case NFSPROC_GETATTR
:
448 if ((dp
= parsereq(rp
, length
)) != NULL
&&
449 parsefh(dp
, v3
) != NULL
)
453 case NFSPROC_SETATTR
:
455 if ((dp
= parsereq(rp
, length
)) != NULL
&&
456 parsefh(dp
, v3
) != NULL
)
462 if ((dp
= parsereq(rp
, length
)) != NULL
&&
463 parsefhn(dp
, v3
) != NULL
)
469 if ((dp
= parsereq(rp
, length
)) != NULL
&&
470 (dp
= parsefh(dp
, v3
)) != NULL
) {
472 printf(" %04x", (u_int32_t
)ntohl(dp
[0]));
477 case NFSPROC_READLINK
:
479 if ((dp
= parsereq(rp
, length
)) != NULL
&&
480 parsefh(dp
, v3
) != NULL
)
486 if ((dp
= parsereq(rp
, length
)) != NULL
&&
487 (dp
= parsefh(dp
, v3
)) != NULL
) {
490 printf(" %u bytes @ ",
491 (u_int32_t
) ntohl(dp
[2]));
492 print_int64(dp
, UNSIGNED
);
495 printf(" %u bytes @ %u",
496 (u_int32_t
)ntohl(dp
[1]),
497 (u_int32_t
)ntohl(dp
[0]));
505 if ((dp
= parsereq(rp
, length
)) != NULL
&&
506 (dp
= parsefh(dp
, v3
)) != NULL
) {
509 printf(" %u bytes @ ",
510 (u_int32_t
) ntohl(dp
[4]));
511 print_int64(dp
, UNSIGNED
);
516 tok2str(nfsv3_writemodes
,
521 printf(" %u (%u) bytes @ %u (%u)",
522 (u_int32_t
)ntohl(dp
[3]),
523 (u_int32_t
)ntohl(dp
[2]),
524 (u_int32_t
)ntohl(dp
[1]),
525 (u_int32_t
)ntohl(dp
[0]));
533 if ((dp
= parsereq(rp
, length
)) != NULL
&&
534 parsefhn(dp
, v3
) != NULL
)
540 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
544 case NFSPROC_SYMLINK
:
546 if ((dp
= parsereq(rp
, length
)) != 0 &&
547 (dp
= parsefhn(dp
, v3
)) != 0) {
548 fputs(" ->", stdout
);
549 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
551 if (parsefn(dp
) == 0)
554 print_sattr3(&sa3
, vflag
);
561 if ((dp
= parsereq(rp
, length
)) != 0 &&
562 (dp
= parsefhn(dp
, v3
)) != 0) {
564 type
= (nfstype
)ntohl(*dp
++);
565 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
567 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
568 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
571 (u_int32_t
)ntohl(dp
[0]),
572 (u_int32_t
)ntohl(dp
[1]));
576 print_sattr3(&sa3
, vflag
);
583 if ((dp
= parsereq(rp
, length
)) != NULL
&&
584 parsefhn(dp
, v3
) != NULL
)
590 if ((dp
= parsereq(rp
, length
)) != NULL
&&
591 parsefhn(dp
, v3
) != NULL
)
597 if ((dp
= parsereq(rp
, length
)) != NULL
&&
598 (dp
= parsefhn(dp
, v3
)) != NULL
) {
599 fputs(" ->", stdout
);
600 if (parsefhn(dp
, v3
) != NULL
)
607 if ((dp
= parsereq(rp
, length
)) != NULL
&&
608 (dp
= parsefh(dp
, v3
)) != NULL
) {
609 fputs(" ->", stdout
);
610 if (parsefhn(dp
, v3
) != NULL
)
615 case NFSPROC_READDIR
:
617 if ((dp
= parsereq(rp
, length
)) != NULL
&&
618 (dp
= parsefh(dp
, v3
)) != NULL
) {
622 * We shouldn't really try to interpret the
623 * offset cookie here.
625 printf(" %u bytes @ ",
626 (u_int32_t
) ntohl(dp
[4]));
627 print_int64(dp
, SIGNED
);
629 printf(" verf %08x%08x", dp
[2],
634 * Print the offset as signed, since -1 is
635 * common, but offsets > 2^31 aren't.
637 printf(" %u bytes @ %d",
638 (u_int32_t
)ntohl(dp
[1]),
639 (u_int32_t
)ntohl(dp
[0]));
645 case NFSPROC_READDIRPLUS
:
646 printf(" readdirplus");
647 if ((dp
= parsereq(rp
, length
)) != NULL
&&
648 (dp
= parsefh(dp
, v3
)) != NULL
) {
651 * We don't try to interpret the offset
654 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
655 print_int64(dp
, SIGNED
);
657 printf(" max %u verf %08x%08x",
658 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
665 if ((dp
= parsereq(rp
, length
)) != NULL
&&
666 parsefh(dp
, v3
) != NULL
)
674 case NFSPROC_PATHCONF
:
680 if ((dp
= parsereq(rp
, length
)) != NULL
&&
681 (dp
= parsefh(dp
, v3
)) != NULL
) {
682 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
683 print_int64(dp
, UNSIGNED
);
689 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
695 fputs(" [|nfs]", stdout
);
699 * Print out an NFS file handle.
700 * We assume packet was not truncated before the end of the
701 * file handle pointed to by dp.
703 * Note: new version (using portable file-handle parser) doesn't produce
704 * generation number. It probably could be made to do that, with some
705 * additional hacking on the parser code.
708 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
712 char *sfsname
= NULL
;
714 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
717 /* file system ID is ASCII, not numeric, for this server OS */
718 static char temp
[NFSX_V3FHMAX
+1];
720 /* Make sure string is null-terminated */
721 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
722 temp
[sizeof(temp
) - 1] = '\0';
723 /* Remove trailing spaces */
724 sfsname
= strchr(temp
, ' ');
728 (void)printf(" fh %s/", temp
);
730 (void)printf(" fh %d,%d/",
731 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
);
734 if(fsid
.Fsid_dev
.Minor
== 257 && uflag
)
735 /* Print the undecoded handle */
736 (void)printf("%s", fsid
.Opaque_Handle
);
738 (void)printf("%ld", (long) ino
);
742 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
743 * us to match up replies with requests and thus to know how to parse
747 struct xid_map_entry
{
748 u_int32_t xid
; /* transaction ID (net order) */
749 int ipver
; /* IP version (4 or 6) */
751 struct in6_addr client
; /* client IP address (net order) */
752 struct in6_addr server
; /* server IP address (net order) */
754 struct in_addr client
; /* client IP address (net order) */
755 struct in_addr server
; /* server IP address (net order) */
757 u_int32_t proc
; /* call proc number (host order) */
758 u_int32_t vers
; /* program version (host order) */
762 * Map entries are kept in an array that we manage as a ring;
763 * new entries are always added at the tail of the ring. Initially,
764 * all the entries are zero and hence don't match anything.
767 #define XIDMAPSIZE 64
769 struct xid_map_entry xid_map
[XIDMAPSIZE
];
771 int xid_map_next
= 0;
772 int xid_map_hint
= 0;
775 xid_map_enter(const struct rpc_msg
*rp
, const u_char
*bp
)
777 struct ip
*ip
= NULL
;
779 struct ip6_hdr
*ip6
= NULL
;
781 struct xid_map_entry
*xmep
;
783 switch (((struct ip
*)bp
)->ip_v
) {
785 ip
= (struct ip
*)bp
;
789 ip6
= (struct ip6_hdr
*)bp
;
796 xmep
= &xid_map
[xid_map_next
];
798 if (++xid_map_next
>= XIDMAPSIZE
)
801 xmep
->xid
= rp
->rm_xid
;
804 memcpy(&xmep
->client
, &ip
->ip_src
, sizeof(ip
->ip_src
));
805 memcpy(&xmep
->server
, &ip
->ip_dst
, sizeof(ip
->ip_dst
));
810 memcpy(&xmep
->client
, &ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
811 memcpy(&xmep
->server
, &ip6
->ip6_dst
, sizeof(ip6
->ip6_dst
));
814 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
815 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
819 * Returns 0 and puts NFSPROC_xxx in proc return and
820 * version in vers return, or returns -1 on failure
823 xid_map_find(const struct rpc_msg
*rp
, const u_char
*bp
, u_int32_t
*proc
,
827 struct xid_map_entry
*xmep
;
828 u_int32_t xid
= rp
->rm_xid
;
829 struct ip
*ip
= (struct ip
*)ip
;
831 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
835 /* Start searching from where we last left off */
840 if (xmep
->ipver
!= ip
->ip_v
|| xmep
->xid
!= xid
)
842 switch (xmep
->ipver
) {
844 if (memcmp(&ip
->ip_src
, &xmep
->server
,
845 sizeof(ip
->ip_src
)) != 0 ||
846 memcmp(&ip
->ip_dst
, &xmep
->client
,
847 sizeof(ip
->ip_dst
)) != 0) {
853 if (memcmp(&ip6
->ip6_src
, &xmep
->server
,
854 sizeof(ip6
->ip6_src
)) != 0 ||
855 memcmp(&ip6
->ip6_dst
, &xmep
->client
,
856 sizeof(ip6
->ip6_dst
)) != 0) {
873 if (++i
>= XIDMAPSIZE
)
875 } while (i
!= xid_map_hint
);
882 * Routines for parsing reply packets
886 * Return a pointer to the beginning of the actual results.
887 * If the packet was truncated, return 0.
889 static const u_int32_t
*
890 parserep(register const struct rpc_msg
*rp
, register u_int length
)
892 register const u_int32_t
*dp
;
894 enum accept_stat astat
;
898 * Here we find the address of the ar_verf credentials.
899 * Originally, this calculation was
900 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
901 * On the wire, the rp_acpt field starts immediately after
902 * the (32 bit) rp_stat field. However, rp_acpt (which is a
903 * "struct accepted_reply") contains a "struct opaque_auth",
904 * whose internal representation contains a pointer, so on a
905 * 64-bit machine the compiler inserts 32 bits of padding
906 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
907 * the internal representation to parse the on-the-wire
908 * representation. Instead, we skip past the rp_stat field,
909 * which is an "enum" and so occupies one 32-bit word.
911 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
917 * skip past the ar_verf credentials.
919 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
923 * now we can check the ar_stat field
925 astat
= ntohl(*(enum accept_stat
*)dp
);
932 printf(" PROG_UNAVAIL");
933 nfserr
= 1; /* suppress trunc string */
937 printf(" PROG_MISMATCH");
938 nfserr
= 1; /* suppress trunc string */
942 printf(" PROC_UNAVAIL");
943 nfserr
= 1; /* suppress trunc string */
947 printf(" GARBAGE_ARGS");
948 nfserr
= 1; /* suppress trunc string */
952 printf(" SYSTEM_ERR");
953 nfserr
= 1; /* suppress trunc string */
957 printf(" ar_stat %d", astat
);
958 nfserr
= 1; /* suppress trunc string */
961 /* successful return */
962 TCHECK2(*dp
, sizeof(astat
));
963 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
968 static const u_int32_t
*
969 parsestatus(const u_int32_t
*dp
, int *er
)
975 errnum
= ntohl(dp
[0]);
980 printf(" ERROR: %s", pcap_strerror(errnum
));
989 static const u_int32_t
*
990 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
992 const struct nfs_fattr
*fap
;
994 fap
= (const struct nfs_fattr
*)dp
;
997 printf(" %s %o ids %d/%d",
998 tok2str(type2str
, "unk-ft %d ",
999 (u_int32_t
)ntohl(fap
->fa_type
)),
1000 (u_int32_t
)ntohl(fap
->fa_mode
),
1001 (u_int32_t
)ntohl(fap
->fa_uid
),
1002 (u_int32_t
) ntohl(fap
->fa_gid
));
1004 TCHECK(fap
->fa3_size
);
1006 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
1009 TCHECK(fap
->fa2_size
);
1010 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
1013 /* print lots more stuff */
1016 TCHECK(fap
->fa3_ctime
);
1017 printf("nlink %d rdev %d/%d ",
1018 (u_int32_t
)ntohl(fap
->fa_nlink
),
1019 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
1020 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
1022 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
1024 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
1025 printf(" a/m/ctime %u.%06u ",
1026 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
1027 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
1029 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
1030 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
1032 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
1033 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
1035 TCHECK(fap
->fa2_ctime
);
1036 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
1037 (u_int32_t
) ntohl(fap
->fa_nlink
),
1038 (u_int32_t
) ntohl(fap
->fa2_rdev
),
1039 (u_int32_t
) ntohl(fap
->fa2_fsid
),
1040 (u_int32_t
) ntohl(fap
->fa2_fileid
));
1042 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
1043 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
1045 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
1046 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
1048 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
1049 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
1052 return ((const u_int32_t
*)((unsigned char *)dp
+
1053 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
1059 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
1063 dp
= parsestatus(dp
, &er
);
1064 if (dp
== NULL
|| er
)
1067 return (parsefattr(dp
, verbose
, v3
) != NULL
);
1071 parsediropres(const u_int32_t
*dp
)
1075 if (!(dp
= parsestatus(dp
, &er
)) || er
)
1078 dp
= parsefh(dp
, 0);
1082 return (parsefattr(dp
, vflag
, 0) != NULL
);
1086 parselinkres(const u_int32_t
*dp
, int v3
)
1090 dp
= parsestatus(dp
, &er
);
1091 if (dp
== NULL
|| er
)
1093 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1096 return (parsefn(dp
) != NULL
);
1100 parsestatfs(const u_int32_t
*dp
, int v3
)
1102 const struct nfs_statfs
*sfsp
;
1105 dp
= parsestatus(dp
, &er
);
1106 if (dp
== NULL
|| (!v3
&& er
))
1115 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1119 TCHECK2(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1121 sfsp
= (const struct nfs_statfs
*)dp
;
1125 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1127 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1129 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1132 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1134 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1136 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1138 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1141 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1142 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1143 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1144 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1145 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1146 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1155 parserddires(const u_int32_t
*dp
)
1159 dp
= parsestatus(dp
, &er
);
1166 printf(" offset %x size %d ",
1167 (u_int32_t
)ntohl(dp
[0]), (u_int32_t
)ntohl(dp
[1]));
1176 static const u_int32_t
*
1177 parse_wcc_attr(const u_int32_t
*dp
)
1180 print_int64(dp
, UNSIGNED
);
1181 printf(" mtime %u.%06u ctime %u.%06u",
1182 (u_int32_t
)ntohl(dp
[2]), (u_int32_t
)ntohl(dp
[3]),
1183 (u_int32_t
)ntohl(dp
[4]), (u_int32_t
)ntohl(dp
[5]));
1188 * Pre operation attributes. Print only if vflag > 1.
1190 static const u_int32_t
*
1191 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1199 return parse_wcc_attr(dp
);
1201 /* If not verbose enough, just skip over wcc_attr */
1209 * Post operation attributes are printed if vflag >= 1
1211 static const u_int32_t
*
1212 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1219 return parsefattr(dp
, verbose
, 1);
1221 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1226 static const u_int32_t
*
1227 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1231 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1236 return parse_post_op_attr(dp
, verbose
);
1239 static const u_int32_t
*
1240 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1244 if (!(dp
= parsestatus(dp
, &er
)))
1247 dp
= parse_wcc_data(dp
, verbose
);
1253 if (!(dp
= parsefh(dp
, 1)))
1256 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1259 printf("dir attr:");
1260 dp
= parse_wcc_data(dp
, verbose
);
1270 parsewccres(const u_int32_t
*dp
, int verbose
)
1274 if (!(dp
= parsestatus(dp
, &er
)))
1276 return parse_wcc_data(dp
, verbose
) != 0;
1279 static const u_int32_t
*
1280 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1284 if (!(dp
= parsestatus(dp
, &er
)))
1288 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1294 printf(" verf %08x%08x", dp
[0], dp
[1]);
1303 parsefsinfo(const u_int32_t
*dp
)
1305 struct nfsv3_fsinfo
*sfp
;
1308 if (!(dp
= parsestatus(dp
, &er
)))
1312 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1317 sfp
= (struct nfsv3_fsinfo
*)dp
;
1319 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1320 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1321 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1322 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1323 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1324 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1326 printf(" rtmult %u wtmult %u maxfsz ",
1327 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1328 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1329 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1330 printf(" delta %u.%06u ",
1331 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1332 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1340 parsepathconf(const u_int32_t
*dp
)
1343 struct nfsv3_pathconf
*spp
;
1345 if (!(dp
= parsestatus(dp
, &er
)))
1349 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1354 spp
= (struct nfsv3_pathconf
*)dp
;
1357 printf(" linkmax %u namemax %u %s %s %s %s",
1358 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1359 (u_int32_t
) ntohl(spp
->pc_namemax
),
1360 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1361 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1362 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1363 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1370 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1372 register const u_int32_t
*dp
;
1376 v3
= (vers
== NFS_VER3
);
1378 if (!v3
&& proc
< NFS_NPROCS
)
1379 proc
= nfsv3_procid
[proc
];
1391 case NFSPROC_GETATTR
:
1393 dp
= parserep(rp
, length
);
1394 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1398 case NFSPROC_SETATTR
:
1400 if (!(dp
= parserep(rp
, length
)))
1403 if (parsewccres(dp
, vflag
))
1406 if (parseattrstat(dp
, !qflag
, 0) != 0)
1411 case NFSPROC_LOOKUP
:
1413 if (!(dp
= parserep(rp
, length
)))
1416 if (!(dp
= parsestatus(dp
, &er
)))
1420 printf(" post dattr:");
1421 dp
= parse_post_op_attr(dp
, vflag
);
1424 if (!(dp
= parsefh(dp
, v3
)))
1426 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1428 printf(" post dattr:");
1429 dp
= parse_post_op_attr(dp
, vflag
);
1435 if (parsediropres(dp
) != 0)
1440 case NFSPROC_ACCESS
:
1442 dp
= parserep(rp
, length
);
1443 if (!(dp
= parsestatus(dp
, &er
)))
1447 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1450 printf(" c %04x", (u_int32_t
)ntohl(dp
[0]));
1453 case NFSPROC_READLINK
:
1454 printf(" readlink");
1455 dp
= parserep(rp
, length
);
1456 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1462 if (!(dp
= parserep(rp
, length
)))
1465 if (!(dp
= parsestatus(dp
, &er
)))
1467 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1473 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1479 if (parseattrstat(dp
, vflag
, 0) != 0)
1486 if (!(dp
= parserep(rp
, length
)))
1489 if (!(dp
= parsestatus(dp
, &er
)))
1491 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1497 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1501 tok2str(nfsv3_writemodes
,
1502 NULL
, ntohl(dp
[1])));
1507 if (parseattrstat(dp
, vflag
, v3
) != 0)
1512 case NFSPROC_CREATE
:
1514 if (!(dp
= parserep(rp
, length
)))
1517 if (parsecreateopres(dp
, vflag
) != 0)
1520 if (parsediropres(dp
) != 0)
1527 if (!(dp
= parserep(rp
, length
)))
1530 if (parsecreateopres(dp
, vflag
) != 0)
1533 if (parsediropres(dp
) != 0)
1538 case NFSPROC_SYMLINK
:
1540 if (!(dp
= parserep(rp
, length
)))
1543 if (parsecreateopres(dp
, vflag
) != 0)
1546 if (parsestatus(dp
, &er
) != 0)
1553 if (!(dp
= parserep(rp
, length
)))
1555 if (parsecreateopres(dp
, vflag
) != 0)
1559 case NFSPROC_REMOVE
:
1561 if (!(dp
= parserep(rp
, length
)))
1564 if (parsewccres(dp
, vflag
))
1567 if (parsestatus(dp
, &er
) != 0)
1574 if (!(dp
= parserep(rp
, length
)))
1577 if (parsewccres(dp
, vflag
))
1580 if (parsestatus(dp
, &er
) != 0)
1585 case NFSPROC_RENAME
:
1587 if (!(dp
= parserep(rp
, length
)))
1590 if (!(dp
= parsestatus(dp
, &er
)))
1594 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1597 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1602 if (parsestatus(dp
, &er
) != 0)
1609 if (!(dp
= parserep(rp
, length
)))
1612 if (!(dp
= parsestatus(dp
, &er
)))
1615 printf(" file POST:");
1616 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1619 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1624 if (parsestatus(dp
, &er
) != 0)
1629 case NFSPROC_READDIR
:
1631 if (!(dp
= parserep(rp
, length
)))
1634 if (parsev3rddirres(dp
, vflag
))
1637 if (parserddires(dp
) != 0)
1642 case NFSPROC_READDIRPLUS
:
1643 printf(" readdirplus");
1644 if (!(dp
= parserep(rp
, length
)))
1646 if (parsev3rddirres(dp
, vflag
))
1650 case NFSPROC_FSSTAT
:
1652 dp
= parserep(rp
, length
);
1653 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1657 case NFSPROC_FSINFO
:
1659 dp
= parserep(rp
, length
);
1660 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1664 case NFSPROC_PATHCONF
:
1665 printf(" pathconf");
1666 dp
= parserep(rp
, length
);
1667 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1671 case NFSPROC_COMMIT
:
1673 dp
= parserep(rp
, length
);
1674 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1679 printf(" proc-%u", proc
);
1684 fputs(" [|nfs]", stdout
);