Add libbox API to detect tun inbounds

This commit is contained in:
世界
2026-09-20 22:24:38 +08:00
parent f5e8cdae19
commit aab74fea51
+11
View File
@@ -6,6 +6,7 @@ import (
"net/netip"
"os"
"reflect"
"slices"
box "github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/adapter"
@@ -269,3 +270,13 @@ func FormatConfig(configContent string) (*StringBox, error) {
}
return wrapString(buffer.String()), nil
}
func HasTunInbound(configContent string) (bool, error) {
options, err := parseConfig(baseContext(nil), configContent)
if err != nil {
return false, err
}
return slices.ContainsFunc(options.Inbounds, func(inbound option.Inbound) bool {
return inbound.Type == C.TypeTun
}), nil
}