Files
pg/vpn/iface/iface_unix.go
rkonfj 90be7dccdd pgcli/vpn: remove --allowed-ip flag
since `--allowed-ip` is an insecure flag, the VPN now uses the system routing table
2024-07-06 12:30:20 +08:00

30 lines
570 B
Go

//go:build !windows
package iface
import (
"net"
"os"
"github.com/rkonfj/peerguard/lru"
"golang.org/x/sys/unix"
"golang.zx2c4.com/wireguard/tun"
)
func CreateFD(tunFD int, cfg Config) (*TunInterface, error) {
err := unix.SetNonblock(tunFD, true)
if err != nil {
return nil, err
}
file := os.NewFile(uintptr(tunFD), "/dev/net/tun")
device, err := tun.CreateTUNFromFile(file, 0)
if err != nil {
return nil, err
}
return &TunInterface{
dev: device,
routing: lru.New[string, net.Addr](512),
peers: lru.New[string, net.Addr](1024),
}, nil
}