fix IPv6 route target comparing (#75)

This commit is contained in:
lideming 2022-01-03 09:43:40 +08:00 committed by GitHub
parent d05963695b
commit b50215f620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -186,13 +186,9 @@ exports.routes = async function(nwid, route, action) {
const network = await network_detail(nwid);
let routes = network.routes;
const target6 = new ipaddr.Address6(route.target);
if (target6.isValid()) {
const parts = route.target.split('/');
route.target = target6.canonicalForm() + '/' + parts[1];
}
route.target = canonicalTarget(route.target);
const route_to_del = routes.find(rt => rt.target === route.target);
const route_to_del = routes.find(rt => canonicalTarget(rt.target) === route.target);
if (!route_to_del) {
if (action === 'add') {
@ -220,6 +216,15 @@ exports.routes = async function(nwid, route, action) {
}
}
function canonicalTarget(target) {
const target6 = new ipaddr.Address6(target);
if (target6.isValid()) {
const parts = target.split('/');
return target6.canonicalForm() + '/' + parts[1];
}
return target;
}
exports.network_object = async function(nwid, object) {
const options = await init_options();
options.method = 'POST';