Projects STRLCPY tun2socks Commits 44ad654d
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■
    core/device/tun/tun_wireguard.go
    skipped 47 lines
    48 48   forcedMTU = int(t.mtu)
    49 49   }
    50 50   
    51  - nt, err := tun.CreateTUN(t.name, forcedMTU)
     51 + nt, err := createTUN(t.name, forcedMTU)
    52 52   if err != nil {
    53 53   return nil, fmt.Errorf("create tun: %w", err)
    54 54   }
    skipped 42 lines
  • ■ ■ ■ ■ ■ ■
    core/device/tun/tun_wireguard_linux.go
    skipped 2 lines
    3 3  package tun
    4 4   
    5 5  import (
    6  - "unsafe"
     6 + "fmt"
     7 + "os"
     8 + 
     9 + "golang.zx2c4.com/wireguard/tun"
     10 + gun "gvisor.dev/gvisor/pkg/tcpip/link/tun"
    7 11  )
    8 12   
    9 13  const (
    10  - virtioNetHdrLen = int(unsafe.Sizeof(virtioNetHdr{}))
    11  - offset = virtioNetHdrLen + 0 /* NO_PI */
    12  - defaultMTU = 1500
     14 + offset = 0 /* IFF_NO_PI */
     15 + defaultMTU = 1500
    13 16  )
    14 17   
    15  -// virtioNetHdr is defined in the kernel in include/uapi/linux/virtio_net.h. The
    16  -// kernel symbol is virtio_net_hdr.
    17  -type virtioNetHdr struct {
    18  - flags uint8
    19  - gsoType uint8
    20  - hdrLen uint16
    21  - gsoSize uint16
    22  - csumStart uint16
    23  - csumOffset uint16
     18 +func createTUN(name string, mtu int) (tun.Device, error) {
     19 + nfd, err := gun.Open(name)
     20 + if err != nil {
     21 + return nil, fmt.Errorf("create tun: %w", err)
     22 + }
     23 + 
     24 + fd := os.NewFile(uintptr(nfd), "/dev/net/tun")
     25 + return tun.CreateTUNFromFile(fd, mtu)
    24 26  }
    25 27   
  • ■ ■ ■ ■ ■ ■
    core/device/tun/tun_wireguard_unix.go
    skipped 1 lines
    2 2   
    3 3  package tun
    4 4   
     5 +import (
     6 + "golang.zx2c4.com/wireguard/tun"
     7 +)
     8 + 
    5 9  const (
    6 10   offset = 4 /* 4 bytes TUN_PI */
    7 11   defaultMTU = 1500
    8 12  )
    9 13   
     14 +func createTUN(name string, mtu int) (tun.Device, error) {
     15 + return tun.CreateTUN(name, mtu)
     16 +}
     17 + 
  • ■ ■ ■ ■ ■ ■
    core/device/tun/tun_wireguard_windows.go
    1 1  package tun
    2 2   
     3 +import (
     4 + "golang.zx2c4.com/wireguard/tun"
     5 +)
     6 + 
    3 7  const (
    4 8   offset = 0
    5 9   defaultMTU = 0 /* auto */
    6 10  )
    7 11   
     12 +func createTUN(name string, mtu int) (tun.Device, error) {
     13 + return tun.CreateTUN(name, mtu)
     14 +}
     15 + 
Please wait...
Page is in error, reload to recover