diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-04-19 04:04:12 -0700 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2014-04-19 14:20:06 +0000 |
commit | 80011ec03c034cbebbe901eb4ded1242efe8fc78 (patch) | |
tree | e10045f12229249b2e348fd8e288b6ecf6ad1074 | |
parent | 1d574597ec2dfed1ba7674866e8634d7f1ed988b (diff) |
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>
-rw-r--r-- | epan/addr_resolv.c | 67 | ||||
-rw-r--r-- | epan/address_to_str.c | 11 | ||||
-rw-r--r-- | epan/column-utils.c | 12 | ||||
-rw-r--r-- | epan/to_str.h | 1 | ||||
-rwxr-xr-x | tools/checkAPIs.pl | 1 |
5 files changed, 36 insertions, 56 deletions
diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index 5ee4da70e4..bdc7c9650f 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -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); - /* We need a "permanently" allocated string */ - return se_address_to_str(addr); + default: + return NULL; + } } void diff --git a/epan/address_to_str.c b/epan/address_to_str.c index 9ec0229a44..2ae8b2af93 100644 --- a/epan/address_to_str.c +++ b/epan/address_to_str.c @@ -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) { diff --git a/epan/column-utils.c b/epan/column-utils.c index 7f10c03f30..0bf6883160 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -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; diff --git a/epan/to_str.h b/epan/to_str.h index 8ac171b1d2..edd9d77c57 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -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); diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl index 1b87dd6cdb..de48d6d3ee 100755 --- a/tools/checkAPIs.pl +++ b/tools/checkAPIs.pl @@ -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', |