Live log: jump from log entry to rule, including NAT – feedback plugin/core hook

Started by BrownyMaster, Today at 02:21:43 AM

Previous topic - Next topic
Hi all,
I would like to share a small project and ask for feedback before opening pull requests.

The problem. In Firewall → Log Files → Live View, entries of filter rules carry a rule id, so
the details dialog can link to the rule. NAT entries don't: the dialog shows nat rule
and an internal pf rule number, and finding the responsible outbound NAT rule or port forward means
comparing interfaces, addresses and aliases by hand. The same goes for automatic rules and UPnP
mappings, and pf numbers shift with every ruleset reload, so an older entry may point to a rule
that has moved since.

What I built. Live Rule Navigator, a plugin that adds an "Associated Rule" section to the
details dialog:
  • the configured rule behind the entry, for filter rules, source/destination/one-to-one NAT,
     automatic rules (outbound NAT, anti-lockout, reflection, plugin rules) and UPnP mappings
     (client, ports, lease expiry);
  • its key settings, Open Rule / Open Rule List (new tab, so the live view keeps its filters),
     and a logging toggle with confirmation that saves through the rule's model (config history) and
     is activated with the page's own Apply;
  • NAT entries are resolved through the active ruleset: pfctl -vv -s nat → structural check
     against the logged packet → alignment with the translation lines of /tmp/rules.debug → verbatim match against the text the configured rules generate. Per-reload snapshots keep older entries attributable. Anything ambiguous is flagged and read-only.

Screenshots, details and tests: https://github.com/Brownys/os-liverulenav


What it needs from core. One small extension point in the live log (17 lines): the details
dialog triggers a jQuery event firewall_log_details with the log record and the dialog body, and
the page loads scripts from www/js/diagnostics/fw_log/. Without such scripts nothing changes.

Patch: https://github.com/Brownys/core/compare/master...live-log-extension-point

Questions to the core team:
  • Would you accept such an extension point, or would you prefer a different mechanism (for
     example an existing way to inject plugin scripts into a core page that I missed)?
  • The plugin reads the NAT rules registered by plugins through reflection on the private \OPNsense\Firewall\Plugin::$natRules, to know which plugin page a generated rule belongs to (with a text-only fallback). Would a public getter be acceptable?
  • To record a snapshot after each successful ruleset load, the plugin registers for the rules_source_nat
     hook and contributes no rules. Is there a better "ruleset loaded" signal?
  • Is net the right category, and is a ~3,000 line initial plugin acceptable in one PR, or
     should I split it (filter rules first, then NAT resolution, then snapshots and UPnP)?

Tested on OPNsense 26.7 with IPv4/IPv6, PPPoE WAN, hybrid outbound NAT, port forwards and os-upnp.

Disclosure: the code was written with the help of Claude Code.
I specified the behaviour, reviewed the changes and tested everything on my own firewall.

Thanks for any feedback!
Stephan