From b50215f6205dd00fa76a5e63b8c08f3ba4c0f09d Mon Sep 17 00:00:00 2001 From: lideming Date: Mon, 3 Jan 2022 09:43:40 +0800 Subject: [PATCH] fix IPv6 route target comparing (#75) --- src/controllers/zt.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/controllers/zt.js b/src/controllers/zt.js index d01f415..0d1117e 100644 --- a/src/controllers/zt.js +++ b/src/controllers/zt.js @@ -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';