MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-hdfs.c
blobb96427a10eeb44a236d98df97a8009d9afc7f740
1 /* packet-hdfs.c
2 * HDFS Protocol and dissectors
4 * Copyright (c) 2011 by Isilon Systems.
6 * Author: Allison Obourn <aobourn@isilon.com>
8 * $Id$
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1999 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "config.h"
32 #include <glib.h>
34 #include <epan/packet.h>
35 #include <epan/dissectors/packet-tcp.h>
36 #include <epan/prefs.h>
38 #if 0
39 #define NAMENODE_PORT 8020
40 #endif
42 #define REQUEST_STR "hrpc"
44 #define SEND_DEC 1936027236
45 #define SEND_OFFSET 13
46 #define HEAR_DEC 1214603634
47 #define HEAR_OFFSET 9
48 #define TBEA_DEC 1952605537
49 #define TBEA_OFFSET 5
50 #define T_DEC 116
51 #define T_OFFSET 1
53 #define FIRST_READ_FRAGMENT_LEN 15
54 #define SECOND_READ_FRAGMENT_LEN 29
57 #if 0
58 static const int START = 0;
59 static const int AUTHENTICATION = 1;
60 static const int DATA = 2;
61 #endif
63 static guint tcp_port = 0;
65 static int proto_hdfs = -1;
66 static int hf_hdfs_pdu_type = -1;
67 static int hf_hdfs_flags = -1;
68 static int hf_hdfs_sequenceno = -1;
69 static int hf_hdfs_packetno = -1;
70 static int hf_hdfs_authlen = -1;
71 static int hf_hdfs_success = -1;
72 static int hf_hdfs_auth = -1;
73 static int hf_hdfs_len = -1;
74 static int hf_hdfs_strcall = -1;
75 static int hf_hdfs_params = -1;
76 static int hf_hdfs_paramtype = -1;
77 static int hf_hdfs_paramval = -1;
78 static int hf_hdfs_paramvalnum = -1;
79 /* static int hf_hdfs_rest = -1; */
80 static int hf_hdfs_fileperm = -1;
81 static int hf_hdfs_blockloc = -1;
82 static int hf_hdfs_endblockloc = -1;
83 static int hf_hdfs_blockgen = -1;
84 static int hf_hdfs_prover = -1;
85 static int hf_hdfs_objname = -1;
86 static int hf_hdfs_filename = -1;
87 static int hf_hdfs_blockcount = -1;
88 static int hf_hdfs_ownername = -1;
89 static int hf_hdfs_groupname = -1;
90 static int hf_hdfs_namelenone = -1;
91 static int hf_hdfs_namelentwo = -1;
92 static int hf_hdfs_accesstime = -1;
93 static int hf_hdfs_modtime = -1;
94 static int hf_hdfs_blockrep = -1;
95 static int hf_hdfs_isdir = -1;
96 static int hf_hdfs_blocksize = -1;
97 static int hf_hdfs_filelen = -1;
98 static int hf_hdfs_construct = -1;
99 static int hf_hdfs_hostname = -1;
100 static int hf_hdfs_rackloc = -1;
101 static int hf_hdfs_adminstate = -1;
102 static int hf_hdfs_activecon = -1;
103 static int hf_hdfs_lastupdate = -1;
104 static int hf_hdfs_remaining = -1;
105 static int hf_hdfs_dfsused = -1;
106 static int hf_hdfs_capacity = -1;
107 static int hf_hdfs_ipcport = -1;
108 static int hf_hdfs_infoport = -1;
109 static int hf_hdfs_storageid = -1;
110 static int hf_hdfs_datanodeid = -1;
111 static int hf_hdfs_locations = -1;
112 static int hf_hdfs_offset = -1;
113 static int hf_hdfs_corrupt = -1;
114 static int hf_hdfs_identifier = -1;
115 static int hf_hdfs_password = -1;
116 static int hf_hdfs_kind = -1;
117 static int hf_hdfs_service = -1;
119 static gint ett_hdfs = -1;
121 static dissector_handle_t hdfs_handle;
123 void proto_reg_handoff_hdfs(void);
125 /* Parses the parameters of a function.
126 Parses the type length which is always in 2 bytes.
127 Next the type which is the previously found length.
128 If this type is variable length it then reads the length of the data
129 from 2 bytes and then the data.
130 Otherwise reads just the data. */
131 static void
132 dissect_params (tvbuff_t *tvb, proto_tree *hdfs_tree, guint offset, int params) {
134 guint length;
135 int i = 0;
136 const guint8* type_name;
137 for (i = 0; i < params; i++) {
139 /* get length that we just dissected */
140 length = tvb_get_ntohs(tvb, offset);
142 /* 2 bytes = parameter type length */
143 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
144 offset += 2;
146 /* length bytes = parameter type */
147 proto_tree_add_item(hdfs_tree, hf_hdfs_paramtype, tvb, offset, length, ENC_ASCII|ENC_NA);
148 offset += length;
150 if (offset >= length && (!tvb_memeql(tvb, offset - length, "long", length) || !tvb_memeql(tvb, offset - length, "int", length) ||
151 !tvb_memeql(tvb, offset - length, "short", length) || !tvb_memeql(tvb, offset - length, "char", length) ||
152 !tvb_memeql(tvb, offset - length, "byte", length) || !tvb_memeql(tvb, offset - length, "float", length)
153 || !tvb_memeql(tvb, offset - length, "double", length) || !tvb_memeql(tvb, offset - length, "boolean", length))) {
155 if (!tvb_memeql(tvb, offset - length, "boolean", length)) {
156 length = 1;
157 } else if (!tvb_memeql(tvb, offset - length, "short", length)) {
158 length = 2;
159 } else {
160 length = sizeof(type_name);
163 proto_tree_add_item(hdfs_tree, hf_hdfs_paramvalnum, tvb, offset, length, ENC_BIG_ENDIAN);
164 offset += length;
166 } else {
167 /* get length */
168 length = tvb_get_ntohs(tvb, offset);
170 /* 2 bytes = parameter value length */
171 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
172 offset += 2;
174 proto_tree_add_item(hdfs_tree, hf_hdfs_paramval, tvb, offset, length, ENC_ASCII|ENC_NA);
175 offset += length;
177 if (!tvb_memeql(tvb, offset - length, "org.apache.hadoop.fs.permission.FsPermission", length)) {
178 proto_tree_add_item(hdfs_tree, hf_hdfs_fileperm, tvb, offset, 2, ENC_BIG_ENDIAN);
179 offset += 2;
186 /* Dissects a data packet of the form:
187 method name length : 2B
188 method name : above value
189 number of parameters : 4B
190 -- list of parameters the length of above --
191 parameter type length : 2B
192 parameter type : above value
193 -- if the type is variable size --
194 parameter value length : 2B
195 parameter value : above value
196 -- otherwise --
197 parameter value : length of the type */
198 static void
199 dissect_data (tvbuff_t *tvb, proto_tree *hdfs_tree, guint offset) {
200 int params = 0;
201 guint length = 0;
203 /* get length */
204 length = tvb_get_ntohs(tvb, offset);
206 /* method name length = 2 B */
207 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
208 offset += 2;
210 /* length bytes = method name */
211 proto_tree_add_item(hdfs_tree, hf_hdfs_strcall, tvb, offset, length, ENC_ASCII|ENC_NA);
212 offset += length;
214 /* we only want to parse the packet if it is not a heartbeat (random looking numbers are the decimal
215 representation of sendHeartbeat */
216 if (!(tvb_get_ntohl(tvb, offset - SEND_OFFSET) == SEND_DEC && tvb_get_ntohl(tvb, offset - HEAR_OFFSET) == HEAR_DEC &&
217 tvb_get_ntohl(tvb, offset - TBEA_OFFSET) == TBEA_DEC && tvb_get_guint8(tvb, offset - T_OFFSET) == T_DEC)) {
219 /* get number of params */
220 params = tvb_get_ntohl(tvb, offset);
222 /* 4 bytes = # of parameters */
223 proto_tree_add_item(hdfs_tree, hf_hdfs_params, tvb, offset, 4, ENC_BIG_ENDIAN);
224 offset += 4;
226 /* go through all params and dissect their type length, type, value length and value */
227 dissect_params (tvb, hdfs_tree, offset, params);
232 response to a get protocol version message
233 contains a type length, type name and the value
235 static int
236 dissect_resp_long (tvbuff_t *tvb, proto_tree *hdfs_tree, int offset) {
237 /* get length that we just dissected */
238 int length = tvb_get_ntohs(tvb, offset);
240 /* 2 bytes = parameter type length */
241 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
242 offset += 2;
244 /* length bytes = parameter type */
245 proto_tree_add_item(hdfs_tree, hf_hdfs_paramtype, tvb, offset, length, ENC_ASCII|ENC_NA);
246 offset += length;
248 /* the value */
249 proto_tree_add_item(hdfs_tree, hf_hdfs_prover, tvb, offset, 8, ENC_BIG_ENDIAN);
250 offset += 8;
252 return offset;
256 Response to a file status message
258 static int
259 dissect_resp_filestatus (tvbuff_t *tvb, proto_tree *hdfs_tree, int offset) {
261 int length;
263 /* file status */
264 proto_tree_add_item(hdfs_tree, hf_hdfs_fileperm, tvb, offset, 2, ENC_BIG_ENDIAN);
265 offset += 2;
267 /* get length */
268 length = tvb_get_ntohs(tvb, offset);
270 /* 2 bytes = file name length */
271 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
272 offset += 2;
274 /* file name */
275 proto_tree_add_item(hdfs_tree, hf_hdfs_filename, tvb, offset, length, ENC_ASCII|ENC_NA);
276 offset += length;
279 /* 8 file size / end location */
280 proto_tree_add_item(hdfs_tree, hf_hdfs_endblockloc, tvb, offset, 8, ENC_BIG_ENDIAN);
281 offset += 8;
283 /* is directory */
284 proto_tree_add_item(hdfs_tree, hf_hdfs_isdir, tvb, offset, 1, ENC_BIG_ENDIAN);
285 offset += 1;
287 /* block replication factor */
288 proto_tree_add_item(hdfs_tree, hf_hdfs_blockrep, tvb, offset, 2, ENC_BIG_ENDIAN);
289 offset += 2;
291 /* block size */
292 proto_tree_add_item(hdfs_tree, hf_hdfs_blocksize, tvb, offset, 8, ENC_BIG_ENDIAN);
293 offset += 8;
295 /* modified time */
296 proto_tree_add_item(hdfs_tree, hf_hdfs_modtime, tvb, offset, 8, ENC_BIG_ENDIAN);
297 offset += 8;
299 /* access time */
300 proto_tree_add_item(hdfs_tree, hf_hdfs_accesstime, tvb, offset, 8, ENC_BIG_ENDIAN);
301 offset += 8;
303 /* 2 of file permissions */
304 proto_tree_add_item(hdfs_tree, hf_hdfs_fileperm, tvb, offset, 2, ENC_BIG_ENDIAN);
305 offset += 2;
308 /* get length */
309 length = tvb_get_guint8 (tvb, offset);
311 /* owner name length */
312 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
313 offset += 1;
315 /* owner name */
316 proto_tree_add_item(hdfs_tree, hf_hdfs_ownername, tvb, offset, length, ENC_ASCII|ENC_NA);
317 offset += length;
319 /* get length */
320 length = tvb_get_guint8 (tvb, offset);
322 /* group name length */
323 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
324 offset += 1;
326 /* group name */
327 proto_tree_add_item(hdfs_tree, hf_hdfs_groupname, tvb, offset, length, ENC_ASCII|ENC_NA);
328 offset += length;
330 return offset;
335 Response to the get block info message
336 parses the sent back information about each blcok
338 static int
339 dissect_block_info (tvbuff_t *tvb, proto_tree *hdfs_tree, int offset) {
341 int length;
343 length = tvb_get_guint8(tvb, offset);
345 /* identifier length */
346 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
347 offset += 1;
349 /* identifier */
350 proto_tree_add_item(hdfs_tree, hf_hdfs_identifier, tvb, offset, length, ENC_ASCII|ENC_NA);
351 offset += length;
353 length = tvb_get_guint8(tvb, offset);
355 /* password length */
356 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
357 offset += 1;
359 /* password */
360 proto_tree_add_item(hdfs_tree, hf_hdfs_password, tvb, offset, length, ENC_ASCII|ENC_NA);
361 offset += length;
363 length = tvb_get_guint8(tvb, offset);
365 /* kind length */
366 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
367 offset += 1;
369 /* kind */
370 proto_tree_add_item(hdfs_tree, hf_hdfs_kind, tvb, offset, length, ENC_ASCII|ENC_NA);
371 offset += length;
373 length = tvb_get_guint8(tvb, offset);
375 /* service length */
376 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
377 offset += 1;
379 /* service */
380 proto_tree_add_item(hdfs_tree, hf_hdfs_service, tvb, offset, length, ENC_ASCII|ENC_NA);
381 offset += length;
383 /* corrupt */
384 proto_tree_add_item(hdfs_tree, hf_hdfs_corrupt, tvb, offset, 1, ENC_BIG_ENDIAN);
385 offset += 1;
387 /* offset */
388 proto_tree_add_item(hdfs_tree, hf_hdfs_offset, tvb, offset, 8, ENC_BIG_ENDIAN);
389 offset += 8;
392 /* block info section */
394 /* block location */
395 proto_tree_add_item(hdfs_tree, hf_hdfs_blockloc, tvb, offset, 8, ENC_BIG_ENDIAN);
396 offset += 8;
398 /* block size */
399 proto_tree_add_item(hdfs_tree, hf_hdfs_blocksize, tvb, offset, 8, ENC_BIG_ENDIAN);
400 offset += 8;
402 /* gen id 8 */
403 proto_tree_add_item(hdfs_tree, hf_hdfs_blockgen, tvb, offset, 8, ENC_BIG_ENDIAN);
404 offset += 8;
406 /* locations */
407 proto_tree_add_item(hdfs_tree, hf_hdfs_locations, tvb, offset, 4, ENC_BIG_ENDIAN);
408 offset += 4;
411 /* address section */
413 /* get length */
414 length = tvb_get_ntohs(tvb, offset);
416 /* length of addr */
417 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
418 offset += 2;
420 /* datanode id */
421 proto_tree_add_item(hdfs_tree, hf_hdfs_datanodeid, tvb, offset, length, ENC_ASCII|ENC_NA);
422 offset += length;
424 length = tvb_get_ntohs(tvb, offset);
426 /* length of addr */
427 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
428 offset += 2;
430 /* storageid */
431 proto_tree_add_item(hdfs_tree, hf_hdfs_storageid, tvb, offset, length, ENC_ASCII|ENC_NA);
432 offset += length;
434 /* info port */
435 proto_tree_add_item(hdfs_tree, hf_hdfs_infoport, tvb, offset, 2, ENC_BIG_ENDIAN);
436 offset += 2;
439 /* default name node port */
440 proto_tree_add_item(hdfs_tree, hf_hdfs_ipcport, tvb, offset, 2, ENC_BIG_ENDIAN);
441 offset += 2;
443 /* capacity */
444 proto_tree_add_item(hdfs_tree, hf_hdfs_capacity, tvb, offset, 8, ENC_BIG_ENDIAN);
445 offset += 8;
447 /* dfs used */
448 proto_tree_add_item(hdfs_tree, hf_hdfs_dfsused, tvb, offset, 8, ENC_BIG_ENDIAN);
449 offset += 8;
451 /* remaining */
452 proto_tree_add_item(hdfs_tree, hf_hdfs_remaining, tvb, offset, 8, ENC_BIG_ENDIAN);
453 offset += 8;
455 /* last update */
456 proto_tree_add_item(hdfs_tree, hf_hdfs_lastupdate, tvb, offset, 8, ENC_BIG_ENDIAN);
457 offset += 8;
459 /* num active connections */
460 proto_tree_add_item(hdfs_tree, hf_hdfs_activecon, tvb, offset, 4, ENC_BIG_ENDIAN);
461 offset += 4;
464 length = tvb_get_guint8(tvb, offset);
466 /* location rack length */
467 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
468 offset += 1;
470 /* location rack */
471 proto_tree_add_item(hdfs_tree, hf_hdfs_rackloc, tvb, offset, length, ENC_ASCII|ENC_NA);
472 offset += length;
474 length = tvb_get_guint8(tvb, offset);
476 /* hostname length */
477 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
478 offset += 1;
480 /* hostname */
481 proto_tree_add_item(hdfs_tree, hf_hdfs_hostname, tvb, offset, length, ENC_ASCII|ENC_NA);
482 offset += length;
484 length = tvb_get_guint8(tvb, offset);
486 /* admin state length */
487 proto_tree_add_item(hdfs_tree, hf_hdfs_namelenone, tvb, offset, 1, ENC_BIG_ENDIAN);
488 offset += 1;
490 /* admin state */
491 proto_tree_add_item(hdfs_tree, hf_hdfs_adminstate, tvb, offset, length, ENC_ASCII|ENC_NA);
492 offset += length;
494 return offset;
501 dissects the response from get block info.
503 static void
504 dissect_resp_locatedblocks (tvbuff_t *tvb, proto_tree *hdfs_tree, int offset) {
507 /* file length = 8 */
508 proto_tree_add_item(hdfs_tree, hf_hdfs_filelen, tvb, offset, 8, ENC_BIG_ENDIAN);
509 offset += 8;
511 /* under construction = 1 */
512 proto_tree_add_item(hdfs_tree, hf_hdfs_construct, tvb, offset, 1, ENC_BIG_ENDIAN);
513 offset += 1;
515 /* number of blocks */
516 proto_tree_add_item(hdfs_tree, hf_hdfs_blockcount, tvb, offset, 4, ENC_BIG_ENDIAN);
517 offset += 4;
519 /* dissect info for each block */
520 while (tvb_reported_length(tvb) - offset > 0) {
521 offset = dissect_block_info (tvb, hdfs_tree, offset);
527 static int
528 dissect_hdfs_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
530 guint offset = 0;
531 int success = 0;
532 guint length = 0;
535 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HDFS");
536 /* Clear out stuff in the info column */
537 col_clear(pinfo->cinfo,COL_INFO);
539 if (tree) {
541 proto_item *ti = NULL;
542 proto_tree *hdfs_tree = NULL;
544 ti = proto_tree_add_item(tree, proto_hdfs, tvb, 0, -1, ENC_NA);
545 hdfs_tree = proto_item_add_subtree(ti, ett_hdfs);
547 /* Response */
548 if (pinfo->srcport == tcp_port) {
549 /* 4 bytes = sequence number */
550 proto_tree_add_item(hdfs_tree, hf_hdfs_packetno, tvb, offset, 4, ENC_BIG_ENDIAN);
551 offset += 4;
553 /* 4 bytes = status -> 0000 = success, 0001 = error, ffff = fatal */
554 success = tvb_get_ntohl(tvb, offset);
555 proto_tree_add_item(hdfs_tree, hf_hdfs_success, tvb, offset, 4, ENC_BIG_ENDIAN);
556 offset += 4;
558 if (success != 0) {
559 return offset;
562 if (!tvb_memeql(tvb, offset + 2, "long", 4)) {
563 dissect_resp_long (tvb, hdfs_tree, offset);
565 } else {
567 /* name length = 2 B */
568 length = tvb_get_ntohs(tvb, offset);
569 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
570 offset += 2;
572 /* length bytes = method name */
573 proto_tree_add_item(hdfs_tree, hf_hdfs_objname, tvb, offset, length, ENC_ASCII|ENC_NA);
574 offset += length;
576 /* get length that we just dissected */
577 length = tvb_get_ntohs(tvb, offset);
579 /* 2 bytes = objects length */
580 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
581 offset += 2;
583 /* length bytes = object name */
584 proto_tree_add_item(hdfs_tree, hf_hdfs_objname, tvb, offset, length, ENC_ASCII|ENC_NA);
585 offset += length;
587 /* responses about block location info */
588 if (!tvb_memeql(tvb, offset - length, "org.apache.hadoop.hdfs.protocol.LocatedBlocks", length)) {
589 dissect_resp_locatedblocks (tvb, hdfs_tree, offset);
591 /* responses about file statuses */
592 } else if (!tvb_memeql(tvb, offset - length, "org.apache.hadoop.hdfs.protocol.HdfsFileStatus", length)) {
593 dissect_resp_filestatus (tvb, hdfs_tree, offset);
595 } else {
596 /* get length */
597 length = tvb_get_ntohs(tvb, offset);
599 /* 2 bytes = parameter value length */
600 proto_tree_add_item(hdfs_tree, hf_hdfs_namelentwo, tvb, offset, 2, ENC_BIG_ENDIAN);
601 offset += 2;
603 /* the value of the parameter */
604 proto_tree_add_item(hdfs_tree, hf_hdfs_paramval, tvb, offset, length, ENC_ASCII|ENC_NA);
605 /*offset += length;*/
609 /* Request to namenode */
610 } else {
612 /* check the packet length */
613 guint auth = tvb_get_ntohl(tvb, offset);
615 /* first setup packet starts with "hrpc" */
616 if (!tvb_memeql(tvb, offset, REQUEST_STR, sizeof(REQUEST_STR) - 1)) {
618 proto_tree_add_item(hdfs_tree, hf_hdfs_sequenceno, tvb, offset, sizeof(REQUEST_STR) - 1, ENC_ASCII|ENC_NA);
619 offset += (int)sizeof(REQUEST_STR) - 1;
621 proto_tree_add_item(hdfs_tree, hf_hdfs_pdu_type, tvb, offset, 1, ENC_BIG_ENDIAN);
622 offset += 1;
624 proto_tree_add_item(hdfs_tree, hf_hdfs_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
625 /*offset += 1;*/
627 } else {
628 /* second authentication packet */
629 if (auth + 4 != tvb_reported_length(tvb)) {
631 /* authentication length (read out of first 4 bytes) */
632 length = tvb_get_ntohl(tvb, offset);
633 proto_tree_add_item(hdfs_tree, hf_hdfs_authlen, tvb, offset, 4, ENC_ASCII|ENC_NA);
634 offset += 4;
636 /* authentication (length the number we just got) */
637 proto_tree_add_item(hdfs_tree, hf_hdfs_auth, tvb, offset, length, ENC_ASCII|ENC_NA);
638 offset += length;
641 /* data packets */
643 /* 4 bytes = length */
644 proto_tree_add_item(hdfs_tree, hf_hdfs_len, tvb, offset, 4, ENC_BIG_ENDIAN);
645 offset += 4;
647 /* 4 bytes = sequence number */
648 proto_tree_add_item(hdfs_tree, hf_hdfs_packetno, tvb, offset, 4, ENC_BIG_ENDIAN);
649 offset += 4;
651 /* dissect packet data */
652 dissect_data (tvb, hdfs_tree, offset);
656 return tvb_length(tvb);
659 /* determine PDU length of protocol */
660 static guint get_hdfs_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset _U_)
662 int len = tvb_reported_length(tvb);
664 if (tvb_reported_length(tvb) == 1448 || tvb_reported_length(tvb) == 1321) {
665 len = 150 * tvb_get_ntohs(tvb, 113) + 115 ;
668 return len;
672 static int
673 dissect_hdfs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
675 int frame_header_len = 0;
676 gboolean need_reassemble = FALSE;
678 frame_header_len = tvb_reported_length(tvb);
680 if (frame_header_len == 1448 || frame_header_len == 1321) {
681 need_reassemble = TRUE;
684 tcp_dissect_pdus(tvb, pinfo, tree, need_reassemble, frame_header_len, get_hdfs_message_len, dissect_hdfs_message, data);
685 return tvb_length(tvb);
688 /* registers the protcol with the given names */
689 void
690 proto_register_hdfs(void)
693 static hf_register_info hf[] = {
695 /* list of all options for dissecting the protocol */
697 /*************************************************
698 First packet
699 **************************************************/
700 { &hf_hdfs_sequenceno,
701 { "HDFS protocol type", "hdfs.type",
702 FT_STRING, BASE_NONE,
703 NULL, 0x0,
704 NULL, HFILL }
706 { &hf_hdfs_pdu_type,
707 { "HDFS protocol version", "hdfs.version",
708 FT_UINT8, BASE_DEC,
709 NULL, 0x0,
710 NULL, HFILL }
712 { &hf_hdfs_flags,
713 { "HDFS authentication type", "hdfs.auth_type",
714 FT_UINT8, BASE_DEC,
715 NULL, 0x0,
716 NULL, HFILL }
718 /***********************************************
719 Authentication packet
720 ***********************************************/
721 { &hf_hdfs_authlen,
722 { "HDFS authentication length", "hdfs.authlen",
723 FT_STRING, BASE_NONE,
724 NULL, 0x0,
725 NULL, HFILL }
727 { &hf_hdfs_auth,
728 { "HDFS authorization bits", "hdfs.auth",
729 FT_STRING, BASE_NONE,
730 NULL, 0x0,
731 NULL, HFILL }
733 /**********************************************
734 Response
735 **********************************************/
736 { &hf_hdfs_packetno,
737 { "HDFS packet number", "hdfs.seqno",
738 FT_UINT32, BASE_DEC,
739 NULL, 0x0,
740 NULL, HFILL }
742 { &hf_hdfs_success,
743 { "HDFS success", "hdfs.success",
744 FT_UINT32, BASE_DEC,
745 NULL, 0x0,
746 NULL, HFILL }
748 { &hf_hdfs_strcall,
749 { "HDFS method name", "hdfs.strcall",
750 FT_STRING, BASE_NONE,
751 NULL, 0x0,
752 NULL, HFILL }
754 #if 0
755 { &hf_hdfs_rest,
756 { "HDFS value", "hdfs.rest",
757 FT_STRING, BASE_NONE,
758 NULL, 0x0,
759 NULL, HFILL }
761 #endif
762 { &hf_hdfs_blockloc,
763 { "HDFS block location", "hdfs.blockloc",
764 FT_UINT64, BASE_DEC,
765 NULL, 0x0,
766 NULL, HFILL }
768 { &hf_hdfs_blocksize,
769 { "HDFS block size", "hdfs.blocksize",
770 FT_UINT64, BASE_DEC,
771 NULL, 0x0,
772 NULL, HFILL }
774 { &hf_hdfs_endblockloc,
775 { "HDFS file size", "hdfs.endblockloc",
776 FT_UINT64, BASE_DEC,
777 NULL, 0x0,
778 NULL, HFILL }
780 { &hf_hdfs_blockgen,
781 { "HDFS block gen", "hdfs.blockgen",
782 FT_UINT64, BASE_DEC,
783 NULL, 0x0,
784 NULL, HFILL }
786 { &hf_hdfs_prover,
787 { "HDFS protocol version", "hdfs.prover",
788 FT_UINT64, BASE_DEC,
789 NULL, 0x0,
790 NULL, HFILL }
792 { &hf_hdfs_objname,
793 { "HDFS object name", "hdfs.objname",
794 FT_STRING, BASE_NONE,
795 NULL, 0x0,
796 NULL, HFILL }
798 { &hf_hdfs_filename,
799 { "HDFS file name", "hdfs.filename",
800 FT_STRING, BASE_NONE,
801 NULL, 0x0,
802 NULL, HFILL }
804 { &hf_hdfs_blockcount,
805 { "HDFS block count", "hdfs.blockcount",
806 FT_UINT32, BASE_DEC,
807 NULL, 0x0,
808 NULL, HFILL }
810 { &hf_hdfs_ownername,
811 { "HDFS owner name", "hdfs.ownername",
812 FT_STRING, BASE_NONE,
813 NULL, 0x0,
814 NULL, HFILL }
816 { &hf_hdfs_groupname,
817 { "HDFS group name", "hdfs.groupname",
818 FT_STRING, BASE_NONE,
819 NULL, 0x0,
820 NULL, HFILL }
822 { &hf_hdfs_accesstime,
823 { "HDFS access time", "hdfs.accesstime",
824 FT_UINT64, BASE_DEC,
825 NULL, 0x0,
826 NULL, HFILL }
828 { &hf_hdfs_modtime,
829 { "HDFS modified time", "hdfs.modtime",
830 FT_UINT64, BASE_DEC,
831 NULL, 0x0,
832 NULL, HFILL }
834 { &hf_hdfs_blockrep,
835 { "HDFS block replication factor", "hdfs.blockrep",
836 FT_UINT16, BASE_DEC,
837 NULL, 0x0,
838 NULL, HFILL }
840 { &hf_hdfs_isdir,
841 { "HDFS is directory", "hdfs.isdir",
842 FT_UINT8, BASE_DEC,
843 NULL, 0x0,
844 NULL, HFILL }
846 { &hf_hdfs_filelen,
847 { "HDFS file length", "hdfs.filelen",
848 FT_UINT64, BASE_DEC,
849 NULL, 0x0,
850 NULL, HFILL }
852 { &hf_hdfs_construct,
853 { "HDFS under construction", "hdfs.construct",
854 FT_UINT8, BASE_DEC,
855 NULL, 0x0,
856 NULL, HFILL }
858 { &hf_hdfs_rackloc,
859 { "HDFS rack location", "hdfs.rackloc",
860 FT_STRING, BASE_NONE,
861 NULL, 0x0,
862 NULL, HFILL }
864 { &hf_hdfs_adminstate,
865 { "HDFS admin state", "hdfs.adminstate",
866 FT_STRING, BASE_NONE,
867 NULL, 0x0,
868 NULL, HFILL }
870 { &hf_hdfs_hostname,
871 { "HDFS hostname", "hdfs.hostname",
872 FT_STRING, BASE_NONE,
873 NULL, 0x0,
874 NULL, HFILL }
878 { &hf_hdfs_namelenone,
879 { "HDFS name length", "hdfs.namelenone",
880 FT_UINT8, BASE_DEC,
881 NULL, 0x0,
882 NULL, HFILL }
884 { &hf_hdfs_namelentwo,
885 { "HDFS name length", "hdfs.namelentwo",
886 FT_UINT16, BASE_DEC,
887 NULL, 0x0,
888 NULL, HFILL }
892 /***************************************
893 file info response
894 ***************************************/
895 { &hf_hdfs_activecon,
896 { "HDFS active connections", "hdfs.activecon",
897 FT_UINT32, BASE_DEC,
898 NULL, 0x0,
899 NULL, HFILL }
901 { &hf_hdfs_lastupdate,
902 { "HDFS lastupdate", "hdfs.lastupdate",
903 FT_UINT64, BASE_DEC,
904 NULL, 0x0,
905 NULL, HFILL }
907 { &hf_hdfs_remaining,
908 { "HDFS remaining", "hdfs.remaining",
909 FT_UINT64, BASE_DEC,
910 NULL, 0x0,
911 NULL, HFILL }
913 { &hf_hdfs_dfsused,
914 { "HDFS dfs used", "hdfs.dfsused",
915 FT_UINT64, BASE_DEC,
916 NULL, 0x0,
917 NULL, HFILL }
919 { &hf_hdfs_capacity,
920 { "HDFS capacity", "hdfs.capacity",
921 FT_UINT64, BASE_DEC,
922 NULL, 0x0,
923 NULL, HFILL }
925 { &hf_hdfs_ipcport,
926 { "HDFS ipcport", "hdfs.ipcport",
927 FT_UINT16, BASE_DEC,
928 NULL, 0x0,
929 NULL, HFILL }
931 { &hf_hdfs_infoport,
932 { "HDFS info port", "hdfs.infoport",
933 FT_UINT16, BASE_DEC,
934 NULL, 0x0,
935 NULL, HFILL }
937 { &hf_hdfs_storageid,
938 { "HDFS storage id", "hdfs.storageid",
939 FT_STRING, BASE_NONE,
940 NULL, 0x0,
941 NULL, HFILL }
943 { &hf_hdfs_datanodeid,
944 { "HDFS datanodeid", "hdfs.datanodeid",
945 FT_STRING, BASE_NONE,
946 NULL, 0x0,
947 NULL, HFILL }
949 { &hf_hdfs_locations,
950 { "HDFS locations", "hdfs.locations",
951 FT_UINT32, BASE_DEC,
952 NULL, 0x0,
953 NULL, HFILL }
956 { &hf_hdfs_identifier,
957 { "HDFS locations", "hdfs.identifier",
958 FT_STRING, BASE_NONE,
959 NULL, 0x0,
960 NULL, HFILL }
962 { &hf_hdfs_password,
963 { "HDFS password", "hdfs.password",
964 FT_STRING, BASE_NONE,
965 NULL, 0x0,
966 NULL, HFILL }
968 { &hf_hdfs_kind,
969 { "HDFS kind", "hdfs.kind",
970 FT_STRING, BASE_NONE,
971 NULL, 0x0,
972 NULL, HFILL }
974 { &hf_hdfs_service,
975 { "HDFS locations", "hdfs.service",
976 FT_STRING, BASE_NONE,
977 NULL, 0x0,
978 NULL, HFILL }
980 { &hf_hdfs_corrupt,
981 { "HDFS corrupt", "hdfs.corrupt",
982 FT_UINT8, BASE_DEC,
983 NULL, 0x0,
984 NULL, HFILL }
986 { &hf_hdfs_offset,
987 { "HDFS offset", "hdfs.offset",
988 FT_UINT64, BASE_DEC,
989 NULL, 0x0,
990 NULL, HFILL }
994 /***********************************************
995 Data request
996 ***********************************************/
997 { &hf_hdfs_len,
998 { "HDFS length", "hdfs.len",
999 FT_UINT32, BASE_DEC,
1000 NULL, 0x0,
1001 NULL, HFILL }
1003 /* packet number, same as in response
1004 method name length, same as in response
1005 string call, same as in response */
1006 { &hf_hdfs_params,
1007 { "HDFS number of parameters", "hdfs.params",
1008 FT_UINT32, BASE_DEC,
1009 NULL, 0x0,
1010 NULL, HFILL }
1012 { &hf_hdfs_paramtype,
1013 { "HDFS parameter type", "hdfs.paramtype",
1014 FT_STRING, BASE_NONE,
1015 NULL, 0x0,
1016 NULL, HFILL }
1018 { &hf_hdfs_paramval,
1019 { "HDFS parameter value", "hdfs.paramval",
1020 FT_STRING, BASE_NONE,
1021 NULL, 0x0,
1022 NULL, HFILL }
1024 /* param value that is displayed as a number not a string */
1025 { &hf_hdfs_paramvalnum,
1026 { "HDFS parameter value", "hdfs.paramvalnum",
1027 FT_INT64, BASE_DEC,
1028 NULL, 0x0,
1029 NULL, HFILL }
1031 { &hf_hdfs_fileperm,
1032 { "HDFS File permission", "hdfs.fileperm",
1033 FT_INT16, BASE_DEC,
1034 NULL, 0x0,
1035 NULL, HFILL }
1040 /* Setup protocol subtree array */
1041 static gint *ett[] = {
1042 &ett_hdfs
1045 module_t *hdfs_module;
1047 proto_hdfs = proto_register_protocol (
1048 "HDFS Protocol", /* name */
1049 "HDFS", /* short name */
1050 "hdfs" /* abbrev */
1053 proto_register_field_array(proto_hdfs, hf, array_length(hf));
1054 proto_register_subtree_array(ett, array_length(ett));
1056 hdfs_module = prefs_register_protocol(proto_hdfs, proto_reg_handoff_hdfs);
1058 prefs_register_uint_preference(hdfs_module,
1059 "tcp.port",
1060 "TCP port for HDFS",
1061 "Set the TCP port for HDFS",
1063 &tcp_port);
1065 hdfs_handle = new_register_dissector("hdfs", dissect_hdfs, proto_hdfs);
1068 /* registers handoff */
1069 void
1070 proto_reg_handoff_hdfs(void)
1072 static gboolean initialized = FALSE;
1073 static guint saved_tcp_port;
1075 if (!initialized) {
1076 dissector_add_handle("tcp.port", hdfs_handle); /* for "decode as" */
1077 initialized = TRUE;
1078 } else if (saved_tcp_port != 0) {
1079 dissector_delete_uint("tcp.port", saved_tcp_port, hdfs_handle);
1082 if (tcp_port != 0) {
1083 dissector_add_uint("tcp.port", tcp_port, hdfs_handle);
1086 saved_tcp_port = tcp_port;
1089 * Editor modelines
1091 * Local Variables:
1092 * c-basic-offset: 4
1093 * tab-width: 8
1094 * indent-tabs-mode: nil
1095 * End:
1097 * ex: set shiftwidth=4 tabstop=8 expandtab:
1098 * :indentSize=4:tabSize=8:noTabs=true: