mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-18 10:46:33 +00:00
Build fixes.
This commit is contained in:
parent
5202fbdaf3
commit
883a216d2a
@ -178,6 +178,7 @@ SqliteNetworkController::SqliteNetworkController(const char *dbPath) :
|
||||
||(sqlite3_prepare_v2(_db,"INSERT INTO Network (networkId,name,creationTime,revision) VALUES (?,?,?,1)",-1,&_sCreateNetwork,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"UPDATE Network SET ? = ? WHERE networkId = ?",-1,&_sUpdateNetworkField,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT revision FROM Network WHERE id = ?",-1,&_sGetNetworkRevision,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"UPDATE Network SET revision = ? WHERE id = ?",-1,&_sSetNetworkRevision,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT ip,ipNetmaskBits,ipVersion FROM IpAssignment WHERE networkId = ? AND nodeId = ?",-1,&_sGetIpAssignmentsForNode2,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"DELETE FROM Relay WHERE networkId = ?",-1,&_sDeleteRelaysForNetwork,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"INSERT INTO Relay (networkId,nodeId,phyAddress) VALUES (?,?,?)",-1,&_sCreateRelay,(const char **)0) != SQLITE_OK)
|
||||
@ -220,6 +221,7 @@ SqliteNetworkController::~SqliteNetworkController()
|
||||
sqlite3_finalize(_sCreateNetwork);
|
||||
sqlite3_finalize(_sUpdateNetworkField);
|
||||
sqlite3_finalize(_sGetNetworkRevision);
|
||||
sqlite3_finalize(_sSetNetworkRevision);
|
||||
sqlite3_finalize(_sGetIpAssignmentsForNode2);
|
||||
sqlite3_finalize(_sDeleteRelaysForNetwork);
|
||||
sqlite3_finalize(_sCreateRelay);
|
||||
@ -841,11 +843,17 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
||||
int64_t revision = 0;
|
||||
sqlite3_reset(_sGetNetworkRevision);
|
||||
sqlite3_bind_text(_sGetNetworkRevision,1,nwids,16,SQLITE_STATIC);
|
||||
if (sqlite3_step(_sGetNetworkRevision) == SQLITE_ROW)
|
||||
bool networkExists = false;
|
||||
if (sqlite3_step(_sGetNetworkRevision) == SQLITE_ROW) {
|
||||
networkExists = true;
|
||||
revision = sqlite3_column_int64(_sGetNetworkRevision,0);
|
||||
}
|
||||
|
||||
if (path.size() >= 3) {
|
||||
|
||||
if (!networkExists)
|
||||
return 404;
|
||||
|
||||
if ((path.size() == 4)&&(path[2] == "member")&&(path[3].length() == 10)) {
|
||||
uint64_t address = Utils::hexStrToU64(path[3].c_str());
|
||||
char addrs[24];
|
||||
@ -856,7 +864,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
||||
|
||||
} else {
|
||||
|
||||
if (revision <= 0) {
|
||||
if (!networkExists) {
|
||||
sqlite3_reset(_sCreateNetwork);
|
||||
sqlite3_bind_text(_sCreateNetwork,1,nwids,16,SQLITE_STATIC);
|
||||
sqlite3_bind_text(_sCreateNetwork,2,nwids,16,SQLITE_STATIC); // default name, will be changed below if a name is specified in JSON
|
||||
@ -1081,6 +1089,11 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
||||
json_value_free(j);
|
||||
}
|
||||
|
||||
sqlite3_reset(_sSetNetworkRevision);
|
||||
sqlite3_bind_int64(_sSetNetworkRevision,1,revision += 1);
|
||||
sqlite3_bind_text(_sSetNetworkRevision,2,nwids,16,SQLITE_STATIC);
|
||||
sqlite3_step(_sSetNetworkRevision);
|
||||
|
||||
return handleControlPlaneHttpGET(path,urlArgs,headers,body,responseBody,responseContentType);
|
||||
}
|
||||
|
||||
|
@ -113,6 +113,7 @@ private:
|
||||
sqlite3_stmt *_sCreateNetwork;
|
||||
sqlite3_stmt *_sUpdateNetworkField;
|
||||
sqlite3_stmt *_sGetNetworkRevision;
|
||||
sqlite3_stmt *_sSetNetworkRevision;
|
||||
sqlite3_stmt *_sGetIpAssignmentsForNode2;
|
||||
sqlite3_stmt *_sDeleteRelaysForNetwork;
|
||||
sqlite3_stmt *_sCreateRelay;
|
||||
|
42
controller/controller-api-test.sh
Executable file
42
controller/controller-api-test.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$#" -ne "2" ]; then
|
||||
echo 'Usage: controller-api-test.sh <network ID to create> <local TCP port for HTTP API>'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
network_json=$(cat <<EOF
|
||||
{
|
||||
name: "test network",
|
||||
private: true,
|
||||
v4AssignMode: "zt",
|
||||
v6AssignMode: "none",
|
||||
multicastLimit: 100,
|
||||
ipAssignmentPools: [
|
||||
{
|
||||
network: "10.1.2.0",
|
||||
netmaskBits: 24
|
||||
}
|
||||
],
|
||||
rules: [
|
||||
{
|
||||
ruleId: 100,
|
||||
etherType: 0x0800,
|
||||
action: "accept"
|
||||
},
|
||||
{
|
||||
ruleId: 200,
|
||||
etherType: 0x0806,
|
||||
action: "accept"
|
||||
},
|
||||
{
|
||||
ruleId: 300,
|
||||
etherType: 0x86dd,
|
||||
action: "accept"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
echo "$network_json" | curl -d - -v "http://127.0.0.1:$2/controller/network/$1"
|
@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "ControlPlane.hpp"
|
||||
#include "ControlPlaneSubsystem.hpp"
|
||||
#include "OneService.hpp"
|
||||
|
||||
#include "../version.h"
|
||||
@ -241,10 +242,9 @@ static void _jsonAppend(unsigned int depth,std::string &buf,const ZT1_Peer *peer
|
||||
buf.append(json);
|
||||
}
|
||||
|
||||
ControlPlane::ControlPlane(OneService *svc,Node *n,SqliteNetworkController *nc) :
|
||||
ControlPlane::ControlPlane(OneService *svc,Node *n) :
|
||||
_svc(svc),
|
||||
_node(n),
|
||||
_controller(nc)
|
||||
_node(n)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ namespace ZeroTier {
|
||||
|
||||
class OneService;
|
||||
class Node;
|
||||
class ControlPlaneSubsystem;
|
||||
struct InetAddress;
|
||||
|
||||
/**
|
||||
|
@ -214,7 +214,7 @@ public:
|
||||
_controlPlane = new ControlPlane(this,_node);
|
||||
_controlPlane->addAuthToken(authToken.c_str());
|
||||
if (_master)
|
||||
_controlPlane->mount("controller",_master);
|
||||
_controlPlane->mount("controller",reinterpret_cast<ControlPlaneSubsystem *>(_master));
|
||||
|
||||
{ // Remember networks from previous session
|
||||
std::vector<std::string> networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str()));
|
||||
|
Loading…
Reference in New Issue
Block a user