diff options
author | Jason T. Greene <jason.greene@redhat.com> | 2022-04-25 15:55:42 -0500 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2022-05-03 13:45:59 -0400 |
commit | 65108dede1f5ec523077f5f230e29f3a0e6f053d (patch) | |
tree | cb68b75bc87bc5a71a0ad3c3e4a0e55b637d2abd /cmd/rootlessport/wsl.go | |
parent | 95633146e08aa0bc81aa3d7949c3ef02f38a2308 (diff) | |
download | podman-65108dede1f5ec523077f5f230e29f3a0e6f053d.tar.gz podman-65108dede1f5ec523077f5f230e29f3a0e6f053d.tar.bz2 podman-65108dede1f5ec523077f5f230e29f3a0e6f053d.zip |
Use simulated dual-stack binds when using WSL
Resolves a WSL problem where traffic from only one stack is relayed
Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
Diffstat (limited to 'cmd/rootlessport/wsl.go')
-rw-r--r-- | cmd/rootlessport/wsl.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cmd/rootlessport/wsl.go b/cmd/rootlessport/wsl.go new file mode 100644 index 000000000..c1e67ba87 --- /dev/null +++ b/cmd/rootlessport/wsl.go @@ -0,0 +1,37 @@ +package main + +import ( + "net" + "strings" + + "github.com/containers/common/pkg/machine" + rkport "github.com/rootless-containers/rootlesskit/pkg/port" +) + +// WSL machines do not relay ipv4 traffic to dual-stack ports, simulate instead +func splitDualStackSpecIfWsl(spec rkport.Spec) []rkport.Spec { + specs := []rkport.Spec{spec} + protocol := spec.Proto + if machine.MachineHostType() != machine.Wsl || strings.HasSuffix(protocol, "4") || strings.HasSuffix(protocol, "6") { + return specs + } + + ip := net.ParseIP(spec.ParentIP) + splitLoopback := ip.IsLoopback() && ip.To4() == nil + // Map ::1 and 0.0.0.0/:: to ipv4 + ipv6 to simulate dual-stack + if ip.IsUnspecified() || splitLoopback { + specs = append(specs, spec) + specs[0].Proto = protocol + "4" + specs[1].Proto = protocol + "6" + if splitLoopback { + // Hacky, but we will only have one ipv4 loopback with WSL config + specs[0].ParentIP = "127.0.0.1" + } + if ip.IsUnspecified() { + specs[0].ParentIP = "0.0.0.0" + specs[1].ParentIP = "::" + } + } + + return specs +} |