mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-08-01 03:24:15 +03:00
Add tunnel
This commit is contained in:
35
route/rule/rule_item_tunnel_source.go
Normal file
35
route/rule/rule_item_tunnel_source.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package rule
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
)
|
||||
|
||||
var _ RuleItem = (*TunnelSourceItem)(nil)
|
||||
|
||||
type TunnelSourceItem struct {
|
||||
sources []string
|
||||
sourceMap map[string]bool
|
||||
}
|
||||
|
||||
func NewTunnelSourceItem(sources []string) *TunnelSourceItem {
|
||||
rule := &TunnelSourceItem{sources, make(map[string]bool)}
|
||||
for _, source := range sources {
|
||||
rule.sourceMap[source] = true
|
||||
}
|
||||
return rule
|
||||
}
|
||||
|
||||
func (r *TunnelSourceItem) Match(metadata *adapter.InboundContext) bool {
|
||||
return r.sourceMap[metadata.TunnelSource]
|
||||
}
|
||||
|
||||
func (r *TunnelSourceItem) String() string {
|
||||
if len(r.sources) == 1 {
|
||||
return F.ToString("tunnel_source=", r.sources[0])
|
||||
} else {
|
||||
return F.ToString("tunnel_source=[", strings.Join(r.sources, " "), "]")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user