Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/MayNiklas/nixos
Browse files Browse the repository at this point in the history
  • Loading branch information
MayNiklas committed Feb 4, 2024
2 parents 571a0ae + cfe3bd3 commit 6b764b8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 49 deletions.
30 changes: 15 additions & 15 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 35 additions & 34 deletions packages/mtu-check/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
{ pkgs, stdenv, ... }:
let
mtu-check-skript = pkgs.writeShellScriptBin "mtu-check" ''
# start with a known good MTU
MTU=1380
IP=1.1.1.1
# 2. Check 5 times before giving up
{ writeShellScriptBin, iputils, ... }:
writeShellScriptBin "mtu-check" ''
# start with a known good MTU
MTU=1380
IP=1.1.1.1
# if argument is given, use it as IP
if [ -n "$1" ]; then
IP=$1
fi
# check maximum transmission unit (MTU) of a network
# loop until we get an error
while true; do
# try to ping with the current MTU
echo "Trying MTU of $MTU"
ping -c 1 -M do -s $MTU $IP >/dev/null 2>&1
if [ $? -ne 0 ]; then
# counter for failed pings in a row
counter=0
# check maximum transmission unit (MTU) of a network
# loop until we get an error
while true; do
# try to ping with the current MTU
echo "Trying MTU of $MTU"
${iputils}/bin/ping -c 1 -M do -s $MTU $IP >/dev/null 2>&1
if [ $? -ne 0 ]; then
counter=$(($counter + 1))
# if we failed 5 times in a row, we assume the MTU is too big
if [ $counter -eq 5 ]; then
# ping failed, so the MTU is too big
echo "Ping with MTU size $MTU failed..."
echo "Adding 28 Bytes for ICMP and IP header to the previous value..."
Expand All @@ -20,25 +32,14 @@ let
MTU=$(($MTU + 28 - 1))
echo "MTU of network is $MTU Bytes"
exit 0
else
# ping succeeded, so the MTU is too small
# increase it by 1 and try again
MTU=$(($MTU + 1))
fi
done
'';
in
stdenv.mkDerivation {

pname = "mtu-check";
version = "0.1.0";

# Needed if no src is used. Alternatively place script in
# separate file and include it as src
dontUnpack = true;

installPhase = ''
cp -r ${mtu-check-skript} $out
'';
}
fi
else
# ping succeeded, so the MTU is too small
# increase it by 1 and try again
MTU=$(($MTU + 1))
# reset counter if we had a successful ping
counter=0
fi
done
''

0 comments on commit 6b764b8

Please sign in to comment.