diff --git a/app/tun/config.pb.go b/app/tun/config.pb.go index 689b4d555..20f686fa0 100644 --- a/app/tun/config.pb.go +++ b/app/tun/config.pb.go @@ -1,13 +1,8 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.30.0 -// protoc v3.21.12 -// source: app/tun/config.proto - package tun import ( routercommon "github.com/v2fly/v2ray-core/v5/app/router/routercommon" + packetaddr "github.com/v2fly/v2ray-core/v5/common/net/packetaddr" _ "github.com/v2fly/v2ray-core/v5/common/protoext" internet "github.com/v2fly/v2ray-core/v5/transport/internet" protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -28,15 +23,16 @@ type Config struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Mtu uint32 `protobuf:"varint,2,opt,name=mtu,proto3" json:"mtu,omitempty"` - UserLevel uint32 `protobuf:"varint,3,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"` - Tag string `protobuf:"bytes,5,opt,name=tag,proto3" json:"tag,omitempty"` - Ips []*routercommon.CIDR `protobuf:"bytes,6,rep,name=ips,proto3" json:"ips,omitempty"` - Routes []*routercommon.CIDR `protobuf:"bytes,7,rep,name=routes,proto3" json:"routes,omitempty"` - EnablePromiscuousMode bool `protobuf:"varint,8,opt,name=enable_promiscuous_mode,json=enablePromiscuousMode,proto3" json:"enable_promiscuous_mode,omitempty"` - EnableSpoofing bool `protobuf:"varint,9,opt,name=enable_spoofing,json=enableSpoofing,proto3" json:"enable_spoofing,omitempty"` - SocketSettings *internet.SocketConfig `protobuf:"bytes,10,opt,name=socket_settings,json=socketSettings,proto3" json:"socket_settings,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Mtu uint32 `protobuf:"varint,2,opt,name=mtu,proto3" json:"mtu,omitempty"` + UserLevel uint32 `protobuf:"varint,3,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"` + PacketEncoding packetaddr.PacketAddrType `protobuf:"varint,4,opt,name=packet_encoding,json=packetEncoding,proto3,enum=v2ray.core.net.packetaddr.PacketAddrType" json:"packet_encoding,omitempty"` + Tag string `protobuf:"bytes,5,opt,name=tag,proto3" json:"tag,omitempty"` + Ips []*routercommon.CIDR `protobuf:"bytes,6,rep,name=ips,proto3" json:"ips,omitempty"` + Routes []*routercommon.CIDR `protobuf:"bytes,7,rep,name=routes,proto3" json:"routes,omitempty"` + EnablePromiscuousMode bool `protobuf:"varint,8,opt,name=enable_promiscuous_mode,json=enablePromiscuousMode,proto3" json:"enable_promiscuous_mode,omitempty"` + EnableSpoofing bool `protobuf:"varint,9,opt,name=enable_spoofing,json=enableSpoofing,proto3" json:"enable_spoofing,omitempty"` + SocketSettings *internet.SocketConfig `protobuf:"bytes,10,opt,name=socket_settings,json=socketSettings,proto3" json:"socket_settings,omitempty"` } func (x *Config) Reset() { @@ -92,6 +88,13 @@ func (x *Config) GetUserLevel() uint32 { return 0 } +func (x *Config) GetPacketEncoding() packetaddr.PacketAddrType { + if x != nil { + return x.PacketEncoding + } + return packetaddr.PacketAddrType(0) +} + func (x *Config) GetTag() string { if x != nil { return x.Tag @@ -144,42 +147,49 @@ var file_app_tun_config_proto_rawDesc = []byte{ 0x6d, 0x6f, 0x6e, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x78, 0x74, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x1a, 0x1f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, - 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x22, 0xae, 0x03, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x74, 0x75, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x03, 0x6d, 0x74, 0x75, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6c, 0x65, 0x76, - 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x4c, 0x65, - 0x76, 0x65, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x3a, 0x0a, 0x03, 0x69, 0x70, 0x73, 0x18, 0x06, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, - 0x61, 0x70, 0x70, 0x2e, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x2e, 0x72, 0x6f, 0x75, 0x74, 0x65, - 0x72, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x43, 0x49, 0x44, 0x52, 0x52, 0x03, 0x69, 0x70, - 0x73, 0x12, 0x40, 0x0a, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x28, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, - 0x70, 0x70, 0x2e, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x2e, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x72, - 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x43, 0x49, 0x44, 0x52, 0x52, 0x06, 0x72, 0x6f, 0x75, - 0x74, 0x65, 0x73, 0x12, 0x36, 0x0a, 0x17, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x72, - 0x6f, 0x6d, 0x69, 0x73, 0x63, 0x75, 0x6f, 0x75, 0x73, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x18, 0x08, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x15, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x6d, - 0x69, 0x73, 0x63, 0x75, 0x6f, 0x75, 0x73, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x65, - 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x73, 0x70, 0x6f, 0x6f, 0x66, 0x69, 0x6e, 0x67, 0x18, 0x09, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x70, 0x6f, 0x6f, - 0x66, 0x69, 0x6e, 0x67, 0x12, 0x54, 0x0a, 0x0f, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x5f, 0x73, - 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, - 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, - 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53, 0x6f, - 0x63, 0x6b, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0e, 0x73, 0x6f, 0x63, 0x6b, - 0x65, 0x74, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x3a, 0x12, 0x82, 0xb5, 0x18, 0x0e, - 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x03, 0x74, 0x75, 0x6e, 0x4a, 0x04, - 0x08, 0x04, 0x10, 0x05, 0x42, 0x57, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, - 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x74, 0x75, 0x6e, 0x50, 0x01, - 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, - 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x35, - 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x74, 0x75, 0x6e, 0xaa, 0x02, 0x12, 0x56, 0x32, 0x52, 0x61, 0x79, - 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x54, 0x75, 0x6e, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x6f, 0x1a, 0x22, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x6e, 0x65, 0x74, 0x2f, 0x70, + 0x61, 0x63, 0x6b, 0x65, 0x74, 0x61, 0x64, 0x64, 0x72, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, + 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xfc, 0x03, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x74, 0x75, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6d, 0x74, 0x75, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, + 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x75, 0x73, + 0x65, 0x72, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x52, 0x0a, 0x0f, 0x70, 0x61, 0x63, 0x6b, 0x65, + 0x74, 0x5f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x29, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x6e, 0x65, + 0x74, 0x2e, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x61, 0x64, 0x64, 0x72, 0x2e, 0x50, 0x61, 0x63, + 0x6b, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0e, 0x70, 0x61, 0x63, + 0x6b, 0x65, 0x74, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x74, + 0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x12, 0x3a, 0x0a, + 0x03, 0x69, 0x70, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x76, 0x32, 0x72, + 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x6f, 0x75, 0x74, + 0x65, 0x72, 0x2e, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, + 0x43, 0x49, 0x44, 0x52, 0x52, 0x03, 0x69, 0x70, 0x73, 0x12, 0x40, 0x0a, 0x06, 0x72, 0x6f, 0x75, + 0x74, 0x65, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x76, 0x32, 0x72, 0x61, + 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x6f, 0x75, 0x74, 0x65, + 0x72, 0x2e, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x43, + 0x49, 0x44, 0x52, 0x52, 0x06, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x12, 0x36, 0x0a, 0x17, 0x65, + 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6d, 0x69, 0x73, 0x63, 0x75, 0x6f, 0x75, + 0x73, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x15, 0x65, 0x6e, + 0x61, 0x62, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x6d, 0x69, 0x73, 0x63, 0x75, 0x6f, 0x75, 0x73, 0x4d, + 0x6f, 0x64, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x73, 0x70, + 0x6f, 0x6f, 0x66, 0x69, 0x6e, 0x67, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x65, 0x6e, + 0x61, 0x62, 0x6c, 0x65, 0x53, 0x70, 0x6f, 0x6f, 0x66, 0x69, 0x6e, 0x67, 0x12, 0x54, 0x0a, 0x0f, + 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x5f, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, + 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, + 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, + 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x52, 0x0e, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, + 0x67, 0x73, 0x3a, 0x12, 0x82, 0xb5, 0x18, 0x0e, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x03, 0x74, 0x75, 0x6e, 0x42, 0x57, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, + 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x74, 0x75, 0x6e, + 0x50, 0x01, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, + 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, + 0x76, 0x35, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x74, 0x75, 0x6e, 0xaa, 0x02, 0x12, 0x56, 0x32, 0x52, + 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x54, 0x75, 0x6e, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -196,19 +206,21 @@ func file_app_tun_config_proto_rawDescGZIP() []byte { var file_app_tun_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_app_tun_config_proto_goTypes = []interface{}{ - (*Config)(nil), // 0: v2ray.core.app.tun.Config - (*routercommon.CIDR)(nil), // 1: v2ray.core.app.router.routercommon.CIDR - (*internet.SocketConfig)(nil), // 2: v2ray.core.transport.internet.SocketConfig + (*Config)(nil), // 0: v2ray.core.app.tun.Config + (packetaddr.PacketAddrType)(0), // 1: v2ray.core.net.packetaddr.PacketAddrType + (*routercommon.CIDR)(nil), // 2: v2ray.core.app.router.routercommon.CIDR + (*internet.SocketConfig)(nil), // 3: v2ray.core.transport.internet.SocketConfig } var file_app_tun_config_proto_depIdxs = []int32{ - 1, // 0: v2ray.core.app.tun.Config.ips:type_name -> v2ray.core.app.router.routercommon.CIDR - 1, // 1: v2ray.core.app.tun.Config.routes:type_name -> v2ray.core.app.router.routercommon.CIDR - 2, // 2: v2ray.core.app.tun.Config.socket_settings:type_name -> v2ray.core.transport.internet.SocketConfig - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 1, // 0: v2ray.core.app.tun.Config.packet_encoding:type_name -> v2ray.core.net.packetaddr.PacketAddrType + 2, // 1: v2ray.core.app.tun.Config.ips:type_name -> v2ray.core.app.router.routercommon.CIDR + 2, // 2: v2ray.core.app.tun.Config.routes:type_name -> v2ray.core.app.router.routercommon.CIDR + 3, // 3: v2ray.core.app.tun.Config.socket_settings:type_name -> v2ray.core.transport.internet.SocketConfig + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_app_tun_config_proto_init() } diff --git a/app/tun/config.proto b/app/tun/config.proto index 68864e3bf..3e255c14f 100644 --- a/app/tun/config.proto +++ b/app/tun/config.proto @@ -9,6 +9,7 @@ option java_multiple_files = true; import "app/router/routercommon/common.proto"; import "common/protoext/extensions.proto"; +import "common/net/packetaddr/config.proto"; import "transport/internet/config.proto"; message Config { @@ -19,7 +20,7 @@ message Config { string name = 1; uint32 mtu = 2; uint32 user_level = 3; - reserved 4; // Reserved for PacketEncode + v2ray.core.net.packetaddr.PacketAddrType packet_encoding = 4; string tag = 5; repeated v2ray.core.app.router.routercommon.CIDR ips = 6; repeated v2ray.core.app.router.routercommon.CIDR routes = 7; diff --git a/app/tun/device/device.go b/app/tun/device/device.go index 2bbb72802..029b63b48 100644 --- a/app/tun/device/device.go +++ b/app/tun/device/device.go @@ -5,6 +5,8 @@ import ( "gvisor.dev/gvisor/pkg/tcpip/stack" ) +//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen + type Device interface { stack.LinkEndpoint diff --git a/app/tun/device/errors.generated.go b/app/tun/device/errors.generated.go new file mode 100644 index 000000000..82f07e1e4 --- /dev/null +++ b/app/tun/device/errors.generated.go @@ -0,0 +1,9 @@ +package device + +import "github.com/v2fly/v2ray-core/v5/common/errors" + +type errPathObjHolder struct{} + +func newError(values ...interface{}) *errors.Error { + return errors.New(values...).WithPathObj(errPathObjHolder{}) +} diff --git a/app/tun/device/linkWriterToWriter.go b/app/tun/device/linkWriterToWriter.go new file mode 100644 index 000000000..47fc42259 --- /dev/null +++ b/app/tun/device/linkWriterToWriter.go @@ -0,0 +1,34 @@ +package device + +import ( + "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 { + return &linkWriterToWriter{writer: writer} +} + +type linkWriterToWriter struct { + writer stack.LinkWriter +} + +func (l linkWriterToWriter) Write(p []byte) (n int, err error) { + + buffer := buffer.MakeWithData(p) + packetBufferPtr := stack.NewPacketBuffer(stack.PacketBufferOptions{ + Payload: buffer, + OnRelease: func() { + buffer.Release() + }, + }) + packetList := stack.PacketBufferList{} + packetList.PushBack(packetBufferPtr) + _, terr := l.writer.WritePackets(packetList) + if terr != nil { + return 0, newError("failed to write packet").Base(errors.New(terr.String())).AtError() + } + return len(p), nil +} diff --git a/app/tun/packetaddradaptar.go b/app/tun/packetaddradaptar.go new file mode 100644 index 000000000..8fb925a60 --- /dev/null +++ b/app/tun/packetaddradaptar.go @@ -0,0 +1,40 @@ +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" +) + +func NewDeviceWithSorter(overlay device.Device, sorter *tunsorter.TunSorter) device.Device { + return &packetAddrDevice{ + Device: overlay, + sorter: sorter, + } +} + +type packetAddrDevice struct { + device.Device + sorter *tunsorter.TunSorter + + secondaryDispatcher stack.NetworkDispatcher +} + +func (p *packetAddrDevice) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) { + buf := pkt.ToBuffer() + _, err := p.sorter.OnPacketReceived(buf.Flatten()) + if err != nil { + p.secondaryDispatcher.DeliverNetworkPacket(protocol, pkt) + } +} + +func (p *packetAddrDevice) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) { + //TODO implement me + panic("implement me") +} + +func (p *packetAddrDevice) Attach(dispatcher stack.NetworkDispatcher) { + p.secondaryDispatcher = dispatcher + p.Device.Attach(p) +} diff --git a/app/tun/packetparse/errors.generated.go b/app/tun/packetparse/errors.generated.go new file mode 100644 index 000000000..f1e216a1c --- /dev/null +++ b/app/tun/packetparse/errors.generated.go @@ -0,0 +1,9 @@ +package packetparse + +import "github.com/v2fly/v2ray-core/v5/common/errors" + +type errPathObjHolder struct{} + +func newError(values ...interface{}) *errors.Error { + return errors.New(values...).WithPathObj(errPathObjHolder{}) +} diff --git a/app/tun/packetparse/packetParse.go b/app/tun/packetparse/packetParse.go new file mode 100644 index 000000000..68e33c4c0 --- /dev/null +++ b/app/tun/packetparse/packetParse.go @@ -0,0 +1,3 @@ +package packetparse + +//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen diff --git a/app/tun/packetparse/udp.go b/app/tun/packetparse/udp.go new file mode 100644 index 000000000..61cbfbd31 --- /dev/null +++ b/app/tun/packetparse/udp.go @@ -0,0 +1,120 @@ +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 nullDestination = net.UnixDestination(net.DomainAddress("null")) + +func TryParseAsUDPPacket(packet []byte) (src, dst net.Destination, data []byte, err error) { + parsedPacket := gopacket.NewPacket(packet, layers.LayerTypeIPv4, gopacket.DecodeOptions{ + Lazy: true, + NoCopy: false, + SkipDecodeRecovery: false, + DecodeStreamsAsDatagrams: false, + }) + + var srcIP net.Address + var dstIP net.Address + ipv4Layer := parsedPacket.Layer(layers.LayerTypeIPv4) + + if ipv4Layer == nil { + parsedPacketAsIPv6 := gopacket.NewPacket(packet, layers.LayerTypeIPv6, gopacket.DecodeOptions{ + Lazy: true, + NoCopy: false, + SkipDecodeRecovery: false, + DecodeStreamsAsDatagrams: false, + }) + ipv6Layer := parsedPacketAsIPv6.Layer(layers.LayerTypeIPv6) + if ipv6Layer == nil { + return nullDestination, nullDestination, nil, errNotIPPacket + } + ipv6 := ipv6Layer.(*layers.IPv6) + srcIP = net.IPAddress(ipv6.SrcIP) + dstIP = net.IPAddress(ipv6.DstIP) + + parsedPacket = parsedPacketAsIPv6 + } else { + ipv4 := ipv4Layer.(*layers.IPv4) + srcIP = net.IPAddress(ipv4.SrcIP) + dstIP = net.IPAddress(ipv4.DstIP) + } + + udpLayer := parsedPacket.Layer(layers.LayerTypeUDP) + if udpLayer == nil { + return nullDestination, nullDestination, nil, errNotUDPPacket + } + udp := udpLayer.(*layers.UDP) + srcPort := net.Port(udp.SrcPort) + dstPort := net.Port(udp.DstPort) + + src = net.UDPDestination(srcIP, srcPort) + dst = net.UDPDestination(dstIP, dstPort) + data = udp.Payload + return +} + +func TryConstructUDPPacket(src, dst net.Destination, data []byte) ([]byte, error) { + if src.Address.Family().IsIPv4() && dst.Address.Family().IsIPv4() { + return constructIPv4UDPPacket(src, dst, data) + } + if src.Address.Family().IsIPv6() && dst.Address.Family().IsIPv6() { + return constructIPv6UDPPacket(src, dst, data) + } + return nil, newError("not supported") +} + +func constructIPv4UDPPacket(src, dst net.Destination, data []byte) ([]byte, error) { + ipv4 := &layers.IPv4{ + Version: 4, + Protocol: layers.IPProtocolUDP, + SrcIP: src.Address.IP(), + DstIP: dst.Address.IP(), + } + udp := &layers.UDP{ + SrcPort: layers.UDPPort(src.Port), + DstPort: layers.UDPPort(dst.Port), + } + err := udp.SetNetworkLayerForChecksum(ipv4) + if err != nil { + return nil, err + } + buffer := gopacket.NewSerializeBuffer() + if err := gopacket.SerializeLayers(buffer, gopacket.SerializeOptions{ + FixLengths: true, + ComputeChecksums: true, + }, ipv4, udp, gopacket.Payload(data)); err != nil { + return nil, err + } + return buffer.Bytes(), nil +} + +func constructIPv6UDPPacket(src, dst net.Destination, data []byte) ([]byte, error) { + ipv6 := &layers.IPv6{ + Version: 6, + NextHeader: layers.IPProtocolUDP, + SrcIP: src.Address.IP(), + DstIP: dst.Address.IP(), + } + udp := &layers.UDP{ + SrcPort: layers.UDPPort(src.Port), + DstPort: layers.UDPPort(dst.Port), + } + err := udp.SetNetworkLayerForChecksum(ipv6) + if err != nil { + return nil, err + } + buffer := gopacket.NewSerializeBuffer() + if err := gopacket.SerializeLayers(buffer, gopacket.SerializeOptions{ + FixLengths: true, + ComputeChecksums: true, + }, ipv6, udp, gopacket.Payload(data)); err != nil { + return nil, err + } + return buffer.Bytes(), nil +} diff --git a/app/tun/tun.go b/app/tun/tun.go index 90f2e46e7..05f045396 100644 --- a/app/tun/tun.go +++ b/app/tun/tun.go @@ -5,11 +5,12 @@ package tun import ( "context" - 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" + "github.com/v2fly/v2ray-core/v5/app/tun/tunsorter" "github.com/v2fly/v2ray-core/v5/common" + "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" @@ -32,7 +33,7 @@ func (t *TUN) Type() interface{} { func (t *TUN) Start() error { DeviceConstructor := gvisor.New - device, err := DeviceConstructor(device.Options{ + tunDevice, err := DeviceConstructor(device.Options{ Name: t.config.Name, MTU: t.config.Mtu, }) @@ -40,7 +41,14 @@ func (t *TUN) Start() error { return newError("failed to create device").Base(err).AtError() } - stack, err := t.CreateStack(device) + if t.config.PacketEncoding != packetaddr.PacketAddrType_None { + writer := device.NewLinkWriterToWriter(tunDevice) + sorter := tunsorter.NewTunSorter(writer, t.dispatcher, t.config.PacketEncoding, t.ctx) + tunDeviceLayered := NewDeviceWithSorter(tunDevice, sorter) + tunDevice = tunDeviceLayered + } + + stack, err := t.CreateStack(tunDevice) if err != nil { return newError("failed to create stack").Base(err).AtError() } diff --git a/app/tun/tunsorter/errors.generated.go b/app/tun/tunsorter/errors.generated.go new file mode 100644 index 000000000..bec96d6c7 --- /dev/null +++ b/app/tun/tunsorter/errors.generated.go @@ -0,0 +1,9 @@ +package tunsorter + +import "github.com/v2fly/v2ray-core/v5/common/errors" + +type errPathObjHolder struct{} + +func newError(values ...interface{}) *errors.Error { + return errors.New(values...).WithPathObj(errPathObjHolder{}) +} diff --git a/app/tun/tunsorter/tunsorter.go b/app/tun/tunsorter/tunsorter.go new file mode 100644 index 000000000..cf32e74f0 --- /dev/null +++ b/app/tun/tunsorter/tunsorter.go @@ -0,0 +1,102 @@ +package tunsorter + +import ( + "context" + "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" + "github.com/v2fly/v2ray-core/v5/common/net/packetaddr" + 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 + +func NewTunSorter(tunWriter io.Writer, dispatcher routing.Dispatcher, packetAddrType packetaddr.PacketAddrType, ctx context.Context) *TunSorter { + return &TunSorter{ + tunWriter: tunWriter, + dispatcher: dispatcher, + packetAddrType: packetAddrType, + ctx: ctx, + } +} + +type TunSorter struct { + tunWriter io.Writer + dispatcher routing.Dispatcher + packetAddrType packetaddr.PacketAddrType + + trackedConnections sync.Map + ctx context.Context +} + +func (t *TunSorter) OnPacketReceived(b []byte) (n int, err error) { + src, dst, data, err := packetparse.TryParseAsUDPPacket(b) + if err != nil { + return 0, err + } + conn := newTrackedUDPConnection(src, t) + trackedConnection, loaded := t.trackedConnections.LoadOrStore(src.String(), conn) + conn = trackedConnection.(*trackedUDPConnection) + if !loaded { + t.onNewConnection(conn) + } + conn.onNewPacket(dst, data) + return len(b), nil +} + +func (t *TunSorter) onNewConnection(connection *trackedUDPConnection) { + udpDispatcherConstructor := udp.NewSplitDispatcher + switch t.packetAddrType { + case packetaddr.PacketAddrType_Packet: + ctx := context.WithValue(t.ctx, udp.DispatcherConnectionTerminationSignalReceiverMark, connection) + packetAddrDispatcherFactory := udp.NewPacketAddrDispatcherCreator(ctx) + udpDispatcherConstructor = packetAddrDispatcherFactory.NewPacketAddrDispatcher + } + udpDispatcher := udpDispatcherConstructor(t.dispatcher, func(ctx context.Context, packet *vudp.Packet) { + connection.onWritePacket(packet.Source, packet.Payload.Bytes()) + }) + connection.packetDispatcher = udpDispatcher +} + +func (t *TunSorter) onWritePacket(src net.Destination, dest net.Destination, data []byte) { + data, err := packetparse.TryConstructUDPPacket(src, dest, data) + if err != nil { + newError("failed to construct udp packet").Base(err).WriteToLog() + return + } + _, err = t.tunWriter.Write(data) + if err != nil { + newError("failed to write udp packet to tun").Base(err).WriteToLog() + return + } +} + +func newTrackedUDPConnection(src net.Destination, tunSorter *TunSorter) *trackedUDPConnection { + return &trackedUDPConnection{ + tunSorter: tunSorter, + src: src, + } +} + +type trackedUDPConnection struct { + packetDispatcher udp.DispatcherI + tunSorter *TunSorter + src net.Destination +} + +func (t *trackedUDPConnection) onNewPacket(dst net.Destination, data []byte) { + t.packetDispatcher.Dispatch(context.Background(), dst, buf.FromBytes(data)) +} + +func (t *trackedUDPConnection) onWritePacket(src net.Destination, data []byte) { + t.tunSorter.onWritePacket(src, t.src, data) +} + +func (t *trackedUDPConnection) Close() error { + t.tunSorter.trackedConnections.Delete(t.src.String()) + return nil +} diff --git a/go.mod b/go.mod index e820051d3..852b3cd55 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 github.com/google/go-cmp v0.5.9 + github.com/google/gopacket v1.1.17 github.com/gorilla/websocket v1.5.0 github.com/jhump/protoreflect v1.15.1 github.com/miekg/dns v1.1.54 @@ -26,13 +27,14 @@ require ( github.com/xiaokangwang/VLite v0.0.0-20220418190619-cff95160a432 go.starlark.net v0.0.0-20230612165344-9532f5667272 go4.org/netipx v0.0.0-20230303233057-f1b76eb4bb35 - golang.org/x/crypto v0.12.0 - golang.org/x/net v0.14.0 - golang.org/x/sync v0.2.0 - golang.org/x/sys v0.11.0 + golang.org/x/crypto v0.14.0 + golang.org/x/net v0.17.0 + golang.org/x/sync v0.4.0 + golang.org/x/sys v0.13.0 google.golang.org/grpc v1.57.0 google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v3 v3.0.1 + gvisor.dev/gvisor v0.0.0-20231020174304-b8a429915ff1 h12.io/socks v1.0.3 ) @@ -51,6 +53,7 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect + github.com/google/btree v1.1.2 // indirect github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect @@ -71,9 +74,10 @@ require ( github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4 // indirect github.com/xtaci/smux v1.5.24 // indirect go.uber.org/mock v0.3.0 // indirect - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/mod v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect - golang.org/x/tools v0.9.3 // indirect + golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 // indirect + golang.org/x/mod v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect + golang.org/x/time v0.3.0 // indirect + golang.org/x/tools v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect ) diff --git a/go.sum b/go.sum index 09c861512..cbec81a2a 100644 --- a/go.sum +++ b/go.sum @@ -114,6 +114,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= +github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -123,6 +125,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbBY= github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -357,15 +360,15 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= -golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY= +golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -383,8 +386,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= -golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -407,8 +410,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= -golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= -golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -421,8 +424,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -454,8 +457,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -470,10 +473,12 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -497,8 +502,8 @@ golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= -golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -560,6 +565,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gvisor.dev/gvisor v0.0.0-20231020174304-b8a429915ff1 h1:qDCwdCWECGnwQSQC01Dpnp09fRHxJs9PbktotUqG+hs= +gvisor.dev/gvisor v0.0.0-20231020174304-b8a429915ff1/go.mod h1:8hmigyCdYtw5xJGfQDJzSH5Ju8XEIDBnpyi8+O6GRt8= h12.io/socks v1.0.3 h1:Ka3qaQewws4j4/eDQnOdpr4wXsC//dXtWvftlIcCQUo= h12.io/socks v1.0.3/go.mod h1:AIhxy1jOId/XCz9BO+EIgNL2rQiPTBNnOfnVnQ+3Eck= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/transport/internet/udp/dispatcher.go b/transport/internet/udp/dispatcher.go index c52021c6f..ca7cb8cfb 100644 --- a/transport/internet/udp/dispatcher.go +++ b/transport/internet/udp/dispatcher.go @@ -2,6 +2,7 @@ package udp import ( "context" + "io" "github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common/buf" @@ -12,3 +13,9 @@ type DispatcherI interface { common.Closable Dispatch(ctx context.Context, destination net.Destination, payload *buf.Buffer) } + +var DispatcherConnectionTerminationSignalReceiverMark = "DispatcherConnectionTerminationSignalReceiverMark" + +type DispatcherConnectionTerminationSignalReceiver interface { + io.Closer +} diff --git a/transport/internet/udp/dispatcher_packetaddr.go b/transport/internet/udp/dispatcher_packetaddr.go index f59422aa9..938447407 100644 --- a/transport/internet/udp/dispatcher_packetaddr.go +++ b/transport/internet/udp/dispatcher_packetaddr.go @@ -17,6 +17,9 @@ type PacketAddrDispatcher struct { } func (p PacketAddrDispatcher) Close() error { + if p.ctx.Value(DispatcherConnectionTerminationSignalReceiverMark) != nil { + p.ctx.Value(DispatcherConnectionTerminationSignalReceiverMark).(DispatcherConnectionTerminationSignalReceiver).Close() + } return p.conn.Close() }