46 lines
791 B
Go
46 lines
791 B
Go
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
//go:build plus
|
|
|
|
package models
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
|
"net"
|
|
)
|
|
|
|
type NSRoute struct {
|
|
Id int64
|
|
Ranges []dnsconfigs.NSRouteRangeInterface
|
|
Priority int32
|
|
Order int32
|
|
UserId int64
|
|
Version int64
|
|
}
|
|
|
|
func (this *NSRoute) Contains(ip net.IP) bool {
|
|
if len(ip) == 0 {
|
|
return false
|
|
}
|
|
|
|
// 先执行IsReverse
|
|
for _, r := range this.Ranges {
|
|
if r.IsExcluding() && r.Contains(ip) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
// 再执行正常的
|
|
for _, r := range this.Ranges {
|
|
if !r.IsExcluding() && r.Contains(ip) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// RealCode 代号
|
|
// TODO 支持自定义代号
|
|
func (this *NSRoute) RealCode() string {
|
|
return RouteIdString(this.Id)
|
|
}
|