Have circuit functionality more closely mirror conversation functionality
This will allow for a smoother transition for refactoring because circuit functionality can now be represented as a strict subset of conversation functionality. Change-Id: I323d7facad707c81b8e35b33143fa1102d6b5976 Reviewed-on: https://code.wireshark.org/review/24290 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
f8a1878202
commit
371b5c526b
|
@ -26,6 +26,11 @@
|
|||
#include "packet.h"
|
||||
#include "circuit.h"
|
||||
|
||||
struct circuit_key {
|
||||
circuit_type ctype;
|
||||
guint32 circuit_id;
|
||||
};
|
||||
|
||||
/*
|
||||
* Hash table for circuits.
|
||||
*/
|
||||
|
@ -33,22 +38,13 @@ static GHashTable *circuit_hashtable = NULL;
|
|||
|
||||
static guint32 new_index;
|
||||
|
||||
/*
|
||||
* Protocol-specific data attached to a circuit_t structure - protocol
|
||||
* index and opaque pointer.
|
||||
*/
|
||||
typedef struct _circuit_proto_data {
|
||||
int proto;
|
||||
void *proto_data;
|
||||
} circuit_proto_data;
|
||||
|
||||
/*
|
||||
* Compute the hash value for a circuit.
|
||||
*/
|
||||
static guint
|
||||
circuit_hash(gconstpointer v)
|
||||
{
|
||||
const circuit_key *key = (const circuit_key *)v;
|
||||
const circuit_key_t key = (const circuit_key_t)v;
|
||||
|
||||
return key->ctype ^ key->circuit_id;
|
||||
}
|
||||
|
@ -59,8 +55,8 @@ circuit_hash(gconstpointer v)
|
|||
static gint
|
||||
circuit_match(gconstpointer v, gconstpointer w)
|
||||
{
|
||||
const circuit_key *v1 = (const circuit_key *)v;
|
||||
const circuit_key *v2 = (const circuit_key *)w;
|
||||
const circuit_key_t v1 = (const circuit_key_t)v;
|
||||
const circuit_key_t v2 = (const circuit_key_t)w;
|
||||
|
||||
return v1->ctype == v2->ctype && v1->circuit_id == v2->circuit_id;
|
||||
}
|
||||
|
@ -110,7 +106,7 @@ circuit_t *
|
|||
circuit_new(circuit_type ctype, guint32 circuit_id, guint32 first_frame)
|
||||
{
|
||||
circuit_t *circuit, *old_circuit;
|
||||
circuit_key *new_key;
|
||||
circuit_key_t new_key;
|
||||
|
||||
new_key = wmem_new(wmem_file_scope(), struct circuit_key);
|
||||
new_key->ctype = ctype;
|
||||
|
@ -122,7 +118,7 @@ circuit_new(circuit_type ctype, guint32 circuit_id, guint32 first_frame)
|
|||
circuit->last_frame = 0; /* not known yet */
|
||||
circuit->circuit_index = new_index;
|
||||
circuit->data_list = NULL;
|
||||
circuit->dissector_handle = NULL;
|
||||
circuit->dissector_tree = wmem_tree_new(wmem_file_scope());
|
||||
circuit->key_ptr = new_key;
|
||||
|
||||
new_index++;
|
||||
|
@ -166,7 +162,7 @@ circuit_new(circuit_type ctype, guint32 circuit_id, guint32 first_frame)
|
|||
circuit_t *
|
||||
find_circuit(circuit_type ctype, guint32 circuit_id, guint32 frame)
|
||||
{
|
||||
circuit_key key;
|
||||
struct circuit_key key;
|
||||
circuit_t *circuit;
|
||||
|
||||
key.ctype = ctype;
|
||||
|
@ -207,80 +203,46 @@ close_circuit(circuit_t *circuit, guint32 last_frame)
|
|||
circuit->last_frame = last_frame;
|
||||
}
|
||||
|
||||
static gint
|
||||
p_compare(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const circuit_proto_data *ap = (const circuit_proto_data *)a;
|
||||
const circuit_proto_data *bp = (const circuit_proto_data *)b;
|
||||
|
||||
if (ap->proto > bp->proto)
|
||||
return 1;
|
||||
else if (ap->proto == bp->proto)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
circuit_add_proto_data(circuit_t *conv, int proto, void *proto_data)
|
||||
{
|
||||
circuit_proto_data *p1 = wmem_new(wmem_file_scope(), circuit_proto_data);
|
||||
/* Add it to the list of items for this conversation. */
|
||||
if (conv->data_list == NULL)
|
||||
conv->data_list = wmem_tree_new(wmem_file_scope());
|
||||
|
||||
p1->proto = proto;
|
||||
p1->proto_data = proto_data;
|
||||
|
||||
/* Add it to the list of items for this circuit. */
|
||||
|
||||
conv->data_list = g_slist_insert_sorted(conv->data_list, (gpointer *)p1,
|
||||
p_compare);
|
||||
wmem_tree_insert32(conv->data_list, proto, proto_data);
|
||||
}
|
||||
|
||||
void *
|
||||
circuit_get_proto_data(circuit_t *conv, int proto)
|
||||
{
|
||||
circuit_proto_data temp, *p1;
|
||||
GSList *item;
|
||||
/* No tree created yet */
|
||||
if (conv->data_list == NULL)
|
||||
return NULL;
|
||||
|
||||
temp.proto = proto;
|
||||
temp.proto_data = NULL;
|
||||
|
||||
item = g_slist_find_custom(conv->data_list, (gpointer *)&temp,
|
||||
p_compare);
|
||||
|
||||
if (item != NULL) {
|
||||
p1 = (circuit_proto_data *)item->data;
|
||||
return p1->proto_data;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return wmem_tree_lookup32(conv->data_list, proto);
|
||||
}
|
||||
|
||||
void
|
||||
circuit_delete_proto_data(circuit_t *conv, int proto)
|
||||
{
|
||||
circuit_proto_data temp;
|
||||
GSList *item;
|
||||
|
||||
temp.proto = proto;
|
||||
temp.proto_data = NULL;
|
||||
|
||||
item = g_slist_find_custom(conv->data_list, (gpointer *)&temp,
|
||||
p_compare);
|
||||
|
||||
if (item != NULL)
|
||||
conv->data_list = g_slist_remove(conv->data_list, item);
|
||||
if (conv->data_list != NULL)
|
||||
wmem_tree_remove32(conv->data_list, proto);
|
||||
}
|
||||
|
||||
void
|
||||
circuit_set_dissector(circuit_t *circuit, dissector_handle_t handle)
|
||||
{
|
||||
circuit->dissector_handle = handle;
|
||||
wmem_tree_insert32(circuit->dissector_tree, 0, (void *)handle);
|
||||
}
|
||||
|
||||
dissector_handle_t
|
||||
circuit_get_dissector(circuit_t *circuit)
|
||||
{
|
||||
return circuit->dissector_handle;
|
||||
if (circuit == NULL)
|
||||
return NULL;
|
||||
|
||||
return (dissector_handle_t)wmem_tree_lookup32_le(circuit->dissector_tree, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -293,14 +255,15 @@ try_circuit_dissector(circuit_type ctype, guint32 circuit_id, guint32 frame,
|
|||
tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
|
||||
{
|
||||
circuit_t *circuit;
|
||||
dissector_handle_t handle;
|
||||
|
||||
circuit = find_circuit(ctype, circuit_id, frame);
|
||||
|
||||
if (circuit != NULL) {
|
||||
if (circuit->dissector_handle == NULL)
|
||||
handle = circuit_get_dissector(circuit);
|
||||
if (handle == NULL)
|
||||
return FALSE;
|
||||
call_dissector_with_data(circuit->dissector_handle, tvb, pinfo,
|
||||
tree, data);
|
||||
call_dissector_with_data(handle, tvb, pinfo, tree, data);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
|
|
@ -33,20 +33,18 @@ extern "C" {
|
|||
/**
|
||||
* Data structure representing a circuit.
|
||||
*/
|
||||
typedef struct circuit_key {
|
||||
circuit_type ctype;
|
||||
guint32 circuit_id;
|
||||
} circuit_key;
|
||||
struct circuit_key;
|
||||
typedef struct circuit_key* circuit_key_t;
|
||||
|
||||
typedef struct circuit {
|
||||
struct circuit *next; /**< pointer to next circuit with given circuit ID */
|
||||
guint32 first_frame; /**< # of first frame for that circuit */
|
||||
guint32 last_frame; /**< # of last frame for that circuit */
|
||||
guint32 circuit_index; /**< unique ID for circuit */
|
||||
GSList *data_list; /**< list of data associated with circuit */
|
||||
dissector_handle_t dissector_handle; /**< handle for protocol dissector client associated with circuit */
|
||||
wmem_tree_t *data_list; /**< list of data associated with circuit */
|
||||
wmem_tree_t *dissector_tree; /** tree containing protocol dissector client associated with circuit */
|
||||
guint options; /**< wildcard flags */
|
||||
circuit_key *key_ptr; /**< pointer to the key for this circuit */
|
||||
circuit_key_t key_ptr; /**< pointer to the key for this circuit */
|
||||
} circuit_t;
|
||||
|
||||
/**
|
||||
|
|
|
@ -3892,8 +3892,8 @@ dissect_dvbci_payload_lsc(guint32 tag, gint len_field,
|
|||
msg_tvb = tvb_new_subset_remaining(tvb, offset);
|
||||
if (!msg_tvb)
|
||||
break;
|
||||
if (dvbci_dissect_lsc_msg && circuit && circuit->dissector_handle) {
|
||||
msg_handle = circuit->dissector_handle;
|
||||
if (dvbci_dissect_lsc_msg && circuit_get_dissector(circuit)) {
|
||||
msg_handle = circuit_get_dissector(circuit);
|
||||
col_append_str(pinfo->cinfo, COL_INFO, ", ");
|
||||
col_set_fence(pinfo->cinfo, COL_INFO);
|
||||
col_append_str(pinfo->cinfo, COL_PROTOCOL, ", ");
|
||||
|
@ -4133,8 +4133,9 @@ dissect_dvbci_payload_sas(guint32 tag, gint len_field _U_,
|
|||
tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
offset += 2;
|
||||
msg_tvb = tvb_new_subset_length(tvb, offset, msg_len);
|
||||
msg_handle = (circuit && circuit->dissector_handle) ?
|
||||
circuit->dissector_handle : data_handle;
|
||||
msg_handle = circuit_get_dissector(circuit);
|
||||
if (msg_handle == NULL)
|
||||
msg_handle = data_handle;
|
||||
call_dissector(msg_handle, msg_tvb, pinfo, tree);
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue