-
Notifications
You must be signed in to change notification settings - Fork 215
Automatically update the endpoint list when then network configuration change #2020
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
Open
Hugal31
wants to merge
24
commits into
eclipse-zenoh:main
Choose a base branch
from
Hugal31:feature/endpoint-auto-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ddf8b19
Detect change on network interface to update locators and scouting
67da75e
Refactor scouting out of the runtime
b94c464
Move net::Runtime::scout to net::Scouting
8a3b311
Make the scouting routine create and close appropriate sockets on net…
3779614
Collect multiple netlink messages before updating the locators and th…
b5aaab5
Reformat code
4f9c5fb
Run clippy
56daad9
Hide the netlink monitoring behind cfg(target_os = "linux")
8c686fe
Add TODO
782021d
Merge tag '1.4.0' into feature/netlink-monitor
e74c967
Merge remote-tracking branch 'upstream/main' into feature/endpoint-au…
7378e00
Send locators updates to peers&routers
eec08cc
Use a 10s poll interval to see if locators have changed instead of NE…
cfd1111
Don't assume TransportManager::get_locators will always yield the loc…
d5418be
Add endpoint_poll_interval_ms to configure the network change detecti…
3d8d2b6
Add attributes to make the linter pass when the netlink feature is no…
fe2256b
Fix RandomState import
da5345e
Only start the endpoint poll routine if the duration is positive
b9f1f51
Fix memory leak at Runtime cleanup
bceee2d
Merge remote-tracking branch 'upstream/main' into feature/endpoint-au…
22010b3
Merge remote-tracking branch 'upstream/main' into feature/endpoint-au…
fb357b2
Merge remote-tracking branch 'upstream/main' into feature/endpoint-au…
4fb7c12
Merge remote-tracking branch 'upstream/main' into feature/endpoint-au…
3f079dc
Merge remote-tracking branch 'upstream/main' into feature/endpoint-au…
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
use std::net::{IpAddr, Ipv6Addr}; | ||
#[cfg(unix)] | ||
use std::sync::RwLock; | ||
|
||
#[cfg(unix)] | ||
use lazy_static::lazy_static; | ||
|
@@ -20,6 +22,8 @@ use pnet_datalink::NetworkInterface; | |
use tokio::net::{TcpSocket, UdpSocket}; | ||
use zenoh_core::zconfigurable; | ||
#[cfg(unix)] | ||
use zenoh_core::{zread, zwrite}; | ||
#[cfg(unix)] | ||
use zenoh_result::zerror; | ||
use zenoh_result::{bail, ZResult}; | ||
|
||
|
@@ -30,7 +34,7 @@ zconfigurable! { | |
|
||
#[cfg(unix)] | ||
lazy_static! { | ||
static ref IFACES: Vec<NetworkInterface> = pnet_datalink::interfaces(); | ||
static ref IFACES: RwLock<Vec<NetworkInterface>> = RwLock::new(pnet_datalink::interfaces()); | ||
} | ||
|
||
#[cfg(windows)] | ||
|
@@ -68,7 +72,7 @@ unsafe fn get_adapters_addresses(af_spec: i32) -> ZResult<Vec<u8>> { | |
pub fn get_interface(name: &str) -> ZResult<Option<IpAddr>> { | ||
#[cfg(unix)] | ||
{ | ||
for iface in IFACES.iter() { | ||
for iface in zread!(IFACES).iter() { | ||
if iface.name == name { | ||
for ifaddr in &iface.ips { | ||
if ifaddr.is_ipv4() { | ||
|
@@ -131,7 +135,7 @@ pub fn get_interface(name: &str) -> ZResult<Option<IpAddr>> { | |
pub fn get_multicast_interfaces() -> Vec<IpAddr> { | ||
#[cfg(unix)] | ||
{ | ||
IFACES | ||
zread!(IFACES) | ||
.iter() | ||
.filter_map(|iface| { | ||
if iface.is_up() && iface.is_running() && iface.is_multicast() { | ||
|
@@ -155,7 +159,7 @@ pub fn get_multicast_interfaces() -> Vec<IpAddr> { | |
pub fn get_local_addresses(interface: Option<&str>) -> ZResult<Vec<IpAddr>> { | ||
#[cfg(unix)] | ||
{ | ||
Ok(IFACES | ||
Ok(zread!(IFACES) | ||
.iter() | ||
.filter(|iface| { | ||
if let Some(interface) = interface.as_ref() { | ||
|
@@ -205,7 +209,7 @@ pub fn get_local_addresses(interface: Option<&str>) -> ZResult<Vec<IpAddr>> { | |
pub fn get_unicast_addresses_of_multicast_interfaces() -> Vec<IpAddr> { | ||
#[cfg(unix)] | ||
{ | ||
IFACES | ||
zread!(IFACES) | ||
.iter() | ||
.filter(|iface| iface.is_up() && iface.is_running() && iface.is_multicast()) | ||
.flat_map(|iface| { | ||
|
@@ -228,7 +232,7 @@ pub fn get_unicast_addresses_of_multicast_interfaces() -> Vec<IpAddr> { | |
pub fn get_unicast_addresses_of_interface(name: &str) -> ZResult<Vec<IpAddr>> { | ||
#[cfg(unix)] | ||
{ | ||
match IFACES.iter().find(|iface| iface.name == name) { | ||
match zread!(IFACES).iter().find(|iface| iface.name == name) { | ||
Some(iface) => { | ||
if !iface.is_up() { | ||
bail!("Interface {name} is not up"); | ||
|
@@ -282,7 +286,7 @@ pub fn get_unicast_addresses_of_interface(name: &str) -> ZResult<Vec<IpAddr>> { | |
pub fn get_index_of_interface(addr: IpAddr) -> ZResult<u32> { | ||
#[cfg(unix)] | ||
{ | ||
IFACES | ||
zread!(IFACES) | ||
.iter() | ||
.find(|iface| iface.ips.iter().any(|ipnet| ipnet.ip() == addr)) | ||
.map(|iface| iface.index) | ||
|
@@ -319,12 +323,12 @@ pub fn get_interface_names_by_addr(addr: IpAddr) -> ZResult<Vec<String>> { | |
#[cfg(unix)] | ||
{ | ||
if addr.is_unspecified() { | ||
Ok(IFACES | ||
Ok(zread!(IFACES) | ||
.iter() | ||
.map(|iface| iface.name.clone()) | ||
.collect::<Vec<String>>()) | ||
} else { | ||
Ok(IFACES | ||
Ok(zread!(IFACES) | ||
.iter() | ||
.filter(|iface| iface.ips.iter().any(|ipnet| ipnet.ip() == addr)) | ||
.map(|iface| iface.name.clone()) | ||
|
@@ -435,6 +439,12 @@ pub fn get_ipv6_ipaddrs(interface: Option<&str>) -> Vec<IpAddr> { | |
.collect() | ||
} | ||
|
||
#[cfg(unix)] | ||
pub fn update_iface_cache() { | ||
let mut interfaces = zwrite!(IFACES); | ||
*interfaces = pnet_datalink::interfaces(); | ||
} | ||
|
||
#[cfg(any(target_os = "linux", target_os = "android"))] | ||
pub fn set_bind_to_device_tcp_socket(socket: &TcpSocket, iface: &str) -> ZResult<()> { | ||
socket.bind_device(Some(iface.as_bytes()))?; | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Is there any specific reason to use i64 for purely positive value, can Option::None be used for disabling ?
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.
I copied the idea from timeout_ms, which has the same semantic if I'm not mistaken (-1 = infinite / disabled).
After verification, I disable the poll if the interval is
<= 0
, not just< 0
, while timeout_ms actually has a timeout of 0 if you set 0.I don't mind changing