From aab74fea51cb14d02d619aa2d8617e35728b39a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 20 Sep 2026 18:25:21 +0800 Subject: [PATCH] Add libbox API to detect tun inbounds --- experimental/libbox/config.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/experimental/libbox/config.go b/experimental/libbox/config.go index 08aa8ff0..a3f47f5e 100644 --- a/experimental/libbox/config.go +++ b/experimental/libbox/config.go @@ -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 +}