From 859299c712894269cd94465684b8c96f724d2bb4 Mon Sep 17 00:00:00 2001
From: DHR60 <dehongren60@gmail.com>
Date: Tue, 4 Mar 2025 10:32:07 +0800
Subject: [PATCH] Add kcp DNS masquerade support (#6852)

* Add kcp DNS masquerade support

* Update V2rayConfig.cs

* Update CoreConfigV2rayService.cs

---------

Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
---
 v2rayN/ServiceLib/Global.cs                                    | 3 ++-
 v2rayN/ServiceLib/Models/V2rayConfig.cs                        | 2 ++
 .../ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs   | 3 ++-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs
index 48df5d22..f962efe1 100644
--- a/v2rayN/ServiceLib/Global.cs
+++ b/v2rayN/ServiceLib/Global.cs
@@ -265,7 +265,8 @@ namespace ServiceLib
             "utp",
             "wechat-video",
             "dtls",
-            "wireguard"
+            "wireguard",
+            "dns"
         ];
 
         public static readonly List<string> CoreTypes =
diff --git a/v2rayN/ServiceLib/Models/V2rayConfig.cs b/v2rayN/ServiceLib/Models/V2rayConfig.cs
index b6ecf52b..e3fa0fd3 100644
--- a/v2rayN/ServiceLib/Models/V2rayConfig.cs
+++ b/v2rayN/ServiceLib/Models/V2rayConfig.cs
@@ -291,6 +291,8 @@ namespace ServiceLib.Models
         public object request { get; set; }
 
         public object response { get; set; }
+
+        public string? domain { get; set; }
     }
 
     public class KcpSettings4Ray
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
index 46c99e97..f07a9c94 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
@@ -915,7 +915,8 @@ namespace ServiceLib.Services.CoreConfig
                         kcpSettings.writeBufferSize = _config.KcpItem.WriteBufferSize;
                         kcpSettings.header = new Header4Ray
                         {
-                            type = node.HeaderType
+                            type = node.HeaderType,
+                            domain = host.IsNullOrEmpty() ? null : host
                         };
                         if (Utils.IsNotEmpty(path))
                         {