]> The Tcpdump Group git mirrors - tcpdump/blob - print-nfs.c
- add support for return code values
[tcpdump] / print-nfs.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 */
21
22 #ifndef lint
23 static const char rcsid[] _U_ =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.102 2004-04-17 08:56:14 guy Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <tcpdump-stdinc.h>
32
33 #include <rpc/rpc.h>
34
35 #include <pcap.h>
36 #include <stdio.h>
37 #include <string.h>
38
39 #include "interface.h"
40 #include "addrtoname.h"
41 #include "extract.h"
42
43 #include "nfs.h"
44 #include "nfsfh.h"
45
46 #include "ip.h"
47 #ifdef INET6
48 #include "ip6.h"
49 #endif
50
51 static void nfs_printfh(const u_int32_t *, const u_int);
52 static void xid_map_enter(const struct rpc_msg *, const u_char *);
53 static int32_t xid_map_find(const struct rpc_msg *, const u_char *,
54 u_int32_t *, u_int32_t *);
55 static void interp_reply(const struct rpc_msg *, u_int32_t, u_int32_t, int);
56 static const u_int32_t *parse_post_op_attr(const u_int32_t *, int);
57 static void print_sattr3(const struct nfsv3_sattr *sa3, int verbose);
58 static int print_int64(const u_int32_t *dp, int how);
59 static void print_nfsaddr(const u_char *, const char *, const char *);
60
61 /*
62 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
63 */
64 u_int32_t nfsv3_procid[NFS_NPROCS] = {
65 NFSPROC_NULL,
66 NFSPROC_GETATTR,
67 NFSPROC_SETATTR,
68 NFSPROC_NOOP,
69 NFSPROC_LOOKUP,
70 NFSPROC_READLINK,
71 NFSPROC_READ,
72 NFSPROC_NOOP,
73 NFSPROC_WRITE,
74 NFSPROC_CREATE,
75 NFSPROC_REMOVE,
76 NFSPROC_RENAME,
77 NFSPROC_LINK,
78 NFSPROC_SYMLINK,
79 NFSPROC_MKDIR,
80 NFSPROC_RMDIR,
81 NFSPROC_READDIR,
82 NFSPROC_FSSTAT,
83 NFSPROC_NOOP,
84 NFSPROC_NOOP,
85 NFSPROC_NOOP,
86 NFSPROC_NOOP,
87 NFSPROC_NOOP,
88 NFSPROC_NOOP,
89 NFSPROC_NOOP,
90 NFSPROC_NOOP
91 };
92
93 /*
94 * NFS V2 and V3 status values.
95 *
96 * Some of these come from the RFCs for NFS V2 and V3, with the message
97 * strings taken from the FreeBSD C library "errlst.c".
98 *
99 * Others are errors that are not in the RFC but that I suspect some
100 * NFS servers could return; the values are FreeBSD errno values, as
101 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
102 * was primarily BSD-derived.
103 */
104 static struct tok status2str[] = {
105 { 1, "Operation not permitted" }, /* EPERM */
106 { 2, "No such file or directory" }, /* ENOENT */
107 { 5, "Input/output error" }, /* EIO */
108 { 6, "Device not configured" }, /* ENXIO */
109 { 11, "Resource deadlock avoided" }, /* EDEADLK */
110 { 12, "Cannot allocate memory" }, /* ENOMEM */
111 { 13, "Permission denied" }, /* EACCES */
112 { 17, "File exists" }, /* EEXIST */
113 { 18, "Cross-device link" }, /* EXDEV */
114 { 19, "Operation not supported by device" }, /* ENODEV */
115 { 20, "Not a directory" }, /* ENOTDIR */
116 { 21, "Is a directory" }, /* EISDIR */
117 { 22, "Invalid argument" }, /* EINVAL */
118 { 26, "Text file busy" }, /* ETXTBSY */
119 { 27, "File too large" }, /* EFBIG */
120 { 28, "No space left on device" }, /* ENOSPC */
121 { 30, "Read-only file system" }, /* EROFS */
122 { 31, "Too many links" }, /* EMLINK */
123 { 45, "Operation not supported" }, /* EOPNOTSUPP */
124 { 62, "Too many levels of symbolic links" }, /* ELOOP */
125 { 63, "File name too long" }, /* ENAMETOOLONG */
126 { 66, "Directory not empty" }, /* ENOTEMPTY */
127 { 69, "Disc quota exceeded" }, /* EDQUOT */
128 { 70, "Stale NFS file handle" }, /* ESTALE */
129 { 71, "Too many levels of remote in path" }, /* EREMOTE */
130 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
131 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
132 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
133 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
134 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
135 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
136 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
137 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
138 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
139 { 0, NULL }
140 };
141
142 static struct tok nfsv3_writemodes[] = {
143 { 0, "unstable" },
144 { 1, "datasync" },
145 { 2, "filesync" },
146 { 0, NULL }
147 };
148
149 static struct tok type2str[] = {
150 { NFNON, "NON" },
151 { NFREG, "REG" },
152 { NFDIR, "DIR" },
153 { NFBLK, "BLK" },
154 { NFCHR, "CHR" },
155 { NFLNK, "LNK" },
156 { NFFIFO, "FIFO" },
157 { 0, NULL }
158 };
159
160 /*
161 * Print out a 64-bit integer. This appears to be different on each system,
162 * try to make the best of it. The integer stored as 2 consecutive XDR
163 * encoded 32-bit integers, to which a pointer is passed.
164 *
165 * We assume that PRId64, PRIu64, and PRIx64 are defined, and that
166 * u_int64_t is defined.
167 */
168
169 #define UNSIGNED 0
170 #define SIGNED 1
171 #define HEX 2
172
173 static int print_int64(const u_int32_t *dp, int how)
174 {
175 u_int64_t res;
176
177 res = ((u_int64_t)EXTRACT_32BITS(&dp[0]) << 32) | (u_int64_t)EXTRACT_32BITS(&dp[1]);
178 switch (how) {
179 case SIGNED:
180 printf("%" PRId64, res);
181 break;
182 case UNSIGNED:
183 printf("%" PRIu64, res);
184 break;
185 case HEX:
186 printf("%" PRIx64, res);
187 break;
188 default:
189 return (0);
190 }
191 return (1);
192 }
193
194 static void
195 print_nfsaddr(const u_char *bp, const char *s, const char *d)
196 {
197 struct ip *ip;
198 #ifdef INET6
199 struct ip6_hdr *ip6;
200 char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
201 #else
202 #ifndef INET_ADDRSTRLEN
203 #define INET_ADDRSTRLEN 16
204 #endif
205 char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN];
206 #endif
207
208 srcaddr[0] = dstaddr[0] = '\0';
209 switch (IP_V((struct ip *)bp)) {
210 case 4:
211 ip = (struct ip *)bp;
212 strlcpy(srcaddr, ipaddr_string(&ip->ip_src), sizeof(srcaddr));
213 strlcpy(dstaddr, ipaddr_string(&ip->ip_dst), sizeof(dstaddr));
214 break;
215 #ifdef INET6
216 case 6:
217 ip6 = (struct ip6_hdr *)bp;
218 strlcpy(srcaddr, ip6addr_string(&ip6->ip6_src),
219 sizeof(srcaddr));
220 strlcpy(dstaddr, ip6addr_string(&ip6->ip6_dst),
221 sizeof(dstaddr));
222 break;
223 #endif
224 default:
225 strlcpy(srcaddr, "?", sizeof(srcaddr));
226 strlcpy(dstaddr, "?", sizeof(dstaddr));
227 break;
228 }
229
230 (void)printf("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d);
231 }
232
233 static const u_int32_t *
234 parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3)
235 {
236 TCHECK(dp[0]);
237 sa3->sa_modeset = EXTRACT_32BITS(dp);
238 dp++;
239 if (sa3->sa_modeset) {
240 TCHECK(dp[0]);
241 sa3->sa_mode = EXTRACT_32BITS(dp);
242 dp++;
243 }
244
245 TCHECK(dp[0]);
246 sa3->sa_uidset = EXTRACT_32BITS(dp);
247 dp++;
248 if (sa3->sa_uidset) {
249 TCHECK(dp[0]);
250 sa3->sa_uid = EXTRACT_32BITS(dp);
251 dp++;
252 }
253
254 TCHECK(dp[0]);
255 sa3->sa_gidset = EXTRACT_32BITS(dp);
256 dp++;
257 if (sa3->sa_gidset) {
258 TCHECK(dp[0]);
259 sa3->sa_gid = EXTRACT_32BITS(dp);
260 dp++;
261 }
262
263 TCHECK(dp[0]);
264 sa3->sa_sizeset = EXTRACT_32BITS(dp);
265 dp++;
266 if (sa3->sa_sizeset) {
267 TCHECK(dp[0]);
268 sa3->sa_size = EXTRACT_32BITS(dp);
269 dp++;
270 }
271
272 TCHECK(dp[0]);
273 sa3->sa_atimetype = EXTRACT_32BITS(dp);
274 dp++;
275 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) {
276 TCHECK(dp[1]);
277 sa3->sa_atime.nfsv3_sec = EXTRACT_32BITS(dp);
278 dp++;
279 sa3->sa_atime.nfsv3_nsec = EXTRACT_32BITS(dp);
280 dp++;
281 }
282
283 TCHECK(dp[0]);
284 sa3->sa_mtimetype = EXTRACT_32BITS(dp);
285 dp++;
286 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) {
287 TCHECK(dp[1]);
288 sa3->sa_mtime.nfsv3_sec = EXTRACT_32BITS(dp);
289 dp++;
290 sa3->sa_mtime.nfsv3_nsec = EXTRACT_32BITS(dp);
291 dp++;
292 }
293
294 return dp;
295 trunc:
296 return NULL;
297 }
298
299 static int nfserr; /* true if we error rather than trunc */
300
301 static void
302 print_sattr3(const struct nfsv3_sattr *sa3, int verbose)
303 {
304 if (sa3->sa_modeset)
305 printf(" mode %o", sa3->sa_mode);
306 if (sa3->sa_uidset)
307 printf(" uid %u", sa3->sa_uid);
308 if (sa3->sa_gidset)
309 printf(" gid %u", sa3->sa_gid);
310 if (verbose > 1) {
311 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT)
312 printf(" atime %u.%06u", sa3->sa_atime.nfsv3_sec,
313 sa3->sa_atime.nfsv3_nsec);
314 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT)
315 printf(" mtime %u.%06u", sa3->sa_mtime.nfsv3_sec,
316 sa3->sa_mtime.nfsv3_nsec);
317 }
318 }
319
320 void
321 nfsreply_print(register const u_char *bp, u_int length,
322 register const u_char *bp2)
323 {
324 register const struct rpc_msg *rp;
325 u_int32_t proc, vers;
326 char srcid[20], dstid[20]; /*fits 32bit*/
327
328 nfserr = 0; /* assume no error */
329 rp = (const struct rpc_msg *)bp;
330
331 if (!nflag) {
332 strlcpy(srcid, "nfs", sizeof(srcid));
333 snprintf(dstid, sizeof(dstid), "%u",
334 EXTRACT_32BITS(&rp->rm_xid));
335 } else {
336 snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
337 snprintf(dstid, sizeof(dstid), "%u",
338 EXTRACT_32BITS(&rp->rm_xid));
339 }
340 print_nfsaddr(bp2, srcid, dstid);
341 (void)printf("reply %s %d",
342 EXTRACT_32BITS(&rp->rm_reply.rp_stat) == MSG_ACCEPTED?
343 "ok":"ERR",
344 length);
345
346 if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
347 interp_reply(rp, proc, vers, length);
348 }
349
350 /*
351 * Return a pointer to the first file handle in the packet.
352 * If the packet was truncated, return 0.
353 */
354 static const u_int32_t *
355 parsereq(register const struct rpc_msg *rp, register u_int length)
356 {
357 register const u_int32_t *dp;
358 register u_int len;
359
360 /*
361 * find the start of the req data (if we captured it)
362 */
363 dp = (u_int32_t *)&rp->rm_call.cb_cred;
364 TCHECK(dp[1]);
365 len = EXTRACT_32BITS(&dp[1]);
366 if (len < length) {
367 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
368 TCHECK(dp[1]);
369 len = EXTRACT_32BITS(&dp[1]);
370 if (len < length) {
371 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
372 TCHECK2(dp[0], 0);
373 return (dp);
374 }
375 }
376 trunc:
377 return (NULL);
378 }
379
380 /*
381 * Print out an NFS file handle and return a pointer to following word.
382 * If packet was truncated, return 0.
383 */
384 static const u_int32_t *
385 parsefh(register const u_int32_t *dp, int v3)
386 {
387 u_int len;
388
389 if (v3) {
390 TCHECK(dp[0]);
391 len = EXTRACT_32BITS(dp) / 4;
392 dp++;
393 } else
394 len = NFSX_V2FH / 4;
395
396 if (TTEST2(*dp, len * sizeof(*dp))) {
397 nfs_printfh(dp, len);
398 return (dp + len);
399 }
400 trunc:
401 return (NULL);
402 }
403
404 /*
405 * Print out a file name and return pointer to 32-bit word past it.
406 * If packet was truncated, return 0.
407 */
408 static const u_int32_t *
409 parsefn(register const u_int32_t *dp)
410 {
411 register u_int32_t len;
412 register const u_char *cp;
413
414 /* Bail if we don't have the string length */
415 TCHECK(*dp);
416
417 /* Fetch string length; convert to host order */
418 len = *dp++;
419 NTOHL(len);
420
421 TCHECK2(*dp, ((len + 3) & ~3));
422
423 cp = (u_char *)dp;
424 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
425 dp += ((len + 3) & ~3) / sizeof(*dp);
426 /* XXX seems like we should be checking the length */
427 putchar('"');
428 (void) fn_printn(cp, len, NULL);
429 putchar('"');
430
431 return (dp);
432 trunc:
433 return NULL;
434 }
435
436 /*
437 * Print out file handle and file name.
438 * Return pointer to 32-bit word past file name.
439 * If packet was truncated (or there was some other error), return 0.
440 */
441 static const u_int32_t *
442 parsefhn(register const u_int32_t *dp, int v3)
443 {
444 dp = parsefh(dp, v3);
445 if (dp == NULL)
446 return (NULL);
447 putchar(' ');
448 return (parsefn(dp));
449 }
450
451 void
452 nfsreq_print(register const u_char *bp, u_int length,
453 register const u_char *bp2)
454 {
455 register const struct rpc_msg *rp;
456 register const u_int32_t *dp;
457 nfs_type type;
458 int v3;
459 u_int32_t proc;
460 struct nfsv3_sattr sa3;
461 char srcid[20], dstid[20]; /*fits 32bit*/
462
463 nfserr = 0; /* assume no error */
464 rp = (const struct rpc_msg *)bp;
465 if (!nflag) {
466 snprintf(srcid, sizeof(srcid), "%u",
467 EXTRACT_32BITS(&rp->rm_xid));
468 strlcpy(dstid, "nfs", sizeof(dstid));
469 } else {
470 snprintf(srcid, sizeof(srcid), "%u",
471 EXTRACT_32BITS(&rp->rm_xid));
472 snprintf(dstid, sizeof(dstid), "%u", NFS_PORT);
473 }
474 print_nfsaddr(bp2, srcid, dstid);
475 (void)printf("%d", length);
476
477 xid_map_enter(rp, bp2); /* record proc number for later on */
478
479 v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3);
480 proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
481
482 if (!v3 && proc < NFS_NPROCS)
483 proc = nfsv3_procid[proc];
484
485 switch (proc) {
486 case NFSPROC_NOOP:
487 printf(" nop");
488 return;
489 case NFSPROC_NULL:
490 printf(" null");
491 return;
492
493 case NFSPROC_GETATTR:
494 printf(" getattr");
495 if ((dp = parsereq(rp, length)) != NULL &&
496 parsefh(dp, v3) != NULL)
497 return;
498 break;
499
500 case NFSPROC_SETATTR:
501 printf(" setattr");
502 if ((dp = parsereq(rp, length)) != NULL &&
503 parsefh(dp, v3) != NULL)
504 return;
505 break;
506
507 case NFSPROC_LOOKUP:
508 printf(" lookup");
509 if ((dp = parsereq(rp, length)) != NULL &&
510 parsefhn(dp, v3) != NULL)
511 return;
512 break;
513
514 case NFSPROC_ACCESS:
515 printf(" access");
516 if ((dp = parsereq(rp, length)) != NULL &&
517 (dp = parsefh(dp, v3)) != NULL) {
518 TCHECK(dp[0]);
519 printf(" %04x", EXTRACT_32BITS(&dp[0]));
520 return;
521 }
522 break;
523
524 case NFSPROC_READLINK:
525 printf(" readlink");
526 if ((dp = parsereq(rp, length)) != NULL &&
527 parsefh(dp, v3) != NULL)
528 return;
529 break;
530
531 case NFSPROC_READ:
532 printf(" read");
533 if ((dp = parsereq(rp, length)) != NULL &&
534 (dp = parsefh(dp, v3)) != NULL) {
535 if (v3) {
536 TCHECK(dp[2]);
537 printf(" %u bytes @ ",
538 EXTRACT_32BITS(&dp[2]));
539 print_int64(dp, UNSIGNED);
540 } else {
541 TCHECK(dp[1]);
542 printf(" %u bytes @ %u",
543 EXTRACT_32BITS(&dp[1]),
544 EXTRACT_32BITS(&dp[0]));
545 }
546 return;
547 }
548 break;
549
550 case NFSPROC_WRITE:
551 printf(" write");
552 if ((dp = parsereq(rp, length)) != NULL &&
553 (dp = parsefh(dp, v3)) != NULL) {
554 if (v3) {
555 TCHECK(dp[4]);
556 printf(" %u bytes @ ",
557 EXTRACT_32BITS(&dp[4]));
558 print_int64(dp, UNSIGNED);
559 if (vflag) {
560 dp += 3;
561 TCHECK(dp[0]);
562 printf(" <%s>",
563 tok2str(nfsv3_writemodes,
564 NULL, EXTRACT_32BITS(dp)));
565 }
566 } else {
567 TCHECK(dp[3]);
568 printf(" %u (%u) bytes @ %u (%u)",
569 EXTRACT_32BITS(&dp[3]),
570 EXTRACT_32BITS(&dp[2]),
571 EXTRACT_32BITS(&dp[1]),
572 EXTRACT_32BITS(&dp[0]));
573 }
574 return;
575 }
576 break;
577
578 case NFSPROC_CREATE:
579 printf(" create");
580 if ((dp = parsereq(rp, length)) != NULL &&
581 parsefhn(dp, v3) != NULL)
582 return;
583 break;
584
585 case NFSPROC_MKDIR:
586 printf(" mkdir");
587 if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0)
588 return;
589 break;
590
591 case NFSPROC_SYMLINK:
592 printf(" symlink");
593 if ((dp = parsereq(rp, length)) != 0 &&
594 (dp = parsefhn(dp, v3)) != 0) {
595 fputs(" ->", stdout);
596 if (v3 && (dp = parse_sattr3(dp, &sa3)) == 0)
597 break;
598 if (parsefn(dp) == 0)
599 break;
600 if (v3 && vflag)
601 print_sattr3(&sa3, vflag);
602 return;
603 }
604 break;
605
606 case NFSPROC_MKNOD:
607 printf(" mknod");
608 if ((dp = parsereq(rp, length)) != 0 &&
609 (dp = parsefhn(dp, v3)) != 0) {
610 TCHECK(*dp);
611 type = (nfs_type)EXTRACT_32BITS(dp);
612 dp++;
613 if ((dp = parse_sattr3(dp, &sa3)) == 0)
614 break;
615 printf(" %s", tok2str(type2str, "unk-ft %d", type));
616 if (vflag && (type == NFCHR || type == NFBLK)) {
617 TCHECK(dp[1]);
618 printf(" %u/%u",
619 EXTRACT_32BITS(&dp[0]),
620 EXTRACT_32BITS(&dp[1]));
621 dp += 2;
622 }
623 if (vflag)
624 print_sattr3(&sa3, vflag);
625 return;
626 }
627 break;
628
629 case NFSPROC_REMOVE:
630 printf(" remove");
631 if ((dp = parsereq(rp, length)) != NULL &&
632 parsefhn(dp, v3) != NULL)
633 return;
634 break;
635
636 case NFSPROC_RMDIR:
637 printf(" rmdir");
638 if ((dp = parsereq(rp, length)) != NULL &&
639 parsefhn(dp, v3) != NULL)
640 return;
641 break;
642
643 case NFSPROC_RENAME:
644 printf(" rename");
645 if ((dp = parsereq(rp, length)) != NULL &&
646 (dp = parsefhn(dp, v3)) != NULL) {
647 fputs(" ->", stdout);
648 if (parsefhn(dp, v3) != NULL)
649 return;
650 }
651 break;
652
653 case NFSPROC_LINK:
654 printf(" link");
655 if ((dp = parsereq(rp, length)) != NULL &&
656 (dp = parsefh(dp, v3)) != NULL) {
657 fputs(" ->", stdout);
658 if (parsefhn(dp, v3) != NULL)
659 return;
660 }
661 break;
662
663 case NFSPROC_READDIR:
664 printf(" readdir");
665 if ((dp = parsereq(rp, length)) != NULL &&
666 (dp = parsefh(dp, v3)) != NULL) {
667 if (v3) {
668 TCHECK(dp[4]);
669 /*
670 * We shouldn't really try to interpret the
671 * offset cookie here.
672 */
673 printf(" %u bytes @ ",
674 EXTRACT_32BITS(&dp[4]));
675 print_int64(dp, SIGNED);
676 if (vflag)
677 printf(" verf %08x%08x", dp[2],
678 dp[3]);
679 } else {
680 TCHECK(dp[1]);
681 /*
682 * Print the offset as signed, since -1 is
683 * common, but offsets > 2^31 aren't.
684 */
685 printf(" %u bytes @ %d",
686 EXTRACT_32BITS(&dp[1]),
687 EXTRACT_32BITS(&dp[0]));
688 }
689 return;
690 }
691 break;
692
693 case NFSPROC_READDIRPLUS:
694 printf(" readdirplus");
695 if ((dp = parsereq(rp, length)) != NULL &&
696 (dp = parsefh(dp, v3)) != NULL) {
697 TCHECK(dp[4]);
698 /*
699 * We don't try to interpret the offset
700 * cookie here.
701 */
702 printf(" %u bytes @ ", EXTRACT_32BITS(&dp[4]));
703 print_int64(dp, SIGNED);
704 if (vflag)
705 printf(" max %u verf %08x%08x",
706 EXTRACT_32BITS(&dp[5]), dp[2], dp[3]);
707 return;
708 }
709 break;
710
711 case NFSPROC_FSSTAT:
712 printf(" fsstat");
713 if ((dp = parsereq(rp, length)) != NULL &&
714 parsefh(dp, v3) != NULL)
715 return;
716 break;
717
718 case NFSPROC_FSINFO:
719 printf(" fsinfo");
720 if ((dp = parsereq(rp, length)) != NULL &&
721 parsefh(dp, v3) != NULL)
722 return;
723 break;
724
725 case NFSPROC_PATHCONF:
726 printf(" pathconf");
727 if ((dp = parsereq(rp, length)) != NULL &&
728 parsefh(dp, v3) != NULL)
729 return;
730 break;
731
732 case NFSPROC_COMMIT:
733 printf(" commit");
734 if ((dp = parsereq(rp, length)) != NULL &&
735 (dp = parsefh(dp, v3)) != NULL) {
736 printf(" %u bytes @ ", EXTRACT_32BITS(&dp[2]));
737 print_int64(dp, UNSIGNED);
738 return;
739 }
740 break;
741
742 default:
743 printf(" proc-%u", EXTRACT_32BITS(&rp->rm_call.cb_proc));
744 return;
745 }
746
747 trunc:
748 if (!nfserr)
749 fputs(" [|nfs]", stdout);
750 }
751
752 /*
753 * Print out an NFS file handle.
754 * We assume packet was not truncated before the end of the
755 * file handle pointed to by dp.
756 *
757 * Note: new version (using portable file-handle parser) doesn't produce
758 * generation number. It probably could be made to do that, with some
759 * additional hacking on the parser code.
760 */
761 static void
762 nfs_printfh(register const u_int32_t *dp, const u_int len)
763 {
764 my_fsid fsid;
765 ino_t ino;
766 const char *sfsname = NULL;
767 char *spacep;
768
769 if (uflag) {
770 u_int i;
771 char const *sep = "";
772
773 printf(" fh[");
774 for (i=0; i<len; i++) {
775 (void)printf("%s%x", sep, dp[i]);
776 sep = ":";
777 }
778 printf("]");
779 return;
780 }
781
782 Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
783
784 if (sfsname) {
785 /* file system ID is ASCII, not numeric, for this server OS */
786 static char temp[NFSX_V3FHMAX+1];
787
788 /* Make sure string is null-terminated */
789 strncpy(temp, sfsname, NFSX_V3FHMAX);
790 temp[sizeof(temp) - 1] = '\0';
791 /* Remove trailing spaces */
792 spacep = strchr(temp, ' ');
793 if (spacep)
794 *spacep = '\0';
795
796 (void)printf(" fh %s/", temp);
797 } else {
798 (void)printf(" fh %d,%d/",
799 fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
800 }
801
802 if(fsid.Fsid_dev.Minor == 257)
803 /* Print the undecoded handle */
804 (void)printf("%s", fsid.Opaque_Handle);
805 else
806 (void)printf("%ld", (long) ino);
807 }
808
809 /*
810 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
811 * us to match up replies with requests and thus to know how to parse
812 * the reply.
813 */
814
815 struct xid_map_entry {
816 u_int32_t xid; /* transaction ID (net order) */
817 int ipver; /* IP version (4 or 6) */
818 #ifdef INET6
819 struct in6_addr client; /* client IP address (net order) */
820 struct in6_addr server; /* server IP address (net order) */
821 #else
822 struct in_addr client; /* client IP address (net order) */
823 struct in_addr server; /* server IP address (net order) */
824 #endif
825 u_int32_t proc; /* call proc number (host order) */
826 u_int32_t vers; /* program version (host order) */
827 };
828
829 /*
830 * Map entries are kept in an array that we manage as a ring;
831 * new entries are always added at the tail of the ring. Initially,
832 * all the entries are zero and hence don't match anything.
833 */
834
835 #define XIDMAPSIZE 64
836
837 struct xid_map_entry xid_map[XIDMAPSIZE];
838
839 int xid_map_next = 0;
840 int xid_map_hint = 0;
841
842 static void
843 xid_map_enter(const struct rpc_msg *rp, const u_char *bp)
844 {
845 struct ip *ip = NULL;
846 #ifdef INET6
847 struct ip6_hdr *ip6 = NULL;
848 #endif
849 struct xid_map_entry *xmep;
850
851 switch (IP_V((struct ip *)bp)) {
852 case 4:
853 ip = (struct ip *)bp;
854 break;
855 #ifdef INET6
856 case 6:
857 ip6 = (struct ip6_hdr *)bp;
858 break;
859 #endif
860 default:
861 return;
862 }
863
864 xmep = &xid_map[xid_map_next];
865
866 if (++xid_map_next >= XIDMAPSIZE)
867 xid_map_next = 0;
868
869 xmep->xid = rp->rm_xid;
870 if (ip) {
871 xmep->ipver = 4;
872 memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
873 memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
874 }
875 #ifdef INET6
876 else if (ip6) {
877 xmep->ipver = 6;
878 memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
879 memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
880 }
881 #endif
882 xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
883 xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
884 }
885
886 /*
887 * Returns 0 and puts NFSPROC_xxx in proc return and
888 * version in vers return, or returns -1 on failure
889 */
890 static int
891 xid_map_find(const struct rpc_msg *rp, const u_char *bp, u_int32_t *proc,
892 u_int32_t *vers)
893 {
894 int i;
895 struct xid_map_entry *xmep;
896 u_int32_t xid = rp->rm_xid;
897 struct ip *ip = (struct ip *)bp;
898 #ifdef INET6
899 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
900 #endif
901 int cmp;
902
903 /* Start searching from where we last left off */
904 i = xid_map_hint;
905 do {
906 xmep = &xid_map[i];
907 cmp = 1;
908 if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
909 goto nextitem;
910 switch (xmep->ipver) {
911 case 4:
912 if (memcmp(&ip->ip_src, &xmep->server,
913 sizeof(ip->ip_src)) != 0 ||
914 memcmp(&ip->ip_dst, &xmep->client,
915 sizeof(ip->ip_dst)) != 0) {
916 cmp = 0;
917 }
918 break;
919 #ifdef INET6
920 case 6:
921 if (memcmp(&ip6->ip6_src, &xmep->server,
922 sizeof(ip6->ip6_src)) != 0 ||
923 memcmp(&ip6->ip6_dst, &xmep->client,
924 sizeof(ip6->ip6_dst)) != 0) {
925 cmp = 0;
926 }
927 break;
928 #endif
929 default:
930 cmp = 0;
931 break;
932 }
933 if (cmp) {
934 /* match */
935 xid_map_hint = i;
936 *proc = xmep->proc;
937 *vers = xmep->vers;
938 return 0;
939 }
940 nextitem:
941 if (++i >= XIDMAPSIZE)
942 i = 0;
943 } while (i != xid_map_hint);
944
945 /* search failed */
946 return (-1);
947 }
948
949 /*
950 * Routines for parsing reply packets
951 */
952
953 /*
954 * Return a pointer to the beginning of the actual results.
955 * If the packet was truncated, return 0.
956 */
957 static const u_int32_t *
958 parserep(register const struct rpc_msg *rp, register u_int length)
959 {
960 register const u_int32_t *dp;
961 u_int len;
962 enum accept_stat astat;
963
964 /*
965 * Portability note:
966 * Here we find the address of the ar_verf credentials.
967 * Originally, this calculation was
968 * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf
969 * On the wire, the rp_acpt field starts immediately after
970 * the (32 bit) rp_stat field. However, rp_acpt (which is a
971 * "struct accepted_reply") contains a "struct opaque_auth",
972 * whose internal representation contains a pointer, so on a
973 * 64-bit machine the compiler inserts 32 bits of padding
974 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
975 * the internal representation to parse the on-the-wire
976 * representation. Instead, we skip past the rp_stat field,
977 * which is an "enum" and so occupies one 32-bit word.
978 */
979 dp = ((const u_int32_t *)&rp->rm_reply) + 1;
980 TCHECK(dp[1]);
981 len = EXTRACT_32BITS(&dp[1]);
982 if (len >= length)
983 return (NULL);
984 /*
985 * skip past the ar_verf credentials.
986 */
987 dp += (len + (2*sizeof(u_int32_t) + 3)) / sizeof(u_int32_t);
988 TCHECK2(dp[0], 0);
989
990 /*
991 * now we can check the ar_stat field
992 */
993 astat = EXTRACT_32BITS(dp);
994 switch (astat) {
995
996 case SUCCESS:
997 break;
998
999 case PROG_UNAVAIL:
1000 printf(" PROG_UNAVAIL");
1001 nfserr = 1; /* suppress trunc string */
1002 return (NULL);
1003
1004 case PROG_MISMATCH:
1005 printf(" PROG_MISMATCH");
1006 nfserr = 1; /* suppress trunc string */
1007 return (NULL);
1008
1009 case PROC_UNAVAIL:
1010 printf(" PROC_UNAVAIL");
1011 nfserr = 1; /* suppress trunc string */
1012 return (NULL);
1013
1014 case GARBAGE_ARGS:
1015 printf(" GARBAGE_ARGS");
1016 nfserr = 1; /* suppress trunc string */
1017 return (NULL);
1018
1019 case SYSTEM_ERR:
1020 printf(" SYSTEM_ERR");
1021 nfserr = 1; /* suppress trunc string */
1022 return (NULL);
1023
1024 default:
1025 printf(" ar_stat %d", astat);
1026 nfserr = 1; /* suppress trunc string */
1027 return (NULL);
1028 }
1029 /* successful return */
1030 TCHECK2(*dp, sizeof(astat));
1031 return ((u_int32_t *) (sizeof(astat) + ((char *)dp)));
1032 trunc:
1033 return (0);
1034 }
1035
1036 static const u_int32_t *
1037 parsestatus(const u_int32_t *dp, int *er)
1038 {
1039 int errnum;
1040
1041 TCHECK(dp[0]);
1042
1043 errnum = EXTRACT_32BITS(&dp[0]);
1044 if (er)
1045 *er = errnum;
1046 if (errnum != 0) {
1047 if (!qflag)
1048 printf(" ERROR: %s",
1049 tok2str(status2str, "unk %d", errnum));
1050 nfserr = 1;
1051 }
1052 return (dp + 1);
1053 trunc:
1054 return NULL;
1055 }
1056
1057 static const u_int32_t *
1058 parsefattr(const u_int32_t *dp, int verbose, int v3)
1059 {
1060 const struct nfs_fattr *fap;
1061
1062 fap = (const struct nfs_fattr *)dp;
1063 TCHECK(fap->fa_gid);
1064 if (verbose) {
1065 printf(" %s %o ids %d/%d",
1066 tok2str(type2str, "unk-ft %d ",
1067 EXTRACT_32BITS(&fap->fa_type)),
1068 EXTRACT_32BITS(&fap->fa_mode),
1069 EXTRACT_32BITS(&fap->fa_uid),
1070 EXTRACT_32BITS(&fap->fa_gid));
1071 if (v3) {
1072 TCHECK(fap->fa3_size);
1073 printf(" sz ");
1074 print_int64((u_int32_t *)&fap->fa3_size, UNSIGNED);
1075 } else {
1076 TCHECK(fap->fa2_size);
1077 printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size));
1078 }
1079 }
1080 /* print lots more stuff */
1081 if (verbose > 1) {
1082 if (v3) {
1083 TCHECK(fap->fa3_ctime);
1084 printf(" nlink %d rdev %d/%d",
1085 EXTRACT_32BITS(&fap->fa_nlink),
1086 EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
1087 EXTRACT_32BITS(&fap->fa3_rdev.specdata2));
1088 printf(" fsid ");
1089 print_int64((u_int32_t *)&fap->fa3_fsid, HEX);
1090 printf(" fileid ");
1091 print_int64((u_int32_t *)&fap->fa3_fileid, HEX);
1092 printf(" a/m/ctime %u.%06u",
1093 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec),
1094 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec));
1095 printf(" %u.%06u",
1096 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec),
1097 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec));
1098 printf(" %u.%06u",
1099 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec),
1100 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec));
1101 } else {
1102 TCHECK(fap->fa2_ctime);
1103 printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
1104 EXTRACT_32BITS(&fap->fa_nlink),
1105 EXTRACT_32BITS(&fap->fa2_rdev),
1106 EXTRACT_32BITS(&fap->fa2_fsid),
1107 EXTRACT_32BITS(&fap->fa2_fileid));
1108 printf(" %u.%06u",
1109 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec),
1110 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec));
1111 printf(" %u.%06u",
1112 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec),
1113 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec));
1114 printf(" %u.%06u",
1115 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec),
1116 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec));
1117 }
1118 }
1119 return ((const u_int32_t *)((unsigned char *)dp +
1120 (v3 ? NFSX_V3FATTR : NFSX_V2FATTR)));
1121 trunc:
1122 return (NULL);
1123 }
1124
1125 static int
1126 parseattrstat(const u_int32_t *dp, int verbose, int v3)
1127 {
1128 int er;
1129
1130 dp = parsestatus(dp, &er);
1131 if (dp == NULL)
1132 return (0);
1133 if (er)
1134 return (1);
1135
1136 return (parsefattr(dp, verbose, v3) != NULL);
1137 }
1138
1139 static int
1140 parsediropres(const u_int32_t *dp)
1141 {
1142 int er;
1143
1144 if (!(dp = parsestatus(dp, &er)))
1145 return (0);
1146 if (er)
1147 return (1);
1148
1149 dp = parsefh(dp, 0);
1150 if (dp == NULL)
1151 return (0);
1152
1153 return (parsefattr(dp, vflag, 0) != NULL);
1154 }
1155
1156 static int
1157 parselinkres(const u_int32_t *dp, int v3)
1158 {
1159 int er;
1160
1161 dp = parsestatus(dp, &er);
1162 if (dp == NULL)
1163 return(0);
1164 if (er)
1165 return(1);
1166 if (v3 && !(dp = parse_post_op_attr(dp, vflag)))
1167 return (0);
1168 putchar(' ');
1169 return (parsefn(dp) != NULL);
1170 }
1171
1172 static int
1173 parsestatfs(const u_int32_t *dp, int v3)
1174 {
1175 const struct nfs_statfs *sfsp;
1176 int er;
1177
1178 dp = parsestatus(dp, &er);
1179 if (dp == NULL)
1180 return (0);
1181 if (!v3 && er)
1182 return (1);
1183
1184 if (qflag)
1185 return(1);
1186
1187 if (v3) {
1188 if (vflag)
1189 printf(" POST:");
1190 if (!(dp = parse_post_op_attr(dp, vflag)))
1191 return (0);
1192 }
1193
1194 TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
1195
1196 sfsp = (const struct nfs_statfs *)dp;
1197
1198 if (v3) {
1199 printf(" tbytes ");
1200 print_int64((u_int32_t *)&sfsp->sf_tbytes, UNSIGNED);
1201 printf(" fbytes ");
1202 print_int64((u_int32_t *)&sfsp->sf_fbytes, UNSIGNED);
1203 printf(" abytes ");
1204 print_int64((u_int32_t *)&sfsp->sf_abytes, UNSIGNED);
1205 if (vflag) {
1206 printf(" tfiles ");
1207 print_int64((u_int32_t *)&sfsp->sf_tfiles, UNSIGNED);
1208 printf(" ffiles ");
1209 print_int64((u_int32_t *)&sfsp->sf_ffiles, UNSIGNED);
1210 printf(" afiles ");
1211 print_int64((u_int32_t *)&sfsp->sf_afiles, UNSIGNED);
1212 printf(" invar %u",
1213 EXTRACT_32BITS(&sfsp->sf_invarsec));
1214 }
1215 } else {
1216 printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
1217 EXTRACT_32BITS(&sfsp->sf_tsize),
1218 EXTRACT_32BITS(&sfsp->sf_bsize),
1219 EXTRACT_32BITS(&sfsp->sf_blocks),
1220 EXTRACT_32BITS(&sfsp->sf_bfree),
1221 EXTRACT_32BITS(&sfsp->sf_bavail));
1222 }
1223
1224 return (1);
1225 trunc:
1226 return (0);
1227 }
1228
1229 static int
1230 parserddires(const u_int32_t *dp)
1231 {
1232 int er;
1233
1234 dp = parsestatus(dp, &er);
1235 if (dp == NULL)
1236 return (0);
1237 if (er)
1238 return (1);
1239 if (qflag)
1240 return (1);
1241
1242 TCHECK(dp[2]);
1243 printf(" offset %x size %d ",
1244 EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1]));
1245 if (dp[2] != 0)
1246 printf(" eof");
1247
1248 return (1);
1249 trunc:
1250 return (0);
1251 }
1252
1253 static const u_int32_t *
1254 parse_wcc_attr(const u_int32_t *dp)
1255 {
1256 printf(" sz ");
1257 print_int64(dp, UNSIGNED);
1258 printf(" mtime %u.%06u ctime %u.%06u",
1259 EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
1260 EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5]));
1261 return (dp + 6);
1262 }
1263
1264 /*
1265 * Pre operation attributes. Print only if vflag > 1.
1266 */
1267 static const u_int32_t *
1268 parse_pre_op_attr(const u_int32_t *dp, int verbose)
1269 {
1270 TCHECK(dp[0]);
1271 if (!EXTRACT_32BITS(&dp[0]))
1272 return (dp + 1);
1273 dp++;
1274 TCHECK2(*dp, 24);
1275 if (verbose > 1) {
1276 return parse_wcc_attr(dp);
1277 } else {
1278 /* If not verbose enough, just skip over wcc_attr */
1279 return (dp + 6);
1280 }
1281 trunc:
1282 return (NULL);
1283 }
1284
1285 /*
1286 * Post operation attributes are printed if vflag >= 1
1287 */
1288 static const u_int32_t *
1289 parse_post_op_attr(const u_int32_t *dp, int verbose)
1290 {
1291 TCHECK(dp[0]);
1292 if (!EXTRACT_32BITS(&dp[0]))
1293 return (dp + 1);
1294 dp++;
1295 if (verbose) {
1296 return parsefattr(dp, verbose, 1);
1297 } else
1298 return (dp + (NFSX_V3FATTR / sizeof (u_int32_t)));
1299 trunc:
1300 return (NULL);
1301 }
1302
1303 static const u_int32_t *
1304 parse_wcc_data(const u_int32_t *dp, int verbose)
1305 {
1306 if (verbose > 1)
1307 printf(" PRE:");
1308 if (!(dp = parse_pre_op_attr(dp, verbose)))
1309 return (0);
1310
1311 if (verbose)
1312 printf(" POST:");
1313 return parse_post_op_attr(dp, verbose);
1314 }
1315
1316 static const u_int32_t *
1317 parsecreateopres(const u_int32_t *dp, int verbose)
1318 {
1319 int er;
1320
1321 if (!(dp = parsestatus(dp, &er)))
1322 return (0);
1323 if (er)
1324 dp = parse_wcc_data(dp, verbose);
1325 else {
1326 TCHECK(dp[0]);
1327 if (!EXTRACT_32BITS(&dp[0]))
1328 return (dp + 1);
1329 dp++;
1330 if (!(dp = parsefh(dp, 1)))
1331 return (0);
1332 if (verbose) {
1333 if (!(dp = parse_post_op_attr(dp, verbose)))
1334 return (0);
1335 if (vflag > 1) {
1336 printf(" dir attr:");
1337 dp = parse_wcc_data(dp, verbose);
1338 }
1339 }
1340 }
1341 return (dp);
1342 trunc:
1343 return (NULL);
1344 }
1345
1346 static int
1347 parsewccres(const u_int32_t *dp, int verbose)
1348 {
1349 int er;
1350
1351 if (!(dp = parsestatus(dp, &er)))
1352 return (0);
1353 return parse_wcc_data(dp, verbose) != 0;
1354 }
1355
1356 static const u_int32_t *
1357 parsev3rddirres(const u_int32_t *dp, int verbose)
1358 {
1359 int er;
1360
1361 if (!(dp = parsestatus(dp, &er)))
1362 return (0);
1363 if (vflag)
1364 printf(" POST:");
1365 if (!(dp = parse_post_op_attr(dp, verbose)))
1366 return (0);
1367 if (er)
1368 return dp;
1369 if (vflag) {
1370 TCHECK(dp[1]);
1371 printf(" verf %08x%08x", dp[0], dp[1]);
1372 dp += 2;
1373 }
1374 return dp;
1375 trunc:
1376 return (NULL);
1377 }
1378
1379 static int
1380 parsefsinfo(const u_int32_t *dp)
1381 {
1382 struct nfsv3_fsinfo *sfp;
1383 int er;
1384
1385 if (!(dp = parsestatus(dp, &er)))
1386 return (0);
1387 if (vflag)
1388 printf(" POST:");
1389 if (!(dp = parse_post_op_attr(dp, vflag)))
1390 return (0);
1391 if (er)
1392 return (1);
1393
1394 sfp = (struct nfsv3_fsinfo *)dp;
1395 TCHECK(*sfp);
1396 printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
1397 EXTRACT_32BITS(&sfp->fs_rtmax),
1398 EXTRACT_32BITS(&sfp->fs_rtpref),
1399 EXTRACT_32BITS(&sfp->fs_wtmax),
1400 EXTRACT_32BITS(&sfp->fs_wtpref),
1401 EXTRACT_32BITS(&sfp->fs_dtpref));
1402 if (vflag) {
1403 printf(" rtmult %u wtmult %u maxfsz ",
1404 EXTRACT_32BITS(&sfp->fs_rtmult),
1405 EXTRACT_32BITS(&sfp->fs_wtmult));
1406 print_int64((u_int32_t *)&sfp->fs_maxfilesize, UNSIGNED);
1407 printf(" delta %u.%06u ",
1408 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
1409 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec));
1410 }
1411 return (1);
1412 trunc:
1413 return (0);
1414 }
1415
1416 static int
1417 parsepathconf(const u_int32_t *dp)
1418 {
1419 int er;
1420 struct nfsv3_pathconf *spp;
1421
1422 if (!(dp = parsestatus(dp, &er)))
1423 return (0);
1424 if (vflag)
1425 printf(" POST:");
1426 if (!(dp = parse_post_op_attr(dp, vflag)))
1427 return (0);
1428 if (er)
1429 return (1);
1430
1431 spp = (struct nfsv3_pathconf *)dp;
1432 TCHECK(*spp);
1433
1434 printf(" linkmax %u namemax %u %s %s %s %s",
1435 EXTRACT_32BITS(&spp->pc_linkmax),
1436 EXTRACT_32BITS(&spp->pc_namemax),
1437 EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
1438 EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
1439 EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
1440 EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : "");
1441 return (1);
1442 trunc:
1443 return (0);
1444 }
1445
1446 static void
1447 interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
1448 {
1449 register const u_int32_t *dp;
1450 register int v3;
1451 int er;
1452
1453 v3 = (vers == NFS_VER3);
1454
1455 if (!v3 && proc < NFS_NPROCS)
1456 proc = nfsv3_procid[proc];
1457
1458 switch (proc) {
1459
1460 case NFSPROC_NOOP:
1461 printf(" nop");
1462 return;
1463
1464 case NFSPROC_NULL:
1465 printf(" null");
1466 return;
1467
1468 case NFSPROC_GETATTR:
1469 printf(" getattr");
1470 dp = parserep(rp, length);
1471 if (dp != NULL && parseattrstat(dp, !qflag, v3) != 0)
1472 return;
1473 break;
1474
1475 case NFSPROC_SETATTR:
1476 printf(" setattr");
1477 if (!(dp = parserep(rp, length)))
1478 return;
1479 if (v3) {
1480 if (parsewccres(dp, vflag))
1481 return;
1482 } else {
1483 if (parseattrstat(dp, !qflag, 0) != 0)
1484 return;
1485 }
1486 break;
1487
1488 case NFSPROC_LOOKUP:
1489 printf(" lookup");
1490 if (!(dp = parserep(rp, length)))
1491 break;
1492 if (v3) {
1493 if (!(dp = parsestatus(dp, &er)))
1494 break;
1495 if (er) {
1496 if (vflag > 1) {
1497 printf(" post dattr:");
1498 dp = parse_post_op_attr(dp, vflag);
1499 }
1500 } else {
1501 if (!(dp = parsefh(dp, v3)))
1502 break;
1503 if ((dp = parse_post_op_attr(dp, vflag)) &&
1504 vflag > 1) {
1505 printf(" post dattr:");
1506 dp = parse_post_op_attr(dp, vflag);
1507 }
1508 }
1509 if (dp)
1510 return;
1511 } else {
1512 if (parsediropres(dp) != 0)
1513 return;
1514 }
1515 break;
1516
1517 case NFSPROC_ACCESS:
1518 printf(" access");
1519 if (!(dp = parserep(rp, length)))
1520 break;
1521 if (!(dp = parsestatus(dp, &er)))
1522 break;
1523 if (vflag)
1524 printf(" attr:");
1525 if (!(dp = parse_post_op_attr(dp, vflag)))
1526 break;
1527 if (!er)
1528 printf(" c %04x", EXTRACT_32BITS(&dp[0]));
1529 return;
1530
1531 case NFSPROC_READLINK:
1532 printf(" readlink");
1533 dp = parserep(rp, length);
1534 if (dp != NULL && parselinkres(dp, v3) != 0)
1535 return;
1536 break;
1537
1538 case NFSPROC_READ:
1539 printf(" read");
1540 if (!(dp = parserep(rp, length)))
1541 break;
1542 if (v3) {
1543 if (!(dp = parsestatus(dp, &er)))
1544 break;
1545 if (!(dp = parse_post_op_attr(dp, vflag)))
1546 break;
1547 if (er)
1548 return;
1549 if (vflag) {
1550 TCHECK(dp[1]);
1551 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1552 if (EXTRACT_32BITS(&dp[1]))
1553 printf(" EOF");
1554 }
1555 return;
1556 } else {
1557 if (parseattrstat(dp, vflag, 0) != 0)
1558 return;
1559 }
1560 break;
1561
1562 case NFSPROC_WRITE:
1563 printf(" write");
1564 if (!(dp = parserep(rp, length)))
1565 break;
1566 if (v3) {
1567 if (!(dp = parsestatus(dp, &er)))
1568 break;
1569 if (!(dp = parse_wcc_data(dp, vflag)))
1570 break;
1571 if (er)
1572 return;
1573 if (vflag) {
1574 TCHECK(dp[0]);
1575 printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
1576 if (vflag > 1) {
1577 TCHECK(dp[1]);
1578 printf(" <%s>",
1579 tok2str(nfsv3_writemodes,
1580 NULL, EXTRACT_32BITS(&dp[1])));
1581 }
1582 return;
1583 }
1584 } else {
1585 if (parseattrstat(dp, vflag, v3) != 0)
1586 return;
1587 }
1588 break;
1589
1590 case NFSPROC_CREATE:
1591 printf(" create");
1592 if (!(dp = parserep(rp, length)))
1593 break;
1594 if (v3) {
1595 if (parsecreateopres(dp, vflag) != 0)
1596 return;
1597 } else {
1598 if (parsediropres(dp) != 0)
1599 return;
1600 }
1601 break;
1602
1603 case NFSPROC_MKDIR:
1604 printf(" mkdir");
1605 if (!(dp = parserep(rp, length)))
1606 break;
1607 if (v3) {
1608 if (parsecreateopres(dp, vflag) != 0)
1609 return;
1610 } else {
1611 if (parsediropres(dp) != 0)
1612 return;
1613 }
1614 break;
1615
1616 case NFSPROC_SYMLINK:
1617 printf(" symlink");
1618 if (!(dp = parserep(rp, length)))
1619 break;
1620 if (v3) {
1621 if (parsecreateopres(dp, vflag) != 0)
1622 return;
1623 } else {
1624 if (parsestatus(dp, &er) != 0)
1625 return;
1626 }
1627 break;
1628
1629 case NFSPROC_MKNOD:
1630 printf(" mknod");
1631 if (!(dp = parserep(rp, length)))
1632 break;
1633 if (parsecreateopres(dp, vflag) != 0)
1634 return;
1635 break;
1636
1637 case NFSPROC_REMOVE:
1638 printf(" remove");
1639 if (!(dp = parserep(rp, length)))
1640 break;
1641 if (v3) {
1642 if (parsewccres(dp, vflag))
1643 return;
1644 } else {
1645 if (parsestatus(dp, &er) != 0)
1646 return;
1647 }
1648 break;
1649
1650 case NFSPROC_RMDIR:
1651 printf(" rmdir");
1652 if (!(dp = parserep(rp, length)))
1653 break;
1654 if (v3) {
1655 if (parsewccres(dp, vflag))
1656 return;
1657 } else {
1658 if (parsestatus(dp, &er) != 0)
1659 return;
1660 }
1661 break;
1662
1663 case NFSPROC_RENAME:
1664 printf(" rename");
1665 if (!(dp = parserep(rp, length)))
1666 break;
1667 if (v3) {
1668 if (!(dp = parsestatus(dp, &er)))
1669 break;
1670 if (vflag) {
1671 printf(" from:");
1672 if (!(dp = parse_wcc_data(dp, vflag)))
1673 break;
1674 printf(" to:");
1675 if (!(dp = parse_wcc_data(dp, vflag)))
1676 break;
1677 }
1678 return;
1679 } else {
1680 if (parsestatus(dp, &er) != 0)
1681 return;
1682 }
1683 break;
1684
1685 case NFSPROC_LINK:
1686 printf(" link");
1687 if (!(dp = parserep(rp, length)))
1688 break;
1689 if (v3) {
1690 if (!(dp = parsestatus(dp, &er)))
1691 break;
1692 if (vflag) {
1693 printf(" file POST:");
1694 if (!(dp = parse_post_op_attr(dp, vflag)))
1695 break;
1696 printf(" dir:");
1697 if (!(dp = parse_wcc_data(dp, vflag)))
1698 break;
1699 return;
1700 }
1701 } else {
1702 if (parsestatus(dp, &er) != 0)
1703 return;
1704 }
1705 break;
1706
1707 case NFSPROC_READDIR:
1708 printf(" readdir");
1709 if (!(dp = parserep(rp, length)))
1710 break;
1711 if (v3) {
1712 if (parsev3rddirres(dp, vflag))
1713 return;
1714 } else {
1715 if (parserddires(dp) != 0)
1716 return;
1717 }
1718 break;
1719
1720 case NFSPROC_READDIRPLUS:
1721 printf(" readdirplus");
1722 if (!(dp = parserep(rp, length)))
1723 break;
1724 if (parsev3rddirres(dp, vflag))
1725 return;
1726 break;
1727
1728 case NFSPROC_FSSTAT:
1729 printf(" fsstat");
1730 dp = parserep(rp, length);
1731 if (dp != NULL && parsestatfs(dp, v3) != 0)
1732 return;
1733 break;
1734
1735 case NFSPROC_FSINFO:
1736 printf(" fsinfo");
1737 dp = parserep(rp, length);
1738 if (dp != NULL && parsefsinfo(dp) != 0)
1739 return;
1740 break;
1741
1742 case NFSPROC_PATHCONF:
1743 printf(" pathconf");
1744 dp = parserep(rp, length);
1745 if (dp != NULL && parsepathconf(dp) != 0)
1746 return;
1747 break;
1748
1749 case NFSPROC_COMMIT:
1750 printf(" commit");
1751 dp = parserep(rp, length);
1752 if (dp != NULL && parsewccres(dp, vflag) != 0)
1753 return;
1754 break;
1755
1756 default:
1757 printf(" proc-%u", proc);
1758 return;
1759 }
1760 trunc:
1761 if (!nfserr)
1762 fputs(" [|nfs]", stdout);
1763 }