Introduction

I have a project to add support for two new block types to Wireshark. This doesn't seem to be documented anywhere and so I'm hoping that my notes here may help someone in the future.

This is work in progress and so the notes here are not complete. Also, I'm using this as a notepad and I may make mistakes which I'll correct later. If you notice mistakes, please feel free to update this page.

Objective

The objective of the project is to add Wireshark support for the display, filtering, etc. of text log data (machine data). The data is presented to Wireshark in a PCAP-NG file that contains two new block types:

The data in the TSDB is used to define heading fields i.e. the heading fields aren't predefined as they typically are in dissectors, but rather defined at file load time (and cleared when the file is closed)

This block is analogous to the Interface Descriptor Block found in a network packet capture

TRB - Text Record Block that contains the log record data

The initial data being used is Apache HTTPD Common format log records, but I'm designing the solution so that any format of log data can be supported. I've started with the Apache HTTPD log data as it is a fairly simple format; space separated variables in fixed columns.

Test PCAP-NG Generation

Of course, the above raises the question, "What creates the PCAP-NG file with the new blocks?". At this time I'm using the Babel function that comes with TribeLab Workbench. The project that should follow this one will be to write a Wiretap reader for log files.

An XML file describes the format of the log file. The XML is used to generate the TSDB, and some elements of it are used to help parse the log records to form TRBs.

See Appendix A below for an example of the XML file

See Appendix B below for a sample PCAP-NG file

NB: Although I'm using Babel to generate the file, anyone can use any tool to generate a suitable file. There is nothing proprietary about the TSDB or TRB formats.

Other points

I'm trying to add this support completely through the plugin framework, and avoid having to make any changes to core Wireshark code. There is an API to add support for new block types via plugins, but I think this may the first project to use this functionality; there could be bugs and it may not be complete.

Even though the code I am writing has nothing to do with network packets, Wireshark still refers to the list of events in the top pane as the Packet List, and various structures that we need to use refer to all events as packets, most notably the wtap_pkthdr structure.

TSDB Handling

The TSDB defines the type and meaning of fields. Wireshark should not generate a "Packet List" entry for this block. Later, I refer to this type of block as a silent block. If you want to add support for a new silent block to your dissector, think of the TSDB as a template.

The TSDB defines each field through TLVs (type-length-value). The types map to native Wireshark field types with two important exceptions.

Field Type Encoding

The encoded integer values for the field types are not the same as the integer values used within Wireshark. This is because the Wireshark types are generated via an enumerated list. A change to the list could change the enumerated values. If we used these values within the TSDB, we would have compatibility problems. Wireshark field tyoe values start at 0. The TSDB field type values start at 1001.

The Wireshark field types values can be found in epan/ftypes/ftype.h. The mapping of TSDB values to Wireshark field values is in the array babeltowsft.

Special Cases

We need to deal with two special cases. A log record could contain many date-time values. We need to indicate which value should be used in the Wireshark packet list. This is done through the EVENT_DATETIME field type.

A log often mixes IPv4 and IPv6 addresses in the same column; both Apache HTTPD and Microsoft IIS do this. To accommodate this we have a TS_FT_IPvx field type.

The Silent Block

I'll refer to a TSDB-style block as a silent block. This type of block carries information but doesn't generate an entry in the packet list; similar to the Interface Descriptor Block (IDB). This is the simplest kind of block to handle. There are two steps:

Define a function that processes the block data - referred to as read block function

Block for Dissection

Encapsulation

In Wireshark terms, the content of a packet block (SPB, EPB or TRB) is encapsulated in a "frame" format. The encapsulation is specified at three levels:

File level - used to populate the file_encap field of a wth structure

Interface level - used to populate the wtap_encap field of a wtapng_if_descr_mandatory_t structure

Per Packet - used to populate the pkt_encap field of a wtap_pkthdr structure

There are 16 available user values (WTAP_ENCAP_USER0 to WTAP_ENCAP_USER15) and I use WTAP_ENCAP_USER11 for the TRBs.

Timestamp Precision

The timestamp precision can be specified at three levels:

File level - used to populate the file_tsprec field of a wth structure

Interface level - used to populate the tsprecision field of a wtapng_if_descr_mandatory_t structure

Per Packet - used to populate the pkt_tsprec field of a wtap_pkthdr structure

wtap_pkthdr structure

In the tsdb_read_block(...) function above, I don't populate any of the fields in the wtap_pkthdr structure. That's OK for a silent block but we need Wireshark to create a dissection chain (?) for the TRBs, i.e. a block that we wish to dissect.

What we need is for the content of the block to be treated as a new protocol, in the same way as the content of an EPB is becomes a Frame.

The wtap_pkthdr structure fields I believe have to be completed by a block read function are:

nstime_t ts - the timestamp for the event you wish to be displayed in the packet list

guint32 caplen - the length of the payload in your block

guint32 len - the length of the original data - unless you are going to get very flash, this will be the same as the caplen

int pkt_encap - this should be set to a value from the WTAP_ENCAP_xxxx list of definitions in wiretap/wtap.h - WTAP_ENCAP_USER11 in the case of the TRB

int pkt_tsprec - this should be set to a value from the WTAP_TSPREC_xxxx list of definitions in wiretap/wtap.h - WTAP_TSPREC_USEC in the case of the TRB