]>
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.71 2000-05-15 00:40:26 assar 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>
53 #include "interface.h"
54 #include "addrtoname.h"
59 static void nfs_printfh(const u_int32_t
*, const u_int
);
60 static void xid_map_enter(const struct rpc_msg
*, const struct ip
*);
61 static int32_t xid_map_find(const struct rpc_msg
*, const struct ip
*,
62 u_int32_t
*, u_int32_t
*);
63 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
64 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
65 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
66 static int print_int64(const u_int32_t
*dp
, int how
);
69 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
71 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
100 static struct tok nfsv3_writemodes
[] = {
107 static struct tok type2str
[] = {
119 * Print out a 64-bit integer. This appears to be different on each system,
120 * try to make the best of it. The integer stored as 2 consecutive XDR
121 * encoded 32-bit integers, to which a pointer is passed.
123 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
124 * integer datatype and can print it.
131 static int print_int64(const u_int32_t
*dp
, int how
)
136 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
139 printf(INT64_FORMAT
, res
);
142 printf(U_INT64_FORMAT
, res
);
145 printf(HEX_INT64_FORMAT
, res
);
155 printf ("0x%x%08x", dp
[0], dp
[1]);
164 static const u_int32_t
*
165 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
168 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
170 sa3
->sa_mode
= ntohl(*dp
++);
174 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
176 sa3
->sa_uid
= ntohl(*dp
++);
180 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
182 sa3
->sa_gid
= ntohl(*dp
++);
186 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
188 sa3
->sa_size
= ntohl(*dp
++);
192 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
194 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
195 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
199 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
201 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
202 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
210 static int nfserr
; /* true if we error rather than trunc */
213 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
216 printf(" mode %o", sa3
->sa_mode
);
218 printf(" uid %u", sa3
->sa_uid
);
220 printf(" gid %u", sa3
->sa_gid
);
222 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
223 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
224 sa3
->sa_atime
.nfsv3_nsec
);
225 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
226 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
227 sa3
->sa_mtime
.nfsv3_nsec
);
232 nfsreply_print(register const u_char
*bp
, u_int length
,
233 register const u_char
*bp2
)
235 register const struct rpc_msg
*rp
;
236 register const struct ip
*ip
;
237 u_int32_t proc
, vers
;
239 nfserr
= 0; /* assume no error */
240 rp
= (const struct rpc_msg
*)bp
;
241 ip
= (const struct ip
*)bp2
;
244 (void)printf("%s.nfs > %s.%u: reply %s %d",
245 ipaddr_string(&ip
->ip_src
),
246 ipaddr_string(&ip
->ip_dst
),
247 (u_int32_t
)ntohl(rp
->rm_xid
),
248 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
252 (void)printf("%s.%u > %s.%u: reply %s %d",
253 ipaddr_string(&ip
->ip_src
),
255 ipaddr_string(&ip
->ip_dst
),
256 (u_int32_t
)ntohl(rp
->rm_xid
),
257 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
261 if (xid_map_find(rp
, ip
, &proc
, &vers
) >= 0)
262 interp_reply(rp
, proc
, vers
, length
);
266 * Return a pointer to the first file handle in the packet.
267 * If the packet was truncated, return 0.
269 static const u_int32_t
*
270 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
272 register const u_int32_t
*dp
;
276 * find the start of the req data (if we captured it)
278 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
282 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
286 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
296 * Print out an NFS file handle and return a pointer to following word.
297 * If packet was truncated, return 0.
299 static const u_int32_t
*
300 parsefh(register const u_int32_t
*dp
, int v3
)
306 len
= (int)ntohl(*dp
) / 4;
311 if (TTEST2(*dp
, len
* sizeof(*dp
))) {
312 nfs_printfh(dp
, len
);
320 * Print out a file name and return pointer to 32-bit word past it.
321 * If packet was truncated, return 0.
323 static const u_int32_t
*
324 parsefn(register const u_int32_t
*dp
)
326 register u_int32_t len
;
327 register const u_char
*cp
;
329 /* Bail if we don't have the string length */
332 /* Fetch string length; convert to host order */
336 TCHECK2(*dp
, ((len
+ 3) & ~3));
339 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
340 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
341 /* XXX seems like we should be checking the length */
343 (void) fn_printn(cp
, len
, NULL
);
352 * Print out file handle and file name.
353 * Return pointer to 32-bit word past file name.
354 * If packet was truncated (or there was some other error), return 0.
356 static const u_int32_t
*
357 parsefhn(register const u_int32_t
*dp
, int v3
)
359 dp
= parsefh(dp
, v3
);
363 return (parsefn(dp
));
367 nfsreq_print(register const u_char
*bp
, u_int length
,
368 register const u_char
*bp2
)
370 register const struct rpc_msg
*rp
;
371 register const struct ip
*ip
;
372 register const u_int32_t
*dp
;
376 struct nfsv3_sattr sa3
;
378 nfserr
= 0; /* assume no error */
379 rp
= (const struct rpc_msg
*)bp
;
380 ip
= (const struct ip
*)bp2
;
382 (void)printf("%s.%u > %s.nfs: %d",
383 ipaddr_string(&ip
->ip_src
),
384 (u_int32_t
)ntohl(rp
->rm_xid
),
385 ipaddr_string(&ip
->ip_dst
),
388 (void)printf("%s.%u > %s.%u: %d",
389 ipaddr_string(&ip
->ip_src
),
390 (u_int32_t
)ntohl(rp
->rm_xid
),
391 ipaddr_string(&ip
->ip_dst
),
395 xid_map_enter(rp
, ip
); /* record proc number for later on */
397 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
398 proc
= ntohl(rp
->rm_call
.cb_proc
);
400 if (!v3
&& proc
< NFS_NPROCS
)
401 proc
= nfsv3_procid
[proc
];
411 case NFSPROC_GETATTR
:
413 if ((dp
= parsereq(rp
, length
)) != NULL
&&
414 parsefh(dp
, v3
) != NULL
)
418 case NFSPROC_SETATTR
:
420 if ((dp
= parsereq(rp
, length
)) != NULL
&&
421 parsefh(dp
, v3
) != NULL
)
427 if ((dp
= parsereq(rp
, length
)) != NULL
&&
428 parsefhn(dp
, v3
) != NULL
)
434 if ((dp
= parsereq(rp
, length
)) != NULL
&&
435 (dp
= parsefh(dp
, v3
)) != NULL
) {
437 printf(" %04x", (unsigned)ntohl(dp
[0]));
442 case NFSPROC_READLINK
:
444 if ((dp
= parsereq(rp
, length
)) != NULL
&&
445 parsefh(dp
, v3
) != NULL
)
451 if ((dp
= parsereq(rp
, length
)) != NULL
&&
452 (dp
= parsefh(dp
, v3
)) != NULL
) {
455 printf(" %u bytes @ ",
456 (u_int32_t
) ntohl(dp
[2]));
457 print_int64(dp
, UNSIGNED
);
460 printf(" %u bytes @ %u",
461 (u_int32_t
)ntohl(dp
[1]),
462 (u_int32_t
)ntohl(dp
[0]));
470 if ((dp
= parsereq(rp
, length
)) != NULL
&&
471 (dp
= parsefh(dp
, v3
)) != NULL
) {
474 printf(" %u bytes @ ",
475 (u_int32_t
) ntohl(dp
[4]));
476 print_int64(dp
, UNSIGNED
);
481 tok2str(nfsv3_writemodes
,
486 printf(" %u (%u) bytes @ %u (%u)",
487 (u_int32_t
)ntohl(dp
[3]),
488 (u_int32_t
)ntohl(dp
[2]),
489 (u_int32_t
)ntohl(dp
[1]),
490 (u_int32_t
)ntohl(dp
[0]));
498 if ((dp
= parsereq(rp
, length
)) != NULL
&&
499 parsefhn(dp
, v3
) != NULL
)
505 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
509 case NFSPROC_SYMLINK
:
511 if ((dp
= parsereq(rp
, length
)) != 0 &&
512 (dp
= parsefhn(dp
, v3
)) != 0) {
513 fputs(" ->", stdout
);
514 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
516 if (parsefn(dp
) == 0)
519 print_sattr3(&sa3
, vflag
);
526 if ((dp
= parsereq(rp
, length
)) != 0 &&
527 (dp
= parsefhn(dp
, v3
)) != 0) {
529 type
= (nfstype
)ntohl(*dp
++);
530 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
532 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
533 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
536 (unsigned)ntohl(dp
[0]),
537 (unsigned)ntohl(dp
[1]));
541 print_sattr3(&sa3
, vflag
);
548 if ((dp
= parsereq(rp
, length
)) != NULL
&&
549 parsefhn(dp
, v3
) != NULL
)
555 if ((dp
= parsereq(rp
, length
)) != NULL
&&
556 parsefhn(dp
, v3
) != NULL
)
562 if ((dp
= parsereq(rp
, length
)) != NULL
&&
563 (dp
= parsefhn(dp
, v3
)) != NULL
) {
564 fputs(" ->", stdout
);
565 if (parsefhn(dp
, v3
) != NULL
)
572 if ((dp
= parsereq(rp
, length
)) != NULL
&&
573 (dp
= parsefh(dp
, v3
)) != NULL
) {
574 fputs(" ->", stdout
);
575 if (parsefhn(dp
, v3
) != NULL
)
580 case NFSPROC_READDIR
:
582 if ((dp
= parsereq(rp
, length
)) != NULL
&&
583 (dp
= parsefh(dp
, v3
)) != NULL
) {
587 * We shouldn't really try to interpret the
588 * offset cookie here.
590 printf(" %u bytes @ ",
591 (u_int32_t
) ntohl(dp
[4]));
592 print_int64(dp
, SIGNED
);
594 printf(" verf %08x%08x", dp
[2],
599 * Print the offset as signed, since -1 is
600 * common, but offsets > 2^31 aren't.
602 printf(" %u bytes @ %d",
603 (u_int32_t
)ntohl(dp
[1]),
604 (u_int32_t
)ntohl(dp
[0]));
610 case NFSPROC_READDIRPLUS
:
611 printf(" readdirplus");
612 if ((dp
= parsereq(rp
, length
)) != NULL
&&
613 (dp
= parsefh(dp
, v3
)) != NULL
) {
616 * We don't try to interpret the offset
619 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
620 print_int64(dp
, SIGNED
);
622 printf(" max %u verf %08x%08x",
623 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
630 if ((dp
= parsereq(rp
, length
)) != NULL
&&
631 parsefh(dp
, v3
) != NULL
)
639 case NFSPROC_PATHCONF
:
645 if ((dp
= parsereq(rp
, length
)) != NULL
&&
646 (dp
= parsefh(dp
, v3
)) != NULL
) {
647 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
648 print_int64(dp
, UNSIGNED
);
654 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
660 fputs(" [|nfs]", stdout
);
664 * Print out an NFS file handle.
665 * We assume packet was not truncated before the end of the
666 * file handle pointed to by dp.
668 * Note: new version (using portable file-handle parser) doesn't produce
669 * generation number. It probably could be made to do that, with some
670 * additional hacking on the parser code.
673 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
677 char *sfsname
= NULL
;
679 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
682 /* file system ID is ASCII, not numeric, for this server OS */
683 static char temp
[NFSX_V3FHMAX
+1];
685 /* Make sure string is null-terminated */
686 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
687 /* Remove trailing spaces */
688 sfsname
= strchr(temp
, ' ');
692 (void)printf(" fh %s/%ld", temp
, (long) ino
);
695 (void)printf(" fh %d,%d/%ld",
696 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
,
702 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
703 * us to match up replies with requests and thus to know how to parse
707 struct xid_map_entry
{
708 u_int32_t xid
; /* transaction ID (net order) */
709 struct in_addr client
; /* client IP address (net order) */
710 struct in_addr server
; /* server IP address (net order) */
711 u_int32_t proc
; /* call proc number (host order) */
712 u_int32_t vers
; /* program version (host order) */
716 * Map entries are kept in an array that we manage as a ring;
717 * new entries are always added at the tail of the ring. Initially,
718 * all the entries are zero and hence don't match anything.
721 #define XIDMAPSIZE 64
723 struct xid_map_entry xid_map
[XIDMAPSIZE
];
725 int xid_map_next
= 0;
726 int xid_map_hint
= 0;
729 xid_map_enter(const struct rpc_msg
*rp
, const struct ip
*ip
)
731 struct xid_map_entry
*xmep
;
733 xmep
= &xid_map
[xid_map_next
];
735 if (++xid_map_next
>= XIDMAPSIZE
)
738 xmep
->xid
= rp
->rm_xid
;
739 xmep
->client
= ip
->ip_src
;
740 xmep
->server
= ip
->ip_dst
;
741 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
742 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
746 * Returns 0 and puts NFSPROC_xxx in proc return and
747 * version in vers return, or returns -1 on failure
750 xid_map_find(const struct rpc_msg
*rp
, const struct ip
*ip
, u_int32_t
*proc
,
754 struct xid_map_entry
*xmep
;
755 u_int32_t xid
= rp
->rm_xid
;
756 u_int32_t clip
= ip
->ip_dst
.s_addr
;
757 u_int32_t sip
= ip
->ip_src
.s_addr
;
759 /* Start searching from where we last left off */
763 if (xmep
->xid
== xid
&& xmep
->client
.s_addr
== clip
&&
764 xmep
->server
.s_addr
== sip
) {
771 if (++i
>= XIDMAPSIZE
)
773 } while (i
!= xid_map_hint
);
780 * Routines for parsing reply packets
784 * Return a pointer to the beginning of the actual results.
785 * If the packet was truncated, return 0.
787 static const u_int32_t
*
788 parserep(register const struct rpc_msg
*rp
, register u_int length
)
790 register const u_int32_t
*dp
;
792 enum accept_stat astat
;
796 * Here we find the address of the ar_verf credentials.
797 * Originally, this calculation was
798 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
799 * On the wire, the rp_acpt field starts immediately after
800 * the (32 bit) rp_stat field. However, rp_acpt (which is a
801 * "struct accepted_reply") contains a "struct opaque_auth",
802 * whose internal representation contains a pointer, so on a
803 * 64-bit machine the compiler inserts 32 bits of padding
804 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
805 * the internal representation to parse the on-the-wire
806 * representation. Instead, we skip past the rp_stat field,
807 * which is an "enum" and so occupies one 32-bit word.
809 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
815 * skip past the ar_verf credentials.
817 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
821 * now we can check the ar_stat field
823 astat
= ntohl(*(enum accept_stat
*)dp
);
830 printf(" PROG_UNAVAIL");
831 nfserr
= 1; /* suppress trunc string */
835 printf(" PROG_MISMATCH");
836 nfserr
= 1; /* suppress trunc string */
840 printf(" PROC_UNAVAIL");
841 nfserr
= 1; /* suppress trunc string */
845 printf(" GARBAGE_ARGS");
846 nfserr
= 1; /* suppress trunc string */
850 printf(" SYSTEM_ERR");
851 nfserr
= 1; /* suppress trunc string */
855 printf(" ar_stat %d", astat
);
856 nfserr
= 1; /* suppress trunc string */
859 /* successful return */
860 TCHECK2(*dp
, sizeof(astat
));
861 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
866 static const u_int32_t
*
867 parsestatus(const u_int32_t
*dp
, int *er
)
873 errnum
= ntohl(dp
[0]);
878 printf(" ERROR: %s", pcap_strerror(errnum
));
887 static const u_int32_t
*
888 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
890 const struct nfs_fattr
*fap
;
892 fap
= (const struct nfs_fattr
*)dp
;
895 printf(" %s %o ids %d/%d",
896 tok2str(type2str
, "unk-ft %d ",
897 (u_int32_t
)ntohl(fap
->fa_type
)),
898 (u_int32_t
)ntohl(fap
->fa_mode
),
899 (u_int32_t
)ntohl(fap
->fa_uid
),
900 (u_int32_t
) ntohl(fap
->fa_gid
));
902 TCHECK(fap
->fa3_size
);
904 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
907 TCHECK(fap
->fa2_size
);
908 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
911 /* print lots more stuff */
914 TCHECK(fap
->fa3_ctime
);
915 printf("nlink %d rdev %d/%d ",
916 (u_int32_t
)ntohl(fap
->fa_nlink
),
917 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
918 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
920 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
922 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
923 printf(" a/m/ctime %u.%06u ",
924 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
925 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
927 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
928 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
930 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
931 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
933 TCHECK(fap
->fa2_ctime
);
934 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
935 (u_int32_t
) ntohl(fap
->fa_nlink
),
936 (u_int32_t
) ntohl(fap
->fa2_rdev
),
937 (u_int32_t
) ntohl(fap
->fa2_fsid
),
938 (u_int32_t
) ntohl(fap
->fa2_fileid
));
940 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
941 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
943 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
944 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
946 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
947 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
950 return ((const u_int32_t
*)((unsigned char *)dp
+
951 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
957 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
961 dp
= parsestatus(dp
, &er
);
962 if (dp
== NULL
|| er
)
965 return (parsefattr(dp
, verbose
, v3
) != NULL
);
969 parsediropres(const u_int32_t
*dp
)
973 if (!(dp
= parsestatus(dp
, &er
)) || er
)
980 return (parsefattr(dp
, vflag
, 0) != NULL
);
984 parselinkres(const u_int32_t
*dp
, int v3
)
988 dp
= parsestatus(dp
, &er
);
989 if (dp
== NULL
|| er
)
991 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
994 return (parsefn(dp
) != NULL
);
998 parsestatfs(const u_int32_t
*dp
, int v3
)
1000 const struct nfs_statfs
*sfsp
;
1003 dp
= parsestatus(dp
, &er
);
1004 if (dp
== NULL
|| (!v3
&& er
))
1013 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1017 TCHECK2(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1019 sfsp
= (const struct nfs_statfs
*)dp
;
1023 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1025 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1027 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1030 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1032 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1034 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1036 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1039 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1040 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1041 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1042 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1043 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1044 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1053 parserddires(const u_int32_t
*dp
)
1057 dp
= parsestatus(dp
, &er
);
1064 printf(" offset %x size %d ",
1065 (unsigned)ntohl(dp
[0]), (unsigned)ntohl(dp
[1]));
1074 static const u_int32_t
*
1075 parse_wcc_attr(const u_int32_t
*dp
)
1078 print_int64(dp
, UNSIGNED
);
1079 printf(" mtime %u.%06u ctime %u.%06u",
1080 (unsigned)ntohl(dp
[2]), (unsigned)ntohl(dp
[3]),
1081 (unsigned)ntohl(dp
[4]), (unsigned)ntohl(dp
[5]));
1086 * Pre operation attributes. Print only if vflag > 1.
1088 static const u_int32_t
*
1089 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1097 return parse_wcc_attr(dp
);
1099 /* If not verbose enough, just skip over wcc_attr */
1107 * Post operation attributes are printed if vflag >= 1
1109 static const u_int32_t
*
1110 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1117 return parsefattr(dp
, verbose
, 1);
1119 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1124 static const u_int32_t
*
1125 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1129 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1134 return parse_post_op_attr(dp
, verbose
);
1137 static const u_int32_t
*
1138 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1142 if (!(dp
= parsestatus(dp
, &er
)))
1145 dp
= parse_wcc_data(dp
, verbose
);
1151 if (!(dp
= parsefh(dp
, 1)))
1154 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1157 printf("dir attr:");
1158 dp
= parse_wcc_data(dp
, verbose
);
1168 parsewccres(const u_int32_t
*dp
, int verbose
)
1172 if (!(dp
= parsestatus(dp
, &er
)))
1174 return parse_wcc_data(dp
, verbose
) != 0;
1177 static const u_int32_t
*
1178 parsev3rddirres(const u_int32_t
*dp
, int verbose
)
1182 if (!(dp
= parsestatus(dp
, &er
)))
1186 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1192 printf(" verf %08x%08x", dp
[0], dp
[1]);
1201 parsefsinfo(const u_int32_t
*dp
)
1203 struct nfsv3_fsinfo
*sfp
;
1206 if (!(dp
= parsestatus(dp
, &er
)))
1210 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1215 sfp
= (struct nfsv3_fsinfo
*)dp
;
1217 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1218 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1219 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1220 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1221 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1222 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1224 printf(" rtmult %u wtmult %u maxfsz ",
1225 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1226 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1227 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1228 printf(" delta %u.%06u ",
1229 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1230 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1238 parsepathconf(const u_int32_t
*dp
)
1241 struct nfsv3_pathconf
*spp
;
1243 if (!(dp
= parsestatus(dp
, &er
)))
1247 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1252 spp
= (struct nfsv3_pathconf
*)dp
;
1255 printf(" linkmax %u namemax %u %s %s %s %s",
1256 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1257 (u_int32_t
) ntohl(spp
->pc_namemax
),
1258 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1259 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1260 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1261 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1268 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1270 register const u_int32_t
*dp
;
1274 v3
= (vers
== NFS_VER3
);
1276 if (!v3
&& proc
< NFS_NPROCS
)
1277 proc
= nfsv3_procid
[proc
];
1289 case NFSPROC_GETATTR
:
1291 dp
= parserep(rp
, length
);
1292 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1296 case NFSPROC_SETATTR
:
1298 if (!(dp
= parserep(rp
, length
)))
1301 if (parsewccres(dp
, vflag
))
1304 if (parseattrstat(dp
, !qflag
, 0) != 0)
1309 case NFSPROC_LOOKUP
:
1311 if (!(dp
= parserep(rp
, length
)))
1314 if (!(dp
= parsestatus(dp
, &er
)))
1318 printf(" post dattr:");
1319 dp
= parse_post_op_attr(dp
, vflag
);
1322 if (!(dp
= parsefh(dp
, v3
)))
1324 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1326 printf(" post dattr:");
1327 dp
= parse_post_op_attr(dp
, vflag
);
1333 if (parsediropres(dp
) != 0)
1338 case NFSPROC_ACCESS
:
1340 dp
= parserep(rp
, length
);
1341 if (!(dp
= parsestatus(dp
, &er
)))
1345 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1348 printf(" c %04x", (unsigned)ntohl(dp
[0]));
1351 case NFSPROC_READLINK
:
1352 printf(" readlink");
1353 dp
= parserep(rp
, length
);
1354 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1360 if (!(dp
= parserep(rp
, length
)))
1363 if (!(dp
= parsestatus(dp
, &er
)))
1365 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1371 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1377 if (parseattrstat(dp
, vflag
, 0) != 0)
1384 if (!(dp
= parserep(rp
, length
)))
1387 if (!(dp
= parsestatus(dp
, &er
)))
1389 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1395 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1399 tok2str(nfsv3_writemodes
,
1400 NULL
, ntohl(dp
[1])));
1405 if (parseattrstat(dp
, vflag
, v3
) != 0)
1410 case NFSPROC_CREATE
:
1412 if (!(dp
= parserep(rp
, length
)))
1415 if (parsecreateopres(dp
, vflag
) != 0)
1418 if (parsediropres(dp
) != 0)
1425 if (!(dp
= parserep(rp
, length
)))
1428 if (parsecreateopres(dp
, vflag
) != 0)
1431 if (parsediropres(dp
) != 0)
1436 case NFSPROC_SYMLINK
:
1438 if (!(dp
= parserep(rp
, length
)))
1441 if (parsecreateopres(dp
, vflag
) != 0)
1444 if (parsestatus(dp
, &er
) != 0)
1451 if (!(dp
= parserep(rp
, length
)))
1453 if (parsecreateopres(dp
, vflag
) != 0)
1457 case NFSPROC_REMOVE
:
1459 if (!(dp
= parserep(rp
, length
)))
1462 if (parsewccres(dp
, vflag
))
1465 if (parsestatus(dp
, &er
) != 0)
1472 if (!(dp
= parserep(rp
, length
)))
1475 if (parsewccres(dp
, vflag
))
1478 if (parsestatus(dp
, &er
) != 0)
1483 case NFSPROC_RENAME
:
1485 if (!(dp
= parserep(rp
, length
)))
1488 if (!(dp
= parsestatus(dp
, &er
)))
1492 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1495 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1500 if (parsestatus(dp
, &er
) != 0)
1507 if (!(dp
= parserep(rp
, length
)))
1510 if (!(dp
= parsestatus(dp
, &er
)))
1513 printf(" file POST:");
1514 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1517 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1522 if (parsestatus(dp
, &er
) != 0)
1527 case NFSPROC_READDIR
:
1529 if (!(dp
= parserep(rp
, length
)))
1532 if (parsev3rddirres(dp
, vflag
))
1535 if (parserddires(dp
) != 0)
1540 case NFSPROC_READDIRPLUS
:
1541 printf(" readdirplus");
1542 if (!(dp
= parserep(rp
, length
)))
1544 if (parsev3rddirres(dp
, vflag
))
1548 case NFSPROC_FSSTAT
:
1550 dp
= parserep(rp
, length
);
1551 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1555 case NFSPROC_FSINFO
:
1557 dp
= parserep(rp
, length
);
1558 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1562 case NFSPROC_PATHCONF
:
1563 printf(" pathconf");
1564 dp
= parserep(rp
, length
);
1565 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1569 case NFSPROC_COMMIT
:
1571 dp
= parserep(rp
, length
);
1572 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1577 printf(" proc-%u", proc
);
1582 fputs(" [|nfs]", stdout
);