2024-10-21 23:38:34 +08:00
|
|
|
package rule
|
2023-11-24 20:58:07 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
F "github.com/sagernet/sing/common/format"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ RuleItem = (*WIFIBSSIDItem)(nil)
|
|
|
|
|
|
|
|
type WIFIBSSIDItem struct {
|
2024-11-10 12:11:21 +08:00
|
|
|
bssidList []string
|
|
|
|
bssidMap map[string]bool
|
|
|
|
networkManager adapter.NetworkManager
|
2023-11-24 20:58:07 +08:00
|
|
|
}
|
|
|
|
|
2024-11-10 12:11:21 +08:00
|
|
|
func NewWIFIBSSIDItem(networkManager adapter.NetworkManager, bssidList []string) *WIFIBSSIDItem {
|
2023-11-24 20:58:07 +08:00
|
|
|
bssidMap := make(map[string]bool)
|
|
|
|
for _, bssid := range bssidList {
|
|
|
|
bssidMap[bssid] = true
|
|
|
|
}
|
|
|
|
return &WIFIBSSIDItem{
|
|
|
|
bssidList,
|
|
|
|
bssidMap,
|
2024-11-10 12:11:21 +08:00
|
|
|
networkManager,
|
2023-11-24 20:58:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *WIFIBSSIDItem) Match(metadata *adapter.InboundContext) bool {
|
2024-11-10 12:11:21 +08:00
|
|
|
return r.bssidMap[r.networkManager.WIFIState().BSSID]
|
2023-11-24 20:58:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *WIFIBSSIDItem) String() string {
|
|
|
|
if len(r.bssidList) == 1 {
|
|
|
|
return F.ToString("wifi_bssid=", r.bssidList[0])
|
|
|
|
}
|
|
|
|
return F.ToString("wifi_bssid=[", strings.Join(r.bssidList, " "), "]")
|
|
|
|
}
|