├── scripts ├── _redirects ├── mkdkmsconf.sh └── install_dkms.sh ├── logo.png ├── .github └── workflows │ ├── scripts.yml │ └── release.yml ├── Makefile ├── example ├── client.py └── server.py ├── README.zh.md ├── README.md ├── .gitignore ├── brutal.c └── LICENSE /scripts/_redirects: -------------------------------------------------------------------------------- 1 | / /install_dkms.sh 301 -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apernet/tcp-brutal/HEAD/logo.png -------------------------------------------------------------------------------- /scripts/mkdkmsconf.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | pkgver() { 6 | if git describe --tags >/dev/null 2>&1; then 7 | git describe --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' 8 | else 9 | printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" 10 | fi 11 | } 12 | 13 | PACKAGE_VERSION=${PACKAGE_VERSION:-$(pkgver)} 14 | 15 | cat << EOF 16 | PACKAGE_NAME="tcp-brutal" 17 | PACKAGE_VERSION="$PACKAGE_VERSION" 18 | 19 | MAKE[0]="make KERNEL_DIR=\${kernel_source_dir} all" 20 | CLEAN="make KERNEL_DIR=\${kernel_source_dir} clean" 21 | 22 | BUILT_MODULE_NAME[0]="brutal" 23 | DEST_MODULE_LOCATION[0]="/extra" 24 | 25 | AUTOINSTALL="yes" 26 | EOF 27 | -------------------------------------------------------------------------------- /.github/workflows/scripts.yml: -------------------------------------------------------------------------------- 1 | name: "Publish scripts" 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | paths: 8 | - scripts/** 9 | 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | permissions: 14 | contents: read 15 | deployments: write 16 | name: Publish scripts to Cloudflare Pages 17 | steps: 18 | - name: Check out 19 | uses: actions/checkout@v4 20 | 21 | - name: Publish to Cloudflare Pages 22 | uses: cloudflare/pages-action@v1 23 | with: 24 | apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} 25 | accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} 26 | projectName: tcpbrutalscripts 27 | directory: scripts 28 | gitHubToken: ${{ secrets.GITHUB_TOKEN }} 29 | branch: main -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: "Build release" 2 | 3 | on: 4 | push: 5 | tags: 6 | - v*.*.* 7 | 8 | jobs: 9 | build: 10 | name: Build 11 | runs-on: ubuntu-latest 12 | env: 13 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true 14 | 15 | steps: 16 | - name: Check out 17 | uses: actions/checkout@v4 18 | 19 | - name: Run build script 20 | run: | 21 | make dkms-tarball 22 | mkdir -p build/ 23 | mv dkms.tar.gz build/tcp-brutal.dkms.tar.gz 24 | 25 | - name: Generate hashes 26 | run: | 27 | for file in build/*; do 28 | sha256sum $file >> build/hashes.txt 29 | done 30 | 31 | - name: Upload GitHub 32 | uses: softprops/action-gh-release@v1 33 | with: 34 | files: build/* 35 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | KERNEL_RELEASE ?= $(shell uname -r) 2 | KERNEL_DIR ?= /lib/modules/$(KERNEL_RELEASE)/build 3 | DKMS_TARBALL ?= dkms.tar.gz 4 | TAR ?= tar 5 | obj-m += brutal.o 6 | 7 | ccflags-y := -std=gnu99 8 | 9 | .PHONY: all clean load unload 10 | .PHONY: .always-make 11 | 12 | all: 13 | $(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules 14 | 15 | clean: clean-dkms.conf clean-dkms-tarball 16 | $(MAKE) -C $(KERNEL_DIR) M=$(PWD) clean 17 | 18 | load: 19 | sudo insmod brutal.ko 20 | 21 | unload: 22 | sudo rmmod brutal 23 | 24 | .PHONY: dkms-tarball clean-dkms-tarball clean-dkms.conf 25 | 26 | .always.make: 27 | 28 | dkms.conf: ./scripts/mkdkmsconf.sh .always-make 29 | ./scripts/mkdkmsconf.sh > dkms.conf 30 | 31 | clean-dkms.conf: 32 | $(RM) dkms.conf 33 | 34 | $(DKMS_TARBALL): dkms.conf Makefile brutal.c 35 | $(TAR) zcf $(DKMS_TARBALL) \ 36 | --transform 's,^,./dkms_source_tree/,' \ 37 | dkms.conf \ 38 | Makefile \ 39 | brutal.c 40 | 41 | dkms-tarball: $(DKMS_TARBALL) 42 | 43 | clean-dkms-tarball: 44 | $(RM) $(DKMS_TARBALL) 45 | -------------------------------------------------------------------------------- /example/client.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import time 3 | import argparse 4 | 5 | DEFAULT_PORT = 65432 6 | DEFAULT_BUFFER_SIZE = 65536 7 | 8 | 9 | def main(host, port, buf_size, rate_mbps): 10 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 11 | s.connect((host, port)) 12 | print(f"Connected to {host}:{port}") 13 | 14 | # Send the rate to the server 15 | s.sendall(rate_mbps.to_bytes(4, byteorder="big")) 16 | 17 | counter = 0 18 | start_time = time.time() 19 | 20 | try: 21 | while True: 22 | data = s.recv(buf_size) 23 | if not data: 24 | break 25 | 26 | counter += len(data) 27 | 28 | current_time = time.time() 29 | if current_time - start_time >= 1: 30 | speed_mbps = ( 31 | (counter * 8) / (1000 * 1000) / (current_time - start_time) 32 | ) 33 | print(f"Current speed: {speed_mbps:.2f} Mbps") 34 | counter = 0 35 | start_time = current_time 36 | 37 | except KeyboardInterrupt: 38 | print("\nInterrupted by user") 39 | 40 | except Exception as e: 41 | print(f"Error: {e}") 42 | 43 | 44 | if __name__ == "__main__": 45 | parser = argparse.ArgumentParser(description="TCP Brutal example client") 46 | parser.add_argument("host", help="Server host", type=str) 47 | parser.add_argument("rate_mbps", help="Rate in Mbps", type=int) 48 | parser.add_argument( 49 | "-p", 50 | "--port", 51 | help="Server port", 52 | type=int, 53 | default=DEFAULT_PORT, 54 | ) 55 | parser.add_argument( 56 | "-b", 57 | "--buffer", 58 | help="Buffer size", 59 | type=int, 60 | default=DEFAULT_BUFFER_SIZE, 61 | ) 62 | args = parser.parse_args() 63 | 64 | main(args.host, args.port, args.buffer, args.rate_mbps) 65 | -------------------------------------------------------------------------------- /example/server.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import struct 3 | import threading 4 | import time 5 | import argparse 6 | 7 | TCP_CONGESTION = 13 8 | TCP_BRUTAL_PARAMS = 23301 9 | 10 | DEFAULT_PORT = 65432 11 | DEFAULT_BUFFER_SIZE = 65536 12 | 13 | 14 | def client_thread(conn, addr, duration, buffer_size, rate): 15 | print(f"Connected by {addr}") 16 | start_time = time.time() 17 | 18 | cwnd_gain = 15 19 | brutal_params_value = struct.pack("QI", rate, cwnd_gain) 20 | conn.setsockopt(socket.IPPROTO_TCP, TCP_BRUTAL_PARAMS, brutal_params_value) 21 | 22 | try: 23 | while time.time() - start_time < duration: 24 | data = bytearray(buffer_size) 25 | conn.sendall(data) 26 | except Exception as e: 27 | print(f"Error sending data: {e}") 28 | finally: 29 | conn.close() 30 | print(f"Disconnected {addr}") 31 | 32 | 33 | def main(): 34 | parser = argparse.ArgumentParser( 35 | description="TCP Brutal example server", 36 | ) 37 | parser.add_argument( 38 | "-l", "--listen", type=str, default="", help="Address to listen on" 39 | ) 40 | parser.add_argument( 41 | "-p", "--port", type=int, default=DEFAULT_PORT, help="Port to listen on" 42 | ) 43 | parser.add_argument( 44 | "-d", "--duration", type=int, default=10, help="Send duration in seconds" 45 | ) 46 | parser.add_argument( 47 | "-b", 48 | "--buffer-size", 49 | type=int, 50 | default=DEFAULT_BUFFER_SIZE, 51 | help="Buffer size", 52 | ) 53 | 54 | args = parser.parse_args() 55 | 56 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 57 | s.setsockopt(socket.IPPROTO_TCP, TCP_CONGESTION, "brutal".encode()) 58 | s.bind((args.listen, args.port)) 59 | s.listen() 60 | 61 | print(f"Server listening on {args.listen}:{args.port}") 62 | 63 | try: 64 | while True: 65 | conn, addr = s.accept() 66 | 67 | rate_bytes = conn.recv(4) 68 | if not rate_bytes: 69 | conn.close() 70 | continue 71 | 72 | rate = struct.unpack("!I", rate_bytes)[0] 73 | rate = int(rate * 1000 * 1000 / 8) # Convert Mbps to bytes per second 74 | 75 | thread = threading.Thread( 76 | target=client_thread, 77 | args=(conn, addr, args.duration, args.buffer_size, rate), 78 | ) 79 | thread.start() 80 | except KeyboardInterrupt: 81 | print("\nServer is shutting down.") 82 | 83 | 84 | if __name__ == "__main__": 85 | main() 86 | -------------------------------------------------------------------------------- /README.zh.md: -------------------------------------------------------------------------------- 1 | # ![TCP Brutal](logo.png) 2 | 3 | TCP Brutal 是 [Hysteria](https://hysteria.network/) 中的同名拥塞控制算法移植到 TCP 的版本,作为一个 Linux 内核模块。关于 Brutal 本身的信息,可以在 [Hysteria 文档](https://hysteria.network/zh/docs/advanced/Full-Server-Config/#_6)中找到。作为 Hysteria 官方子项目,TCP Brutal 会保持与 Hysteria 中的 Brutal 同步更新。 4 | 5 | ## 用户指南 6 | 7 | 安装脚本: 8 | 9 | ```bash 10 | bash <(curl -fsSL https://tcp.hy2.sh/) 11 | ``` 12 | 13 | 手动编译并加载: 14 | 15 | ```bash 16 | # 确保安装了内核头文件 17 | # Ubuntu: apt install linux-headers-$(uname -r) 18 | make && make load 19 | ``` 20 | 21 | > 需要内核版本 4.9 或以上,推荐使用 5.8 以上的内核。**对于小于 5.8 的内核, 只支持 IPv4。** [(缺导出符号 `tcpv6_prot`)](https://github.com/torvalds/linux/commit/6abde0b241224347cd88e2ae75902e07f55c42cb#diff-8b341e52e57c996bc4f294087ab526ac0b1c3c47e045557628cc24277cbfda0dR2124) 22 | > 23 | > **⚠️ 注意** 对于内核版本低于 4.13 的系统,必须手动开启 fq pacing (`tc qdisc add dev eth0 root fq pacing`) 否则 TCP Brutal 无法正常工作。 24 | 25 | ### 需要新协议吗? 26 | 27 | 不需要。TCP Brutal 支持一切已有的 TCP 代理协议,**但是需要代理客户端和服务端软件的支持**(以提供带宽设置选项,交换带宽信息等)。请向你使用的代理软件的作者请求适配。 28 | 29 | ### 测速 30 | 31 | [example](example) 目录中提供了一个 Python 的简单测速服务端+客户端。使用方法: 32 | 33 | ```bash 34 | # 服务端,监听在 TCP 1234 端口 35 | python server.py -p 1234 36 | 37 | # 客户端,连接到 example.com:1234,请求下载速度 50 Mbps 38 | python client.py -p 1234 example.com 50 39 | ``` 40 | 41 | ### 需要配置 sysctl 吗? / 能把 TCP Brutal 设置成系统默认的拥塞控制吗? 42 | 43 | 不需要也不能。与 BBR 不同,TCP Brutal 仅在应用程序对每个 TCP 连接设置带宽参数之后才能正常工作,绝大部分应用程序都不支持这个操作,将 TCP Brutal 设置成默认拥塞控制只会让系统的所有 TCP 连接降速到 1 Mbps。支持的应用程序会主动配置 TCP 连接使用 TCP Brutal 拥塞控制。 44 | 45 | ## 开发者指南 46 | 47 | 该内核模块向系统添加了一个新的 "brutal" TCP 拥塞控制算法,程序可以使用 TCP_CONGESTION sockopt 来启用。 48 | 49 | ```python 50 | s.setsockopt(socket.IPPROTO_TCP, TCP_CONGESTION, "brutal".encode()) 51 | ``` 52 | 53 | 设置发送速率和 CWND 增益(推荐默认值为 1.5 倍到 2 倍,需要表达为 15/20,因为内核不支持浮点数): 54 | 55 | ```c 56 | struct brutal_params 57 | { 58 | u64 rate; // 发送速率,以每秒字节数计 59 | u32 cwnd_gain; // CWND 增益,以十分之一为单位(10=1.0) 60 | } __packed; 61 | ``` 62 | 63 | ```python 64 | TCP_BRUTAL_PARAMS = 23301 65 | 66 | rate = 2000000 # 2 MB/s 67 | cwnd_gain = 15 68 | brutal_params_value = struct.pack("QI", rate, cwnd_gain) 69 | conn.setsockopt(socket.IPPROTO_TCP, TCP_BRUTAL_PARAMS, brutal_params_value) 70 | ``` 71 | 72 | ### 代理开发者须知(重要) 73 | 74 | 与 Hysteria 一样,Brutal 需要用户知道自己所处网络环境的带宽上限是多少。Hysteria 的协议从设计上就考虑了这一点,但目前现有的 TCP 代理协议中没有一个有在客户端与服务端之间交换带宽信息的机制,因此客户端无法告知服务端应该以多快的速度发送数据,反之亦然。 75 | 76 | 为了解决这个问题,我们建议利用所有代理协议中都存在的 "目标地址" 字段。支持 TCP Brutal 的客户端和服务端可以使用一个特殊的地址(例如 `_BrutalBwExchange`)来表示他们希望交换带宽信息。例如,客户端可以发起一个 `_BrutalBwExchange` 连接请求,如果服务端接受,就通过这个连接和服务端交换各自的带宽信息。 77 | 78 | 以下链接是 sing-box 的实现: 79 | 80 | 81 | 82 | 另外需要注意的是,sockopt 设置的是每个连接的速度。**这意味着其只适用于支持多路复用(mux)的协议,因为多路复用让客户端可以将所有代理连接整合到一个 TCP 连接中传输。** 对于需要为每个代理连接单独建立连接的协议,当同时有多个连接活跃时,使用 TCP Brutal 会导致总发送速率超过所设置的上限。 83 | 84 | ### 兼容性 85 | 86 | TCP Brutal 只是 TCP 的拥塞控制算法,并不修改 TCP 协议本身。客户端和服务端可以只有单边安装内核模块。拥塞控制算法控制的是数据的发送,而考虑到代理用户通常下载的数据量远大于上传,只在服务端使用 TCP Brutal 就可以获得大部分的收益。(客户端使用 TCP Brutal 可以获得更好的上传速度,但很多人使用的是 Windows, macOS 或手机,安装内核模块往往不现实。) 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![TCP Brutal](logo.png) 2 | 3 | TCP Brutal is [Hysteria](https://hysteria.network/)'s congestion control algorithm ported to TCP, as a Linux kernel module. Information about Brutal itself can be found in the [Hysteria documentation](https://hysteria.network/docs/advanced/Full-Server-Config/#bandwidth-behavior-explained). As an official subproject of Hysteria, TCP Brutal is actively maintained to be in sync with the Brutal implementation in Hysteria. 4 | 5 | **中文文档:[README.zh.md](README.zh.md)** 6 | 7 | ## For users 8 | 9 | Installation script: 10 | 11 | ```bash 12 | bash <(curl -fsSL https://tcp.hy2.sh/) 13 | ``` 14 | 15 | Manual compilation and loading: 16 | 17 | ```bash 18 | # Make sure kernel headers are installed 19 | # Ubuntu: apt install linux-headers-$(uname -r) 20 | make && make load 21 | ``` 22 | 23 | > Kernel version 4.9 or later is required, version 5.8 or later is recommended. **If your kernel version is earlier than 5.8, only IPv4 is supported.** [(lack of exported symbol `tcpv6_prot`)](https://github.com/torvalds/linux/commit/6abde0b241224347cd88e2ae75902e07f55c42cb#diff-8b341e52e57c996bc4f294087ab526ac0b1c3c47e045557628cc24277cbfda0dR2124) 24 | > 25 | > **⚠️ Warning** For systems with kernel versions lower than 4.13, you MUST manually enable fq pacing (`tc qdisc add dev eth0 root fq pacing`), otherwise TCP Brutal will not work properly. 26 | 27 | ### Do I need a new proxy protocol? 28 | 29 | No. TCP Brutal supports all existing TCP proxy protocols, **but requires support from both the client and server software** (to provide bandwidth options, exchange bandwidth information, etc.). Ask the developers of the proxy software you use to add support. 30 | 31 | ### Speed test 32 | 33 | The [example](example) directory contains a simple speed test server+client in Python. Usage: 34 | 35 | ```bash 36 | # Server, listening on TCP port 1234 37 | python server.py -p 1234 38 | 39 | # Client, connect to example.com:1234, request download speed of 50 Mbps 40 | python client.py -p 1234 example.com 50 41 | ``` 42 | 43 | ### Do I need to configure sysctl? / Can I set TCP Brutal as the system's default congestion control? 44 | 45 | You don't need to, and shouldn't. Unlike BBR, TCP Brutal can only work properly if the program sets the bandwidth using a special sockopt, which most programs don't support unless otherwise specified. Setting it as the default congestion control would slow down all connections to 1 Mbps. Programs that do support it will actively switch to using TCP Brutal congestion control on their own. 46 | 47 | ## For developers 48 | 49 | This kernel module adds a new "brutal" TCP congestion control algorithm to the system, which programs can enable using TCP_CONGESTION sockopt. 50 | 51 | ```python 52 | s.setsockopt(socket.IPPROTO_TCP, TCP_CONGESTION, "brutal".encode()) 53 | ``` 54 | 55 | To set the send rate and congestion window gain (we recommend a default value of 1.5x to 2x, which is expressed as 15/20 since the kernel doesn't support floating point): 56 | 57 | ```c 58 | struct brutal_params 59 | { 60 | u64 rate; // Send rate in bytes per second 61 | u32 cwnd_gain; // CWND gain in tenths (10=1.0) 62 | } __packed; 63 | ``` 64 | 65 | ```python 66 | TCP_BRUTAL_PARAMS = 23301 67 | 68 | rate = 2000000 # 2 MB/s 69 | cwnd_gain = 15 70 | brutal_params_value = struct.pack("QI", rate, cwnd_gain) 71 | conn.setsockopt(socket.IPPROTO_TCP, TCP_BRUTAL_PARAMS, brutal_params_value) 72 | ``` 73 | 74 | ### For proxy developers (important) 75 | 76 | Like Hysteria, Brutal is designed for environments where the user knows the bandwidth of their connection, as this information is essential for Brutal to work. While Hysteria's protocol is designed with this in mind, none of the existing TCP proxy protocols (at the time of this writing) have such a mechanism for exchanging bandwidth information between client and server, so that a client can tell the server how fast it should send and vice versa. 77 | 78 | To work around this, we suggest using the "destination address" field, which every proxy protocol has in one form or another. Clients and servers supporting TCP Brutal can use a special address (e.g. `_BrutalBwExchange`) to indicate that they want to exchange bandwidth information. For example, the client can create a `_BrutalBwExchange` connection request and, if the server accepts, use that connection to exchange bandwidth information with the server. 79 | 80 | The following link shows how this is implemented in sing-box: 81 | 82 | 83 | 84 | An important aspect to understand about TCP Brutal's rate setting is that it applies to each individual connection. **This makes it suitable only for protocols that support multiplexing (mux), which allows a client to consolidate all proxy connections into a single TCP connection.** For protocols that require a separate connection for each proxy connection, using TCP Brutal will overwhelm the receiver if multiple connections are active at the same time. 85 | 86 | ### Compatibility 87 | 88 | TCP Brutal is only a congestion control algorithm for TCP and does not alter the TCP protocol itself. Clients and servers can use TCP Brutal unilaterally. The congestion control algorithm controls the sending of data, and since proxy users typically download far more data than they upload, implementing TCP Brutal on the server side alone can reap most of the benefits. (Clients using TCP Brutal could achieve better upload speeds, but many users are on Windows, MacOS, or phones where installing kernel modules is impractical). 89 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/windows,linux,macos,visualstudiocode,clion+all,c++,c 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=windows,linux,macos,visualstudiocode,clion+all,c++,c 3 | 4 | ### C ### 5 | # Prerequisites 6 | *.d 7 | 8 | # Object files 9 | *.o 10 | *.ko 11 | *.obj 12 | *.elf 13 | 14 | # Linker output 15 | *.ilk 16 | *.map 17 | *.exp 18 | 19 | # Precompiled Headers 20 | *.gch 21 | *.pch 22 | 23 | # Libraries 24 | *.lib 25 | *.a 26 | *.la 27 | *.lo 28 | 29 | # Shared objects (inc. Windows DLLs) 30 | *.dll 31 | *.so 32 | *.so.* 33 | *.dylib 34 | 35 | # Executables 36 | *.exe 37 | *.out 38 | *.app 39 | *.i*86 40 | *.x86_64 41 | *.hex 42 | 43 | # Debug files 44 | *.dSYM/ 45 | *.su 46 | *.idb 47 | *.pdb 48 | 49 | # Kernel Module Compile Results 50 | *.mod* 51 | *.cmd 52 | .tmp_versions/ 53 | modules.order 54 | Module.symvers 55 | Mkfile.old 56 | dkms.conf 57 | 58 | ### C++ ### 59 | # Prerequisites 60 | 61 | # Compiled Object files 62 | *.slo 63 | 64 | # Precompiled Headers 65 | 66 | # Compiled Dynamic libraries 67 | 68 | # Fortran module files 69 | *.mod 70 | *.smod 71 | 72 | # Compiled Static libraries 73 | *.lai 74 | 75 | # Executables 76 | 77 | ### CLion+all ### 78 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 79 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 80 | 81 | # User-specific stuff 82 | .idea/**/workspace.xml 83 | .idea/**/tasks.xml 84 | .idea/**/usage.statistics.xml 85 | .idea/**/dictionaries 86 | .idea/**/shelf 87 | 88 | # AWS User-specific 89 | .idea/**/aws.xml 90 | 91 | # Generated files 92 | .idea/**/contentModel.xml 93 | 94 | # Sensitive or high-churn files 95 | .idea/**/dataSources/ 96 | .idea/**/dataSources.ids 97 | .idea/**/dataSources.local.xml 98 | .idea/**/sqlDataSources.xml 99 | .idea/**/dynamic.xml 100 | .idea/**/uiDesigner.xml 101 | .idea/**/dbnavigator.xml 102 | 103 | # Gradle 104 | .idea/**/gradle.xml 105 | .idea/**/libraries 106 | 107 | # Gradle and Maven with auto-import 108 | # When using Gradle or Maven with auto-import, you should exclude module files, 109 | # since they will be recreated, and may cause churn. Uncomment if using 110 | # auto-import. 111 | # .idea/artifacts 112 | # .idea/compiler.xml 113 | # .idea/jarRepositories.xml 114 | # .idea/modules.xml 115 | # .idea/*.iml 116 | # .idea/modules 117 | # *.iml 118 | # *.ipr 119 | 120 | # CMake 121 | cmake-build-*/ 122 | 123 | # Mongo Explorer plugin 124 | .idea/**/mongoSettings.xml 125 | 126 | # File-based project format 127 | *.iws 128 | 129 | # IntelliJ 130 | out/ 131 | 132 | # mpeltonen/sbt-idea plugin 133 | .idea_modules/ 134 | 135 | # JIRA plugin 136 | atlassian-ide-plugin.xml 137 | 138 | # Cursive Clojure plugin 139 | .idea/replstate.xml 140 | 141 | # SonarLint plugin 142 | .idea/sonarlint/ 143 | 144 | # Crashlytics plugin (for Android Studio and IntelliJ) 145 | com_crashlytics_export_strings.xml 146 | crashlytics.properties 147 | crashlytics-build.properties 148 | fabric.properties 149 | 150 | # Editor-based Rest Client 151 | .idea/httpRequests 152 | 153 | # Android studio 3.1+ serialized cache file 154 | .idea/caches/build_file_checksums.ser 155 | 156 | ### CLion+all Patch ### 157 | # Ignore everything but code style settings and run configurations 158 | # that are supposed to be shared within teams. 159 | 160 | .idea/* 161 | 162 | !.idea/codeStyles 163 | !.idea/runConfigurations 164 | 165 | ### Linux ### 166 | *~ 167 | 168 | # temporary files which can be created if a process still has a handle open of a deleted file 169 | .fuse_hidden* 170 | 171 | # KDE directory preferences 172 | .directory 173 | 174 | # Linux trash folder which might appear on any partition or disk 175 | .Trash-* 176 | 177 | # .nfs files are created when an open file is removed but is still being accessed 178 | .nfs* 179 | 180 | ### macOS ### 181 | # General 182 | .DS_Store 183 | .AppleDouble 184 | .LSOverride 185 | 186 | # Icon must end with two \r 187 | Icon 188 | 189 | 190 | # Thumbnails 191 | ._* 192 | 193 | # Files that might appear in the root of a volume 194 | .DocumentRevisions-V100 195 | .fseventsd 196 | .Spotlight-V100 197 | .TemporaryItems 198 | .Trashes 199 | .VolumeIcon.icns 200 | .com.apple.timemachine.donotpresent 201 | 202 | # Directories potentially created on remote AFP share 203 | .AppleDB 204 | .AppleDesktop 205 | Network Trash Folder 206 | Temporary Items 207 | .apdisk 208 | 209 | ### macOS Patch ### 210 | # iCloud generated files 211 | *.icloud 212 | 213 | ### VisualStudioCode ### 214 | .vscode/* 215 | !.vscode/settings.json 216 | !.vscode/tasks.json 217 | !.vscode/launch.json 218 | !.vscode/extensions.json 219 | !.vscode/*.code-snippets 220 | 221 | # Local History for Visual Studio Code 222 | .history/ 223 | 224 | # Built Visual Studio Code Extensions 225 | *.vsix 226 | 227 | ### VisualStudioCode Patch ### 228 | # Ignore all local history of files 229 | .history 230 | .ionide 231 | 232 | ### Windows ### 233 | # Windows thumbnail cache files 234 | Thumbs.db 235 | Thumbs.db:encryptable 236 | ehthumbs.db 237 | ehthumbs_vista.db 238 | 239 | # Dump file 240 | *.stackdump 241 | 242 | # Folder config file 243 | [Dd]esktop.ini 244 | 245 | # Recycle Bin used on file shares 246 | $RECYCLE.BIN/ 247 | 248 | # Windows Installer files 249 | *.cab 250 | *.msi 251 | *.msix 252 | *.msm 253 | *.msp 254 | 255 | # Windows shortcuts 256 | *.lnk 257 | 258 | # End of https://www.toptal.com/developers/gitignore/api/windows,linux,macos,visualstudiocode,clion+all,c++,c 259 | 260 | /dkms.conf 261 | /dkms.tar.gz 262 | -------------------------------------------------------------------------------- /brutal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #if IS_ENABLED(CONFIG_IPV6) && LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) 7 | #include 8 | #else 9 | #warning IPv6 support is disabled. Brutal will only work with IPv4. \ 10 | Please ensure you have enabled CONFIG_IPV6 in your kernel config \ 11 | and your kernel version is greater than 5.8. 12 | #endif 13 | 14 | #define INIT_PACING_RATE 125000 // 1 Mbps 15 | #define INIT_CWND_GAIN 20 16 | 17 | #define MIN_PACING_RATE 62500 // 500 Kbps 18 | #define MIN_CWND_GAIN 5 19 | #define MAX_CWND_GAIN 80 20 | #define MIN_CWND 4 21 | 22 | #ifndef ICSK_CA_PRIV_SIZE 23 | #error "ICSK_CA_PRIV_SIZE not defined" 24 | #else 25 | // This is the size of the private data area in struct inet_connection_sock 26 | // The size varies between Linux versions 27 | // We use it to calculate the number of slots in the packet info array 28 | #define RAW_PKT_INFO_SLOTS ((ICSK_CA_PRIV_SIZE - 2 * sizeof(u64)) / sizeof(struct brutal_pkt_info)) 29 | #define PKT_INFO_SLOTS (RAW_PKT_INFO_SLOTS < 3 ? 3 : (RAW_PKT_INFO_SLOTS > 5 ? 5 : RAW_PKT_INFO_SLOTS)) 30 | #endif 31 | 32 | #define MIN_PKT_INFO_SAMPLES 50 33 | #define MIN_ACK_RATE_PERCENT 80 34 | 35 | #define TCP_BRUTAL_PARAMS 23301 36 | 37 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) 38 | static u64 tcp_sock_get_sec(const struct tcp_sock *tp) 39 | { 40 | return div_u64(tp->tcp_mstamp, USEC_PER_SEC); 41 | } 42 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) 43 | // see https://github.com/torvalds/linux/commit/9a568de4818dea9a05af141046bd3e589245ab83 44 | static u64 tcp_sock_get_sec(const struct tcp_sock *tp) 45 | { 46 | return div_u64(tp->tcp_mstamp.stamp_us, USEC_PER_SEC); 47 | } 48 | #else 49 | #include 50 | static u64 tcp_sock_get_sec(const struct tcp_sock *tp) 51 | { 52 | return div_u64(jiffies_to_usecs(tcp_time_stamp), USEC_PER_SEC); 53 | } 54 | #endif 55 | 56 | struct brutal_pkt_info 57 | { 58 | u64 sec; 59 | u32 acked; 60 | u32 losses; 61 | }; 62 | 63 | struct brutal 64 | { 65 | u64 rate; 66 | u32 cwnd_gain; 67 | 68 | struct brutal_pkt_info slots[PKT_INFO_SLOTS]; 69 | }; 70 | 71 | struct brutal_params 72 | { 73 | u64 rate; // Send rate in bytes per second 74 | u32 cwnd_gain; // CWND gain in tenths (10=1.0) 75 | } __packed; 76 | 77 | static struct proto tcp_prot_override __ro_after_init; 78 | #ifdef _TRANSP_V6_H 79 | static struct proto tcpv6_prot_override __ro_after_init; 80 | #endif // _TRANSP_V6_H 81 | 82 | #ifdef _LINUX_SOCKPTR_H 83 | static int brutal_set_params(struct sock *sk, sockptr_t optval, unsigned int optlen) 84 | #else 85 | static int brutal_set_params(struct sock *sk, char __user *optval, unsigned int optlen) 86 | #endif 87 | { 88 | struct brutal *brutal = inet_csk_ca(sk); 89 | struct brutal_params params; 90 | 91 | if (optlen < sizeof(params)) 92 | return -EINVAL; 93 | 94 | #ifdef _LINUX_SOCKPTR_H 95 | if (copy_from_sockptr(¶ms, optval, sizeof(params))) 96 | return -EFAULT; 97 | #else 98 | if (copy_from_user(¶ms, optval, sizeof(params))) 99 | return -EFAULT; 100 | #endif 101 | 102 | // Sanity checks 103 | if (params.rate < MIN_PACING_RATE) 104 | return -EINVAL; 105 | if (params.cwnd_gain < MIN_CWND_GAIN || params.cwnd_gain > MAX_CWND_GAIN) 106 | return -EINVAL; 107 | 108 | brutal->rate = params.rate; 109 | brutal->cwnd_gain = params.cwnd_gain; 110 | 111 | return 0; 112 | } 113 | 114 | #ifdef _LINUX_SOCKPTR_H 115 | static int brutal_tcp_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, unsigned int optlen) 116 | #else 117 | static int brutal_tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval, unsigned int optlen) 118 | #endif 119 | { 120 | if (level == IPPROTO_TCP && optname == TCP_BRUTAL_PARAMS) 121 | return brutal_set_params(sk, optval, optlen); 122 | else 123 | return tcp_prot.setsockopt(sk, level, optname, optval, optlen); 124 | } 125 | 126 | #ifdef _TRANSP_V6_H 127 | #ifdef _LINUX_SOCKPTR_H 128 | static int brutal_tcpv6_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, unsigned int optlen) 129 | #else // _LINUX_SOCKPTR_H 130 | static int brutal_tcpv6_setsockopt(struct sock *sk, int level, int optname, char __user *optval, unsigned int optlen) 131 | #endif // _LINUX_SOCKPTR_H 132 | { 133 | if (level == IPPROTO_TCP && optname == TCP_BRUTAL_PARAMS) 134 | return brutal_set_params(sk, optval, optlen); 135 | else 136 | return tcpv6_prot.setsockopt(sk, level, optname, optval, optlen); 137 | } 138 | #endif // _TRANSP_V6_H 139 | 140 | static void brutal_init(struct sock *sk) 141 | { 142 | struct tcp_sock *tp = tcp_sk(sk); 143 | struct brutal *brutal = inet_csk_ca(sk); 144 | 145 | if (sk->sk_family == AF_INET) 146 | sk->sk_prot = &tcp_prot_override; 147 | #ifdef _TRANSP_V6_H 148 | else if (sk->sk_family == AF_INET6) 149 | sk->sk_prot = &tcpv6_prot_override; 150 | #endif // _TRANSP_V6_H 151 | else 152 | BUG(); // WTF? 153 | 154 | tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; 155 | 156 | brutal->rate = INIT_PACING_RATE; 157 | brutal->cwnd_gain = INIT_CWND_GAIN; 158 | 159 | memset(brutal->slots, 0, sizeof(brutal->slots)); 160 | 161 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) 162 | // Pacing is REQUIRED for Brutal to work, but Linux only has internal pacing after 4.13. 163 | // For kernels prior to 4.13, you MUST add fq pacing manually (e.g. "tc qdisc add dev eth0 root fq pacing") 164 | // or rate control will be broken. 165 | // See https://github.com/torvalds/linux/commit/218af599fa635b107cfe10acf3249c4dfe5e4123 for details. 166 | cmpxchg(&sk->sk_pacing_status, SK_PACING_NONE, SK_PACING_NEEDED); 167 | #endif 168 | } 169 | 170 | // Copied from tcp.h for compatibility reasons 171 | static inline u32 brutal_tcp_snd_cwnd(const struct tcp_sock *tp) 172 | { 173 | return tp->snd_cwnd; 174 | } 175 | 176 | // Copied from tcp.h for compatibility reasons 177 | static inline void brutal_tcp_snd_cwnd_set(struct tcp_sock *tp, u32 val) 178 | { 179 | WARN_ON_ONCE((int)val <= 0); 180 | tp->snd_cwnd = val; 181 | } 182 | 183 | static void brutal_update_rate(struct sock *sk) 184 | { 185 | struct tcp_sock *tp = tcp_sk(sk); 186 | struct brutal *brutal = inet_csk_ca(sk); 187 | 188 | u64 sec = tcp_sock_get_sec(tp); 189 | u64 min_sec = sec - PKT_INFO_SLOTS; 190 | u32 acked = 0, losses = 0; 191 | u32 ack_rate; // Scaled by 100 (100=1.00) as kernel doesn't support float 192 | u64 rate = brutal->rate; 193 | u32 cwnd; 194 | 195 | u32 mss = tp->mss_cache; 196 | u32 rtt_ms = (tp->srtt_us >> 3) / USEC_PER_MSEC; 197 | if (!rtt_ms) 198 | rtt_ms = 1; 199 | 200 | for (int i = 0; i < PKT_INFO_SLOTS; i++) 201 | { 202 | if (brutal->slots[i].sec >= min_sec) 203 | { 204 | acked += brutal->slots[i].acked; 205 | losses += brutal->slots[i].losses; 206 | } 207 | } 208 | if (acked + losses < MIN_PKT_INFO_SAMPLES) 209 | ack_rate = 100; 210 | else 211 | { 212 | ack_rate = acked * 100 / (acked + losses); 213 | if (ack_rate < MIN_ACK_RATE_PERCENT) 214 | ack_rate = MIN_ACK_RATE_PERCENT; 215 | } 216 | 217 | rate *= 100; 218 | rate = div_u64(rate, ack_rate); 219 | 220 | // The order here is chosen carefully to avoid overflow as much as possible 221 | cwnd = div_u64(rate, MSEC_PER_SEC); 222 | cwnd *= rtt_ms; 223 | cwnd /= mss; 224 | cwnd *= brutal->cwnd_gain; 225 | cwnd /= 10; 226 | cwnd = max_t(u32, cwnd, MIN_CWND); 227 | 228 | brutal_tcp_snd_cwnd_set(tp, min(cwnd, tp->snd_cwnd_clamp)); 229 | 230 | WRITE_ONCE(sk->sk_pacing_rate, min_t(u64, rate, READ_ONCE(sk->sk_max_pacing_rate))); 231 | } 232 | 233 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 10, 0) 234 | static void brutal_main(struct sock *sk, u32 ack, int flag, const struct rate_sample *rs) 235 | #else 236 | static void brutal_main(struct sock *sk, const struct rate_sample *rs) 237 | #endif 238 | { 239 | struct tcp_sock *tp = tcp_sk(sk); 240 | struct brutal *brutal = inet_csk_ca(sk); 241 | 242 | u64 sec; 243 | u32 slot; 244 | 245 | // Ignore invalid rate samples 246 | if (rs->delivered < 0 || rs->interval_us <= 0) 247 | return; 248 | 249 | sec = tcp_sock_get_sec(tp); 250 | div_u64_rem(sec, PKT_INFO_SLOTS, &slot); 251 | 252 | if (brutal->slots[slot].sec == sec) 253 | { 254 | // Current slot, update 255 | brutal->slots[slot].acked += rs->acked_sacked; 256 | brutal->slots[slot].losses += rs->losses; 257 | } 258 | else 259 | { 260 | // Uninitialized slot or slot expired 261 | brutal->slots[slot].sec = sec; 262 | brutal->slots[slot].acked = rs->acked_sacked; 263 | brutal->slots[slot].losses = rs->losses; 264 | } 265 | 266 | brutal_update_rate(sk); 267 | } 268 | 269 | static u32 brutal_undo_cwnd(struct sock *sk) 270 | { 271 | return brutal_tcp_snd_cwnd(tcp_sk(sk)); 272 | } 273 | 274 | static u32 brutal_ssthresh(struct sock *sk) 275 | { 276 | return tcp_sk(sk)->snd_ssthresh; 277 | } 278 | 279 | static struct tcp_congestion_ops tcp_brutal_ops = { 280 | .flags = TCP_CONG_NON_RESTRICTED, 281 | .name = "brutal", 282 | .owner = THIS_MODULE, 283 | .init = brutal_init, 284 | .cong_control = brutal_main, 285 | .undo_cwnd = brutal_undo_cwnd, 286 | .ssthresh = brutal_ssthresh, 287 | }; 288 | 289 | static int __init brutal_register(void) 290 | { 291 | BUILD_BUG_ON(sizeof(struct brutal) > ICSK_CA_PRIV_SIZE); 292 | BUILD_BUG_ON(PKT_INFO_SLOTS < 1); 293 | 294 | tcp_prot_override = tcp_prot; 295 | tcp_prot_override.setsockopt = brutal_tcp_setsockopt; 296 | 297 | #ifdef _TRANSP_V6_H 298 | tcpv6_prot_override = tcpv6_prot; 299 | tcpv6_prot_override.setsockopt = brutal_tcpv6_setsockopt; 300 | #endif // _TRANSP_V6_H 301 | 302 | return tcp_register_congestion_control(&tcp_brutal_ops); 303 | } 304 | 305 | static void __exit brutal_unregister(void) 306 | { 307 | tcp_unregister_congestion_control(&tcp_brutal_ops); 308 | } 309 | 310 | module_init(brutal_register); 311 | module_exit(brutal_unregister); 312 | 313 | MODULE_AUTHOR("Aperture Internet Laboratory"); 314 | MODULE_LICENSE("GPL"); 315 | MODULE_DESCRIPTION("TCP Brutal"); 316 | MODULE_VERSION("1.0.2"); 317 | -------------------------------------------------------------------------------- /scripts/install_dkms.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # install_dkms.sh - tcp-brutal dkms module install script 4 | # Try `install_dkms.sh --help` for usage. 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # Copyright (c) 2023 Aperture Internet Laboratory 8 | # 9 | 10 | set -e 11 | 12 | 13 | ### 14 | # SCRIPT CONFIGURATION 15 | ### 16 | 17 | # Command line arguments of this script 18 | SCRIPT_ARGS=("$@") 19 | 20 | # Initial URL & command of one-click script (for usage & logging) 21 | # TODO: change the link to real 22 | SCRIPT_INITIATOR_URL="https://tcp.hy2.sh" 23 | SCRIPT_INITIATOR_COMMAND="bash <(curl -fsSL $SCRIPT_INITIATOR_URL)" 24 | 25 | # URL of GitHub 26 | REPO_URL="https://github.com/apernet/tcp-brutal" 27 | 28 | # URL of Hysteria 2 API 29 | HY2_API_BASE_URL="https://api.hy2.io/v1" 30 | 31 | # curl command line flags. 32 | # To using a proxy, please specify ALL_PROXY in the environ variable, such like: 33 | # export ALL_PROXY=socks5h://192.0.2.1:1080 34 | CURL_FLAGS=(-L -f -q --retry 5 --retry-delay 10 --retry-max-time 60) 35 | 36 | DKMS_MODULE_NAME="tcp-brutal" 37 | KERNEL_MODULE_NAME="brutal" 38 | 39 | 40 | ### 41 | # AUTO DETECTED GLOBAL VARIABLE 42 | ### 43 | 44 | # Package manager 45 | PACKAGE_MANAGEMENT_INSTALL="${PACKAGE_MANAGEMENT_INSTALL:-}" 46 | 47 | 48 | ### 49 | # COMMAND REPLACEMENT & UTILITIES 50 | ### 51 | 52 | has_command() { 53 | local _command=$1 54 | 55 | type -P "$_command" > /dev/null 2>&1 56 | } 57 | 58 | curl() { 59 | command curl "${CURL_FLAGS[@]}" "$@" 60 | } 61 | 62 | mktemp() { 63 | command mktemp "$@" "/tmp/brutalinst.XXXXXXXXXX" 64 | } 65 | 66 | tput() { 67 | if has_command tput; then 68 | command tput "$@" 69 | fi 70 | } 71 | 72 | tred="$(tput setaf 1)" 73 | tgreen="$(tput setaf 2)" 74 | tyellow="$(tput setaf 3)" 75 | tblue="$(tput setaf 4)" 76 | taoi="$(tput setaf 6)" 77 | tbold="$(tput bold)" 78 | treset="$(tput sgr0)" 79 | 80 | is_run_from_fd() { 81 | has_prefix "$0" "/dev/" || has_prefix "$0" "/proc/" 82 | } 83 | 84 | script_name() { 85 | local _keep_dirname="$1" 86 | 87 | if is_run_from_fd; then 88 | echo "$SCRIPT_INITIATOR_COMMAND" 89 | return 90 | fi 91 | 92 | if ! has_prefix "$0" "." && [[ -z "$_keep_dirname" ]]; then 93 | basename "$0" 94 | return 95 | fi 96 | echo "$0" 97 | } 98 | 99 | note() { 100 | local _msg="$1" 101 | 102 | echo -e "$(script_name): ${tbold}note: $_msg${treset}" 103 | } 104 | 105 | warning() { 106 | local _msg="$1" 107 | 108 | echo -e "$(script_name): ${tyellow}warning: $_msg${treset}" 109 | } 110 | 111 | error() { 112 | local _msg="$1" 113 | 114 | echo -e "$(script_name): ${tred}error: $_msg${treset}" 115 | } 116 | 117 | has_prefix() { 118 | local _s="$1" 119 | local _prefix="$2" 120 | 121 | if [[ -z "$_prefix" ]]; then 122 | return 0 123 | fi 124 | 125 | if [[ -z "$_s" ]]; then 126 | return 1 127 | fi 128 | 129 | [[ "x$_s" != "x${_s#"$_prefix"}" ]] 130 | } 131 | 132 | show_argument_error_and_exit() { 133 | local _error_msg="$1" 134 | 135 | error "$_error_msg" 136 | echo "Try \"$(script_name) --help\" for usage." >&2 137 | exit 22 138 | } 139 | 140 | exec_sudo() { 141 | # exec sudo with configurable environ preserved. 142 | local _saved_ifs="$IFS" 143 | IFS=$'\n' 144 | local _preserved_env=( 145 | $(env | grep "^PACKAGE_MANAGEMENT_INSTALL=" || true) 146 | $(env | grep "^FORCE_\w*=" || true) 147 | ) 148 | IFS="$_saved_ifs" 149 | 150 | exec sudo env \ 151 | "${_preserved_env[@]}" \ 152 | "$@" 153 | } 154 | 155 | detect_package_manager() { 156 | if [[ -n "$PACKAGE_MANAGEMENT_INSTALL" ]]; then 157 | return 0 158 | fi 159 | 160 | if has_command apt; then 161 | apt update 162 | PACKAGE_MANAGEMENT_INSTALL='apt -y --no-install-recommends install' 163 | return 0 164 | fi 165 | 166 | if has_command dnf; then 167 | PACKAGE_MANAGEMENT_INSTALL='dnf -y install' 168 | return 0 169 | fi 170 | 171 | if has_command yum; then 172 | PACKAGE_MANAGEMENT_INSTALL='yum -y install' 173 | return 0 174 | fi 175 | 176 | if has_command zypper; then 177 | PACKAGE_MANAGEMENT_INSTALL='zypper install -y' 178 | return 0 179 | fi 180 | 181 | if has_command pacman; then 182 | PACKAGE_MANAGEMENT_INSTALL='pacman -Syu --noconfirm' 183 | return 0 184 | fi 185 | 186 | return 1 187 | } 188 | 189 | install_software() { 190 | local _package_name="$1" 191 | 192 | if ! detect_package_manager; then 193 | error "Supported package manager is not detected, please install the following package manually:" 194 | echo 195 | echo -e "\t* $_package_name" 196 | echo 197 | exit 65 198 | fi 199 | 200 | echo "Installing missing dependence '$_package_name' with '$PACKAGE_MANAGEMENT_INSTALL' ... " 201 | if $PACKAGE_MANAGEMENT_INSTALL "$_package_name"; then 202 | echo "ok" 203 | else 204 | error "Cannot install '$_package_name' with detected package manager, please install it manually." 205 | exit 65 206 | fi 207 | } 208 | 209 | install_linux_headers() { 210 | local _kernel_ver="$(uname -r)" 211 | 212 | echo "Try to install linux-headers for $_kernel_ver ... " 213 | 214 | if has_command pacman; then 215 | local _kernel_img="/lib/modules/$_kernel_ver/vmlinuz" 216 | if [[ ! -f "$_kernel_img" ]]; then 217 | error "Kernel image does not exist." 218 | note "If you are using a kernel installed by pacman, this usually caused by system upgrading without reboot." 219 | note "Please reboot your server and try again." 220 | return 2 221 | fi 222 | local _kernel_pkg=$(pacman -Qoq "$_kernel_img") 223 | if [[ -z "$_kernel_pkg" ]]; then 224 | error "Failed to detect kernel package." 225 | warning "It seems like you are NOT using a kernel that installed by pacman." 226 | return 2 227 | fi 228 | install_software "$_kernel_pkg-headers" 229 | elif has_command apt; then 230 | install_software "linux-headers-$_kernel_ver" 231 | elif has_command dnf || has_command yum; then 232 | install_software "kernel-devel-$_kernel_ver" 233 | else 234 | # unsupported 235 | error "Automatically linux headers installing is currently not supported on this distribution." 236 | return 1 237 | fi 238 | } 239 | 240 | rerun_with_sudo() { 241 | if ! has_command sudo; then 242 | return 13 243 | fi 244 | 245 | local _target_script 246 | 247 | if is_run_from_fd; then 248 | local _tmp_script="$(mktemp)" 249 | chmod +x "$_tmp_script" 250 | 251 | if has_command curl; then 252 | curl -o "$_tmp_script" "$SCRIPT_INITIATOR_URL" 253 | elif has_command wget; then 254 | wget -O "$_tmp_script" "$SCRIPT_INITIATOR_URL" 255 | else 256 | return 127 257 | fi 258 | 259 | _target_script="$_tmp_script" 260 | else 261 | _target_script="$0" 262 | fi 263 | 264 | note "Re-running this script with sudo." 265 | exec_sudo "$_target_script" "${SCRIPT_ARGS[@]}" 266 | } 267 | 268 | check_permission() { 269 | if [[ "$UID" -eq '0' ]]; then 270 | return 271 | fi 272 | 273 | note "The user running this script is not root." 274 | 275 | if ! rerun_with_sudo; then 276 | error "Please manually switch to root and run this script again." 277 | echo 278 | echo -e "\t${tred}sudo -H bash${treset}" 279 | echo -e "\t${tred}$(script_name "1")${treset}" 280 | echo 281 | exit 13 282 | fi 283 | } 284 | 285 | check_environment_operating_system() { 286 | if [[ "x$(uname)" == "xLinux" ]]; then 287 | return 288 | fi 289 | 290 | error "This script only supports Linux." 291 | exit 95 292 | } 293 | 294 | check_environment_curl() { 295 | if has_command curl; then 296 | return 297 | fi 298 | 299 | install_software curl 300 | } 301 | 302 | check_environment_grep() { 303 | if has_command grep; then 304 | return 305 | fi 306 | 307 | install_software grep 308 | } 309 | 310 | check_environment_dkms() { 311 | if has_command dkms; then 312 | return 313 | fi 314 | 315 | install_software dkms 316 | } 317 | 318 | is_linux_headers_installed() { 319 | test -d "/lib/modules/$(uname -r)/build" 320 | } 321 | 322 | is_archlinux() { 323 | test -f "/etc/arch-release" 324 | } 325 | 326 | 327 | check_linux_headers() { 328 | echo -n "Checking linux-headers ... " 329 | if is_linux_headers_installed; then 330 | echo "ok" 331 | else 332 | echo "not installed" 333 | if ! install_linux_headers; then 334 | warning "Kernel headers is missing for current running kernel." 335 | warning "The DKMS kernel module will not be compiled." 336 | fi 337 | fi 338 | } 339 | 340 | check_environment() { 341 | check_environment_operating_system 342 | check_environment_curl 343 | check_environment_grep 344 | check_environment_dkms 345 | check_linux_headers 346 | } 347 | 348 | vercmp_segment() { 349 | local _lhs="$1" 350 | local _rhs="$2" 351 | 352 | if [[ "x$_lhs" == "x$_rhs" ]]; then 353 | echo 0 354 | return 355 | fi 356 | if [[ -z "$_lhs" ]]; then 357 | echo -1 358 | return 359 | fi 360 | if [[ -z "$_rhs" ]]; then 361 | echo 1 362 | return 363 | fi 364 | 365 | local _lhs_num="${_lhs//[A-Za-z]*/}" 366 | local _rhs_num="${_rhs//[A-Za-z]*/}" 367 | 368 | if [[ "x$_lhs_num" == "x$_rhs_num" ]]; then 369 | echo 0 370 | return 371 | fi 372 | if [[ -z "$_lhs_num" ]]; then 373 | echo -1 374 | return 375 | fi 376 | if [[ -z "$_rhs_num" ]]; then 377 | echo 1 378 | return 379 | fi 380 | local _numcmp=$(($_lhs_num - $_rhs_num)) 381 | if [[ "$_numcmp" -ne 0 ]]; then 382 | echo "$_numcmp" 383 | return 384 | fi 385 | 386 | local _lhs_suffix="${_lhs#"$_lhs_num"}" 387 | local _rhs_suffix="${_rhs#"$_rhs_num"}" 388 | 389 | if [[ "x$_lhs_suffix" == "x$_rhs_suffix" ]]; then 390 | echo 0 391 | return 392 | fi 393 | if [[ -z "$_lhs_suffix" ]]; then 394 | echo 1 395 | return 396 | fi 397 | if [[ -z "$_rhs_suffix" ]]; then 398 | echo -1 399 | return 400 | fi 401 | if [[ "$_lhs_suffix" < "$_rhs_suffix" ]]; then 402 | echo -1 403 | return 404 | fi 405 | echo 1 406 | } 407 | 408 | vercmp() { 409 | local _lhs=${1#v} 410 | local _rhs=${2#v} 411 | 412 | while [[ -n "$_lhs" && -n "$_rhs" ]]; do 413 | local _clhs="${_lhs/.*/}" 414 | local _crhs="${_rhs/.*/}" 415 | 416 | local _segcmp="$(vercmp_segment "$_clhs" "$_crhs")" 417 | if [[ "$_segcmp" -ne 0 ]]; then 418 | echo "$_segcmp" 419 | return 420 | fi 421 | 422 | _lhs="${_lhs#"$_clhs"}" 423 | _lhs="${_lhs#.}" 424 | _rhs="${_rhs#"$_crhs"}" 425 | _rhs="${_rhs#.}" 426 | done 427 | 428 | if [[ "x$_lhs" == "x$_rhs" ]]; then 429 | echo 0 430 | return 431 | fi 432 | 433 | if [[ -z "$_lhs" ]]; then 434 | echo -1 435 | return 436 | fi 437 | 438 | if [[ -z "$_rhs" ]]; then 439 | echo 1 440 | return 441 | fi 442 | 443 | return 444 | } 445 | 446 | 447 | ### 448 | # ARGUMENTS PARSER 449 | ### 450 | 451 | show_usage_and_exit() { 452 | echo 453 | echo -e "\t${tbold}$(script_name)${treset} - tcp-brutal dkms install script" 454 | echo 455 | echo -e "Usage:" 456 | echo 457 | echo -e "${tbold}Install tcp-brutal${treset}" 458 | echo -e "\t$(script_name) [install] [ -f | -l | --version ]" 459 | echo -e "Options:" 460 | echo -e "\t-f, --force\tForce re-install latest or specified version even if it has been installed." 461 | echo -e "\t-l, --local \tInstall specified DKMS tarball instead of download it." 462 | echo -e "\t--version \tInstall specified version instead of the latest." 463 | echo 464 | echo -e "${tbold}Uninstall tcp-brutal${treset}" 465 | echo -e "\t$(script_name) uninstall" 466 | echo 467 | echo -e "${tbold}Check for the status & update${treset}" 468 | echo -e "\t$(script_name) check" 469 | echo 470 | echo -e "${tbold}Reload / Unload tcp-brutal kernel module${treset}" 471 | echo -e "\t$(script_name) [re]load" 472 | echo -e "\t$(script_name) unload" 473 | echo 474 | echo -e "${tbold}Show this help${treset}" 475 | echo -e "\t$(script_name) help" 476 | exit 0 477 | } 478 | 479 | check_show_usage_and_exit() { 480 | case "$1" in 481 | "help") 482 | show_usage_and_exit 483 | ;; 484 | esac 485 | 486 | # if '-h' or '--help' appear in arguments in any position, 487 | # display help and exit 488 | while [[ "$#" -gt '0' ]]; do 489 | case "$1" in 490 | '--help' | '-h') 491 | show_usage_and_exit 492 | ;; 493 | esac 494 | shift 495 | done 496 | } 497 | 498 | 499 | ### 500 | # DKMS 501 | ### 502 | 503 | dkms_get_installed_versions() { 504 | local _module="$1" 505 | 506 | local _dkms_moddir="/var/lib/dkms/$_module" 507 | 508 | if [[ ! -d "$_dkms_moddir" ]]; then 509 | return 510 | fi 511 | 512 | for file in $(command ls "$_dkms_moddir/"); do 513 | if [[ -L "$_dkms_moddir/$file" ]]; then 514 | # ignore kernel-* symlinks 515 | continue 516 | fi 517 | echo "v$file" 518 | done 519 | } 520 | 521 | dkms_remove_modules() { 522 | local _module="$1" 523 | local _keep_latest="$2" 524 | 525 | local _versions_to_remove=($(dkms_get_installed_versions "$_module")) 526 | if [[ -n "$_keep_latest" ]]; then 527 | local _latest="" 528 | local _new_versions_to_remove 529 | _new_versions_to_remove=() 530 | for version in "${_versions_to_remove[@]}"; do 531 | local _vercmp="$(vercmp "$version" "$_latest")" 532 | if [[ "$_vercmp" -gt 0 ]]; then 533 | if [[ -n "$_latest" ]]; then 534 | _new_versions_to_remove+=("$_latest") 535 | fi 536 | _latest="$version" 537 | else 538 | _new_versions_to_remove+=("$version") 539 | fi 540 | done 541 | _versions_to_remove=("${_new_versions_to_remove[@]}") 542 | fi 543 | 544 | for version in "${_versions_to_remove[@]}"; do 545 | local _dkms_version="${version#v}" 546 | 547 | echo -n "Removing DKMS module $_module/$_dkms_version ... " 548 | if dkms remove "$_module/$_dkms_version" --all > /dev/null; then 549 | echo "ok" 550 | else 551 | # suppress dkms remove failed, shall not to be a problem 552 | continue 553 | fi 554 | echo -n "Cleaning DKMS module source /usr/src/$_module-$_dkms_version ... " 555 | if rm -rf "/usr/src/$_module-$_dkms_version"; then 556 | echo "ok" 557 | else 558 | # also suppress this 559 | continue 560 | fi 561 | done 562 | } 563 | 564 | dkms_ldtarball() { 565 | local _tarball="$1" 566 | 567 | # dkms variables 568 | local PACKAGE_NAME PACKAGE_VERSION MAKE CLEAN 569 | local BUILT_MODULE_NAME DEST_MODULE_LOCATION AUTOINSTALL 570 | 571 | local _extractdir="$(mktemp -d)" 572 | tar xf "$_tarball" -C "$_extractdir" 573 | source "$_extractdir/dkms_source_tree/dkms.conf" 574 | 575 | if [[ -z "$PACKAGE_NAME" || -z "$PACKAGE_VERSION" ]]; then 576 | error "Malformed DKMS tarball, PACKAGE_NAME or PACKAGE_VERSION is missing." 577 | exit 22 578 | fi 579 | 580 | rm -rf "/usr/src/$PACKAGE_NAME-$PACKAGE_VERSION" 581 | mkdir -p "/usr/src/$PACKAGE_NAME-$PACKAGE_VERSION" 582 | cp -a "$_extractdir/dkms_source_tree/." "/usr/src/$PACKAGE_NAME-$PACKAGE_VERSION/" 583 | rm -rf "$_extractdir" 584 | 585 | dkms add "$PACKAGE_NAME/$PACKAGE_VERSION" 586 | } 587 | 588 | dkms_install_tarball() { 589 | local _tarball="$1" 590 | 591 | echo "Installing DKMS module from tarball file $_tarball ... " 592 | if ! dkms_ldtarball "$_tarball"; then 593 | error "Failed to install DKMS tarball, please check above output or try to uninstall first." 594 | return 1 595 | fi 596 | } 597 | 598 | 599 | ### 600 | # Kernel modules 601 | ### 602 | 603 | kmod_is_loaded() { 604 | local _module="$1" 605 | 606 | lsmod | grep -qP '\b'"$_module"'\b' 607 | } 608 | 609 | kmod_load_if_unloaded() { 610 | local _module="$1" 611 | 612 | if ! kmod_is_loaded "$_module"; then 613 | echo -n "Loading kernel module $_module ... " 614 | if modprobe "$_module"; then 615 | echo "ok" 616 | else 617 | error "Failed to load kernel module, kernel module might not be installed successfully." 618 | return 1 619 | fi 620 | fi 621 | } 622 | 623 | kmod_unload_if_loaded() { 624 | local _module="$1" 625 | 626 | if kmod_is_loaded "$_module"; then 627 | echo -n "Unloading kernel module $_module ... " 628 | if rmmod "$_module"; then 629 | echo "ok" 630 | else 631 | error "Failed to unload kernel module, kernel module might be occupied by other process." 632 | error "Try to stop all related proxy service, or simply reboot your server and try again." 633 | return 1 634 | fi 635 | fi 636 | } 637 | 638 | kmod_setup_autoload() { 639 | local _module="$1" 640 | 641 | echo -n "Enabling auto load kernel module $_module on system boot ... " 642 | if echo "$_module" > "/etc/modules-load.d/$_module.conf"; then 643 | echo "ok" 644 | else 645 | warning "Failed to enable auto load $_module on system boot." 646 | fi 647 | } 648 | 649 | kmod_unsetup_autoload() { 650 | local _module="$1" 651 | 652 | echo -n "Disabling auto load kernel module $_module on system boot ... " 653 | if rm -f "/etc/modules-load.d/$_module.conf"; then 654 | echo "ok" 655 | else 656 | warning "Failed to disable auto load $_module on system boot." 657 | fi 658 | } 659 | 660 | ### 661 | # API 662 | ### 663 | 664 | get_latest_version() { 665 | if [[ -n "$VERSION" ]]; then 666 | echo "$VERSION" 667 | return 668 | fi 669 | 670 | local _tmpfile=$(mktemp) 671 | if ! curl -sS "$HY2_API_BASE_URL/update?cver=installscript&arch=generic&plat=linux&chan=tcp-brutal" -o "$_tmpfile"; then 672 | error "Failed to get the latest version from Hysteria 2 API, please check your network and try again." 673 | exit 11 674 | fi 675 | 676 | local _latest_version=$(grep -oP '"lver":\s*\K"v.*?"' "$_tmpfile" | head -1) 677 | _latest_version=${_latest_version#'"'} 678 | _latest_version=${_latest_version%'"'} 679 | 680 | if [[ -n "$_latest_version" ]]; then 681 | echo "$_latest_version" 682 | fi 683 | 684 | rm -f "$_tmpfile" 685 | } 686 | 687 | download_dkms_tarball() { 688 | local _version="$1" 689 | local _destination="$2" 690 | 691 | local _download_url="$REPO_URL/releases/download/$_version/tcp-brutal.dkms.tar.gz" 692 | echo "Downloading DKMS tarball: $_download_url ..." 693 | if ! curl -R -H 'Cache-Control: no-cache' "$_download_url" -o "$_destination"; then 694 | error "Download failed, please check your network and try again." 695 | return 11 696 | fi 697 | return 0 698 | } 699 | 700 | 701 | ### 702 | # ENTRY 703 | ### 704 | 705 | perform_install() { 706 | local _local_file="" 707 | local _user_provided_local_file="" 708 | local _version="" 709 | local _install_needed="" 710 | 711 | while [[ "$#" -gt '0' ]]; do 712 | case "$1" in 713 | '--force' | '-f') 714 | _install_needed="1" 715 | ;; 716 | '--local' | '-l') 717 | shift 718 | if [[ "x$1" == "x--" ]]; then 719 | shift 720 | _local_file="$1" 721 | elif has_prefix "$1" "-"; then 722 | _local_file="" 723 | else 724 | _local_file="$1" 725 | fi 726 | if [[ -z "$_local_file" ]]; then 727 | show_argument_error_and_exit "Please specify the local dkms.tar file to install for option '-l' or '--local'." 728 | fi 729 | _install_needed="1" 730 | _user_provided_local_file="1" 731 | ;; 732 | '--version') 733 | shift 734 | if [[ "x$1" == "x--" ]]; then 735 | shift 736 | _version="$1" 737 | elif has_prefix "$1" "-"; then 738 | _version="" 739 | else 740 | _version="$1" 741 | fi 742 | if [[ -z "$_version" ]]; then 743 | show_argument_error_and_exit "Please specify the version for option '--version'." 744 | fi 745 | ;; 746 | *) 747 | show_argument_error_and_exit "Unrecognized option '$1' for subcommand 'install'." 748 | ;; 749 | esac 750 | shift 751 | done 752 | 753 | if [[ -n "$_local_file" && -n "$_version" ]]; then 754 | show_argument_error_and_exit "'--version' and '--local' cannot be used together." 755 | fi 756 | 757 | # check installed version 758 | echo "Cleaning old installations ... " 759 | dkms_remove_modules "$DKMS_MODULE_NAME" "1" 760 | 761 | echo -n "Checking installed version ... " 762 | local _installed_version="$(dkms_get_installed_versions "$DKMS_MODULE_NAME" | head -1)" 763 | if [[ -n "$_installed_version" ]]; then 764 | echo "$_installed_version" 765 | else 766 | echo "not installed" 767 | fi 768 | 769 | if [[ -z "$_local_file" && -z "$_version" ]]; then 770 | echo -n "Checking latest version ... " 771 | local _latest_version=$(get_latest_version) 772 | if [[ -n "$_latest_version" ]]; then 773 | echo "$_latest_version" 774 | _version="$_latest_version" 775 | fi 776 | fi 777 | 778 | if [[ -z "$_local_file" && -n "$_version" ]]; then 779 | local _vercmp="$(vercmp "$_installed_version" "$_version")" 780 | if [[ "$_vercmp" -lt "0" ]]; then 781 | _install_needed="1" 782 | fi 783 | if [[ -n "$_install_needed" ]]; then 784 | local _download_destination="$(mktemp).tar.gz" 785 | download_dkms_tarball "$_version" "$_download_destination" 786 | _local_file="$_download_destination" 787 | fi 788 | fi 789 | 790 | if [[ -n "$_install_needed" ]]; then 791 | # remove all installed version as DKMS not allowed to overwrite a installed module 792 | dkms_remove_modules "$DKMS_MODULE_NAME" "" 793 | dkms_install_tarball "$_local_file" 794 | fi 795 | 796 | if [[ -z "$_user_provided_local_file" && -n "$_local_file" ]]; then 797 | # clean auto downloaded tarball 798 | rm -f "$_local_file" 799 | fi 800 | 801 | echo "Rebuilding DKMS modules as needed ... " 802 | if ! dkms autoinstall; then 803 | warning "Error occurred in 'dkms autoinstall', please check above output." 804 | fi 805 | 806 | kmod_setup_autoload "$KERNEL_MODULE_NAME" 807 | 808 | if [[ -z "$_install_needed" ]]; then 809 | if ! kmod_load_if_unloaded "$KERNEL_MODULE_NAME"; then 810 | warning "tcp-brutal is installed but failed to load." 811 | fi 812 | 813 | echo "${tbold}There is nothing to do today.${treset}" 814 | exit 0 815 | fi 816 | 817 | if ! kmod_unload_if_loaded "$KERNEL_MODULE_NAME"; then 818 | warning "tcp-brutal is successfully update, but occupied by other process, please reboot your server to active the latest change." 819 | exit 0 820 | fi 821 | 822 | if ! kmod_load_if_unloaded "$KERNEL_MODULE_NAME"; then 823 | error "tcp-brutal is successfully installed, but failed to load, this might cause by mismatched linux-headers." 824 | error "If you update your system recently, reboot the system might solve this." 825 | exit 2 826 | fi 827 | 828 | echo 829 | echo -e "${tbold}Congratulation! tcp-brutal $_version has been successfully installed and loaded on your server.${treset}" 830 | } 831 | 832 | perform_uninstall() { 833 | while [[ "$#" -gt '0' ]]; do 834 | case "$1" in 835 | *) 836 | show_argument_error_and_exit "Unrecognized option '$1' for subcommand 'uninstall'." 837 | ;; 838 | esac 839 | shift 840 | done 841 | 842 | kmod_unsetup_autoload "$KERNEL_MODULE_NAME" 843 | 844 | dkms_remove_modules "$DKMS_MODULE_NAME" "" 845 | 846 | if ! kmod_unload_if_loaded "$KERNEL_MODULE_NAME"; then 847 | warning "tcp-brutal is successfully uninstall from your server, but failed to unload from the kernel." 848 | warning "Please reboot your system to unload it from the kernel." 849 | exit 0 850 | fi 851 | 852 | echo 853 | echo -e "${tbold}Congratulation! tcp-brutal has been successfully uninstalled and unloaded." 854 | } 855 | 856 | perform_check() { 857 | while [[ "$#" -gt '0' ]]; do 858 | case "$1" in 859 | *) 860 | show_argument_error_and_exit "Unrecognized option '$1' for subcommand 'check'." 861 | ;; 862 | esac 863 | shift 864 | done 865 | 866 | echo -n "Checking kernel module ... " 867 | if kmod_is_loaded "$KERNEL_MODULE_NAME"; then 868 | echo "loaded" 869 | else 870 | echo "not loaded" 871 | fi 872 | 873 | echo -n "Checking installed version ... " 874 | local _installed_versions=($(dkms_get_installed_versions "$DKMS_MODULE_NAME")) 875 | if [[ "${#_installed_versions[@]}" -eq "0" ]]; then 876 | echo "not installed" 877 | elif [[ "${#_installed_versions[@]}" -eq "1" ]]; then 878 | echo "${_installed_versions[0]}" 879 | else 880 | echo "multiple version installed" 881 | for version in "${_installed_versions[@]}"; do 882 | echo -e "\tFound $version" 883 | done 884 | fi 885 | 886 | echo -n "Checking latest version ... " 887 | local _latest_version=$(get_latest_version) 888 | if [[ -n "$_latest_version" ]]; then 889 | echo "$_latest_version" 890 | fi 891 | } 892 | 893 | perform_reload() { 894 | while [[ "$#" -gt '0' ]]; do 895 | case "$1" in 896 | *) 897 | show_argument_error_and_exit "Unrecognized option '$1' for subcommand 'reload'." 898 | ;; 899 | esac 900 | shift 901 | done 902 | 903 | kmod_unload_if_loaded "$KERNEL_MODULE_NAME" 904 | kmod_load_if_unloaded "$KERNEL_MODULE_NAME" 905 | } 906 | 907 | perform_unload() { 908 | while [[ "$#" -gt '0' ]]; do 909 | case "$1" in 910 | *) 911 | show_argument_error_and_exit "Unrecognized option '$1' for subcommand 'unload'." 912 | ;; 913 | esac 914 | shift 915 | done 916 | 917 | kmod_unload_if_loaded "$KERNEL_MODULE_NAME" 918 | } 919 | 920 | main() { 921 | check_show_usage_and_exit "$@" 922 | 923 | check_permission 924 | check_environment 925 | 926 | case "$1" in 927 | "install") 928 | shift 929 | perform_install "$@" 930 | ;; 931 | "uninstall" | "remove") 932 | shift 933 | perform_uninstall "$@" 934 | ;; 935 | "check" | "status") 936 | shift 937 | perform_check "$@" 938 | ;; 939 | "load" | "reload") 940 | shift 941 | perform_reload "$@" 942 | ;; 943 | "unload") 944 | shift 945 | perform_unload "$@" 946 | ;; 947 | *) 948 | # default action 949 | perform_install "$@" 950 | ;; 951 | esac 952 | } 953 | 954 | main "$@" 955 | 956 | # vim:set ft=bash ts=2 sw=2 sts=2 et: 957 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------