-
Notifications
You must be signed in to change notification settings - Fork 20
/
open_linux_armamd64.go
55 lines (47 loc) · 1.29 KB
/
open_linux_armamd64.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//go:build (linux && amd64) || (linux && arm64)
// +build linux,amd64 linux,arm64
package tun
import (
"fmt"
"github.com/Asutorufa/yuhaiin/pkg/net/netlink"
vnetlink "github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
gun "gvisor.dev/gvisor/pkg/tcpip/link/tun"
"gvisor.dev/gvisor/pkg/tcpip/stack"
)
func init() {
openFD = func(sc netlink.TunScheme, mtu int) (stack.LinkEndpoint, error) {
switch sc.Scheme {
case "fd":
return fdbased.New(&fdbased.Options{
FDs: []int{sc.Fd},
MTU: uint32(mtu),
RXChecksumOffload: true,
})
case "tun":
// fdbased current not support gso, so open new tun direct instead of wireguard
dev, err := gun.Open(sc.Name)
if err != nil {
return nil, fmt.Errorf("create tun failed: %w", err)
}
tunLink, err := vnetlink.LinkByName(sc.Name)
if err != nil {
unix.Close(dev)
return nil, err
}
if err := vnetlink.LinkSetMTU(tunLink, mtu); err != nil {
unix.Close(dev)
return nil, err
}
return fdbased.New(&fdbased.Options{
FDs: []int{dev},
MTU: uint32(mtu),
RXChecksumOffload: true,
MaxSyscallHeaderBytes: 0x00,
})
default:
return nil, fmt.Errorf("invalid tun: %v", sc)
}
}
}