45 Commits
Author SHA1 Message Date
Mikhail Levin 9c7b87fba6 feat: expose native group strategies with group-scoped fallback 2026-11-15 23:16:39 +03:00
Markson GuGa BeyondandCopilot 3f39ac1016 chore(core): bump xray-core to v26.10.31
Update the dependency and its transitive modules. Xray moved PacketConnWrapper from transport/internet to common/net, so refresh the references in the TUIC and Juicity outbound comments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-02 10:58:07 +08:00
dependabot[bot] cd5c339e2d chore(deps): bump github.com/klauspost/compress in /core
Bumps [github.com/klauspost/compress](https://github.com/klauspost/compress) from 1.17.4 to 1.18.7.
- [Release notes](https://github.com/klauspost/compress/releases)
- [Commits](https://github.com/klauspost/compress/compare/v1.17.4...v1.18.7)

---
updated-dependencies:
- dependency-name: github.com/klauspost/compress
  dependency-version: 1.18.7
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-10-20 19:44:04 +00:00
ILIKEFUTANARI e010d19a5d feat: add DNS interception opt-out 2026-10-09 17:43:48 +08:00
Markson GuGa Beyond a2f7952a4f fix: juicity and tuic dial, and a QUIC-only node gets a latency
Every core the service starts has outbound traffic counters on, and with them on
xray wraps the underlay connection of a native QUIC outbound in a
*stat.CounterConnection. That wrapper embeds net.Conn alone, so ReadFrom and
WriteTo are hidden and hint/proxy/juicity and hint/proxy/tuic failed their
net.PacketConn assertion before a single QUIC packet left: the node imported, and
then every connection through it died on the spot. Unwrap the stats connection
before the assertion.

A QUIC server listens on UDP only, so the TCP dial the ping made to its port said
nothing and every juicity, tuic and hysteria2 node read TIMEOUT. Keep the TCP
attempt, and when it fails ask the same port over UDP with a QUIC long header
carrying a reserved greased version: a QUIC server answers that with a Version
Negotiation packet (RFC 9000 section 6), and the round trip of that answer is the
latency. A node that answers neither probe is still TIMEOUT; the troubleshooting
pages in the six locales describe that.
2026-09-29 18:54:02 +08:00
Zakk 304594eef9 fix: what a read of main since 2.5.5 turned up
- A page's late /touch response no longer writes the store after the page is
  gone: useNodes marks itself disposed with its scope and apply() drops the
  result, so leaving Subscriptions for Proxies while a request is in flight
  cannot hand a batch action a stale member list.
- The dashboard's subscription card links go to the Subscriptions page, not
  Proxies, which no longer lists subscriptions.
- Page shortcuts stay quiet while a menu is open (Escape dismissed the batch
  menu and cleared the selection in one stroke) and treat checkboxes as
  buttons, not text entry; the node checkboxes drop a keydown.stop that only
  served the row activation that is gone.
- Submissions in flight are not started twice from the new Enter shortcuts:
  GFWList update, subscription save, excluded domains, whitelist IPs.
- Choosing Documentation in the phone's app bar menu closes the menu.
- The Clash importer no longer writes allow_insecure into anytls and tuic
  links (nothing reads it since 1c392550); the core's example configs drop the
  stale key.
2026-09-22 14:58:28 +10:00
Zakk 1c39255010 fix: TUIC, Juicity and AnyTLS no longer skip certificate verification
v2rayA dropped allowInsecure years ago: VMess, VLESS and Trojan links carrying it
are parsed and the flag ignored, and a self-signed server is reached by pinning
its certificate. The three native protocols added in May brought the switch back
in their own config, service objects and forms. It goes everywhere: the core's
dialers verify or pin (the proto field 5 is reserved), the service no longer
parses, stores or exports allow_insecure for them, the forms lose the switch,
the codec ignores the parameter, and the quick-start docs say so in six locales.
Certificate pinning stays as it was.
2026-09-22 02:40:22 +10:00
Markson GuGa Beyond 412f7fca71 core: remove outdate license informations 2026-09-21 22:16:56 +08:00
Zakk c14e68e7b4 fix(core): register the tuic outbound in distro/all like anytls and juicity 2026-09-21 12:44:14 +10:00
Markson Hon 900e7e26b6 Merge pull request #2018 from Zakkaus/dns-upstream-scheme
feat(dns): DNS over HTTPS upstreams, direct and through the proxy; DoT keeps its server name; DoQ refused on save
2026-09-20 19:58:24 +08:00
Zakk cc60098633 feat(dns): DNS over HTTPS upstreams, direct and through the proxy; DNS over TLS keeps its server name
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.
2026-09-20 18:53:48 +10:00
Zakk 833af7dc74 refactor: use what the dependencies already provide
A read of the tree for home-grown code that a dependency or the platform
covers. Each item names what replaces it.

- IPv4 CIDR membership was a binary-string trie (infra/dataStructure/trie)
  fed with CIDRs rendered as bit strings; net.IPNet.Contains, which the
  same file already used for IPv6, does it. The trie package is gone.
- The response replay cache was an LRU with its own linked list, indexes
  and timeout strategy (infra/dataStructure/lru), of which one fixed-size
  instance existed; hashicorp/golang-lru/v2, already in go.mod, is that
  cache, typed. go mod tidy also dropped go-nanoid, which nothing imported.
- The HTTP client for subscription updates through the local proxy carried
  a CONNECT dialer of its own (pkg/util/proxyWithHttp); http.Transport's
  Proxy handles socks5:// and http:// URLs, resolves hostnames on the
  SOCKS proxy and uses CONNECT for https. Verified on the VM: a
  subscription update succeeds in both "pac" and "proxy" modes.
- core/dns/qtype.go listed nine type names in two switches before falling
  back to miekg/dns tables that contain the same names; dns.Type.String
  and dns.StringToType are the tables.
- The GUI tracked prefers-color-scheme with its own media query and
  toggled a theme-dark class nothing reads any more; Vuetify's "system"
  theme follows the OS itself. Verified in headless Chrome: auto follows
  the OS in both directions, an explicit choice overrides it.
- The AUR packages carried .INSTALL hooks whose only content was a
  coloured "Completed!" banner, duplicated in the deb/rpm after-install
  scripts; pacman and apt report that themselves. The hooks are gone, the
  release workflow stops copying them, and after_install/after_upgrade
  keep only daemon-reload and the restart.
- The tap release job downloaded eight artifacts in eight steps;
  actions/download-artifact takes a pattern with merge-multiple.
2026-09-20 16:40:34 +10:00
Zakk ad509ce51b fix(service): the confirmed findings of four independent backend scans
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.
2026-09-20 09:59:29 +10:00
Zakk ae8e5a5047 chore: drop what nothing reaches
Three service packages outside the executable's dependency graph
(common/antiPollution, pkg/util/gopeed, kernel/vmessInfo), a blank
import of miekg/dns the core already imports, the --core-type flag no
code read, the PutAccount handler whose route was commented out, two GUI
API wrappers without a caller, two .SRCINFO files the release regenerates
and an unreferenced runit sample. The workflow path filters watched a
root go.mod that does not exist and the PR build skipped core/.
2026-09-20 09:17:11 +10:00
Markson GuGa Beyond 1da93f75a9 fix(core): re-add missing xray core version number 2026-09-19 19:59:27 +08:00
Zakk 88841d7d9d fix(core): DNS module answers match the client's EDNS
The module asked every upstream with DNSSEC OK and handed the upstream's
additional section back untouched, so a client got an OPT record it never
sent — carrying the module's loop token and the DO flag — and RRSIG
records it did not ask for. macOS's resolver treats such an answer as
invalid and waits out its 30-second timeout on every uncached name, which
made the tun mode's loopback resolver unusable there. Upstream queries no
longer set DO (the module validates nothing), and the response is
rewritten to the client's EDNS: no OPT when the client sent none, a fresh
OPT with the client's UDP size and DO bit when it did, and RRSIGs only for
a DO client.
2026-09-19 10:34:55 +10:00
Zakk a6c2d5f1d2 feat(core): bind the DNS module's own sockets to an egress interface
On Linux the module's upstream, bootstrap and health-check sockets carry
SO_MARK 0x80, which the transparent-proxy rules exempt. Windows and macOS
have no mark: once a TUN holds the default route, those sockets would send
the module's own queries into the TUN, where the core's port-53
interception hands them straight back to the module. The module config
gains egress_interface; when set, every dialer created by
newMarkedDnsClient binds to it with IP_UNICAST_IF / IPV6_UNICAST_IF on
Windows and IP_BOUND_IF / IPV6_BOUND_IF on macOS. Unset, the dialers are
unchanged, and Linux keeps the mark.

The darwin and windows tests dial through the dialer and read the option
back; they run on those platforms. The interface lookup itself is tested
everywhere.
2026-09-19 10:34:55 +10:00
Zakk fa051aa35f feat(core): register the tun-mips inbound and load it from JSON
The inbound is registered like xray's tun: it declares no listening
network, opens its device in Start, and tears the stack down in Close. Its
settings object is validated on load — name, mtu, address4 and dnsTarget
are required, address6, excludeProcesses, selfPids and directTag are
optional — so a field the service forgot fails the configuration instead
of becoming a zero value at runtime.

The JSON loader gains an inbound side. It is a separate protocol set from
the outbound one, and a protocol used in the wrong direction is an error
rather than being stripped and then silently skipped. The three production
entry points (file builder, cmdarg loader, reader loader) now share one
strip and one append step, so an inbound cannot be handled on one path
and forgotten on another. The receiver settings carry the sniffing block,
which is what the proxyman builds the sniffing context from.

Tests load the document the service will generate through both the file
and the reader path and check tag, sniffing, every settings field, no
listening port, and that the native socks inbound beside it is untouched;
they reject tun-mips as an outbound and anytls as an inbound, fail a
document missing dnsTarget, and confirm a document without custom
protocols is returned byte-identical.
2026-09-19 10:34:55 +10:00
Zakk 834d8dd340 feat(core): tunmips process exclusion by socket owner
A flow's owner is looked up once per TCP connection or UDP session from
the application's local address and port: sock_diag plus a /proc fd scan
on Linux, the iphlpapi owner-PID tables on Windows, the pcblist sysctl on
macOS. A wildcard-bound UDP socket is matched by port when no exact match
exists. When any owner is the core or v2rayA itself (by PID, so a renamed
binary still counts) or is on the user's list (by executable basename,
case-folded and without ".exe" on Windows), the session is dispatched with
a forced outbound tag so the router is skipped and the direct outbound —
which already carries the self-exclusion mark — takes it.

An owner that cannot be determined, because the lookup failed or the
socket is already gone, leaves the flow on its normal route: proxying a
packet that should have gone direct is the safer mistake, and this is the
same boundary TinyTun's /proc backend had. The Windows and macOS lookups
compile but are verified on those machines, not here.
2026-09-19 10:34:55 +10:00
Zakk 247531c81c feat(core): tunmips answers port-53 flows through the DNS module
A query the application sends to any resolver that is not an address of
this host — a public one, the TUN gateway address the system resolver is
pointed at on Windows and macOS — is relayed to the core's DNS module
instead of being routed. UDP sessions are per four-tuple and replies are
sourced from the resolver the application queried; TCP streams are relayed
both ways. Queries to loopback or to one of the host's own addresses are
left to ordinary routing: they never enter the TUN in the first place, and
the module's own listener on 127.2.0.17 is one of them.

The relay target is the module's listen address; it is not yet wired to
configuration, which the inbound registration commit does.
2026-09-19 10:34:55 +10:00
Zakk b4472b0e33 feat(core): tunmips forwarder hands TCP and UDP flows to the dispatcher
Each accepted TCP connection becomes one DispatchLink with the same session
context xray's tun inbound builds (inbound tag, sniffing request, user
level, access log), so routing rules, geosite and sniffing treat TUN
traffic exactly like the socks inbound did.

UDP is keyed by the application's source address only: datagrams from one
socket to any number of remotes share one dispatcher session, every buffer
read by the outbound carries its own destination in buf.Buffer.UDP, and
every buffer the outbound writes back carries the remote it came from,
which the stack uses as the source address of the datagram it sends to the
application. That is the full-cone behaviour TinyTun's socks loop could
not offer. The datagram is enqueued under the session lock because the
session is closed under the same lock when the outbound finishes.

Tests use a fake dispatcher: one TCP flow yields one DispatchLink with the
right destination and inbound tag and bytes flow both ways; two UDP
destinations from one source yield one session whose buffers carry each
destination, a packet from a third remote is written back with that
remote as its source, and the session is recreated after the outbound
finishes.
2026-09-19 10:34:55 +10:00
Zakk aaf18bd645 feat(core): tunmips device and stack skeleton for the in-core TUN
The TUN inbound that replaces the external TinyTun process needs a device
and an IP stack before it can hand anything to the dispatcher. This adds
both behind a stack-independent contract (Handlers: one TCP callback per
accepted connection, one UDP callback per datagram with a reply function
that chooses its own source address) so the stack can be swapped without
touching the forwarding code that follows.

The stack is mipstack in transparent mode: it owns no address, admits every
unicast packet the device delivers and answers from whatever address the
application dialed. The interface address belongs to the operating-system
side of the link and is deliberately not registered with the stack —
mipstack routes packets to its own addresses into an internal loopback, so
replies would never reach the device. The core configures that address on
the interface itself (netlink on Linux, winipcfg on Windows, SIOCAIFADDR on
macOS); other platforms compile but report ErrUnsupportedPlatform.

Tests drive the stack through wireguard's channel device: a SYN gets a
SYN-ACK back and, once the handshake completes, the TCP handler runs with
the right flow; a UDP datagram reaches the handler and a reply from a third
address leaves the device with that address as its source, which is what
full-cone NAT needs later. Both run for IPv4 and IPv6.
2026-09-19 10:34:55 +10:00
Markson GuGa Beyond 447e43cf07 fix(dir): remove old core/xray submodule dir 2026-09-19 07:07:24 +08:00
Markson GuGa Beyond cffe97ca3d core: migrate xray-core from git submodule to go mod and port QUIC outbounds to daeuniverse/outbound
The vendored core/xray submodule is dropped. xray-core is now pinned via a
go mod pseudo-version resolving to v26.7.28 (commit 5ca6f4b7); v26 tags are
not directly resolvable because Xray's module path lacks the /v26 suffix, so
the pin must be made by commit hash. CI workflows and the AUR PKGBUILD no
longer need "submodules: recursive" / "git submodule update".

The juicity and tuic outbounds are ported from softwind to
github.com/daeuniverse/outbound (temporarily replaced with an olicesx fork
pending sticky-ip support):

- Dialer calls use DialContext; the network string is decoded with
  netproxy.ParseMagicNetwork instead of a "udp" prefix check, since it may
  be binary-encoded via netproxy.MagicNetwork.
- A packetConnAdapter wraps xray's UDP dial result: outbound asserts the
  underlay conn to netproxy.PacketConn whose ReadFrom/WriteTo signatures
  (netip.AddrPort / string) differ from net.PacketConn, while xray returns
  *internet.PacketConnWrapper.
2026-09-18 13:15:45 +08:00
dependabot[bot] 252cde9694 build(deps): bump google.golang.org/grpc from 1.82.1 to 1.83.2 in /core
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.82.1 to 1.83.2.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.82.1...v1.83.2)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-version: 1.83.2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-09-17 23:20:56 +00:00
Zakk b2f2aff8d6 fix(dns): refuse a query that has looped back through an upstream
A rule that sends a name to a local resolver which forwards back to v2rayA
makes the two exchange the same query until one of them runs out of memory;
v2rayA/v2rayA discussion #1950 reproduces it with dnsmasq on OpenWrt. The
firewall-level self-redirect is already handled by the 0x80 mark, but nothing
saw the loop at the resolver level.

Every query this process sends upstream carries a random per-process token in
an EDNS0 local option. A query that arrives carrying that token has come back
around such a loop and is answered with SERVFAIL, with one log line per ten
seconds naming the question and how many were refused.
2026-09-18 06:30:12 +10:00
Zakk 9cdc300d0e fix(core/dns): query_type decoding, ECS scope, cache TTLs, bind errors, and SO_MARK for native outbounds
RuleConfig.QueryType had no string decoder while the service writes
query_type as "A"/"AAAA", so any DNS rule with a query type made the core
exit at startup; accept names and numbers. ECS was gated on
IsGlobalUnicast, which is true for RFC 1918 and ULA, so LAN clients'
private prefixes were still sent upstream; also require a non-private,
non-loopback, non-link-local address. Cache hits returned the stored
message with its original TTLs; subtract the elapsed time, floored at
min_ttl, on a copy. The listener logged bind failures inside the serve
goroutines and Start returned nil; bind synchronously so the error is
reported. DNS-over-TCP read the length prefix with a single Read; use
io.ReadFull. CacheConfig.NegativeCache was never read; negative answers
are no longer cached when it is off.

The native anytls, juicity and tuic outbounds were rebuilt with an empty
SenderConfig and dialed with their own dialers, so streamSettings.sockopt
(the 0x80 loop-protection mark) never reached their server connections
and transparent-proxy mode re-captured them. Carry the original
streamSettings into the rebuilt sender settings and dial through the
xray dialer that applies them.
2026-09-18 02:49:39 +10:00
xuweizhi e6ab3f92eb fix(core/dns): only attach ECS for global unicast client addresses
RFC 7871 requires that non-globally-routable client addresses are not
sent as EDNS Client Subnet. Sending ECS with loopback/private addresses
(e.g. 127.0.0.1 from the local listeners) breaks split-horizon zones:
AliDNS returned only the CNAME without the target A record for such
queries, so Cloudflare-fronted proxy servers could never be resolved.
2026-08-26 19:39:27 +08:00
zhangthree78 daa5d69261 fix(dns): make marked-client Control assertions platform-specific
Review (goal verification) found that socket_test.go asserted
Dialer.Control != nil without build tags, so 'go test ./core/dns/'
fails on Windows where markedDialer() deliberately omits Control
(SO_MARK is a Linux-only option; markFd is a no-op there).

Move the Control assertions to socket_unix_test.go (//go:build !windows);
socket_test.go keeps the platform-neutral assertions (Net/UDPSize/timeouts/
Dialer non-nil). Verified: Linux go build + go test all pass, and
GOOS=windows go vet compiles the test files cleanly.
2026-08-17 01:01:15 +08:00
zhangthree78 734792cfc2 fix: complete per-query log gating, clean residual DNS rules on stop, dedupe marked client
Follow-up review of 525654e found:

1. Log gating was incomplete: only the direct/route path was gated;
   cache-hit/cache-miss, proxy and dispatcher per-query logs were still
   unconditional log.Printf (the hottest paths under load). Gate them
   behind V2RAYA_DNS_DEBUG=1 too; error logs stay visible.

2. Stopping the transparent proxy left the direct nat OUTPUT/PREROUTING
   REDIRECT --to-port 52353 rules and the fwmark 0x80 exemption rules in
   place (Tproxy/Redirect GetCleanCommands only clean their own chains).
   Once the DNS module exits, local DNS queries hit a dead port and DNS
   fails. Add cleanDnsRedirectRules() and run it on the normal stop path.

3. module.go bootstrap client inlined its own markFd + marked dialer;
   reuse newMarkedDnsClient (keeping the 3s fail-fast timeout).

4. dnsLogf/dnsDebugEnabled were duplicated in socket_unix.go /
   socket_windows.go; move them to a common debug.go.

5. No unit tests for newMarkedDnsClient; add tests asserting
   Net/UDPSize/Timeout and a non-nil Dialer.Control.

Verified: go build ./dns/... ./kernel/v2ray/... ; go test ./dns/...
2026-08-17 00:49:48 +08:00
zhangthree78 525654ec9b fix: prevent DNS redirect loop causing unbounded memory growth
Fixes defects in the v2.4.8+ transparent-proxy DNS path that cause the
core to exhaust memory within seconds on low-RAM hosts (see discussion
#1915: '2.4.9 内存占用过高' / '有严重的内存泄漏,别用了。本地DNS完全废掉了'):

1. core/dns: upstream queries from NewUpstreamManager /
   GetOrCreateUpstream / getClientForProtocol used bare &dns.Client{}
   with no Dialer configured, so their sockets never carried
   SO_MARK=0x80. The unmarked queries were hijacked by the module's own
   transparent-proxy DNS redirect rules and looped back into :52353 —
   an infinite self-query loop and memory snowball.

2. service/kernel/v2ray/transparent.go: the unconditional DNS hijack
   rules (REDIRECT --to-port 52353) had no fwmark-0x80 exemption, and
   being inserted with -I they sat at the head of nat OUTPUT/PREROUTING,
   so marked traffic was looped back as well.

3. core/dns: per-query info logging (query/route/upstream) produced
   thousands of lines/second under load, amplifying CPU/IO/memory
   pressure.

Fix:
- Route every upstream client through newMarkedDnsClient, whose
  net.Dialer sets SO_MARK=0x80 on all sockets. miekg/dns dials UDP
  through net.Dialer too, so Dialer.Control covers UDP sockets — no
  manual socket path is needed. UDPSize=4096 keeps a sane receive
  buffer for queries without an EDNS0 OPT record.
- Append the DNS redirects with -A and insert the mark exemption with
  -I so the exemption is matched first; also delete the exemption
  rules in the residual-rule cleanup so they don't accumulate across
  restarts.
- redirect mode: insert the DNS_REDIRECT jumps after the TP_PRE/TP_OUT
  jumps so they actually take precedence (-I inserts at chain head),
  keeping local and LAN TCP DNS flowing to the DNS module (:52353)
  instead of the proxy inbound (:52345).
- Gate per-query info logs behind V2RAYA_DNS_DEBUG=1; error logs stay
  always visible.

Verified: unpatched v2.4.11 core RSS 230MB->1GB in ~6s then OOM/hang;
patched build stable at ~25MB idle / ~243MB loaded, DNS and SOCKS proxy
working.
2026-08-16 23:59:43 +08:00
Markson Pigeonzilla Plus 3d86c775a5 feat: add shared cert-chain pinning helpers for native protocols 2026-08-11 21:59:36 +08:00
Markson Pigeonzilla Plus 0bdd83345d chore: bump xray-core and core module dependencies 2026-08-11 21:59:34 +08:00
Markson Pigeonzilla Plus 06273efcc1 fix: cert chain sha256 not applied of juicity 2026-08-11 20:26:49 +08:00
Markson GuGa Beyond 1b94f178d9 fix: hysteria2 should not be plugin-based 2026-08-09 13:15:38 +08:00
Markson Joe Hon 62edf08c24 fix(core/dns): increase UDP receive buffer from 512 to 65535
exchangeUDPWithMark used dns.DefaultMsgSize (512 bytes) as the UDP
receive buffer. The query sets EDNS0 UDP size 4096, so the upstream
may respond with up to 4096 bytes. With a 512-byte buffer, UDP
datagram data beyond 512 bytes is silently discarded (UDP datagram
property), causing truncated/corrupted DNS responses.

Fix: use dns.MaxMsgSize (65535) as the receive buffer, matching the
maximum possible UDP datagram size. This ensures large DNS responses
(common with DNSSEC or many A/AAAA records) are fully received.
2026-07-22 14:05:32 +08:00
Markson Joe Hon 9fcbd6a5db fix(core/dns): fix DNS split routing, bootstrap loop, and response corruption
## Issue 1: DNS rule matching logic (MatchAll + OrMatcher)

BuildMatchers flattened all geosite-expanded domains into a single list,
and the old MatchAny used AND logic (all matchers must match). This
made geosite:cn rules impossible to hit (e.g. qq.com and baidu.com
can never match simultaneously).

Fix: introduce OrMatcher to group matchers from the same rule field
with OR semantics, while different field groups use AND. The thousands
of domains from geosite:cn expansion are wrapped in a single OrMatcher
so matching any one domain satisfies the rule.

## Issue 2: Bootstrap self-reference loop (SO_MARK + public DNS fallback)

Bootstrap resolution runs before the DNS listener starts, but iptables
already hijacks :53 traffic:
- bootstrap query to system DNS(:53) → iptables redirects to 127.2.0.17:53
- DNS module not yet listening → connection refused → bootstrap fails
- Domain upstreams (e.g. dns.google) remain unresolved → relies on proxy
- Proxy DNS may re-enter DNS module → loop or REFUSED

Fix:
1. Add SO_MARK=0x80 to bootstrap DNS client to bypass iptables redirect
2. collectBootstrapDns() with 3-tier priority (config > system > hardcoded)
3. Hardcoded fallback includes Alibaba/Tencent/Google/Cloudflare: 13 servers
4. isOwnAddress() filters self-referencing addresses (127.0.0.1:53 etc.)

## Issue 3: handlePacket mutates cached response in-place

m = resp.RawMsg; m.SetReply(msg) directly modifies the *dns.Msg shared
with the cache, corrupting subsequent cache hits. SetReply also forces
Rcode=RcodeSuccess, overwriting NXDOMAIN etc. from upstream.

Fix: Pack/Unpack deep copy before modification; preserve original Rcode.

## Issue 4: Double OPT record causes FORMERR

Three exchange functions called AddECSSubnet BEFORE SetEdns0.
miekg/dns v1.1.72's SetEdns0 always appends a new OPT record without
checking for existing ones, producing a malformed query with two OPT
records.

Fix: call SetEdns0 before AddECSSubnet; use UDP size 4096 in
AddECSSubnet instead of 512 to preserve the size set by SetEdns0.

## Issue 5: localhost upstream skipped in template (template_dns.go)

localhost upstream was continue-skipped during config generation,
making the geosite:private rule reference a non-existent upstream.

Fix: map localhost to 127.0.0.1, keep it as a valid upstream.

## Incidental fixes

- handler.go: remove duplicate :53 in log format (dns.google:53:53)
- response.go: use 4096 instead of dns.DefaultMsgSize(512) for ECS
2026-07-22 14:01:39 +08:00
Markson Pigeonzilla Plus 2069b477d4 fix(windows): fix syscall.SetsockoptInt type mismatch on Windows
syscall.SetsockoptInt takes int (Linux) vs syscall.Handle (Windows)
as its first argument. The existing code used int(fd) which fails on
Windows where fd is uintptr and syscall.Handle = uintptr.

Fix: extract a platform-specific setSocketMark(fd uintptr) helper:
  - socket_unix.go (!windows) : calls SetsockoptInt(int(fd), ...)
  - socket_windows.go (windows): no-op (SO_MARK is Linux-only)
2026-07-02 21:32:37 +08:00
Markson Joe Hon eef675f5f9 fix: persist kernel exit status across restarts and fix geosite DNS resolution
core: fix geosite.dat parsing in DNS resolver
- Replace broken GeoSiteList unmarshal with correct varint-length-delimited
  stream parser matching xray-core's format
- Add result caching to avoid re-reading the file per tag expansion

service: persist kernel exit status for proper state restoration
- Add LastKernelExitStatus (running/stopped/crashed) to DB
- Set 'running' on graceful shutdown while kernel is active so it
  is automatically restored on next startup
- Set 'stopped' when user explicitly stops the kernel via API
- Set 'crashed' when the kernel exits unexpectedly
- Check saved status at startup and log appropriate messages
- Expose lastKernelExit field via GET /api/version for the frontend
2026-07-02 13:51:44 +08:00
Markson Joe Hon 47f1462baf feat: init a new for v2raya core and fix a firewall mistake 2026-07-02 13:10:12 +08:00
Markson Hon cfe5a69049 chore: update xray submodule to v26.6.1 and replace allowInsecure with cert pinning
- Update core/xray submodule from v1.260327.0 (v26.3.27) to v26.6.1
- Remove deprecated AllowInsecure field from all protocol structs
- Add PinnedPeerCertSha256 and VerifyPeerCertByName fields (service layer)
- Update ngui (Nuxt) frontend with text inputs for new fields
- Update gui (Vue 2) frontend with text inputs for new fields
- Keep existing PinnedSHA256 for juicity (no duplicate)
- Backward compatible: old allowInsecure params silently ignored
- Run go mod tidy to update dependencies
2026-06-20 22:51:17 +08:00
Markson Hon baf3db6039 feat(tuic): add native TUIC outbound support 2026-05-11 23:38:32 +08:00
Markson Hon c017127867 chore: update xray-core to v26.3.27 and sync dependencies
- Xray-core submodule already pointed to v26.3.27 (d2758a02)
- Synchronized go.mod/go.sum dependencies via go mod tidy
- No code changes required: v26.3.23→v26.3.27 has no breaking changes
  for Reality protocol
- RealitySettings JSON tags remain fully compatible with Xray-core
  v26.3.27 REALITYConfig
2026-05-05 08:51:07 +08:00
Markson Hon 0baefc4530 feat(core): mix-up v2ray and xray and anytls and juicity 2026-05-03 15:55:13 +08:00
Markson Hon 56c1f8fbfd try to mix cores 2026-05-02 11:58:21 +08:00