Skip to content

Commit 82c1c09

Browse files
committed
cidr ip format validator
1 parent cc4e053 commit 82c1c09

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

func/main.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,18 @@ is_alias_format_valid() {
502502
is_ip_format_valid() {
503503
object_name=${2-ip}
504504
ip_regex='([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'
505-
if ! [[ $1 =~ ^$ip_regex\.$ip_regex\.$ip_regex\.$ip_regex$ ]]; then
505+
ip_clean=$(echo "${1%/[0-9][0-9]}")
506+
ip_clean=$(echo "${1%/[0-9]}")
507+
if ! [[ $ip_clean =~ ^$ip_regex\.$ip_regex\.$ip_regex\.$ip_regex$ ]]; then
506508
check_result $E_INVALID "invalid $object_name format :: $1"
507509
fi
510+
if [ $1 != "$ip_clean" ]; then
511+
ip_cidr="$ip_clean/"
512+
ip_cidr=$(echo "${1#$ip_cidr}")
513+
if [[ "$ip_cidr" -gt 32 ]]; then
514+
check_result $E_INVALID "invalid $object_name format :: $1"
515+
fi
516+
fi
508517
}
509518

510519
# Proxy extention format validator

0 commit comments

Comments
 (0)