This patch extends the domain XML processing to parse the top level referenced filter along with potentially provided parameters and also converts the internal data back into XML representation. Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx> Signed-off-by: Gerhard Stenzel <gerhard.stenzel@xxxxxxxxxx>
--- src/conf/domain_conf.c | 39 +++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 +++ 2 files changed, 42 insertions(+) Index: libvirt-acl/src/conf/domain_conf.c =================================================================== --- libvirt-acl.orig/src/conf/domain_conf.c +++ libvirt-acl/src/conf/domain_conf.c @@ -42,6 +42,7 @@ #include "logging.h" #include "network.h" #include "macvtap.h" +#include "nwfilter_conf.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -456,6 +457,9 @@ void virDomainNetDefFree(virDomainNetDef virDomainDeviceInfoClear(&def->info); + VIR_FREE(def->filter); + virNWFilterHashTableFree(def->filterparams); + VIR_FREE(def); } @@ -1724,9 +1728,11 @@ virDomainNetDefParseXML(virCapsPtr caps, char *address = NULL; char *port = NULL; char *model = NULL; + char *filter = NULL; char *internal = NULL; char *devaddr = NULL; char *mode = NULL; + virNWFilterHashTablePtr filterparams = NULL; if (VIR_ALLOC(def) < 0) { virReportOOMError(); @@ -1795,6 +1801,9 @@ virDomainNetDefParseXML(virCapsPtr caps, script = virXMLPropString(cur, "path"); } else if (xmlStrEqual (cur->name, BAD_CAST "model")) { model = virXMLPropString(cur, "type"); + } else if (xmlStrEqual (cur->name, BAD_CAST "filterref")) { + filter = virXMLPropString(cur, "filter"); + filterparams = virNWFilterParseParamAttributes(cur); } else if ((flags & VIR_DOMAIN_XML_INTERNAL_STATUS) && xmlStrEqual(cur->name, BAD_CAST "state")) { /* Legacy back-compat. Don't add any more attributes here */ @@ -1970,6 +1979,22 @@ virDomainNetDefParseXML(virCapsPtr caps, model = NULL; } + if (filter != NULL) { + switch (def->type) { + case VIR_DOMAIN_NET_TYPE_ETHERNET: + case VIR_DOMAIN_NET_TYPE_NETWORK: + case VIR_DOMAIN_NET_TYPE_BRIDGE: + case VIR_DOMAIN_NET_TYPE_DIRECT: + def->filter = filter; + filter = NULL; + def->filterparams = filterparams; + filterparams = NULL; + break; + default: + break; + } + } + cleanup: VIR_FREE(macaddr); VIR_FREE(network); @@ -1980,10 +2005,12 @@ cleanup: VIR_FREE(script); VIR_FREE(bridge); VIR_FREE(model); + VIR_FREE(filter); VIR_FREE(type); VIR_FREE(internal); VIR_FREE(devaddr); VIR_FREE(mode); + virNWFilterHashTableFree(filterparams); return def; @@ -4878,6 +4905,7 @@ virDomainNetDefFormat(virBufferPtr buf, int flags) { const char *type = virDomainNetTypeToString(def->type); + char *attrs; if (!type) { virDomainReportError(VIR_ERR_INTERNAL_ERROR, @@ -4952,6 +4980,17 @@ virDomainNetDefFormat(virBufferPtr buf, if (def->model) virBufferEscapeString(buf, " <model type='%s'/>\n", def->model); + if (def->filter) { + virBufferEscapeString(buf, " <filterref filter='%s'", + def->filter); + attrs = virNWFilterFormatParamAttributes(def->filterparams, + " "); + if (!attrs || strlen(attrs) <= 1) + virBufferAddLit(buf, "/>\n"); + else + virBufferVSprintf(buf, ">\n%s </filterref>\n", attrs); + VIR_FREE(attrs); + } if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; Index: libvirt-acl/src/conf/domain_conf.h =================================================================== --- libvirt-acl.orig/src/conf/domain_conf.h +++ libvirt-acl/src/conf/domain_conf.h @@ -36,6 +36,8 @@ # include "threads.h" # include "hash.h" # include "network.h" +# include "nwfilter_params.h" +# include "nwfilter_conf.h" /* Private component of virDomainXMLFlags */ typedef enum { @@ -282,6 +284,8 @@ struct _virDomainNetDef { } data; char *ifname; virDomainDeviceInfo info; + char *filter; + virNWFilterHashTablePtr filterparams; }; enum virDomainChrTargetType {
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list