提交 6e244c65 编写于 作者: V Vasiliy Tolstov 提交者: Daniel P. Berrange

qemu domain allow to set ip address, peer address and route

Signed-off-by: NVasiliy Tolstov <v.tolstov@selfip.ru>
上级 afee47d0
......@@ -438,6 +438,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
bool template_ifname = false;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
const char *tunpath = "/dev/net/tun";
size_t i;
if (net->backend.tap) {
tunpath = net->backend.tap;
......@@ -474,6 +475,45 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
if (virNetDevSetMAC(net->ifname, &tapmac) < 0)
goto cleanup;
for (i = 0; i < net->nips; i++) {
virDomainNetIpDefPtr ip = net->ips[i];
unsigned int prefix = (ip->prefix > 0) ? ip->prefix :
VIR_SOCKET_ADDR_DEFAULT_PREFIX;
char *ipStr = virSocketAddrFormat(&ip->address);
VIR_DEBUG("Adding IP address '%s/%u' to '%s'",
ipStr, ip->prefix, net->ifname);
if (virNetDevSetIPAddress(net->ifname, &ip->address, &ip->peer, prefix) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Failed to set IP address '%s' on %s"),
ipStr, net->ifname);
VIR_FREE(ipStr);
goto cleanup;
}
VIR_FREE(ipStr);
}
if (net->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP ||
net->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT) {
if (virNetDevSetOnline(net->ifname, true) < 0)
goto cleanup;
/* Set the routes */
for (i = 0; i < net->nroutes; i++) {
virNetworkRouteDefPtr route = net->routes[i];
if (virNetDevAddRoute(net->ifname,
virNetworkRouteDefGetAddress(route),
virNetworkRouteDefGetPrefix(route),
virNetworkRouteDefGetGateway(route),
virNetworkRouteDefGetMetric(route)) < 0) {
goto cleanup;
}
}
}
if (net->script &&
qemuExecuteEthernetScript(net->ifname, net->script) < 0)
goto cleanup;
......@@ -493,7 +533,6 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
cleanup:
if (ret < 0) {
size_t i;
for (i = 0; i < tapfdSize && tapfd[i] >= 0; i++)
VIR_FORCE_CLOSE(tapfd[i]);
if (template_ifname)
......
......@@ -124,6 +124,13 @@ virNetDevSetMAC(const char *ifname ATTRIBUTE_UNUSED,
return 0;
}
int
virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUSED,
bool online ATTRIBUTE_UNUSED)
{
return 0;
}
int
virCommandRun(virCommandPtr cmd ATTRIBUTE_UNUSED,
int *exitstatus)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册