[v2] util: add function mtu_is_valid

Submitted by Jonatan Schlag on June 7, 2017, 6:24 a.m.

Details

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

Commit Message

Jonatan Schlag June 7, 2017, 6:24 a.m.
This function checks if an mtu is valid for a given IP protocol.

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

Patch hide | download patch | download mbox

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