Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

Wirdigen turns a declarative description of a network protocol into a Wireshark dissector.

You write a Protocol Description, a YAML file that names the protocol and lays out the Fields of its payload. Wirdigen checks it, reports any mistake with a precise location, and generates a Lua Dissector for Wireshark 4.4 and later.

name: demo
fields:
  - { name: id, type: uint8 }
  - { name: length, type: uint16 }

By convention the file is named <protocol>.wirdigen.yaml, here demo.wirdigen.yaml.

New to Wirdigen? The tutorial builds a complete description step by step and runs its Dissector in tshark; Installing a Dissector then puts it in Wireshark. To check first whether Wirdigen can describe your protocol, see Limits.

About this book

This book is the user guide and the reference of the Protocol Description format. Every YAML example in it is a complete description checked by Wirdigen’s CI, so it is valid unless the text says which Diagnostic it shows. The Glossary defines the terms it uses.

Wirdigen v1 is being written: chapters shown greyed out in the table of contents are not written yet. The book at https://cerclique.github.io/wirdigen/ follows the latest release; the one at https://cerclique.github.io/wirdigen/dev/ follows the development branch.

Tutorial: UDP telemetry

This tutorial writes the Protocol Description of a small protocol from scratch, generates its Dissector and watches it dissect real packets in tshark, Wireshark’s command-line twin. It takes about fifteen minutes.

You need the wirdigen command (see the README to install it) and, for the last part, Wireshark 4.4 or later with its tshark and text2pcap tools (see Installing a Dissector). The finished description and its sample packets are in the repository under examples/telemetry/.

The protocol

Sensor Telemetry is an invented protocol. A sensor node measures one quantity, temperature, humidity or pressure, and sends each reading in a UDP datagram of its own to port 47100. A datagram is 14 bytes, every number big-endian:

BytesFieldMeaning
1versionProtocol version, 1
2nodeIdentifier of the sending node
4seqCounts the node’s datagrams from 1
1sensor1 temperature, 2 humidity, 3 pressure
1statusFlags: low battery (top bit), calibrated (next bit), a 2-bit priority, 4 unused bits
4readingThe measurement, an IEEE 754 single-precision float
1batteryCharge left, in percent

A first temperature reading of 21.5 from node 0x00a1 looks like this on the wire:

01 00 a1 00 00 00 01 01 50 41 ac 00 00 57

A first description

Create telemetry.wirdigen.yaml with the protocol’s name and its first three Fields:

name: telemetry
fields:
  - { name: version, type: uint8 }
  - { name: node, type: uint16 }
  - { name: seq, type: uint32 }

name: is the protocol’s filter name in Wireshark, so it is lowercase. fields: lists the payload’s Fields in the order they come, each with a name: and a type: there are no offsets to compute. Fields are big-endian unless endian: says otherwise, which is what this protocol needs.

Generate the Dissector:

wirdigen generate telemetry.wirdigen.yaml

The command prints nothing on success and writes telemetry.lua next to the description. This is already a working Dissector, showing the first three Fields of every packet. The rest of the tutorial fills in the other Fields and the details that make it pleasant to read.

Labels for values

A raw sensor of 2 means little to a reader of the capture. values: gives each value a label. Here the labels are declared once as an Enum, under the top-level enums:, so other Fields could share them later:

name: telemetry
fields:
  - { name: version, type: uint8 }
  - { name: node, type: uint16, display: hex }
  - { name: seq, type: uint32 }
  - { name: sensor, type: uint8, values: Sensor }
enums:
  Sensor:
    1: Temperature
    2: Humidity
    3: Pressure

Wireshark now shows Sensor: Humidity (2), and Unknown (9) for a value without a label. A filter still matches the number: telemetry.sensor == 2. The node also gained display: hex, since node identifiers are usually written in hex. See Value mappings and Display.

Flags in a bitfield

status packs two flags and a small number into one byte. A Bitfield splits it with bits:, from the most significant bit down. Here is a first attempt:

name: telemetry
fields:
  - name: status
    type: uint8
    bits:
      - { name: low_battery, width: 1 }
      - { name: calibrated, width: 1 }
      - { name: priority, width: 2 }

wirdigen generate (or wirdigen validate, which checks without writing) refuses it, and says why:

$ wirdigen validate telemetry.wirdigen.yaml
error[mismatched-bit-widths]: these widths add up to 4 bits, but `uint8` has 8
 --> telemetry.wirdigen.yaml:5:5
  |
5 |     bits:
  |     ^^^^
  |
  = note: name every bit, or cover the gaps with `{ padding: <bits> }` entries
  = note: see https://cerclique.github.io/wirdigen/diagnostics.html#mismatched-bit-widths

error: 1 error in 1 of 1 file

Every bit must be accounted for. The four unused bits are { padding: 4 }, and the priority gets labels of its own, given inline this time since nothing else uses them:

name: telemetry
fields:
  - name: status
    type: uint8
    display: hex
    bits:
      - { name: low_battery, width: 1 }
      - { name: calibrated, width: 1 }
      - { name: priority, width: 2, values: { 0: Low, 1: Normal, 2: High, 3: Critical } }
      - { padding: 4 }

The one-bit Sub-Fields are shown as Set or Not set, each with its bits marked as Wireshark shows the flags of TCP, and can be filtered on their own: telemetry.status.low_battery == 1. See Bitfields.

The reading and the battery

The reading is a float32. The battery is a percentage, and unit: shows it after the value:

name: telemetry
fields:
  - { name: reading, type: float32 }
  - { name: battery, type: uint8, unit: "%" }

The Info column

Wireshark’s packet list sums each packet up in its Info column. info: fills it from an Info Template, with Fields named in braces:

name: telemetry
info: "{sensor} {reading} from node {node}, seq {seq}"
fields:
  - { name: node, type: uint16, display: hex }
  - { name: seq, type: uint32 }
  - { name: sensor, type: uint8, values: { 1: Temperature, 2: Humidity, 3: Pressure } }
  - { name: reading, type: float32 }

Each Field shows as in the tree: the sensor’s label, the node in hex. The first packet’s Info column reads Temperature 21.5 from node 0x00a1, seq 1. See Info column.

Claiming the port

So far the Dissector is only offered in Wireshark’s Decode As: someone has to tell Wireshark that port 47100 carries Sensor Telemetry. registration: claims the port by default:

name: telemetry
registration:
  ports:
    udp: [47100]
fields:
  - { name: version, type: uint8 }

The port also becomes a preference, telemetry.udp_ports, which a user can change without regenerating anything. See Registration.

The complete description

Put together, with a title: for the root of the protocol tree, a description: for a few Fields (Wireshark shows it as help text) and comments documenting the file:

# Sensor Telemetry, an invented protocol: the example of the book's tutorial.
#
# A sensor node sends each reading in a UDP datagram of its own to port 47100. A datagram is
# 14 bytes, big-endian:
#
#   version  node  seq  sensor  status  reading  battery
#   1        2     4    1       1       4        1
name: telemetry
title: Sensor Telemetry
registration:
  ports:
    udp: [47100]
info: "{sensor} {reading} from node {node}, seq {seq}"
fields:
  - { name: version, type: uint8 }
  - { name: node, type: uint16, display: hex, description: "Identifier of the sending node" }
  - { name: seq, type: uint32, description: "Counts the node's datagrams from 1" }
  - { name: sensor, type: uint8, values: Sensor }
  - name: status
    type: uint8
    display: hex
    bits:
      - { name: low_battery, width: 1 }
      - { name: calibrated, width: 1 }
      - { name: priority, width: 2, values: { 0: Low, 1: Normal, 2: High, 3: Critical } }
      - { padding: 4 }
  - { name: reading, type: float32 }
  - { name: battery, type: uint8, unit: "%" }
enums:
  Sensor:
    1: Temperature
    2: Humidity
    3: Pressure

Generate it again:

wirdigen generate telemetry.wirdigen.yaml

Trying it in tshark

Without a sensor at hand, build a capture from hex. Save the repository’s packets.txt next to the description: five datagrams, each a commented line of hex in the format of text2pcap. The last one is cut short on purpose.

# Node 0x00a1, seq 1: Temperature 21.5, calibrated, Normal priority, battery 87 %.
0000  01 00 a1 00 00 00 01 01 50 41 ac 00 00 57

text2pcap -u wraps each one in a UDP datagram, here from port 40000 to port 47100:

text2pcap -u 40000,47100 packets.txt telemetry.pcapng

tshark -X lua_script: loads a Dissector for one run, without installing it. Run it as your usual user, not root: as root, tshark skips Lua scripts.

$ tshark -X lua_script:telemetry.lua -r telemetry.pcapng
    1 0.000000000     10.1.1.1 → 10.2.2.2     TELEMETRY 60 Temperature 21.5 from node 0x00a1, seq 1
    2 0.000001000     10.1.1.1 → 10.2.2.2     TELEMETRY 60 Humidity 48.25 from node 0x00a1, seq 2
    3 0.000002000     10.1.1.1 → 10.2.2.2     TELEMETRY 60 Pressure 1013.25 from node 0x00b7, seq 7
    4 0.000003000     10.1.1.1 → 10.2.2.2     TELEMETRY 60 9 0 from node 0x00c3, seq 1
    5 0.000004000     10.1.1.1 → 10.2.2.2     TELEMETRY 60 Temperature  from node 0x00c3, seq 2

Port 47100 was recognised with no -d option: that is the registration at work. -O telemetry prints the protocol tree of each packet:

$ tshark -X lua_script:telemetry.lua -r telemetry.pcapng -O telemetry
...
Sensor Telemetry
    Version: 1
    Node: 0x00b7
    Seq: 7
    Sensor: Pressure (3)
    Status: 0xb0
        1... .... = Low battery: Set
        .0.. .... = Calibrated: Not set
        ..11 .... = Priority: Critical (3)
    Reading: 1013.25
    Battery: 9 %

Display filters work on every Field, -Y here and the filter bar in Wireshark:

$ tshark -X lua_script:telemetry.lua -r telemetry.pcapng -Y "telemetry.status.low_battery == 1"
    3 0.000002000     10.1.1.1 → 10.2.2.2     TELEMETRY 60 Pressure 1013.25 from node 0x00b7, seq 7

The fifth datagram ends after its sensor byte. The Dissector shows what it could read and marks the packet Malformed, rather than failing:

Sensor Telemetry
    Version: 1
    Node: 0x00c3
    Seq: 2
    Sensor: Temperature (1)
    [Expert Info (Error/Malformed): Malformed: truncated: status]

To keep the Dissector in Wireshark for good, copy telemetry.lua into its personal Lua plugins folder: see Installing a Dissector.

Where next

Example: TCP request/response describes a protocol over TCP, with Framing, a switch over Types and strings carrying their length. Example: tagged records reads a list of records to the end of a datagram, with if:, padding, hidden Fields, expect: and a handoff to Wireshark’s JSON dissector. The Format reference covers every construct: strings and sizes, arrays, if: and switch:, Types, Framing over TCP and Expressions. Every mistake Wirdigen reports has an entry in the Diagnostics index.

Example: TCP request/response

The tutorial described a protocol whose every datagram has the same layout. This example walks through a protocol over TCP, where messages of several kinds follow one another in a stream: it needs Framing to find where each message ends, a switch to read the right layout for each kind, named Types for those layouts, and strings that carry their own length.

The finished description and its sample packets are in the repository under examples/kvstore/. To run them you need the same tools as the tutorial: wirdigen, and Wireshark 4.4 or later with tshark and text2pcap.

The protocol

Key-Value Store is an invented protocol. A client connects to a server on TCP port 47200 and sends requests: read a key, write a value under a key, delete a key. The server answers each request with a reply carrying the same request id.

Every message, request or reply, starts with the same 8-byte header, every number big-endian:

BytesFieldMeaning
1versionProtocol version, 1
1opWhat the message is: 0x01 Get, 0x02 Put, 0x03 Delete, 0x81 Value, 0x82 Done
2lengthSize of the body, the bytes after the header
4request_idChosen by the client, copied into the reply

The body depends on op:

opBody
Get, Deletethe key
Putthe key, then the value
Value, the reply to a Geta status byte, then the value
Done, the reply to a Put or a Deletea status byte

A key is a string of up to 255 bytes, preceded by its length in one byte. A value is preceded by its length in two bytes. The status is 0 for Ok, 1 when the key was not found, 2 for an error.

A Get of the key temp, with request id 1, looks like this on the wire:

01 01 00 05 00 00 00 01 04 74 65 6d 70

The header is four plain Fields. op takes its labels from an Enum, since the switch below will name its cases after the same operations:

name: kvstore
fields:
  - { name: version, type: uint8 }
  - { name: op, type: uint8, display: hex, values: Op }
  - { name: length, type: uint16 }
  - { name: request_id, type: uint32 }
enums:
  Op:
    0x01: Get
    0x02: Put
    0x03: Delete
    0x81: Value
    0x82: Done

Finding each message

TCP carries a stream of bytes, not messages. A segment can hold several messages, or only part of one, as when a client sends requests back to back or a large value spans segments. The Dissector has to know where a message ends before it reads it, and here the header says: the message is the 8 header bytes plus length bytes of body.

framing: gives exactly that, in two parts:

name: kvstore
framing:
  header: 4
  length: "length + 8"
fields:
  - { name: version, type: uint8 }
  - { name: op, type: uint8 }
  - { name: length, type: uint16 }
  - { name: request_id, type: uint32 }
  - { name: body, type: bytes, size: length }
  • header: 4 is how many bytes the Dissector needs before it can compute the length. length ends at byte 4, so the first four bytes are enough; request_id is not needed.
  • length: is an Expression giving the whole message’s size, header included, from the Fields of those first bytes.

With this, the Dissector asks Wireshark for more data when a message is cut by the end of a segment, and reads several messages when a segment holds more than one. Each message gets its own Key-Value Store tree. See Framing.

One layout per operation

The body above is still raw bytes. A switch Field reads a different layout depending on a value, here op. Each case names a Type, a group of Fields declared once under the top-level types::

name: kvstore
fields:
  - { name: op, type: uint8 }
  - name: body
    switch: op
    cases:
      0x01: Get
      0x02: Put
    default:
      - { name: data, type: bytes, size: "_remaining" }
types:
  Get:
    fields:
      - { name: key, type: string, prefix: uint8 }
  Put:
    fields:
      - { name: key, type: string, prefix: uint8 }
      - { name: value, type: string, prefix: uint16 }

default: is read when no case matches, so a message of an operation this description does not know still shows its body, as data. Without it, the rest of the message would be shown as unmatched bytes with an expert note. Under Framing, _remaining counts the bytes left in the current message, not in the segment. See switch:.

The Fields of a case are filtered by their path from the top: kvstore.body.key matches the key of a Get, a Put and a Delete alike.

Strings with a length

prefix: uint8 reads a one-byte length, then that many bytes of string. The key temp is 04 74 65 6d 70 on the wire, and Wireshark shows Key: temp. The value uses prefix: uint16 because it can be longer. The prefix is not a Field of its own: Key covers only the string’s bytes, after it. See prefix:.

A prefix that claims more bytes than the message holds does not throw the Dissector off: it reports the Field truncated and marks the message Malformed, as below.

The Info column and the port

The Info column names the operation and the request, then the key or the status, whichever the message has:

name: kvstore
info: "{op} #{request_id}: {body.key}{body.status}"
fields:
  - { name: op, type: uint8, values: { 1: Get, 0x82: Done } }
  - { name: request_id, type: uint32 }
  - name: body
    switch: op
    cases:
      1: [ { name: key, type: string, prefix: uint8 } ]
      0x82: [ { name: status, type: uint8, values: { 0: Ok, 1: Not found } } ]

A Field in a case the message did not read shows nothing, so a Get reads Get #1: temp and a reply Done #3: Not found. See Info column.

registration: claims TCP port 47200 by default, as in the tutorial. Claiming a TCP port without framing: would get the warning tcp-without-framing, since each segment would then be read as one message.

The complete description

Put together, with the five Types, a second Enum for the status and a few description:s:

# Key-Value Store, an invented protocol: the book's TCP request/response example.
#
# A client sends requests to a server on TCP port 47200, which answers each one. Every Message,
# request or reply, starts with the same 8-byte header, big-endian:
#
#   version  op  length  request_id
#   1        1   2       4
#
# then `length` bytes of body, whose layout depends on `op`. Strings carry their length before
# them: a uint8 for a key, a uint16 for a value.
name: kvstore
title: Key-Value Store
registration:
  ports:
    tcp: [47200]
framing:
  header: 4
  length: "length + 8"
info: "{op} #{request_id}: {body.key}{body.status}"
fields:
  - { name: version, type: uint8 }
  - { name: op, type: uint8, display: hex, values: Op }
  - { name: length, type: uint16, description: "Size of the body, after the header" }
  - { name: request_id, type: uint32, description: "Pairs a reply with its request" }
  - name: body
    switch: op
    cases:
      0x01: Get
      0x02: Put
      0x03: Delete
      0x81: Value
      0x82: Done
    default:
      - { name: data, type: bytes, size: "_remaining" }
types:
  Get:
    fields:
      - { name: key, type: string, prefix: uint8 }
  Put:
    fields:
      - { name: key, type: string, prefix: uint8 }
      - { name: value, type: string, prefix: uint16 }
  Delete:
    fields:
      - { name: key, type: string, prefix: uint8 }
  Value:
    fields:
      - { name: status, type: uint8, values: Status }
      - { name: value, type: string, prefix: uint16 }
  Done:
    fields:
      - { name: status, type: uint8, values: Status }
enums:
  Op:
    0x01: Get
    0x02: Put
    0x03: Delete
    0x81: Value
    0x82: Done
  Status:
    0: Ok
    1: Not found
    2: Error

Generate the Dissector:

wirdigen generate kvstore.wirdigen.yaml

Trying it in tshark

The repository’s packets.txt holds the five segments of one TCP connection, in the hex format of text2pcap:

  1. Get #1, then the first 10 bytes of the 20 of Put #2;
  2. the rest of Put #2, then Delete #3;
  3. three replies back to back: Value #1, Done #2 and Done #3;
  4. a message with op 0x7f, which the description does not know;
  5. a Get whose key claims 9 bytes in a 4-byte body.

text2pcap -T wraps each one in a TCP segment of the same connection, here from port 52000 to port 47200. It writes every segment in the same direction, so the replies travel the same way as the requests: the Dissector does not mind, since it reads each message from its own header.

text2pcap -T 52000,47200 packets.txt kvstore.pcapng
$ tshark -X lua_script:kvstore.lua -r kvstore.pcapng
    1 0.000000000     10.1.1.1 → 10.2.2.2     KVSTORE 77 Get #1: temp
    2 0.000001000     10.1.1.1 → 10.2.2.2     KVSTORE 77 Delete #3: temp
    3 0.000002000     10.1.1.1 → 10.2.2.2     KVSTORE 87 Done #3: Not found
    4 0.000003000     10.1.1.1 → 10.2.2.2     KVSTORE 65 127 #4:
    5 0.000004000     10.1.1.1 → 10.2.2.2     KVSTORE 66 Get #5:

Put #2 began in the first segment, but Wireshark shows it in the second, where its last byte arrives, together with Delete #3. Packet 2’s Info column shows only the Delete, the last message of the packet, though TCP fenced off the Put’s text after reassembling it. The tree of packet 2 holds one Key-Value Store root per message:

$ tshark -X lua_script:kvstore.lua -r kvstore.pcapng -O kvstore
...
Key-Value Store
    Version: 1
    Op: Put (0x02)
    Length: 12
    Request id: 2
    Body: Put
        Key: color
        Value: teal
Key-Value Store
    Version: 1
    Op: Delete (0x03)
    Length: 5
    Request id: 3
    Body: Delete
        Key: temp

The unknown operation of packet 4 falls to default:, and the Get of packet 5 reads past its own body, so its key is reported truncated:

Key-Value Store
    Version: 1
    Op: Unknown (0x7f)
    Length: 3
    Request id: 4
    Body: 127
        Data: deadbe

Key-Value Store
    Version: 1
    Op: Get (0x01)
    Length: 4
    Request id: 5
    Body: Get
        [Expert Info (Error/Malformed): Malformed: truncated: body.key]

The truncation stays inside the message: Framing already said where it ends, so a message after it in the stream would still be read.

A filter on a Field of a Type matches every message that has it, here the two that name the key temp:

$ tshark -X lua_script:kvstore.lua -r kvstore.pcapng -Y 'kvstore.body.key == "temp"'
    1 0.000000000     10.1.1.1 → 10.2.2.2     KVSTORE 77 Get #1: temp
    2 0.000001000     10.1.1.1 → 10.2.2.2     KVSTORE 77 Delete #3: temp

Example: tagged records

The tutorial and the TCP example described messages whose layout the header decides once. This example walks through a protocol whose datagrams carry a list of records, each saying what it is and how long it is: it reads them with an array that runs to the end of the datagram, reads a Field only when a flag says it is there with if:, skips filler bytes with Padding, keeps bookkeeping Fields out of the tree with hidden:, warns about values the protocol never sends with expect:, and makes a Handoff of JSON to Wireshark’s own dissector with dissector:.

The finished description and its sample packets are in the repository under examples/tracker/. To run them you need the same tools as the tutorial: wirdigen, and Wireshark 4.4 or later with tshark and text2pcap.

The protocol

Asset Tracker is an invented protocol. A tracker fixed to a shipping container sends UDP datagrams to port 47300. Each datagram starts with a header, every number big-endian:

BytesFieldMeaning
2magicAlways 0x4154, “AT” in ASCII
1versionProtocol version, 1
1flagsThe top bit is set while the container is on a trip; the other bits are 0
2assetIdentifier of the container
4tripIdentifier of the trip, only when the top bit of flags is set

Records follow, up to the end of the datagram. Each record is:

BytesFieldMeaning
1tagWhat the record holds: 1 Position, 2 Heading, 3 Note, 4 Manifest
1lengthSize of the value
lengthvalueDepends on the tag
0 to 3paddingZero bytes, so the next record starts at a multiple of 4 bytes

A Position is a latitude and a longitude, each a signed 4-byte number of millionths of a degree. A Heading is 2 bytes, 0 to 359 degrees. A Note is text. A Manifest is a JSON document listing what the container holds. A tracker may send tags this description does not know: their value is skipped by its length.

A Heading of 90 degrees is a record of 4 bytes, with no padding:

02 02 00 5a

A Field that may be absent

trip is in the datagram only when the top bit of flags is set. A Bitfield names that bit, and if: reads trip only when it is non-zero:

name: tracker
fields:
  - { name: magic, type: uint16, display: hex }
  - { name: version, type: uint8 }
  - name: flags
    type: uint8
    display: hex
    bits:
      - { name: on_trip, width: 1 }
      - { padding: 7 }
  - { name: asset, type: uint16 }
  - { name: trip, type: uint32, if: flags.on_trip }

if: takes an Expression: flags.on_trip is the sub-Field’s value, 0 or 1. When it is 0, trip adds nothing to the tree and reads no bytes, so the records start right after asset. See if:.

Records to the end

The records are an array of one Type, Record, read with repeat: to_end until no bytes are left in the datagram. A record’s value is a switch on its tag, as in the TCP example, with inline Fields for each case:

name: tracker
fields:
  - { name: asset, type: uint16 }
  - { name: records, type: Record, repeat: to_end }
types:
  Record:
    fields:
      - { name: tag, type: uint8, values: Tag }
      - { name: length, type: uint8 }
      - name: value
        switch: tag
        cases:
          1:
            - { name: latitude, type: int32 }
            - { name: longitude, type: int32 }
          2: [ { name: heading, type: uint16, unit: [degree, degrees] } ]
          3: [ { name: note, type: string, size: length } ]
        default:
          - { name: data, type: bytes, size: length }
enums:
  Tag:
    1: Position
    2: Heading
    3: Note

Each record is an Element of the array, its own subtree item: Records [0], Records [1] and so on; there is no item for the array as a whole. Every Element shares the same filter names: tracker.records.tag == 2 matches every datagram with at least one Heading. See Arrays.

The note and the unknown tags take their size from length, an earlier Field of the same record. Position and Heading have a fixed size and do not need it.

Nothing can follow an array that runs to the end, so a Field after it is the warning unreachable-field:

name: tracker
fields:
  - name: records
    repeat: to_end
    fields:
      - { name: tag, type: uint8 }
  - { name: checksum, type: uint16 }

Padding and hidden Fields

Each record ends with zero bytes up to a multiple of 4. A record is 2 bytes of tag and length plus length bytes of value, so the Padding is (4 - (length + 2) % 4) % 4 bytes. { padding: … } takes that Expression and skips the bytes as a single “Padding” item, with no filter name:

name: tracker
fields:
  - name: records
    repeat: to_end
    fields:
      - { name: tag, type: uint8 }
      - { name: length, type: uint8, hidden: true }
      - { name: value, type: bytes, size: length }
      - { padding: "(4 - (length + 2) % 4) % 4" }

The length matters to the Dissector, not to someone reading the tree: the value’s item already covers its bytes. hidden: true reads the Field without showing it. It can still be used in Expressions, as here, and in display filters: tracker.records.length > 100 still works. See Padding and Hidden Fields.

Values the protocol never sends

magic is always 0x4154 and version is always 1, so showing them in every tree tells the reader nothing. A value that differs, though, is worth knowing about: it may be another protocol on the same port, or a newer tracker. expect: checks a Field’s value and adds an expert info warning when it does not match, and the dissection goes on:

name: tracker
fields:
  - { name: magic, type: uint16, display: hex, hidden: true, expect: 0x4154 }
  - { name: version, type: uint8, expect: 1 }
  - { name: heading, type: uint16, unit: [degree, degrees], expect: "0-359" }

expect: takes a value, a "low-high" range or a list of both. It works on hidden Fields too, so magic is hidden and still checked. Every warning is filtered as tracker._protocol.unexpected. See Expected values.

Handoff to Wireshark’s JSON dissector

A Manifest is JSON, which Wireshark already knows how to show. dissector: on a bytes Field makes a Handoff: it passes the Field’s bytes to a dissector by name, here json, whose tree goes right after the Field’s item:

name: tracker
fields:
  - { name: length, type: uint8 }
  - { name: manifest, type: bytes, size: length, dissector: json }

The name is the one Wireshark registers the dissector under. A name Wireshark does not know is a warning on the packet, not an error, and the dissection goes on. See Handing bytes to another dissector.

The complete description

Put together, with the Info column showing the asset, the port and a few description:s:

# Asset Tracker, an invented protocol: the book's tagged records example.
#
# A tracker fixed to a shipping container sends UDP datagrams to port 47300. Each one starts
# with a 6-byte header, big-endian, then a 4-byte trip number when the top bit of `flags` is set:
#
#   magic  version  flags  asset  [trip]
#   2      1        1      2      4
#
# Records follow up to the end of the datagram. Each is a tag, the length of its value, the
# value, then zero bytes up to a multiple of 4. A manifest record is JSON, handed to Wireshark's
# own JSON dissector.
name: tracker
title: Asset Tracker
registration:
  ports:
    udp: [47300]
info: "Asset {asset}"
fields:
  - { name: magic, type: uint16, display: hex, hidden: true, expect: 0x4154 }
  - { name: version, type: uint8, expect: 1 }
  - name: flags
    type: uint8
    display: hex
    bits:
      - { name: on_trip, width: 1 }
      - { padding: 7 }
  - { name: asset, type: uint16, description: "Identifier of the tracked container" }
  - { name: trip, type: uint32, if: flags.on_trip, description: "Present while on a trip" }
  - { name: records, type: Record, repeat: to_end }
types:
  Record:
    fields:
      - { name: tag, type: uint8, values: Tag }
      - { name: length, type: uint8, hidden: true }
      - name: value
        switch: tag
        cases:
          1:
            - { name: latitude, type: int32, description: "Millionths of a degree" }
            - { name: longitude, type: int32, description: "Millionths of a degree" }
          2: [ { name: heading, type: uint16, unit: [degree, degrees], expect: "0-359" } ]
          3: [ { name: note, type: string, size: length } ]
          4: [ { name: manifest, type: bytes, size: length, dissector: json } ]
        default:
          - { name: data, type: bytes, size: length }
      - { padding: "(4 - (length + 2) % 4) % 4" }
enums:
  Tag:
    1: Position
    2: Heading
    3: Note
    4: Manifest

Generate the Dissector:

wirdigen generate tracker.wirdigen.yaml

Trying it in tshark

The repository’s packets.txt holds four datagrams, in the hex format of text2pcap:

  1. asset 7 on trip 42, with a Position, a Heading, a Note and a Manifest;
  2. asset 7 off trip, with a record of tag 0x7f, which the description does not know, and a Heading of 400 degrees;
  3. asset 9 with a wrong magic and version 2, then a Heading;
  4. asset 9 with a Note whose length claims 8 bytes when 2 are left.
text2pcap -u 40000,47300 packets.txt tracker.pcapng
$ tshark -X lua_script:tracker.lua -r tracker.pcapng
    1 0.000000000     10.1.1.1 → 10.2.2.2     TRACKER 96 Asset 7
    2 0.000001000     10.1.1.1 → 10.2.2.2     TRACKER 60 Asset 7
    3 0.000002000     10.1.1.1 → 10.2.2.2     TRACKER 60 Asset 9
    4 0.000003000     10.1.1.1 → 10.2.2.2     TRACKER 60 Asset 9

The first datagram has every kind of record. Trip is there because On trip is set, Magic and the lengths are hidden, each record ends with its padding, and the Manifest’s bytes are followed by the JSON dissector’s own tree:

$ tshark -X lua_script:tracker.lua -r tracker.pcapng -O tracker,json
...
Asset Tracker
    Version: 1
    Flags: 0x80
        1... .... = On trip: Set
    Asset: 7
    Trip: 42
    Records [0]
        Tag: Position (1)
        Value: Position
            Latitude: 48858400
            Longitude: 2294500
        Padding
    Records [1]
        Tag: Heading (2)
        Value: Heading
            Heading: 90 degrees
        Padding
    Records [2]
        Tag: Note (3)
        Value: Note
            Note: door open
        Padding
    Records [3]
        Tag: Manifest (4)
        Value: Manifest
            Manifest: 7b2270616c6c657473223a337d
            JavaScript Object Notation
                Object
                    Member: pallets
                        [Path with value: /pallets:3]
                        [Member with value: pallets:3]
                        Number value: 3
                        Key: pallets
                        [Path: /pallets]
        Padding

A Heading’s padding item covers no byte: it is shown even when the amount is 0.

In the second datagram, trip is absent, the unknown tag falls to default: and the Heading gets its warning:

Asset Tracker
    Version: 1
    Flags: 0x00
        0... .... = On trip: Not set
    Asset: 7
    Records [0]
        Tag: Unknown (127)
        Value: 127
            Data: deadbe
        Padding
    Records [1]
        Tag: Heading (2)
        Value: Heading
            Heading: 400 degrees
                [Expert Info (Warning/Protocol): Unexpected value: records.value.heading (expected 0-359)]
                    [Unexpected value: records.value.heading (expected 0-359)]
                    [Severity level: Warning]
                    [Group: Protocol]
        Padding

The third datagram has two warnings, but the tree shows only the version’s: the magic’s is on a hidden item. It is still in the packet, so a filter finds it, and so do Wireshark’s Analyze → Expert Information and tshark’s summary of them:

$ tshark -q -X lua_script:tracker.lua -r tracker.pcapng -z expert,warn

Errors (1)
=============
   Frequency      Group           Protocol  Summary
           1  Malformed            TRACKER  Malformed: truncated: records.value.note

Warns (3)
=============
   Frequency      Group           Protocol  Summary
           1   Protocol            TRACKER  Unexpected value: records.value.heading (expected 0-359)
           1   Protocol            TRACKER  Unexpected value: magic (expected 0x4154)
           1   Protocol            TRACKER  Unexpected value: version (expected 1)
$ tshark -X lua_script:tracker.lua -r tracker.pcapng -Y tracker._protocol.unexpected
    2 0.000001000     10.1.1.1 → 10.2.2.2     TRACKER 60 Asset 7
    3 0.000002000     10.1.1.1 → 10.2.2.2     TRACKER 60 Asset 9

The error above is the fourth datagram’s: its Note claims more bytes than are left, so the record is reported truncated and the packet Malformed, and the array stops there.

Installing a Dissector

A generated Dissector is a single Lua file, such as telemetry.lua. Wireshark loads it from its personal Lua plugins folder at startup; tshark can also load it for one run, with nothing installed. Wirdigen has no install command: copying the file is all there is to it.

Wireshark 4.4 or later

Dissectors need Wireshark 4.4 or later, whose Lua is 5.3 or 5.4. tshark --version or Help → About Wireshark shows the version you have. Loaded into an older Wireshark, a Dissector stops with an error naming the version it found (see Troubleshooting).

Most platforms’ current packages are recent enough. Ubuntu 24.04 ships 4.2: install a newer release from the Wireshark developers’ PPA instead.

sudo add-apt-repository ppa:wireshark-dev/stable
sudo apt update
sudo apt install wireshark tshark

Trying a Dissector without installing it

-X lua_script:<file> loads a Lua file for one run of tshark or Wireshark, on top of the installed plugins. It is the quickest way to check a Dissector on a capture:

tshark -X lua_script:telemetry.lua -r capture.pcapng
wireshark -X lua_script:telemetry.lua capture.pcapng

A Dissector that does not claim ports by default (no registration:) is reached through Decode As, which -d gives on the command line:

tshark -X lua_script:demo.lua -d udp.port==5000,demo -r capture.pcapng

Finding the plugins folder

Where Wireshark looks for Lua plugins depends on the platform, the version and how Wireshark was installed, so ask Wireshark rather than guessing:

  • In Wireshark, Help → About Wireshark → Folders: the Personal Lua Plugins row.

  • From the command line, tshark -G folders:

    $ tshark -G folders | grep "Personal Lua"
    Personal Lua Plugins:	/home/alice/.local/lib/wireshark/plugins
    

Typical answers look like these, but only the two above are authoritative:

PlatformPersonal Lua plugins folder, for example
Linux, macOS~/.local/lib/wireshark/plugins
Windows%APPDATA%\Wireshark\plugins

The folder may not exist yet: create it. Copy the Dissector into it, and Wireshark loads it at its next start:

mkdir -p ~/.local/lib/wireshark/plugins
cp telemetry.lua ~/.local/lib/wireshark/plugins/

A Global Lua Plugins folder also exists, for every user of the machine; it usually needs administrator rights.

Reloading

Wireshark reads Lua plugins when it starts. After regenerating a Dissector, either restart Wireshark or reload the plugins with Analyze → Reload Lua Plugins (Ctrl+Shift+L). tshark reads them afresh on every run.

Troubleshooting

“This Dissector requires Wireshark >= 4.4”

Every Dissector checks the Wireshark version as it loads, and refuses an older one with a clear message instead of failing later on a missing Lua function:

tshark: Lua: Error during loading:
telemetry.lua:9: This Dissector requires Wireshark >= 4.4, found 4.2.2

Upgrade Wireshark (see above); regenerating does not help.

tshark exits 0 although the Dissector failed

When a Lua file fails to load, tshark prints Lua: Error during loading: on stderr, then reads the capture without that Dissector and still exits with status 0. A script, or a CI job, that runs tshark must not trust the exit status alone: check that stderr is empty, and that the packets show the protocol. Wireshark itself shows the same error in a dialog at startup.

Nothing happens when running as root

tshark and Wireshark do not run Lua plugins as root: they print Running as user "root" and group "root". This could be dangerous. and dissect the capture as if the Dissector did not exist, so the packets show as plain UDP or TCP. Run them as your usual user; capture permissions are granted through the wireshark group (or your platform’s equivalent), not by running as root. Containers often run as root by default: pass a user, as in docker run --user "$(id -u):$(id -g)".

The packets show as plain UDP or TCP

If the Dissector loaded (no error above) but its packets are not decoded:

  • Check that the Dissector claims the traffic’s port: its registration: ports, or the <name>.udp_ports and <name>.tcp_ports preferences that start from them. Without registration:, use Analyze → Decode As (or -d with tshark).
  • In Wireshark, check Help → About Wireshark → Plugins lists the file, then reload (Ctrl+Shift+L).

Command-line interface

The wirdigen command validates Protocol Descriptions and generates their Dissectors:

CommandDoes
wirdigen validate <inputs>…Validates, writes nothing.
wirdigen generate <inputs>…Validates and writes Dissectors.
wirdigen generate --check <inputs>…Writes nothing; fails if a Dissector on disk is missing or differs.
wirdigen schema [-o <file>]Prints the JSON Schema, for editor completion.

This chapter covers where the output goes, running Wirdigen in CI, and the parts of the command line that scripts rely on: the exit codes and the JSON Lines output. Every flag is described by wirdigen --help, wirdigen <command> --help and the man pages shipped in the release archives:

Generate Wireshark Lua dissectors from YAML protocol descriptions

Usage: wirdigen [OPTIONS] <COMMAND>

Commands:
  validate  Validate Protocol Descriptions; write nothing
  generate  Validate Protocol Descriptions and write their Dissectors
  schema    Print the JSON Schema of Protocol Descriptions, for editor completion
  help      Print this message or the help of the given subcommand(s)

Options:
      --color <COLOR>
          When to colour Diagnostics on stderr

          Possible values:
          - auto:   Colour when stderr is a terminal, unless `NO_COLOR` or `CLICOLOR_FORCE` says otherwise
          - always: Always colour
          - never:  Never colour
          
          [default: auto]

  -q, --quiet
          Hide warnings and the summary line; errors are still shown

  -v, --verbose
          List each Dissector as written or unchanged

      --message-format <MESSAGE_FORMAT>
          How to report Diagnostics and results: `human` on stderr, or `json` Lines on stdout

          Possible values:
          - human: Rendered Diagnostics and status lines on stderr
          - json:  One JSON object per line on stdout: `diagnostic`, `file` and `summary` records
          
          [default: human]

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

There is no configuration file and no environment variable of Wirdigen’s own; NO_COLOR and CLICOLOR_FORCE are honoured below an explicit --color.

Inputs

Inputs are one or more paths, named on the command line: Wirdigen walks no directory and searches for nothing. Any extension is accepted, though .wirdigen.yaml is the convention. Diagnostics name each input as it was typed. - reads the description from standard input, once, under the name <stdin>.

Where the Dissector goes

By default the Dissector is written next to its input, named after the input’s file name, never after the protocol’s name::

InputDissector
proto/telemetry.wirdigen.yamlproto/telemetry.lua
proto/telemetry.yamlproto/telemetry.lua (the last extension is replaced)
- (standard input)standard output

Two flags move it:

  • -o <file> writes the Dissector of the only input to <file>, and -o - to standard output. It takes exactly one input.
  • --out-dir <dir> writes every Dissector into <dir>, under the same name as above. It takes any number of inputs.
wirdigen generate telemetry.wirdigen.yaml                       # telemetry.lua
wirdigen generate -o plugins/telemetry.lua telemetry.wirdigen.yaml
wirdigen generate --out-dir build/ proto/*.wirdigen.yaml
wirdigen generate - < telemetry.wirdigen.yaml > telemetry.lua

Two inputs that would write the same file, or an output that is its own input, are a usage error, reported before anything is read or written.

Writes are atomic: the Dissector goes to a temporary file in the same directory, which is then renamed, so a reader never sees half a file. An existing file is overwritten without asking, except when it already holds the same bytes: it is left alone, and keeps its modification time, so build tools that watch it see no change.

Each input succeeds or fails on its own. When one of several inputs has errors, the others are still written, and the exit code reports the failure.

Checking generated Dissectors in CI

A repository that commits its generated Dissectors can check, in CI, that they match their descriptions. generate --check writes nothing; it compares each Dissector on disk with the bytes generate would write there, honouring -o and --out-dir, and fails when one differs or is missing:

$ wirdigen generate --check proto/*.wirdigen.yaml
error: `proto/telemetry.lua` is stale
error: `proto/tracker.lua` is stale (missing)

Running the same generate command without --check brings them up to date. The Diagnostics are checked too, so --check also fails on an error in a description, and --deny-warnings applies as it does to generate.

A GitHub Actions step, with wirdigen installed earlier in the job:

- name: Check the Dissectors are up to date
  run: wirdigen generate --check --deny-warnings proto/*.wirdigen.yaml

--check needs a file to compare with: -o -, and standard input without -o <file>, are rejected.

Exit codes

CodeMeaning
0Success.
1Any failure: an error Diagnostic, a denied warning, a stale or missing Dissector under --check, an input that cannot be read or an output that cannot be written.
2A usage error, reported before any input is processed.

With several inputs, the exit code is the worst result among them. Any other code, such as 101 for a panic, is a bug: please report it. These codes are stable; a finer split could only come later behind a flag of its own, never by renumbering.

Failing on warnings

A warning means the description is clear but probably wrong, so by default it is shown and the Dissector is still written. --deny-warnings makes warnings fail the run, for validate and generate (with or without --check): each warning is rendered as an error, with a note saying warnings are denied, and a file with only warnings is not written.

$ wirdigen validate --deny-warnings demo.wirdigen.yaml
error[unused-type]: the Type `Header` is never used
 --> demo.wirdigen.yaml:5:3
  |
5 |   Header:
  |   ^^^^^^
  |
  = note: use it as `type: Header`, or remove it
  = note: warnings are denied for this run
  = note: see https://cerclique.github.io/wirdigen/diagnostics.html#unused-type

error: 1 error in 1 of 1 file

It is all or nothing: there is no flag to deny or allow a single warning. To accept a warning in one description, silence it there with allow:.

A minor release can break a --deny-warnings build. New warnings are added in minor releases, since they reject nothing on their own; under --deny-warnings they become errors. Before upgrading, read the New warnings group of the changelog, or pin the Wirdigen version your CI installs.

JSON Lines output

--message-format json reports a run as JSON Lines on standard output, for editors, CI annotations and other tools. This section is the contract of that output.

Each line is one JSON object, whose type says what it records:

  • one diagnostic record per Diagnostic, for each input in argument order, and in source order within an input;
  • one file record per input, after that input’s Diagnostics;
  • one summary record, last.

For example, with the rendered text abridged:

$ wirdigen generate --message-format json --deny-warnings unused.wirdigen.yaml ok.wirdigen.yaml
{"type":"diagnostic","file":"unused.wirdigen.yaml","name":"unused-type","severity":"warning","message":"the Type `Header` is never used","span":{"start":58,"end":64,"line":5,"column":3,"end_line":5,"end_column":9},"notes":[{"message":"use it as `type: Header`, or remove it"}],"rendered":"error[unused-type]: …","denied":true}
{"type":"file","input":"unused.wirdigen.yaml","output":"unused.lua","status":"failed"}
{"type":"file","input":"ok.wirdigen.yaml","output":"ok.lua","status":"written"}
{"type":"summary","errors":0,"warnings":1,"exit_code":1}

diagnostic

FieldValue
type"diagnostic"
fileThe input’s name as typed, or "<stdin>".
nameThe Diagnostic’s name, such as "unused-type": the anchor of its entry in the Diagnostics index and the token of allow:.
severity"error" or "warning". A warning denied by --deny-warnings stays "warning".
messageThe message, one line.
spanWhere the Diagnostic points: a span.
notesAn array, possibly empty, of {"message", "span"} objects; span is left out when the note points nowhere.
renderedThe Diagnostic as rendered on stderr in human mode, without colour, ending with a newline.
deniedtrue when the warning was promoted by --deny-warnings; left out otherwise.

Spans

FieldValue
start, endByte offsets into the input, end exclusive.
line, columnWhere start falls: a 1-based line, and a 1-based column counted in characters, not bytes.
end_line, end_columnWhere end falls, counted the same way.

file

FieldValue
type"file"
inputThe input’s name as typed, or "<stdin>".
outputThe path of its Dissector, as generate would write it; null under validate.
statusWhat happened to the input, below.
statusMeaning
"valid"validate: the input is valid.
"written"generate: the Dissector was written.
"unchanged"generate: the file already held these bytes and was left alone. --check: the Dissector is up to date.
"stale"--check: the Dissector differs or is missing.
"failed"The input could not be read or has errors (denied warnings included), or its output could not be read or written.

summary

FieldValue
type"summary"
errorsThe number of error Diagnostics in the run.
warningsThe number of warning Diagnostics, denied ones included.
exit_codeThe exit code the run ends with.

A usage error ends the run before it starts, with exit code 2, a message on stderr and nothing on stdout.

Standard streams

Every record is emitted whatever -q and -v say. Standard error then carries only error: lines for an input or output that cannot be read or written, and for each stale Dissector under --check; the records already say the same, so a tool can ignore stderr.

The Dissector of standard input normally goes to standard output, which the records now use: --message-format json is rejected with -o -, and with - as an input of generate unless -o <file> is given.

Stability

The JSON Lines output is part of the CLI’s compatibility promise, and its shape belongs to the CLI alone: the library has no JSON form of its own.

  • Adding a field to a record, or a new record type, is a minor change. Consumers must ignore fields and record types they do not know.
  • Removing or renaming a field or a record type, or changing what one means, is a major change.
  • Diagnostic messages, notes, the rendered text and how precise a span is are not stable, just as for the human output; the names and severities of Diagnostics are.

Cheat sheet

A Protocol Description has ten top-level keys. They are accepted in any order and listed here in the order the book and the examples use.

KeyRequiredMeaning
nameyesFilter name of the protocol: a lowercase letter, then lowercase letters, digits, _ or -, 2 to 32 characters.
titlenoFull name shown at the root of the protocol tree. Defaults to the uppercase name.
registrationnoPorts claimed by default, and Decode As (Registration). Leaving it out means Decode As only.
framingnoHow messages are found in a TCP stream: a constant header size and a length Expression (Framing).
endiannoDefault byte order, big (the default) or little.
infonoTemplate of the Info column (Info column). Without it, the column names the case of the outermost switch Field.
fieldsyesThe top-level layout: a non-empty list of Fields.
typesnoNamed Types, reusable groups of Fields.
enumsnoNamed tables of labels for integer values.
allownoNames of warnings to silence.

The smallest description is name: plus fields::

name: demo
fields:
  - { name: id, type: uint8 }

With a title and a silenced warning:

name: demo
title: Demo Protocol
fields:
  - { name: id, type: uint8 }
allow: [unknown-allow]

There is no format-version key and no top-level description: key: YAML comments document a file. (A Field’s own description: is its help text in Wireshark.)

Fields and Types

The top-level fields: is the layout of the payload: an ordered list of Fields, read one after another from the start of the packet. There are no absolute offsets.

name: demo
fields:
  - { name: msg_type, type: uint8 }
  - { name: length, type: uint16 }
  - { name: sender, type: ipv4 }

Each Field is shown in the protocol tree and can be filtered as <protocol>.<name>, here demo.msg_type, demo.length and demo.sender (see Filter names).

A Field

A Field is a mapping with a name: and exactly one key saying what it is. This chapter covers type: with a built-in type or a Type, and fields: with an inline structure; switch: picks a layout among several (see switch:).

The tree shows a Field under a label derived from its name: _ becomes a space and the first letter is capitalised, so msg_type is shown as “Msg type”. label: replaces it (see Tree text).

Built-in types

Built-in names describe the bytes on the wire. Every one in this table has a fixed size, so a Field of one of them takes no size:, prefix: or terminator: (unexpected-length). string and bytes are as long as one of those keys says (see Sizes), and the timestamps abs_time and rel_time as long as their encoding says (see Timestamps).

TypeBytesValue
uint8 uint16 uint24 uint321, 2, 3, 4unsigned integer
uint40 uint48 uint56 uint645, 6, 7, 8unsigned integer, shown as 64-bit
int8 int16 int24 int321, 2, 3, 4signed integer, two’s complement
int40 int48 int56 int645, 6, 7, 8signed integer, shown as 64-bit
bool1true when the byte is not zero
float32 float644, 8IEEE 754 floating point
ipv44IPv4 address
ipv616IPv6 address
ether6Ethernet (MAC-48) address
eui648EUI-64 identifier
guid16GUID (UUID)

A type: starting with an uppercase letter names a Type instead. A lowercase type: naming none of these built-ins is unknown-type.

name: sensor
fields:
  - { name: sensor_id, type: uint24 }
  - { name: timestamp_ms, type: uint48 }
  - { name: offset, type: int16 }
  - { name: temperature, type: float32 }
  - { name: calibrated, type: bool }
  - { name: gateway, type: ether }
  - { name: device, type: guid }

Byte order

Fields are big-endian (network byte order) unless endian: says otherwise. The top-level endian: sets the default for the whole description, an inline structure’s endian: the default for the Fields inside it, and a Field’s own endian: overrides both. A Type is read in its own byte order: its endian:, else the top-level one. The value is big or little (invalid-endian).

name: sensor
endian: little
fields:
  - { name: reading, type: int32 }
  - { name: port, type: uint16, endian: big }
  - { name: sample, type: float64 }

Byte order applies to the multi-byte integers, float32, float64, ipv4, eui64 and guid. A little-endian guid is the mixed-endian layout Windows uses, with its first three groups reversed. It also applies to a prefix: count, to utf16 and ucs2 text (see Strings and bytes) and to every timestamp encoding (see Timestamps). Single bytes, ipv6, ether and raw bytes have no byte order, so endian: does not change them.

Strings and bytes

string is text and bytes is raw bytes. Neither has a size of its own: a Field of either type gives its length with exactly one of size:, prefix: or terminator: (see Sizes).

name: chat
fields:
  - { name: room, type: string, size: 8 }
  - { name: nick, type: string, prefix: uint8 }
  - { name: client, type: string, terminator: 0 }
  - { name: digest, type: bytes, size: 16, display: colon }

encoding: says how a string’s bytes become text. Besides string, only the timestamps take it (see Timestamps); on any other type it is incompatible-display.

encoding:TextDefault
ascii7-bit ASCII
utf8UTF-8yes
utf16UTF-16, in the Field’s byte order
ucs2UCS-2, in the Field’s byte order
latin1ISO 8859-1

A utf16 or ucs2 string ends at a 2-byte zero aligned on its 2-byte code units, so its terminator: can only be 0.

name: files
endian: little
fields:
  - { name: share, type: string, terminator: 0, encoding: utf16 }
  - { name: host, type: string, size: 16, encoding: ascii }
  - { name: owner, type: string, prefix: uint16, encoding: latin1 }

Timestamps

abs_time is a point in time and rel_time a duration. encoding: says how the bytes count time, and so how many bytes the Field reads: a timestamp takes no size:, prefix: or terminator: (unexpected-length).

encoding:Bytesabs_timerel_timeDefault
secs4seconds since 1970-01-01 UTCsecondsyes
secs_nsecs4 + 4seconds since 1970, then nanosecondsseconds, then nanoseconds
ntp8NTP: seconds since 1900, then a 32-bit fraction of a secondnot taken
msecs8milliseconds since 1970milliseconds
usecs8microseconds since 1970microseconds
nsecs8nanoseconds since 1970nanoseconds

Every encoding follows the Field’s byte order. ntp on a rel_time, or a text encoding on a timestamp, is incompatible-display.

name: clock
fields:
  - { name: sent, type: abs_time }
  - { name: received, type: abs_time, encoding: ntp, display: utc }
  - { name: logged, type: abs_time, encoding: usecs, endian: little }
  - { name: round_trip, type: rel_time, encoding: secs_nsecs }
  - { name: timeout, type: rel_time, encoding: msecs }

An abs_time is shown in the time zone of whoever views the capture unless display: says otherwise (see Display). A rel_time takes no display:.

Display

display: says how a value is shown in the tree. Which values it takes depends on the type. For integers:

Typedisplay:DefaultShows 258 as
unsigned integersdecyes258
hex0x0102
oct0402
dec_hex258 (0x0102)
hex_dec0x0102 (258)
signed integersdecyes258

Hex digits are padded to the type’s width. For bytes, display: picks the separator between bytes:

display:DefaultShows 01 02 03 as
plainyes010203
dot01.02.03
dash01-02-03
colon01:02:03
space01 02 03

For abs_time, display: picks the time zone:

display:DefaultShows 2024-01-01 00:00:00 UTC as
localyesin the viewer’s time zone, such as Jan 1, 2024 01:00:00.000000000 CET
utcJan 1, 2024 00:00:00.000000000 UTC
doy_utc2024/001:00:00:00.000000000 UTC, with the day of the year

string, bool, float32, float64, rel_time and the address types take no display:. Any other combination is incompatible-display.

name: demo
fields:
  - { name: flags, type: uint8, display: hex }
  - { name: length, type: uint16 }
  - { name: mode, type: uint16, display: oct }
  - { name: session, type: uint32, display: hex_dec }
  - { name: station, type: bytes, size: 6, display: dash }

Display changes only what the tree shows: a filter matches the value whichever way it is written, so demo.flags == 16 and demo.flags == 0x10 are the same filter.

Value mappings

Three keys give a value words. Like display:, they change only what the tree shows: a filter still matches the number, so demo.msg_type == 1 finds every “Request”.

KeyTypesShows
values:integersa label in place of the value, with the value after it: Request (1)
true: / false:boola label for each state, in place of True and False
unit:integers, float32, float64the value, a space, then the unit: 16 bytes

On any other type, each of these keys is incompatible-display. A Field has values: or unit:, not both (conflicting-mappings).

Values tables

values: maps values to labels. A key is an integer, in decimal or hex, or a range of integers written as a string "low-high", both bounds included. A value with no key is shown as Unknown (7).

name: demo
fields:
  - name: status
    type: uint16
    display: hex
    values:
      0x0000: OK
      0x0001: Retry
      0xffff: Failed
  - name: delta
    type: int8
    values:
      "-128--1": Behind
      0: Even
      "1-127": Ahead

A negative bound keeps its sign, so "-128--1" runs from -128 to -1. A key that is neither an integer nor a range, such as 1.5 or a quoted "16", and a range whose first bound is the higher, are wrong-value-type; a key spelt twice is duplicate-key. Two keys matching one value, such as 5 inside "0-9", are overlapping-values. A key the Field’s type cannot hold, such as 256 on a uint8, is the warning unreachable-value; a range is reported only when none of its values fit. Each label is a non-empty single line (invalid-label).

Enums

A table several Fields share is declared once as an Enum, under the top-level enums:, and named by each Field’s values:. A request and its response sharing an opcode table is the typical case.

name: demo
fields:
  - { name: msg_type, type: uint8, values: MsgType }
  - { name: reply_to, type: uint8, values: MsgType }
enums:
  MsgType:
    1: Request
    2: Response
    "16-31": Vendor

An Enum’s name is an uppercase letter then letters or digits (invalid-type-name). A values: naming no Enum is unknown-enum, and an Enum no Field names is the warning unused-enum. An Enum’s table follows the rules of an inline one. A key outside the type of one Field using it is reported once, and is left out only for that Field, so one Enum can serve a uint8 and a uint16.

States and units

true: and false: label the two states of a bool. Either can be given alone; the other keeps its default, True or False.

name: demo
fields:
  - { name: enabled, type: bool, true: Enabled, false: Disabled }
  - { name: urgent, type: bool, true: Urgent }
  - { name: length, type: uint16, unit: [byte, bytes] }
  - { name: timeout, type: uint32, unit: ms }
  - { name: distance, type: float32, unit: [metre, metres] }

unit: is one string, used whatever the value, or a [singular, plural] pair: the singular when the value is 1, the plural otherwise. Here a length of 1 is shown as 1 byte and a length of 16 as 16 bytes. A unit with one form is a plain string: a list holds exactly the two forms (wrong-value-type). Each form is a non-empty single line (invalid-unit), and a value YAML would read as a number or a bool needs quotes.

Tree text

label: is the text the tree shows for the Field, in place of the one derived from its name. description: is a longer explanation, which Wireshark shows in the status bar when the Field is selected and in its field reference.

name: demo
fields:
  - { name: msg_type, type: uint8 }
  - name: seq
    type: uint32
    label: Sequence number
    description: Incremented by the sender for each message

Here msg_type is shown as “Msg type” and seq as “Sequence number”. A label is a non-empty single line (invalid-label); a description is a single line (invalid-description). Both are plain text, so a value YAML would read as a number or a bool, such as label: 2 or label: true, needs quotes.

Inline structures

A Field with fields: in place of type: is an inline structure: a group of Fields read one after another, shown as a subtree that spans the bytes they read. Its fields: is written like the top-level one, a non-empty list of Fields (empty-fields), and a Field inside it can be a structure too, to any depth.

name: demo
fields:
  - { name: msg_type, type: uint8 }
  - name: header
    label: Fixed header
    endian: little
    fields:
      - { name: length, type: uint16 }
      - name: flags
        fields:
          - { name: urgent, type: bool }
          - { name: priority, type: uint8 }
  - { name: payload, type: bytes, prefix: uint8 }

A structure takes name:, label:, description:, count: or repeat: to make it an array, if: to read it only under a condition, hidden:, and endian:, which is the byte order of the Fields inside it unless they set their own (see Byte order). The keys that say how a value is read or shown belong on the Fields inside: a length key on a structure is unexpected-length, and display:, encoding:, values:, true:, false:, unit:, expect: or dissector: is incompatible-display.

Only the Fields of one structure need different names: header.length and a top-level length can live side by side.

Types

A Type is a named group of Fields, declared once under the top-level types: and used by any number of Fields with type: <Name>. A Field of a Type is shown like an inline structure: a subtree holding the Type’s Fields.

name: demo
fields:
  - { name: req_hdr, type: Header, label: Request header }
  - { name: resp_hdr, type: Header, label: Response header }
types:
  Header:
    fields:
      - { name: length, type: uint16 }
      - { name: sent, type: Stamp }
  Stamp:
    endian: little
    fields:
      - { name: secs, type: uint32 }
      - { name: usecs, type: uint32 }
  • types: maps each Type name to a body with a required fields:, written like an inline structure’s, and an optional endian:. Types can be declared in any order and use each other.
  • A Type name is an uppercase letter, then letters or digits: Header, V2Header (invalid-type-name). Built-in types are all lowercase, so the two never clash.
  • A Type is read in its own byte order: its endian:, else the top-level endian:, whatever structure the Field using it is in. A Field of a Type takes name:, label:, description:, count: or repeat: to make it an array, if: and hidden: only: endian: on it is invalid-endian, a length key unexpected-length, and a display or value-mapping key, expect: or dissector:, incompatible-display.
  • Using a Type nobody declared is unknown-type, reported once however many Fields use it. Declaring a name twice is duplicate-key. A Type that contains itself, directly or through other Types, is recursive-type, and a Type no Field uses is the warning unused-type.

Type names never appear in filter names: each Field of a Type is filtered under the path of the Field using it, so the example above gives demo.req_hdr.length, demo.req_hdr.sent.secs, demo.resp_hdr.length and demo.resp_hdr.sent.secs, and a request header can be filtered apart from a response header.

Padding

{ padding: n } in place of a Field skips n bytes. It can stand anywhere in a structure, top-level, inline, in a Type or in a switch case, and takes no other key: no name:, so no filter name, and nothing an Expression can read. The tree shows the bytes as one item, “Padding”.

name: demo
fields:
  - { name: kind, type: uint8 }
  - { padding: 3 }                           # align `length` on 4 bytes
  - { name: length, type: uint16 }
  - { name: text, type: string, size: length }
  - { padding: "(4 - length % 4) % 4" }      # up to the next multiple of 4
  - { name: crc, type: uint32 }

n is a number of bytes or an Expression, like a size:. A negative constant is invalid-padding, and so is a constant Expression that is negative or has no value. An Expression whose value turns out negative, or has none, when a packet is read is reported as “Malformed” and the dissection stops; padding past the end of the packet is “Malformed: truncated”. Any key beside padding: is unknown-key.

Hidden Fields

hidden: true reads a Field without adding it to the tree. Expressions can still read it, and display filters still match it: a hidden Field keeps its filter name. Hiding a structure, a Field of a Type, a switch Field or an array hides everything in it; for a bitfield, the sub-Fields can also be hidden one by one. hidden: false is the default.

name: demo
fields:
  - { name: length, type: uint16, hidden: true }   # shown only through `data`
  - { name: data, type: bytes, size: length }
  - name: reserved
    hidden: true
    fields:
      - { name: a, type: uint32 }
      - { name: b, type: uint32 }

Expected values

expect: declares the values a Field should hold: one value, a "low-high" range string with both bounds included, or a list mixing both. It goes on integer and bool Fields and on bitfield sub-Fields. A bool holds 0 or 1, as Expressions read it.

name: demo
fields:
  - { name: magic, type: uint32, display: hex, expect: 0xcafe }
  - { name: version, type: uint8, expect: [1, "5-7"] }
  - { name: ready, type: bool, expect: 1 }
  - name: flags
    type: uint8
    bits:
      - { name: reserved, width: 4, expect: 0 }
      - { name: kind, width: 4 }

A value outside it is not a malformed packet: the Dissector adds an expert info warning on the Field, “Unexpected value: version (expected 1, 5-7)”, filtered as <protocol>._protocol.unexpected, and goes on reading. A hidden Field is checked too.

Values are written as in a values table: an entry that is neither an integer nor a range, a range whose first bound is the higher, and an empty list are wrong-value-type. On any other type, expect: is incompatible-display. An expect: none of whose values the Field’s type can hold, such as 256 on a uint8, never matches: it is the warning unreachable-expect, and every packet gets the expert info.

Handing bytes to another dissector

dissector: on a bytes Field passes its bytes to a dissector Wireshark already has, by the name Wireshark registers it under: json, http, data, and so on. The Field is shown as usual, then the other dissector’s layer right after it, in the same structure.

name: demo
fields:
  - { name: length, type: uint16 }
  - { name: payload, type: bytes, size: length, dissector: json }
  - { name: trailer, type: bytes, prefix: uint8, dissector: data, hidden: true }
  • The other layer is shown even when the Field is hidden: hidden: true with dissector: shows the decoded bytes but not the raw ones.
  • A Field with no bytes calls no dissector. The Protocol column keeps this protocol’s name.
  • Whether Wireshark has a dissector by that name is known only when a packet is read. A name it does not know adds an expert info warning, even when the Field is empty, Unknown dissector <name>: payload, filtered as <protocol>._undecoded.dissector, and the dissection goes on.
  • Bytes the other dissector cannot read are its own malformed packet, shown in its layer; the dissection of this protocol goes on.

The name is one word: an empty name, one with a space, or a value that is not a string is invalid-dissector. dissector: on any other type is incompatible-display.

Filter names

Every Field the tree shows, structures included, gets the display filter name <protocol>.<path>, where the path is the chain of Field names from the top level down, through inline structures and Fields of a Type, never through Type names. In the example above they are demo.msg_type, demo.header, demo.header.length, demo.header.flags, demo.header.flags.urgent, demo.header.flags.priority and demo.payload. A filter on a structure, such as demo.header.flags, matches every packet that has it. The sub-Fields of a bitfield extend their container’s name: demo.flags.ext. The cases of a switch add no segment, so Fields of two cases can reach one filter name and share it.

Filter names are part of a Dissector’s behaviour: users save filters and colouring rules against them. Renaming a Field, or moving it into or out of a structure, changes its filter name, and so breaks those filters. Wirdigen never renames a Field on its own: the filter name is always the one the description spells.

Sizes

A Field of a fixed-size built-in type (uint16, ipv4, abs_time, …) knows how many bytes it reads. A string or bytes Field does not: it says where its value ends with exactly one of these keys.

KeyThe value ends
size: <n>after n bytes: a constant of zero or more, or an Expression
size: "_remaining"at the end of the message
prefix: <type>after as many bytes as the unsigned integer just before it says
terminator: <byte>before the first byte of that value
name: chat
fields:
  - { name: room, type: string, size: 8 }
  - { name: nick, type: string, prefix: uint8 }
  - { name: client, type: string, terminator: 0 }
  - { name: digest, type: bytes, size: 16, display: colon }
  - { name: extension, type: bytes, prefix: uint32 }

size:

size: is a number of bytes: a YAML integer, or an Expression written as a string. An Expression can read Fields read earlier by name (see References), so a length carried in a header is written as its name.

name: chat
fields:
  - { name: length, type: uint16 }
  - { name: text, type: string, size: length }
  - { name: padding, type: bytes, size: "(4 - length % 4) % 4" }
  - { name: header, type: bytes, size: "4 * 6 + 2" }

A negative constant is invalid-size, and so is a constant Expression that is negative, divides by zero or shifts by a count outside 0 to 63.

name: demo
fields: [ {name: data, type: bytes, size: "2 - 4"} ]

A count: on an array and the amount of a padding follow the same rules as a size:.

size: "_remaining"

_remaining is the built-in holding the number of bytes left in the message, so size: "_remaining" reads everything up to its end: a trailing payload, or a blob the description does not break down.

name: demo
fields:
  - { name: kind, type: uint8 }
  - { name: payload, type: bytes, size: "_remaining" }

A Field after it, in the same structure or after the structure holding it, can only be empty or truncated, which is the warning unreachable-field.

name: demo
fields:
  - { name: body, type: bytes, size: "_remaining" }
  - { name: checksum, type: uint16 }

When the size: "_remaining" Field is under if:, the Field after it is read whenever the condition is false, so it is not unreachable-field.

name: demo
fields:
  - { name: flags, type: uint8 }
  - { name: body, type: bytes, size: "_remaining", if: "flags & 1" }
  - { name: checksum, type: uint16 }

prefix:

prefix: names the unsigned integer type, uint8 to uint64, read just before the value and giving its length in bytes. The count is read in the Field’s byte order.

name: chat
endian: little
fields:
  - { name: nick, type: string, prefix: uint8 }
  - { name: text, type: string, prefix: uint16 }

Any other prefix: is invalid-prefix.

name: demo
fields: [ {name: user, type: string, prefix: int16} ]

terminator:

terminator: is a byte value, 0 to 255: the value runs up to the first byte equal to it. The terminator is read, but is not part of the value. terminator: 0 reads a NUL-terminated string.

name: files
fields:
  - { name: path, type: string, terminator: 0 }
  - { name: line, type: string, terminator: 10 }

A utf16 or ucs2 string (see Strings and bytes) ends at a 2-byte zero aligned on its 2-byte code units, so its terminator: can only be 0. A terminator outside 0 to 255, or other than 0 on those encodings, is invalid-terminator.

name: demo
fields: [ {name: user, type: string, encoding: utf16, terminator: 10} ]

In the packet

  • The tree highlights the value bytes only: the prefix: count and the terminator are read but not highlighted with the value.
  • When the packet ends before the value does, or before a terminator is found, the Dissector reports “Malformed: truncated” on that Field and stops, filtered as <protocol>._malformed.truncated.
  • A size: Expression that is negative, divides by zero or shifts by a count outside 0 to 63 in a packet is “Malformed”, filtered as <protocol>._malformed.expression (see In the packet).

Arrays

An array is a Field read several times in a row: a list of records, each laid out the same way. Its element is an inline structure or a Field of a Type, and one of two keys says how many elements there are:

KeyElements
count: <Expression>as many as the Expression gives, or a constant
repeat: to_endas many as fit, until the message ends
name: demo
fields:
  - { name: n, type: uint8 }
  - name: items
    count: n
    fields:
      - { name: id, type: uint16 }
      - { name: len, type: uint8 }
      - { name: data, type: bytes, size: len }
  - name: corners
    count: 4
    type: Point
types:
  Point:
    fields:
      - { name: x, type: int16 }
      - { name: y, type: int16 }

Here items holds n records, each with its own length, and corners four points.

Elements in the tree

Each element is its own subtree item, labelled with the Field’s label and the element’s index from 0: “Items [0]”, “Items [1]”, and so on. There is no item for the array as a whole.

All the elements share the array’s filter names: demo.items.id matches the id of every element, as Wireshark matches every occurrence of a field in a packet.

count:

count: is a constant or an Expression over the Fields read before the array, written like a size:. It is computed once, before the first element.

  • A constant count: that is negative, divides by zero or shifts by a count outside 0 to 63 is invalid-count.
  • In a packet, a count that is negative or has no value adds a “Malformed” expert info error on the array and stops the dissection, filtered as <protocol>._malformed.expression.
  • A count larger than the packet holds is a truncation: the element that does not fit is “Malformed: truncated”, as for any Field.
name: demo
fields:
  - name: items
    count: "2 - 4"
    fields: [ {name: id, type: uint8} ]

repeat: to_end

repeat: to_end reads elements until the message ends, as in a list of tag-length-value records filling the rest of a packet. The last element must end exactly with the message, or it is truncated.

name: demo
fields:
  - { name: version, type: uint8 }
  - name: options
    repeat: to_end
    fields:
      - { name: tag, type: uint8 }
      - { name: len, type: uint8 }
      - { name: value, type: bytes, size: len }

A Field after a repeat: to_end array, in the same structure or after the structure holding it, can only be empty or truncated, which is the warning unreachable-field.

Elements that read nothing

An element that reads no bytes would repeat forever without moving through the packet, so the Dissector stops the array there with a “Malformed: empty element” expert info error, whatever the count, filtered as <protocol>._malformed.empty_element. It happens only when every Field of the element can be empty, such as a bytes Field whose size is 0 in the packet.

Rules

  • count: and repeat: together are conflicting-repeat, and a repeat: other than to_end is invalid-repeat.
  • Only an inline structure or a Field of a Type repeats: count: or repeat: on a Field of a built-in type is invalid-array. Put the value in a one-Field structure instead.
  • A Field inside an element can read the Fields before it in the same element, and the Fields read before the array. Nothing outside an element can read inside it: items.len after items is unknown-field, since there is one len per element.
name: demo
fields:
  - { name: ids, type: uint16, count: 4 }
name: demo
fields:
  - name: ids
    count: 4
    fields: [ {name: id, type: uint16} ]

Bitfields

A bitfield is an unsigned integer Field split into sub-Fields of a few bits each, as protocol headers pack flags and small numbers into one byte or word. Its bits: lists the sub-Fields by width, most significant bit first, and Wirdigen computes each one’s mask.

name: demo
fields:
  - name: flags
    type: uint8
    bits:
      - { name: version, width: 3 }
      - { padding: 1 }
      - { name: ext, width: 1 }
      - { name: kind, width: 3 }

Here version is the top three bits (mask 0xE0), one bit is unused, ext is the next bit (0x08) and kind the three lowest bits (0x07). The tree shows flags as a number with a subtree holding version, ext and kind, each with its bits marked, as Wireshark shows the flags of IP or TCP.

The container

  • bits: goes only on a Field of a fixed-size unsigned integer type, uint8 to uint64 (invalid-bits). The container is read and shown like any unsigned integer, with its own display:, values:, label: and endian:.
  • Every bit is accounted for: the widths, padding included, must add up to the bits of the container, 8 for a uint8, 16 for a uint16, and so on (mismatched-bit-widths). Each width is at least 1 (invalid-bit-width).
  • { padding: n } covers n bits nothing names. It adds nothing to the tree and has no filter name.
  • Bits are counted on the container’s value, after its byte order: in a little-endian uint16, the first sub-Field is still the most significant bits of the number.
name: demo
fields:
  - name: control
    type: uint16
    endian: little
    display: hex
    bits:
      - { name: channel, width: 4 }
      - { padding: 4 }
      - { name: level, width: 8 }

Sub-Fields

A sub-Field takes name: and width:, both required, and optionally display:, values:, unit:, true:, false:, hidden:, label: and description:. Its name follows the rule of Field names, and two sub-Fields of one bitfield need different names.

  • A 1-bit sub-Field is a boolean, shown as “Set” or “Not set”. true: and false: replace those labels.
  • A wider sub-Field is an unsigned integer of its width. It takes the display: of an unsigned integer, and values: (an inline table or an Enum) or unit:, as described in Value mappings. A key that does not fit in the sub-Field’s width is the warning unreachable-value.
  • A 1-bit sub-Field with values:, unit: or display: is an unsigned integer too, holding 0 or 1.
  • There are no signed sub-Fields.
name: demo
enums:
  Priority: { 0: Low, 1: Normal, 2: High, 3: Urgent }
fields:
  - name: header
    type: uint16
    bits:
      - { name: ack, width: 1, true: Acknowledged, false: Pending }
      - { name: priority, width: 2, values: Priority }
      - { name: retries, width: 5, unit: [try, tries] }
      - { name: ttl, width: 8, display: hex, label: Time to live }

A sub-Field also takes expect:, checked against the values its width holds: 0 to 3 for a 2-bit sub-Field, 0 or 1 for a 1-bit one. Any other key on a sub-Field is unknown-key.

Hidden bitfields

hidden: true on the container leaves it and all its sub-Fields out of the tree. On a sub-Field it leaves out that sub-Field only. Hidden items are still read: Expressions can use them and display filters still match them. Any other Field can be hidden the same way.

name: demo
fields:
  - name: options
    type: uint8
    hidden: true
    bits:
      - { name: has_trailer, width: 1 }
      - { name: reserved, width: 7, hidden: true }
  - { name: body, type: bytes, size: "_remaining" }

Filter names and Expressions

Each sub-Field extends the filter name of its container: the first example gives demo.flags, demo.flags.version, demo.flags.ext and demo.flags.kind. A boolean sub-Field can be filtered on by name alone (demo.flags.ext), or compared to 1 or 0.

Expressions read a sub-Field with a dotted path from its container, as they read into a structure: flags.ext is 1 or 0, flags.kind the number in its three bits.

name: demo
fields:
  - name: flags
    type: uint8
    bits:
      - { name: has_checksum, width: 1 }
      - { name: option_words, width: 7 }
  - { name: options, type: bytes, size: "flags.option_words * 4" }
  - { name: checksum, type: bytes, size: "flags.has_checksum * 2" }

A bare sub-Field name such as option_words is not a Field of the structure, so it is unknown-field: always write the container first.

if and switch

Some Fields are in a message only sometimes: an extension present when a flag is set, a body whose layout depends on a Field of the header. if: reads a Field only under a condition; switch: picks one layout among several.

if:

if: <Expression> reads the Field only when the Expression is not zero. Otherwise the Field is skipped: it reads no bytes and adds nothing to the tree.

name: demo
fields:
  - { name: flags, type: uint8 }
  - { name: session, type: uint32, if: "flags & 0x01" }
  - { name: checksum, type: uint16, if: "flags & 0x80 == 0x80" }
  - { name: payload, type: bytes, size: "_remaining" }

session is in the packet only when the lowest bit of flags is set, checksum only when the highest one is.

  • Any Field. if: goes on a Field of a built-in type, an inline structure, a Field of a Type, an array, and on the Fields inside a Type. On an array, the condition is computed first, and count: only when it is true.
  • C truthiness. Any value other than zero is true, negative values included. Comparisons, !, && and || give 1 or 0, so if: "len > 4" and if: "!(flags & 1)" read as they look.
  • A constant works too: if: 0 never reads the Field. A YAML true or false is wrong-value-type: write 1 or 0.
  • In the packet, a condition that divides by zero or shifts by a count outside 0 to 63 adds a “Malformed” expert info error on the Field and stops the dissection, as for any Expression. A negative condition is simply true.
  • A Field after a conditional size: "_remaining" Field or repeat: to_end array is reachable when the condition is false, so it is not unreachable-field.

Conditional scope

A Field under if: has a value only when its condition was true, so an Expression may read it only from inside the same conditional scope: inside the Field carrying the if:. Reading a conditional Field, or a Field inside a conditional structure or Type, from anywhere else is conditional-reference, reported at the reference.

Conditions are never compared: two Fields with the same if: are still in two scopes, so the second cannot read the first.

name: demo
fields:
  - { name: flags, type: uint8 }
  - { name: len, type: uint8, if: "flags & 1" }
  - { name: data, type: bytes, size: len, if: "flags & 1" }

The way out is an inline structure carrying the if:: inside it, its Fields read each other as usual, and its own if: is computed once.

name: demo
fields:
  - { name: flags, type: uint8 }
  - name: ext
    if: "flags & 1"
    fields:
      - { name: len, type: uint8 }
      - { name: data, type: bytes, size: len }

The rule follows the path: after ext above, ext.len is a conditional-reference too, and so is hdr.len when len is read under an if: inside the Type of hdr. The Fields of a switch case follow the same rule.

switch:

A switch Field reads one layout among several, picked by the value of an Expression, its subject. It is how a protocol with several kinds of message is described: a header saying which message follows, then a switch on it.

name: demo
fields:
  - { name: msg_type, type: uint8, values: MsgType }
  - name: body
    switch: msg_type
    cases:
      1: Login
      2:
        - { name: reason, type: uint8 }
      "16-31": Vendor
    default:
      - { name: unknown, type: bytes, size: "_remaining" }
types:
  Login:
    fields:
      - { name: user_id, type: uint32 }
      - { name: name, type: string, prefix: uint8 }
  Vendor:
    fields:
      - { name: code, type: uint16 }
enums:
  MsgType:
    1: Login
    2: Logout
    "16-31": Vendor
  • switch: is the subject: an Expression, or a constant, computed once before the cases. A subject that divides by zero or shifts out of range is “Malformed”, as for any Expression.
  • cases: maps values to layouts. A key is an integer or a "low-high" range string, as in a values table, and cases: needs at least one. Two cases matching a same value are overlapping-cases: the subject is a 64-bit signed value, so -1 and 18446744073709551615 are the same value there.
  • A case is the name of a Type, or a list of Fields spelled like an inline structure. A built-in type is not a case: wrap it in a list, [ { name: value, type: uint8 } ].
  • default:, optional, is read when no case matches. It is a Type or a list of Fields too.
  • No match and no default:: the rest of the message is shown raw as “Unmatched bytes” (filtered as <protocol>._unmatched) with an expert info note “No case for 7: body” (<protocol>._undecoded.unmatched), and the dissection stops there, since nothing says where the unknown layout ends. It is a note, not “Malformed”: the packet may be fine, only this description does not know it.

A switch Field takes name:, label:, description:, if:, hidden:, switch:, cases: and default: only. Any other key is an error under the name the key has elsewhere: values:, display:, expect: or dissector: is incompatible-display, size: unexpected-length, count: or repeat: invalid-array, endian: invalid-endian, bits: invalid-bits. A case is read in the byte order of the structure the switch is in, and a Type case in its own. cases: or default: without switch: is missing-field-kind, or conflicting-field-kind next to type: or fields:.

Tree and filter names

The switch Field is a subtree, like an inline structure, and the case it reads goes straight into it: a case adds no level to the tree and no segment to filter names. Above, the Login’s user_id is demo.body.user_id, not demo.body.Login.user_id.

The subtree item is named after the subject’s value: “Body: Login”. When the subject is a bare Field Path (msg_type, hdr.kind, flags.op) to a Field read in the same layout or Type, the name is that Field’s values: label, else the number; any other Expression ("kind & 0x0f"), or a path a Type reads from where it is used, shows the number: “Body: 7”. Without info:, the label of the outermost switch Field’s subject value is also what the Info column shows.

Two cases reaching one filter name share its ProtoField when the two Fields have the same type, display:, value mappings, label: and description:, so demo.body.user_id filters both a Login’s user_id and another message’s. When they differ, it is conflicting-filter-name: rename one, or make them match.

name: demo
fields:
  - { name: msg_type, type: uint8 }
  - name: body
    switch: msg_type
    cases:
      1: [ { name: id, type: uint32 } ]
      2: [ { name: id, type: uint16 } ]

Scope

A case is a conditional scope: its Fields have a value only when it matched. They read each other, and the Fields before the switch, as usual, but nothing outside the case can read them: body.reason after body is conditional-reference. What later Fields need belongs in the header before the switch, or inside each case.

Registration

Registration is how a Dissector attaches to traffic in Wireshark: the ports it claims by default, and its place in Decode As. registration: is optional; leaving it out means Decode As only.

name: demo
registration:
  ports:
    udp: [5000, "6000-6010"]
fields:
  - { name: id, type: uint8 }

Here Wireshark decodes UDP port 5000 and ports 6000 to 6010 as demo with no setup.

Ports

ports: declares the ports per transport, under udp:, tcp: or both. Each is a list whose items are a port or a "low-high" range, both bounds included, written like the ranges of values::

  • A port is a YAML integer from 1 to 65535: port 0 and larger numbers are invalid-port, and so is a range reaching them.
  • A range is a string of two integers with the lower one first; "6010-6000" is wrong-value-type, and so is a quoted single port such as "5000".
  • A port is declared once per transport: a port listed twice, spelt twice (5000 and 0x1388) or inside a range of the same list is overlapping-ports. The same port on UDP and on TCP is fine.
  • A transport is declared with at least one port: udp: [] is wrong-value-type. Leave the transport out instead.
name: demo
registration:
  ports:
    udp: [5000, "6000-6010"]
    tcp: [5000]
framing:
  header: 2
  length: "len + 2"
fields:
  - { name: len, type: uint16 }
  - { name: body, type: bytes, size: len }

TCP and Framing

On TCP, a message can be split across segments, and a segment can hold several messages. framing: tells the Dissector where each message ends. TCP ports without framing: are the warning tcp-without-framing: each segment is then dissected as one message, which is right only when every message travels in a segment of its own.

name: demo
registration:
  ports:
    tcp: [5000]
fields:
  - { name: id, type: uint8 }

Port preferences

Each transport with declared ports gets a preference of the protocol, listed in Wireshark’s preferences under the protocol’s title, which defaults to the declared ports:

TransportPreferenceLabel
UDP<name>.udp_portsUDP port(s)
TCP<name>.tcp_portsTCP port(s)

Changing a preference moves the Dissector: it stops claiming the old ports and claims the new ones. From the command line, tshark -o demo.udp_ports:7000-7005 does the same for one run. A transport with no declared ports has no preference.

Decode As

Every Dissector is offered in Wireshark’s Decode As, on both UDP and TCP ports, whether or not it declares ports. No key controls this. A description without registration: is used through Decode As only, or from the command line:

tshark -X lua_script:demo.lua -d udp.port==5000,demo

Framing

On TCP, a message can be split across segments, and a segment can hold several messages. Framing tells the Dissector where each message ends: a header of constant size, and the whole message’s length computed from it.

name: demo
framing:
  header: 4
  length: "len + 4"
fields:
  - { name: kind, type: uint16 }
  - { name: len, type: uint16 }
  - { name: body, type: bytes, size: len }

Here every message starts with 4 bytes, the last 2 of which give the length of what follows.

KeyValue
headerthe number of bytes the length is computed from: an integer of at least 1
lengththe whole message’s length, its header included: an integer, or an Expression

Both are required. A header below 1, or a constant length shorter than the header, is invalid-framing.

The header

The length is computed before the message is read, from its first header bytes alone. So length reads only top-level Fields, and the sub-Fields of top-level bitfields, that lie entirely within those bytes:

name: demo
framing:
  header: 2
  length: "flags.size + 2"
fields:
  - name: flags
    type: uint16
    bits:
      - { name: version, width: 4 }
      - { name: size, width: 12 }
  - { name: body, type: bytes, size: "flags.size" }

Each of these is invalid-framing:

  • a Field that ends after the header;
  • a Field under if:, or after a Field whose size is known only once it is read, whose place in the message is not fixed;
  • a Field inside an inline structure or a Type;
  • the built-ins _offset and _remaining.
name: demo
framing:
  header: 2
  length: "len + 4"
fields:
  - { name: kind, type: uint16 }
  - { name: len, type: uint16 }

A name that is no top-level Field is unknown-field, and a Field without an integer value is non-numeric-reference.

In the stream

Framing applies to TCP, through Registration or Decode As. Over UDP, each datagram is one message, as without framing:.

  • The Dissector reads the messages of a segment one after another, each under its own tree root. _offset and _remaining count from the start of the message, not of the segment.
  • A message that goes on past the segment waits for the next ones: Wireshark shows it in the packet where its last byte arrives. A segment holding only part of a message shows no message of its own.
  • When TCP reassembly is off (the TCP preference Allow subdissector to reassemble TCP streams), the end of the segment ends the last message, which is then reported truncated.
  • A length that is negative, below the header, or has no value (a division by zero, a shift outside 0 to 63) is a “Malformed” expert info error: the rest of the segment is shown as one malformed message.
  • With several messages in a packet, the Info column shows the last one’s, with only the Fields that message read. It replaces any text TCP reassembly fenced off, so the last message’s text stands alone even after a reassembled one.

Expressions

An Expression is a small formula that computes a number from constants and Fields read earlier: a size, a count, a condition or a switch subject. It is written as a YAML string.

name: demo
fields:
  - { name: header, type: bytes, size: "4 * 6 + 2" }
  - { name: count, type: uint8 }
  - { name: records, type: bytes, size: "count * 8" }

This version reads Expressions in size:, in the count: of an array, and in if:.

Writing an Expression in YAML

Quote every Expression with "...". Some unquoted ones would parse as YAML (4 * 6), but others would not: one starting with * or ! means something else in YAML, and # starts a comment. A plain YAML integer such as size: 16 is a constant, not an Expression.

Values

ValueExample
decimal integer42, 1_000
hexadecimal integer, 0x or 0X0x1F, 0xFFFF_0000
binary integer, 0b or 0B0b1010_0001
a Field read earlier, by its pathlength, header.length
a built-in_offset, _remaining
a parenthesized Expression(length + 4)
  • _ separates digits anywhere after the first one. There are no character literals and no strings.
  • A literal starting with 0 followed by more digits, such as 010, is leading-zero-literal: it would be octal in C, and Expressions have no octal.
  • A literal must fit in 64 bits. Above 0x7FFF_FFFF_FFFF_FFFF it wraps to a negative value, so 0xFFFF_FFFF_FFFF_FFFF is -1.
  • A name starting with _ is a built-in, which is why Field names cannot start with _. _offset is the number of bytes from the start of the message, and _remaining the number of bytes left in it.

Operators

From the tightest binding to the loosest:

OperatorsMeaning
! ~ - (unary)not (1 for zero, else 0), bitwise complement, negation
* / %multiplication, division, remainder
+ -addition, subtraction
<< >>shifts
&bitwise and
^bitwise exclusive or
|bitwise or
== != < <= > >=comparisons
&&logical and
||logical or

Operators of one row group from the left: a - b - c is (a - b) - c.

The order is Rust’s and Python’s, not C’s: bitwise operators bind tighter than comparisons, so a mask test means what it looks like. flags & 0x80 == 0x80 is (flags & 0x80) == 0x80, where C would read flags & (0x80 == 0x80).

Comparisons do not chain: a < b < c is chained-comparison. Write a < b && b < c, or (a < b) < c to compare the first result.

An Expression nests at most 64 levels deep. Each value, parenthesis and unary operator is a level, and so is each binary operator over its operands: x is 1 deep, -x and (x) are 2 deep, and a + a + … + a with 64 operands is 64 deep. A deeper Expression is expression-too-deep, because Lua could not load the Dissector it makes. No Expression written by hand comes close.

Any other mistake, such as a missing value or parenthesis or a character Expressions do not use, is expression-syntax, pointing at the token.

name: demo
fields: [ {name: data, type: bytes, size: "1 < 2 < 3"} ]

Arithmetic

Every value is a signed 64-bit integer, and the arithmetic is C’s:

  • / truncates toward zero and % takes the sign of the left side: -7 / 2 is -3 and -7 % 2 is -1. Lua’s own operators would give -4 and 1.
  • >> is arithmetic: it keeps the sign, so -8 >> 1 is -4.
  • Overflow wraps around: 0x7FFF_FFFF_FFFF_FFFF + 1 is the most negative value.
  • Comparisons, !, && and || give 1 or 0, and any value other than 0 counts as true.
  • && and || stop as soon as the result is known: in 0 && 1 / 0, the division is never done.
name: demo
fields:
  - { name: masked, type: bytes, size: "0x1234 & 0xF" }
  - { name: rounded, type: bytes, size: "(13 + 3) / 4 * 4" }
  - { name: either, type: bytes, size: "(2 > 1 || 0) + 1" }

A constant size: that is negative, divides by zero or shifts by a count outside 0 to 63 is invalid-size, and such a count: is invalid-count.

name: demo
fields: [ {name: data, type: bytes, size: "2 - 4"} ]

References

A name in an Expression reads the value of a Field read earlier in the packet.

  • Nearest first. A name is looked up among the earlier Fields of the structure the Expression is in, then among the earlier Fields of each enclosing structure, out to the top-level fields:. The nearest Field of that name wins.
  • Dotted paths go into a structure or a Field of a Type read earlier: hdr.len, request.header.flags, and into the sub-Fields of a bitfield: flags.ext.
  • Only earlier Fields. A Field read later, or the Field the Expression belongs to, is forward-reference. A name that matches nothing is unknown-field, and so is a path into the structure still being read: inside hdr, write len, not hdr.len.
  • Not into arrays. A Field inside an element of an array can be read only from inside that element: after items, items.len is unknown-field, since each element has its own len.
  • Not into conditionals. A Field under if:, or inside one, can be read only from inside the Field carrying the if:; from anywhere else it is conditional-reference.
  • Only numbers. Integer and bool Fields and bitfield sub-Fields can be read; a bool or a boolean sub-Field reads as 1 or 0. A string, bytes, float, address, timestamp or structure is non-numeric-reference.
name: demo
fields:
  - { name: length, type: uint8 }
  - name: header
    fields:
      - { name: length, type: uint16 }
      - { name: compressed, type: bool }
      - { name: options, type: bytes, size: "length - 4" }
  - { name: body, type: bytes, size: "header.length * (header.compressed + 1)" }
  - { name: trailer, type: bytes, size: length }

Here options reads header.length, the nearest length, and trailer reads the top-level one.

Inside a Type

A Type can read its own Fields, and also names it does not declare. Those are resolved at each place the Type is used, in the scope of that use, so one Type can read a different Field at each use. An error is reported at the use that cannot resolve the name, with a note pointing at the name in the Type.

name: demo
fields:
  - { name: size, type: uint8 }
  - { name: request, type: Block }
  - name: reply
    fields:
      - { name: size, type: uint16 }
      - { name: block, type: Block }
types:
  Block:
    fields:
      - { name: kind, type: uint8 }
      - { name: data, type: bytes, size: "size - 1" }

request.data reads the top-level size, and reply.block.data reads reply.size.

Built-ins

Built-inValue
_offsetthe number of bytes from the start of the message to the Field being read
_remainingthe number of bytes left in the message from the Field being read

size: "_remaining" reads everything left (see Sizes). Under Framing, the message is the one Framing cut out of the TCP stream, so both count from its start.

name: demo
fields:
  - { name: kind, type: uint8 }
  - { name: align, type: bytes, size: "(4 - _offset % 4) % 4" }
  - { name: payload, type: bytes, size: "_remaining" }

In the packet

An Expression that reads Fields is computed when the packet is read, with the arithmetic above. A Field value is a signed 64-bit integer, so a uint64 above 0x7FFF_FFFF_FFFF_FFFF reads as a negative number.

When the value cannot be used, the Dissector shows what it read so far, adds a “Malformed” expert info error on the Field, filtered as <protocol>._malformed.expression, and stops:

  • a division or remainder by zero;
  • a shift by a count outside 0 to 63;
  • a negative size or count, which includes a uint64 above 0x7FFF_FFFF_FFFF_FFFF.

A size or count larger than what is left of the packet is a truncation, as for any Field that does not fit: “Malformed: truncated”, filtered as <protocol>._malformed.truncated.

Info column

Wireshark’s packet list shows a one-line summary of each packet in its Info column. info: fills it from a template naming Fields of the packet:

name: demo
info: "{msg_type} id={id}"
fields:
  - { name: msg_type, type: uint8, values: { 1: Request, 2: Response } }
  - { name: id, type: uint16, display: hex }

A request with id 0x002a shows “Request id=0x002a”. The column is set once the Dissector has read the message, however far it got. The Protocol column always shows the protocol’s short name, the uppercase name:.

Templates

A template is text with Field Paths in braces:

  • {path} shows a Field. The path is the Field’s name, then the names down into inline structures, Types, switch cases and bitfields, as in its filter name: {msg_type}, {header.seq}, {flags.ack}, {body.user_id}.
  • {{ and }} are a literal { and }: "{{{id}}}" shows {42}.

Braces hold a Field Path and nothing more. An Expression ({len + 4}), a format specifier ({id:04x}) or an empty {} is invalid-info, as is a brace that pairs with nothing, and a template on several lines. To change how a number looks, give its Field a display:.

What a Field shows

The FieldShows
An integer with values:, or a sub-Field with themThe label of its value, or the number when no label matches.
A switch FieldThe name of its case, as in its tree item: “Login”, or the number.
Any other FieldIts value as Wireshark displays it: with its display:, its unit, its true:/false: label, a string’s text, an address.
A Field that was not readNothing.

Any Field of a built-in type can be referenced, hidden ones included, and so can a bitfield sub-Field and a switch Field:

name: demo
info: "{kind} {flags.prio} from {source} ({body})"
fields:
  - { name: kind, type: uint8, values: Kind }
  - name: flags
    type: uint8
    bits:
      - { name: prio, width: 2, values: { 0: low, 3: high } }
      - { padding: 6 }
  - { name: source, type: ipv4 }
  - name: body
    switch: kind
    cases:
      1: [ { name: user, type: string, prefix: uint8 } ]
      2: [ { name: code, type: uint16 } ]
enums:
  Kind:
    1: Login
    2: Error

Unlike an Expression, a template can reach into an if: Field or a switch case: the column is set after the whole message, so a Field that was not read, being under a false if:, in another case, or after the end of a truncated packet, shows nothing. Above, {body.code} would be empty in a Login.

A path is resolved from the top-level fields:. One that names no Field is unknown-field, and so is one going into an array: an array has a value per element, and the column shows one. A path ending on an inline structure, a Field of a Type or an array has no value of its own to show: it is invalid-info.

name: demo
info: "{header}"
fields:
  - name: header
    fields: [ { name: seq, type: uint16 } ]

Without info:

Without info:, the Info column shows the label of the outermost switch Field’s subject value, the way a protocol with several kinds of message names each one: “Login”, “Error”. The outermost is the switch Field with the fewest structures and Types around it, the first one in the layout among equals; a switch inside an array is never picked. When that switch Field is not read, or there is none, the column keeps what Wireshark’s UDP or TCP layer wrote.

Limits

What Wirdigen cannot describe, and what happens when a description runs into it. Each entry says what the limit is and what you see when you reach it, and links to the section or the Diagnostic with the details.

Size and depth

  • An Expression nests at most 64 levels deep. A deeper one is expression-too-deep: Lua could not load the Dissector it makes. See Operators for how levels count.
  • A Field is at most 64 deep, counted through every Type it is reached by: at most 64 names lie between the protocol’s and its own in its filter name. A deeper Field is field-too-deep.
  • YAML nests at most 256 levels, anywhere in the file. A deeper node is yaml-too-deep. A description within the Field limit never comes near it.
  • There is no limit on size. A description can have any number of Fields, Types and Enums: one of 1,000 Fields, or of 500 Types used side by side, loads and dissects in tshark.

The YAML subset

A Protocol Description is written in a subset of YAML 1.2. Fields are reused through Types, not through YAML’s own reuse features.

Expressions and references

Expressions do integer arithmetic on Fields read earlier, and nothing more.

  • Only Fields read earlier. A Field read later, or the Expression’s own Field, is forward-reference. See References.
  • Not into arrays. A Field inside an array element can be read only from inside that element; from outside it is unknown-field. There is no indexing (items[0]) and no _index, both expression-syntax.
  • Not into conditionals. A Field under if: or in a switch case can be read only from inside it; from outside it is conditional-reference, even under an identical condition.
  • Only numbers. Integer and bool Fields and bitfield sub-Fields can be read. A string, bytes, float, address, timestamp or structure is non-numeric-reference.
  • No strings, labels, ?: or function calls. A string literal, a ?: or a call is expression-syntax. An Expression cannot compare a Field with one of its values: labels: a label in an Expression is read as a Field name, so it is unknown-field. Compare with the number instead.
  • Framing’s length reads only the header. It reads top-level Fields, and their bitfield sub-Fields, at a fixed place entirely in the first header bytes, and not _offset or _remaining. A Field under if:, after a Field of variable size, or inside a structure is invalid-framing too. See The header.
  • The Info Template takes Field Paths only. No Expressions or format specifiers in braces: those are invalid-info. See Templates. info: is top-level only: on a Type it is unknown-key.

Wireshark

  • Lua Dissectors for Wireshark 4.4 and later. Wirdigen generates a Lua file and nothing else, no C plugin. Loaded into an older Wireshark, the Dissector stops with an error naming the version it found. See Installing a Dissector.
  • A Lua error at load time does not fail tshark. tshark prints it on stderr, reads the capture without the Dissector and exits 0. See Troubleshooting.
  • Wireshark shows a tree at most 500 levels deep (the gui.max_tree_depth preference). No description reaches it: the Field depth limit keeps a Dissector’s own tree far below 500 levels, so the preference never needs raising for Wirdigen.

Not in v1

These are not supported yet, but can come in a later 1.x release. Until then, writing one is an error, most often unknown-key, unknown-type or expression-syntax.

  • Layout: repeating until a condition (only count: and repeat: to_end; repeat: { until: … } is invalid-repeat), align:, a byte order chosen at runtime, computed Fields, and checksum verification.
  • Framing: messages ended by a delimiter rather than a length.
  • Handoff: choosing the next dissector from a Field’s value or through a dissector table; dissector: names one dissector.
  • Expressions: strings, ?:, function calls and array indexing.
  • Info column: a per-Type info:.
  • Registration: heuristic dissectors, and dissector tables other than UDP and TCP ports (ethertype, ip.proto, sctp.ppi, …). See Registration.
  • Built-in types: char, framenum, protocol, none, ipx, oid, rel_oid and systemid, and signed bitfield sub-Fields.

Diagnostics

A Diagnostic is an error or a warning that Wirdigen reports about a Protocol Description. Each one has a stable kebab-case name and points at where in the description it applies:

warning[unknown-allow]: there is no warning named `bogus`
 --> demo.wirdigen.yaml:3:9
  |
3 | allow: [bogus]
  |         ^^^^^
  |
  = note: see https://cerclique.github.io/wirdigen/diagnostics.html#unknown-allow

The last note links to the Diagnostic’s entry in the Diagnostics index, which explains what it means and how to fix it.

Errors and warnings

  • An error means the description has no single meaning or contradicts itself. No Dissector is generated.
  • A warning means the meaning is clear but probably a mistake. The Dissector is generated anyway.

Checks run in stages: YAML parsing, then the keys and the kinds of their values, then the meaning of the description. Each stage reports all its errors, and the next one runs only if there were none, so fixing errors can reveal new ones.

Silencing warnings

The top-level allow: lists the names of the warnings to silence for the whole description. Errors cannot be silenced. Naming something that is not a warning is itself the warning unknown-allow, which allow: can silence too:

name: demo
fields:
  - { name: id, type: uint8 }
allow: [unknown-allow, a-warning-from-a-newer-wirdigen]

Stability

Diagnostic names and severities are stable: a later 1.x release never renames a Diagnostic nor turns a warning into an error. It can add new warnings, though, so a build that fails on any warning can start failing after an upgrade. The message wording, the notes and the layout of the rendered text can change in any release.

Diagnostics index

One entry per Diagnostic, in alphabetical order, under the name Wirdigen prints in brackets (error[unknown-key]) and links to at the end of each message. See Diagnostics for how errors, warnings and allow: work.

Errors cannot be silenced: fix the description. Warnings can be fixed, or silenced by adding their name to the top-level allow: list.

chained-comparison

Severity: error

Two comparisons follow each other without parentheses, as in a < b < c. Comparisons do not chain: in C, 1 < 3 < 2 compares the 1 of 1 < 3 with 2, which is rarely what was meant. The error points at the second comparison.

name: demo
fields: [ {name: data, type: bytes, size: "1 < 2 < 3"} ]

Fix: join the two comparisons with &&, as in a < b && b < c, or add parentheses to compare the 1 or 0 of the first: (a < b) < c.

conditional-reference

Severity: error

An Expression reads a Field that is read only under an if: or in a switch case, or a Field inside one, from outside that if: or case. When the condition is false, or another case matched, the Field has no value. Two if: with the same condition still count as different: conditions are never compared.

name: demo
fields:
  - { name: flags, type: uint8 }
  - { name: len, type: uint8, if: "flags & 1" }
  - { name: data, type: bytes, size: len, if: "flags & 1" }

Fix: put the Field and everything that reads it in one inline structure carrying the if::

name: demo
fields:
  - { name: flags, type: uint8 }
  - name: ext
    if: "flags & 1"
    fields:
      - { name: len, type: uint8 }
      - { name: data, type: bytes, size: len }

conflicting-field-kind

Severity: error

A Field has more than one of type:, fields: and switch:, so it has no single meaning. A note points at the first of them.

name: demo
fields:
  - { name: id, type: uint8, fields: [ {name: low, type: uint8} ] }

Fix: keep one. To group Fields under a name, use fields: alone.

conflicting-filter-name

Severity: error

Two Fields reach one filter name with ProtoFields that differ in type, display:, value labels, label: or description:. The cases of a switch add no segment to filter names, so a Field of one case and a Field of the same name in another reach the same name, and Wireshark can register only one ProtoField under it. Wirdigen never renames a Field on its own: filter names are what the description spells.

name: demo
fields:
  - { name: kind, type: uint8 }
  - name: body
    switch: kind
    cases:
      1: [ { name: id, type: uint32 } ]
      2: [ { name: id, type: uint16, label: Short id } ]

Fix: rename one of the Fields, or make them match so they share the ProtoField.

conflicting-length

Severity: error

A Field has more than one of size:, prefix: and terminator:, so its length has no single meaning. A note points at the first of them.

name: demo
fields: [ {name: user, type: string, size: 8, terminator: 0} ]

Fix: keep the one key that says where the value ends.

conflicting-mappings

Severity: error

A Field has both values: and unit:. Wireshark shows either a label in place of the value or a unit after it, never both.

name: demo
fields:
  - name: length
    type: uint16
    values: { 0: Empty }
    unit: [byte, bytes]

Fix: keep one of them. A label for a special value can go in the Field’s description:.

conflicting-repeat

Severity: error

A Field has both count: and repeat:, so the number of elements of the array has no single meaning. A note points at count:.

name: demo
fields:
  - name: items
    count: 4
    repeat: to_end
    fields: [ {name: id, type: uint8} ]

Fix: keep count: when the number of elements is known before the array, or repeat: to_end when the elements fill the rest of the message.

duplicate-field-name

Severity: error

Two Fields of the same structure share a name, so their filter name and any reference to them would be ambiguous. A note points at the first one.

name: demo
fields:
  - { name: id, type: uint8 }
  - { name: id, type: uint16 }

Fix: rename one of them.

duplicate-key

Severity: error

A key appears twice in the same mapping, so the description has no single meaning. A note points at the first occurrence.

name: demo
name: other
fields: [ {name: a, type: uint8} ]

Fix: keep one of the two.

empty-fields

Severity: error

The top-level fields: list is empty: a protocol must declare at least one Field. The same holds for the fields: of an inline structure.

name: demo
fields: []

Fix: declare the Fields of the payload.

expression-syntax

Severity: error

An Expression cannot be read: a missing or extra value, operator or parenthesis, a character Expressions do not use (such as = or a quote), a malformed or oversized integer literal, a built-in other than _offset and _remaining, or a Field Path with an empty segment. The error points at the offending token; in an escaped or multi-line YAML string, at the whole value. Only the first error of each Expression is reported.

name: demo
fields: [ {name: data, type: bytes, size: "(4 + 2"} ]

Fix: correct the Expression, here by closing the parenthesis: "(4 + 2)".

expression-too-deep

Severity: error

An Expression nests more than 64 levels deep. Each value, parenthesis and unary operator is a level, and so is each binary operator over its operands, so a flat chain such as 1+1+…+1 of 65 operands is 65 deep. Lua cannot load the Dissector such an Expression would make. The error points at the token that reaches depth 65.

name: demo
fields:
  - name: data
    type: bytes
    size: "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1"

Fix: make the Expression shallower. Group a long chain with parentheses, as (1+1+…) + (1+1+…), which is about half as deep, and remove parentheses that change nothing.

field-too-deep

Severity: error

A Field is more than 64 deep: more than 64 Fields enclose it, counted through every Type it is reached by. An inline structure, an array, a switch Field, a bitfield (for its sub-Fields) and a Field of a Type each add one level; a switch case adds none. That makes 64 the most names between the protocol’s and the Field’s own in its filter name. The error points at each Field that is the first past 64 on its path, once however many uses of a Type take it there, and names a filter name that reaches it; the Fields under it are not reported.

name: demo
fields: [ { name: t, type: T1 } ]
types:
  T1: { fields: [ { name: next, type: T2 } ] }
  T2: { fields: [ { name: next, type: T3 } ] }
  T3: { fields: [ { name: next, type: T4 } ] }
  T4: { fields: [ { name: next, type: T5 } ] }
  T5: { fields: [ { name: next, type: T6 } ] }
  T6: { fields: [ { name: next, type: T7 } ] }
  T7: { fields: [ { name: next, type: T8 } ] }
  T8: { fields: [ { name: next, type: T9 } ] }
  T9: { fields: [ { name: next, type: T10 } ] }
  T10: { fields: [ { name: next, type: T11 } ] }
  T11: { fields: [ { name: next, type: T12 } ] }
  T12: { fields: [ { name: next, type: T13 } ] }
  T13: { fields: [ { name: next, type: T14 } ] }
  T14: { fields: [ { name: next, type: T15 } ] }
  T15: { fields: [ { name: next, type: T16 } ] }
  T16: { fields: [ { name: next, type: T17 } ] }
  T17: { fields: [ { name: next, type: T18 } ] }
  T18: { fields: [ { name: next, type: T19 } ] }
  T19: { fields: [ { name: next, type: T20 } ] }
  T20: { fields: [ { name: next, type: T21 } ] }
  T21: { fields: [ { name: next, type: T22 } ] }
  T22: { fields: [ { name: next, type: T23 } ] }
  T23: { fields: [ { name: next, type: T24 } ] }
  T24: { fields: [ { name: next, type: T25 } ] }
  T25: { fields: [ { name: next, type: T26 } ] }
  T26: { fields: [ { name: next, type: T27 } ] }
  T27: { fields: [ { name: next, type: T28 } ] }
  T28: { fields: [ { name: next, type: T29 } ] }
  T29: { fields: [ { name: next, type: T30 } ] }
  T30: { fields: [ { name: next, type: T31 } ] }
  T31: { fields: [ { name: next, type: T32 } ] }
  T32: { fields: [ { name: next, type: T33 } ] }
  T33: { fields: [ { name: next, type: T34 } ] }
  T34: { fields: [ { name: next, type: T35 } ] }
  T35: { fields: [ { name: next, type: T36 } ] }
  T36: { fields: [ { name: next, type: T37 } ] }
  T37: { fields: [ { name: next, type: T38 } ] }
  T38: { fields: [ { name: next, type: T39 } ] }
  T39: { fields: [ { name: next, type: T40 } ] }
  T40: { fields: [ { name: next, type: T41 } ] }
  T41: { fields: [ { name: next, type: T42 } ] }
  T42: { fields: [ { name: next, type: T43 } ] }
  T43: { fields: [ { name: next, type: T44 } ] }
  T44: { fields: [ { name: next, type: T45 } ] }
  T45: { fields: [ { name: next, type: T46 } ] }
  T46: { fields: [ { name: next, type: T47 } ] }
  T47: { fields: [ { name: next, type: T48 } ] }
  T48: { fields: [ { name: next, type: T49 } ] }
  T49: { fields: [ { name: next, type: T50 } ] }
  T50: { fields: [ { name: next, type: T51 } ] }
  T51: { fields: [ { name: next, type: T52 } ] }
  T52: { fields: [ { name: next, type: T53 } ] }
  T53: { fields: [ { name: next, type: T54 } ] }
  T54: { fields: [ { name: next, type: T55 } ] }
  T55: { fields: [ { name: next, type: T56 } ] }
  T56: { fields: [ { name: next, type: T57 } ] }
  T57: { fields: [ { name: next, type: T58 } ] }
  T58: { fields: [ { name: next, type: T59 } ] }
  T59: { fields: [ { name: next, type: T60 } ] }
  T60: { fields: [ { name: next, type: T61 } ] }
  T61: { fields: [ { name: next, type: T62 } ] }
  T62: { fields: [ { name: next, type: T63 } ] }
  T63: { fields: [ { name: next, type: T64 } ] }
  T64: { fields: [ { name: next, type: T65 } ] }
  T65: { fields: [ { name: x, type: uint8 } ] }

Fix: flatten the layout: move the Field, or a Field enclosing it, closer to the top level, for example by reading records that each hold the next as an array of one Type.

forward-reference

Severity: error

An Expression reads a Field that is read only after it, or reads its own Field. A Dissector reads a packet in order, so the value does not exist yet. A note points at the later Field.

name: demo
fields:
  - { name: data, type: bytes, size: length }
  - { name: length, type: uint8 }

Fix: move the Field that is read before the Field that reads it.

incompatible-display

Severity: error

A Field’s display: or encoding: is not one its type takes, or the Field has a value-mapping key its type does not take. Unsigned integers take dec, hex, oct, dec_hex and hex_dec; signed integers are shown only as dec; bytes take plain, dot, dash, colon and space; abs_time takes local, utc and doy_utc; string, rel_time, bool, the floats and the address types take no display: at all. Only string, abs_time and rel_time take encoding:, each its own values: ntp is an abs_time encoding only. Only integers take values:, only bool takes true: and false:, only integers and floats take unit:, and only bytes take dissector:. An inline structure takes none of these keys: they belong on the Fields inside it. A bitfield sub-Field takes the displays of an unsigned integer, and true: and false: only when it is boolean: 1 bit wide, without values:, unit: or display:.

name: demo
fields: [ {name: offset, type: int16, display: hex} ]

Fix: pick a value from the table in Fields, or remove display: to use the type’s default. A signed value shown in hex needs an unsigned type. The encodings are listed in Strings and bytes and Timestamps, and the value mappings in Value mappings.

invalid-array

Severity: error

A Field of a built-in type has count: or repeat:. Only an inline structure or a Field of a Type repeats, so that each element is a subtree item of its own.

name: demo
fields:
  - { name: ids, type: uint16, count: 4 }

Fix: put the value in an inline structure that repeats:

name: demo
fields:
  - name: ids
    count: 4
    fields: [ {name: id, type: uint16} ]

See Arrays.

invalid-bit-width

Severity: error

A sub-Field or a { padding: n } entry of bits: is less than 1 bit wide.

name: demo
fields:
  - name: flags
    type: uint8
    bits:
      - { name: version, width: 0 }
      - { name: rest, width: 8 }

Fix: give the width in bits, at least 1, or remove an entry that takes no bits.

invalid-bits

Severity: error

A Field with bits: is not a fixed-size unsigned integer. Only uint8 to uint64 Fields can be split into sub-Fields: not a signed integer, bytes, an inline structure or a Field of a Type.

name: demo
fields:
  - name: flags
    type: int8
    bits: [ { name: low, width: 8 } ]

Fix: give the bitfield an unsigned integer type as wide as its sub-Fields, here uint8. See Bitfields.

invalid-count

Severity: error

A constant count: is a negative number of elements, or an Expression that has no value: it divides by zero, or shifts by a count outside 0 to 63. The error points at the dividing or shifting operator.

name: demo
fields:
  - name: items
    count: -1
    fields: [ {name: id, type: uint8} ]

Fix: write the number of elements, zero or more.

invalid-description

Severity: error

A Field’s description: spans several lines or is not a string. Wireshark shows it on one line, in the status bar and the field reference.

name: demo
fields:
  - { name: id, type: uint8, description: "Identifies\nthe request" }

Fix: write the description on one line, or quote a value YAML reads as a number or a bool.

invalid-dissector

Severity: error

A Field’s dissector: is not the name of a Dissector: it is empty, has a space in it, or is not a string. A dissector name is one word, as Wireshark registers it. Whether Wireshark has a dissector by that name is only known when a packet is read, where an unknown one is a warning in the tree.

name: demo
fields:
  - { name: payload, type: bytes, size: 8, dissector: "" }

Fix: write the name Wireshark registers the dissector under, such as json or data. tshark -G dissectors lists them.

invalid-endian

Severity: error

An endian: value, at the top level, on a Type or on a Field, is not a byte order. Byte order is big or little, never encoded in a type name.

name: demo
endian: network
fields: [ {name: id, type: uint16} ]

Fix: write big or little, or leave endian: out for big-endian.

It is also reported for endian: on a Field of a Type: a Type is read in its own byte order, whichever Field uses it.

name: demo
fields:
  - { name: hdr, type: Header, endian: little }
types:
  Header:
    fields: [ {name: length, type: uint16} ]

Fix: set endian: on the Type, or on the Fields inside it.

invalid-field-name

Severity: error

A Field’s name: is not a lowercase letter followed by lowercase letters, digits or _. Names appear bare in filters and Expressions, so - and . are refused, and a leading _ is kept for Wirdigen’s built-ins.

name: demo
fields: [ {name: msgType, type: uint8} ]

Fix: rename the Field, here msg_type. Its tree label is derived from the name (“Msg type”).

invalid-framing

Severity: error

framing: cannot find a Message’s length from its header alone: its header is below 1, a constant length is shorter than the header, or the length Expression reads _offset, _remaining, a Field inside a structure, or a top-level Field that does not lie entirely within the first header bytes (because it ends after them, is read under if:, or comes after a Field whose size is known only once it is read).

name: demo
framing:
  header: 2
  length: "len + 4"
fields:
  - { name: kind, type: uint16 }
  - { name: len, type: uint16 }

Fix: make header cover every Field length reads, and give those Fields a fixed place at the start of the Message:

name: demo
framing:
  header: 4
  length: "len + 4"
fields:
  - { name: kind, type: uint16 }
  - { name: len, type: uint16 }
  - { name: body, type: bytes, size: len }

invalid-info

Severity: error

The top-level info: template cannot be read: it is not a string, it is on several lines, a { or } pairs with nothing, or braces hold something other than a bare Field Path, such as an Expression or a format specifier. Or a Field Path names an inline structure, a Field of a Type or an array, which have no value of their own to show.

name: demo
info: "id={id:04x}"
fields:
  - { name: id, type: uint16 }

Fix: write each Field Path in braces, {id}, and give the Field the display: it should show with. Write {{ and }} for literal braces, and reference a Field inside a structure rather than the structure.

invalid-label

Severity: error

A label is empty, blank, spans several lines or is not a string: a Field’s label:, a label in a values table, or the true: or false: label of a bool. A label is one line of text in the protocol tree.

name: demo
fields: [ {name: id, type: uint8, label: ""} ]

Fix: write a single-line label, or leave label: out to derive it from the name (“Id”).

invalid-padding

Severity: error

A constant padding: is a negative number of bytes, or an Expression that has no value: it divides by zero, or shifts by a count outside 0 to 63. The error points at the dividing or shifting operator.

name: demo
fields:
  - { name: kind, type: uint8 }
  - { padding: -2 }

Fix: write the number of bytes to skip, zero or more.

invalid-port

Severity: error

A port of registration: ports: is not a port number: port 0, a number above 65535, or a range reaching one of them.

name: demo
registration:
  ports:
    udp: [0, "65000-70000"]
fields:
  - { name: id, type: uint8 }

Fix: write ports from 1 to 65535, here udp: ["65000-65535"].

invalid-prefix

Severity: error

A prefix: does not name an unsigned integer type. The prefix is the count of bytes read just before the value, so it is one of uint8 to uint64.

name: demo
fields: [ {name: user, type: string, prefix: int16} ]

Fix: name the unsigned integer type of the count, here uint16.

invalid-protocol-name

Severity: error

name: is not a valid filter name. A name is a lowercase letter, then at least one lowercase letter, digit, _ or -, 2 to 32 characters in all: Wireshark refuses one-character filter names. Uppercase is never lowercased silently, and a . is refused because it would blur where the Field Path starts in filters such as demo.id.

name: Demo
fields: [ {name: a, type: uint8} ]

Fix: choose a name that follows the rules, here demo. The uppercase form is derived for the Protocol column, and title: sets the full name.

invalid-protocol-title

Severity: error

title: is empty, blank or spans several lines. A title is shown on one line at the root of the protocol tree.

name: demo
title: ""
fields: [ {name: a, type: uint8} ]

Fix: write a single-line title, or leave title: out to use the uppercase name:.

invalid-repeat

Severity: error

A repeat: is not to_end, the only way to repeat other than count: in this version of the format.

name: demo
fields:
  - name: items
    repeat: forever
    fields: [ {name: id, type: uint8} ]

Fix: write repeat: to_end to read elements until the message ends, or give the number of elements with count:. See Arrays.

invalid-size

Severity: error

A constant size: is a negative number of bytes, or an Expression that has no value: it divides by zero, or shifts by a count outside 0 to 63. The error points at the dividing or shifting operator.

name: demo
fields: [ {name: data, type: bytes, size: -4} ]
name: demo
fields: [ {name: data, type: bytes, size: "16 / (4 - 4)"} ]

Fix: write the length in bytes, zero or more.

invalid-terminator

Severity: error

A terminator: is not a byte from 0 to 255, or it is not 0 on a utf16 or ucs2 string, which always ends at a 2-byte zero.

name: demo
fields: [ {name: user, type: string, encoding: utf16, terminator: 10} ]

Fix: write the byte value of the terminator, such as 0 or 10 for a line feed. A utf16 or ucs2 string takes only terminator: 0.

invalid-type-name

Severity: error

The name of a Type under types: or of an Enum under enums: is not an uppercase letter followed by letters or digits. Names of Types and Enums start with an uppercase letter so they can never be mistaken for a Field or a built-in type, which are lowercase.

name: demo
fields:
  - { name: kind, type: uint8, values: msg_type }
enums:
  msg_type: { 1: Request }

Fix: rename the Enum and every values: naming it, here MsgType. For a Type, rename it and every type: naming it.

invalid-unit

Severity: error

A form of a Field’s unit: is empty, blank, spans several lines or is not a string. The tree prints the unit on the value’s line, right after it.

name: demo
fields:
  - { name: length, type: uint16, unit: [byte, ""] }

Fix: write each form on one line (unit: [byte, bytes]), or remove unit:. Quote a unit YAML reads as a number or a bool.

leading-zero-literal

Severity: error

An integer literal in an Expression starts with 0 and has more digits, such as 010. In C that would be octal; Expressions have no octal, so the number is ambiguous.

name: demo
fields: [ {name: data, type: bytes, size: "4 * 010"} ]

Fix: write the decimal number without the zeros (10), or use 0x or 0b for hexadecimal or binary (0x10, 0b10).

merge-key

Severity: error

The file uses a YAML merge key (<<:). Merge keys are not part of the YAML subset Wirdigen reads, because a description reuses Fields through Types.

name: demo
fields: [ {name: a, type: uint8} ]
<<: {}

Fix: write the keys out, or move repeated Fields into a Type.

mismatched-bit-widths

Severity: error

The widths of a bitfield’s sub-Fields and padding do not add up to the bits of its container: 8 for a uint8, 16 for a uint16, and so on. Every bit must be named or padded, so that the masks Wirdigen computes leave no bit ambiguous.

name: demo
fields:
  - name: flags
    type: uint8
    bits:
      - { name: version, width: 3 }
      - { name: ext, width: 1 }

Fix: cover the bits nothing names with a { padding: n } entry, here { padding: 4 } last, or correct a width.

missing-field-kind

Severity: error

A Field says nothing about what it is. A Field needs exactly one of type: (a built-in type or a Type), fields: (an inline structure) or switch: (a choice of layout).

name: demo
fields: [ {name: id} ]

Fix: add the Field’s type:, here {name: id, type: uint8}.

missing-key

Severity: error

A required key is missing: every description needs name: and fields:. An empty file is missing both.

name: demo

Fix: add the key. When the key is only misspelt, Wirdigen reports the unknown-key instead, with the spelling it expected.

missing-length

Severity: error

A string or bytes Field does not say how long it is. Its length comes from exactly one of size:, prefix: or terminator:.

name: demo
fields: [ {name: user, type: string} ]

Fix: add the length key that matches the wire: size: 16 for a constant length, prefix: uint8 when a count comes just before the value, or terminator: 0 for a NUL-terminated string. See Sizes.

multiple-documents

Severity: error

A Protocol Description is a single YAML document, but the file holds several, separated by ---.

name: a
fields: [ {name: a, type: uint8} ]
---
name: b

Fix: put each Protocol Description in its own file.

non-numeric-reference

Severity: error

An Expression reads a Field that has no number: a string, bytes, float, address, timestamp, inline structure or Field of a Type. Only integer and bool Fields can be read.

name: demo
fields:
  - { name: tag, type: string, size: 4 }
  - { name: data, type: bytes, size: tag }

Fix: read an integer Field, or go into the structure for one: header.length rather than header.

overlapping-cases

Severity: error

Two cases of a switch match a same value: a value inside a range, two ranges that share values, or one value spelt twice. A value picks one layout, so the description has no single meaning. The subject is a signed 64-bit value, so -1 and 18446744073709551615 are the same case.

name: demo
fields:
  - { name: kind, type: uint8 }
  - name: body
    switch: kind
    cases:
      "1-5": [ { name: small, type: uint8 } ]
      3: [ { name: three, type: uint16 } ]

Fix: give each value to a single case, here by splitting the range into "1-2" and "4-5".

overlapping-ports

Severity: error

A port is declared twice on one transport of registration: ports:: listed twice, spelt twice (5000 and 0x1388), or inside a range of the same list. The same port on UDP and on TCP is fine.

name: demo
registration:
  ports:
    udp: ["5000-5010", 5005]
fields:
  - { name: id, type: uint8 }

Fix: declare each port once, here by removing 5005.

overlapping-values

Severity: error

Two keys of one values table match a same value: a value inside a range, two ranges that share values, or one value spelt twice (16 and 0x10). The Dissector could show only one of the labels.

name: demo
fields:
  - name: kind
    type: uint8
    values:
      "0-9": Low
      5: Five

Fix: give each value one label, here by splitting the range into "0-4" and "6-9".

protocol-name-taken

Severity: warning

Wireshark already has a protocol with one of the names the description gives its own: the filter name name:, the short name (name: in uppercase) or the full name (title:, or the short name without one). Wireshark refuses to load a Dissector whose protocol names are taken.

name: dns
fields:
  - { name: id, type: uint16 }

The built-in protocols are those of the latest stable Wireshark when this Wirdigen was released. They vary with the Wireshark version and build, which is why this is a warning.

Fix: pick a name and a title of your own, such as name: mydns. When the Wireshark you target lacks the built-in protocol, allow the warning:

name: dns
fields:
  - { name: id, type: uint16 }
allow: [protocol-name-taken]

recursive-type

Severity: error

A Type contains itself, directly or through other Types, so reading it would never end. Each cycle is reported once, at the use the first-declared Type of the cycle makes of the next one, and a note spells the whole cycle.

name: demo
fields:
  - { name: root, type: Node }
types:
  Node:
    fields:
      - { name: id, type: uint8 }
      - { name: child, type: Node }

Fix: break the cycle, for example by giving the inner Field a Type of its own that does not use the outer one.

tcp-without-framing

Severity: warning

registration: ports: declares TCP ports, but the description has no framing:. Each TCP segment is then dissected as one message, which goes wrong when a message is split across segments or a segment holds several messages.

name: demo
registration:
  ports:
    tcp: [5000]
fields:
  - { name: id, type: uint8 }

Fix: add framing: to say where each message ends. When every message travels in a segment of its own, allow the warning:

name: demo
registration:
  ports:
    tcp: [5000]
fields:
  - { name: id, type: uint8 }
allow: [tcp-without-framing]

unexpected-length

Severity: error

A Field of a fixed-size type has a length key (size:, prefix: or terminator:). Its size already follows from its type, or for a timestamp (abs_time, rel_time) from its encoding:. An inline structure takes no length key either: it is as long as its Fields.

name: demo
fields: [ {name: id, type: uint32, size: 4} ]

Fix: remove the length key.

unknown-allow

Severity: warning

An allow: entry names no warning: either no Diagnostic has that name, or it names an error, which cannot be silenced. It is a warning rather than an error so that a description allowing a warning added by a newer Wirdigen still works with an older one.

name: demo
fields: [ {name: a, type: uint8} ]
allow: [bogus]

Fix: correct the name or remove the entry. To keep an entry meant for a newer Wirdigen, allow this warning too:

name: demo
fields: [ {name: a, type: uint8} ]
allow: [unknown-allow, bogus]

unknown-enum

Severity: error

A Field’s values: names an Enum that the top-level enums: does not declare.

name: demo
fields:
  - { name: kind, type: uint8, values: MsgTyp }
enums:
  MsgType: { 1: Request }

Fix: correct the name, here MsgType, or declare the Enum under enums:. To label the values of this Field only, write the table inline: values: { 1: Request }.

unknown-field

Severity: error

A name in an Expression matches no Field read before it: a misspelling, a path into a structure that has no such Field or into a Field that is not a structure, a path into the structure still being read, or a path into an array, whose Fields only its elements can read. Inside a Type, a name the Type does not declare is looked up where the Type is used, and the error points at that use. A Field Path of the info: template is checked the same way, from the top-level Fields.

name: demo
fields:
  - { name: length, type: uint8 }
  - { name: data, type: bytes, size: "lengths * 2" }
name: demo
fields:
  - { name: record, type: Record }
types:
  Record:
    fields: [ {name: data, type: bytes, size: count} ]

Fix: correct the name, or declare the Field it reads before the Field that reads it: here length, and a count Field before record.

unknown-key

Severity: error

A key is not part of the format. When it is close to a known key, the message suggests that key.

name: demo
bogus: 1
fields: [ {name: a, type: uint8} ]

Fix: correct the spelling, or remove the key. Use a YAML comment to document a description.

unknown-type

Severity: error

A Field’s type: names no built-in type and no Type. When the name is close to a built-in or to a declared Type, the message suggests it. An unknown Type is reported once, at its first use, however many Fields use it.

name: demo
fields: [ {name: id, type: unit8} ]

Fix: correct the spelling, here uint8, or declare the Type under types:. The built-in types are listed in Fields.

unreachable-expect

Severity: warning

An expect: lists no value the Field’s type can hold: 256 on a uint8, 2 on a bool, 4 on a 2-bit sub-Field. It never matches, so every packet gets the “Unexpected value” expert info. A list or a range is reported only when none of its values fit.

name: demo
fields:
  - { name: version, type: uint8, expect: 256 }

Fix: correct the value, or widen the Field’s type if the value can occur. To flag every packet on purpose, allow the warning:

name: demo
fields:
  - { name: version, type: uint8, expect: 256 }
allow: [unreachable-expect]

unreachable-field

Severity: warning

A Field comes after a Field that reads every byte left in the message, so it is always empty or truncated. The earlier Field is a size: "_remaining" Field or a repeat: to_end array, or an inline structure, a Field of a Type or a switch that always reads one: a switch only when every case does. A Field under if: or an array with count: may read nothing, so it does not count.

name: demo
fields:
  - { name: body, type: bytes, size: "_remaining" }
  - { name: checksum, type: uint16 }
name: demo
fields:
  - name: records
    repeat: to_end
    fields: [ {name: tag, type: uint8} ]
  - { name: checksum, type: uint16 }
name: demo
fields:
  - name: body
    fields:
      - { name: kind, type: uint8 }
      - { name: data, type: bytes, size: "_remaining" }
  - { name: checksum, type: uint16 }

Fix: give the earlier Field a size that leaves room, such as "_remaining - 2", or a count: in place of repeat: to_end, or remove the later Field. When the later Field is meant to be empty, allow the warning:

name: demo
fields:
  - { name: body, type: bytes, size: "_remaining" }
  - { name: checksum, type: uint16 }
allow: [unreachable-field]

unreachable-value

Severity: warning

A key of a values table is outside the range of the Field’s type, so no packet can show its label: 256 on a uint8, or -1 on any unsigned type. A range is reported only when none of its values fit. For an Enum, each key is reported once, for the first Field whose type cannot hold it. The Dissector leaves the key out.

name: demo
fields:
  - { name: kind, type: uint8, values: { 1: One, 256: Never } }

Fix: remove the key, or widen the Field’s type if the value can occur. An Enum shared by Fields of several widths can keep keys only the widest reaches; allow the warning then:

name: demo
fields:
  - { name: short_kind, type: uint8, values: Kind }
  - { name: long_kind, type: uint16, values: Kind }
enums:
  Kind: { 1: One, 256: Wide }
allow: [unreachable-value]

unused-enum

Severity: warning

An Enum under enums: is never named by a Field’s values:.

name: demo
fields:
  - { name: kind, type: uint8 }
enums:
  MsgType: { 1: Request }

Fix: use it with values: MsgType, or remove it. To keep it for later, allow the warning:

name: demo
fields:
  - { name: kind, type: uint8 }
enums:
  MsgType: { 1: Request }
allow: [unused-enum]

unused-type

Severity: warning

A Type under types: is never named by a Field’s type:, so the Dissector never reads it.

name: demo
fields:
  - { name: id, type: uint8 }
types:
  Header:
    fields: [ {name: length, type: uint16} ]

Fix: use it with type: Header, or remove it. To keep it for later, allow the warning:

name: demo
fields:
  - { name: id, type: uint8 }
types:
  Header:
    fields: [ {name: length, type: uint16} ]
allow: [unused-type]

wrong-value-type

Severity: error

A value has the wrong kind: a scalar where a list is expected, a list where a mapping is expected, a float or a bool where an integer is expected, and so on. The whole description must be a mapping.

name: demo
fields: [ {name: a, type: uint8} ]
allow: unknown-allow

Fix: write the value in the kind the message asks for, here a list: allow: [unknown-allow].

yaml-alias

Severity: error

The file uses a YAML alias (*name). Aliases are not part of the YAML subset Wirdigen reads, because a description reuses Fields through Types. An alias always comes with the anchor it refers to, which is the error yaml-anchor.

x: &a demo
name: *a
fields: [ {name: a, type: uint8} ]

Fix: write the value out, or move repeated Fields into a Type.

yaml-anchor

Severity: error

The file declares a YAML anchor (&name). Anchors are not part of the YAML subset Wirdigen reads, because a description reuses Fields through Types.

name: &n demo
fields: [ {name: a, type: uint8} ]

Fix: remove the anchor, and move repeated Fields into a Type.

yaml-syntax

Severity: error

The file is not well-formed YAML, so nothing else can be checked. The message is the YAML parser’s.

name: [demo
fields: []

Fix: correct the YAML at the position shown, here by closing the [ list or writing name: demo.

yaml-tag

Severity: error

The file uses a YAML tag (!foo, !!str). Tags are not part of the YAML subset Wirdigen reads.

name: !foo demo
fields: [ {name: a, type: uint8} ]

Fix: remove the tag. To keep a value as text, quote it.

yaml-too-deep

Severity: error

The YAML nests more than 256 levels deep, anywhere in the file: the root is the first level, and each value inside a list or a mapping is one level deeper. The error points at the first node past the limit, and nothing else is checked. A description within the field-too-deep limit nests at most about 194 levels.

name: demo
info: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
fields: [ { name: a, type: uint8 } ]

Fix: flatten the nesting.

Glossary

The terms this book uses for the parts of a Protocol Description and of the Dissector generated from it, written with a capital letter in the text, such as Field or Case. Under Avoid, each entry lists other names you may know the same idea by; this book does not use them.

Array

A Field whose layout is read several times in a row: as many times as a count gives, or until the Message ends. Avoid: List, sequence, repeated field, vector

Bitfield

A Field of an unsigned integer type whose bits are split, most significant first, into Sub-Fields and Padding, every bit accounted for. Avoid: Flags, bitmask, packed field

Byte Order

Whether a multi-byte value is read most significant byte first (big) or last (little). A Field takes the nearest one set on itself, its enclosing Structures or the Protocol Description; a Type keeps its own, whatever Structure uses it. Avoid: Endianness, endian

Case

One layout a Switch can read, a Type or a group of Fields, picked by a set of Subject values or, for the default Case, when no other matches. It adds no level to the tree or to Filter Names. Avoid: Branch, arm, variant, alternative, message type

Conditional Field

A Field read only when its condition, an Expression, is not zero; otherwise it reads nothing and adds nothing to the tree. Avoid: Optional field, guarded field

Conditional Scope

A Conditional Field or a Case: the Fields inside it have a value only when it was read, so only Expressions inside it can read them. Avoid: Conditional block, branch

Depth

How many Fields enclose a Field in the tree, through every Type it is reached by; a Case adds none. A top-level Field has depth 0. It is the number of names in its Filter Name, less the protocol’s and its own. Avoid: Nesting level, level

Diagnostic

An error or a warning that Wirdigen reports about a Protocol Description, identified by a stable name and pointing at where in the description it applies. An error stops generation; a warning does not. Avoid: Lint, issue, validation message

Dissector

The Wireshark Lua plugin generated from a Protocol Description. The dissectors Wireshark already has, such as the one a Handoff passes bytes to, are written in lowercase: one of them can be a Dissector, but most are not. Avoid: Plugin, LUA file

Element

One reading of an Array’s layout, shown in the tree on its own and numbered from 0, but sharing the Array’s name and Filter Names. Avoid: Item, entry, record

Enum

A named table of labels for integer values and value ranges, defined once in a Protocol Description and shared by every Field whose values it names. Avoid: Value string, lookup table, dictionary

Expected Values

The values a Field or Sub-Field should hold. A Message holding another value gets a warning in Wireshark but is still read to the end; it is not Malformed. Avoid: Constraint, assertion, validation, magic value

Expression

A formula in a Protocol Description that computes a size, a count, an amount of Padding, a condition, the Subject of a Switch or the length Framing gives a Message, from constants and Fields read earlier. Avoid: Formula, rule, script

Field

One named element of a Protocol Description’s payload layout: a single value, or a group of Fields, with its display settings. Avoid: Data chunk, data, attribute

Field Path

The dotted chain of Field names by which an Expression or an Info Template names a Field. In an Expression it names a Field read earlier, looked up from the nearest enclosing Structure outward; in an Info Template it is looked up from the top-level Structure. Avoid: Reference, variable, identifier

Filter Name

The name a Wireshark display filter uses for a Field: the protocol’s name, then the Field names from the top-level Structure down to it, never through a Type’s name or a Case. Saved filters depend on it, so changing it breaks them. Avoid: Abbreviation, abbrev, field ID, filter path

Framing

How a Dissector finds where each Message starts and ends in a TCP stream, so one Message split across segments, or several in one segment, are dissected correctly. Avoid: Reassembly, segmentation, PDU splitting

Handoff

Passing the bytes of a Field to a dissector Wireshark already has, named in the Protocol Description; its layer is shown right after the Field. Avoid: Sub-dissector, delegation, chaining, payload dissector

Hidden Field

A Field read but left out of the protocol tree; it can still be filtered and used in Expressions. Avoid: Invisible field, private field, internal field

Info Template

The text a Protocol Description gives for Wireshark’s Info column, with Field Paths in braces that show the Fields of each Message; without one, the column shows the label of the outermost Switch’s Subject value. Avoid: Info format, summary line, info string

Malformed

What a Dissector reports when a Message cannot be read as its Protocol Description says, because a Field does not fit (truncated), an Expression’s value cannot be used, or an Element reads no bytes; it shows what it read so far and stops, never failing with a Lua error. Avoid: Invalid packet, corrupt, parse error

Message

One unit of traffic a Dissector reads with the top-level Structure: a packet’s payload, or one piece cut out by Framing. Avoid: PDU, frame, packet

Padding

Unnamed space that is skipped: bytes between the entries of a Structure, or bits between the Sub-Fields of a Bitfield. It cannot be filtered or referenced. Avoid: Gap, filler, reserved bytes, unused bits, alignment

Protocol Description

The document a user writes to describe one protocol: its identity, its Registration, and the layout of its payload. Avoid: Package, packet description, message description, dissector description

Registration

How a Dissector attaches to traffic in Wireshark: the ports it claims by default, and its availability in Decode As. Avoid: Connection, network information, binding

Structure

An ordered list of entries read one after another, each a Field or Padding: the top-level layout, an inline group of Fields, a Type’s body or a Case. Avoid: Record, block, section

Sub-Field

A Field of a Bitfield, a few bits wide: an unsigned integer, or a boolean when it is one bit wide and given no labels for values, unit or display. Avoid: Bit field, flag, bit

Subject

The Expression whose value picks a Switch’s Case, computed once before any Case is read. Avoid: Selector, discriminant, tag, key

Switch

A Field that reads one Case among several, picked by the value of its Subject. Avoid: Union, variant, choice

Type

A named, reusable group of Fields, defined once in a Protocol Description and used wherever a layout is needed, including as a Case of a Switch. Avoid: Struct, message, template

Value Mapping

What a Field shows beside or instead of its raw value: labels for values and value ranges, given inline or by naming an Enum, labels for true and false, or a unit. Avoid: Value labels, value string, lookup