let get_local_addr_ipv4 return error code
This commit is contained in:
7
deps/oblib/src/lib/net/ob_net_util.cpp
vendored
7
deps/oblib/src/lib/net/ob_net_util.cpp
vendored
@ -95,10 +95,9 @@ int ObNetUtil::get_local_addr_ipv6(const char *dev_name, char *ipv6, int len,
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t ObNetUtil::get_local_addr_ipv4(const char *dev_name)
|
||||
int ObNetUtil::get_local_addr_ipv4(const char *dev_name, uint32_t &addr)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
uint32_t ret_addr = 0;
|
||||
struct ifaddrs *ifa = nullptr, *ifa_tmp = nullptr;
|
||||
|
||||
if (nullptr == dev_name) {
|
||||
@ -116,7 +115,7 @@ uint32_t ObNetUtil::get_local_addr_ipv4(const char *dev_name)
|
||||
0 == strcmp(ifa_tmp->ifa_name, dev_name)) {
|
||||
has_found = true;
|
||||
struct sockaddr_in *in = (struct sockaddr_in *) ifa_tmp->ifa_addr;
|
||||
ret_addr = in->sin_addr.s_addr;
|
||||
addr = in->sin_addr.s_addr;
|
||||
} // if end
|
||||
ifa_tmp = ifa_tmp->ifa_next;
|
||||
} // while end
|
||||
@ -132,7 +131,7 @@ uint32_t ObNetUtil::get_local_addr_ipv4(const char *dev_name)
|
||||
freeifaddrs(ifa);
|
||||
}
|
||||
|
||||
return ret_addr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string ObNetUtil::addr_to_string(uint64_t ipport)
|
||||
|
||||
2
deps/oblib/src/lib/net/ob_net_util.h
vendored
2
deps/oblib/src/lib/net/ob_net_util.h
vendored
@ -49,7 +49,7 @@ private:
|
||||
static bool is_wild_match(const common::ObString &client_ip, const common::ObString &host_name);
|
||||
public:
|
||||
static int get_local_addr_ipv6(const char *dev_name, char *ipv6, int len, bool *is_linklocal = nullptr);
|
||||
static uint32_t get_local_addr_ipv4(const char *dev_name);
|
||||
static int get_local_addr_ipv4(const char *dev_name, uint32_t &addr);
|
||||
static std::string addr_to_string(uint64_t ipport);
|
||||
static uint64_t ip_to_addr(uint32_t ip, int port);
|
||||
// get ipv4 by hostname, no need free the returned value
|
||||
|
||||
@ -118,7 +118,7 @@ int ObRpcProtocolProcessor::decode(easy_message_t *ms, ObRpcPacket *&pkt)
|
||||
bool is_demand_data_enough = false;
|
||||
int64_t preceding_data_len = 0;
|
||||
int64_t decode_data_len = 0;
|
||||
common::ObTimeGuard timeguard("ObRpcProtocolProcessor::encode", common::OB_EASY_HANDLER_COST_TIME);
|
||||
common::ObTimeGuard timeguard("ObRpcProtocolProcessor::decode", common::OB_EASY_HANDLER_COST_TIME);
|
||||
if (OB_FAIL(resolve_packet_type(timeguard, ms, is_demand_data_enough, preceding_data_len, decode_data_len))) {
|
||||
LOG_ERROR("failed to resolve packet type", K(ret));
|
||||
} else if (is_demand_data_enough) {
|
||||
|
||||
@ -1859,21 +1859,23 @@ int ObServer::init_config()
|
||||
} else {
|
||||
if (config_.use_ipv6) {
|
||||
char ipv6[MAX_IP_ADDR_LENGTH] = { '\0' };
|
||||
if (0 != obsys::ObNetUtil::get_local_addr_ipv6(config_.devname, ipv6, sizeof(ipv6))) {
|
||||
ret = OB_ERROR;
|
||||
_LOG_ERROR("call get_local_addr_ipv6 failed, devname:%s, errno:%d.", config_.devname.get_value(), errno);
|
||||
if (OB_FAIL(obsys::ObNetUtil::get_local_addr_ipv6(config_.devname, ipv6, sizeof(ipv6)))) {
|
||||
LOG_ERROR("get ipv6 address by devname failed", "devname",
|
||||
config_.devname.get_value(), KR(ret));
|
||||
} else {
|
||||
config_.local_ip.set_value(ipv6);
|
||||
config_.local_ip.set_version(start_time_);
|
||||
_LOG_INFO("set local_ip via devname, local_ip:%s, devname:%s.", ipv6, config_.devname.get_value());
|
||||
}
|
||||
} else {
|
||||
uint32_t ipv4_binary = obsys::ObNetUtil::get_local_addr_ipv4(config_.devname);
|
||||
uint32_t ipv4_net = 0;
|
||||
char ipv4[INET_ADDRSTRLEN] = { '\0' };
|
||||
if (nullptr == inet_ntop(AF_INET, (void *)&ipv4_binary, ipv4, sizeof(ipv4))) {
|
||||
ret = OB_ERROR;
|
||||
_LOG_ERROR("call inet_ntop failed, devname:%s, ipv4_binary:0x%08x, errno:%d.",
|
||||
config_.devname.get_value(), ipv4_binary, errno);
|
||||
if (OB_FAIL(obsys::ObNetUtil::get_local_addr_ipv4(config_.devname, ipv4_net))) {
|
||||
LOG_ERROR("get ipv4 address by devname failed", "devname",
|
||||
config_.devname.get_value(), KR(ret));
|
||||
} else if (nullptr == inet_ntop(AF_INET, (void *)&ipv4_net, ipv4, sizeof(ipv4))) {
|
||||
ret = OB_ERR_SYS;
|
||||
LOG_ERROR("call inet_ntop failed", K(ipv4_net), K(errno), KERRMSG, KR(ret));
|
||||
} else {
|
||||
config_.local_ip.set_value(ipv4);
|
||||
config_.local_ip.set_version(start_time_);
|
||||
@ -1900,8 +1902,14 @@ int ObServer::init_config()
|
||||
obsys::ObNetUtil::get_local_addr_ipv6(config_.devname, ipv6, sizeof(ipv6));
|
||||
self_addr_.set_ip_addr(ipv6, local_port);
|
||||
} else {
|
||||
int32_t ipv4 = ntohl(obsys::ObNetUtil::get_local_addr_ipv4(config_.devname));
|
||||
self_addr_.set_ipv4_addr(ipv4, local_port);
|
||||
uint32_t ipv4_net = 0;
|
||||
if (OB_FAIL(obsys::ObNetUtil::get_local_addr_ipv4(config_.devname, ipv4_net))) {
|
||||
LOG_ERROR("get ipv4 address by devname failed", "devname",
|
||||
config_.devname.get_value(), KR(ret));
|
||||
} else {
|
||||
int32_t ipv4 = ntohl(ipv4_net);
|
||||
self_addr_.set_ipv4_addr(ipv4, local_port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -183,10 +183,16 @@ int ObAdminExecutor::load_config()
|
||||
tmp_addr.set_ip_addr(ipv6, local_port);
|
||||
GCTX.self_addr_seq_.set_addr(tmp_addr);
|
||||
} else {
|
||||
int32_t ipv4 = ntohl(obsys::ObNetUtil::get_local_addr_ipv4(config.devname));
|
||||
ObAddr tmp_addr = GCTX.self_addr();
|
||||
tmp_addr.set_ipv4_addr(ipv4, local_port);
|
||||
GCTX.self_addr_seq_.set_addr(tmp_addr);
|
||||
uint32_t ipv4_net = 0;
|
||||
if (OB_FAIL(obsys::ObNetUtil::get_local_addr_ipv4(config.devname, ipv4_net))) {
|
||||
LOG_ERROR("get ipv4 address by devname failed", "devname",
|
||||
config.devname.get_value(), KR(ret));
|
||||
} else {
|
||||
int32_t ipv4 = ntohl(ipv4_net);
|
||||
ObAddr tmp_addr = GCTX.self_addr();
|
||||
tmp_addr.set_ipv4_addr(ipv4, local_port);
|
||||
GCTX.self_addr_seq_.set_addr(tmp_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -85,13 +85,18 @@ int MockObServer::init(const char *schema_file,
|
||||
}
|
||||
}
|
||||
|
||||
int32_t local_ip = ntohl(obsys::ObNetUtil::get_local_addr_ipv4(config_.devname));
|
||||
int32_t local_port = static_cast<int32_t>(config_.rpc_port);
|
||||
|
||||
config_.print();
|
||||
|
||||
// initialize self address
|
||||
self_addr_.set_ipv4_addr(local_ip, local_port);
|
||||
uint32_t ipv4_net = 0;
|
||||
if (OB_FAIL(obsys::ObNetUtil::get_local_addr_ipv4(config_.devname, ipv4_net))) {
|
||||
LOG_ERROR("get ipv4 address by devname failed", "devname",
|
||||
config_.devname.get_value(), KR(ret));
|
||||
} else {
|
||||
int32_t local_ip = ntohl(ipv4_net);
|
||||
int32_t local_port = static_cast<int32_t>(config_.rpc_port);
|
||||
// initialize self address
|
||||
self_addr_.set_ipv4_addr(local_ip, local_port);
|
||||
}
|
||||
}
|
||||
// init env
|
||||
if (OB_SUCC(ret)) {
|
||||
|
||||
Reference in New Issue
Block a user