diff --git a/net/bpftune/Makefile b/net/bpftune/Makefile new file mode 100644 index 00000000000000..7450f9ce9408a7 --- /dev/null +++ b/net/bpftune/Makefile @@ -0,0 +1,157 @@ +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=bpftune +PKG_VERSION:=0.4.2-f562f77 +PKG_RELEASE:=1 + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://github.com/KyleGospo/bpftune.git +PKG_SOURCE_DATE:=2026-08-26 +PKG_SOURCE_VERSION:=f562f776aac16478a2eeae1bf4871a66dd0070c3 +PKG_MIRROR_HASH:=fb49aaad19ee711226b8bf62ded281e7346750c4e4d08909b2a37ac58765438c +PKG_BUILD_DIR:=$(BUILD_DIR)/$(if $(BUILD_VARIANT),bpftune-$(BUILD_VARIANT)/)bpftune-$(PKG_VERSION) + +PKG_LICENSE:=GPL-2.0-WITH-Linux-syscall-note +PKG_LICENSE_FILES:=COPYING +PKG_MAINTAINER:=Shon Sebastian + +PKG_BUILD_DEPENDS:=bpf-headers + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/bpf.mk + +define Package/bpftune/default + SECTION:=net + CATEGORY:=Network + DEPENDS:=+@KERNEL_BPF_EVENTS +@KERNEL_CGROUPS +@KERNEL_CGROUP_BPF \ + +kmod-tcp-bbr +libnl-route +libcap +libbpf \ + $(BPF_DEPENDS) +endef + +define Package/bpftune + $(call Package/bpftune/default) + URL:=https://github.com/oracle/bpftune + TITLE:=BPF driven auto-tuning (needs TCP_CONG_HTCP and TCP_CONG_DCTCP) + CONFLICTS:=bpftune-gaming bpftune-gaming-full +endef + +define Package/bpftune-full + $(call Package/bpftune/default) + URL:=https://github.com/oracle/bpftune + TITLE:=bpftune with BTF support (might cause crashloops on limited hardware). + DEPENDS:=+bpftune +@KERNEL_DEBUG_INFO +@KERNEL_DEBUG_INFO_BTF \ + +@KERNEL_NAMESPACES +@KERNEL_NET_NS +endef + +define Package/bpftune-gaming + $(call Package/bpftune/default) + URL:=https://github.com/KyleGospo/bpftune + TITLE:=Fork of bpftune with gaming tuner without BTF support (needs TCP_CONG_HTCP and TCP_CONG_DCTCP) + VARIANT:=gaming + CONFLICTS:=bpftune bpftune-full +endef + +define Package/bpftune-gaming-full + $(call Package/bpftune/default) + URL:=https://github.com/KyleGospo/bpftune + TITLE:=bpftune-gaming with BTF support (might cause crashloops on limited hardware) + DEPENDS:=+bpftune-gaming +@KERNEL_DEBUG_INFO +@KERNEL_DEBUG_INFO_BTF \ + +@KERNEL_NAMESPACES +@KERNEL_NET_NS +endef + +define Package/bpftune/description + bpftune aims to provide lightweight, always-on auto-tuning of system + behaviour. By using BPF observability features, we can continuously + monitor and adjust system behaviour at a fine grain. (Needs TCP_CONG_HTCP + and TCP_CONG_DCTCP from target/linux/generic/config- manually enabled + to function correctly. Runs on no-BTF mode). +endef + +define Package/bpftune-full/description + bpftune with BTF support for intended functionality. Needs TCP_CONG_HTCP + and TCP_CONG_DCTCP from target/linux/generic/config- manually enabled + to function, and KERNEL_DEBUG_INFO_REDUCED disabled manually. This package enables + KERNEL_NET_NS and KERNEL_DEBUG_INFO_BTF as well which might cause crashloops on + limited hardware eg. single core cpu routers. +endef + +define Package/bpftune-gaming/description + Fork of bpftune which adds separate tuner and changes for gaming. (Needs + TCP_CONG_HTCP and TCP_CONG_DCTCP from target/linux/generic/config- + manually enabled to function correctly. Runs on no-BTF mode). +endef + +define Package/bpftune-gaming-full/description + bpftune-gaming with BTF support for intended functionality. Needs TCP_CONG_HTCP + and TCP_CONG_DCTCP from target/linux/generic/config- manually enabled + to function, and KERNEL_DEBUG_INFO_REDUCED disabled manually. This package enables + KERNEL_NET_NS and KERNEL_DEBUG_INFO_BTF as well which might cause crashloops on + limited hardware eg. single core cpu routers. +endef + +bpf_srcarch=$(subst \ + aarch64,arm64,$(subst \ + armeb,arm,$(subst \ + i386,x86,$(subst \ + x86_64,x86,$(subst \ + loongarch64,loongarch,$(subst \ + mipsel,mips,$(subst \ + mips64,mips,$(subst \ + powerpc64,powerpc,$(subst \ + riscv64,riscv,$(1)))))))))) + +BPF_SRCARCH:=$(call bpf_srcarch,$(ARCH)) + +MAKE_FLAGS += \ + BPFTUNE_VERSION="$(PKG_VERSION)-$(PKG_RELEASE)" \ + SRCARCH="$(BPF_SRCARCH)" \ + BPF_TARGET="$(BPF_TARGET)" \ + BPF_CLANG="$(CLANG)" \ + LLVM_STRIP="$(LLVM_STRIP)" \ + PKG_BUILD_DIR=$(PKG_BUILD_DIR) \ + GAMING_BUILD=$(if $(filter gaming,$(BUILD_VARIANT)),true) + +define Package/bpftune/conffiles +/etc/config/bpftune +endef +define Package/bpftune-gaming/conffiles +/etc/config/bpftune +endef + +define Package/bpftune/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/bpftune $(1)/usr/sbin/bpftune + $(INSTALL_DIR) $(1)/usr/lib + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/libbpftune.so.0.4.2 $(1)/usr/lib/libbpftune.so.0.4.2 + $(LN) libbpftune.so.0.4.2 $(1)/usr/lib/libbpftune.so + $(INSTALL_DIR) $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/tcp_buffer_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/route_table_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/neigh_table_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/sysctl_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/tcp_conn_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/netns_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/net_buffer_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/ip_frag_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/udp_buffer_tuner.so $(1)/usr/lib/bpftune + $(INSTALL_DIR) $(1)/etc + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_DATA) ./files/bpftune.confd $(1)/etc/config/bpftune + $(INSTALL_BIN) ./files/bpftune.initd $(1)/etc/init.d/bpftune +endef + +define Package/bpftune-gaming/install + $(call Package/bpftune/install) + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/gaming_tuner.so $(1)/usr/lib/bpftune +endef + +$(eval $(call BuildPackage,bpftune)) +$(eval $(call BuildPackage,bpftune-full)) +$(eval $(call BuildPackage,bpftune-gaming)) +$(eval $(call BuildPackage,bpftune-gaming-full)) diff --git a/net/bpftune/files/bpftune.confd b/net/bpftune/files/bpftune.confd new file mode 100644 index 00000000000000..cc2f68880f4322 --- /dev/null +++ b/net/bpftune/files/bpftune.confd @@ -0,0 +1,2 @@ +config defaults 'defaults' + option command_args "-R -c /sys/fs/cgroup" diff --git a/net/bpftune/files/bpftune.initd b/net/bpftune/files/bpftune.initd new file mode 100644 index 00000000000000..3f70795e4ca519 --- /dev/null +++ b/net/bpftune/files/bpftune.initd @@ -0,0 +1,37 @@ +#!/bin/sh /etc/rc.common +# SPDX-License-Identifier: GPL-2.0-or-later + +USE_PROCD=1 + +START=81 +STOP=81 + +NAME=bpftune +PROG=/usr/sbin/bpftune +CONFIG=/etc/config/bpftune + +ARGS="-R -c /sys/fs/cgroup" +EXTRA_COMMANDS="checkconf" + +checkconf() { + config_load 'bpftune' + config_get ARGS defaults command_args "$ARGS" + $PROG -S $ARGS 2>&1 +} + +start_pre() { + checkconf > /dev/null 2>&1 +} + +start_service() +{ + if ! start_pre; then + return 1 + fi + + procd_open_instance + procd_set_param file $CONFIG + procd_set_param command $PROG $ARGS + procd_set_param respawn + procd_close_instance +} diff --git a/net/bpftune/patches/build-src-only.patch b/net/bpftune/patches/build-src-only.patch new file mode 100644 index 00000000000000..abcb639dea018f --- /dev/null +++ b/net/bpftune/patches/build-src-only.patch @@ -0,0 +1,28 @@ +From ef5d2d5e44dfc4e38e53da92843731b6317aa32d Mon Sep 17 00:00:00 2001 +From: Shon Sebastian +Date: Tue, 22 Sep 2026 03:25:50 +0530 +Subject: [PATCH] build src only + +Simplify build + +Signed-off-by: Shon Sebastian +--- + Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index 5e93dc0..c23a5f0 100644 +--- a/Makefile ++++ b/Makefile +@@ -33,7 +33,7 @@ INSTALLPATH = $(installprefix) + + .PHONY: all clean + +-all: srcdir docdir testdir ++all: srcdir + + srcdir: + cd src; make +-- +2.55.0 + diff --git a/net/bpftune/patches/fix-Makefile.patch b/net/bpftune/patches/fix-Makefile.patch new file mode 100644 index 00000000000000..0ed50edfab096f --- /dev/null +++ b/net/bpftune/patches/fix-Makefile.patch @@ -0,0 +1,128 @@ +From cb358f17dd1c6b7154f36fe94d2dc5479d6e95c6 Mon Sep 17 00:00:00 2001 +From: Shon Sebastian +Date: Tue, 22 Sep 2026 03:23:21 +0530 +Subject: [PATCH] fix Makefile + +Adapts build for openwrt + +Signed-off-by: Shon Sebastian +--- + src/Makefile | 53 ++++++++++++++++++++++++++++------------------------ + 1 file changed, 29 insertions(+), 24 deletions(-) + +diff --git a/src/Makefile b/src/Makefile +index 85a6d55..cb80c11 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -15,21 +15,17 @@ + # License along with this program. If not, see . + # + +-ARCH ?= $(shell uname -m) +-SRCARCH ?= $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ +- -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \ +- -e s/aarch64.*/arm64/ ) +- + CLANG ?= clang + GCC_BPF ?= + LLC ?= llc + LLVM_STRIP ?= llvm-strip + BPFTOOL ?= bpftool +-BPF_INCLUDE := /usr/include +-BPF_LOCAL_INCLUDE := /usr/local/include +-BPF_CFLAGS := -g -fno-stack-protector -Wall -Wno-incompatible-pointer-types-discards-qualifiers +-NL_INCLUDE := /usr/include/libnl3 +-INCLUDES := -I../include -I$(BPF_INCLUDE) -I$(BPF_LOCAL_INCLUDE) -I$(NL_INCLUDE) -I../include/uapi ++BPF_CFLAGS += -g -fno-stack-protector -Wall -Wno-incompatible-pointer-types-discards-qualifiers ++ ++INCLUDES := -I../include \ ++ -I$(STAGING_DIR)/usr/include \ ++ -I$(STAGING_DIR)/usr/include/libnl3 ++ + INSTALL ?= install + + SBINPATH ?= $(shell rpm --eval '%{_sbindir}' 2>/dev/null) +@@ -52,7 +48,7 @@ else + DEFAULT_LIBDIR := lib64 + endif + +-libdir ?= $(DEFAULT_LIBDIR) ++libdir = lib + installprefix = $(DESTDIR)/$(prefix) + + INSTALLPATH = $(installprefix) +@@ -75,7 +71,7 @@ endif + VERSION = 0.4.2 + VERSION_SCRIPT := libbpftune.map + +-CFLAGS = -fPIC -Wall -Wextra -g -I../include -std=c99 ++CFLAGS += -fPIC -Wall -Wextra -g -std=c99 + + CFLAGS += -DBPFTUNE_VERSION='"$(BPFTUNE_VERSION)"' \ + -DBPFTUNER_PREFIX_DIR='"$(prefix)"' \ +@@ -92,12 +88,12 @@ VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL) + VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ + $(wildcard $(VMLINUX_BTF_PATHS)))) + +-# Some systems ship with a vmlinux.h; use it. +-VMLINUX_H_PATH ?= /usr/include/$(ARCH)-linux-gnu/linux/bpf/ +-VMLINUX_H_FILE := $(wildcard $(VMLINUX_H_PATH)/vmlinux.h) ++# Try to reach generated vmlinux.h if it exists ++VMLINUX_H_FILE := $(wildcard $(PKG_BUILD_DIR)/vmlinux.h) + ++# Defaults to ../include/bpftune/vmlinux_aarch64.h as the best available fallback. + ifneq ($(VMLINUX_H_FILE),) +-BPF_CFLAGS += -DVMLINUX_H -I$(VMLINUX_H_PATH) ++BPF_CFLAGS += -DVMLINUX_H -I$(PKG_BUILD_DIR) + endif + + OPATH := +@@ -114,9 +110,15 @@ MAKEFLAGS += --no-print-directory + submake_extras := feature_display=0 + endif + ++ifneq ($(GAMING_BUILD),) + TUNERS = tcp_buffer_tuner route_table_tuner neigh_table_tuner sysctl_tuner \ + tcp_conn_tuner netns_tuner net_buffer_tuner ip_frag_tuner \ + udp_buffer_tuner gaming_tuner ++else ++TUNERS = tcp_buffer_tuner route_table_tuner neigh_table_tuner sysctl_tuner \ ++ tcp_conn_tuner netns_tuner net_buffer_tuner ip_frag_tuner \ ++ udp_buffer_tuner ++endif + + TUNER_OBJS = $(patsubst %,%.o,$(TUNERS)) + TUNER_SRCS = $(patsubst %,%.c,$(TUNERS)) +@@ -209,18 +211,21 @@ $(OPATH)bpftune.o: $(OPATH)libbpftune.so + # check if GCC_BPF flag is set, otherwise use CLANG + ifeq ($(GCC_BPF),) + $(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../include/bpftune/bpftune.bpf.h +- $(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -O2 -target bpf \ +- $(INCLUDES) -c $(patsubst %.o,%.c,$(@)) -o $(@) ++ $(BPF_CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -O2 -target $(BPF_TARGET) \ ++ -I../include -c $(patsubst %.o,%.c,$(@)) -o $(@) ++ $(LLVM_STRIP) --strip-debug $(@) + + $(LEGACY_BPF_OBJS): $(patsubst %.legacy.o,%.c,$(LEGACY_BPF_OBJS)) ../include/bpftune/bpftune.bpf.h +- $(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_LEGACY -O2 -target bpf \ +- $(INCLUDES) -c $(patsubst %.legacy.o,%.c,$(@)) \ +- -o $(@) ++ $(BPF_CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_LEGACY -O2 -target $(BPF_TARGET) \ ++ -I../include -c $(patsubst %.legacy.o,%.c,$(@)) \ ++ -o $(@) ++ $(LLVM_STRIP) --strip-debug $(@) + + $(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS)) ../include/bpftune/bpftune.bpf.h +- $(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_NOBTF -O2 -target bpf \ +- $(INCLUDES) -c $(patsubst %.nobtf.o,%.c,$(@)) \ +- -o $(@) ++ $(BPF_CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_NOBTF -O2 -target $(BPF_TARGET) \ ++ -I../include -c $(patsubst %.nobtf.o,%.c,$(@)) \ ++ -o $(@) ++ $(LLVM_STRIP) --strip-debug $(@) + else + GCC_BPF_FLAGS := -g -O2 \ + $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) \ +-- +2.55.0 + diff --git a/net/bpftune/patches/libbpftune-musl-fixes.patch b/net/bpftune/patches/libbpftune-musl-fixes.patch new file mode 100644 index 00000000000000..b96507a618dc57 --- /dev/null +++ b/net/bpftune/patches/libbpftune-musl-fixes.patch @@ -0,0 +1,46 @@ +From 1de39854a279b1ec17306679c88ddf14fb06cabd Mon Sep 17 00:00:00 2001 +From: Shon Sebastian +Date: Tue, 22 Sep 2026 03:33:35 +0530 +Subject: [PATCH] libbpftune: musl fixes + +Fixes for compiling with musl + +Signed-off-by: Shon Sebastian +--- + src/libbpftune.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/libbpftune.c b/src/libbpftune.c +index 39e2c66..ee8525d 100644 +--- a/src/libbpftune.c ++++ b/src/libbpftune.c +@@ -2167,7 +2167,7 @@ static void bpftuner_strategy_update(struct bpftuner *tuner) + bpftuner_strategy_set(tuner, max_strategy); + } + +-static void bpftuner_strategy_timeout(sigval_t sigval) ++static void bpftuner_strategy_timeout(union sigval sigval) + { + struct bpftuner *tuner = sigval.sival_ptr; + +@@ -2583,7 +2583,7 @@ void *bpftune_server_thread(void *arg) + if (port == 0) { + len = sizeof(saddr); + +- if (!getsockname(fd, &saddr, &len)) ++ if (!getsockname(fd, (struct sockaddr *)&saddr, &len)) + port = ntohs(saddr.sin_port); + } + if (port != 0) { +@@ -2604,7 +2604,7 @@ void *bpftune_server_thread(void *arg) + char buf[BPFTUNE_SERVER_MSG_MAX]; + char req[81]; + struct sockaddr_in caddr; +- int cfd = accept(fd, (struct sockaddr_in *)&caddr, &len); ++ int cfd = accept(fd, (struct sockaddr *)&caddr, &len); + ssize_t req_len; + unsigned long i; + +-- +2.55.0 + diff --git a/net/bpftune/patches/vmlinux-fallback.patch b/net/bpftune/patches/vmlinux-fallback.patch new file mode 100644 index 00000000000000..1012f1a204e2e7 --- /dev/null +++ b/net/bpftune/patches/vmlinux-fallback.patch @@ -0,0 +1,34 @@ +From 7813293917d8a4e0bfebe66ca9cfa2c375cfab9a Mon Sep 17 00:00:00 2001 +From: Shon Sebastian +Date: Tue, 22 Sep 2026 03:30:43 +0530 +Subject: [PATCH] vmlinux fallback + +Falls back to vmlinux_aarch64.h if no vmlinux.h is found. + +Signed-off-by: Shon Sebastian +--- + include/bpftune/bpftune.bpf.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/include/bpftune/bpftune.bpf.h b/include/bpftune/bpftune.bpf.h +index 42466a6..23e3039 100644 +--- a/include/bpftune/bpftune.bpf.h ++++ b/include/bpftune/bpftune.bpf.h +@@ -30,12 +30,13 @@ + __builtin_preserve_access_index(&obj->field) + #endif + ++// select atleast one vmlinux.h file + #ifdef VMLINUX_H + #include + #else + #if defined(__TARGET_ARCH_x86) + #include +-#elif defined(__TARGET_ARCH_arm64) ++#else + #include + #endif + #endif /* VMLIMUX_H */ +-- +2.55.0 +