Coverage Report

Created: 2026-05-14 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-hdfs.c
Line
Count
Source
1
/* packet-hdfs.c
2
 * HDFS Protocol and dissectors
3
 *
4
 * Copyright (c) 2011 by Isilon Systems.
5
 *
6
 * Author: Allison Obourn <aobourn@isilon.com>
7
 *
8
 * Wireshark - Network traffic analyzer
9
 * By Gerald Combs <gerald@wireshark.org>
10
 * Copyright 1999 Gerald Combs
11
 *
12
 * SPDX-License-Identifier: GPL-2.0-or-later
13
 */
14
15
16
#include "config.h"
17
18
#include <epan/packet.h>
19
#include <epan/prefs.h>
20
#include "packet-tcp.h"
21
22
void proto_register_hdfs(void);
23
void proto_reg_handoff_hdfs(void);
24
25
#if 0
26
#define NAMENODE_PORT 8020
27
#endif
28
29
0
#define REQUEST_STR "hrpc"
30
31
0
#define SEND_DEC 1936027236
32
0
#define SEND_OFFSET 13
33
0
#define HEAR_DEC 1214603634
34
0
#define HEAR_OFFSET 9
35
0
#define TBEA_DEC 1952605537
36
0
#define TBEA_OFFSET 5
37
0
#define T_DEC 116
38
0
#define T_OFFSET 1
39
40
#define FIRST_READ_FRAGMENT_LEN 15
41
#define SECOND_READ_FRAGMENT_LEN 29
42
43
44
#if 0
45
static const int START;
46
static const int AUTHENTICATION = 1;
47
static const int DATA = 2;
48
#endif
49
50
static range_t *tcp_ports;
51
52
static int proto_hdfs;
53
static int hf_hdfs_pdu_type;
54
static int hf_hdfs_flags;
55
static int hf_hdfs_sequenceno;
56
static int hf_hdfs_packetno;
57
static int hf_hdfs_authlen;
58
static int hf_hdfs_success;
59
static int hf_hdfs_auth;
60
static int hf_hdfs_len;
61
static int hf_hdfs_strcall;
62
static int hf_hdfs_params;
63
static int hf_hdfs_paramtype;
64
static int hf_hdfs_paramval;
65
static int hf_hdfs_paramvalnum;
66
/* static int hf_hdfs_rest; */
67
static int hf_hdfs_fileperm;
68
static int hf_hdfs_blockloc;
69
static int hf_hdfs_endblockloc;
70
static int hf_hdfs_blockgen;
71
static int hf_hdfs_prover;
72
static int hf_hdfs_objname;
73
static int hf_hdfs_filename;
74
static int hf_hdfs_blockcount;
75
static int hf_hdfs_ownername;
76
static int hf_hdfs_groupname;
77
static int hf_hdfs_namelenone;
78
static int hf_hdfs_namelentwo;
79
static int hf_hdfs_accesstime;
80
static int hf_hdfs_modtime;
81
static int hf_hdfs_blockrep;
82
static int hf_hdfs_isdir;
83
static int hf_hdfs_blocksize;
84
static int hf_hdfs_filelen;
85
static int hf_hdfs_construct;
86
static int hf_hdfs_hostname;
87
static int hf_hdfs_rackloc;
88
static int hf_hdfs_adminstate;
89
static int hf_hdfs_activecon;
90
static int hf_hdfs_lastupdate;
91
static int hf_hdfs_remaining;
92
static int hf_hdfs_dfsused;
93
static int hf_hdfs_capacity;
94
static int hf_hdfs_ipcport;
95
static int hf_hdfs_infoport;
96
static int hf_hdfs_storageid;
97
static int hf_hdfs_datanodeid;
98
static int hf_hdfs_locations;
99
static int hf_hdfs_offset;
100
static int hf_hdfs_corrupt;
101
static int hf_hdfs_identifier;
102
static int hf_hdfs_password;
103
static int hf_hdfs_kind;
104
static int hf_hdfs_service;
105
106
static int ett_hdfs;
107
108
static dissector_handle_t hdfs_handle;
109
110
/* Parses the parameters of a function.
111
   Parses the type length which is always in 2 bytes.
112
   Next the type which is the previously found length.
113
   If this type is variable length it then reads the length of the data
114
   from 2 bytes and then the data.
115
   Otherwise reads just the data. */
116
static void
117
0
dissect_params (tvbuff_t *tvb, proto_tree *hdfs_tree, unsigned offset, unsigned params) {
118
119
0
    unsigned length;
120
0
    unsigned i =  0;
121
0
    const uint8_t* type_name;
122
0
    for (i = 0; i < params; i++) {
123
124
        /* get length that we just dissected */
125
0
        length = tvb_get_ntohs(tvb, offset);
126
127
        /* 2 bytes = parameter type length */
128
0
        proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
129
0
        offset += 2;
130
131
        /* length bytes = parameter type */
132
0
        proto_tree_add_item(hdfs_tree, hf_hdfs_paramtype, tvb, offset, length, ENC_ASCII);
133
0
        offset += length;
134
135
0
        if (offset >= length && (!tvb_memeql(tvb, offset - length, (const uint8_t*)"long", length) || !tvb_memeql(tvb, offset - length, (const uint8_t*)"int", length) ||
136
0
                                 !tvb_memeql(tvb, offset - length, (const uint8_t*)"short", length) || !tvb_memeql(tvb, offset - length, (const uint8_t*)"char", length) ||
137
0
                                 !tvb_memeql(tvb, offset - length, (const uint8_t*)"byte", length) || !tvb_memeql(tvb, offset - length, (const uint8_t*)"float", length)
138
0
                                 || !tvb_memeql(tvb, offset - length, (const uint8_t*)"double", length) || !tvb_memeql(tvb, offset - length, (const uint8_t*)"boolean", length))) {
139
140
0
            if (!tvb_memeql(tvb, offset - length, (const uint8_t*)"boolean", length)) {
141
0
                length = 1;
142
0
            } else if (!tvb_memeql(tvb, offset - length, (const uint8_t*)"short", length)) {
143
0
                length = 2;
144
0
            } else {
145
0
                length = sizeof(type_name);
146
0
            }
147
148
0
            proto_tree_add_item(hdfs_tree, hf_hdfs_paramvalnum, tvb, offset, length, ENC_BIG_ENDIAN);
149
0
            offset += length;
150
151
0
        } else {
152
            /* get length */
153
0
            length = tvb_get_ntohs(tvb, offset);
154
155
            /* 2 bytes = parameter value length */
156
0
            proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
157
0
            offset += 2;
158
159
0
            proto_tree_add_item(hdfs_tree, hf_hdfs_paramval, tvb, offset, length, ENC_ASCII);
160
0
            offset += length;
161
162
0
            if (!tvb_memeql(tvb, offset - length, (const uint8_t*)"org.apache.hadoop.fs.permission.FsPermission", length)) {
163
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_fileperm, tvb, offset, 2, ENC_BIG_ENDIAN);
164
0
                offset += 2;
165
0
            }
166
0
        }
167
0
    }
168
0
}
169
170
171
/* Dissects a data packet of the form:
172
   method name length   : 2B
173
   method name          : above value
174
   number of parameters         : 4B
175
    -- list of parameters the length of above --
176
   parameter type length        : 2B
177
   parameter type               : above value
178
   -- if the type is variable size --
179
   parameter value length       : 2B
180
   parameter value              : above value
181
   -- otherwise --
182
   parameter value      : length of the type  */
183
static void
184
0
dissect_data (tvbuff_t *tvb, proto_tree *hdfs_tree, unsigned offset) {
185
0
    unsigned params = 0;
186
0
    unsigned length = 0;
187
188
    /* get length */
189
0
    length = tvb_get_ntohs(tvb, offset);
190
191
    /* method name length = 2 B */
192
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
193
0
    offset += 2;
194
195
    /* length bytes = method name */
196
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_strcall, tvb, offset, length, ENC_ASCII);
197
0
    offset += length;
198
199
    /* we only want to parse the packet if it is not a heartbeat (random looking numbers are the decimal
200
       representation of sendHeartbeat */
201
0
    if (!(tvb_get_ntohl(tvb, offset - SEND_OFFSET) == SEND_DEC && tvb_get_ntohl(tvb, offset - HEAR_OFFSET) == HEAR_DEC &&
202
0
          tvb_get_ntohl(tvb, offset - TBEA_OFFSET) == TBEA_DEC && tvb_get_uint8(tvb, offset - T_OFFSET) == T_DEC)) {
203
204
        /* 4 bytes = # of parameters */
205
0
        proto_tree_add_item_ret_uint(hdfs_tree, hf_hdfs_params, tvb, offset, 4, ENC_BIG_ENDIAN, &params);
206
0
        offset += 4;
207
208
        /* go through all params and dissect their type length, type, value length and value */
209
0
        dissect_params (tvb, hdfs_tree, offset, params);
210
0
    }
211
0
}
212
213
/*
214
response to a get protocol version message
215
contains a type length, type name and the value
216
*/
217
static int
218
0
dissect_resp_long (tvbuff_t *tvb, proto_tree *hdfs_tree, int offset) {
219
    /* get length that we just dissected */
220
0
    int length = tvb_get_ntohs(tvb, offset);
221
222
    /* 2 bytes = parameter type length */
223
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
224
0
    offset += 2;
225
226
    /* length bytes = parameter type */
227
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_paramtype, tvb, offset, length, ENC_ASCII);
228
0
    offset += length;
229
230
    /* the value */
231
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_prover, tvb, offset, 8, ENC_BIG_ENDIAN);
232
0
    offset += 8;
233
234
0
    return offset;
235
0
}
236
237
/*
238
Response to a file status message
239
*/
240
static int
241
0
dissect_resp_filestatus (tvbuff_t *tvb, proto_tree *hdfs_tree, int offset) {
242
243
0
    int length;
244
245
    /* file status */
246
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_fileperm, tvb, offset, 2, ENC_BIG_ENDIAN);
247
0
    offset += 2;
248
249
    /* get length */
250
0
    length = tvb_get_ntohs(tvb, offset);
251
252
    /* 2 bytes = file name length */
253
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
254
0
    offset += 2;
255
256
    /* file name */
257
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_filename, tvb, offset, length, ENC_ASCII);
258
0
    offset += length;
259
260
261
    /* 8 file size / end location  */
262
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_endblockloc, tvb, offset, 8, ENC_BIG_ENDIAN);
263
0
    offset += 8;
264
265
    /* is directory */
266
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_isdir, tvb, offset, 1, ENC_BIG_ENDIAN);
267
0
    offset += 1;
268
269
    /* block replication factor */
270
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_blockrep, tvb, offset, 2, ENC_BIG_ENDIAN);
271
0
    offset += 2;
272
273
    /* block size */
274
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_blocksize, tvb, offset, 8, ENC_BIG_ENDIAN);
275
0
    offset += 8;
276
277
    /* modified time */
278
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_modtime, tvb, offset, 8, ENC_BIG_ENDIAN);
279
0
    offset += 8;
280
281
    /* access time */
282
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_accesstime, tvb, offset, 8, ENC_BIG_ENDIAN);
283
0
    offset += 8;
284
285
    /* 2 of file permissions */
286
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_fileperm, tvb, offset, 2, ENC_BIG_ENDIAN);
287
0
    offset += 2;
288
289
290
    /* get length */
291
0
    length = tvb_get_uint8 (tvb, offset);
292
293
    /* owner name length */
294
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
295
0
    offset += 1;
296
297
    /* owner name */
298
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_ownername, tvb, offset, length, ENC_ASCII);
299
0
    offset += length;
300
301
    /* get length */
302
0
    length = tvb_get_uint8 (tvb, offset);
303
304
    /* group name length */
305
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
306
0
    offset += 1;
307
308
    /* group name */
309
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_groupname, tvb, offset, length, ENC_ASCII);
310
0
    offset += length;
311
312
0
    return offset;
313
0
}
314
315
316
/*
317
Response to the get block info message
318
parses the sent back information about each blcok
319
*/
320
static int
321
0
dissect_block_info (tvbuff_t *tvb, proto_tree *hdfs_tree, int offset) {
322
323
0
    int length;
324
325
0
    length = tvb_get_uint8(tvb, offset);
326
327
    /* identifier length */
328
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
329
0
    offset += 1;
330
331
    /* identifier */
332
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_identifier, tvb, offset, length, ENC_ASCII);
333
0
    offset += length;
334
335
0
    length = tvb_get_uint8(tvb, offset);
336
337
    /* password length */
338
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
339
0
    offset += 1;
340
341
    /* password */
342
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_password, tvb, offset, length, ENC_ASCII);
343
0
    offset += length;
344
345
0
    length = tvb_get_uint8(tvb, offset);
346
347
    /* kind length */
348
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
349
0
    offset += 1;
350
351
    /* kind */
352
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_kind, tvb, offset, length, ENC_ASCII);
353
0
    offset += length;
354
355
0
    length = tvb_get_uint8(tvb, offset);
356
357
    /* service length */
358
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
359
0
    offset += 1;
360
361
    /* service */
362
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_service, tvb, offset, length, ENC_ASCII);
363
0
    offset += length;
364
365
    /* corrupt */
366
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_corrupt, tvb, offset, 1, ENC_BIG_ENDIAN);
367
0
    offset += 1;
368
369
    /* offset */
370
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_offset, tvb, offset, 8, ENC_BIG_ENDIAN);
371
0
    offset += 8;
372
373
374
    /* block info section */
375
376
    /* block location */
377
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_blockloc, tvb, offset, 8, ENC_BIG_ENDIAN);
378
0
    offset += 8;
379
380
    /* block size */
381
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_blocksize, tvb, offset, 8, ENC_BIG_ENDIAN);
382
0
    offset += 8;
383
384
    /* gen id 8 */
385
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_blockgen, tvb, offset, 8, ENC_BIG_ENDIAN);
386
0
    offset += 8;
387
388
    /* locations */
389
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_locations, tvb, offset, 4, ENC_BIG_ENDIAN);
390
0
    offset += 4;
391
392
393
    /* address section */
394
395
    /* get length */
396
0
    length = tvb_get_ntohs(tvb, offset);
397
398
    /* length of addr */
399
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
400
0
    offset += 2;
401
402
    /* datanode id */
403
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_datanodeid, tvb, offset, length, ENC_ASCII);
404
0
    offset += length;
405
406
0
    length = tvb_get_ntohs(tvb, offset);
407
408
    /* length of addr */
409
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
410
0
    offset += 2;
411
412
    /* storageid */
413
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_storageid, tvb, offset, length, ENC_ASCII);
414
0
    offset += length;
415
416
    /* info port */
417
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_infoport, tvb, offset, 2, ENC_BIG_ENDIAN);
418
0
    offset += 2;
419
420
421
    /* default name node port */
422
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_ipcport, tvb, offset, 2, ENC_BIG_ENDIAN);
423
0
    offset += 2;
424
425
    /* capacity */
426
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_capacity, tvb, offset, 8, ENC_BIG_ENDIAN);
427
0
    offset += 8;
428
429
    /* dfs used */
430
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_dfsused, tvb, offset, 8, ENC_BIG_ENDIAN);
431
0
    offset += 8;
432
433
    /* remaining */
434
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_remaining, tvb, offset, 8, ENC_BIG_ENDIAN);
435
0
    offset += 8;
436
437
    /* last update */
438
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_lastupdate, tvb, offset, 8, ENC_BIG_ENDIAN);
439
0
    offset += 8;
440
441
    /* num active connections */
442
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_activecon, tvb, offset, 4, ENC_BIG_ENDIAN);
443
0
    offset += 4;
444
445
446
0
    length = tvb_get_uint8(tvb, offset);
447
448
    /* location rack length */
449
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
450
0
    offset += 1;
451
452
    /* location rack */
453
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_rackloc, tvb, offset, length, ENC_ASCII);
454
0
    offset += length;
455
456
0
    length = tvb_get_uint8(tvb, offset);
457
458
    /* hostname length */
459
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
460
0
    offset += 1;
461
462
    /* hostname */
463
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_hostname, tvb, offset, length, ENC_ASCII);
464
0
    offset += length;
465
466
0
    length = tvb_get_uint8(tvb, offset);
467
468
    /* admin state length */
469
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
470
0
    offset += 1;
471
472
    /* admin state */
473
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_adminstate, tvb, offset, length, ENC_ASCII);
474
0
    offset += length;
475
476
0
    return offset;
477
478
0
}
479
480
481
482
/*
483
dissects the response from get block info.
484
*/
485
static void
486
0
dissect_resp_locatedblocks (tvbuff_t *tvb, proto_tree *hdfs_tree, int offset) {
487
488
489
    /* file length = 8  */
490
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_filelen, tvb, offset, 8, ENC_BIG_ENDIAN);
491
0
    offset += 8;
492
493
    /* under construction = 1  */
494
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_construct, tvb, offset, 1, ENC_BIG_ENDIAN);
495
0
    offset += 1;
496
497
    /* number of blocks */
498
0
    proto_tree_add_item(hdfs_tree, hf_hdfs_blockcount, tvb, offset, 4, ENC_BIG_ENDIAN);
499
0
    offset += 4;
500
501
    /* dissect info for each block */
502
0
    while (tvb_reported_length(tvb) - offset > 0) {
503
0
        offset = dissect_block_info (tvb, hdfs_tree, offset);
504
0
    }
505
506
0
}
507
508
509
static int
510
dissect_hdfs_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
511
0
{
512
0
    unsigned offset = 0;
513
0
    unsigned success = 0;
514
0
    unsigned length = 0;
515
516
517
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "HDFS");
518
    /* Clear out stuff in the info column */
519
0
    col_clear(pinfo->cinfo,COL_INFO);
520
521
0
    if (tree) {
522
523
0
        proto_item *ti;
524
0
        proto_tree *hdfs_tree;
525
526
0
        ti = proto_tree_add_item(tree, proto_hdfs, tvb, 0, -1, ENC_NA);
527
0
        hdfs_tree = proto_item_add_subtree(ti, ett_hdfs);
528
529
        /* Response */
530
0
        if (value_is_in_range(tcp_ports, pinfo->srcport)) {
531
            /* 4 bytes = sequence number */
532
0
            proto_tree_add_item(hdfs_tree, hf_hdfs_packetno, tvb, offset, 4, ENC_BIG_ENDIAN);
533
0
            offset += 4;
534
535
            /* 4 bytes = status -> 0000 = success, 0001 = error, ffff = fatal */
536
0
            proto_tree_add_item_ret_uint(hdfs_tree, hf_hdfs_success, tvb, offset, 4, ENC_BIG_ENDIAN, &success);
537
0
            offset += 4;
538
539
0
            if (success != 0) {
540
0
                return offset;
541
0
            }
542
543
0
            if (!tvb_memeql(tvb, offset + 2, (const uint8_t*)"long", 4)) {
544
0
                dissect_resp_long (tvb, hdfs_tree,  offset);
545
546
0
            } else {
547
548
                /* name length = 2 B */
549
0
                length = tvb_get_ntohs(tvb, offset);
550
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
551
0
                offset += 2;
552
553
                /* length bytes = method name */
554
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_objname, tvb, offset, length, ENC_ASCII);
555
0
                offset += length;
556
557
                /* get length that we just dissected */
558
0
                length = tvb_get_ntohs(tvb, offset);
559
560
                /* 2 bytes = objects length */
561
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
562
0
                offset += 2;
563
564
                /* length bytes = object name */
565
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_objname, tvb, offset, length, ENC_ASCII);
566
0
                offset += length;
567
568
                /* responses about block location info */
569
0
                if (!tvb_memeql(tvb, offset - length, (const uint8_t*)"org.apache.hadoop.hdfs.protocol.LocatedBlocks", length)) {
570
0
                    dissect_resp_locatedblocks (tvb, hdfs_tree, offset);
571
572
                    /* responses about file statuses */
573
0
                } else if (!tvb_memeql(tvb, offset - length, (const uint8_t*)"org.apache.hadoop.hdfs.protocol.HdfsFileStatus", length)) {
574
0
                    dissect_resp_filestatus (tvb, hdfs_tree, offset);
575
576
0
                } else {
577
                    /* get length */
578
0
                    length = tvb_get_ntohs(tvb, offset);
579
580
                    /* 2 bytes = parameter value length */
581
0
                    proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
582
0
                    offset += 2;
583
584
                    /* the value of the parameter */
585
0
                    proto_tree_add_item(hdfs_tree, hf_hdfs_paramval, tvb, offset, length, ENC_ASCII);
586
                    /*offset += length;*/
587
0
                }
588
0
            }
589
590
            /* Request to namenode */
591
0
        } else {
592
593
            /* check the packet length */
594
0
            unsigned auth = tvb_get_ntohl(tvb, offset);
595
596
            /* first setup packet starts with "hrpc" */
597
0
            if (!tvb_memeql(tvb, offset, (const uint8_t*)REQUEST_STR, sizeof(REQUEST_STR) - 1)) {
598
599
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_sequenceno, tvb, offset, sizeof(REQUEST_STR) - 1, ENC_ASCII);
600
0
                offset += (int)sizeof(REQUEST_STR) - 1;
601
602
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_pdu_type, tvb, offset, 1, ENC_BIG_ENDIAN);
603
0
                offset += 1;
604
605
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
606
                /*offset += 1;*/
607
608
0
            } else {
609
                /* second authentication packet */
610
0
                if (auth + 4 != tvb_reported_length(tvb)) {
611
612
                    /* authentication length (read out of first 4 bytes) */
613
0
                    length = tvb_get_ntohl(tvb, offset);
614
0
                    proto_tree_add_item(hdfs_tree, hf_hdfs_authlen, tvb, offset, 4, ENC_ASCII);
615
0
                    offset += 4;
616
617
                    /* authentication (length the number we just got) */
618
0
                    proto_tree_add_item(hdfs_tree, hf_hdfs_auth, tvb, offset, length, ENC_ASCII);
619
0
                    offset += length;
620
0
                }
621
622
                /* data packets */
623
624
                /* 4 bytes = length */
625
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_len, tvb, offset, 4, ENC_BIG_ENDIAN);
626
0
                offset += 4;
627
628
                /* 4 bytes = sequence number */
629
0
                proto_tree_add_item(hdfs_tree, hf_hdfs_packetno, tvb, offset, 4, ENC_BIG_ENDIAN);
630
0
                offset += 4;
631
632
                /* dissect packet data */
633
0
                dissect_data (tvb, hdfs_tree, offset);
634
0
            }
635
0
        }
636
0
    }
637
0
    return tvb_captured_length(tvb);
638
0
}
639
640
/* determine PDU length of protocol  */
641
static unsigned get_hdfs_message_len(packet_info *pinfo _U_, tvbuff_t *tvb,
642
                                  int offset _U_, void *data _U_)
643
0
{
644
0
    int len = tvb_reported_length(tvb);
645
646
0
    if (tvb_reported_length(tvb) == 1448 || tvb_reported_length(tvb) == 1321) {
647
0
        len = 150 * tvb_get_ntohs(tvb, 113) + 115 ;
648
0
    }
649
650
0
    return len;
651
652
0
}
653
654
static int
655
dissect_hdfs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
656
0
{
657
0
    int frame_header_len = 0;
658
0
    bool need_reassemble = false;
659
660
0
    frame_header_len = tvb_reported_length(tvb);
661
662
0
    if (frame_header_len == 1448 || frame_header_len ==  1321) {
663
0
        need_reassemble = true;
664
0
    }
665
666
0
    tcp_dissect_pdus(tvb, pinfo, tree, need_reassemble, frame_header_len, get_hdfs_message_len, dissect_hdfs_message, data);
667
0
    return tvb_captured_length(tvb);
668
0
}
669
670
static void
671
apply_hdfs_prefs(void)
672
15
{
673
  /* HDFS uses the port preference to determine request/response */
674
15
  tcp_ports = prefs_get_range_value("hdfs", "tcp.port");
675
15
}
676
677
/* registers the protcol with the given names */
678
void
679
proto_register_hdfs(void)
680
15
{
681
682
15
    static hf_register_info hf[] = {
683
684
        /* list of all options for dissecting the protocol */
685
686
        /*************************************************
687
        First packet
688
        **************************************************/
689
15
        { &hf_hdfs_sequenceno,
690
15
          { "HDFS protocol type", "hdfs.type",
691
15
            FT_STRING, BASE_NONE,
692
15
            NULL, 0x0,
693
15
            NULL, HFILL }
694
15
        },
695
15
        { &hf_hdfs_pdu_type,
696
15
          { "HDFS protocol version", "hdfs.version",
697
15
            FT_UINT8, BASE_DEC,
698
15
            NULL, 0x0,
699
15
            NULL, HFILL }
700
15
        },
701
15
        { &hf_hdfs_flags,
702
15
          { "HDFS authentication type", "hdfs.auth_type",
703
15
            FT_UINT8, BASE_DEC,
704
15
            NULL, 0x0,
705
15
            NULL, HFILL }
706
15
        },
707
        /***********************************************
708
        Authentication packet
709
        ***********************************************/
710
15
        { &hf_hdfs_authlen,
711
15
          { "HDFS authentication length", "hdfs.authlen",
712
15
            FT_STRING, BASE_NONE,
713
15
            NULL, 0x0,
714
15
            NULL, HFILL }
715
15
        },
716
15
        { &hf_hdfs_auth,
717
15
          { "HDFS authorization bits", "hdfs.auth",
718
15
            FT_STRING, BASE_NONE,
719
15
            NULL, 0x0,
720
15
            NULL, HFILL }
721
15
        },
722
        /**********************************************
723
        Response
724
        **********************************************/
725
15
        { &hf_hdfs_packetno,
726
15
          { "HDFS packet number", "hdfs.seqno",
727
15
            FT_UINT32, BASE_DEC,
728
15
            NULL, 0x0,
729
15
            NULL, HFILL }
730
15
        },
731
15
        { &hf_hdfs_success,
732
15
          { "HDFS success", "hdfs.success",
733
15
            FT_UINT32, BASE_DEC,
734
15
            NULL, 0x0,
735
15
            NULL, HFILL }
736
15
        },
737
15
        { &hf_hdfs_strcall,
738
15
          { "HDFS method name", "hdfs.strcall",
739
15
            FT_STRING, BASE_NONE,
740
15
            NULL, 0x0,
741
15
            NULL, HFILL }
742
15
        },
743
#if 0
744
        { &hf_hdfs_rest,
745
          { "HDFS value", "hdfs.rest",
746
            FT_STRING, BASE_NONE,
747
            NULL, 0x0,
748
            NULL, HFILL }
749
        },
750
#endif
751
15
        { &hf_hdfs_blockloc,
752
15
          { "HDFS block location", "hdfs.blockloc",
753
15
            FT_UINT64, BASE_DEC,
754
15
            NULL, 0x0,
755
15
            NULL, HFILL }
756
15
        },
757
15
        { &hf_hdfs_blocksize,
758
15
          { "HDFS block size", "hdfs.blocksize",
759
15
            FT_UINT64, BASE_DEC,
760
15
            NULL, 0x0,
761
15
            NULL, HFILL }
762
15
        },
763
15
        { &hf_hdfs_endblockloc,
764
15
          { "HDFS file size", "hdfs.endblockloc",
765
15
            FT_UINT64, BASE_DEC,
766
15
            NULL, 0x0,
767
15
            NULL, HFILL }
768
15
        },
769
15
        { &hf_hdfs_blockgen,
770
15
          { "HDFS block gen", "hdfs.blockgen",
771
15
            FT_UINT64, BASE_DEC,
772
15
            NULL, 0x0,
773
15
            NULL, HFILL }
774
15
        },
775
15
        { &hf_hdfs_prover,
776
15
          { "HDFS protocol version", "hdfs.prover",
777
15
            FT_UINT64, BASE_DEC,
778
15
            NULL, 0x0,
779
15
            NULL, HFILL }
780
15
        },
781
15
        { &hf_hdfs_objname,
782
15
          { "HDFS object name", "hdfs.objname",
783
15
            FT_STRING, BASE_NONE,
784
15
            NULL, 0x0,
785
15
            NULL, HFILL }
786
15
        },
787
15
        { &hf_hdfs_filename,
788
15
          { "HDFS file name", "hdfs.filename",
789
15
            FT_STRING, BASE_NONE,
790
15
            NULL, 0x0,
791
15
            NULL, HFILL }
792
15
        },
793
15
        { &hf_hdfs_blockcount,
794
15
          { "HDFS block count", "hdfs.blockcount",
795
15
            FT_UINT32, BASE_DEC,
796
15
            NULL, 0x0,
797
15
            NULL, HFILL }
798
15
        },
799
15
        { &hf_hdfs_ownername,
800
15
          { "HDFS owner name", "hdfs.ownername",
801
15
            FT_STRING, BASE_NONE,
802
15
            NULL, 0x0,
803
15
            NULL, HFILL }
804
15
        },
805
15
        { &hf_hdfs_groupname,
806
15
          { "HDFS group name", "hdfs.groupname",
807
15
            FT_STRING, BASE_NONE,
808
15
            NULL, 0x0,
809
15
            NULL, HFILL }
810
15
        },
811
15
        { &hf_hdfs_accesstime,
812
15
          { "HDFS access time", "hdfs.accesstime",
813
15
            FT_UINT64, BASE_DEC,
814
15
            NULL, 0x0,
815
15
            NULL, HFILL }
816
15
        },
817
15
        { &hf_hdfs_modtime,
818
15
          { "HDFS modified time", "hdfs.modtime",
819
15
            FT_UINT64, BASE_DEC,
820
15
            NULL, 0x0,
821
15
            NULL, HFILL }
822
15
        },
823
15
        { &hf_hdfs_blockrep,
824
15
          { "HDFS block replication factor", "hdfs.blockrep",
825
15
            FT_UINT16, BASE_DEC,
826
15
            NULL, 0x0,
827
15
            NULL, HFILL }
828
15
        },
829
15
        { &hf_hdfs_isdir,
830
15
          { "HDFS is directory", "hdfs.isdir",
831
15
            FT_UINT8, BASE_DEC,
832
15
            NULL, 0x0,
833
15
            NULL, HFILL }
834
15
        },
835
15
        { &hf_hdfs_filelen,
836
15
          { "HDFS file length", "hdfs.filelen",
837
15
            FT_UINT64, BASE_DEC,
838
15
            NULL, 0x0,
839
15
            NULL, HFILL }
840
15
        },
841
15
        { &hf_hdfs_construct,
842
15
          { "HDFS under construction", "hdfs.construct",
843
15
            FT_UINT8, BASE_DEC,
844
15
            NULL, 0x0,
845
15
            NULL, HFILL }
846
15
        },
847
15
        { &hf_hdfs_rackloc,
848
15
          { "HDFS rack location", "hdfs.rackloc",
849
15
            FT_STRING, BASE_NONE,
850
15
            NULL, 0x0,
851
15
            NULL, HFILL }
852
15
        },
853
15
        { &hf_hdfs_adminstate,
854
15
          { "HDFS admin state", "hdfs.adminstate",
855
15
            FT_STRING, BASE_NONE,
856
15
            NULL, 0x0,
857
15
            NULL, HFILL }
858
15
        },
859
15
        { &hf_hdfs_hostname,
860
15
          { "HDFS hostname", "hdfs.hostname",
861
15
            FT_STRING, BASE_NONE,
862
15
            NULL, 0x0,
863
15
            NULL, HFILL }
864
15
        },
865
866
867
15
        { &hf_hdfs_namelenone,
868
15
          { "HDFS name length", "hdfs.namelenone",
869
15
            FT_UINT8, BASE_DEC,
870
15
            NULL, 0x0,
871
15
            NULL, HFILL }
872
15
        },
873
15
        { &hf_hdfs_namelentwo,
874
15
          { "HDFS name length", "hdfs.namelentwo",
875
15
            FT_UINT16, BASE_DEC,
876
15
            NULL, 0x0,
877
15
            NULL, HFILL }
878
15
        },
879
880
881
        /***************************************
882
        file info response
883
        ***************************************/
884
15
        { &hf_hdfs_activecon,
885
15
          { "HDFS active connections", "hdfs.activecon",
886
15
            FT_UINT32, BASE_DEC,
887
15
            NULL, 0x0,
888
15
            NULL, HFILL }
889
15
        },
890
15
        { &hf_hdfs_lastupdate,
891
15
          { "HDFS lastupdate", "hdfs.lastupdate",
892
15
            FT_UINT64, BASE_DEC,
893
15
            NULL, 0x0,
894
15
            NULL, HFILL }
895
15
        },
896
15
        { &hf_hdfs_remaining,
897
15
          { "HDFS remaining", "hdfs.remaining",
898
15
            FT_UINT64, BASE_DEC,
899
15
            NULL, 0x0,
900
15
            NULL, HFILL }
901
15
        },
902
15
        { &hf_hdfs_dfsused,
903
15
          { "HDFS dfs used", "hdfs.dfsused",
904
15
            FT_UINT64, BASE_DEC,
905
15
            NULL, 0x0,
906
15
            NULL, HFILL }
907
15
        },
908
15
        { &hf_hdfs_capacity,
909
15
          { "HDFS capacity", "hdfs.capacity",
910
15
            FT_UINT64, BASE_DEC,
911
15
            NULL, 0x0,
912
15
            NULL, HFILL }
913
15
        },
914
15
        { &hf_hdfs_ipcport,
915
15
          { "HDFS ipcport", "hdfs.ipcport",
916
15
            FT_UINT16, BASE_DEC,
917
15
            NULL, 0x0,
918
15
            NULL, HFILL }
919
15
        },
920
15
        { &hf_hdfs_infoport,
921
15
          { "HDFS info port", "hdfs.infoport",
922
15
            FT_UINT16, BASE_DEC,
923
15
            NULL, 0x0,
924
15
            NULL, HFILL }
925
15
        },
926
15
        { &hf_hdfs_storageid,
927
15
          { "HDFS storage id", "hdfs.storageid",
928
15
            FT_STRING, BASE_NONE,
929
15
            NULL, 0x0,
930
15
            NULL, HFILL }
931
15
        },
932
15
        { &hf_hdfs_datanodeid,
933
15
          { "HDFS datanodeid", "hdfs.datanodeid",
934
15
            FT_STRING, BASE_NONE,
935
15
            NULL, 0x0,
936
15
            NULL, HFILL }
937
15
        },
938
15
        { &hf_hdfs_locations,
939
15
          { "HDFS locations", "hdfs.locations",
940
15
            FT_UINT32, BASE_DEC,
941
15
            NULL, 0x0,
942
15
            NULL, HFILL }
943
15
        },
944
945
15
        { &hf_hdfs_identifier,
946
15
          { "HDFS locations", "hdfs.identifier",
947
15
            FT_STRING, BASE_NONE,
948
15
            NULL, 0x0,
949
15
            NULL, HFILL }
950
15
        },
951
15
        { &hf_hdfs_password,
952
15
          { "HDFS password", "hdfs.password",
953
15
            FT_STRING, BASE_NONE,
954
15
            NULL, 0x0,
955
15
            NULL, HFILL }
956
15
        },
957
15
        { &hf_hdfs_kind,
958
15
          { "HDFS kind", "hdfs.kind",
959
15
            FT_STRING, BASE_NONE,
960
15
            NULL, 0x0,
961
15
            NULL, HFILL }
962
15
        },
963
15
        { &hf_hdfs_service,
964
15
          { "HDFS locations", "hdfs.service",
965
15
            FT_STRING, BASE_NONE,
966
15
            NULL, 0x0,
967
15
            NULL, HFILL }
968
15
        },
969
15
        { &hf_hdfs_corrupt,
970
15
          { "HDFS corrupt", "hdfs.corrupt",
971
15
            FT_UINT8, BASE_DEC,
972
15
            NULL, 0x0,
973
15
            NULL, HFILL }
974
15
        },
975
15
        { &hf_hdfs_offset,
976
15
          { "HDFS offset", "hdfs.offset",
977
15
            FT_UINT64, BASE_DEC,
978
15
            NULL, 0x0,
979
15
            NULL, HFILL }
980
15
        },
981
982
983
        /***********************************************
984
        Data request
985
        ***********************************************/
986
15
        { &hf_hdfs_len,
987
15
          { "HDFS length", "hdfs.len",
988
15
            FT_UINT32, BASE_DEC,
989
15
            NULL, 0x0,
990
15
            NULL, HFILL }
991
15
        },
992
        /* packet number, same as in response
993
           method name length, same as in response
994
           string call, same as in response */
995
15
        { &hf_hdfs_params,
996
15
          { "HDFS number of parameters", "hdfs.params",
997
15
            FT_UINT32, BASE_DEC,
998
15
            NULL, 0x0,
999
15
            NULL, HFILL }
1000
15
        },
1001
15
        { &hf_hdfs_paramtype,
1002
15
          { "HDFS parameter type", "hdfs.paramtype",
1003
15
            FT_STRING, BASE_NONE,
1004
15
            NULL, 0x0,
1005
15
            NULL, HFILL }
1006
15
        },
1007
15
        { &hf_hdfs_paramval,
1008
15
          { "HDFS parameter value", "hdfs.paramval",
1009
15
            FT_STRING, BASE_NONE,
1010
15
            NULL, 0x0,
1011
15
            NULL, HFILL }
1012
15
        },
1013
        /* param value that is displayed as a number not a string */
1014
15
        { &hf_hdfs_paramvalnum,
1015
15
          { "HDFS parameter value", "hdfs.paramvalnum",
1016
15
            FT_INT64, BASE_DEC,
1017
15
            NULL, 0x0,
1018
15
            NULL, HFILL }
1019
15
        },
1020
15
        { &hf_hdfs_fileperm,
1021
15
          { "HDFS File permission", "hdfs.fileperm",
1022
15
            FT_INT16, BASE_DEC,
1023
15
            NULL, 0x0,
1024
15
            NULL, HFILL }
1025
15
        },
1026
1027
15
    };
1028
1029
    /* Setup protocol subtree array */
1030
15
    static int *ett[] = {
1031
15
        &ett_hdfs
1032
15
    };
1033
1034
15
    proto_hdfs = proto_register_protocol ("HDFS Protocol", "HDFS", "hdfs");
1035
1036
15
    proto_register_field_array(proto_hdfs, hf, array_length(hf));
1037
15
    proto_register_subtree_array(ett, array_length(ett));
1038
1039
15
    prefs_register_protocol(proto_hdfs, apply_hdfs_prefs);
1040
15
    hdfs_handle = register_dissector("hdfs", dissect_hdfs, proto_hdfs);
1041
15
}
1042
1043
/* registers handoff */
1044
void
1045
proto_reg_handoff_hdfs(void)
1046
15
{
1047
15
    dissector_add_for_decode_as_with_preference("tcp.port", hdfs_handle);
1048
15
    apply_hdfs_prefs();
1049
15
}
1050
/*
1051
 * Editor modelines
1052
 *
1053
 * Local Variables:
1054
 * c-basic-offset: 4
1055
 * tab-width: 8
1056
 * indent-tabs-mode: nil
1057
 * End:
1058
 *
1059
 * ex: set shiftwidth=4 tabstop=8 expandtab:
1060
 * :indentSize=4:tabSize=8:noTabs=true:
1061
 */