API: Add ListRule() for routing (#5569)

https://github.com/XTLS/Xray-core/pull/5569#issuecomment-3766310407
This commit is contained in:
MouMeng
2026-01-23 23:44:16 +08:00
committed by GitHub
parent 5846f94784
commit 59dc2cee2e
8 changed files with 457 additions and 283 deletions
+16 -1
View File
@@ -2,7 +2,7 @@ package router
import (
"context"
sync "sync"
"sync"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
@@ -181,6 +181,21 @@ func (r *Router) RemoveRule(tag string) error {
return errors.New("empty tag name!")
}
// ListRule implements routing.Router
func (r *Router) ListRule() []routing.Route {
r.mu.Lock()
defer r.mu.Unlock()
ruleList := make([]routing.Route, 0)
for _, rule := range r.rules {
ruleList = append(ruleList, &Route{
outboundTag: rule.Tag,
ruleTag: rule.RuleTag,
})
}
return ruleList
}
func (r *Router) pickRouteInternal(ctx routing.Context) (*Rule, routing.Context, error) {
// SkipDNSResolve is set from DNS module.
// the DOH remote server maybe a domain name,