2009-07-15 17:34:04 +00:00
|
|
|
/*
|
|
|
|
* interface_conf.c: interfaces XML handling
|
|
|
|
*
|
2015-05-27 17:30:50 +00:00
|
|
|
* Copyright (C) 2006-2010, 2013-2015 Red Hat, Inc.
|
2009-07-15 17:34:04 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-07-15 17:34:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2009-07-15 17:34:04 +00:00
|
|
|
#include "datatypes.h"
|
|
|
|
|
|
|
|
#include "interface_conf.h"
|
|
|
|
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:13:21 +00:00
|
|
|
#include "virxml.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2020-03-22 16:39:50 +00:00
|
|
|
#include "virstring.h"
|
2009-07-15 17:34:04 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_INTERFACE
|
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virInterface,
|
|
|
|
VIR_INTERFACE_TYPE_LAST,
|
2019-01-20 16:30:15 +00:00
|
|
|
"ethernet", "bridge", "bond", "vlan",
|
|
|
|
);
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2010-01-02 01:40:25 +00:00
|
|
|
static virInterfaceDefPtr
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType);
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2010-01-02 01:40:25 +00:00
|
|
|
static int
|
2014-06-19 09:58:56 +00:00
|
|
|
virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def,
|
|
|
|
virInterfaceType parentIfType);
|
2010-01-02 01:40:25 +00:00
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
static void
|
|
|
|
virInterfaceIPDefFree(virInterfaceIPDefPtr def)
|
2014-03-18 08:15:05 +00:00
|
|
|
{
|
2009-10-28 13:13:18 +00:00
|
|
|
if (def == NULL)
|
|
|
|
return;
|
|
|
|
VIR_FREE(def->address);
|
2009-11-03 19:02:52 +00:00
|
|
|
VIR_FREE(def);
|
2009-10-28 13:13:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
virInterfaceProtocolDefFree(virInterfaceProtocolDefPtr def)
|
2014-03-18 08:15:05 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-10-28 13:13:18 +00:00
|
|
|
|
|
|
|
if (def == NULL)
|
|
|
|
return;
|
2014-11-13 14:23:27 +00:00
|
|
|
for (i = 0; i < def->nips; i++)
|
2016-06-08 16:48:50 +00:00
|
|
|
virInterfaceIPDefFree(def->ips[i]);
|
2009-10-28 13:13:18 +00:00
|
|
|
VIR_FREE(def->ips);
|
|
|
|
VIR_FREE(def->family);
|
|
|
|
VIR_FREE(def->gateway);
|
|
|
|
VIR_FREE(def);
|
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
virInterfaceDefFree(virInterfaceDefPtr def)
|
2009-07-15 17:34:04 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
|
|
|
int pp;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
|
|
|
if (def == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(def->name);
|
|
|
|
VIR_FREE(def->mac);
|
|
|
|
|
|
|
|
switch (def->type) {
|
|
|
|
case VIR_INTERFACE_TYPE_BRIDGE:
|
2010-08-03 14:31:59 +00:00
|
|
|
VIR_FREE(def->data.bridge.delay);
|
2013-05-24 16:58:25 +00:00
|
|
|
for (i = 0; i < def->data.bridge.nbItf; i++) {
|
2010-05-17 20:38:59 +00:00
|
|
|
if (def->data.bridge.itf[i] == NULL)
|
2009-07-15 17:34:04 +00:00
|
|
|
break; /* to cope with half parsed data on errors */
|
2010-05-17 20:38:59 +00:00
|
|
|
virInterfaceDefFree(def->data.bridge.itf[i]);
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(def->data.bridge.itf);
|
|
|
|
break;
|
|
|
|
case VIR_INTERFACE_TYPE_BOND:
|
|
|
|
VIR_FREE(def->data.bond.target);
|
2013-05-24 16:58:25 +00:00
|
|
|
for (i = 0; i < def->data.bond.nbItf; i++) {
|
2010-05-17 20:38:59 +00:00
|
|
|
if (def->data.bond.itf[i] == NULL)
|
2009-07-15 17:34:04 +00:00
|
|
|
break; /* to cope with half parsed data on errors */
|
2010-05-17 20:38:59 +00:00
|
|
|
virInterfaceDefFree(def->data.bond.itf[i]);
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(def->data.bond.itf);
|
|
|
|
break;
|
|
|
|
case VIR_INTERFACE_TYPE_VLAN:
|
|
|
|
VIR_FREE(def->data.vlan.tag);
|
2014-10-01 14:07:46 +00:00
|
|
|
VIR_FREE(def->data.vlan.dev_name);
|
2009-07-15 17:34:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-28 13:13:18 +00:00
|
|
|
/* free all protos */
|
2014-11-13 14:23:27 +00:00
|
|
|
for (pp = 0; pp < def->nprotos; pp++)
|
2009-10-28 13:13:18 +00:00
|
|
|
virInterfaceProtocolDefFree(def->protos[pp]);
|
|
|
|
VIR_FREE(def->protos);
|
2009-07-15 17:34:04 +00:00
|
|
|
VIR_FREE(def);
|
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseName(virInterfaceDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
char *tmp;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./@name)", ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (tmp == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("interface has no name"));
|
2012-03-22 11:33:35 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
def->name = tmp;
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2010-01-02 01:40:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2010-01-02 01:40:25 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseMtu(virInterfaceDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2010-01-02 01:40:25 +00:00
|
|
|
unsigned long mtu;
|
|
|
|
int ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathULong("string(./mtu/@size)", ctxt, &mtu);
|
2009-07-15 17:34:04 +00:00
|
|
|
if ((ret == -2) || ((ret == 0) && (mtu > 100000))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("interface mtu value is improper"));
|
2012-03-22 11:33:35 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
} else if (ret == 0) {
|
|
|
|
def->mtu = (unsigned int) mtu;
|
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseStartMode(virInterfaceDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
char *tmp;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./start/@mode)", ctxt);
|
2014-09-03 17:29:38 +00:00
|
|
|
if (tmp == NULL) {
|
2009-10-28 08:55:33 +00:00
|
|
|
def->startmode = VIR_INTERFACE_START_UNSPECIFIED;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "onboot")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
def->startmode = VIR_INTERFACE_START_ONBOOT;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "hotplug")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
def->startmode = VIR_INTERFACE_START_HOTPLUG;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "none")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
def->startmode = VIR_INTERFACE_START_NONE;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unknown interface startmode %s"), tmp);
|
2009-07-15 17:34:04 +00:00
|
|
|
VIR_FREE(tmp);
|
2012-03-22 11:33:35 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2014-03-18 08:15:05 +00:00
|
|
|
virInterfaceDefParseBondMode(xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
char *tmp;
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./@mode)", ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (tmp == NULL)
|
2012-03-22 11:33:35 +00:00
|
|
|
return VIR_INTERFACE_BOND_NONE;
|
2014-09-03 17:29:38 +00:00
|
|
|
if (STREQ(tmp, "balance-rr")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_BALRR;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "active-backup")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_ABACKUP;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "balance-xor")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_BALXOR;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "broadcast")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_BCAST;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "802.3ad")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_8023AD;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "balance-tlb")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_BALTLB;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "balance-alb")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_BALALB;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unknown bonding mode %s"), tmp);
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2014-03-18 08:15:05 +00:00
|
|
|
virInterfaceDefParseBondMiiCarrier(xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
char *tmp;
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./miimon/@carrier)", ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (tmp == NULL)
|
2012-03-22 11:33:35 +00:00
|
|
|
return VIR_INTERFACE_BOND_MII_NONE;
|
2014-09-03 17:29:38 +00:00
|
|
|
if (STREQ(tmp, "ioctl")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_MII_IOCTL;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "netif")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_MII_NETIF;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unknown mii bonding carrier %s"), tmp);
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2014-03-18 08:15:05 +00:00
|
|
|
virInterfaceDefParseBondArpValid(xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
char *tmp;
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./arpmon/@validate)", ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (tmp == NULL)
|
2012-03-22 11:33:35 +00:00
|
|
|
return VIR_INTERFACE_BOND_ARP_NONE;
|
2014-09-03 17:29:38 +00:00
|
|
|
if (STREQ(tmp, "active")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_ARP_ACTIVE;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "backup")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_ARP_BACKUP;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (STREQ(tmp, "all")) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = VIR_INTERFACE_BOND_ARP_ALL;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unknown arp bonding validate %s"), tmp);
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlNodePtr dhcp, xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2020-06-02 20:06:41 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
char *tmp;
|
|
|
|
int ret = 0;
|
|
|
|
|
2009-10-28 13:13:18 +00:00
|
|
|
def->dhcp = 1;
|
2009-07-15 17:34:04 +00:00
|
|
|
ctxt->node = dhcp;
|
2020-03-22 16:39:50 +00:00
|
|
|
def->peerdns = -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
/* Not much to do in the current version */
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./@peerdns)", ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (tmp) {
|
2020-03-22 16:39:50 +00:00
|
|
|
bool state = false;
|
|
|
|
if (virStringParseYesNo(tmp, &state) < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unknown dhcp peerdns value %s"), tmp);
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = -1;
|
2020-03-22 16:39:50 +00:00
|
|
|
} else {
|
|
|
|
def->peerdns = state ? 1 : 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
2014-09-03 17:29:38 +00:00
|
|
|
}
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2016-06-08 16:48:50 +00:00
|
|
|
virInterfaceDefParseIP(virInterfaceIPDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
int ret = 0;
|
|
|
|
char *tmp;
|
|
|
|
long l;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./@address)", ctxt);
|
2009-10-28 13:13:18 +00:00
|
|
|
def->address = tmp;
|
2009-07-15 17:34:04 +00:00
|
|
|
if (tmp != NULL) {
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathLong("string(./@prefix)", ctxt, &l);
|
2014-09-03 17:29:38 +00:00
|
|
|
if (ret == 0) {
|
2009-10-28 13:13:18 +00:00
|
|
|
def->prefix = (int) l;
|
2014-09-03 17:29:38 +00:00
|
|
|
} else if (ret == -2) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("Invalid ip address prefix value"));
|
2012-03-22 11:33:35 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-10-28 13:13:18 +00:00
|
|
|
xmlNodePtr dhcp;
|
|
|
|
xmlNodePtr *ipNodes = NULL;
|
2016-06-08 16:48:50 +00:00
|
|
|
int nipNodes, ret = -1;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-10-28 13:13:18 +00:00
|
|
|
char *tmp;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./route[1]/@gateway)", ctxt);
|
2009-10-28 13:13:18 +00:00
|
|
|
def->gateway = tmp;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
dhcp = virXPathNode("./dhcp", ctxt);
|
2009-11-03 20:01:32 +00:00
|
|
|
if (dhcp != NULL) {
|
2013-09-25 08:33:12 +00:00
|
|
|
if (virInterfaceDefParseDhcp(def, dhcp, ctxt) < 0)
|
|
|
|
return -1;
|
2009-11-03 20:01:32 +00:00
|
|
|
}
|
2009-10-28 13:13:18 +00:00
|
|
|
|
2016-06-08 16:48:50 +00:00
|
|
|
nipNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
|
|
|
|
if (nipNodes < 0)
|
2010-02-02 19:54:01 +00:00
|
|
|
return -1;
|
2009-10-28 13:13:18 +00:00
|
|
|
if (ipNodes == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2016-06-08 16:48:50 +00:00
|
|
|
if (VIR_ALLOC_N(def->ips, nipNodes) < 0)
|
2009-10-28 13:13:18 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
def->nips = 0;
|
2016-06-08 16:48:50 +00:00
|
|
|
for (i = 0; i < nipNodes; i++) {
|
2009-10-28 13:13:18 +00:00
|
|
|
|
2016-06-08 16:48:50 +00:00
|
|
|
virInterfaceIPDefPtr ip;
|
2009-10-28 09:40:54 +00:00
|
|
|
|
2013-07-04 10:02:00 +00:00
|
|
|
if (VIR_ALLOC(ip) < 0)
|
2009-10-28 13:13:18 +00:00
|
|
|
goto error;
|
|
|
|
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
ctxt->node = ipNodes[i];
|
2016-06-08 16:48:50 +00:00
|
|
|
if (virInterfaceDefParseIP(ip, ctxt) < 0) {
|
|
|
|
virInterfaceIPDefFree(ip);
|
2009-10-28 13:13:18 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
def->ips[def->nips++] = ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
error:
|
2009-10-28 13:13:18 +00:00
|
|
|
VIR_FREE(ipNodes);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-10-28 13:13:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-10-28 13:13:18 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-10-28 13:13:18 +00:00
|
|
|
xmlNodePtr dhcp, autoconf;
|
|
|
|
xmlNodePtr *ipNodes = NULL;
|
2016-06-08 16:48:50 +00:00
|
|
|
int nipNodes, ret = -1;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-10-28 13:13:18 +00:00
|
|
|
char *tmp;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./route[1]/@gateway)", ctxt);
|
2009-10-28 13:13:18 +00:00
|
|
|
def->gateway = tmp;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
autoconf = virXPathNode("./autoconf", ctxt);
|
2009-10-28 13:13:18 +00:00
|
|
|
if (autoconf != NULL)
|
|
|
|
def->autoconf = 1;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
dhcp = virXPathNode("./dhcp", ctxt);
|
2009-11-03 20:01:32 +00:00
|
|
|
if (dhcp != NULL) {
|
2013-09-25 08:33:12 +00:00
|
|
|
if (virInterfaceDefParseDhcp(def, dhcp, ctxt) < 0)
|
|
|
|
return -1;
|
2009-11-03 20:01:32 +00:00
|
|
|
}
|
2009-10-28 09:40:54 +00:00
|
|
|
|
2016-06-08 16:48:50 +00:00
|
|
|
nipNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
|
|
|
|
if (nipNodes < 0)
|
2010-02-02 19:54:01 +00:00
|
|
|
return -1;
|
2009-10-28 13:13:18 +00:00
|
|
|
if (ipNodes == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2016-06-08 16:48:50 +00:00
|
|
|
if (VIR_ALLOC_N(def->ips, nipNodes) < 0)
|
2009-10-28 13:13:18 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
def->nips = 0;
|
2016-06-08 16:48:50 +00:00
|
|
|
for (i = 0; i < nipNodes; i++) {
|
2009-10-28 13:13:18 +00:00
|
|
|
|
2016-06-08 16:48:50 +00:00
|
|
|
virInterfaceIPDefPtr ip;
|
2009-10-28 13:13:18 +00:00
|
|
|
|
2013-07-04 10:02:00 +00:00
|
|
|
if (VIR_ALLOC(ip) < 0)
|
2009-10-28 13:13:18 +00:00
|
|
|
goto error;
|
|
|
|
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
ctxt->node = ipNodes[i];
|
2016-06-08 16:48:50 +00:00
|
|
|
if (virInterfaceDefParseIP(ip, ctxt) < 0) {
|
|
|
|
virInterfaceIPDefFree(ip);
|
2009-10-28 13:13:18 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
def->ips[def->nips++] = ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
error:
|
2009-10-28 13:13:18 +00:00
|
|
|
VIR_FREE(ipNodes);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseIfAdressing(virInterfaceDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2020-06-02 20:06:41 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
2009-10-28 13:13:18 +00:00
|
|
|
xmlNodePtr *protoNodes = NULL;
|
|
|
|
int nProtoNodes, pp, ret = -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
char *tmp;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
nProtoNodes = virXPathNodeSet("./protocol", ctxt, &protoNodes);
|
2011-05-12 19:45:22 +00:00
|
|
|
if (nProtoNodes < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (nProtoNodes == 0) {
|
2009-10-28 13:13:18 +00:00
|
|
|
/* no protocols is an acceptable outcome */
|
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
2009-10-28 13:13:18 +00:00
|
|
|
|
2013-07-04 10:02:00 +00:00
|
|
|
if (VIR_ALLOC_N(def->protos, nProtoNodes) < 0)
|
2009-10-28 13:13:18 +00:00
|
|
|
goto error;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2009-10-28 13:13:18 +00:00
|
|
|
def->nprotos = 0;
|
|
|
|
for (pp = 0; pp < nProtoNodes; pp++) {
|
|
|
|
|
|
|
|
virInterfaceProtocolDefPtr proto;
|
|
|
|
|
2013-07-04 10:02:00 +00:00
|
|
|
if (VIR_ALLOC(proto) < 0)
|
2009-10-28 13:13:18 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
ctxt->node = protoNodes[pp];
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./@family)", ctxt);
|
2009-10-28 13:13:18 +00:00
|
|
|
if (tmp == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("protocol misses the family attribute"));
|
2009-10-28 13:13:18 +00:00
|
|
|
virInterfaceProtocolDefFree(proto);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
proto->family = tmp;
|
|
|
|
if (STREQ(tmp, "ipv4")) {
|
2010-02-10 12:28:05 +00:00
|
|
|
ret = virInterfaceDefParseProtoIPv4(proto, ctxt);
|
2009-10-28 13:13:18 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
virInterfaceProtocolDefFree(proto);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else if (STREQ(tmp, "ipv6")) {
|
2010-02-10 12:28:05 +00:00
|
|
|
ret = virInterfaceDefParseProtoIPv6(proto, ctxt);
|
2009-10-28 13:13:18 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
virInterfaceProtocolDefFree(proto);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unsupported protocol family '%s'"), tmp);
|
2009-10-28 13:13:18 +00:00
|
|
|
virInterfaceProtocolDefFree(proto);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
def->protos[def->nprotos++] = proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
error:
|
2009-10-28 13:13:18 +00:00
|
|
|
VIR_FREE(protoNodes);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseBridge(virInterfaceDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
xmlNodePtr *interfaces = NULL;
|
|
|
|
xmlNodePtr bridge;
|
2010-01-02 01:40:25 +00:00
|
|
|
virInterfaceDefPtr itf;
|
2014-06-19 09:47:26 +00:00
|
|
|
char *tmp = NULL;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int nbItf;
|
|
|
|
size_t i;
|
2009-07-15 17:34:04 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
bridge = ctxt->node;
|
2014-06-19 09:47:26 +00:00
|
|
|
def->data.bridge.stp = -1;
|
|
|
|
if ((tmp = virXMLPropString(bridge, "stp"))) {
|
|
|
|
if (STREQ(tmp, "on")) {
|
|
|
|
def->data.bridge.stp = 1;
|
|
|
|
} else if (STREQ(tmp, "off")) {
|
|
|
|
def->data.bridge.stp = 0;
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("bridge interface stp should be on or off got %s"),
|
|
|
|
tmp);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
def->data.bridge.delay = virXMLPropString(bridge, "delay");
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
nbItf = virXPathNodeSet("./interface", ctxt, &interfaces);
|
2010-01-02 01:40:24 +00:00
|
|
|
if (nbItf < 0) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = -1;
|
|
|
|
goto error;
|
|
|
|
}
|
2010-01-02 01:40:24 +00:00
|
|
|
if (nbItf > 0) {
|
|
|
|
if (VIR_ALLOC_N(def->data.bridge.itf, nbItf) < 0) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = -1;
|
|
|
|
goto error;
|
|
|
|
}
|
2010-01-02 01:40:24 +00:00
|
|
|
def->data.bridge.nbItf = nbItf;
|
|
|
|
|
2013-05-24 16:58:25 +00:00
|
|
|
for (i = 0; i < nbItf; i++) {
|
2010-01-02 01:40:24 +00:00
|
|
|
ctxt->node = interfaces[i];
|
2010-02-10 12:28:05 +00:00
|
|
|
itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BRIDGE);
|
2010-01-02 01:40:24 +00:00
|
|
|
if (itf == NULL) {
|
|
|
|
ret = -1;
|
|
|
|
def->data.bridge.nbItf = i;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
def->data.bridge.itf[i] = itf;
|
|
|
|
}
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
error:
|
2014-06-19 09:47:26 +00:00
|
|
|
VIR_FREE(tmp);
|
2009-07-15 17:34:04 +00:00
|
|
|
VIR_FREE(interfaces);
|
|
|
|
ctxt->node = bridge;
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseBondItfs(virInterfaceDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
xmlNodePtr *interfaces = NULL;
|
2020-06-02 20:06:41 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
2010-01-02 01:40:25 +00:00
|
|
|
virInterfaceDefPtr itf;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int nbItf;
|
|
|
|
size_t i;
|
2015-05-27 17:30:50 +00:00
|
|
|
int ret = -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
nbItf = virXPathNodeSet("./interface", ctxt, &interfaces);
|
2015-05-27 17:30:50 +00:00
|
|
|
if (nbItf < 0)
|
|
|
|
goto cleanup;
|
2011-05-12 19:45:22 +00:00
|
|
|
|
|
|
|
if (nbItf == 0) {
|
2015-05-27 17:30:50 +00:00
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
2011-05-12 19:45:22 +00:00
|
|
|
|
2015-05-27 17:30:50 +00:00
|
|
|
if (VIR_ALLOC_N(def->data.bond.itf, nbItf) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
def->data.bond.nbItf = nbItf;
|
|
|
|
|
2013-05-24 16:58:25 +00:00
|
|
|
for (i = 0; i < nbItf; i++) {
|
2009-07-15 17:34:04 +00:00
|
|
|
ctxt->node = interfaces[i];
|
2010-02-10 12:28:05 +00:00
|
|
|
itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BOND);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (itf == NULL) {
|
|
|
|
def->data.bond.nbItf = i;
|
2015-05-27 17:30:50 +00:00
|
|
|
goto cleanup;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
def->data.bond.itf[i] = itf;
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:30:50 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-07-15 17:34:04 +00:00
|
|
|
VIR_FREE(interfaces);
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseBond(virInterfaceDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2013-03-21 21:44:11 +00:00
|
|
|
int res;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
def->data.bond.mode = virInterfaceDefParseBondMode(ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.bond.mode < 0)
|
2013-03-21 21:44:11 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2013-03-21 21:44:11 +00:00
|
|
|
if (virInterfaceDefParseBondItfs(def, ctxt) != 0)
|
|
|
|
return -1;
|
2009-11-03 19:15:38 +00:00
|
|
|
|
2010-03-05 15:18:47 +00:00
|
|
|
if (virXPathNode("./miimon[1]", ctxt) != NULL) {
|
2009-07-15 17:34:04 +00:00
|
|
|
def->data.bond.monit = VIR_INTERFACE_BOND_MONIT_MII;
|
|
|
|
|
2013-03-21 21:44:11 +00:00
|
|
|
res = virXPathInt("string(./miimon/@freq)", ctxt,
|
|
|
|
&def->data.bond.frequency);
|
|
|
|
if ((res == -2) || (res == -1)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("bond interface miimon freq missing or invalid"));
|
2013-03-21 21:44:11 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 21:44:11 +00:00
|
|
|
res = virXPathInt("string(./miimon/@downdelay)", ctxt,
|
|
|
|
&def->data.bond.downdelay);
|
|
|
|
if (res == -2) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("bond interface miimon downdelay invalid"));
|
2013-03-21 21:44:11 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 21:44:11 +00:00
|
|
|
res = virXPathInt("string(./miimon/@updelay)", ctxt,
|
|
|
|
&def->data.bond.updelay);
|
|
|
|
if (res == -2) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("bond interface miimon updelay invalid"));
|
2013-03-21 21:44:11 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
def->data.bond.carrier = virInterfaceDefParseBondMiiCarrier(ctxt);
|
2013-03-21 21:44:11 +00:00
|
|
|
if (def->data.bond.carrier < 0)
|
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2010-03-05 15:18:47 +00:00
|
|
|
} else if (virXPathNode("./arpmon[1]", ctxt) != NULL) {
|
2009-07-15 17:34:04 +00:00
|
|
|
|
|
|
|
def->data.bond.monit = VIR_INTERFACE_BOND_MONIT_ARP;
|
|
|
|
|
2013-03-21 21:44:11 +00:00
|
|
|
res = virXPathInt("string(./arpmon/@interval)", ctxt,
|
|
|
|
&def->data.bond.interval);
|
|
|
|
if ((res == -2) || (res == -1)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("bond interface arpmon interval missing or invalid"));
|
2013-03-21 21:44:11 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def->data.bond.target =
|
2010-02-04 21:52:34 +00:00
|
|
|
virXPathString("string(./arpmon/@target)", ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.bond.target == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("bond interface arpmon target missing"));
|
2013-03-21 21:44:11 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 12:28:05 +00:00
|
|
|
def->data.bond.validate = virInterfaceDefParseBondArpValid(ctxt);
|
2013-03-21 21:44:11 +00:00
|
|
|
if (def->data.bond.validate < 0)
|
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
2013-03-21 21:44:11 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceDefParseVlan(virInterfaceDefPtr def,
|
2014-03-18 08:15:05 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2010-02-04 21:52:34 +00:00
|
|
|
def->data.vlan.tag = virXPathString("string(./@tag)", ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.vlan.tag == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("vlan interface misses the tag attribute"));
|
2012-03-22 11:33:35 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 14:07:46 +00:00
|
|
|
def->data.vlan.dev_name =
|
2010-02-04 21:52:34 +00:00
|
|
|
virXPathString("string(./interface/@name)", ctxt);
|
2014-10-01 14:07:46 +00:00
|
|
|
if (def->data.vlan.dev_name == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("vlan interface misses name attribute"));
|
2012-03-22 11:33:35 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static virInterfaceDefPtr
|
2017-03-02 16:44:11 +00:00
|
|
|
virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
|
|
|
|
int parentIfType)
|
2014-03-18 08:15:05 +00:00
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
virInterfaceDefPtr def;
|
|
|
|
int type;
|
|
|
|
char *tmp;
|
2020-06-02 20:06:41 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
2014-06-13 14:07:05 +00:00
|
|
|
xmlNodePtr lnk;
|
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
|
|
|
|
/* check @type */
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./@type)", ctxt);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (tmp == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("interface misses the type attribute"));
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
type = virInterfaceTypeFromString(tmp);
|
|
|
|
if (type == -1) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2012-07-18 10:50:44 +00:00
|
|
|
_("unknown interface type %s"), tmp);
|
2009-07-15 17:34:04 +00:00
|
|
|
VIR_FREE(tmp);
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
2013-07-04 10:02:00 +00:00
|
|
|
if (VIR_ALLOC(def) < 0)
|
2009-07-15 17:34:04 +00:00
|
|
|
return NULL;
|
2010-01-02 01:40:25 +00:00
|
|
|
|
|
|
|
if (((parentIfType == VIR_INTERFACE_TYPE_BOND)
|
|
|
|
&& (type != VIR_INTERFACE_TYPE_ETHERNET))
|
|
|
|
|| ((parentIfType == VIR_INTERFACE_TYPE_BRIDGE)
|
|
|
|
&& (type != VIR_INTERFACE_TYPE_ETHERNET)
|
|
|
|
&& (type != VIR_INTERFACE_TYPE_BOND)
|
|
|
|
&& (type != VIR_INTERFACE_TYPE_VLAN))
|
|
|
|
|| (parentIfType == VIR_INTERFACE_TYPE_ETHERNET)
|
|
|
|
|| (parentIfType == VIR_INTERFACE_TYPE_VLAN))
|
|
|
|
{
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("interface has unsupported type '%s'"),
|
|
|
|
virInterfaceTypeToString(type));
|
2010-01-02 01:40:25 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2009-07-15 17:34:04 +00:00
|
|
|
def->type = type;
|
2014-06-13 14:07:05 +00:00
|
|
|
|
2014-06-19 09:51:38 +00:00
|
|
|
if (virInterfaceDefParseName(def, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
|
|
|
|
/* only recognize these in toplevel bond interfaces */
|
|
|
|
if (virInterfaceDefParseStartMode(def, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
if (virInterfaceDefParseMtu(def, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
if (virInterfaceDefParseIfAdressing(def, ctxt) < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-06-13 14:07:05 +00:00
|
|
|
if (type != VIR_INTERFACE_TYPE_BRIDGE) {
|
|
|
|
/* link status makes no sense for a bridge */
|
|
|
|
lnk = virXPathNode("./link", ctxt);
|
|
|
|
if (lnk && virInterfaceLinkParseXML(lnk, &def->lnk) < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
switch (type) {
|
2014-06-19 09:51:38 +00:00
|
|
|
case VIR_INTERFACE_TYPE_ETHERNET:
|
|
|
|
if ((tmp = virXPathString("string(./mac/@address)", ctxt)))
|
2009-07-15 17:34:04 +00:00
|
|
|
def->mac = tmp;
|
|
|
|
break;
|
|
|
|
case VIR_INTERFACE_TYPE_BRIDGE: {
|
|
|
|
xmlNodePtr bridge;
|
|
|
|
|
2014-06-19 09:51:38 +00:00
|
|
|
if (!(bridge = virXPathNode("./bridge[1]", ctxt))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("bridge interface misses the bridge element"));
|
2009-07-15 17:34:04 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ctxt->node = bridge;
|
2012-06-14 17:20:17 +00:00
|
|
|
if (virInterfaceDefParseBridge(def, ctxt) < 0)
|
|
|
|
goto error;
|
2009-07-15 17:34:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIR_INTERFACE_TYPE_BOND: {
|
|
|
|
xmlNodePtr bond;
|
|
|
|
|
2014-06-19 09:51:38 +00:00
|
|
|
if (!(bond = virXPathNode("./bond[1]", ctxt))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("bond interface misses the bond element"));
|
2009-07-15 17:34:04 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ctxt->node = bond;
|
2010-02-10 12:28:05 +00:00
|
|
|
if (virInterfaceDefParseBond(def, ctxt) < 0)
|
2009-07-15 17:34:04 +00:00
|
|
|
goto error;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIR_INTERFACE_TYPE_VLAN: {
|
|
|
|
xmlNodePtr vlan;
|
|
|
|
|
2014-06-19 09:51:38 +00:00
|
|
|
if (!(vlan = virXPathNode("./vlan[1]", ctxt))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
"%s", _("vlan interface misses the vlan element"));
|
2009-07-15 17:34:04 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ctxt->node = vlan;
|
2010-02-10 12:28:05 +00:00
|
|
|
if (virInterfaceDefParseVlan(def, ctxt) < 0)
|
2009-07-15 17:34:04 +00:00
|
|
|
goto error;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return def;
|
|
|
|
|
2014-03-25 06:48:31 +00:00
|
|
|
error:
|
2009-07-15 17:34:04 +00:00
|
|
|
virInterfaceDefFree(def);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
|
|
|
virInterfaceDefPtr
|
|
|
|
virInterfaceDefParseNode(xmlDocPtr xml,
|
|
|
|
xmlNodePtr root)
|
2009-07-15 17:34:04 +00:00
|
|
|
{
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2017-08-14 12:31:52 +00:00
|
|
|
if (!virXMLNodeNameEqual(root, "interface")) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unexpected root element <%s>, "
|
|
|
|
"expecting <interface>"),
|
|
|
|
root->name);
|
2009-07-15 17:34:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-09 06:33:58 +00:00
|
|
|
if (!(ctxt = virXMLXPathContextNew(xml)))
|
2019-09-16 10:52:57 +00:00
|
|
|
return NULL;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
|
|
|
ctxt->node = root;
|
2019-09-16 10:52:57 +00:00
|
|
|
return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST);
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2010-02-24 20:53:16 +00:00
|
|
|
static virInterfaceDefPtr
|
|
|
|
virInterfaceDefParse(const char *xmlStr,
|
|
|
|
const char *filename)
|
2009-07-15 17:34:04 +00:00
|
|
|
{
|
2010-02-24 20:53:16 +00:00
|
|
|
xmlDocPtr xml;
|
2009-07-15 17:34:04 +00:00
|
|
|
virInterfaceDefPtr def = NULL;
|
|
|
|
|
2011-09-14 14:17:57 +00:00
|
|
|
if ((xml = virXMLParse(filename, xmlStr, _("(interface_definition)")))) {
|
2010-02-24 20:53:16 +00:00
|
|
|
def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml));
|
|
|
|
xmlFreeDoc(xml);
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
|
|
|
virInterfaceDefPtr
|
|
|
|
virInterfaceDefParseString(const char *xmlStr)
|
2009-07-15 17:34:04 +00:00
|
|
|
{
|
2010-02-24 20:53:16 +00:00
|
|
|
return virInterfaceDefParse(xmlStr, NULL);
|
|
|
|
}
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
|
|
|
virInterfaceDefPtr
|
|
|
|
virInterfaceDefParseFile(const char *filename)
|
2010-02-24 20:53:16 +00:00
|
|
|
{
|
|
|
|
return virInterfaceDefParse(NULL, filename);
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2017-03-02 16:44:11 +00:00
|
|
|
virInterfaceBridgeDefFormat(virBufferPtr buf,
|
|
|
|
const virInterfaceDef *def)
|
maint: avoid 'const fooPtr' in conf
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up remaining offenders in src/conf, and their fallout.
* src/conf/snapshot_conf.h (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Drop attempt at const.
* src/conf/interface_conf.h (virInterfaceObjIsActive)
(virInterfaceDefFormat): Use intended type.
(virInterfaceFindByMACString, virInterfaceFindByName)
(virInterfaceAssignDef, virInterfaceRemove): Drop attempt at
const.
* src/conf/network_conf.h (virNetworkObjIsActive)
(virNetworkDefFormat, virNetworkDefForwardIf)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask): Use intended type.
(virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef)
(virNetworkObjAssignDef, virNetworkRemoveInactive)
(virNetworkBridgeInUse, virNetworkSetBridgeName)
(virNetworkAllocateBridge): Drop attempt at const.
* src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make
const-correct.
* src/conf/node_device_conf.h (virNodeDeviceHasCap)
(virNodeDeviceDefFormat): Use intended type.
(virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceGetParentHost): Drop attempt at const.
* src/conf/secret_conf.h (virSecretDefFormat): Use intended type.
* src/conf/snapshot_conf.c (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Fix fallout.
* src/conf/interface_conf.c (virInterfaceBridgeDefFormat)
(virInterfaceBondDefFormat, virInterfaceVlanDefFormat)
(virInterfaceProtocolDefFormat, virInterfaceDefDevFormat)
(virInterfaceDefFormat, virInterfaceFindByMACString)
(virInterfaceFindByName, virInterfaceAssignDef)
(virInterfaceRemove): Likewise.
* src/conf/network_conf.c
(VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef)
(virNetworkAssignDef, virNetworkRemoveInactive)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML)
(virNetworkIpDefFormat, virNetworkRouteDefFormat)
(virPortGroupDefFormat, virNetworkForwardNatDefFormat)
(virNetworkDefFormatInternal, virNetworkBridgeInUse)
(virNetworkAllocateBridge, virNetworkSetBridgeName)
(virNetworkDNSDefFormat, virNetworkDefFormat): Likewise.
* src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise.
* src/conf/node_device_conf.c (virNodeDeviceHasCap)
(virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise.
* src/conf/secret_conf.c (virSecretDefFormatUsage)
(virSecretDefFormat): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-07-15 17:34:04 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAddLit(buf, "<bridge");
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.bridge.stp == 1)
|
2010-01-02 01:40:23 +00:00
|
|
|
virBufferAddLit(buf, " stp='on'");
|
2009-07-15 17:34:04 +00:00
|
|
|
else if (def->data.bridge.stp == 0)
|
2010-01-02 01:40:23 +00:00
|
|
|
virBufferAddLit(buf, " stp='off'");
|
|
|
|
if (def->data.bridge.delay != NULL)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " delay='%s'", def->data.bridge.delay);
|
2010-01-02 01:40:23 +00:00
|
|
|
virBufferAddLit(buf, ">\n");
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, 2);
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2013-05-24 16:58:25 +00:00
|
|
|
for (i = 0; i < def->data.bridge.nbItf; i++) {
|
2014-06-19 09:58:56 +00:00
|
|
|
if (virInterfaceDefDevFormat(buf, def->data.bridge.itf[i],
|
|
|
|
VIR_INTERFACE_TYPE_BRIDGE) < 0)
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</bridge>\n");
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2017-03-02 16:44:11 +00:00
|
|
|
virInterfaceBondDefFormat(virBufferPtr buf,
|
|
|
|
const virInterfaceDef *def)
|
maint: avoid 'const fooPtr' in conf
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up remaining offenders in src/conf, and their fallout.
* src/conf/snapshot_conf.h (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Drop attempt at const.
* src/conf/interface_conf.h (virInterfaceObjIsActive)
(virInterfaceDefFormat): Use intended type.
(virInterfaceFindByMACString, virInterfaceFindByName)
(virInterfaceAssignDef, virInterfaceRemove): Drop attempt at
const.
* src/conf/network_conf.h (virNetworkObjIsActive)
(virNetworkDefFormat, virNetworkDefForwardIf)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask): Use intended type.
(virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef)
(virNetworkObjAssignDef, virNetworkRemoveInactive)
(virNetworkBridgeInUse, virNetworkSetBridgeName)
(virNetworkAllocateBridge): Drop attempt at const.
* src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make
const-correct.
* src/conf/node_device_conf.h (virNodeDeviceHasCap)
(virNodeDeviceDefFormat): Use intended type.
(virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceGetParentHost): Drop attempt at const.
* src/conf/secret_conf.h (virSecretDefFormat): Use intended type.
* src/conf/snapshot_conf.c (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Fix fallout.
* src/conf/interface_conf.c (virInterfaceBridgeDefFormat)
(virInterfaceBondDefFormat, virInterfaceVlanDefFormat)
(virInterfaceProtocolDefFormat, virInterfaceDefDevFormat)
(virInterfaceDefFormat, virInterfaceFindByMACString)
(virInterfaceFindByName, virInterfaceAssignDef)
(virInterfaceRemove): Likewise.
* src/conf/network_conf.c
(VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef)
(virNetworkAssignDef, virNetworkRemoveInactive)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML)
(virNetworkIpDefFormat, virNetworkRouteDefFormat)
(virPortGroupDefFormat, virNetworkForwardNatDefFormat)
(virNetworkDefFormatInternal, virNetworkBridgeInUse)
(virNetworkAllocateBridge, virNetworkSetBridgeName)
(virNetworkDNSDefFormat, virNetworkDefFormat): Likewise.
* src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise.
* src/conf/node_device_conf.c (virNodeDeviceHasCap)
(virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise.
* src/conf/secret_conf.c (virSecretDefFormatUsage)
(virSecretDefFormat): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-07-15 17:34:04 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAddLit(buf, "<bond");
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.bond.mode == VIR_INTERFACE_BOND_BALRR)
|
|
|
|
virBufferAddLit(buf, " mode='balance-rr'");
|
|
|
|
else if (def->data.bond.mode == VIR_INTERFACE_BOND_ABACKUP)
|
|
|
|
virBufferAddLit(buf, " mode='active-backup'");
|
|
|
|
else if (def->data.bond.mode == VIR_INTERFACE_BOND_BALXOR)
|
|
|
|
virBufferAddLit(buf, " mode='balance-xor'");
|
|
|
|
else if (def->data.bond.mode == VIR_INTERFACE_BOND_BCAST)
|
|
|
|
virBufferAddLit(buf, " mode='broadcast'");
|
|
|
|
else if (def->data.bond.mode == VIR_INTERFACE_BOND_8023AD)
|
|
|
|
virBufferAddLit(buf, " mode='802.3ad'");
|
|
|
|
else if (def->data.bond.mode == VIR_INTERFACE_BOND_BALTLB)
|
|
|
|
virBufferAddLit(buf, " mode='balance-tlb'");
|
|
|
|
else if (def->data.bond.mode == VIR_INTERFACE_BOND_BALALB)
|
|
|
|
virBufferAddLit(buf, " mode='balance-alb'");
|
|
|
|
virBufferAddLit(buf, ">\n");
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, 2);
|
2009-07-15 17:34:04 +00:00
|
|
|
|
|
|
|
if (def->data.bond.monit == VIR_INTERFACE_BOND_MONIT_MII) {
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<miimon freq='%d'",
|
|
|
|
def->data.bond.frequency);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.bond.downdelay > 0)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " downdelay='%d'", def->data.bond.downdelay);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.bond.updelay > 0)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " updelay='%d'", def->data.bond.updelay);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.bond.carrier == VIR_INTERFACE_BOND_MII_IOCTL)
|
|
|
|
virBufferAddLit(buf, " carrier='ioctl'");
|
|
|
|
else if (def->data.bond.carrier == VIR_INTERFACE_BOND_MII_NETIF)
|
|
|
|
virBufferAddLit(buf, " carrier='netif'");
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
} else if (def->data.bond.monit == VIR_INTERFACE_BOND_MONIT_ARP) {
|
|
|
|
if (def->data.bond.target == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("bond arp monitoring has no target"));
|
2012-03-22 11:33:35 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<arpmon interval='%d' target='%s'",
|
2009-07-15 17:34:04 +00:00
|
|
|
def->data.bond.interval, def->data.bond.target);
|
|
|
|
if (def->data.bond.validate == VIR_INTERFACE_BOND_ARP_ACTIVE)
|
|
|
|
virBufferAddLit(buf, " validate='active'");
|
|
|
|
else if (def->data.bond.validate == VIR_INTERFACE_BOND_ARP_BACKUP)
|
|
|
|
virBufferAddLit(buf, " validate='backup'");
|
|
|
|
else if (def->data.bond.validate == VIR_INTERFACE_BOND_ARP_ALL)
|
|
|
|
virBufferAddLit(buf, " validate='all'");
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
2013-05-24 16:58:25 +00:00
|
|
|
for (i = 0; i < def->data.bond.nbItf; i++) {
|
2014-06-19 09:58:56 +00:00
|
|
|
if (virInterfaceDefDevFormat(buf, def->data.bond.itf[i],
|
|
|
|
VIR_INTERFACE_TYPE_BOND) < 0)
|
2009-07-15 17:34:04 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</bond>\n");
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2017-03-02 16:44:11 +00:00
|
|
|
virInterfaceVlanDefFormat(virBufferPtr buf,
|
|
|
|
const virInterfaceDef *def)
|
maint: avoid 'const fooPtr' in conf
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up remaining offenders in src/conf, and their fallout.
* src/conf/snapshot_conf.h (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Drop attempt at const.
* src/conf/interface_conf.h (virInterfaceObjIsActive)
(virInterfaceDefFormat): Use intended type.
(virInterfaceFindByMACString, virInterfaceFindByName)
(virInterfaceAssignDef, virInterfaceRemove): Drop attempt at
const.
* src/conf/network_conf.h (virNetworkObjIsActive)
(virNetworkDefFormat, virNetworkDefForwardIf)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask): Use intended type.
(virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef)
(virNetworkObjAssignDef, virNetworkRemoveInactive)
(virNetworkBridgeInUse, virNetworkSetBridgeName)
(virNetworkAllocateBridge): Drop attempt at const.
* src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make
const-correct.
* src/conf/node_device_conf.h (virNodeDeviceHasCap)
(virNodeDeviceDefFormat): Use intended type.
(virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceGetParentHost): Drop attempt at const.
* src/conf/secret_conf.h (virSecretDefFormat): Use intended type.
* src/conf/snapshot_conf.c (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Fix fallout.
* src/conf/interface_conf.c (virInterfaceBridgeDefFormat)
(virInterfaceBondDefFormat, virInterfaceVlanDefFormat)
(virInterfaceProtocolDefFormat, virInterfaceDefDevFormat)
(virInterfaceDefFormat, virInterfaceFindByMACString)
(virInterfaceFindByName, virInterfaceAssignDef)
(virInterfaceRemove): Likewise.
* src/conf/network_conf.c
(VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef)
(virNetworkAssignDef, virNetworkRemoveInactive)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML)
(virNetworkIpDefFormat, virNetworkRouteDefFormat)
(virPortGroupDefFormat, virNetworkForwardNatDefFormat)
(virNetworkDefFormatInternal, virNetworkBridgeInUse)
(virNetworkAllocateBridge, virNetworkSetBridgeName)
(virNetworkDNSDefFormat, virNetworkDefFormat): Likewise.
* src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise.
* src/conf/node_device_conf.c (virNodeDeviceHasCap)
(virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise.
* src/conf/secret_conf.c (virSecretDefFormatUsage)
(virSecretDefFormat): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->data.vlan.tag == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("vlan misses the tag name"));
|
2012-03-22 11:33:35 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<vlan tag='%s'", def->data.vlan.tag);
|
2014-10-01 14:07:46 +00:00
|
|
|
if (def->data.vlan.dev_name != NULL) {
|
2009-07-15 17:34:04 +00:00
|
|
|
virBufferAddLit(buf, ">\n");
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
virBufferAsprintf(buf, "<interface name='%s'/>\n",
|
2014-10-01 14:07:46 +00:00
|
|
|
def->data.vlan.dev_name);
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</vlan>\n");
|
2014-09-03 17:29:38 +00:00
|
|
|
} else {
|
2009-07-15 17:34:04 +00:00
|
|
|
virBufferAddLit(buf, "/>\n");
|
2014-09-03 17:29:38 +00:00
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2017-03-02 16:44:11 +00:00
|
|
|
virInterfaceProtocolDefFormat(virBufferPtr buf,
|
|
|
|
const virInterfaceDef *def)
|
maint: avoid 'const fooPtr' in conf
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up remaining offenders in src/conf, and their fallout.
* src/conf/snapshot_conf.h (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Drop attempt at const.
* src/conf/interface_conf.h (virInterfaceObjIsActive)
(virInterfaceDefFormat): Use intended type.
(virInterfaceFindByMACString, virInterfaceFindByName)
(virInterfaceAssignDef, virInterfaceRemove): Drop attempt at
const.
* src/conf/network_conf.h (virNetworkObjIsActive)
(virNetworkDefFormat, virNetworkDefForwardIf)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask): Use intended type.
(virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef)
(virNetworkObjAssignDef, virNetworkRemoveInactive)
(virNetworkBridgeInUse, virNetworkSetBridgeName)
(virNetworkAllocateBridge): Drop attempt at const.
* src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make
const-correct.
* src/conf/node_device_conf.h (virNodeDeviceHasCap)
(virNodeDeviceDefFormat): Use intended type.
(virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceGetParentHost): Drop attempt at const.
* src/conf/secret_conf.h (virSecretDefFormat): Use intended type.
* src/conf/snapshot_conf.c (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Fix fallout.
* src/conf/interface_conf.c (virInterfaceBridgeDefFormat)
(virInterfaceBondDefFormat, virInterfaceVlanDefFormat)
(virInterfaceProtocolDefFormat, virInterfaceDefDevFormat)
(virInterfaceDefFormat, virInterfaceFindByMACString)
(virInterfaceFindByName, virInterfaceAssignDef)
(virInterfaceRemove): Likewise.
* src/conf/network_conf.c
(VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef)
(virNetworkAssignDef, virNetworkRemoveInactive)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML)
(virNetworkIpDefFormat, virNetworkRouteDefFormat)
(virPortGroupDefFormat, virNetworkForwardNatDefFormat)
(virNetworkDefFormatInternal, virNetworkBridgeInUse)
(virNetworkAllocateBridge, virNetworkSetBridgeName)
(virNetworkDNSDefFormat, virNetworkDefFormat): Likewise.
* src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise.
* src/conf/node_device_conf.c (virNodeDeviceHasCap)
(virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise.
* src/conf/secret_conf.c (virSecretDefFormatUsage)
(virSecretDefFormat): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i, j;
|
2009-10-28 13:13:18 +00:00
|
|
|
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (i = 0; i < def->nprotos; i++) {
|
2009-10-28 13:13:18 +00:00
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<protocol family='%s'>\n",
|
|
|
|
def->protos[i]->family);
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
2009-10-28 13:13:18 +00:00
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
if (def->protos[i]->autoconf)
|
|
|
|
virBufferAddLit(buf, "<autoconf/>\n");
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
if (def->protos[i]->dhcp) {
|
|
|
|
if (def->protos[i]->peerdns == 0)
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAddLit(buf, "<dhcp peerdns='no'/>\n");
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
else if (def->protos[i]->peerdns == 1)
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAddLit(buf, "<dhcp peerdns='yes'/>\n");
|
2009-10-28 13:13:18 +00:00
|
|
|
else
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAddLit(buf, "<dhcp/>\n");
|
2009-10-28 13:13:18 +00:00
|
|
|
}
|
|
|
|
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (j = 0; j < def->protos[i]->nips; j++) {
|
|
|
|
if (def->protos[i]->ips[j]->address != NULL) {
|
2009-10-28 13:13:18 +00:00
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<ip address='%s'",
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
def->protos[i]->ips[j]->address);
|
|
|
|
if (def->protos[i]->ips[j]->prefix != 0) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " prefix='%d'",
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
def->protos[i]->ips[j]->prefix);
|
2009-10-28 13:13:18 +00:00
|
|
|
}
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
}
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
if (def->protos[i]->gateway != NULL) {
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<route gateway='%s'/>\n",
|
|
|
|
def->protos[i]->gateway);
|
2009-10-28 13:13:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</protocol>\n");
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2009-07-15 17:34:04 +00:00
|
|
|
static int
|
2010-02-10 12:28:05 +00:00
|
|
|
virInterfaceStartmodeDefFormat(virBufferPtr buf,
|
2014-04-28 00:15:22 +00:00
|
|
|
virInterfaceStartMode startmode)
|
2014-03-05 12:24:22 +00:00
|
|
|
{
|
2009-07-15 17:34:04 +00:00
|
|
|
const char *mode;
|
|
|
|
switch (startmode) {
|
2009-10-28 08:55:33 +00:00
|
|
|
case VIR_INTERFACE_START_UNSPECIFIED:
|
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
case VIR_INTERFACE_START_NONE:
|
|
|
|
mode = "none";
|
|
|
|
break;
|
|
|
|
case VIR_INTERFACE_START_ONBOOT:
|
|
|
|
mode = "onboot";
|
|
|
|
break;
|
|
|
|
case VIR_INTERFACE_START_HOTPLUG:
|
|
|
|
mode = "hotplug";
|
|
|
|
break;
|
|
|
|
default:
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("virInterfaceDefFormat unknown startmode"));
|
2009-07-15 17:34:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<start mode='%s'/>\n", mode);
|
2012-03-22 11:33:35 +00:00
|
|
|
return 0;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
2010-01-02 01:40:25 +00:00
|
|
|
static int
|
2017-03-02 16:44:11 +00:00
|
|
|
virInterfaceDefDevFormat(virBufferPtr buf,
|
|
|
|
const virInterfaceDef *def,
|
2014-06-19 09:58:56 +00:00
|
|
|
virInterfaceType parentIfType)
|
maint: avoid 'const fooPtr' in conf
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up remaining offenders in src/conf, and their fallout.
* src/conf/snapshot_conf.h (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Drop attempt at const.
* src/conf/interface_conf.h (virInterfaceObjIsActive)
(virInterfaceDefFormat): Use intended type.
(virInterfaceFindByMACString, virInterfaceFindByName)
(virInterfaceAssignDef, virInterfaceRemove): Drop attempt at
const.
* src/conf/network_conf.h (virNetworkObjIsActive)
(virNetworkDefFormat, virNetworkDefForwardIf)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask): Use intended type.
(virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef)
(virNetworkObjAssignDef, virNetworkRemoveInactive)
(virNetworkBridgeInUse, virNetworkSetBridgeName)
(virNetworkAllocateBridge): Drop attempt at const.
* src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make
const-correct.
* src/conf/node_device_conf.h (virNodeDeviceHasCap)
(virNodeDeviceDefFormat): Use intended type.
(virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceGetParentHost): Drop attempt at const.
* src/conf/secret_conf.h (virSecretDefFormat): Use intended type.
* src/conf/snapshot_conf.c (virDomainSnapshotAssignDef)
(virDomainSnapshotFindByName): Fix fallout.
* src/conf/interface_conf.c (virInterfaceBridgeDefFormat)
(virInterfaceBondDefFormat, virInterfaceVlanDefFormat)
(virInterfaceProtocolDefFormat, virInterfaceDefDevFormat)
(virInterfaceDefFormat, virInterfaceFindByMACString)
(virInterfaceFindByName, virInterfaceAssignDef)
(virInterfaceRemove): Likewise.
* src/conf/network_conf.c
(VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef)
(virNetworkAssignDef, virNetworkRemoveInactive)
(virNetworkDefGetIpByIndex, virNetworkIpDefPrefix)
(virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML)
(virNetworkIpDefFormat, virNetworkRouteDefFormat)
(virPortGroupDefFormat, virNetworkForwardNatDefFormat)
(virNetworkDefFormatInternal, virNetworkBridgeInUse)
(virNetworkAllocateBridge, virNetworkSetBridgeName)
(virNetworkDNSDefFormat, virNetworkDefFormat): Likewise.
* src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise.
* src/conf/node_device_conf.c (virNodeDeviceHasCap)
(virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName)
(virNodeDeviceAssignDef, virNodeDeviceObjRemove)
(virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise.
* src/conf/secret_conf.c (virSecretDefFormatUsage)
(virSecretDefFormat): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
|
|
|
{
|
2009-12-09 23:00:50 +00:00
|
|
|
const char *type = NULL;
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2010-01-02 01:40:25 +00:00
|
|
|
if (def == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("virInterfaceDefFormat NULL def"));
|
2020-01-06 21:57:26 +00:00
|
|
|
return -1;
|
2010-01-02 01:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((def->name == NULL) && (def->type != VIR_INTERFACE_TYPE_VLAN)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("virInterfaceDefFormat missing interface name"));
|
2020-01-06 21:57:26 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(type = virInterfaceTypeToString(def->type))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unexpected interface type %d"), def->type);
|
2020-01-06 21:57:26 +00:00
|
|
|
return -1;
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<interface type='%s' ", type);
|
2009-07-15 17:34:04 +00:00
|
|
|
if (def->name != NULL)
|
2010-01-02 01:40:25 +00:00
|
|
|
virBufferEscapeString(buf, "name='%s'", def->name);
|
|
|
|
virBufferAddLit(buf, ">\n");
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, 2);
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2014-06-19 09:58:56 +00:00
|
|
|
if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
|
|
|
|
/* these elements are only valid on top-level interfaces - IP
|
|
|
|
* address info ("protocol") only makes sense for the
|
|
|
|
* top-level, and subordinate interfaces inherit the toplevel
|
|
|
|
* setting for mtu and start mode, which cannot be overridden.
|
|
|
|
*/
|
|
|
|
virInterfaceStartmodeDefFormat(buf, def->startmode);
|
|
|
|
if (def->mtu)
|
|
|
|
virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu);
|
|
|
|
virInterfaceProtocolDefFormat(buf, def);
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:23:27 +00:00
|
|
|
if (def->type != VIR_INTERFACE_TYPE_BRIDGE)
|
2014-06-19 09:58:56 +00:00
|
|
|
virInterfaceLinkFormat(buf, &def->lnk);
|
2009-07-15 17:34:04 +00:00
|
|
|
switch (def->type) {
|
|
|
|
case VIR_INTERFACE_TYPE_ETHERNET:
|
2014-06-19 09:58:56 +00:00
|
|
|
if (def->mac)
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAsprintf(buf, "<mac address='%s'/>\n", def->mac);
|
2009-07-15 17:34:04 +00:00
|
|
|
break;
|
|
|
|
case VIR_INTERFACE_TYPE_BRIDGE:
|
2014-03-05 12:24:22 +00:00
|
|
|
virInterfaceBridgeDefFormat(buf, def);
|
2009-07-15 17:34:04 +00:00
|
|
|
break;
|
|
|
|
case VIR_INTERFACE_TYPE_BOND:
|
2014-03-05 12:24:22 +00:00
|
|
|
virInterfaceBondDefFormat(buf, def);
|
2009-07-15 17:34:04 +00:00
|
|
|
break;
|
|
|
|
case VIR_INTERFACE_TYPE_VLAN:
|
2014-03-05 12:24:22 +00:00
|
|
|
virInterfaceVlanDefFormat(buf, def);
|
2009-07-15 17:34:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:24:22 +00:00
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</interface>\n");
|
2009-07-15 17:34:04 +00:00
|
|
|
|
2010-01-02 01:40:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-02 16:44:11 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
virInterfaceDefFormat(const virInterfaceDef *def)
|
2010-01-02 01:40:25 +00:00
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
|
2014-06-19 09:58:56 +00:00
|
|
|
if (virInterfaceDefDevFormat(&buf, def, VIR_INTERFACE_TYPE_LAST) < 0) {
|
2010-01-02 01:40:25 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return virBufferContentAndReset(&buf);
|
2009-07-15 17:34:04 +00:00
|
|
|
}
|