Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(config): distinguish network routes from default gateways

Rudy Celekliacf8e1d07ce8
diff --git a/app/config/config.py b/app/config/config.py
index 4538fdfa..dadb9f4b 100644
--- a/app/config/config.py
+++ b/app/config/config.py
@@ -383,12 +383,16 @@ def get_container_default_gateway_ip(route_path: str = "/proc/net/route") -> str
for line in route_lines[1:]:
fields = line.strip().split()
- if len(fields) < 3:
+ if len(fields) < 8:
continue
destination = fields[1]
gateway = fields[2]
- if destination != "00000000" or gateway == "00000000":
+ if (
+ destination != "00000000"
+ or fields[7] != "00000000"
+ or gateway == "00000000"
+ ):
continue
try:
diff --git a/test/services/test_container_default_route_mask.py b/test/services/test_container_default_route_mask.py
new file mode 100644
index 00000000..101aa349
--- /dev/null
+++ b/test/services/test_container_default_route_mask.py
@@ -0,0 +1,18 @@
+import pytest
+
+from app.config import config
+
+
+HEADER = "Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT\n"
+SPLIT_ROUTE = "tun0 00000000 0100080A 0003 0 0 0 00000080 0 0 0\n"
+DEFAULT_ROUTE = "eth0 00000000 010011AC 0003 0 0 100 00000000 0 0 0\n"
+
+
[email protected]("routes,expected", [
+ (SPLIT_ROUTE + DEFAULT_ROUTE, "172.17.0.1"),
+ (SPLIT_ROUTE, ""),
+])
+def test_zero_destination_network_route_is_not_a_default_gateway(tmp_path, routes, expected):
+ route_path = tmp_path / "route"
+ route_path.write_text(HEADER + routes)
+ assert config.get_container_default_gateway_ip(str(route_path)) == expected