]>
The Tcpdump Group git mirrors - tcpdump/blob - parsenfsfh.c
2 * Copyright (c) 1993, 1994 Jeffrey C. Mogul, Digital Equipment Corporation,
3 * Western Research Laboratory. All rights reserved.
4 * Copyright (c) 2001 Compaq Computer Corporation. All rights reserved.
6 * Permission to use, copy, and modify this software and its
7 * documentation is hereby granted only under the following terms and
8 * conditions. Both the above copyright notice and this permission
9 * notice must appear in all copies of the software, derivative works
10 * or modified versions, and any portions thereof, and both notices
11 * must appear in supporting documentation.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in
20 * the documentation and/or other materials provided with the
23 * THE SOFTWARE IS PROVIDED "AS IS" AND COMPAQ COMPUTER CORPORATION
24 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
25 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
26 * EVENT SHALL COMPAQ COMPUTER CORPORATION BE LIABLE FOR ANY
27 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
28 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
29 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
30 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
35 * parsenfsfh.c - portable parser for NFS file handles
36 * uses all sorts of heuristics
39 * Digital Equipment Corporation
40 * Western Research Laboratory
47 #include "netdissect-stdinc.h"
52 #include "netdissect.h"
57 * This routine attempts to parse a file handle (in network byte order),
58 * using heuristics to guess what kind of format it is in. See the
59 * file "fhandle_layouts" for a detailed description of the various
60 * patterns we know about.
62 * The file handle is parsed into our internal representation of a
63 * file-system id, and an internal representation of an inode-number.
80 static int is_UCX(const unsigned char *, u_int
);
83 Parse_fh(const unsigned char *fh
, u_int len
, my_fsid
*fsidp
,
85 const char **osnamep
, /* if non-NULL, return OS name here */
86 const char **fsnamep
, /* if non-NULL, return server fs name here (for VMS) */
87 int ourself
) /* true if file handle was generated on this host */
89 const unsigned char *fhp
= fh
;
91 int fhtype
= FHT_UNKNOWN
;
95 * Require at least 16 bytes of file handle; it's variable-length
96 * in NFSv3. "len" is in units of 32-bit words, not bytes.
102 /* File handle generated on this host, no need for guessing */
124 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \
125 || defined(__OpenBSD__)
130 * This is basically a big decision tree
132 else if ((EXTRACT_U_1(fhp
) == 0) && (EXTRACT_U_1(fhp
+ 1) == 0)) {
133 /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
134 /* probably rules out HP-UX, AIX unless they allow major=0 */
135 if ((EXTRACT_U_1(fhp
+ 2) == 0) && (EXTRACT_U_1(fhp
+ 3) == 0)) {
136 /* bytes[2,3] == (0,0); must be Auspex */
137 /* XXX or could be Ultrix+MASSBUS "hp" disk? */
142 * bytes[2,3] != (0,0); rules out Auspex, could be
143 * DECOSF, SUNOS4, or IRIX4
145 if ((EXTRACT_U_1(fhp
+ 4) != 0) && (EXTRACT_U_1(fhp
+ 5) == 0) &&
146 (EXTRACT_U_1(fhp
+ 8) == 12) && (EXTRACT_U_1(fhp
+ 9) == 0)) {
147 /* seems to be DECOSF, with minor == 0 */
151 /* could be SUNOS4 or IRIX4 */
152 /* XXX the test of fhp[5] == 8 could be wrong */
153 if ((EXTRACT_U_1(fhp
+ 4) == 0) && (EXTRACT_U_1(fhp
+ 5) == 8) && (EXTRACT_U_1(fhp
+ 6) == 0) &&
154 (EXTRACT_U_1(fhp
+ 7) == 0)) {
155 /* looks like a length, not a file system typecode */
167 * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
168 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
169 * could be AIX, HP-UX
171 if ((EXTRACT_U_1(fhp
+ 2) == 0) && (EXTRACT_U_1(fhp
+ 3) == 0)) {
173 * bytes[2,3] == (0,0); rules out OSF, probably not UCX
174 * (unless the exported device name is just one letter!),
175 * could be Ultrix, IRIX5, AIX, or SUNOS5
176 * might be HP-UX (depends on their values for minor devs)
178 if ((EXTRACT_U_1(fhp
+ 6) == 0) && (EXTRACT_U_1(fhp
+ 7) == 0)) {
181 /*XXX we probably only need to test of these two bytes */
182 else if ((len
>= 24/4) && (EXTRACT_U_1(fhp
+ 21) == 0) && (EXTRACT_U_1(fhp
+ 23) == 0)) {
186 /* Could be SUNOS5/IRIX5, maybe AIX */
187 /* XXX no obvious difference between SUNOS5 and IRIX5 */
188 if (EXTRACT_U_1(fhp
+ 9) == 10)
190 /* XXX what about AIX? */
195 * bytes[2,3] != (0,0); rules out Ultrix, could be
196 * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
198 if ((EXTRACT_U_1(fhp
+ 8) == 12) && (EXTRACT_U_1(fhp
+ 9) == 0)) {
201 else if ((EXTRACT_U_1(fhp
+ 8) == 0) && (EXTRACT_U_1(fhp
+ 9) == 10)) {
202 /* could be SUNOS5/IRIX5, AIX, HP-UX */
203 if ((EXTRACT_U_1(fhp
+ 7) == 0) && (EXTRACT_U_1(fhp
+ 6) == 0) &&
204 (EXTRACT_U_1(fhp
+ 5) == 0) && (EXTRACT_U_1(fhp
+ 4) == 0)) {
205 /* XXX is this always true of HP-UX? */
208 else if (EXTRACT_U_1(fhp
+ 7) == 2) {
209 /* This would be MNT_NFS on AIX, which is impossible */
210 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
214 * XXX Could be SUNOS5/IRIX5 or AIX. I don't
215 * XXX see any way to disambiguate these, so
216 * XXX I'm going with the more likely guess.
217 * XXX Sorry, Big Blue.
219 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
223 if (is_UCX(fhp
, len
)) {
227 fhtype
= FHT_UNKNOWN
;
234 /* XXX still needs to handle SUNOS3 */
238 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
+ 7);
239 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 6);
240 fsidp
->fsid_code
= 0;
242 *inop
= EXTRACT_BE_U_4(fhp
+ 12);
249 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
);
250 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 1);
251 fsidp
->fsid_code
= 0;
253 *inop
= EXTRACT_LE_U_4(fhp
+ 12);
256 *osnamep
= "BSD 4.4";
260 fsidp
->fsid_code
= EXTRACT_LE_U_4(fhp
+ 4);
261 /* XXX could ignore 3 high-order bytes */
263 temp
= EXTRACT_LE_U_4(fhp
);
264 fsidp
->Fsid_dev
.Minor
= temp
& 0xFFFFF;
265 fsidp
->Fsid_dev
.Major
= (temp
>>20) & 0xFFF;
267 *inop
= EXTRACT_LE_U_4(fhp
+ 12);
273 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
+ 3);
274 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 2);
275 fsidp
->fsid_code
= 0;
277 *inop
= EXTRACT_BE_U_4(fhp
+ 8);
284 fsidp
->Fsid_dev
.Minor
= EXTRACT_BE_U_2(fhp
+ 2);
285 fsidp
->Fsid_dev
.Major
= EXTRACT_BE_U_2(fhp
);
286 fsidp
->fsid_code
= EXTRACT_BE_U_4(fhp
+ 4);
288 *inop
= EXTRACT_BE_U_4(fhp
+ 12);
297 * XXX - none of the heuristics above return this.
298 * Are there any SunOS 3.x systems around to care about?
306 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
+ 3);
307 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 2);
308 fsidp
->fsid_code
= EXTRACT_BE_U_4(fhp
+ 4);
310 *inop
= EXTRACT_BE_U_4(fhp
+ 12);
317 temp
= EXTRACT_BE_U_2(fhp
);
318 fsidp
->Fsid_dev
.Major
= (temp
>>2) & 0x3FFF;
319 temp
= EXTRACT_BE_U_3(fhp
+ 1);
320 fsidp
->Fsid_dev
.Minor
= temp
& 0x3FFFF;
321 fsidp
->fsid_code
= EXTRACT_BE_U_4(fhp
+ 4);
323 *inop
= EXTRACT_BE_U_4(fhp
+ 12);
330 fsidp
->fsid_code
= 0;
331 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
);
332 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 1);
334 temp
= EXTRACT_LE_U_4(fhp
+ 4);
341 /* No numeric file system ID, so hash on the device-name */
342 if (sizeof(*fsidp
) >= 14) {
343 if (sizeof(*fsidp
) > 14)
344 memset((char *)fsidp
, 0, sizeof(*fsidp
));
345 /* just use the whole thing */
346 memcpy((char *)fsidp
, (const char *)fh
, 14);
349 uint32_t tempa
[4]; /* at least 16 bytes, maybe more */
351 memset((char *)tempa
, 0, sizeof(tempa
));
352 memcpy((char *)tempa
, (const char *)fh
, 14); /* ensure alignment */
353 fsidp
->Fsid_dev
.Minor
= tempa
[0] + (tempa
[1]<<1);
354 fsidp
->Fsid_dev
.Major
= tempa
[2] + (tempa
[3]<<1);
355 fsidp
->fsid_code
= 0;
358 /* VMS file ID is: (RVN, FidHi, FidLo) */
359 *inop
= (((uint32_t)EXTRACT_U_1(fhp
+ 26)) << 24) |
360 (((uint32_t)EXTRACT_U_1(fhp
+ 27)) << 16) |
361 (EXTRACT_LE_U_2(fhp
+ 22) << 0);
363 /* Caller must save (and null-terminate?) this value */
365 *fsnamep
= (const char *)(fhp
+ 1);
372 fsidp
->Fsid_dev
.Minor
= EXTRACT_BE_U_2(fhp
+ 2);
373 fsidp
->Fsid_dev
.Major
= EXTRACT_BE_U_2(fhp
);
374 fsidp
->fsid_code
= EXTRACT_BE_U_4(fhp
+ 4);
376 *inop
= EXTRACT_BE_U_4(fhp
+ 12);
383 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
);
384 temp
= EXTRACT_BE_U_3(fhp
+ 1);
385 fsidp
->Fsid_dev
.Minor
= temp
;
386 fsidp
->fsid_code
= EXTRACT_BE_U_4(fhp
+ 4);
388 *inop
= EXTRACT_BE_U_4(fhp
+ 12);
397 for (i
= 0; i
< len
*4; i
++)
398 (void)fprintf(stderr
, "%x.", EXTRACT_U_1(fhp
+ i
));
399 (void)fprintf(stderr
, "\n");
401 /* Save the actual handle, so it can be display with -u */
402 for (i
= 0; i
< len
*4 && i
*2 < sizeof(fsidp
->Opaque_Handle
) - 1; i
++)
403 (void)nd_snprintf(&(fsidp
->Opaque_Handle
[i
*2]), 3, "%.2X",
404 EXTRACT_U_1(fhp
+ i
));
405 fsidp
->Opaque_Handle
[i
*2] = '\0';
407 /* XXX for now, give "bogus" values to aid debugging */
408 fsidp
->fsid_code
= 0;
409 fsidp
->Fsid_dev
.Minor
= 257;
410 fsidp
->Fsid_dev
.Major
= 257;
413 /* display will show this string instead of (257,257) */
415 *fsnamep
= "Unknown";
418 *osnamep
= "Unknown";
425 * Is this a VMS UCX file handle?
427 * (1) leading code byte [XXX not yet]
428 * (2) followed by string of printing chars & spaces
429 * (3) followed by string of nulls
432 is_UCX(const unsigned char *fhp
, u_int len
)
438 * Require at least 28 bytes of file handle; it's variable-length
439 * in NFSv3. "len" is in units of 32-bit words, not bytes.
444 for (i
= 1; i
< 14; i
++) {
445 if (ND_ISPRINT(EXTRACT_U_1(fhp
+ i
))) {
451 else if (EXTRACT_U_1(fhp
+ i
) == 0) {