blob: a71e068da6888e2dfca7255ef926837575959d6c [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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
Elliott Hughese2e3bd12017-05-15 10:59:29 -070022/* \summary: Network File System (NFS) printer */
23
The Android Open Source Project2949f582009-03-03 19:30:46 -080024#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
Elliott Hughese2e3bd12017-05-15 10:59:29 -070028#include <netdissect-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080029
The Android Open Source Project2949f582009-03-03 19:30:46 -080030#include <stdio.h>
31#include <string.h>
32
Elliott Hughese2e3bd12017-05-15 10:59:29 -070033#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080034#include "addrtoname.h"
35#include "extract.h"
36
37#include "nfs.h"
38#include "nfsfh.h"
39
40#include "ip.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080041#include "ip6.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080042#include "rpc_auth.h"
43#include "rpc_msg.h"
44
Elliott Hughes892a68b2015-10-19 14:43:53 -070045static const char tstr[] = " [|nfs]";
46
47static void nfs_printfh(netdissect_options *, const uint32_t *, const u_int);
48static int xid_map_enter(netdissect_options *, const struct sunrpc_msg *, const u_char *);
JP Abgrall53f17a92014-02-12 14:02:41 -080049static int xid_map_find(const struct sunrpc_msg *, const u_char *,
Elliott Hughes892a68b2015-10-19 14:43:53 -070050 uint32_t *, uint32_t *);
51static void interp_reply(netdissect_options *, const struct sunrpc_msg *, uint32_t, uint32_t, int);
52static const uint32_t *parse_post_op_attr(netdissect_options *, const uint32_t *, int);
The Android Open Source Project2949f582009-03-03 19:30:46 -080053
54/*
55 * Mapping of old NFS Version 2 RPC numbers to generic numbers.
56 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -070057static uint32_t nfsv3_procid[NFS_NPROCS] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080058 NFSPROC_NULL,
59 NFSPROC_GETATTR,
60 NFSPROC_SETATTR,
61 NFSPROC_NOOP,
62 NFSPROC_LOOKUP,
63 NFSPROC_READLINK,
64 NFSPROC_READ,
65 NFSPROC_NOOP,
66 NFSPROC_WRITE,
67 NFSPROC_CREATE,
68 NFSPROC_REMOVE,
69 NFSPROC_RENAME,
70 NFSPROC_LINK,
71 NFSPROC_SYMLINK,
72 NFSPROC_MKDIR,
73 NFSPROC_RMDIR,
74 NFSPROC_READDIR,
75 NFSPROC_FSSTAT,
76 NFSPROC_NOOP,
77 NFSPROC_NOOP,
78 NFSPROC_NOOP,
79 NFSPROC_NOOP,
80 NFSPROC_NOOP,
81 NFSPROC_NOOP,
82 NFSPROC_NOOP,
83 NFSPROC_NOOP
84};
85
Elliott Hughes892a68b2015-10-19 14:43:53 -070086static const struct tok nfsproc_str[] = {
87 { NFSPROC_NOOP, "nop" },
88 { NFSPROC_NULL, "null" },
89 { NFSPROC_GETATTR, "getattr" },
90 { NFSPROC_SETATTR, "setattr" },
91 { NFSPROC_LOOKUP, "lookup" },
92 { NFSPROC_ACCESS, "access" },
93 { NFSPROC_READLINK, "readlink" },
94 { NFSPROC_READ, "read" },
95 { NFSPROC_WRITE, "write" },
96 { NFSPROC_CREATE, "create" },
97 { NFSPROC_MKDIR, "mkdir" },
98 { NFSPROC_SYMLINK, "symlink" },
99 { NFSPROC_MKNOD, "mknod" },
100 { NFSPROC_REMOVE, "remove" },
101 { NFSPROC_RMDIR, "rmdir" },
102 { NFSPROC_RENAME, "rename" },
103 { NFSPROC_LINK, "link" },
104 { NFSPROC_READDIR, "readdir" },
105 { NFSPROC_READDIRPLUS, "readdirplus" },
106 { NFSPROC_FSSTAT, "fsstat" },
107 { NFSPROC_FSINFO, "fsinfo" },
108 { NFSPROC_PATHCONF, "pathconf" },
109 { NFSPROC_COMMIT, "commit" },
110 { 0, NULL }
111};
112
The Android Open Source Project2949f582009-03-03 19:30:46 -0800113/*
114 * NFS V2 and V3 status values.
115 *
116 * Some of these come from the RFCs for NFS V2 and V3, with the message
117 * strings taken from the FreeBSD C library "errlst.c".
118 *
119 * Others are errors that are not in the RFC but that I suspect some
120 * NFS servers could return; the values are FreeBSD errno values, as
121 * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
122 * was primarily BSD-derived.
123 */
JP Abgrall53f17a92014-02-12 14:02:41 -0800124static const struct tok status2str[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800125 { 1, "Operation not permitted" }, /* EPERM */
126 { 2, "No such file or directory" }, /* ENOENT */
127 { 5, "Input/output error" }, /* EIO */
128 { 6, "Device not configured" }, /* ENXIO */
129 { 11, "Resource deadlock avoided" }, /* EDEADLK */
130 { 12, "Cannot allocate memory" }, /* ENOMEM */
131 { 13, "Permission denied" }, /* EACCES */
132 { 17, "File exists" }, /* EEXIST */
133 { 18, "Cross-device link" }, /* EXDEV */
134 { 19, "Operation not supported by device" }, /* ENODEV */
135 { 20, "Not a directory" }, /* ENOTDIR */
136 { 21, "Is a directory" }, /* EISDIR */
137 { 22, "Invalid argument" }, /* EINVAL */
138 { 26, "Text file busy" }, /* ETXTBSY */
139 { 27, "File too large" }, /* EFBIG */
140 { 28, "No space left on device" }, /* ENOSPC */
141 { 30, "Read-only file system" }, /* EROFS */
142 { 31, "Too many links" }, /* EMLINK */
143 { 45, "Operation not supported" }, /* EOPNOTSUPP */
144 { 62, "Too many levels of symbolic links" }, /* ELOOP */
145 { 63, "File name too long" }, /* ENAMETOOLONG */
146 { 66, "Directory not empty" }, /* ENOTEMPTY */
147 { 69, "Disc quota exceeded" }, /* EDQUOT */
148 { 70, "Stale NFS file handle" }, /* ESTALE */
149 { 71, "Too many levels of remote in path" }, /* EREMOTE */
150 { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */
151 { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */
152 { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */
153 { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */
154 { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */
155 { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */
156 { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */
157 { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */
158 { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */
159 { 0, NULL }
160};
161
JP Abgrall53f17a92014-02-12 14:02:41 -0800162static const struct tok nfsv3_writemodes[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800163 { 0, "unstable" },
164 { 1, "datasync" },
165 { 2, "filesync" },
166 { 0, NULL }
167};
168
JP Abgrall53f17a92014-02-12 14:02:41 -0800169static const struct tok type2str[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800170 { NFNON, "NON" },
171 { NFREG, "REG" },
172 { NFDIR, "DIR" },
173 { NFBLK, "BLK" },
174 { NFCHR, "CHR" },
175 { NFLNK, "LNK" },
176 { NFFIFO, "FIFO" },
177 { 0, NULL }
178};
179
Elliott Hughes892a68b2015-10-19 14:43:53 -0700180static const struct tok sunrpc_auth_str[] = {
181 { SUNRPC_AUTH_OK, "OK" },
182 { SUNRPC_AUTH_BADCRED, "Bogus Credentials (seal broken)" },
183 { SUNRPC_AUTH_REJECTEDCRED, "Rejected Credentials (client should begin new session)" },
184 { SUNRPC_AUTH_BADVERF, "Bogus Verifier (seal broken)" },
185 { SUNRPC_AUTH_REJECTEDVERF, "Verifier expired or was replayed" },
186 { SUNRPC_AUTH_TOOWEAK, "Credentials are too weak" },
187 { SUNRPC_AUTH_INVALIDRESP, "Bogus response verifier" },
188 { SUNRPC_AUTH_FAILED, "Unknown failure" },
189 { 0, NULL }
190};
191
192static const struct tok sunrpc_str[] = {
193 { SUNRPC_PROG_UNAVAIL, "PROG_UNAVAIL" },
194 { SUNRPC_PROG_MISMATCH, "PROG_MISMATCH" },
195 { SUNRPC_PROC_UNAVAIL, "PROC_UNAVAIL" },
196 { SUNRPC_GARBAGE_ARGS, "GARBAGE_ARGS" },
197 { SUNRPC_SYSTEM_ERR, "SYSTEM_ERR" },
198 { 0, NULL }
199};
200
The Android Open Source Project2949f582009-03-03 19:30:46 -0800201static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700202print_nfsaddr(netdissect_options *ndo,
203 const u_char *bp, const char *s, const char *d)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800204{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700205 const struct ip *ip;
206 const struct ip6_hdr *ip6;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800207 char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800208
209 srcaddr[0] = dstaddr[0] = '\0';
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700210 switch (IP_V((const struct ip *)bp)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800211 case 4:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700212 ip = (const struct ip *)bp;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700213 strlcpy(srcaddr, ipaddr_string(ndo, &ip->ip_src), sizeof(srcaddr));
214 strlcpy(dstaddr, ipaddr_string(ndo, &ip->ip_dst), sizeof(dstaddr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800215 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800216 case 6:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700217 ip6 = (const struct ip6_hdr *)bp;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700218 strlcpy(srcaddr, ip6addr_string(ndo, &ip6->ip6_src),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800219 sizeof(srcaddr));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700220 strlcpy(dstaddr, ip6addr_string(ndo, &ip6->ip6_dst),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800221 sizeof(dstaddr));
222 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800223 default:
224 strlcpy(srcaddr, "?", sizeof(srcaddr));
225 strlcpy(dstaddr, "?", sizeof(dstaddr));
226 break;
227 }
228
Elliott Hughes892a68b2015-10-19 14:43:53 -0700229 ND_PRINT((ndo, "%s.%s > %s.%s: ", srcaddr, s, dstaddr, d));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800230}
231
Elliott Hughes892a68b2015-10-19 14:43:53 -0700232static const uint32_t *
233parse_sattr3(netdissect_options *ndo,
234 const uint32_t *dp, struct nfsv3_sattr *sa3)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800235{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700236 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800237 sa3->sa_modeset = EXTRACT_32BITS(dp);
238 dp++;
239 if (sa3->sa_modeset) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700240 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800241 sa3->sa_mode = EXTRACT_32BITS(dp);
242 dp++;
243 }
244
Elliott Hughes892a68b2015-10-19 14:43:53 -0700245 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800246 sa3->sa_uidset = EXTRACT_32BITS(dp);
247 dp++;
248 if (sa3->sa_uidset) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700249 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800250 sa3->sa_uid = EXTRACT_32BITS(dp);
251 dp++;
252 }
253
Elliott Hughes892a68b2015-10-19 14:43:53 -0700254 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800255 sa3->sa_gidset = EXTRACT_32BITS(dp);
256 dp++;
257 if (sa3->sa_gidset) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700258 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800259 sa3->sa_gid = EXTRACT_32BITS(dp);
260 dp++;
261 }
262
Elliott Hughes892a68b2015-10-19 14:43:53 -0700263 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800264 sa3->sa_sizeset = EXTRACT_32BITS(dp);
265 dp++;
266 if (sa3->sa_sizeset) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700267 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800268 sa3->sa_size = EXTRACT_32BITS(dp);
269 dp++;
270 }
271
Elliott Hughes892a68b2015-10-19 14:43:53 -0700272 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800273 sa3->sa_atimetype = EXTRACT_32BITS(dp);
274 dp++;
275 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700276 ND_TCHECK(dp[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800277 sa3->sa_atime.nfsv3_sec = EXTRACT_32BITS(dp);
278 dp++;
279 sa3->sa_atime.nfsv3_nsec = EXTRACT_32BITS(dp);
280 dp++;
281 }
282
Elliott Hughes892a68b2015-10-19 14:43:53 -0700283 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800284 sa3->sa_mtimetype = EXTRACT_32BITS(dp);
285 dp++;
286 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700287 ND_TCHECK(dp[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800288 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;
295trunc:
296 return NULL;
297}
298
299static int nfserr; /* true if we error rather than trunc */
300
301static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700302print_sattr3(netdissect_options *ndo,
303 const struct nfsv3_sattr *sa3, int verbose)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800304{
305 if (sa3->sa_modeset)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700306 ND_PRINT((ndo, " mode %o", sa3->sa_mode));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800307 if (sa3->sa_uidset)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700308 ND_PRINT((ndo, " uid %u", sa3->sa_uid));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800309 if (sa3->sa_gidset)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700310 ND_PRINT((ndo, " gid %u", sa3->sa_gid));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800311 if (verbose > 1) {
312 if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700313 ND_PRINT((ndo, " atime %u.%06u", sa3->sa_atime.nfsv3_sec,
314 sa3->sa_atime.nfsv3_nsec));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800315 if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700316 ND_PRINT((ndo, " mtime %u.%06u", sa3->sa_mtime.nfsv3_sec,
317 sa3->sa_mtime.nfsv3_nsec));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800318 }
319}
320
321void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700322nfsreply_print(netdissect_options *ndo,
323 register const u_char *bp, u_int length,
324 register const u_char *bp2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800325{
326 register const struct sunrpc_msg *rp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800327 char srcid[20], dstid[20]; /*fits 32bit*/
The Android Open Source Project2949f582009-03-03 19:30:46 -0800328
329 nfserr = 0; /* assume no error */
330 rp = (const struct sunrpc_msg *)bp;
331
Elliott Hughes892a68b2015-10-19 14:43:53 -0700332 ND_TCHECK(rp->rm_xid);
333 if (!ndo->ndo_nflag) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800334 strlcpy(srcid, "nfs", sizeof(srcid));
335 snprintf(dstid, sizeof(dstid), "%u",
336 EXTRACT_32BITS(&rp->rm_xid));
337 } else {
338 snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
339 snprintf(dstid, sizeof(dstid), "%u",
340 EXTRACT_32BITS(&rp->rm_xid));
341 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700342 print_nfsaddr(ndo, bp2, srcid, dstid);
JP Abgrall53f17a92014-02-12 14:02:41 -0800343
Elliott Hughes892a68b2015-10-19 14:43:53 -0700344 nfsreply_print_noaddr(ndo, bp, length, bp2);
JP Abgrall53f17a92014-02-12 14:02:41 -0800345 return;
346
347trunc:
348 if (!nfserr)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700349 ND_PRINT((ndo, "%s", tstr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800350}
351
352void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700353nfsreply_print_noaddr(netdissect_options *ndo,
354 register const u_char *bp, u_int length,
355 register const u_char *bp2)
JP Abgrall53f17a92014-02-12 14:02:41 -0800356{
357 register const struct sunrpc_msg *rp;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700358 uint32_t proc, vers, reply_stat;
JP Abgrall53f17a92014-02-12 14:02:41 -0800359 enum sunrpc_reject_stat rstat;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700360 uint32_t rlow;
361 uint32_t rhigh;
JP Abgrall53f17a92014-02-12 14:02:41 -0800362 enum sunrpc_auth_stat rwhy;
363
364 nfserr = 0; /* assume no error */
365 rp = (const struct sunrpc_msg *)bp;
366
Elliott Hughes892a68b2015-10-19 14:43:53 -0700367 ND_TCHECK(rp->rm_reply.rp_stat);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800368 reply_stat = EXTRACT_32BITS(&rp->rm_reply.rp_stat);
369 switch (reply_stat) {
370
371 case SUNRPC_MSG_ACCEPTED:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700372 ND_PRINT((ndo, "reply ok %u", length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800373 if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700374 interp_reply(ndo, rp, proc, vers, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800375 break;
376
377 case SUNRPC_MSG_DENIED:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700378 ND_PRINT((ndo, "reply ERR %u: ", length));
379 ND_TCHECK(rp->rm_reply.rp_reject.rj_stat);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800380 rstat = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_stat);
381 switch (rstat) {
382
383 case SUNRPC_RPC_MISMATCH:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700384 ND_TCHECK(rp->rm_reply.rp_reject.rj_vers.high);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800385 rlow = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_vers.low);
386 rhigh = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_vers.high);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700387 ND_PRINT((ndo, "RPC Version mismatch (%u-%u)", rlow, rhigh));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800388 break;
389
390 case SUNRPC_AUTH_ERROR:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700391 ND_TCHECK(rp->rm_reply.rp_reject.rj_why);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800392 rwhy = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_why);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700393 ND_PRINT((ndo, "Auth %s", tok2str(sunrpc_auth_str, "Invalid failure code %u", rwhy)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800394 break;
395
396 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700397 ND_PRINT((ndo, "Unknown reason for rejecting rpc message %u", (unsigned int)rstat));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800398 break;
399 }
400 break;
401
402 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700403 ND_PRINT((ndo, "reply Unknown rpc response code=%u %u", reply_stat, length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800404 break;
405 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800406 return;
407
408trunc:
409 if (!nfserr)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700410 ND_PRINT((ndo, "%s", tstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800411}
412
413/*
414 * Return a pointer to the first file handle in the packet.
415 * If the packet was truncated, return 0.
416 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700417static const uint32_t *
418parsereq(netdissect_options *ndo,
419 register const struct sunrpc_msg *rp, register u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800420{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700421 register const uint32_t *dp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800422 register u_int len;
423
424 /*
425 * find the start of the req data (if we captured it)
426 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700427 dp = (const uint32_t *)&rp->rm_call.cb_cred;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700428 ND_TCHECK(dp[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800429 len = EXTRACT_32BITS(&dp[1]);
430 if (len < length) {
431 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700432 ND_TCHECK(dp[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800433 len = EXTRACT_32BITS(&dp[1]);
434 if (len < length) {
435 dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700436 ND_TCHECK2(dp[0], 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800437 return (dp);
438 }
439 }
440trunc:
441 return (NULL);
442}
443
444/*
445 * Print out an NFS file handle and return a pointer to following word.
446 * If packet was truncated, return 0.
447 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700448static const uint32_t *
449parsefh(netdissect_options *ndo,
450 register const uint32_t *dp, int v3)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800451{
452 u_int len;
453
454 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700455 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800456 len = EXTRACT_32BITS(dp) / 4;
457 dp++;
458 } else
459 len = NFSX_V2FH / 4;
460
Elliott Hughes892a68b2015-10-19 14:43:53 -0700461 if (ND_TTEST2(*dp, len * sizeof(*dp))) {
462 nfs_printfh(ndo, dp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800463 return (dp + len);
464 }
465trunc:
466 return (NULL);
467}
468
469/*
470 * Print out a file name and return pointer to 32-bit word past it.
471 * If packet was truncated, return 0.
472 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700473static const uint32_t *
474parsefn(netdissect_options *ndo,
475 register const uint32_t *dp)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800476{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700477 register uint32_t len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800478 register const u_char *cp;
479
480 /* Bail if we don't have the string length */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700481 ND_TCHECK(*dp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800482
483 /* Fetch string length; convert to host order */
484 len = *dp++;
485 NTOHL(len);
486
Elliott Hughes892a68b2015-10-19 14:43:53 -0700487 ND_TCHECK2(*dp, ((len + 3) & ~3));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800488
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700489 cp = (const u_char *)dp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800490 /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
491 dp += ((len + 3) & ~3) / sizeof(*dp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700492 ND_PRINT((ndo, "\""));
493 if (fn_printn(ndo, cp, len, ndo->ndo_snapend)) {
494 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800495 goto trunc;
496 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700497 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800498
499 return (dp);
500trunc:
501 return NULL;
502}
503
504/*
505 * Print out file handle and file name.
506 * Return pointer to 32-bit word past file name.
507 * If packet was truncated (or there was some other error), return 0.
508 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700509static const uint32_t *
510parsefhn(netdissect_options *ndo,
511 register const uint32_t *dp, int v3)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800512{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700513 dp = parsefh(ndo, dp, v3);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800514 if (dp == NULL)
515 return (NULL);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700516 ND_PRINT((ndo, " "));
517 return (parsefn(ndo, dp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800518}
519
520void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700521nfsreq_print_noaddr(netdissect_options *ndo,
522 register const u_char *bp, u_int length,
523 register const u_char *bp2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800524{
525 register const struct sunrpc_msg *rp;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700526 register const uint32_t *dp;
JP Abgrall53f17a92014-02-12 14:02:41 -0800527 nfs_type type;
528 int v3;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700529 uint32_t proc;
530 uint32_t access_flags;
JP Abgrall53f17a92014-02-12 14:02:41 -0800531 struct nfsv3_sattr sa3;
532
Elliott Hughes892a68b2015-10-19 14:43:53 -0700533 ND_PRINT((ndo, "%d", length));
JP Abgrall53f17a92014-02-12 14:02:41 -0800534 nfserr = 0; /* assume no error */
535 rp = (const struct sunrpc_msg *)bp;
536
Elliott Hughes892a68b2015-10-19 14:43:53 -0700537 if (!xid_map_enter(ndo, rp, bp2)) /* record proc number for later on */
JP Abgrall53f17a92014-02-12 14:02:41 -0800538 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800539
540 v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3);
541 proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
542
543 if (!v3 && proc < NFS_NPROCS)
544 proc = nfsv3_procid[proc];
545
Elliott Hughes892a68b2015-10-19 14:43:53 -0700546 ND_PRINT((ndo, " %s", tok2str(nfsproc_str, "proc-%u", proc)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800547 switch (proc) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800548
549 case NFSPROC_GETATTR:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800550 case NFSPROC_SETATTR:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700551 case NFSPROC_READLINK:
552 case NFSPROC_FSSTAT:
553 case NFSPROC_FSINFO:
554 case NFSPROC_PATHCONF:
555 if ((dp = parsereq(ndo, rp, length)) != NULL &&
556 parsefh(ndo, dp, v3) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800557 return;
558 break;
559
560 case NFSPROC_LOOKUP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700561 case NFSPROC_CREATE:
562 case NFSPROC_MKDIR:
563 case NFSPROC_REMOVE:
564 case NFSPROC_RMDIR:
565 if ((dp = parsereq(ndo, rp, length)) != NULL &&
566 parsefhn(ndo, dp, v3) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800567 return;
568 break;
569
570 case NFSPROC_ACCESS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700571 if ((dp = parsereq(ndo, rp, length)) != NULL &&
572 (dp = parsefh(ndo, dp, v3)) != NULL) {
573 ND_TCHECK(dp[0]);
JP Abgrall53f17a92014-02-12 14:02:41 -0800574 access_flags = EXTRACT_32BITS(&dp[0]);
575 if (access_flags & ~NFSV3ACCESS_FULL) {
576 /* NFSV3ACCESS definitions aren't up to date */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700577 ND_PRINT((ndo, " %04x", access_flags));
JP Abgrall53f17a92014-02-12 14:02:41 -0800578 } else if ((access_flags & NFSV3ACCESS_FULL) == NFSV3ACCESS_FULL) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700579 ND_PRINT((ndo, " NFS_ACCESS_FULL"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800580 } else {
581 char separator = ' ';
582 if (access_flags & NFSV3ACCESS_READ) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700583 ND_PRINT((ndo, " NFS_ACCESS_READ"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800584 separator = '|';
585 }
586 if (access_flags & NFSV3ACCESS_LOOKUP) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700587 ND_PRINT((ndo, "%cNFS_ACCESS_LOOKUP", separator));
JP Abgrall53f17a92014-02-12 14:02:41 -0800588 separator = '|';
589 }
590 if (access_flags & NFSV3ACCESS_MODIFY) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700591 ND_PRINT((ndo, "%cNFS_ACCESS_MODIFY", separator));
JP Abgrall53f17a92014-02-12 14:02:41 -0800592 separator = '|';
593 }
594 if (access_flags & NFSV3ACCESS_EXTEND) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700595 ND_PRINT((ndo, "%cNFS_ACCESS_EXTEND", separator));
JP Abgrall53f17a92014-02-12 14:02:41 -0800596 separator = '|';
597 }
598 if (access_flags & NFSV3ACCESS_DELETE) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700599 ND_PRINT((ndo, "%cNFS_ACCESS_DELETE", separator));
JP Abgrall53f17a92014-02-12 14:02:41 -0800600 separator = '|';
601 }
602 if (access_flags & NFSV3ACCESS_EXECUTE)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700603 ND_PRINT((ndo, "%cNFS_ACCESS_EXECUTE", separator));
JP Abgrall53f17a92014-02-12 14:02:41 -0800604 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800605 return;
606 }
607 break;
608
The Android Open Source Project2949f582009-03-03 19:30:46 -0800609 case NFSPROC_READ:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700610 if ((dp = parsereq(ndo, rp, length)) != NULL &&
611 (dp = parsefh(ndo, dp, v3)) != NULL) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800612 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700613 ND_TCHECK(dp[2]);
614 ND_PRINT((ndo, " %u bytes @ %" PRIu64,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800615 EXTRACT_32BITS(&dp[2]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700616 EXTRACT_64BITS(&dp[0])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800617 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700618 ND_TCHECK(dp[1]);
619 ND_PRINT((ndo, " %u bytes @ %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800620 EXTRACT_32BITS(&dp[1]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700621 EXTRACT_32BITS(&dp[0])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800622 }
623 return;
624 }
625 break;
626
627 case NFSPROC_WRITE:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700628 if ((dp = parsereq(ndo, rp, length)) != NULL &&
629 (dp = parsefh(ndo, dp, v3)) != NULL) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800630 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700631 ND_TCHECK(dp[2]);
632 ND_PRINT((ndo, " %u (%u) bytes @ %" PRIu64,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800633 EXTRACT_32BITS(&dp[4]),
634 EXTRACT_32BITS(&dp[2]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700635 EXTRACT_64BITS(&dp[0])));
636 if (ndo->ndo_vflag) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800637 dp += 3;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700638 ND_TCHECK(dp[0]);
639 ND_PRINT((ndo, " <%s>",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800640 tok2str(nfsv3_writemodes,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700641 NULL, EXTRACT_32BITS(dp))));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800642 }
643 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700644 ND_TCHECK(dp[3]);
645 ND_PRINT((ndo, " %u (%u) bytes @ %u (%u)",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800646 EXTRACT_32BITS(&dp[3]),
647 EXTRACT_32BITS(&dp[2]),
648 EXTRACT_32BITS(&dp[1]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700649 EXTRACT_32BITS(&dp[0])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800650 }
651 return;
652 }
653 break;
654
The Android Open Source Project2949f582009-03-03 19:30:46 -0800655 case NFSPROC_SYMLINK:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700656 if ((dp = parsereq(ndo, rp, length)) != NULL &&
657 (dp = parsefhn(ndo, dp, v3)) != NULL) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700658 ND_PRINT((ndo, " ->"));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700659 if (v3 && (dp = parse_sattr3(ndo, dp, &sa3)) == NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800660 break;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700661 if (parsefn(ndo, dp) == NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800662 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700663 if (v3 && ndo->ndo_vflag)
664 print_sattr3(ndo, &sa3, ndo->ndo_vflag);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800665 return;
666 }
667 break;
668
669 case NFSPROC_MKNOD:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700670 if ((dp = parsereq(ndo, rp, length)) != NULL &&
671 (dp = parsefhn(ndo, dp, v3)) != NULL) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700672 ND_TCHECK(*dp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800673 type = (nfs_type)EXTRACT_32BITS(dp);
674 dp++;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700675 if ((dp = parse_sattr3(ndo, dp, &sa3)) == NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800676 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700677 ND_PRINT((ndo, " %s", tok2str(type2str, "unk-ft %d", type)));
678 if (ndo->ndo_vflag && (type == NFCHR || type == NFBLK)) {
679 ND_TCHECK(dp[1]);
680 ND_PRINT((ndo, " %u/%u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800681 EXTRACT_32BITS(&dp[0]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700682 EXTRACT_32BITS(&dp[1])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800683 dp += 2;
684 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700685 if (ndo->ndo_vflag)
686 print_sattr3(ndo, &sa3, ndo->ndo_vflag);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800687 return;
688 }
689 break;
690
The Android Open Source Project2949f582009-03-03 19:30:46 -0800691 case NFSPROC_RENAME:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700692 if ((dp = parsereq(ndo, rp, length)) != NULL &&
693 (dp = parsefhn(ndo, dp, v3)) != NULL) {
694 ND_PRINT((ndo, " ->"));
695 if (parsefhn(ndo, dp, v3) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800696 return;
697 }
698 break;
699
700 case NFSPROC_LINK:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700701 if ((dp = parsereq(ndo, rp, length)) != NULL &&
702 (dp = parsefh(ndo, dp, v3)) != NULL) {
703 ND_PRINT((ndo, " ->"));
704 if (parsefhn(ndo, dp, v3) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800705 return;
706 }
707 break;
708
709 case NFSPROC_READDIR:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700710 if ((dp = parsereq(ndo, rp, length)) != NULL &&
711 (dp = parsefh(ndo, dp, v3)) != NULL) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800712 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700713 ND_TCHECK(dp[4]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800714 /*
715 * We shouldn't really try to interpret the
716 * offset cookie here.
717 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700718 ND_PRINT((ndo, " %u bytes @ %" PRId64,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800719 EXTRACT_32BITS(&dp[4]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700720 EXTRACT_64BITS(&dp[0])));
721 if (ndo->ndo_vflag)
722 ND_PRINT((ndo, " verf %08x%08x", dp[2], dp[3]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800723 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700724 ND_TCHECK(dp[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800725 /*
726 * Print the offset as signed, since -1 is
727 * common, but offsets > 2^31 aren't.
728 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700729 ND_PRINT((ndo, " %u bytes @ %d",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800730 EXTRACT_32BITS(&dp[1]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700731 EXTRACT_32BITS(&dp[0])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800732 }
733 return;
734 }
735 break;
736
737 case NFSPROC_READDIRPLUS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700738 if ((dp = parsereq(ndo, rp, length)) != NULL &&
739 (dp = parsefh(ndo, dp, v3)) != NULL) {
740 ND_TCHECK(dp[4]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800741 /*
742 * We don't try to interpret the offset
743 * cookie here.
744 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700745 ND_PRINT((ndo, " %u bytes @ %" PRId64,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800746 EXTRACT_32BITS(&dp[4]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700747 EXTRACT_64BITS(&dp[0])));
748 if (ndo->ndo_vflag) {
749 ND_TCHECK(dp[5]);
750 ND_PRINT((ndo, " max %u verf %08x%08x",
751 EXTRACT_32BITS(&dp[5]), dp[2], dp[3]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800752 }
753 return;
754 }
755 break;
756
The Android Open Source Project2949f582009-03-03 19:30:46 -0800757 case NFSPROC_COMMIT:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700758 if ((dp = parsereq(ndo, rp, length)) != NULL &&
759 (dp = parsefh(ndo, dp, v3)) != NULL) {
760 ND_TCHECK(dp[2]);
761 ND_PRINT((ndo, " %u bytes @ %" PRIu64,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800762 EXTRACT_32BITS(&dp[2]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700763 EXTRACT_64BITS(&dp[0])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800764 return;
765 }
766 break;
767
768 default:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800769 return;
770 }
771
772trunc:
773 if (!nfserr)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700774 ND_PRINT((ndo, "%s", tstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800775}
776
777/*
778 * Print out an NFS file handle.
779 * We assume packet was not truncated before the end of the
780 * file handle pointed to by dp.
781 *
782 * Note: new version (using portable file-handle parser) doesn't produce
783 * generation number. It probably could be made to do that, with some
784 * additional hacking on the parser code.
785 */
786static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700787nfs_printfh(netdissect_options *ndo,
788 register const uint32_t *dp, const u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800789{
790 my_fsid fsid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700791 uint32_t ino;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800792 const char *sfsname = NULL;
793 char *spacep;
794
Elliott Hughes892a68b2015-10-19 14:43:53 -0700795 if (ndo->ndo_uflag) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800796 u_int i;
797 char const *sep = "";
798
Elliott Hughes892a68b2015-10-19 14:43:53 -0700799 ND_PRINT((ndo, " fh["));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800800 for (i=0; i<len; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700801 ND_PRINT((ndo, "%s%x", sep, dp[i]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800802 sep = ":";
803 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700804 ND_PRINT((ndo, "]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800805 return;
806 }
807
808 Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
809
810 if (sfsname) {
811 /* file system ID is ASCII, not numeric, for this server OS */
812 static char temp[NFSX_V3FHMAX+1];
813
814 /* Make sure string is null-terminated */
815 strncpy(temp, sfsname, NFSX_V3FHMAX);
816 temp[sizeof(temp) - 1] = '\0';
817 /* Remove trailing spaces */
818 spacep = strchr(temp, ' ');
819 if (spacep)
820 *spacep = '\0';
821
Elliott Hughes892a68b2015-10-19 14:43:53 -0700822 ND_PRINT((ndo, " fh %s/", temp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800823 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700824 ND_PRINT((ndo, " fh %d,%d/",
825 fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800826 }
827
828 if(fsid.Fsid_dev.Minor == 257)
829 /* Print the undecoded handle */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700830 ND_PRINT((ndo, "%s", fsid.Opaque_Handle));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800831 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700832 ND_PRINT((ndo, "%ld", (long) ino));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800833}
834
835/*
836 * Maintain a small cache of recent client.XID.server/proc pairs, to allow
837 * us to match up replies with requests and thus to know how to parse
838 * the reply.
839 */
840
841struct xid_map_entry {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700842 uint32_t xid; /* transaction ID (net order) */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800843 int ipver; /* IP version (4 or 6) */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800844 struct in6_addr client; /* client IP address (net order) */
845 struct in6_addr server; /* server IP address (net order) */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700846 uint32_t proc; /* call proc number (host order) */
847 uint32_t vers; /* program version (host order) */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800848};
849
850/*
851 * Map entries are kept in an array that we manage as a ring;
852 * new entries are always added at the tail of the ring. Initially,
853 * all the entries are zero and hence don't match anything.
854 */
855
856#define XIDMAPSIZE 64
857
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700858static struct xid_map_entry xid_map[XIDMAPSIZE];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800859
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700860static int xid_map_next = 0;
861static int xid_map_hint = 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800862
JP Abgrall53f17a92014-02-12 14:02:41 -0800863static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700864xid_map_enter(netdissect_options *ndo,
865 const struct sunrpc_msg *rp, const u_char *bp)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800866{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700867 const struct ip *ip = NULL;
868 const struct ip6_hdr *ip6 = NULL;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800869 struct xid_map_entry *xmep;
870
Elliott Hughes892a68b2015-10-19 14:43:53 -0700871 if (!ND_TTEST(rp->rm_call.cb_vers))
JP Abgrall53f17a92014-02-12 14:02:41 -0800872 return (0);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700873 switch (IP_V((const struct ip *)bp)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800874 case 4:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700875 ip = (const struct ip *)bp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800876 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800877 case 6:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700878 ip6 = (const struct ip6_hdr *)bp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800879 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800880 default:
JP Abgrall53f17a92014-02-12 14:02:41 -0800881 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800882 }
883
884 xmep = &xid_map[xid_map_next];
885
886 if (++xid_map_next >= XIDMAPSIZE)
887 xid_map_next = 0;
888
Elliott Hughes892a68b2015-10-19 14:43:53 -0700889 UNALIGNED_MEMCPY(&xmep->xid, &rp->rm_xid, sizeof(xmep->xid));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800890 if (ip) {
891 xmep->ipver = 4;
JP Abgrall53f17a92014-02-12 14:02:41 -0800892 UNALIGNED_MEMCPY(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
893 UNALIGNED_MEMCPY(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800894 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800895 else if (ip6) {
896 xmep->ipver = 6;
JP Abgrall53f17a92014-02-12 14:02:41 -0800897 UNALIGNED_MEMCPY(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
898 UNALIGNED_MEMCPY(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800899 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800900 xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
901 xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
JP Abgrall53f17a92014-02-12 14:02:41 -0800902 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800903}
904
905/*
906 * Returns 0 and puts NFSPROC_xxx in proc return and
907 * version in vers return, or returns -1 on failure
908 */
909static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700910xid_map_find(const struct sunrpc_msg *rp, const u_char *bp, uint32_t *proc,
911 uint32_t *vers)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800912{
913 int i;
914 struct xid_map_entry *xmep;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700915 uint32_t xid;
916 const struct ip *ip = (const struct ip *)bp;
917 const struct ip6_hdr *ip6 = (const struct ip6_hdr *)bp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800918 int cmp;
919
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700920 UNALIGNED_MEMCPY(&xid, &rp->rm_xid, sizeof(xmep->xid));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800921 /* Start searching from where we last left off */
922 i = xid_map_hint;
923 do {
924 xmep = &xid_map[i];
925 cmp = 1;
926 if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
927 goto nextitem;
928 switch (xmep->ipver) {
929 case 4:
JP Abgrall53f17a92014-02-12 14:02:41 -0800930 if (UNALIGNED_MEMCMP(&ip->ip_src, &xmep->server,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800931 sizeof(ip->ip_src)) != 0 ||
JP Abgrall53f17a92014-02-12 14:02:41 -0800932 UNALIGNED_MEMCMP(&ip->ip_dst, &xmep->client,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800933 sizeof(ip->ip_dst)) != 0) {
934 cmp = 0;
935 }
936 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800937 case 6:
JP Abgrall53f17a92014-02-12 14:02:41 -0800938 if (UNALIGNED_MEMCMP(&ip6->ip6_src, &xmep->server,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800939 sizeof(ip6->ip6_src)) != 0 ||
JP Abgrall53f17a92014-02-12 14:02:41 -0800940 UNALIGNED_MEMCMP(&ip6->ip6_dst, &xmep->client,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800941 sizeof(ip6->ip6_dst)) != 0) {
942 cmp = 0;
943 }
944 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800945 default:
946 cmp = 0;
947 break;
948 }
949 if (cmp) {
950 /* match */
951 xid_map_hint = i;
952 *proc = xmep->proc;
953 *vers = xmep->vers;
954 return 0;
955 }
956 nextitem:
957 if (++i >= XIDMAPSIZE)
958 i = 0;
959 } while (i != xid_map_hint);
960
961 /* search failed */
962 return (-1);
963}
964
965/*
966 * Routines for parsing reply packets
967 */
968
969/*
970 * Return a pointer to the beginning of the actual results.
971 * If the packet was truncated, return 0.
972 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700973static const uint32_t *
974parserep(netdissect_options *ndo,
975 register const struct sunrpc_msg *rp, register u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800976{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700977 register const uint32_t *dp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800978 u_int len;
979 enum sunrpc_accept_stat astat;
980
981 /*
982 * Portability note:
983 * Here we find the address of the ar_verf credentials.
984 * Originally, this calculation was
Elliott Hughes892a68b2015-10-19 14:43:53 -0700985 * dp = (uint32_t *)&rp->rm_reply.rp_acpt.ar_verf
The Android Open Source Project2949f582009-03-03 19:30:46 -0800986 * On the wire, the rp_acpt field starts immediately after
987 * the (32 bit) rp_stat field. However, rp_acpt (which is a
988 * "struct accepted_reply") contains a "struct opaque_auth",
989 * whose internal representation contains a pointer, so on a
990 * 64-bit machine the compiler inserts 32 bits of padding
991 * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use
992 * the internal representation to parse the on-the-wire
993 * representation. Instead, we skip past the rp_stat field,
994 * which is an "enum" and so occupies one 32-bit word.
995 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700996 dp = ((const uint32_t *)&rp->rm_reply) + 1;
997 ND_TCHECK(dp[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800998 len = EXTRACT_32BITS(&dp[1]);
999 if (len >= length)
1000 return (NULL);
1001 /*
1002 * skip past the ar_verf credentials.
1003 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001004 dp += (len + (2*sizeof(uint32_t) + 3)) / sizeof(uint32_t);
1005 ND_TCHECK2(dp[0], 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001006
1007 /*
1008 * now we can check the ar_stat field
1009 */
1010 astat = (enum sunrpc_accept_stat) EXTRACT_32BITS(dp);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001011 if (astat != SUNRPC_SUCCESS) {
1012 ND_PRINT((ndo, " %s", tok2str(sunrpc_str, "ar_stat %d", astat)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001013 nfserr = 1; /* suppress trunc string */
1014 return (NULL);
1015 }
1016 /* successful return */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001017 ND_TCHECK2(*dp, sizeof(astat));
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001018 return ((const uint32_t *) (sizeof(astat) + ((const char *)dp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001019trunc:
1020 return (0);
1021}
1022
Elliott Hughes892a68b2015-10-19 14:43:53 -07001023static const uint32_t *
1024parsestatus(netdissect_options *ndo,
1025 const uint32_t *dp, int *er)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001026{
1027 int errnum;
1028
Elliott Hughes892a68b2015-10-19 14:43:53 -07001029 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001030
1031 errnum = EXTRACT_32BITS(&dp[0]);
1032 if (er)
1033 *er = errnum;
1034 if (errnum != 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001035 if (!ndo->ndo_qflag)
1036 ND_PRINT((ndo, " ERROR: %s",
1037 tok2str(status2str, "unk %d", errnum)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001038 nfserr = 1;
1039 }
1040 return (dp + 1);
1041trunc:
1042 return NULL;
1043}
1044
Elliott Hughes892a68b2015-10-19 14:43:53 -07001045static const uint32_t *
1046parsefattr(netdissect_options *ndo,
1047 const uint32_t *dp, int verbose, int v3)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001048{
1049 const struct nfs_fattr *fap;
1050
1051 fap = (const struct nfs_fattr *)dp;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001052 ND_TCHECK(fap->fa_gid);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001053 if (verbose) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001054 ND_PRINT((ndo, " %s %o ids %d/%d",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001055 tok2str(type2str, "unk-ft %d ",
1056 EXTRACT_32BITS(&fap->fa_type)),
1057 EXTRACT_32BITS(&fap->fa_mode),
1058 EXTRACT_32BITS(&fap->fa_uid),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001059 EXTRACT_32BITS(&fap->fa_gid)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001060 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001061 ND_TCHECK(fap->fa3_size);
1062 ND_PRINT((ndo, " sz %" PRIu64,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001063 EXTRACT_64BITS((const uint32_t *)&fap->fa3_size)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001064 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001065 ND_TCHECK(fap->fa2_size);
1066 ND_PRINT((ndo, " sz %d", EXTRACT_32BITS(&fap->fa2_size)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001067 }
1068 }
1069 /* print lots more stuff */
1070 if (verbose > 1) {
1071 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001072 ND_TCHECK(fap->fa3_ctime);
1073 ND_PRINT((ndo, " nlink %d rdev %d/%d",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001074 EXTRACT_32BITS(&fap->fa_nlink),
1075 EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001076 EXTRACT_32BITS(&fap->fa3_rdev.specdata2)));
1077 ND_PRINT((ndo, " fsid %" PRIx64,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001078 EXTRACT_64BITS((const uint32_t *)&fap->fa3_fsid)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001079 ND_PRINT((ndo, " fileid %" PRIx64,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001080 EXTRACT_64BITS((const uint32_t *)&fap->fa3_fileid)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001081 ND_PRINT((ndo, " a/m/ctime %u.%06u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001082 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001083 EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec)));
1084 ND_PRINT((ndo, " %u.%06u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001085 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001086 EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec)));
1087 ND_PRINT((ndo, " %u.%06u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001088 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001089 EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001090 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001091 ND_TCHECK(fap->fa2_ctime);
1092 ND_PRINT((ndo, " nlink %d rdev 0x%x fsid 0x%x nodeid 0x%x a/m/ctime",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001093 EXTRACT_32BITS(&fap->fa_nlink),
1094 EXTRACT_32BITS(&fap->fa2_rdev),
1095 EXTRACT_32BITS(&fap->fa2_fsid),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001096 EXTRACT_32BITS(&fap->fa2_fileid)));
1097 ND_PRINT((ndo, " %u.%06u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001098 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001099 EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec)));
1100 ND_PRINT((ndo, " %u.%06u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001101 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001102 EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec)));
1103 ND_PRINT((ndo, " %u.%06u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001104 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001105 EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001106 }
1107 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001108 return ((const uint32_t *)((const unsigned char *)dp +
The Android Open Source Project2949f582009-03-03 19:30:46 -08001109 (v3 ? NFSX_V3FATTR : NFSX_V2FATTR)));
1110trunc:
1111 return (NULL);
1112}
1113
1114static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001115parseattrstat(netdissect_options *ndo,
1116 const uint32_t *dp, int verbose, int v3)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001117{
1118 int er;
1119
Elliott Hughes892a68b2015-10-19 14:43:53 -07001120 dp = parsestatus(ndo, dp, &er);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001121 if (dp == NULL)
1122 return (0);
1123 if (er)
1124 return (1);
1125
Elliott Hughes892a68b2015-10-19 14:43:53 -07001126 return (parsefattr(ndo, dp, verbose, v3) != NULL);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001127}
1128
1129static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001130parsediropres(netdissect_options *ndo,
1131 const uint32_t *dp)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001132{
1133 int er;
1134
Elliott Hughes892a68b2015-10-19 14:43:53 -07001135 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001136 return (0);
1137 if (er)
1138 return (1);
1139
Elliott Hughes892a68b2015-10-19 14:43:53 -07001140 dp = parsefh(ndo, dp, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001141 if (dp == NULL)
1142 return (0);
1143
Elliott Hughes892a68b2015-10-19 14:43:53 -07001144 return (parsefattr(ndo, dp, ndo->ndo_vflag, 0) != NULL);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001145}
1146
1147static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001148parselinkres(netdissect_options *ndo,
1149 const uint32_t *dp, int v3)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001150{
1151 int er;
1152
Elliott Hughes892a68b2015-10-19 14:43:53 -07001153 dp = parsestatus(ndo, dp, &er);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001154 if (dp == NULL)
1155 return(0);
1156 if (er)
1157 return(1);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001158 if (v3 && !(dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001159 return (0);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001160 ND_PRINT((ndo, " "));
1161 return (parsefn(ndo, dp) != NULL);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001162}
1163
1164static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001165parsestatfs(netdissect_options *ndo,
1166 const uint32_t *dp, int v3)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001167{
1168 const struct nfs_statfs *sfsp;
1169 int er;
1170
Elliott Hughes892a68b2015-10-19 14:43:53 -07001171 dp = parsestatus(ndo, dp, &er);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001172 if (dp == NULL)
1173 return (0);
1174 if (!v3 && er)
1175 return (1);
1176
Elliott Hughes892a68b2015-10-19 14:43:53 -07001177 if (ndo->ndo_qflag)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001178 return(1);
1179
1180 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001181 if (ndo->ndo_vflag)
1182 ND_PRINT((ndo, " POST:"));
1183 if (!(dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001184 return (0);
1185 }
1186
Elliott Hughes892a68b2015-10-19 14:43:53 -07001187 ND_TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001188
1189 sfsp = (const struct nfs_statfs *)dp;
1190
1191 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001192 ND_PRINT((ndo, " tbytes %" PRIu64 " fbytes %" PRIu64 " abytes %" PRIu64,
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001193 EXTRACT_64BITS((const uint32_t *)&sfsp->sf_tbytes),
1194 EXTRACT_64BITS((const uint32_t *)&sfsp->sf_fbytes),
1195 EXTRACT_64BITS((const uint32_t *)&sfsp->sf_abytes)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001196 if (ndo->ndo_vflag) {
1197 ND_PRINT((ndo, " tfiles %" PRIu64 " ffiles %" PRIu64 " afiles %" PRIu64 " invar %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001198 EXTRACT_64BITS((const uint32_t *)&sfsp->sf_tfiles),
1199 EXTRACT_64BITS((const uint32_t *)&sfsp->sf_ffiles),
1200 EXTRACT_64BITS((const uint32_t *)&sfsp->sf_afiles),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001201 EXTRACT_32BITS(&sfsp->sf_invarsec)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001202 }
1203 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001204 ND_PRINT((ndo, " tsize %d bsize %d blocks %d bfree %d bavail %d",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001205 EXTRACT_32BITS(&sfsp->sf_tsize),
1206 EXTRACT_32BITS(&sfsp->sf_bsize),
1207 EXTRACT_32BITS(&sfsp->sf_blocks),
1208 EXTRACT_32BITS(&sfsp->sf_bfree),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001209 EXTRACT_32BITS(&sfsp->sf_bavail)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001210 }
1211
1212 return (1);
1213trunc:
1214 return (0);
1215}
1216
1217static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001218parserddires(netdissect_options *ndo,
1219 const uint32_t *dp)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001220{
1221 int er;
1222
Elliott Hughes892a68b2015-10-19 14:43:53 -07001223 dp = parsestatus(ndo, dp, &er);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001224 if (dp == NULL)
1225 return (0);
1226 if (er)
1227 return (1);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001228 if (ndo->ndo_qflag)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001229 return (1);
1230
Elliott Hughes892a68b2015-10-19 14:43:53 -07001231 ND_TCHECK(dp[2]);
1232 ND_PRINT((ndo, " offset 0x%x size %d ",
1233 EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1])));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001234 if (dp[2] != 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001235 ND_PRINT((ndo, " eof"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001236
1237 return (1);
1238trunc:
1239 return (0);
1240}
1241
Elliott Hughes892a68b2015-10-19 14:43:53 -07001242static const uint32_t *
1243parse_wcc_attr(netdissect_options *ndo,
1244 const uint32_t *dp)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001245{
Elliott Hughes892a68b2015-10-19 14:43:53 -07001246 ND_PRINT((ndo, " sz %" PRIu64, EXTRACT_64BITS(&dp[0])));
1247 ND_PRINT((ndo, " mtime %u.%06u ctime %u.%06u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001248 EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001249 EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5])));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001250 return (dp + 6);
1251}
1252
1253/*
1254 * Pre operation attributes. Print only if vflag > 1.
1255 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001256static const uint32_t *
1257parse_pre_op_attr(netdissect_options *ndo,
1258 const uint32_t *dp, int verbose)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001259{
Elliott Hughes892a68b2015-10-19 14:43:53 -07001260 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001261 if (!EXTRACT_32BITS(&dp[0]))
1262 return (dp + 1);
1263 dp++;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001264 ND_TCHECK2(*dp, 24);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001265 if (verbose > 1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001266 return parse_wcc_attr(ndo, dp);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001267 } else {
1268 /* If not verbose enough, just skip over wcc_attr */
1269 return (dp + 6);
1270 }
1271trunc:
1272 return (NULL);
1273}
1274
1275/*
1276 * Post operation attributes are printed if vflag >= 1
1277 */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001278static const uint32_t *
1279parse_post_op_attr(netdissect_options *ndo,
1280 const uint32_t *dp, int verbose)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001281{
Elliott Hughes892a68b2015-10-19 14:43:53 -07001282 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001283 if (!EXTRACT_32BITS(&dp[0]))
1284 return (dp + 1);
1285 dp++;
1286 if (verbose) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001287 return parsefattr(ndo, dp, verbose, 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001288 } else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001289 return (dp + (NFSX_V3FATTR / sizeof (uint32_t)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001290trunc:
1291 return (NULL);
1292}
1293
Elliott Hughes892a68b2015-10-19 14:43:53 -07001294static const uint32_t *
1295parse_wcc_data(netdissect_options *ndo,
1296 const uint32_t *dp, int verbose)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001297{
1298 if (verbose > 1)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001299 ND_PRINT((ndo, " PRE:"));
1300 if (!(dp = parse_pre_op_attr(ndo, dp, verbose)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001301 return (0);
1302
1303 if (verbose)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001304 ND_PRINT((ndo, " POST:"));
1305 return parse_post_op_attr(ndo, dp, verbose);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001306}
1307
Elliott Hughes892a68b2015-10-19 14:43:53 -07001308static const uint32_t *
1309parsecreateopres(netdissect_options *ndo,
1310 const uint32_t *dp, int verbose)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001311{
1312 int er;
1313
Elliott Hughes892a68b2015-10-19 14:43:53 -07001314 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001315 return (0);
1316 if (er)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001317 dp = parse_wcc_data(ndo, dp, verbose);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001318 else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001319 ND_TCHECK(dp[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001320 if (!EXTRACT_32BITS(&dp[0]))
1321 return (dp + 1);
1322 dp++;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001323 if (!(dp = parsefh(ndo, dp, 1)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001324 return (0);
1325 if (verbose) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001326 if (!(dp = parse_post_op_attr(ndo, dp, verbose)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001327 return (0);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001328 if (ndo->ndo_vflag > 1) {
1329 ND_PRINT((ndo, " dir attr:"));
1330 dp = parse_wcc_data(ndo, dp, verbose);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001331 }
1332 }
1333 }
1334 return (dp);
1335trunc:
1336 return (NULL);
1337}
1338
1339static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001340parsewccres(netdissect_options *ndo,
1341 const uint32_t *dp, int verbose)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001342{
1343 int er;
1344
Elliott Hughes892a68b2015-10-19 14:43:53 -07001345 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001346 return (0);
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001347 return parse_wcc_data(ndo, dp, verbose) != NULL;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001348}
1349
Elliott Hughes892a68b2015-10-19 14:43:53 -07001350static const uint32_t *
1351parsev3rddirres(netdissect_options *ndo,
1352 const uint32_t *dp, int verbose)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001353{
1354 int er;
1355
Elliott Hughes892a68b2015-10-19 14:43:53 -07001356 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001357 return (0);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001358 if (ndo->ndo_vflag)
1359 ND_PRINT((ndo, " POST:"));
1360 if (!(dp = parse_post_op_attr(ndo, dp, verbose)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001361 return (0);
1362 if (er)
1363 return dp;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001364 if (ndo->ndo_vflag) {
1365 ND_TCHECK(dp[1]);
1366 ND_PRINT((ndo, " verf %08x%08x", dp[0], dp[1]));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001367 dp += 2;
1368 }
1369 return dp;
1370trunc:
1371 return (NULL);
1372}
1373
1374static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001375parsefsinfo(netdissect_options *ndo,
1376 const uint32_t *dp)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001377{
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001378 const struct nfsv3_fsinfo *sfp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001379 int er;
1380
Elliott Hughes892a68b2015-10-19 14:43:53 -07001381 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001382 return (0);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001383 if (ndo->ndo_vflag)
1384 ND_PRINT((ndo, " POST:"));
1385 if (!(dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001386 return (0);
1387 if (er)
1388 return (1);
1389
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001390 sfp = (const struct nfsv3_fsinfo *)dp;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001391 ND_TCHECK(*sfp);
1392 ND_PRINT((ndo, " rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001393 EXTRACT_32BITS(&sfp->fs_rtmax),
1394 EXTRACT_32BITS(&sfp->fs_rtpref),
1395 EXTRACT_32BITS(&sfp->fs_wtmax),
1396 EXTRACT_32BITS(&sfp->fs_wtpref),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001397 EXTRACT_32BITS(&sfp->fs_dtpref)));
1398 if (ndo->ndo_vflag) {
1399 ND_PRINT((ndo, " rtmult %u wtmult %u maxfsz %" PRIu64,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001400 EXTRACT_32BITS(&sfp->fs_rtmult),
1401 EXTRACT_32BITS(&sfp->fs_wtmult),
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001402 EXTRACT_64BITS((const uint32_t *)&sfp->fs_maxfilesize)));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001403 ND_PRINT((ndo, " delta %u.%06u ",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001404 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
Elliott Hughes892a68b2015-10-19 14:43:53 -07001405 EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001406 }
1407 return (1);
1408trunc:
1409 return (0);
1410}
1411
1412static int
Elliott Hughes892a68b2015-10-19 14:43:53 -07001413parsepathconf(netdissect_options *ndo,
1414 const uint32_t *dp)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001415{
1416 int er;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001417 const struct nfsv3_pathconf *spp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001418
Elliott Hughes892a68b2015-10-19 14:43:53 -07001419 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001420 return (0);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001421 if (ndo->ndo_vflag)
1422 ND_PRINT((ndo, " POST:"));
1423 if (!(dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001424 return (0);
1425 if (er)
1426 return (1);
1427
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001428 spp = (const struct nfsv3_pathconf *)dp;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001429 ND_TCHECK(*spp);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001430
Elliott Hughes892a68b2015-10-19 14:43:53 -07001431 ND_PRINT((ndo, " linkmax %u namemax %u %s %s %s %s",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001432 EXTRACT_32BITS(&spp->pc_linkmax),
1433 EXTRACT_32BITS(&spp->pc_namemax),
1434 EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
1435 EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
1436 EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
Elliott Hughes892a68b2015-10-19 14:43:53 -07001437 EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001438 return (1);
1439trunc:
1440 return (0);
1441}
1442
1443static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001444interp_reply(netdissect_options *ndo,
1445 const struct sunrpc_msg *rp, uint32_t proc, uint32_t vers, int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001446{
Elliott Hughes892a68b2015-10-19 14:43:53 -07001447 register const uint32_t *dp;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001448 register int v3;
1449 int er;
1450
1451 v3 = (vers == NFS_VER3);
1452
1453 if (!v3 && proc < NFS_NPROCS)
1454 proc = nfsv3_procid[proc];
1455
Elliott Hughes892a68b2015-10-19 14:43:53 -07001456 ND_PRINT((ndo, " %s", tok2str(nfsproc_str, "proc-%u", proc)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001457 switch (proc) {
1458
The Android Open Source Project2949f582009-03-03 19:30:46 -08001459 case NFSPROC_GETATTR:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001460 dp = parserep(ndo, rp, length);
1461 if (dp != NULL && parseattrstat(ndo, dp, !ndo->ndo_qflag, v3) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001462 return;
1463 break;
1464
1465 case NFSPROC_SETATTR:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001466 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001467 return;
1468 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001469 if (parsewccres(ndo, dp, ndo->ndo_vflag))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001470 return;
1471 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001472 if (parseattrstat(ndo, dp, !ndo->ndo_qflag, 0) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001473 return;
1474 }
1475 break;
1476
1477 case NFSPROC_LOOKUP:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001478 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001479 break;
1480 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001481 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001482 break;
1483 if (er) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001484 if (ndo->ndo_vflag > 1) {
1485 ND_PRINT((ndo, " post dattr:"));
1486 dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001487 }
1488 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001489 if (!(dp = parsefh(ndo, dp, v3)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001490 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001491 if ((dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag)) &&
1492 ndo->ndo_vflag > 1) {
1493 ND_PRINT((ndo, " post dattr:"));
1494 dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001495 }
1496 }
1497 if (dp)
1498 return;
1499 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001500 if (parsediropres(ndo, dp) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001501 return;
1502 }
1503 break;
1504
1505 case NFSPROC_ACCESS:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001506 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001507 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001508 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001509 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001510 if (ndo->ndo_vflag)
1511 ND_PRINT((ndo, " attr:"));
1512 if (!(dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001513 break;
1514 if (!er)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001515 ND_PRINT((ndo, " c %04x", EXTRACT_32BITS(&dp[0])));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001516 return;
1517
1518 case NFSPROC_READLINK:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001519 dp = parserep(ndo, rp, length);
1520 if (dp != NULL && parselinkres(ndo, dp, v3) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001521 return;
1522 break;
1523
1524 case NFSPROC_READ:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001525 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001526 break;
1527 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001528 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001529 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001530 if (!(dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001531 break;
1532 if (er)
1533 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001534 if (ndo->ndo_vflag) {
1535 ND_TCHECK(dp[1]);
1536 ND_PRINT((ndo, " %u bytes", EXTRACT_32BITS(&dp[0])));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001537 if (EXTRACT_32BITS(&dp[1]))
Elliott Hughes892a68b2015-10-19 14:43:53 -07001538 ND_PRINT((ndo, " EOF"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001539 }
1540 return;
1541 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001542 if (parseattrstat(ndo, dp, ndo->ndo_vflag, 0) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001543 return;
1544 }
1545 break;
1546
1547 case NFSPROC_WRITE:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001548 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001549 break;
1550 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001551 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001552 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001553 if (!(dp = parse_wcc_data(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001554 break;
1555 if (er)
1556 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001557 if (ndo->ndo_vflag) {
1558 ND_TCHECK(dp[0]);
1559 ND_PRINT((ndo, " %u bytes", EXTRACT_32BITS(&dp[0])));
1560 if (ndo->ndo_vflag > 1) {
1561 ND_TCHECK(dp[1]);
1562 ND_PRINT((ndo, " <%s>",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001563 tok2str(nfsv3_writemodes,
Elliott Hughes892a68b2015-10-19 14:43:53 -07001564 NULL, EXTRACT_32BITS(&dp[1]))));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001565 }
1566 return;
1567 }
1568 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001569 if (parseattrstat(ndo, dp, ndo->ndo_vflag, v3) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001570 return;
1571 }
1572 break;
1573
1574 case NFSPROC_CREATE:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001575 case NFSPROC_MKDIR:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001576 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001577 break;
1578 if (v3) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001579 if (parsecreateopres(ndo, dp, ndo->ndo_vflag) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001580 return;
1581 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001582 if (parsediropres(ndo, dp) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001583 return;
1584 }
1585 break;
1586
1587 case NFSPROC_SYMLINK:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001588 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001589 break;
1590 if (v3) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001591 if (parsecreateopres(ndo, dp, ndo->ndo_vflag) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001592 return;
1593 } else {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001594 if (parsestatus(ndo, dp, &er) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001595 return;
1596 }
1597 break;
1598
1599 case NFSPROC_MKNOD:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001600 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001601 break;
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001602 if (parsecreateopres(ndo, dp, ndo->ndo_vflag) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001603 return;
1604 break;
1605
1606 case NFSPROC_REMOVE:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001607 case NFSPROC_RMDIR:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001608 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001609 break;
1610 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001611 if (parsewccres(ndo, dp, ndo->ndo_vflag))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001612 return;
1613 } else {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001614 if (parsestatus(ndo, dp, &er) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001615 return;
1616 }
1617 break;
1618
1619 case NFSPROC_RENAME:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001620 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001621 break;
1622 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001623 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001624 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001625 if (ndo->ndo_vflag) {
1626 ND_PRINT((ndo, " from:"));
1627 if (!(dp = parse_wcc_data(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001628 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001629 ND_PRINT((ndo, " to:"));
1630 if (!(dp = parse_wcc_data(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001631 break;
1632 }
1633 return;
1634 } else {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001635 if (parsestatus(ndo, dp, &er) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001636 return;
1637 }
1638 break;
1639
1640 case NFSPROC_LINK:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001641 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001642 break;
1643 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001644 if (!(dp = parsestatus(ndo, dp, &er)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001645 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001646 if (ndo->ndo_vflag) {
1647 ND_PRINT((ndo, " file POST:"));
1648 if (!(dp = parse_post_op_attr(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001649 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001650 ND_PRINT((ndo, " dir:"));
1651 if (!(dp = parse_wcc_data(ndo, dp, ndo->ndo_vflag)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001652 break;
1653 return;
1654 }
1655 } else {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001656 if (parsestatus(ndo, dp, &er) != NULL)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001657 return;
1658 }
1659 break;
1660
1661 case NFSPROC_READDIR:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001662 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001663 break;
1664 if (v3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001665 if (parsev3rddirres(ndo, dp, ndo->ndo_vflag))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001666 return;
1667 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001668 if (parserddires(ndo, dp) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001669 return;
1670 }
1671 break;
1672
1673 case NFSPROC_READDIRPLUS:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001674 if (!(dp = parserep(ndo, rp, length)))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001675 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001676 if (parsev3rddirres(ndo, dp, ndo->ndo_vflag))
The Android Open Source Project2949f582009-03-03 19:30:46 -08001677 return;
1678 break;
1679
1680 case NFSPROC_FSSTAT:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001681 dp = parserep(ndo, rp, length);
1682 if (dp != NULL && parsestatfs(ndo, dp, v3) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001683 return;
1684 break;
1685
1686 case NFSPROC_FSINFO:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001687 dp = parserep(ndo, rp, length);
1688 if (dp != NULL && parsefsinfo(ndo, dp) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001689 return;
1690 break;
1691
1692 case NFSPROC_PATHCONF:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001693 dp = parserep(ndo, rp, length);
1694 if (dp != NULL && parsepathconf(ndo, dp) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001695 return;
1696 break;
1697
1698 case NFSPROC_COMMIT:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001699 dp = parserep(ndo, rp, length);
1700 if (dp != NULL && parsewccres(ndo, dp, ndo->ndo_vflag) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001701 return;
1702 break;
1703
1704 default:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001705 return;
1706 }
1707trunc:
1708 if (!nfserr)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001709 ND_PRINT((ndo, "%s", tstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001710}