Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions lib/endpoints/networks/ips.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ function ensureIpExists(req, res, next) {
return;
}

if (!filterRange(ip)) {
next(new restify.ResourceNotFoundError(
'IP address not within network range'));
}

req._ip = ip;
res.etag = ip.etag;

Expand All @@ -88,14 +93,40 @@ function validateIP(req, res, next) {
if (!req._network.subnet.contains(ip)) {
return next(new restify.ResourceNotFoundError(
'IP is not in subnet'));

}

req.params.ip = ip;

return next();
}

/**
* Honor Network Provisionable Range
*/
function filterRange(ip) {
assert.object(ip, "ip")

// We should show managed addresses
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Show" managed addresses, or "evaluate within" managed addresses? Not sure what's being shown here.

Or is this a TODO item you want to have happen later?

if (ip.params != null && ip.params.belongs_to_type === "other") {
return true;
}

var Addr
if (ip.params.ipaddr != null) {
Addr = util_ip.addressToNumber(ip.params.ipaddr);
}
if (ip.params.ip != null) {
Addr = util_ip.addressToNumber(ip.params.ip.toString());
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you guaranteed that Addr will be set when you reach here? (Pardon my JS lack of knowledge here... not knowing any better, it could be possible that "ipaddr" AND "ip" are both null.

var maxAddr = util_ip.addressToNumber(ip.params.network.provisionMax.toString());
var minAddr = util_ip.addressToNumber(ip.params.network.provisionMin.toString());
if (Addr >= minAddr && Addr <= maxAddr) {
return true;
}

return false;
}



// --- Endpoints
Expand All @@ -114,7 +145,9 @@ function listIPs(req, res, next) {

var serialized = [];
for (var t in ips) {
serialized.push(ips[t].serialize());
if (filterRange(ips[t])) {
serialized.push(ips[t].serialize());
}
}

res.send(200, serialized);
Expand All @@ -131,6 +164,7 @@ function getIP(req, res, next) {
if (req._ip.etag !== null) {
res.header('Etag', req._ip.etag);
}

res.send(200, req._ip.serialize());
next();
}
Expand Down