Initial commit (code only without large binaries)
This commit is contained in:
45
EdgeDNS/internal/models/ns_route.go
Normal file
45
EdgeDNS/internal/models/ns_route.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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)
|
||||
}
|
||||
Reference in New Issue
Block a user