feat: debug options

This commit is contained in:
FUFSoB committed 2026-10-11 11:18:48 +05:00
1 parent cacd51595c
commit e293efd1c1
33 files changed
+965 -77

No files matched your search

+3
View File
@@ -68,6 +68,9 @@ in
withCurlImpersonate = cfg.tools.curlImpersonate.enable;
env = {
CLASH_API = "http://127.0.0.1:${toString singBoxCfg.clashApiPort}";
# The TUN backends' own, root's alone (`debug conns --backend`).
CLASH_API_TUN = "http://127.0.0.1:${toString constants.globalTunClashApiPort}";
CLASH_API_PER_APP_TUN = "http://127.0.0.1:${toString constants.perAppTunClashApiPort}";
SELECTION = selectionMode;
SUB_TAGS_FILE = toString subscriptionTagsFile;
SUB_CACHE_DIR = subscriptionCacheDir;
+93
View File
@@ -223,6 +223,98 @@ let
};
};
# debug.connectionLog: `proxy-ctl debug conns` into the journal, a unit per sing-box
# instance, up while it is.
connectionLogUnit =
let
logCfg = cfg.debug.connectionLog;
instances = [
{
unit = "proxy-suite-connection-log";
backend = "socks";
service = "proxy-suite-socks.service";
}
]
++ lib.optional globalTun.enable {
unit = "proxy-suite-connection-log-tun";
backend = "tun";
service = "proxy-suite-tun.service";
}
++ lib.optional perAppRoutingTun.enable {
unit = "proxy-suite-connection-log-per-app-tun";
backend = "per-app-tun";
service = "proxy-suite-per-app-tun.service";
};
in
lib.mkIf derived.connectionLogEnabled {
services.proxy-suite.internal.services = lib.listToAttrs (
map (instance: {
name = instance.unit;
value = mkConnectionLog logCfg instance;
}) instances
);
};
mkConnectionLog =
logCfg:
{ backend, service, ... }:
{
description = "proxy-suite - record the ${backend} backend's connections (debug.connectionLog)";
after = [ service ];
# Not BindsTo: per-app TUN stops when no app needs it, and this must not count as one.
partOf = [ service ];
wantedBy = [ service ];
serviceConfig = {
ExecStart = lib.escapeShellArgs (
[
"${control.proxyCtl}/bin/proxy-ctl"
"debug"
"conns"
"--backend"
backend
"--stall"
(toString logCfg.stallAfter)
"--interval"
(toString logCfg.interval)
]
++ lib.concatMap (h: [
"--host"
h
]) logCfg.hosts
++ lib.concatMap (i: [
"--inbound"
i
]) logCfg.inbounds
);
Restart = "on-failure";
RestartSec = 5;
# Root for the Clash API secret's sake (its file is root's), with no capability at all.
CapabilityBoundingSet = [ "" ];
NoNewPrivileges = true;
PrivateTmp = true;
# Root without capabilities still owns the disks' device nodes.
PrivateDevices = true;
ProtectSystem = "strict";
ProtectHome = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
LockPersonality = true;
RestrictAddressFamilies = [
"AF_UNIX"
"AF_INET"
"AF_INET6"
];
# The API is on loopback; nothing else to reach.
IPAddressAllow = [ "localhost" ];
IPAddressDeny = [ "any" ];
};
};
# userControl.groups cannot own the spools the way userControl.group does: POSIX ACLs let
# them in, set again on every boot and whenever the groups change (a changed unit
# restarts), so a group dropped from the configuration loses what it had. With
@@ -261,6 +353,7 @@ lib.mkMerge [
autoProxyUnits
outboundGroupsUnit
clashBrokerUnit
connectionLogUnit
aclUnit
{
services.proxy-suite.internal = {
@@ -257,7 +257,7 @@ let
set -euo pipefail
${resolveInstance}
${dnsServers}
exec ${python3} ${proxySuiteScriptsDir}/per_app_dns.py --port "$dns_port" --mark "$mark" "''${servers[@]}"
exec ${python3} ${proxySuiteScriptsDir}/per_app_dns.py --port "$dns_port" --mark "$mark" ${lib.optionalString cfg.debug.perAppDns "--log "}"''${servers[@]}"
'';
# A failure keeps the marking and the unreachable rule, so the apps are turned away rather
@@ -13,6 +13,7 @@ let
xrayEnabled
hybridEnabled
pureXrayEnabled
xrayLogLevel
constants
zapretCutoffProxyFallback
zapret2DirectSync
@@ -196,7 +197,8 @@ let
RUNTIME_DIR="${runtimeDir}"
ROUTE_MODE_STATE_FILE="${routeModeStateFile}"
BACKEND_JQ_FILTER=${lib.escapeShellArg backendJqFilterFile}
XRAY_LOGLEVEL=""
# debug.logLevel; empty keeps each config's own "warning".
XRAY_LOGLEVEL=${lib.escapeShellArg (lib.optionalString (xrayLogLevel != "warning") xrayLogLevel)}
XRAY_SINGLE_PROXY_TAG=""
mkdir -p "$RUNTIME_DIR"
OUTBOUNDS_JSON='[]'
+1
View File
@@ -193,6 +193,7 @@ let
]
++ map (l: "--listen ${l}") listeners
++ map (a: "--bind ${a}") bind
++ lib.optional ctx.cfg.debug.perAppDns "--log"
++ [ ctx.constants.perAppDnsUpstream ]
);
runtimeDirectory = "proxy-suite-per-app-${route}-dns";