Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/interface/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ pub struct Interface {
/// Default gateway associated with this interface, when known.
///
/// This field is available only with the `gateway` feature. It may be `None` when the
/// interface is not the default route, when the gateway has no link-layer address available,
/// or when the platform cannot resolve gateway information.
/// interface has no gateway addresses or when the platform cannot obtain gateway
/// information. If the gateway addresses are known but the link-layer address cannot be
/// resolved, the device contains a zero MAC address.
#[cfg(feature = "gateway")]
pub gateway: Option<NetworkDevice>,
/// DNS resolver addresses associated with this interface.
Expand Down
25 changes: 16 additions & 9 deletions src/os/android/netlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,24 +376,31 @@ pub fn collect_routes() -> io::Result<HashMap<u32, GwRow>> {
}
}

let mut mac_candidates = crate::os::linux::gateway::GatewayMacCandidates::default();
for n in neighs {
let (ip, mac, ifi) = neigh_extract(&n);
let ifi = match ifi {
Some(i) => i,
None => continue,
};
if let Some(row) = m.get_mut(&ifi) {
if let (Some(m6), Some(ip)) = (mac, ip) {
let hit = match ip {
IpAddr::V4(v4) => row.gw_v4.contains(&v4),
IpAddr::V6(v6) => row.gw_v6.contains(&v6),
};
if hit {
row.mac = Some(m6);
}
let (Some(row), Some(m6), Some(ip)) = (m.get_mut(&ifi), mac, ip) else {
continue;
};
match ip {
IpAddr::V4(v4) if row.gw_v4.contains(&v4) => {
mac_candidates.record_ipv4(ifi, m6);
}
IpAddr::V6(v6) if row.gw_v6.contains(&v6) => {
mac_candidates.record_ipv6(ifi, m6);
}
_ => {}
}
}

for (ifindex, row) in &mut m {
// Preserve the established IPv4 result when both families use different routers.
row.mac = mac_candidates.get(*ifindex);
}

Ok(m)
}
Loading
Loading