Raw firewall tools for MikroTik MCP: 16 tools that drop traffic before connection tracking

1 hour ago

The MCP server could manage MikroTik filter rules, but it had no way to touch the raw tables. Raw rules run first, in the prerouting and output chains. They are the cheap place to drop blocklisted or rate limited sources, and to exempt traffic from tracking with notrack. Everything else still goes through connection tracking and the filter rules afterwards. This pull request adds sixteen tools for the raw tables, eight for IPv4 and eight for IPv6.

Ask about this presentation

Chapters

  1. 0:00Raw rules
  2. 0:28How it is built
  3. 1:02Safety
  4. 1:34What to check
Show transcript
  1. The MCP server could manage MikroTik filter rules, but it had no way to touch the raw tables. Raw rules run first, in the prerouting and output chains. They are the cheap place to drop blocklisted or rate limited sources, and to exempt traffic from tracking with notrack. Everything else still goes through connection tracking and the filter rules afterwards. This pull request adds sixteen tools for the raw tables, eight for IPv4 and eight for IPv6.

    Slide text
    PR 188 · /ip and /ipv6 firewall raw

    Drop unwanted traffic before the router tracks it

    Raw rules
    →
    Connection tracking
    →
    Filter rules
  2. The logic lives in one shared module. The IPv4 and IPv6 tool modules are thin wrappers that pass in their own executor, so the usual test patching still works. The only matcher that differs is time to live for IPv4 and hop limit for IPv6. In read-only mode just the four list and get tools are registered. Creating rules supports the raw specific actions, and it refuses a jump without a target or an address list action without a list. There is no connection state matcher, because raw runs before connection tracking.

    Slide text
    DESIGN

    One shared implementation serves both address families

    _firewall_raw.pyAll the logic, about 275 lines
    Two thin tool modulesIPv4 uses ttl, IPv6 uses hop_limit
    Read-only modeOnly the 4 list and get tools register
    Raw actionsnotrack, jump, add to address list
  3. RouterOS prints nothing when a write works and prints text when it refuses, often without the word error in it. So create wraps the add in a put and only reports success when a new star id comes back. Set and remove treat any output as a refusal, such as not enough permissions, and remove then counts the rule to confirm it is gone. Every value is model controlled, so names go through quoting and bare matcher values must match a strict pattern. A value with a semicolon and a second command is refused before anything is sent.

    Slide text
    SAFETY

    Success is confirmed by evidence, and input is validated first

    CreateMust echo back a new *id
    Set and removeAny output counts as a refusal
    RemoveConfirmed with a count of zero
    Injection 1.2.3.4; /system reset-configuration is refused
  4. The new unit tests run for both address families and cover the exact command strings, the refusal paths and the not found cases. The author also ran the list and get tools against a RouterOS 7.24.2 router. The write tools were not run on a device, because that account was read-only, so a reviewer with a lab router could try create, move and remove. Merging counts as a feature, which raises the minor version and publishes a release.

    Slide text
    REVIEW

    Read tools ran on a real router; write tools ran only in unit tests

    670 unit tests passExact commands, refusals, not found
    RouterOS 7.24.2List and get checked, with stats
    Writes untested liveThe device account was read-only
    Feature releaseA merge bumps the minor version

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York