Feature/loopback proxy rematch rules#2862
Open
Medium1992 wants to merge 9 commits into
Open
Conversation
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new outbound type:
loopback.The design is conceptually similar to Xray's outbound loopback routing, allowing a connection to re-enter the routing engine instead of immediately establishing an outbound connection.
The implementation was developed with the help of Codex based on the routing behavior described in the issue and refined through local testing.
The primary goal is to reduce proxy group complexity while preserving routing flexibility.
Without loopback, users often need large proxy groups containing many routing-specific choices. With loopback, a user can expose only a small number of high-level selections while still applying arbitrary routing logic afterwards. This makes it possible to build a single convenient proxy group with minimal UI buttons while retaining full rule-based routing capabilities.
loopbackis a virtual outbound that does not establish a network connection. Instead, when selected, it sends the connection back for another rule matching pass.During rematching, it can optionally:
IN-NAME;sub-ruleset.As a result, selecting an item inside a proxy group no longer has to determine the final outbound. It can instead switch routing context and let rules decide the final path.
Motivation
Currently, when traffic is routed to a proxy group and the user selects an item inside that group, the selected proxy becomes the final outbound.
This limits the ability to create compact user-facing proxy groups while keeping sophisticated routing policies underneath.
loopbackallows a proxy group selection to act as a routing context switch rather than a final outbound, enabling:Example
Flow:
mixed-in.GLOBAL.LB.LBrematches the connection withIN-NAME=LB_TEST.Configuration
in-nameOverrides
metadata.InNamebefore rematching.sub-ruleUses the specified sub-rule set for the second routing pass.
in-name+sub-ruleBoth options can be used together.
Validation
A loopback outbound must define at least one of:
in-namesub-ruleOtherwise it is considered invalid.
If a referenced
sub-ruledoes not exist:in-nameis present, the configuration falls back to the main rule set and logs a warning;in-nameis absent, the loopback outbound is disabled and logs an error.Loop Protection
Only one loopback rematch is allowed per connection.
If rematching selects another loopback outbound, the connection is rejected and a warning is logged, preventing infinite routing loops.
Health Check
loopbacksupports health checks andurl-testby applying the same rematching logic before establishing the actual outbound connection.Connection Chain
The loopback step is appended to the connection chain, allowing UIs to display the complete routing path.