[libvirt] Missing libxl_device_nic settings

Hi, I was trying to pass ip address to scripts/vif-bridge by putting <ip address=""/> in guest config xml file, however, I found that libxlMakeNic(which located in libxl/libxl_conf.c:956) doesn't set x_nic->ip. So I patched myself but I'm not so sure about VIR_DOMAIN_NET_TYPE_ETHERNET. It seems like vif-route, correct? Here is my patch: diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 0555b91..0effc59 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1047,10 +1047,18 @@ libxlMakeNic(virDomainDefPtr def, if (VIR_STRDUP(x_nic->bridge, virDomainNetGetActualBridgeName(l_nic)) < 0) return -1; - /* fallthrough */ + if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) + return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.bridge.ipaddr) < 0) + return -1; + break; case VIR_DOMAIN_NET_TYPE_ETHERNET: if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.ethernet.ipaddr) < 0) + return -1; + if (VIR_STRDUP(x_nic->gatewaydev, l_nic->data.ethernet.dev) < 0) + return -1; break; case VIR_DOMAIN_NET_TYPE_NETWORK: { Regards, Jihoon

Kim Larry wrote:
Hi,
I was trying to pass ip address to scripts/vif-bridge by putting <ip address=""/> in guest config xml file, however, I found that libxlMakeNic(which located in libxl/libxl_conf.c:956) doesn't set x_nic->ip. So I patched myself but I'm not so sure about VIR_DOMAIN_NET_TYPE_ETHERNET. It seems like vif-route, correct?
If you want to use a routed setup, consider a 'network' type interface. E.g. <interface type='network'> <source network='routed-network'/> </interface> where 'routed-network' is a libvirt network with |<forward mode='route'/>. For more details on libvirt networking see the wiki| || |http://wiki.libvirt.org/page/Networking| || ||
Here is my patch:
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 0555b91..0effc59 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1047,10 +1047,18 @@ libxlMakeNic(virDomainDefPtr def, if (VIR_STRDUP(x_nic->bridge, virDomainNetGetActualBridgeName(l_nic)) < 0) return -1; - /* fallthrough */ + if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) + return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.bridge.ipaddr) < 0)
You will need to rebase against latest git master. ipaddr was removed by commit aa2cc721.
+ return -1; + break; case VIR_DOMAIN_NET_TYPE_ETHERNET: if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.ethernet.ipaddr) < 0) + return -1; + if (VIR_STRDUP(x_nic->gatewaydev, l_nic->data.ethernet.dev) < 0)
I don't think the last part is right. data.ethernet.dev is the vdev name, not a gateway. Regards, Jim

Then how do I set ip address when a VM has to use bridged network with specific ip? Clearly libxl supports it, but I don't see any way to set it though libvirt. JIhoon Jim Fehlig <jfehlig@suse.com> wrote: Kim Larry wrote: Hi, I was trying to pass ip address to scripts/vif-bridge by putting <ip address=""/> in guest config xml file, however, I found that libxlMakeNic(which located in libxl/libxl_conf.c:956) doesn't set x_nic->ip. So I patched myself but I'm not so sure about VIR_DOMAIN_NET_TYPE_ETHERNET. It seems like vif-route, correct? If you want to use a routed setup, consider a 'network' type interface. E.g. <interface type='network'> <source network='routed-network'/> </interface> where 'routed-network' is a libvirt network with |<forward mode='route'/>. For more details on libvirt networking see the wiki| || |http://wiki.libvirt.org/page/Networking| || || Here is my patch: diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 0555b91..0effc59 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1047,10 +1047,18 @@ libxlMakeNic(virDomainDefPtr def, if (VIR_STRDUP(x_nic->bridge, virDomainNetGetActualBridgeName(l_nic)) < 0) return -1; - /* fallthrough */ + if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) + return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.bridge.ipaddr) < 0) You will need to rebase against latest git master. ipaddr was removed by commit aa2cc721. + return -1; + break; case VIR_DOMAIN_NET_TYPE_ETHERNET: if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.ethernet.ipaddr) < 0) + return -1; + if (VIR_STRDUP(x_nic->gatewaydev, l_nic->data.ethernet.dev) < 0) I don't think the last part is right. data.ethernet.dev is the vdev name, not a gateway. Regards, Jim

Kim Larry wrote:
Then how do I set ip address when a VM has to use bridged network with specific ip?
As you describe, and as your patch attempts to do :). But you'll need a V2 to address my comments, particularly the need to rebase against master. Cedric provided some hints on doing that. Regards, Jim
Clearly libxl supports it, but I don't see any way to set it though libvirt.
JIhoon
Jim Fehlig <jfehlig@suse.com> wrote:
Kim Larry wrote:
Hi, I was trying to pass ip address to scripts/vif-bridge by putting <ip address=""/> in guest config xml file, however, I found that libxlMakeNic(which located in libxl/libxl_conf.c:956) doesn't set x_nic->ip. So I patched myself but I'm not so sure about VIR_DOMAIN_NET_TYPE_ETHERNET. It seems like vif-route, correct?
If you want to use a routed setup, consider a 'network' type interface. E.g.
<interface type='network'> <source network='routed-network'/> </interface>
where 'routed-network' is a libvirt network with |<forward mode='route'/>. For more details on libvirt networking see the wiki| || |http://wiki.libvirt.org/page/Networking| <http://wiki.libvirt.org/page/Networking%7C> || ||
Here is my patch: diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 0555b91..0effc59 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1047,10 +1047,18 @@ libxlMakeNic(virDomainDefPtr def, if (VIR_STRDUP(x_nic->bridge, virDomainNetGetActualBridgeName(l_nic)) < 0) return -1; - /* fallthrough */ + if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) + return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.bridge.ipaddr) < 0)
You will need to rebase against latest git master. ipaddr was removed by commit aa2cc721.
+ return -1; + break; case VIR_DOMAIN_NET_TYPE_ETHERNET: if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.ethernet.ipaddr) < 0) + return -1; + if (VIR_STRDUP(x_nic->gatewaydev, l_nic->data.ethernet.dev) < 0)
I don't think the last part is right. data.ethernet.dev is the vdev name, not a gateway.
Regards, Jim

Hi Jihoon, On Sat, 2015-01-24 at 17:17 +0000, Kim Larry wrote:
I was trying to pass ip address to scripts/vif-bridge by putting <ip address=""/> in guest config xml file, however, I found that libxlMakeNic(which located in libxl/libxl_conf.c:956) doesn't set x_nic->ip. So I patched myself but I'm not so sure about VIR_DOMAIN_NET_TYPE_ETHERNET. It seems like vif-route, correct?
You're right that the libxl driver needs to support that feature. However you should pull lastest sources from master branch as I pushed pretty big changes in the network configuration recently.
Here is my patch:
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 0555b91..0effc59 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1047,10 +1047,18 @@ libxlMakeNic(virDomainDefPtr def, if (VIR_STRDUP(x_nic->bridge, virDomainNetGetActualBridgeName(l_nic)) < 0) return -1; - /* fallthrough */ + if (VIR_STRDUP(x_nic->script, l_nic->script) < 0) + return -1; + if (VIR_STRDUP(x_nic->ip, l_nic->data.bridge.ipaddr) < 0) + return -1; + break;
Now, domains can have multiple IPs: l_nic->data.bridge.ipaddr doesn't exist anymore, you'll need to read from l_nic->ips (array of size l_nic->nips). I hope that helps, -- Cedric
participants (3)
-
Cedric Bosdonnat
-
Jim Fehlig
-
Kim Larry