强制使用规范的网络路由地址

This commit is contained in:
lihz
2023-06-13 13:22:00 +08:00
parent a9e798f203
commit fc2920e140
5 changed files with 35 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ package dbdata
import (
"errors"
"fmt"
"net"
"strings"
"time"
@@ -31,11 +32,16 @@ func SetPolicy(p *Policy) error {
continue
}
ipMask, _, err := parseIpNet(v.Val)
ipMask, ipNet, err := parseIpNet(v.Val)
if err != nil {
return errors.New("RouteInclude 错误" + err.Error())
}
if strings.Split(ipMask, "/")[0] != ipNet.IP.String() {
errMsg := fmt.Sprintf("RouteInclude 错误: 网络地址错误,建议: %s 改为 %s", v.Val, ipNet)
return errors.New(errMsg)
}
v.IpMask = ipMask
routeInclude = append(routeInclude, v)
}
@@ -45,10 +51,15 @@ func SetPolicy(p *Policy) error {
routeExclude := []ValData{}
for _, v := range p.RouteExclude {
if v.Val != "" {
ipMask, _, err := parseIpNet(v.Val)
ipMask, ipNet, err := parseIpNet(v.Val)
if err != nil {
return errors.New("RouteExclude 错误" + err.Error())
}
if strings.Split(ipMask, "/")[0] != ipNet.IP.String() {
errMsg := fmt.Sprintf("RouteInclude 错误: 网络地址错误,建议: %s 改为 %s", v.Val, ipNet)
return errors.New(errMsg)
}
v.IpMask = ipMask
routeExclude = append(routeExclude, v)
}