Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions infra/conf/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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,
Expand All @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions proxy/tun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions proxy/tun/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proxy/tun/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions proxy/tun/tun_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down