Skip to content

pbr-1.2.4: report a missing fw4 table, and why a start failed - #203

Open
egc112 wants to merge 1 commit into
mossdef-org:1.2.4from
egc112:pbr-1.2.4-fw4-table-check
Open

egc112 wants to merge 1 commit into
mossdef-org:1.2.4from
egc112:pbr-1.2.4-fw4-table-check

Conversation

@egc112

@egc112 egc112 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Problem

With no inet fw4 table (the firewall is not loaded, or firewall (fw3) has replaced firewall4), pbr fails to start without saying why. Reported on the forum: https://forum.openwrt.org/t/policy-based-routing-pbr-package-discussion/140639/3143 (that box runs firewall3).

Two bugs:

  1. The table check can never fail. nft_check_element() reads nft list table inet fw4 2>&1, so with no table nft's error text is the dump, and a non-empty dump counts as "table present". The chain checks then fail on it instead: three "Default fw4 chain 'mangle_…' is missing" errors (four with a DNS or Tor policy) for what is really one missing table. 1.2.2 has the same 2>&1.
  2. On 1.2.4 none of those errors is shown anywhere. When the environment check fails, start_service() returns null, and the errors stay in state.errors. Measured on x86 OpenWrt 25.12 with stock 1.2.4-r2 (stop pbr, nft delete table inet fw4, start pbr), the whole output is:
    Loading environment (on_start) [✗]
    pbr 1.2.4-r2 FAILED TO START!!!
    Check the output of nft -c -f /var/run/pbr.nft
    
    status says "not active", the service data in procd is empty, so the WebUI shows nothing either, and the nft hint points the wrong way. The same holds for every environment check failure (e.g. ip-full missing).

Fix

  • nft.uc: read the table with 2>/dev/null.
  • pbr.uc: skip the chain checks when the table itself is missing (one error, not three or four). When the environment check fails, return { errors, warnings, retryOnBoot } instead of null; emit_procd_shell() writes the errors into the service data, so service_started() logs them and the WebUI shows them. The "Check the output of nft -c -f" hint is printed only when no error explains the failure.
  • init.d/pbr: _pbr_retry_on_boot keeps the boot-mode retry (interface.*.up trigger) that the wrapper set up for a null result, so a check that fails briefly still recovers on the next interface event.

No new message codes, so no compat bump: luci-app-pbr 1.2.4 already has errorDefaultFw4TableMissing and errorDefaultFw4ChainMissing. The "service disabled" path is unchanged (it prints its own message).

Tests

  • The global fixture popen~nft_list_table_inet_fw4_2_1.txt is renamed for the new command line.
  • The orphan-set reaper runs the same nft list table inet fw4 2>/dev/null, so the per-test fixtures of 03_nft_rules/08 and 14 now also feed the health check; they gain the dstnat and mangle_* chains every fw4 table has.
  • New 02_config/12_fw4_table_missing: one table error, no chain errors, retryOnBoot, and the error plus _pbr_retry_on_boot='1' in the emitted procd shell. 7/7 with the fix, 2/7 without.
  • tests/run_tests.sh: 76/76. check-ucode-syntax.sh with ucode 85922056 (25.12): 17/17.

Hardware

Same router and procedure as above, with the patched files:

Loading environment (on_start) [✗]
pbr 1.2.4-r2 FAILED TO START!!!
ERROR: Default fw4 table 'fw4' is missing!
ERROR: Errors encountered, please check https://docs.mossdef.org/pbr/1.2.4/#error-messages-details!

and ubus call service list '{"name":"pbr"}' holds [ { "code": "errorDefaultFw4TableMissing", "info": "fw4" } ]; "Setting trigger (on_boot) ✓" is still printed. A normal restart is unchanged (active, no errors). Note for anyone reproducing: use stop / delete / start, not restart, because pbr's stop reloads fw4 and recreates the table.

The analysis, the patch, the tests and the hardware runs were done with the help of an LLM (Claude); I reviewed the result.

With no 'inet fw4' table (firewall not loaded, or firewall3 installed in
place of firewall4), pbr failed to start without saying why:

- nft_check_element() read the table with 'nft list table inet fw4 2>&1',
  so nft's error text made the table look present, and the chain checks
  failed on it instead. Drop stderr, and skip the chain checks when the
  table itself is missing: one error, "Default fw4 table 'fw4' is missing".
- When the environment check failed, start_service() returned null, so
  its errors stayed in state.errors: the log showed only "Loading
  environment [x]", "FAILED TO START" and a hint to check the nft file,
  while status and the WebUI showed nothing. Return the errors instead;
  emit_procd_shell() writes them into the service data, so
  service_started() logs them and the WebUI shows them. The new
  retryOnBoot flag keeps the boot-mode retry the wrapper set up for a
  null result. The nft hint is printed only when no error explains the
  failure.

The orphan-set reaper reads the same 'nft list table inet fw4 2>/dev/null'
command, so the fixtures of tests 08 and 14 gain the dstnat and mangle_*
chains every fw4 table has. New test 02_config/12_fw4_table_missing:
7/7 with the fix, 2/7 without.

Tested on x86 OpenWrt 25.12 with 1.2.4-r2 (stop pbr, delete the fw4 table,
start pbr): before, no reason anywhere; after, "ERROR: Default fw4 table
'fw4' is missing!" in the log, the error in the service data, and the
boot-mode retry trigger still set. A normal restart is unchanged.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Erik Conijn <egc112@msn.com>
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