2009-03-03 19:51:08 +00:00
|
|
|
/* packet-ziop.c
|
|
|
|
* Routines for CORBA ZIOP packet disassembly
|
|
|
|
* Significantly based on packet-giop.c
|
|
|
|
* Copyright 2009 Alvaro Vega Garcia <avega at tid dot es>
|
|
|
|
*
|
|
|
|
* According with GIOP Compression RFP revised submission
|
|
|
|
* OMG mars/2008-12-20
|
2009-07-14 19:13:14 +00:00
|
|
|
* http://www.omg.org/docs/ptc/09-01-03.pdf
|
2009-03-03 19:51:08 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/conversation.h>
|
|
|
|
|
|
|
|
#include "packet-ziop.h"
|
|
|
|
#include "packet-giop.h"
|
|
|
|
#include "packet-tcp.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set to 1 for DEBUG output - TODO make this a runtime option
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEBUG 0
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ------------------------------------------------------------------------------------------+
|
|
|
|
* Data/Variables/Structs
|
|
|
|
* ------------------------------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int proto_ziop = -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (sub)Tree declares
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gint hf_ziop_magic = -1;
|
|
|
|
static gint hf_ziop_giop_version_major = -1;
|
|
|
|
static gint hf_ziop_giop_version_minor = -1;
|
|
|
|
static gint hf_ziop_flags = -1;
|
|
|
|
static gint hf_ziop_message_type = -1;
|
|
|
|
static gint hf_ziop_message_size = -1;
|
|
|
|
static gint hf_ziop_compressor_id = -1;
|
|
|
|
static gint hf_ziop_original_length = -1;
|
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
static gint ett_ziop = -1;
|
2009-03-03 19:51:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
static dissector_handle_t data_handle;
|
2009-03-05 04:32:08 +00:00
|
|
|
static dissector_handle_t ziop_tcp_handle;
|
2009-03-03 19:51:08 +00:00
|
|
|
|
|
|
|
|
2010-05-13 18:28:34 +00:00
|
|
|
static const value_string ziop_compressor_ids[] = {
|
2009-03-03 19:51:08 +00:00
|
|
|
{ 0, "None" },
|
|
|
|
{ 1, "GZIP"},
|
|
|
|
{ 2, "PKZIP"},
|
|
|
|
{ 3, "BZIP2"},
|
|
|
|
{ 4, "ZLIB"},
|
|
|
|
{ 5, "LZMA"},
|
|
|
|
{ 6, "LZOP"},
|
|
|
|
{ 7, "RZIP"},
|
|
|
|
{ 8, "7X"},
|
|
|
|
{ 9, "XAR"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const value_string giop_message_types[] = {
|
2011-04-21 22:49:36 +00:00
|
|
|
{ 0x0, "Request" },
|
|
|
|
{ 0x1, "Reply"},
|
|
|
|
{ 0x2, "CancelRequest"},
|
|
|
|
{ 0x3, "LocateRequest"},
|
|
|
|
{ 0x4, "LocateReply"},
|
|
|
|
{ 0x5, "CloseConnection"},
|
|
|
|
{ 0x6, "MessageError"},
|
|
|
|
{ 0x7, "Fragment"},
|
|
|
|
{ 0, NULL}
|
2009-03-03 19:51:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-06 19:48:05 +00:00
|
|
|
static gboolean ziop_desegment = TRUE;
|
2009-03-03 19:51:08 +00:00
|
|
|
|
2009-03-05 16:41:50 +00:00
|
|
|
static void dissect_ziop (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree);
|
2009-03-03 19:51:08 +00:00
|
|
|
|
|
|
|
static guint
|
|
|
|
get_ziop_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
|
|
|
|
{
|
2009-07-14 19:13:14 +00:00
|
|
|
guint8 flags;
|
2009-03-03 19:51:08 +00:00
|
|
|
guint message_size;
|
|
|
|
gboolean stream_is_big_endian;
|
|
|
|
|
|
|
|
if ( tvb_memeql(tvb, 0, ZIOP_MAGIC, 4) != 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
flags = tvb_get_guint8(tvb, offset + 6);
|
2010-05-13 18:28:34 +00:00
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
stream_is_big_endian = ((flags & 0x1) == 0);
|
2010-05-13 18:28:34 +00:00
|
|
|
|
2009-03-03 19:51:08 +00:00
|
|
|
if (stream_is_big_endian)
|
2009-07-14 19:13:14 +00:00
|
|
|
message_size = tvb_get_ntohl(tvb, offset + 8);
|
2009-03-03 19:51:08 +00:00
|
|
|
else
|
2009-07-14 19:13:14 +00:00
|
|
|
message_size = tvb_get_letohl(tvb, offset + 8);
|
2010-05-13 18:28:34 +00:00
|
|
|
|
2009-03-03 19:51:08 +00:00
|
|
|
return message_size + ZIOP_HEADER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_ziop_tcp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree) {
|
2010-05-13 18:28:34 +00:00
|
|
|
|
2009-03-03 19:51:08 +00:00
|
|
|
if ( tvb_memeql(tvb, 0, ZIOP_MAGIC ,4) != 0) {
|
|
|
|
|
|
|
|
if ( tvb_memeql(tvb, 0, GIOP_MAGIC ,4) == 0)
|
|
|
|
dissect_giop(tvb, pinfo, tree);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tcp_dissect_pdus(tvb, pinfo, tree, ziop_desegment, ZIOP_HEADER_SIZE,
|
|
|
|
get_ziop_pdu_len, dissect_ziop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
dissect_ziop_heur (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree) {
|
|
|
|
|
|
|
|
guint tot_len;
|
|
|
|
|
|
|
|
conversation_t *conversation;
|
|
|
|
/* check magic number and version */
|
|
|
|
|
|
|
|
|
|
|
|
tot_len = tvb_length(tvb);
|
|
|
|
|
|
|
|
|
|
|
|
if (tot_len < ZIOP_HEADER_SIZE) /* tot_len < 12 */
|
|
|
|
{
|
|
|
|
/* Not enough data captured to hold the ZIOP header; don't try
|
|
|
|
to interpret it as GIOP. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ( tvb_memeql(tvb, 0, ZIOP_MAGIC, 4) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pinfo->ptype == PT_TCP )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Make the ZIOP dissector the dissector for this conversation.
|
|
|
|
*
|
|
|
|
* If this isn't the first time this packet has been processed,
|
|
|
|
* we've already done this work, so we don't need to do it
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
if (!pinfo->fd->flags.visited)
|
|
|
|
{
|
2010-05-13 18:28:34 +00:00
|
|
|
conversation = find_or_create_conversation(pinfo);
|
|
|
|
|
2009-03-03 19:51:08 +00:00
|
|
|
/* Set dissector */
|
2009-03-05 04:32:08 +00:00
|
|
|
conversation_set_dissector(conversation, ziop_tcp_handle);
|
2011-04-21 22:49:36 +00:00
|
|
|
}
|
2009-03-03 19:51:08 +00:00
|
|
|
dissect_ziop_tcp (tvb, pinfo, tree);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dissect_ziop (tvb, pinfo, tree);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Main entry point */
|
2010-05-13 18:28:34 +00:00
|
|
|
static void
|
2009-03-05 16:41:50 +00:00
|
|
|
dissect_ziop (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree) {
|
2009-03-03 19:51:08 +00:00
|
|
|
guint offset = 0;
|
2009-07-14 19:13:14 +00:00
|
|
|
guint8 giop_version_major, giop_version_minor, message_type;
|
2010-05-13 18:28:34 +00:00
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
proto_tree *ziop_tree = NULL;
|
2009-03-03 19:51:08 +00:00
|
|
|
proto_item *ti;
|
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
col_set_str (pinfo->cinfo, COL_PROTOCOL, ZIOP_MAGIC);
|
2009-03-03 19:51:08 +00:00
|
|
|
|
|
|
|
/* Clear out stuff in the info column */
|
2009-07-14 19:13:14 +00:00
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
2009-03-03 19:51:08 +00:00
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
giop_version_major = tvb_get_guint8(tvb, 4);
|
|
|
|
giop_version_minor = tvb_get_guint8(tvb, 5);
|
|
|
|
message_type = tvb_get_guint8(tvb, 7);
|
2009-03-03 19:51:08 +00:00
|
|
|
|
2010-05-13 18:28:34 +00:00
|
|
|
if ( (giop_version_major < 1) ||
|
2009-07-15 21:30:37 +00:00
|
|
|
(giop_version_minor < 2) ) /* earlier than GIOP 1.2 */
|
2009-03-03 19:51:08 +00:00
|
|
|
{
|
2009-07-14 19:13:14 +00:00
|
|
|
col_add_fstr (pinfo->cinfo, COL_INFO, "Version %u.%u",
|
2011-04-21 22:49:36 +00:00
|
|
|
giop_version_major, giop_version_minor);
|
2009-03-03 19:51:08 +00:00
|
|
|
if (tree)
|
2011-04-21 22:49:36 +00:00
|
|
|
{
|
|
|
|
ti = proto_tree_add_item (tree, proto_ziop, tvb, 0, -1, FALSE);
|
|
|
|
ziop_tree = proto_item_add_subtree (ti, ett_ziop);
|
|
|
|
proto_tree_add_text (ziop_tree, tvb, 4, 2,
|
|
|
|
"Version %u.%u not supported",
|
|
|
|
giop_version_major,
|
|
|
|
giop_version_minor);
|
|
|
|
}
|
2009-03-03 19:51:08 +00:00
|
|
|
call_dissector(data_handle, tvb, pinfo, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-13 18:28:34 +00:00
|
|
|
col_add_fstr (pinfo->cinfo, COL_INFO, "ZIOP %u.%u %s",
|
2011-04-21 22:49:36 +00:00
|
|
|
giop_version_major,
|
|
|
|
giop_version_minor,
|
|
|
|
val_to_str(message_type, giop_message_types,
|
|
|
|
"Unknown message type (0x%02x)")
|
|
|
|
);
|
2009-03-03 19:51:08 +00:00
|
|
|
|
|
|
|
if (tree)
|
|
|
|
{
|
2009-07-14 19:13:14 +00:00
|
|
|
guint8 flags;
|
|
|
|
gboolean little_endian;
|
|
|
|
emem_strbuf_t *flags_strbuf = ep_strbuf_new_label("none");
|
|
|
|
|
2009-03-03 19:51:08 +00:00
|
|
|
ti = proto_tree_add_item (tree, proto_ziop, tvb, 0, -1, FALSE);
|
2009-07-14 19:13:14 +00:00
|
|
|
ziop_tree = proto_item_add_subtree (ti, ett_ziop);
|
2009-03-03 19:51:08 +00:00
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
proto_tree_add_item(ziop_tree, hf_ziop_magic, tvb, offset, 4, FALSE);
|
2009-03-03 19:51:08 +00:00
|
|
|
offset += 4;
|
2009-07-14 19:13:14 +00:00
|
|
|
proto_tree_add_item(ziop_tree, hf_ziop_giop_version_major, tvb, offset, 1, FALSE);
|
2009-03-03 19:51:08 +00:00
|
|
|
offset++;
|
2009-07-14 19:13:14 +00:00
|
|
|
proto_tree_add_item(ziop_tree, hf_ziop_giop_version_minor, tvb, offset, 1, FALSE);
|
2009-03-03 19:51:08 +00:00
|
|
|
offset++;
|
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
flags = tvb_get_guint8(tvb, offset);
|
|
|
|
little_endian = flags & 0x01;
|
2009-03-03 19:51:08 +00:00
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
if (flags & 0x01) {
|
2011-04-21 22:49:36 +00:00
|
|
|
ep_strbuf_printf(flags_strbuf, "little-endian");
|
2009-07-14 19:13:14 +00:00
|
|
|
}
|
2011-05-19 20:21:08 +00:00
|
|
|
proto_tree_add_uint_format_value(ziop_tree, hf_ziop_flags, tvb, offset, 1,
|
2011-04-21 22:49:36 +00:00
|
|
|
flags, "0x%02x (%s)", flags, flags_strbuf->str);
|
2009-07-14 19:13:14 +00:00
|
|
|
offset++;
|
2009-03-03 19:51:08 +00:00
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
proto_tree_add_item(ziop_tree, hf_ziop_message_type, tvb, offset, 1, FALSE);
|
|
|
|
offset++;
|
2009-03-03 19:51:08 +00:00
|
|
|
|
2009-07-14 19:13:14 +00:00
|
|
|
proto_tree_add_item(ziop_tree, hf_ziop_message_size, tvb, offset, 4, little_endian);
|
|
|
|
offset += 4;
|
|
|
|
proto_tree_add_item(ziop_tree, hf_ziop_compressor_id, tvb, offset, 2, little_endian);
|
|
|
|
offset += 4;
|
|
|
|
proto_tree_add_item(ziop_tree, hf_ziop_original_length, tvb, offset, 4, little_endian);
|
|
|
|
}
|
2009-03-03 19:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void proto_register_ziop (void) {
|
|
|
|
|
|
|
|
|
|
|
|
/* A header field is something you can search/filter on.
|
2010-05-13 18:28:34 +00:00
|
|
|
*
|
2009-03-03 19:51:08 +00:00
|
|
|
* We create a structure to register our fields. It consists of an
|
|
|
|
* array of hf_register_info structures, each of which are of the format
|
|
|
|
* {&(field id), {name, abbrev, type, display, strings, bitmask, blurb, HFILL}}.
|
|
|
|
*/
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_ziop_magic,
|
2009-07-14 19:13:14 +00:00
|
|
|
{ "Header magic", "ziop.magic", FT_STRING, BASE_NONE, NULL, 0x0,
|
2009-03-03 19:51:08 +00:00
|
|
|
"ZIOPHeader magic", HFILL }},
|
|
|
|
{ &hf_ziop_giop_version_major,
|
|
|
|
{ "Header major version", "ziop.giop_version_major", FT_UINT8, BASE_OCT, NULL, 0x0,
|
2009-03-05 16:41:50 +00:00
|
|
|
"ZIOPHeader giop_major_version", HFILL }},
|
2009-03-03 19:51:08 +00:00
|
|
|
{ &hf_ziop_giop_version_minor,
|
|
|
|
{ "Header minor version", "ziop.giop_version_minor", FT_UINT8, BASE_OCT, NULL, 0x0,
|
2009-03-05 16:41:50 +00:00
|
|
|
"ZIOPHeader giop_minor_version", HFILL }},
|
2009-03-03 19:51:08 +00:00
|
|
|
{ &hf_ziop_flags,
|
|
|
|
{ "Header flags", "ziop.flags", FT_UINT8, BASE_OCT, NULL, 0x0,
|
|
|
|
"ZIOPHeader flags", HFILL }},
|
|
|
|
{ &hf_ziop_message_type,
|
2009-07-14 19:13:14 +00:00
|
|
|
{ "Header type", "ziop.message_type", FT_UINT8, BASE_OCT, VALS(giop_message_types), 0x0,
|
2009-03-03 19:51:08 +00:00
|
|
|
"ZIOPHeader message_type", HFILL }},
|
|
|
|
{ &hf_ziop_message_size,
|
|
|
|
{ "Header size", "ziop.message_size", FT_UINT32, BASE_DEC, NULL, 0x0,
|
|
|
|
"ZIOPHeader message_size", HFILL }},
|
|
|
|
{ &hf_ziop_compressor_id,
|
2009-07-14 19:13:14 +00:00
|
|
|
{ "Header compressor id", "ziop.compressor_id", FT_UINT16, BASE_DEC, VALS(ziop_compressor_ids), 0x0,
|
2009-03-03 19:51:08 +00:00
|
|
|
"ZIOPHeader compressor_id", HFILL }},
|
|
|
|
{ &hf_ziop_original_length,
|
|
|
|
{ "Header original length", "ziop.original_length", FT_UINT32, BASE_DEC, NULL, 0x0,
|
|
|
|
"ZIOP original_length", HFILL }},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
2009-07-14 19:13:14 +00:00
|
|
|
&ett_ziop,
|
2009-03-03 19:51:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
proto_ziop = proto_register_protocol("Zipped Inter-ORB Protocol", "ZIOP",
|
2011-04-21 22:49:36 +00:00
|
|
|
"ziop");
|
2009-07-14 19:13:14 +00:00
|
|
|
proto_register_field_array (proto_ziop, hf, array_length (hf));
|
2009-03-03 19:51:08 +00:00
|
|
|
proto_register_subtree_array (ett, array_length (ett));
|
|
|
|
|
|
|
|
register_dissector("ziop", dissect_ziop, proto_ziop);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void proto_reg_handoff_ziop (void) {
|
|
|
|
|
2009-03-05 04:32:08 +00:00
|
|
|
ziop_tcp_handle = create_dissector_handle(dissect_ziop_tcp, proto_ziop);
|
|
|
|
dissector_add_handle("udp.port", ziop_tcp_handle); /* For 'Decode As' */
|
2010-05-13 18:28:34 +00:00
|
|
|
|
2009-03-03 19:51:08 +00:00
|
|
|
heur_dissector_add("tcp", dissect_ziop_heur, proto_ziop);
|
|
|
|
|
2009-03-05 04:10:45 +00:00
|
|
|
data_handle = find_dissector("data");
|
2009-03-03 19:51:08 +00:00
|
|
|
}
|