]>
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.67 1999-11-21 05:43:50 assar Exp $ (LBL)";
27 #include <sys/param.h>
29 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <netinet/if_ether.h>
39 #include <netinet/in_systm.h>
40 #include <netinet/ip.h>
49 #include "interface.h"
50 #include "addrtoname.h"
55 static void nfs_printfh(const u_int32_t
*, const u_int
);
56 static void xid_map_enter(const struct rpc_msg
*, const struct ip
*);
57 static int32_t xid_map_find(const struct rpc_msg
*, const struct ip
*,
58 u_int32_t
*, u_int32_t
*);
59 static void interp_reply(const struct rpc_msg
*, u_int32_t
, u_int32_t
, int);
60 static const u_int32_t
*parse_post_op_attr(const u_int32_t
*, int);
61 static void print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
);
62 static int print_int64(const u_int32_t
*dp
, int how
);
65 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
67 u_int32_t nfsv3_procid
[NFS_NPROCS
] = {
96 const char *nfsv3_writemodes
[NFSV3WRITE_NMODES
] = {
102 static struct tok type2str
[] = {
114 * Print out a 64-bit integer. This appears to be different on each system,
115 * try to make the best of it. The integer stored as 2 consecutive XDR
116 * encoded 32-bit integers, to which a pointer is passed.
118 * Assume that a system that has INT64_FORMAT defined, has a 64-bit
119 * integer datatype and can print it.
126 static int print_int64(const u_int32_t
*dp
, int how
)
131 res
= ((u_int64_t
)ntohl(dp
[0]) << 32) | (u_int64_t
)ntohl(dp
[1]);
134 printf(INT64_FORMAT
, res
);
137 printf(U_INT64_FORMAT
, res
);
140 printf(HEX_INT64_FORMAT
, res
);
150 printf ("0x%x%x", dp
[0], dp
[1]);
159 static const u_int32_t
*
160 parse_sattr3(const u_int32_t
*dp
, struct nfsv3_sattr
*sa3
)
162 register const u_int32_t
*ep
= (u_int32_t
*)snapend
;
166 if ((sa3
->sa_modeset
= ntohl(*dp
++))) {
169 sa3
->sa_mode
= ntohl(*dp
++);
174 if ((sa3
->sa_uidset
= ntohl(*dp
++))) {
177 sa3
->sa_uid
= ntohl(*dp
++);
182 if ((sa3
->sa_gidset
= ntohl(*dp
++))) {
185 sa3
->sa_gid
= ntohl(*dp
++);
190 if ((sa3
->sa_sizeset
= ntohl(*dp
++))) {
193 sa3
->sa_size
= ntohl(*dp
++);
198 if ((sa3
->sa_atimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
201 sa3
->sa_atime
.nfsv3_sec
= ntohl(*dp
++);
202 sa3
->sa_atime
.nfsv3_nsec
= ntohl(*dp
++);
207 if ((sa3
->sa_mtimetype
= ntohl(*dp
++)) == NFSV3SATTRTIME_TOCLIENT
) {
210 sa3
->sa_mtime
.nfsv3_sec
= ntohl(*dp
++);
211 sa3
->sa_mtime
.nfsv3_nsec
= ntohl(*dp
++);
217 static int nfserr
; /* true if we error rather than trunc */
220 print_sattr3(const struct nfsv3_sattr
*sa3
, int verbose
)
223 printf(" mode %o", sa3
->sa_mode
);
225 printf(" uid %u", sa3
->sa_uid
);
227 printf(" gid %u", sa3
->sa_gid
);
229 if (sa3
->sa_atimetype
== NFSV3SATTRTIME_TOCLIENT
)
230 printf(" atime %u.%06u", sa3
->sa_atime
.nfsv3_sec
,
231 sa3
->sa_atime
.nfsv3_nsec
);
232 if (sa3
->sa_mtimetype
== NFSV3SATTRTIME_TOCLIENT
)
233 printf(" mtime %u.%06u", sa3
->sa_mtime
.nfsv3_sec
,
234 sa3
->sa_mtime
.nfsv3_nsec
);
239 nfsreply_print(register const u_char
*bp
, u_int length
,
240 register const u_char
*bp2
)
242 register const struct rpc_msg
*rp
;
243 register const struct ip
*ip
;
244 u_int32_t proc
, vers
;
246 nfserr
= 0; /* assume no error */
247 rp
= (const struct rpc_msg
*)bp
;
248 ip
= (const struct ip
*)bp2
;
251 (void)printf("%s.nfs > %s.%u: reply %s %d",
252 ipaddr_string(&ip
->ip_src
),
253 ipaddr_string(&ip
->ip_dst
),
254 (u_int32_t
)ntohl(rp
->rm_xid
),
255 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
259 (void)printf("%s.%u > %s.%u: reply %s %d",
260 ipaddr_string(&ip
->ip_src
),
262 ipaddr_string(&ip
->ip_dst
),
263 (u_int32_t
)ntohl(rp
->rm_xid
),
264 ntohl(rp
->rm_reply
.rp_stat
) == MSG_ACCEPTED
?
268 if (xid_map_find(rp
, ip
, &proc
, &vers
) >= 0)
269 interp_reply(rp
, proc
, vers
, length
);
273 * Return a pointer to the first file handle in the packet.
274 * If the packet was truncated, return 0.
276 static const u_int32_t
*
277 parsereq(register const struct rpc_msg
*rp
, register u_int length
)
279 register const u_int32_t
*dp
;
283 * find the start of the req data (if we captured it)
285 dp
= (u_int32_t
*)&rp
->rm_call
.cb_cred
;
289 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
293 dp
+= (len
+ (2 * sizeof(*dp
) + 3)) / sizeof(*dp
);
303 * Print out an NFS file handle and return a pointer to following word.
304 * If packet was truncated, return 0.
306 static const u_int32_t
*
307 parsefh(register const u_int32_t
*dp
, int v3
)
312 if (dp
+ 1 > (u_int32_t
*)snapend
)
314 len
= (int)ntohl(*dp
) / 4;
319 if (dp
+ len
<= (u_int32_t
*)snapend
) {
320 nfs_printfh(dp
, len
);
327 * Print out a file name and return pointer to 32-bit word past it.
328 * If packet was truncated, return 0.
330 static const u_int32_t
*
331 parsefn(register const u_int32_t
*dp
)
333 register u_int32_t len
;
334 register const u_char
*cp
;
336 /* Bail if we don't have the string length */
337 if ((u_char
*)dp
> snapend
- sizeof(*dp
))
340 /* Fetch string length; convert to host order */
345 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
346 dp
+= ((len
+ 3) & ~3) / sizeof(*dp
);
347 if ((u_char
*)dp
> snapend
)
349 /* XXX seems like we should be checking the length */
351 (void) fn_printn(cp
, len
, NULL
);
358 * Print out file handle and file name.
359 * Return pointer to 32-bit word past file name.
360 * If packet was truncated (or there was some other error), return 0.
362 static const u_int32_t
*
363 parsefhn(register const u_int32_t
*dp
, int v3
)
365 dp
= parsefh(dp
, v3
);
369 return (parsefn(dp
));
373 nfsreq_print(register const u_char
*bp
, u_int length
,
374 register const u_char
*bp2
)
376 register const struct rpc_msg
*rp
;
377 register const struct ip
*ip
;
378 register const u_int32_t
*dp
;
382 struct nfsv3_sattr sa3
;
384 nfserr
= 0; /* assume no error */
385 rp
= (const struct rpc_msg
*)bp
;
386 ip
= (const struct ip
*)bp2
;
388 (void)printf("%s.%u > %s.nfs: %d",
389 ipaddr_string(&ip
->ip_src
),
390 (u_int32_t
)ntohl(rp
->rm_xid
),
391 ipaddr_string(&ip
->ip_dst
),
394 (void)printf("%s.%u > %s.%u: %d",
395 ipaddr_string(&ip
->ip_src
),
396 (u_int32_t
)ntohl(rp
->rm_xid
),
397 ipaddr_string(&ip
->ip_dst
),
401 xid_map_enter(rp
, ip
); /* record proc number for later on */
403 v3
= (ntohl(rp
->rm_call
.cb_vers
) == NFS_VER3
);
404 proc
= ntohl(rp
->rm_call
.cb_proc
);
406 if (!v3
&& proc
< NFS_NPROCS
)
407 proc
= nfsv3_procid
[proc
];
417 case NFSPROC_GETATTR
:
419 if ((dp
= parsereq(rp
, length
)) != NULL
&&
420 parsefh(dp
, v3
) != NULL
)
424 case NFSPROC_SETATTR
:
426 if ((dp
= parsereq(rp
, length
)) != NULL
&&
427 parsefh(dp
, v3
) != NULL
)
433 if ((dp
= parsereq(rp
, length
)) != NULL
&&
434 parsefhn(dp
, v3
) != NULL
)
440 if ((dp
= parsereq(rp
, length
)) != NULL
&&
441 (dp
= parsefh(dp
, v3
)) != NULL
) {
443 printf(" %04x", ntohl(dp
[0]));
448 case NFSPROC_READLINK
:
450 if ((dp
= parsereq(rp
, length
)) != NULL
&&
451 parsefh(dp
, v3
) != NULL
)
457 if ((dp
= parsereq(rp
, length
)) != NULL
&&
458 (dp
= parsefh(dp
, v3
)) != NULL
) {
460 TCHECK2(dp
[0], 3 * sizeof(*dp
));
461 printf(" %u bytes @ ",
462 (u_int32_t
) ntohl(dp
[2]));
463 print_int64(dp
, UNSIGNED
);
465 TCHECK2(dp
[0], 2 * sizeof(*dp
));
466 printf(" %u bytes @ %u",
467 (u_int32_t
)ntohl(dp
[1]),
468 (u_int32_t
)ntohl(dp
[0]));
476 if ((dp
= parsereq(rp
, length
)) != NULL
&&
477 (dp
= parsefh(dp
, v3
)) != NULL
) {
479 TCHECK2(dp
[0], 3 * sizeof(*dp
));
480 printf(" %u bytes @ ",
481 (u_int32_t
) ntohl(dp
[4]));
482 print_int64(dp
, UNSIGNED
);
485 TCHECK2(dp
[0], sizeof(*dp
));
487 nfsv3_writemodes
[ntohl(*dp
)]);
490 TCHECK2(dp
[0], 4 * sizeof(*dp
));
491 printf(" %u (%u) bytes @ %u (%u)",
492 (u_int32_t
)ntohl(dp
[3]),
493 (u_int32_t
)ntohl(dp
[2]),
494 (u_int32_t
)ntohl(dp
[1]),
495 (u_int32_t
)ntohl(dp
[0]));
503 if ((dp
= parsereq(rp
, length
)) != NULL
&&
504 parsefhn(dp
, v3
) != NULL
)
510 if ((dp
= parsereq(rp
, length
)) != 0 && parsefhn(dp
, v3
) != 0)
514 case NFSPROC_SYMLINK
:
516 if ((dp
= parsereq(rp
, length
)) != 0 &&
517 (dp
= parsefhn(dp
, v3
)) != 0) {
518 fputs(" ->", stdout
);
519 if (v3
&& (dp
= parse_sattr3(dp
, &sa3
)) == 0)
521 if (parsefn(dp
) == 0)
524 print_sattr3(&sa3
, vflag
);
531 if ((dp
= parsereq(rp
, length
)) != 0 &&
532 (dp
= parsefhn(dp
, v3
)) != 0) {
533 if (dp
+ 1 > (u_int32_t
*)snapend
)
535 type
= (nfstype
)ntohl(*dp
++);
536 if ((dp
= parse_sattr3(dp
, &sa3
)) == 0)
538 printf(" %s", tok2str(type2str
, "unk-ft %d", type
));
539 if (vflag
&& (type
== NFCHR
|| type
== NFBLK
)) {
540 if (dp
+ 2 > (u_int32_t
*)snapend
)
542 printf(" %u/%u", ntohl(dp
[0]), ntohl(dp
[1]));
546 print_sattr3(&sa3
, vflag
);
553 if ((dp
= parsereq(rp
, length
)) != NULL
&&
554 parsefhn(dp
, v3
) != NULL
)
560 if ((dp
= parsereq(rp
, length
)) != NULL
&&
561 parsefhn(dp
, v3
) != NULL
)
567 if ((dp
= parsereq(rp
, length
)) != NULL
&&
568 (dp
= parsefhn(dp
, v3
)) != NULL
) {
569 fputs(" ->", stdout
);
570 if (parsefhn(dp
, v3
) != NULL
)
577 if ((dp
= parsereq(rp
, length
)) != NULL
&&
578 (dp
= parsefh(dp
, v3
)) != NULL
) {
579 fputs(" ->", stdout
);
580 if (parsefhn(dp
, v3
) != NULL
)
585 case NFSPROC_READDIR
:
587 if ((dp
= parsereq(rp
, length
)) != NULL
&&
588 (dp
= parsefh(dp
, v3
)) != NULL
) {
592 * We shouldn't really try to interpret the
593 * offset cookie here.
595 printf(" %u bytes @ ",
596 (u_int32_t
) ntohl(dp
[4]));
597 print_int64(dp
, SIGNED
);
599 printf(" verf %08x%08x", dp
[2],
602 TCHECK2(dp
[0], 2 * sizeof(*dp
));
604 * Print the offset as signed, since -1 is
605 * common, but offsets > 2^31 aren't.
607 printf(" %u bytes @ %d",
608 (u_int32_t
)ntohl(dp
[1]),
609 (u_int32_t
)ntohl(dp
[0]));
615 case NFSPROC_READDIRPLUS
:
616 printf(" readdirplus");
617 if ((dp
= parsereq(rp
, length
)) != NULL
&&
618 (dp
= parsefh(dp
, v3
)) != NULL
) {
621 * We don't try to interpret the offset
624 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[4]));
625 print_int64(dp
, SIGNED
);
627 printf(" max %u verf %08x%08x",
628 (u_int32_t
) ntohl(dp
[5]), dp
[2], dp
[3]);
635 if ((dp
= parsereq(rp
, length
)) != NULL
&&
636 parsefh(dp
, v3
) != NULL
)
644 case NFSPROC_PATHCONF
:
650 if ((dp
= parsereq(rp
, length
)) != NULL
&&
651 (dp
= parsefh(dp
, v3
)) != NULL
) {
652 printf(" %u bytes @ ", (u_int32_t
) ntohl(dp
[2]));
653 print_int64(dp
, UNSIGNED
);
659 printf(" proc-%u", (u_int32_t
)ntohl(rp
->rm_call
.cb_proc
));
664 fputs(" [|nfs]", stdout
);
668 * Print out an NFS file handle.
669 * We assume packet was not truncated before the end of the
670 * file handle pointed to by dp.
672 * Note: new version (using portable file-handle parser) doesn't produce
673 * generation number. It probably could be made to do that, with some
674 * additional hacking on the parser code.
677 nfs_printfh(register const u_int32_t
*dp
, const u_int len
)
681 char *sfsname
= NULL
;
683 Parse_fh((caddr_t
*)dp
, len
, &fsid
, &ino
, NULL
, &sfsname
, 0);
686 /* file system ID is ASCII, not numeric, for this server OS */
687 static char temp
[NFSX_V3FHMAX
+1];
689 /* Make sure string is null-terminated */
690 strncpy(temp
, sfsname
, NFSX_V3FHMAX
);
691 /* Remove trailing spaces */
692 sfsname
= strchr(temp
, ' ');
696 (void)printf(" fh %s/%ld", temp
, (long) ino
);
699 (void)printf(" fh %d,%d/%ld",
700 fsid
.Fsid_dev
.Major
, fsid
.Fsid_dev
.Minor
,
706 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
707 * us to match up replies with requests and thus to know how to parse
711 struct xid_map_entry
{
712 u_int32_t xid
; /* transaction ID (net order) */
713 struct in_addr client
; /* client IP address (net order) */
714 struct in_addr server
; /* server IP address (net order) */
715 u_int32_t proc
; /* call proc number (host order) */
716 u_int32_t vers
; /* program version (host order) */
720 * Map entries are kept in an array that we manage as a ring;
721 * new entries are always added at the tail of the ring. Initially,
722 * all the entries are zero and hence don't match anything.
725 #define XIDMAPSIZE 64
727 struct xid_map_entry xid_map
[XIDMAPSIZE
];
729 int xid_map_next
= 0;
730 int xid_map_hint
= 0;
733 xid_map_enter(const struct rpc_msg
*rp
, const struct ip
*ip
)
735 struct xid_map_entry
*xmep
;
737 xmep
= &xid_map
[xid_map_next
];
739 if (++xid_map_next
>= XIDMAPSIZE
)
742 xmep
->xid
= rp
->rm_xid
;
743 xmep
->client
= ip
->ip_src
;
744 xmep
->server
= ip
->ip_dst
;
745 xmep
->proc
= ntohl(rp
->rm_call
.cb_proc
);
746 xmep
->vers
= ntohl(rp
->rm_call
.cb_vers
);
749 /* Returns NFSPROC_xxx or -1 on failure */
751 xid_map_find(const struct rpc_msg
*rp
, const struct ip
*ip
, u_int32_t
*proc
,
755 struct xid_map_entry
*xmep
;
756 u_int32_t xid
= rp
->rm_xid
;
757 u_int32_t clip
= ip
->ip_dst
.s_addr
;
758 u_int32_t sip
= ip
->ip_src
.s_addr
;
760 /* Start searching from where we last left off */
764 if (xmep
->xid
== xid
&& xmep
->client
.s_addr
== clip
&&
765 xmep
->server
.s_addr
== sip
) {
772 if (++i
>= XIDMAPSIZE
)
774 } while (i
!= xid_map_hint
);
781 * Routines for parsing reply packets
785 * Return a pointer to the beginning of the actual results.
786 * If the packet was truncated, return 0.
788 static const u_int32_t
*
789 parserep(register const struct rpc_msg
*rp
, register u_int length
)
791 register const u_int32_t
*dp
;
793 enum accept_stat astat
;
797 * Here we find the address of the ar_verf credentials.
798 * Originally, this calculation was
799 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
800 * On the wire, the rp_acpt field starts immediately after
801 * the (32 bit) rp_stat field. However, rp_acpt (which is a
802 * "struct accepted_reply") contains a "struct opaque_auth",
803 * whose internal representation contains a pointer, so on a
804 * 64-bit machine the compiler inserts 32 bits of padding
805 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
806 * the internal representation to parse the on-the-wire
807 * representation. Instead, we skip past the rp_stat field,
808 * which is an "enum" and so occupies one 32-bit word.
810 dp
= ((const u_int32_t
*)&rp
->rm_reply
) + 1;
816 * skip past the ar_verf credentials.
818 dp
+= (len
+ (2*sizeof(u_int32_t
) + 3)) / sizeof(u_int32_t
);
822 * now we can check the ar_stat field
824 astat
= ntohl(*(enum accept_stat
*)dp
);
831 printf(" PROG_UNAVAIL");
832 nfserr
= 1; /* suppress trunc string */
836 printf(" PROG_MISMATCH");
837 nfserr
= 1; /* suppress trunc string */
841 printf(" PROC_UNAVAIL");
842 nfserr
= 1; /* suppress trunc string */
846 printf(" GARBAGE_ARGS");
847 nfserr
= 1; /* suppress trunc string */
851 printf(" SYSTEM_ERR");
852 nfserr
= 1; /* suppress trunc string */
856 printf(" ar_stat %d", astat
);
857 nfserr
= 1; /* suppress trunc string */
860 /* successful return */
861 if ((sizeof(astat
) + ((u_char
*)dp
)) < snapend
)
862 return ((u_int32_t
*) (sizeof(astat
) + ((char *)dp
)));
867 #define T2CHECK(p, l) if ((u_char *)(p) > ((u_char *)snapend) - l) return(0)
870 * Not all systems have strerror().
875 return (strerror(errno
));
878 static const u_int32_t
*
879 parsestatus(const u_int32_t
*dp
, int *er
)
884 errno
= ntohl(dp
[0]);
887 if (errno
!= 0 && !qflag
) {
890 errmsg
= strerr(errno
);
892 printf(" ERROR: '%s'", errmsg
);
894 printf(" ERROR: %d", errno
);
899 static const u_int32_t
*
900 parsefattr(const u_int32_t
*dp
, int verbose
, int v3
)
902 const struct nfs_fattr
*fap
;
904 T2CHECK(dp
, 5 * sizeof(*dp
));
906 fap
= (const struct nfs_fattr
*)dp
;
908 printf(" %s %o ids %d/%d",
909 tok2str(type2str
, "unk-ft %d ",
910 (u_int32_t
)ntohl(fap
->fa_type
)),
911 (u_int32_t
)ntohl(fap
->fa_mode
),
912 (u_int32_t
)ntohl(fap
->fa_uid
),
913 (u_int32_t
) ntohl(fap
->fa_gid
));
915 T2CHECK(dp
, 7 * sizeof(*dp
));
917 print_int64((u_int32_t
*)&fap
->fa3_size
, UNSIGNED
);
921 T2CHECK(dp
, 6 * sizeof(*dp
));
922 printf(" sz %d ", (u_int32_t
) ntohl(fap
->fa2_size
));
925 /* print lots more stuff */
929 printf("nlink %d rdev %d/%d ",
930 (u_int32_t
)ntohl(fap
->fa_nlink
),
931 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata1
),
932 (u_int32_t
) ntohl(fap
->fa3_rdev
.specdata2
));
934 print_int64((u_int32_t
*)&fap
->fa2_fsid
, HEX
);
936 print_int64((u_int32_t
*)&fap
->fa2_fileid
, HEX
);
937 printf(" a/m/ctime %u.%06u ",
938 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_sec
),
939 (u_int32_t
) ntohl(fap
->fa3_atime
.nfsv3_nsec
));
941 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_sec
),
942 (u_int32_t
) ntohl(fap
->fa3_mtime
.nfsv3_nsec
));
944 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_sec
),
945 (u_int32_t
) ntohl(fap
->fa3_ctime
.nfsv3_nsec
));
948 printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
949 (u_int32_t
) ntohl(fap
->fa_nlink
),
950 (u_int32_t
) ntohl(fap
->fa2_rdev
),
951 (u_int32_t
) ntohl(fap
->fa2_fsid
),
952 (u_int32_t
) ntohl(fap
->fa2_fileid
));
954 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_sec
),
955 (u_int32_t
) ntohl(fap
->fa2_atime
.nfsv2_usec
));
957 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_sec
),
958 (u_int32_t
) ntohl(fap
->fa2_mtime
.nfsv2_usec
));
960 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_sec
),
961 (u_int32_t
) ntohl(fap
->fa2_ctime
.nfsv2_usec
));
964 return ((const u_int32_t
*)((unsigned char *)dp
+
965 (v3
? NFSX_V3FATTR
: NFSX_V2FATTR
)));
969 parseattrstat(const u_int32_t
*dp
, int verbose
, int v3
)
973 dp
= parsestatus(dp
, &er
);
974 if (dp
== NULL
|| er
)
977 return (parsefattr(dp
, verbose
, v3
) != NULL
);
981 parsediropres(const u_int32_t
*dp
)
985 if (!(dp
= parsestatus(dp
, &er
)) || er
)
992 return (parsefattr(dp
, vflag
, 0) != NULL
);
996 parselinkres(const u_int32_t
*dp
, int v3
)
1000 dp
= parsestatus(dp
, &er
);
1001 if (dp
== NULL
|| er
)
1003 if (v3
&& !(dp
= parse_post_op_attr(dp
, vflag
)))
1006 return (parsefn(dp
) != NULL
);
1010 parsestatfs(const u_int32_t
*dp
, int v3
)
1012 const struct nfs_statfs
*sfsp
;
1015 dp
= parsestatus(dp
, &er
);
1016 if (dp
== NULL
|| (!v3
&& er
))
1025 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1029 T2CHECK(dp
, (v3
? NFSX_V3STATFS
: NFSX_V2STATFS
));
1031 sfsp
= (const struct nfs_statfs
*)dp
;
1035 print_int64((u_int32_t
*)&sfsp
->sf_tbytes
, UNSIGNED
);
1037 print_int64((u_int32_t
*)&sfsp
->sf_fbytes
, UNSIGNED
);
1039 print_int64((u_int32_t
*)&sfsp
->sf_abytes
, UNSIGNED
);
1042 print_int64((u_int32_t
*)&sfsp
->sf_tfiles
, UNSIGNED
);
1044 print_int64((u_int32_t
*)&sfsp
->sf_ffiles
, UNSIGNED
);
1046 print_int64((u_int32_t
*)&sfsp
->sf_afiles
, UNSIGNED
);
1048 (u_int32_t
) ntohl(sfsp
->sf_invarsec
));
1051 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1052 (u_int32_t
)ntohl(sfsp
->sf_tsize
),
1053 (u_int32_t
)ntohl(sfsp
->sf_bsize
),
1054 (u_int32_t
)ntohl(sfsp
->sf_blocks
),
1055 (u_int32_t
)ntohl(sfsp
->sf_bfree
),
1056 (u_int32_t
)ntohl(sfsp
->sf_bavail
));
1063 parserddires(const u_int32_t
*dp
)
1067 dp
= parsestatus(dp
, &er
);
1074 printf(" offset %x size %d ", ntohl(dp
[0]), ntohl(dp
[1]));
1081 static const u_int32_t
*
1082 parse_wcc_attr(const u_int32_t
*dp
)
1085 print_int64(dp
, UNSIGNED
);
1086 printf(" mtime %u.%06u ctime %u.%06u", ntohl(dp
[2]), ntohl(dp
[3]),
1087 ntohl(dp
[4]), ntohl(dp
[5]));
1092 * Pre operation attributes. Print only if vflag > 1.
1094 static const u_int32_t
*
1095 parse_pre_op_attr(const u_int32_t
*dp
, int verbose
)
1103 return parse_wcc_attr(dp
);
1105 /* If not verbose enough, just skip over wcc_attr */
1111 * Post operation attributes are printed if vflag >= 1
1113 static const u_int32_t
*
1114 parse_post_op_attr(const u_int32_t
*dp
, int verbose
)
1121 return parsefattr(dp
, verbose
, 1);
1123 return (dp
+ (NFSX_V3FATTR
/ sizeof (u_int32_t
)));
1126 static const u_int32_t
*
1127 parse_wcc_data(const u_int32_t
*dp
, int verbose
)
1131 if (!(dp
= parse_pre_op_attr(dp
, verbose
)))
1136 return parse_post_op_attr(dp
, verbose
);
1139 static const u_int32_t
*
1140 parsecreateopres(const u_int32_t
*dp
, int verbose
)
1144 if (!(dp
= parsestatus(dp
, &er
)))
1147 dp
= parse_wcc_data(dp
, verbose
);
1153 if (!(dp
= parsefh(dp
, 1)))
1156 if (!(dp
= parse_post_op_attr(dp
, verbose
)))
1159 printf("dir attr:");
1160 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]);
1199 parsefsinfo(const u_int32_t
*dp
)
1201 struct nfsv3_fsinfo
*sfp
;
1204 if (!(dp
= parsestatus(dp
, &er
)))
1208 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1213 T2CHECK(dp
, sizeof (struct nfsv3_fsinfo
));
1215 sfp
= (struct nfsv3_fsinfo
*)dp
;
1216 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1217 (u_int32_t
) ntohl(sfp
->fs_rtmax
),
1218 (u_int32_t
) ntohl(sfp
->fs_rtpref
),
1219 (u_int32_t
) ntohl(sfp
->fs_wtmax
),
1220 (u_int32_t
) ntohl(sfp
->fs_wtpref
),
1221 (u_int32_t
) ntohl(sfp
->fs_dtpref
));
1223 printf(" rtmult %u wtmult %u maxfsz ",
1224 (u_int32_t
) ntohl(sfp
->fs_rtmult
),
1225 (u_int32_t
) ntohl(sfp
->fs_wtmult
));
1226 print_int64((u_int32_t
*)&sfp
->fs_maxfilesize
, UNSIGNED
);
1227 printf(" delta %u.%06u ",
1228 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_sec
),
1229 (u_int32_t
) ntohl(sfp
->fs_timedelta
.nfsv3_nsec
));
1235 parsepathconf(const u_int32_t
*dp
)
1238 struct nfsv3_pathconf
*spp
;
1240 if (!(dp
= parsestatus(dp
, &er
)))
1244 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1249 T2CHECK(dp
, sizeof (struct nfsv3_pathconf
));
1251 spp
= (struct nfsv3_pathconf
*)dp
;
1253 printf(" linkmax %u namemax %u %s %s %s %s",
1254 (u_int32_t
) ntohl(spp
->pc_linkmax
),
1255 (u_int32_t
) ntohl(spp
->pc_namemax
),
1256 ntohl(spp
->pc_notrunc
) ? "notrunc" : "",
1257 ntohl(spp
->pc_chownrestricted
) ? "chownres" : "",
1258 ntohl(spp
->pc_caseinsensitive
) ? "igncase" : "",
1259 ntohl(spp
->pc_casepreserving
) ? "keepcase" : "");
1264 interp_reply(const struct rpc_msg
*rp
, u_int32_t proc
, u_int32_t vers
, int length
)
1266 register const u_int32_t
*dp
;
1270 v3
= (vers
== NFS_VER3
);
1272 if (!v3
&& proc
< NFS_NPROCS
)
1273 proc
= nfsv3_procid
[proc
];
1285 case NFSPROC_GETATTR
:
1287 dp
= parserep(rp
, length
);
1288 if (dp
!= NULL
&& parseattrstat(dp
, !qflag
, v3
) != 0)
1292 case NFSPROC_SETATTR
:
1294 if (!(dp
= parserep(rp
, length
)))
1297 if (parsewccres(dp
, vflag
))
1300 if (parseattrstat(dp
, !qflag
, 0) != 0)
1305 case NFSPROC_LOOKUP
:
1307 if (!(dp
= parserep(rp
, length
)))
1310 if (!(dp
= parsestatus(dp
, &er
)))
1314 printf(" post dattr:");
1315 dp
= parse_post_op_attr(dp
, vflag
);
1318 if (!(dp
= parsefh(dp
, v3
)))
1320 if ((dp
= parse_post_op_attr(dp
, vflag
)) &&
1322 printf(" post dattr:");
1323 dp
= parse_post_op_attr(dp
, vflag
);
1329 if (parsediropres(dp
) != 0)
1334 case NFSPROC_ACCESS
:
1336 dp
= parserep(rp
, length
);
1337 if (!(dp
= parsestatus(dp
, &er
)))
1341 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1344 printf(" c %04x", ntohl(dp
[0]));
1347 case NFSPROC_READLINK
:
1348 printf(" readlink");
1349 dp
= parserep(rp
, length
);
1350 if (dp
!= NULL
&& parselinkres(dp
, v3
) != 0)
1356 if (!(dp
= parserep(rp
, length
)))
1359 if (!(dp
= parsestatus(dp
, &er
)))
1361 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1367 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1373 if (parseattrstat(dp
, vflag
, 0) != 0)
1380 if (!(dp
= parserep(rp
, length
)))
1383 if (!(dp
= parsestatus(dp
, &er
)))
1385 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1391 printf("%u bytes", (u_int32_t
) ntohl(dp
[0]));
1395 nfsv3_writemodes
[ntohl(dp
[1])]);
1400 if (parseattrstat(dp
, vflag
, v3
) != 0)
1405 case NFSPROC_CREATE
:
1407 if (!(dp
= parserep(rp
, length
)))
1410 if (parsecreateopres(dp
, vflag
) != 0)
1413 if (parsediropres(dp
) != 0)
1420 if (!(dp
= parserep(rp
, length
)))
1423 if (parsecreateopres(dp
, vflag
) != 0)
1426 if (parsediropres(dp
) != 0)
1431 case NFSPROC_SYMLINK
:
1433 if (!(dp
= parserep(rp
, length
)))
1436 if (parsecreateopres(dp
, vflag
) != 0)
1439 if (parsestatus(dp
, &er
) != 0)
1446 if (!(dp
= parserep(rp
, length
)))
1448 if (parsecreateopres(dp
, vflag
) != 0)
1452 case NFSPROC_REMOVE
:
1454 if (!(dp
= parserep(rp
, length
)))
1457 if (parsewccres(dp
, vflag
))
1460 if (parsestatus(dp
, &er
) != 0)
1467 if (!(dp
= parserep(rp
, length
)))
1470 if (parsewccres(dp
, vflag
))
1473 if (parsestatus(dp
, &er
) != 0)
1478 case NFSPROC_RENAME
:
1480 if (!(dp
= parserep(rp
, length
)))
1483 if (!(dp
= parsestatus(dp
, &er
)))
1487 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1490 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1495 if (parsestatus(dp
, &er
) != 0)
1502 if (!(dp
= parserep(rp
, length
)))
1505 if (!(dp
= parsestatus(dp
, &er
)))
1508 printf(" file POST:");
1509 if (!(dp
= parse_post_op_attr(dp
, vflag
)))
1512 if (!(dp
= parse_wcc_data(dp
, vflag
)))
1517 if (parsestatus(dp
, &er
) != 0)
1522 case NFSPROC_READDIR
:
1524 if (!(dp
= parserep(rp
, length
)))
1527 if (parsev3rddirres(dp
, vflag
))
1530 if (parserddires(dp
) != 0)
1535 case NFSPROC_READDIRPLUS
:
1536 printf(" readdirplus");
1537 if (!(dp
= parserep(rp
, length
)))
1539 if (parsev3rddirres(dp
, vflag
))
1543 case NFSPROC_FSSTAT
:
1545 dp
= parserep(rp
, length
);
1546 if (dp
!= NULL
&& parsestatfs(dp
, v3
) != 0)
1550 case NFSPROC_FSINFO
:
1552 dp
= parserep(rp
, length
);
1553 if (dp
!= NULL
&& parsefsinfo(dp
) != 0)
1557 case NFSPROC_PATHCONF
:
1558 printf(" pathconf");
1559 dp
= parserep(rp
, length
);
1560 if (dp
!= NULL
&& parsepathconf(dp
) != 0)
1564 case NFSPROC_COMMIT
:
1566 dp
= parserep(rp
, length
);
1567 if (dp
!= NULL
&& parsewccres(dp
, vflag
) != 0)
1572 printf(" proc-%u", proc
);
1576 fputs(" [|nfs]", stdout
);