Skip to content

Commit

Permalink
check the cidr format whether is correct (#1396)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3206a7a)
  • Loading branch information
wangyd1988 authored and oilbeater committed Mar 24, 2022
1 parent b54364b commit 899de6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ func CheckProtocol(address string) string {
ip := net.ParseIP(address)
if ip.To4() != nil {
return kubeovnv1.ProtocolIPv4
} else if ip.To16() != nil {
return kubeovnv1.ProtocolIPv6
}
return kubeovnv1.ProtocolIPv6

// cidr formal error
return ""
}

// ProtocolToFamily converts protocol string to netlink family
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func ValidateSubnet(subnet kubeovnv1.Subnet) error {
if err := cidrConflict(subnet.Spec.CIDRBlock); err != nil {
return err
}
if CheckProtocol(subnet.Spec.CIDRBlock) == "" {
return fmt.Errorf("CIDRBlock: %s formal error", subnet.Spec.CIDRBlock)
}
excludeIps := subnet.Spec.ExcludeIps
for _, ipr := range excludeIps {
ips := strings.Split(ipr, "..")
Expand Down

0 comments on commit 899de6f

Please sign in to comment.