Skip to content

Commit

Permalink
fix IPv6 route target comparing (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
lideming authored Jan 3, 2022
1 parent d059636 commit b50215f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/controllers/zt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit b50215f

Please sign in to comment.