-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
wifi_ssid
and wifi_bssid
route and DNS rules
- Loading branch information
1 parent
4fcf29d
commit a5cea60
Showing
12 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package route | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/sagernet/sing-box/adapter" | ||
F "github.com/sagernet/sing/common/format" | ||
) | ||
|
||
var _ RuleItem = (*WIFIBSSIDItem)(nil) | ||
|
||
type WIFIBSSIDItem struct { | ||
bssidList []string | ||
bssidMap map[string]bool | ||
router adapter.Router | ||
} | ||
|
||
func NewWIFIBSSIDItem(router adapter.Router, bssidList []string) *WIFIBSSIDItem { | ||
bssidMap := make(map[string]bool) | ||
for _, bssid := range bssidList { | ||
bssidMap[bssid] = true | ||
} | ||
return &WIFIBSSIDItem{ | ||
bssidList, | ||
bssidMap, | ||
router, | ||
} | ||
} | ||
|
||
func (r *WIFIBSSIDItem) Match(metadata *adapter.InboundContext) bool { | ||
return r.bssidMap[r.router.WIFIState().BSSID] | ||
} | ||
|
||
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, " "), "]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package route | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/sagernet/sing-box/adapter" | ||
F "github.com/sagernet/sing/common/format" | ||
) | ||
|
||
var _ RuleItem = (*WIFISSIDItem)(nil) | ||
|
||
type WIFISSIDItem struct { | ||
ssidList []string | ||
ssidMap map[string]bool | ||
router adapter.Router | ||
} | ||
|
||
func NewWIFISSIDItem(router adapter.Router, ssidList []string) *WIFISSIDItem { | ||
ssidMap := make(map[string]bool) | ||
for _, ssid := range ssidList { | ||
ssidMap[ssid] = true | ||
} | ||
return &WIFISSIDItem{ | ||
ssidList, | ||
ssidMap, | ||
router, | ||
} | ||
} | ||
|
||
func (r *WIFISSIDItem) Match(metadata *adapter.InboundContext) bool { | ||
return r.ssidMap[r.router.WIFIState().SSID] | ||
} | ||
|
||
func (r *WIFISSIDItem) String() string { | ||
if len(r.ssidList) == 1 { | ||
return F.ToString("wifi_ssid=", r.ssidList[0]) | ||
} | ||
return F.ToString("wifi_ssid=[", strings.Join(r.ssidList, " "), "]") | ||
} |