On Tue, Mar 17, 2015 at 05:52:53PM +0100, Michal Privoznik wrote:
Not all NICs (esp. the virtual ones like TUN) must have a hardware
address. Learn our RPC that it's possible.
s/Learn/Teach/
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
daemon/remote.c | 5 ++++-
include/libvirt/libvirt-domain.h | 2 +-
src/libvirt-domain.c | 3 ++-
src/remote/remote_driver.c | 3 ++-
src/remote/remote_protocol.x | 2 +-
src/remote_protocol-structs | 2 +-
6 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 1dca64a..b6ea236 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -6525,7 +6525,9 @@ remoteSerializeDomainInterface(virDomainInterfacePtr *ifaces,
if ((VIR_STRDUP(iface_ret->name, iface->name)) < 0)
goto cleanup;
- if ((VIR_STRDUP(iface_ret->hwaddr, iface->hwaddr)) < 0)
+ if (iface->hwaddr &&
+ (VIR_ALLOC(iface_ret->hwaddr) < 0 ||
+ VIR_STRDUP(*iface_ret->hwaddr, iface->hwaddr) < 0))
goto cleanup;
if (iface->naddrs > REMOTE_DOMAIN_IP_ADDR_MAX) {
@@ -6561,6 +6563,7 @@ remoteSerializeDomainInterface(virDomainInterfacePtr *ifaces,
for (i = 0; i < ifaces_count; i++) {
remote_domain_interface *iface_ret = &(ret->ifaces.ifaces_val[i]);
VIR_FREE(iface_ret->name);
+ VIR_FREE(*iface_ret->hwaddr);
This will crash if hwaddr was NULL, and also leak
if (iface_ret->hwaddr)
VIR_FREE(*iface_ret->hwaddr);
VIR_FREE(iface_ret->hwaddr);
VIR_FREE(iface_ret->hwaddr);
for (j = 0; j < iface_ret->addrs.addrs_len; j++) {
remote_domain_ip_addr *ip_addr =
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index a026b9a..79ba3d7 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3760,7 +3760,7 @@ typedef struct _virDomainInterface virDomainInterface;
typedef virDomainInterface *virDomainInterfacePtr;
struct _virDomainInterface {
char *name; /* interface name */
- char *hwaddr; /* hardware address */
+ char *hwaddr; /* hardware address, may be NULL */
unsigned int naddrs; /* number of items in @addrs */
virDomainIPAddressPtr addrs; /* array of IP addresses */
};
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index a3f179d..0bd9274 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11460,7 +11460,8 @@ virDomainFSInfoFree(virDomainFSInfoPtr info)
* ... do something with returned values, for example:
* for (i = 0; i < ifaces_count; i++) {
* printf("name: %s", ifaces[i]->name);
- * printf(" hwaddr: %s", ifaces[i]->hwaddr);
+ * if (ifaces[i]->hwaddr)
+ * printf(" hwaddr: %s", ifaces[i]->hwaddr);
*
* for (j = 0; j < ifaces[i]->naddrs; j++) {
* virDomainIPAddressPtr ip_addr = ifaces[i]->addrs + j;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index d89db47..e69f235 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -7963,7 +7963,8 @@ remoteDomainInterfaceAddresses(virDomainPtr dom,
if (VIR_STRDUP(iface->name, iface_ret->name) < 0)
goto cleanup;
- if (VIR_STRDUP(iface->hwaddr, iface_ret->hwaddr) < 0)
+ if (iface_ret->hwaddr &&
+ VIR_STRDUP(iface->hwaddr, *iface_ret->hwaddr) < 0)
goto cleanup;
if (iface_ret->addrs.addrs_len > REMOTE_DOMAIN_IP_ADDR_MAX) {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index fe5fcdc..eb862e1 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -3191,7 +3191,7 @@ struct remote_domain_ip_addr {
struct remote_domain_interface {
remote_nonnull_string name;
- remote_nonnull_string hwaddr;
+ remote_string hwaddr;
remote_domain_ip_addr addrs<REMOTE_DOMAIN_IP_ADDR_MAX>;
};
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 5f4ebff..b3e2e40 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2646,7 +2646,7 @@ struct remote_domain_ip_addr {
};
struct remote_domain_interface {
remote_nonnull_string name;
- remote_nonnull_string hwaddr;
+ remote_string hwaddr;
struct {
u_int addrs_len;
remote_domain_ip_addr * addrs_val;
ACK with the inline fix applied
Regards,
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|