DNS message encoding and decoding for Zig, with no I/O and no allocation.
zig-dns CONTRIBUTING.md
3.8 kB · 106 lines
Markdown
at main

Contributing to zig-dns #

Issues and pull requests go to the Tangled mirror, https://tangled.org/jcollie.dev/zig-dns. What follows is what a change needs before it is ready to send.

The toolchain #

Everything runs inside the Nix devshell, which pins Zig 0.17.0, dnspython for the differential check, reuse, and the rest:

$ nix develop

Any command below can also be run from outside it as nix develop -c ….

Before sending a change #

All of these pass on every commit. The Forgejo workflow runs each of them, the last by way of nix flake check, and a bounded zig build fuzz-run as well:

$ reuse lint
$ zig fmt --exclude zig-pkg --check .
$ zig build test --summary all
$ zig build check
$ zig build differential

zig build check compiles the parts no test runs, such as the tools. nix flake check runs the differential check in a sandbox, with the Zig dependency taken from build.zig.zon.nix. If a dependency in build.zig.zon moves, regenerate that file:

$ zon2nix --17 --nix=build.zig.zon.nix build.zig.zon

Every file carries an SPDX header, or is covered in REUSE.toml when it cannot hold one. New code is MIT licensed.

Changing what the decoder accepts #

This is the part that needs care, because a decoder's strictness is its interface. Read GLOSSARY.md and the decisions in docs/adr/ first. The short version:

  • Framing is always enforced: counts, lengths and names that do not add up are refused.
  • A shape rule — one that holds whatever a field means — is enforced, and data that breaks it is refused as MalformedRdata.
  • A meaning rule — one that depends on what a registry number currently means — is not, and the data is carried through (ADR 0001).
  • Builder checks framing and nothing else, so a test can write a malformed message on purpose.

A change that refuses something new, or stops refusing something, nearly always changes how this library and dnspython disagree. zig build differential puts a couple of hundred thousand mutated messages to both and fails on any kind of disagreement not written down in EXPECTED in tests/differential.py. When it fails, the new kind is either a bug to fix or a deliberate difference to add to EXPECTED, with a sentence saying why it is one. An entry that no longer comes up should be removed rather than left to absorb something else later. Rarer kinds turn up only in longer runs, which are worth doing before sending such a change:

$ zig build differential -- --count 1000000 --seed 3

A decision that is hard to reverse, would surprise a later reader, and came from a real trade-off gets an ADR in docs/adr/, numbered after the last one. A new term gets a line in GLOSSARY.md.

Fuzzing #

tests/fuzz.zig holds the properties that must survive any input. A change to decoding is worth a run:

$ zig build fuzz --fuzz=1M
$ zig build fuzz-run

A finding prints input saved to '.zig-cache/f/crash'. Anything else that goes wrong in the fuzzer is the tooling, not a finding.

Documentation #

The API documentation is generated from the doc comments, which carry most of the explanation of why DNS is the shape it is, so a change to behavior changes the comment beside it. zig build docs builds it and zig build docs-serve serves it at http://127.0.0.1:8000/.

The README describes the project as it is now, for someone who has never seen it. A record type, an RFC the code is written from, or a change to what is refused belongs there as well as in the code, and every RFC cited goes into the references section.