From 30a60be2143dc93da034799859fcc2112f69a902 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 11 Sep 2023 09:26:00 +0800 Subject: [PATCH] add rpc update interface --- source/dnode/mnode/impl/src/mndUser.c | 2 +- source/libs/transport/inc/transComm.h | 12 +++--- source/libs/transport/src/transComm.c | 55 +++++++++++++++++++++++---- source/os/src/osSocket.c | 26 ------------- 4 files changed, 55 insertions(+), 40 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 9fa17c328b..01aae39fae 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -192,7 +192,7 @@ int64_t mndGetIpWhiteVer(SMnode *pMnode) { ver = ipWhiteMgt.ver; taosThreadRwlockUnlock(&ipWhiteMgt.rw); - mDebug("ip-white-mnode ver, %" PRId64 "", ver); + mInfo("ip-white-mnode ver, %" PRId64 "", ver); return ver; } diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index b72745b018..dc8b7a3245 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -439,12 +439,12 @@ int32_t transGetInstMgt(); void transHttpEnvDestroy(); typedef struct { - int32_t netmask; - int32_t address; - int32_t network; - int32_t broadcast; - char info[32]; - int8_t type; + uint32_t netmask; + uint32_t address; + uint32_t network; + uint32_t broadcast; + char info[32]; + int8_t type; } SubnetUtils; int32_t subnetInit(SubnetUtils* pUtils, SIpV4Range* pRange); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index f9da22c865..b09a5cab20 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -655,14 +655,47 @@ void transDestoryExHandle(void* handle) { taosMemoryFree(handle); } -int32_t subnetInit(SubnetUtils* pUtils, SIpV4Range* pRange) { - pUtils->address = pRange->ip; +void subnetIp2int(const char* const ip_addr, uint8_t* dst) { + char ip_addr_cpy[20]; + char ip[5]; - int32_t mask = 0; - for (int i = 0; i < pRange->mask; i++) { - mask |= (1 << (31 - i)); + tstrncpy(ip_addr_cpy, ip_addr, sizeof(ip_addr_cpy)); + + char *s_start, *s_end; + s_start = ip_addr_cpy; + s_end = ip_addr_cpy; + + int32_t k = 0; + + for (k = 0; *s_start != '\0'; s_start = s_end) { + for (s_end = s_start; *s_end != '.' && *s_end != '\0'; s_end++) { + } + if (*s_end == '.') { + *s_end = '\0'; + s_end++; + } + dst[k++] = (char)atoi(s_start); + } +} + +int32_t subnetInit(SubnetUtils* pUtils, SIpV4Range* pRange) { + if (pRange->mask == 0) { + pUtils->address = pRange->ip; + pUtils->type = 0; + return 0; + } + + SIpV4Range tRange = {.ip = pRange->ip, .mask = 0}; + char tbuf[32] = {0}; + transUtilSIpRangeToStr(&tRange, tbuf); + uint8_t el[4] = {0}; + subnetIp2int(tbuf, el); + + pUtils->address = (el[0] << 24) | (el[1] << 16) | (el[2] << 8) | (el[0]); + + for (int i = 0; i < pRange->mask; i++) { + pUtils->netmask |= (1 << (31 - i)); } - pUtils->netmask = mask; pUtils->network = pUtils->address & pUtils->netmask; pUtils->broadcast = (pUtils->network) | (pUtils->netmask ^ 0xFFFFFFFF); @@ -681,7 +714,15 @@ int32_t subnetCheckIp(SubnetUtils* pUtils, uint32_t ip) { if (pUtils->type == 0) { return pUtils->address == ip; } else { - return pUtils->network >= ip && pUtils->broadcast <= ip; + SIpV4Range tRange = {.ip = ip, .mask = 0}; + char tbuf[32] = {0}; + transUtilSIpRangeToStr(&tRange, tbuf); + uint8_t el[4] = {0}; + subnetIp2int(tbuf, el); + + ip = (el[0] << 24) | (el[1] << 16) | (el[2] << 8) | (el[0]); + + return ip >= pUtils->network && ip <= pUtils->broadcast; } } diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 0ec6ded93a..faf1ecbfc7 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -898,32 +898,6 @@ int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len #endif // endif 0 -uint32_t ip2uint(const char *const ip_addr) { - char ip_addr_cpy[20]; - char ip[5]; - - tstrncpy(ip_addr_cpy, ip_addr, sizeof(ip_addr_cpy)); - - char *s_start, *s_end; - s_start = ip_addr_cpy; - s_end = ip_addr_cpy; - - int32_t k; - - for (k = 0; *s_start != '\0'; s_start = s_end) { - for (s_end = s_start; *s_end != '.' && *s_end != '\0'; s_end++) { - } - if (*s_end == '.') { - *s_end = '\0'; - s_end++; - } - ip[k++] = (char)atoi(s_start); - } - - ip[k] = '\0'; - - return *((uint32_t *)ip); -} void taosBlockSIGPIPE() { #ifdef WINDOWS // ASSERT(0);