libvirt/src/conf/netdev_vport_profile_conf.c
Daniel P. Berrange d3406045fd Split src/util/network.{c,h} into 5 pieces
The src/util/network.c file is a dumping ground for many different
APIs. Split it up into 5 pieces, along functional lines

 - src/util/virnetdevbandwidth.c: virNetDevBandwidth type & helper APIs
 - src/util/virnetdevvportprofile.c: virNetDevVPortProfile type & helper APIs
 - src/util/virsocketaddr.c: virSocketAddr and APIs
 - src/conf/netdev_bandwidth_conf.c: XML parsing / formatting
   for virNetDevBandwidth
 - src/conf/netdev_vport_profile_conf.c: XML parsing / formatting
   for virNetDevVPortProfile

* src/util/network.c, src/util/network.h: Split into 5 pieces
* src/conf/netdev_bandwidth_conf.c, src/conf/netdev_bandwidth_conf.h,
  src/conf/netdev_vport_profile_conf.c, src/conf/netdev_vport_profile_conf.h,
  src/util/virnetdevbandwidth.c, src/util/virnetdevbandwidth.h,
  src/util/virnetdevvportprofile.c, src/util/virnetdevvportprofile.h,
  src/util/virsocketaddr.c, src/util/virsocketaddr.h: New pieces
* daemon/libvirtd.h, daemon/remote.c, src/conf/domain_conf.c,
  src/conf/domain_conf.h, src/conf/network_conf.c,
  src/conf/network_conf.h, src/conf/nwfilter_conf.h,
  src/esx/esx_util.h, src/network/bridge_driver.c,
  src/qemu/qemu_conf.c, src/rpc/virnetsocket.c,
  src/rpc/virnetsocket.h, src/util/dnsmasq.h, src/util/interface.h,
  src/util/iptables.h, src/util/macvtap.c, src/util/macvtap.h,
  src/util/virnetdev.h, src/util/virnetdevtap.c,
  tools/virsh.c: Update include files
2011-11-15 10:27:54 +00:00

237 lines
8.0 KiB
C

/*
* Copyright (C) 2009-2011 Red Hat, Inc.
*
* 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
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors:
* Stefan Berger <stefanb@us.ibm.com>
* Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#include "netdev_vport_profile_conf.h"
#include "virterror_internal.h"
#include "memory.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#define virNetDevError(code, ...) \
virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
VIR_ENUM_IMPL(virNetDevVPort, VIR_NETDEV_VPORT_PROFILE_LAST,
"none",
"802.1Qbg",
"802.1Qbh")
virNetDevVPortProfilePtr
virNetDevVPortProfileParse(xmlNodePtr node)
{
char *virtPortType;
char *virtPortManagerID = NULL;
char *virtPortTypeID = NULL;
char *virtPortTypeIDVersion = NULL;
char *virtPortInstanceID = NULL;
char *virtPortProfileID = NULL;
virNetDevVPortProfilePtr virtPort = NULL;
xmlNodePtr cur = node->children;
if (VIR_ALLOC(virtPort) < 0) {
virReportOOMError();
return NULL;
}
virtPortType = virXMLPropString(node, "type");
if (!virtPortType) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("missing virtualportprofile type"));
goto error;
}
if ((virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) {
virNetDevError(VIR_ERR_XML_ERROR,
_("unknown virtualportprofile type %s"), virtPortType);
goto error;
}
while (cur != NULL) {
if (xmlStrEqual(cur->name, BAD_CAST "parameters")) {
virtPortManagerID = virXMLPropString(cur, "managerid");
virtPortTypeID = virXMLPropString(cur, "typeid");
virtPortTypeIDVersion = virXMLPropString(cur, "typeidversion");
virtPortInstanceID = virXMLPropString(cur, "instanceid");
virtPortProfileID = virXMLPropString(cur, "profileid");
break;
}
cur = cur->next;
}
switch (virtPort->virtPortType) {
case VIR_NETDEV_VPORT_PROFILE_8021QBG:
if (virtPortManagerID != NULL && virtPortTypeID != NULL &&
virtPortTypeIDVersion != NULL) {
unsigned int val;
if (virStrToLong_ui(virtPortManagerID, NULL, 0, &val)) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of managerid parameter"));
goto error;
}
if (val > 0xff) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("value of managerid out of range"));
goto error;
}
virtPort->u.virtPort8021Qbg.managerID = (uint8_t)val;
if (virStrToLong_ui(virtPortTypeID, NULL, 0, &val)) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of typeid parameter"));
goto error;
}
if (val > 0xffffff) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("value for typeid out of range"));
goto error;
}
virtPort->u.virtPort8021Qbg.typeID = (uint32_t)val;
if (virStrToLong_ui(virtPortTypeIDVersion, NULL, 0, &val)) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse value of typeidversion parameter"));
goto error;
}
if (val > 0xff) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("value of typeidversion out of range"));
goto error;
}
virtPort->u.virtPort8021Qbg.typeIDVersion = (uint8_t)val;
if (virtPortInstanceID != NULL) {
if (virUUIDParse(virtPortInstanceID,
virtPort->u.virtPort8021Qbg.instanceID)) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("cannot parse instanceid parameter as a uuid"));
goto error;
}
} else {
if (virUUIDGenerate(virtPort->u.virtPort8021Qbg.instanceID)) {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("cannot generate a random uuid for instanceid"));
goto error;
}
}
virtPort->virtPortType = VIR_NETDEV_VPORT_PROFILE_8021QBG;
} else {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("a parameter is missing for 802.1Qbg description"));
goto error;
}
break;
case VIR_NETDEV_VPORT_PROFILE_8021QBH:
if (virtPortProfileID != NULL) {
if (virStrcpyStatic(virtPort->u.virtPort8021Qbh.profileID,
virtPortProfileID) != NULL) {
virtPort->virtPortType = VIR_NETDEV_VPORT_PROFILE_8021QBH;
} else {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("profileid parameter too long"));
goto error;
}
} else {
virNetDevError(VIR_ERR_XML_ERROR, "%s",
_("profileid parameter is missing for 802.1Qbh descripion"));
goto error;
}
break;
default:
virNetDevError(VIR_ERR_XML_ERROR,
_("unexpected virtualport type %d"), virtPort->virtPortType);
goto error;
}
cleanup:
VIR_FREE(virtPortManagerID);
VIR_FREE(virtPortTypeID);
VIR_FREE(virtPortTypeIDVersion);
VIR_FREE(virtPortInstanceID);
VIR_FREE(virtPortProfileID);
VIR_FREE(virtPortType);
return virtPort;
error:
VIR_FREE(virtPort);
goto cleanup;
}
int
virNetDevVPortProfileFormat(virNetDevVPortProfilePtr virtPort,
virBufferPtr buf)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (!virtPort || virtPort->virtPortType == VIR_NETDEV_VPORT_PROFILE_NONE)
return 0;
virBufferAsprintf(buf, "<virtualport type='%s'>\n",
virNetDevVPortTypeToString(virtPort->virtPortType));
switch (virtPort->virtPortType) {
case VIR_NETDEV_VPORT_PROFILE_8021QBG:
virUUIDFormat(virtPort->u.virtPort8021Qbg.instanceID,
uuidstr);
virBufferAsprintf(buf,
" <parameters managerid='%d' typeid='%d' "
"typeidversion='%d' instanceid='%s'/>\n",
virtPort->u.virtPort8021Qbg.managerID,
virtPort->u.virtPort8021Qbg.typeID,
virtPort->u.virtPort8021Qbg.typeIDVersion,
uuidstr);
break;
case VIR_NETDEV_VPORT_PROFILE_8021QBH:
virBufferAsprintf(buf,
" <parameters profileid='%s'/>\n",
virtPort->u.virtPort8021Qbh.profileID);
break;
default:
virNetDevError(VIR_ERR_XML_ERROR,
_("unexpected virtualport type %d"), virtPort->virtPortType);
return -1;
}
virBufferAddLit(buf, "</virtualport>\n");
return 0;
}