Fix: unexpected proxy dial behavior on mapping mode

This commit is contained in:
Dreamacro
2021-10-18 21:08:27 +08:00
parent fea9d1c5e2
commit 81d5da51a3
8 changed files with 105 additions and 78 deletions

View File

@ -71,6 +71,7 @@ type Metadata struct {
DstPort string `json:"destinationPort"`
AddrType int `json:"-"`
Host string `json:"host"`
DNSMode DNSMode `json:"dnsMode"`
}
func (m *Metadata) RemoteAddress() string {
@ -85,6 +86,23 @@ func (m *Metadata) Resolved() bool {
return m.DstIP != nil
}
// 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 != nil {
copy := *m
copy.Host = ""
if copy.DstIP.To4() != nil {
copy.AddrType = AtypIPv4
} else {
copy.AddrType = AtypIPv6
}
return &copy
}
return m
}
func (m *Metadata) UDPAddr() *net.UDPAddr {
if m.NetWork != UDP || m.DstIP == nil {
return nil