Skip to content

Instantly share code, notes, and snippets.

@PtaxLaine
Last active April 28, 2024 18:28
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PtaxLaine/2d4115a3c4004884a36d7f6f07bda666 to your computer and use it in GitHub Desktop.
Save PtaxLaine/2d4115a3c4004884a36d7f6f07bda666 to your computer and use it in GitHub Desktop.

Дисклеймер: проверено на свежем ArchLinux с systemd-networkd. Скрипт достаточно наивен и работа на иных конфигурация может быть под вопросом. Отлаживать через ip rule, ip route show table 10032590.

[опционально] Определите ваш MTU для маршрута к Valve

$ curl https://gist.githubusercontent.com/PtaxLaine/2d4115a3c4004884a36d7f6f07bda666/raw/mtu_probe.sh | bash

Установка

pacman-based (Arch, Manjaro, etc)

Загрузить пакетированный скрипт archlinux-pmtud-bh-workaround-*.pkg.tar.zst

$ sudo pacman -U archlinux-pmtud-bh-workaround-*.pkg.tar.zst
apt-based (Ubuntu, Debian, etc)

Загрузить пакетированный скрипт debian-pmtud-bh-workaround-*.deb

$ sudo apt install -f ./debian-pmtud-bh-workaround-*.deb
Ручная
  1. Установите зависимости gawk whois gzip iproute2

  2. Клонируете скрипты во временную директорию

    $ git clone https://github.com/PtaxLaine/pmtud-bh-workaround.git /tmp/pmtud-bh-workaround
  3. Скопируйте файлы из временной директории

    $ sudo cp -i /tmp/pmtud-bh-workaround/pmtud-bh-workaround.sh /usr/bin/pmtud-bh-workaround
    $ sudo cp -i /tmp/pmtud-bh-workaround/systemd/* /usr/lib/systemd/system/

Активация

[note] Если на шаге №0 обнаруженный MTU не был равен 1280, замените 1280 во второй команде на ваше значение

Перезагрузите список демонов systemd и активируйте сервис:

$ sudo systemctl daemon-reload
$ sudo systemctl enable --now pmtud-bh-workaround@"AS32590:1280".service

Проверка работы новых правил

$ ip route get 155.133.254.0
    155.133.254.0 via GW dev DEV table 1029732590 src HOST uid UID 
        cache mtu 1280 
#!/usr/bin/bash
set -euo pipefail
PROBE_IP="162.254.198.1"
START_MTU=1500
STOP_MTU=512
MTU_STEP=110
ICMP_COUNT=3
ICMP_TIMEOUT=2
ICMP_INTERVAL=1
ICMP_LEN=28
PING="/usr/bin/ping"
$PING -4 -W 2 -c 1 $PROBE_IP 2>&1 > /dev/null ||
while [ true ]; do
echo "Failed to check the probe $PROBE_IP"
exit 1
done;
CMD="$PING -4 -n -O -c $ICMP_COUNT -i $ICMP_INTERVAL -W $ICMP_TIMEOUT -M do $PROBE_IP"
CURRENT_MTU=$START_MTU
while [ $CURRENT_MTU -ge $STOP_MTU ]; do
echo "Trying with MTU $CURRENT_MTU..."
set +e
$CMD -s $(($CURRENT_MTU - $ICMP_LEN))
if [[ $? != 1 ]]; then
echo "MTU found: $CURRENT_MTU"
exit 0
fi;
true
set -e
CURRENT_MTU=$(($CURRENT_MTU - $MTU_STEP))
done;
echo "MTU discovery failed"
exit 1
@PtaxLaine
Copy link
Author

PtaxLaine commented Feb 6, 2024

[del]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment