1
0
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:
Massimo Candela
2019-08-18 23:19:33 +02:00
parent 4d816feb08
commit 7ea02e88af
9 changed files with 90 additions and 57 deletions

View File

@@ -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;
};
}

View File

@@ -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) => {