Last active
November 24, 2020 12:50
-
-
Save sebastianw/0dd359582b7b794d23251cff0f70d285 to your computer and use it in GitHub Desktop.
MTU Size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mtusize { | |
#set -x | |
[ -z "$1" ] && { echo "mtusize <host> [<initial data size> <step length>]"; return 1; } | |
ip=$1 | |
size=${2:-1345} | |
step=${3:-64} | |
count=0 | |
minfailed=999999 | |
rstring=("" " failed") | |
while true; do | |
((count++)) | |
ping -q -W 1 -s "$size" -c1 -M "do" "$ip" >&/dev/null | |
result=$? | |
>&2 echo "[$count] Step $step / MTU $((size+28))${rstring[$result]}" | |
if [ "$result" -ne 0 ]; then | |
if [ "$step" -le 1 ] ; then | |
break | |
fi | |
minfailed=$size | |
((step=step/2)) | |
((size-=step)) | |
else | |
while [ $((size+step)) -ge "$minfailed" ]; do | |
((step=step/2)) | |
done | |
((size+=step)) | |
if [ "$step" -le 0 ] ; then | |
((size+=1)) | |
break | |
fi | |
fi | |
done | |
#set +x | |
echo "Max MTU size: $((size-1+28)) Byte ($count Pings)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mtusize6 { | |
#set -x | |
[ -z "$1" ] && { echo "mtusize <host> [<initial data size> <step length>]"; return 1; } | |
ip=$1 | |
size=${2:-1345} | |
step=${3:-64} | |
count=0 | |
minfailed=999999 | |
rstring=("" " failed") | |
while true; do | |
((count++)) | |
ping6 -q -W 1 -s "$size" -c1 -M "do" "$ip" >&/dev/null | |
result=$? | |
>&2 echo "[$count] Step $step / MTU $((size+48))${rstring[$result]}" | |
if [ "$result" -ne 0 ]; then | |
if [ "$step" -le 1 ] ; then | |
break | |
fi | |
minfailed=$size | |
((step=step/2)) | |
((size-=step)) | |
else | |
while [ $((size+step)) -ge "$minfailed" ]; do | |
((step=step/2)) | |
done | |
((size+=step)) | |
if [ "$step" -le 0 ] ; then | |
((size+=1)) | |
break | |
fi | |
fi | |
done | |
#set +x | |
echo "Max MTU size: $((size-1+48)) Byte ($count Pings)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment