mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-13 22:12:56 +00:00
Rename ruleId to ruleNo and optimize some indexes in Sqlite3 schema.
This commit is contained in:
parent
1b122cddbd
commit
8a9715f183
@ -167,8 +167,8 @@ SqliteNetworkController::SqliteNetworkController(const char *dbPath) :
|
||||
||(sqlite3_prepare_v2(_db,"SELECT n.id FROM Member AS m,Node AS n WHERE m.networkId = ? AND n.id = m.nodeId ORDER BY n.id ASC",-1,&_sListNetworkMembers,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT m.authorized,m.activeBridge,n.identity,n.lastAt,n.lastSeen,n.firstSeen FROM Member AS m,Node AS n WHERE m.networkId = ? AND m.nodeId = ?",-1,&_sGetMember2,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT ipNetwork,ipNetmaskBits,ipVersion FROM IpAssignmentPool WHERE networkId = ? ORDER BY ipNetwork ASC",-1,&_sGetIpAssignmentPools2,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT ruleId,nodeId,vlanId,vlanPcp,etherType,macSource,macDest,ipSource,ipDest,ipTos,ipProtocol,ipSourcePort,ipDestPort,\"flags\",invFlags,\"action\" FROM Rule WHERE networkId = ? ORDER BY ruleId ASC",-1,&_sListRules,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"INSERT INTO Rule (networkId,ruleId,nodeId,vlanId,vlanPcP,etherType,macSource,macDest,ipSource,ipDest,ipTos,ipProtocol,ipSourcePort,ipDestPort,\"action\") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",-1,&_sCreateRule,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT ruleNo,nodeId,vlanId,vlanPcp,etherType,macSource,macDest,ipSource,ipDest,ipTos,ipProtocol,ipSourcePort,ipDestPort,\"flags\",invFlags,\"action\" FROM Rule WHERE networkId = ? ORDER BY ruleNo ASC",-1,&_sListRules,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"INSERT INTO Rule (networkId,ruleNo,nodeId,vlanId,vlanPcP,etherType,macSource,macDest,ipSource,ipDest,ipTos,ipProtocol,ipSourcePort,ipDestPort,\"action\") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",-1,&_sCreateRule,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"INSERT INTO Network (id,name,creationTime,revision) VALUES (?,?,?,1)",-1,&_sCreateNetwork,(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)
|
||||
@ -855,7 +855,7 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
||||
json_value *rj = j->u.object.values[k].value->u.array.values[kk];
|
||||
if ((rj)&&(rj->type == json_object)) {
|
||||
struct { // NULL pointers indicate missing or NULL -- wildcards
|
||||
const json_int_t *ruleId;
|
||||
const json_int_t *ruleNo;
|
||||
const char *nodeId;
|
||||
const json_int_t *vlanId;
|
||||
const json_int_t *vlanPcp;
|
||||
@ -875,8 +875,8 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
||||
memset(&rule,0,sizeof(rule));
|
||||
|
||||
for(unsigned int rk=0;rk<rj->u.object.length;++rk) {
|
||||
if ((!strcmp(rj->u.object.values[rk].name,"ruleId"))&&(rj->u.object.values[rk].value->type == json_integer))
|
||||
rule.ruleId = &(rj->u.object.values[rk].value->u.integer);
|
||||
if ((!strcmp(rj->u.object.values[rk].name,"ruleNo"))&&(rj->u.object.values[rk].value->type == json_integer))
|
||||
rule.ruleNo = &(rj->u.object.values[rk].value->u.integer);
|
||||
else if ((!strcmp(rj->u.object.values[rk].name,"nodeId"))&&(rj->u.object.values[rk].value->type == json_string))
|
||||
rule.nodeId = rj->u.object.values[rk].value->u.string.ptr;
|
||||
else if ((!strcmp(rj->u.object.values[rk].name,"vlanId"))&&(rj->u.object.values[rk].value->type == json_integer))
|
||||
@ -909,11 +909,11 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
||||
rule.action = rj->u.object.values[rk].value->u.string.ptr;
|
||||
}
|
||||
|
||||
if ((rule.ruleId)&&(rule.action)&&(rule.action[0])) {
|
||||
if ((rule.ruleNo)&&(rule.action)&&(rule.action[0])) {
|
||||
char mactmp1[16],mactmp2[16];
|
||||
sqlite3_reset(_sCreateRule);
|
||||
sqlite3_bind_text(_sCreateRule,1,nwids,16,SQLITE_STATIC);
|
||||
sqlite3_bind_int64(_sCreateRule,2,*rule.ruleId);
|
||||
sqlite3_bind_int64(_sCreateRule,2,*rule.ruleNo);
|
||||
|
||||
// Optional values: null by default
|
||||
for(int i=3;i<=16;++i)
|
||||
@ -1233,7 +1233,7 @@ unsigned int SqliteNetworkController::_doCPGet(
|
||||
bool firstRule = true;
|
||||
while (sqlite3_step(_sListRules) == SQLITE_ROW) {
|
||||
responseBody.append(firstRule ? "\n\t{\n" : ",{\n");
|
||||
Utils::snprintf(json,sizeof(json),"\t\t\"ruleId\": %lld,\n",sqlite3_column_int64(_sListRules,0));
|
||||
Utils::snprintf(json,sizeof(json),"\t\t\"ruleNo\": %lld,\n",sqlite3_column_int64(_sListRules,0));
|
||||
responseBody.append(json);
|
||||
if (sqlite3_column_type(_sListRules,1) != SQLITE_NULL) {
|
||||
Utils::snprintf(json,sizeof(json),"\t\t\"nodeId\": \"%s\",\n",(const char *)sqlite3_column_text(_sListRules,1));
|
||||
|
@ -32,12 +32,10 @@ CREATE TABLE IpAssignment (
|
||||
ipVersion integer NOT NULL DEFAULT(4)
|
||||
);
|
||||
|
||||
CREATE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);
|
||||
CREATE UNIQUE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);
|
||||
|
||||
CREATE INDEX IpAssignment_networkId_nodeId ON IpAssignment (networkId, nodeId);
|
||||
|
||||
CREATE INDEX IpAssignment_networkId ON IpAssignment (networkId);
|
||||
|
||||
CREATE TABLE IpAssignmentPool (
|
||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
||||
ipNetwork blob(16) NOT NULL,
|
||||
@ -55,8 +53,6 @@ CREATE TABLE Member (
|
||||
PRIMARY KEY (networkId, nodeId)
|
||||
);
|
||||
|
||||
CREATE INDEX Member_networkId ON Member (networkId);
|
||||
|
||||
CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);
|
||||
|
||||
CREATE TABLE MulticastRate (
|
||||
@ -81,7 +77,7 @@ CREATE INDEX Relay_networkId ON Relay (networkId);
|
||||
|
||||
CREATE TABLE Rule (
|
||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
||||
ruleId integer NOT NULL,
|
||||
ruleNo integer NOT NULL,
|
||||
nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,
|
||||
vlanId integer,
|
||||
vlanPcp integer,
|
||||
@ -99,4 +95,4 @@ CREATE TABLE Rule (
|
||||
"action" varchar(4096) NOT NULL DEFAULT('accept')
|
||||
);
|
||||
|
||||
CREATE INDEX Rule_networkId ON Rule (networkId);
|
||||
CREATE UNIQUE INDEX Rule_networkId_ruleNo ON Rule (networkId, ruleNo);
|
||||
|
@ -33,12 +33,10 @@
|
||||
" ipVersion integer NOT NULL DEFAULT(4)\n"\
|
||||
");\n"\
|
||||
"\n"\
|
||||
"CREATE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);\n"\
|
||||
"CREATE UNIQUE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);\n"\
|
||||
"\n"\
|
||||
"CREATE INDEX IpAssignment_networkId_nodeId ON IpAssignment (networkId, nodeId);\n"\
|
||||
"\n"\
|
||||
"CREATE INDEX IpAssignment_networkId ON IpAssignment (networkId);\n"\
|
||||
"\n"\
|
||||
"CREATE TABLE IpAssignmentPool (\n"\
|
||||
" networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
|
||||
" ipNetwork blob(16) NOT NULL,\n"\
|
||||
@ -56,8 +54,6 @@
|
||||
" PRIMARY KEY (networkId, nodeId)\n"\
|
||||
");\n"\
|
||||
"\n"\
|
||||
"CREATE INDEX Member_networkId ON Member (networkId);\n"\
|
||||
"\n"\
|
||||
"CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);\n"\
|
||||
"\n"\
|
||||
"CREATE TABLE MulticastRate (\n"\
|
||||
@ -82,7 +78,7 @@
|
||||
"\n"\
|
||||
"CREATE TABLE Rule (\n"\
|
||||
" networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\
|
||||
" ruleId integer NOT NULL,\n"\
|
||||
" ruleNo integer NOT NULL,\n"\
|
||||
" nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\
|
||||
" vlanId integer,\n"\
|
||||
" vlanPcp integer,\n"\
|
||||
@ -100,5 +96,5 @@
|
||||
" \"action\" varchar(4096) NOT NULL DEFAULT('accept')\n"\
|
||||
");\n"\
|
||||
"\n"\
|
||||
"CREATE INDEX Rule_networkId ON Rule (networkId);\n"\
|
||||
"CREATE UNIQUE INDEX Rule_networkId_ruleNo ON Rule (networkId, ruleNo);\n"\
|
||||
""
|
||||
|
@ -204,7 +204,7 @@ Relay objects define network-specific preferred relay nodes. Traffic to peers on
|
||||
|
||||
* **Note**: at the moment, <u>only rules specifying allowed Ethernet types are used</u>. The database supports a richer rule set, but this is not implemented yet in the client. <u>Other types of rules will have no effect</u> (yet).
|
||||
|
||||
Rules are matched in order of ruleId. If no rules match, the default action is 'drop'. To allow all traffic, create a single rule with all *null* fields and an action of 'accept'.
|
||||
Rules are matched in order of ruleNo. If no rules match, the default action is 'drop'. To allow all traffic, create a single rule with all *null* fields and an action of 'accept'.
|
||||
|
||||
Rule object fields can be *null*, in which case they are omitted from the object. A null field indicates "no match on this criteria."
|
||||
|
||||
@ -212,7 +212,7 @@ IP related fields apply only to Ethernet frames of type IPv4 or IPV6. Otherwise
|
||||
|
||||
<table>
|
||||
<tr><td><b>Field</b></td><td><b>Type</b></td><td><b>Description</b></td></tr>
|
||||
<tr><td>ruleId</td><td>integer</td><td>User-defined rule ID and sort order</td></tr>
|
||||
<tr><td>ruleNo</td><td>integer</td><td>User-defined rule ID and sort order</td></tr>
|
||||
<tr><td>nodeId</td><td>string</td><td>10-digit hex ZeroTier address of node (a.k.a. "port on switch")</td></tr>
|
||||
<tr><td>vlanId</td><td>integer</td><td>Ethernet VLAN ID</td></tr>
|
||||
<tr><td>vlanPcp</td><td>integer</td><td>Ethernet VLAN priority code point (PCP) ID</td></tr>
|
||||
|
Loading…
x
Reference in New Issue
Block a user