diff options
author | Michael Mann <mmann78@netscape.net> | 2017-10-28 13:26:51 -0400 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-10-28 19:22:24 +0000 |
commit | 7dbc520d57b8567738a15f617a11d9b5b70f40a7 (patch) | |
tree | 4b39448bd5f2243275f1d0590e0e1f0b4a3469dc | |
parent | db3be9f850446c1a1c4894f5d08d67a370abf94a (diff) |
Privatize the conversation_key structure
The intention is to make it more transparent when making a switch
to an "endpoint" over address/port combination.
Change-Id: Ic424c32095ecb103bcb4f7f4079c549de2c8d9c4
Reviewed-on: https://code.wireshark.org/review/24148
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r-- | debian/libwireshark0.symbols | 5 | ||||
-rw-r--r-- | epan/conversation.c | 76 | ||||
-rw-r--r-- | epan/conversation.h | 22 | ||||
-rw-r--r-- | epan/dissectors/asn1/t38/packet-t38-template.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-dof.c | 8 | ||||
-rw-r--r-- | epan/dissectors/packet-rtmpt.c | 8 | ||||
-rw-r--r-- | epan/dissectors/packet-t38.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-tcp.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-tftp.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-udp.c | 4 | ||||
-rw-r--r-- | plugins/profinet/packet-dcerpc-pn-io.c | 8 | ||||
-rw-r--r-- | plugins/profinet/packet-pn-rt.c | 4 | ||||
-rw-r--r-- | plugins/profinet/packet-pn-rtc-one.c | 4 | ||||
-rw-r--r-- | ui/gtk/conversation_hastables_dlg.c | 4 | ||||
-rw-r--r-- | ui/qt/conversation_hash_tables_dialog.cpp | 10 |
15 files changed, 108 insertions, 55 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index 7dcbe28790..3487521f16 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -154,8 +154,13 @@ libwireshark.so.0 libwireshark0 #MINVER# conversation_delete_proto_data@Base 1.9.1 conversation_filter_from_packet@Base 2.2.8 conversation_get_dissector@Base 2.0.0 + conversation_get_html_hash@Base 2.5.0 conversation_get_proto_data@Base 1.9.1 conversation_hash_exact@Base 2.5.0 + conversation_key_addr1@Base 2.5.0 + conversation_key_addr2@Base 2.5.0 + conversation_key_port1@Base 2.5.0 + conversation_key_port2@Base 2.5.0 conversation_new@Base 1.9.1 conversation_set_dissector@Base 1.9.1 conversation_set_dissector_from_frame_number@Base 2.0.0 diff --git a/epan/conversation.c b/epan/conversation.c index bf81957b5f..21e8bf160a 100644 --- a/epan/conversation.c +++ b/epan/conversation.c @@ -36,6 +36,15 @@ int _debug_conversation_indent = 0; #endif +struct conversation_key { + struct conversation_key *next; + address addr1; + address addr2; + port_type ptype; + guint32 port1; + guint32 port2; +}; + /* * Hash table for conversations with no wildcards. */ @@ -165,7 +174,7 @@ conversation_create_from_template(conversation_t *conversation, const address *a guint conversation_hash_exact(gconstpointer v) { - const conversation_key *key = (const conversation_key *)v; + const conversation_key_t key = (const conversation_key_t)v; guint hash_val; address tmp_addr; @@ -195,8 +204,8 @@ conversation_hash_exact(gconstpointer v) static gint conversation_match_exact(gconstpointer v, gconstpointer w) { - const conversation_key *v1 = (const conversation_key *)v; - const conversation_key *v2 = (const conversation_key *)w; + const conversation_key_t v1 = (const conversation_key_t)v; + const conversation_key_t v2 = (const conversation_key_t)w; if (v1->ptype != v2->ptype) return 0; /* different types of port */ @@ -248,7 +257,7 @@ conversation_match_exact(gconstpointer v, gconstpointer w) static guint conversation_hash_no_addr2(gconstpointer v) { - const conversation_key *key = (const conversation_key *)v; + const conversation_key_t key = (const conversation_key_t)v; guint hash_val; address tmp_addr; @@ -279,8 +288,8 @@ conversation_hash_no_addr2(gconstpointer v) static gint conversation_match_no_addr2(gconstpointer v, gconstpointer w) { - const conversation_key *v1 = (const conversation_key *)v; - const conversation_key *v2 = (const conversation_key *)w; + const conversation_key_t v1 = (const conversation_key_t)v; + const conversation_key_t v2 = (const conversation_key_t)w; if (v1->ptype != v2->ptype) return 0; /* different types of port */ @@ -313,7 +322,7 @@ conversation_match_no_addr2(gconstpointer v, gconstpointer w) static guint conversation_hash_no_port2(gconstpointer v) { - const conversation_key *key = (const conversation_key *)v; + const conversation_key_t key = (const conversation_key_t)v; guint hash_val; address tmp_addr; @@ -343,8 +352,8 @@ conversation_hash_no_port2(gconstpointer v) static gint conversation_match_no_port2(gconstpointer v, gconstpointer w) { - const conversation_key *v1 = (const conversation_key *)v; - const conversation_key *v2 = (const conversation_key *)w; + const conversation_key_t v1 = (const conversation_key_t)v; + const conversation_key_t v2 = (const conversation_key_t)w; if (v1->ptype != v2->ptype) return 0; /* different types of port */ @@ -377,7 +386,7 @@ conversation_match_no_port2(gconstpointer v, gconstpointer w) static guint conversation_hash_no_addr2_or_port2(gconstpointer v) { - const conversation_key *key = (const conversation_key *)v; + const conversation_key_t key = (const conversation_key_t)v; guint hash_val; address tmp_addr; @@ -405,8 +414,8 @@ conversation_hash_no_addr2_or_port2(gconstpointer v) static gint conversation_match_no_addr2_or_port2(gconstpointer v, gconstpointer w) { - const conversation_key *v1 = (const conversation_key *)v; - const conversation_key *v2 = (const conversation_key *)w; + const conversation_key_t v1 = (const conversation_key_t)v; + const conversation_key_t v2 = (const conversation_key_t)w; if (v1->ptype != v2->ptype) return 0; /* different types of port */ @@ -606,7 +615,7 @@ conversation_new(const guint32 setup_frame, const address *addr1, const address */ wmem_map_t* hashtable; conversation_t *conversation=NULL; - conversation_key *new_key; + conversation_key_t new_key; DPRINT(("creating conversation for frame #%d: %s:%d -> %s:%d (ptype=%d)", setup_frame, address_to_str(wmem_packet_scope(), addr1), port1, @@ -737,7 +746,7 @@ conversation_lookup_hashtable(wmem_map_t *hashtable, const guint32 frame_num, co conversation_t* convo=NULL; conversation_t* match=NULL; conversation_t* chain_head=NULL; - conversation_key key; + struct conversation_key key; /* * We don't make a copy of the address data, we just copy the @@ -1310,6 +1319,45 @@ get_conversation_hashtable_no_addr2_or_port2(void) return conversation_hashtable_no_addr2_or_port2; } +address* +conversation_key_addr1(const conversation_key_t key) +{ + return &key->addr1; +} + +address* +conversation_key_addr2(const conversation_key_t key) +{ + return &key->addr2; +} + +guint32 +conversation_key_port1(const conversation_key_t key) +{ + return key->port1; +} + +guint32 +conversation_key_port2(const conversation_key_t key) +{ + return key->port2; +} + +gchar* +conversation_get_html_hash(const conversation_key_t key) +{ + gchar *hash, *addr1, *addr2; + + addr1 = address_to_str(NULL, &key->addr1); + addr2 = address_to_str(NULL, &key->addr2); + hash = wmem_strdup_printf(NULL, "<tr><td>%s</td><td>%d</td><td>%s</td><td>%d</td></tr>\n", + addr1, key->port1, addr2, key->port2); + wmem_free(NULL, addr1); + wmem_free(NULL, addr2); + + return hash; +} + /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * diff --git a/epan/conversation.h b/epan/conversation.h index a2f90133a9..b50bc78a06 100644 --- a/epan/conversation.h +++ b/epan/conversation.h @@ -60,14 +60,8 @@ extern "C" { /** * Data structure representing a conversation. */ -typedef struct conversation_key { - struct conversation_key *next; - address addr1; - address addr2; - port_type ptype; - guint32 port1; - guint32 port2; -} conversation_key; +struct conversation_key; +typedef struct conversation_key* conversation_key_t; typedef struct conversation { struct conversation *next; /** pointer to next conversation on hash chain */ @@ -82,9 +76,15 @@ typedef struct conversation { wmem_tree_t *dissector_tree; /** tree containing protocol dissector client associated with conversation */ guint options; /** wildcard flags */ - conversation_key *key_ptr; /** pointer to the key for this conversation */ + conversation_key_t key_ptr; /** pointer to the key for this conversation */ } conversation_t; + +WS_DLL_PUBLIC address* conversation_key_addr1(const conversation_key_t key); +WS_DLL_PUBLIC address* conversation_key_addr2(const conversation_key_t key); +WS_DLL_PUBLIC guint32 conversation_key_port1(const conversation_key_t key); +WS_DLL_PUBLIC guint32 conversation_key_port2(const conversation_key_t key); + /** * Create a new hash tables for conversations. */ @@ -207,6 +207,10 @@ wmem_map_t *get_conversation_hashtable_no_addr2_or_port2(void); WS_DLL_PUBLIC guint conversation_hash_exact(gconstpointer v); +/* Provide a wmem_alloced (NULL scope) hash string using HTML tags */ +WS_DLL_PUBLIC gchar* +conversation_get_html_hash(const conversation_key_t key); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/epan/dissectors/asn1/t38/packet-t38-template.c b/epan/dissectors/asn1/t38/packet-t38-template.c index 34d4d7357b..4434e7f364 100644 --- a/epan/dissectors/asn1/t38/packet-t38-template.c +++ b/epan/dissectors/asn1/t38/packet-t38-template.c @@ -473,7 +473,7 @@ init_t38_info_conv(packet_info *pinfo) p_add_proto_data(wmem_file_scope(), pinfo, proto_t38, 0, p_t38_packet_conv); } - if (addresses_equal(&p_conv->key_ptr->addr1, &pinfo->net_src)) { + if (addresses_equal(conversation_key_addr1(p_conv->key_ptr), &pinfo->net_src)) { p_t38_conv_info = &(p_t38_conv->src_t38_info); p_t38_packet_conv_info = &(p_t38_packet_conv->src_t38_info); } else { diff --git a/epan/dissectors/packet-dof.c b/epan/dissectors/packet-dof.c index 8a8279e187..15402f690d 100644 --- a/epan/dissectors/packet-dof.c +++ b/epan/dissectors/packet-dof.c @@ -5667,10 +5667,10 @@ static tcp_session_data* create_tcp_session_data(packet_info *pinfo, conversatio { tcp_session_data *packet = wmem_new0(wmem_file_scope(), tcp_session_data); - copy_address_wmem(wmem_file_scope(), &packet->client.addr, &conversation->key_ptr->addr1); - packet->client.port = conversation->key_ptr->port1; - copy_address_wmem(wmem_file_scope(), &packet->server.addr, &conversation->key_ptr->addr2); - packet->server.port = conversation->key_ptr->port2; + copy_address_wmem(wmem_file_scope(), &packet->client.addr, conversation_key_addr1(conversation->key_ptr)); + packet->client.port = conversation_key_port1(conversation->key_ptr); + copy_address_wmem(wmem_file_scope(), &packet->server.addr, conversation_key_addr2(conversation->key_ptr)); + packet->server.port = conversation_key_port2(conversation->key_ptr); packet->not_dps = FALSE; diff --git a/epan/dissectors/packet-rtmpt.c b/epan/dissectors/packet-rtmpt.c index 0145309b7d..0d26203179 100644 --- a/epan/dissectors/packet-rtmpt.c +++ b/epan/dissectors/packet-rtmpt.c @@ -2305,10 +2305,10 @@ dissect_rtmpt_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* dat rconv = rtmpt_init_rconv(conv); } - cdir = (addresses_equal(&conv->key_ptr->addr1, &pinfo->src) && - addresses_equal(&conv->key_ptr->addr2, &pinfo->dst) && - conv->key_ptr->port1 == pinfo->srcport && - conv->key_ptr->port2 == pinfo->destport) ? 0 : 1; + cdir = (addresses_equal(conversation_key_addr1(conv->key_ptr), &pinfo->src) && + addresses_equal(conversation_key_addr2(conv->key_ptr), &pinfo->dst) && + conversation_key_port1(conv->key_ptr) == pinfo->srcport && + conversation_key_port2(conv->key_ptr) == pinfo->destport) ? 0 : 1; dissect_rtmpt_common(tvb, pinfo, tree, rconv, cdir, tcpinfo->seq, tcpinfo->lastackseq); return tvb_reported_length(tvb); diff --git a/epan/dissectors/packet-t38.c b/epan/dissectors/packet-t38.c index 39b5583d07..2d7a436b84 100644 --- a/epan/dissectors/packet-t38.c +++ b/epan/dissectors/packet-t38.c @@ -1062,7 +1062,7 @@ init_t38_info_conv(packet_info *pinfo) p_add_proto_data(wmem_file_scope(), pinfo, proto_t38, 0, p_t38_packet_conv); } - if (addresses_equal(&p_conv->key_ptr->addr1, &pinfo->net_src)) { + if (addresses_equal(conversation_key_addr1(p_conv->key_ptr), &pinfo->net_src)) { p_t38_conv_info = &(p_t38_conv->src_t38_info); p_t38_packet_conv_info = &(p_t38_packet_conv->src_t38_info); } else { diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c index 66f2312c09..9ddd88e020 100644 --- a/epan/dissectors/packet-tcp.c +++ b/epan/dissectors/packet-tcp.c @@ -1557,9 +1557,9 @@ add_tcp_process_info(guint32 frame_num, address *local_addr, address *remote_add return; } - if (cmp_address(local_addr, &conv->key_ptr->addr1) == 0 && local_port == conv->key_ptr->port1) { + if (cmp_address(local_addr, conversation_key_addr1(conv->key_ptr)) == 0 && local_port == conversation_key_port1(conv->key_ptr)) { flow = &tcpd->flow1; - } else if (cmp_address(remote_addr, &conv->key_ptr->addr1) == 0 && remote_port == conv->key_ptr->port1) { + } else if (cmp_address(remote_addr, conversation_key_addr1(conv->key_ptr)) == 0 && remote_port == conversation_key_port1(conv->key_ptr)) { flow = &tcpd->flow2; } if (!flow || (flow->process_info && flow->process_info->command)) { diff --git a/epan/dissectors/packet-tftp.c b/epan/dissectors/packet-tftp.c index 1d8e6bb6c9..30530696b7 100644 --- a/epan/dissectors/packet-tftp.c +++ b/epan/dissectors/packet-tftp.c @@ -673,7 +673,7 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ pinfo->destport, pinfo->srcport, 0); conversation_set_dissector(conversation, tftp_handle); } else if (conversation->options & NO_PORT_B) { - if (pinfo->destport == conversation->key_ptr->port1) + if (pinfo->destport == conversation_key_port1(conversation->key_ptr)) conversation_set_port2(conversation, pinfo->srcport); else return 0; diff --git a/epan/dissectors/packet-udp.c b/epan/dissectors/packet-udp.c index f595a92f96..9cc5d13377 100644 --- a/epan/dissectors/packet-udp.c +++ b/epan/dissectors/packet-udp.c @@ -490,9 +490,9 @@ add_udp_process_info(guint32 frame_num, address *local_addr, address *remote_add return; } - if ((cmp_address(local_addr, &conv->key_ptr->addr1) == 0) && (local_port == conv->key_ptr->port1)) { + if ((cmp_address(local_addr, conversation_key_addr1(conv->key_ptr)) == 0) && (local_port == conversation_key_port1(conv->key_ptr))) { flow = &udpd->flow1; - } else if ((cmp_address(remote_addr, &conv->key_ptr->addr1) == 0) && (remote_port == conv->key_ptr->port1)) { + } else if ((cmp_address(remote_addr, conversation_key_addr1(conv->key_ptr)) == 0) && (remote_port == conversation_key_port1(conv->key_ptr))) { flow = &udpd->flow2; } if (!flow || flow->command) { diff --git a/plugins/profinet/packet-dcerpc-pn-io.c b/plugins/profinet/packet-dcerpc-pn-io.c index b00aa3f69a..ec13d9353e 100644 --- a/plugins/profinet/packet-dcerpc-pn-io.c +++ b/plugins/profinet/packet-dcerpc-pn-io.c @@ -8288,14 +8288,14 @@ dissect_ARBlockReq_block(tvbuff_t *tvb, int offset, if (apdu_status_switch == NULL) { /* apdu status switch information is valid for whole file*/ apdu_status_switch = wmem_new0(wmem_file_scope(), apduStatusSwitch); - apdu_status_switch->dl_src = conversation->key_ptr->addr1; - apdu_status_switch->dl_dst = conversation->key_ptr->addr2; + copy_address_shallow(&apdu_status_switch->dl_src, conversation_key_addr1(conversation->key_ptr)); + copy_address_shallow(&apdu_status_switch->dl_dst, conversation_key_addr2(conversation->key_ptr)); apdu_status_switch->isRedundancyActive = TRUE; conversation_add_proto_data(conversation, proto_pn_io_apdu_status, apdu_status_switch); } else { - apdu_status_switch->dl_src = conversation->key_ptr->addr1; - apdu_status_switch->dl_dst = conversation->key_ptr->addr2; + copy_address_shallow(&apdu_status_switch->dl_src, conversation_key_addr1(conversation->key_ptr)); + copy_address_shallow(&apdu_status_switch->dl_dst, conversation_key_addr2(conversation->key_ptr)); apdu_status_switch->isRedundancyActive = TRUE; } } diff --git a/plugins/profinet/packet-pn-rt.c b/plugins/profinet/packet-pn-rt.c index d675ba0519..4c5bf743ab 100644 --- a/plugins/profinet/packet-pn-rt.c +++ b/plugins/profinet/packet-pn-rt.c @@ -187,12 +187,12 @@ dissect_DataStatus(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info *pin apdu_status_switch = (apduStatusSwitch*)conversation_get_proto_data(conversation, proto_pn_io_apdu_status); if (apdu_status_switch != NULL && apdu_status_switch->isRedundancyActive) { /* IOC -> IOD: OutputCR */ - if (addresses_equal(&(pinfo->src), &(conversation->key_ptr->addr1)) && addresses_equal(&(pinfo->dst), &(conversation->key_ptr->addr2))) { + if (addresses_equal(&(pinfo->src), conversation_key_addr1(conversation->key_ptr)) && addresses_equal(&(pinfo->dst), conversation_key_addr2(conversation->key_ptr))) { outputFlag = TRUE; inputFlag = FALSE; } /* IOD -> IOC: InputCR */ - if (addresses_equal(&(pinfo->dst), &(conversation->key_ptr->addr1)) && addresses_equal(&(pinfo->src), &(conversation->key_ptr->addr2))) { + if (addresses_equal(&(pinfo->dst), conversation_key_addr1(conversation->key_ptr)) && addresses_equal(&(pinfo->src), conversation_key_addr2(conversation->key_ptr))) { inputFlag = TRUE; outputFlag = FALSE; } diff --git a/plugins/profinet/packet-pn-rtc-one.c b/plugins/profinet/packet-pn-rtc-one.c index 0d52002beb..cd1d01dcf6 100644 --- a/plugins/profinet/packet-pn-rtc-one.c +++ b/plugins/profinet/packet-pn-rtc-one.c @@ -439,14 +439,14 @@ dissect_PNIO_C_SDU_RTC1(tvbuff_t *tvb, int offset, col_set_str(pinfo->cinfo, COL_PROTOCOL, "PNIO_PS"); /* set PROFISsafe protocol name */ } - if (addresses_equal(&(pinfo->src), &(conversation->key_ptr->addr1)) && addresses_equal(&(pinfo->dst), &(conversation->key_ptr->addr2))) { + if (addresses_equal(&(pinfo->src), conversation_key_addr1(conversation->key_ptr)) && addresses_equal(&(pinfo->dst), conversation_key_addr2(conversation->key_ptr))) { inputFlag = TRUE; outputFlag = FALSE; number_io_data_objects_input_cr = station_info->ioDataObjectNr; number_iocs_input_cr = station_info->iocsNr; } - if (addresses_equal(&(pinfo->dst), &(conversation->key_ptr->addr1)) && addresses_equal(&(pinfo->src), &(conversation->key_ptr->addr2))) { + if (addresses_equal(&(pinfo->dst), conversation_key_addr1(conversation->key_ptr)) && addresses_equal(&(pinfo->src), conversation_key_addr2(conversation->key_ptr))) { outputFlag = TRUE; inputFlag = FALSE; number_io_data_objects_output_cr = station_info->ioDataObjectNr; diff --git a/ui/gtk/conversation_hastables_dlg.c b/ui/gtk/conversation_hastables_dlg.c index c7c6122173..be01abd2e5 100644 --- a/ui/gtk/conversation_hastables_dlg.c +++ b/ui/gtk/conversation_hastables_dlg.c @@ -45,10 +45,8 @@ conversation_hashtable_exact_to_texbuff(gpointer key, gpointer value _U_, gpoint { gchar string_buff[CONV_STR_BUF_MAX]; GtkTextBuffer *buffer = (GtkTextBuffer*)user_data; - /*conversation_t *conversation = (conversation_t *)value;*/ - conversation_key *conv_key = (conversation_key*)key; - g_snprintf(string_buff, CONV_STR_BUF_MAX, "Key:0x%x\n",conversation_hash_exact(conv_key)); + g_snprintf(string_buff, CONV_STR_BUF_MAX, "Key:0x%x\n",conversation_hash_exact(key)); gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1); diff --git a/ui/qt/conversation_hash_tables_dialog.cpp b/ui/qt/conversation_hash_tables_dialog.cpp index 11b6cbbf0c..356b70ac71 100644 --- a/ui/qt/conversation_hash_tables_dialog.cpp +++ b/ui/qt/conversation_hash_tables_dialog.cpp @@ -61,15 +61,13 @@ ConversationHashTablesDialog::~ConversationHashTablesDialog() static void populate_html_table(gpointer data, gpointer user_data) { - const conversation_key *conv_key = (const conversation_key *)data; + const conversation_key_t conv_key = (const conversation_key_t)data; QString* html_table = (QString*)user_data; + gchar* tmp = conversation_get_html_hash(conv_key); // XXX Add a column for the hash value. - (*html_table) += QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>\n") - .arg(address_to_qstring(&conv_key->addr1)) - .arg(conv_key->port1) - .arg(address_to_qstring(&conv_key->addr2)) - .arg(conv_key->port2); + (*html_table) += QString(tmp); + wmem_free(NULL, tmp); } const QString ConversationHashTablesDialog::hashTableToHtmlTable(const QString table_name, wmem_map_t *hash_table) |