mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
chore: rebuild udp dns resolve
The DNS resolution of the overall UDP part has been delayed to the connection initiation stage. During the rule matching process, it will only be triggered when the IP rule without no-resolve is matched. For direct and wireguard outbound, the same logic as the TCP part will be followed, that is, when direct-nameserver (or DNS configured by wireguard) exists, the result of the matching process will be discarded and the domain name will be re-resolved. This re-resolution logic is only effective for fakeip. For reject and DNS outbound, no resolution is required. For other outbound, resolution will still be performed when the connection is initiated, and the domain name will not be sent directly to the remote server at present.
This commit is contained in:
@@ -92,8 +92,7 @@ type Conn interface {
|
||||
type PacketConn interface {
|
||||
N.EnhancePacketConn
|
||||
Connection
|
||||
// Deprecate WriteWithMetadata because of remote resolve DNS cause TURN failed
|
||||
// WriteWithMetadata(p []byte, metadata *Metadata) (n int, err error)
|
||||
ResolveUDP(ctx context.Context, metadata *Metadata) error
|
||||
}
|
||||
|
||||
type Dialer interface {
|
||||
@@ -319,10 +318,15 @@ type PacketSender interface {
|
||||
Send(PacketAdapter)
|
||||
// Process is a blocking loop to send PacketAdapter to PacketConn and update the WriteBackProxy
|
||||
Process(PacketConn, WriteBackProxy)
|
||||
// ResolveUDP do a local resolve UDP dns blocking if metadata is not resolved
|
||||
ResolveUDP(*Metadata) error
|
||||
// Close stop the Process loop
|
||||
Close()
|
||||
// DoSniff will blocking after sniffer work done
|
||||
DoSniff(*Metadata) error
|
||||
// AddMapping add a destination NAT record
|
||||
AddMapping(originMetadata *Metadata, metadata *Metadata)
|
||||
// RestoreReadFrom restore destination NAT for ReadFrom
|
||||
// the implement must ensure returned netip.Add is valid (or just return input addr)
|
||||
RestoreReadFrom(addr netip.Addr) netip.Addr
|
||||
}
|
||||
|
||||
type NatTable interface {
|
||||
|
||||
@@ -261,6 +261,11 @@ func (m *Metadata) Pure() *Metadata {
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Metadata) Clone() *Metadata {
|
||||
copyM := *m
|
||||
return ©M
|
||||
}
|
||||
|
||||
func (m *Metadata) AddrPort() netip.AddrPort {
|
||||
return netip.AddrPortFrom(m.DstIP.Unmap(), m.DstPort)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user