[PR #5912] [MERGED] [client] Reconcile external nft accept rules on external manager reload #28741

Open
opened 2026-08-05 08:06:52 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5912
Author: @lixmal
Created: 4/17/2026
Status: Merged
Merged: 4/20/2026
Merged by: @lixmal

Base: proto-ipv6-overlayHead: nft-external-chain-monitor


📝 Commits (1)

  • 27bd60b Reconcile external nft accept rules on external changes

📊 Changes

5 files changed (+523 additions, -41 deletions)

View changed files

client/firewall/nftables/external_chain_monitor_integration_linux_test.go (+76 -0)
client/firewall/nftables/external_chain_monitor_linux.go (+199 -0)
client/firewall/nftables/external_chain_monitor_linux_test.go (+137 -0)
📝 client/firewall/nftables/manager_linux.go (+31 -0)
📝 client/firewall/nftables/router_linux.go (+80 -41)

📄 Description

Describe your changes

External nftables managers can flush or recreate their tables and chains at runtime (e.g. on firewall-cmd --reload), which wipes the netbird passthrough accept rules and breaks new flows over wt0. This adds a netlink monitor that re-inserts the rules when relevant tables/chains appear.

  • Add an nftables netlink monitor in the firewall manager; debounces event bursts and reconnects with exponential backoff on netlink errors
  • Re-apply external-chain accept rules for both v4 and v6 routers when relevant events fire
  • Make the inserts idempotent via UserData tag lookup; bail on lookup error so blind re-inserts don't accumulate duplicates
  • Add unit and root-only integration tests for the monitor

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Internal firewall reconciliation behavior, no user-facing API change.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • New Features

    • Added Linux nftables external chain monitoring to detect and automatically reconcile firewall chains created by non-NetBird processes.
    • Implemented automatic deduplication of firewall rules to prevent duplicate accept rules when managing external filter chains.
  • Tests

    • Added unit and integration test coverage for external chain monitoring and reconciliation functionality.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5912 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 4/17/2026 **Status:** ✅ Merged **Merged:** 4/20/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `proto-ipv6-overlay` ← **Head:** `nft-external-chain-monitor` --- ### 📝 Commits (1) - [`27bd60b`](https://github.com/netbirdio/netbird/commit/27bd60bbe0cd96151d80fde00b7f1f18019c9047) Reconcile external nft accept rules on external changes ### 📊 Changes **5 files changed** (+523 additions, -41 deletions) <details> <summary>View changed files</summary> ➕ `client/firewall/nftables/external_chain_monitor_integration_linux_test.go` (+76 -0) ➕ `client/firewall/nftables/external_chain_monitor_linux.go` (+199 -0) ➕ `client/firewall/nftables/external_chain_monitor_linux_test.go` (+137 -0) 📝 `client/firewall/nftables/manager_linux.go` (+31 -0) 📝 `client/firewall/nftables/router_linux.go` (+80 -41) </details> ### 📄 Description ## Describe your changes External nftables managers can flush or recreate their tables and chains at runtime (e.g. on `firewall-cmd --reload`), which wipes the netbird passthrough accept rules and breaks new flows over `wt0`. This adds a netlink monitor that re-inserts the rules when relevant tables/chains appear. - Add an nftables netlink monitor in the firewall manager; debounces event bursts and reconnects with exponential backoff on netlink errors - Re-apply external-chain accept rules for both v4 and v6 routers when relevant events fire - Make the inserts idempotent via `UserData` tag lookup; bail on lookup error so blind re-inserts don't accumulate duplicates - Add unit and root-only integration tests for the monitor ## Issue ticket number and link ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) Internal firewall reconciliation behavior, no user-facing API change. ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added Linux nftables external chain monitoring to detect and automatically reconcile firewall chains created by non-NetBird processes. * Implemented automatic deduplication of firewall rules to prevent duplicate accept rules when managing external filter chains. * **Tests** * Added unit and integration test coverage for external chain monitoring and reconciliation functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 08:06:52 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#28741