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