update test case
This commit is contained in:
parent
c0a8f81176
commit
6cfab63ee0
|
@ -80,7 +80,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SHashObj* pList;
|
SHashObj* pList;
|
||||||
int64_t ver;
|
int64_t ver;
|
||||||
} SWhiteList;
|
} SIpWhiteListTab;
|
||||||
typedef struct SWorkThrd {
|
typedef struct SWorkThrd {
|
||||||
TdThread thread;
|
TdThread thread;
|
||||||
uv_connect_t connect_req;
|
uv_connect_t connect_req;
|
||||||
|
@ -95,7 +95,7 @@ typedef struct SWorkThrd {
|
||||||
void* pTransInst;
|
void* pTransInst;
|
||||||
bool quit;
|
bool quit;
|
||||||
|
|
||||||
SWhiteList* pWhiteList;
|
SIpWhiteListTab* pWhiteList;
|
||||||
int64_t whiteListVer;
|
int64_t whiteListVer;
|
||||||
int8_t enableIpWhiteList;
|
int8_t enableIpWhiteList;
|
||||||
} SWorkThrd;
|
} SWorkThrd;
|
||||||
|
@ -120,13 +120,13 @@ typedef struct SServerObj {
|
||||||
bool inited;
|
bool inited;
|
||||||
} SServerObj;
|
} SServerObj;
|
||||||
|
|
||||||
SWhiteList* uvWhiteListCreate();
|
SIpWhiteListTab* uvWhiteListCreate();
|
||||||
void uvWhiteListDestroy(SWhiteList* pWhite);
|
void uvWhiteListDestroy(SIpWhiteListTab* pWhite);
|
||||||
void uvWhiteListAdd(SWhiteList* pWhite, char* user, SIpWhiteList* pList, int64_t ver);
|
void uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* pList, int64_t ver);
|
||||||
void uvWhiteListUpdate(SWhiteList* pWhite, SHashObj* pTable);
|
void uvWhiteListUpdate(SIpWhiteListTab* pWhite, SHashObj* pTable);
|
||||||
bool uvWhiteListCheckConn(SWhiteList* pWhite, SSvrConn* pConn);
|
bool uvWhiteListCheckConn(SIpWhiteListTab* pWhite, SSvrConn* pConn);
|
||||||
bool uvWhiteListFilte(SWhiteList* pWhite, char* user, uint32_t ip, int64_t ver);
|
bool uvWhiteListFilte(SIpWhiteListTab* pWhite, char* user, uint32_t ip, int64_t ver);
|
||||||
void uvWhiteListSetConnVer(SWhiteList* pWhite, SSvrConn* pConn);
|
void uvWhiteListSetConnVer(SIpWhiteListTab* pWhite, SSvrConn* pConn);
|
||||||
|
|
||||||
static void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
static void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
||||||
static void uvAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
static void uvAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
||||||
|
@ -219,14 +219,14 @@ static bool uvCheckIp(SIpV4Range* pRange, int32_t ip) {
|
||||||
}
|
}
|
||||||
return subnetCheckIp(&subnet, ip);
|
return subnetCheckIp(&subnet, ip);
|
||||||
}
|
}
|
||||||
SWhiteList* uvWhiteListCreate() {
|
SIpWhiteListTab* uvWhiteListCreate() {
|
||||||
SWhiteList* pWhiteList = taosMemoryCalloc(1, sizeof(SWhiteList));
|
SIpWhiteListTab* pWhiteList = taosMemoryCalloc(1, sizeof(SIpWhiteListTab));
|
||||||
|
|
||||||
pWhiteList->pList = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), 0, HASH_NO_LOCK);
|
pWhiteList->pList = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), 0, HASH_NO_LOCK);
|
||||||
pWhiteList->ver = -1;
|
pWhiteList->ver = -1;
|
||||||
return pWhiteList;
|
return pWhiteList;
|
||||||
}
|
}
|
||||||
void uvWhiteListDestroy(SWhiteList* pWhite) {
|
void uvWhiteListDestroy(SIpWhiteListTab* pWhite) {
|
||||||
SHashObj* pWhiteList = pWhite->pList;
|
SHashObj* pWhiteList = pWhite->pList;
|
||||||
void* pIter = taosHashIterate(pWhiteList, NULL);
|
void* pIter = taosHashIterate(pWhiteList, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
|
@ -250,7 +250,7 @@ void uvWhiteListToStr(SWhiteUserList* plist, char* user, char** ppBuf) {
|
||||||
|
|
||||||
*ppBuf = pBuf;
|
*ppBuf = pBuf;
|
||||||
}
|
}
|
||||||
void uvWhiteListDebug(SWhiteList* pWrite) {
|
void uvWhiteListDebug(SIpWhiteListTab* pWrite) {
|
||||||
SHashObj* pWhiteList = pWrite->pList;
|
SHashObj* pWhiteList = pWrite->pList;
|
||||||
void* pIter = taosHashIterate(pWhiteList, NULL);
|
void* pIter = taosHashIterate(pWhiteList, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
|
@ -268,7 +268,7 @@ void uvWhiteListDebug(SWhiteList* pWrite) {
|
||||||
pIter = taosHashIterate(pWhiteList, pIter);
|
pIter = taosHashIterate(pWhiteList, pIter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void uvWhiteListAdd(SWhiteList* pWhite, char* user, SIpWhiteList* plist, int64_t ver) {
|
void uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* plist, int64_t ver) {
|
||||||
SHashObj* pWhiteList = pWhite->pList;
|
SHashObj* pWhiteList = pWhite->pList;
|
||||||
|
|
||||||
SWhiteUserList** ppUserList = taosHashGet(pWhiteList, user, strlen(user));
|
SWhiteUserList** ppUserList = taosHashGet(pWhiteList, user, strlen(user));
|
||||||
|
@ -289,7 +289,7 @@ void uvWhiteListAdd(SWhiteList* pWhite, char* user, SIpWhiteList* plist, int64_t
|
||||||
uvWhiteListDebug(pWhite);
|
uvWhiteListDebug(pWhite);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uvWhiteListUpdate(SWhiteList* pWhite, SHashObj* pTable) {
|
void uvWhiteListUpdate(SIpWhiteListTab* pWhite, SHashObj* pTable) {
|
||||||
pWhite->ver++;
|
pWhite->ver++;
|
||||||
// impl later
|
// impl later
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ static bool uvWhiteListIsDefaultAddr(uint32_t ip) {
|
||||||
static SIpV4Range range = {.ip = 16777343, .mask = 32};
|
static SIpV4Range range = {.ip = 16777343, .mask = 32};
|
||||||
return range.ip == ip;
|
return range.ip == ip;
|
||||||
}
|
}
|
||||||
bool uvWhiteListFilte(SWhiteList* pWhite, char* user, uint32_t ip, int64_t ver) {
|
bool uvWhiteListFilte(SIpWhiteListTab* pWhite, char* user, uint32_t ip, int64_t ver) {
|
||||||
// impl check
|
// impl check
|
||||||
SHashObj* pWhiteList = pWhite->pList;
|
SHashObj* pWhiteList = pWhite->pList;
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
|
@ -310,10 +310,10 @@ bool uvWhiteListFilte(SWhiteList* pWhite, char* user, uint32_t ip, int64_t ver)
|
||||||
if (ppList == NULL || *ppList == NULL) {
|
if (ppList == NULL || *ppList == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SWhiteUserList* pList = *ppList;
|
SWhiteUserList* pUserList = *ppList;
|
||||||
if (pList->ver == ver) return true;
|
if (pUserList->ver == ver) return true;
|
||||||
|
|
||||||
SIpWhiteList* pIpWhiteList = pList->pList;
|
SIpWhiteList* pIpWhiteList = pUserList->pList;
|
||||||
for (int i = 0; i < pIpWhiteList->num; i++) {
|
for (int i = 0; i < pIpWhiteList->num; i++) {
|
||||||
SIpV4Range* range = &pIpWhiteList->pIpRange[i];
|
SIpV4Range* range = &pIpWhiteList->pIpRange[i];
|
||||||
if (uvCheckIp(range, ip)) {
|
if (uvCheckIp(range, ip)) {
|
||||||
|
@ -323,7 +323,7 @@ bool uvWhiteListFilte(SWhiteList* pWhite, char* user, uint32_t ip, int64_t ver)
|
||||||
}
|
}
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
bool uvWhiteListCheckConn(SWhiteList* pWhite, SSvrConn* pConn) {
|
bool uvWhiteListCheckConn(SIpWhiteListTab* pWhite, SSvrConn* pConn) {
|
||||||
if (pConn->inType == TDMT_MND_STATUS || pConn->inType == TDMT_MND_RETRIEVE_IP_WHITE ||
|
if (pConn->inType == TDMT_MND_STATUS || pConn->inType == TDMT_MND_RETRIEVE_IP_WHITE ||
|
||||||
pConn->serverIp == pConn->clientIp ||
|
pConn->serverIp == pConn->clientIp ||
|
||||||
pWhite->ver == pConn->whiteListVer /*|| strncmp(pConn->user, "_dnd", strlen("_dnd")) == 0*/)
|
pWhite->ver == pConn->whiteListVer /*|| strncmp(pConn->user, "_dnd", strlen("_dnd")) == 0*/)
|
||||||
|
@ -331,7 +331,7 @@ bool uvWhiteListCheckConn(SWhiteList* pWhite, SSvrConn* pConn) {
|
||||||
|
|
||||||
return uvWhiteListFilte(pWhite, pConn->user, pConn->clientIp, pConn->whiteListVer);
|
return uvWhiteListFilte(pWhite, pConn->user, pConn->clientIp, pConn->whiteListVer);
|
||||||
}
|
}
|
||||||
void uvWhiteListSetConnVer(SWhiteList* pWhite, SSvrConn* pConn) {
|
void uvWhiteListSetConnVer(SIpWhiteListTab* pWhite, SSvrConn* pConn) {
|
||||||
// if conn already check by current whiteLis
|
// if conn already check by current whiteLis
|
||||||
pConn->whiteListVer = pWhite->ver;
|
pConn->whiteListVer = pWhite->ver;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue