]>
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.
81 /* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */
82 #define XFF(x) ((uint32_t)(x))
87 #define make_uint32(msb,b,c,lsb)\
88 (XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24))
90 #define make_uint24(msb,b, lsb)\
91 (XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16))
93 #define make_uint16(msb,lsb)\
94 (XFF(lsb) + (XFF(msb)<<8))
96 static int is_UCX(const unsigned char *, u_int
);
99 Parse_fh(const unsigned char *fh
, u_int len
, my_fsid
*fsidp
,
101 const char **osnamep
, /* if non-NULL, return OS name here */
102 const char **fsnamep
, /* if non-NULL, return server fs name here (for VMS) */
103 int ourself
) /* true if file handle was generated on this host */
105 const unsigned char *fhp
= fh
;
107 int fhtype
= FHT_UNKNOWN
;
111 * Require at least 16 bytes of file handle; it's variable-length
112 * in NFSv3. "len" is in units of 32-bit words, not bytes.
115 fhtype
= FHT_UNKNOWN
;
118 /* File handle generated on this host, no need for guessing */
140 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \
141 || defined(__OpenBSD__)
146 * This is basically a big decision tree
148 else if ((EXTRACT_U_1(fhp
) == 0) && (EXTRACT_U_1(fhp
+ 1) == 0)) {
149 /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
150 /* probably rules out HP-UX, AIX unless they allow major=0 */
151 if ((EXTRACT_U_1(fhp
+ 2) == 0) && (EXTRACT_U_1(fhp
+ 3) == 0)) {
152 /* bytes[2,3] == (0,0); must be Auspex */
153 /* XXX or could be Ultrix+MASSBUS "hp" disk? */
158 * bytes[2,3] != (0,0); rules out Auspex, could be
159 * DECOSF, SUNOS4, or IRIX4
161 if ((EXTRACT_U_1(fhp
+ 4) != 0) && (EXTRACT_U_1(fhp
+ 5) == 0) &&
162 (EXTRACT_U_1(fhp
+ 8) == 12) && (EXTRACT_U_1(fhp
+ 9) == 0)) {
163 /* seems to be DECOSF, with minor == 0 */
167 /* could be SUNOS4 or IRIX4 */
168 /* XXX the test of fhp[5] == 8 could be wrong */
169 if ((EXTRACT_U_1(fhp
+ 4) == 0) && (EXTRACT_U_1(fhp
+ 5) == 8) && (EXTRACT_U_1(fhp
+ 6) == 0) &&
170 (EXTRACT_U_1(fhp
+ 7) == 0)) {
171 /* looks like a length, not a file system typecode */
183 * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
184 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
185 * could be AIX, HP-UX
187 if ((EXTRACT_U_1(fhp
+ 2) == 0) && (EXTRACT_U_1(fhp
+ 3) == 0)) {
189 * bytes[2,3] == (0,0); rules out OSF, probably not UCX
190 * (unless the exported device name is just one letter!),
191 * could be Ultrix, IRIX5, AIX, or SUNOS5
192 * might be HP-UX (depends on their values for minor devs)
194 if ((EXTRACT_U_1(fhp
+ 6) == 0) && (EXTRACT_U_1(fhp
+ 7) == 0)) {
197 /*XXX we probably only need to test of these two bytes */
198 else if ((len
>= 24/4) && (EXTRACT_U_1(fhp
+ 21) == 0) && (EXTRACT_U_1(fhp
+ 23) == 0)) {
202 /* Could be SUNOS5/IRIX5, maybe AIX */
203 /* XXX no obvious difference between SUNOS5 and IRIX5 */
204 if (EXTRACT_U_1(fhp
+ 9) == 10)
206 /* XXX what about AIX? */
211 * bytes[2,3] != (0,0); rules out Ultrix, could be
212 * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
214 if ((EXTRACT_U_1(fhp
+ 8) == 12) && (EXTRACT_U_1(fhp
+ 9) == 0)) {
217 else if ((EXTRACT_U_1(fhp
+ 8) == 0) && (EXTRACT_U_1(fhp
+ 9) == 10)) {
218 /* could be SUNOS5/IRIX5, AIX, HP-UX */
219 if ((EXTRACT_U_1(fhp
+ 7) == 0) && (EXTRACT_U_1(fhp
+ 6) == 0) &&
220 (EXTRACT_U_1(fhp
+ 5) == 0) && (EXTRACT_U_1(fhp
+ 4) == 0)) {
221 /* XXX is this always true of HP-UX? */
224 else if (EXTRACT_U_1(fhp
+ 7) == 2) {
225 /* This would be MNT_NFS on AIX, which is impossible */
226 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
230 * XXX Could be SUNOS5/IRIX5 or AIX. I don't
231 * XXX see any way to disambiguate these, so
232 * XXX I'm going with the more likely guess.
233 * XXX Sorry, Big Blue.
235 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
239 if (is_UCX(fhp
, len
)) {
243 fhtype
= FHT_UNKNOWN
;
250 /* XXX still needs to handle SUNOS3 */
254 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
+ 7);
255 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 6);
256 fsidp
->fsid_code
= 0;
258 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 12), EXTRACT_U_1(fhp
+ 13),
259 EXTRACT_U_1(fhp
+ 14), EXTRACT_U_1(fhp
+ 15));
266 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
);
267 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 1);
268 fsidp
->fsid_code
= 0;
270 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 15), EXTRACT_U_1(fhp
+ 14),
271 EXTRACT_U_1(fhp
+ 13), EXTRACT_U_1(fhp
+ 12));
274 *osnamep
= "BSD 4.4";
278 fsidp
->fsid_code
= make_uint32(EXTRACT_U_1(fhp
+ 7),
279 EXTRACT_U_1(fhp
+ 6),
280 EXTRACT_U_1(fhp
+ 5),
281 EXTRACT_U_1(fhp
+ 4));
282 /* XXX could ignore 3 high-order bytes */
284 temp
= make_uint32(EXTRACT_U_1(fhp
+ 3), EXTRACT_U_1(fhp
+ 2),
285 EXTRACT_U_1(fhp
+ 1), EXTRACT_U_1(fhp
));
286 fsidp
->Fsid_dev
.Minor
= temp
& 0xFFFFF;
287 fsidp
->Fsid_dev
.Major
= (temp
>>20) & 0xFFF;
289 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 15), EXTRACT_U_1(fhp
+ 14),
290 EXTRACT_U_1(fhp
+ 13), EXTRACT_U_1(fhp
+ 12));
296 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
+ 3);
297 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 2);
298 fsidp
->fsid_code
= 0;
300 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 8), EXTRACT_U_1(fhp
+ 9),
301 EXTRACT_U_1(fhp
+ 10), EXTRACT_U_1(fhp
+ 11));
308 fsidp
->Fsid_dev
.Minor
= make_uint16(EXTRACT_U_1(fhp
+ 2),
309 EXTRACT_U_1(fhp
+ 3));
310 fsidp
->Fsid_dev
.Major
= make_uint16(EXTRACT_U_1(fhp
),
311 EXTRACT_U_1(fhp
+ 1));
312 fsidp
->fsid_code
= make_uint32(EXTRACT_U_1(fhp
+ 4),
313 EXTRACT_U_1(fhp
+ 5),
314 EXTRACT_U_1(fhp
+ 6),
315 EXTRACT_U_1(fhp
+ 7));
317 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 12), EXTRACT_U_1(fhp
+ 13),
318 EXTRACT_U_1(fhp
+ 14), EXTRACT_U_1(fhp
+ 15));
327 * XXX - none of the heuristics above return this.
328 * Are there any SunOS 3.x systems around to care about?
336 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
+ 3);
337 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 2);
338 fsidp
->fsid_code
= make_uint32(EXTRACT_U_1(fhp
+ 4),
339 EXTRACT_U_1(fhp
+ 5),
340 EXTRACT_U_1(fhp
+ 6),
341 EXTRACT_U_1(fhp
+ 7));
343 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 12), EXTRACT_U_1(fhp
+ 13),
344 EXTRACT_U_1(fhp
+ 14), EXTRACT_U_1(fhp
+ 15));
351 temp
= make_uint16(EXTRACT_U_1(fhp
), EXTRACT_U_1(fhp
+ 1));
352 fsidp
->Fsid_dev
.Major
= (temp
>>2) & 0x3FFF;
353 temp
= make_uint24(EXTRACT_U_1(fhp
+ 1), EXTRACT_U_1(fhp
+ 2),
354 EXTRACT_U_1(fhp
+ 3));
355 fsidp
->Fsid_dev
.Minor
= temp
& 0x3FFFF;
356 fsidp
->fsid_code
= make_uint32(EXTRACT_U_1(fhp
+ 4),
357 EXTRACT_U_1(fhp
+ 5),
358 EXTRACT_U_1(fhp
+ 6),
359 EXTRACT_U_1(fhp
+ 7));
361 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 12), EXTRACT_U_1(fhp
+ 13),
362 EXTRACT_U_1(fhp
+ 14), EXTRACT_U_1(fhp
+ 15));
369 fsidp
->fsid_code
= 0;
370 fsidp
->Fsid_dev
.Minor
= EXTRACT_U_1(fhp
);
371 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
+ 1);
373 temp
= make_uint32(EXTRACT_U_1(fhp
+ 7), EXTRACT_U_1(fhp
+ 6),
374 EXTRACT_U_1(fhp
+ 5), EXTRACT_U_1(fhp
+ 4));
381 /* No numeric file system ID, so hash on the device-name */
382 if (sizeof(*fsidp
) >= 14) {
383 if (sizeof(*fsidp
) > 14)
384 memset((char *)fsidp
, 0, sizeof(*fsidp
));
385 /* just use the whole thing */
386 memcpy((char *)fsidp
, (const char *)fh
, 14);
389 uint32_t tempa
[4]; /* at least 16 bytes, maybe more */
391 memset((char *)tempa
, 0, sizeof(tempa
));
392 memcpy((char *)tempa
, (const char *)fh
, 14); /* ensure alignment */
393 fsidp
->Fsid_dev
.Minor
= tempa
[0] + (tempa
[1]<<1);
394 fsidp
->Fsid_dev
.Major
= tempa
[2] + (tempa
[3]<<1);
395 fsidp
->fsid_code
= 0;
398 /* VMS file ID is: (RVN, FidHi, FidLo) */
399 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 26), EXTRACT_U_1(fhp
+ 27),
400 EXTRACT_U_1(fhp
+ 23), EXTRACT_U_1(fhp
+ 22));
402 /* Caller must save (and null-terminate?) this value */
404 *fsnamep
= (const char *)(fhp
+ 1);
411 fsidp
->Fsid_dev
.Minor
= make_uint16(EXTRACT_U_1(fhp
+ 2),
412 EXTRACT_U_1(fhp
+ 3));
413 fsidp
->Fsid_dev
.Major
= make_uint16(EXTRACT_U_1(fhp
),
414 EXTRACT_U_1(fhp
+ 1));
415 fsidp
->fsid_code
= make_uint32(EXTRACT_U_1(fhp
+ 4),
416 EXTRACT_U_1(fhp
+ 5),
417 EXTRACT_U_1(fhp
+ 6),
418 EXTRACT_U_1(fhp
+ 7));
420 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 12), EXTRACT_U_1(fhp
+ 13),
421 EXTRACT_U_1(fhp
+ 14), EXTRACT_U_1(fhp
+ 15));
428 fsidp
->Fsid_dev
.Major
= EXTRACT_U_1(fhp
);
429 temp
= make_uint24(EXTRACT_U_1(fhp
+ 1), EXTRACT_U_1(fhp
+ 2),
430 EXTRACT_U_1(fhp
+ 3));
431 fsidp
->Fsid_dev
.Minor
= temp
;
432 fsidp
->fsid_code
= make_uint32(EXTRACT_U_1(fhp
+ 4),
433 EXTRACT_U_1(fhp
+ 5),
434 EXTRACT_U_1(fhp
+ 6),
435 EXTRACT_U_1(fhp
+ 7));
437 *inop
= make_uint32(EXTRACT_U_1(fhp
+ 12), EXTRACT_U_1(fhp
+ 13),
438 EXTRACT_U_1(fhp
+ 14), EXTRACT_U_1(fhp
+ 15));
447 for (i
= 0; i
< len
*4; i
++)
448 (void)fprintf(stderr
, "%x.", EXTRACT_U_1(fhp
+ i
));
449 (void)fprintf(stderr
, "\n");
451 /* Save the actual handle, so it can be display with -u */
452 for (i
= 0; i
< len
*4 && i
*2 < sizeof(fsidp
->Opaque_Handle
) - 1; i
++)
453 (void)nd_snprintf(&(fsidp
->Opaque_Handle
[i
*2]), 3, "%.2X",
454 EXTRACT_U_1(fhp
+ i
));
455 fsidp
->Opaque_Handle
[i
*2] = '\0';
457 /* XXX for now, give "bogus" values to aid debugging */
458 fsidp
->fsid_code
= 0;
459 fsidp
->Fsid_dev
.Minor
= 257;
460 fsidp
->Fsid_dev
.Major
= 257;
463 /* display will show this string instead of (257,257) */
465 *fsnamep
= "Unknown";
468 *osnamep
= "Unknown";
475 * Is this a VMS UCX file handle?
477 * (1) leading code byte [XXX not yet]
478 * (2) followed by string of printing chars & spaces
479 * (3) followed by string of nulls
482 is_UCX(const unsigned char *fhp
, u_int len
)
488 * Require at least 28 bytes of file handle; it's variable-length
489 * in NFSv3. "len" is in units of 32-bit words, not bytes.
494 for (i
= 1; i
< 14; i
++) {
495 if (ND_ISPRINT(EXTRACT_U_1(fhp
+ i
))) {
501 else if (EXTRACT_U_1(fhp
+ i
) == 0) {