mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-11 01:23:01 +00:00
Log: show the matching rule tag (#3809)
This commit is contained in:
parent
88ae774cce
commit
7970f240de
@ -10,8 +10,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"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/buf"
|
||||||
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/log"
|
"github.com/xtls/xray-core/common/log"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
@ -421,7 +421,11 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
|
|||||||
outTag := route.GetOutboundTag()
|
outTag := route.GetOutboundTag()
|
||||||
if h := d.ohm.GetHandler(outTag); h != nil {
|
if h := d.ohm.GetHandler(outTag); h != nil {
|
||||||
isPickRoute = 2
|
isPickRoute = 2
|
||||||
|
if route.GetRuleTag() == "" {
|
||||||
errors.LogInfo(ctx, "taking detour [", outTag, "] for [", destination, "]")
|
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
|
handler = h
|
||||||
} else {
|
} else {
|
||||||
errors.LogWarning(ctx, "non existing outTag: ", outTag)
|
errors.LogWarning(ctx, "non existing outTag: ", outTag)
|
||||||
|
@ -28,6 +28,10 @@ func (c routingContext) GetTargetPort() net.Port {
|
|||||||
return net.Port(c.RoutingContext.GetTargetPort())
|
return net.Port(c.RoutingContext.GetTargetPort())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c routingContext) GetRuleTag() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// GetSkipDNSResolve is a mock implementation here to match the interface,
|
// GetSkipDNSResolve is a mock implementation here to match the interface,
|
||||||
// SkipDNSResolve is set from dns module, no use if coming from a protobuf object?
|
// SkipDNSResolve is set from dns module, no use if coming from a protobuf object?
|
||||||
// TODO: please confirm @Vigilans
|
// TODO: please confirm @Vigilans
|
||||||
|
@ -34,6 +34,7 @@ type Route struct {
|
|||||||
routing.Context
|
routing.Context
|
||||||
outboundGroupTags []string
|
outboundGroupTags []string
|
||||||
outboundTag string
|
outboundTag string
|
||||||
|
ruleTag string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes the Router.
|
// Init initializes the Router.
|
||||||
@ -89,7 +90,7 @@ func (r *Router) PickRoute(ctx routing.Context) (routing.Route, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Route{Context: ctx, outboundTag: tag}, nil
|
return &Route{Context: ctx, outboundTag: tag, ruleTag: rule.RuleTag}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRule implements routing.Router.
|
// AddRule implements routing.Router.
|
||||||
@ -239,6 +240,10 @@ func (r *Route) GetOutboundTag() string {
|
|||||||
return r.outboundTag
|
return r.outboundTag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Route) GetRuleTag() string {
|
||||||
|
return r.ruleTag
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||||
r := new(Router)
|
r := new(Router)
|
||||||
|
@ -30,6 +30,9 @@ type Route interface {
|
|||||||
|
|
||||||
// GetOutboundTag returns the tag of the outbound the connection was dispatched to.
|
// GetOutboundTag returns the tag of the outbound the connection was dispatched to.
|
||||||
GetOutboundTag() string
|
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.
|
// RouterType return the type of Router interface. Can be used to implement common.HasType.
|
||||||
|
Loading…
Reference in New Issue
Block a user