chore: add procfs fallback for android findProcess#2639
Conversation
|
Thank you for your contribution; we believe adding procfs fallback is very meaningful. However, there's a small question: is it really necessary to add a From your description, |
|
@wwqgtxx yes, it is necessary. Actually you can add procfs fallback as default behaviour for app UID detection without adding new config |
|
To simplify future maintenance, I think we don't need to add a new configuration item; simply adding fallback paths to the existing code will suffice. Furthermore, these fallbacks should only work on GOOS==android to avoid affecting results on other platforms. |
|
Yeah, fallback behaviour would be enough as for me |
ea38bc1 to
617b998
Compare
617b998 to
bd22ecd
Compare
Summary
find-process-backend(auto|netlink|procfs) to control how the local socket owner is resolved for process-based rules./proc/net/tcp,tcp6,udp,udp6, matches primarily by local port when TUN metadata source IP does not match the kernel row (e.g. fake-ip / gateway IP).inode == 0rows for port-only matches to avoid TIME_WAIT false positives./proc/<pid>/fdresolution fails but UID is known, fall back to resolving the process/package name by UID (typical on Android where all app processes share one UID).Problem
On Android 16, users running Mihomo under root (e.g. KernelSU Next, SUSFS, TUN + redirect) observed unstable process identification:
NLMSG_ERROR) or UID 0 with no process name, whilessstill shows the correct UID/PID.198.18.0.1) that does not appear aslocal_addressin/proc/net/tcpfor the real app socket, so naive IP+port matching fails.Repro / validation environment (reported): OnePlus 15, Android 16, KernelSU Next + SUSFS, Mihomo in any mode with process-based rules.
Solution
find-process-backendin general config (same level asfind-process-mode, not undertun:).auto(default): try netlink first; on error or UID 0, retry via procfs.procfs: use/proc/net/*only (bypass netlink).netlink: preserve previous behavior (netlink only)./procfor that UID (Android package/cmdline).Changes
component/process/find_process_backend.go—FindProcessBackendtype, defaults,Get/Set, text unmarshaling.component/process/process_linux_procfs.go— parse/proc/net/tcp*/udp*, port-first + exact IP when possible, skipinode=0for port-only rows.component/process/process_linux.go— backend switch, netlink → procfs fallback,resolveProcessNameByUID.config/config.go—find-process-backendonGeneral/RawConfig, defaultauto, wire into parsed general.hub/executor/executor.go— apply backend on config load /GetGeneral.hub/route/configs.go— REST PATCH support forfind-process-backend.Usage
Testing