fix: addressed edge cases for external routing
This commit is contained in:
parent
b770d53f57
commit
1517ca6f1c
@ -59,7 +59,7 @@ async fn handled_main() -> anyhow::Result<()> {
|
|||||||
let mut interfaces = pcap_sys::PcapDevIterator::new()?;
|
let mut interfaces = pcap_sys::PcapDevIterator::new()?;
|
||||||
|
|
||||||
let interface_name = interfaces
|
let interface_name = interfaces
|
||||||
.find(|eth| eth.starts_with("eth"))
|
.find(|eth| eth.starts_with("eth") || eth.starts_with("en"))
|
||||||
.ok_or(anyhow!("Could not get an ethernet interface"))?;
|
.ok_or(anyhow!("Could not get an ethernet interface"))?;
|
||||||
|
|
||||||
log::info!("Attaching to interface {}", &interface_name);
|
log::info!("Attaching to interface {}", &interface_name);
|
||||||
|
|||||||
@ -178,16 +178,22 @@ impl<T: From<*mut nl_object>> Iterator for CacheIter<'_, T> {
|
|||||||
type Item = T;
|
type Item = T;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.index >= self.cache_size || self.obj.is_null() {
|
loop {
|
||||||
return None;
|
if self.index >= self.cache_size {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.index += 1;
|
||||||
|
|
||||||
|
let obj = self.obj;
|
||||||
|
self.obj = unsafe { nl_cache_get_next(obj) };
|
||||||
|
|
||||||
|
if obj.is_null() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break Some(T::from(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.index += 1;
|
|
||||||
|
|
||||||
let obj = self.obj;
|
|
||||||
self.obj = unsafe { nl_cache_get_next(obj) };
|
|
||||||
|
|
||||||
Some(T::from(obj))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
|||||||
@ -73,6 +73,9 @@ impl Link {
|
|||||||
pub fn name(&self) -> String {
|
pub fn name(&self) -> String {
|
||||||
unsafe {
|
unsafe {
|
||||||
let name = rtnl_link_get_name(self.link);
|
let name = rtnl_link_get_name(self.link);
|
||||||
|
if name.is_null() {
|
||||||
|
return "".to_string();
|
||||||
|
}
|
||||||
let name_rs = CStr::from_ptr(name);
|
let name_rs = CStr::from_ptr(name);
|
||||||
std::str::from_utf8(name_rs.to_bytes()).unwrap().to_owned()
|
std::str::from_utf8(name_rs.to_bytes()).unwrap().to_owned()
|
||||||
}
|
}
|
||||||
@ -96,7 +99,7 @@ impl Link {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let ltype_rs = CStr::from_ptr(ltype);
|
let ltype_rs = CStr::from_ptr(ltype);
|
||||||
Some(std::str::from_utf8(ltype_rs.to_bytes()).unwrap().to_owned())
|
Some(std::str::from_utf8(ltype_rs.to_bytes()).ok()?.to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,8 +199,6 @@ pub fn get_macs_and_src_for_ip(
|
|||||||
|
|
||||||
let link = netlink::get_link_by_index(links, link_ind)?;
|
let link = netlink::get_link_by_index(links, link_ind)?;
|
||||||
|
|
||||||
let neighs_ = neighs.iter().collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let neigh = neighs
|
let neigh = neighs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|n| n.ifindex() == link.ifindex())
|
.find(|n| n.ifindex() == link.ifindex())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user