fix tun app lints

This commit is contained in:
Shelikhoo 2023-10-23 01:44:36 +01:00
parent e87af12bf8
commit 0ca849637d
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
10 changed files with 39 additions and 27 deletions

View File

@ -1,8 +1,9 @@
package device
import (
"github.com/v2fly/v2ray-core/v5/common"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"github.com/v2fly/v2ray-core/v5/common"
)
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen

View File

@ -8,10 +8,11 @@ import (
"fmt"
"unsafe"
"github.com/v2fly/v2ray-core/v5/app/tun/device"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"github.com/v2fly/v2ray-core/v5/app/tun/device"
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
"gvisor.dev/gvisor/pkg/tcpip/link/rawfile"
"gvisor.dev/gvisor/pkg/tcpip/link/tun"

View File

@ -1,10 +1,12 @@
package device
import (
"io"
"github.com/v2fly/v2ray-core/v5/common/errors"
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"io"
)
func NewLinkWriterToWriter(writer stack.LinkWriter) io.Writer {
@ -16,7 +18,6 @@ type linkWriterToWriter struct {
}
func (l linkWriterToWriter) Write(p []byte) (n int, err error) {
buffer := buffer.MakeWithData(p)
packetBufferPtr := stack.NewPacketBuffer(stack.PacketBufferOptions{
Payload: buffer,

View File

@ -4,6 +4,13 @@ import (
"context"
"time"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/waiter"
tun_net "github.com/v2fly/v2ray-core/v5/app/tun/net"
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/buf"
@ -15,12 +22,6 @@ import (
"github.com/v2fly/v2ray-core/v5/features/policy"
"github.com/v2fly/v2ray-core/v5/features/routing"
internet "github.com/v2fly/v2ray-core/v5/transport/internet"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/waiter"
)
const (
@ -150,7 +151,6 @@ func applySocketOptions(s *stack.Stack, endpoint tcpip.Endpoint, config *interne
if config.TcpKeepAliveInterval > 0 || config.TcpKeepAliveIdle > 0 {
endpoint.SocketOptions().SetKeepAlive(true)
}
{
var sendBufferSizeRangeOption tcpip.TCPSendBufferSizeRangeOption

View File

@ -3,6 +3,11 @@ package tun
import (
"context"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/stack"
gvisor_udp "gvisor.dev/gvisor/pkg/tcpip/transport/udp"
"gvisor.dev/gvisor/pkg/waiter"
tun_net "github.com/v2fly/v2ray-core/v5/app/tun/net"
"github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/net"
@ -11,10 +16,6 @@ import (
"github.com/v2fly/v2ray-core/v5/features/policy"
"github.com/v2fly/v2ray-core/v5/features/routing"
"github.com/v2fly/v2ray-core/v5/transport/internet/udp"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/stack"
gvisor_udp "gvisor.dev/gvisor/pkg/tcpip/transport/udp"
"gvisor.dev/gvisor/pkg/waiter"
)
type UDPHandler struct {

View File

@ -1,12 +1,13 @@
package tun
import (
"github.com/v2fly/v2ray-core/v5/app/router/routercommon"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"github.com/v2fly/v2ray-core/v5/app/router/routercommon"
)
func CreateNIC(id tcpip.NICID, linkEndpoint stack.LinkEndpoint) StackOption {

View File

@ -1,10 +1,11 @@
package tun
import (
"github.com/v2fly/v2ray-core/v5/app/tun/device"
"github.com/v2fly/v2ray-core/v5/app/tun/tunsorter"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"github.com/v2fly/v2ray-core/v5/app/tun/device"
"github.com/v2fly/v2ray-core/v5/app/tun/tunsorter"
)
func NewDeviceWithSorter(overlay device.Device, sorter *tunsorter.TunSorter) device.Device {
@ -30,7 +31,7 @@ func (p *packetAddrDevice) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNu
}
func (p *packetAddrDevice) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
//TODO implement me
// TODO implement me
panic("implement me")
}

View File

@ -3,11 +3,14 @@ package packetparse
import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/v2fly/v2ray-core/v5/common/net"
)
var errNotIPPacket = newError("not an IP packet")
var errNotUDPPacket = newError("not a UDP packet")
var (
errNotIPPacket = newError("not an IP packet")
errNotUDPPacket = newError("not a UDP packet")
)
var nullDestination = net.UnixDestination(net.DomainAddress("null"))
@ -56,7 +59,7 @@ func TryParseAsUDPPacket(packet []byte) (src, dst net.Destination, data []byte,
src = net.UDPDestination(srcIP, srcPort)
dst = net.UDPDestination(dstIP, dstPort)
data = udp.Payload
return
return // nolint: nakedret
}
func TryConstructUDPPacket(src, dst net.Destination, data []byte) ([]byte, error) {

View File

@ -5,6 +5,9 @@ package tun
import (
"context"
"gvisor.dev/gvisor/pkg/tcpip/stack"
core "github.com/v2fly/v2ray-core/v5"
"github.com/v2fly/v2ray-core/v5/app/tun/device"
"github.com/v2fly/v2ray-core/v5/app/tun/device/gvisor"
@ -13,7 +16,6 @@ import (
"github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v5/features/policy"
"github.com/v2fly/v2ray-core/v5/features/routing"
"gvisor.dev/gvisor/pkg/tcpip/stack"
)
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen

View File

@ -2,6 +2,9 @@ package tunsorter
import (
"context"
"io"
"sync"
"github.com/v2fly/v2ray-core/v5/app/tun/packetparse"
"github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/net"
@ -9,8 +12,6 @@ import (
vudp "github.com/v2fly/v2ray-core/v5/common/protocol/udp"
"github.com/v2fly/v2ray-core/v5/features/routing"
"github.com/v2fly/v2ray-core/v5/transport/internet/udp"
"io"
"sync"
)
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
@ -50,9 +51,9 @@ func (t *TunSorter) OnPacketReceived(b []byte) (n int, err error) {
func (t *TunSorter) onNewConnection(connection *trackedUDPConnection) {
udpDispatcherConstructor := udp.NewSplitDispatcher
switch t.packetAddrType {
switch t.packetAddrType { // nolint: gocritic
case packetaddr.PacketAddrType_Packet:
ctx := context.WithValue(t.ctx, udp.DispatcherConnectionTerminationSignalReceiverMark, connection)
ctx := context.WithValue(t.ctx, udp.DispatcherConnectionTerminationSignalReceiverMark, connection) // nolint:staticcheck
packetAddrDispatcherFactory := udp.NewPacketAddrDispatcherCreator(ctx)
udpDispatcherConstructor = packetAddrDispatcherFactory.NewPacketAddrDispatcher
}