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