]>
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"
53 #include "netdissect-ctype.h"
55 #include "netdissect.h"
60 * This routine attempts to parse a file handle (in network byte order),
61 * using heuristics to guess what kind of format it is in. See the
62 * file "fhandle_layouts" for a detailed description of the various
63 * patterns we know about.
65 * The file handle is parsed into our internal representation of a
66 * file-system id, and an internal representation of an inode-number.
83 static int is_UCX(netdissect_options
*, const unsigned char *, u_int
);
86 Parse_fh(netdissect_options
*ndo
, const unsigned char *fh
, u_int len
,
87 my_fsid
*fsidp
, uint32_t *inop
,
88 const char **osnamep
, /* if non-NULL, return OS name here */
89 const char **fsnamep
, /* if non-NULL, return server fs name here (for VMS) */
90 int ourself
) /* true if file handle was generated on this host */
92 const unsigned char *fhp
= fh
;
94 int fhtype
= FHT_UNKNOWN
;
98 * Require at least 16 bytes of file handle; it's variable-length
99 * in NFSv3. "len" is in units of 32-bit words, not bytes.
102 fhtype
= FHT_UNKNOWN
;
105 /* File handle generated on this host, no need for guessing */
127 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \
128 || defined(__OpenBSD__)
133 * This is basically a big decision tree
135 else if ((GET_U_1(fhp
) == 0) && (GET_U_1(fhp
+ 1) == 0)) {
136 /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
137 /* probably rules out HP-UX, AIX unless they allow major=0 */
138 if ((GET_U_1(fhp
+ 2) == 0) && (GET_U_1(fhp
+ 3) == 0)) {
139 /* bytes[2,3] == (0,0); must be Auspex */
140 /* XXX or could be Ultrix+MASSBUS "hp" disk? */
144 * bytes[2,3] != (0,0); rules out Auspex, could be
145 * DECOSF, SUNOS4, or IRIX4
147 if ((GET_U_1(fhp
+ 4) != 0) && (GET_U_1(fhp
+ 5) == 0) &&
148 (GET_U_1(fhp
+ 8) == 12) && (GET_U_1(fhp
+ 9) == 0)) {
149 /* seems to be DECOSF, with minor == 0 */
152 /* could be SUNOS4 or IRIX4 */
153 /* XXX the test of fhp[5] == 8 could be wrong */
154 if ((GET_U_1(fhp
+ 4) == 0) && (GET_U_1(fhp
+ 5) == 8) && (GET_U_1(fhp
+ 6) == 0) &&
155 (GET_U_1(fhp
+ 7) == 0)) {
156 /* looks like a length, not a file system typecode */
166 * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
167 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
168 * could be AIX, HP-UX
170 if ((GET_U_1(fhp
+ 2) == 0) && (GET_U_1(fhp
+ 3) == 0)) {
172 * bytes[2,3] == (0,0); rules out OSF, probably not UCX
173 * (unless the exported device name is just one letter!),
174 * could be Ultrix, IRIX5, AIX, or SUNOS5
175 * might be HP-UX (depends on their values for minor devs)
177 if ((GET_U_1(fhp
+ 6) == 0) && (GET_U_1(fhp
+ 7) == 0)) {
180 /*XXX we probably only need to test of these two bytes */
181 else if ((len
>= 24/4) && (GET_U_1(fhp
+ 21) == 0) && (GET_U_1(fhp
+ 23) == 0)) {
184 /* Could be SUNOS5/IRIX5, maybe AIX */
185 /* XXX no obvious difference between SUNOS5 and IRIX5 */
186 if (GET_U_1(fhp
+ 9) == 10)
188 /* XXX what about AIX? */
192 * bytes[2,3] != (0,0); rules out Ultrix, could be
193 * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
195 if ((GET_U_1(fhp
+ 8) == 12) && (GET_U_1(fhp
+ 9) == 0)) {
197 } else if ((GET_U_1(fhp
+ 8) == 0) && (GET_U_1(fhp
+ 9) == 10)) {
198 /* could be SUNOS5/IRIX5, AIX, HP-UX */
199 if ((GET_U_1(fhp
+ 7) == 0) && (GET_U_1(fhp
+ 6) == 0) &&
200 (GET_U_1(fhp
+ 5) == 0) && (GET_U_1(fhp
+ 4) == 0)) {
201 /* XXX is this always true of HP-UX? */
203 } else if (GET_U_1(fhp
+ 7) == 2) {
204 /* This would be MNT_NFS on AIX, which is impossible */
205 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
208 * XXX Could be SUNOS5/IRIX5 or AIX. I don't
209 * XXX see any way to disambiguate these, so
210 * XXX I'm going with the more likely guess.
211 * XXX Sorry, Big Blue.
213 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
216 if (is_UCX(ndo
, fhp
, len
)) {
219 fhtype
= FHT_UNKNOWN
;
226 /* XXX still needs to handle SUNOS3 */
230 fsidp
->Fsid_dev
.Minor
= GET_U_1(fhp
+ 7);
231 fsidp
->Fsid_dev
.Major
= GET_U_1(fhp
+ 6);
232 fsidp
->fsid_code
= 0;
234 *inop
= GET_BE_U_4(fhp
+ 12);
241 fsidp
->Fsid_dev
.Minor
= GET_U_1(fhp
);
242 fsidp
->Fsid_dev
.Major
= GET_U_1(fhp
+ 1);
243 fsidp
->fsid_code
= 0;
245 *inop
= GET_LE_U_4(fhp
+ 12);
248 *osnamep
= "BSD 4.4";
252 fsidp
->fsid_code
= GET_LE_U_4(fhp
+ 4);
253 /* XXX could ignore 3 high-order bytes */
255 temp
= GET_LE_U_4(fhp
);
256 fsidp
->Fsid_dev
.Minor
= temp
& 0xFFFFF;
257 fsidp
->Fsid_dev
.Major
= (temp
>>20) & 0xFFF;
259 *inop
= GET_LE_U_4(fhp
+ 12);
265 fsidp
->Fsid_dev
.Minor
= GET_U_1(fhp
+ 3);
266 fsidp
->Fsid_dev
.Major
= GET_U_1(fhp
+ 2);
267 fsidp
->fsid_code
= 0;
269 *inop
= GET_BE_U_4(fhp
+ 8);
276 fsidp
->Fsid_dev
.Minor
= GET_BE_U_2(fhp
+ 2);
277 fsidp
->Fsid_dev
.Major
= GET_BE_U_2(fhp
);
278 fsidp
->fsid_code
= GET_BE_U_4(fhp
+ 4);
280 *inop
= GET_BE_U_4(fhp
+ 12);
289 * XXX - none of the heuristics above return this.
290 * Are there any SunOS 3.x systems around to care about?
298 fsidp
->Fsid_dev
.Minor
= GET_U_1(fhp
+ 3);
299 fsidp
->Fsid_dev
.Major
= GET_U_1(fhp
+ 2);
300 fsidp
->fsid_code
= GET_BE_U_4(fhp
+ 4);
302 *inop
= GET_BE_U_4(fhp
+ 12);
309 temp
= GET_BE_U_2(fhp
);
310 fsidp
->Fsid_dev
.Major
= (temp
>>2) & 0x3FFF;
311 temp
= GET_BE_U_3(fhp
+ 1);
312 fsidp
->Fsid_dev
.Minor
= temp
& 0x3FFFF;
313 fsidp
->fsid_code
= GET_BE_U_4(fhp
+ 4);
315 *inop
= GET_BE_U_4(fhp
+ 12);
322 fsidp
->fsid_code
= 0;
323 fsidp
->Fsid_dev
.Minor
= GET_U_1(fhp
);
324 fsidp
->Fsid_dev
.Major
= GET_U_1(fhp
+ 1);
326 temp
= GET_LE_U_4(fhp
+ 4);
333 /* No numeric file system ID, so hash on the device-name */
334 if (sizeof(*fsidp
) >= 14) {
335 if (sizeof(*fsidp
) > 14)
336 memset((char *)fsidp
, 0, sizeof(*fsidp
));
337 /* just use the whole thing */
338 memcpy((char *)fsidp
, (const char *)fh
, 14);
340 uint32_t tempa
[4]; /* at least 16 bytes, maybe more */
342 memset((char *)tempa
, 0, sizeof(tempa
));
343 memcpy((char *)tempa
, (const char *)fh
, 14); /* ensure alignment */
344 fsidp
->Fsid_dev
.Minor
= tempa
[0] + (tempa
[1]<<1);
345 fsidp
->Fsid_dev
.Major
= tempa
[2] + (tempa
[3]<<1);
346 fsidp
->fsid_code
= 0;
349 /* VMS file ID is: (RVN, FidHi, FidLo) */
350 *inop
= (((uint32_t) GET_U_1(fhp
+ 26)) << 24) |
351 (((uint32_t) GET_U_1(fhp
+ 27)) << 16) |
352 (GET_LE_U_2(fhp
+ 22) << 0);
354 /* Caller must save (and null-terminate?) this value */
356 *fsnamep
= (const char *)(fhp
+ 1);
363 fsidp
->Fsid_dev
.Minor
= GET_BE_U_2(fhp
+ 2);
364 fsidp
->Fsid_dev
.Major
= GET_BE_U_2(fhp
);
365 fsidp
->fsid_code
= GET_BE_U_4(fhp
+ 4);
367 *inop
= GET_BE_U_4(fhp
+ 12);
374 fsidp
->Fsid_dev
.Major
= GET_U_1(fhp
);
375 temp
= GET_BE_U_3(fhp
+ 1);
376 fsidp
->Fsid_dev
.Minor
= temp
;
377 fsidp
->fsid_code
= GET_BE_U_4(fhp
+ 4);
379 *inop
= GET_BE_U_4(fhp
+ 12);
388 for (i
= 0; i
< len
*4; i
++)
389 (void)fprintf(stderr
, "%x.", GET_U_1(fhp
+ i
));
390 (void)fprintf(stderr
, "\n");
392 /* Save the actual handle, so it can be display with -u */
393 /* XXX really ? When -u is used this function is not called */
394 for (i
= 0; i
< len
*4 && i
*2 < sizeof(fsidp
->Opaque_Handle
) - 1; i
++)
395 (void)snprintf(&(fsidp
->Opaque_Handle
[i
*2]), 3, "%.2X",
397 fsidp
->Opaque_Handle
[i
*2] = '\0';
399 /* XXX for now, give "bogus" values to aid debugging */
400 fsidp
->fsid_code
= 0;
401 fsidp
->Fsid_dev
.Minor
= UINT_MAX
;
402 fsidp
->Fsid_dev
.Major
= UINT_MAX
;
405 /* display will show this string instead of (UINT_MAX,UINT_MAX) */
408 *fsnamep
= "Unknown";
411 *osnamep
= "Unknown";
418 * Is this a VMS UCX file handle?
420 * (1) leading code byte [XXX not yet]
421 * (2) followed by string of printing chars & spaces
422 * (3) followed by string of nulls
425 is_UCX(netdissect_options
*ndo
, const unsigned char *fhp
, u_int len
)
431 * Require at least 28 bytes of file handle; it's variable-length
432 * in NFSv3. "len" is in units of 32-bit words, not bytes.
437 for (i
= 1; i
< 14; i
++) {
438 if (ND_ASCII_ISPRINT(GET_U_1(fhp
+ i
))) {
443 } else if (GET_U_1(fhp
+ i
) == 0) {