Small wrapper to lookup interface in domain definition by its name. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_conf.c | 29 +++++++++++++++++++++++------ src/conf/domain_conf.h | 1 + src/libvirt_private.syms | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87192eb2d..2289399cd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26952,17 +26952,34 @@ virDomainNetFind(virDomainDefPtr def, const char *device) } } } else { /* ifname */ - for (i = 0; i < def->nnets; i++) { - if (STREQ_NULLABLE(device, def->nets[i]->ifname)) { - net = def->nets[i]; - break; - } - } + net = virDomainNetFindByName(def, device); } return net; } +/** + * virDomainNetFindByName: + * @def: domain's def + * @ifname: interface name + * + * Finds a domain's net def given the interface name. + * + * Returns a pointer to the net def or NULL if not found. + */ +virDomainNetDefPtr +virDomainNetFindByName(virDomainDefPtr def, const char *ifname) +{ + size_t i; + + for (i = 0; i < def->nnets; i++) { + if (STREQ_NULLABLE(ifname, def->nets[i]->ifname)) + return def->nets[i]; + } + + return NULL; +} + /** * virDomainDeviceDefCopy: * @caps: Capabilities diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 05a035a16..9ba84a94d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3000,6 +3000,7 @@ int virDomainDiskSourceParse(xmlNodePtr node, int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net); virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *device); +virDomainNetDefPtr virDomainNetFindByName(virDomainDefPtr def, const char *ifname); bool virDomainHasNet(virDomainDefPtr def, virDomainNetDefPtr net); int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net); virDomainNetDefPtr virDomainNetRemove(virDomainDefPtr def, size_t i); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5b1bc5e4f..7a12d6a14 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -422,6 +422,7 @@ virDomainNetDefClear; virDomainNetDefFormat; virDomainNetDefFree; virDomainNetFind; +virDomainNetFindByName; virDomainNetFindIdx; virDomainNetGenerateMAC; virDomainNetGetActualBandwidth; -- 2.13.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list