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
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 3m54s
This commit is contained in:
@@ -12,6 +12,7 @@ const {
|
|||||||
buildMikrotikConfig,
|
buildMikrotikConfig,
|
||||||
buildMikrotikInterfaceBlocks,
|
buildMikrotikInterfaceBlocks,
|
||||||
buildMikrotikRecursiveRoutes,
|
buildMikrotikRecursiveRoutes,
|
||||||
|
getParentGateway,
|
||||||
} = require('../utils/mikrotikInterfaceGenerator');
|
} = require('../utils/mikrotikInterfaceGenerator');
|
||||||
const { createRosClient, applyBlock } = require('../services/mikrotikApplyService');
|
const { createRosClient, applyBlock } = require('../services/mikrotikApplyService');
|
||||||
|
|
||||||
@@ -318,6 +319,7 @@ async function pingViaInterface(req, res) {
|
|||||||
const config = await loadNetworkConfig();
|
const config = await loadNetworkConfig();
|
||||||
const tunnelIfaces = Array.isArray(config.tunnelInterfaces) ? config.tunnelInterfaces : [];
|
const tunnelIfaces = Array.isArray(config.tunnelInterfaces) ? config.tunnelInterfaces : [];
|
||||||
|
|
||||||
|
// 1) Пытаемся сопоставить gatewayIp с локальным/удалённым IP туннельного интерфейса
|
||||||
const iface = tunnelIfaces.find((i) => {
|
const iface = tunnelIfaces.find((i) => {
|
||||||
const sameServer =
|
const sameServer =
|
||||||
i.serverId === serverId ||
|
i.serverId === serverId ||
|
||||||
@@ -330,6 +332,40 @@ async function pingViaInterface(req, res) {
|
|||||||
if (iface) {
|
if (iface) {
|
||||||
ifaceName = iface.name || null;
|
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 = {};
|
const body = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user