pbr: main_chains cleanup flushes fw4 forward chain and breaks DNS resolution

Aperta Adatta ai principianti
#31,373 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
linux, shell
Ambito
networking

Direzione di ricerca

Inizia da net/pbr/files/etc/init.d/pbr, in cleanup(main_chains), vicino alla riga 1295, e controlla come viene costruito il nome della catena per la voce forward. Verifica che la correzione svuoti la catena gestita da PBR preservando la catena di base di fw4. Convalida poi con la build del pacchetto e una ricostruzione della policy che richieda nuove query DNS.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Package Name

pbr

Maintainer

@stangri

OpenWrt Version

25.12.5 r33051-f5dae5ece4

OpenWrt Target/Subtarget

x86/64

Steps to Reproduce

Environment: PBR and luci-app-pbr 1.2.2-r20, fw4 nft file mode, OpenWrt 25.12.5 r33051-f5dae5ece4 on a Proxmox x86/64 VM, kernel 6.12.94. LuCI: openwrt-25.12 branch 26.207.72448~3727980.

  1. Use resolver_set='none' with domain policies routing ifconfig.co, github.com and raw.githubusercontent.com via WAN. The failure also occurs with strict_enforcement=0; procd_reload_delay=5 was already configured.

  2. Configure OpenWrt's dnsmasq to use a Pi-hole on the LAN. Pi-hole queries its local Unbound, which forwards to VPN DNS servers. Unbound's upstream traffic therefore passes through OpenWrt to reach tun0.

  3. Switch Unbound's upstream DNS servers from OpenVPN hooks:

    route-up /etc/openvpn/up.sh
    route-pre-down /etc/openvpn/down.sh
    
  4. Trigger a full PBR policy rebuild during a VPN connection transition. Observe a rebuild that requires fresh upstream DNS answers; cached answers can mask the failure. For comparison testing, the DNS caches on OpenWrt, Pi-hole and Unbound were cleared.

  5. Inspect PBR's resolution errors and active nft rules. Capture DNS on both OpenWrt and Pi-hole with tcpdump -i any, filtering the formatted output to the affected domain names.

The issue was intermittent before the local fix. After the one-line PBR fix, fresh DNS tests and extended testing succeeded.

Actual Behaviour

PBR intermittently reported Failed to resolve during full policy rebuilds. The affected domains then lacked their IPv4 destination rules. A later successful DNS query did not automatically restore those rules.

PBR service error messages

PBR itself reported the following errors during the failure window captured on November 18 (chat-escaped punctuation normalized):

Wed Nov 18 17:31:40 2026 user.notice pbr [19335]: ERROR: Failed to resolve 'ifconfig.co'!
Wed Nov 18 17:31:40 2026 user.notice pbr [19335]: ERROR: Failed to resolve 'raw.githubusercontent.com'!
Wed Nov 18 17:31:40 2026 user.notice pbr [19335]: ERROR: Errors encountered, please check https://docs.openwrt.melmac.ca/pbr/1.2.2/#error-messages-details!
Suspected cause and locally tested fix

In cleanup(main_chains), PBR 1.2.2-r20 executes this directly against the live ruleset:

nft_call flush chain inet "$nftTable" "${i}"

With nftTable=fw4, nftPrefix=pbr and i=forward, the missing prefix targets fw4's general forward chain rather than PBR's own pbr_forward chain:

Script expression Actual chain
${nftPrefix}_${i} pbr_forward (PBR-owned)
${i} forward (fw4 base chain)

The router's base chain has type filter hook forward priority filter; policy drop;. Flushing it removes the accept rules while retaining the drop policy, temporarily blocking forwarded traffic. PBR performs this cleanup before resolving domain policies and reloads fw4 only after policy processing. Thus the LAN resolver's upstream traffic can be blocked precisely while PBR needs fresh DNS answers.

Expected behaviour: cleanup should target PBR-owned chains and preserve fw4's unrelated forwarding rules.

This one-line change fixed the observed problem locally:

- nft_call flush chain inet "$nftTable" "${i}"
+ nft_call flush chain inet "$nftTable" "${nftPrefix}_${i}"

Affected code: net/pbr/files/etc/init.d/pbr, cleanup(main_chains).

Validation

After clearing the OpenWrt, Pi-hole and Unbound caches, fresh A lookups for ifconfig.co, github.com and raw.githubusercontent.com received matching upstream replies through tun0 in about 24 ms during policy processing. Extended testing through the following day remained error-free.

The tcpdump excerpts below support the diagnosis together with the code path and base-chain drop policy. They are not an nftables trace identifying a specific drop verdict.

Selected tcpdump evidence before and after the fix

These are excerpts of our domain-filtered, human-readable tcpdump output. Labels are translated to English and DNS server addresses omitted; timestamps, DNS IDs, ports and interface directions are retained.

Before the fix — Pi-hole: The same A query reappeared about 2.5 seconds later at both resolver hops. No successful reply is shown in this excerpt; these lines alone do not identify the point of failure.

2026-11-18 20:02:15.247181 | ifconfig.co A | OpenWrt -> Pi-hole | REQUEST | id=23060 port=33778
2026-11-18 20:02:15.247399 | ifconfig.co A | Pi-hole -> Unbound | REQUEST | id=13320 port=44609
2026-11-18 20:02:17.750166 | ifconfig.co A | OpenWrt -> Pi-hole | REQUEST | id=23060 port=33778
2026-11-18 20:02:17.750369 | ifconfig.co A | Pi-hole -> Unbound | REQUEST | id=13320 port=44609

Before the fix — OpenWrt, a separate failure window: An upstream query arrived on LAN interfaces. No matching tun0 output or reply was observed in that failure excerpt. Combined with the code path flushing forward before policy resolution and its retained policy drop, this supports the forwarding-blockage diagnosis.

2026-11-18 19:55:50.587947 | ifconfig.co A | LAN/Router -> VPN-DNS | REQUEST | id=16747 port=40740 | iface=eth0 dir=In source=Pi-hole-LAN destination=VPN-DNS
2026-11-18 19:55:50.587947 | ifconfig.co A | LAN/Router -> VPN-DNS | REQUEST | id=16747 port=40740 | iface=br-lan dir=In source=Pi-hole-LAN destination=VPN-DNS

After the fix — OpenWrt, fresh A lookup during policy processing: The query left through tun0; its matching NOERROR reply arrived about 24 ms later and was forwarded back to Pi-hole.

2026-11-18 21:12:01.795067 | ifconfig.co A | LAN/Router -> VPN-DNS | REQUEST | id=47141 port=25264 | iface=br-lan dir=In source=Pi-hole-LAN destination=VPN-DNS
2026-11-18 21:12:01.795144 | ifconfig.co A | LAN/Router -> VPN-DNS | REQUEST | id=47141 port=25264 | iface=tun0 dir=Out source=other-IP destination=VPN-DNS
2026-11-18 21:12:01.818940 | ifconfig.co A | VPN-DNS -> LAN/Router | RESPONSE NOERROR | id=47141 port=25264 | records=2/0/1 | iface=tun0 dir=In source=VPN-DNS destination=other-IP
2026-11-18 21:12:01.818994 | ifconfig.co A | VPN-DNS -> LAN/Router | RESPONSE NOERROR | id=47141 port=25264 | records=2/0/1 | iface=br-lan dir=Out source=VPN-DNS destination=Pi-hole-LAN

Next-day checks: Pi-hole received an A answer from Unbound; in a separate router capture, a DNS HTTPS query and its reply traversed tun0. These are different queries at different times, not one combined transaction. HTTPS here is a DNS record type, not the A-record policy-resolution test above.

2026-11-19 13:58:25.769280 | ifconfig.co A | Pi-hole -> Unbound | REQUEST | id=57856 port=47374
2026-11-19 13:58:25.817993 | ifconfig.co A | Unbound -> Pi-hole | RESPONSE NOERROR | id=57856 port=47374 | records=2/0/1
2026-11-19 20:15:31.908774 | ifconfig.co HTTPS | LAN/Router -> VPN-DNS | REQUEST | id=48338 port=42077 | iface=tun0 dir=Out source=other-IP destination=VPN-DNS
2026-11-19 20:15:31.937429 | ifconfig.co HTTPS | VPN-DNS -> LAN/Router | RESPONSE NOERROR | id=48338 port=42077 | records=1/0/1 | iface=tun0 dir=In source=VPN-DNS destination=other-IP

Capturing on any can show the same packet on both eth0 and br-lan. Such near-simultaneous observations are not counted as separate DNS retries; the seconds-apart repetitions above are the relevant distinction.

Additional package check

The candidate change was also packaged successfully using the official OpenWrt 25.12.5 x86/64 SDK in Debian 13 / WSL 2: make -j2 package/pbr/compile NO_DEPS=1 V=s (shell-only package; dependency rebuilds skipped). The resulting r21 APK passed integrity and packaged-script checks. Runtime tests used the same init-script fix in installed r20, not the new APK. No new APK was installed on the router.

LLM disclosure: An LLM assisted with diagnosis, the candidate code change, log selection/translation and drafting this report. Runtime tests were performed by me on my router.

Confirmation Checklist
Lingua principale
Makefile
Stelle
4.7k
Fork
4k
Merge medio
2g 12h
PR unite (30g)
287

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openwrt/packages

Tutte le issue di openwrt/packages

Issue simili

Altre issue su Networking

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.