From cd5b9e8954e919894de1d9f5ce772fbdd9a87397 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Tue, 1 Feb 2022 17:17:09 +0800 Subject: [PATCH] Chore: rename to fdbased --- core/device/{fd => fdbased}/fd.go | 2 +- core/device/{fd => fdbased}/fd_unix.go | 2 +- core/device/{fd => fdbased}/fd_windows.go | 2 +- core/device/{fd => fdbased}/open_linux.go | 7 ++++--- core/device/{fd => fdbased}/open_others.go | 2 +- engine/parse.go | 6 +++--- 6 files changed, 11 insertions(+), 10 deletions(-) rename core/device/{fd => fdbased}/fd.go (74%) rename core/device/{fd => fdbased}/fd_unix.go (97%) rename core/device/{fd => fdbased}/fd_windows.go (91%) rename core/device/{fd => fdbased}/open_linux.go (81%) rename core/device/{fd => fdbased}/open_others.go (96%) diff --git a/core/device/fd/fd.go b/core/device/fdbased/fd.go similarity index 74% rename from core/device/fd/fd.go rename to core/device/fdbased/fd.go index 0e5c66f..20ae348 100644 --- a/core/device/fd/fd.go +++ b/core/device/fdbased/fd.go @@ -1,4 +1,4 @@ -package fd +package fdbased const Driver = "fd" diff --git a/core/device/fd/fd_unix.go b/core/device/fdbased/fd_unix.go similarity index 97% rename from core/device/fd/fd_unix.go rename to core/device/fdbased/fd_unix.go index 5b7d49d..cb9617b 100644 --- a/core/device/fd/fd_unix.go +++ b/core/device/fdbased/fd_unix.go @@ -1,6 +1,6 @@ //go:build !windows -package fd +package fdbased import ( "fmt" diff --git a/core/device/fd/fd_windows.go b/core/device/fdbased/fd_windows.go similarity index 91% rename from core/device/fd/fd_windows.go rename to core/device/fdbased/fd_windows.go index 0e7d5a3..897108b 100644 --- a/core/device/fd/fd_windows.go +++ b/core/device/fdbased/fd_windows.go @@ -1,4 +1,4 @@ -package fd +package fdbased import ( "errors" diff --git a/core/device/fd/open_linux.go b/core/device/fdbased/open_linux.go similarity index 81% rename from core/device/fd/open_linux.go rename to core/device/fdbased/open_linux.go index 8cd98f5..97797ca 100644 --- a/core/device/fd/open_linux.go +++ b/core/device/fdbased/open_linux.go @@ -1,4 +1,4 @@ -package fd +package fdbased import ( "fmt" @@ -12,8 +12,9 @@ func open(fd int, mtu uint32) (device.Device, error) { f := &FD{fd: fd, mtu: mtu} ep, err := fdbased.New(&fdbased.Options{ - MTU: mtu, - FDs: []int{fd}, + FDs: []int{fd}, + MTU: mtu, + // TUN only, ignore ethernet header. EthernetHeader: false, }) if err != nil { diff --git a/core/device/fd/open_others.go b/core/device/fdbased/open_others.go similarity index 96% rename from core/device/fd/open_others.go rename to core/device/fdbased/open_others.go index 977353c..16f41a4 100644 --- a/core/device/fd/open_others.go +++ b/core/device/fdbased/open_others.go @@ -1,6 +1,6 @@ //go:build !linux && !windows -package fd +package fdbased import ( "fmt" diff --git a/engine/parse.go b/engine/parse.go index b8d1293..12958f5 100644 --- a/engine/parse.go +++ b/engine/parse.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/xjasonlyu/tun2socks/v2/core/device" - "github.com/xjasonlyu/tun2socks/v2/core/device/fd" + "github.com/xjasonlyu/tun2socks/v2/core/device/fdbased" "github.com/xjasonlyu/tun2socks/v2/core/device/tun" "github.com/xjasonlyu/tun2socks/v2/proxy" "github.com/xjasonlyu/tun2socks/v2/proxy/proto" @@ -27,8 +27,8 @@ func parseDevice(s string, mtu uint32) (device.Device, error) { driver := strings.ToLower(u.Scheme) switch driver { - case fd.Driver: - return fd.Open(name, mtu) + case fdbased.Driver: + return fdbased.Open(name, mtu) case tun.Driver: return tun.Open(name, mtu) default: