V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m38s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-07-08 21:15:41 +02:00
parent 6d255e9c07
commit 980f81bfb3
12 changed files with 47 additions and 37 deletions

View File

@@ -18,6 +18,8 @@ guard_sourcing
# ERR_INVALID_IPV4
# Arguments:
# 1: IPv4 to validate.
# Returns:
# ERR_INVALID_IPV4
#######################################
validation_ipv4() {
declare var_ip="$1"
@@ -25,7 +27,7 @@ validation_ipv4() {
if [[ "${var_ip}" =~ ^((25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})$ ]]; then
do_log "info" "true" "'${var_ip}' seems to be a valid IPv4."
else
exit "${ERR_INVALID_IPV4}"
return "${ERR_INVALID_IPV4}"
fi
}
@@ -39,6 +41,8 @@ validation_ipv4() {
# ERR_INVALID_IPV6
# Arguments:
# 1: IPv6 address
# Returns:
# ERR_INVALID_IPV6
#######################################
validation_ipv6() {
### Original input (may include %zone).
@@ -50,7 +54,7 @@ validation_ipv6() {
### Step 1 - IPv4-mapped / -embedded addresses (::ffff:192.0.2.1)
if [[ "${var_addr}" == *.* ]]; then
declare var_ipv4_part="${var_addr##*:}"
validation_ipv4 "${var_ipv4_part}" || exit "${ERR_INVALID_IPV6}"
validation_ipv4 "${var_ipv4_part}" || return "${ERR_INVALID_IPV6}"
### Replace IPv4 part by a placeholder, so we can count hextets later
var_addr="${var_addr%:*}:0:0"
fi
@@ -59,7 +63,7 @@ validation_ipv6() {
if [[ "${var_addr}" == *::* ]]; then
var_has_double_colon=1
### Remove first '::' and check there is no second one.
[[ ${var_addr#*::*} == *::* ]] && exit "${ERR_INVALID_IPV6}"
[[ ${var_addr#*::*} == *::* ]] && return "${ERR_INVALID_IPV6}"
fi
### Step 3 - Split into hextets and validate format.
@@ -71,14 +75,14 @@ validation_ipv6() {
for var_hextet in "${var_segments[@]}"; do
### Empty part of '::' compression
[[ -z "${var_hextet}" ]] && continue
[[ "${var_hextet}" =~ ^[0-9a-fA-F]{1,4}$ ]] || exit "${ERR_INVALID_IPV6}"
[[ "${var_hextet}" =~ ^[0-9a-fA-F]{1,4}$ ]] || return "${ERR_INVALID_IPV6}"
done
### Step 4 - Check total hextet count.
if (( var_has_double_colon )); then
(( seg_count <= 8 )) || exit "${ERR_INVALID_IPV6}"
(( seg_count <= 8 )) || return "${ERR_INVALID_IPV6}"
else
(( seg_count == 8 )) || exit "${ERR_INVALID_IPV6}"
(( seg_count == 8 )) || return "${ERR_INVALID_IPV6}"
fi
### Success
@@ -91,6 +95,8 @@ validation_ipv6() {
# ERR_INVALID_PORT
# Arguments:
# 1: Port number
# Returns:
# ERR_INVALID_PORT
#######################################
validation_port() {
declare var_port="$1"
@@ -98,7 +104,7 @@ validation_port() {
do_log "info" "true" "'${var_port}' seems to be a valid port."
else
do_log "error" "false" "'${var_port}' seems to be NOT a valid port."
exit "${ERR_INVALID_PORT}"
return "${ERR_INVALID_PORT}"
fi
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh