|
|
@ -14,7 +14,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/sagernet/wireguard-go/tun"
|
|
|
|
"github.com/sagernet/wireguard-go/tun"
|
|
|
|
"github.com/xtls/xray-core/features/dns"
|
|
|
|
"github.com/xtls/xray-core/features/dns"
|
|
|
|
"gvisor.dev/gvisor/pkg/bufferv2"
|
|
|
|
"gvisor.dev/gvisor/pkg/buffer"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip/header"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip/header"
|
|
|
@ -30,7 +30,7 @@ type netTun struct {
|
|
|
|
ep *channel.Endpoint
|
|
|
|
ep *channel.Endpoint
|
|
|
|
stack *stack.Stack
|
|
|
|
stack *stack.Stack
|
|
|
|
events chan tun.Event
|
|
|
|
events chan tun.Event
|
|
|
|
incomingPacket chan *bufferv2.View
|
|
|
|
incomingPacket chan *buffer.View
|
|
|
|
mtu int
|
|
|
|
mtu int
|
|
|
|
dnsClient dns.Client
|
|
|
|
dnsClient dns.Client
|
|
|
|
hasV4, hasV6 bool
|
|
|
|
hasV4, hasV6 bool
|
|
|
@ -48,7 +48,7 @@ func CreateNetTUN(localAddresses []netip.Addr, dnsClient dns.Client, mtu int) (t
|
|
|
|
ep: channel.New(1024, uint32(mtu), ""),
|
|
|
|
ep: channel.New(1024, uint32(mtu), ""),
|
|
|
|
stack: stack.New(opts),
|
|
|
|
stack: stack.New(opts),
|
|
|
|
events: make(chan tun.Event, 10),
|
|
|
|
events: make(chan tun.Event, 10),
|
|
|
|
incomingPacket: make(chan *bufferv2.View),
|
|
|
|
incomingPacket: make(chan *buffer.View),
|
|
|
|
dnsClient: dnsClient,
|
|
|
|
dnsClient: dnsClient,
|
|
|
|
mtu: mtu,
|
|
|
|
mtu: mtu,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -66,7 +66,7 @@ func CreateNetTUN(localAddresses []netip.Addr, dnsClient dns.Client, mtu int) (t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protoAddr := tcpip.ProtocolAddress{
|
|
|
|
protoAddr := tcpip.ProtocolAddress{
|
|
|
|
Protocol: protoNumber,
|
|
|
|
Protocol: protoNumber,
|
|
|
|
AddressWithPrefix: tcpip.Address(ip.AsSlice()).WithPrefix(),
|
|
|
|
AddressWithPrefix: tcpip.AddrFromSlice(ip.AsSlice()).WithPrefix(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tcpipErr := dev.stack.AddProtocolAddress(1, protoAddr, stack.AddressProperties{})
|
|
|
|
tcpipErr := dev.stack.AddProtocolAddress(1, protoAddr, stack.AddressProperties{})
|
|
|
|
if tcpipErr != nil {
|
|
|
|
if tcpipErr != nil {
|
|
|
@ -116,7 +116,7 @@ func (tun *netTun) Write(buf []byte, offset int) (int, error) {
|
|
|
|
return 0, nil
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pkb := stack.NewPacketBuffer(stack.PacketBufferOptions{Payload: bufferv2.MakeWithData(packet)})
|
|
|
|
pkb := stack.NewPacketBuffer(stack.PacketBufferOptions{Payload: buffer.MakeWithData(packet)})
|
|
|
|
switch packet[0] >> 4 {
|
|
|
|
switch packet[0] >> 4 {
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
tun.ep.InjectInbound(header.IPv4ProtocolNumber, pkb)
|
|
|
|
tun.ep.InjectInbound(header.IPv4ProtocolNumber, pkb)
|
|
|
@ -172,7 +172,7 @@ func convertToFullAddr(endpoint netip.AddrPort) (tcpip.FullAddress, tcpip.Networ
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tcpip.FullAddress{
|
|
|
|
return tcpip.FullAddress{
|
|
|
|
NIC: 1,
|
|
|
|
NIC: 1,
|
|
|
|
Addr: tcpip.Address(endpoint.Addr().AsSlice()),
|
|
|
|
Addr: tcpip.AddrFromSlice(endpoint.Addr().AsSlice()),
|
|
|
|
Port: endpoint.Port(),
|
|
|
|
Port: endpoint.Port(),
|
|
|
|
}, protoNumber
|
|
|
|
}, protoNumber
|
|
|
|
}
|
|
|
|
}
|
|
|
|