Optimization: Prevent redundant process search for non-local inbound traffic in Route Rules
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 38.1k
- Forks
- 4.6k
- Avg merge
- 19d 15h
- Merged PRs (30d)
- 1
Description
1. Description
Currently, when a process_name or process_path rule exists in route.rules, sing-box appears to trigger a system process search (PID lookup) for every incoming packet, even if the packet originates from an external LAN device (e.g., via TUN inbound) that cannot possibly have a local PID.
This results in:
1.Log Spam: Constant INFO router: failed to search process: process not found messages.
2.Performance Overhead: Unnecessary syscalls/kernel lookups for every forwarded packet from LAN clients.
2. Actual Behavior (Log)
INFO [tun-in]: inbound packet connection from 192.168.102.188:57805
router: failed to search process: process not found
Even when using logical and with source_ip filtering, the process search seems to be pre-fetched or executed regardless of the previous match results.
3. Expected Behavior / Suggestion
Implement Short-circuit Evaluation for metadata fetching in the routing engine.
If a rule is structured like this:
JSON
{
"type": "logical", "mode": "and",
"rules": [
{ "source_ip": ["127.0.0.1"] },
{ "process_name": ["AdGuardHome"] }
]
}
sing-box should only attempt to search for the process AFTER the source_ip condition is met. If the first condition fails, the process lookup should be skipped entirely.
4. Refined Logic Suggestion:
The routing engine should inherently distinguish between locally-initiated requests and forwarded/inbound traffic before executing a process_name lookup. Since connections originating from external clients (e.g., LAN devices via TUN) will never have a corresponding local process name, attempting a lookup is a deterministic failure.
I suggest that process_name matching should only be triggered if the connection's source metadata satisfies the conditions for a local process (e.g., matching loopback interfaces or specific local source IPs). By skipping the process search for all non-local traffic, sing-box can avoid redundant syscalls and keep the logs clean from "process not found" noise in transparent proxy environments.
5. Environment
Version: 1.13.5
Platform: Linux (OpenWrt)
Mode: TUN with auto_route strict_route auto_redirect
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing route.rules evaluation in the routing engine, focusing on logical and rules that combine source_ip with process_name metadata. Reproduce the TUN inbound case on Linux and inspect when process lookup occurs; done means failed source conditions avoid the lookup and external traffic no longer produces process-not-found log messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100