Skip to content

Commit 684ba22

Browse files
committed
Install netcat-openbsd on gateways that only have busybox nc
busybox nc lacks the -q flag needed for clean connection teardown. Install netcat-openbsd if nc is missing or is the busybox version, then use the original nc -q 1 which works correctly.
1 parent 7af0da8 commit 684ba22

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/NetworkOptimizer.Web/Services/SqmDeploymentService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,11 @@ private string GenerateSqmMonitorScript(string wan1Interface, string wan1Name, s
10691069
sb.AppendLine();
10701070
sb.AppendLine("mkdir -p \"$SQM_MONITOR_DIR\"");
10711071
sb.AppendLine();
1072+
sb.AppendLine("# Install netcat if not available (busybox nc lacks -q flag)");
1073+
sb.AppendLine("if ! command -v nc > /dev/null 2>&1 || nc -h 2>&1 | grep -q BusyBox; then");
1074+
sb.AppendLine(" apt-get update -qq > /dev/null 2>&1 && apt-get install -y -qq netcat-openbsd > /dev/null 2>&1");
1075+
sb.AppendLine("fi");
1076+
sb.AppendLine();
10721077
sb.AppendLine("# Create the SQM monitor handler script");
10731078
sb.AppendLine("cat > \"$SQM_MONITOR_DIR/sqm-monitor.sh\" << 'HANDLER_EOF'");
10741079
sb.AppendLine("#!/bin/sh");
@@ -1297,7 +1302,7 @@ private string GenerateSqmMonitorScript(string wan1Interface, string wan1Name, s
12971302
sb.AppendLine(" echo \"Access-Control-Allow-Origin: *\"");
12981303
sb.AppendLine(" echo \"\"");
12991304
sb.AppendLine(" \"$SCRIPT_DIR/sqm-monitor.sh\"");
1300-
sb.AppendLine(" } | busybox nc -l -p \"$PORT\" > /dev/null 2>&1");
1305+
sb.AppendLine(" } | nc -l -p \"$PORT\" -q 1 > /dev/null 2>&1");
13011306
sb.AppendLine(" sleep 0.1");
13021307
sb.AppendLine("done");
13031308
sb.AppendLine("SERVER_EOF");

0 commit comments

Comments
 (0)