From mboxrd@z Thu Jan  1 00:00:00 1970
From: Jonatan Schlag <jonatan.schlag@ipfire.org>
To: network@lists.ipfire.org
Subject: [PATCH v2] util: add function mtu_is_valid
Date: Wed, 07 Jun 2017 08:24:34 +0200
Message-ID: <1496816674-6333-1-git-send-email-jonatan.schlag@ipfire.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============4829332498901454928=="
List-Id: <network.lists.ipfire.org>

--===============4829332498901454928==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

This function checks if an mtu is valid for a given IP protocol.

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

diff --git a/src/functions/functions.util b/src/functions/functions.util
index 4b6f956..b7e35c9 100644
--- a/src/functions/functions.util
+++ b/src/functions/functions.util
@@ -321,6 +321,24 @@ isipaddress() {
 	ip_is_valid ${addr}
 }
 
+mtu_is_valid() {
+	local proto=${1}
+	local mtu=${2}
+
+	case ${proto} in
+		ipv4)
+			[ ${mtu} -ge 576 ] && [ ${mtu} -le 9000 ]
+			;;
+		ipv6)
+			[ ${mtu} -ge 1280 ] && [ ${mtu} -le 9000 ]
+			;;
+		*)
+			error "${proto} is not a valid proto"
+			return ${EXIT_ERROR}
+			;;
+	esac
+}
+
 backtrace() {
 	local start=1
 
-- 
2.6.3


--===============4829332498901454928==--