From 68c7e383038935429e2110668b77b869965e4144 Mon Sep 17 00:00:00 2001
From: Luna D Dragon <luna.dragon@suse.com>
Date: Tue, 10 Mar 2026 11:24:28 +0530
Subject: [PATCH] backport: b8b3be2c38c887cd94a6aa7427a28b44a56b02c6

---
 src/libvirt-xml-parse.js    |  9 ------
 src/libvirtApi/common.js    |  2 +-
 src/libvirtApi/interface.js | 61 +++++++++++--------------------------
 3 files changed, 18 insertions(+), 54 deletions(-)

diff --git a/src/libvirt-xml-parse.js b/src/libvirt-xml-parse.js
index 50bc1c30..6e05b8af 100644
--- a/src/libvirt-xml-parse.js
+++ b/src/libvirt-xml-parse.js
@@ -801,15 +801,6 @@ export function parseDumpxmlMachinesMetadataElement(metadataElem, name) {
     return subElems.length > 0 ? subElems[0].textContent : null;
 }
 
-export function parseIfaceDumpxml(ifaceXml) {
-    const retObj = {};
-    const ifaceElem = getElem(ifaceXml);
-
-    retObj.type = ifaceElem.getAttribute("type");
-
-    return retObj;
-}
-
 export function parseNetDumpxml(netXml) {
     const retObj = {};
     const netElem = getElem(netXml);
diff --git a/src/libvirtApi/common.js b/src/libvirtApi/common.js
index f40a6838..533f36e2 100644
--- a/src/libvirtApi/common.js
+++ b/src/libvirtApi/common.js
@@ -436,7 +436,7 @@ export function getApiData({ connectionName }) {
     return Promise.allSettled([
         domainGetAll({ connectionName }),
         storagePoolGetAll({ connectionName }),
-        interfaceGetAll({ connectionName }),
+        interfaceGetAll(),
         networkGetAll({ connectionName }),
         nodeDeviceGetAll({ connectionName }),
         getNodeMaxMemory({ connectionName }),
diff --git a/src/libvirtApi/interface.js b/src/libvirtApi/interface.js
index 6555583a..f65ee439 100644
--- a/src/libvirtApi/interface.js
+++ b/src/libvirtApi/interface.js
@@ -21,54 +21,27 @@
  * Provider for Libvirt using libvirt-dbus API.
  * See https://github.com/libvirt/libvirt-dbus
  */
+import cockpit from 'cockpit';
+
 import store from '../store.js';
 
 import { updateOrAddInterface } from '../actions/store-actions.js';
-import { parseIfaceDumpxml } from '../libvirt-xml-parse.js';
-import { call, Enum, timeout } from './helpers.js';
 
-/*
- * Read properties of a single Interface
- *
- * @param {object} objPath interface object path
- * @param {string} connectionName
- */
-export function interfaceGet({
-    id: objPath,
-    connectionName,
-}) {
-    const props = {};
+export async function interfaceGetAll() {
+    let ifaces = [];
 
-    return call(connectionName, objPath, 'org.freedesktop.DBus.Properties', 'GetAll', ['org.libvirt.Interface'], { timeout, type: 's' })
-            .then(resultProps => {
-                /* Sometimes not all properties are returned; for example when some network got deleted while part
-                 * of the properties got fetched from libvirt. Make sure that there is check before reading the attributes.
-                 */
-                if ("Active" in resultProps[0])
-                    props.active = resultProps[0].Active.v.v;
-                if ("MAC" in resultProps[0])
-                    props.mac = resultProps[0].MAC.v.v;
-                if ("Name" in resultProps[0])
-                    props.name = resultProps[0].Name.v.v;
-                props.id = objPath;
-                props.connectionName = connectionName;
+    try {
+        const ipData = await cockpit.spawn(["ip", "--json", "a"], { err: "message" });
+        ifaces = JSON.parse(ipData);
+    } catch (ex) {
+        console.warn("Failed to get interfaces with ip command:", ex.toString());
+    }
 
-                return call(connectionName, objPath, 'org.libvirt.Interface', 'GetXMLDesc', [0], { timeout, type: 'u' });
-            })
-            .then(xml => {
-                const iface = parseIfaceDumpxml(xml);
-                return store.dispatch(updateOrAddInterface(Object.assign({}, props, iface)));
-            })
-            .catch(ex => console.log('listInactiveInterfaces action for path', objPath, ex.toString()));
-}
-
-export function interfaceGetAll({ connectionName }) {
-    const flags = Enum.VIR_CONNECT_LIST_INTERFACES_ACTIVE | Enum.VIR_CONNECT_LIST_INTERFACES_INACTIVE;
-
-    return call(connectionName, '/org/libvirt/QEMU', 'org.libvirt.Connect', 'ListInterfaces', [flags], { timeout, type: 'u' })
-            .then(ifaces => Promise.all(ifaces[0].map(path => interfaceGet({ connectionName, id: path }))))
-            .catch(ex => {
-                console.warn('getAllInterfaces action failed:', ex.toString());
-                return Promise.reject(ex);
-            });
+    for (const iface of ifaces) {
+        store.dispatch(updateOrAddInterface({
+            name: iface.ifname,
+            MAC: iface.address,
+            Active: iface.operstate === "UP",
+        }));
+    }
 }
-- 
2.53.0

