os-bind: BIND is restarted on every interface link-up, including interfaces it does not listen on

Aperta
#5,916 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à
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php

Direzione di ricerca

Start with dns/bind/src/etc/inc/plugins.inc.d/bind.inc, especially the bind_configure() hook registration and bind_configure_do() arguments; compare the interface-aware Unbound hook behavior described in the report. Use the reproduction steps to trigger link-up on an interface without a BIND listen address and check /var/log/system and the named PID. Done means such link-ups do not restart running BIND, while boot, manual reload, and listen-address link-ups still work.

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

Descrizione

Important notices

  • I have read the contributing guide lines at https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md
  • I have searched the existing issues, open and closed, and I'm convinced that mine is new. (The closest one is #3958, a BIND hang after two quick link changes, closed by the stale bot; it describes a different symptom.)
  • The title contains the plugin to which this issue belongs

Describe the bug

Whenever any interface gets a link-up event, BIND is stopped and started again, even if the interface is one BIND does not listen on.

We have two routers joined by a direct cable for pfsync/CARP (a private /24 that is not in BIND's listen addresses). When one router reboots, the other sees that link go down and up about five times. Each link-up runs rc.linkup, then interface_configure(), then the dns plugin hook. os-bind registers that hook as 'dns' => ['bind_configure_do'], so it rebuilds the config and runs a full BIND restart each time. On the router that stayed up, BIND was restarted five or six times within about 30 seconds (about 3 s each), and a monitoring query to it got SERVFAIL in between, so DNS was patchy for the whole network while the other router rebooted.

Since 26.7.9 core passes the interface to the dns hook (core#11083, the Unbound change). Unbound registers the hook as unbound_configure_do:2 and skips interfaces it doesn't care about. os-bind doesn't ask for the interface, so it never sees it. I don't know of a last working version.

To Reproduce

  1. Bring any interface down and up: ifconfig <if> down; ifconfig <if> up, or /usr/local/etc/rc.linkup start <if>.
  2. Watch /var/log/system for plugins_configure dns (...) and execute task : bind_configure_do(...).
  3. BIND stops and starts again (the named pid changes), whichever interface it was.

Expected behavior

An interface that carries none of BIND's listen addresses should not restart BIND, as with Unbound.

Relevant log files

/var/log/system on the router that stayed up when its peer rebooted: five or six plugins_configure dns (execute task : bind_configure_do(...)) lines within about 30 seconds, each followed by a BIND restart.

Additional context

We tried the same pattern for os-bind: register bind_configure_do:2, and skip the restart when none of the passed interfaces carries an address BIND listens on. BIND still restarts at boot (no interface passed) and starts if it isn't running. Diff below; it applies to current master (bind.inc unchanged since January 2024).

What we tested (HA pair, BIND listening on LAN/VLAN addresses, IPv4 and IPv6). Each case ran three times:

  • Before the change, BIND restarted every time on: the pfsync interface (hook only, rc.linkup, and a real ifconfig igc3 down/up, which restarted BIND on both routers); on the second router, an uncabled WAN and a VLAN with a listen address.
  • After the change, no restart (BIND's pid unchanged, both routers) on: the pfsync interface (hook and rc.linkup), WAN, a Tailscale interface and an IPv6 tracker interface. Also no restart in 12 observations of a real pfsync link down/up with the change on both routers.
  • After the change, BIND still restarts for an interface with a listen address (DMZ VLAN, both routers; LAN, WireGuard and a VLAN link-up, second router), when no interface is passed (second router), and it starts when it was stopped beforehand (second router).
  • Not tested: a full reboot of the peer with the change in place, and a call with an explicitly empty interface list (core doesn't pass one through plugins_configure()).
--- a/dns/bind/src/etc/inc/plugins.inc.d/bind.inc
+++ b/dns/bind/src/etc/inc/plugins.inc.d/bind.inc
@@ -36,7 +36,7 @@
 function bind_configure()
 {
     return [
-        'dns' => ['bind_configure_do'],
+        'dns' => ['bind_configure_do:2'],
     ];
 }
 
@@ -90,8 +90,44 @@
     return [$result];
 }
 
-function bind_configure_do($verbose)
+function bind_match_interface($interface_map)
 {
+    if (empty($interface_map)) {
+        /* no interface given (boot, manual reload): restart as before */
+        return true;
+    }
+
+    $model = new \OPNsense\Bind\General();
+    $listen = array_merge(
+        explode(',', (string)$model->listenv4),
+        explode(',', (string)$model->listenv6)
+    );
+
+    foreach (interfaces_addresses($interface_map) as $address) {
+        if (in_array($address['address'], $listen)) {
+            return true;
+        }
+    }
+
+    /*
+     * None of these interfaces carries an address BIND listens on
+     * (wildcard listen addresses are picked up by BIND itself),
+     * so a restart is not needed.
+     */
+    return false;
+}
+
+function bind_configure_do($verbose = false, $interface_map = null)
+{
+    if (!plugins_argument_map($interface_map)) {
+        return;
+    }
+
+    /* try to avoid restarting, but make sure to let it start if it is not running */
+    if (!bind_match_interface($interface_map) && isvalidpid('/var/run/named/pid')) {
+        return;
+    }
+
     service_log('Starting BIND...', $verbose);
 
     configd_run('template reload OPNsense/Bind');

Environment

OPNsense 26.7.9 (amd64), os-bind 1.34_4, BIND 9.20.30; two Intel igc-based routers in a CARP/pfsync pair.

AI disclosure: I used Claude (Anthropic), with several different models, to trace the hook path through the core and plugin code and to write and run the tests. I reviewed the result, ran the tests on my own routers, and I'm responsible for the report.

Lingua principale
PHP
Stelle
1.2k
Fork
926
Merge medio
1g 10h
PR unite (30g)
25

Preparare l'ambiente

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 opnsense/plugins

Tutte le issue di opnsense/plugins

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.