github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/cmd/rootlessport/wsl.go (about) 1 package main 2 3 import ( 4 "net" 5 "strings" 6 7 "github.com/containers/common/pkg/machine" 8 rkport "github.com/rootless-containers/rootlesskit/pkg/port" 9 ) 10 11 // WSL machines do not relay ipv4 traffic to dual-stack ports, simulate instead 12 func splitDualStackSpecIfWsl(spec rkport.Spec) []rkport.Spec { 13 specs := []rkport.Spec{spec} 14 protocol := spec.Proto 15 if machine.MachineHostType() != machine.Wsl || strings.HasSuffix(protocol, "4") || strings.HasSuffix(protocol, "6") { 16 return specs 17 } 18 19 ip := net.ParseIP(spec.ParentIP) 20 splitLoopback := ip.IsLoopback() && ip.To4() == nil 21 // Map ::1 and 0.0.0.0/:: to ipv4 + ipv6 to simulate dual-stack 22 if ip.IsUnspecified() || splitLoopback { 23 specs = append(specs, spec) 24 specs[0].Proto = protocol + "4" 25 specs[1].Proto = protocol + "6" 26 if splitLoopback { 27 // Hacky, but we will only have one ipv4 loopback with WSL config 28 specs[0].ParentIP = "127.0.0.1" 29 } 30 if ip.IsUnspecified() { 31 specs[0].ParentIP = "0.0.0.0" 32 specs[1].ParentIP = "::" 33 } 34 } 35 36 return specs 37 }