ソースを参照

Fix: opt-in Surge DNS's special handling for `.local`

SukkaW 3 ヶ月 前
コミット
800b16a7c4

+ 10 - 2
Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts

@@ -233,7 +233,9 @@ export const buildDomesticRuleset = task(require.main === module, __filename)(as
             const ruleset_name = cur[0].toLowerCase();
             const ruleset_name = cur[0].toLowerCase();
             const mihomo_ruleset_id = `mihomo_nameserver_policy_${ruleset_name}`;
             const mihomo_ruleset_id = `mihomo_nameserver_policy_${ruleset_name}`;
 
 
-            acc.dns['nameserver-policy'][`rule-set:${mihomo_ruleset_id}`] = dns;
+            if (dns) {
+              acc.dns['nameserver-policy'][`rule-set:${mihomo_ruleset_id}`] = dns;
+            }
 
 
             acc['rule-providers'][mihomo_ruleset_id] = {
             acc['rule-providers'][mihomo_ruleset_id] = {
               type: 'http',
               type: 'http',
@@ -257,7 +259,9 @@ export const buildDomesticRuleset = task(require.main === module, __filename)(as
                   break;
                   break;
               }
               }
 
 
-              acc.dns['nameserver-policy'][domain] = dns;
+              if (dns) {
+                acc.dns['nameserver-policy'][domain] = dns;
+              }
             });
             });
           }
           }
 
 
@@ -297,6 +301,10 @@ export const buildDomesticRuleset = task(require.main === module, __filename)(as
         'https://doh.pub/dns-query',
         'https://doh.pub/dns-query',
         '[//]udp://10.10.1.1:53',
         '[//]udp://10.10.1.1:53',
         ...(([DOMESTICS, DIRECTS, LAN, HOSTS] as const).flatMap(Object.values) as DNSMapping[]).flatMap(({ domains, dns: _dns }) => domains.flatMap((domain) => {
         ...(([DOMESTICS, DIRECTS, LAN, HOSTS] as const).flatMap(Object.values) as DNSMapping[]).flatMap(({ domains, dns: _dns }) => domains.flatMap((domain) => {
+          if (!_dns) {
+            return [];
+          }
+
           let dns;
           let dns;
           if (_dns in AdGuardHomeDNSMapping) {
           if (_dns in AdGuardHomeDNSMapping) {
             dns = AdGuardHomeDNSMapping[_dns as keyof typeof AdGuardHomeDNSMapping].join(' ');
             dns = AdGuardHomeDNSMapping[_dns as keyof typeof AdGuardHomeDNSMapping].join(' ');

+ 17 - 2
Source/non_ip/direct.ts

@@ -6,7 +6,7 @@ export interface DNSMapping {
   realip: boolean,
   realip: boolean,
   /** should convert to ruleset */
   /** should convert to ruleset */
   ruleset: boolean,
   ruleset: boolean,
-  dns: string,
+  dns: string | null,
   /**
   /**
    * domain[0]
    * domain[0]
    *
    *
@@ -47,6 +47,18 @@ export const DIRECTS = {
 } as const satisfies Record<string, DNSMapping>;
 } as const satisfies Record<string, DNSMapping>;
 
 
 export const LAN = {
 export const LAN = {
+  // By default, all hostnames with the suffix '.local' will be resolved by the system.
+  // Some app like OrbStack uses mDNS and this TLD (orb.local) via mDNS.
+  // Surge already handles .local with mDNS properly, we should not map to server:system
+  LOCAL_SPECIAL: {
+    dns: null,
+    hosts: {},
+    realip: false,
+    ruleset: false,
+    domains: [
+      '+local'
+    ]
+  },
   LAN_WITHOUT_REAL_IP: {
   LAN_WITHOUT_REAL_IP: {
     dns: 'system',
     dns: 'system',
     hosts: {
     hosts: {
@@ -139,7 +151,10 @@ export const LAN = {
     ruleset: true,
     ruleset: true,
     domains: [
     domains: [
       '+lan',
       '+lan',
-      '+local',
+      // By default, all hostnames with the suffix '.local' will be resolved by the system.
+      // Some app like OrbStack uses mDNS and this TLD (orb.local) via mDNS.
+      // Surge already handles .local with mDNS properly, we should not map to server:system
+      // '+local',
       '+internal',
       '+internal',
       // 'amplifi.lan',
       // 'amplifi.lan',
       // '$localhost',
       // '$localhost',