With TUN on, every proxy node IP gets a host route through the physical
gateway on macOS and Windows. A node on 127.0.0.1, such as a local
forwarder, then had 127.0.0.1 routed to the Wi-Fi gateway: loopback
broke for every process, the connectivity probe of the core API failed,
the transparent proxy paused, the routes went away, the probe recovered
and the cycle repeated. Loopback nodes are reached without leaving the
host, so collectNodeIPs drops them.
Fixes#2148
runtimeAssetDir called os.MkdirAll on $XDG_RUNTIME_DIR/v2raya with mode
0700. When v2rayA runs as root on a system where /run/user does not
exist yet (OpenRC with elogind before any login), that created
/run/user itself as 0700 root:root, and every other user then failed to
get a runtime directory.
The runtime directory belongs to the login manager, so use it only when
it already exists and otherwise put the asset links in the
configuration directory, as a service user without a session already
does. A regular file there is one the user placed, so the lookup now
uses it instead of replacing it with a link to the system copy.
Closes#2092
deleteTransparentProxyRules returned before touching the system proxy
whenever no snapshot had been persisted. GetCleanCommands already
handles both cases -- it restores the saved original when a snapshot
exists and falls back to disabling ProxyEnable when none does -- so the
guard only suppressed the fallback that makes the two modes exclusive.
The leftover registry value pointed at 52345, which only the
system_proxy mode ever listens on. Switching back to tun therefore left
proxy-using applications connected to a dead port: their sockets stayed
in SYN_SENT until the process was restarted.
The regression test drives deleteTransparentProxyRules with no snapshot
and asserts the proxy is disabled. Against the previous code it fails
with "the system proxy was never touched"; it passes with this change.
Since v2.4 the dokodemo transparent inbound binds 127.0.0.1 only, so
traffic intercepted by the PREROUTING transparent rules and REDIRECTed
to the interface address (e.g. docker bridge containers) can never
reach it: all bridge-container TCP breaks while transparent proxy is
enabled, a regression from 2.2.x where the inbound listened on 0.0.0.0.
Let the inbound follow the existing 'Allow connections from LAN'
(PortSharing) setting, which the socks/http inbounds
(template_inbound.go) and dns-in (template_outbound.go) already follow.
Default behavior is unchanged (loopback-only with PortSharing off);
with PortSharing on, redirected/forwarded traffic works again.
Settings had a Multiplex switch and a concurrency field, validated and stored,
that no template code read. VMess outbounds get mux.enabled and the
concurrency when the switch is on, which is what the help text promised
("vmess only"). The core accepts the result (run -test).
Strings that still named v2ray-core, "v2ray / xray" or a wiki: six locales
(the core is v2raya_core; the invalid-service message, the SS plugin help,
the transparent-proxy hint, the TUN example, the custom inbound tag hint),
the --v2ray-bin, --core-startup-timeout and --plugin-manager descriptions
and their copies in the OpenRC confd files (the plugin manager is called
with --stage=parse|configuration, --link and --v2raya-confdir, not with
life-cycle stages), two comments that forbade or excused the current design,
the package descriptions that listed SSR, the AUR Go minimum (go.mod says
1.26), the systemd Documentation= and the installer's shortcut that pointed
at the wiki and the docs site, and the README sentence on network requests,
which left out the weekly release check and the NTP query on VMess failure.
copyfile, the empty ports/ss.go stub, parseDnsAddr and DnsRouting (the DNS
config is generated for the core's module now), the Inter font and the
switch-menu icon of the old GUI, the docs-site dispatch workflow (the site is
retired; the docs are in the app), the unused v2ray_arch in the docker helper,
the root .gitignore rule for a web directory that moved, and the .dockerignore
patterns for binary and test names that no longer exist. The skipped
TestFillEmpty asserts what FillEmpty does instead of what it once did.
--redirect-respect-bound-device was the first field of Params, so it led
--help, --report config and the /etc/default/v2raya the packages generate
from it; it now follows --ipv6-support. Its description says what it does
in the user's terms (SO_BINDTODEVICE, NetworkManager's connectivity
checks) and what it needs (kernel 5.7, cgroup v2). When SO_NETNS_COOKIE
is missing the error says the kernel is too old instead of ENOPROTOOPT.
cilium/ebpf moves to the direct require block, as go mod tidy puts it.
Currently, if system /usr/share/v2raya/geosite.dat is used, v2raya will
not post error, but will display "none" for local GFWList date.
Since v2rayA reads this compatible file, we should display a date for
it, so that user is not confused.
Assisted-by: GPT-5.6-terra
Node hostnames, upstream hostnames and the service's own lookups (subscriptions,
latency tests) were resolved by hard-coded public resolvers (223.5.5.5, 119.29.29.29,
...) whatever the DNS rules said; the second nameserver written into the hijacked
/etc/resolv.conf was hard-coded too. directDnsServers() now collects the plain
udp/tcp IP upstreams of the rules with the direct outbound, and
- resolv.PreferredServers hands them to the service's resolver before its public list
- the module's bootstrap_dns is the system's resolvers plus those upstreams
- the upstream for node hostnames is the first of them
- HijackResolv writes the first port-53 one as the second nameserver, and so does the
restore when no backup exists
getSystemDnsServers reads the backup while resolv.conf is hijacked, so a restart
no longer hands the module its own listener as bootstrap.
The DNS module spoke UDP, TCP and DNS over TLS. An https:// upstream is
now an RFC 8484 POST through an http.Client the upstream keeps between
queries; the TLS handshake is done in the dialer so the server name is
the upstream's hostname while the address dialled is what bootstrap
resolved for it — the module cannot ask itself for its own upstream's
address. A direct upstream dials on a marked socket, as the other
protocols do; a proxied one dials through the xray dispatcher, so the
request leaves through the chosen outbound.
Two things the dispatcher path had wrong for tls:// upstreams: it sent
plain DNS over TCP whatever the protocol, and bootstrap replaced the
hostname by an IP without keeping it, so TLS had nothing to verify
against. The hostname is kept as ServerName on the upstream, the
dispatcher path wraps the connection in TLS for tcp-tls, and the direct
miekg client verifies the same name. The service adds https and tls
hostnames to the bootstrap list, which it skipped for every scheme
address before. CheckDnsUpstream accepts https:// URLs with a host and
still refuses quic://.
Verified on the VM with a raw UDP client against the module, names not
in its cache: https://dns.google/dns-query direct (bootstrap dns.google
→ 8.8.8.8, a v2raya_core connection to 8.8.8.8:443), https://1.1.1.1
/dns-query via proxy (the connection goes to the proxy server's :443),
tls://dns.google via proxy (rewritten to 8.8.8.8:853, TLS verified as
dns.google) and tls://1.1.1.1 direct all answer; the previous rules
restore unchanged. A unit test runs the DoH client against an httptest
TLS server.
The DNS form's placeholder offered https://dns.google/dns-query, the
service turned https:// into protocol "https" and quic:// into "quic",
and the DNS module handed those to a miekg/dns client, which speaks udp,
tcp and tcp-tls only. Saving succeeded and every query on that rule then
failed, visible only in the log.
CheckDnsUpstream in kernel/v2ray accepts an address, tcp://, udp:// and
tls:// (DNS over TLS, which the module does support) and rejects https://
and quic:// with a message that names the alternatives; PutDnsRules
returns it as a 400 before anything is stored. The placeholder in the six
locales shows the supported forms and the docs say which schemes work.
Verified on the VM: https:// and quic:// rules come back BAD_REQUEST with
the message, tls://1.1.1.1 saves and the module logs
addr=1.1.1.1:853 protocol=tcp-tls; the previous rules restore unchanged.
The core's asset directory defaulted to v2raya/ under the XDG runtime
directory, and the lookup created the links there with xdg.RuntimeFile.
A service user has no session, so /run/user/<uid> does not exist and the
user cannot create it; the first lookup failed with "could not create any
of the following paths: /run/user/1001/v2raya" and the start died, while
geoip.dat and geosite.dat sat in /usr/share/v2raya. That is every
OpenRC v2raya-user.<user> instance and any lite start outside a desktop
session. When the runtime directory cannot be made, the configuration
directory, which the process owns, holds the links instead.
Verified on the Gentoo VM: /etc/init.d/v2raya-user.tuser starts, reports
lite and links /usr/share/v2raya/*.dat into ~/.config/v2raya.
Inspect bound_dev_if at connect time, preserve existing socket marks and
add the existing 0x80 bypass bit before REDIRECT. Scope the guard to the
manager's network namespace and release real BPF links on teardown.
Include opt-in isolated cgroup tests and document the experimental status,
unverified native behavior, performance work, and connect-time limits.
Deleting nodes stored the renumbered connections, the subscriptions and
the servers in three commits; they are one transaction. Without a
catch-all DNS rule the module keeps its own fallback, as every earlier
release did. The login body is capped at 4 KiB, since it is now read
before the one-at-a-time semaphore. The apply-config error names a
failed restore, so every handler's message says whether the previous
value came back. The Windows system proxy reuses a snapshot pending
from an earlier run instead of refusing to start.
A custom latency test URL that http.NewRequest rejects made a spawned
goroutine dereference nil and exit the process; the URL is validated
before any goroutine starts and the request error is handled. A
Shadowsocks link whose plugin field has no ";" panicked the parser, and
from the automatic subscription update that goroutine was unrecovered;
the parser accepts it and each updater recovers and logs.
The DNS module took the last non-bootstrap upstream as the fallback
while the template emitted upstreams in rule order with deduplication,
so a catch-all rule anywhere but last, or one whose upstream was
deduplicated, was not the fallback. The template names the fallback in
a new default_upstream field and the module honours it.
PUT /routingA stored the rules without regenerating the running core.
It goes through ApplyCoreConfig like the other config writers, with
restore on failure. UpdateSubscription logged a failed core reload and
answered success; it returns the error. PATCH /subscription joins the
mutation turn.
Subscription fetching retried through a direct connection when the
selected proxy failed, leaking the subscription URL; it returns the
error. Subscription documents are capped at 32 MiB and downloaded
assets at 256 MiB. PUT /gfwList validates the downloaded file as a
geosite list before replacing the working one.
The login handler took its one-at-a-time semaphore before reading the
body, so a client sending headers and no body blocked every login; the
body is read first and the HTTP server has header and idle timeouts.
Share links: a VLESS or VMess link without a numeric port is rejected
at parse time instead of producing port 0; an SSR link with a password
that is not base64 is rejected instead of importing empty; the SIP003
path gets its leading slash prepended, not a trailing one appended.
The macOS system proxy quoted shell arguments with strconv.Quote,
which leaves $(...) live; values are single-quoted. The Windows system
proxy snapshot includes AutoConfigURL, which teardown deleted and never
restored. Latency test responses with a non-2xx status are closed. The
version response carries the docker flag the GUI's port hints read.
Three structural changes that share files, so one commit:
Settings, ports, DNS rules and custom inbounds each carried their own
copy of "store the new value, regenerate the core config, put the old
value back when that fails", and the outbound setting path had no
restore at all. ApplyCoreConfig takes a snapshot function and a store
function and does the sequence once for all five callers; the outbound
setting path restores like the others, and the error names which of
the three steps failed.
configure.Which was the persisted discriminator, the key that locates a
node, and the response row with its latency, link and selected flag at
once. NodeRef {type, id, sub, outbound} is the identity used by the
locator, EqualTo, the connected lists and the group operations; Which
embeds it and keeps the status fields. The JSON stays byte for byte
what it was (a test marshals a fixture before and after), stored
connected lists decode unchanged, and deduplication keys by identity
instead of by the whole row.
db.List* dispatched on "bucket/key" string literals to reach the
servers and subscriptions tables. The bodies are now Servers* and
Subscriptions* functions that configure calls directly; the List*
wrappers remain for the migration.
systemd sends the whole cgroup SIGTERM, so the core died before the
service and was recorded as a crash; the next boot then refused to
restore the proxy ("exited abnormally the last time", discussion
#1922). The signal handler marks the manager as shutting down before
anything else, a core exit in that state keeps the running flag, and
the units use KillMode=mixed so only the service receives the signal.
A SQLite file that an earlier release's migration left empty next to an
intact bolt.db was taken as authoritative; a file without the system
settings a completed migration writes is discarded and the migration
runs again. A database migrated by that earlier release holds its
groups and outbound settings in the two tables the runtime never read;
opening it copies them into the keys it reads, for outbounds that have
none yet.
A start whose host-state recovery failed refused to run, and a start
that rolled back after its own stop tore the host state down a second
time; recovery is logged and retried at the next start, and a rollback
that stopped its process only clears the marker. A system-proxy
snapshot pending from an earlier run blocked every later system-proxy
start; it is reused as the original instead (Linux and macOS here; the
Windows side follows with its per-profile snapshot).
An empty /etc/resolv.conf was backed up as an empty file, which the
restore rejects as truncated; it is written as a marker and restored as
empty. db.Close resets the once so a reopen works.
Start persisted running=false, stopped the old core, published the new
process and unlocked, installed the firewall rules, DNS hijack, TUN
routes or system proxy, and only then persisted running=true. A crash in
that window made the next start skip the core and clean only TUN
residue, so redirect rules, a hijacked resolver or the system proxy kept
pointing at a dead listener.
Before it installs anything, Start now stores a host-state marker (the
transparent type, API port and TUN teardown settings) and clears it once
the start commits or is rolled back; startup and the next Start tear
that state down when they find the marker. Every host mutation and the
final commit check that the process they started is still the manager's
current one, so a core that exits during afterStart fails the start
instead of leaving the UI and the store saying running. The system-proxy
implementations persist the user's original proxy settings when they
capture them and restore from that copy when the in-memory one is gone.
A recovery that fails is logged and retried at the next start; it never
blocks the service.
The core hooks ran under exec.Command with no deadline while Start held
the manager's lock, so a hook that never returned left the proxy stopped
and every status read blocked. They now run with the startup timeout as
their deadline in their own process group.
The custom-inbound POST and DELETE handlers did not take the mutation
turn; two concurrent additions read the same list and the last write
won. They take it like every other state-changing handler.
A failed HTTP bind ended in log.Fatal before the deferred cleanup, so
the core and the transparent-proxy rules stayed behind; run() now
returns the error through the same cleanup the shutdown path uses.
The resolv.conf backup was written in place; a crash mid-write left a
truncated file that the next start restored as the original. It is
written to a temporary file, synced and renamed, and an empty backup is
ignored on restore.
SetAPI starts the traffic and observatory producers together with the
template, and only a running process closes them. A start that failed
before the process existed — the config write, the inbound port check or
the missing GFWList — returned without closing the template, and the
latency test returned early on port exhaustion the same way. Each such
failure left goroutines dialling a port nothing listens on and logging a
warning every second for the rest of the service's life.
NewProcess closes the template on every error path, the GFWList check
closes it before returning, and the latency test closes its template
until the process manager owns it.
Which.LocateServerRaw read and parsed every stored node for each lookup,
so a loop over n whiches cost n reads: the latency test, the config
generation for a group, the touch and the subscription update each
scaled with the square of the node count. A Locator reads each list on
first use and resolves every which of the loop against it; the single
lookups keep LocateServerRaw. Resolving 1000 subscription nodes drops
from 1.1 s to 1.6 ms (BenchmarkLocateAll vs BenchmarkLocatorAll).
The core's StatsService is registered and enabled in the template;
a producer reads the inbound counters every second and publishes
{up, down, upTotal, downTotal} as a traffic frame, which the GUI's
dashboard plots. A GUI that does not know the frame type ignores it.
An outbound group with several members is balanced by the observatory
(least ping). The group's setting now also names one member's share
link as Selected: the core template then keeps only that member, the
touch flags it on the connected entry, and PUT /outboundSelection sets
or clears it. A selection that matches no member is ignored, so a node
removed or renamed by a subscription update returns the group to
balancing instead of breaking it.
PUT /dnsRules regenerates the running core's config and restores the
previous rules when that fails; SetPorts restores the previous ports
when the restart fails. The HTTP latency test drops subscription
entries as intended. The remote GFWList version request has a deadline
and its cache a one-hour TTL. CheckUpdate picks the index of the running
architecture and closes the body on every path.
Running() reads the process under the manager's lock; the early-exit
flag is atomic; a second Close no longer waits on the reaped process; an
empty log chunk no longer panics. The observatory producer rejects tags
it cannot map instead of attributing them to the first node, paces every
path so an unknown tag cannot spin it, closes an unavailable connection
before dropping it and cancels each dial context at once. Balancer
outbounds get their serverInfoMap entry on success, not only on failure.
The resolv hijacker is serialised between the start path and the
connectivity monitor.
The binaries workflow, the PR workflow and build.ps1 no longer pass
-tags tinytun; there is nothing behind the tag. The Windows installer
takes wintun.dll from the official 0.14.1 package, pinned by hash, one
DLL per architecture, and deletes a tinytun.exe an earlier installer left
in the application's bin directory. The README states what the built-in
TUN does and its known limitation on Windows and macOS.
Neither platform has a socket mark, so the physical default route is left
in place and two /1 routes per family are added on the TUN instead; the
core's sockets and the DNS module's upstreams are bound to the physical
interface, which the template reads from the default route before the
TUN routes exist.
Windows points the adapter's DNS at the TUN gateway address with the
lowest interface metric; queries sent there enter the TUN and the core
relays them to the DNS module. macOS needs two things more. A socket
bound to en0 with IP_BOUND_IF looks routes up in en0's scope, and once
the /1 routes exist the only match is theirs, so the lookup fails with
ENETUNREACH: a scoped copy of the physical default route
(route add -ifscope en0 default <gw>) gives bound sockets a way out. And
mDNSResponder scopes its queries to the service's interface, dropping a
reply that arrives through the utun, so the system resolver is pointed at
loopback and the DNS module gets a 127.0.0.1:53 listener in tun mode.
The routes use the gateway form, as xray's own tun does. The kernel
assigns the utun unit and the service finds the device by its address;
the previous resolvers of every network service are kept for stop.
Both were exercised in milestone C: a Windows Server 2025 VM and an
arm64 MacBook. Applications that query a LAN resolver directly still
bypass the TUN on these platforms in this phase; that is documented as a
known limitation.
transparentType=tun no longer starts the TinyTun process. The template
emits a tun-mips inbound tagged transparent — device name, address, MTU,
the DNS module's address as the relay target, the user's exclusion list
plus v2rayA and the core by name and v2rayA by PID — and the service does
what the operating system needs once the core has the device up.
On Linux that is one table and four policy rules: table 2020 holds the
default route into tun0; marked packets (0x80: the core's sockets, the
direct outbound, the DNS module's upstreams) look up main in full and
leave through the physical interface, or fail with ENETUNREACH when main
has no route for their family rather than fall into the TUN; unmarked
packets take main with its default route suppressed, so LAN and static
routes stay physical, and everything else goes to table 2020. The main
table is never edited, so stopping restores egress by itself. A rule in
our preference range or a route in our table that is not ours is reported
and left alone; our own leftovers from a crash are removed first. Every
command that succeeded is recorded and undone in reverse on stop.
Three things the TinyTun path never hit are now on tun's path, so they
are fixed here: the DNS module is generated in tun mode (TinyTun did DNS
itself); its 127.2.0.17:53 listener is only added when port 53 is free,
instead of making the core exit on a host running another resolver; its
primary listener stays on loopback unless port sharing is on or the user
chose an address, and the DNS REDIRECT rules and their cleanup follow the
module's port instead of a hard-coded 52353, and a ::1 listener is added
when IPv6 is supported, because ip6tables REDIRECT delivers an
application's IPv6 query to ::1 which the IPv4 listener never saw. The
tun branch no longer
skips those rules: they are what catches queries to a LAN resolver, which
the routing keeps off the TUN.
The connectivity monitor probes the core's API port; the TinyTun socks
loop-back port it used is gone. Removed with TinyTun: --tinytun-bin, the
tunProcessBackend (eBPF) and tunBypassInterfaces settings (connected and
static routes bypass the TUN unconditionally now), the /networkInterfaces
endpoint that only served the latter, and the build tag. The version
endpoint reports tunSupported instead of tinytunSupported.
Tests cover the generated inbound and DNS module, the listen-address
rules, the redirect port, and — with V2RAYA_CORE_BIN set — that the
generated document loads in the real core. Windows and macOS route
handling follows in a separate commit; until then those builds report
the TUN as unsupported.
Three endpoints answered FAIL for something the caller asked for and got:
- an up-to-date GFWList came back as "could not update GFWList: latest version
is …. GFWList is up to date", because the check returned an error;
- deleting the GFWList when it was already gone returned the raw
"remove …: no such file or directory";
- the update check said "failed to get latest version from Package file: 1".
The up-to-date case is now a sentinel error the controller turns into a
success carrying alreadyUpToDate, deleting what is already gone succeeds, and
the two package-index messages say what was missing. "which can not be nil"
also became a sentence about the request.
A DNS or connection failure produced "Could not download the asset from
api.github.com (HTTP )" in the GUI, because the localized message always
rendered an HTTP status and there was none. Unreachable hosts now use their own
code with the innermost reason, so the user sees the DNS or connection error
instead of an empty pair of brackets.
When the OOM killer takes v2rayA the core survives, is adopted by init and
keeps 20170/20171, so every later start failed with "port is already in use"
until someone killed it by hand (second half of v2rayA/v2rayA discussion
#1932). A process holding one of our ports that runs our core binary and whose
parent is init is ours to clean up.
The version mismatch also said only which two numbers differ, so users who had
installed xray-core concluded v2rayA was broken (#1930, #1903, #1891); it now
says which binary v2rayA needs.
A custom inbound port was open to anyone who could reach it, and older v2rayA
versions did offer authenticated inbounds, so users who relied on them had no
replacement (v2rayA/v2rayA discussions #1894, #1907).
CustomInbound carries optional credentials, which become the inbound's account
list. Half a credential pair is rejected: it would silently leave the port open.
The hijack wrote the file directly, so on any systemd-resolved, resolvconf or
openresolv system it overwrote the resolver's own file through the symlink and
destroyed the link; stopping the proxy then wrote a second hijacked file with
public resolvers rather than restoring anything. The machine was left bypassing
its resolver with no way back short of reinstalling, which is what v2rayA/v2rayA
discussion #1958 and defect B of #1920 describe.
Save the original first — the target when it is a symlink, the content
otherwise — replace the link instead of writing through it, and put the
original back on stop. Closing the hijacker now also waits for a tick that is
already writing, which used to put the hijacked file back after the restore.
Shutdown asks for the teardown twice: pre_run calls CheckAndStopTransparentProxy
and then Stop calls it again through beforeStop. Both ran the user's pre-stop
and post-stop transparent hooks, so a hook that is not idempotent ran twice on
every exit.
Record whether this process installed the rules and make the teardown a no-op
once they are gone. Rules left behind by an earlier process are still removed
by cleanupResidualTransparentProxyRules when the next ones are written.
v2raya_core is started with XRAY_LOCATION_ASSET and looks nowhere else, while
v2rayA only created links in that directory as a side effect of looking a file
up for itself. On a host whose XDG runtime directory is cleared between login
sessions, the core then started with an empty asset directory and failed with
"failed to open geosite.dat" although the files were installed in
/usr/share/v2raya all along; the failure reads like a broken config.
Link the four dat files the core loads by name into that directory before
starting it, taking them from the XDG data directories or the two system
directories a distribution installs into.