feat(ping): enhance interface resolution logic by integrating gateway checks for improved tunnel interface matching
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 3m54s

This commit is contained in:
2026-02-10 22:54:50 +07:00
parent 18e488a8e8
commit de6fd2dddb
+36
View File
@@ -12,6 +12,7 @@ const {
buildMikrotikConfig,
buildMikrotikInterfaceBlocks,
buildMikrotikRecursiveRoutes,
getParentGateway,
} = require('../utils/mikrotikInterfaceGenerator');
const { createRosClient, applyBlock } = require('../services/mikrotikApplyService');
@@ -318,6 +319,7 @@ async function pingViaInterface(req, res) {
const config = await loadNetworkConfig();
const tunnelIfaces = Array.isArray(config.tunnelInterfaces) ? config.tunnelInterfaces : [];
// 1) Пытаемся сопоставить gatewayIp с локальным/удалённым IP туннельного интерфейса
const iface = tunnelIfaces.find((i) => {
const sameServer =
i.serverId === serverId ||
@@ -330,6 +332,40 @@ async function pingViaInterface(req, res) {
if (iface) {
ifaceName = iface.name || null;
}
// 2) Если по tunnelInterfaces не нашли — пробуем взять интерфейс из gateways в /network-config
if (!ifaceName && Array.isArray(config.gateways)) {
const gw = config.gateways.find((g) => {
if (!g || !g.ip) return false;
const sameServer =
g.serverId === serverId ||
g.serverId === server.ip ||
g.serverId === server.dns;
return sameServer && g.ip === gatewayIp;
});
if (gw) {
// Вариант А: gateway сам хранит имя интерфейса
if (gw.interfaceName) {
ifaceName = gw.interfaceName;
}
// Вариант Б: gateway ссылается на интерфейс через parentGatewayId / parentGateways
if (!ifaceName && (gw.parentGatewayId || (Array.isArray(gw.parentGateways) && gw.parentGateways.length > 0))) {
const parentRefs = (gw.parentGateways && gw.parentGateways.length > 0)
? gw.parentGateways
: [{ id: gw.parentGatewayId }];
for (const pref of parentRefs) {
const parent = getParentGateway(pref.id, config);
if (parent && parent.parentType === 'interface' && parent.name) {
ifaceName = parent.name;
break;
}
}
}
}
}
}
const body = {};