Skip to content

Rest refactor - #4

Merged
nolsen311 merged 2 commits into
mainfrom
REST-refactor
Sep 6, 2026
Merged

nolsen311 merged 2 commits into
mainfrom
REST-refactor

Conversation

@nolsen311

Copy link
Copy Markdown
Owner

No description provided.

nolsen311 and others added 2 commits September 6, 2026 09:51
Two related fixes for toggling firewall/NAT rules over REST v2:

1. FIELD_EMPTY_NOT_ALLOWED on rule toggle. pfSense's webConfigurator
   stores content-less config elements (<statetype></statetype>), which
   the REST API surfaces as "". A PATCH re-validates the whole rule, so
   toggling a rule whose statetype is empty fails even though only
   `disabled` changed. _set_rule_disabled now backfills the empty field
   with pfSense's own default ("keep state"), which is a no-op for the
   rule's behaviour. Driven by a per-endpoint _RULE_REQUIRED_DEFAULTS
   table. Verified on 26.07 / RESTAPI 2.10.2.

2. New option "Reset matching states when a rule switch is toggled"
   (rule_switch_kill_states, default off). When set, enabling or
   disabling any rule switch also flushes the state-table entries for
   the hosts/networks that rule matches, so existing connections stop
   riding the old ruleset without a global `pfctl -F states`.

   kill_states_for_rule() resolves the rule's source/destination to
   concrete IPv4 networks (literal CIDR/host, or alias names expanded
   via /firewall/aliases, following nested aliases), turns each into a
   firewall/state value prefix (host -> "ip:", octet-aligned CIDR ->
   leading octets), and issues DELETE /firewall/states with a
   {source,destination}__startswith filter. REST-only, best effort:
   `any`, `(self)`, interface macros, negated aliases, non
   octet-aligned networks and IPv6 are skipped rather than shelling out
   to pfctl. A single DELETE clears every currently-matching state
   (no per-call cap); it can't stop a busy host reopening connections,
   which is expected. The toggle never fails if the kill errors.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

🎉 Thank you for contributing to SkyRadar Fusion! Your Pull Request has been received. Our automated tests (Hassfest, Ruff, etc.) will run shortly. If anything fails, don't worry—just check the logs and update your branch!

@nolsen311
nolsen311 merged commit 7fb2ba2 into main Sep 6, 2026
6 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant