aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/wtap.c
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2023-01-26 00:42:10 -0500
committerJohn Thacker <johnthacker@gmail.com>2023-01-30 13:29:49 +0000
commit67a01bdf263aff8581defea55a74c2e8c29df468 (patch)
tree84f08d58bf1e24730b65a462ac70cf8d5310e6ec /wiretap/wtap.c
parent3ff9f075c625b93bade74490ca360e191df017c4 (diff)
wiretap: Preserve NRBs with editcap, mergecap, and tshark
Use a pointer to the growing array of NRBs from the source file, as with DSBs, so as to handle reading NRBs in the middle of a file in one-pass mode. Write NRBs when reading a file with editcap, or in tshark when not dissecting packets and writing our own NRB. Continue not to write the NRB if we're supplying our own list of address info instead. If we have already read the entire source file in (such as in two-pass tshark), move all the NRBs to the beginning of the file before packets, as done with DSBs. When merging files with mergecap, write both sets of NRBs. (There is no attempt to merge the NRBs by looking for common entries.) Check for name resolution data in the middle of dumping a file, not just at the end, and check for DSBs at the end of a file, after all the packets. This means that Wireshark no longer writes the NRB at the very end of the file after all the packets (which is worse for future one-pass reads), and DSBs after all packets are preserved. Ping #15502
Diffstat (limited to 'wiretap/wtap.c')
-rw-r--r--wiretap/wtap.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 8e63e81f5f..fca574265d 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -440,31 +440,31 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr,
wtap_block_t
wtap_file_get_nrb(wtap *wth)
{
- if ((wth == NULL) || (wth->nrb_hdrs == NULL) || (wth->nrb_hdrs->len == 0))
+ if ((wth == NULL) || (wth->nrbs == NULL) || (wth->nrbs->len == 0))
return NULL;
- return g_array_index(wth->nrb_hdrs, wtap_block_t, 0);
+ return g_array_index(wth->nrbs, wtap_block_t, 0);
}
GArray*
wtap_file_get_nrb_for_new_file(wtap *wth)
{
guint nrb_count;
- wtap_block_t nrb_hdr_src, nrb_hdr_dest;
- GArray* nrb_hdrs;
+ wtap_block_t nrb_src, nrb_dest;
+ GArray* nrbs;
- if ((wth == NULL || wth->nrb_hdrs == NULL) || (wth->nrb_hdrs->len == 0))
+ if ((wth == NULL || wth->nrbs == NULL) || (wth->nrbs->len == 0))
return NULL;
- nrb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+ nrbs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
- for (nrb_count = 0; nrb_count < wth->nrb_hdrs->len; nrb_count++) {
- nrb_hdr_src = g_array_index(wth->nrb_hdrs, wtap_block_t, nrb_count);
- nrb_hdr_dest = wtap_block_make_copy(nrb_hdr_src);
- g_array_append_val(nrb_hdrs, nrb_hdr_dest);
+ for (nrb_count = 0; nrb_count < wth->nrbs->len; nrb_count++) {
+ nrb_src = g_array_index(wth->nrbs, wtap_block_t, nrb_count);
+ nrb_dest = wtap_block_make_copy(nrb_src);
+ g_array_append_val(nrbs, nrb_dest);
}
- return nrb_hdrs;
+ return nrbs;
}
void
@@ -479,10 +479,10 @@ wtap_dump_params_init(wtap_dump_params *params, wtap *wth)
params->tsprec = wtap_file_tsprec(wth);
params->shb_hdrs = wtap_file_get_shb_for_new_file(wth);
params->idb_inf = wtap_file_get_idb_info(wth);
- params->nrb_hdrs = wtap_file_get_nrb_for_new_file(wth);
/* Assume that the input handle remains open until the dumper is closed.
* Refer to the DSBs from the input file, wtap_dump will then copy DSBs
* as they become available. */
+ params->nrbs_growing = wth->nrbs;
params->dsbs_growing = wth->dsbs;
params->dont_copy_idbs = FALSE;
}
@@ -503,15 +503,21 @@ wtap_dump_params_init_no_idbs(wtap_dump_params *params, wtap *wth)
params->tsprec = wtap_file_tsprec(wth);
params->shb_hdrs = wtap_file_get_shb_for_new_file(wth);
params->idb_inf = wtap_file_get_idb_info(wth);
- params->nrb_hdrs = wtap_file_get_nrb_for_new_file(wth);
/* Assume that the input handle remains open until the dumper is closed.
* Refer to the DSBs from the input file, wtap_dump will then copy DSBs
* as they become available. */
+ params->nrbs_growing = wth->nrbs;
params->dsbs_growing = wth->dsbs;
params->dont_copy_idbs = TRUE;
}
void
+wtap_dump_params_discard_name_resolution(wtap_dump_params *params)
+{
+ params->nrbs_growing = NULL;
+}
+
+void
wtap_dump_params_discard_decryption_secrets(wtap_dump_params *params)
{
params->dsbs_initial = NULL;
@@ -523,7 +529,6 @@ wtap_dump_params_cleanup(wtap_dump_params *params)
{
wtap_block_array_free(params->shb_hdrs);
/* params->idb_inf is currently expected to be freed by the caller. */
- wtap_block_array_free(params->nrb_hdrs);
memset(params, 0, sizeof(*params));
}
@@ -1477,7 +1482,7 @@ wtap_close(wtap *wth)
}
wtap_block_array_free(wth->shb_hdrs);
- wtap_block_array_free(wth->nrb_hdrs);
+ wtap_block_array_free(wth->nrbs);
wtap_block_array_free(wth->interface_data);
wtap_block_array_free(wth->dsbs);
@@ -1522,18 +1527,16 @@ void wtap_set_cb_new_ipv4(wtap *wth, wtap_new_ipv4_callback_t add_new_ipv4) {
wth->add_new_ipv4 = add_new_ipv4;
- /* Are there any existing NRBs? (XXX: Unlike with DSBs, the
- * GArray of nrb_hdrs is not initialized until the first one
- * is encountered. */
- if (!wth->nrb_hdrs)
+ /* Are there any existing NRBs? */
+ if (!wth->nrbs)
return;
/*
* Send all NRBs that were read so far to the new callback. file.c
* relies on this to support redissection (during redissection, the
* previous name resolutions are lost and has to be resupplied).
*/
- for (guint i = 0; i < wth->nrb_hdrs->len; i++) {
- wtap_block_t nrb = g_array_index(wth->nrb_hdrs, wtap_block_t, i);
+ for (guint i = 0; i < wth->nrbs->len; i++) {
+ wtap_block_t nrb = g_array_index(wth->nrbs, wtap_block_t, i);
wtapng_process_nrb_ipv4(wth, nrb);
}
}
@@ -1544,18 +1547,16 @@ void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6) {
wth->add_new_ipv6 = add_new_ipv6;
- /* Are there any existing NRBs? (XXX: Unlike with DSBs, the
- * GArray of nrb_hdrs is not initialized until the first one
- * is encountered. */
- if (!wth->nrb_hdrs)
+ /* Are there any existing NRBs? */
+ if (!wth->nrbs)
return;
/*
* Send all NRBs that were read so far to the new callback. file.c
* relies on this to support redissection (during redissection, the
* previous name resolutions are lost and has to be resupplied).
*/
- for (guint i = 0; i < wth->nrb_hdrs->len; i++) {
- wtap_block_t nrb = g_array_index(wth->nrb_hdrs, wtap_block_t, i);
+ for (guint i = 0; i < wth->nrbs->len; i++) {
+ wtap_block_t nrb = g_array_index(wth->nrbs, wtap_block_t, i);
wtapng_process_nrb_ipv6(wth, nrb);
}
}