mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-10 02:53:12 +00:00
30 lines
569 B
Go
30 lines
569 B
Go
|
package route
|
||
|
|
||
|
import (
|
||
|
"github.com/sagernet/sing-box/adapter"
|
||
|
)
|
||
|
|
||
|
var _ RuleItem = (*IPVersionItem)(nil)
|
||
|
|
||
|
type IPVersionItem struct {
|
||
|
isIPv6 bool
|
||
|
}
|
||
|
|
||
|
func NewIPVersionItem(isIPv6 bool) *IPVersionItem {
|
||
|
return &IPVersionItem{isIPv6}
|
||
|
}
|
||
|
|
||
|
func (r *IPVersionItem) Match(metadata *adapter.InboundContext) bool {
|
||
|
return metadata.Destination.IsIP() && metadata.Destination.Family().IsIPv6() == r.isIPv6
|
||
|
}
|
||
|
|
||
|
func (r *IPVersionItem) String() string {
|
||
|
var versionStr string
|
||
|
if r.isIPv6 {
|
||
|
versionStr = "6"
|
||
|
} else {
|
||
|
versionStr = "4"
|
||
|
}
|
||
|
return "ip_version=" + versionStr
|
||
|
}
|