2016-01-26 01:17:21 +00:00
|
|
|
/* wtap_opttypes.c
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 2001 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2016-01-26 01:17:21 +00:00
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wtap.h"
|
|
|
|
#include "wtap_opttypes.h"
|
|
|
|
#include "wtap-int.h"
|
2016-03-04 13:52:48 +00:00
|
|
|
#include "pcapng_module.h"
|
2021-05-23 23:46:43 +00:00
|
|
|
#include <wsutil/ws_assert.h>
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2021-03-23 15:41:54 +00:00
|
|
|
#include <wsutil/glib-compat.h>
|
2021-04-29 11:23:21 +00:00
|
|
|
#include <wsutil/inet_ipv6.h>
|
2022-12-06 19:27:24 +00:00
|
|
|
#include <wsutil/unicode-utils.h>
|
2021-04-29 11:23:21 +00:00
|
|
|
|
|
|
|
#if 0
|
2022-03-31 17:27:11 +00:00
|
|
|
#define wtap_debug(...) ws_warning(__VA_ARGS__)
|
2021-04-29 11:23:21 +00:00
|
|
|
#define DEBUG_COUNT_REFS
|
|
|
|
#else
|
|
|
|
#define wtap_debug(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ROUND_TO_4BYTE(len) (((len) + 3) & ~3)
|
2021-03-23 15:41:54 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* Structure describing a type of block.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
wtap_block_type_t block_type; /**< internal type code for block */
|
2016-01-26 01:17:21 +00:00
|
|
|
const char *name; /**< name of block */
|
|
|
|
const char *description; /**< human-readable description of block */
|
2016-03-02 14:13:08 +00:00
|
|
|
wtap_block_create_func create;
|
|
|
|
wtap_mand_free_func free_mand;
|
|
|
|
wtap_mand_copy_func copy_mand;
|
2021-02-05 06:09:23 +00:00
|
|
|
GHashTable *options; /**< hash table of known options */
|
2016-07-14 23:01:57 +00:00
|
|
|
} wtap_blocktype_t;
|
2016-03-02 14:13:08 +00:00
|
|
|
|
2021-02-05 06:09:23 +00:00
|
|
|
#define GET_OPTION_TYPE(options, option_id) \
|
|
|
|
(const wtap_opttype_t *)g_hash_table_lookup((options), GUINT_TO_POINTER(option_id))
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* Structure describing a type of option.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2021-01-30 06:21:39 +00:00
|
|
|
const char *name; /**< name of option */
|
|
|
|
const char *description; /**< human-readable description of option */
|
|
|
|
wtap_opttype_e data_type; /**< data type of that option */
|
|
|
|
guint flags; /**< flags for the option */
|
2016-07-14 23:01:57 +00:00
|
|
|
} wtap_opttype_t;
|
|
|
|
|
|
|
|
/* Flags */
|
|
|
|
#define WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED 0x00000001 /* multiple instances allowed */
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
/* Debugging reference counting */
|
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
static guint block_count = 0;
|
|
|
|
static guint8 blocks_active[sizeof(guint)/8];
|
|
|
|
|
|
|
|
static void rc_set(guint refnum)
|
|
|
|
{
|
|
|
|
guint cellno = refnum / 8;
|
|
|
|
guint bitno = refnum % 8;
|
|
|
|
blocks_active[cellno] |= (guint8)(1 << bitno);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rc_clear(guint refnum)
|
|
|
|
{
|
|
|
|
guint cellno = refnum / 8;
|
|
|
|
guint bitno = refnum % 8;
|
|
|
|
blocks_active[cellno] &= (guint8)~(1 << bitno);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DEBUG_COUNT_REFS */
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
struct wtap_block
|
2016-03-02 14:13:08 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_blocktype_t* info;
|
2016-01-26 01:17:21 +00:00
|
|
|
void* mandatory_data;
|
2016-07-14 23:01:57 +00:00
|
|
|
GArray* options;
|
2021-04-29 11:23:21 +00:00
|
|
|
gint ref_count;
|
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
guint id;
|
|
|
|
#endif
|
2016-01-26 01:17:21 +00:00
|
|
|
};
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/* Keep track of wtap_blocktype_t's via their id number */
|
|
|
|
static wtap_blocktype_t* blocktype_list[MAX_WTAP_BLOCK_TYPE_VALUE];
|
2016-03-02 14:13:08 +00:00
|
|
|
|
2021-04-27 17:22:00 +00:00
|
|
|
static if_filter_opt_t if_filter_dup(if_filter_opt_t* filter_src)
|
|
|
|
{
|
|
|
|
if_filter_opt_t filter_dest;
|
|
|
|
|
|
|
|
memset(&filter_dest, 0, sizeof(filter_dest));
|
|
|
|
|
|
|
|
/* Deep copy. */
|
|
|
|
filter_dest.type = filter_src->type;
|
|
|
|
switch (filter_src->type) {
|
|
|
|
|
|
|
|
case if_filter_pcap:
|
|
|
|
/* pcap filter string */
|
|
|
|
filter_dest.data.filter_str =
|
|
|
|
g_strdup(filter_src->data.filter_str);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case if_filter_bpf:
|
|
|
|
/* BPF program */
|
|
|
|
filter_dest.data.bpf_prog.bpf_prog_len =
|
|
|
|
filter_src->data.bpf_prog.bpf_prog_len;
|
|
|
|
filter_dest.data.bpf_prog.bpf_prog =
|
|
|
|
(wtap_bpf_insn_t *)g_memdup2(filter_src->data.bpf_prog.bpf_prog,
|
|
|
|
filter_src->data.bpf_prog.bpf_prog_len * sizeof (wtap_bpf_insn_t));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return filter_dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void if_filter_free(if_filter_opt_t* filter_src)
|
|
|
|
{
|
|
|
|
switch (filter_src->type) {
|
|
|
|
|
|
|
|
case if_filter_pcap:
|
|
|
|
/* pcap filter string */
|
|
|
|
g_free(filter_src->data.filter_str);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case if_filter_bpf:
|
|
|
|
/* BPF program */
|
|
|
|
g_free(filter_src->data.bpf_prog.bpf_prog);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-30 21:36:44 +00:00
|
|
|
static packet_verdict_opt_t
|
|
|
|
packet_verdict_dup(packet_verdict_opt_t* verdict_src)
|
|
|
|
{
|
|
|
|
packet_verdict_opt_t verdict_dest;
|
|
|
|
|
|
|
|
memset(&verdict_dest, 0, sizeof(verdict_dest));
|
|
|
|
|
|
|
|
/* Deep copy. */
|
|
|
|
verdict_dest.type = verdict_src->type;
|
|
|
|
switch (verdict_src->type) {
|
|
|
|
|
|
|
|
case packet_verdict_hardware:
|
|
|
|
/* array of octets */
|
|
|
|
verdict_dest.data.verdict_bytes =
|
|
|
|
g_byte_array_new_take((guint8 *)g_memdup2(verdict_src->data.verdict_bytes->data,
|
|
|
|
verdict_src->data.verdict_bytes->len),
|
|
|
|
verdict_src->data.verdict_bytes->len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case packet_verdict_linux_ebpf_tc:
|
|
|
|
/* eBPF TC_ACT_ value */
|
|
|
|
verdict_dest.data.verdict_linux_ebpf_tc =
|
|
|
|
verdict_src->data.verdict_linux_ebpf_tc;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case packet_verdict_linux_ebpf_xdp:
|
|
|
|
/* xdp_action value */
|
|
|
|
verdict_dest.data.verdict_linux_ebpf_xdp =
|
|
|
|
verdict_src->data.verdict_linux_ebpf_xdp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return verdict_dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wtap_packet_verdict_free(packet_verdict_opt_t* verdict)
|
|
|
|
{
|
|
|
|
switch (verdict->type) {
|
|
|
|
|
|
|
|
case packet_verdict_hardware:
|
|
|
|
/* array of bytes */
|
|
|
|
g_byte_array_free(verdict->data.verdict_bytes, TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-11 20:28:03 +00:00
|
|
|
static packet_hash_opt_t
|
|
|
|
packet_hash_dup(packet_hash_opt_t* hash_src)
|
|
|
|
{
|
|
|
|
packet_hash_opt_t hash_dest;
|
|
|
|
|
|
|
|
memset(&hash_dest, 0, sizeof(hash_dest));
|
|
|
|
|
|
|
|
/* Deep copy. */
|
|
|
|
hash_dest.type = hash_src->type;
|
|
|
|
/* array of octets */
|
|
|
|
hash_dest.hash_bytes =
|
|
|
|
g_byte_array_new_take((guint8 *)g_memdup2(hash_src->hash_bytes->data,
|
|
|
|
hash_src->hash_bytes->len),
|
|
|
|
hash_src->hash_bytes->len);
|
|
|
|
return hash_dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wtap_packet_hash_free(packet_hash_opt_t* hash)
|
|
|
|
{
|
|
|
|
/* array of bytes */
|
|
|
|
g_byte_array_free(hash->hash_bytes, TRUE);
|
|
|
|
}
|
|
|
|
|
2021-02-10 02:46:29 +00:00
|
|
|
static void wtap_opttype_block_register(wtap_blocktype_t *blocktype)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2021-02-10 02:46:29 +00:00
|
|
|
wtap_block_type_t block_type;
|
2016-07-14 23:01:57 +00:00
|
|
|
static const wtap_opttype_t opt_comment = {
|
|
|
|
"opt_comment",
|
|
|
|
"Comment",
|
2017-02-14 17:41:25 +00:00
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-06-21 14:56:58 +00:00
|
|
|
static const wtap_opttype_t opt_custom = {
|
|
|
|
"opt_custom",
|
|
|
|
"Custom Option",
|
|
|
|
WTAP_OPTTYPE_CUSTOM,
|
|
|
|
WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED
|
|
|
|
};
|
2016-07-14 23:01:57 +00:00
|
|
|
|
2021-02-10 02:46:29 +00:00
|
|
|
block_type = blocktype->block_type;
|
|
|
|
|
2016-03-02 14:13:08 +00:00
|
|
|
/* Check input */
|
2021-05-23 23:46:43 +00:00
|
|
|
ws_assert(block_type < MAX_WTAP_BLOCK_TYPE_VALUE);
|
2016-03-02 14:13:08 +00:00
|
|
|
|
|
|
|
/* Don't re-register. */
|
2021-05-23 23:46:43 +00:00
|
|
|
ws_assert(blocktype_list[block_type] == NULL);
|
2016-03-02 14:13:08 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
2021-05-23 23:46:43 +00:00
|
|
|
ws_assert(blocktype->name);
|
|
|
|
ws_assert(blocktype->description);
|
|
|
|
ws_assert(blocktype->create);
|
2016-07-14 23:01:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the set of supported options.
|
2021-06-21 14:56:58 +00:00
|
|
|
* All blocks that support options at all support
|
|
|
|
* OPT_COMMENT and OPT_CUSTOM.
|
2021-02-05 06:09:23 +00:00
|
|
|
*
|
|
|
|
* XXX - there's no "g_uint_hash()" or "g_uint_equal()",
|
|
|
|
* so we use "g_direct_hash()" and "g_direct_equal()".
|
2016-07-14 23:01:57 +00:00
|
|
|
*/
|
2021-02-05 06:09:23 +00:00
|
|
|
blocktype->options = g_hash_table_new(g_direct_hash, g_direct_equal);
|
|
|
|
g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_COMMENT),
|
|
|
|
(gpointer)&opt_comment);
|
2021-06-21 14:56:58 +00:00
|
|
|
g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_CUSTOM_STR_COPY),
|
|
|
|
(gpointer)&opt_custom);
|
|
|
|
g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_CUSTOM_BIN_COPY),
|
|
|
|
(gpointer)&opt_custom);
|
|
|
|
g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_CUSTOM_STR_NO_COPY),
|
|
|
|
(gpointer)&opt_custom);
|
|
|
|
g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(OPT_CUSTOM_BIN_NO_COPY),
|
|
|
|
(gpointer)&opt_custom);
|
2016-07-14 23:01:57 +00:00
|
|
|
|
|
|
|
blocktype_list[block_type] = blocktype;
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
|
|
|
|
2021-02-05 06:09:23 +00:00
|
|
|
static void wtap_opttype_option_register(wtap_blocktype_t *blocktype, guint opttype, const wtap_opttype_t *option)
|
2016-07-14 23:01:57 +00:00
|
|
|
{
|
2021-02-05 06:09:23 +00:00
|
|
|
g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(opttype),
|
|
|
|
(gpointer) option);
|
2016-07-14 23:01:57 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 02:46:29 +00:00
|
|
|
wtap_block_type_t wtap_block_get_type(wtap_block_t block)
|
|
|
|
{
|
|
|
|
return block->info->block_type;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
void* wtap_block_get_mandatory_data(wtap_block_t block)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-03-02 14:13:08 +00:00
|
|
|
return block->mandatory_data;
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_optval_t *
|
|
|
|
wtap_block_get_option(wtap_block_t block, guint option_id)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-03-02 14:13:08 +00:00
|
|
|
guint i;
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_option_t *opt;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
for (i = 0; i < block->options->len; i++) {
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
|
|
|
if (opt->option_id == option_id)
|
|
|
|
return &opt->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static wtap_optval_t *
|
|
|
|
wtap_block_get_nth_option(wtap_block_t block, guint option_id, guint idx)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
guint opt_idx;
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
opt_idx = 0;
|
|
|
|
for (i = 0; i < block->options->len; i++) {
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
|
|
|
if (opt->option_id == option_id) {
|
|
|
|
if (opt_idx == idx)
|
|
|
|
return &opt->value;
|
|
|
|
opt_idx++;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 14:13:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_block_t wtap_block_create(wtap_block_type_t block_type)
|
2016-03-02 14:13:08 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_block_t block;
|
2016-03-02 14:13:08 +00:00
|
|
|
|
Remove the existing "custom block" mechanism:
For most file types, blocks for which we don't have a wtap_block_type_t
aren't "custom", they're just "file-type specific". Add
WTAP_BLOCK_FT_SPECIFIC_REPORT and WTAP_BLOCK_FT_SPECIFIC_EVENT block
types; the "mandatory" part of those blocks includes a
file-type-specific block type value, with specific values assigned to
specific block types (either as part of the file type's definition, or
by us if necessary).
For pcapng files, blocks for which we don't have a wtap_block_type_t are
either "local" (block type has the high-order bit set), are defined in
the current spec but aren't supported yet (which we should fix), or are
*not* defined in the current spec and are *not* "local" (in which case
whoever's using the block number should submit a pull request to the
spec to register the block type *and* give it a specification, so we can
add support). For "local" block types and for not-yet-supported
non-"local" block types, they should be handled as file-type-specific
blocks with the file-type-specific block value being the pcapng block
type code, with plugin support in the pcapng code to read *and* write
those blocks.
Move the structures for the "mandatory" parts of blocks to
wiretap/wtap_opttypes.h, right after the definition of
wtap_block_type_t.
2021-02-10 07:21:49 +00:00
|
|
|
if (block_type >= MAX_WTAP_BLOCK_TYPE_VALUE)
|
2016-03-02 14:13:08 +00:00
|
|
|
return NULL;
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
block = g_new(struct wtap_block, 1);
|
|
|
|
block->info = blocktype_list[block_type];
|
|
|
|
block->options = g_array_new(FALSE, FALSE, sizeof(wtap_option_t));
|
2016-03-02 14:13:08 +00:00
|
|
|
block->info->create(block);
|
2021-04-29 11:23:21 +00:00
|
|
|
block->ref_count = 1;
|
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
block->id = block_count++;
|
|
|
|
rc_set(block->id);
|
|
|
|
wtap_debug("Created #%d %s", block->id, block->info->name);
|
|
|
|
#endif /* DEBUG_COUNT_REFS */
|
2016-03-02 14:13:08 +00:00
|
|
|
|
2016-01-26 01:17:21 +00:00
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
2016-07-16 00:25:41 +00:00
|
|
|
static void wtap_block_free_option(wtap_block_t block, wtap_option_t *opt)
|
|
|
|
{
|
2021-02-05 06:09:23 +00:00
|
|
|
const wtap_opttype_t *opttype;
|
2016-07-16 00:25:41 +00:00
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-05 06:09:23 +00:00
|
|
|
opttype = GET_OPTION_TYPE(block->info->options, opt->option_id);
|
2016-07-16 00:25:41 +00:00
|
|
|
switch (opttype->data_type) {
|
|
|
|
|
|
|
|
case WTAP_OPTTYPE_STRING:
|
|
|
|
g_free(opt->value.stringval);
|
|
|
|
break;
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
case WTAP_OPTTYPE_BYTES:
|
|
|
|
g_bytes_unref(opt->value.byteval);
|
|
|
|
break;
|
|
|
|
|
2021-06-21 14:56:58 +00:00
|
|
|
case WTAP_OPTTYPE_CUSTOM:
|
2021-08-04 17:57:52 +00:00
|
|
|
switch (opt->value.custom_opt.pen) {
|
|
|
|
case PEN_NFLX:
|
|
|
|
g_free(opt->value.custom_opt.data.nflx_data.custom_data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_free(opt->value.custom_opt.data.generic_data.custom_data);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-21 14:56:58 +00:00
|
|
|
break;
|
|
|
|
|
2021-09-09 22:12:05 +00:00
|
|
|
case WTAP_OPTTYPE_IF_FILTER:
|
|
|
|
if_filter_free(&opt->value.if_filterval);
|
|
|
|
break;
|
|
|
|
|
2021-08-30 21:36:44 +00:00
|
|
|
case WTAP_OPTTYPE_PACKET_VERDICT:
|
|
|
|
wtap_packet_verdict_free(&opt->value.packet_verdictval);
|
|
|
|
break;
|
|
|
|
|
2022-08-11 20:28:03 +00:00
|
|
|
case WTAP_OPTTYPE_PACKET_HASH:
|
|
|
|
wtap_packet_hash_free(&opt->value.packet_hash);
|
|
|
|
break;
|
|
|
|
|
2016-07-16 00:25:41 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void wtap_block_free_options(wtap_block_t block)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
|
|
|
guint i;
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_option_t *opt;
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL || block->options == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
for (i = 0; i < block->options->len; i++) {
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
2016-07-16 00:25:41 +00:00
|
|
|
wtap_block_free_option(block, opt);
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
2021-04-29 11:23:21 +00:00
|
|
|
g_array_remove_range(block->options, 0, block->options->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_block_t wtap_block_ref(wtap_block_t block)
|
|
|
|
{
|
|
|
|
if (block == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_atomic_int_inc(&block->ref_count);
|
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
wtap_debug("Ref #%d %s", block->id, block->info->name);
|
|
|
|
#endif /* DEBUG_COUNT_REFS */
|
|
|
|
return block;
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
void wtap_block_unref(wtap_block_t block)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
|
|
|
if (block != NULL)
|
|
|
|
{
|
2021-04-29 11:23:21 +00:00
|
|
|
if (g_atomic_int_dec_and_test(&block->ref_count)) {
|
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
wtap_debug("Destroy #%d %s", block->id, block->info->name);
|
|
|
|
rc_clear(block->id);
|
|
|
|
#endif /* DEBUG_COUNT_REFS */
|
|
|
|
if (block->info->free_mand != NULL)
|
|
|
|
block->info->free_mand(block);
|
|
|
|
|
|
|
|
g_free(block->mandatory_data);
|
|
|
|
wtap_block_free_options(block);
|
|
|
|
g_array_free(block->options, TRUE);
|
|
|
|
g_free(block);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
else {
|
|
|
|
wtap_debug("Unref #%d %s", block->id, block->info->name);
|
|
|
|
}
|
|
|
|
#endif /* DEBUG_COUNT_REFS */
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
void wtap_block_array_free(GArray* block_array)
|
2016-05-31 03:42:41 +00:00
|
|
|
{
|
|
|
|
guint block;
|
2016-07-14 23:01:57 +00:00
|
|
|
|
2016-05-31 03:42:41 +00:00
|
|
|
if (block_array == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (block = 0; block < block_array->len; block++) {
|
2021-04-29 11:23:21 +00:00
|
|
|
wtap_block_unref(g_array_index(block_array, wtap_block_t, block));
|
2016-05-31 03:42:41 +00:00
|
|
|
}
|
|
|
|
g_array_free(block_array, TRUE);
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* Make a copy of a block.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
|
|
|
guint i;
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_option_t *src_opt;
|
2021-02-05 06:09:23 +00:00
|
|
|
const wtap_opttype_t *opttype;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* Copy the mandatory data.
|
|
|
|
*/
|
2016-03-02 14:13:08 +00:00
|
|
|
if (dest_block->info->copy_mand != NULL)
|
|
|
|
dest_block->info->copy_mand(dest_block, src_block);
|
|
|
|
|
|
|
|
/* Copy the options. For now, don't remove any options that are in destination
|
|
|
|
* but not source.
|
|
|
|
*/
|
2016-07-14 23:01:57 +00:00
|
|
|
for (i = 0; i < src_block->options->len; i++)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
src_opt = &g_array_index(src_block->options, wtap_option_t, i);
|
2021-02-05 06:09:23 +00:00
|
|
|
opttype = GET_OPTION_TYPE(src_block->info->options, src_opt->option_id);
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
switch(opttype->data_type) {
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
case WTAP_OPTTYPE_UINT8:
|
|
|
|
wtap_block_add_uint8_option(dest_block, src_opt->option_id, src_opt->value.uint8val);
|
|
|
|
break;
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
case WTAP_OPTTYPE_UINT32:
|
|
|
|
wtap_block_add_uint32_option(dest_block, src_opt->option_id, src_opt->value.uint32val);
|
|
|
|
break;
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
case WTAP_OPTTYPE_UINT64:
|
|
|
|
wtap_block_add_uint64_option(dest_block, src_opt->option_id, src_opt->value.uint64val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_OPTTYPE_IPv4:
|
|
|
|
wtap_block_add_ipv4_option(dest_block, src_opt->option_id, src_opt->value.ipv4val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_OPTTYPE_IPv6:
|
|
|
|
wtap_block_add_ipv6_option(dest_block, src_opt->option_id, &src_opt->value.ipv6val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WTAP_OPTTYPE_STRING:
|
|
|
|
wtap_block_add_string_option(dest_block, src_opt->option_id, src_opt->value.stringval, strlen(src_opt->value.stringval));
|
|
|
|
break;
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
case WTAP_OPTTYPE_BYTES:
|
|
|
|
wtap_block_add_bytes_option_borrow(dest_block, src_opt->option_id, src_opt->value.byteval);
|
|
|
|
break;
|
|
|
|
|
2021-06-21 14:56:58 +00:00
|
|
|
case WTAP_OPTTYPE_CUSTOM:
|
2021-08-04 17:57:52 +00:00
|
|
|
switch (src_opt->value.custom_opt.pen) {
|
|
|
|
case PEN_NFLX:
|
|
|
|
wtap_block_add_nflx_custom_option(dest_block, src_opt->value.custom_opt.data.nflx_data.type, src_opt->value.custom_opt.data.nflx_data.custom_data, src_opt->value.custom_opt.data.nflx_data.custom_data_len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wtap_block_add_custom_option(dest_block, src_opt->option_id, src_opt->value.custom_opt.pen, src_opt->value.custom_opt.data.generic_data.custom_data, src_opt->value.custom_opt.data.generic_data.custom_data_len);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-21 14:56:58 +00:00
|
|
|
break;
|
2021-08-30 21:36:44 +00:00
|
|
|
|
2021-09-09 08:33:47 +00:00
|
|
|
case WTAP_OPTTYPE_IF_FILTER:
|
|
|
|
wtap_block_add_if_filter_option(dest_block, src_opt->option_id, &src_opt->value.if_filterval);
|
|
|
|
break;
|
|
|
|
|
2021-08-30 21:36:44 +00:00
|
|
|
case WTAP_OPTTYPE_PACKET_VERDICT:
|
|
|
|
wtap_block_add_packet_verdict_option(dest_block, src_opt->option_id, &src_opt->value.packet_verdictval);
|
|
|
|
break;
|
2022-10-12 05:41:18 +00:00
|
|
|
|
2022-08-11 20:28:03 +00:00
|
|
|
case WTAP_OPTTYPE_PACKET_HASH:
|
|
|
|
wtap_block_add_packet_hash_option(dest_block, src_opt->option_id, &src_opt->value.packet_hash);
|
|
|
|
break;
|
2016-03-02 14:13:08 +00:00
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 02:10:49 +00:00
|
|
|
wtap_block_t wtap_block_make_copy(wtap_block_t block)
|
|
|
|
{
|
|
|
|
wtap_block_t block_copy;
|
|
|
|
|
|
|
|
block_copy = wtap_block_create(block->info->block_type);
|
|
|
|
wtap_block_copy(block_copy, block);
|
|
|
|
return block_copy;
|
|
|
|
}
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
guint
|
|
|
|
wtap_block_count_option(wtap_block_t block, guint option_id)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
guint ret_val = 0;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
if (block == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < block->options->len; i++) {
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
|
|
|
if (opt->option_id == option_id)
|
|
|
|
ret_val++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-27 20:25:16 +00:00
|
|
|
gboolean wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data)
|
2016-03-04 13:52:48 +00:00
|
|
|
{
|
|
|
|
guint i;
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_option_t *opt;
|
2021-02-05 06:09:23 +00:00
|
|
|
const wtap_opttype_t *opttype;
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
for (i = 0; i < block->options->len; i++) {
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
2021-02-05 06:09:23 +00:00
|
|
|
opttype = GET_OPTION_TYPE(block->info->options, opt->option_id);
|
2021-06-27 20:25:16 +00:00
|
|
|
if (!func(block, opt->option_id, opttype->data_type, &opt->value, user_data))
|
|
|
|
return FALSE;
|
2016-03-04 13:52:48 +00:00
|
|
|
}
|
2021-06-27 20:25:16 +00:00
|
|
|
return TRUE;
|
2016-03-04 13:52:48 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_opttype_return_val
|
|
|
|
wtap_block_add_option_common(wtap_block_t block, guint option_id, wtap_opttype_e type, wtap_option_t **optp)
|
|
|
|
{
|
|
|
|
wtap_option_t *opt;
|
2021-02-05 06:09:23 +00:00
|
|
|
const wtap_opttype_t *opttype;
|
2016-07-14 23:01:57 +00:00
|
|
|
guint i;
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return WTAP_OPTTYPE_BAD_BLOCK;
|
|
|
|
}
|
|
|
|
|
2021-02-05 06:09:23 +00:00
|
|
|
opttype = GET_OPTION_TYPE(block->info->options, option_id);
|
|
|
|
if (opttype == NULL) {
|
2016-07-14 23:01:57 +00:00
|
|
|
/* There's no option for this block with that option ID */
|
|
|
|
return WTAP_OPTTYPE_NO_SUCH_OPTION;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* Is this an option of the specified data type?
|
|
|
|
*/
|
|
|
|
if (opttype->data_type != type) {
|
|
|
|
/*
|
|
|
|
* No.
|
|
|
|
*/
|
|
|
|
return WTAP_OPTTYPE_TYPE_MISMATCH;
|
|
|
|
}
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* Can there be more than one instance of this option?
|
|
|
|
*/
|
|
|
|
if (!(opttype->flags & WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED)) {
|
|
|
|
/*
|
|
|
|
* No. Is there already an instance of this option?
|
|
|
|
*/
|
|
|
|
if (wtap_block_get_option(block, option_id) != NULL) {
|
|
|
|
/*
|
|
|
|
* Yes. Fail.
|
|
|
|
*/
|
|
|
|
return WTAP_OPTTYPE_ALREADY_EXISTS;
|
|
|
|
}
|
2016-03-04 13:52:48 +00:00
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* Add an instance.
|
|
|
|
*/
|
|
|
|
i = block->options->len;
|
|
|
|
g_array_set_size(block->options, i + 1);
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
|
|
|
opt->option_id = option_id;
|
|
|
|
*optp = opt;
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_opttype_return_val
|
|
|
|
wtap_block_get_option_common(wtap_block_t block, guint option_id, wtap_opttype_e type, wtap_optval_t **optvalp)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2021-02-05 06:09:23 +00:00
|
|
|
const wtap_opttype_t *opttype;
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_optval_t *optval;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return WTAP_OPTTYPE_BAD_BLOCK;
|
|
|
|
}
|
|
|
|
|
2021-02-05 06:09:23 +00:00
|
|
|
opttype = GET_OPTION_TYPE(block->info->options, option_id);
|
|
|
|
if (opttype == NULL) {
|
2016-07-14 23:01:57 +00:00
|
|
|
/* There's no option for this block with that option ID */
|
|
|
|
return WTAP_OPTTYPE_NO_SUCH_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is this an option of the specified data type?
|
|
|
|
*/
|
|
|
|
if (opttype->data_type != type) {
|
|
|
|
/*
|
|
|
|
* No.
|
|
|
|
*/
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_TYPE_MISMATCH;
|
2016-07-14 23:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can there be more than one instance of this option?
|
|
|
|
*/
|
|
|
|
if (opttype->flags & WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED) {
|
|
|
|
/*
|
|
|
|
* Yes. You can't ask for "the" value.
|
|
|
|
*/
|
|
|
|
return WTAP_OPTTYPE_NUMBER_MISMATCH;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
optval = wtap_block_get_option(block, option_id);
|
|
|
|
if (optval == NULL) {
|
|
|
|
/* Didn't find the option */
|
|
|
|
return WTAP_OPTTYPE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
*optvalp = optval;
|
2016-05-20 02:28:43 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_opttype_return_val
|
|
|
|
wtap_block_get_nth_option_common(wtap_block_t block, guint option_id, wtap_opttype_e type, guint idx, wtap_optval_t **optvalp)
|
2016-05-20 02:28:43 +00:00
|
|
|
{
|
2021-02-05 06:09:23 +00:00
|
|
|
const wtap_opttype_t *opttype;
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_optval_t *optval;
|
2016-05-20 02:28:43 +00:00
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return WTAP_OPTTYPE_BAD_BLOCK;
|
|
|
|
}
|
|
|
|
|
2021-02-05 06:09:23 +00:00
|
|
|
opttype = GET_OPTION_TYPE(block->info->options, option_id);
|
|
|
|
if (opttype == NULL) {
|
2016-07-14 23:01:57 +00:00
|
|
|
/* There's no option for this block with that option ID */
|
|
|
|
return WTAP_OPTTYPE_NO_SUCH_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is this an option of the specified data type?
|
|
|
|
*/
|
|
|
|
if (opttype->data_type != type) {
|
|
|
|
/*
|
|
|
|
* No.
|
|
|
|
*/
|
2016-05-20 02:28:43 +00:00
|
|
|
return WTAP_OPTTYPE_TYPE_MISMATCH;
|
2016-07-14 23:01:57 +00:00
|
|
|
}
|
2016-05-20 02:28:43 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* Can there be more than one instance of this option?
|
|
|
|
*/
|
|
|
|
if (!(opttype->flags & WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED)) {
|
|
|
|
/*
|
|
|
|
* No.
|
|
|
|
*/
|
|
|
|
return WTAP_OPTTYPE_NUMBER_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
optval = wtap_block_get_nth_option(block, option_id, idx);
|
|
|
|
if (optval == NULL) {
|
|
|
|
/* Didn't find the option */
|
|
|
|
return WTAP_OPTTYPE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
*optvalp = optval;
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_uint8_option(wtap_block_t block, guint option_id, guint8 value)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_UINT8, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.uint8val = value;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_uint8_option_value(wtap_block_t block, guint option_id, guint8 value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_UINT8, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
optval->uint8val = value;
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_uint8_option_value(wtap_block_t block, guint option_id, guint8* value)
|
2016-06-06 01:04:23 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-06-06 01:04:23 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_UINT8, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->uint8val;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-06-06 01:04:23 +00:00
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_uint32_option(wtap_block_t block, guint option_id, guint32 value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_UINT32, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.uint32val = value;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_uint32_option_value(wtap_block_t block, guint option_id, guint32 value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_UINT32, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
optval->uint32val = value;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_uint32_option_value(wtap_block_t block, guint option_id, guint32* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_UINT32, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->uint32val;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_uint64_option(wtap_block_t block, guint option_id, guint64 value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
2016-06-06 01:04:23 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_UINT64, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.uint64val = value;
|
2016-06-06 01:04:23 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_uint64_option_value(wtap_block_t block, guint option_id, guint64 value)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_UINT64, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
optval->uint64val = value;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_uint64_option_value(wtap_block_t block, guint option_id, guint64 *value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_UINT64, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->uint64val;
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_ipv4_option(wtap_block_t block, guint option_id, guint32 value)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_IPv4, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.ipv4val = value;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_ipv4_option_value(wtap_block_t block, guint option_id, guint32 value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_IPv4, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
optval->ipv4val = value;
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_ipv4_option_value(wtap_block_t block, guint option_id, guint32* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_IPv4, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->ipv4val;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-05-17 21:04:04 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
2017-10-26 08:50:00 +00:00
|
|
|
wtap_block_add_ipv6_option(wtap_block_t block, guint option_id, ws_in6_addr *value)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_IPv6, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.ipv6val = *value;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
2017-10-26 08:50:00 +00:00
|
|
|
wtap_block_set_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_addr *value)
|
2016-07-14 23:01:57 +00:00
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_IPv6, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
optval->ipv6val = *value;
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
2017-10-26 08:50:00 +00:00
|
|
|
wtap_block_get_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_addr* value)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2021-08-27 19:54:02 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_IPv6, &optval);
|
2016-07-14 23:01:57 +00:00
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->ipv6val;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_string_option(wtap_block_t block, guint option_id, const char *value, gsize value_length)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_STRING, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.stringval = g_strndup(value, value_length);
|
2022-12-06 19:27:24 +00:00
|
|
|
WS_UTF_8_CHECK(opt->value.stringval, -1);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_string_option_owned(wtap_block_t block, guint option_id, char *value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_STRING, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.stringval = value;
|
|
|
|
WS_UTF_8_CHECK(opt->value.stringval, -1);
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_opttype_return_val
|
|
|
|
wtap_block_add_string_option_vformat(wtap_block_t block, guint option_id, const char *format, va_list va)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_STRING, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
2021-12-18 18:48:20 +00:00
|
|
|
opt->value.stringval = ws_strdup_vprintf(format, va);
|
2022-12-06 19:27:24 +00:00
|
|
|
WS_UTF_8_CHECK(opt->value.stringval, -1);
|
2016-07-14 23:01:57 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_string_option_format(wtap_block_t block, guint option_id, const char *format, ...)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
va_list va;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_STRING, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
va_start(va, format);
|
2021-12-18 18:48:20 +00:00
|
|
|
opt->value.stringval = ws_strdup_vprintf(format, va);
|
2016-07-14 23:01:57 +00:00
|
|
|
va_end(va);
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_string_option_value(wtap_block_t block, guint option_id, const char *value, size_t value_length)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_STRING, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS) {
|
|
|
|
if (ret == WTAP_OPTTYPE_NOT_FOUND) {
|
|
|
|
/*
|
|
|
|
* There's no instance to set, so just try to create a new one
|
|
|
|
* with the value.
|
|
|
|
*/
|
|
|
|
return wtap_block_add_string_option(block, option_id, value, value_length);
|
|
|
|
}
|
|
|
|
/* Otherwise fail. */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
g_free(optval->stringval);
|
|
|
|
optval->stringval = g_strndup(value, value_length);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, const char *value, size_t value_length)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_nth_option_common(block, option_id, WTAP_OPTTYPE_STRING, idx, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
g_free(optval->stringval);
|
|
|
|
optval->stringval = g_strndup(value, value_length);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_string_option_value_format(wtap_block_t block, guint option_id, const char *format, ...)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
va_list va;
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_STRING, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS) {
|
|
|
|
if (ret == WTAP_OPTTYPE_NOT_FOUND) {
|
|
|
|
/*
|
|
|
|
* There's no instance to set, so just try to create a new one
|
|
|
|
* with the formatted string.
|
|
|
|
*/
|
|
|
|
va_start(va, format);
|
|
|
|
ret = wtap_block_add_string_option_vformat(block, option_id, format, va);
|
|
|
|
va_end(va);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* Otherwise fail. */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
g_free(optval->stringval);
|
|
|
|
va_start(va, format);
|
2021-12-18 18:48:20 +00:00
|
|
|
optval->stringval = ws_strdup_vprintf(format, va);
|
2016-07-14 23:01:57 +00:00
|
|
|
va_end(va);
|
2016-01-26 01:17:21 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-01-30 09:49:45 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_nth_string_option_value_format(wtap_block_t block, guint option_id, guint idx, const char *format, ...)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
ret = wtap_block_get_nth_option_common(block, option_id, WTAP_OPTTYPE_STRING, idx, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
g_free(optval->stringval);
|
|
|
|
va_start(va, format);
|
2021-12-18 18:48:20 +00:00
|
|
|
optval->stringval = ws_strdup_vprintf(format, va);
|
2021-01-30 09:49:45 +00:00
|
|
|
va_end(va);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_string_option_value(wtap_block_t block, guint option_id, char** value)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_STRING, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->stringval;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, char** value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
ret = wtap_block_get_nth_option_common(block, option_id, WTAP_OPTTYPE_STRING, idx, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->stringval;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
2016-01-26 01:17:21 +00:00
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_bytes_option(wtap_block_t block, guint option_id, const guint8 *value, gsize value_length)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_BYTES, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.byteval = g_bytes_new(value, value_length);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_bytes_option_borrow(wtap_block_t block, guint option_id, GBytes *value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_BYTES, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.byteval = g_bytes_ref(value);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_bytes_option_value(wtap_block_t block, guint option_id, const guint8 *value, size_t value_length)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_BYTES, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS) {
|
|
|
|
if (ret == WTAP_OPTTYPE_NOT_FOUND) {
|
|
|
|
/*
|
|
|
|
* There's no instance to set, so just try to create a new one
|
|
|
|
* with the value.
|
|
|
|
*/
|
|
|
|
return wtap_block_add_bytes_option(block, option_id, value, value_length);
|
|
|
|
}
|
|
|
|
/* Otherwise fail. */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
g_bytes_unref(optval->byteval);
|
|
|
|
optval->byteval = g_bytes_new(value, value_length);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_nth_bytes_option_value(wtap_block_t block, guint option_id, guint idx, GBytes *value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_nth_option_common(block, option_id, WTAP_OPTTYPE_BYTES, idx, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
g_bytes_unref(optval->byteval);
|
|
|
|
optval->byteval = g_bytes_ref(value);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_bytes_option_value(wtap_block_t block, guint option_id, GBytes** value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_BYTES, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->byteval;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_nth_bytes_option_value(wtap_block_t block, guint option_id, guint idx, GBytes** value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_nth_option_common(block, option_id, WTAP_OPTTYPE_BYTES, idx, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->byteval;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:57:52 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_nflx_custom_option(wtap_block_t block, guint32 type, const char *custom_data, gsize custom_data_len)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, OPT_CUSTOM_BIN_COPY, WTAP_OPTTYPE_CUSTOM, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.custom_opt.pen = PEN_NFLX;
|
|
|
|
opt->value.custom_opt.data.nflx_data.type = type;
|
|
|
|
opt->value.custom_opt.data.nflx_data.custom_data_len = custom_data_len;
|
|
|
|
opt->value.custom_opt.data.nflx_data.custom_data = g_memdup2(custom_data, custom_data_len);
|
|
|
|
opt->value.custom_opt.data.nflx_data.use_little_endian = (block->info->block_type == WTAP_BLOCK_CUSTOM);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_nflx_custom_option(wtap_block_t block, guint32 nflx_type, char *nflx_custom_data _U_, gsize nflx_custom_data_len)
|
|
|
|
{
|
|
|
|
const wtap_opttype_t *opttype;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (block == NULL) {
|
|
|
|
return WTAP_OPTTYPE_BAD_BLOCK;
|
|
|
|
}
|
|
|
|
opttype = GET_OPTION_TYPE(block->info->options, OPT_CUSTOM_BIN_COPY);
|
|
|
|
if (opttype == NULL) {
|
|
|
|
return WTAP_OPTTYPE_NO_SUCH_OPTION;
|
|
|
|
}
|
|
|
|
if (opttype->data_type != WTAP_OPTTYPE_CUSTOM) {
|
|
|
|
return WTAP_OPTTYPE_TYPE_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < block->options->len; i++) {
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
|
|
|
if ((opt->option_id == OPT_CUSTOM_BIN_COPY) &&
|
|
|
|
(opt->value.custom_opt.pen == PEN_NFLX) &&
|
|
|
|
(opt->value.custom_opt.data.nflx_data.type == nflx_type)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == block->options->len) {
|
|
|
|
return WTAP_OPTTYPE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
if (nflx_custom_data_len < opt->value.custom_opt.data.nflx_data.custom_data_len) {
|
|
|
|
return WTAP_OPTTYPE_TYPE_MISMATCH;
|
|
|
|
}
|
|
|
|
switch (nflx_type) {
|
|
|
|
case NFLX_OPT_TYPE_VERSION: {
|
|
|
|
guint32 *src, *dst;
|
|
|
|
|
|
|
|
ws_assert(nflx_custom_data_len == sizeof(guint32));
|
|
|
|
src = (guint32 *)opt->value.custom_opt.data.nflx_data.custom_data;
|
|
|
|
dst = (guint32 *)nflx_custom_data;
|
|
|
|
*dst = GUINT32_FROM_LE(*src);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NFLX_OPT_TYPE_TCPINFO: {
|
|
|
|
struct nflx_tcpinfo *src, *dst;
|
|
|
|
|
|
|
|
ws_assert(nflx_custom_data_len == sizeof(struct nflx_tcpinfo));
|
|
|
|
src = (struct nflx_tcpinfo *)opt->value.custom_opt.data.nflx_data.custom_data;
|
|
|
|
dst = (struct nflx_tcpinfo *)nflx_custom_data;
|
|
|
|
dst->tlb_tv_sec = GUINT64_FROM_LE(src->tlb_tv_sec);
|
|
|
|
dst->tlb_tv_usec = GUINT64_FROM_LE(src->tlb_tv_usec);
|
|
|
|
dst->tlb_ticks = GUINT32_FROM_LE(src->tlb_ticks);
|
|
|
|
dst->tlb_sn = GUINT32_FROM_LE(src->tlb_sn);
|
|
|
|
dst->tlb_stackid = src->tlb_stackid;
|
|
|
|
dst->tlb_eventid = src->tlb_eventid;
|
|
|
|
dst->tlb_eventflags = GUINT16_FROM_LE(src->tlb_eventflags);
|
|
|
|
dst->tlb_errno = GINT32_FROM_LE(src->tlb_errno);
|
|
|
|
dst->tlb_rxbuf_tls_sb_acc = GUINT32_FROM_LE(src->tlb_rxbuf_tls_sb_acc);
|
|
|
|
dst->tlb_rxbuf_tls_sb_ccc = GUINT32_FROM_LE(src->tlb_rxbuf_tls_sb_ccc);
|
|
|
|
dst->tlb_rxbuf_tls_sb_spare = GUINT32_FROM_LE(src->tlb_rxbuf_tls_sb_spare);
|
|
|
|
dst->tlb_txbuf_tls_sb_acc = GUINT32_FROM_LE(src->tlb_txbuf_tls_sb_acc);
|
|
|
|
dst->tlb_txbuf_tls_sb_ccc = GUINT32_FROM_LE(src->tlb_txbuf_tls_sb_ccc);
|
|
|
|
dst->tlb_txbuf_tls_sb_spare = GUINT32_FROM_LE(src->tlb_txbuf_tls_sb_spare);
|
|
|
|
dst->tlb_state = GINT32_FROM_LE(src->tlb_state);
|
|
|
|
dst->tlb_starttime = GUINT32_FROM_LE(src->tlb_starttime);
|
|
|
|
dst->tlb_iss = GUINT32_FROM_LE(src->tlb_iss);
|
|
|
|
dst->tlb_flags = GUINT32_FROM_LE(src->tlb_flags);
|
|
|
|
dst->tlb_snd_una = GUINT32_FROM_LE(src->tlb_snd_una);
|
|
|
|
dst->tlb_snd_max = GUINT32_FROM_LE(src->tlb_snd_max);
|
|
|
|
dst->tlb_snd_cwnd = GUINT32_FROM_LE(src->tlb_snd_cwnd);
|
|
|
|
dst->tlb_snd_nxt = GUINT32_FROM_LE(src->tlb_snd_nxt);
|
|
|
|
dst->tlb_snd_recover = GUINT32_FROM_LE(src->tlb_snd_recover);
|
|
|
|
dst->tlb_snd_wnd = GUINT32_FROM_LE(src->tlb_snd_wnd);
|
|
|
|
dst->tlb_snd_ssthresh = GUINT32_FROM_LE(src->tlb_snd_ssthresh);
|
|
|
|
dst->tlb_srtt = GUINT32_FROM_LE(src->tlb_srtt);
|
|
|
|
dst->tlb_rttvar = GUINT32_FROM_LE(src->tlb_rttvar);
|
|
|
|
dst->tlb_rcv_up = GUINT32_FROM_LE(src->tlb_rcv_up);
|
|
|
|
dst->tlb_rcv_adv = GUINT32_FROM_LE(src->tlb_rcv_adv);
|
|
|
|
dst->tlb_flags2 = GUINT32_FROM_LE(src->tlb_flags2);
|
|
|
|
dst->tlb_rcv_nxt = GUINT32_FROM_LE(src->tlb_rcv_nxt);
|
|
|
|
dst->tlb_rcv_wnd = GUINT32_FROM_LE(src->tlb_rcv_wnd);
|
|
|
|
dst->tlb_dupacks = GUINT32_FROM_LE(src->tlb_dupacks);
|
|
|
|
dst->tlb_segqlen = GINT32_FROM_LE(src->tlb_segqlen);
|
|
|
|
dst->tlb_snd_numholes = GINT32_FROM_LE(src->tlb_snd_numholes);
|
|
|
|
dst->tlb_flex1 = GUINT32_FROM_LE(src->tlb_flex1);
|
|
|
|
dst->tlb_flex2 = GUINT32_FROM_LE(src->tlb_flex2);
|
|
|
|
dst->tlb_fbyte_in = GUINT32_FROM_LE(src->tlb_fbyte_in);
|
|
|
|
dst->tlb_fbyte_out = GUINT32_FROM_LE(src->tlb_fbyte_out);
|
|
|
|
dst->tlb_snd_scale = src->tlb_snd_scale;
|
|
|
|
dst->tlb_rcv_scale = src->tlb_rcv_scale;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
dst->_pad[i] = src->_pad[i];
|
|
|
|
}
|
|
|
|
dst->tlb_stackinfo_bbr_cur_del_rate = GUINT64_FROM_LE(src->tlb_stackinfo_bbr_cur_del_rate);
|
|
|
|
dst->tlb_stackinfo_bbr_delRate = GUINT64_FROM_LE(src->tlb_stackinfo_bbr_delRate);
|
|
|
|
dst->tlb_stackinfo_bbr_rttProp = GUINT64_FROM_LE(src->tlb_stackinfo_bbr_rttProp);
|
|
|
|
dst->tlb_stackinfo_bbr_bw_inuse = GUINT64_FROM_LE(src->tlb_stackinfo_bbr_bw_inuse);
|
|
|
|
dst->tlb_stackinfo_bbr_inflight = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_inflight);
|
|
|
|
dst->tlb_stackinfo_bbr_applimited = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_applimited);
|
|
|
|
dst->tlb_stackinfo_bbr_delivered = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_delivered);
|
|
|
|
dst->tlb_stackinfo_bbr_timeStamp = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_timeStamp);
|
|
|
|
dst->tlb_stackinfo_bbr_epoch = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_epoch);
|
|
|
|
dst->tlb_stackinfo_bbr_lt_epoch = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_lt_epoch);
|
|
|
|
dst->tlb_stackinfo_bbr_pkts_out = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_pkts_out);
|
|
|
|
dst->tlb_stackinfo_bbr_flex1 = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_flex1);
|
|
|
|
dst->tlb_stackinfo_bbr_flex2 = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_flex2);
|
|
|
|
dst->tlb_stackinfo_bbr_flex3 = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_flex3);
|
|
|
|
dst->tlb_stackinfo_bbr_flex4 = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_flex4);
|
|
|
|
dst->tlb_stackinfo_bbr_flex5 = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_flex5);
|
|
|
|
dst->tlb_stackinfo_bbr_flex6 = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_flex6);
|
|
|
|
dst->tlb_stackinfo_bbr_lost = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_lost);
|
|
|
|
dst->tlb_stackinfo_bbr_pacing_gain = GUINT16_FROM_LE(src->tlb_stackinfo_bbr_lost);
|
|
|
|
dst->tlb_stackinfo_bbr_cwnd_gain = GUINT16_FROM_LE(src->tlb_stackinfo_bbr_lost);
|
|
|
|
dst->tlb_stackinfo_bbr_flex7 = GUINT16_FROM_LE(src->tlb_stackinfo_bbr_flex7);
|
|
|
|
dst->tlb_stackinfo_bbr_bbr_state = src->tlb_stackinfo_bbr_bbr_state;
|
|
|
|
dst->tlb_stackinfo_bbr_bbr_substate = src->tlb_stackinfo_bbr_bbr_substate;
|
|
|
|
dst->tlb_stackinfo_bbr_inhpts = src->tlb_stackinfo_bbr_inhpts;
|
|
|
|
dst->tlb_stackinfo_bbr_ininput = src->tlb_stackinfo_bbr_ininput;
|
|
|
|
dst->tlb_stackinfo_bbr_use_lt_bw = src->tlb_stackinfo_bbr_use_lt_bw;
|
|
|
|
dst->tlb_stackinfo_bbr_flex8 = src->tlb_stackinfo_bbr_flex8;
|
|
|
|
dst->tlb_stackinfo_bbr_pkt_epoch = GUINT32_FROM_LE(src->tlb_stackinfo_bbr_pkt_epoch);
|
|
|
|
dst->tlb_len = GUINT32_FROM_LE(src->tlb_len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NFLX_OPT_TYPE_DUMPINFO: {
|
|
|
|
struct nflx_dumpinfo *src, *dst;
|
|
|
|
|
|
|
|
ws_assert(nflx_custom_data_len == sizeof(struct nflx_dumpinfo));
|
|
|
|
src = (struct nflx_dumpinfo *)opt->value.custom_opt.data.nflx_data.custom_data;
|
|
|
|
dst = (struct nflx_dumpinfo *)nflx_custom_data;
|
|
|
|
dst->tlh_version = GUINT32_FROM_LE(src->tlh_version);
|
|
|
|
dst->tlh_type = GUINT32_FROM_LE(src->tlh_type);
|
|
|
|
dst->tlh_length = GUINT64_FROM_LE(src->tlh_length);
|
|
|
|
dst->tlh_ie_fport = src->tlh_ie_fport;
|
|
|
|
dst->tlh_ie_lport = src->tlh_ie_lport;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
dst->tlh_ie_faddr_addr32[i] = src->tlh_ie_faddr_addr32[i];
|
|
|
|
dst->tlh_ie_laddr_addr32[i] = src->tlh_ie_laddr_addr32[i];
|
|
|
|
}
|
|
|
|
dst->tlh_ie_zoneid = src->tlh_ie_zoneid;
|
|
|
|
dst->tlh_offset_tv_sec = GUINT64_FROM_LE(src->tlh_offset_tv_sec);
|
|
|
|
dst->tlh_offset_tv_usec = GUINT64_FROM_LE(src->tlh_offset_tv_usec);
|
|
|
|
memcpy(dst->tlh_id, src->tlh_id, 64);
|
|
|
|
memcpy(dst->tlh_reason, src->tlh_reason, 32);
|
|
|
|
memcpy(dst->tlh_tag, src->tlh_tag, 32);
|
|
|
|
dst->tlh_af = src->tlh_af;
|
|
|
|
memcpy(dst->_pad, src->_pad, 7);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NFLX_OPT_TYPE_DUMPTIME: {
|
|
|
|
guint64 *src, *dst;
|
|
|
|
|
|
|
|
ws_assert(nflx_custom_data_len == sizeof(guint64));
|
|
|
|
src = (guint64 *)opt->value.custom_opt.data.nflx_data.custom_data;
|
|
|
|
dst = (guint64 *)nflx_custom_data;
|
|
|
|
*dst = GUINT64_FROM_LE(*src);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NFLX_OPT_TYPE_STACKNAME:
|
|
|
|
ws_assert(nflx_custom_data_len >= 2);
|
|
|
|
memcpy(nflx_custom_data, opt->value.custom_opt.data.nflx_data.custom_data, nflx_custom_data_len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return WTAP_OPTTYPE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-06-21 14:56:58 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_custom_option(wtap_block_t block, guint option_id, guint32 pen, const char *custom_data, gsize custom_data_len)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_CUSTOM, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.custom_opt.pen = pen;
|
2021-08-04 17:57:52 +00:00
|
|
|
opt->value.custom_opt.data.generic_data.custom_data_len = custom_data_len;
|
|
|
|
opt->value.custom_opt.data.generic_data.custom_data = g_memdup2(custom_data, custom_data_len);
|
2021-06-21 14:56:58 +00:00
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:33:47 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_if_filter_option(wtap_block_t block, guint option_id, if_filter_opt_t* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_IF_FILTER, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.if_filterval = if_filter_dup(value);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_if_filter_option_value(wtap_block_t block, guint option_id, if_filter_opt_t* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
if_filter_opt_t prev_value;
|
|
|
|
|
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_IF_FILTER, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
prev_value = optval->if_filterval;
|
|
|
|
optval->if_filterval = if_filter_dup(value);
|
|
|
|
/* Free after memory is duplicated in case structure was manipulated with a "get then set" */
|
|
|
|
if_filter_free(&prev_value);
|
|
|
|
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_if_filter_option_value(wtap_block_t block, guint option_id, if_filter_opt_t* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_option_common(block, option_id, WTAP_OPTTYPE_IF_FILTER, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->if_filterval;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-08-30 21:36:44 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_packet_verdict_option(wtap_block_t block, guint option_id, packet_verdict_opt_t* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_PACKET_VERDICT, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.packet_verdictval = packet_verdict_dup(value);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_set_nth_packet_verdict_option_value(wtap_block_t block, guint option_id, guint idx, packet_verdict_opt_t* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
packet_verdict_opt_t prev_value;
|
|
|
|
|
|
|
|
ret = wtap_block_get_nth_option_common(block, option_id, WTAP_OPTTYPE_PACKET_VERDICT, idx, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
prev_value = optval->packet_verdictval;
|
|
|
|
optval->packet_verdictval = packet_verdict_dup(value);
|
|
|
|
/* Free after memory is duplicated in case structure was manipulated with a "get then set" */
|
|
|
|
wtap_packet_verdict_free(&prev_value);
|
|
|
|
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_get_nth_packet_verdict_option_value(wtap_block_t block, guint option_id, guint idx, packet_verdict_opt_t* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_optval_t *optval;
|
|
|
|
|
|
|
|
ret = wtap_block_get_nth_option_common(block, option_id, WTAP_OPTTYPE_STRING, idx, &optval);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
*value = optval->packet_verdictval;
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-08-11 20:28:03 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_add_packet_hash_option(wtap_block_t block, guint option_id, packet_hash_opt_t* value)
|
|
|
|
{
|
|
|
|
wtap_opttype_return_val ret;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
|
|
|
ret = wtap_block_add_option_common(block, option_id, WTAP_OPTTYPE_PACKET_HASH, &opt);
|
|
|
|
if (ret != WTAP_OPTTYPE_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
opt->value.packet_hash = packet_hash_dup(value);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-07-16 00:25:41 +00:00
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_remove_option(wtap_block_t block, guint option_id)
|
|
|
|
{
|
2021-02-05 06:09:23 +00:00
|
|
|
const wtap_opttype_t *opttype;
|
2016-07-16 00:25:41 +00:00
|
|
|
guint i;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return WTAP_OPTTYPE_BAD_BLOCK;
|
|
|
|
}
|
|
|
|
|
2021-02-05 06:09:23 +00:00
|
|
|
opttype = GET_OPTION_TYPE(block->info->options, option_id);
|
|
|
|
if (opttype == NULL) {
|
2016-07-16 00:25:41 +00:00
|
|
|
/* There's no option for this block with that option ID */
|
|
|
|
return WTAP_OPTTYPE_NO_SUCH_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can there be more than one instance of this option?
|
|
|
|
*/
|
|
|
|
if (opttype->flags & WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED) {
|
|
|
|
/*
|
|
|
|
* Yes. You can't remove "the" value.
|
|
|
|
*/
|
|
|
|
return WTAP_OPTTYPE_NUMBER_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < block->options->len; i++) {
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
|
|
|
if (opt->option_id == option_id) {
|
|
|
|
/* Found it - free up the value */
|
|
|
|
wtap_block_free_option(block, opt);
|
|
|
|
/* Remove the option from the array of options */
|
|
|
|
g_array_remove_index(block->options, i);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Didn't find the option */
|
|
|
|
return WTAP_OPTTYPE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtap_opttype_return_val
|
|
|
|
wtap_block_remove_nth_option_instance(wtap_block_t block, guint option_id,
|
|
|
|
guint idx)
|
|
|
|
{
|
2021-02-05 06:09:23 +00:00
|
|
|
const wtap_opttype_t *opttype;
|
2016-07-16 00:25:41 +00:00
|
|
|
guint i;
|
|
|
|
wtap_option_t *opt;
|
|
|
|
guint opt_idx;
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
if (block == NULL) {
|
|
|
|
return WTAP_OPTTYPE_BAD_BLOCK;
|
|
|
|
}
|
|
|
|
|
2021-02-05 06:09:23 +00:00
|
|
|
opttype = GET_OPTION_TYPE(block->info->options, option_id);
|
|
|
|
if (opttype == NULL) {
|
2016-07-16 00:25:41 +00:00
|
|
|
/* There's no option for this block with that option ID */
|
|
|
|
return WTAP_OPTTYPE_NO_SUCH_OPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can there be more than one instance of this option?
|
|
|
|
*/
|
|
|
|
if (!(opttype->flags & WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED)) {
|
|
|
|
/*
|
|
|
|
* No.
|
|
|
|
*/
|
|
|
|
return WTAP_OPTTYPE_NUMBER_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
opt_idx = 0;
|
|
|
|
for (i = 0; i < block->options->len; i++) {
|
|
|
|
opt = &g_array_index(block->options, wtap_option_t, i);
|
|
|
|
if (opt->option_id == option_id) {
|
|
|
|
if (opt_idx == idx) {
|
|
|
|
/* Found it - free up the value */
|
|
|
|
wtap_block_free_option(block, opt);
|
|
|
|
/* Remove the option from the array of options */
|
|
|
|
g_array_remove_index(block->options, i);
|
|
|
|
return WTAP_OPTTYPE_SUCCESS;
|
|
|
|
}
|
|
|
|
opt_idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Didn't find the option */
|
|
|
|
return WTAP_OPTTYPE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void shb_create(wtap_block_t block)
|
2016-03-02 14:13:08 +00:00
|
|
|
{
|
2021-05-24 09:25:02 +00:00
|
|
|
wtapng_section_mandatory_t* section_mand = g_new(wtapng_section_mandatory_t, 1);
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
section_mand->section_length = -1;
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
block->mandatory_data = section_mand;
|
|
|
|
}
|
2016-03-02 14:13:08 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void shb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
|
|
|
|
{
|
2021-05-24 09:25:02 +00:00
|
|
|
memcpy(dest_block->mandatory_data, src_block->mandatory_data, sizeof(wtapng_section_mandatory_t));
|
2016-03-02 14:13:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void nrb_create(wtap_block_t block)
|
2016-03-02 14:13:08 +00:00
|
|
|
{
|
2023-01-20 06:10:27 +00:00
|
|
|
block->mandatory_data = g_new0(wtapng_nrb_mandatory_t, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nrb_free_mand(wtap_block_t block)
|
|
|
|
{
|
|
|
|
wtapng_nrb_mandatory_t *mand = (wtapng_nrb_mandatory_t *)block->mandatory_data;
|
|
|
|
g_list_free_full(mand->ipv4_addr_list, g_free);
|
|
|
|
g_list_free_full(mand->ipv6_addr_list, g_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static gpointer copy_hashipv4(gconstpointer src, gpointer user_data _U_
|
|
|
|
{
|
|
|
|
hashipv4_t *src_ipv4 = (hashipv4_t*)src;
|
|
|
|
hashipv4_t *dst = g_new0(hashipv4_t, 1);
|
|
|
|
dst->addr = src_ipv4->addr;
|
|
|
|
(void) g_strlcpy(dst->name, src_ipv4->name, MAXNAMELEN);
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer copy_hashipv4(gconstpointer src, gpointer user_data _U_
|
|
|
|
{
|
|
|
|
hashipv6_t *src_ipv6 = (hashipv6_t*)src;
|
|
|
|
hashipv6_t *dst = g_new0(hashipv6_t, 1);
|
|
|
|
dst->addr = src_ipv4->addr;
|
|
|
|
(void) g_strlcpy(dst->name, src_ipv4->name, MAXNAMELEN);
|
|
|
|
return dst;
|
2016-07-14 23:01:57 +00:00
|
|
|
}
|
2016-03-04 13:52:48 +00:00
|
|
|
|
2023-01-20 06:10:27 +00:00
|
|
|
static void nrb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
|
|
|
|
{
|
|
|
|
wtapng_nrb_mandatory_t *src = (wtapng_nrb_mandatory_t *)src_block->mandatory_data;
|
|
|
|
wtapng_nrb_mandatory_t *dst = (wtapng_nrb_mandatory_t *)dest_block->mandatory_data;
|
|
|
|
g_list_free_full(dst->ipv4_addr_list, g_free);
|
|
|
|
g_list_free_full(dst->ipv6_addr_list, g_free);
|
|
|
|
dst->ipv4_addr_list = g_list_copy_deep(src->ipv4_addr_list, copy_hashipv4, NULL);
|
|
|
|
dst->ipv6_addr_list = g_list_copy_deep(src->ipv6_addr_list, copy_hashipv6, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void isb_create(wtap_block_t block)
|
|
|
|
{
|
2016-03-02 14:13:08 +00:00
|
|
|
block->mandatory_data = g_new0(wtapng_if_stats_mandatory_t, 1);
|
2016-07-14 23:01:57 +00:00
|
|
|
}
|
2016-03-02 14:13:08 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void isb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
|
2016-03-02 14:13:08 +00:00
|
|
|
{
|
|
|
|
memcpy(dest_block->mandatory_data, src_block->mandatory_data, sizeof(wtapng_if_stats_mandatory_t));
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void idb_create(wtap_block_t block)
|
2016-03-02 14:13:08 +00:00
|
|
|
{
|
|
|
|
block->mandatory_data = g_new0(wtapng_if_descr_mandatory_t, 1);
|
2016-07-14 23:01:57 +00:00
|
|
|
}
|
2016-03-02 14:13:08 +00:00
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void idb_free_mand(wtap_block_t block)
|
2016-03-02 14:13:08 +00:00
|
|
|
{
|
|
|
|
guint j;
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_block_t if_stats;
|
2016-03-02 14:13:08 +00:00
|
|
|
wtapng_if_descr_mandatory_t* mand = (wtapng_if_descr_mandatory_t*)block->mandatory_data;
|
|
|
|
|
|
|
|
for(j = 0; j < mand->num_stat_entries; j++) {
|
2016-07-14 23:01:57 +00:00
|
|
|
if_stats = g_array_index(mand->interface_statistics, wtap_block_t, j);
|
2021-04-29 11:23:21 +00:00
|
|
|
wtap_block_unref(if_stats);
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 14:13:08 +00:00
|
|
|
if (mand->interface_statistics)
|
|
|
|
g_array_free(mand->interface_statistics, TRUE);
|
|
|
|
}
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static void idb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
|
2016-03-02 14:13:08 +00:00
|
|
|
{
|
|
|
|
guint j;
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_block_t src_if_stats, dest_if_stats;
|
2016-03-02 14:13:08 +00:00
|
|
|
wtapng_if_descr_mandatory_t *src_mand = (wtapng_if_descr_mandatory_t*)src_block->mandatory_data,
|
|
|
|
*dest_mand = (wtapng_if_descr_mandatory_t*)dest_block->mandatory_data;
|
|
|
|
|
|
|
|
/* Need special consideration for copying of the interface_statistics member */
|
|
|
|
if (dest_mand->num_stat_entries != 0)
|
|
|
|
g_array_free(dest_mand->interface_statistics, TRUE);
|
|
|
|
|
|
|
|
memcpy(dest_mand, src_mand, sizeof(wtapng_if_descr_mandatory_t));
|
|
|
|
if (src_mand->num_stat_entries != 0)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
dest_mand->interface_statistics = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
|
2016-03-02 14:13:08 +00:00
|
|
|
for (j = 0; j < src_mand->num_stat_entries; j++)
|
2016-01-26 01:17:21 +00:00
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
src_if_stats = g_array_index(src_mand->interface_statistics, wtap_block_t, j);
|
2020-10-22 02:10:49 +00:00
|
|
|
dest_if_stats = wtap_block_make_copy(src_if_stats);
|
2016-03-02 14:13:08 +00:00
|
|
|
dest_mand->interface_statistics = g_array_append_val(dest_mand->interface_statistics, dest_if_stats);
|
2016-01-26 01:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-02 14:13:08 +00:00
|
|
|
|
2018-11-17 12:56:12 +00:00
|
|
|
static void dsb_create(wtap_block_t block)
|
|
|
|
{
|
|
|
|
block->mandatory_data = g_new0(wtapng_dsb_mandatory_t, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dsb_free_mand(wtap_block_t block)
|
|
|
|
{
|
|
|
|
wtapng_dsb_mandatory_t *mand = (wtapng_dsb_mandatory_t *)block->mandatory_data;
|
|
|
|
g_free(mand->secrets_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dsb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
|
|
|
|
{
|
|
|
|
wtapng_dsb_mandatory_t *src = (wtapng_dsb_mandatory_t *)src_block->mandatory_data;
|
|
|
|
wtapng_dsb_mandatory_t *dst = (wtapng_dsb_mandatory_t *)dest_block->mandatory_data;
|
|
|
|
dst->secrets_type = src->secrets_type;
|
|
|
|
dst->secrets_len = src->secrets_len;
|
|
|
|
g_free(dst->secrets_data);
|
2021-03-23 15:41:54 +00:00
|
|
|
dst->secrets_data = (guint8 *)g_memdup2(src->secrets_data, src->secrets_len);
|
2018-11-17 12:56:12 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
static void pkt_create(wtap_block_t block)
|
|
|
|
{
|
|
|
|
/* Commented out for now, there's no mandatory data that isn't handled by
|
|
|
|
* Wireshark in other ways.
|
|
|
|
*/
|
|
|
|
//block->mandatory_data = g_new0(wtapng_packet_mandatory_t, 1);
|
|
|
|
|
|
|
|
/* Ensure this is null, so when g_free is called on it, it simply returns */
|
|
|
|
block->mandatory_data = NULL;
|
|
|
|
}
|
|
|
|
|
2022-01-13 04:42:13 +00:00
|
|
|
static void sjeb_create(wtap_block_t block)
|
|
|
|
{
|
|
|
|
/* Ensure this is null, so when g_free is called on it, it simply returns */
|
|
|
|
block->mandatory_data = NULL;
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:57:52 +00:00
|
|
|
static void cb_create(wtap_block_t block)
|
|
|
|
{
|
|
|
|
/* Ensure this is null, so when g_free is called on it, it simply returns */
|
|
|
|
block->mandatory_data = NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-02 14:13:08 +00:00
|
|
|
void wtap_opttypes_initialize(void)
|
|
|
|
{
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_blocktype_t shb_block = {
|
2021-02-09 21:40:59 +00:00
|
|
|
WTAP_BLOCK_SECTION, /* block_type */
|
2016-07-14 23:01:57 +00:00
|
|
|
"SHB", /* name */
|
|
|
|
"Section Header Block", /* description */
|
|
|
|
shb_create, /* create */
|
|
|
|
NULL, /* free_mand */
|
|
|
|
shb_copy_mand, /* copy_mand */
|
|
|
|
NULL /* options */
|
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t shb_hardware = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"hardware",
|
|
|
|
"SHB Hardware",
|
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t shb_os = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"os",
|
|
|
|
"SHB Operating System",
|
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t shb_userappl = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"user_appl",
|
|
|
|
"SHB User Application",
|
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-03-02 14:13:08 +00:00
|
|
|
};
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_blocktype_t idb_block = {
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
WTAP_BLOCK_IF_ID_AND_INFO, /* block_type */
|
2016-07-14 23:01:57 +00:00
|
|
|
"IDB", /* name */
|
|
|
|
"Interface Description Block", /* description */
|
|
|
|
idb_create, /* create */
|
|
|
|
idb_free_mand, /* free_mand */
|
|
|
|
idb_copy_mand, /* copy_mand */
|
|
|
|
NULL /* options */
|
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t if_name = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"name",
|
|
|
|
"IDB Name",
|
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t if_description = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"description",
|
|
|
|
"IDB Description",
|
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t if_speed = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"speed",
|
|
|
|
"IDB Speed",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t if_tsresol = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"tsresol",
|
|
|
|
"IDB Time Stamp Resolution",
|
|
|
|
WTAP_OPTTYPE_UINT8, /* XXX - signed? */
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t if_filter = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"filter",
|
|
|
|
"IDB Filter",
|
2021-02-01 23:56:47 +00:00
|
|
|
WTAP_OPTTYPE_IF_FILTER,
|
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t if_os = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"os",
|
|
|
|
"IDB Operating System",
|
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t if_fcslen = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"fcslen",
|
|
|
|
"IDB FCS Length",
|
|
|
|
WTAP_OPTTYPE_UINT8,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-03-02 14:13:08 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t if_hardware = {
|
2018-08-11 02:08:40 +00:00
|
|
|
"hardware",
|
|
|
|
"IDB Hardware",
|
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2018-08-11 02:08:40 +00:00
|
|
|
};
|
2016-03-02 14:13:08 +00:00
|
|
|
|
2018-11-17 12:56:12 +00:00
|
|
|
static wtap_blocktype_t dsb_block = {
|
2021-02-09 21:40:59 +00:00
|
|
|
WTAP_BLOCK_DECRYPTION_SECRETS,
|
2018-11-17 12:56:12 +00:00
|
|
|
"DSB",
|
|
|
|
"Decryption Secrets Block",
|
|
|
|
dsb_create,
|
|
|
|
dsb_free_mand,
|
|
|
|
dsb_copy_mand,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_blocktype_t nrb_block = {
|
2021-02-09 21:40:59 +00:00
|
|
|
WTAP_BLOCK_NAME_RESOLUTION, /* block_type */
|
|
|
|
"NRB", /* name */
|
|
|
|
"Name Resolution Block", /* description */
|
|
|
|
nrb_create, /* create */
|
2023-01-20 06:10:27 +00:00
|
|
|
nrb_free_mand, /* free_mand */
|
|
|
|
/* We eventually want to copy these, when dumper actually
|
|
|
|
* writes them out. If we're actually processing packets,
|
|
|
|
* as opposed to just reading and writing a file without
|
|
|
|
* printing (e.g., editcap), do we still want to copy all
|
|
|
|
* the pre-existing NRBs, or do we want to limit it to
|
|
|
|
* the actually used addresses, as currently?
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
nrb_copy_mand, /* copy_mand */
|
|
|
|
#endif
|
|
|
|
NULL,
|
2021-02-09 21:40:59 +00:00
|
|
|
NULL /* options */
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t ns_dnsname = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"dnsname",
|
|
|
|
"NRB DNS server name",
|
|
|
|
WTAP_OPTTYPE_STRING,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t ns_dnsIP4addr = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"dnsIP4addr",
|
|
|
|
"NRB DNS server IPv4 address",
|
|
|
|
WTAP_OPTTYPE_IPv4,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t ns_dnsIP6addr = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"dnsIP6addr",
|
|
|
|
"NRB DNS server IPv6 address",
|
|
|
|
WTAP_OPTTYPE_IPv6,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-03-02 14:13:08 +00:00
|
|
|
};
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
static wtap_blocktype_t isb_block = {
|
2021-02-09 21:40:59 +00:00
|
|
|
WTAP_BLOCK_IF_STATISTICS, /* block_type */
|
2016-07-14 23:01:57 +00:00
|
|
|
"ISB", /* name */
|
|
|
|
"Interface Statistics Block", /* description */
|
|
|
|
isb_create, /* create */
|
|
|
|
NULL, /* free_mand */
|
|
|
|
isb_copy_mand, /* copy_mand */
|
|
|
|
NULL /* options */
|
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t isb_starttime = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"starttime",
|
|
|
|
"ISB Start Time",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t isb_endtime = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"endtime",
|
|
|
|
"ISB End Time",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t isb_ifrecv = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"ifrecv",
|
|
|
|
"ISB Received Packets",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t isb_ifdrop = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"ifdrop",
|
|
|
|
"ISB Dropped Packets",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t isb_filteraccept = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"filteraccept",
|
|
|
|
"ISB Packets Accepted By Filter",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t isb_osdrop = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"osdrop",
|
|
|
|
"ISB Packets Dropped By The OS",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-07-14 23:01:57 +00:00
|
|
|
};
|
2021-02-05 06:09:23 +00:00
|
|
|
static const wtap_opttype_t isb_usrdeliv = {
|
2016-07-14 23:01:57 +00:00
|
|
|
"usrdeliv",
|
|
|
|
"ISB Packets Delivered To The User",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
2021-02-01 23:56:47 +00:00
|
|
|
0
|
2016-03-02 14:13:08 +00:00
|
|
|
};
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
static wtap_blocktype_t pkt_block = {
|
|
|
|
WTAP_BLOCK_PACKET, /* block_type */
|
|
|
|
"EPB/SPB/PB", /* name */
|
|
|
|
"Packet Block", /* description */
|
|
|
|
pkt_create, /* create */
|
|
|
|
NULL, /* free_mand */
|
|
|
|
NULL, /* copy_mand */
|
|
|
|
NULL /* options */
|
|
|
|
};
|
|
|
|
static const wtap_opttype_t pkt_flags = {
|
|
|
|
"flags",
|
|
|
|
"Link-layer flags",
|
|
|
|
WTAP_OPTTYPE_UINT32,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
static const wtap_opttype_t pkt_dropcount = {
|
|
|
|
"dropcount",
|
|
|
|
"Packets Dropped since last packet",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
static const wtap_opttype_t pkt_id = {
|
|
|
|
"packetid",
|
|
|
|
"Unique Packet Identifier",
|
|
|
|
WTAP_OPTTYPE_UINT64,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
static const wtap_opttype_t pkt_queue = {
|
|
|
|
"queue",
|
|
|
|
"Queue ID in which packet was received",
|
|
|
|
WTAP_OPTTYPE_UINT32,
|
|
|
|
0
|
|
|
|
};
|
2021-07-19 21:25:40 +00:00
|
|
|
static const wtap_opttype_t pkt_hash = {
|
|
|
|
"hash",
|
|
|
|
"Hash of packet data",
|
2022-08-11 20:28:03 +00:00
|
|
|
WTAP_OPTTYPE_PACKET_HASH,
|
2021-07-19 21:25:40 +00:00
|
|
|
WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED
|
|
|
|
};
|
2021-04-29 11:23:21 +00:00
|
|
|
static const wtap_opttype_t pkt_verdict = {
|
|
|
|
"verdict",
|
|
|
|
"Packet Verdict",
|
2021-08-30 21:36:44 +00:00
|
|
|
WTAP_OPTTYPE_PACKET_VERDICT,
|
2021-04-29 11:23:21 +00:00
|
|
|
WTAP_OPTTYPE_FLAG_MULTIPLE_ALLOWED
|
|
|
|
};
|
|
|
|
|
2022-01-13 04:42:13 +00:00
|
|
|
static wtap_blocktype_t journal_block = {
|
|
|
|
WTAP_BLOCK_SYSTEMD_JOURNAL_EXPORT, /* block_type */
|
|
|
|
"SJEB", /* name */
|
|
|
|
"systemd Journal Export Block", /* description */
|
|
|
|
sjeb_create, /* create */
|
|
|
|
NULL, /* free_mand */
|
|
|
|
NULL, /* copy_mand */
|
|
|
|
NULL /* options */
|
|
|
|
};
|
|
|
|
|
2021-08-04 17:57:52 +00:00
|
|
|
static wtap_blocktype_t cb_block = {
|
|
|
|
WTAP_BLOCK_CUSTOM, /* block_type */
|
|
|
|
"CB", /* name */
|
2022-01-13 13:10:35 +00:00
|
|
|
"Custom Block", /* description */
|
2021-08-04 17:57:52 +00:00
|
|
|
cb_create, /* create */
|
|
|
|
NULL, /* free_mand */
|
|
|
|
NULL, /* copy_mand */
|
|
|
|
NULL /* options */
|
|
|
|
};
|
|
|
|
|
2016-07-14 23:01:57 +00:00
|
|
|
/*
|
2017-01-20 01:36:50 +00:00
|
|
|
* Register the SHB and the options that can appear in it.
|
2016-07-14 23:01:57 +00:00
|
|
|
*/
|
2021-02-10 02:46:29 +00:00
|
|
|
wtap_opttype_block_register(&shb_block);
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_option_register(&shb_block, OPT_SHB_HARDWARE, &shb_hardware);
|
|
|
|
wtap_opttype_option_register(&shb_block, OPT_SHB_OS, &shb_os);
|
|
|
|
wtap_opttype_option_register(&shb_block, OPT_SHB_USERAPPL, &shb_userappl);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register the IDB and the options that can appear in it.
|
|
|
|
*/
|
2021-02-10 02:46:29 +00:00
|
|
|
wtap_opttype_block_register(&idb_block);
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_option_register(&idb_block, OPT_IDB_NAME, &if_name);
|
2021-07-14 06:48:19 +00:00
|
|
|
wtap_opttype_option_register(&idb_block, OPT_IDB_DESCRIPTION, &if_description);
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_option_register(&idb_block, OPT_IDB_SPEED, &if_speed);
|
|
|
|
wtap_opttype_option_register(&idb_block, OPT_IDB_TSRESOL, &if_tsresol);
|
|
|
|
wtap_opttype_option_register(&idb_block, OPT_IDB_FILTER, &if_filter);
|
|
|
|
wtap_opttype_option_register(&idb_block, OPT_IDB_OS, &if_os);
|
|
|
|
wtap_opttype_option_register(&idb_block, OPT_IDB_FCSLEN, &if_fcslen);
|
2018-08-11 02:08:40 +00:00
|
|
|
wtap_opttype_option_register(&idb_block, OPT_IDB_HARDWARE, &if_hardware);
|
2016-07-14 23:01:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register the NRB and the options that can appear in it.
|
|
|
|
*/
|
2021-02-10 02:46:29 +00:00
|
|
|
wtap_opttype_block_register(&nrb_block);
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_option_register(&nrb_block, OPT_NS_DNSNAME, &ns_dnsname);
|
|
|
|
wtap_opttype_option_register(&nrb_block, OPT_NS_DNSIP4ADDR, &ns_dnsIP4addr);
|
|
|
|
wtap_opttype_option_register(&nrb_block, OPT_NS_DNSIP6ADDR, &ns_dnsIP6addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register the ISB and the options that can appear in it.
|
|
|
|
*/
|
2021-02-10 02:46:29 +00:00
|
|
|
wtap_opttype_block_register(&isb_block);
|
2016-07-14 23:01:57 +00:00
|
|
|
wtap_opttype_option_register(&isb_block, OPT_ISB_STARTTIME, &isb_starttime);
|
|
|
|
wtap_opttype_option_register(&isb_block, OPT_ISB_ENDTIME, &isb_endtime);
|
|
|
|
wtap_opttype_option_register(&isb_block, OPT_ISB_IFRECV, &isb_ifrecv);
|
|
|
|
wtap_opttype_option_register(&isb_block, OPT_ISB_IFDROP, &isb_ifdrop);
|
|
|
|
wtap_opttype_option_register(&isb_block, OPT_ISB_FILTERACCEPT, &isb_filteraccept);
|
|
|
|
wtap_opttype_option_register(&isb_block, OPT_ISB_OSDROP, &isb_osdrop);
|
|
|
|
wtap_opttype_option_register(&isb_block, OPT_ISB_USRDELIV, &isb_usrdeliv);
|
2018-11-17 12:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register the DSB, currently no options are defined.
|
|
|
|
*/
|
2021-02-10 02:46:29 +00:00
|
|
|
wtap_opttype_block_register(&dsb_block);
|
2021-04-29 11:23:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register EPB/SPB/PB and the options that can appear in it/them.
|
|
|
|
* NB: Simple Packet Blocks have no options.
|
|
|
|
* NB: obsolete Packet Blocks have dropcount as a mandatory member instead
|
|
|
|
* of an option.
|
|
|
|
*/
|
|
|
|
wtap_opttype_block_register(&pkt_block);
|
2021-07-12 16:41:57 +00:00
|
|
|
wtap_opttype_option_register(&pkt_block, OPT_PKT_FLAGS, &pkt_flags);
|
2021-04-29 11:23:21 +00:00
|
|
|
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);
|
2021-07-19 21:25:40 +00:00
|
|
|
wtap_opttype_option_register(&pkt_block, OPT_PKT_HASH, &pkt_hash);
|
2021-04-29 11:23:21 +00:00
|
|
|
wtap_opttype_option_register(&pkt_block, OPT_PKT_VERDICT, &pkt_verdict);
|
|
|
|
|
2022-01-13 04:42:13 +00:00
|
|
|
/*
|
|
|
|
* Register the SJEB and the (no) options that can appear in it.
|
|
|
|
*/
|
|
|
|
wtap_opttype_block_register(&journal_block);
|
|
|
|
|
2021-08-04 17:57:52 +00:00
|
|
|
/*
|
|
|
|
* Register the CB and the options that can appear in it.
|
|
|
|
*/
|
|
|
|
wtap_opttype_block_register(&cb_block);
|
|
|
|
|
2021-04-29 11:23:21 +00:00
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
memset(blocks_active, 0, sizeof(blocks_active));
|
|
|
|
#endif
|
2016-03-02 14:13:08 +00:00
|
|
|
}
|
2017-02-04 15:26:34 +00:00
|
|
|
|
|
|
|
void wtap_opttypes_cleanup(void)
|
|
|
|
{
|
2017-02-14 17:41:25 +00:00
|
|
|
guint block_type;
|
2021-04-29 11:23:21 +00:00
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
guint i;
|
|
|
|
guint cellno;
|
|
|
|
guint bitno;
|
|
|
|
guint8 mask;
|
|
|
|
#endif /* DEBUG_COUNT_REFS */
|
2017-02-14 17:41:25 +00:00
|
|
|
|
Remove the existing "custom block" mechanism:
For most file types, blocks for which we don't have a wtap_block_type_t
aren't "custom", they're just "file-type specific". Add
WTAP_BLOCK_FT_SPECIFIC_REPORT and WTAP_BLOCK_FT_SPECIFIC_EVENT block
types; the "mandatory" part of those blocks includes a
file-type-specific block type value, with specific values assigned to
specific block types (either as part of the file type's definition, or
by us if necessary).
For pcapng files, blocks for which we don't have a wtap_block_type_t are
either "local" (block type has the high-order bit set), are defined in
the current spec but aren't supported yet (which we should fix), or are
*not* defined in the current spec and are *not* "local" (in which case
whoever's using the block number should submit a pull request to the
spec to register the block type *and* give it a specification, so we can
add support). For "local" block types and for not-yet-supported
non-"local" block types, they should be handled as file-type-specific
blocks with the file-type-specific block value being the pcapng block
type code, with plugin support in the pcapng code to read *and* write
those blocks.
Move the structures for the "mandatory" parts of blocks to
wiretap/wtap_opttypes.h, right after the definition of
wtap_block_type_t.
2021-02-10 07:21:49 +00:00
|
|
|
for (block_type = (guint)WTAP_BLOCK_SECTION;
|
|
|
|
block_type < (guint)MAX_WTAP_BLOCK_TYPE_VALUE; block_type++) {
|
2017-02-14 17:41:25 +00:00
|
|
|
if (blocktype_list[block_type]) {
|
|
|
|
if (blocktype_list[block_type]->options)
|
2021-02-05 06:09:23 +00:00
|
|
|
g_hash_table_destroy(blocktype_list[block_type]->options);
|
2017-02-14 17:41:25 +00:00
|
|
|
blocktype_list[block_type] = NULL;
|
|
|
|
}
|
2017-02-04 15:26:34 +00:00
|
|
|
}
|
2021-04-29 11:23:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_COUNT_REFS
|
|
|
|
for (i = 0 ; i < block_count; i++) {
|
|
|
|
cellno = i / 8;
|
|
|
|
bitno = i % 8;
|
|
|
|
mask = 1 << bitno;
|
|
|
|
|
|
|
|
if ((blocks_active[cellno] & mask) == mask) {
|
|
|
|
wtap_debug("wtap_opttypes_cleanup: orphaned block #%d", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* DEBUG_COUNT_REFS */
|
2017-02-04 15:26:34 +00:00
|
|
|
}
|