From 83d6acf536164100d2f60b17217d3e5bd7f1bd2b Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Fri, 29 Nov 2024 01:38:28 -0500 Subject: [PATCH] Fakedns should be optional --- app/dispatcher/default.go | 2 +- app/dns/nameserver.go | 6 +++++- app/dns/nameserver_fakedns.go | 4 ++++ proxy/dns/dns.go | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/dispatcher/default.go b/app/dispatcher/default.go index 42fca674..dbf58dad 100644 --- a/app/dispatcher/default.go +++ b/app/dispatcher/default.go @@ -106,7 +106,7 @@ func init() { common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { d := new(DefaultDispatcher) if err := core.RequireFeatures(ctx, func(om outbound.Manager, router routing.Router, pm policy.Manager, sm stats.Manager, dc dns.Client) error { - core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) { + core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) { // FakeDNSEngine is optional d.fdns = fdns }) return d.Init(config.(*Config), om, router, pm, sm, dc) diff --git a/app/dns/nameserver.go b/app/dns/nameserver.go index 1cca1453..ecba9aff 100644 --- a/app/dns/nameserver.go +++ b/app/dns/nameserver.go @@ -78,7 +78,11 @@ func NewClient( ) (*Client, error) { client := &Client{} - err := core.RequireFeatures(ctx, func(dispatcher routing.Dispatcher, fd dns.FakeDNSEngine) error { + var fd dns.FakeDNSEngine + err := core.RequireFeatures(ctx, func(dispatcher routing.Dispatcher) error { + core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) { // FakeDNSEngine is optional + fd = fdns + }) // Create a new server for each client for now server, err := NewServer(ns.Address.AsDestination(), dispatcher, ns.GetQueryStrategy(), fd) if err != nil { diff --git a/app/dns/nameserver_fakedns.go b/app/dns/nameserver_fakedns.go index 4b9d93f9..ae7a1a7d 100644 --- a/app/dns/nameserver_fakedns.go +++ b/app/dns/nameserver_fakedns.go @@ -21,6 +21,10 @@ func (FakeDNSServer) Name() string { } func (f *FakeDNSServer) QueryIP(ctx context.Context, domain string, _ net.IP, opt dns.IPOption, _ bool) ([]net.IP, error) { + if f.fakeDNSEngine == nil { + return nil, errors.New("Unable to locate a fake DNS Engine").AtError() + } + var ips []net.Address if fkr0, ok := f.fakeDNSEngine.(dns.FakeDNSEngineRev0); ok { ips = fkr0.GetFakeIPForDomain3(domain, opt.IPv4Enable, opt.IPv6Enable) diff --git a/proxy/dns/dns.go b/proxy/dns/dns.go index ed063197..790c80c1 100644 --- a/proxy/dns/dns.go +++ b/proxy/dns/dns.go @@ -27,7 +27,7 @@ func init() { common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { h := new(Handler) if err := core.RequireFeatures(ctx, func(dnsClient dns.Client, policyManager policy.Manager) error { - core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) { + core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) { // FakeDNSEngine is optional h.fdns = fdns }) return h.Init(config.(*Config), dnsClient, policyManager)