domainsnapshot.rng \
interface.rng \
network.rng \
+ networkcommon.rng \
nodedev.rng \
nwfilter.rng \
secret.rng \
<include href='basictypes.rng'/>
<include href='storageencryption.rng'/>
+ <include href='networkcommon.rng'/>
<!--
description element, maybe placed anywhere under the root
</optional>
</interleave>
</define>
- <define name="virtualPortProfile">
- <choice>
- <group>
- <element name="virtualport">
- <attribute name="type">
- <value>802.1Qbg</value>
- </attribute>
- <element name="parameters">
- <attribute name="managerid">
- <ref name="uint8range"/>
- </attribute>
- <attribute name="typeid">
- <ref name="uint24range"/>
- </attribute>
- <attribute name="typeidversion">
- <ref name="uint8range"/>
- </attribute>
- <optional>
- <attribute name="instanceid">
- <ref name="UUID"/>
- </attribute>
- </optional>
- </element>
- </element>
- </group>
- <group>
- <element name="virtualport">
- <attribute name="type">
- <value>802.1Qbh</value>
- </attribute>
- <element name="parameters">
- <attribute name="profileid">
- <ref name="virtualPortProfileID"/>
- </attribute>
- </element>
- </element>
- </group>
- </choice>
- </define>
<!--
An emulator description is just a path to the binary used for the task
-->
<param name="pattern">[a-zA-Z0-9_\.:]+</param>
</data>
</define>
- <define name="virtualPortProfileID">
- <data type="string">
- <param name="maxLength">39</param>
- </data>
- </define>
</grammar>
--- /dev/null
+<?xml version="1.0"?>
+<!-- network-related definitions used in multiple grammars -->
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+
+ <define name="virtualPortProfileID">
+ <data type="string">
+ <param name="maxLength">39</param>
+ </data>
+ </define>
+
+ <define name="virtualPortProfile">
+ <choice>
+ <group>
+ <element name="virtualport">
+ <attribute name="type">
+ <value>802.1Qbg</value>
+ </attribute>
+ <element name="parameters">
+ <attribute name="managerid">
+ <ref name="uint8range"/>
+ </attribute>
+ <attribute name="typeid">
+ <ref name="uint24range"/>
+ </attribute>
+ <attribute name="typeidversion">
+ <ref name="uint8range"/>
+ </attribute>
+ <optional>
+ <attribute name="instanceid">
+ <ref name="UUID"/>
+ </attribute>
+ </optional>
+ </element>
+ </element>
+ </group>
+ <group>
+ <element name="virtualport">
+ <attribute name="type">
+ <value>802.1Qbh</value>
+ </attribute>
+ <element name="parameters">
+ <attribute name="profileid">
+ <ref name="virtualPortProfileID"/>
+ </attribute>
+ </element>
+ </element>
+ </group>
+ </choice>
+ </define>
+</grammar>
%{_datadir}/libvirt/schemas/storageencryption.rng
%{_datadir}/libvirt/schemas/nwfilter.rng
%{_datadir}/libvirt/schemas/basictypes.rng
+%{_datadir}/libvirt/schemas/networkcommon.rng
%{_datadir}/libvirt/cpu_map.xml
%{_mingw32_datadir}/libvirt/schemas/secret.rng
%{_mingw32_datadir}/libvirt/schemas/storageencryption.rng
%{_mingw32_datadir}/libvirt/schemas/basictypes.rng
+%{_mingw32_datadir}/libvirt/schemas/networkcommon.rng
%{_mingw32_datadir}/libvirt/cpu_map.xml
"dynamic",
"static")
-VIR_ENUM_IMPL(virVirtualPort, VIR_VIRTUALPORT_TYPE_LAST,
- "none",
- "802.1Qbg",
- "802.1Qbh")
-
VIR_ENUM_IMPL(virDomainClockOffset, VIR_DOMAIN_CLOCK_OFFSET_LAST,
"utc",
"localtime",
}
-static int
-virVirtualPortProfileParamsParseXML(xmlNodePtr node,
- virVirtualPortProfileParamsPtr virtPort)
-{
- int ret = -1;
- char *virtPortType;
- char *virtPortManagerID = NULL;
- char *virtPortTypeID = NULL;
- char *virtPortTypeIDVersion = NULL;
- char *virtPortInstanceID = NULL;
- char *virtPortProfileID = NULL;
- xmlNodePtr cur = node->children;
- const char *msg = NULL;
-
- virtPortType = virXMLPropString(node, "type");
- if (!virtPortType)
- return -1;
-
- 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;
- }
-
- virtPort->virtPortType = VIR_VIRTUALPORT_NONE;
-
- switch (virVirtualPortTypeFromString(virtPortType)) {
-
- case VIR_VIRTUALPORT_8021QBG:
- if (virtPortManagerID != NULL && virtPortTypeID != NULL &&
- virtPortTypeIDVersion != NULL) {
- unsigned int val;
-
- if (virStrToLong_ui(virtPortManagerID, NULL, 0, &val)) {
- msg = _("cannot parse value of managerid parameter");
- goto err_exit;
- }
-
- if (val > 0xff) {
- msg = _("value of managerid out of range");
- goto err_exit;
- }
-
- virtPort->u.virtPort8021Qbg.managerID = (uint8_t)val;
-
- if (virStrToLong_ui(virtPortTypeID, NULL, 0, &val)) {
- msg = _("cannot parse value of typeid parameter");
- goto err_exit;
- }
-
- if (val > 0xffffff) {
- msg = _("value for typeid out of range");
- goto err_exit;
- }
-
- virtPort->u.virtPort8021Qbg.typeID = (uint32_t)val;
-
- if (virStrToLong_ui(virtPortTypeIDVersion, NULL, 0, &val)) {
- msg = _("cannot parse value of typeidversion parameter");
- goto err_exit;
- }
-
- if (val > 0xff) {
- msg = _("value of typeidversion out of range");
- goto err_exit;
- }
-
- virtPort->u.virtPort8021Qbg.typeIDVersion = (uint8_t)val;
-
- if (virtPortInstanceID != NULL) {
- if (virUUIDParse(virtPortInstanceID,
- virtPort->u.virtPort8021Qbg.instanceID)) {
- msg = _("cannot parse instanceid parameter as a uuid");
- goto err_exit;
- }
- } else {
- if (virUUIDGenerate(virtPort->u.virtPort8021Qbg.instanceID)) {
- msg = _("cannot generate a random uuid for instanceid");
- goto err_exit;
- }
- }
-
- virtPort->virtPortType = VIR_VIRTUALPORT_8021QBG;
- ret = 0;
- } else {
- msg = _("a parameter is missing for 802.1Qbg description");
- goto err_exit;
- }
- break;
-
- case VIR_VIRTUALPORT_8021QBH:
- if (virtPortProfileID != NULL) {
- if (virStrcpyStatic(virtPort->u.virtPort8021Qbh.profileID,
- virtPortProfileID) != NULL) {
- virtPort->virtPortType = VIR_VIRTUALPORT_8021QBH;
- ret = 0;
- } else {
- msg = _("profileid parameter too long");
- goto err_exit;
- }
- } else {
- msg = _("profileid parameter is missing for 802.1Qbh descripion");
- goto err_exit;
- }
- break;
-
-
- default:
- case VIR_VIRTUALPORT_NONE:
- case VIR_VIRTUALPORT_TYPE_LAST:
- msg = _("unknown virtualport type");
- goto err_exit;
- break;
- }
-
-err_exit:
-
- if (msg)
- virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s", msg);
-
- VIR_FREE(virtPortManagerID);
- VIR_FREE(virtPortTypeID);
- VIR_FREE(virtPortTypeIDVersion);
- VIR_FREE(virtPortInstanceID);
- VIR_FREE(virtPortProfileID);
- VIR_FREE(virtPortType);
-
- return ret;
-}
-
-
/* Parse the XML definition for a network interface
* @param node XML nodeset to parse for net definition
* @return 0 on success, -1 on failure
} else if (!virtPortParsed &&
(def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
xmlStrEqual(cur->name, BAD_CAST "virtualport")) {
- if (virVirtualPortProfileParamsParseXML(cur, &virtPort))
+ if (virVirtualPortProfileParseXML(cur, &virtPort))
goto error;
virtPortParsed = true;
} else if ((network == NULL) &&
return type;
}
-static void
-virVirtualPortProfileFormat(virBufferPtr buf,
- virVirtualPortProfileParamsPtr virtPort,
- const char *indent)
-{
- char uuidstr[VIR_UUID_STRING_BUFLEN];
-
- if (virtPort->virtPortType == VIR_VIRTUALPORT_NONE)
- return;
-
- virBufferAsprintf(buf, "%s<virtualport type='%s'>\n",
- indent,
- virVirtualPortTypeToString(virtPort->virtPortType));
-
- switch (virtPort->virtPortType) {
- case VIR_VIRTUALPORT_NONE:
- case VIR_VIRTUALPORT_TYPE_LAST:
- break;
-
- case VIR_VIRTUALPORT_8021QBG:
- virUUIDFormat(virtPort->u.virtPort8021Qbg.instanceID,
- uuidstr);
- virBufferAsprintf(buf,
- "%s <parameters managerid='%d' typeid='%d' "
- "typeidversion='%d' instanceid='%s'/>\n",
- indent,
- virtPort->u.virtPort8021Qbg.managerID,
- virtPort->u.virtPort8021Qbg.typeID,
- virtPort->u.virtPort8021Qbg.typeIDVersion,
- uuidstr);
- break;
-
- case VIR_VIRTUALPORT_8021QBH:
- virBufferAsprintf(buf,
- "%s <parameters profileid='%s'/>\n",
- indent,
- virtPort->u.virtPort8021Qbh.profileID);
- break;
- }
-
- virBufferAsprintf(buf, "%s</virtualport>\n", indent);
-}
-
int virDomainDiskIndexByName(virDomainDefPtr def, const char *name)
{
virDomainDiskDefPtr vdisk;
virSocketParseIpv4Addr;
virSocketParseIpv6Addr;
virSocketSetPort;
+virVirtualPortProfileFormat;
+virVirtualPortProfileParseXML;
# network_conf.h
#include "util.h"
#include "macvtap.h"
+#include "network.h"
VIR_ENUM_IMPL(virMacvtapMode, VIR_MACVTAP_MODE_LAST,
"vepa",
VIR_DEBUG("%s: VM OPERATION: %s", __FUNCTION__, virVMOperationTypeToString(vmOp));
- if (vmOp == VIR_VM_OP_NO_OP)
+ if (!virtPort || vmOp == VIR_VM_OP_NO_OP)
return 0;
switch (virtPort->virtPortType) {
VIR_DEBUG("%s: VM OPERATION: %s", __FUNCTION__, virVMOperationTypeToString(vmOp));
+ if (!virtPort)
+ return 0;
+
switch (virtPort->virtPortType) {
case VIR_VIRTUALPORT_NONE:
case VIR_VIRTUALPORT_TYPE_LAST:
# include <config.h>
-
-enum virVirtualPortType {
- VIR_VIRTUALPORT_NONE,
- VIR_VIRTUALPORT_8021QBG,
- VIR_VIRTUALPORT_8021QBH,
-
- VIR_VIRTUALPORT_TYPE_LAST,
-};
-
/* the mode type for macvtap devices */
enum virMacvtapMode {
VIR_MACVTAP_MODE_VEPA,
VIR_MACVTAP_MODE_LAST,
};
-
-# ifdef IFLA_VF_PORT_PROFILE_MAX
-# define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX IFLA_VF_PORT_PROFILE_MAX
-# else
-# define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX 40
-# endif
-
-/* profile data for macvtap (VEPA) */
-typedef struct _virVirtualPortProfileParams virVirtualPortProfileParams;
-typedef virVirtualPortProfileParams *virVirtualPortProfileParamsPtr;
-struct _virVirtualPortProfileParams {
- enum virVirtualPortType virtPortType;
- union {
- struct {
- uint8_t managerID;
- uint32_t typeID; /* 24 bit valid */
- uint8_t typeIDVersion;
- unsigned char instanceID[VIR_UUID_BUFLEN];
- } virtPort8021Qbg;
- struct {
- char profileID[LIBVIRT_IFLA_VF_PORT_PROFILE_MAX];
- } virtPort8021Qbh;
- } u;
-};
-
enum virVMOperationType {
VIR_VM_OP_CREATE,
VIR_VM_OP_SAVE,
# if WITH_MACVTAP
# include "internal.h"
+# include "network.h"
int openMacvtapTap(const char *ifname,
const unsigned char *macaddress,
# endif /* WITH_MACVTAP */
-VIR_ENUM_DECL(virVirtualPort)
VIR_ENUM_DECL(virVMOperation)
VIR_ENUM_DECL(virMacvtapMode)
#include <arpa/inet.h>
#include "memory.h"
+#include "uuid.h"
#include "network.h"
#include "util.h"
#include "virterror_internal.h"
error:
return result;
}
+
+/* virtualPortProfile utilities */
+
+VIR_ENUM_IMPL(virVirtualPort, VIR_VIRTUALPORT_TYPE_LAST,
+ "none",
+ "802.1Qbg",
+ "802.1Qbh")
+
+int
+virVirtualPortProfileParseXML(xmlNodePtr node,
+ virVirtualPortProfileParamsPtr virtPort)
+{
+ int ret = -1;
+ char *virtPortType;
+ char *virtPortManagerID = NULL;
+ char *virtPortTypeID = NULL;
+ char *virtPortTypeIDVersion = NULL;
+ char *virtPortInstanceID = NULL;
+ char *virtPortProfileID = NULL;
+ xmlNodePtr cur = node->children;
+
+ virtPortType = virXMLPropString(node, "type");
+ if (!virtPortType) {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("missing virtualportprofile type"));
+ 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;
+ }
+
+ virtPort->virtPortType = VIR_VIRTUALPORT_NONE;
+
+ switch (virVirtualPortTypeFromString(virtPortType)) {
+
+ case VIR_VIRTUALPORT_8021QBG:
+ if (virtPortManagerID != NULL && virtPortTypeID != NULL &&
+ virtPortTypeIDVersion != NULL) {
+ unsigned int val;
+
+ if (virStrToLong_ui(virtPortManagerID, NULL, 0, &val)) {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("cannot parse value of managerid parameter"));
+ goto error;
+ }
+
+ if (val > 0xff) {
+ virSocketError(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)) {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("cannot parse value of typeid parameter"));
+ goto error;
+ }
+
+ if (val > 0xffffff) {
+ virSocketError(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)) {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("cannot parse value of typeidversion parameter"));
+ goto error;
+ }
+
+ if (val > 0xff) {
+ virSocketError(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)) {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("cannot parse instanceid parameter as a uuid"));
+ goto error;
+ }
+ } else {
+ if (virUUIDGenerate(virtPort->u.virtPort8021Qbg.instanceID)) {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("cannot generate a random uuid for instanceid"));
+ goto error;
+ }
+ }
+
+ virtPort->virtPortType = VIR_VIRTUALPORT_8021QBG;
+ ret = 0;
+ } else {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("a parameter is missing for 802.1Qbg description"));
+ goto error;
+ }
+ break;
+
+ case VIR_VIRTUALPORT_8021QBH:
+ if (virtPortProfileID != NULL) {
+ if (virStrcpyStatic(virtPort->u.virtPort8021Qbh.profileID,
+ virtPortProfileID) != NULL) {
+ virtPort->virtPortType = VIR_VIRTUALPORT_8021QBH;
+ ret = 0;
+ } else {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("profileid parameter too long"));
+ goto error;
+ }
+ } else {
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("profileid parameter is missing for 802.1Qbh descripion"));
+ goto error;
+ }
+ break;
+
+
+ default:
+ case VIR_VIRTUALPORT_NONE:
+ case VIR_VIRTUALPORT_TYPE_LAST:
+ virSocketError(VIR_ERR_XML_ERROR, "%s",
+ _("unknown virtualport type"));
+ goto error;
+ break;
+ }
+
+error:
+ VIR_FREE(virtPortManagerID);
+ VIR_FREE(virtPortTypeID);
+ VIR_FREE(virtPortTypeIDVersion);
+ VIR_FREE(virtPortInstanceID);
+ VIR_FREE(virtPortProfileID);
+ VIR_FREE(virtPortType);
+
+ return ret;
+}
+
+void
+virVirtualPortProfileFormat(virBufferPtr buf,
+ virVirtualPortProfileParamsPtr virtPort,
+ const char *indent)
+{
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ if (!virtPort || virtPort->virtPortType == VIR_VIRTUALPORT_NONE)
+ return;
+
+ virBufferAsprintf(buf, "%s<virtualport type='%s'>\n",
+ indent,
+ virVirtualPortTypeToString(virtPort->virtPortType));
+
+ switch (virtPort->virtPortType) {
+ case VIR_VIRTUALPORT_NONE:
+ case VIR_VIRTUALPORT_TYPE_LAST:
+ break;
+
+ case VIR_VIRTUALPORT_8021QBG:
+ virUUIDFormat(virtPort->u.virtPort8021Qbg.instanceID,
+ uuidstr);
+ virBufferAsprintf(buf,
+ "%s <parameters managerid='%d' typeid='%d' "
+ "typeidversion='%d' instanceid='%s'/>\n",
+ indent,
+ virtPort->u.virtPort8021Qbg.managerID,
+ virtPort->u.virtPort8021Qbg.typeID,
+ virtPort->u.virtPort8021Qbg.typeIDVersion,
+ uuidstr);
+ break;
+
+ case VIR_VIRTUALPORT_8021QBH:
+ virBufferAsprintf(buf,
+ "%s <parameters profileid='%s'/>\n",
+ indent,
+ virtPort->u.virtPort8021Qbh.profileID);
+ break;
+ }
+
+ virBufferAsprintf(buf, "%s</virtualport>\n", indent);
+}
# define __VIR_NETWORK_H__
# include "internal.h"
+# include "buf.h"
+# include "util.h"
# include <sys/types.h>
# include <sys/socket.h>
# endif
# include <netdb.h>
# include <netinet/in.h>
+# include <xml.h>
typedef struct {
union {
virSocketAddrPtr netmask,
int family);
+/* virtualPortProfile utilities */
+# ifdef IFLA_VF_PORT_PROFILE_MAX
+# define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX IFLA_VF_PORT_PROFILE_MAX
+# else
+# define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX 40
+# endif
+
+enum virVirtualPortType {
+ VIR_VIRTUALPORT_NONE,
+ VIR_VIRTUALPORT_8021QBG,
+ VIR_VIRTUALPORT_8021QBH,
+
+ VIR_VIRTUALPORT_TYPE_LAST,
+};
+
+VIR_ENUM_DECL(virVirtualPort)
+
+/* profile data for macvtap (VEPA) */
+typedef struct _virVirtualPortProfileParams virVirtualPortProfileParams;
+typedef virVirtualPortProfileParams *virVirtualPortProfileParamsPtr;
+struct _virVirtualPortProfileParams {
+ enum virVirtualPortType virtPortType;
+ union {
+ struct {
+ uint8_t managerID;
+ uint32_t typeID; /* 24 bit valid */
+ uint8_t typeIDVersion;
+ unsigned char instanceID[VIR_UUID_BUFLEN];
+ } virtPort8021Qbg;
+ struct {
+ char profileID[LIBVIRT_IFLA_VF_PORT_PROFILE_MAX];
+ } virtPort8021Qbh;
+ } u;
+};
+
+int
+virVirtualPortProfileParseXML(xmlNodePtr node,
+ virVirtualPortProfileParamsPtr virtPort);
+void
+virVirtualPortProfileFormat(virBufferPtr buf,
+ virVirtualPortProfileParamsPtr virtPort,
+ const char *indent);
+
#endif /* __VIR_NETWORK_H__ */