Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/libvirt_private.syms | 1 +
src/vz/vz_sdk.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2b55369..3f2845b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2185,6 +2185,7 @@ virSocketAddrEqual;
virSocketAddrFormat;
virSocketAddrFormatFull;
virSocketAddrGetIpPrefix;
+virSocketAddrGetNumNetmaskBits;
virSocketAddrGetPort;
virSocketAddrGetRange;
virSocketAddrIsNetmask;
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 29b31a2..db85558 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -727,6 +727,91 @@ prlsdkAddDomainOpticalDisksInfo(vzDriverPtr driver, PRL_HANDLE
sdkdom, virDomain
return -1;
}
+static virDomainNetIpDefPtr
+prlsdkParseNetAddress(char *addr)
+{
+ char *maskstr = NULL;
+ int nbits;
+ virSocketAddr mask;
+ virDomainNetIpDefPtr ip = NULL, ret = NULL;
+
+ if (!(maskstr = strchr(addr, '/')))
+ goto cleanup;
+
+ *maskstr = '\0';
+ ++maskstr;
+
+ if (VIR_ALLOC(ip) < 0)
+ goto cleanup;
+
+ if (virSocketAddrParse(&ip->address, addr, AF_UNSPEC) < 0)
+ goto cleanup;
+
+ if (virSocketAddrParse(&mask, maskstr, AF_UNSPEC) < 0)
+ goto cleanup;
+
+ if ((nbits = virSocketAddrGetNumNetmaskBits(&mask)) < 0)
+ goto cleanup;
+ ip->prefix = nbits;
+
+ ret = ip;
+ ip = NULL;
+
+ cleanup:
+ if (!ret)
+ VIR_WARN("cannot parse network address '%s'", addr);
+
+ VIR_FREE(ip);
+ VIR_FREE(addr);
+
+ return ret;
+}
+
+static int
+prlsdkGetNetAddresses(PRL_HANDLE sdknet, virDomainNetDefPtr net)
+{
+ int ret = -1;
+ PRL_HANDLE addrlist = PRL_INVALID_HANDLE;
+ PRL_UINT32 num;
+ size_t i;
+ PRL_RESULT pret;
+
+ pret = PrlVmDevNet_GetNetAddresses(sdknet, &addrlist);
+ prlsdkCheckRetGoto(pret, cleanup);
+
+ PrlStrList_GetItemsCount(addrlist, &num);
+ prlsdkCheckRetGoto(pret, cleanup);
+
+ for (i = 0; i < num; ++i) {
+ virDomainNetIpDefPtr ip = NULL;
+ PRL_UINT32 buflen = 0;
+ char *addr;
+
+ pret = PrlStrList_GetItem(addrlist, i, NULL, &buflen);
+ prlsdkCheckRetGoto(pret, cleanup);
+
+ if (VIR_ALLOC_N(addr, buflen) < 0)
+ goto cleanup;
+
+ pret = PrlStrList_GetItem(addrlist, i, addr, &buflen);
+ prlsdkCheckRetGoto(pret, cleanup);
+
+ if (!(ip = prlsdkParseNetAddress(addr)))
+ continue;
+
+ if (VIR_APPEND_ELEMENT(net->ips, net->nips, ip) < 0) {
+ VIR_FREE(ip);
+ goto cleanup;
+ }
+ }
+
+ ret = 0;
+ cleanup:
+
+ PrlHandle_Free(addrlist);
+ return ret;
+}
+
static int
prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt)
{
@@ -766,6 +851,9 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool
isCt)
if (virMacAddrParse(macstr, &net->mac) < 0)
goto cleanup;
+ if (prlsdkGetNetAddresses(netAdapter, net) < 0)
+ goto cleanup;
+
pret = PrlVmDev_GetEmulatedType(netAdapter, &emulatedType);
prlsdkCheckRetGoto(pret, cleanup);
--
1.8.3.1