diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b8f82ab0ee..561fa22884 100644 --- a/src/conf/domain_conf.c +++ b/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_NET_TYPE_LAST, "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_DOMAIN_SECLABEL_LAST, "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(virDomainNetDefPtr def) 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 'dev' attribute specified with ")); + 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, " data.direct.linkdev); + virBufferVSprintf(buf, " mode='%s'", + virDomainNetdevMacvtapTypeToString(def->data.direct.mode)); + virBufferAddLit(buf, "/>\n"); + break; } if (def->ifname) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 07c9866871..231d8c8911 100644 --- a/src/conf/domain_conf.h +++ b/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 */ diff --git a/src/util/macvtap.h b/src/util/macvtap.h new file mode 100644 index 0000000000..e69de29bb2