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