[PR #6650] [client] Add unicast UPnP discovery for port forwarding. #29767

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6650
Author: @jnfrati
Created: 7/2/2026
Status: 🔄 Open

Base: mainHead: fix/fail-to-create-upnp-port-mapping-on-opnsense-firewall


📝 Commits (3)

  • c0cb24b [client] Add unicast UPnP discovery for port forwarding.
  • de2e0f5 Merge branch 'main' of github.com:netbirdio/netbird into fix/fail-to-create-upnp-port-mapping-on-opnsense-firewall
  • 59a09b0 fix lint issue on body close

📊 Changes

5 files changed (+745 additions, -2 deletions)

View changed files

📝 client/internal/portforward/state.go (+26 -1)
client/internal/portforward/upnp/nat.go (+155 -0)
client/internal/portforward/upnp/upnp.go (+246 -0)
client/internal/portforward/upnp/upnp_test.go (+317 -0)
📝 go.mod (+1 -1)

📄 Description

Describe your changes

Add a UPnP IGD discovery fallback that sends unicast SSDP M-SEARCH requests directly to the default gateway when PCP and multicast discovery do not find a gateway.

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)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

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)

Docs not needed as this is a fix to existing implementation

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
    • Expanded port-forwarding gateway discovery to include unicast UPnP Internet Gateway Devices (in addition to existing methods).
    • Added UPnP-based NAT port mapping with automatic renewal that reuses the previously selected external port.
  • Bug Fixes
    • Improved fallback behavior when one discovery approach fails, increasing the likelihood of finding a compatible gateway.
    • Enhanced lease handling for routers that require a “permanent lease” retry behavior.
  • Tests
    • Added coverage for UPnP discovery, mapping renewal, fallback scenarios, and error/lease-code behavior.

🔄 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/6650 **Author:** [@jnfrati](https://github.com/jnfrati) **Created:** 7/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/fail-to-create-upnp-port-mapping-on-opnsense-firewall` --- ### 📝 Commits (3) - [`c0cb24b`](https://github.com/netbirdio/netbird/commit/c0cb24b6cec6f2fe70e1691bbba9a4de0e8b4f6e) [client] Add unicast UPnP discovery for port forwarding. - [`de2e0f5`](https://github.com/netbirdio/netbird/commit/de2e0f541bbe9e454d8a0b9af038502ce4f533d9) Merge branch 'main' of github.com:netbirdio/netbird into fix/fail-to-create-upnp-port-mapping-on-opnsense-firewall - [`59a09b0`](https://github.com/netbirdio/netbird/commit/59a09b0ff30470577deaa3383e3f70dcfcf6c90e) fix lint issue on body close ### 📊 Changes **5 files changed** (+745 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/portforward/state.go` (+26 -1) ➕ `client/internal/portforward/upnp/nat.go` (+155 -0) ➕ `client/internal/portforward/upnp/upnp.go` (+246 -0) ➕ `client/internal/portforward/upnp/upnp_test.go` (+317 -0) 📝 `go.mod` (+1 -1) </details> ### 📄 Description ## Describe your changes Add a UPnP IGD discovery fallback that sends unicast SSDP M-SEARCH requests directly to the default gateway when PCP and multicast discovery do not find a gateway. ## 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) - [ ] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — **OR** I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#discuss-changes-with-the-netbird-team-first). > 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) > Docs not needed as this is a fix to existing implementation ### 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** * Expanded port-forwarding gateway discovery to include unicast UPnP Internet Gateway Devices (in addition to existing methods). * Added UPnP-based NAT port mapping with automatic renewal that reuses the previously selected external port. * **Bug Fixes** * Improved fallback behavior when one discovery approach fails, increasing the likelihood of finding a compatible gateway. * Enhanced lease handling for routers that require a “permanent lease” retry behavior. * **Tests** * Added coverage for UPnP discovery, mapping renewal, fallback scenarios, and error/lease-code behavior. <!-- 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:08:55 -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#29767