alias udp://

This commit is contained in:
Meo597
2026-11-15 21:10:30 +08:00
parent ddfac74131
commit fa4aeb1a56
2 changed files with 13 additions and 6 deletions
+3 -1
View File
@@ -68,8 +68,10 @@ func NewServer(ctx context.Context, dest net.Destination, dispatcher routing.Dis
return NewTCPNameServer(u, dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
case strings.EqualFold(u.Scheme, "tcp+local"): // DNS-over-TCP Local mode
return NewTCPLocalNameServer(u, disableCache, serveStale, serveExpiredTTL, clientIP)
case strings.EqualFold(u.Scheme, "udp"): // UDP DNS Remote mode
return NewUDPNameServer(u, dispatcher, false, disableCache, serveStale, serveExpiredTTL, clientIP)
case strings.EqualFold(u.Scheme, "udp+local"): // UDP DNS Local mode
return NewUDPLocalNameServer(u, dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
return NewUDPNameServer(u, dispatcher, true, disableCache, serveStale, serveExpiredTTL, clientIP)
case strings.EqualFold(u.String(), "fakedns"):
var fd dns.FakeDNSEngine
err = core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) {
+10 -5
View File
@@ -64,10 +64,10 @@ func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher
return s
}
// NewUDPLocalNameServer creates a UDP DNS client for local resolving.
func NewUDPLocalNameServer(url *url.URL, dispatcher routing.Dispatcher, disableCache bool, serveStale bool, serveExpiredTTL uint32, clientIP net.IP) (*ClassicNameServer, error) {
// NewUDPNameServer creates a UDP DNS client from a URL.
func NewUDPNameServer(url *url.URL, dispatcher routing.Dispatcher, local bool, disableCache bool, serveStale bool, serveExpiredTTL uint32, clientIP net.IP) (*ClassicNameServer, error) {
if url.Hostname() == "" {
return nil, errors.New("missing UDP local nameserver host")
return nil, errors.New("missing UDP nameserver host")
}
port := net.Port(53)
if url.Port() != "" {
@@ -76,8 +76,13 @@ func NewUDPLocalNameServer(url *url.URL, dispatcher routing.Dispatcher, disableC
return nil, err
}
}
s := NewClassicNameServer(net.UDPDestination(net.ParseAddress(url.Hostname()), port), &localUDPDispatcher{dispatcher}, disableCache, serveStale, serveExpiredTTL, clientIP)
s.cacheController.name = "UDPL//" + s.address.NetAddr()
if local {
dispatcher = &localUDPDispatcher{dispatcher}
}
s := NewClassicNameServer(net.UDPDestination(net.ParseAddress(url.Hostname()), port), dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
if local {
s.cacheController.name = "UDPL//" + s.address.NetAddr()
}
return s, nil
}