[1/4] ipv4: new function ipv4_net_is_valid

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

Details

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

Commit Message

Jonatan Schlag June 3, 2017, 11:25 a.m.
This function checks if a given network is valid IPv4 network

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/functions/functions.ipv4 | 9 +++++++++
 1 file changed, 9 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/functions/functions.ipv4 b/src/functions/functions.ipv4
index f63c2b7..e893f5e 100644
--- a/src/functions/functions.ipv4
+++ b/src/functions/functions.ipv4
@@ -51,6 +51,15 @@  ipv4_prefix_is_valid() {
 	return ${EXIT_TRUE}
 }
 
+ipv4_net_is_valid() {
+	local net="${1}"
+
+	local prefix="$(ip_get_prefix "${net}")"
+	local addr="$(ip_split_prefix "${net}")"
+
+	ipv4_prefix_is_valid "${prefix}" && ipv4_is_valid "${addr}"
+}
+
 ipv4_netmask_is_valid() {
 	local netmask="${1}"