8 Commits

Author SHA1 Message Date
juewuy
732d17087e Merge pull request #1302 from DustinWin/new-dev
sing-box 域名嗅探相关优化
2026-07-11 16:39:32 +08:00
juewuy
19cc6b70a0 Merge pull request #1305 from ashi009/core-store-raw-on-compressed-rom
core: 压缩 rom 设备优先裸二进制、避开 upx,不解压到 tmpfs
2026-07-11 16:39:06 +08:00
Xiaoyi
433774071a core: choose core storage by weighing rom cost vs ram cost
Replaces the binary compressed-rom check with store_raw_worth_it(),
which decides per environment: store the naked binary on $BINDIR (0 RAM)
only when $TMPDIR is tmpfs AND $BINDIR can hold it with margin
(estimated ~2:1 on squashfs/ubifs, full size otherwise). Otherwise keep
a compressed copy and decompress to tmp as before. core_webget skips
the upx core when raw storage is viable, fetching tar.gz instead.

Rationale (rough budgets for a ~40M core): raw on squashfs ~15M rom /
0 RAM; gz 10M rom / ~40M RAM; upx 9M rom / ~40M RAM (memfd). Raw wins
when rom has room; compressed wins when rom is the scarce resource.

Also corrects the upx branch symlink target $TMPDIR -> $BINDIR (#1295).

For #1304
2026-07-11 16:38:49 +08:00
Xiaoyi
55cfa65875 core: prefer raw binary on compressed rom, avoid upx on tmpfs devices
Adds store_on_rom() helper (tmpfs $TMPDIR + squashfs/ubifs/overlay
$BINDIR). On such devices core_webget no longer downloads the upx core
(its stub decompresses into a memfd = RAM at runtime); it fetches the
tar.gz instead and core_check stores the naked binary as
$BINDIR/CrashCore.raw, symlinked from $TMPDIR. The binary is
transparently compressed on rom and file-backed/reclaimable at runtime
(RssShmem 0). Other filesystems and explicit upx keep prior behavior.

Also corrects the upx branch symlink target $TMPDIR -> $BINDIR (same
dangling-symlink issue as #1295).

For #1304
2026-07-11 15:59:42 +08:00
Xiaoyi
edd6936903 core: store naked core on compressed rom instead of unpacking to tmpfs
On OpenWrt $TMPDIR is tmpfs (RAM) and $BINDIR sits on a
transparently-compressed fs (squashfs/ubifs). Unpacking the core to
$TMPDIR pins the whole ~40MB binary in unreclaimable Shmem, and a
compressed copy is still kept on rom - paying twice.

When $TMPDIR is tmpfs and $BINDIR is squashfs/ubifs/overlay, store the
verified naked binary as $BINDIR/CrashCore.raw and symlink
$TMPDIR/CrashCore to it, dropping the downloaded archive. The binary is
transparently compressed on rom (~2.2:1, comparable to keeping .gz) and
its text/rodata become file-backed and reclaimable at runtime
(RssShmem 0). Other filesystems keep the existing behavior.

The upx branch's symlink target is also corrected from $TMPDIR to
$BINDIR (same dangling-symlink issue as #1295).

For #1304
2026-07-11 15:41:46 +08:00
DustinWin
988c0cde34 sing-box 域名嗅探相关优化 2026-07-07 10:53:01 +08:00
DustinWin
a85cd5b505 Merge branch 'juewuy:dev' into dev 2026-07-07 10:45:02 +08:00
DustinWin
b31c824f94 适配 sing-box v1.14.0-alpha.21+ 版本内核 2026-05-17 22:48:13 +08:00
5 changed files with 55 additions and 16 deletions

View File

@@ -216,7 +216,7 @@ UPG_CORE_V1_SUFFIX=" \033[32m原meta内核支持全面\033[0m \033[33m占
UPG_CORE_V1_DOC="说明文档:\033[36;4mhttps://wiki.metacubex.one\033[0m"
UPG_CORE_V2_PREFIX="2) \033[43;30mSingBoxR\033[0m\033[32m"
UPG_CORE_V2_SUFFIX=" \033[32m支持全面\033[0m \033[33m使用reF1nd增强分支\033[0m"
UPG_CORE_V2_DOC="说明文档:\033[36;4mhttps://sing-boxr.dustinwin.us.kg\033[0m"
UPG_CORE_V2_DOC="说明文档:\033[36;4mhttps://sing-boxr.dustinwin.cc.cd\033[0m"
UPG_CORE_V3_PREFIX="3) \033[43;30mSingBox\033[0m\033[32m"
UPG_CORE_V3_SUFFIX=" \033[32m占用较低\033[0m \033[33m不支持providers\033[0m"
UPG_CORE_V3_DOC="说明文档:\033[36;4mhttps://sing-box.sagernet.org\033[0m"

View File

@@ -216,7 +216,7 @@ UPG_CORE_V1_SUFFIX=" \033[32m(full meta core) highly compatible\033[0m \033[33mm
UPG_CORE_V1_DOC="Docs: \033[36;4mhttps://wiki.metacubex.one\033[0m"
UPG_CORE_V2_PREFIX="2) \033[43;30mSingBoxR\033[0m: \033[32m"
UPG_CORE_V2_SUFFIX=" \033[32mfully featured\033[0m \033[33mreF1nd enhanced branch\033[0m"
UPG_CORE_V2_DOC="Docs: \033[36;4mhttps://sing-boxr.dustinwin.us.kg\033[0m"
UPG_CORE_V2_DOC="Docs: \033[36;4mhttps://sing-boxr.dustinwin.cc.cd\033[0m"
UPG_CORE_V3_PREFIX="3) \033[43;30mSingBox\033[0m: \033[32m"
UPG_CORE_V3_SUFFIX=" \033[32mlower resource usage\033[0m \033[33mproviders are not supported\033[0m"
UPG_CORE_V3_DOC="Docs: \033[36;4mhttps://sing-box.sagernet.org\033[0m"

View File

@@ -2,6 +2,20 @@
[ -n "$(find --help 2>&1 | grep -o size)" ] && find_para=' -size +2000' #find命令兼容
#根据环境权衡决定是否把裸二进制存于$BINDIR(rom)——省RAM前提是rom装得下
#$1=裸二进制字节数。仅当$TMPDIR在内存(tmpfs)时裸存才省RAM
#再按$BINDIR文件系统估算裸二进制落盘体积(透明压缩fs约2:1),需留有余量($raw_margin,默认8M)
store_raw_worth_it(){
case "$(df -T "$TMPDIR" 2>/dev/null | awk 'END{print $2}')" in tmpfs|ramfs) ;; *) return 1 ;; esac
rom_free=$(df -k "$BINDIR" 2>/dev/null | awk 'END{print $4}') #KB
[ -z "$rom_free" ] && return 1
case "$(df -T "$BINDIR" 2>/dev/null | awk 'END{print $2}')" in
squashfs|ubifs|overlay|overlayfs) est=$(( ${1:-0}/1024/2 )) ;; #透明压缩约2:1
*) est=$(( ${1:-0}/1024 )) ;; #无压缩,全量
esac
[ $(( rom_free - est )) -gt "${raw_margin:-8192}" ] && return 0 || return 1
}
core_unzip() { #$1:需要解压的文件 $2:目标文件名
if echo "$1" |grep -q 'tar.gz$' ;then
[ "$BINDIR" = "$TMPDIR" ] && rm -rf "$TMPDIR"/CrashCore #小闪存模式防止空间不足
@@ -14,6 +28,8 @@ core_unzip() { #$1:需要解压的文件 $2:目标文件名
rm -rf "$TMPDIR"/core_tmp
elif echo "$1" |grep -q '.gz$' ;then
gunzip -c "$1" > "$TMPDIR"/"$2"
elif echo "$1" |grep -q '.raw$' ;then
ln -sf "$1" "$TMPDIR"/"$2"
elif echo "$1" |grep -q '.upx$' ;then
ln -sf "$1" "$TMPDIR"/"$2"
else
@@ -45,16 +61,20 @@ core_check(){
rm -rf "$1" "$TMPDIR"/core_new
return 2
else
rm -f "$BINDIR"/CrashCore.tar.gz "$BINDIR"/CrashCore.gz "$BINDIR"/CrashCore.upx
if [ -z "$zip_type" ];then
rm -f "$BINDIR"/CrashCore.tar.gz "$BINDIR"/CrashCore.gz "$BINDIR"/CrashCore.upx "$BINDIR"/CrashCore.raw
if [ "$zip_type" = 'upx' ];then
mv -f "$1" "$BINDIR/CrashCore.upx"
rm -f "$TMPDIR"/core_new
ln -sf "$BINDIR/CrashCore.upx" "$TMPDIR/CrashCore"
elif store_raw_worth_it "$(wc -c < "$TMPDIR/core_new")" ;then
rm -f "$1"
mv -f "$TMPDIR/core_new" "$BINDIR/CrashCore.raw"
ln -sf "$BINDIR/CrashCore.raw" "$TMPDIR/CrashCore"
elif [ -z "$zip_type" ];then
gzip -c "$TMPDIR/core_new" > "$BINDIR/CrashCore.gz"
mv -f "$TMPDIR/core_new" "$TMPDIR/CrashCore"
else
mv -f "$1" "$BINDIR/CrashCore.$zip_type"
fi
if [ "$zip_type" = 'upx' ];then
rm -f "$1" "$TMPDIR"/core_new
ln -sf "$TMPDIR/CrashCore.upx" "$TMPDIR/CrashCore"
else
mv -f "$TMPDIR/core_new" "$TMPDIR/CrashCore"
fi
core_v="$v"
@@ -70,6 +90,8 @@ core_webget(){
. "$CRASHDIR"/libs/check_target.sh
if [ -z "$custcorelink" ];then
[ -z "$zip_type" ] && zip_type='tar.gz'
#若环境适合裸存(见store_raw_worth_it按典型核心~45M估算)避免下载upx改取tar.gz的裸二进制
[ "$zip_type" = 'upx' ] && store_raw_worth_it 47185920 && zip_type='tar.gz'
get_bin "$TMPDIR/Coretmp.$zip_type" "bin/$crashcore/${target}-linux-${cpucore}.$zip_type"
else
case "$custcorelink" in

View File

@@ -540,7 +540,7 @@ EOF
# s自定义singbox配置文件
set_singbox_adv() {
comp_box "\033[33m$OVR_SING_TITLE1\033[0m" \
"\033[36mlog dns ntp certificate experimental\033[0m" \
"\033[36mlog dns ntp certificate http_clients experimental\033[0m" \
"\033[33m$OVR_SING_TITLE2\033[0m" \
"\033[36mendpoints inbounds outbounds providers route services\033[0m" \
"$OVR_SING_TITLE3" \

View File

@@ -92,10 +92,11 @@ EOF
],
"rules": [
{
"ip_accept_any": true,
"preferred_by": [ "hosts" ],
"server": "hosts"
}
]}
]
}
}
EOF
fi
@@ -153,7 +154,7 @@ generate_dns_related_jsons() {
"format": "binary",
$srs_path
"url": "https://testingcf.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/cn.srs",
"download_detour": "DIRECT"
"http_client": "detour_direct"
}
]
}
@@ -217,7 +218,8 @@ EOF
generate_route_and_inbounds_jsons() {
#生成add_route.json
#域名嗅探配置
[ "$sniffer" != OFF ] && sniffer_set='{ "domain_suffix": [ "push.apple.com" ], "rule_set": [ "telegramip" ], "domain": [ "Mijia Cloud" ], "invert": true, "action": "sniff", "timeout": "500ms" },'
grep -q 'telegramip' "$TMPDIR"/jsons/route.json && telegramip_set=' "rule_set": [ "telegramip" ],'
[ "$sniffer" != OFF ] && sniffer_set='{ "domain_suffix": [ "push.apple.com" ],'"$telegramip_set"' "domain": [ "Mijia Cloud" ], "invert": true, "action": "sniff", "timeout": "500ms" },'
[ "$ts_service" = ON ] && tailscale_set='{ "inbound": [ "ts-ep" ], "port": 53, "action": "hijack-dns" },'
cat >"$TMPDIR"/jsons/add_route.json <<EOF
{
@@ -225,9 +227,9 @@ generate_route_and_inbounds_jsons() {
"default_domain_resolver": "dns_resolver",
"default_mark": $routing_mark,
"rules": [
{ "inbound": [ "dns-in" ], "action": "hijack-dns" },
$tailscale_set
$sniffer_set
{ "inbound": [ "dns-in" ], "action": "hijack-dns" },
{ "clash_mode": "Direct" , "outbound": "DIRECT" },
{ "clash_mode": "Global" , "outbound": "GLOBAL" }
]
@@ -324,6 +326,21 @@ generate_outbounds_and_experimental_jsons() {
$add_global
]
}
EOF
#生成http_clients.json
cat >"$TMPDIR"/jsons/http_clients.json <<EOF
{
"http_clients": [
{
"tag": "detour_proxy",
"detour": "GLOBAL"
},
{
"tag": "detour_direct",
"detour": "DIRECT"
}
]
}
EOF
#生成experimental.json
[ "$crashcore" = "singboxr" ] && urltest_unified_delay=',"urltest_unified_delay": true'
@@ -394,7 +411,7 @@ link_custom_jsons() {
#加载自定义配置文件
mkdir -p "$TMPDIR"/jsons_base
#以下为覆盖脚本的自定义文件
for char in log dns ntp certificate experimental; do
for char in log dns ntp certificate http_clients experimental; do
[ -s "$CRASHDIR"/jsons/${char}.json ] && {
ln -sf "$CRASHDIR"/jsons/${char}.json "$TMPDIR"/jsons/cust_${char}.json
mv -f "$TMPDIR"/jsons/${char}.json "$TMPDIR"/jsons_base #如果重复则临时备份