Crate resynth

source ·
Expand description

Resynth: A Packet Synthesis Language

Resynth is a packet synthesis language. It produces network traffic (in the form of pcap files) from textual descriptions of traffic. It enables version-controlled packets-as-code workflows which can be useful for various packet processing, or security research applications such as DPI engines, or network intrusion detection systems.

Structure of the Codebase

The codebase is split in to several major components

  • pkt A low-level packet generation library which mostly contains structs and consts to do with various network protocols.
  • ezpkt A more high-level packet generation library which provides abstractions around concepts such as flows
  • crate The language compiler and interpreter itself is the root of the crate. In future we will probably move in to its own module at some point in future.
  • stdlib Contains the resynth standard library which is mostly glue to allow resynth programs to use the functionality in pkt and ezpkt

Compiler Phases

  1. Lexer uses a static regex to parse each line in to a stream of tokens
  2. Parser is a hand-written LR-parser which takes a token at a time and whenever a complete statement is encountered, the statement is pushed in to a results vector which can later be retreived
  3. Program maintains the execution state of any given program. It takes one statement at a time, and updates the program state based on that. If the program has a pkt::PcapWriter attached to it, then any generated packets will be written in to the corresponding pcap file as they are generated.

Modules

Macros

Structs

The lexer takes a line at a time and returns a vector of tokens. If an error occurs then the location of that error may be retreived from Lexer::loc.
Identifies a line number and column number within a source file.
A hand-written LR-parser which takes a token at a time and whenever a complete statement is encountered, the statement is pushed in to a results vector which can later be retreived with Parser::get_results. Each type of statement which is produced contains a line number and column number which allows any error mesages to locate themselves within the source file.
The interpreter and program-state
Represents a lexeme within the resynth language.

Enums

Error code for resynth program. Think of it as base exception type for the resynth language.
A complete statement of the resynth language

Constants

EOF token