mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-28 21:15:46 -05:00
proxy dns with NOTIMP error (#2954)
* proxy dns with NOTIMP error * fix compile error when protoc is relative link ``` $ go generate ... proto.go fork/exec ../Cellar/protobuf/28.3/bin/protoc: no such file or directory exit status 1 proto.go:5: running "go": exit status 1 context_test.go functions_test.go v2ray_test.go $ ls -l `which protoc` lrwxr-xr-x 1 local admin 34 Nov 1 13:56 /opt/homebrew/bin/protoc -> ../Cellar/protobuf/28.3/bin/protoc ``` * add nonIPQuery for dns config * go generate with only dns.proto * Try Allowing Github actions * fix merge error * apply coding style --------- Co-authored-by: local <local@localhost> Co-authored-by: Shelikhoo <xiaokangwang@outlook.com>
This commit is contained in:
@@ -182,10 +182,6 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if linkPath, err := os.Readlink(protoc); err == nil {
|
|
||||||
protoc = linkPath
|
|
||||||
}
|
|
||||||
|
|
||||||
installedVersion, err := getInstalledProtocVersion(protoc)
|
installedVersion, err := getInstalledProtocVersion(protoc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Config struct {
|
|||||||
UserLevel uint32 `protobuf:"varint,2,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"`
|
UserLevel uint32 `protobuf:"varint,2,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"`
|
||||||
OverrideResponseTtl bool `protobuf:"varint,4,opt,name=override_response_ttl,json=overrideResponseTtl,proto3" json:"override_response_ttl,omitempty"`
|
OverrideResponseTtl bool `protobuf:"varint,4,opt,name=override_response_ttl,json=overrideResponseTtl,proto3" json:"override_response_ttl,omitempty"`
|
||||||
ResponseTtl uint32 `protobuf:"varint,3,opt,name=response_ttl,json=responseTtl,proto3" json:"response_ttl,omitempty"`
|
ResponseTtl uint32 `protobuf:"varint,3,opt,name=response_ttl,json=responseTtl,proto3" json:"response_ttl,omitempty"`
|
||||||
|
Non_IPQuery string `protobuf:"bytes,5,opt,name=non_IP_query,json=nonIPQuery,proto3" json:"non_IP_query,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@@ -87,6 +88,13 @@ func (x *Config) GetResponseTtl() uint32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Config) GetNon_IPQuery() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Non_IPQuery
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type SimplifiedConfig struct {
|
type SimplifiedConfig struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
OverrideResponseTtl bool `protobuf:"varint,4,opt,name=override_response_ttl,json=overrideResponseTtl,proto3" json:"override_response_ttl,omitempty"`
|
OverrideResponseTtl bool `protobuf:"varint,4,opt,name=override_response_ttl,json=overrideResponseTtl,proto3" json:"override_response_ttl,omitempty"`
|
||||||
@@ -141,41 +149,22 @@ func (x *SimplifiedConfig) GetResponseTtl() uint32 {
|
|||||||
|
|
||||||
var File_proxy_dns_config_proto protoreflect.FileDescriptor
|
var File_proxy_dns_config_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_proxy_dns_config_proto_rawDesc = string([]byte{
|
const file_proxy_dns_config_proto_rawDesc = "" +
|
||||||
0x0a, 0x16, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x64, 0x6e, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x66,
|
"\n" +
|
||||||
0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e,
|
"\x16proxy/dns/config.proto\x12\x14v2ray.core.proxy.dns\x1a\x1ccommon/net/destination.proto\x1a common/protoext/extensions.proto\"\xd9\x01\n" +
|
||||||
0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x64, 0x6e, 0x73, 0x1a, 0x1c,
|
"\x06Config\x127\n" +
|
||||||
0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x6e, 0x65, 0x74, 0x2f, 0x64, 0x65, 0x73, 0x74, 0x69,
|
"\x06server\x18\x01 \x01(\v2\x1f.v2ray.core.common.net.EndpointR\x06server\x12\x1d\n" +
|
||||||
0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x63, 0x6f,
|
"\n" +
|
||||||
0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x78, 0x74, 0x2f, 0x65, 0x78,
|
"user_level\x18\x02 \x01(\rR\tuserLevel\x122\n" +
|
||||||
0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb7,
|
"\x15override_response_ttl\x18\x04 \x01(\bR\x13overrideResponseTtl\x12!\n" +
|
||||||
0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x37, 0x0a, 0x06, 0x73, 0x65, 0x72,
|
"\fresponse_ttl\x18\x03 \x01(\rR\vresponseTtl\x12 \n" +
|
||||||
0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x76, 0x32, 0x72, 0x61,
|
"\fnon_IP_query\x18\x05 \x01(\tR\n" +
|
||||||
0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x6e, 0x65,
|
"nonIPQuery\"~\n" +
|
||||||
0x74, 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76,
|
"\x10SimplifiedConfig\x122\n" +
|
||||||
0x65, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c,
|
"\x15override_response_ttl\x18\x04 \x01(\bR\x13overrideResponseTtl\x12!\n" +
|
||||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x4c, 0x65, 0x76, 0x65,
|
"\fresponse_ttl\x18\x03 \x01(\rR\vresponseTtl:\x13\x82\xb5\x18\x0f\n" +
|
||||||
0x6c, 0x12, 0x32, 0x0a, 0x15, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x5f, 0x72, 0x65,
|
"\boutbound\x12\x03dnsB]\n" +
|
||||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x5f, 0x74, 0x74, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08,
|
"\x18com.v2ray.core.proxy.dnsP\x01Z(github.com/v2fly/v2ray-core/v5/proxy/dns\xaa\x02\x14V2Ray.Core.Proxy.Dnsb\x06proto3"
|
||||||
0x52, 0x13, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
|
||||||
0x73, 0x65, 0x54, 0x74, 0x6c, 0x12, 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
|
||||||
0x65, 0x5f, 0x74, 0x74, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x72, 0x65, 0x73,
|
|
||||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x54, 0x74, 0x6c, 0x22, 0x7e, 0x0a, 0x10, 0x53, 0x69, 0x6d, 0x70,
|
|
||||||
0x6c, 0x69, 0x66, 0x69, 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x32, 0x0a, 0x15,
|
|
||||||
0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
|
||||||
0x65, 0x5f, 0x74, 0x74, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x13, 0x6f, 0x76, 0x65,
|
|
||||||
0x72, 0x72, 0x69, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x54, 0x74, 0x6c,
|
|
||||||
0x12, 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x5f, 0x74, 0x74, 0x6c,
|
|
||||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
|
||||||
0x54, 0x74, 0x6c, 0x3a, 0x13, 0x82, 0xb5, 0x18, 0x0f, 0x0a, 0x08, 0x6f, 0x75, 0x74, 0x62, 0x6f,
|
|
||||||
0x75, 0x6e, 0x64, 0x12, 0x03, 0x64, 0x6e, 0x73, 0x42, 0x5d, 0x0a, 0x18, 0x63, 0x6f, 0x6d, 0x2e,
|
|
||||||
0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x78, 0x79,
|
|
||||||
0x2e, 0x64, 0x6e, 0x73, 0x50, 0x01, 0x5a, 0x28, 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, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x64, 0x6e, 0x73,
|
|
||||||
0xaa, 0x02, 0x14, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x72,
|
|
||||||
0x6f, 0x78, 0x79, 0x2e, 0x44, 0x6e, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
|
||||||
})
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_proxy_dns_config_proto_rawDescOnce sync.Once
|
file_proxy_dns_config_proto_rawDescOnce sync.Once
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ message Config {
|
|||||||
// original one.
|
// original one.
|
||||||
v2ray.core.common.net.Endpoint server = 1;
|
v2ray.core.common.net.Endpoint server = 1;
|
||||||
uint32 user_level = 2;
|
uint32 user_level = 2;
|
||||||
|
|
||||||
bool override_response_ttl = 4;
|
bool override_response_ttl = 4;
|
||||||
uint32 response_ttl = 3;
|
uint32 response_ttl = 3;
|
||||||
|
string non_IP_query = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SimplifiedConfig {
|
message SimplifiedConfig {
|
||||||
@@ -25,4 +25,4 @@ message SimplifiedConfig {
|
|||||||
|
|
||||||
bool override_response_ttl = 4;
|
bool override_response_ttl = 4;
|
||||||
uint32 response_ttl = 3;
|
uint32 response_ttl = 3;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ type Handler struct {
|
|||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
|
||||||
config *Config
|
config *Config
|
||||||
|
|
||||||
|
nonIPQuery string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager policy.Manager) error {
|
func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager policy.Manager) error {
|
||||||
@@ -88,6 +90,8 @@ func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager polic
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.config = config
|
h.config = config
|
||||||
|
|
||||||
|
h.nonIPQuery = config.Non_IPQuery
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,15 +204,16 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
|
|||||||
|
|
||||||
if !h.isOwnLink(ctx) {
|
if !h.isOwnLink(ctx) {
|
||||||
isIPQuery, domain, id, qType := parseIPQuery(b.Bytes())
|
isIPQuery, domain, id, qType := parseIPQuery(b.Bytes())
|
||||||
if isIPQuery {
|
if isIPQuery || h.nonIPQuery != "drop" {
|
||||||
if domain, err := strmatcher.ToDomain(domain); err == nil {
|
if domain, err := strmatcher.ToDomain(domain); err == nil {
|
||||||
go h.handleIPQuery(id, qType, domain, writer)
|
go h.handleIPQuery(id, qType, domain, writer)
|
||||||
continue
|
} else {
|
||||||
|
h.handleDNSError(id, dnsmessage.RCodeFormatError, writer)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
h.handleDNSError(id, dnsmessage.RCodeNotImplemented, writer)
|
||||||
}
|
}
|
||||||
}
|
} else if err := connWriter.WriteMessage(b); err != nil {
|
||||||
|
|
||||||
if err := connWriter.WriteMessage(b); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,6 +310,35 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) handleDNSError(id uint16, rCode dnsmessage.RCode, writer dns_proto.MessageWriter) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
b := buf.New()
|
||||||
|
rawBytes := b.Extend(buf.Size)
|
||||||
|
builder := dnsmessage.NewBuilder(rawBytes[:0], dnsmessage.Header{
|
||||||
|
ID: id,
|
||||||
|
RCode: rCode,
|
||||||
|
RecursionAvailable: true,
|
||||||
|
RecursionDesired: true,
|
||||||
|
Response: true,
|
||||||
|
})
|
||||||
|
builder.EnableCompression()
|
||||||
|
common.Must(builder.StartQuestions())
|
||||||
|
common.Must(builder.StartAnswers())
|
||||||
|
|
||||||
|
msgBytes, err := builder.Finish()
|
||||||
|
if err != nil {
|
||||||
|
newError("pack message").Base(err).WriteToLog()
|
||||||
|
b.Release()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.Resize(0, int32(len(msgBytes)))
|
||||||
|
|
||||||
|
if err := writer.WriteMessage(b); err != nil {
|
||||||
|
newError("write IP answer").Base(err).WriteToLog()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type outboundConn struct {
|
type outboundConn struct {
|
||||||
access sync.Mutex
|
access sync.Mutex
|
||||||
dialer func() (internet.Connection, error)
|
dialer func() (internet.Connection, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user