Skip to content

feat: handle creation and configuration of multiple WireGuard tunnels#3226

Open
MircoBarone wants to merge 1 commit into
liqotech:masterfrom
MircoBarone:PR1-multitunnel-flags
Open

feat: handle creation and configuration of multiple WireGuard tunnels#3226
MircoBarone wants to merge 1 commit into
liqotech:masterfrom
MircoBarone:PR1-multitunnel-flags

Conversation

@MircoBarone

Copy link
Copy Markdown
Contributor

Description

Part of the multi-tunnel WireGuard implementation. This is the first PR related to issue #3225.

Add --listen-ports and --endpoint-ports flags to the WireGuard container.

These flags allow specifying multiple ports for the Gateway server and client, respectively.
The original idea was to also include the --num-interfaces flag to indicate the number of WireGuard interfaces to create, but it is unnecessary and redundant: the same information can be inferred from the number of ports, maintaining a single source of truth.

The existing --listen-port and --endpoint-port flags are preserved for backward compatibility and default values. They can be ignored if values are provided in the new multi-port flags, ensuring that the existing infrastructure continues to work without changes.

@adamjensenbot

Copy link
Copy Markdown
Collaborator

Hi @MircoBarone. Thanks for your PR!

I am @adamjensenbot.
You can interact with me issuing a slash command in the first line of a comment.
Currently, I understand the following commands:

  • /rebase: Rebase this PR onto the master branch (You can add the option test=true to launch the tests
    when the rebase operation is completed)
  • /merge: Merge this PR into the master branch
  • /build Build Liqo components
  • /test Launch the E2E and Unit tests
  • /hold, /unhold Add/remove the hold label to prevent merging with /merge

Make sure this PR appears in the liqo changelog, adding one of the following labels:

  • feat: 🚀 New Feature
  • fix: 🐛 Bug Fix
  • refactor: 🧹 Code Refactoring
  • docs: 📝 Documentation
  • style: 💄 Code Style
  • perf: 🐎 Performance Improvement
  • test: ✅ Tests
  • chore: 🚚 Dependencies Management
  • build: 📦 Builds Management
  • ci: 👷 CI/CD
  • revert: ⏪ Reverts Previous Changes

@github-actions github-actions Bot added the feat Adds a new feature to the codebase label Mar 14, 2026
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch from eed8d0b to aceb4aa Compare March 14, 2026 20:34
@github-actions github-actions Bot added the ci Changes to CI configuration files or scripts label Mar 24, 2026
@MircoBarone

Copy link
Copy Markdown
Contributor Author

/rebase test=true

@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch from 0a09450 to 1767f22 Compare April 1, 2026 08:59
@github-actions github-actions Bot removed the ci Changes to CI configuration files or scripts label Apr 1, 2026
Comment thread pkg/gateway/tunnel/wireguard/options.go Outdated
Comment thread pkg/gateway/tunnel/wireguard/flags.go Outdated
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch from 1767f22 to a70df72 Compare April 16, 2026 20:40
@github-actions github-actions Bot added refactor Reorganizes or optimizes code without changing its behavior style Changes related to code formatting, whitespace, or linting, without affecting functionality labels Apr 16, 2026
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch 2 times, most recently from 8218c64 to 518dbb2 Compare April 16, 2026 21:06
@MircoBarone
MircoBarone marked this pull request as draft April 17, 2026 10:44
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Apr 24, 2026
@MircoBarone

Copy link
Copy Markdown
Contributor Author

I have updated the logic to support the creation of multiple interfaces.
This commit is an incremental step, as the interfaces are created but not yet fully configured.

I have added the GetWireguardPorts function to extract the list of ports from the flags (--endpoint-port(s), --listen-port(s)) , which is also used to determine the number of interfaces. I tried to correctly handle priority between the new plural flags and the legacy single-port flags.

I have also extended GetInterfaceIP to assign a unique IP to each interface within the 169.254.0.0/16 range. Each interface now gets its own /30 subnetwork.
I considered assigning the same IP to all interfaces, but in my opinion, it is problematic because it would generate overlapping routes where the kernel consistently picks only the first available route.
For example:

169.254.18.0/30 dev liqo-tunnel proto kernel scope link src 169.254.18.2
169.254.18.0/30 dev liqo-tunnel1 proto kernel scope link src 169.254.18.2
169.254.18.0/30 dev liqo-tunnel2 proto kernel scope link src 169.254.18.2
169.254.18.0/30 dev liqo-tunnel3 proto kernel scope link src 169.254.18.2

This would cause, in particular, issues with keepalives.

The wireguard container entrypoint has been extended to initialize N interfaces using a fail-fast approach: if the creation of even a single interface fails, the entire container is considered failed and will exit.

Additionally, all underlying interface creation functions have been refactored to support this index-based multi-tunnel logic.

@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch from b028ef3 to 6b61345 Compare April 24, 2026 09:53
@MircoBarone
MircoBarone marked this pull request as ready for review April 24, 2026 09:55
@github-actions github-actions Bot added the fix Fixes a bug in the codebase. label May 24, 2026
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch 3 times, most recently from 7429e07 to 9ac65ec Compare May 24, 2026 19:31
@MircoBarone
MircoBarone marked this pull request as draft May 24, 2026 19:37
@MircoBarone
MircoBarone marked this pull request as ready for review May 26, 2026 10:25
@MircoBarone

Copy link
Copy Markdown
Contributor Author

In the commit ad92c6b I have removed the single-port flags of the wireguard container (--endpoint-port and --listen-port) and replaced them with --endpoint-ports and --listen-ports.

This change is meant to be integrated with PR #3233 and PR #3236. The idea is to update the template later on, introducing something like this:

--endpoint-ports={{ if .Spec.Endpoint.Ports }}{{ range $i, $p := .Spec.Endpoint.Ports }}{{ if $i }},{{ end }}{{ $p }}{{ end }}{{ else }}{{ .Spec.Endpoint.Port }}{{ end }}

I will submit the template modifications once the two PRs are merged.

Let me know if you agree with this approach.

Comment thread pkg/gateway/tunnel/wireguard/netlink.go Outdated
@MircoBarone MircoBarone changed the title feat(wireguard): add listen-ports and endpoint-ports flags feat: handle creation and configuration of multiple WireGuard tunnels Jun 5, 2026
Comment thread apis/networking/v1beta1/gatewayserver_types.go
Comment thread apis/networking/v1beta1/gatewayserver_types.go
Comment thread apis/networking/v1beta1/gatewayserver_types.go
Comment thread apis/networking/v1beta1/gatewayserver_types.go Outdated
Comment thread apis/networking/v1beta1/gatewayserver_types.go Outdated
Comment thread pkg/gateway/tunnel/wireguard/netlink.go Outdated
Comment thread pkg/gateway/tunnel/wireguard/netlink.go Outdated
Comment thread pkg/gateway/tunnel/wireguard/netlink.go Outdated
Comment thread pkg/gateway/tunnel/wireguard/publickeys_controller.go Outdated
Comment thread pkg/gateway/tunnel/wireguard/publickeys_controller.go Outdated
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch 5 times, most recently from 5072e1f to c67087f Compare June 11, 2026 21:54
Comment thread deployments/liqo/templates/liqo-wireguard-gateway-client-template.yaml Outdated
Comment thread pkg/gateway/tunnel/wireguard/device.go Outdated
Comment thread pkg/gateway/tunnel/wireguard/device.go Outdated
Comment thread pkg/gateway/tunnel/wireguard/netlink.go
Comment thread pkg/gateway/tunnel/wireguard/netlink.go Outdated
Comment thread pkg/utils/kernel/threaded.go
Comment thread pkg/utils/kernel/threaded.go Outdated
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch 2 times, most recently from 1002df2 to f448783 Compare June 21, 2026 14:47
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch 2 times, most recently from 5d2402c to f24e82b Compare July 4, 2026 14:33
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch 3 times, most recently from 6fe71f2 to fa51af1 Compare July 11, 2026 22:37
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch 2 times, most recently from 21dcb9e to 0cfad4c Compare July 17, 2026 16:26
@fra98

fra98 commented Jul 18, 2026

Copy link
Copy Markdown
Member

/build

@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch from 0cfad4c to 848a117 Compare July 18, 2026 16:26
…aces

- Add '--listen-ports' and '--endpoint-ports' flags to replace legacy single-port flags.
- Rework IP assignment to support per-tunnel addressing within the 169.254.18.0/24 block.
- Add 'Ports' and 'NodePorts' fields to GatewayClient and GatewayServer CRDs.
- Enforce strict API coherence via CEL validations:
  - Make port/ports and nodePort/nodePorts mutually exclusive (reject CR if both are set).
  - Require at least one of Port or Ports to be defined.
  - Prevent duplicate values within Ports and NodePorts arrays.
- Implement threaded NAPI logic:
  - Remount '/sys' as RW (up to 100 attempts), enable threaded NAPI per interface (up to 3 attempts), and remount '/sys' back to RO.
  - Skip interfaces where threaded NAPI is already active or if sysfs is absent.
- Update WgGatewayClient and WgGatewayServer templates:
  - Generate multi-port flags dynamically based on configuration.
  - Conditionally inject 'SYS_ADMIN' capability only when multi-tunneling is active to allow sysfs remounts.
  - Complete templating for the '--enable-multipath-hash-policy' flag.
@MircoBarone
MircoBarone force-pushed the PR1-multitunnel-flags branch from 848a117 to ccd3df3 Compare July 18, 2026 16:56
@github-actions github-actions Bot removed fix Fixes a bug in the codebase. style Changes related to code formatting, whitespace, or linting, without affecting functionality refactor Reorganizes or optimizes code without changing its behavior labels Jul 18, 2026
@fra98

fra98 commented Jul 18, 2026

Copy link
Copy Markdown
Member

/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Adds a new feature to the codebase size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants