From b6358f99ff3ce22fbffe02863d7ff969f97fc85f Mon Sep 17 00:00:00 2001 From: stickz Date: Sat, 22 Apr 2023 23:28:59 -0400 Subject: [PATCH] Move to swizzin.conf file This commit adds a feature to enable the BBR congestion control algorithm. This increases throughput of TCP connections thanks to clever engineering by Google. --- README.md | 5 +++++ setup.sh | 51 ++++++++++++++++++++++++++++++++++++++++++ unattended.example.env | 4 +++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 311c8ce1a..b43f7bbe1 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,11 @@ Want to specify the user and their password? And the packages to have installed? bash <(curl -sL git.io/swizzin) --unattend qbittorrent nginx panel --user tester --pass test1234 ``` +Want to enable BBR Congestion Control for increased TCP throughput? Use the `--enablebbr` flag on your supported or default configuration! Optionally, combine it with the `--unattend`, `--user` and `--pass` flags above for automated setup! +```bash +bash <(curl -sL git.io/swizzin) --enablebbr +``` + Want something a bit more complex, specify package install variables, don't want a super long command to type, and store the configuration? Use the `--env` flag with your custom `env` file! (see the [unattended.example.env](unattended.example.env) file for an example) ```bash bash <(curl -sL git.io/swizzin) --env /path/to/your/env/file/here.env diff --git a/setup.sh b/setup.sh index 5d28066ec..3097b89e3 100755 --- a/setup.sh +++ b/setup.sh @@ -110,6 +110,10 @@ function _option_parse() { rmgrsec=yes echo_info "OVH Kernel nuke = $rmgrsec" ;; + --enablebbr) + enablebbr=true + echo_info "Enable BBR = $enablebbr" + ;; --env) shift if [[ ! -f $1 ]]; then @@ -221,6 +225,52 @@ function _preparation() { echo } +function _checkbbr() { + # If bbr is enabled through unattended setup mark it as enabled + if [[ -n $BBR_CONGESTION_CONTROL ]]; then + [[ $BBR_CONGESTION_CONTROL = "yes" ]] && enablebbr=true + fi + # If bbr is already running on the operating system, skip checks and exit function + local old_cc=$(sysctl net.ipv4.tcp_congestion_control | grep -c bbr) + if [[ $old_cc -ge 1 ]]; then + echo_info "BBR Congestion Control is already enabled, skipping BBR" + return 0 + fi + # if sysctl.conf has already defined a cc or qdisc, skip checks and exit function + local sysctl_cc=$(grep -c net.ipv4.tcp_congestion_control /etc/sysctl.conf) + local sysctl_qdisc=$(grep -c net.core.default_qdisc /etc/sysctl.conf) + if [[ $sysctl_cc -ge 1 ]] || [[ $sysctl_qdisc -ge 1 ]]; then + echo_info "sysctl.conf has conflicting options, skipping BBR" + return 0 + fi + # If bbr is not supported by the linux kernel, skip checks and exit function + modprobe tcp_bbr >> $log 2>&1 + local availible_cc=$(sysctl net.ipv4.tcp_available_congestion_control | grep -c bbr) + if [[ $availible_cc -le 0 ]]; then + echo_info "Linux Kernel does not support BBR Congestion Control, skipping BBR" + return 0 + fi + # If fq is not supported by the linux kernel, skip checks and exit function + local availible_fq=$(grep -c CONFIG_NET_SCH_FQ= /boot/config-$(uname -r)) + if [[ $availible_fq -le 0 ]]; then + echo_info "Linux Kernel does not support Fair Queue Scheduler, skipping BBR" + return 0 + fi + # If enablebbr was NOT set and we're not in unattended mode + if [[ $enablebbr != "true" ]] && [[ $unattend != "true" ]]; then + # Ask the user if they would like to enable bbr congestion control + if ask "Would you like to enable BBR congestion control for increased throughput?" Y; then + enablebbr=true + fi + fi + # If enablebbr is set then enable fq plus bbq and apply the changes + if [[ $enablebbr = "true" ]]; then + echo "net.core.default_qdisc=fq" >> /etc/sysctl.d/55-swizzin.conf + echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.d/55-swizzin.conf + sysctl --system >> $log 2>&1 + fi +} + #FYI code duplication from `box rmgrsec` function _nukeovh() { bash /etc/swizzin/scripts/nukeovh @@ -404,6 +454,7 @@ _run_post() { _os _preparation +_checkbbr ## If install is attended, do the nice intro if [[ $unattend != "true" ]]; then if [[ -z "$user" ]] && [[ -z "$pass" ]]; then # If password AND username are empty diff --git a/unattended.example.env b/unattended.example.env index 00b90e4d9..5bbfdcc96 100644 --- a/unattended.example.env +++ b/unattended.example.env @@ -7,6 +7,8 @@ pass=test123 ## packages to install separated by colons. packages=nginx:panel:transmission:letsencrypt +## Enable BBR congestion control for increased TCP throughput +BBR_CONGESTION_CONTROL=yes # PACKAGE SPECIFIC OPTIONS @@ -25,4 +27,4 @@ LE_DEFAULTCONF=yes # LE_BOOL_CF=no if you don't want to use any cloudflare LE_CF_API=aaapppiiiikkkeeeeeyyyyyyyy LE_CF_EMAIL="email@blach.lol" -LE_CF_ZONE="some.zone.asdasdasdasd" # or LE_CF_ZONEEXISTS=yes if you don't need it created \ No newline at end of file +LE_CF_ZONE="some.zone.asdasdasdasd" # or LE_CF_ZONEEXISTS=yes if you don't need it created