[3/4] util: add function mtu_is_valid

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

Details

Message ID 1496489110-10134-3-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 an mtu is valid for a given IP protocol.

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

Patch hide | download patch | download mbox

diff --git a/src/functions/functions.util b/src/functions/functions.util
index 4b6f956..98ad9d4 100644
--- a/src/functions/functions.util
+++ b/src/functions/functions.util
@@ -321,6 +321,25 @@  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
 

Comments

Michael Tremer June 3, 2017, 1:04 p.m.
Hello,

could you please resend this patch with indentation fixed?

All other functions are indented by one tab where this one is not.

On Sat, 2017-06-03 at 13:25 +0200, Jonatan Schlag wrote:
> 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 | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/src/functions/functions.util b/src/functions/functions.util
> index 4b6f956..98ad9d4 100644
> --- a/src/functions/functions.util
> +++ b/src/functions/functions.util
> @@ -321,6 +321,25 @@ isipaddress() {
>  	ip_is_valid ${addr}
>  }
>  
> +mtu_is_valid() {
> +
> +local proto=${1}
> +local mtu=${2}

The empty line after the function name is unnecessary.

> +
> +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
> 

Best,
-Michael