From 1d8eb81d7007b8613eaf87b7b9577074447a2c89 Mon Sep 17 00:00:00 2001 From: Jasper344612 <282825138+Jasper344612@users.noreply.github.com> Date: Sat, 18 Jul 2026 06:21:33 +0800 Subject: [PATCH] TUN inbound: Add `desc` config for Windows ("Wintun" by default) (#6486) https://github.com/XTLS/Xray-docs-next/pull/872#issuecomment-4936055488 --- infra/conf/tun.go | 5 +++++ proxy/tun/README.md | 8 ++++++-- proxy/tun/config.pb.go | 18 ++++++++++++++---- proxy/tun/config.proto | 1 + proxy/tun/tun_windows.go | 6 +++--- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/infra/conf/tun.go b/infra/conf/tun.go index 0f82363a6..73e71a991 100644 --- a/infra/conf/tun.go +++ b/infra/conf/tun.go @@ -13,6 +13,7 @@ import ( type TunConfig struct { Name string `json:"name"` + Desc string `json:"desc"` MTU uint32 `json:"mtu"` Gateway []string `json:"gateway"` DNS []string `json:"dns"` @@ -24,6 +25,7 @@ type TunConfig struct { func (v *TunConfig) Build() (proto.Message, error) { config := &tun.Config{ Name: v.Name, + Desc: v.Desc, MTU: v.MTU, Gateway: v.Gateway, DNS: v.DNS, @@ -44,6 +46,9 @@ func (v *TunConfig) Build() (proto.Message, error) { } config.Name = name } + if config.Desc == "" { + config.Desc = "Wintun" + } if config.MTU == 0 { config.MTU = 1500 } diff --git a/proxy/tun/README.md b/proxy/tun/README.md index d1c3aeb77..18c4c3345 100644 --- a/proxy/tun/README.md +++ b/proxy/tun/README.md @@ -31,13 +31,17 @@ Here is simple Xray config snippet to enable the inbound: "port": 0, "protocol": "tun", "settings": { - "name": "xray0", - "MTU": 1492 + "name": "utun10", + "desc": "Wintun", + "mtu": 1500 } } ], ``` +`desc` sets the Windows Wintun adapter tunnel type and defaults to `Wintun`. +It is ignored on other platforms. + ## SUPPORTED FEATURES - IPv4 and IPv6 diff --git a/proxy/tun/config.pb.go b/proxy/tun/config.pb.go index 04ce01d80..33bc2ba6f 100644 --- a/proxy/tun/config.pb.go +++ b/proxy/tun/config.pb.go @@ -7,11 +7,12 @@ package tun import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" unsafe "unsafe" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const ( @@ -30,6 +31,7 @@ type Config struct { UserLevel uint32 `protobuf:"varint,5,opt,name=user_level,json=userLevel,proto3" json:"user_level,omitempty"` AutoSystemRoutingTable []string `protobuf:"bytes,6,rep,name=auto_system_routing_table,json=autoSystemRoutingTable,proto3" json:"auto_system_routing_table,omitempty"` AutoOutboundsInterface string `protobuf:"bytes,7,opt,name=auto_outbounds_interface,json=autoOutboundsInterface,proto3" json:"auto_outbounds_interface,omitempty"` + Desc string `protobuf:"bytes,8,opt,name=desc,proto3" json:"desc,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -113,11 +115,18 @@ func (x *Config) GetAutoOutboundsInterface() string { return "" } +func (x *Config) GetDesc() string { + if x != nil { + return x.Desc + } + return "" +} + var File_proxy_tun_config_proto protoreflect.FileDescriptor const file_proxy_tun_config_proto_rawDesc = "" + "\n" + - "\x16proxy/tun/config.proto\x12\x0exray.proxy.tun\"\xee\x01\n" + + "\x16proxy/tun/config.proto\x12\x0exray.proxy.tun\"\x82\x02\n" + "\x06Config\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x10\n" + "\x03MTU\x18\x02 \x01(\rR\x03MTU\x12\x18\n" + @@ -126,7 +135,8 @@ const file_proxy_tun_config_proto_rawDesc = "" + "\n" + "user_level\x18\x05 \x01(\rR\tuserLevel\x129\n" + "\x19auto_system_routing_table\x18\x06 \x03(\tR\x16autoSystemRoutingTable\x128\n" + - "\x18auto_outbounds_interface\x18\a \x01(\tR\x16autoOutboundsInterfaceBL\n" + + "\x18auto_outbounds_interface\x18\a \x01(\tR\x16autoOutboundsInterface\x12\x12\n" + + "\x04desc\x18\b \x01(\tR\x04descBL\n" + "\x12com.xray.proxy.tunP\x01Z#github.com/xtls/xray-core/proxy/tun\xaa\x02\x0eXray.Proxy.Tunb\x06proto3" var ( diff --git a/proxy/tun/config.proto b/proxy/tun/config.proto index 50d43ce2b..376ac5af4 100644 --- a/proxy/tun/config.proto +++ b/proxy/tun/config.proto @@ -14,4 +14,5 @@ message Config { uint32 user_level = 5; repeated string auto_system_routing_table = 6; string auto_outbounds_interface = 7; + string desc = 8; } diff --git a/proxy/tun/tun_windows.go b/proxy/tun/tun_windows.go index daa44c8ae..4c5a0ed88 100644 --- a/proxy/tun/tun_windows.go +++ b/proxy/tun/tun_windows.go @@ -50,7 +50,7 @@ var _ GVisorDevice = (*WindowsTun)(nil) // interface with the same name exist, it tried to be reused. func NewTun(options *Config) (Tun, error) { // instantiate wintun adapter - adapter, err := open(options.Name) + adapter, err := open(options.Name, options.Desc) if err != nil { return nil, err } @@ -73,12 +73,12 @@ func NewTun(options *Config) (Tun, error) { return tun, nil } -func open(name string) (*wintun.Adapter, error) { +func open(name, desc string) (*wintun.Adapter, error) { // generate a deterministic GUID from the adapter name id := md5.Sum([]byte(name)) guid := (*windows.GUID)(unsafe.Pointer(&id[0])) // try to create adapter anew - adapter, err := wintun.CreateAdapter(name, "Xray", guid) + adapter, err := wintun.CreateAdapter(name, desc, guid) if err == nil { return adapter, nil }