aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-02-09 23:21:49 -0800
committerGuy Harris <gharris@sonic.net>2021-02-10 09:05:41 +0000
commita1e03ea89e0bad27772025dc9ecd87cc7a672376 (patch)
tree8723e835728825222ddfb96ba751be87ba20ab40 /wiretap
parente92620454ee3f671a3220188bec05507ddecefd4 (diff)
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.
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/wtap.h55
-rw-r--r--wiretap/wtap_opttypes.c46
-rw-r--r--wiretap/wtap_opttypes.h76
3 files changed, 78 insertions, 99 deletions
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 0de1569072..30b8535ca6 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1466,61 +1466,6 @@ typedef struct {
#define WTAP_HAS_INT_QUEUE 0x00000080 /**< interface queue */
#define WTAP_HAS_VERDICT 0x00000100 /**< packet verdict */
-/**
- * Holds the required data from pcapng:s Section Header block(SHB).
- */
-typedef struct wtapng_section_mandatory_s {
- guint64 section_length; /**< 64-bit value specifying the length in bytes of the
- * following section.
- * Section Length equal -1 (0xFFFFFFFFFFFFFFFF) means
- * that the size of the section is not specified
- * Note: if writing to a new file, this length will
- * be invalid if anything changes, such as the other
- * members of this struct, or the packets written.
- */
-} wtapng_mandatory_section_t;
-
-/** struct holding the information to build IDB:s
- * the interface_data array holds an array of wtap_block_t
- * represending IDB of one per interface.
- */
-typedef struct wtapng_iface_descriptions_s {
- GArray *interface_data;
-} wtapng_iface_descriptions_t;
-
-/**
- * Interface description data
- */
-typedef struct wtapng_if_descr_mandatory_s {
- int wtap_encap; /**< link_type translated to wtap_encap */
- guint64 time_units_per_second;
- int tsprecision; /**< WTAP_TSPREC_ value for this interface */
-
- guint32 snap_len;
-
- guint8 num_stat_entries;
- GArray *interface_statistics; /**< An array holding the interface statistics from
- * pcapng ISB:s or equivalent(?)*/
-} wtapng_if_descr_mandatory_t;
-
-/**
- * Decryption Secrets Block data.
- */
-typedef struct wtapng_dsb_mandatory_s {
- guint32 secrets_type; /** Type of secrets stored in data (see secrets-types.h) */
- guint32 secrets_len; /** Length of the secrets data in bytes */
- guint8 *secrets_data; /** Buffer of secrets (not NUL-terminated) */
-} wtapng_dsb_mandatory_t;
-
-/**
- * Holds the required data for pcapng Interface Statistics Block (ISB).
- */
-typedef struct wtapng_if_stats_mandatory_s {
- guint32 interface_id;
- guint32 ts_high;
- guint32 ts_low;
-} wtapng_if_stats_mandatory_t;
-
#ifndef MAXNAMELEN
#define MAXNAMELEN 64 /* max name length (hostname and port name) */
#endif
diff --git a/wiretap/wtap_opttypes.c b/wiretap/wtap_opttypes.c
index 07f39e1a6d..981533578c 100644
--- a/wiretap/wtap_opttypes.c
+++ b/wiretap/wtap_opttypes.c
@@ -59,13 +59,8 @@ struct wtap_block
GArray* options;
};
-#define MAX_WTAP_BLOCK_CUSTOM 10
-#define MAX_WTAP_BLOCK_TYPE_VALUE (WTAP_BLOCK_END_OF_LIST+MAX_WTAP_BLOCK_CUSTOM)
-
/* Keep track of wtap_blocktype_t's via their id number */
static wtap_blocktype_t* blocktype_list[MAX_WTAP_BLOCK_TYPE_VALUE];
-static guint num_custom_blocks;
-static wtap_blocktype_t custom_blocktype_list[MAX_WTAP_BLOCK_CUSTOM];
static void wtap_opttype_block_register(wtap_blocktype_t *blocktype)
{
@@ -79,8 +74,10 @@ static void wtap_opttype_block_register(wtap_blocktype_t *blocktype)
block_type = blocktype->block_type;
+ block_type = blocktype->block_type;
+
/* Check input */
- g_assert(block_type < WTAP_BLOCK_END_OF_LIST);
+ g_assert(block_type < MAX_WTAP_BLOCK_TYPE_VALUE);
/* Don't re-register. */
g_assert(blocktype_list[block_type] == NULL);
@@ -104,33 +101,6 @@ static void wtap_opttype_block_register(wtap_blocktype_t *blocktype)
blocktype_list[block_type] = blocktype;
}
-int wtap_opttype_register_custom_block_type(const char* name, const char* description, wtap_block_create_func create,
- wtap_mand_free_func free_mand, wtap_mand_copy_func copy_mand)
-{
- int block_type;
-
- /* Ensure valid data/functions for required fields */
- g_assert(name);
- g_assert(description);
- g_assert(create);
-
- /* This shouldn't happen, so flag it for fixing */
- g_assert(num_custom_blocks < MAX_WTAP_BLOCK_CUSTOM);
-
- block_type = (wtap_block_type_t)(WTAP_BLOCK_END_OF_LIST+num_custom_blocks);
-
- custom_blocktype_list[num_custom_blocks].block_type = (wtap_block_type_t)block_type;
- custom_blocktype_list[num_custom_blocks].name = name;
- custom_blocktype_list[num_custom_blocks].description = description;
- custom_blocktype_list[num_custom_blocks].create = create;
- custom_blocktype_list[num_custom_blocks].free_mand = free_mand;
- custom_blocktype_list[num_custom_blocks].copy_mand = copy_mand;
- blocktype_list[block_type] = &custom_blocktype_list[num_custom_blocks];
-
- num_custom_blocks++;
- return block_type;
-}
-
static void wtap_opttype_option_register(wtap_blocktype_t *blocktype, guint opttype, const wtap_opttype_t *option)
{
g_hash_table_insert(blocktype->options, GUINT_TO_POINTER(opttype),
@@ -186,7 +156,7 @@ wtap_block_t wtap_block_create(wtap_block_type_t block_type)
{
wtap_block_t block;
- if (block_type >= (wtap_block_type_t)(WTAP_BLOCK_END_OF_LIST+num_custom_blocks))
+ if (block_type >= MAX_WTAP_BLOCK_TYPE_VALUE)
return NULL;
block = g_new(struct wtap_block, 1);
@@ -1229,11 +1199,6 @@ void wtap_opttypes_initialize(void)
0
};
- /* Initialize the custom block array. This is for future proofing
- "outside registered" block types (for NULL checking) */
- memset(blocktype_list, 0, MAX_WTAP_BLOCK_TYPE_VALUE*sizeof(wtap_blocktype_t*));
- num_custom_blocks = 0;
-
/*
* Register the SHB and the options that can appear in it.
*/
@@ -1285,7 +1250,8 @@ void wtap_opttypes_cleanup(void)
{
guint block_type;
- for (block_type = 0; block_type < (WTAP_BLOCK_END_OF_LIST+num_custom_blocks); block_type++) {
+ for (block_type = (guint)WTAP_BLOCK_SECTION;
+ block_type < (guint)MAX_WTAP_BLOCK_TYPE_VALUE; block_type++) {
if (blocktype_list[block_type]) {
if (blocktype_list[block_type]->options)
g_hash_table_destroy(blocktype_list[block_type]->options);
diff --git a/wiretap/wtap_opttypes.h b/wiretap/wtap_opttypes.h
index 87447643ba..1334c76510 100644
--- a/wiretap/wtap_opttypes.h
+++ b/wiretap/wtap_opttypes.h
@@ -140,9 +140,73 @@ typedef enum {
WTAP_BLOCK_IF_STATISTICS,
WTAP_BLOCK_DECRYPTION_SECRETS,
WTAP_BLOCK_PACKET,
- WTAP_BLOCK_END_OF_LIST
+ WTAP_BLOCK_FT_SPECIFIC_REPORT,
+ WTAP_BLOCK_FT_SPECIFIC_EVENT,
+ MAX_WTAP_BLOCK_TYPE_VALUE
} wtap_block_type_t;
+/**
+ * Holds the required data from a WTAP_BLOCK_SECTION.
+ */
+typedef struct wtapng_section_mandatory_s {
+ guint64 section_length; /**< 64-bit value specifying the length in bytes of the
+ * following section.
+ * Section Length equal -1 (0xFFFFFFFFFFFFFFFF) means
+ * that the size of the section is not specified
+ * Note: if writing to a new file, this length will
+ * be invalid if anything changes, such as the other
+ * members of this struct, or the packets written.
+ */
+} wtapng_mandatory_section_t;
+
+/** struct holding the information to build an WTAP_BLOCK_IF_DESCRIPTION.
+ * the interface_data array holds an array of wtap_block_t
+ * representing interfacs, one per interface.
+ */
+typedef struct wtapng_iface_descriptions_s {
+ GArray *interface_data;
+} wtapng_iface_descriptions_t;
+
+/**
+ * Holds the required data from a WTAP_BLOCK_IF_DESCRIPTION.
+ */
+typedef struct wtapng_if_descr_mandatory_s {
+ int wtap_encap; /**< link_type translated to wtap_encap */
+ guint64 time_units_per_second;
+ int tsprecision; /**< WTAP_TSPREC_ value for this interface */
+
+ guint32 snap_len;
+
+ guint8 num_stat_entries;
+ GArray *interface_statistics; /**< An array holding the interface statistics from
+ * pcapng ISB:s or equivalent(?)*/
+} wtapng_if_descr_mandatory_t;
+
+/**
+ * Holds the required data from a WTAP_BLOCK_IF_STATISTICS.
+ */
+typedef struct wtapng_if_stats_mandatory_s {
+ guint32 interface_id;
+ guint32 ts_high;
+ guint32 ts_low;
+} wtapng_if_stats_mandatory_t;
+
+/**
+ * Holds the required data from a WTAP_BLOCK_DECRYPTION_SECRETS.
+ */
+typedef struct wtapng_dsb_mandatory_s {
+ guint32 secrets_type; /** Type of secrets stored in data (see secrets-types.h) */
+ guint32 secrets_len; /** Length of the secrets data in bytes */
+ guint8 *secrets_data; /** Buffer of secrets (not NUL-terminated) */
+} wtapng_dsb_mandatory_t;
+
+/**
+ * Holds the required data from a WTAP_BLOCK_FT_SPECIFIC_REPORT.
+ */
+typedef struct wtapng_ft_specific_mandatory_s {
+ guint record_type; /* the type of record this is - file type-specific value */
+} wtapng_ft_specific_mandatory_t;
+
/* Currently supported option types */
typedef enum {
WTAP_OPTTYPE_UINT8,
@@ -259,6 +323,13 @@ WS_DLL_PUBLIC void wtap_block_array_free(GArray* block_array);
*/
WS_DLL_PUBLIC wtap_block_type_t wtap_block_get_type(wtap_block_t block);
+/** Provide type of a block
+ *
+ * @param[in] block Block from which to retrieve mandatory data
+ * @return Block type.
+ */
+WS_DLL_PUBLIC wtap_block_type_t wtap_block_get_type(wtap_block_t block);
+
/** Provide mandatory data of a block
*
* @param[in] block Block from which to retrieve mandatory data
@@ -571,9 +642,6 @@ WS_DLL_PUBLIC wtap_block_t wtap_block_make_copy(wtap_block_t block);
typedef void (*wtap_block_foreach_func)(wtap_block_t block, guint option_id, wtap_opttype_e option_type, wtap_optval_t *option, void *user_data);
WS_DLL_PUBLIC void wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data);
-WS_DLL_PUBLIC int wtap_opttype_register_custom_block_type(const char* name, const char* description, wtap_block_create_func create,
- wtap_mand_free_func free_mand, wtap_mand_copy_func copy_mand);
-
/** Cleanup the internal structures
*/
WS_DLL_PUBLIC void wtap_opttypes_cleanup(void);