forked from osmocom/wireshark
Don't se_ allocate strings when mapping addresses to column strings.
This should significantly reduce memory usage, without increasing the CPU time required to process a capture file in TShark or Wireshark. As a result, se_address_to_str() is no longer used; eliminate it. Fixes bug #9949. Change-Id: I65a112a426c82cc73a957b81384c765c3d14f2c3 Reviewed-on: https://code.wireshark.org/review/1213 Reviewed-by: Evan Huus <eapache@gmail.com>
This commit is contained in:
parent
1d574597ec
commit
80011ec03c
|
@ -1055,34 +1055,6 @@ solve_address_to_name(const address *addr)
|
|||
}
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
se_solve_address_to_name(const address *addr)
|
||||
{
|
||||
switch (addr->type) {
|
||||
|
||||
case AT_ETHER:
|
||||
return get_ether_name((const guint8 *)addr->data);
|
||||
|
||||
case AT_IPv4: {
|
||||
guint32 ip4_addr;
|
||||
memcpy(&ip4_addr, addr->data, sizeof ip4_addr);
|
||||
return get_hostname(ip4_addr);
|
||||
}
|
||||
|
||||
case AT_IPv6: {
|
||||
struct e_in6_addr ip6_addr;
|
||||
memcpy(&ip6_addr.bytes, addr->data, sizeof ip6_addr.bytes);
|
||||
return get_hostname6(&ip6_addr);
|
||||
}
|
||||
|
||||
case AT_STRINGZ:
|
||||
return se_strdup((const gchar *)addr->data);
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Ethernet / manufacturer resolution
|
||||
*
|
||||
|
@ -3036,25 +3008,42 @@ get_addr_name(const address *addr)
|
|||
return ep_address_to_str(addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX - we should rename get_addr_name() to ep_addr_name(), to indicate
|
||||
* that the scope of the string it returns may be as short-lived as
|
||||
* an ep_allocated string (although it may be longer-lived), and
|
||||
* rename this to get_addr_name(), as its strings have the same scope
|
||||
* as the get_XXX_name() routines it calls.
|
||||
*/
|
||||
const gchar *
|
||||
se_get_addr_name(const address *addr)
|
||||
{
|
||||
const gchar *result;
|
||||
guint32 ip4_addr;
|
||||
struct e_in6_addr ip6_addr;
|
||||
|
||||
result = se_solve_address_to_name(addr);
|
||||
/*
|
||||
* Try to look up a name for this address.
|
||||
* If it's not found, this might return a string corresponding to
|
||||
* the address, or it might return NULL.
|
||||
*
|
||||
* Whatever string is returned has at least session scope.
|
||||
*/
|
||||
switch (addr->type) {
|
||||
|
||||
if (result != NULL)
|
||||
return result;
|
||||
case AT_ETHER:
|
||||
return get_ether_name((const guint8 *)addr->data);
|
||||
|
||||
/* if it gets here, either it is of type AT_NONE, */
|
||||
/* or it should be solvable in se_address_to_str -unless addr->type is wrongly defined */
|
||||
case AT_IPv4:
|
||||
memcpy(&ip4_addr, addr->data, sizeof ip4_addr);
|
||||
return get_hostname(ip4_addr);
|
||||
|
||||
if (addr->type == AT_NONE){
|
||||
return "NONE";
|
||||
case AT_IPv6:
|
||||
memcpy(&ip6_addr.bytes, addr->data, sizeof ip6_addr.bytes);
|
||||
return get_hostname6(&ip6_addr);
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We need a "permanently" allocated string */
|
||||
return se_address_to_str(addr);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -541,17 +541,6 @@ ep_address_to_str(const address *addr)
|
|||
return str;
|
||||
}
|
||||
|
||||
/* The called routines use se_alloc'ed memory */
|
||||
gchar*
|
||||
se_address_to_str(const address *addr)
|
||||
{
|
||||
gchar *str;
|
||||
|
||||
str=(gchar *)se_alloc(MAX_ADDR_STR_LEN);
|
||||
address_to_str_buf(addr, str, MAX_ADDR_STR_LEN);
|
||||
return str;
|
||||
}
|
||||
|
||||
void
|
||||
address_to_str_buf(const address *addr, gchar *buf, int buf_len)
|
||||
{
|
||||
|
|
|
@ -1590,15 +1590,19 @@ static void
|
|||
col_set_addr(packet_info *pinfo, const int col, const address *addr, const gboolean is_src,
|
||||
const gboolean fill_col_exprs, const gboolean res)
|
||||
{
|
||||
const char *name;
|
||||
|
||||
if (addr->type == AT_NONE) {
|
||||
/* No address, nothing to do */
|
||||
return;
|
||||
}
|
||||
|
||||
if (res)
|
||||
pinfo->cinfo->col_data[col] = se_get_addr_name(addr);
|
||||
else
|
||||
pinfo->cinfo->col_data[col] = se_address_to_str(addr);
|
||||
if (res && (name = se_get_addr_name(addr)) != NULL)
|
||||
pinfo->cinfo->col_data[col] = name;
|
||||
else {
|
||||
pinfo->cinfo->col_data[col] = pinfo->cinfo->col_buf[col];
|
||||
address_to_str_buf(addr, pinfo->cinfo->col_buf[col], COL_MAX_LEN);
|
||||
}
|
||||
|
||||
if (!fill_col_exprs)
|
||||
return;
|
||||
|
|
|
@ -51,7 +51,6 @@ struct e_in6_addr;
|
|||
|
||||
WS_DLL_PUBLIC gchar* address_to_str(wmem_allocator_t *scope, const address *addr);
|
||||
WS_DLL_PUBLIC gchar* ep_address_to_str(const address *);
|
||||
extern gchar* se_address_to_str(const address *);
|
||||
WS_DLL_PUBLIC void address_to_str_buf(const address *addr, gchar *buf, int buf_len);
|
||||
WS_DLL_PUBLIC const gchar* ether_to_str(const guint8 *);
|
||||
WS_DLL_PUBLIC const gchar* tvb_ether_to_str(tvbuff_t *tvb, const gint offset);
|
||||
|
|
|
@ -163,7 +163,6 @@ my %APIs = (
|
|||
'se_strdup_vprintf',
|
||||
'se_strdup_printf',
|
||||
'se_alloc_array',
|
||||
'se_address_to_str',
|
||||
'se_tree_create',
|
||||
'se_tree_insert32',
|
||||
'se_tree_lookup32',
|
||||
|
|
Loading…
Reference in New Issue