tshark: process async DNS queue during the first pass

In the first pass of two-pass wireshark, where we can do
asynchronous DNS lookups, make sure to actually take the
requests off the queue and process them, instead of waiting
until the end of the first pass.

Use a mutex to protect taking requests off the queue, just in
case.

Related to #19629.
This commit is contained in:
John Thacker 2024-02-01 06:49:44 -05:00
parent 132847b6a4
commit 1ad0cd4580
3 changed files with 25 additions and 1 deletions

View File

@ -376,6 +376,7 @@ static ares_channel ghbn_chan; /* ares_gethostbyname -- Usually interactive, tim
static gboolean async_dns_initialized = FALSE;
static guint async_dns_in_flight = 0;
static wmem_list_t *async_dns_queue_head = NULL;
static GMutex async_dns_queue_mtx;
//UAT for providing a list of DNS servers to C-ARES for name resolution
gboolean use_custom_dns_server_list = FALSE;
@ -536,6 +537,9 @@ process_async_dns_queue(void)
if (async_dns_queue_head == NULL)
return;
if (!g_mutex_trylock(&async_dns_queue_mtx))
return;
head = wmem_list_head(async_dns_queue_head);
while (head != NULL && async_dns_in_flight <= name_resolve_concurrency) {
@ -553,6 +557,8 @@ process_async_dns_queue(void)
head = wmem_list_head(async_dns_queue_head);
}
g_mutex_unlock(&async_dns_queue_mtx);
}
static void

View File

@ -192,7 +192,7 @@ WS_DLL_PUBLIC void disable_name_resolution(void);
/** If we're using c-ares process outstanding host name lookups.
* This is called from a GLIB timeout in Wireshark and before processing
* each packet in TShark.
* each packet in the first pass of two-pass TShark.
*
* @return True if any new objects have been resolved since the previous
* call. This can be used to trigger a display update, e.g. in Wireshark.

View File

@ -3273,6 +3273,24 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
from the dissection or running taps on the packet; if we're doing
any of that, we'll do it in the second pass.) */
if (edt) {
if (gbl_resolv_flags.network_name || gbl_resolv_flags.maxmind_geoip) {
/* If we're doing async lookups, send any that are queued and
* retrieve results.
*
* Ideally we'd force any lookups that need to happen on the second pass
* to be sent asynchronously on this pass so the results would be ready.
* That will happen if they're involved in a filter (because we prime the
* tree below), but not currently for taps, if we're printing packet
* summaries or details, etc.
*
* XXX - If we're running a read filter that depends on a resolved
* name, we should be doing synchronous lookups in that case. Also
* marking the dependent frames below might not work with a display
* filter that depends on a resolved name.
*/
host_name_lookup_process();
}
column_info *cinfo = NULL;
/* If we're running a read filter, prime the epan_dissect_t with that