aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMaximilian <public@complexvector.space>2023-12-11 07:36:18 +0100
committerGitHub <noreply@github.com>2023-12-11 07:36:18 +0100
commit16db6fcf3d982eafd256e7a836670a6b70f06f2c (patch)
tree8bdd66de425dc8b0e154141375c3f9a2d594aa74 /cmd
parent4c5528bd0eece405903f6ecc3dbebdd804ca8488 (diff)
downloadsyncthing-16db6fcf3d982eafd256e7a836670a6b70f06f2c.tar.gz
syncthing-16db6fcf3d982eafd256e7a836670a6b70f06f2c.zip
lib/nat, lib/upnp: IPv6 UPnP support (#9010)
This pull request allows syncthing to request an IPv6 [pinhole](https://en.wikipedia.org/wiki/Firewall_pinhole), addressing issue #7406. This helps users who prefer to use IPv6 for hosting their services or are forced to do so because of [CGNAT](https://en.wikipedia.org/wiki/Carrier-grade_NAT). Otherwise, such users would have to configure their firewall manually to allow syncthing traffic to pass through while IPv4 users can use UPnP to take care of network configuration already. ### Testing I have tested this in a virtual machine setup with miniupnpd running on the virtualized router. It successfully added an IPv6 pinhole when used with IPv6 only, an IPv4 port mapping when used with IPv4 only and both when dual-stack (IPv4 and IPv6) is used. Automated tests could be added for SOAP responses from the router but automatically testing this with a real network is likely infeasible. ### Documentation https://docs.syncthing.net/users/firewall.html could be updated to mention the fact that UPnP now works with IPv6, although this change is more "behind the scenes". --------- Co-authored-by: Simon Frei <freisim93@gmail.com> Co-authored-by: bt90 <btom1990@googlemail.com> Co-authored-by: André Colomb <github.com@andre.colomb.de>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/strelaysrv/main.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/cmd/strelaysrv/main.go b/cmd/strelaysrv/main.go
index be682a565..bc24912f6 100644
--- a/cmd/strelaysrv/main.go
+++ b/cmd/strelaysrv/main.go
@@ -194,7 +194,15 @@ func main() {
cfg.Options.NATTimeoutS = natTimeout
})
natSvc := nat.NewService(id, wrapper)
- mapping := mapping{natSvc.NewMapping(nat.TCP, addr.IP, addr.Port)}
+ var ipVersion nat.IPVersion
+ if strings.HasSuffix(proto, "4") {
+ ipVersion = nat.IPv4Only
+ } else if strings.HasSuffix(proto, "6") {
+ ipVersion = nat.IPv6Only
+ } else {
+ ipVersion = nat.IPvAny
+ }
+ mapping := mapping{natSvc.NewMapping(nat.TCP, ipVersion, addr.IP, addr.Port)}
if natEnabled {
ctx, cancel := context.WithCancel(context.Background())