This commit is contained in:
Adam Ierymenko 2014-05-21 02:48:58 +00:00
parent 319f9a9346
commit f0b821f880
3 changed files with 11 additions and 10 deletions

View file

@ -307,6 +307,7 @@ function doNetconfRequest(message)
DB.hmset(memberKey,{
'lastSeen': Date.now(),
'lastAt': fromIpAndPort,
'authorized': authorized ? '1' : '0', // reset authorized to unhide in UI, since UI uses -1 to hide
'clientVersion': (message.data['clientVersion']) ? message.data['clientVersion'] : '?.?.?',
'clientOs': (message.data['clientOs']) ? message.data['clientOs'] : '?'
},next);
@ -362,19 +363,19 @@ function doNetconfRequest(message)
var peerAddress = peerId.address();
var network = 0;
var ipnetwork = 0;
var netmask = 0;
var netmaskBits = 0;
var v4pool = network['v4AssignPool']; // technically csv but only one netblock currently supported
if (v4pool) {
var v4poolSplit = v4Pool.split('/');
var v4poolSplit = v4pool.split('/');
if (v4poolSplit.length === 2) {
var networkSplit = v4poolSplit[0].split('.');
if (networkSplit.length === 4) {
network |= (parseInt(networkSplit[0],10) << 24) & 0xff000000;
network |= (parseInt(networkSplit[1],10) << 16) & 0x00ff0000;
network |= (parseInt(networkSplit[2],10) << 8) & 0x0000ff00;
network |= parseInt(networkSplit[3],10) & 0x000000ff;
ipnetwork |= (parseInt(networkSplit[0],10) << 24) & 0xff000000;
ipnetwork |= (parseInt(networkSplit[1],10) << 16) & 0x00ff0000;
ipnetwork |= (parseInt(networkSplit[2],10) << 8) & 0x0000ff00;
ipnetwork |= parseInt(networkSplit[3],10) & 0x000000ff;
netmaskBits = parseInt(v4poolSplit[1],10);
if (netmaskBits > 32)
netmaskBits = 32; // sanity check
@ -384,7 +385,7 @@ function doNetconfRequest(message)
}
}
}
if ((network === 0)||(netmask === 0xffffffff))
if ((ipnetwork === 0)||(netmask === 0xffffffff))
return next(null);
var invmask = netmask ^ 0xffffffff;
@ -409,7 +410,7 @@ function doNetconfRequest(message)
abcd &= 0xffffffff;
// Derive an IP to test and generate assignment ip/bits string
var ip = (abcd & invmask) | (network & netmask);
var ip = (abcd & invmask) | (ipnetwork & netmask);
var assignment = ((ip >> 24) & 0xff).toString(10) + '.' + ((ip >> 16) & 0xff).toString(10) + '.' + ((ip >> 8) & 0xff).toString(10) + '.' + (ip & 0xff).toString(10) + '/' + netmaskBits.toString(10);
// Check :ipAssignments to see if this IP is already taken

View file

@ -5,7 +5,7 @@ export PATH=/bin:/usr/bin:/usr/local/bin
# We will start in ZT_HOME
if [ ! -d ./services.d/netconf-service ]; then
echo 'cannot find netconf-service subfolder to launch subprocess' >>&2
echo 'cannot find netconf-service subfolder to launch subprocess' >&2
exit 1
fi

View file

@ -101,6 +101,6 @@ The ipAssignments field is re-generated whenever the zt1:network:\<nwid\>:ipAssi
### zt1:network:\<nwid\>:ipAssignments
This is a hash mapping IP/netmask bits fields to 10-digit ZeroTier addresses of network members. IPv4 fields contain dots, e.g. "10.2.3.4/24" or "29.1.1.1/7". IPv6 fields contain colons. Note that IPv6 IP abbreviations should *not* be used; use \:0000\: instead of \:\: for zero parts of addresses. This is to simplify parser code and canonicalize for rapid search. All hex digits must be lower-case.
This is a hash mapping IP/netmask bits fields to 10-digit ZeroTier addresses of network members. IPv4 fields contain dots, e.g. "10.2.3.4/24" or "29.1.1.1/7". IPv6 fields contain colons. Note that IPv6 IP abbreviations must *not* be used; use \:0000\: instead of \:\: for zero parts of addresses. This is to simplify parser code and canonicalize for rapid search. All hex digits must be lower-case.
This is only used if the network's IPv4 and/or IPv6 auto-assign mode is 'zt' for ZeroTier assignment. The netconf-master will auto-populate by choosing unused IPs, and it can be edited via the API as well.