25 lines
1.8 KiB
TypeScript
25 lines
1.8 KiB
TypeScript
/** Native ECMP gateways can be a comma list or an array. Match exact table
|
|
* names/IDs after @, including address%interface@table and interface@table. */
|
|
export function gatewayReferencesTable(value: unknown, references: readonly string[]) {
|
|
if (value === undefined || value === "") return false
|
|
const values = typeof value === "string" ? [value] : value
|
|
if (!Array.isArray(values) || values.length > 256 || values.some(item => typeof item !== "string" || item.length > 65536)) throw new Error("Не подтверждены gateway references маршрута")
|
|
const matches = (token: string) => references.some(reference => reference.length > 0 && token.length > reference.length + 1 && token.endsWith("@" + reference))
|
|
// Preserve literal whitespace in names before accepting separator whitespace.
|
|
if (values.some(item => matches(item) || matches(item.trim()))) return true
|
|
if (!values.some(item => item.includes("@"))) return false
|
|
if (references.some(reference => /[,"'\\\r\n]/.test(reference)) || values.some(item => /["'\\\r\n]/.test(item))) throw new Error("Не подтверждён синтаксис gateway/table references")
|
|
const tokens: string[] = []
|
|
for (const item of values) for (const token of item.split(",")) {
|
|
if (tokens.length >= 256) throw new Error("Превышен предел ECMP gateway references")
|
|
tokens.push(token)
|
|
}
|
|
return tokens.some(token => matches(token) || matches(token.trim()))
|
|
}
|
|
|
|
/** Derived routes inside the target table are removed/moved by VRF membership;
|
|
* keep them sealed for drift checks without treating them as external users. */
|
|
export function isDynamicRouteInsideTable(row: Readonly<Record<string, unknown>>, references: readonly string[]) {
|
|
return [true, "true"].includes(row.dynamic as boolean | string) && typeof row["routing-table"] === "string" && references.includes(row["routing-table"])
|
|
}
|