]> git.ipfire.org Git - people/ms/network.git/commitdiff
util: add function mtu_is_valid
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 7 Jun 2017 06:24:34 +0000 (08:24 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 14 Jun 2017 20:43:17 +0000 (22:43 +0200)
This function checks if an mtu is valid for a given IP protocol.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.util

index 4b6f956633a20bdad2779be98dc1d34e294dc4e5..b7e35c91e063814fc9301dd04a474ed0d6346b60 100644 (file)
@@ -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