fix(tun): apply the displayed default MTU (#8292)

* fix(tun): apply the displayed default MTU

Co-authored-by: ❤是纱雾酱哟~ <49941141+Dragon1573@users.noreply.github.com>
Signed-off-by: ❤是纱雾酱哟~ <49941141+Dragon1573@users.noreply.github.com>

* fix(tun): apply default MTU 1500 during config enhancement

Move the default `tun.mtu` fallback out of `IClashTemp::new` into `enhance::ensure_tun_default_mtu` so profile and
Merge/Script overrides are not overridden by `AuthoritativeFields` unless the user explicitly saved `tun.mtu` in
settings. Ignore `null` TUN values when collecting GUI keys, prevent clearing the MTU input in `TunViewer` from sending
`NaN`/`null`, and update `Changelog.md` to match template rules.

Assisted-by: Gemini 4 Hydrogen (Medium)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: ❤是纱雾酱哟~ <49941141+Dragon1573@users.noreply.github.com>

---------

Signed-off-by: ❤是纱雾酱哟~ <49941141+Dragon1573@users.noreply.github.com>
Co-authored-by: susu-Sugar <214122492+susu-Sugar@users.noreply.github.com>
Co-authored-by: ❤是纱雾酱哟~ <49941141+Dragon1573@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
susu-Sugar
2026-11-14 17:38:07 +00:00
committed by GitHub
co-authored by Copilot susu-Sugar ❤是纱雾酱哟~
parent bab4cd14cb
commit 41ad2d6d02
4 changed files with 24 additions and 7 deletions
+1
View File
@@ -32,6 +32,7 @@
- 修复窗口较窄时,首页「当前节点」卡片中过长的节点名把延迟标签挤出卡片
- 修复断开链式代理时清空已选节点,导致再次连接需要重新选择的问题
- 修复「连接」页表格排序时表头换行、标题位置跳动的问题
- 修复「TUN 设置」未手动保存时,界面显示的默认 MTU 1500 未生效的问题
**🍎 macOS**
+2
View File
@@ -70,6 +70,8 @@ pub mod files {
pub mod tun {
pub const DEFAULT_STACK: &str = "mips";
pub const DEFAULT_MTU: u16 = 1500;
pub const DNS_HIJACK: &[&str] = &["any:53"];
/// Saved dialog fields; `enable` belongs to the verge switch.
+15 -2
View File
@@ -459,7 +459,7 @@ fn gui_tun_keys(clash_config: &Mapping) -> Vec<Value> {
keys.extend(
constants::tun::GUI_KEYS
.iter()
.filter(|key| tun.contains_key(**key))
.filter(|key| tun.get(**key).is_some_and(|value| !value.is_null()))
.map(|key| Value::from(*key)),
);
}
@@ -531,6 +531,16 @@ fn ensure_lan_bind_address(mut config: Mapping) -> Mapping {
config
}
fn ensure_tun_default_mtu(mut config: Mapping) -> Mapping {
if let Some(Value::Mapping(tun)) = config.get_mut("tun")
&& matches!(tun.get("mtu"), None | Some(Value::Null))
{
tun.insert(Value::from("mtu"), Value::from(constants::tun::DEFAULT_MTU));
}
config
}
/// Merges the app's clash config over the profile; switches are parameters to keep it pure.
fn merge_default_config(
mut config: Mapping,
@@ -548,7 +558,9 @@ fn merge_default_config(
});
let patch_tun = value.as_mapping().cloned().unwrap_or_else(Mapping::new);
for (key, value) in patch_tun.into_iter() {
tun.insert(key, value);
if !value.is_null() {
tun.insert(key, value);
}
}
config.insert("tun".into(), tun.into());
} else {
@@ -878,6 +890,7 @@ pub async fn enhance(
notify_discarded_keys(authoritative.overridden(&authoritative, &authoritative.current(&config)));
let config = authoritative.enforce(config);
let config = ensure_tun_default_mtu(config);
let config = ensure_lan_bind_address(config);
let config = cleanup_proxy_groups(config);
+6 -5
View File
@@ -54,7 +54,7 @@ export function TunViewer({ ref }: { ref?: Ref<DialogRef> }) {
autoDetectInterface: true,
dnsHijack: ['any:53'],
strictRoute: false,
mtu: 1500,
mtu: 1500 as number | undefined,
dnsMode: '',
})
@@ -374,14 +374,15 @@ export function TunViewer({ ref }: { ref?: Ref<DialogRef> }) {
autoCapitalize="off"
spellCheck="false"
sx={{ width: 250 }}
value={values.mtu}
value={values.mtu ?? ''}
placeholder="1500"
onChange={(e) =>
onChange={(e) => {
const next = Number.parseInt(e.target.value, 10)
setValues((v) => ({
...v,
mtu: parseInt(e.target.value),
mtu: Number.isNaN(next) ? undefined : next,
}))
}
}}
/>
</ListItem>