]> xenbits.xensource.com Git - xen-guest-agent.git/commitdiff
netlink: use name from NLA in Link events
authorYann Dirson <yann.dirson@vates.fr>
Mon, 20 Nov 2023 14:29:47 +0000 (15:29 +0100)
committerYann Dirson <yann.dirson@vates.fr>
Fri, 8 Dec 2023 09:59:46 +0000 (10:59 +0100)
We were always calling `if_indextoname()` to get the interface name when
receiving a New/DelLink message.  Just use the data we already received
instead.

On NewLink messages we just received the interface name, so we don't need
to make another query to get the information; on DelLink the sycall cannot
even give us this information any more.

Note at this point we still use "" to denote the lack of a name - it
seems unlikely to happen there anyway, and will be made cleaner next.

Signed-off-by: Yann Dirson <yann.dirson@vates.fr>
src/collector_net_netlink.rs

index c63634edf0207ec296c2c38528dce3cef2dc9eb5..47faf45bd923f1dc6c7c4de5a4bbb13abbcc116e 100644 (file)
@@ -134,8 +134,12 @@ fn nl_linkmessage_decode(msg: &LinkMessage) -> io::Result<(NetInterface, String)
     let LinkMessage{header, nlas, ..} = msg;
 
     // extract fields of interest
+    let mut iface_name: Option<String> = None;
     let mut address_bytes: Option<&Vec<u8>> = None;
     for nla in nlas {
+        if let link::nlas::Nla::IfName(name) = nla {
+            iface_name = Some(name.to_string());
+        }
         if let link::nlas::Nla::Address(addr) = nla {
             address_bytes = Some(addr);
         }
@@ -146,7 +150,7 @@ fn nl_linkmessage_decode(msg: &LinkMessage) -> io::Result<(NetInterface, String)
                                         .collect::<Vec<String>>().join(":"));
 
     let iface = NetInterface { index: header.index,
-                               name: interface_name(header.index),
+                               name: iface_name.unwrap_or(String::from("")),
                                toolstack_iface: ToolstackNetInterface::None,
     };