[PATCHv4 4/6] Add a function virDomainNetFind

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a function virDomainNetFind to find a domain's net def.
---
 src/conf/domain_conf.c   |   39 +++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |    3 +++
 src/libvirt_private.syms |    1 +
 3 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2897b4a..7fa4adb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13726,3 +13726,42 @@ virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def,
 
     return 0;
 }
+
+/**
+ * virDomainNetFind:
+ * @def: domain's def
+ * @device: could be the interface name or MAC address
+ *
+ * Finds a domain's net def, given the interface name or MAC address
+ *
+ * Returns a pointer to the net def or NULL if not found.
+ */
+virDomainNetDefPtr
+virDomainNetFind(virDomainDefPtr def, const char *device)
+{
+    bool isMac = false;
+    virDomainNetDefPtr net = NULL;
+    unsigned char mac[VIR_MAC_BUFLEN];
+    int i;
+
+    if (virParseMacAddr(device, mac) == 0)
+        isMac = true;
+
+    if (isMac) {
+        for (i = 0; i < def->nnets; i++) {
+            if (memcmp(mac, def->nets[i]->mac, VIR_MAC_BUFLEN) == 0) {
+                net = def->nets[i];
+                break;
+            }
+        }
+    } else { /* ifname */
+        for (i = 0; i < def->nnets; i++) {
+            if (STREQ(device, def->nets[i]->ifname)) {
+                net = def->nets[i];
+                break;
+            }
+        }
+    }
+
+    return net;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 1f6e442..9bcdb3a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2033,4 +2033,7 @@ VIR_ENUM_DECL(virDomainTimerTickpolicy)
 VIR_ENUM_DECL(virDomainTimerMode)
 
 VIR_ENUM_DECL(virDomainStartupPolicy)
+
+virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def,
+                                    const char *device);
 #endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6fa9093..216a5a5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -308,6 +308,7 @@ virDomainDiskSnapshotTypeFromString;
 virDomainDiskSnapshotTypeToString;
 virDomainDiskTypeFromString;
 virDomainDiskTypeToString;
+virDomainNetFind;
 virDomainFSDefFree;
 virDomainFSTypeFromString;
 virDomainFSTypeToString;
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]