@@ -16,6 +16,17 @@ import (
1616 M "github.com/sagernet/sing/common/metadata"
1717)
1818
19+ var DnsDirectTags = []string {
20+ DNSStaticTag ,
21+ DNSDirectTag ,
22+ DNSLocalTag ,
23+ DNSTricksDirectTag ,
24+ }
25+ var DnsRemoteTags = []string {
26+ DNSRemoteTag ,
27+ DNSRemoteTagFallback ,
28+ }
29+
1930func setDns (options * option.Options , opt * HiddifyOptions , staticIps * map [string ][]string ) error {
2031 remote_dns , err := getDNSServerOptions (DNSRemoteTag , opt .RemoteDnsAddress , DNSDirectTag , OutboundMainDetour )
2132 if err != nil {
@@ -58,12 +69,22 @@ func setDns(options *option.Options, opt *HiddifyOptions, staticIps *map[string]
5869 // return err
5970 // }
6071
72+ multi_dns_direct , err := getMultiDnsServerOptions (DNSMultiDirectTag , DnsDirectTags , false )
73+ if err != nil {
74+ return err
75+ }
76+
77+ multi_dns_remote , err := getMultiDnsServerOptions (DNSMultiRemoteTag , DnsRemoteTags , true )
78+ if err != nil {
79+ return err
80+ }
81+
6182 dnsOptions := option.DNSOptions {
6283 RawDNSOptions : option.RawDNSOptions {
6384 DNSClientOptions : option.DNSClientOptions {
6485 IndependentCache : opt .IndependentDNSCache && ! C .IsIos ,
6586 },
66- Final : DNSRemoteTag ,
87+ Final : DNSMultiRemoteTag ,
6788
6889 Servers : []option.DNSServerOptions {
6990 * static_dns ,
@@ -73,6 +94,8 @@ func setDns(options *option.Options, opt *HiddifyOptions, staticIps *map[string]
7394 * direct_dns ,
7495 * local_dns ,
7596 * remote_no_warp_dns ,
97+ * multi_dns_direct ,
98+ * multi_dns_remote ,
7699 // *block_dns,
77100 },
78101 Rules : []option.DNSRule {},
@@ -116,75 +139,74 @@ func getAllOutboundsOptions(options *option.Options) []any {
116139}
117140func addForceDirect (options * option.Options , hopt * HiddifyOptions ) ([]option.DefaultDNSRule , error ) {
118141 dnsMap := make (map [string ]string )
119- outbounds := getAllOutboundsOptions (options )
142+ // outbounds := getAllOutboundsOptions(options)
120143
121- for _ , outbound := range outbounds {
122-
123- if server , ok := outbound .(option.ServerOptionsWrapper ); ok {
124- serverDomain := server .TakeServerOptions ().Server
125- detour := OutboundDirectTag
126- if dialer , ok := outbound .(option.DialerOptionsWrapper ); ok {
127- if server_detour := dialer .TakeDialerOptions ().Detour ; server_detour != "" {
128- detour = server_detour
129- }
130- }
144+ // for _, outbound := range outbounds {
145+ // // fmt.Println("out", outbound)
146+ // if server, ok := outbound.(option.ServerOptionsWrapper); ok {
147+ // serverDomain := server.TakeServerOptions().Server
148+ // detour := OutboundDirectTag
149+ // if dialer, ok := outbound.(option.DialerOptionsWrapper); ok {
150+ // if server_detour := dialer.TakeDialerOptions().Detour; server_detour != "" {
151+ // detour = server_detour
152+ // }
153+ // }
154+ // fmt.Println("serverDomain", serverDomain, "detour", detour)
131155
132- if host , err := getHostnameIfNotIP (serverDomain ); err == nil {
133- if _ , ok := dnsMap [host ]; ! ok || detour == OutboundDirectTag {
134- dnsMap [host ] = detour
135- }
136- }
137- }
138- }
156+ // if host, err := getHostnameIfNotIP(serverDomain); err == nil && host != "" {
157+ // fmt.Println("serverDomain", serverDomain, "host", host, "detour", detour)
158+ // if _, ok := dnsMap[host]; !ok || detour == OutboundDirectTag {
159+ // dnsMap[host] = detour
160+ // }
161+ // }
162+ // }
163+ // }
139164
140- // dnsMap[]
165+ // // dnsMap[]
141166 forceDirectRules := []option.DefaultDNSRule {}
142- if len (dnsMap ) > 0 {
143- unique_dns_detours := make (map [string ]bool )
144- for _ , detour := range dnsMap {
145- unique_dns_detours [detour ] = true
146- }
167+ // if len(dnsMap) > 0 {
168+ // unique_dns_detours := make(map[string]bool)
169+ // for _, detour := range dnsMap {
170+ // unique_dns_detours[detour] = true
171+ // }
147172
148- for detour := range unique_dns_detours {
149- domains := []string {}
150- for domain , d := range dnsMap {
151- if d == detour {
152- domains = append (domains , domain )
153- }
154- }
155- if len (domains ) == 0 {
156- continue
157- }
158- dns_detour := DNSDirectTag
159- if detour != OutboundDirectTag {
160- dns_detour = "dns-" + detour
161- remote_dns , err := getDNSServerOptions (dns_detour , hopt .RemoteDnsAddress , DNSDirectTag , detour )
162- if err != nil {
163- return nil , err
164- }
165- options .DNS .Servers = append (options .DNS .Servers , * remote_dns )
166- if err != nil {
167- return nil , err
168- }
173+ // for detour := range unique_dns_detours {
174+ // domains := []string{}
175+ // for domain, d := range dnsMap {
176+ // if d == detour {
177+ // domains = append(domains, domain)
178+ // }
179+ // }
180+ // if len(domains) == 0 {
181+ // continue
182+ // }
183+ // dns_detour := DNSMultiDirectTag
184+ // if detour != OutboundDirectTag {
185+ // dns_detour = "dns-" + detour
186+ // remote_dns, err := getDNSServerOptions(dns_detour, hopt.RemoteDnsAddress, DNSDirectTag, detour)
187+ // if err != nil {
188+ // return nil, err
189+ // }
190+ // options.DNS.Servers = append(options.DNS.Servers, *remote_dns)
169191
170- }
192+ // }
171193
172- forceDirectRules = append (forceDirectRules ,
173- option.DefaultDNSRule {
174- RawDefaultDNSRule : option.RawDefaultDNSRule {
175- Domain : domains ,
176- },
177- DNSRuleAction : option.DNSRuleAction {
178- Action : C .RuleActionTypeRoute ,
179- RouteOptions : option.DNSRouteActionOptions {
180- Server : dns_detour ,
181- BypassIfFailed : true ,
182- },
183- },
184- },
185- )
186- }
187- }
194+ // forceDirectRules = append(forceDirectRules,
195+ // option.DefaultDNSRule{
196+ // RawDefaultDNSRule: option.RawDefaultDNSRule{
197+ // Domain: domains,
198+ // },
199+ // DNSRuleAction: option.DNSRuleAction{
200+ // Action: C.RuleActionTypeRoute,
201+ // RouteOptions: option.DNSRouteActionOptions{
202+ // Server: dns_detour,
203+ // BypassIfFailed: true,
204+ // },
205+ // },
206+ // },
207+ // )
208+ // }
209+ // }
188210 domains := []string {}
189211
190212 forceDirectRules = append (forceDirectRules ,
@@ -226,7 +248,7 @@ func addForceDirect(options *option.Options, hopt *HiddifyOptions) ([]option.Def
226248 DNSRuleAction : option.DNSRuleAction {
227249 Action : C .RuleActionTypeRoute ,
228250 RouteOptions : option.DNSRouteActionOptions {
229- Server : DNSDirectTag ,
251+ Server : DNSMultiDirectTag ,
230252 BypassIfFailed : true ,
231253 },
232254 },
@@ -444,3 +466,18 @@ func getStaticDNSServerOptions(tag string, staticIps *map[string][]string) (*opt
444466 }
445467 return & o , nil
446468}
469+ func getMultiDnsServerOptions (tag string , servers []string , parallel bool ) (* option.DNSServerOptions , error ) {
470+ o := option.DNSServerOptions {
471+ Tag : tag ,
472+ Type : C .DNSTypeMulti ,
473+ Options : & option.MultiDNSServerOptions {
474+ Servers : servers ,
475+ Parallel : parallel ,
476+ IgnoreRanges : []badoption.Prefix {
477+ badoption .Prefix (netip .MustParsePrefix ("10.10.34.0/24" )),
478+ badoption .Prefix (netip .MustParsePrefix ("001:4188:2:600::/64" )),
479+ },
480+ },
481+ }
482+ return & o , nil
483+ }
0 commit comments