Carry drop count/packet ID/queue ID as options on packet block

This commit is contained in:
David Perry 2021-07-19 21:25:40 +00:00 committed by Guy Harris
parent c7ed8aa3ee
commit dc7089e831
8 changed files with 40 additions and 122 deletions

View File

@ -338,6 +338,9 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void*
proto_item *volatile ti = NULL;
guint cap_len = 0, frame_len = 0;
guint32 pack_flags = 0;
guint32 interface_queue = 0;
guint64 drop_count = 0;
guint64 packet_id = 0;
proto_tree *volatile tree;
proto_tree *comments_tree;
proto_tree *volatile fh_tree = NULL;
@ -617,10 +620,9 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void*
}
}
if (pinfo->rec->presence_flags & WTAP_HAS_INT_QUEUE)
proto_tree_add_uint(fh_tree, hf_frame_interface_queue, tvb, 0, 0,
pinfo->rec->rec_header.packet_header.interface_queue);
if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_uint32_option_value(fr_data->pkt_block, OPT_PKT_QUEUE, &interface_queue)) {
proto_tree_add_uint(fh_tree, hf_frame_interface_queue, tvb, 0, 0, interface_queue);
}
if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_uint32_option_value(fr_data->pkt_block, OPT_PKT_FLAGS, &pack_flags)) {
proto_tree *flags_tree;
proto_item *flags_item;
@ -645,9 +647,9 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void*
proto_tree_add_bitmask_list_value(flags_tree, tvb, 0, 0, flags, pack_flags);
}
if (pinfo->rec->presence_flags & WTAP_HAS_PACKET_ID)
proto_tree_add_uint64(fh_tree, hf_frame_packet_id, tvb, 0, 0,
pinfo->rec->rec_header.packet_header.packet_id);
if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_uint64_option_value(fr_data->pkt_block, OPT_PKT_PACKETID, &packet_id)) {
proto_tree_add_uint64(fh_tree, hf_frame_packet_id, tvb, 0, 0, packet_id);
}
if (wtap_block_count_option(fr_data->pkt_block, OPT_PKT_VERDICT) > 0) {
proto_tree *verdict_tree;
@ -725,9 +727,9 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void*
0, 0, cap_len, "Capture Length: %u byte%s (%u bits)",
cap_len, cap_plurality, cap_len * 8);
if (pinfo->rec->presence_flags & WTAP_HAS_DROP_COUNT)
proto_tree_add_uint64(fh_tree, hf_frame_drop_count, tvb, 0, 0,
pinfo->rec->rec_header.packet_header.drop_count);
if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_uint64_option_value(fr_data->pkt_block, OPT_PKT_DROPCOUNT, &drop_count)) {
proto_tree_add_uint64(fh_tree, hf_frame_drop_count, tvb, 0, 0, drop_count);
}
if (generate_md5_hash) {
const guint8 *cp;

View File

@ -504,7 +504,6 @@ static gboolean extcap_dumper_dump(struct extcap_dumper extcap_dumper,
rec.ts.nsecs = (int) nanoseconds;
rec.block = NULL;
rec.rec_header.packet_header.drop_count = 0;
/* NOTE: Try to handle pseudoheaders manually */
if (extcap_dumper.encap == EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) {

View File

@ -1217,7 +1217,6 @@
},
["wtap_presence_flags"] = {
["CAP_LEN"] = 2,
["DROP_COUNT"] = 16,
["INTERFACE_ID"] = 4,
["TS"] = 1
},

View File

@ -623,8 +623,7 @@ write_current_packet (void)
wtap_block_add_uint32_option(rec.block, OPT_PKT_FLAGS, direction);
rec.presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS;
if (has_seqno) {
rec.presence_flags |= WTAP_HAS_PACKET_ID;
rec.rec_header.packet_header.packet_id = seqno;
wtap_block_add_uint64_option(rec.block, OPT_PKT_PACKETID, (guint64)seqno);
}
/* XXX - report errors! */

View File

@ -627,9 +627,6 @@ blf_init_rec(blf_params_t *params, guint64 object_timestamp, int pkt_encap, guin
params->rec->rec_header.packet_header.pkt_encap = pkt_encap;
params->rec->rec_header.packet_header.interface_id = channel;
params->rec->rec_header.packet_header.drop_count = 0;
params->rec->rec_header.packet_header.packet_id = 0;
params->rec->rec_header.packet_header.interface_queue = 0;
/* TODO: before we had to remove comments and verdict here to not leak memory but APIs have changed ... */
}
@ -754,8 +751,9 @@ blf_read_ethernetframe_ext(blf_params_t *params, int *err, gchar **err_info, gin
}
blf_init_rec(params, logheader.object_timestamp, WTAP_ENCAP_ETHERNET, ethheader.channel);
params->rec->presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN | WTAP_HAS_INTERFACE_ID | WTAP_HAS_INT_QUEUE;
params->rec->rec_header.packet_header.interface_queue = ethheader.hw_channel;
params->rec->presence_flags = WTAP_HAS_TS | WTAP_HAS_CAP_LEN | WTAP_HAS_INTERFACE_ID;
params->rec->block = wtap_block_create(WTAP_BLOCK_PACKET);
wtap_block_add_uint32_option(params->rec->block, OPT_PKT_QUEUE, ethheader.hw_channel);
params->rec->rec_header.packet_header.caplen = ethheader.frame_length;
params->rec->rec_header.packet_header.len = ethheader.frame_length;
return TRUE;

View File

@ -1465,16 +1465,7 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock,
/* XXX - free anything? */
return FALSE;
}
/* Don't cast a guint8 * into a guint64 *--the
* guint8 * may not point to something that's
* aligned correctly.
*/
memcpy(&tmp64, option_content, sizeof(guint64));
if (section_info->byte_swapped)
tmp64 = GUINT64_SWAP_LE_BE(tmp64);
wblock->rec->presence_flags |= WTAP_HAS_DROP_COUNT;
wblock->rec->rec_header.packet_header.drop_count = tmp64;
ws_debug("drop_count %" G_GINT64_MODIFIER "u", tmp64);
pcapng_process_uint64_option(wblock, section_info, option_code, option_length, option_content);
break;
case(OPT_EPB_PACKETID):
if (option_length != 8) {
@ -1484,16 +1475,7 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock,
/* XXX - free anything? */
return FALSE;
}
/* Don't cast a guint8 * into a guint64 *--the
* guint8 * may not point to something that's
* aligned correctly.
*/
memcpy(&tmp64, option_content, sizeof(guint64));
if (section_info->byte_swapped)
tmp64 = GUINT64_SWAP_LE_BE(tmp64);
wblock->rec->presence_flags |= WTAP_HAS_PACKET_ID;
wblock->rec->rec_header.packet_header.packet_id = tmp64;
ws_debug("packet_id %" G_GINT64_MODIFIER "u", tmp64);
pcapng_process_uint64_option(wblock, section_info, option_code, option_length, option_content);
break;
case(OPT_EPB_QUEUE):
if (option_length != 4) {
@ -1510,8 +1492,7 @@ pcapng_process_packet_block_option(wtapng_block_t *wblock,
memcpy(&tmp32, option_content, sizeof(guint32));
if (section_info->byte_swapped)
tmp32 = GUINT32_SWAP_LE_BE(tmp32);
wblock->rec->presence_flags |= WTAP_HAS_INT_QUEUE;
wblock->rec->rec_header.packet_header.interface_queue = tmp32;
pcapng_process_uint32_option(wblock, option_code, option_length, tmp32);
ws_debug("queue %u", tmp32);
break;
case(OPT_EPB_VERDICT):
@ -1587,6 +1568,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh,
wtapng_packet_t packet;
guint32 padding;
guint32 flags;
guint64 tmp64;
interface_info_t iface_info;
guint64 ts;
int pseudo_header_len;
@ -1616,14 +1598,14 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh,
if (section_info->byte_swapped) {
packet.interface_id = GUINT32_SWAP_LE_BE(epb.interface_id);
packet.drops_count = -1; /* invalid */
packet.drops_count = 0xFFFF; /* invalid */
packet.ts_high = GUINT32_SWAP_LE_BE(epb.timestamp_high);
packet.ts_low = GUINT32_SWAP_LE_BE(epb.timestamp_low);
packet.cap_len = GUINT32_SWAP_LE_BE(epb.captured_len);
packet.packet_len = GUINT32_SWAP_LE_BE(epb.packet_len);
} else {
packet.interface_id = epb.interface_id;
packet.drops_count = -1; /* invalid */
packet.drops_count = 0xFFFF; /* invalid */
packet.ts_high = epb.timestamp_high;
packet.ts_low = epb.timestamp_low;
packet.cap_len = epb.captured_len;
@ -1771,11 +1753,6 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh,
block_read += padding;
}
/* Option defaults */
wblock->rec->rec_header.packet_header.drop_count = -1;
wblock->rec->rec_header.packet_header.packet_id = 0;
wblock->rec->rec_header.packet_header.interface_queue = 0;
/* FCS length default */
fcslen = iface_info.fcslen;
@ -1798,6 +1775,12 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh,
fcslen = PACK_FLAGS_FCS_LENGTH(flags);
}
}
/*
* How about a drop_count option? If not, set it from other sources
*/
if (WTAP_OPTTYPE_SUCCESS != wtap_block_get_uint64_option_value(wblock->block, OPT_PKT_DROPCOUNT, &tmp64) && packet.drops_count != 0xFFFF) {
wtap_block_add_uint64_option(wblock->block, OPT_PKT_DROPCOUNT, (guint64)packet.drops_count);
}
pcap_read_post_process(FALSE, iface_info.wtap_encap,
wblock->rec, ws_buffer_start_ptr(wblock->frame_buffer),
@ -1921,9 +1904,6 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh,
wblock->rec->ts.secs = 0;
wblock->rec->ts.nsecs = 0;
wblock->rec->rec_header.packet_header.interface_id = 0;
wblock->rec->rec_header.packet_header.drop_count = 0;
wblock->rec->rec_header.packet_header.packet_id = 0;
wblock->rec->rec_header.packet_header.interface_queue = 0;
memset((void *)&wblock->rec->rec_header.packet_header.pseudo_header, 0, sizeof(union wtap_pseudo_header));
pseudo_header_len = pcap_process_pseudo_header(fh,
@ -4239,7 +4219,6 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec,
guint32 phdr_len;
gboolean have_options = FALSE;
guint32 options_total_length = 0;
struct option option_hdr;
gsize options_len = 0;
wtap_block_t int_data;
wtapng_if_descr_mandatory_t *int_data_mand;
@ -4261,7 +4240,6 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec,
pad_len = 0;
}
if (rec->block != NULL) {
// Current options expected to be here: comments, flags, verdicts, custom.
// Remember to also add newly-supported option types to packet_block_options_supported
// below.
options_len = wtap_block_get_options_size_padded(rec->block);
@ -4271,18 +4249,6 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec,
}
}
if (rec->presence_flags & WTAP_HAS_DROP_COUNT) {
have_options = TRUE;
options_total_length = options_total_length + 12;
}
if (rec->presence_flags & WTAP_HAS_PACKET_ID) {
have_options = TRUE;
options_total_length = options_total_length + 12;
}
if (rec->presence_flags & WTAP_HAS_INT_QUEUE) {
have_options = TRUE;
options_total_length = options_total_length + 8;
}
if (have_options) {
/* End-of options tag */
options_total_length += 4;
@ -4419,42 +4385,6 @@ pcapng_write_enhanced_packet_block(wtap_dumper *wdh, const wtap_rec *rec,
if (!wtap_block_foreach_option(rec->block, pcapng_write_option_cb, &block_data)) {
return FALSE;
}
if (rec->presence_flags & WTAP_HAS_DROP_COUNT) {
option_hdr.type = OPT_EPB_DROPCOUNT;
option_hdr.value_length = 8;
if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
return FALSE;
wdh->bytes_dumped += 4;
if (!wtap_dump_file_write(wdh, &rec->rec_header.packet_header.drop_count, 8, err))
return FALSE;
wdh->bytes_dumped += 8;
ws_debug("Wrote Options drop count: %" G_GINT64_MODIFIER "u",
rec->rec_header.packet_header.drop_count);
}
if (rec->presence_flags & WTAP_HAS_PACKET_ID) {
option_hdr.type = OPT_EPB_PACKETID;
option_hdr.value_length = 8;
if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
return FALSE;
wdh->bytes_dumped += 4;
if (!wtap_dump_file_write(wdh, &rec->rec_header.packet_header.packet_id, 8, err))
return FALSE;
wdh->bytes_dumped += 8;
ws_debug("Wrote Options packet id: %" G_GINT64_MODIFIER "u",
rec->rec_header.packet_header.packet_id);
}
if (rec->presence_flags & WTAP_HAS_INT_QUEUE) {
option_hdr.type = OPT_EPB_QUEUE;
option_hdr.value_length = 4;
if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
return FALSE;
wdh->bytes_dumped += 4;
if (!wtap_dump_file_write(wdh, &rec->rec_header.packet_header.interface_queue, 4, err))
return FALSE;
wdh->bytes_dumped += 4;
ws_debug("Wrote Options queue: %u",
rec->rec_header.packet_header.interface_queue);
}
/* Write end of options if we have options */
if (have_options) {
if (!pcapng_write_option_eofopt(wdh, err))
@ -5689,7 +5619,11 @@ static const struct supported_option_type decryption_secrets_block_options_suppo
static const struct supported_option_type packet_block_options_supported[] = {
{ OPT_COMMENT, MULTIPLE_OPTIONS_SUPPORTED },
{ OPT_PKT_FLAGS, ONE_OPTION_SUPPORTED },
{ OPT_EPB_VERDICT, MULTIPLE_OPTIONS_SUPPORTED },
{ OPT_PKT_DROPCOUNT, ONE_OPTION_SUPPORTED },
{ OPT_PKT_PACKETID, ONE_OPTION_SUPPORTED },
{ OPT_PKT_QUEUE, ONE_OPTION_SUPPORTED },
{ OPT_PKT_HASH, MULTIPLE_OPTIONS_SUPPORTED },
{ OPT_PKT_VERDICT, MULTIPLE_OPTIONS_SUPPORTED },
{ OPT_CUSTOM_STR_COPY, MULTIPLE_OPTIONS_SUPPORTED },
{ OPT_CUSTOM_BIN_COPY, MULTIPLE_OPTIONS_SUPPORTED },
{ OPT_CUSTOM_STR_NO_COPY, MULTIPLE_OPTIONS_SUPPORTED },

View File

@ -1221,10 +1221,6 @@ typedef struct {
/* pcapng variables */
guint32 interface_id; /* identifier of the interface. */
/* options */
guint64 drop_count; /* number of packets lost (by the interface and the
operating system) between this packet and the preceding one. */
guint32 interface_queue; /* queue of the interface the packet was received on. */
guint64 packet_id; /* unique packet identifier */
union wtap_pseudo_header pseudo_header;
} wtap_packet_header;
@ -1377,9 +1373,6 @@ typedef struct {
#define WTAP_HAS_TS 0x00000001 /**< time stamp */
#define WTAP_HAS_CAP_LEN 0x00000002 /**< captured length separate from on-the-network length */
#define WTAP_HAS_INTERFACE_ID 0x00000004 /**< interface ID */
#define WTAP_HAS_DROP_COUNT 0x00000010 /**< drop count */
#define WTAP_HAS_PACKET_ID 0x00000040 /**< packet id */
#define WTAP_HAS_INT_QUEUE 0x00000080 /**< interface queue */
#ifndef MAXNAMELEN
#define MAXNAMELEN 64 /* max name length (hostname and port name) */

View File

@ -1607,14 +1607,6 @@ void wtap_opttypes_initialize(void)
WTAP_OPTTYPE_UINT32,
0
};
#if 0
// We handle these options via a different mechanism
static const wtap_opttype_t pkt_hash = {
"hash",
"Hash of packet data",
WTAP_OPTTYPE_BYTES, // TODO: replace with a pkt_filter_opt_t
WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED
};
static const wtap_opttype_t pkt_dropcount = {
"dropcount",
"Packets Dropped since last packet",
@ -1633,7 +1625,12 @@ void wtap_opttypes_initialize(void)
WTAP_OPTTYPE_UINT32,
0
};
#endif
static const wtap_opttype_t pkt_hash = {
"hash",
"Hash of packet data",
WTAP_OPTTYPE_BYTES, // TODO: replace with a pkt_hash_opt_t
WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED
};
static const wtap_opttype_t pkt_verdict = {
"verdict",
"Packet Verdict",
@ -1696,13 +1693,10 @@ void wtap_opttypes_initialize(void)
*/
wtap_opttype_block_register(&pkt_block);
wtap_opttype_option_register(&pkt_block, OPT_PKT_FLAGS, &pkt_flags);
#if 0
// We handle these options via a different mechanism
wtap_opttype_option_register(&pkt_block, OPT_PKT_HASH, &pkt_hash);
wtap_opttype_option_register(&pkt_block, OPT_PKT_DROPCOUNT, &pkt_dropcount);
wtap_opttype_option_register(&pkt_block, OPT_PKT_PACKETID, &pkt_id);
wtap_opttype_option_register(&pkt_block, OPT_PKT_QUEUE, &pkt_queue);
#endif
wtap_opttype_option_register(&pkt_block, OPT_PKT_HASH, &pkt_hash);
wtap_opttype_option_register(&pkt_block, OPT_PKT_VERDICT, &pkt_verdict);
#ifdef DEBUG_COUNT_REFS