mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 21:31:16 +08:00
fix: no_gvisor compile failed for target linux
This commit is contained in:
parent
850c52d07c
commit
9a035d3c51
@ -1,12 +1,7 @@
|
||||
package fdbased
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Dreamacro/clash/listener/tun/device"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/link/rawfile"
|
||||
)
|
||||
|
||||
func open(fd int, mtu uint32) (device.Device, error) {
|
||||
@ -16,17 +11,7 @@ func open(fd int, mtu uint32) (device.Device, error) {
|
||||
}
|
||||
|
||||
func (f *FD) useEndpoint() error {
|
||||
ep, err := fdbased.New(&fdbased.Options{
|
||||
FDs: []int{f.fd},
|
||||
MTU: f.mtu,
|
||||
// TUN only, ignore ethernet header.
|
||||
EthernetHeader: false,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("create endpoint: %w", err)
|
||||
}
|
||||
f.LinkEndpoint = ep
|
||||
return nil
|
||||
return f.newLinuxEp()
|
||||
}
|
||||
|
||||
func (f *FD) useIOBased() error {
|
||||
@ -34,23 +19,9 @@ func (f *FD) useIOBased() error {
|
||||
}
|
||||
|
||||
func (f *FD) Read(packet []byte) (int, error) {
|
||||
n, gvErr := rawfile.BlockingRead(f.fd, packet)
|
||||
if gvErr != nil {
|
||||
return 0, fmt.Errorf("read error: %s", gvErr.String())
|
||||
}
|
||||
|
||||
return n, nil
|
||||
return f.read(packet)
|
||||
}
|
||||
|
||||
func (f *FD) Write(packet []byte) (int, error) {
|
||||
n := len(packet)
|
||||
if n == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
gvErr := rawfile.NonBlockingWrite(f.fd, packet)
|
||||
if gvErr != nil {
|
||||
return 0, fmt.Errorf("write error: %s", gvErr.String())
|
||||
}
|
||||
return n, nil
|
||||
return f.write(packet)
|
||||
}
|
||||
|
45
listener/tun/device/fdbased/open_linux_gvisor.go
Normal file
45
listener/tun/device/fdbased/open_linux_gvisor.go
Normal file
@ -0,0 +1,45 @@
|
||||
//go:build !no_gvisor && (linux || android)
|
||||
|
||||
package fdbased
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/link/rawfile"
|
||||
)
|
||||
|
||||
func (f *FD) newLinuxEp() error {
|
||||
ep, err := fdbased.New(&fdbased.Options{
|
||||
FDs: []int{f.fd},
|
||||
MTU: f.mtu,
|
||||
// TUN only, ignore ethernet header.
|
||||
EthernetHeader: false,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("create endpoint: %w", err)
|
||||
}
|
||||
f.LinkEndpoint = ep
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FD) read(packet []byte) (int, error) {
|
||||
n, gvErr := rawfile.BlockingRead(f.fd, packet)
|
||||
if gvErr != nil {
|
||||
return 0, fmt.Errorf("read error: %s", gvErr.String())
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (f *FD) write(packet []byte) (int, error) {
|
||||
n := len(packet)
|
||||
if n == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
gvErr := rawfile.NonBlockingWrite(f.fd, packet)
|
||||
if gvErr != nil {
|
||||
return 0, fmt.Errorf("write error: %s", gvErr.String())
|
||||
}
|
||||
return n, nil
|
||||
}
|
19
listener/tun/device/fdbased/open_linux_no_gvisor.go
Normal file
19
listener/tun/device/fdbased/open_linux_no_gvisor.go
Normal file
@ -0,0 +1,19 @@
|
||||
//go:build no_gvisor
|
||||
|
||||
package fdbased
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (f *FD) newLinuxEp() error {
|
||||
return fmt.Errorf("unsupported gvisor on the build")
|
||||
}
|
||||
|
||||
func (f *FD) read(packet []byte) (int, error) {
|
||||
return 0, fmt.Errorf("unsupported gvisor on the build")
|
||||
}
|
||||
|
||||
func (f *FD) write(packet []byte) (int, error) {
|
||||
return 0, fmt.Errorf("unsupported gvisor on the build")
|
||||
}
|
@ -16,7 +16,7 @@ func open(fd int, mtu uint32) (device.Device, error) {
|
||||
}
|
||||
|
||||
func (f *FD) useEndpoint() error {
|
||||
return newEp(f)
|
||||
return f.newEpOther()
|
||||
}
|
||||
|
||||
func (f *FD) useIOBased() error {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"github.com/Dreamacro/clash/listener/tun/device/iobased"
|
||||
)
|
||||
|
||||
func newEp(f *FD) error {
|
||||
func (f *FD) newEpOther() error {
|
||||
ep, err := iobased.New(os.NewFile(uintptr(f.fd), f.Name()), f.mtu, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create endpoint: %w", err)
|
||||
|
@ -6,6 +6,6 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func newEp(f *FD) error {
|
||||
func (f *FD) newEpOther() error {
|
||||
return fmt.Errorf("unsupported gvisor on the build")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user