mirror of https://gitee.com/openkylin/libvirt.git
conf: use virNetDevIPInfo for guest-side <interface> config
All the same information was already there, just in slightly different places in the virDomainNetDef.
This commit is contained in:
parent
69e04044dd
commit
fbc1843d2e
|
@ -2420,27 +2420,7 @@
|
|||
<empty/>
|
||||
</element>
|
||||
</optional>
|
||||
<zeroOrMore>
|
||||
<element name="ip">
|
||||
<attribute name="address">
|
||||
<ref name="ipAddr"/>
|
||||
</attribute>
|
||||
<optional>
|
||||
<attribute name="family">
|
||||
<ref name="addr-family"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="prefix">
|
||||
<ref name="ipPrefix"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<empty/>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
<zeroOrMore>
|
||||
<ref name="route"/>
|
||||
</zeroOrMore>
|
||||
<ref name="interface-ip-info"/>
|
||||
<optional>
|
||||
<element name="script">
|
||||
<attribute name="path">
|
||||
|
|
|
@ -1740,8 +1740,6 @@ virDomainActualNetDefFree(virDomainActualNetDefPtr def)
|
|||
void
|
||||
virDomainNetDefClear(virDomainNetDefPtr def)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!def)
|
||||
return;
|
||||
|
||||
|
@ -1799,14 +1797,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
|
|||
VIR_FREE(def->ifname_guest);
|
||||
VIR_FREE(def->ifname_guest_actual);
|
||||
|
||||
for (i = 0; i < def->nips; i++)
|
||||
VIR_FREE(def->ips[i]);
|
||||
VIR_FREE(def->ips);
|
||||
|
||||
for (i = 0; i < def->nroutes; i++)
|
||||
virNetDevIPRouteFree(def->routes[i]);
|
||||
VIR_FREE(def->routes);
|
||||
|
||||
virNetDevIPInfoClear(&def->guestIP);
|
||||
virDomainDeviceInfoClear(&def->info);
|
||||
|
||||
VIR_FREE(def->filter);
|
||||
|
@ -8898,7 +8889,7 @@ virDomainNetAppendIPAddress(virDomainNetDefPtr def,
|
|||
goto error;
|
||||
ipDef->prefix = prefix;
|
||||
|
||||
if (VIR_APPEND_ELEMENT(def->ips, def->nips, ipDef) < 0)
|
||||
if (VIR_APPEND_ELEMENT(def->guestIP.ips, def->guestIP.nips, ipDef) < 0)
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
|
@ -8960,11 +8951,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||
virDomainActualNetDefPtr actual = NULL;
|
||||
xmlNodePtr oldnode = ctxt->node;
|
||||
int ret, val;
|
||||
size_t i;
|
||||
size_t nips = 0;
|
||||
virNetDevIPAddrPtr *ips = NULL;
|
||||
size_t nroutes = 0;
|
||||
virNetDevIPRoutePtr *routes = NULL;
|
||||
|
||||
if (VIR_ALLOC(def) < 0)
|
||||
return NULL;
|
||||
|
@ -9080,24 +9066,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||
localport = virXPathString("string(./local/@port)", ctxt);
|
||||
ctxt->node = tmpnode;
|
||||
}
|
||||
} else if (xmlStrEqual(cur->name, BAD_CAST "ip")) {
|
||||
virNetDevIPAddrPtr ip = NULL;
|
||||
|
||||
if (!(ip = virDomainNetIPParseXML(cur)))
|
||||
goto error;
|
||||
|
||||
if (VIR_APPEND_ELEMENT(ips, nips, ip) < 0)
|
||||
goto error;
|
||||
} else if (xmlStrEqual(cur->name, BAD_CAST "route")) {
|
||||
virNetDevIPRoutePtr route = NULL;
|
||||
if (!(route = virNetDevIPRouteParseXML(_("Domain interface"),
|
||||
cur, ctxt)))
|
||||
goto error;
|
||||
|
||||
if (VIR_APPEND_ELEMENT(routes, nroutes, route) < 0) {
|
||||
virNetDevIPRouteFree(route);
|
||||
goto error;
|
||||
}
|
||||
} else if (!ifname &&
|
||||
xmlStrEqual(cur->name, BAD_CAST "target")) {
|
||||
ifname = virXMLPropString(cur, "dev");
|
||||
|
@ -9418,12 +9386,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < nips; i++) {
|
||||
if (VIR_APPEND_ELEMENT(def->ips, def->nips, ips[i]) < 0)
|
||||
goto error;
|
||||
}
|
||||
def->nroutes = nroutes;
|
||||
def->routes = routes;
|
||||
if (virDomainNetIPInfoParseXML(_("guest interface"),
|
||||
ctxt, &def->guestIP) < 0)
|
||||
goto error;
|
||||
|
||||
if (script != NULL) {
|
||||
def->script = script;
|
||||
|
@ -9705,7 +9670,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||
VIR_FREE(addrtype);
|
||||
VIR_FREE(domain_name);
|
||||
VIR_FREE(trustGuestRxFilters);
|
||||
VIR_FREE(ips);
|
||||
VIR_FREE(vhost_path);
|
||||
VIR_FREE(localaddr);
|
||||
VIR_FREE(localport);
|
||||
|
@ -20894,9 +20858,7 @@ virDomainNetDefFormat(virBufferPtr buf,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (virDomainNetIPsFormat(buf, def->ips, def->nips) < 0)
|
||||
return -1;
|
||||
if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
|
||||
if (virDomainNetIPInfoFormat(buf, &def->guestIP) < 0)
|
||||
return -1;
|
||||
|
||||
virBufferEscapeString(buf, "<script path='%s'/>\n",
|
||||
|
|
|
@ -964,8 +964,9 @@ struct _virDomainNetDef {
|
|||
char *script;
|
||||
char *domain_name; /* backend domain name */
|
||||
char *ifname;
|
||||
char *ifname_guest;
|
||||
char *ifname_guest_actual;
|
||||
char *ifname_guest;
|
||||
virNetDevIPInfo guestIP;
|
||||
virDomainDeviceInfo info;
|
||||
char *filter;
|
||||
virNWFilterHashTablePtr filterparams;
|
||||
|
@ -973,10 +974,6 @@ struct _virDomainNetDef {
|
|||
virNetDevVlan vlan;
|
||||
int trustGuestRxFilters; /* enum virTristateBool */
|
||||
int linkstate;
|
||||
size_t nips;
|
||||
virNetDevIPAddrPtr *ips;
|
||||
size_t nroutes;
|
||||
virNetDevIPRoutePtr *routes;
|
||||
};
|
||||
|
||||
/* Used for prefix of ifname of any network name generated dynamically
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* libxl_conf.c: libxl configuration management
|
||||
*
|
||||
* Copyright (C) 2012-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2012-2014, 2016 Red Hat, Inc.
|
||||
* Copyright (c) 2011-2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
* Copyright (C) 2011 Univention GmbH.
|
||||
*
|
||||
|
@ -908,8 +908,8 @@ libxlMakeNic(virDomainDefPtr def,
|
|||
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
||||
if (VIR_STRDUP(x_nic->script, l_nic->script) < 0)
|
||||
goto cleanup;
|
||||
if (l_nic->nips > 0) {
|
||||
x_nic->ip = virSocketAddrFormat(&l_nic->ips[0]->address);
|
||||
if (l_nic->guestIP.nips > 0) {
|
||||
x_nic->ip = virSocketAddrFormat(&l_nic->guestIP.ips[0]->address);
|
||||
if (!x_nic->ip)
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -924,8 +924,8 @@ libxlMakeNic(virDomainDefPtr def,
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
if (l_nic->nips > 0) {
|
||||
x_nic->ip = virSocketAddrFormat(&l_nic->ips[0]->address);
|
||||
if (l_nic->guestIP.nips > 0) {
|
||||
x_nic->ip = virSocketAddrFormat(&l_nic->guestIP.ips[0]->address);
|
||||
if (!x_nic->ip)
|
||||
goto cleanup;
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
|||
(dev->data.net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||
dev->data.net->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
|
||||
dev->data.net->type == VIR_DOMAIN_NET_TYPE_NETWORK)) {
|
||||
if (dev->data.net->nips > 1) {
|
||||
if (dev->data.net->guestIP.nips > 1) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("multiple IP addresses not supported on device type %s"),
|
||||
virDomainNetTypeToString(dev->data.net->type));
|
||||
|
|
|
@ -512,8 +512,8 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
|
|||
if (rc < 0)
|
||||
goto error_out;
|
||||
|
||||
for (j = 0; j < netDef->nips; j++) {
|
||||
virNetDevIPAddrPtr ip = netDef->ips[j];
|
||||
for (j = 0; j < netDef->guestIP.nips; j++) {
|
||||
virNetDevIPAddrPtr ip = netDef->guestIP.ips[j];
|
||||
int prefix;
|
||||
char *ipStr = virSocketAddrFormat(&ip->address);
|
||||
|
||||
|
@ -538,7 +538,7 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
|
|||
VIR_FREE(ipStr);
|
||||
}
|
||||
|
||||
if (netDef->nips ||
|
||||
if (netDef->guestIP.nips ||
|
||||
netDef->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
|
||||
VIR_DEBUG("Enabling %s", newname);
|
||||
rc = virNetDevSetOnline(newname, true);
|
||||
|
@ -546,8 +546,8 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
|
|||
goto error_out;
|
||||
|
||||
/* Set the routes */
|
||||
for (j = 0; j < netDef->nroutes; j++) {
|
||||
virNetDevIPRoutePtr route = netDef->routes[j];
|
||||
for (j = 0; j < netDef->guestIP.nroutes; j++) {
|
||||
virNetDevIPRoutePtr route = netDef->guestIP.routes[j];
|
||||
|
||||
if (virNetDevIPRouteAdd(newname,
|
||||
virNetDevIPRouteGetAddress(route),
|
||||
|
|
|
@ -522,19 +522,19 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data)
|
|||
data->name)))
|
||||
goto error;
|
||||
|
||||
net->ips = data->ips;
|
||||
net->nips = data->nips;
|
||||
net->guestIP.ips = data->ips;
|
||||
net->guestIP.nips = data->nips;
|
||||
|
||||
if (data->gateway_ipv4 &&
|
||||
lxcAddNetworkRouteDefinition(data->gateway_ipv4, AF_INET,
|
||||
&net->routes,
|
||||
&net->nroutes) < 0)
|
||||
&net->guestIP.routes,
|
||||
&net->guestIP.nroutes) < 0)
|
||||
goto error;
|
||||
|
||||
if (data->gateway_ipv6 &&
|
||||
lxcAddNetworkRouteDefinition(data->gateway_ipv6, AF_INET6,
|
||||
&net->routes,
|
||||
&net->nroutes) < 0)
|
||||
&net->guestIP.routes,
|
||||
&net->guestIP.nroutes) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_EXPAND_N(data->def->nets, data->def->nnets, 1) < 0)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* openvz_driver.c: core driver methods for managing OpenVZ VEs
|
||||
*
|
||||
* Copyright (C) 2010-2015 Red Hat, Inc.
|
||||
* Copyright (C) 2010-2016 Red Hat, Inc.
|
||||
* Copyright (C) 2006, 2007 Binary Karma
|
||||
* Copyright (C) 2006 Shuveb Hussain
|
||||
* Copyright (C) 2007 Anoop Joe Cyriac
|
||||
|
@ -856,7 +856,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
|
|||
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||
(net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
||||
net->nips == 0)) {
|
||||
net->guestIP.nips == 0)) {
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
int veid = openvzGetVEID(vpsid);
|
||||
|
||||
|
@ -906,12 +906,12 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
|
|||
virCommandAddArg(cmd, "--netif_add");
|
||||
virCommandAddArgBuffer(cmd, &buf);
|
||||
} else if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
||||
net->nips > 0) {
|
||||
net->guestIP.nips > 0) {
|
||||
size_t i;
|
||||
|
||||
/* --ipadd ip */
|
||||
for (i = 0; i < net->nips; i++) {
|
||||
char *ipStr = virSocketAddrFormat(&net->ips[i]->address);
|
||||
for (i = 0; i < net->guestIP.nips; i++) {
|
||||
char *ipStr = virSocketAddrFormat(&net->guestIP.ips[i]->address);
|
||||
if (!ipStr)
|
||||
goto cleanup;
|
||||
virCommandAddArgList(cmd, "--ipadd", ipStr, NULL);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* uml_conf.c: UML driver configuration
|
||||
*
|
||||
* Copyright (C) 2006-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2014, 2016 Red Hat, Inc.
|
||||
* Copyright (C) 2006 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
|
@ -173,7 +173,7 @@ umlBuildCommandLineNet(virConnectPtr conn,
|
|||
virBufferAddLit(&buf, "tuntap,");
|
||||
if (def->ifname)
|
||||
virBufferAdd(&buf, def->ifname, -1);
|
||||
if (def->nips > 0) {
|
||||
if (def->guestIP.nips > 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("IP address not supported for ethernet interface"));
|
||||
goto error;
|
||||
|
|
|
@ -1313,11 +1313,11 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
|
|||
} else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||
VIR_DEBUG("NIC(%zu): brname: %s", i, def->nets[i]->data.bridge.brname);
|
||||
VIR_DEBUG("NIC(%zu): script: %s", i, def->nets[i]->script);
|
||||
if (def->nets[i]->nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&def->nets[i]->ips[0]->address);
|
||||
if (def->nets[i]->guestIP.nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&def->nets[i]->guestIP.ips[0]->address);
|
||||
VIR_DEBUG("NIC(%zu): ipaddr: %s", i, ipStr);
|
||||
VIR_FREE(ipStr);
|
||||
} else if (def->nets[i]->nips > 1) {
|
||||
} else if (def->nets[i]->guestIP.nips > 1) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Driver does not support setting multiple IP addresses"));
|
||||
return -1;
|
||||
|
|
|
@ -2654,7 +2654,7 @@ static int prlsdkCheckNetUnsupportedParams(virDomainNetDefPtr net)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (net->ifname_guest) {
|
||||
if (net->guestIf.name) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Setting guest interface name is not "
|
||||
"supported by vz driver."));
|
||||
|
|
|
@ -1153,11 +1153,11 @@ xenFormatNet(virConnectPtr conn,
|
|||
switch (net->type) {
|
||||
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
||||
virBufferAsprintf(&buf, ",bridge=%s", net->data.bridge.brname);
|
||||
if (net->nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&net->ips[0]->address);
|
||||
if (net->guestIP.nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&net->guestIP.ips[0]->address);
|
||||
virBufferAsprintf(&buf, ",ip=%s", ipStr);
|
||||
VIR_FREE(ipStr);
|
||||
} else if (net->nips > 1) {
|
||||
} else if (net->guestIP.nips > 1) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Driver does not support setting multiple IP addresses"));
|
||||
goto cleanup;
|
||||
|
@ -1168,11 +1168,11 @@ xenFormatNet(virConnectPtr conn,
|
|||
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
||||
if (net->script)
|
||||
virBufferAsprintf(&buf, ",script=%s", net->script);
|
||||
if (net->nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&net->ips[0]->address);
|
||||
if (net->guestIP.nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&net->guestIP.ips[0]->address);
|
||||
virBufferAsprintf(&buf, ",ip=%s", ipStr);
|
||||
VIR_FREE(ipStr);
|
||||
} else if (net->nips > 1) {
|
||||
} else if (net->guestIP.nips > 1) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Driver does not support setting multiple IP addresses"));
|
||||
goto cleanup;
|
||||
|
|
|
@ -1875,11 +1875,11 @@ xenFormatSxprNet(virConnectPtr conn,
|
|||
script = def->script;
|
||||
|
||||
virBufferEscapeSexpr(buf, "(script '%s')", script);
|
||||
if (def->nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&def->ips[0]->address);
|
||||
if (def->guestIP.nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&def->guestIP.ips[0]->address);
|
||||
virBufferEscapeSexpr(buf, "(ip '%s')", ipStr);
|
||||
VIR_FREE(ipStr);
|
||||
} else if (def->nips > 1) {
|
||||
} else if (def->guestIP.nips > 1) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Driver does not support setting multiple IP addresses"));
|
||||
return -1;
|
||||
|
@ -1916,11 +1916,11 @@ xenFormatSxprNet(virConnectPtr conn,
|
|||
if (def->script)
|
||||
virBufferEscapeSexpr(buf, "(script '%s')",
|
||||
def->script);
|
||||
if (def->nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&def->ips[0]->address);
|
||||
if (def->guestIP.nips == 1) {
|
||||
char *ipStr = virSocketAddrFormat(&def->guestIP.ips[0]->address);
|
||||
virBufferEscapeSexpr(buf, "(ip '%s')", ipStr);
|
||||
VIR_FREE(ipStr);
|
||||
} else if (def->nips > 1) {
|
||||
} else if (def->guestIP.nips > 1) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Driver does not support setting multiple IP addresses"));
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue