Skip to content

pbr[1.2.3]: tighten is_netifd_interface() to require env.netifd_mark#105

Merged
stangri merged 1 commit into
mossdef-org:1.2.3from
Per-Terra:1.2.3-tighten-is-netifd-interface
May 20, 2026
Merged

pbr[1.2.3]: tighten is_netifd_interface() to require env.netifd_mark#105
stangri merged 1 commit into
mossdef-org:1.2.3from
Per-Terra:1.2.3-tighten-is-netifd-interface

Conversation

@Per-Terra
Copy link
Copy Markdown

Re-take of #104 along the direction @stangri proposed in #104 (comment) — instead of adding a netifd-specific branch to interface_routing.create, tighten is_netifd_interface() itself.

is_netifd_interface() previously classified by UCI alone (any iface with ip4table or ip6table set), which over-included user-manual two-uplink setups that pbr did not put in place. In dynamic-routing-tables mode this caused interface_routing 'create' to early-return for such ifaces, leaving the per-mark chain and ip rule fwmark uninstalled while policy processing still emitted goto pbr_mark_${mark} — the resulting ruleset failed nft -c -f and pbr aborted on start.

The helper is now narrowed to ifaces present in env.netifd_mark, populated from pkg.nft_netifd_file — i.e. ifaces pbr itself set up via its netifd extensions. The check now mirrors is_mwan4_interface()'s env.mwan4_mark[iface].

One subtle side effect: user-manual ip4table ifaces are now added to ifaces_triggers, so pbr reloads on their dev up/down — the intended behaviour once pbr does manage them.

The helper classified by UCI alone (any iface with `ip4table` or `ip6table` set), which over-included user-manual two-uplink setups that pbr did not put in place. In dynamic-routing-tables mode this caused `interface_routing 'create'` to early-return for such ifaces, leaving the per-mark chain and `ip rule fwmark` uninstalled while policy processing still emitted `goto pbr_mark_${mark}` — the resulting ruleset failed `nft -c -f` and pbr aborted on start.

Narrow the helper to ifaces present in `env.netifd_mark`, populated from `pkg.nft_netifd_file` — i.e. ifaces pbr itself set up via its netifd extensions. The check now mirrors `is_mwan4_interface()`.

Side effect: user-manual `ip4table` ifaces are now added to `ifaces_triggers` so pbr reloads on their dev up/down — the intended behaviour once pbr does manage them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: per_terra <53376589+Per-Terra@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines how pbr detects “netifd-managed” interfaces by narrowing is_netifd_interface() so it only matches interfaces that pbr itself set up via netifd extensions (those present in env.netifd_mark). This prevents manual ip4table/ip6table configurations from being misclassified as netifd interfaces, which (per the PR description) can lead to missing mark chains / fwmark rules and an invalid generated nft ruleset in dynamic-routing-tables mode.

Changes:

  • Change is_netifd_interface() from UCI (ip4table/ip6table) based detection to env.netifd_mark[iface] based detection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread files/lib/pbr/network.uc
Comment on lines 133 to 136
function is_netifd_table(name) { let c = readfile('/etc/config/network') || ''; return index(c, name) >= 0 && !!match(c, regexp('ip.table.*' + name)); }
function is_netifd_interface(iface) {
let ctx = config.uci_ctx('network');
let ip4t = ctx.get('network', iface, 'ip4table');
let ip6t = ctx.get('network', iface, 'ip6table');
return !!(ip4t || ip6t);
return !!(iface && env.netifd_mark[iface]);
}
@stangri
Copy link
Copy Markdown
Collaborator

stangri commented May 20, 2026

@Per-Terra apologies for the delay in merging. This is a very elegant fix, kudos!

@stangri stangri merged commit c5734ee into mossdef-org:1.2.3 May 20, 2026
7 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.

3 participants