mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
chore: parse user's hosts before remoteDial
This commit is contained in:
parent
6106adc6a5
commit
a46436f61a
|
@ -16,6 +16,7 @@ const (
|
|||
DNSNormal DNSMode = iota
|
||||
DNSFakeIP
|
||||
DNSMapping
|
||||
DNSHosts
|
||||
)
|
||||
|
||||
type DNSMode int
|
||||
|
@ -64,6 +65,8 @@ func (e DNSMode) String() string {
|
|||
return "fake-ip"
|
||||
case DNSMapping:
|
||||
return "redir-host"
|
||||
case DNSHosts:
|
||||
return "hosts"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ func (m *Metadata) Resolved() bool {
|
|||
// Pure is used to solve unexpected behavior
|
||||
// when dialing proxy connection in DNSMapping mode.
|
||||
func (m *Metadata) Pure() *Metadata {
|
||||
if m.DNSMode == DNSMapping && m.DstIP.IsValid() {
|
||||
if (m.DNSMode == DNSMapping || m.DNSMode == DNSHosts) && m.DstIP.IsValid() {
|
||||
copyM := *m
|
||||
copyM.Host = ""
|
||||
if copyM.DstIP.Is4() {
|
||||
|
|
|
@ -331,9 +331,18 @@ func handleTCPConn(connCtx C.ConnContext) {
|
|||
return
|
||||
}
|
||||
|
||||
dialMetadata := metadata
|
||||
if len(metadata.Host) > 0 {
|
||||
if node := resolver.DefaultHosts.Search(metadata.Host); node != nil {
|
||||
dialMetadata.DstIP = node.Data
|
||||
dialMetadata.DNSMode = C.DNSHosts
|
||||
dialMetadata = dialMetadata.Pure()
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTCPTimeout)
|
||||
defer cancel()
|
||||
remoteConn, err := proxy.DialContext(ctx, metadata)
|
||||
remoteConn, err := proxy.DialContext(ctx, dialMetadata)
|
||||
if err != nil {
|
||||
if rule == nil {
|
||||
log.Warnln("[TCP] dial %s to %s error: %s", proxy.Name(), metadata.RemoteAddress(), err.Error())
|
||||
|
|
Loading…
Reference in New Issue
Block a user