diff options
author | Bill Meier <wmeier@newsguy.com> | 2012-03-16 02:24:57 +0000 |
---|---|---|
committer | Bill Meier <wmeier@newsguy.com> | 2012-03-16 02:24:57 +0000 |
commit | 43402e0119db7ec22ffb30f72296a11d0f7488de (patch) | |
tree | 235e000bd6e6b4855ee79948e2b9d68df3e9e45b | |
parent | a2c94ef9bfe13ca7599a9596b4aa0a1b559d64ea (diff) |
FT_BOOLEAN hf[] entry with a 0 'bitmask' should have 'display' = BASE_NONE;
Reformat long lines;
Use consistent indentation;
Do some general whitespace changes.
svn path=/trunk/; revision=41589
-rw-r--r-- | asn1/idmp/packet-idmp-template.c | 443 | ||||
-rw-r--r-- | epan/dissectors/packet-idmp.c | 447 |
2 files changed, 444 insertions, 446 deletions
diff --git a/asn1/idmp/packet-idmp-template.c b/asn1/idmp/packet-idmp-template.c index ebcf846e7d..3dc3648360 100644 --- a/asn1/idmp/packet-idmp-template.c +++ b/asn1/idmp/packet-idmp-template.c @@ -1,6 +1,6 @@ /* packet-idmp.c * Routines for X.519 Internet Directly Mapped Procotol (IDMP) packet dissection - * Graeme Lunt 2020 + * Graeme Lunt 2010 * * $Id$ * @@ -48,16 +48,16 @@ #define PSNAME "IDMP" #define PFNAME "idmp" -static gboolean idmp_desegment = TRUE; -static guint global_idmp_tcp_port = 1102; /* made up for now */ -static gboolean idmp_reassemble = TRUE; -static guint tcp_port = 0; -static dissector_handle_t idmp_handle = NULL; +static gboolean idmp_desegment = TRUE; +static guint global_idmp_tcp_port = 1102; /* made up for now */ +static gboolean idmp_reassemble = TRUE; +static guint tcp_port = 0; +static dissector_handle_t idmp_handle = NULL; -static proto_tree *top_tree = NULL; -static const char *protocolID = NULL; +static proto_tree *top_tree = NULL; +static const char *protocolID = NULL; static const char *saved_protocolID = NULL; -static guint32 opcode = -1; +static guint32 opcode = -1; static void prefs_register_idmp(void); /* forward declaration for use in preferences registration */ @@ -69,7 +69,7 @@ static int hf_idmp_final = -1; static int hf_idmp_length = -1; static int hf_idmp_PDU = -1; -static GHashTable *idmp_segment_table = NULL; +static GHashTable *idmp_segment_table = NULL; static GHashTable *idmp_reassembled_table = NULL; static int hf_idmp_fragments = -1; @@ -87,44 +87,44 @@ static gint ett_idmp_fragment = -1; static gint ett_idmp_fragments = -1; static const fragment_items idmp_frag_items = { - /* Fragment subtrees */ - &ett_idmp_fragment, - &ett_idmp_fragments, - /* Fragment fields */ - &hf_idmp_fragments, - &hf_idmp_fragment, - &hf_idmp_fragment_overlap, - &hf_idmp_fragment_overlap_conflicts, - &hf_idmp_fragment_multiple_tails, - &hf_idmp_fragment_too_long_fragment, - &hf_idmp_fragment_error, - &hf_idmp_fragment_count, - /* Reassembled in field */ - &hf_idmp_reassembled_in, - /* Reassembled length field */ - &hf_idmp_reassembled_length, - /* Tag */ - "IDMP fragments" + /* Fragment subtrees */ + &ett_idmp_fragment, + &ett_idmp_fragments, + /* Fragment fields */ + &hf_idmp_fragments, + &hf_idmp_fragment, + &hf_idmp_fragment_overlap, + &hf_idmp_fragment_overlap_conflicts, + &hf_idmp_fragment_multiple_tails, + &hf_idmp_fragment_too_long_fragment, + &hf_idmp_fragment_error, + &hf_idmp_fragment_count, + /* Reassembled in field */ + &hf_idmp_reassembled_in, + /* Reassembled length field */ + &hf_idmp_reassembled_length, + /* Tag */ + "IDMP fragments" }; static int call_idmp_oid_callback(tvbuff_t *tvb, int offset, packet_info *pinfo, int op, proto_tree *tree _U_) { - struct SESSION_DATA_STRUCTURE *session; + struct SESSION_DATA_STRUCTURE *session; - if((session = (struct SESSION_DATA_STRUCTURE*)pinfo->private_data) != NULL) { + if((session = (struct SESSION_DATA_STRUCTURE*)pinfo->private_data) != NULL) { - if((!saved_protocolID) && (op == (ROS_OP_BIND | ROS_OP_RESULT))) { - /* save for subsequent operations - should be into session data */ - saved_protocolID = se_strdup(protocolID); - } + if((!saved_protocolID) && (op == (ROS_OP_BIND | ROS_OP_RESULT))) { + /* save for subsequent operations - should be into session data */ + saved_protocolID = se_strdup(protocolID); + } - /* mimic ROS! */ - session->ros_op = op; - offset = call_ros_oid_callback(saved_protocolID ? saved_protocolID : protocolID, tvb, offset, pinfo, top_tree); - } + /* mimic ROS! */ + session->ros_op = op; + offset = call_ros_oid_callback(saved_protocolID ? saved_protocolID : protocolID, tvb, offset, pinfo, top_tree); + } - return offset; + return offset; } @@ -139,230 +139,229 @@ static gint ett_idmp = -1; void register_idmp_protocol_info(const char *oid, const ros_info_t *rinfo, int proto _U_, const char *name) { - /* just register with ROS for now */ - register_ros_protocol_info(oid, rinfo, proto, name, FALSE); + /* just register with ROS for now */ + register_ros_protocol_info(oid, rinfo, proto, name, FALSE); } static void dissect_idmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) { - int offset = 0; + int offset = 0; - proto_item *item=NULL; - proto_tree *tree=NULL; - asn1_ctx_t asn1_ctx; - void *save_private_data; - struct SESSION_DATA_STRUCTURE session; - gboolean idmp_final; - guint32 idmp_length; - fragment_data *fd_head; - conversation_t *conv; - guint32 dst_ref = 0; + proto_item *item = NULL; + proto_tree *tree = NULL; + asn1_ctx_t asn1_ctx; + void *save_private_data; + struct SESSION_DATA_STRUCTURE session; + gboolean idmp_final; + guint32 idmp_length; + fragment_data *fd_head; + conversation_t *conv; + guint32 dst_ref = 0; - asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo); + asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo); conv = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst, - pinfo->ptype, pinfo->srcport, pinfo->destport, 0); + pinfo->ptype, pinfo->srcport, pinfo->destport, 0); if (conv) { - /* Found a conversation, also use index for the generated dst_ref */ - dst_ref = conv->index; + /* Found a conversation, also use index for the generated dst_ref */ + dst_ref = conv->index; } - /* save parent_tree so subdissectors can create new top nodes */ - top_tree=parent_tree; - - if(parent_tree){ - item = proto_tree_add_item(parent_tree, proto_idmp, tvb, 0, -1, ENC_NA); - tree = proto_item_add_subtree(item, ett_idmp); - } - - col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDMP"); - - /* now check the segment fields */ - - proto_tree_add_item(tree, hf_idmp_version, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; - proto_tree_add_item(tree, hf_idmp_final, tvb, offset, 1, ENC_BIG_ENDIAN); - idmp_final = tvb_get_guint8(tvb, offset); offset++; - proto_tree_add_item(tree, hf_idmp_length, tvb, offset, 4, ENC_BIG_ENDIAN); - idmp_length = tvb_get_ntohl(tvb, offset); offset += 4; - - if(idmp_reassemble) { - - pinfo->fragmented = !idmp_final; - - if (check_col(pinfo->cinfo, COL_INFO)) - col_append_fstr(pinfo->cinfo, COL_INFO, " [%sIDMP fragment, %u byte%s]", - idmp_final ? "Final " : "" , - idmp_length, plurality(idmp_length, "", "s")); + /* save parent_tree so subdissectors can create new top nodes */ + top_tree=parent_tree; - fd_head = fragment_add_seq_next(tvb, offset, pinfo, dst_ref, - idmp_segment_table, idmp_reassembled_table, - idmp_length, !idmp_final); - - if(fd_head && fd_head->next) { - proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0, - "IDMP segment data (%u byte%s)", idmp_length, - plurality(idmp_length, "", "s")); - - if (idmp_final) { - /* This is the last segment */ - tvb = process_reassembled_data (tvb, offset, pinfo, - "Reassembled IDMP", fd_head, &idmp_frag_items, NULL, tree); - offset = 0; - } else if (pinfo->fd->num != fd_head->reassembled_in) { - /* Add a "Reassembled in" link if not reassembled in this frame */ - proto_tree_add_uint (tree, hf_idmp_reassembled_in, - tvb, 0, 0, fd_head->reassembled_in); - } - } - - } else { - if(!idmp_final) { - - if (check_col(pinfo->cinfo, COL_INFO)) - col_append_fstr(pinfo->cinfo, COL_INFO, " [IDMP fragment, %u byte%s, IDMP reassembly not enabled]", - idmp_length, plurality(idmp_length, "", "s")); + if(parent_tree){ + item = proto_tree_add_item(parent_tree, proto_idmp, tvb, 0, -1, ENC_NA); + tree = proto_item_add_subtree(item, ett_idmp); + } - proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0, - "IDMP segment data (%u byte%s) (IDMP reassembly not enabled)", idmp_length, - plurality(idmp_length, "", "s")); - } - } - /* not reassembling - just dissect */ - if(idmp_final) { - save_private_data = pinfo->private_data; - pinfo->private_data = &session; + col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDMP"); + + /* now check the segment fields */ + + proto_tree_add_item(tree, hf_idmp_version, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; + proto_tree_add_item(tree, hf_idmp_final, tvb, offset, 1, ENC_BIG_ENDIAN); + idmp_final = tvb_get_guint8(tvb, offset); offset++; + proto_tree_add_item(tree, hf_idmp_length, tvb, offset, 4, ENC_BIG_ENDIAN); + idmp_length = tvb_get_ntohl(tvb, offset); offset += 4; + + if(idmp_reassemble) { + + pinfo->fragmented = !idmp_final; + + if (check_col(pinfo->cinfo, COL_INFO)) + col_append_fstr(pinfo->cinfo, COL_INFO, " [%sIDMP fragment, %u byte%s]", + idmp_final ? "Final " : "" , + idmp_length, plurality(idmp_length, "", "s")); + + fd_head = fragment_add_seq_next(tvb, offset, pinfo, dst_ref, + idmp_segment_table, idmp_reassembled_table, + idmp_length, !idmp_final); + + if(fd_head && fd_head->next) { + proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0, + "IDMP segment data (%u byte%s)", idmp_length, + plurality(idmp_length, "", "s")); + + if (idmp_final) { + /* This is the last segment */ + tvb = process_reassembled_data (tvb, offset, pinfo, + "Reassembled IDMP", fd_head, &idmp_frag_items, NULL, tree); + offset = 0; + } else if (pinfo->fd->num != fd_head->reassembled_in) { + /* Add a "Reassembled in" link if not reassembled in this frame */ + proto_tree_add_uint (tree, hf_idmp_reassembled_in, + tvb, 0, 0, fd_head->reassembled_in); + } + } + + } else { + if(!idmp_final) { + + if (check_col(pinfo->cinfo, COL_INFO)) + col_append_fstr(pinfo->cinfo, COL_INFO, " [IDMP fragment, %u byte%s, IDMP reassembly not enabled]", + idmp_length, plurality(idmp_length, "", "s")); + + proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0, + "IDMP segment data (%u byte%s) (IDMP reassembly not enabled)", idmp_length, + plurality(idmp_length, "", "s")); + } + } + /* not reassembling - just dissect */ + if(idmp_final) { + save_private_data = pinfo->private_data; + pinfo->private_data = &session; - dissect_idmp_IDM_PDU(FALSE, tvb, offset, &asn1_ctx, tree, hf_idmp_PDU); + dissect_idmp_IDM_PDU(FALSE, tvb, offset, &asn1_ctx, tree, hf_idmp_PDU); - pinfo->private_data = save_private_data; - } + pinfo->private_data = save_private_data; + } } static guint get_idmp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset) { - guint32 len; + guint32 len; - len = tvb_get_ntohl(tvb, offset + 2); + len = tvb_get_ntohl(tvb, offset + 2); - return len + 6; + return len + 6; } static void dissect_idmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) { - tcp_dissect_pdus(tvb, pinfo, parent_tree, idmp_desegment, 0, get_idmp_pdu_len, dissect_idmp); + tcp_dissect_pdus(tvb, pinfo, parent_tree, idmp_desegment, 0, get_idmp_pdu_len, dissect_idmp); } static void idmp_reassemble_init (void) { - fragment_table_init (&idmp_segment_table); - reassembled_table_init (&idmp_reassembled_table); + fragment_table_init (&idmp_segment_table); + reassembled_table_init (&idmp_reassembled_table); - saved_protocolID = NULL; + saved_protocolID = NULL; } /*--- proto_register_idmp -------------------------------------------*/ -void proto_register_idmp(void) { - - /* List of fields */ - static hf_register_info hf[] = - { - { &hf_idmp_version, - { "version", "idmp.version", - FT_INT8, BASE_DEC, NULL, 0, - "idmp.INTEGER", HFILL }}, - { &hf_idmp_final, - { "final", "idmp.final", - FT_BOOLEAN, 8, NULL, 0, - "idmp.BOOLEAN", HFILL }}, - { &hf_idmp_length, - { "length", "idmp.length", - FT_INT32, BASE_DEC, NULL, 0, - "idmp.INTEGER", HFILL }}, - { &hf_idmp_PDU, - { "IDM-PDU", "idmp.pdu", - FT_UINT32, BASE_DEC, VALS(idmp_IDM_PDU_vals), 0, - "idmp.PDU", HFILL }}, - /* Fragment entries */ - { &hf_idmp_fragments, - { "IDMP fragments", "idmp.fragments", FT_NONE, BASE_NONE, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment, - { "IDMP fragment", "idmp.fragment", FT_FRAMENUM, BASE_NONE, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_overlap, - { "IDMP fragment overlap", "idmp.fragment.overlap", FT_BOOLEAN, - BASE_NONE, NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_overlap_conflicts, - { "IDMP fragment overlapping with conflicting data", - "idmp.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_multiple_tails, - { "IDMP has multiple tail fragments", - "idmp.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_too_long_fragment, - { "IDMP fragment too long", "idmp.fragment.too_long_fragment", - FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_error, - { "IDMP defragmentation error", "idmp.fragment.error", FT_FRAMENUM, - BASE_NONE, NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_count, - { "IDMP fragment count", "idmp.fragment.count", FT_UINT32, BASE_DEC, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_reassembled_in, - { "Reassembled IDMP in frame", "idmp.reassembled.in", FT_FRAMENUM, BASE_NONE, - NULL, 0x00, "This IDMP packet is reassembled in this frame", HFILL } }, - { &hf_idmp_reassembled_length, - { "Reassembled IDMP length", "idmp.reassembled.length", FT_UINT32, BASE_DEC, - NULL, 0x00, "The total length of the reassembled payload", HFILL } }, +void proto_register_idmp(void) +{ + /* List of fields */ + static hf_register_info hf[] = { + { &hf_idmp_version, + { "version", "idmp.version", + FT_INT8, BASE_DEC, NULL, 0, + "idmp.INTEGER", HFILL }}, + { &hf_idmp_final, + { "final", "idmp.final", + FT_BOOLEAN, BASE_NONE, NULL, 0, + "idmp.BOOLEAN", HFILL }}, + { &hf_idmp_length, + { "length", "idmp.length", + FT_INT32, BASE_DEC, NULL, 0, + "idmp.INTEGER", HFILL }}, + { &hf_idmp_PDU, + { "IDM-PDU", "idmp.pdu", + FT_UINT32, BASE_DEC, VALS(idmp_IDM_PDU_vals), 0, + "idmp.PDU", HFILL }}, + /* Fragment entries */ + { &hf_idmp_fragments, + { "IDMP fragments", "idmp.fragments", FT_NONE, BASE_NONE, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment, + { "IDMP fragment", "idmp.fragment", FT_FRAMENUM, BASE_NONE, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_overlap, + { "IDMP fragment overlap", "idmp.fragment.overlap", FT_BOOLEAN, + BASE_NONE, NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_overlap_conflicts, + { "IDMP fragment overlapping with conflicting data", + "idmp.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_multiple_tails, + { "IDMP has multiple tail fragments", + "idmp.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_too_long_fragment, + { "IDMP fragment too long", "idmp.fragment.too_long_fragment", + FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_error, + { "IDMP defragmentation error", "idmp.fragment.error", FT_FRAMENUM, + BASE_NONE, NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_count, + { "IDMP fragment count", "idmp.fragment.count", FT_UINT32, BASE_DEC, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_reassembled_in, + { "Reassembled IDMP in frame", "idmp.reassembled.in", FT_FRAMENUM, BASE_NONE, + NULL, 0x00, "This IDMP packet is reassembled in this frame", HFILL } }, + { &hf_idmp_reassembled_length, + { "Reassembled IDMP length", "idmp.reassembled.length", FT_UINT32, BASE_DEC, + NULL, 0x00, "The total length of the reassembled payload", HFILL } }, #include "packet-idmp-hfarr.c" - }; + }; - /* List of subtrees */ - static gint *ett[] = { - &ett_idmp, - &ett_idmp_fragment, - &ett_idmp_fragments, + /* List of subtrees */ + static gint *ett[] = { + &ett_idmp, + &ett_idmp_fragment, + &ett_idmp_fragments, #include "packet-idmp-ettarr.c" - }; - module_t *idmp_module; + }; + module_t *idmp_module; - /* Register protocol */ - proto_idmp = proto_register_protocol(PNAME, PSNAME, PFNAME); + /* Register protocol */ + proto_idmp = proto_register_protocol(PNAME, PSNAME, PFNAME); - /* Register fields and subtrees */ - proto_register_field_array(proto_idmp, hf, array_length(hf)); - proto_register_subtree_array(ett, array_length(ett)); + /* Register fields and subtrees */ + proto_register_field_array(proto_idmp, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); - register_dissector("idmp", dissect_idmp_tcp, proto_idmp); + register_dissector("idmp", dissect_idmp_tcp, proto_idmp); - register_init_routine (&idmp_reassemble_init); + register_init_routine (&idmp_reassemble_init); - /* Register our configuration options for IDMP, particularly our port */ + /* Register our configuration options for IDMP, particularly our port */ - idmp_module = prefs_register_protocol_subtree("OSI/X.500", proto_idmp, prefs_register_idmp); + idmp_module = prefs_register_protocol_subtree("OSI/X.500", proto_idmp, prefs_register_idmp); - prefs_register_bool_preference(idmp_module, "desegment_idmp_messages", - "Reassemble IDMP messages spanning multiple TCP segments", - "Whether the IDMP dissector should reassemble messages spanning multiple TCP segments." - " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.", - &idmp_desegment); + prefs_register_bool_preference(idmp_module, "desegment_idmp_messages", + "Reassemble IDMP messages spanning multiple TCP segments", + "Whether the IDMP dissector should reassemble messages spanning multiple TCP segments." + " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.", + &idmp_desegment); prefs_register_bool_preference(idmp_module, "reassemble", - "Reassemble segmented IDMP datagrams", - "Whether segmented IDMP datagrams should be reassembled." - " To use this option, you must also enable" - " \"Allow subdissectors to reassemble TCP streams\"" - " in the TCP protocol settings.", &idmp_reassemble); + "Reassemble segmented IDMP datagrams", + "Whether segmented IDMP datagrams should be reassembled." + " To use this option, you must also enable" + " \"Allow subdissectors to reassemble TCP streams\"" + " in the TCP protocol settings.", &idmp_reassemble); - prefs_register_uint_preference(idmp_module, "tcp.port", "IDMP TCP Port", - "Set the port for Internet Directly Mapped Protocol requests/responses", - 10, &global_idmp_tcp_port); + prefs_register_uint_preference(idmp_module, "tcp.port", "IDMP TCP Port", + "Set the port for Internet Directly Mapped Protocol requests/responses", + 10, &global_idmp_tcp_port); } @@ -370,8 +369,8 @@ void proto_register_idmp(void) { /*--- proto_reg_handoff_idm --- */ void proto_reg_handoff_idm(void) { - /* remember the idm handler for change in preferences */ - idmp_handle = find_dissector(PFNAME); + /* remember the idm handler for change in preferences */ + idmp_handle = find_dissector(PFNAME); } @@ -380,15 +379,15 @@ static void prefs_register_idmp(void) { - /* de-register the old port */ - /* port 102 is registered by TPKT - don't undo this! */ - if(idmp_handle) - dissector_delete_uint("tcp.port", tcp_port, idmp_handle); + /* de-register the old port */ + /* port 102 is registered by TPKT - don't undo this! */ + if(idmp_handle) + dissector_delete_uint("tcp.port", tcp_port, idmp_handle); - /* Set our port number for future use */ - tcp_port = global_idmp_tcp_port; + /* Set our port number for future use */ + tcp_port = global_idmp_tcp_port; - if((tcp_port > 0) && idmp_handle) - dissector_add_uint("tcp.port", global_idmp_tcp_port, idmp_handle); + if((tcp_port > 0) && idmp_handle) + dissector_add_uint("tcp.port", global_idmp_tcp_port, idmp_handle); } diff --git a/epan/dissectors/packet-idmp.c b/epan/dissectors/packet-idmp.c index f1ce614f4d..c2d3471694 100644 --- a/epan/dissectors/packet-idmp.c +++ b/epan/dissectors/packet-idmp.c @@ -8,7 +8,7 @@ #line 1 "../../asn1/idmp/packet-idmp-template.c" /* packet-idmp.c * Routines for X.519 Internet Directly Mapped Procotol (IDMP) packet dissection - * Graeme Lunt 2020 + * Graeme Lunt 2010 * * $Id$ * @@ -56,16 +56,16 @@ #define PSNAME "IDMP" #define PFNAME "idmp" -static gboolean idmp_desegment = TRUE; -static guint global_idmp_tcp_port = 1102; /* made up for now */ -static gboolean idmp_reassemble = TRUE; -static guint tcp_port = 0; -static dissector_handle_t idmp_handle = NULL; +static gboolean idmp_desegment = TRUE; +static guint global_idmp_tcp_port = 1102; /* made up for now */ +static gboolean idmp_reassemble = TRUE; +static guint tcp_port = 0; +static dissector_handle_t idmp_handle = NULL; -static proto_tree *top_tree = NULL; -static const char *protocolID = NULL; +static proto_tree *top_tree = NULL; +static const char *protocolID = NULL; static const char *saved_protocolID = NULL; -static guint32 opcode = -1; +static guint32 opcode = -1; static void prefs_register_idmp(void); /* forward declaration for use in preferences registration */ @@ -77,7 +77,7 @@ static int hf_idmp_final = -1; static int hf_idmp_length = -1; static int hf_idmp_PDU = -1; -static GHashTable *idmp_segment_table = NULL; +static GHashTable *idmp_segment_table = NULL; static GHashTable *idmp_reassembled_table = NULL; static int hf_idmp_fragments = -1; @@ -95,44 +95,44 @@ static gint ett_idmp_fragment = -1; static gint ett_idmp_fragments = -1; static const fragment_items idmp_frag_items = { - /* Fragment subtrees */ - &ett_idmp_fragment, - &ett_idmp_fragments, - /* Fragment fields */ - &hf_idmp_fragments, - &hf_idmp_fragment, - &hf_idmp_fragment_overlap, - &hf_idmp_fragment_overlap_conflicts, - &hf_idmp_fragment_multiple_tails, - &hf_idmp_fragment_too_long_fragment, - &hf_idmp_fragment_error, - &hf_idmp_fragment_count, - /* Reassembled in field */ - &hf_idmp_reassembled_in, - /* Reassembled length field */ - &hf_idmp_reassembled_length, - /* Tag */ - "IDMP fragments" + /* Fragment subtrees */ + &ett_idmp_fragment, + &ett_idmp_fragments, + /* Fragment fields */ + &hf_idmp_fragments, + &hf_idmp_fragment, + &hf_idmp_fragment_overlap, + &hf_idmp_fragment_overlap_conflicts, + &hf_idmp_fragment_multiple_tails, + &hf_idmp_fragment_too_long_fragment, + &hf_idmp_fragment_error, + &hf_idmp_fragment_count, + /* Reassembled in field */ + &hf_idmp_reassembled_in, + /* Reassembled length field */ + &hf_idmp_reassembled_length, + /* Tag */ + "IDMP fragments" }; static int call_idmp_oid_callback(tvbuff_t *tvb, int offset, packet_info *pinfo, int op, proto_tree *tree _U_) { - struct SESSION_DATA_STRUCTURE *session; + struct SESSION_DATA_STRUCTURE *session; - if((session = (struct SESSION_DATA_STRUCTURE*)pinfo->private_data) != NULL) { + if((session = (struct SESSION_DATA_STRUCTURE*)pinfo->private_data) != NULL) { - if((!saved_protocolID) && (op == (ROS_OP_BIND | ROS_OP_RESULT))) { - /* save for subsequent operations - should be into session data */ - saved_protocolID = se_strdup(protocolID); - } + if((!saved_protocolID) && (op == (ROS_OP_BIND | ROS_OP_RESULT))) { + /* save for subsequent operations - should be into session data */ + saved_protocolID = se_strdup(protocolID); + } - /* mimic ROS! */ - session->ros_op = op; - offset = call_ros_oid_callback(saved_protocolID ? saved_protocolID : protocolID, tvb, offset, pinfo, top_tree); - } + /* mimic ROS! */ + session->ros_op = op; + offset = call_ros_oid_callback(saved_protocolID ? saved_protocolID : protocolID, tvb, offset, pinfo, top_tree); + } - return offset; + return offset; } @@ -621,186 +621,185 @@ dissect_idmp_IDM_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U void register_idmp_protocol_info(const char *oid, const ros_info_t *rinfo, int proto _U_, const char *name) { - /* just register with ROS for now */ - register_ros_protocol_info(oid, rinfo, proto, name, FALSE); + /* just register with ROS for now */ + register_ros_protocol_info(oid, rinfo, proto, name, FALSE); } static void dissect_idmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) { - int offset = 0; + int offset = 0; - proto_item *item=NULL; - proto_tree *tree=NULL; - asn1_ctx_t asn1_ctx; - void *save_private_data; - struct SESSION_DATA_STRUCTURE session; - gboolean idmp_final; - guint32 idmp_length; - fragment_data *fd_head; - conversation_t *conv; - guint32 dst_ref = 0; + proto_item *item = NULL; + proto_tree *tree = NULL; + asn1_ctx_t asn1_ctx; + void *save_private_data; + struct SESSION_DATA_STRUCTURE session; + gboolean idmp_final; + guint32 idmp_length; + fragment_data *fd_head; + conversation_t *conv; + guint32 dst_ref = 0; - asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo); + asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo); conv = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst, - pinfo->ptype, pinfo->srcport, pinfo->destport, 0); + pinfo->ptype, pinfo->srcport, pinfo->destport, 0); if (conv) { - /* Found a conversation, also use index for the generated dst_ref */ - dst_ref = conv->index; + /* Found a conversation, also use index for the generated dst_ref */ + dst_ref = conv->index; } - /* save parent_tree so subdissectors can create new top nodes */ - top_tree=parent_tree; - - if(parent_tree){ - item = proto_tree_add_item(parent_tree, proto_idmp, tvb, 0, -1, ENC_NA); - tree = proto_item_add_subtree(item, ett_idmp); - } - - col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDMP"); - - /* now check the segment fields */ - - proto_tree_add_item(tree, hf_idmp_version, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; - proto_tree_add_item(tree, hf_idmp_final, tvb, offset, 1, ENC_BIG_ENDIAN); - idmp_final = tvb_get_guint8(tvb, offset); offset++; - proto_tree_add_item(tree, hf_idmp_length, tvb, offset, 4, ENC_BIG_ENDIAN); - idmp_length = tvb_get_ntohl(tvb, offset); offset += 4; - - if(idmp_reassemble) { - - pinfo->fragmented = !idmp_final; - - if (check_col(pinfo->cinfo, COL_INFO)) - col_append_fstr(pinfo->cinfo, COL_INFO, " [%sIDMP fragment, %u byte%s]", - idmp_final ? "Final " : "" , - idmp_length, plurality(idmp_length, "", "s")); - - fd_head = fragment_add_seq_next(tvb, offset, pinfo, dst_ref, - idmp_segment_table, idmp_reassembled_table, - idmp_length, !idmp_final); + /* save parent_tree so subdissectors can create new top nodes */ + top_tree=parent_tree; - if(fd_head && fd_head->next) { - proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0, - "IDMP segment data (%u byte%s)", idmp_length, - plurality(idmp_length, "", "s")); - - if (idmp_final) { - /* This is the last segment */ - tvb = process_reassembled_data (tvb, offset, pinfo, - "Reassembled IDMP", fd_head, &idmp_frag_items, NULL, tree); - offset = 0; - } else if (pinfo->fd->num != fd_head->reassembled_in) { - /* Add a "Reassembled in" link if not reassembled in this frame */ - proto_tree_add_uint (tree, hf_idmp_reassembled_in, - tvb, 0, 0, fd_head->reassembled_in); - } - } - - } else { - if(!idmp_final) { - - if (check_col(pinfo->cinfo, COL_INFO)) - col_append_fstr(pinfo->cinfo, COL_INFO, " [IDMP fragment, %u byte%s, IDMP reassembly not enabled]", - idmp_length, plurality(idmp_length, "", "s")); + if(parent_tree){ + item = proto_tree_add_item(parent_tree, proto_idmp, tvb, 0, -1, ENC_NA); + tree = proto_item_add_subtree(item, ett_idmp); + } - proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0, - "IDMP segment data (%u byte%s) (IDMP reassembly not enabled)", idmp_length, - plurality(idmp_length, "", "s")); - } - } - /* not reassembling - just dissect */ - if(idmp_final) { - save_private_data = pinfo->private_data; - pinfo->private_data = &session; + col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDMP"); + + /* now check the segment fields */ + + proto_tree_add_item(tree, hf_idmp_version, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; + proto_tree_add_item(tree, hf_idmp_final, tvb, offset, 1, ENC_BIG_ENDIAN); + idmp_final = tvb_get_guint8(tvb, offset); offset++; + proto_tree_add_item(tree, hf_idmp_length, tvb, offset, 4, ENC_BIG_ENDIAN); + idmp_length = tvb_get_ntohl(tvb, offset); offset += 4; + + if(idmp_reassemble) { + + pinfo->fragmented = !idmp_final; + + if (check_col(pinfo->cinfo, COL_INFO)) + col_append_fstr(pinfo->cinfo, COL_INFO, " [%sIDMP fragment, %u byte%s]", + idmp_final ? "Final " : "" , + idmp_length, plurality(idmp_length, "", "s")); + + fd_head = fragment_add_seq_next(tvb, offset, pinfo, dst_ref, + idmp_segment_table, idmp_reassembled_table, + idmp_length, !idmp_final); + + if(fd_head && fd_head->next) { + proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0, + "IDMP segment data (%u byte%s)", idmp_length, + plurality(idmp_length, "", "s")); + + if (idmp_final) { + /* This is the last segment */ + tvb = process_reassembled_data (tvb, offset, pinfo, + "Reassembled IDMP", fd_head, &idmp_frag_items, NULL, tree); + offset = 0; + } else if (pinfo->fd->num != fd_head->reassembled_in) { + /* Add a "Reassembled in" link if not reassembled in this frame */ + proto_tree_add_uint (tree, hf_idmp_reassembled_in, + tvb, 0, 0, fd_head->reassembled_in); + } + } + + } else { + if(!idmp_final) { + + if (check_col(pinfo->cinfo, COL_INFO)) + col_append_fstr(pinfo->cinfo, COL_INFO, " [IDMP fragment, %u byte%s, IDMP reassembly not enabled]", + idmp_length, plurality(idmp_length, "", "s")); + + proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0, + "IDMP segment data (%u byte%s) (IDMP reassembly not enabled)", idmp_length, + plurality(idmp_length, "", "s")); + } + } + /* not reassembling - just dissect */ + if(idmp_final) { + save_private_data = pinfo->private_data; + pinfo->private_data = &session; - dissect_idmp_IDM_PDU(FALSE, tvb, offset, &asn1_ctx, tree, hf_idmp_PDU); + dissect_idmp_IDM_PDU(FALSE, tvb, offset, &asn1_ctx, tree, hf_idmp_PDU); - pinfo->private_data = save_private_data; - } + pinfo->private_data = save_private_data; + } } static guint get_idmp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset) { - guint32 len; + guint32 len; - len = tvb_get_ntohl(tvb, offset + 2); + len = tvb_get_ntohl(tvb, offset + 2); - return len + 6; + return len + 6; } static void dissect_idmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) { - tcp_dissect_pdus(tvb, pinfo, parent_tree, idmp_desegment, 0, get_idmp_pdu_len, dissect_idmp); + tcp_dissect_pdus(tvb, pinfo, parent_tree, idmp_desegment, 0, get_idmp_pdu_len, dissect_idmp); } static void idmp_reassemble_init (void) { - fragment_table_init (&idmp_segment_table); - reassembled_table_init (&idmp_reassembled_table); + fragment_table_init (&idmp_segment_table); + reassembled_table_init (&idmp_reassembled_table); - saved_protocolID = NULL; + saved_protocolID = NULL; } /*--- proto_register_idmp -------------------------------------------*/ -void proto_register_idmp(void) { - - /* List of fields */ - static hf_register_info hf[] = - { - { &hf_idmp_version, - { "version", "idmp.version", - FT_INT8, BASE_DEC, NULL, 0, - "idmp.INTEGER", HFILL }}, - { &hf_idmp_final, - { "final", "idmp.final", - FT_BOOLEAN, 8, NULL, 0, - "idmp.BOOLEAN", HFILL }}, - { &hf_idmp_length, - { "length", "idmp.length", - FT_INT32, BASE_DEC, NULL, 0, - "idmp.INTEGER", HFILL }}, - { &hf_idmp_PDU, - { "IDM-PDU", "idmp.pdu", - FT_UINT32, BASE_DEC, VALS(idmp_IDM_PDU_vals), 0, - "idmp.PDU", HFILL }}, - /* Fragment entries */ - { &hf_idmp_fragments, - { "IDMP fragments", "idmp.fragments", FT_NONE, BASE_NONE, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment, - { "IDMP fragment", "idmp.fragment", FT_FRAMENUM, BASE_NONE, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_overlap, - { "IDMP fragment overlap", "idmp.fragment.overlap", FT_BOOLEAN, - BASE_NONE, NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_overlap_conflicts, - { "IDMP fragment overlapping with conflicting data", - "idmp.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_multiple_tails, - { "IDMP has multiple tail fragments", - "idmp.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_too_long_fragment, - { "IDMP fragment too long", "idmp.fragment.too_long_fragment", - FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_error, - { "IDMP defragmentation error", "idmp.fragment.error", FT_FRAMENUM, - BASE_NONE, NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_fragment_count, - { "IDMP fragment count", "idmp.fragment.count", FT_UINT32, BASE_DEC, - NULL, 0x00, NULL, HFILL } }, - { &hf_idmp_reassembled_in, - { "Reassembled IDMP in frame", "idmp.reassembled.in", FT_FRAMENUM, BASE_NONE, - NULL, 0x00, "This IDMP packet is reassembled in this frame", HFILL } }, - { &hf_idmp_reassembled_length, - { "Reassembled IDMP length", "idmp.reassembled.length", FT_UINT32, BASE_DEC, - NULL, 0x00, "The total length of the reassembled payload", HFILL } }, +void proto_register_idmp(void) +{ + /* List of fields */ + static hf_register_info hf[] = { + { &hf_idmp_version, + { "version", "idmp.version", + FT_INT8, BASE_DEC, NULL, 0, + "idmp.INTEGER", HFILL }}, + { &hf_idmp_final, + { "final", "idmp.final", + FT_BOOLEAN, BASE_NONE, NULL, 0, + "idmp.BOOLEAN", HFILL }}, + { &hf_idmp_length, + { "length", "idmp.length", + FT_INT32, BASE_DEC, NULL, 0, + "idmp.INTEGER", HFILL }}, + { &hf_idmp_PDU, + { "IDM-PDU", "idmp.pdu", + FT_UINT32, BASE_DEC, VALS(idmp_IDM_PDU_vals), 0, + "idmp.PDU", HFILL }}, + /* Fragment entries */ + { &hf_idmp_fragments, + { "IDMP fragments", "idmp.fragments", FT_NONE, BASE_NONE, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment, + { "IDMP fragment", "idmp.fragment", FT_FRAMENUM, BASE_NONE, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_overlap, + { "IDMP fragment overlap", "idmp.fragment.overlap", FT_BOOLEAN, + BASE_NONE, NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_overlap_conflicts, + { "IDMP fragment overlapping with conflicting data", + "idmp.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_multiple_tails, + { "IDMP has multiple tail fragments", + "idmp.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_too_long_fragment, + { "IDMP fragment too long", "idmp.fragment.too_long_fragment", + FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_error, + { "IDMP defragmentation error", "idmp.fragment.error", FT_FRAMENUM, + BASE_NONE, NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_fragment_count, + { "IDMP fragment count", "idmp.fragment.count", FT_UINT32, BASE_DEC, + NULL, 0x00, NULL, HFILL } }, + { &hf_idmp_reassembled_in, + { "Reassembled IDMP in frame", "idmp.reassembled.in", FT_FRAMENUM, BASE_NONE, + NULL, 0x00, "This IDMP packet is reassembled in this frame", HFILL } }, + { &hf_idmp_reassembled_length, + { "Reassembled IDMP length", "idmp.reassembled.length", FT_UINT32, BASE_DEC, + NULL, 0x00, "The total length of the reassembled payload", HFILL } }, /*--- Included file: packet-idmp-hfarr.c ---*/ @@ -935,14 +934,14 @@ void proto_register_idmp(void) { NULL, HFILL }}, /*--- End of included file: packet-idmp-hfarr.c ---*/ -#line 324 "../../asn1/idmp/packet-idmp-template.c" - }; +#line 323 "../../asn1/idmp/packet-idmp-template.c" + }; - /* List of subtrees */ - static gint *ett[] = { - &ett_idmp, - &ett_idmp_fragment, - &ett_idmp_fragments, + /* List of subtrees */ + static gint *ett[] = { + &ett_idmp, + &ett_idmp_fragment, + &ett_idmp_fragments, /*--- Included file: packet-idmp-ettarr.c ---*/ #line 1 "../../asn1/idmp/packet-idmp-ettarr.c" @@ -958,41 +957,41 @@ void proto_register_idmp(void) { &ett_idmp_InvokeId, /*--- End of included file: packet-idmp-ettarr.c ---*/ -#line 332 "../../asn1/idmp/packet-idmp-template.c" - }; - module_t *idmp_module; +#line 331 "../../asn1/idmp/packet-idmp-template.c" + }; + module_t *idmp_module; - /* Register protocol */ - proto_idmp = proto_register_protocol(PNAME, PSNAME, PFNAME); + /* Register protocol */ + proto_idmp = proto_register_protocol(PNAME, PSNAME, PFNAME); - /* Register fields and subtrees */ - proto_register_field_array(proto_idmp, hf, array_length(hf)); - proto_register_subtree_array(ett, array_length(ett)); + /* Register fields and subtrees */ + proto_register_field_array(proto_idmp, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); - register_dissector("idmp", dissect_idmp_tcp, proto_idmp); + register_dissector("idmp", dissect_idmp_tcp, proto_idmp); - register_init_routine (&idmp_reassemble_init); + register_init_routine (&idmp_reassemble_init); - /* Register our configuration options for IDMP, particularly our port */ + /* Register our configuration options for IDMP, particularly our port */ - idmp_module = prefs_register_protocol_subtree("OSI/X.500", proto_idmp, prefs_register_idmp); + idmp_module = prefs_register_protocol_subtree("OSI/X.500", proto_idmp, prefs_register_idmp); - prefs_register_bool_preference(idmp_module, "desegment_idmp_messages", - "Reassemble IDMP messages spanning multiple TCP segments", - "Whether the IDMP dissector should reassemble messages spanning multiple TCP segments." - " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.", - &idmp_desegment); + prefs_register_bool_preference(idmp_module, "desegment_idmp_messages", + "Reassemble IDMP messages spanning multiple TCP segments", + "Whether the IDMP dissector should reassemble messages spanning multiple TCP segments." + " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.", + &idmp_desegment); prefs_register_bool_preference(idmp_module, "reassemble", - "Reassemble segmented IDMP datagrams", - "Whether segmented IDMP datagrams should be reassembled." - " To use this option, you must also enable" - " \"Allow subdissectors to reassemble TCP streams\"" - " in the TCP protocol settings.", &idmp_reassemble); + "Reassemble segmented IDMP datagrams", + "Whether segmented IDMP datagrams should be reassembled." + " To use this option, you must also enable" + " \"Allow subdissectors to reassemble TCP streams\"" + " in the TCP protocol settings.", &idmp_reassemble); - prefs_register_uint_preference(idmp_module, "tcp.port", "IDMP TCP Port", - "Set the port for Internet Directly Mapped Protocol requests/responses", - 10, &global_idmp_tcp_port); + prefs_register_uint_preference(idmp_module, "tcp.port", "IDMP TCP Port", + "Set the port for Internet Directly Mapped Protocol requests/responses", + 10, &global_idmp_tcp_port); } @@ -1000,8 +999,8 @@ void proto_register_idmp(void) { /*--- proto_reg_handoff_idm --- */ void proto_reg_handoff_idm(void) { - /* remember the idm handler for change in preferences */ - idmp_handle = find_dissector(PFNAME); + /* remember the idm handler for change in preferences */ + idmp_handle = find_dissector(PFNAME); } @@ -1010,15 +1009,15 @@ static void prefs_register_idmp(void) { - /* de-register the old port */ - /* port 102 is registered by TPKT - don't undo this! */ - if(idmp_handle) - dissector_delete_uint("tcp.port", tcp_port, idmp_handle); + /* de-register the old port */ + /* port 102 is registered by TPKT - don't undo this! */ + if(idmp_handle) + dissector_delete_uint("tcp.port", tcp_port, idmp_handle); - /* Set our port number for future use */ - tcp_port = global_idmp_tcp_port; + /* Set our port number for future use */ + tcp_port = global_idmp_tcp_port; - if((tcp_port > 0) && idmp_handle) - dissector_add_uint("tcp.port", global_idmp_tcp_port, idmp_handle); + if((tcp_port > 0) && idmp_handle) + dissector_add_uint("tcp.port", global_idmp_tcp_port, idmp_handle); } |