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