pkt-nio and ObNetKeepAlive prevent tcp self connect
This commit is contained in:

committed by
ob-robot

parent
8684c5cd8b
commit
e63e1eb45e
19
deps/oblib/src/rpc/obrpc/ob_net_keepalive.cpp
vendored
19
deps/oblib/src/rpc/obrpc/ob_net_keepalive.cpp
vendored
@ -415,6 +415,25 @@ client* create_client(rpc_server *rs)
|
|||||||
c->status_ = CONNECT_OK;
|
c->status_ = CONNECT_OK;
|
||||||
_LOG_DEBUG("connect ok, addr: %s", addr_to_string(rs->svr_addr_));
|
_LOG_DEBUG("connect ok, addr: %s", addr_to_string(rs->svr_addr_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OB_SUCC(ret)) {
|
||||||
|
if (AF_INET == addr.ss_family) {
|
||||||
|
struct sockaddr_in self_addr;
|
||||||
|
socklen_t len = sizeof(self_addr);
|
||||||
|
if (0 == getsockname(c->fd_, (struct sockaddr *)&self_addr, &len)) {
|
||||||
|
struct sockaddr_in *dst_addr = (struct sockaddr_in *)(&addr);
|
||||||
|
if (self_addr.sin_port == dst_addr->sin_port && self_addr.sin_addr.s_addr == dst_addr->sin_addr.s_addr) {
|
||||||
|
char str[INET_ADDRSTRLEN];
|
||||||
|
ret = OB_IO_ERROR;
|
||||||
|
_LOG_WARN("connection to %s failed, self connect self", inet_ntop(AF_INET, (const void*)(&addr), str, sizeof(str)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret = OB_IO_ERROR;
|
||||||
|
_LOG_WARN("getsockname failed: fd:%d, errno:%d", c->fd_, errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (OB_FAIL(ret)) {
|
if (OB_FAIL(ret)) {
|
||||||
if (c->fd_ >= 0) close(c->fd_);
|
if (c->fd_ >= 0) close(c->fd_);
|
||||||
c = NULL;
|
c = NULL;
|
||||||
|
18
deps/ussl-hook/ussl-hook.c
vendored
18
deps/ussl-hook/ussl-hook.c
vendored
@ -59,9 +59,25 @@ int ussl_connect(int sockfd, const struct sockaddr *address, socklen_t address_l
|
|||||||
ussl_clear_client_opt(sockfd);
|
ussl_clear_client_opt(sockfd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (AF_INET == address->sa_family) {
|
||||||
|
struct sockaddr_in self_addr;
|
||||||
|
socklen_t len = sizeof(self_addr);
|
||||||
|
if (0 == getsockname(sockfd, (struct sockaddr *)&self_addr, &len)) {
|
||||||
|
struct sockaddr_in *dst_addr = (struct sockaddr_in *)address;
|
||||||
|
if (self_addr.sin_port == dst_addr->sin_port && self_addr.sin_addr.s_addr == dst_addr->sin_addr.s_addr) {
|
||||||
|
ret = -1;
|
||||||
|
errno = EIO;
|
||||||
|
char str[INET_ADDRSTRLEN];
|
||||||
|
ussl_log_warn("connection to %s failed, self connect self", inet_ntop(AF_INET, (const void*)(address), str, sizeof(str)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret = -1;
|
||||||
|
ussl_log_warn("getsockname failed, fd:%d, error:%s", sockfd, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
/* if gid has been set and connect return success, we also let the ret to be -1 and errno to be
|
/* if gid has been set and connect return success, we also let the ret to be -1 and errno to be
|
||||||
* EINPROGRESS */
|
* EINPROGRESS */
|
||||||
if (sockfd >= 0 && sockfd < USSL_MAX_FD_NUM && global_gid_arr[sockfd] != UINT64_MAX) {
|
if (ret == 0 && sockfd >= 0 && sockfd < USSL_MAX_FD_NUM && global_gid_arr[sockfd] != UINT64_MAX) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
errno = EINPROGRESS;
|
errno = EINPROGRESS;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user