From 5f469a9e5aa5510f9ff9aa60b8f3606c3b65f590 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 6 Apr 2007 05:02:41 +0000 Subject: [PATCH] update of dissector to reflect wire format changes svn path=/trunk/; revision=21345 --- epan/dissectors/packet-ctdb.c | 95 +++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 22 deletions(-) diff --git a/epan/dissectors/packet-ctdb.c b/epan/dissectors/packet-ctdb.c index c131e6e73d..a8a6788aae 100644 --- a/epan/dissectors/packet-ctdb.c +++ b/epan/dissectors/packet-ctdb.c @@ -43,6 +43,8 @@ static int proto_ctdb = -1; static int hf_ctdb_length = -1; static int hf_ctdb_opcode = -1; +static int hf_ctdb_magic = -1; +static int hf_ctdb_version = -1; static int hf_ctdb_dst = -1; static int hf_ctdb_src = -1; static int hf_ctdb_id = -1; @@ -77,14 +79,14 @@ static const value_string ctdb_opcodes[] = { static int -dissect_ctdb_reply_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) +dissect_ctdb_reply_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int endianess) { /* status */ - proto_tree_add_item(tree, hf_ctdb_status, tvb, offset, 4, TRUE); + proto_tree_add_item(tree, hf_ctdb_status, tvb, offset, 4, endianess); offset+=4; /* datalen */ - proto_tree_add_item(tree, hf_ctdb_datalen, tvb, offset, 4, TRUE); + proto_tree_add_item(tree, hf_ctdb_datalen, tvb, offset, 4, endianess); offset+=4; /* data */ @@ -93,10 +95,10 @@ dissect_ctdb_reply_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto } static int -dissect_ctdb_reply_dmaster(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) +dissect_ctdb_reply_dmaster(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int endianess) { /* datalen */ - proto_tree_add_item(tree, hf_ctdb_datalen, tvb, offset, 4, TRUE); + proto_tree_add_item(tree, hf_ctdb_datalen, tvb, offset, 4, endianess); offset+=4; /* data */ @@ -110,13 +112,17 @@ static const true_false_string flags_immediate_tfs={ }; static int -dissect_ctdb_req_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) +dissect_ctdb_req_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int endianess) { guint32 flags; /* flags */ - proto_tree_add_item(tree, hf_ctdb_flags_immediate, tvb, offset, 4, TRUE); - flags=tvb_get_letohl(tvb, offset); + proto_tree_add_item(tree, hf_ctdb_flags_immediate, tvb, offset, 4, endianess); + if(endianess){ + flags=tvb_get_letohl(tvb, offset); + } else { + flags=tvb_get_ntohl(tvb, offset); + } if(flags&0x00000001){ if(check_col(pinfo->cinfo, COL_INFO)){ col_append_fstr(pinfo->cinfo, COL_INFO, " IMMEDIATE"); @@ -125,11 +131,11 @@ dissect_ctdb_req_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree offset+=4; /* dbid */ - proto_tree_add_item(tree, hf_ctdb_dbid, tvb, offset, 4, TRUE); + proto_tree_add_item(tree, hf_ctdb_dbid, tvb, offset, 4, endianess); offset+=4; /* callid */ - proto_tree_add_item(tree, hf_ctdb_callid, tvb, offset, 4, TRUE); + proto_tree_add_item(tree, hf_ctdb_callid, tvb, offset, 4, endianess); offset+=4; /* keylen */ @@ -146,6 +152,23 @@ dissect_ctdb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) proto_item *item=NULL; int offset=0; guint32 opcode, src, dst; + int endianess; + + /* does this look like CTDB? */ + if(tvb_length_remaining(tvb, offset)<8){ + return FALSE; + } + switch(tvb_get_letohl(tvb, offset+4)){ + case 0x42445443: + endianess=FALSE; + break; + case 0x43544442: + endianess=TRUE; + break; + default: + return FALSE; + } + if(check_col(pinfo->cinfo, COL_PROTOCOL)){ col_set_str(pinfo->cinfo, COL_PROTOCOL, "CTDB"); @@ -156,32 +179,52 @@ dissect_ctdb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) if(parent_tree){ item=proto_tree_add_item(parent_tree, proto_ctdb, tvb, offset, - -1, TRUE); + -1, endianess); tree=proto_item_add_subtree(item, ett_ctdb); } /* header*/ /* length */ - proto_tree_add_item(tree, hf_ctdb_length, tvb, offset, 4, TRUE); + proto_tree_add_item(tree, hf_ctdb_length, tvb, offset, 4, endianess); + offset+=4; + + /* magic */ + proto_tree_add_item(tree, hf_ctdb_magic, tvb, offset, 4, endianess); + offset+=4; + + /* version */ + proto_tree_add_item(tree, hf_ctdb_version, tvb, offset, 4, endianess); offset+=4; /* opcode */ - proto_tree_add_item(tree, hf_ctdb_opcode, tvb, offset, 4, TRUE); - opcode=tvb_get_letohl(tvb, offset); + proto_tree_add_item(tree, hf_ctdb_opcode, tvb, offset, 4, endianess); + if(endianess){ + opcode=tvb_get_letohl(tvb, offset); + } else { + opcode=tvb_get_ntohl(tvb, offset); + } offset+=4; /* dst */ - proto_tree_add_item(tree, hf_ctdb_dst, tvb, offset, 4, TRUE); - dst=tvb_get_letohl(tvb, offset); + proto_tree_add_item(tree, hf_ctdb_dst, tvb, offset, 4, endianess); + if(endianess){ + dst=tvb_get_letohl(tvb, offset); + } else { + dst=tvb_get_ntohl(tvb, offset); + } offset+=4; /* src */ - proto_tree_add_item(tree, hf_ctdb_src, tvb, offset, 4, TRUE); - src=tvb_get_letohl(tvb, offset); + proto_tree_add_item(tree, hf_ctdb_src, tvb, offset, 4, endianess); + if(endianess){ + src=tvb_get_letohl(tvb, offset); + } else { + src=tvb_get_ntohl(tvb, offset); + } offset+=4; /* id */ - proto_tree_add_item(tree, hf_ctdb_id, tvb, offset, 4, TRUE); + proto_tree_add_item(tree, hf_ctdb_id, tvb, offset, 4, endianess); offset+=4; if(check_col(pinfo->cinfo, COL_INFO)){ @@ -192,13 +235,13 @@ dissect_ctdb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) switch(opcode){ case CTDB_REQ_CALL: - offset=dissect_ctdb_req_call(tvb, offset, pinfo, tree); + offset=dissect_ctdb_req_call(tvb, offset, pinfo, tree, endianess); break; case CTDB_REPLY_CALL: - offset=dissect_ctdb_reply_call(tvb, offset, pinfo, tree); + offset=dissect_ctdb_reply_call(tvb, offset, pinfo, tree, endianess); break; case CTDB_REPLY_DMASTER: - offset=dissect_ctdb_reply_dmaster(tvb, offset, pinfo, tree); + offset=dissect_ctdb_reply_dmaster(tvb, offset, pinfo, tree, endianess); break; case CTDB_REPLY_REDIRECT: break; @@ -251,6 +294,12 @@ proto_register_ctdb(void) { &hf_ctdb_datalen, { "Data Length", "ctdb.datalen", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }}, + { &hf_ctdb_magic, { + "Magic", "ctdb.magic", FT_UINT32, BASE_HEX, + NULL, 0x0, "", HFILL }}, + { &hf_ctdb_version, { + "Version", "ctdb.version", FT_UINT32, BASE_DEC, + NULL, 0x0, "", HFILL }}, }; /* Setup protocol subtree array */ @@ -274,4 +323,6 @@ proto_reg_handoff_ctdb(void) ctdb_handle = new_create_dissector_handle(dissect_ctdb, proto_ctdb); dissector_add_handle("tcp.port", ctdb_handle); + + heur_dissector_add("tcp", dissect_ctdb, proto_ctdb); }