[libvirt] [PATCHv2] libxl: set IP address when creating NIC

Ján Tomko jtomko at redhat.com
Mon Feb 9 08:16:48 UTC 2015


On Sat, Feb 07, 2015 at 04:53:46PM +0900, Jihoon Kim wrote:
> From: Ji-hoon Kim <relip at me.com>
> 
> Currently libxlMakeNic() does not set ip address when creating NIC,
> this patch makes it to set ip address.
> 
> Signed-off-by: Ji-hoon Kim <relip at me.com>
> ---
>  src/libxl/libxl_conf.c |   14 ++++++++++++++
>  1 files changed, 14 insertions(+), 0 deletions(-)
> 

I'm not that familiar with libxl, but...

> diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
> index 0555b91..e49715d 100644
> --- a/src/libxl/libxl_conf.c
> +++ b/src/libxl/libxl_conf.c
> @@ -1042,6 +1042,20 @@ libxlMakeNic(virDomainDefPtr def,
>      if (VIR_STRDUP(x_nic->ifname, l_nic->ifname) < 0)
>          return -1;
>  
> +    if (l_nic->nips == 1) {
> +        char *ipStr = virSocketAddrFormat(&l_nic->ips[0]->address);
> +        if (VIR_STRDUP(x_nic->ip, ipStr) < 0) {
> +            VIR_FREE(ipStr);
> +            return -1;
> +        }
> +        VIR_FREE(ipStr);

This does not check the return value of virSocketAddrFormat (VIR_STRDUP
returns 0 when the source string is NULL).

The VIR_STRDUP is also redundant, the string allocated by
virSocketAddrFormat can be just assigned to x_nic->ip.

Jan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150209/dc9f7c2c/attachment-0001.sig>


More information about the libvir-list mailing list