From 0e31670d256da037a6badea335ebfe6dfb1b6bc7 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 17 Aug 2024 10:26:28 +0200 Subject: [PATCH] Add TCP BBR configuration option to installer, addresses #1624 --- installers/common.sh | 62 ++++++++++++++++++++++++++++++++++++++++++ installers/raspbian.sh | 5 ++++ 2 files changed, 67 insertions(+) diff --git a/installers/common.sh b/installers/common.sh index acd8982b..aeb270b5 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -55,6 +55,7 @@ function _install_raspap() { _install_lighttpd_configs _default_configuration _configure_networking + _prompt_configure_tcp_bbr _prompt_install_features _install_extra_features _patch_system_files @@ -788,6 +789,67 @@ function _configure_networking() { _install_status 0 } +# Prompt to configure TCP BBR option +function _prompt_configure_tcp_bbr() { + _install_log "Configure TCP BBR congestion control" + echo "Network performance can be improved by changing TCP congestion control to BBR (Bottleneck Bandwidth and RTT)" + echo -n "Enable TCP BBR congestion control algorithm (Recommended)? [Y/n]: " + if [ "$assume_yes" == 0 ]; then + read answer < /dev/tty + if [ "$answer" != "${answer#[Nn]}" ]; then + _install_status 0 "(Skipped)" + else + _configure_tcp_bbr + fi + elif [ "${bbr_option}" == 1 ]; then + _configure_tcp_bbr + else + echo "(Skipped)" + fi +} + +function _configure_tcp_bbr() { + echo "Checking kernel support for the TCP BBR algorithm..." + _check_tcp_bbr_available + if [ $? -eq 0 ]; then + echo "TCP BBR option found. Enabling configuration" + # Load the BBR module + echo "Loading BBR kernel module" + sudo modprobe tcp_bbr || _install_status 1 "Unable to execute modprobe tcp_bbr" + # Add BBR configuration to sysctl.conf if not present + echo "Adding BBR configuration to /etc/sysctl.conf if not present" + if ! grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf; then + echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf || _install_status 1 "Unable to modify /etc/sysctl.conf" + fi + if ! grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then + echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf || _install_status 1 "Unable to modify /etc/sysctl.conf" + fi + # Apply the sysctl changes + echo "Applying changes" + sudo sysctl -p + + # Verify if BBR is enabled + current_cc=$(sysctl net.ipv4.tcp_congestion_control | awk '{print $3}') + if [ "$current_cc" == "bbr" ]; then + echo "TCP BBR has been successfully enabled" + else + _install_status 1 "Failed to enable TCP BBR" + fi + else + _install_status 2 "TCP BBR option is not available (Skipped)" + fi + _install_status 0 +} + +function _check_tcp_bbr_available() { + config_file="/boot/config-$(uname -r)" + if grep -q 'CONFIG_TCP_CONG_BBR' "$config_file" && grep -q 'CONFIG_NET_SCH_FQ' "$config_file"; then + return 0 + else + return 1 + fi +} + # Add sudoers file to /etc/sudoers.d/ and set file permissions function _patch_system_files() { diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 0626faab..fed89149 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -44,6 +44,7 @@ OPTIONS: -a, --adblock Used with -y, --yes, sets Adblock install option (0=no install) -w, --wireguard Used with -y, --yes, sets WireGuard install option (0=no install) -e, --provider Used with -y, --yes, sets the VPN provider install option +-g, --tcp-bbr Used with -y, --yes, sets the TCP BBR congestion control algorithm option -r, --repo, --repository Overrides the default GitHub repo (RaspAP/raspap-webgui) -b, --branch Overrides the default git branch (latest release) -t, --token Specify a GitHub token to access a private repository @@ -129,6 +130,10 @@ function _parse_params() { pv_option="$2" shift ;; + -g|--tcp-bbr) + bbr_option="$2" + shift + ;; -c|--cert|--certificate) install_cert=1 ;;