-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature](network interface) Support network interface #16617
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e7b03f7
interface 3.1
ZashJie 4a91dc4
Network Interface
ZashJie 2d7b77a
Network InterfaceI
ZashJie 037688d
network_interface_configmd
ZashJie 76e53df
network_interface_be_style
ZashJie 1a9d1e1
network_interfaces_docs
ZashJie 696f09a
network_interface_modify
ZashJie 952b25a
network_interface_rebase
ZashJie 5e5092a
network_interface_rebaseipv6
ZashJie e7c3357
network_interface_3_6_13
ZashJie 9033644
network_interface_beformat
ZashJie ffa6398
network_interface_beformat_1
ZashJie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
|
||
#include "service/backend_options.h" | ||
|
||
#include <arpa/inet.h> | ||
#include <ifaddrs.h> | ||
|
||
#include <algorithm> | ||
|
||
#include "common/config.h" | ||
|
@@ -31,14 +34,19 @@ namespace doris { | |
static const std::string PRIORITY_CIDR_SEPARATOR = ";"; | ||
|
||
std::string BackendOptions::_s_localhost; | ||
std::vector<std::string> BackendOptions::_s_network_interfaces; | ||
std::vector<CIDR> BackendOptions::_s_priority_cidrs; | ||
bool BackendOptions::_bind_ipv6 = false; | ||
const char* _service_bind_address = "0.0.0.0"; | ||
|
||
bool BackendOptions::init() { | ||
if (!analyze_priority_cidrs()) { | ||
bool interfaceResult = get_network_interfaces(); | ||
bool cidrResult = analyze_priority_cidrs(); | ||
|
||
if (!interfaceResult && !cidrResult) { | ||
return false; | ||
} | ||
|
||
std::vector<InetAddress> hosts; | ||
Status status = get_hosts(&hosts); | ||
|
||
|
@@ -56,7 +64,11 @@ bool BackendOptions::init() { | |
std::vector<InetAddress>::iterator addr_it = hosts.begin(); | ||
for (; addr_it != hosts.end(); ++addr_it) { | ||
VLOG_CRITICAL << "check ip=" << addr_it->get_host_address(); | ||
if (!_s_priority_cidrs.empty()) { | ||
if (!_s_network_interfaces.empty()) { | ||
if (is_in_network_interface(addr_it->get_host_address())) { | ||
_s_localhost = addr_it->get_host_address(); | ||
} | ||
} else if (!_s_priority_cidrs.empty()) { | ||
// Whether to use IPV4 or IPV6, it's configured by CIDR format. | ||
// If both IPV4 and IPV6 are configured, the config order decides priority. | ||
if (is_in_prior_network(addr_it->get_host_address())) { | ||
|
@@ -118,6 +130,43 @@ bool BackendOptions::analyze_priority_cidrs() { | |
return true; | ||
} | ||
|
||
bool BackendOptions::get_network_interfaces() { | ||
if (config::network_interfaces == "") { | ||
return true; | ||
} | ||
LOG(INFO) << "network interfaces in conf: " << config::network_interfaces; | ||
|
||
struct ifaddrs* if_addr_struct = nullptr; | ||
void* tmp_addr_ptr = nullptr; | ||
getifaddrs(&if_addr_struct); | ||
|
||
std::vector<std::string> nic_names = | ||
strings::Split(config::network_interfaces, PRIORITY_CIDR_SEPARATOR); | ||
bool flag = false; | ||
|
||
for (auto& nic_name : nic_names) { | ||
for (; if_addr_struct != nullptr; if_addr_struct = if_addr_struct->ifa_next) { | ||
if (nic_name == if_addr_struct->ifa_name) { | ||
tmp_addr_ptr = &((struct sockaddr_in*)if_addr_struct->ifa_addr)->sin_addr; | ||
char address_buffer[INET_ADDRSTRLEN]; | ||
inet_ntop(AF_INET, tmp_addr_ptr, address_buffer, INET_ADDRSTRLEN); | ||
_s_network_interfaces.push_back(address_buffer); | ||
flag = true; | ||
} | ||
} | ||
} | ||
return flag; | ||
} | ||
|
||
bool BackendOptions::is_in_network_interface(const std::string& ip) { | ||
for (auto& interface_ip : _s_network_interfaces) { | ||
if (interface_ip == ip) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
||
bool BackendOptions::is_in_prior_network(const std::string& ip) { | ||
for (auto& cidr : _s_priority_cidrs) { | ||
CIDR _ip; | ||
|
@@ -129,4 +178,4 @@ bool BackendOptions::is_in_prior_network(const std::string& ip) { | |
return false; | ||
} | ||
|
||
} // namespace doris | ||
} // namespace doris |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,10 @@ mysql_service_nio_enabled = true | |
# Default value is empty. | ||
# priority_networks = 10.10.10.0/24;192.168.0.0/16 | ||
|
||
# Use network interface name, e.g. eth0 | ||
# Default value is empty. | ||
# network_interfaces = eth0;docker0 | ||
|
||
# Advanced configurations | ||
# log_roll_size_mb = 1024 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
# sys_log_dir = ${DORIS_HOME}/log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found may be a better name here.