mirror of
https://github.com/nttgin/BGPalerter.git
synced 2024-05-19 06:50:08 +00:00
improved accuracy rules matching
This commit is contained in:
@@ -36,6 +36,8 @@ import ipUtils from "../ipUtils";
|
||||
export default class Input {
|
||||
|
||||
constructor(config){
|
||||
this.prefixes = [];
|
||||
this.cache = {};
|
||||
};
|
||||
|
||||
validateAS = (asn) => {
|
||||
@@ -60,4 +62,28 @@ export default class Input {
|
||||
throw new Error('The method getMonitoredPrefixes MUST be implemented');
|
||||
};
|
||||
|
||||
getMoreSpecificMatch = (prefix) => {
|
||||
|
||||
for (let p of this.prefixes) {
|
||||
if (p.prefix === prefix) {
|
||||
return p;
|
||||
} else {
|
||||
if (!this.cache[p.prefix]) {
|
||||
this.cache[p.prefix] = ipUtils.getNetmask(p.prefix);
|
||||
}
|
||||
const p2 = ipUtils.getNetmask(prefix);
|
||||
|
||||
if (ipUtils.isSubnetBinary(this.cache[p.prefix], p2)) {
|
||||
if (p.ignoreMorespecifics){
|
||||
return null;
|
||||
} else {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import yaml from "js-yaml";
|
||||
import fs from "fs";
|
||||
import Input from "./input";
|
||||
import env from "../env";
|
||||
import ipUtils from "../ipUtils";
|
||||
|
||||
export default class InputYml extends Input {
|
||||
|
||||
@@ -70,9 +71,12 @@ export default class InputYml extends Input {
|
||||
|
||||
this.prefixes = this.prefixes.concat(monitoredPrefixes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.prefixes = this.prefixes.sort((a, b) => {
|
||||
return ipUtils.sortByPrefixLength(b.prefix, a.prefix);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
validate = (fileContent) => {
|
||||
|
||||
Reference in New Issue
Block a user