2026-01-07 23:05:08 +01:00
|
|
|
package conf
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/xtls/xray-core/proxy/tun"
|
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type TunConfig struct {
|
2026-04-13 21:38:10 +08:00
|
|
|
Name string `json:"name"`
|
2026-04-15 15:40:19 +03:00
|
|
|
MTU uint32 `json:"mtu"`
|
2026-04-13 21:38:10 +08:00
|
|
|
Gateway []string `json:"gateway"`
|
|
|
|
|
DNS []string `json:"dns"`
|
|
|
|
|
UserLevel uint32 `json:"userLevel"`
|
|
|
|
|
AutoSystemRoutingTable []string `json:"autoSystemRoutingTable"`
|
|
|
|
|
AutoOutboundsInterface *string `json:"autoOutboundsInterface"`
|
2026-01-07 23:05:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v *TunConfig) Build() (proto.Message, error) {
|
|
|
|
|
config := &tun.Config{
|
2026-04-13 21:38:10 +08:00
|
|
|
Name: v.Name,
|
|
|
|
|
MTU: v.MTU,
|
|
|
|
|
Gateway: v.Gateway,
|
|
|
|
|
DNS: v.DNS,
|
|
|
|
|
UserLevel: v.UserLevel,
|
|
|
|
|
AutoSystemRoutingTable: v.AutoSystemRoutingTable,
|
|
|
|
|
}
|
|
|
|
|
if v.AutoOutboundsInterface != nil {
|
|
|
|
|
config.AutoOutboundsInterface = *v.AutoOutboundsInterface
|
|
|
|
|
}
|
|
|
|
|
if len(v.AutoSystemRoutingTable) > 0 && v.AutoOutboundsInterface == nil {
|
|
|
|
|
config.AutoOutboundsInterface = "auto"
|
2026-01-07 23:05:08 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-13 21:38:10 +08:00
|
|
|
if config.Name == "" {
|
2026-01-07 23:05:08 +01:00
|
|
|
config.Name = "xray0"
|
|
|
|
|
}
|
2026-04-15 15:40:19 +03:00
|
|
|
if config.MTU == 0 {
|
|
|
|
|
config.MTU = 1500
|
2026-01-07 23:05:08 +01:00
|
|
|
}
|
|
|
|
|
return config, nil
|
|
|
|
|
}
|