[2/4] ip: restructure ip_net_is_valid

Submitted by Jonatan Schlag on June 3, 2017, 11:25 a.m.

Details

Message ID 1496489110-10134-2-git-send-email-jonatan.schlag@ipfire.org
State New
Headers show

Commit Message

Jonatan Schlag June 3, 2017, 11:25 a.m.
Insted of checking the network manually we now just calö ipv4_net_is_valid or
ipv6_net_is_valid

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/functions/functions.ip | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/functions/functions.ip b/src/functions/functions.ip
index 97750e3..0a07fd0 100644
--- a/src/functions/functions.ip
+++ b/src/functions/functions.ip
@@ -83,23 +83,14 @@  ip_is_network() {
 	local network=${1}
 	assert isset network
 
-	# Get the address part.
-	local address=$(ip_split_prefix ${network})
-	isset address || return ${EXIT_FALSE}
-
-	# Get the prefix.
-	local prefix=$(ip_get_prefix ${network})
-	isset prefix || return ${EXIT_FALSE}
-
-	# Detect the protocol (if this fails, the
-	# address part is invalid)
-	local proto=$(ip_detect_protocol ${address})
-	isset proto || return ${EXIT_FALSE}
-
-	# Check if the prefix is correct.
-	ip_prefix_is_valid ${proto} ${prefix} || return ${EXIT_FALSE}
+	local protocol
+	for protocol in ${IP_SUPPORTED_PROTOCOLS}; do
+		if ${protocol}_net_is_valid "${network}"; then
+			return ${EXIT_TRUE}
+		fi
+	done
 
-	return ${EXIT_TRUE}
+	return ${EXIT_FALSE}
 }
 
 ip_prefix_is_valid() {