mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
10
olm/olm.go
10
olm/olm.go
@@ -56,6 +56,8 @@ type Config struct {
|
||||
Version string
|
||||
OrgID string
|
||||
// DoNotCreateNewClient bool
|
||||
|
||||
FileDescriptorTun uint32
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -366,16 +368,16 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string,
|
||||
}
|
||||
|
||||
tdev, err = func() (tun.Device, error) {
|
||||
if runtime.GOOS == "darwin" {
|
||||
if config.FileDescriptorTun != 0 {
|
||||
return createTUNFromFD(config.FileDescriptorTun, config.MTU)
|
||||
}
|
||||
if runtime.GOOS == "darwin" { // this is if we dont pass a fd
|
||||
interfaceName, err := findUnusedUTUN()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tun.CreateTUN(interfaceName, config.MTU)
|
||||
}
|
||||
if tunFdStr := os.Getenv(ENV_WG_TUN_FD); tunFdStr != "" {
|
||||
return createTUNFromFD(tunFdStr, config.MTU)
|
||||
}
|
||||
return tun.CreateTUN(interfaceName, config.MTU)
|
||||
}()
|
||||
|
||||
|
||||
12
olm/unix.go
12
olm/unix.go
@@ -5,25 +5,19 @@ package olm
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"golang.zx2c4.com/wireguard/ipc"
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
)
|
||||
|
||||
func createTUNFromFD(tunFdStr string, mtuInt int) (tun.Device, error) {
|
||||
fd, err := strconv.ParseUint(tunFdStr, 10, 32)
|
||||
func createTUNFromFD(tunFd uint32, mtuInt int) (tun.Device, error) {
|
||||
err := unix.SetNonblock(int(tunFd), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = unix.SetNonblock(int(fd), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file := os.NewFile(uintptr(fd), "")
|
||||
file := os.NewFile(uintptr(tunFd), "")
|
||||
return tun.CreateTUNFromFile(file, mtuInt)
|
||||
}
|
||||
func uapiOpen(interfaceName string) (*os.File, error) {
|
||||
|
||||
Reference in New Issue
Block a user