Skip to content

Commit

Permalink
UAPI for macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Noha <[email protected]>
  • Loading branch information
nohajc committed Sep 10, 2023
1 parent 469159e commit cf9371f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ipc/uapi_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func UAPIListen(name string, file *os.File) (net.Listener, error) {
if err != nil {
return nil, err
}
uapi.keventFd, err = unix.Open(socketDirectory, unix.O_RDONLY, 0)
uapi.keventFd, err = unix.Open(sockDir(), unix.O_RDONLY, 0)
if err != nil {
unix.Close(uapi.kqueueFd)
return nil, err
Expand Down
17 changes: 15 additions & 2 deletions ipc/uapi_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"net"
"os"
"strings"

"golang.org/x/sys/unix"
)
Expand All @@ -28,12 +29,24 @@ const (
// flag in wireguard-android.
var socketDirectory = "/var/run/wireguard"

const NET_EXT_APP_ID = "com.wireguard.macos.network-extension"

func sockDir() string {
baseDir := socketDirectory
homeDir, err := os.UserHomeDir()
if err == nil && strings.Contains(homeDir, NET_EXT_APP_ID) {
// this is a macOS sandboxed app, so we don't have access to /var/run
baseDir = homeDir
}
return baseDir
}

func sockPath(iface string) string {
return fmt.Sprintf("%s/%s.sock", socketDirectory, iface)
return fmt.Sprintf("%s/%s.sock", sockDir(), iface)
}

func UAPIOpen(name string) (*os.File, error) {
if err := os.MkdirAll(socketDirectory, 0o755); err != nil {
if err := os.MkdirAll(sockDir(), 0o755); err != nil {
return nil, err
}

Expand Down

0 comments on commit cf9371f

Please sign in to comment.