Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
pcapng_module.h
Go to the documentation of this file.
1
8
9#ifndef __PCAP_MODULE_H__
10#define __PCAP_MODULE_H__
11
12#include <wiretap/wtap_module.h>
13
14#include "ws_symbol_export.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/*
21 * These are the officially registered block types, from the pcapng
22 * specification.
23 *
24 * XXX - Dear Sysdig People: please add your blocks to the spec!
25 */
26#define BLOCK_TYPE_SHB 0x0A0D0D0A /* Section Header Block */
27#define BLOCK_TYPE_IDB 0x00000001 /* Interface Description Block */
28#define BLOCK_TYPE_PB 0x00000002 /* Packet Block (obsolete) */
29#define BLOCK_TYPE_SPB 0x00000003 /* Simple Packet Block */
30#define BLOCK_TYPE_NRB 0x00000004 /* Name Resolution Block */
31#define BLOCK_TYPE_ISB 0x00000005 /* Interface Statistics Block */
32#define BLOCK_TYPE_EPB 0x00000006 /* Enhanced Packet Block */
33#define BLOCK_TYPE_IRIG_TS 0x00000007 /* IRIG Timestamp Block */
34#define BLOCK_TYPE_ARINC_429 0x00000008 /* ARINC 429 in AFDX Encapsulation Information Block */
35#define BLOCK_TYPE_SYSTEMD_JOURNAL_EXPORT 0x00000009 /* systemd journal entry */
36#define BLOCK_TYPE_DSB 0x0000000A /* Decryption Secrets Block */
37#define BLOCK_TYPE_HP_MIB 0x00000101 /* Hone Project Machine Info Block */
38#define BLOCK_TYPE_HP_CEB 0x00000102 /* Hone Project Connection Event Block */
39#define BLOCK_TYPE_SYSDIG_MI 0x00000201 /* Sysdig Machine Info Block */
40#define BLOCK_TYPE_SYSDIG_PL_V1 0x00000202 /* Sysdig Process List Block */
41#define BLOCK_TYPE_SYSDIG_FDL_V1 0x00000203 /* Sysdig File Descriptor List Block */
42#define BLOCK_TYPE_SYSDIG_EVENT 0x00000204 /* Sysdig Event Block */
43#define BLOCK_TYPE_SYSDIG_IL_V1 0x00000205 /* Sysdig Interface List Block */
44#define BLOCK_TYPE_SYSDIG_UL_V1 0x00000206 /* Sysdig User List Block */
45#define BLOCK_TYPE_SYSDIG_PL_V2 0x00000207 /* Sysdig Process List Block version 2 */
46#define BLOCK_TYPE_SYSDIG_EVF 0x00000208 /* Sysdig Event Block with flags */
47#define BLOCK_TYPE_SYSDIG_PL_V3 0x00000209 /* Sysdig Process List Block version 3 */
48#define BLOCK_TYPE_SYSDIG_PL_V4 0x00000210 /* Sysdig Process List Block version 4 */
49#define BLOCK_TYPE_SYSDIG_PL_V5 0x00000211 /* Sysdig Process List Block version 5 */
50#define BLOCK_TYPE_SYSDIG_PL_V6 0x00000212 /* Sysdig Process List Block version 6 */
51#define BLOCK_TYPE_SYSDIG_PL_V7 0x00000213 /* Sysdig Process List Block version 7 */
52#define BLOCK_TYPE_SYSDIG_PL_V8 0x00000214 /* Sysdig Process List Block version 8 */
53#define BLOCK_TYPE_SYSDIG_PL_V9 0x00000215 /* Sysdig Process List Block version 9 */
54#define BLOCK_TYPE_SYSDIG_EVENT_V2 0x00000216 /* Sysdig Event Block version 2 */
55#define BLOCK_TYPE_SYSDIG_EVF_V2 0x00000217 /* Sysdig Event Block with flags version 2 */
56#define BLOCK_TYPE_SYSDIG_FDL_V2 0x00000218 /* Sysdig File Descriptor List Block */
57#define BLOCK_TYPE_SYSDIG_IL_V2 0x00000219 /* Sysdig Interface List Block version 2 */
58#define BLOCK_TYPE_SYSDIG_UL_V2 0x00000220 /* Sysdig User List Block version 2 */
59#define BLOCK_TYPE_SYSDIG_EVENT_V2_LARGE 0x00000221 /* Sysdig Event Block version 2 with large payload */
60#define BLOCK_TYPE_SYSDIG_EVF_V2_LARGE 0x00000222 /* Sysdig Event Block with flags version 2 with large payload */
61#define BLOCK_TYPE_CB_COPY 0x00000BAD /* Custom Block which can be copied */
62#define BLOCK_TYPE_CB_NO_COPY 0x40000BAD /* Custom Block which should not be copied */
63#define BLOCK_TYPE_LEGACY_DPIB 0x80000001 /* Historically, Apple used this code for Darwin Process Info Block. */
64
65/*
66 * The Wireshark Foundation's Private Enterprise Number, used for Custom
67 * Blocks and Custom Options defined by Wireshark, and the Block Entry
68 * Types of Wireshark Custom Blocks; see
69 * https://wiki.wireshark.org/Development/PcapngCustom for the format.
70 * Entry type numbers must never be reused for something else. Entry
71 * types 1 (File Preferences) and 2 (Decryption Key) are reserved by
72 * that page but not implemented.
73 */
74#define PEN_WIRESHARK 32622
75#define WIRESHARK_CB_ENTRY_PROCESS_INFORMATION 3 /* Process Information Block body */
76
77/*
78 * Falco libs meta event blocks (process list, file descriptor list, etc.)
79 * can be very large, and a process list from a busy host can exceed
80 * MAX_BLOCK_SIZE. Allow up to 1 GiB for those block types.
81 */
82#define MAX_FALCO_META_BLOCK_SIZE (1024U * 1024U * 1024U)
83
84/* TODO: the following are not yet well defined in the draft spec,
85 * and do not yet have block type values assigned to them:
86 * Alternative Packet Blocks
87 * Compression Block
88 * Encryption Block
89 * Fixed Length Block
90 * Directory Block
91 * Traffic Statistics and Monitoring Blocks
92 * Event/Security Block
93 */
94
98typedef struct wtapng_block_s {
99 uint32_t type;
100 bool internal;
101 wtap_block_t block;
104
105
106/*
107 * XXX - there needs to be a more general way to implement the Netflix
108 * BBLog blocks and options.
109 */
122
123/*
124 * Reader and writer routines for pcapng block types.
125 */
126typedef bool (*block_reader)(wtap* wth, FILE_T fh, uint32_t block_type,
127 uint32_t block_content_length,
128 section_info_t* section_info,
129 wtapng_block_t *wblock,
130 int *err, char **err_info);
131typedef bool (*block_writer)(wtap_dumper *wdh, const wtap_rec *rec,
132 int *err, char **err_info);
133typedef bool (*block_processor)(wtap* wth, section_info_t* section_info _U_,
134 wtapng_block_t* wblock);
135
136
141 unsigned type;
142 block_reader reader;
143 block_processor processor;
144 block_writer writer;
145 bool internal;
146 GHashTable *option_handlers;
148
154WS_DLL_PUBLIC
156
157/*
158 * Handler routines for pcapng option type.
159 */
160typedef bool (*option_parser)(wtap_block_t block, bool byte_swapped,
161 unsigned option_length,
162 const uint8_t *option_content,
163 int *err, char **err_info);
164typedef uint32_t (*option_sizer)(unsigned option_id, wtap_optval_t *optval);
165typedef bool (*option_writer)(wtap_dumper *wdh, unsigned option_id,
166 wtap_optval_t *optval, int *err);
167
172WS_DLL_PUBLIC
173GHashTable *pcapng_create_option_handler_table(void);
174
185WS_DLL_PUBLIC
186void register_pcapng_option_handler(unsigned block_type, unsigned option_code,
187 option_parser parser,
188 option_sizer sizer,
189 option_writer writer);
190
210
224WS_DLL_PUBLIC
225bool pcapng_process_options(FILE_T fh, wtapng_block_t *wblock,
226 section_info_t *section_info,
227 unsigned opt_cont_buf_len,
228 bool (*process_option)(wtapng_block_t *,
230 uint16_t, uint16_t,
231 const uint8_t *,
232 int *, char **),
233 pcapng_opt_byte_order_e byte_order,
234 int *err, char **err_info);
235
245WS_DLL_PUBLIC
247 uint16_t option_code, uint16_t option_length,
248 const uint8_t *option_content);
249
260WS_DLL_PUBLIC
262 section_info_t *section_info,
263 pcapng_opt_byte_order_e byte_order,
264 uint16_t option_code, uint16_t option_length,
265 const uint8_t *option_content);
266
277WS_DLL_PUBLIC
279 section_info_t *section_info,
280 pcapng_opt_byte_order_e byte_order,
281 uint16_t option_code, uint16_t option_length,
282 const uint8_t *option_content);
283
294WS_DLL_PUBLIC
296 section_info_t *section_info,
297 pcapng_opt_byte_order_e byte_order,
298 uint16_t option_code, uint16_t option_length,
299 const uint8_t *option_content);
300
311WS_DLL_PUBLIC
313 section_info_t *section_info,
314 pcapng_opt_byte_order_e byte_order,
315 uint16_t option_code, uint16_t option_length,
316 const uint8_t *option_content);
317
326WS_DLL_PUBLIC
327void pcapng_process_string_option(wtapng_block_t *wblock, uint16_t option_code,
328 uint16_t option_length, const uint8_t *option_content);
329
338WS_DLL_PUBLIC
339void pcapng_process_bytes_option(wtapng_block_t *wblock, uint16_t option_code,
340 uint16_t option_length, const uint8_t *option_content);
341
342typedef uint32_t (*compute_option_size_func)(wtap_block_t, unsigned, wtap_opttype_e, wtap_optval_t*);
343
348 uint32_t size;
349 compute_option_size_func compute_option_size;
351
359WS_DLL_PUBLIC
360uint32_t pcapng_compute_options_size(wtap_block_t block, compute_option_size_func compute_option_size);
361
362typedef bool (*write_option_func)(wtap_dumper *wdh, wtap_block_t block,
363 unsigned option_id,
364 wtap_opttype_e option_type,
365 wtap_optval_t *optval,
366 int *err, char **err_info);
367
379WS_DLL_PUBLIC
381 wtap_block_t block, write_option_func write_option,
382 int *err, char **err_info);
383
384/*
385 * Handler routines for pcapng custom blocks with an enterprise number.
386 *
387 * The parser is called after the block header and the PEN have been
388 * read, with wblock->block a WTAP_BLOCK_CUSTOM block and wblock->rec
389 * set up as a custom block record whose length is the length of the
390 * rest of the block; it reads that data. If the block is to be
391 * processed internally, e.g. added to a per-file table, rather than
392 * returned as a record, the parser sets wblock->internal and leaves
393 * the block to be processed in wblock->block; the processor for the
394 * custom block type is then called with it.
395 */
396typedef bool (*custom_option_parser)(FILE_T fh, section_info_t* section_info,
397 wtapng_block_t* wblock,
398 int* err, char** err_info);
399typedef bool (*custom_option_processor)(wtapng_block_t* wblock,
400 section_info_t* section_info, uint16_t option_code,
401 const uint8_t* value, uint16_t length);
402
407 custom_option_parser parser;
408 custom_option_processor processor;
409 block_writer writer;
411
412/*
413 * Register a handler for a pcapng custom block with an enterprise number.
414 */
421WS_DLL_PUBLIC
423
424/*
425 * Helper routines for modules.
426 */
427
428/*
429 * Write block header.
430 */
440WS_DLL_PUBLIC
441bool pcapng_write_block_header(wtap_dumper *wdh, uint32_t block_type,
442 uint32_t block_content_length, int *err);
443
444/*
445 * Write padding after a chunk of data.
446 */
455static inline bool
456pcapng_write_padding(wtap_dumper *wdh, size_t pad, int *err)
457{
458 if (pad != 0) {
459 const uint32_t zero_pad = 0;
460 if (!wtap_dump_file_write(wdh, &zero_pad, pad, err))
461 return false;
462 }
463
464 return true;
465}
466
467/*
468 * Write block footer.
469 */
478WS_DLL_PUBLIC
479bool pcapng_write_block_footer(wtap_dumper *wdh, uint32_t block_content_length,
480 int *err);
481
486typedef struct {
487 void *(*provision)(void);
488 GDestroyNotify free;
490
491/*
492 * Find custom block information from a section_info_t; add a
493 * newly-created one and return it if none is found.
494 */
503WS_DLL_PUBLIC
505 uint32_t pen,
506 const section_info_funcs_t *funcs);
507
517WS_DLL_PUBLIC
519 uint32_t block_type,
520 const section_info_funcs_t *funcs);
521
522#ifdef __cplusplus
523}
524#endif /* __cplusplus */
525
526#endif /* __PCAP_MODULE_H__ */
WS_DLL_PUBLIC void pcapng_process_uint64_option(wtapng_block_t *wblock, section_info_t *section_info, pcapng_opt_byte_order_e byte_order, uint16_t option_code, uint16_t option_length, const uint8_t *option_content)
Process a 64-bit unsigned integer option in a PCAP-NG block.
Definition pcapng.c:677
WS_DLL_PUBLIC void * pcapng_get_lb_section_info_data(section_info_t *section_info, uint32_t block_type, const section_info_funcs_t *funcs)
Find local block information from a section_info_t; add a newly-created one and return it if none is ...
Definition pcapng.c:503
WS_DLL_PUBLIC bool pcapng_write_block_footer(wtap_dumper *wdh, uint32_t block_content_length, int *err)
Writes a block footer for a PCAPNG file.
Definition pcapng.c:6353
WS_DLL_PUBLIC void pcapng_process_timestamp_option(wtapng_block_t *wblock, section_info_t *section_info, pcapng_opt_byte_order_e byte_order, uint16_t option_code, uint16_t option_length, const uint8_t *option_content)
Process a timestamp option in a PCAPng block.
Definition pcapng.c:618
WS_DLL_PUBLIC uint32_t pcapng_compute_options_size(wtap_block_t block, compute_option_size_func compute_option_size)
Computes the total size of all options in a PCAPNG block.
Definition pcapng.c:4201
WS_DLL_PUBLIC void pcapng_process_uint32_option(wtapng_block_t *wblock, section_info_t *section_info, pcapng_opt_byte_order_e byte_order, uint16_t option_code, uint16_t option_length, const uint8_t *option_content)
Process a 32-bit unsigned integer option in a PCAPNG block.
Definition pcapng.c:561
WS_DLL_PUBLIC void * pcapng_get_cb_section_info_data(section_info_t *section_info, uint32_t pen, const section_info_funcs_t *funcs)
Find local block information from a section_info_t; add a newly-created one and return it if none is ...
Definition pcapng.c:450
WS_DLL_PUBLIC void pcapng_process_uint8_option(wtapng_block_t *wblock, uint16_t option_code, uint16_t option_length, const uint8_t *option_content)
Helper routines to process options with types used in more than one block type.
Definition pcapng.c:546
WS_DLL_PUBLIC void pcapng_process_int64_option(wtapng_block_t *wblock, section_info_t *section_info, pcapng_opt_byte_order_e byte_order, uint16_t option_code, uint16_t option_length, const uint8_t *option_content)
Process a 64-bit integer option in a PCAPNG block.
Definition pcapng.c:729
struct wtapng_block_s wtapng_block_t
Transient container used to pass a parsed pcapng block between internal read functions.
WS_DLL_PUBLIC void register_pcapng_option_handler(unsigned block_type, unsigned option_code, option_parser parser, option_sizer sizer, option_writer writer)
Register a handler for a pcapng option code for a particular block type.
Definition pcapng.c:386
pcapng_opt_byte_order_e
Byte order of the options within a block.
Definition pcapng_module.h:205
@ OPT_BIG_ENDIAN
Definition pcapng_module.h:207
@ OPT_LITTLE_ENDIAN
Definition pcapng_module.h:208
@ OPT_SECTION_BYTE_ORDER
Definition pcapng_module.h:206
WS_DLL_PUBLIC void register_pcapng_block_type_information(pcapng_block_type_information_t *handler)
Register a handler for a pcapng block type.
Definition pcapng.c:259
WS_DLL_PUBLIC void pcapng_process_string_option(wtapng_block_t *wblock, uint16_t option_code, uint16_t option_length, const uint8_t *option_content)
Process a string option in a PCAPNG block.
Definition pcapng.c:781
WS_DLL_PUBLIC void pcapng_process_bytes_option(wtapng_block_t *wblock, uint16_t option_code, uint16_t option_length, const uint8_t *option_content)
Processes a bytes option in a PCAPng block.
Definition pcapng.c:802
WS_DLL_PUBLIC bool pcapng_write_block_header(wtap_dumper *wdh, uint32_t block_type, uint32_t block_content_length, int *err)
Write a pcapng block header.
Definition pcapng.c:6333
WS_DLL_PUBLIC GHashTable * pcapng_create_option_handler_table(void)
Create a table of handlers for pcapng option codes.
Definition pcapng.c:358
WS_DLL_PUBLIC bool pcapng_process_options(FILE_T fh, wtapng_block_t *wblock, section_info_t *section_info, unsigned opt_cont_buf_len, bool(*process_option)(wtapng_block_t *, section_info_t *, uint16_t, uint16_t, const uint8_t *, int *, char **), pcapng_opt_byte_order_e byte_order, int *err, char **err_info)
Process the options section of a block.
Definition pcapng.c:942
WS_DLL_PUBLIC void register_pcapng_custom_block_enterprise_handler(unsigned enterprise_number, pcapng_custom_block_enterprise_handler_t const *handler)
Register a handler for a pcapng custom block with an enterprise number.
Definition pcapng.c:2965
WS_DLL_PUBLIC bool pcapng_write_options(wtap_dumper *wdh, pcapng_opt_byte_order_e byte_order, wtap_block_t block, write_option_func write_option, int *err, char **err_info)
Writes options to a pcapng file.
Definition pcapng.c:4867
Accumulator and callback used to compute the total serialized size of a block's options.
Definition pcapng_module.h:347
compute_option_size_func compute_option_size
Definition pcapng_module.h:349
uint32_t size
Definition pcapng_module.h:348
Dispatch table entry registering the reader, processor, and writer callbacks for a single pcapng bloc...
Definition pcapng_module.h:140
block_reader reader
Definition pcapng_module.h:142
block_writer writer
Definition pcapng_module.h:144
GHashTable * option_handlers
Definition pcapng_module.h:146
bool internal
Definition pcapng_module.h:145
block_processor processor
Definition pcapng_module.h:143
unsigned type
Definition pcapng_module.h:141
Dispatch table for handling a vendor-specific pcapng custom block identified by a Private Enterprise ...
Definition pcapng_module.h:406
custom_option_processor processor
Definition pcapng_module.h:408
block_writer writer
Definition pcapng_module.h:409
custom_option_parser parser
Definition pcapng_module.h:407
Holds the allocation and deallocation callbacks for custom or local block data associated with a sect...
Definition pcapng_module.h:486
GDestroyNotify free
Definition pcapng_module.h:488
Per-section state accumulated while reading a pcapng Section Header Block and its contents.
Definition pcapng_module.h:113
uint16_t version_major
Definition pcapng_module.h:115
int64_t shb_off
Definition pcapng_module.h:118
uint16_t version_minor
Definition pcapng_module.h:116
GHashTable * local_block_data
Definition pcapng_module.h:120
GHashTable * custom_block_data
Definition pcapng_module.h:119
GArray * interfaces
Definition pcapng_module.h:117
bool byte_swapped
Definition pcapng_module.h:114
Wiretap dumper handle and associated state.
Definition wtap_module.h:166
Represents a single capture record read from or written to a capture file, regardless of record type.
Definition wtap.h:1613
Definition wtap_module.h:58
Transient container used to pass a parsed pcapng block between internal read functions.
Definition pcapng_module.h:98
wtap_block_t block
Definition pcapng_module.h:101
uint32_t type
Definition pcapng_module.h:99
bool internal
Definition pcapng_module.h:100
wtap_rec * rec
Definition pcapng_module.h:102
Discriminated union holding the value of any Wiretap option type.
Definition wtap_opttypes.h:559
wtap_opttype_e
Data types for option values stored within a wtap block.
Definition wtap_opttypes.h:411