Add a function virDomainFindNetDef 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..9f508d5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13726,3 +13726,42 @@ virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def,
return 0;
}
+
+/**
+ * virDomainFindNetDef:
+ * @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
+virDomainFindNetDef(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..2682edf 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 virDomainFindNetDef(virDomainDefPtr def,
+ const char *device);
#endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6fa9093..64917a7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -308,6 +308,7 @@ virDomainDiskSnapshotTypeFromString;
virDomainDiskSnapshotTypeToString;
virDomainDiskTypeFromString;
virDomainDiskTypeToString;
+virDomainFindNetDef;
virDomainFSDefFree;
virDomainFSTypeFromString;
virDomainFSTypeToString;
--
1.7.4.4