mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-29 15:35:13 +08:00
💐 Sync 2026-09-10 14:49:21
This commit is contained in:
1 parent
0e9e9c2496
commit
7b0b16dcd4
181 files changed
+23375
-22143
No files matched your search
+17
-67
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user