Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/dispatcher/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/log"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol"
Expand Down Expand Up @@ -421,7 +421,11 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
outTag := route.GetOutboundTag()
if h := d.ohm.GetHandler(outTag); h != nil {
isPickRoute = 2
errors.LogInfo(ctx, "taking detour [", outTag, "] for [", destination, "]")
if route.GetRuleTag() == "" {
errors.LogInfo(ctx, "taking detour [", outTag, "] for [", destination, "]")
} else {
errors.LogInfo(ctx, "Hit route rule: [", route.GetRuleTag(), "] so taking detour [", outTag, "] for [", destination, "]")
}
handler = h
} else {
errors.LogWarning(ctx, "non existing outTag: ", outTag)
Expand Down
4 changes: 4 additions & 0 deletions app/router/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (c routingContext) GetTargetPort() net.Port {
return net.Port(c.RoutingContext.GetTargetPort())
}

func (c routingContext) GetRuleTag() string {
return ""
}

// GetSkipDNSResolve is a mock implementation here to match the interface,
// SkipDNSResolve is set from dns module, no use if coming from a protobuf object?
// TODO: please confirm @Vigilans
Expand Down
7 changes: 6 additions & 1 deletion app/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Route struct {
routing.Context
outboundGroupTags []string
outboundTag string
ruleTag string
}

// Init initializes the Router.
Expand Down Expand Up @@ -89,7 +90,7 @@ func (r *Router) PickRoute(ctx routing.Context) (routing.Route, error) {
if err != nil {
return nil, err
}
return &Route{Context: ctx, outboundTag: tag}, nil
return &Route{Context: ctx, outboundTag: tag, ruleTag: rule.RuleTag}, nil
}

// AddRule implements routing.Router.
Expand Down Expand Up @@ -239,6 +240,10 @@ func (r *Route) GetOutboundTag() string {
return r.outboundTag
}

func (r *Route) GetRuleTag() string {
return r.ruleTag
}

func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
r := new(Router)
Expand Down
3 changes: 3 additions & 0 deletions features/routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Route interface {

// GetOutboundTag returns the tag of the outbound the connection was dispatched to.
GetOutboundTag() string

// GetRuleTag returns the matching rule tag for debugging if exists
GetRuleTag() string
}

// RouterType return the type of Router interface. Can be used to implement common.HasType.
Expand Down