From 83c36d643d7fe49cd0fc6203e110f7c397fcc7ab Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Sun, 15 Mar 2026 09:28:10 +0300 Subject: [PATCH] implement Redmine #16284 - fix interface mismatch and reload filter_configure after service start --- .../files/usr/local/pkg/netbird/netbird.inc | 59 ++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/security/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird.inc b/security/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird.inc index ebd06989c1fb..f5cd32561f55 100644 --- a/security/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird.inc +++ b/security/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird.inc @@ -27,9 +27,10 @@ define('NETBIRD_BIN', '/usr/local/bin/netbird'); define('NETBIRD_CONFIG', '/var/db/netbird/config.json'); define('PKG_BIN', '/usr/sbin/pkg'); - function netbird_resync_config() { + netbird_patch_interface_mismatch(); + $json = file_get_contents(NETBIRD_CONFIG); $config = json_decode($json, true); @@ -147,14 +148,17 @@ function netbird_display_connection_info(): void function netbird_write_rcfile() { $rc['file'] = 'netbird.sh'; $rc['start'] .= "/usr/local/bin/netbird service start\n\t"; + $rc['start'] .= "sleep 2 && /etc/rc.filter_configure &\n\t"; $rc['stop'] .= "/usr/local/bin/netbird service stop\n\t"; $rc['restart'] .= "/usr/local/bin/netbird service restart\n\t"; + $rc['restart'] .= "sleep 2 && /etc/rc.filter_configure &\n\t"; write_rcfile($rc); } function netbird_install() { netbird_write_rcfile(); + netbird_patch_interface_mismatch(); if (!netbird_is_running()){ $cmd = implode(' ', [NETBIRD_BIN, 'service', 'start']); @@ -171,10 +175,61 @@ function netbird_deinstall() } unlink_if_exists(NETBIRD_CONFIG); + netbird_unpatch_interface_mismatch(); if (isset($config['installedpackages']['netbird'])) { unset($config['installedpackages']['netbird']); - write_config("Removed netbird configuration"); + } + + write_config("NetBird: Removed package configuration"); +} + +/** + * Add ^wt to pfSense's is_interface_mismatch() skip regex so that + * wt0 is treated like other virtual interfaces and not removed on reboot. + */ +function netbird_patch_interface_mismatch() +{ + $files = glob('/etc/inc/*.inc'); + foreach ($files as $file) { + $content = file_get_contents($file); + if ($content === false) { + continue; + } + if (strpos($content, 'is_interface_mismatch') === false) { + continue; + } + if (strpos($content, '^wt') !== false) { + return; + } + $patched = str_replace('|^wg', '|^wg|^wt', $content); + if ($patched !== $content) { + file_put_contents($file, $patched); + log_error("NetBird: Patched interface mismatch check to skip wt interfaces in {$file}"); + } } } + +/** + * Remove the ^wt entry from pfSense's mismatch skip regex on uninstall. + */ +function netbird_unpatch_interface_mismatch() +{ + $files = glob('/etc/inc/*.inc'); + foreach ($files as $file) { + $content = file_get_contents($file); + if ($content === false) { + continue; + } + if (strpos($content, '|^wt') === false) { + continue; + } + $unpatched = str_replace('|^wt', '', $content); + if ($unpatched !== $content) { + file_put_contents($file, $unpatched); + log_error("NetBird: Removed wt interface mismatch patch from {$file}"); + } + } +} + ?> \ No newline at end of file