#!/bin/bash

echo "=== Vérification des paramètres sysctl ==="

# Liste des paramètres à vérifier avec leur valeur recommandée
declare -A sysctl_params=(
  [net.core.somaxconn]=65535
  [net.ipv4.tcp_max_syn_backlog]=32768
  [net.ipv4.tcp_syncookies]=1
  [net.ipv4.ip_local_port_range]="1024 65535"
  [net.ipv4.tcp_fin_timeout]=5
  [net.ipv4.tcp_tw_reuse]=1
  [net.core.netdev_max_backlog]=65536
  [net.core.rmem_max]=33554432
  [net.core.wmem_max]=33554432
  [net.ipv4.tcp_rmem]="8192 87380 33554432"
  [net.ipv4.tcp_wmem]="8192 65536 33554432"
)

for param in "${!sysctl_params[@]}"; do
  expected="${sysctl_params[$param]}"
  actual=$(sysctl -n $param 2>/dev/null)
  if [ "$actual" = "$expected" ]; then
    echo "[OK] $param = $actual"
  else
    echo "[WARN] $param = $actual (attendu: $expected)"
  fi
done

echo
echo "=== Vérification ulimit (max fichiers ouverts) ==="
ulimit_n=$(ulimit -n)
if [ "$ulimit_n" -lt 100000 ]; then
  echo "[WARN] ulimit -n = $ulimit_n (recommandé >= 100000)"
else
  echo "[OK] ulimit -n = $ulimit_n"
fi

echo
echo "=== Vérification du port range local ==="
cat /proc/sys/net/ipv4/ip_local_port_range

echo
echo "=== Fin du diagnostic. ==="

