mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-10 19:20:15 +08:00
Feature: fdbased open fd with offset (#272)
This commit is contained in:
@@ -21,7 +21,7 @@ type FD struct {
|
|||||||
mtu uint32
|
mtu uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func Open(name string, mtu uint32) (device.Device, error) {
|
func Open(name string, mtu uint32, offset int) (device.Device, error) {
|
||||||
fd, err := strconv.Atoi(name)
|
fd, err := strconv.Atoi(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot open fd: %s", name)
|
return nil, fmt.Errorf("cannot open fd: %s", name)
|
||||||
@@ -29,7 +29,7 @@ func Open(name string, mtu uint32) (device.Device, error) {
|
|||||||
if mtu == 0 {
|
if mtu == 0 {
|
||||||
mtu = defaultMTU
|
mtu = defaultMTU
|
||||||
}
|
}
|
||||||
return open(fd, mtu)
|
return open(fd, mtu, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FD) Type() string {
|
func (f *FD) Type() string {
|
||||||
|
@@ -6,6 +6,6 @@ import (
|
|||||||
"github.com/xjasonlyu/tun2socks/v2/core/device"
|
"github.com/xjasonlyu/tun2socks/v2/core/device"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Open(name string, mtu uint32) (device.Device, error) {
|
func Open(name string, mtu uint32, offset int) (device.Device, error) {
|
||||||
return nil, errors.New("not supported")
|
return nil, errors.New("not supported")
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/xjasonlyu/tun2socks/v2/core/device"
|
"github.com/xjasonlyu/tun2socks/v2/core/device"
|
||||||
)
|
)
|
||||||
|
|
||||||
func open(fd int, mtu uint32) (device.Device, error) {
|
func open(fd int, mtu uint32, offset int) (device.Device, error) {
|
||||||
f := &FD{fd: fd, mtu: mtu}
|
f := &FD{fd: fd, mtu: mtu}
|
||||||
|
|
||||||
ep, err := fdbased.New(&fdbased.Options{
|
ep, err := fdbased.New(&fdbased.Options{
|
||||||
|
@@ -10,10 +10,10 @@ import (
|
|||||||
"github.com/xjasonlyu/tun2socks/v2/core/device/iobased"
|
"github.com/xjasonlyu/tun2socks/v2/core/device/iobased"
|
||||||
)
|
)
|
||||||
|
|
||||||
func open(fd int, mtu uint32) (device.Device, error) {
|
func open(fd int, mtu uint32, offset int) (device.Device, error) {
|
||||||
f := &FD{fd: fd, mtu: mtu}
|
f := &FD{fd: fd, mtu: mtu}
|
||||||
|
|
||||||
ep, err := iobased.New(os.NewFile(uintptr(fd), f.Name()), mtu, 0)
|
ep, err := iobased.New(os.NewFile(uintptr(fd), f.Name()), mtu, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("create endpoint: %w", err)
|
return nil, fmt.Errorf("create endpoint: %w", err)
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ func parseDevice(s string, mtu uint32) (device.Device, error) {
|
|||||||
|
|
||||||
switch driver {
|
switch driver {
|
||||||
case fdbased.Driver:
|
case fdbased.Driver:
|
||||||
return fdbased.Open(name, mtu)
|
return fdbased.Open(name, mtu, 0)
|
||||||
case tun.Driver:
|
case tun.Driver:
|
||||||
return tun.Open(name, mtu)
|
return tun.Open(name, mtu)
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user