mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-24 08:26:15 +00:00
tun: dual MTU, gateway, DNS, auto routing
Change TunSettings to support separate IPv4/IPv6 MTU values and add gateway, DNS, autoSystemRoutingTable and autoOutboundsInterface properties. Introduces _normalizeMtu to accept legacy single-value or array forms and provide sensible defaults. Update fromJson/toJson to handle new fields and preserve backward compatibility. Update tun form UI to expose MTU IPv4/IPv6 inputs, Gateway/DNS tag selects, Auto Routing Table and Auto Outbounds input.
This commit is contained in:
parent
eb16cca551
commit
094ea9faaa
2 changed files with 80 additions and 8 deletions
|
|
@ -2723,29 +2723,60 @@ Inbound.TunSettings = class extends Inbound.Settings {
|
|||
constructor(
|
||||
protocol,
|
||||
name = 'xray0',
|
||||
mtu = 1500,
|
||||
userLevel = 0
|
||||
mtu = [1500, 1280],
|
||||
gateway = [],
|
||||
dns = [],
|
||||
userLevel = 0,
|
||||
autoSystemRoutingTable = [],
|
||||
autoOutboundsInterface = 'auto'
|
||||
) {
|
||||
super(protocol);
|
||||
this.name = name;
|
||||
this.mtu = mtu;
|
||||
this.mtu = this._normalizeMtu(mtu);
|
||||
this.gateway = Array.isArray(gateway) ? gateway : [];
|
||||
this.dns = Array.isArray(dns) ? dns : [];
|
||||
this.userLevel = userLevel;
|
||||
this.autoSystemRoutingTable = Array.isArray(autoSystemRoutingTable) ? autoSystemRoutingTable : [];
|
||||
this.autoOutboundsInterface = autoOutboundsInterface;
|
||||
}
|
||||
|
||||
_normalizeMtu(mtu) {
|
||||
if (!Array.isArray(mtu)) {
|
||||
const single = Number(mtu) || 1500;
|
||||
return [single, single];
|
||||
}
|
||||
if (mtu.length === 0) {
|
||||
return [1500, 1280];
|
||||
}
|
||||
if (mtu.length === 1) {
|
||||
const single = Number(mtu[0]) || 1500;
|
||||
return [single, single];
|
||||
}
|
||||
return [Number(mtu[0]) || 1500, Number(mtu[1]) || 1280];
|
||||
}
|
||||
|
||||
static fromJson(json = {}) {
|
||||
return new Inbound.TunSettings(
|
||||
Protocols.TUN,
|
||||
json.name ?? 'xray0',
|
||||
json.mtu ?? json.MTU ?? 1500,
|
||||
json.userLevel ?? 0
|
||||
json.mtu ?? json.MTU ?? [1500, 1280],
|
||||
json.gateway ?? json.Gateway ?? [],
|
||||
json.dns ?? json.DNS ?? [],
|
||||
json.userLevel ?? 0,
|
||||
json.autoSystemRoutingTable ?? [],
|
||||
Object.prototype.hasOwnProperty.call(json, 'autoOutboundsInterface') ? json.autoOutboundsInterface : 'auto'
|
||||
);
|
||||
}
|
||||
|
||||
toJson() {
|
||||
return {
|
||||
name: this.name || 'xray0',
|
||||
mtu: this.mtu || 1500,
|
||||
mtu: this._normalizeMtu(this.mtu),
|
||||
gateway: this.gateway,
|
||||
dns: this.dns,
|
||||
userLevel: this.userLevel || 0,
|
||||
autoSystemRoutingTable: this.autoSystemRoutingTable,
|
||||
autoOutboundsInterface: this.autoOutboundsInterface,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
@ -22,17 +22,43 @@
|
|||
<template slot="title">
|
||||
<span>{{ i18n "pages.xray.tun.mtuDesc" }}</span>
|
||||
</template>
|
||||
MTU
|
||||
MTU IPv4
|
||||
<a-icon type="question-circle"></a-icon>
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<a-input-number
|
||||
v-model.number="inbound.settings.mtu"
|
||||
v-model.number="inbound.settings.mtu[0]"
|
||||
:min="1"
|
||||
:max="9000"
|
||||
placeholder="1500"
|
||||
></a-input-number>
|
||||
</a-form-item>
|
||||
<a-form-item label="MTU IPv6">
|
||||
<a-input-number
|
||||
v-model.number="inbound.settings.mtu[1]"
|
||||
:min="1"
|
||||
:max="9000"
|
||||
placeholder="1280"
|
||||
></a-input-number>
|
||||
</a-form-item>
|
||||
<a-form-item label="Gateway">
|
||||
<a-select
|
||||
mode="tags"
|
||||
v-model="inbound.settings.gateway"
|
||||
:style="{ width: '100%' }"
|
||||
:token-separators="[',']"
|
||||
placeholder="IPv4/IPv6 gateway"
|
||||
></a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="DNS">
|
||||
<a-select
|
||||
mode="tags"
|
||||
v-model="inbound.settings.dns"
|
||||
:style="{ width: '100%' }"
|
||||
:token-separators="[',']"
|
||||
placeholder="DNS servers"
|
||||
></a-select>
|
||||
</a-form-item>
|
||||
<a-form-item>
|
||||
<template slot="label">
|
||||
<a-tooltip>
|
||||
|
|
@ -49,5 +75,20 @@
|
|||
placeholder="0"
|
||||
></a-input-number>
|
||||
</a-form-item>
|
||||
<a-form-item label="Auto Routing Table">
|
||||
<a-select
|
||||
mode="tags"
|
||||
v-model="inbound.settings.autoSystemRoutingTable"
|
||||
:style="{ width: '100%' }"
|
||||
:token-separators="[',']"
|
||||
placeholder="e.g. vpn, proxy"
|
||||
></a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="Auto Outbounds">
|
||||
<a-input
|
||||
v-model.trim="inbound.settings.autoOutboundsInterface"
|
||||
placeholder="auto"
|
||||
></a-input>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
{{end}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue