From 629f9a970e73f8ea34eb34978db151b42ddbbd73 Mon Sep 17 00:00:00 2001 From: Chapito <282825138+Jasper344612@users.noreply.github.com> Date: Mon, 13 Jul 2026 10:19:47 +0800 Subject: [PATCH 1/2] TUN Inbound: mannul tun desc of Windows --- infra/conf/tun.go | 5 +++++ proxy/tun/README.md | 4 ++++ proxy/tun/config.pb.go | 18 ++++++++++++++---- proxy/tun/config.proto | 1 + proxy/tun/tun_windows.go | 6 +++--- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/infra/conf/tun.go b/infra/conf/tun.go index 0f82363a66d3..73e71a991af2 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 d1c3aeb7735d..797f40f48fb9 100644 --- a/proxy/tun/README.md +++ b/proxy/tun/README.md @@ -32,12 +32,16 @@ Here is simple Xray config snippet to enable the inbound: "protocol": "tun", "settings": { "name": "xray0", + "desc": "Wintun", "MTU": 1492 } } ], ``` +`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 04ce01d803e6..33bc2ba6f9fa 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 50d43ce2b8d4..376ac5af49ec 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 daa44c8aeb39..4c5a0ed88a66 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 } From 6705acf8a6e77537b09a1650a620b4d3617820ac Mon Sep 17 00:00:00 2001 From: Chapito <282825138+Jasper344612@users.noreply.github.com> Date: Fri, 17 Jul 2026 23:37:24 +0800 Subject: [PATCH 2/2] fix: readme --- proxy/tun/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/tun/README.md b/proxy/tun/README.md index 797f40f48fb9..18c4c3345513 100644 --- a/proxy/tun/README.md +++ b/proxy/tun/README.md @@ -31,9 +31,9 @@ Here is simple Xray config snippet to enable the inbound: "port": 0, "protocol": "tun", "settings": { - "name": "xray0", + "name": "utun10", "desc": "Wintun", - "MTU": 1492 + "mtu": 1500 } } ],