From: Michal Privoznik Date: Tue, 17 Mar 2015 16:18:02 +0000 (+0100) Subject: RPC: Allow HW address in remote_domain_interface struct to be NULL X-Git-Tag: v1.2.14-rc1~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3640245db7d72bf8e05df726587625a6328c895e;p=thirdparty%2Flibvirt.git RPC: Allow HW address in remote_domain_interface struct to be NULL Not all NICs (esp. the virtual ones like TUN) must have a hardware address. Teach our RPC that it's possible. Signed-off-by: Michal Privoznik --- diff --git a/daemon/remote.c b/daemon/remote.c index 1dca64a507..62a4728990 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,7 +6563,10 @@ 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); + if (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 = &(iface_ret->addrs.addrs_val[j]); diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index a026b9aa6c..79ba3d7ab2 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 a3f179d9d4..0bd9274be8 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 d89db47ae4..e69f2356f1 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 fe5fcdc237..eb862e1a4a 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; }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 5f4ebffba3..b3e2e40d27 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;