1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

added fake dns + others matching logic

This commit is contained in:
Shelikhoo 2021-04-10 13:40:15 +01:00
parent 94ab10fce3
commit 488f9845c6
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
4 changed files with 25 additions and 5 deletions

View File

@ -186,6 +186,11 @@ func shouldOverride(result SniffResult, domainOverride []string) bool {
if strings.HasPrefix(protocolString, p) {
return true
}
if resultSubset, ok := result.(SnifferIsProtoSubsetOf); ok {
if resultSubset.IsProtoSubsetOf(p) {
return true
}
}
}
return false
}

View File

@ -4,6 +4,7 @@ package dispatcher
import (
"context"
"strings"
core "github.com/v2fly/v2ray-core/v4"
"github.com/v2fly/v2ray-core/v4/common"
@ -68,7 +69,15 @@ type ipAddressInRangeOpt struct {
}
type DNSThenOthersSniffResult struct {
domainName string
domainName string
protocolOriginalName string
}
func (f DNSThenOthersSniffResult) IsProtoSubsetOf(protocolName string) bool {
if strings.HasPrefix(protocolName, f.protocolOriginalName) {
return true
}
return false
}
func (DNSThenOthersSniffResult) Protocol() string {
@ -93,7 +102,7 @@ func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWit
for _, v := range others {
if v.metadataSniffer || bytes != nil {
if result, err := v.protocolSniffer(ctx, bytes); err == nil {
return DNSThenOthersSniffResult{result.Domain()}, nil
return DNSThenOthersSniffResult{domainName: result.Domain(), protocolOriginalName: result.Protocol()}, nil
}
}
}
@ -107,6 +116,6 @@ func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWit
return nil, common.ErrNoClue
}
},
metadataSniffer: true,
metadataSniffer: false,
}, nil
}

View File

@ -42,8 +42,8 @@ func NewSniffer(ctx context.Context) *Sniffer {
others := ret.sniffer
ret.sniffer = append(ret.sniffer, sniffer)
fakeDNSThenOthers, err := newFakeDNSThenOthers(ctx, sniffer, others)
if err != nil {
ret.sniffer = append(ret.sniffer, fakeDNSThenOthers)
if err == nil {
ret.sniffer = append([]protocolSnifferWithMetadata{fakeDNSThenOthers}, ret.sniffer...)
}
}
return ret
@ -128,3 +128,7 @@ func (c compositeResult) ProtocolForDomainResult() string {
type SnifferResultComposite interface {
ProtocolForDomainResult() string
}
type SnifferIsProtoSubsetOf interface {
IsProtoSubsetOf(protocolName string) bool
}

View File

@ -75,6 +75,8 @@ func (c *SniffingConfig) Build() (*proxyman.SniffingConfig, error) {
p = append(p, "tls")
case "fakedns":
p = append(p, "fakedns")
case "fakedns+others":
p = append(p, "fakedns+others")
default:
return nil, newError("unknown protocol: ", domainOverride)
}