[PR #5630] [management] Add proto fields for IPv6 overlay and compact IP encoding #26334

Open
opened 2026-08-05 07:07:12 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/5630

State: closed
Merged: No


Describe your changes

Adds proto fields to support IPv6 overlay addressing and a compact binary encoding for IP prefixes in FirewallRule.

  • Add bytes address_v6 = 9 to PeerConfig for the peer's IPv6 overlay address (compact: 16 bytes IP + 1 byte prefix length)
  • Add repeated bytes peer_ips = 9 to FirewallRule, superseding the deprecated string PeerIP field, using compact encoding (5 bytes v4, 17 bytes v6)
  • Add uint32 customProtocol = 8 to FirewallRule for parity with RouteFirewallRule
  • Add shared/netiputil package with encode/decode helpers and tests for the compact prefix format

Why only FirewallRule gets a new bytes field

FirewallRule.PeerIP is the only field where sending IPv6 data to old clients is dangerous: on nftables (default on modern Linux), a v6 PeerIP causes AddPeerFiltering to return an error, which triggers a rollback of ALL peer ACL rules. The default-deny chain policy means the peer loses all connectivity (not a security issue, but a DoS to the peer). This means version gating on the management side is mandatory for this field.

Since we need to gate FirewallRule anyway, it is the natural place to also switch from string to compact bytes encoding. The repeated bytes format also future-proofs it for multi-source ACL rules (multiple prefixes per rule).

Other IP-related proto fields (routes, route firewall rules, allowed IPs, forwarding rules) already handle IPv6 correctly on existing clients, either parsing v6 CIDRs via netip.ParsePrefix or accepting variable-length bytes. Those fields do not need gating or replacement, management can start including v6 data in them for any client version.

PeerConfig.address_v6 is a new field (not replacing an existing one) since peers need both a v4 and v6 address simultaneously and the existing address field is singular.

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)

Proto-only change with no user-facing behavior yet. Client and management consumption will follow in subsequent PRs.

Summary by CodeRabbit

  • New Features

    • Added IPv6 overlay address support for peers.
    • Enhanced firewall rules with custom protocol IDs and a compact, flexible peer-prefix format; legacy PeerIP marked deprecated (still supported).
    • Implemented efficient binary encoding/decoding for IPv4 and IPv6 addresses.
  • Tests

    • Added comprehensive tests for address encoding/decoding, round-trip behavior, and error handling.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/5630 **State:** closed **Merged:** No --- ## Describe your changes Adds proto fields to support IPv6 overlay addressing and a compact binary encoding for IP prefixes in `FirewallRule`. - Add `bytes address_v6 = 9` to `PeerConfig` for the peer's IPv6 overlay address (compact: 16 bytes IP + 1 byte prefix length) - Add `repeated bytes peer_ips = 9` to `FirewallRule`, superseding the deprecated `string PeerIP` field, using compact encoding (5 bytes v4, 17 bytes v6) - Add `uint32 customProtocol = 8` to `FirewallRule` for parity with `RouteFirewallRule` - Add `shared/netiputil` package with encode/decode helpers and tests for the compact prefix format ### Why only FirewallRule gets a new bytes field FirewallRule.PeerIP is the only field where sending IPv6 data to old clients is dangerous: on nftables (default on modern Linux), a v6 PeerIP causes AddPeerFiltering to return an error, which triggers a rollback of ALL peer ACL rules. The default-deny chain policy means the peer loses all connectivity (not a security issue, but a DoS to the peer). This means version gating on the management side is mandatory for this field. Since we need to gate FirewallRule anyway, it is the natural place to also switch from string to compact bytes encoding. The repeated bytes format also future-proofs it for multi-source ACL rules (multiple prefixes per rule). Other IP-related proto fields (routes, route firewall rules, allowed IPs, forwarding rules) already handle IPv6 correctly on existing clients, either parsing v6 CIDRs via netip.ParsePrefix or accepting variable-length bytes. Those fields do not need gating or replacement, management can start including v6 data in them for any client version. PeerConfig.address_v6 is a new field (not replacing an existing one) since peers need both a v4 and v6 address simultaneously and the existing address field is singular. ## Issue ticket number and link ## Stack <!-- branch-stack --> ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] 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) Proto-only change with no user-facing behavior yet. Client and management consumption will follow in subsequent PRs. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added IPv6 overlay address support for peers. * Enhanced firewall rules with custom protocol IDs and a compact, flexible peer-prefix format; legacy PeerIP marked deprecated (still supported). * Implemented efficient binary encoding/decoding for IPv4 and IPv6 addresses. * **Tests** * Added comprehensive tests for address encoding/decoding, round-trip behavior, and error handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
saavagebueno added the pull-request label 2026-08-05 07:07:12 -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#26334