Commit 5d0a855f authored by Daniel P. Berrange's avatar Daniel P. Berrange

Fix handling of domain interface list data

The approach to handling the domain interface list data was broken and
only worked by luck when there was a single interface, with a single
address. If there were multiple interfaces or multiple addresses a
Go exception would result.

Rewrite it to use pointer arithmetic instead of trying to turn the C
array into a go slice
Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 6d8485c4
......@@ -1807,37 +1807,29 @@ func (d *Domain) ListAllInterfaceAddresses(src uint) ([]DomainInterface, error)
return nil, GetLastError()
}
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(cList)),
Len: int(numIfaces),
Cap: int(numIfaces),
}
ifaces := make([]DomainInterface, numIfaces)
ifaceSlice := *(*[]C.virDomainInterfacePtr)(unsafe.Pointer(&hdr))
for i := 0; i < numIfaces; i++ {
ifaces[i].Name = C.GoString(ifaceSlice[i].name)
ifaces[i].Hwaddr = C.GoString(ifaceSlice[i].hwaddr)
numAddr := int(ifaceSlice[i].naddrs)
addrHdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(&ifaceSlice[i].addrs)),
Len: int(numAddr),
Cap: int(numAddr),
}
var ciface *C.virDomainInterface
ciface = *(**C.virDomainInterface)(unsafe.Pointer(uintptr(unsafe.Pointer(cList)) + (unsafe.Sizeof(ciface) * uintptr(i))))
ifaces[i].Name = C.GoString(ciface.name)
ifaces[i].Hwaddr = C.GoString(ciface.hwaddr)
numAddr := int(ciface.naddrs)
ifaces[i].Addrs = make([]DomainIPAddress, numAddr)
addrSlice := *(*[]C.virDomainIPAddressPtr)(unsafe.Pointer(&addrHdr))
for k := 0; k < numAddr; k++ {
var caddr *C.virDomainIPAddress
caddr = (*C.virDomainIPAddress)(unsafe.Pointer(uintptr(unsafe.Pointer(ciface.addrs)) + (unsafe.Sizeof(*caddr) * uintptr(k))))
ifaces[i].Addrs[k] = DomainIPAddress{}
ifaces[i].Addrs[k].Type = int(addrSlice[k]._type)
ifaces[i].Addrs[k].Addr = C.GoString(addrSlice[k].addr)
ifaces[i].Addrs[k].Prefix = uint(addrSlice[k].prefix)
ifaces[i].Addrs[k].Type = int(caddr._type)
ifaces[i].Addrs[k].Addr = C.GoString(caddr.addr)
ifaces[i].Addrs[k].Prefix = uint(caddr.prefix)
}
C.virDomainInterfaceFreeCompat(ifaceSlice[i])
C.virDomainInterfaceFreeCompat(ciface)
}
C.free(unsafe.Pointer(cList))
return ifaces, nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment