Skip to content
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

fix(linux): do not override interface name by label #127

Merged
merged 1 commit into from
Sep 13, 2023
Merged
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
7 changes: 5 additions & 2 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,12 @@ pub fn list_afinet_netifas() -> Result<Vec<(String, IpAddr)>, Error> {
}

let mut ipaddr = None;
let mut label = None;

for rtattr in p.rtattrs.iter() {
if rtattr.rta_type == Ifa::Label {
let ifname = parse_ifname(rtattr.payload().as_ref())?;
if_indexes.insert(p.ifa_index, ifname);
label = Some(ifname);
} else if rtattr.rta_type == Ifa::Address {
if ipaddr.is_some() {
// do not override IFA_LOCAL
Expand Down Expand Up @@ -420,7 +421,9 @@ pub fn list_afinet_netifas() -> Result<Vec<(String, IpAddr)>, Error> {
}

if let Some(ipaddr) = ipaddr {
if let Some(ifname) = if_indexes.get(&p.ifa_index) {
if let Some(ifname) = label {
interfaces.push((ifname, ipaddr));
} else if let Some(ifname) = if_indexes.get(&p.ifa_index) {
interfaces.push((ifname.clone(), ipaddr));
}
}
Expand Down
Loading