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

From: Ji-hoon Kim <relip@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@me.com> --- src/libxl/libxl_conf.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) 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); + } + else if (l_nic->nips > 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Driver does not support setting multiple IP addresses")); + return -1; + } + switch (actual_type) { case VIR_DOMAIN_NET_TYPE_BRIDGE: if (VIR_STRDUP(x_nic->bridge, -- 1.7.1

On Sat, Feb 07, 2015 at 04:53:46PM +0900, Jihoon Kim wrote:
From: Ji-hoon Kim <relip@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@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

Jihoon Kim wrote:
From: Ji-hoon Kim <relip@me.com>
Currently libxlMakeNic() does not set ip address when creating NIC, this patch makes it to set ip address.
FYI, Marek recently sent a patch to do the same https://www.redhat.com/archives/libvir-list/2015-February/msg00139.html I like Marek's error checking for multiple IPs in libxlDomainDeviceDefPostParse(), but do think that <ip address=''> should also be supported for <interface type=network>. Regards, Jim
Signed-off-by: Ji-hoon Kim <relip@me.com> --- src/libxl/libxl_conf.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
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); + } + else if (l_nic->nips > 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Driver does not support setting multiple IP addresses")); + return -1; + } + switch (actual_type) { case VIR_DOMAIN_NET_TYPE_BRIDGE: if (VIR_STRDUP(x_nic->bridge,

Jim Fehlig wrote:
Jihoon Kim wrote:
From: Ji-hoon Kim <relip@me.com>
Currently libxlMakeNic() does not set ip address when creating NIC, this patch makes it to set ip address.
FYI, Marek recently sent a patch to do the same
https://www.redhat.com/archives/libvir-list/2015-February/msg00139.html
I like Marek's error checking for multiple IPs in libxlDomainDeviceDefPostParse(), but do think that <ip address=''> should also be supported for <interface type=network>.
Marek provided a follow-up patch, which I've pushed http://libvirt.org/git/?p=libvirt.git;a=commit;h=8703ee58bd9d9d02b5d64fae48c... Thanks again for helping with the libxl driver! Any improvements or fixes you have are welcomed. Regards, Jim
participants (3)
-
Jihoon Kim
-
Jim Fehlig
-
Ján Tomko