💐 Sync 2026-09-10 14:49:21

This commit is contained in:
github-actions[bot] committed 2026-09-10 14:49:21 +08:00
1 parent 0e9e9c2496
commit 7b0b16dcd4
181 files changed
+23375 -22143

No files matched your search

+1 -4
View File
@@ -9,7 +9,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=glorytun
PKG_RELEASE:=3
PKG_RELEASE:=4
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=95fa5ead2154adb546bcdb454c56c876e9f60bb5
PKG_SOURCE:=glorytun-$(PKG_VERSION).tar.gz
@@ -50,13 +50,10 @@ endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/glorytun $(1)/usr/sbin/$(PKG_NAME)
$(INSTALL_BIN) files/glorytun-irq-affinity.sh $(1)/usr/sbin/glorytun-irq-affinity.sh
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) init $(1)/etc/init.d/$(PKG_NAME)
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DATA) glorytun.config $(1)/etc/config/glorytun
$(INSTALL_DIR) $(1)/etc/glorytun
$(INSTALL_DATA) files/glorytun-sysctl.conf $(1)/etc/glorytun/glorytun-sysctl.conf
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
-86
View File
@@ -1,86 +0,0 @@
#!/bin/sh
# Set IRQ affinity for glorytun interfaces
set_irq_affinity() {
local irq=$1
local cpu=$2
local mask=$(printf "%x" $((1 << $cpu)))
echo "Setting IRQ $irq to CPU $cpu (mask: $mask)"
echo $mask > /proc/irq/$irq/smp_affinity
}
# Get interface IRQs
get_interface_irqs() {
local interface=$1
grep -E "$interface" /proc/interrupts | awk '{print $1}' | tr -d ':'
}
# Main function
setup_irq_affinity() {
# Get available CPU cores
local cpu_count=$(grep -c processor /proc/cpuinfo)
echo "Available CPU cores: $cpu_count"
# Determine tun interface
local tun_interface=$(ip link | grep tun | awk -F': ' '{print $2}' | head -n1)
if [ -z "$tun_interface" ]; then
echo "No tun interface found"
return 1
fi
echo "Found tun interface: $tun_interface"
# Get IRQs for tun interface
local irqs=$(get_interface_irqs $tun_interface)
if [ -z "$irqs" ]; then
echo "No IRQs found for $tun_interface"
return 1
fi
# Distribute IRQs across available cores (except CPU0)
local cpu=1
for irq in $irqs; do
set_irq_affinity $irq $cpu
cpu=$(( (cpu + 1) % cpu_count ))
if [ $cpu -eq 0 ]; then
cpu=1
fi
done
# Set RPS (Receive Packet Steering) for better packet distribution
if [ -e /sys/class/net/$tun_interface/queues/rx-0/rps_cpus ]; then
# Calculate mask for all CPUs except CPU0
local rps_mask=$(printf "%x" $(( (1 << $cpu_count) - 2 )))
echo "Setting RPS mask to $rps_mask for $tun_interface"
echo $rps_mask > /sys/class/net/$tun_interface/queues/rx-0/rps_cpus
fi
# Set RFS (Receive Flow Steering) limits if available
if [ -e /proc/sys/net/core/rps_sock_flow_entries ]; then
echo 32768 > /proc/sys/net/core/rps_sock_flow_entries
if [ -e /sys/class/net/$tun_interface/queues/rx-0/rps_flow_cnt ]; then
echo 32768 > /sys/class/net/$tun_interface/queues/rx-0/rps_flow_cnt
fi
fi
# Set XPS (Transmit Packet Steering) if available
if [ -e /sys/class/net/$tun_interface/queues/tx-0/xps_cpus ]; then
# Use all CPUs except CPU0 for transmit
local xps_mask=$(printf "%x" $(( (1 << $cpu_count) - 2 )))
echo "Setting XPS mask to $xps_mask for $tun_interface"
echo $xps_mask > /sys/class/net/$tun_interface/queues/tx-0/xps_cpus
fi
# Increase network queue length for better performance
if [ -e /sys/class/net/$tun_interface/tx_queue_len ]; then
echo 1000 > /sys/class/net/$tun_interface/tx_queue_len
fi
echo "IRQ affinity setup completed for $tun_interface"
}
# Run the main function
setup_irq_affinity
exit 0
-27
View File
@@ -1,27 +0,0 @@
# Glorytun-specific optimizations
# Note: These settings complement the system-wide sysctl parameters
# Buffer size optimization for glorytun tunnels
# Increase only if not already set in system configuration
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.optmem_max = 16777216
# Enable BBR congestion control for better tunnel performance
net.core.default_qdisc = fq
# RPS/RFS settings for tunnel interfaces
# These are critical for multicore performance with glorytun
net.core.rps_sock_flow_entries = 32768
# Network device tuning for tunnel interfaces
net.core.netdev_max_backlog = 10000
net.core.netdev_budget = 600
net.core.netdev_budget_usecs = 10000
# Lower TCP timeout for faster recovery of tunnel connections
net.ipv4.tcp_keepalive_intvl = 10
net.ipv4.tcp_keepalive_probes = 6
# Disable slow start after idle for more consistent tunnel performance
net.ipv4.tcp_slow_start_after_idle = 0
-1
View File
@@ -11,6 +11,5 @@ config glorytun 'vpn'
option localip '10.255.255.2'
option remoteip '10.255.255.1'
option multiqueue '1'
option cpu_affinity '1'
option label 'Default VPN'
option timeout '10000'
+17 -67
View File
@@ -18,14 +18,6 @@ _err() {
logger -p daemon.err -t ${PROG_NAME} "$@"
}
# Apply system optimizations
apply_sysctl_optimizations() {
if [ -f /etc/glorytun/glorytun-sysctl.conf ]; then
_log "Applying system optimizations"
sysctl -q -p /etc/glorytun/glorytun-sysctl.conf
fi
}
validate_section() {
uci_validate_section glorytun glorytun "${1}" \
'enable:bool:0' \
@@ -38,50 +30,13 @@ validate_section() {
'timeout:uinteger:10000' \
'chacha20:bool:0' \
'multiqueue:bool:1' \
'cpu_affinity:bool:1' \
'proto:string' \
'localip:string' \
'remoteip:string'
}
# New function for CPU core optimization
optimize_cpu_cores() {
local dev="$1"
local multiqueue="$2"
local cpu_affinity="$3"
if [ "$cpu_affinity" = "1" ]; then
_log "Setting up CPU affinity for $dev"
if [ -x /usr/sbin/glorytun-irq-affinity.sh ]; then
/usr/sbin/glorytun-irq-affinity.sh
fi
fi
if [ "$multiqueue" = "1" ]; then
_log "Enabling multiqueue for $dev"
# Get CPU count
local cpu_count=$(grep -c processor /proc/cpuinfo)
if [ "$cpu_count" -gt 1 ]; then
# Use half of available CPUs but at least 2
local queue_count=$(( cpu_count / 2 ))
[ "$queue_count" -lt 2 ] && queue_count=2
# Set multiqueue parameters
ip link set dev "$dev" multiqueue on
# Increase buffer sizes for better performance
if [ -e /proc/sys/net/core/rmem_max ]; then
echo 16777216 > /proc/sys/net/core/rmem_max
echo 16777216 > /proc/sys/net/core/wmem_max
echo 16777216 > /proc/sys/net/core/optmem_max
fi
fi
fi
}
start_instance() {
local enable key host port dev mptcp proto chacha20 mode multiqueue cpu_affinity timeout localip remoteip
local enable key host port dev mptcp proto chacha20 mode multiqueue timeout localip remoteip
local key_dir="/var/run/${PROG_NAME}"
local key_file="${key_dir}/${1}.key"
@@ -91,9 +46,6 @@ start_instance() {
}
[ "${enable}" = "1" ] || return 1
apply_sysctl_optimizations
[ "${proto}" = "tcp" ] || return 1
[ -n "${key}" ] || {
_err "Key empty"
@@ -147,25 +99,23 @@ start_instance() {
procd_set_param stderr 1
procd_close_instance
# Apply CPU optimizations after the instance is started
optimize_cpu_cores "$dev" "$multiqueue" "$cpu_affinity"
# Configure interface IP addresses
# Configure the tunnel addresses once glorytun has created the device.
# RPS/XPS steering for it is set by /etc/hotplug.d/net/20-rps-xps
# (openmptcprouter package), which handles every interface.
if [ -n "$localip" ] && [ -n "$remoteip" ]; then
(
# Wait for device to be created
local count=0
while [ $count -lt 10 ]; do
if ip link show "$dev" >/dev/null 2>&1; then
ifconfig "$dev" "$localip" pointopoint "$remoteip" up && \
_log "Configured $dev with IP $localip peer $remoteip"
break
fi
sleep 1
count=$((count + 1))
done
) &
(
count=0
while [ $count -lt 10 ]; do
if [ -d "/sys/class/net/$dev" ]; then
ifconfig "$dev" "$localip" pointopoint "$remoteip" up && \
_log "Configured $dev with IP $localip peer $remoteip"
break
fi
sleep 1
count=$((count + 1))
done
) &
fi
}