lazydns

Sequence Plugin

The sequence plugin executes a configurable chain of plugin steps (actions) and optional match conditions. It is the core rule engine used to compose complex request handling logic from smaller plugins (forwarders, cache, ipset writers, debug helpers, etc.). The behavior and many built-in matchers/actions are inspired by the MOSDNS sequence plugin but adapted to this project’s plugin and builder model.

Overview

Basic configuration shape

This repository implements a simplified sequence constructor in the executable plugin wrapper: the builder accepts a plugins array for simple sequences, and the broader configuration format supports a richer args-based rules structure. Example (YAML):

- tag: main
  type: sequence
  args:
    # Simple plugin list (resolved by name)
    plugins:
      - cache
      - forward

    # Or a richer rule list (matchers + exec)
    rules:
      - matches:
          - qname example.com
        exec: black_hole 127.0.0.1 ::1
      - matches:
          - env MOSDNS_ENABLE_CACHE
        exec: cache 1024
      - exec: forward 8.8.8.8

Notes:

Matchers (built-in)

Sequence uses a set of built-in matchers for request and response inspection. Common matchers include:

Each matcher accepts arguments in the same style as other dataset and matcher plugins (tags, inline expressions, or file references). See the individual matcher plugin docs (domain_set, ip_set, etc.) for details on expression formats.

Built-in actions (common)

Sequence rules typically invoke small, executable plugins as actions. Common actions available in this project include:

Actions are normal plugins and support the same quick-setup string or args configuration used by executable plugins across the project.

Control flow operations

Sequence includes several control operations for structured flow across multiple sequences or within a sequence:

Use goto/jump to build modular rule sets and delegate handling to named sequences (define target sequences with tag and type: sequence).

Error handling

Examples

1) Simple ordered plugins (unconditional):

- tag: simple_chain
  type: sequence
  args:
    plugins: [ mark, cache, forward ]

2) Blocking ad domains and forwarding otherwise:

- tag: main
  type: sequence
  args:
    rules:
      - matches:
          - qname $ad_domains
        exec: reject 5
      - exec: forward 8.8.8.8

3) Conditional caching controlled by environment:

- tag: main
  type: sequence
  args:
    rules:
      - matches:
          - env ENABLE_CACHE
        exec: cache 2048
      - exec: forward 1.1.1.1

4) Jump/goto example: delegate local handling:

- tag: handle_local_query
  type: sequence
  args:
    rules:
      - exec: forward 192.168.0.1

- tag: main
  type: sequence
  args:
    rules:
      - matches:
          - qname internal.example.com
        exec: goto handle_local_query
      - exec: forward 8.8.8.8

Implementation notes (this codebase)

Troubleshooting & tips

See also