Skip to content

Commit 85c38f2

Browse files
authored
Merge pull request #1639 from RaspAP/feat/installer-tcp-bbr
Adds TCP BBR configuration option to installer
2 parents d9f1a4d + 8f033e5 commit 85c38f2

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

installers/common.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function _install_raspap() {
5555
_install_lighttpd_configs
5656
_default_configuration
5757
_configure_networking
58+
_prompt_configure_tcp_bbr
5859
_prompt_install_features
5960
_install_extra_features
6061
_patch_system_files
@@ -788,6 +789,67 @@ function _configure_networking() {
788789
_install_status 0
789790
}
790791

792+
# Prompt to configure TCP BBR option
793+
function _prompt_configure_tcp_bbr() {
794+
_install_log "Configure TCP BBR congestion control"
795+
echo "Network performance can be improved by changing TCP congestion control to BBR (Bottleneck Bandwidth and RTT)"
796+
echo -n "Enable TCP BBR congestion control algorithm (Recommended)? [Y/n]: "
797+
if [ "$assume_yes" == 0 ]; then
798+
read answer < /dev/tty
799+
if [ "$answer" != "${answer#[Nn]}" ]; then
800+
_install_status 0 "(Skipped)"
801+
else
802+
_configure_tcp_bbr
803+
fi
804+
elif [ "${bbr_option}" == 1 ]; then
805+
_configure_tcp_bbr
806+
else
807+
echo "(Skipped)"
808+
fi
809+
}
810+
811+
function _configure_tcp_bbr() {
812+
echo "Checking kernel support for the TCP BBR algorithm..."
813+
_check_tcp_bbr_available
814+
if [ $? -eq 0 ]; then
815+
echo "TCP BBR option found. Enabling configuration"
816+
# Load the BBR module
817+
echo "Loading BBR kernel module"
818+
sudo modprobe tcp_bbr || _install_status 1 "Unable to execute modprobe tcp_bbr"
819+
# Add BBR configuration to sysctl.conf if not present
820+
echo "Adding BBR configuration to /etc/sysctl.conf if not present"
821+
if ! grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf; then
822+
echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf || _install_status 1 "Unable to modify /etc/sysctl.conf"
823+
fi
824+
if ! grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then
825+
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf || _install_status 1 "Unable to modify /etc/sysctl.conf"
826+
fi
827+
# Apply the sysctl changes
828+
echo "Applying changes"
829+
sudo sysctl -p || _install_status 1 "Unable to execute sysctl"
830+
831+
# Verify if BBR is enabled
832+
cc=$(sysctl net.ipv4.tcp_congestion_control | awk '{print $3}')
833+
if [ "$cc" == "bbr" ]; then
834+
echo "TCP BBR successfully enabled"
835+
else
836+
_install_status 1 "Failed to enable TCP BBR"
837+
fi
838+
else
839+
_install_status 2 "TCP BBR option is not available (Skipped)"
840+
fi
841+
_install_status 0
842+
}
843+
844+
function _check_tcp_bbr_available() {
845+
config_file="/boot/config-$(uname -r)"
846+
if grep -q 'CONFIG_TCP_CONG_BBR' "$config_file" && grep -q 'CONFIG_NET_SCH_FQ' "$config_file"; then
847+
return 0
848+
else
849+
return 1
850+
fi
851+
}
852+
791853
# Add sudoers file to /etc/sudoers.d/ and set file permissions
792854
function _patch_system_files() {
793855

installers/raspbian.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ OPTIONS:
4444
-a, --adblock <flag> Used with -y, --yes, sets Adblock install option (0=no install)
4545
-w, --wireguard <flag> Used with -y, --yes, sets WireGuard install option (0=no install)
4646
-e, --provider <value> Used with -y, --yes, sets the VPN provider install option
47+
-g, --tcp-bbr <value> Used with -y, --yes, sets the TCP BBR congestion control algorithm option
4748
-r, --repo, --repository <name> Overrides the default GitHub repo (RaspAP/raspap-webgui)
4849
-b, --branch <name> Overrides the default git branch (latest release)
4950
-t, --token <accesstoken> Specify a GitHub token to access a private repository
@@ -129,6 +130,10 @@ function _parse_params() {
129130
pv_option="$2"
130131
shift
131132
;;
133+
-g|--tcp-bbr)
134+
bbr_option="$2"
135+
shift
136+
;;
132137
-c|--cert|--certificate)
133138
install_cert=1
134139
;;

0 commit comments

Comments
 (0)