mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-07-22 15:23:29 +03:00
Add wifi_ssid and wifi_bssid route and DNS rules
This commit is contained in:
@@ -86,6 +86,8 @@ type Router struct {
|
||||
clashServer adapter.ClashServer
|
||||
v2rayServer adapter.V2RayServer
|
||||
platformInterface platform.Interface
|
||||
needWIFIState bool
|
||||
wifiState adapter.WIFIState
|
||||
}
|
||||
|
||||
func NewRouter(
|
||||
@@ -116,6 +118,7 @@ func NewRouter(
|
||||
defaultMark: options.DefaultMark,
|
||||
pauseManager: pause.ManagerFromContext(ctx),
|
||||
platformInterface: platformInterface,
|
||||
needWIFIState: true, // hasRule(options.Rules, isWIFIRule) || hasDNSRule(dnsOptions.Rules, isWIFIDNSRule),
|
||||
}
|
||||
router.dnsClient = dns.NewClient(dns.ClientOptions{
|
||||
DisableCache: dnsOptions.DNSClientOptions.DisableCache,
|
||||
@@ -328,6 +331,9 @@ func NewRouter(
|
||||
service.ContextWith[serviceNTP.TimeService](ctx, timeService)
|
||||
router.timeService = timeService
|
||||
}
|
||||
if platformInterface != nil && router.interfaceMonitor != nil && router.needWIFIState {
|
||||
router.interfaceMonitor.RegisterCallback(router.updateWIFIState)
|
||||
}
|
||||
return router, nil
|
||||
}
|
||||
|
||||
@@ -468,6 +474,9 @@ func (r *Router) Start() error {
|
||||
r.geositeCache = nil
|
||||
r.geositeReader = nil
|
||||
}
|
||||
if r.needWIFIState {
|
||||
r.updateWIFIState(0)
|
||||
}
|
||||
for i, rule := range r.rules {
|
||||
err := rule.Start()
|
||||
if err != nil {
|
||||
@@ -940,6 +949,10 @@ func (r *Router) Rules() []adapter.Rule {
|
||||
return r.rules
|
||||
}
|
||||
|
||||
func (r *Router) WIFIState() adapter.WIFIState {
|
||||
return r.wifiState
|
||||
}
|
||||
|
||||
func (r *Router) NetworkMonitor() tun.NetworkUpdateMonitor {
|
||||
return r.networkMonitor
|
||||
}
|
||||
@@ -1019,3 +1032,15 @@ func (r *Router) ResetNetwork() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Router) updateWIFIState(_ int) {
|
||||
state /*, err */ := r.platformInterface.ReadWIFIState()
|
||||
/*if err != nil {
|
||||
r.logger.Error("read WIFI state: ", err)
|
||||
return
|
||||
}*/
|
||||
if state != r.wifiState {
|
||||
r.wifiState = state
|
||||
r.logger.Info("updated WIFI state: SSID=", state.SSID, ", BSSID=", state.BSSID)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user