Skip to content

Commit

Permalink
net: Create client endpoint in the same dir as the remote's
Browse files Browse the repository at this point in the history
With unixgram sockets, we need to specify a client endpoint, which is a
path on the filesystem with a maximum length of 104 bytes on macOS.
When using -device virtio-net,unixSocketPath=/tmp/vnet.sock, we
need to create a client endpoint before connecting to /tmp/vnet.sock.
It's currently put into `/Users/user/Library/Application Support`, which
is already fairly long. Depending on the username, the 104 bytes are
easily exceeded, this has been causing problems to podman machine.

This commit will create the client endpoint in the same directory as the
server endpoint, which gives more control to the user of vfkit wrt where
this socket is going.

This fixes #194

Signed-off-by: Christophe Fergeau <[email protected]>
  • Loading branch information
cfergeau committed Sep 20, 2024
1 parent e3e642d commit 303dbf5
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions pkg/vf/virtionet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ type VirtioNet struct {
localAddr *net.UnixAddr
}

func localUnixSocketPath() (string, error) {
homeDir, err := os.UserHomeDir()
func localUnixSocketPath(dir string) (string, error) {
tmpFile, err := os.CreateTemp(dir, fmt.Sprintf("vfkit-%d-*.sock", os.Getpid()))
if err != nil {
return "", err
}
dir := filepath.Join(homeDir, "Library", "Application Support", "vfkit")
if err := os.MkdirAll(dir, 0755); err != nil {
return "", err
}
tmpFile, err := os.CreateTemp(dir, fmt.Sprintf("net-%d-*.sock", os.Getpid()))
if err != nil {
return "", err
}
// slightly racy, but this is in a directory only user-writable
// slightly racy, but hopefully this is in a directory only user-writable
defer tmpFile.Close()
defer os.Remove(tmpFile.Name())

Expand All @@ -44,7 +36,7 @@ func (dev *VirtioNet) connectUnixPath() error {
Name: dev.UnixSocketPath,
Net: "unixgram",
}
localSocketPath, err := localUnixSocketPath()
localSocketPath, err := localUnixSocketPath(filepath.Dir(dev.UnixSocketPath))
if err != nil {
return err
}
Expand Down

0 comments on commit 303dbf5

Please sign in to comment.