提交 ee3de186 编写于 作者: H Hu Tao 提交者: Osier Yang

domiftune: Add a util function virDomainNetFind

Add a util function virDomainNetFind to find a domain's net def.
上级 e7dfe00d
......@@ -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_NULLABLE(device, def->nets[i]->ifname)) {
net = def->nets[i];
break;
}
}
}
return net;
}
......@@ -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 */
......@@ -308,6 +308,7 @@ virDomainDiskSnapshotTypeFromString;
virDomainDiskSnapshotTypeToString;
virDomainDiskTypeFromString;
virDomainDiskTypeToString;
virDomainNetFind;
virDomainFSDefFree;
virDomainFSTypeFromString;
virDomainFSTypeToString;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册