|
|
c480ed |
From a8234641ad57553aa054bded71ed97c94f3100f1 Mon Sep 17 00:00:00 2001
|
|
|
c480ed |
Message-Id: <a8234641ad57553aa054bded71ed97c94f3100f1@dist-git>
|
|
|
c480ed |
From: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
|
|
|
c480ed |
Date: Wed, 5 Jun 2019 14:51:10 +0200
|
|
|
c480ed |
Subject: [PATCH] nwfilter: fix adding std MAC and IP values to filter binding
|
|
|
c480ed |
MIME-Version: 1.0
|
|
|
c480ed |
Content-Type: text/plain; charset=UTF-8
|
|
|
c480ed |
Content-Transfer-Encoding: 8bit
|
|
|
c480ed |
|
|
|
c480ed |
Commit d1a7c08eb changed filter instantiation code to ignore MAC and IP
|
|
|
c480ed |
variables explicitly specified for filter binding. It just replaces
|
|
|
c480ed |
explicit values with values associated with the binding. Before the
|
|
|
c480ed |
commit virNWFilterCreateVarsFrom was used so that explicit value
|
|
|
c480ed |
take precedence. Let's bring old behavior back.
|
|
|
c480ed |
|
|
|
c480ed |
This is useful. For example if domain has two interfaces it makes
|
|
|
c480ed |
sense to list both mac adresses in MAC var of every interface
|
|
|
c480ed |
filterref. So that if guest make a bond of these interfaces
|
|
|
c480ed |
and start sending frames with one of the mac adresses from
|
|
|
c480ed |
both interfaces we can pass outgress traffic from both
|
|
|
c480ed |
interfaces too.
|
|
|
c480ed |
|
|
|
c480ed |
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
c480ed |
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
|
|
|
c480ed |
(cherry picked from commit 01e11ebcb6e8f24662b7c67b70134c192785691c)
|
|
|
c480ed |
|
|
|
c480ed |
https://bugzilla.redhat.com/show_bug.cgi?id=1691356
|
|
|
c480ed |
|
|
|
c480ed |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c480ed |
Acked-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
c480ed |
---
|
|
|
c480ed |
src/nwfilter/nwfilter_gentech_driver.c | 92 +++++++++-----------------
|
|
|
c480ed |
1 file changed, 32 insertions(+), 60 deletions(-)
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
|
|
|
c480ed |
index e5dea91f83..ece5d28f41 100644
|
|
|
c480ed |
--- a/src/nwfilter/nwfilter_gentech_driver.c
|
|
|
c480ed |
+++ b/src/nwfilter/nwfilter_gentech_driver.c
|
|
|
c480ed |
@@ -128,60 +128,6 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst)
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
-/**
|
|
|
c480ed |
- * virNWFilterVarHashmapAddStdValues:
|
|
|
c480ed |
- * @tables: pointer to hash tabel to add values to
|
|
|
c480ed |
- * @macaddr: The string of the MAC address to add to the hash table,
|
|
|
c480ed |
- * may be NULL
|
|
|
c480ed |
- * @ipaddr: The string of the IP address to add to the hash table;
|
|
|
c480ed |
- * may be NULL
|
|
|
c480ed |
- *
|
|
|
c480ed |
- * Returns 0 in case of success, -1 in case an error happened with
|
|
|
c480ed |
- * error having been reported.
|
|
|
c480ed |
- *
|
|
|
c480ed |
- * Adds a couple of standard keys (MAC, IP) to the hash table.
|
|
|
c480ed |
- */
|
|
|
c480ed |
-static int
|
|
|
c480ed |
-virNWFilterVarHashmapAddStdValues(virHashTablePtr table,
|
|
|
c480ed |
- const char *macaddr,
|
|
|
c480ed |
- const virNWFilterVarValue *ipaddr)
|
|
|
c480ed |
-{
|
|
|
c480ed |
- virNWFilterVarValue *val;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (macaddr) {
|
|
|
c480ed |
- val = virNWFilterVarValueCreateSimpleCopyValue(macaddr);
|
|
|
c480ed |
- if (!val)
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virHashUpdateEntry(table,
|
|
|
c480ed |
- NWFILTER_STD_VAR_MAC,
|
|
|
c480ed |
- val) < 0) {
|
|
|
c480ed |
- virNWFilterVarValueFree(val);
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
- "%s", _("Could not add variable 'MAC' to hashmap"));
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (ipaddr) {
|
|
|
c480ed |
- val = virNWFilterVarValueCopy(ipaddr);
|
|
|
c480ed |
- if (!val)
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virHashUpdateEntry(table,
|
|
|
c480ed |
- NWFILTER_STD_VAR_IP,
|
|
|
c480ed |
- val) < 0) {
|
|
|
c480ed |
- virNWFilterVarValueFree(val);
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
- "%s", _("Could not add variable 'IP' to hashmap"));
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- return 0;
|
|
|
c480ed |
-}
|
|
|
c480ed |
-
|
|
|
c480ed |
-
|
|
|
c480ed |
/**
|
|
|
c480ed |
* Convert a virHashTable into a string of comma-separated
|
|
|
c480ed |
* variable names.
|
|
|
c480ed |
@@ -707,6 +653,28 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techdriver,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virNWFilterVarHashmapAddStdValue(virHashTablePtr table,
|
|
|
c480ed |
+ const char *var,
|
|
|
c480ed |
+ const char *value)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ virNWFilterVarValue *val;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virHashLookup(table, var))
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!(val = virNWFilterVarValueCreateSimpleCopyValue(value)))
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virHashAddEntry(table, var, val) < 0) {
|
|
|
c480ed |
+ virNWFilterVarValueFree(val);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
/*
|
|
|
c480ed |
* Call this function while holding the NWFilter filter update lock
|
|
|
c480ed |
*/
|
|
|
c480ed |
@@ -719,7 +687,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverStatePtr driver,
|
|
|
c480ed |
bool forceWithPendingReq,
|
|
|
c480ed |
bool *foundNewFilter)
|
|
|
c480ed |
{
|
|
|
c480ed |
- int rc;
|
|
|
c480ed |
+ int rc = -1;
|
|
|
c480ed |
const char *drvname = EBIPTABLES_DRIVER_ID;
|
|
|
c480ed |
virNWFilterTechDriverPtr techdriver;
|
|
|
c480ed |
virNWFilterObjPtr obj;
|
|
|
c480ed |
@@ -745,14 +713,18 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverStatePtr driver,
|
|
|
c480ed |
return -1;
|
|
|
c480ed |
|
|
|
c480ed |
virMacAddrFormat(&binding->mac, vmmacaddr);
|
|
|
c480ed |
+ if (virNWFilterVarHashmapAddStdValue(binding->filterparams,
|
|
|
c480ed |
+ NWFILTER_STD_VAR_MAC,
|
|
|
c480ed |
+ vmmacaddr) < 0)
|
|
|
c480ed |
+ goto err_exit;
|
|
|
c480ed |
|
|
|
c480ed |
ipaddr = virNWFilterIPAddrMapGetIPAddr(binding->portdevname);
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virNWFilterVarHashmapAddStdValues(binding->filterparams,
|
|
|
c480ed |
- vmmacaddr, ipaddr) < 0) {
|
|
|
c480ed |
- rc = -1;
|
|
|
c480ed |
+ if (ipaddr &&
|
|
|
c480ed |
+ virNWFilterVarHashmapAddStdValue(binding->filterparams,
|
|
|
c480ed |
+ NWFILTER_STD_VAR_IP,
|
|
|
c480ed |
+ virNWFilterVarValueGetSimple(ipaddr)) < 0)
|
|
|
c480ed |
goto err_exit;
|
|
|
c480ed |
- }
|
|
|
c480ed |
+
|
|
|
c480ed |
|
|
|
c480ed |
filter = virNWFilterObjGetDef(obj);
|
|
|
c480ed |
|
|
|
c480ed |
--
|
|
|
c480ed |
2.22.0
|
|
|
c480ed |
|