mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-09-30 21:16:03 +00:00
TUN inbound: Rename strictRoute to autoSystemWFP
It only turns on the Windows Filtering Platform filters, along with Xray resolving its own lookups while they restrict DNS, so it is named after what it sets up in the system, like autoSystemRoutingTable and autoSystemDNS. The config field becomes auto_system_wfp, with the same number; strictRoute was never released. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
edd916b08e
commit
63de6135cb
+2
-2
@@ -21,7 +21,7 @@ type TunConfig struct {
|
||||
AutoSystemRoutingTable []string `json:"autoSystemRoutingTable"`
|
||||
AutoOutboundsInterface *string `json:"autoOutboundsInterface"`
|
||||
AutoSystemDNS bool `json:"autoSystemDNS"`
|
||||
StrictRoute bool `json:"strictRoute"`
|
||||
AutoSystemWFP bool `json:"autoSystemWFP"`
|
||||
}
|
||||
|
||||
func (v *TunConfig) Build() (proto.Message, error) {
|
||||
@@ -34,7 +34,7 @@ func (v *TunConfig) Build() (proto.Message, error) {
|
||||
UserLevel: v.UserLevel,
|
||||
AutoSystemRoutingTable: v.AutoSystemRoutingTable,
|
||||
AutoSystemDns: v.AutoSystemDNS,
|
||||
StrictRoute: v.StrictRoute,
|
||||
AutoSystemWfp: v.AutoSystemWFP,
|
||||
}
|
||||
if v.AutoOutboundsInterface != nil {
|
||||
config.AutoOutboundsInterface = *v.AutoOutboundsInterface
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/xtls/xray-core/proxy/tun"
|
||||
)
|
||||
|
||||
func TestTunConfigStrictRoute(t *testing.T) {
|
||||
func TestTunConfigAutoSystemWFP(t *testing.T) {
|
||||
creator := func() Buildable {
|
||||
return new(TunConfig)
|
||||
}
|
||||
@@ -19,9 +19,9 @@ func TestTunConfigStrictRoute(t *testing.T) {
|
||||
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500},
|
||||
},
|
||||
{
|
||||
Input: `{"name": "xray0", "strictRoute": true}`,
|
||||
Input: `{"name": "xray0", "autoSystemWFP": true}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, StrictRoute: true},
|
||||
Output: &tun.Config{Name: "xray0", Desc: "Wintun", MTU: 1500, AutoSystemWfp: true},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
+2
-2
@@ -200,7 +200,7 @@ After the start network adapter with the name you chose in the config will be cr
|
||||
|
||||
When `dns` is set, those servers are applied to the adapter. Windows is kept from registering the TUN's addresses in DNS, and its DNS cache is flushed when the TUN starts and stops.
|
||||
|
||||
With `strictRoute` and `autoSystemRoutingTable` set, Xray also adds Windows Filtering Platform filters that keep two kinds of traffic of every program but Xray itself from leaving outside the TUN:
|
||||
With `autoSystemWFP` and `autoSystemRoutingTable` set, Xray also adds Windows Filtering Platform filters that keep two kinds of traffic of every program but Xray itself from leaving outside the TUN:
|
||||
- With `dns` set, DNS (port 53) only goes through the TUN. Windows keeps sending name queries to the DNS servers of the other interfaces as well, out through those interfaces whatever the routes say, and other programs reach a resolver on the local network (e.g. `192.168.1.1` handed out by DHCP) through its more specific LAN route instead of the TUN. On Windows 11 and Server 2022 and later, where those queries may also go over HTTPS or TLS, Windows' DNS Client service cannot connect outside the TUN at all, except for name resolution on the local network (LLMNR, mDNS). The `dns` servers therefore have to lie within `gateway` or `autoSystemRoutingTable` (a warning is logged otherwise), and DNS servers that should be reached directly belong in Xray's own `dns` settings.
|
||||
- Unless the TUN carries IPv6, that is, has an IPv6 address in `gateway` and IPv6 routes in `autoSystemRoutingTable`, IPv6 is blocked entirely, in both directions, as it would bypass the TUN. Only loopback and what Windows itself needs on the local link (neighbor and multicast listener discovery, DHCPv6) remain allowed.
|
||||
|
||||
@@ -210,7 +210,7 @@ Names that Xray resolves through the system resolver, such as an outbound's serv
|
||||
|
||||
If the filters cannot be added, the TUN does not start (on Windows 10 and later; older versions only log a warning). They are removed when Xray exits. Not covered is name resolution on the local network (LLMNR, mDNS, NetBIOS), except over IPv6 while that is blocked.
|
||||
|
||||
`strictRoute` (Windows only) is `false` by default, as the filters break some setups: a local DNS resolver other programs use (e.g. on `127.0.0.1:53`), the DNS of another VPN on its own interface, IPv6 on the local network while the TUN has no IPv6 address, virtual machines whose NAT resolves names on the host, or signing in to a captive portal. Without the filters, DNS may leak as described above.
|
||||
`autoSystemWFP` (Windows only) is `false` by default, as the filters break some setups: a local DNS resolver other programs use (e.g. on `127.0.0.1:53`), the DNS of another VPN on its own interface, IPv6 on the local network while the TUN has no IPv6 address, virtual machines whose NAT resolves names on the host, or signing in to a captive portal. Without the filters, DNS may leak as described above.
|
||||
|
||||
You can give the adapter ip address manually, you can live Windows to give it autogenerated ip address (which take few seconds), it doesn't matter, the traffic going _through_ the interface will be forwarded into the app for proxying. \
|
||||
Minimal configuration that will work for local machine is routing passing the traffic on-link through the interface.
|
||||
|
||||
@@ -33,7 +33,7 @@ type Config struct {
|
||||
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"`
|
||||
AutoSystemDns bool `protobuf:"varint,9,opt,name=auto_system_dns,json=autoSystemDns,proto3" json:"auto_system_dns,omitempty"`
|
||||
StrictRoute bool `protobuf:"varint,10,opt,name=strict_route,json=strictRoute,proto3" json:"strict_route,omitempty"`
|
||||
AutoSystemWfp bool `protobuf:"varint,10,opt,name=auto_system_wfp,json=autoSystemWfp,proto3" json:"auto_system_wfp,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -131,9 +131,9 @@ func (x *Config) GetAutoSystemDns() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Config) GetStrictRoute() bool {
|
||||
func (x *Config) GetAutoSystemWfp() bool {
|
||||
if x != nil {
|
||||
return x.StrictRoute
|
||||
return x.AutoSystemWfp
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -142,7 +142,7 @@ var File_proxy_tun_config_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_proxy_tun_config_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x16proxy/tun/config.proto\x12\x0exray.proxy.tun\"\xcd\x02\n" +
|
||||
"\x16proxy/tun/config.proto\x12\x0exray.proxy.tun\"\xd2\x02\n" +
|
||||
"\x06Config\x12\x12\n" +
|
||||
"\x04name\x18\x01 \x01(\tR\x04name\x12\x10\n" +
|
||||
"\x03MTU\x18\x02 \x01(\rR\x03MTU\x12\x18\n" +
|
||||
@@ -153,9 +153,9 @@ const file_proxy_tun_config_proto_rawDesc = "" +
|
||||
"\x19auto_system_routing_table\x18\x06 \x03(\tR\x16autoSystemRoutingTable\x128\n" +
|
||||
"\x18auto_outbounds_interface\x18\a \x01(\tR\x16autoOutboundsInterface\x12\x12\n" +
|
||||
"\x04desc\x18\b \x01(\tR\x04desc\x12&\n" +
|
||||
"\x0fauto_system_dns\x18\t \x01(\bR\rautoSystemDns\x12!\n" +
|
||||
"\fstrict_route\x18\n" +
|
||||
" \x01(\bR\vstrictRouteBL\n" +
|
||||
"\x0fauto_system_dns\x18\t \x01(\bR\rautoSystemDns\x12&\n" +
|
||||
"\x0fauto_system_wfp\x18\n" +
|
||||
" \x01(\bR\rautoSystemWfpBL\n" +
|
||||
"\x12com.xray.proxy.tunP\x01Z#github.com/xtls/xray-core/proxy/tun\xaa\x02\x0eXray.Proxy.Tunb\x06proto3"
|
||||
|
||||
var (
|
||||
|
||||
@@ -16,5 +16,5 @@ message Config {
|
||||
string auto_outbounds_interface = 7;
|
||||
string desc = 8;
|
||||
bool auto_system_dns = 9;
|
||||
bool strict_route = 10;
|
||||
bool auto_system_wfp = 10;
|
||||
}
|
||||
|
||||
@@ -246,10 +246,10 @@ startOver:
|
||||
}
|
||||
}
|
||||
|
||||
// With strictRoute, once the system routes lead to the TUN, keep DNS if
|
||||
// With autoSystemWFP, once the system routes lead to the TUN, keep DNS if
|
||||
// dns is set, and IPv6 if the TUN cannot carry it (no IPv6 address, or no
|
||||
// IPv6 route to it), from leaving through the other interfaces.
|
||||
if blockDNS, blockIPv6 := len(dns) > 0, !address6 || !route6; t.options.StrictRoute && (route4 || route6) && (blockDNS || blockIPv6) {
|
||||
if blockDNS, blockIPv6 := len(dns) > 0, !address6 || !route6; t.options.AutoSystemWfp && (route4 || route6) && (blockDNS || blockIPv6) {
|
||||
if t.wfp, err = blockLeaks(t.luid, blockDNS, blockIPv6); err != nil {
|
||||
what := "DNS and IPv6"
|
||||
if !blockIPv6 {
|
||||
@@ -261,7 +261,7 @@ startOver:
|
||||
// untested, and sing-box's broke its TUN there (SagerNet/sing-box#3659),
|
||||
// so older versions only get a warning.
|
||||
if major, _, _ := windows.RtlGetNtVersionNumbers(); major >= 10 {
|
||||
return errors.New("unable to block ", what, " outside the TUN (set strictRoute to false to run without)").Base(err)
|
||||
return errors.New("unable to block ", what, " outside the TUN (set autoSystemWFP to false to run without)").Base(err)
|
||||
}
|
||||
errors.LogWarningInner(context.Background(), err, "[tun] unable to block ", what, " outside the TUN, leaks are possible")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user