This part adds support to domain_conf.{c|h} for parsing the new interface XML of type 'direct'. The parsed mode is now stored as an int. Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>
Index: libvirt-macvtap/src/conf/domain_conf.c =================================================================== --- libvirt-macvtap.orig/src/conf/domain_conf.c +++ libvirt-macvtap/src/conf/domain_conf.c @@ -41,6 +41,7 @@ #include "c-ctype.h" #include "logging.h" #include "network.h" +#include "macvtap.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -140,7 +141,8 @@ VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_N "mcast", "network", "bridge", - "internal") + "internal", + "direct") VIR_ENUM_IMPL(virDomainChrTarget, VIR_DOMAIN_CHR_TARGET_TYPE_LAST, "null", @@ -222,6 +224,11 @@ VIR_ENUM_IMPL(virDomainSeclabel, VIR_DOM "dynamic", "static") +VIR_ENUM_IMPL(virDomainNetdevMacvtap, VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST, + "vepa", + "private", + "bridge") + #define virDomainReportError(code, fmt...) \ virReportErrorHelper(NULL, VIR_FROM_DOMAIN, code, __FILE__, \ __FUNCTION__, __LINE__, fmt) @@ -430,6 +437,10 @@ void virDomainNetDefFree(virDomainNetDef case VIR_DOMAIN_NET_TYPE_INTERNAL: VIR_FREE(def->data.internal.name); break; + + case VIR_DOMAIN_NET_TYPE_DIRECT: + VIR_FREE(def->data.direct.linkdev); + break; } VIR_FREE(def->ifname); @@ -1622,6 +1633,7 @@ virDomainNetDefParseXML(virCapsPtr caps, char *model = NULL; char *internal = NULL; char *devaddr = NULL; + char *mode = NULL; if (VIR_ALLOC(def) < 0) { virReportOOMError(); @@ -1658,9 +1670,11 @@ virDomainNetDefParseXML(virCapsPtr caps, (xmlStrEqual(cur->name, BAD_CAST "source"))) { bridge = virXMLPropString(cur, "bridge"); } else if ((dev == NULL) && - (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET) && + (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET || + def->type == VIR_DOMAIN_NET_TYPE_DIRECT) && xmlStrEqual(cur->name, BAD_CAST "source")) { - dev = virXMLPropString(cur, "dev"); + dev = virXMLPropString(cur, "dev"); + mode = virXMLPropString(cur, "mode"); } else if ((network == NULL) && ((def->type == VIR_DOMAIN_NET_TYPE_SERVER) || (def->type == VIR_DOMAIN_NET_TYPE_CLIENT) || @@ -1814,6 +1828,29 @@ virDomainNetDefParseXML(virCapsPtr caps, def->data.internal.name = internal; internal = NULL; break; + + case VIR_DOMAIN_NET_TYPE_DIRECT: + if (dev == NULL) { + virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("No <source> 'dev' attribute specified with <interface type='direct'/>")); + goto error; + } + + if (mode != NULL) { + int m; + if ((m = virDomainNetdevMacvtapTypeFromString(mode)) < 0) { + virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unkown mode has been specified")); + goto error; + } + def->data.direct.mode = m; + } else + def->data.direct.mode = VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA; + + def->data.direct.linkdev = dev; + dev = NULL; + + break; } if (ifname != NULL) { @@ -4740,6 +4777,13 @@ virDomainNetDefFormat(virBufferPtr buf, def->data.internal.name); break; + case VIR_DOMAIN_NET_TYPE_DIRECT: + virBufferEscapeString(buf, " <source dev='%s'", + def->data.direct.linkdev); + virBufferVSprintf(buf, " mode='%s'", + virDomainNetdevMacvtapTypeToString(def->data.direct.mode)); + virBufferAddLit(buf, "/>\n"); + break; } if (def->ifname) Index: libvirt-macvtap/src/conf/domain_conf.h =================================================================== --- libvirt-macvtap.orig/src/conf/domain_conf.h +++ libvirt-macvtap/src/conf/domain_conf.h @@ -211,11 +211,22 @@ enum virDomainNetType { VIR_DOMAIN_NET_TYPE_NETWORK, VIR_DOMAIN_NET_TYPE_BRIDGE, VIR_DOMAIN_NET_TYPE_INTERNAL, + VIR_DOMAIN_NET_TYPE_DIRECT, VIR_DOMAIN_NET_TYPE_LAST, }; +/* the mode type for macvtap devices */ +enum virDomainNetdevMacvtapType { + VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA, + VIR_DOMAIN_NETDEV_MACVTAP_MODE_PRIVATE, + VIR_DOMAIN_NETDEV_MACVTAP_MODE_BRIDGE, + + VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST, +}; + + /* Stores the virtual network interface configuration */ typedef struct _virDomainNetDef virDomainNetDef; typedef virDomainNetDef *virDomainNetDefPtr; @@ -244,6 +255,10 @@ struct _virDomainNetDef { struct { char *name; } internal; + struct { + char *linkdev; + int mode; + } direct; } data; char *ifname; virDomainDeviceInfo info; @@ -897,4 +912,6 @@ VIR_ENUM_DECL(virDomainGraphics) VIR_ENUM_DECL(virDomainState) VIR_ENUM_DECL(virDomainSeclabel) +VIR_ENUM_DECL(virDomainNetdevMacvtap) + #endif /* __DOMAIN_CONF_H */
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list