fix(ospf): сопоставлять IPv6 адреса и исключать неоднозначный BFD

This commit is contained in:
Denozordec committed 2026-10-12 09:48:06 +07:00
1 parent 1b63e3ec43
commit e1617f1472
11 files changed
+201 -19

No files matched your search

+14 -3
View File
@@ -19,11 +19,22 @@ export function ospfBfdConflicts<T extends { localRouter: string; localIface: st
interfaces: Array<{ serverId: string; interfaceName: string; useBfd?: boolean | null; active?: boolean | null; dataUnknown?: boolean }>,
sessions: Array<{ serverId: string; iface: string; remoteAddr: string; state: BfdState; multihop?: boolean | null; dataUnknown?: boolean }>,
): T[] {
const ip = (value: string) => value.split("%")[0]?.toLowerCase() ?? ""
const ip = (value: string, iface: string): string | null => {
const [address, zone, ...extra] = value.trim().split("%")
if (!address || extra.length || (zone !== undefined && zone !== iface)) return null
if (address.includes(":")) {
if (!/^[0-9a-f:.]+$/i.test(address)) return null
try { return new URL(`http://[${address}]/`).hostname } catch { return null }
}
const parts = address.split(".")
return parts.length === 4 && parts.every(p => /^(0|[1-9]\d{0,2})$/.test(p) && Number(p) <= 255) ? address : null
}
return neighbors.filter(n => {
if (n.dataUnknown || n.state !== "Full" || !n.neighborAddress || !n.localIface) return false
if (!interfaces.some(i => !i.dataUnknown && i.active === true && i.useBfd === true && i.serverId === n.localRouter && i.interfaceName === n.localIface)) return false
const matching = sessions.filter(s => !s.dataUnknown && s.multihop === false && s.serverId === n.localRouter && s.iface === n.localIface && ip(s.remoteAddr) === ip(n.neighborAddress!))
return matching.length === 1 && (matching[0]!.state === "Down" || matching[0]!.state === "AdminDown")
const peer = ip(n.neighborAddress, n.localIface)
if (!peer) return false
const matching = sessions.filter(s => s.multihop === false && s.serverId === n.localRouter && s.iface === n.localIface && ip(s.remoteAddr, s.iface) === peer)
return matching.length === 1 && !matching[0]!.dataUnknown && (matching[0]!.state === "Down" || matching[0]!.state === "AdminDown")
})
}