#include "proto.h"
#include "conversation_table.h"
#include "addr_resolv.h"
-#include "emem.h"
-#include "stat_cmd_args.h"
-
-GList *cmd_string_list_ = NULL;
+#include "stat_tap_ui.h"
struct register_ct {
gboolean hide_ports; /* hide TCP / UDP port columns */
int proto_id; /* protocol id (0-indexed) */
tap_packet_cb conv_func; /* function to be called for new incoming packets for conversation*/
tap_packet_cb host_func; /* function to be called for new incoming packets for hostlist */
- host_tap_prefix prefix_func; /* function to provide prefix if different than default (host) */
conv_gui_init_cb conv_gui_init; /* GUI specific function to initialize conversation */
host_gui_init_cb host_gui_init; /* GUI specific function to initialize hostlist */
};
return ct->host_func;
}
-host_tap_prefix get_hostlist_prefix_func(register_ct_t* ct)
-{
- return ct->prefix_func;
-}
-
-
static GSList *registered_ct_tables = NULL;
void
g_string_append(cmd_str, proto_get_protocol_filter_name(table->proto_id));
if(!strncmp(opt_arg, cmd_str->str, cmd_str->len)){
- filter = opt_arg + cmd_str->len;
- } else {
- filter = NULL;
+ if (opt_arg[cmd_str->len] == ',') {
+ filter = opt_arg + cmd_str->len + 1;
+ }
}
g_string_free(cmd_str, TRUE);
GString *cmd_str = g_string_new("");
const char *filter=NULL;
- g_string_printf(cmd_str, "%s,%s,", (table->prefix_func != NULL) ? table->prefix_func() : "host", proto_get_protocol_filter_name(table->proto_id));
+ g_string_printf(cmd_str, "%s,%s,", HOSTLIST_TAP_PREFIX, proto_get_protocol_filter_name(table->proto_id));
if(!strncmp(opt_arg, cmd_str->str, cmd_str->len)){
- filter=opt_arg+cmd_str->len;
+ if (opt_arg[cmd_str->len] == ',') {
+ filter = opt_arg + cmd_str->len + 1;
+ }
} else {
filter=NULL;
}
}
void
-register_conversation_table(const int proto_id, gboolean hide_ports, tap_packet_cb conv_packet_func, tap_packet_cb hostlist_func, host_tap_prefix prefix_func)
+register_conversation_table(const int proto_id, gboolean hide_ports, tap_packet_cb conv_packet_func, tap_packet_cb hostlist_func)
{
register_ct_t *table;
- GString *conv_cmd_str = g_string_new("conv,");
- GString *host_cmd_str = g_string_new("");
- tap_ui ui_info;
table = g_new(register_ct_t,1);
table->host_func = hostlist_func;
table->conv_gui_init = NULL;
table->host_gui_init = NULL;
- table->prefix_func = prefix_func;
registered_ct_tables = g_slist_insert_sorted(registered_ct_tables, table, insert_sorted_by_table_name);
-
- g_string_append(conv_cmd_str, proto_get_protocol_filter_name(table->proto_id));
- cmd_string_list_ = g_list_append(cmd_string_list_, conv_cmd_str->str);
- ui_info.group = REGISTER_STAT_GROUP_CONVERSATION_LIST;
- ui_info.title = NULL; /* construct this from the protocol info? */
- ui_info.cli_string = conv_cmd_str->str;
- ui_info.tap_init_cb = dissector_conversation_init;
- ui_info.index = -1;
- ui_info.nparams = 0;
- ui_info.params = NULL;
- register_tap_ui(&ui_info, table);
- g_string_free(conv_cmd_str, FALSE);
-
- g_string_printf(host_cmd_str, "%s,%s", (get_hostlist_prefix_func(table) != NULL) ? get_hostlist_prefix_func(table)() : "host",
- proto_get_protocol_filter_name(table->proto_id));
- ui_info.group = REGISTER_STAT_GROUP_ENDPOINT_LIST;
- ui_info.title = NULL; /* construct this from the protocol info? */
- ui_info.cli_string = host_cmd_str->str;
- ui_info.tap_init_cb = dissector_hostlist_init;
- ui_info.index = -1;
- ui_info.nparams = 0;
- ui_info.params = NULL;
- register_tap_ui(&ui_info, table);
- g_string_free(host_cmd_str, FALSE);
}
/* Set GUI fields for register_ct list */
static void
set_conv_gui_data(gpointer data, gpointer user_data)
{
+ GString *conv_cmd_str = g_string_new("conv,");
+ stat_tap_ui ui_info;
register_ct_t *table = (register_ct_t*)data;
+
table->conv_gui_init = (conv_gui_init_cb)user_data;
+
+ g_string_append(conv_cmd_str, proto_get_protocol_filter_name(table->proto_id));
+ ui_info.group = REGISTER_STAT_GROUP_CONVERSATION_LIST;
+ ui_info.title = NULL; /* construct this from the protocol info? */
+ ui_info.cli_string = g_string_free(conv_cmd_str, FALSE);
+ ui_info.tap_init_cb = dissector_conversation_init;
+ ui_info.nparams = 0;
+ ui_info.params = NULL;
+ register_stat_tap_ui(&ui_info, table);
}
void conversation_table_set_gui_info(conv_gui_init_cb init_cb)
static void
set_host_gui_data(gpointer data, gpointer user_data)
{
+ GString *host_cmd_str = g_string_new("");
+ stat_tap_ui ui_info;
register_ct_t *table = (register_ct_t*)data;
+
table->host_gui_init = (host_gui_init_cb)user_data;
+
+ g_string_printf(host_cmd_str, "%s,%s", HOSTLIST_TAP_PREFIX, proto_get_protocol_filter_name(table->proto_id));
+ ui_info.group = REGISTER_STAT_GROUP_ENDPOINT_LIST;
+ ui_info.title = NULL; /* construct this from the protocol info? */
+ ui_info.cli_string = g_string_free(host_cmd_str, FALSE);
+ ui_info.tap_init_cb = dissector_hostlist_init;
+ ui_info.nparams = 0;
+ ui_info.params = NULL;
+ register_stat_tap_ui(&ui_info, table);
}
void hostlist_table_set_gui_info(host_gui_init_cb init_cb)
guint hash_val;
hash_val = 0;
- ADD_ADDRESS_TO_HASH(hash_val, &key->addr1);
+ add_address_to_hash(hash_val, &key->addr1);
hash_val += key->port1;
- ADD_ADDRESS_TO_HASH(hash_val, &key->addr2);
+ add_address_to_hash(hash_val, &key->addr2);
hash_val += key->port2;
hash_val ^= key->conv_id;
{
if (ck1->port1 == ck2->port1 &&
ck1->port2 == ck2->port2 &&
- ADDRESSES_EQUAL(&ck1->addr1, &ck2->addr1) &&
- ADDRESSES_EQUAL(&ck1->addr2, &ck2->addr2)) {
+ addresses_equal(&ck1->addr1, &ck2->addr1) &&
+ addresses_equal(&ck1->addr2, &ck2->addr2)) {
return TRUE;
}
if (ck1->port2 == ck2->port1 &&
ck1->port1 == ck2->port2 &&
- ADDRESSES_EQUAL(&ck1->addr2, &ck2->addr1) &&
- ADDRESSES_EQUAL(&ck1->addr1, &ck2->addr2)) {
+ addresses_equal(&ck1->addr2, &ck2->addr1) &&
+ addresses_equal(&ck1->addr1, &ck2->addr2)) {
return TRUE;
}
}
ch->hashtable=NULL;
}
-const char *get_conversation_address(address *addr, gboolean resolve_names)
+const char *get_conversation_address(wmem_allocator_t *allocator, address *addr, gboolean resolve_names)
{
if (resolve_names) {
- return ep_address_to_display(addr);
+ return address_to_display(allocator, addr);
} else {
- return ep_address_to_str(addr);
+ return address_to_str(allocator, addr);
}
}
-const char *get_conversation_port(guint32 port, port_type ptype, gboolean resolve_names)
+const char *get_conversation_port(wmem_allocator_t *allocator, guint32 port, port_type ptype, gboolean resolve_names)
{
if(!resolve_names) ptype = PT_NONE;
switch(ptype) {
case(PT_TCP):
- return ep_tcp_port_to_display(port);
+ return tcp_port_to_display(allocator, port);
case(PT_UDP):
- return ep_udp_port_to_display(port);
+ return udp_port_to_display(allocator, port);
case(PT_SCTP):
- return ep_sctp_port_to_display(port);
+ return sctp_port_to_display(allocator, port);
default:
- return ep_strdup_printf("%d", port);
+ return wmem_strdup_printf(allocator, "%d", port);
}
}
const char *get_conversation_filter(conv_item_t *conv_item, conv_direction_e direction)
{
- char *sport, *dport;
+ char *sport, *dport, *src_addr, *dst_addr;
const char *str = "INVALID";
sport = ct_port_to_str(conv_item->ptype, conv_item->src_port);
dport = ct_port_to_str(conv_item->ptype, conv_item->dst_port);
+ src_addr = address_to_str(NULL, &conv_item->src_address);
+ dst_addr = address_to_str(NULL, &conv_item->dst_address);
+
+ if (conv_item->src_address.type == AT_STRINGZ || conv_item->src_address.type == AT_USB) {
+ char *new_addr;
+
+ new_addr = wmem_strdup_printf(NULL, "\"%s\"", src_addr);
+ wmem_free(NULL, src_addr);
+ src_addr = new_addr;
+ }
+ if (conv_item->dst_address.type == AT_STRINGZ || conv_item->dst_address.type == AT_USB) {
+ char *new_addr;
+
+ new_addr = wmem_strdup_printf(NULL, "\"%s\"", dst_addr);
+ wmem_free(NULL, dst_addr);
+ dst_addr = new_addr;
+ }
switch(direction){
case CONV_DIR_A_TO_FROM_B:
/* A <-> B */
- str = ep_strdup_printf("%s==%s%s%s%s%s && %s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s && %s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_ANY_ADDRESS),
- ep_address_to_str(&conv_item->src_address),
+ src_addr,
sport?" && ":"",
sport?conversation_get_filter_name(conv_item, CONV_FT_ANY_PORT):"",
sport?"==":"",
sport?sport:"",
conversation_get_filter_name(conv_item, CONV_FT_ANY_ADDRESS),
- ep_address_to_str(&conv_item->dst_address),
+ dst_addr,
dport?" && ":"",
dport?conversation_get_filter_name(conv_item, CONV_FT_ANY_PORT):"",
dport?"==":"",
break;
case CONV_DIR_A_TO_B:
/* A --> B */
- str = ep_strdup_printf("%s==%s%s%s%s%s && %s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s && %s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_SRC_ADDRESS),
- ep_address_to_str(&conv_item->src_address),
+ src_addr,
sport?" && ":"",
sport?conversation_get_filter_name(conv_item, CONV_FT_SRC_PORT):"",
sport?"==":"",
sport?sport:"",
conversation_get_filter_name(conv_item, CONV_FT_DST_ADDRESS),
- ep_address_to_str(&conv_item->dst_address),
+ dst_addr,
dport?" && ":"",
dport?conversation_get_filter_name(conv_item, CONV_FT_DST_PORT):"",
dport?"==":"",
break;
case CONV_DIR_A_FROM_B:
/* A <-- B */
- str = ep_strdup_printf("%s==%s%s%s%s%s && %s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s && %s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_DST_ADDRESS),
- ep_address_to_str(&conv_item->src_address),
+ src_addr,
sport?" && ":"",
sport?conversation_get_filter_name(conv_item, CONV_FT_DST_PORT):"",
sport?"==":"",
sport?sport:"",
conversation_get_filter_name(conv_item, CONV_FT_SRC_ADDRESS),
- ep_address_to_str(&conv_item->dst_address),
+ dst_addr,
dport?" && ":"",
dport?conversation_get_filter_name(conv_item, CONV_FT_SRC_PORT):"",
dport?"==":"",
break;
case CONV_DIR_A_TO_FROM_ANY:
/* A <-> ANY */
- str = ep_strdup_printf("%s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_ANY_ADDRESS),
- ep_address_to_str(&conv_item->src_address),
+ src_addr,
sport?" && ":"",
sport?conversation_get_filter_name(conv_item, CONV_FT_ANY_PORT):"",
sport?"==":"",
break;
case CONV_DIR_A_TO_ANY:
/* A --> ANY */
- str = ep_strdup_printf("%s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_SRC_ADDRESS),
- ep_address_to_str(&conv_item->src_address),
+ src_addr,
sport?" && ":"",
sport?conversation_get_filter_name(conv_item, CONV_FT_SRC_PORT):"",
sport?"==":"",
break;
case CONV_DIR_A_FROM_ANY:
/* A <-- ANY */
- str = ep_strdup_printf("%s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_DST_ADDRESS),
- ep_address_to_str(&conv_item->src_address),
+ src_addr,
sport?" && ":"",
sport?conversation_get_filter_name(conv_item, CONV_FT_DST_PORT):"",
sport?"==":"",
break;
case CONV_DIR_ANY_TO_FROM_B:
/* ANY <-> B */
- str = ep_strdup_printf("%s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_ANY_ADDRESS),
- ep_address_to_str(&conv_item->dst_address),
+ dst_addr,
dport?" && ":"",
dport?conversation_get_filter_name(conv_item, CONV_FT_ANY_PORT):"",
dport?"==":"",
break;
case CONV_DIR_ANY_FROM_B:
/* ANY <-- B */
- str = ep_strdup_printf("%s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_SRC_ADDRESS),
- ep_address_to_str(&conv_item->dst_address),
+ dst_addr,
dport?" && ":"",
dport?conversation_get_filter_name(conv_item, CONV_FT_SRC_PORT):"",
dport?"==":"",
break;
case CONV_DIR_ANY_TO_B:
/* ANY --> B */
- str = ep_strdup_printf("%s==%s%s%s%s%s",
+ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s",
conversation_get_filter_name(conv_item, CONV_FT_DST_ADDRESS),
- ep_address_to_str(&conv_item->dst_address),
+ dst_addr,
dport?" && ":"",
dport?conversation_get_filter_name(conv_item, CONV_FT_DST_PORT):"",
dport?"==":"",
}
g_free(sport);
g_free(dport);
+ wmem_free(NULL, src_addr);
+ wmem_free(NULL, dst_addr);
return str;
}
const char *get_hostlist_filter(hostlist_talker_t *host)
{
- char *sport;
+ char *sport, *src_addr;
const char *str;
sport=ct_port_to_str(host->ptype, host->port);
+ src_addr = address_to_str(NULL, &host->myaddress);
+ if (host->myaddress.type == AT_STRINGZ || host->myaddress.type == AT_USB) {
+ char *new_addr;
+
+ new_addr = wmem_strdup_printf(NULL, "\"%s\"", src_addr);
+ wmem_free(NULL, src_addr);
+ src_addr = new_addr;
+ }
str = g_strdup_printf("%s==%s%s%s%s%s",
hostlist_get_filter_name(host, CONV_FT_ANY_ADDRESS),
- ep_address_to_str(&host->myaddress),
+ src_addr,
sport?" && ":"",
sport?hostlist_get_filter_name(host, CONV_FT_ANY_PORT):"",
sport?"==":"",
sport?sport:"");
+ g_free(sport);
+ wmem_free(NULL, src_addr);
return str;
}
addr1 = dst;
port2 = src_port;
port1 = dst_port;
- } else if (CMP_ADDRESS(src, dst) < 0) {
+ } else if (cmp_address(src, dst) < 0) {
addr1 = src;
addr2 = dst;
port1 = src_port;
} else {
/* try to find it among the existing known conversations */
conv_key_t existing_key;
+ gpointer conversation_idx_hash_val;
existing_key.addr1 = *addr1;
existing_key.addr2 = *addr2;
existing_key.port1 = port1;
existing_key.port2 = port2;
existing_key.conv_id = conv_id;
- if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, (gpointer *) &conversation_idx)) {
- conv_item = &g_array_index(ch->conv_array, conv_item_t, conversation_idx);
+ if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, &conversation_idx_hash_val)) {
+ conv_item = &g_array_index(ch->conv_array, conv_item_t, GPOINTER_TO_UINT(conversation_idx_hash_val));
}
}
conv_key_t *new_key;
conv_item_t new_conv_item;
- COPY_ADDRESS(&new_conv_item.src_address, addr1);
- COPY_ADDRESS(&new_conv_item.dst_address, addr2);
+ copy_address(&new_conv_item.src_address, addr1);
+ copy_address(&new_conv_item.dst_address, addr2);
new_conv_item.dissector_info = ct_info;
new_conv_item.ptype = ptype;
new_conv_item.src_port = port1;
/* ct->conversations address is not a constant but src/dst_address.data are */
new_key = g_new(conv_key_t, 1);
- SET_ADDRESS(&new_key->addr1, conv_item->src_address.type, conv_item->src_address.len, conv_item->src_address.data);
- SET_ADDRESS(&new_key->addr2, conv_item->dst_address.type, conv_item->dst_address.len, conv_item->dst_address.data);
+ set_address(&new_key->addr1, conv_item->src_address.type, conv_item->src_address.len, conv_item->src_address.data);
+ set_address(&new_key->addr2, conv_item->dst_address.type, conv_item->dst_address.len, conv_item->dst_address.data);
new_key->port1 = port1;
new_key->port2 = port2;
new_key->conv_id = conv_id;
/* update the conversation struct */
conv_item->modified = TRUE;
- if ( (!CMP_ADDRESS(src, addr1)) && (!CMP_ADDRESS(dst, addr2)) && (src_port==port1) && (dst_port==port2) ) {
+ if ( (!cmp_address(src, addr1)) && (!cmp_address(dst, addr2)) && (src_port==port1) && (dst_port==port2) ) {
conv_item->tx_frames += num_frames;
conv_item->tx_bytes += num_bytes;
} else {
guint hash_val;
hash_val = 0;
- ADD_ADDRESS_TO_HASH(hash_val, &key->myaddress);
+ add_address_to_hash(hash_val, &key->myaddress);
hash_val += key->port;
return hash_val;
}
const host_key_t *v2 = (const host_key_t *)w;
if (v1->port == v2->port &&
- ADDRESSES_EQUAL(&v1->myaddress, &v2->myaddress)) {
+ addresses_equal(&v1->myaddress, &v2->myaddress)) {
return 1;
}
/*
else {
/* try to find it among the existing known conversations */
host_key_t existing_key;
+ gpointer talker_idx_hash_val;
existing_key.myaddress = *addr;
existing_key.port = port;
- if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, (gpointer *) &talker_idx)) {
- talker = &g_array_index(ch->conv_array, hostlist_talker_t, talker_idx);
+ if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, &talker_idx_hash_val)) {
+ talker = &g_array_index(ch->conv_array, hostlist_talker_t, GPOINTER_TO_UINT(talker_idx_hash_val));
}
}
host_key_t *new_key;
hostlist_talker_t host;
- COPY_ADDRESS(&host.myaddress, addr);
+ copy_address(&host.myaddress, addr);
host.dissector_info = host_info;
host.ptype=port_type_val;
host.port=port;
/* hl->hosts address is not a constant but address.data is */
new_key = g_new(host_key_t,1);
- SET_ADDRESS(&new_key->myaddress, talker->myaddress.type, talker->myaddress.len, talker->myaddress.data);
+ set_address(&new_key->myaddress, talker->myaddress.type, talker->myaddress.len, talker->myaddress.data);
new_key->port = port;
g_hash_table_insert(ch->hashtable, new_key, GUINT_TO_POINTER(talker_idx));
}