Don't keep the pcap/pcapng link-layer header type as interface data.

Either 1) it can be determined from the libwiretap encapsulation type,
in which case it's redundant information or 2) there *is* no pcap/pcapng
link-layer header type for that encapsulation type, in which case you
need to check for the attempt to determine it failing and handle that
failure appropriately.

Change-Id: Ie9557b513365c1fc8c6df74b9c8239e29aad46bc
Reviewed-on: https://code.wireshark.org/review/21924
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2017-06-03 12:58:36 -07:00
parent 69ed5d5841
commit 30c86f8b34
9 changed files with 12 additions and 27 deletions

View File

@ -501,7 +501,6 @@ file_import_open(text_import_info_t *info)
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = info->encapsulation;
int_data_mand->time_units_per_second = 1000000; /* default microsecond resolution */
int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(info->encapsulation);
int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE;
wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF File->Import", strlen("Fake IF File->Import"));

View File

@ -146,7 +146,6 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU;
int_data_mand->time_units_per_second = 1000000000; /* default nanosecond resolution */
int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE;
wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF, PDU->Export", strlen("Fake IF, PDU->Export"));

View File

@ -953,7 +953,6 @@ int erf_populate_interfaces(wtap *wth)
int_data_mand->wtap_encap = WTAP_ENCAP_ERF;
/* int_data.time_units_per_second = (1LL<<32); ERF format resolution is 2^-32, capture resolution is unknown */
int_data_mand->time_units_per_second = 1000000000; /* XXX Since Wireshark only supports down to nanosecond resolution we have to dilute to this */
int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_ERF);
int_data_mand->snap_len = 65535; /* ERF max length */
/* XXX: if_IPv4addr opt 4 Interface network address and netmask.*/
@ -1242,7 +1241,6 @@ int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_header
int_data_mand->wtap_encap = WTAP_ENCAP_ERF;
/* int_data.time_units_per_second = (1LL<<32); ERF format resolution is 2^-32, capture resolution is unknown */
int_data_mand->time_units_per_second = 1000000000; /* XXX Since Wireshark only supports down to nanosecond resolution we have to dilute to this */
int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_ERF);
int_data_mand->snap_len = 65535; /* ERF max length */
/* XXX: if_IPv4addr opt 4 Interface network address and netmask.*/

View File

@ -1125,7 +1125,6 @@ success:
/* No need to add an option, this is the default */
descr_mand->tsprecision = WTAP_TSPREC_USEC;
}
descr_mand->link_type = wtap_wtap_encap_to_pcap_encap(wth->file_encap);
descr_mand->snap_len = wth->snapshot_length;
descr_mand->num_stat_entries = 0; /* Number of ISB:s */
@ -2221,7 +2220,6 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co
if ((encap != WTAP_ENCAP_PER_PACKET) && (encap != file_int_data_mand->wtap_encap)) {
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
descr_mand->wtap_encap = encap;
descr_mand->link_type = wtap_wtap_encap_to_pcap_encap(encap);
}
g_array_append_val(wdh->interface_data, descr);
}
@ -2230,7 +2228,6 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
descr_mand->wtap_encap = encap;
descr_mand->time_units_per_second = 1000000; /* default microsecond resolution */
descr_mand->link_type = wtap_wtap_encap_to_pcap_encap(encap);
descr_mand->snap_len = snaplen;
descr_mand->num_stat_entries = 0; /* Number of ISB:s */
descr_mand->interface_statistics = NULL;

View File

@ -460,14 +460,6 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2)
return FALSE;
}
merge_debug("idb1_mand->link_type == idb2_mand->link_type: %s",
(idb1_mand->link_type == idb2_mand->link_type) ? "TRUE":"FALSE");
if (idb1_mand->link_type != idb2_mand->link_type) {
/* Clearly not the same interface. */
merge_debug("merge::is_duplicate_idb() returning FALSE");
return FALSE;
}
merge_debug("idb1_mand->time_units_per_second == idb2_mand->time_units_per_second: %s",
(idb1_mand->time_units_per_second == idb2_mand->time_units_per_second) ? "TRUE":"FALSE");
if (idb1_mand->time_units_per_second != idb2_mand->time_units_per_second) {

View File

@ -788,7 +788,6 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU;
int_data_mand->time_units_per_second = 1000000; /* default microsecond resolution */
int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE;
wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF", strlen("Fake IF"));
int_data_mand->num_stat_entries = 0; /* Number of ISB:s */

View File

@ -677,6 +677,7 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh,
guint to_read, opt_cont_buf_len;
pcapng_interface_description_block_t idb;
wtapng_if_descr_mandatory_t* if_descr_mand;
guint link_type;
pcapng_option_header_t oh;
guint8 *option_content = NULL; /* Allocate as large as the options block */
gchar* tmp_content;
@ -720,19 +721,19 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh,
wblock->block = wtap_block_create(WTAP_BLOCK_IF_DESCR);
if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(wblock->block);
if (pn->byte_swapped) {
if_descr_mand->link_type = GUINT16_SWAP_LE_BE(idb.linktype);
link_type = GUINT16_SWAP_LE_BE(idb.linktype);
if_descr_mand->snap_len = GUINT32_SWAP_LE_BE(idb.snaplen);
} else {
if_descr_mand->link_type = idb.linktype;
link_type = idb.linktype;
if_descr_mand->snap_len = idb.snaplen;
}
if_descr_mand->wtap_encap = wtap_pcap_encap_to_wtap_encap(if_descr_mand->link_type);
if_descr_mand->wtap_encap = wtap_pcap_encap_to_wtap_encap(link_type);
if_descr_mand->time_units_per_second = time_units_per_second;
if_descr_mand->tsprecision = tsprecision;
pcapng_debug("pcapng_read_if_descr_block: IDB link_type %u (%s), snap %u",
if_descr_mand->link_type,
link_type,
wtap_encap_string(if_descr_mand->wtap_encap),
if_descr_mand->snap_len);
@ -3970,13 +3971,15 @@ pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err)
pcapng_write_block_t block_data;
struct pcapng_option_header option_hdr;
wtapng_if_descr_mandatory_t* mand_data = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int link_type;
pcapng_debug("pcapng_write_if_descr_block: encap = %d (%s), snaplen = %d",
mand_data->link_type,
wtap_encap_string(wtap_pcap_encap_to_wtap_encap(mand_data->link_type)),
mand_data->wtap_encap,
wtap_encap_string(mand_data->wtap_encap),
mand_data->snap_len);
if (mand_data->link_type == (guint16)-1) {
link_type = wtap_wtap_encap_to_pcap_encap(mand_data->wtap_encap);
if (link_type == -1) {
*err = WTAP_ERR_UNWRITABLE_ENCAP;
return FALSE;
}
@ -4000,7 +4003,7 @@ pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err)
wdh->bytes_dumped += sizeof bh;
/* write block fixed content */
idb.linktype = mand_data->link_type;
idb.linktype = link_type;
idb.reserved = 0;
idb.snaplen = mand_data->snap_len;

View File

@ -254,10 +254,9 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr,
}
g_string_append_printf(info,
"%*cEncapsulation = %s (%d/%u - %s)%s", indent, ' ',
"%*cEncapsulation = %s (%d - %s)%s", indent, ' ',
wtap_encap_string(if_descr_mand->wtap_encap),
if_descr_mand->wtap_encap,
if_descr_mand->link_type,
wtap_encap_short_string(if_descr_mand->wtap_encap),
line_end);

View File

@ -1286,7 +1286,6 @@ typedef struct wtapng_if_descr_mandatory_s {
guint64 time_units_per_second;
int tsprecision; /**< WTAP_TSPREC_ value for this interface */
guint16 link_type;
guint32 snap_len;
guint8 num_stat_entries;