Try to make the tun replacable

Former-commit-id: 6be0958887
This commit is contained in:
Owen
2025-12-30 21:38:07 -05:00
parent c56696bab1
commit cce8742490
4 changed files with 517 additions and 193 deletions

View File

@@ -5,6 +5,7 @@ package device
import (
"net"
"os"
"runtime"
"github.com/fosrl/newt/logger"
"golang.org/x/sys/unix"
@@ -13,6 +14,11 @@ import (
)
func CreateTUNFromFD(tunFd uint32, mtuInt int) (tun.Device, error) {
if runtime.GOOS == "android" { // otherwise we get a permission denied
theTun, _, err := tun.CreateUnmonitoredTUNFromFD(int(tunFd))
return theTun, err
}
dupTunFd, err := unix.Dup(int(tunFd))
if err != nil {
logger.Error("Unable to dup tun fd: %v", err)