Add Linux WI-FI state support

Support monitoring WIFI state on Linux through:
- NetworkManager (D-Bus)
- IWD (D-Bus)
- wpa_supplicant (control socket)
- ConnMan (D-Bus)
This commit is contained in:
世界
2025-12-07 11:05:43 +08:00
parent cd56eaaba2
commit 8d8ca282a1
19 changed files with 913 additions and 31 deletions

View File

@@ -38,7 +38,6 @@ type Router struct {
pauseManager pause.Manager
trackers []adapter.ConnectionTracker
platformInterface platform.Interface
needWIFIState bool
started bool
}
@@ -57,7 +56,6 @@ func NewRouter(ctx context.Context, logFactory log.Factory, options option.Route
needFindProcess: hasRule(options.Rules, isProcessRule) || hasDNSRule(dnsOptions.Rules, isProcessDNSRule) || options.FindProcess,
pauseManager: service.FromContext[pause.Manager](ctx),
platformInterface: service.FromContext[platform.Interface](ctx),
needWIFIState: hasRule(options.Rules, isWIFIRule) || hasDNSRule(dnsOptions.Rules, isWIFIDNSRule),
}
}
@@ -113,15 +111,13 @@ func (r *Router) Start(stage adapter.StartStage) error {
if cacheContext != nil {
cacheContext.Close()
}
r.network.Initialize(r.ruleSets)
needFindProcess := r.needFindProcess
for _, ruleSet := range r.ruleSets {
metadata := ruleSet.Metadata()
if metadata.ContainsProcessRule {
needFindProcess = true
}
if metadata.ContainsWIFIRule {
r.needWIFIState = true
}
}
if needFindProcess {
if r.platformInterface != nil {
@@ -195,10 +191,6 @@ func (r *Router) RuleSet(tag string) (adapter.RuleSet, bool) {
return ruleSet, loaded
}
func (r *Router) NeedWIFIState() bool {
return r.needWIFIState
}
func (r *Router) Rules() []adapter.Rule {
return r.rules
}