| 1 | From: Cage maintainers |
| 2 | Subject: [PATCH] usernet: listen on native socket paths without URL parsing |
| 3 | |
| 4 | On Windows an absolute socket path contains a drive letter and backslashes. |
| 5 | Constructing unix://C:\\... treats the drive as a URL host and rejects the |
| 6 | backslashes. The endpoint is always a Unix socket; pass the path directly to |
| 7 | net.Listen, which supports AF_UNIX on Windows 10 1803 and newer. |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | @@ -20,7 +20,6 @@ import ( |
| 13 | "time" |
| 14 | |
| 15 | "github.com/balajiv113/fd" |
| 16 | - "github.com/containers/gvisor-tap-vsock/pkg/transport" |
| 17 | "github.com/containers/gvisor-tap-vsock/pkg/types" |
| 18 | "github.com/containers/gvisor-tap-vsock/pkg/virtualnetwork" |
| 19 | "github.com/miekg/dns" |
| 20 | @@ -166,7 +165,7 @@ func run(ctx context.Context, g *errgroup.Group, configuration *types.Configuration |
| 21 | return err |
| 22 | } |
| 23 | |
| 24 | - ln, err := transport.Listen(fmt.Sprintf("unix://%s", opts.Endpoint)) |
| 25 | + ln, err := net.Listen("unix", opts.Endpoint) |
| 26 | if err != nil { |
| 27 | return err |
| 28 | } |
| 29 | |
| 30 | new file mode 100644 |
| 31 | |
| 32 | |
| 33 | @@ -0,0 +1,40 @@ |
| 34 | +//go:build windows |
| 35 | + |
| 36 | +// SPDX-FileCopyrightText: Copyright The Lima Authors |
| 37 | +// SPDX-License-Identifier: Apache-2.0 |
| 38 | + |
| 39 | +package usernet |
| 40 | + |
| 41 | +import ( |
| 42 | + "context" |
| 43 | + "net" |
| 44 | + "os" |
| 45 | + "path/filepath" |
| 46 | + "testing" |
| 47 | +) |
| 48 | + |
| 49 | +func TestNetstackWindowsNativeSocketPaths(t *testing.T) { |
| 50 | + // A drive letter, spaces and URL punctuation must remain a file path. |
| 51 | + dir, err := os.MkdirTemp("", "cage %23-") |
| 52 | + if err != nil { |
| 53 | + t.Fatal(err) |
| 54 | + } |
| 55 | + defer os.RemoveAll(dir) |
| 56 | + ctx, cancel := context.WithCancel(context.Background()) |
| 57 | + defer cancel() |
| 58 | + endpoint := filepath.Join(dir, "ep.sock") |
| 59 | + qemu := filepath.Join(dir, "qemu.sock") |
| 60 | + if err := StartGVisorNetstack(ctx, &GVisorNetstackOpts{ |
| 61 | + MTU: 1500, Endpoint: endpoint, QemuSocket: qemu, |
| 62 | + Subnet: "192.168.127.0/24", Async: true, |
| 63 | + }); err != nil { |
| 64 | + t.Fatal(err) |
| 65 | + } |
| 66 | + for _, path := range []string{endpoint, qemu} { |
| 67 | + conn, err := net.Dial("unix", path) |
| 68 | + if err != nil { |
| 69 | + t.Fatalf("cannot connect to native socket %q: %v", path, err) |
| 70 | + } |
| 71 | + conn.Close() |
| 72 | + } |
| 73 | +} |