[PATCH v2 19/27] conf: add a virFirewall object to virNetworkObj

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This virFirewall object will store the list of actions required to
remove the firewall that was added for the currently active instance
of the network, so it has been named "fwRemoval".

There are no uses of the fwRemoval object in the virNetworkObj yet,
but everything is in place to add it to the XML when formatted, parse
it from the XML when reading network status, and free the virFirewall
object when the virNetworkObj is freed.

Signed-off-by: Laine Stump <laine@xxxxxxxxxx>
---
 src/conf/virnetworkobj.c | 39 +++++++++++++++++++++++++++++++++++++++
 src/conf/virnetworkobj.h | 11 +++++++++++
 src/libvirt_private.syms |  3 +++
 3 files changed, 53 insertions(+)

diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index d5aa121e20..3501c8cab7 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -55,6 +55,11 @@ struct _virNetworkObj {
 
     unsigned int taint;
 
+    /* fwRemoval contains all commands needed to remove the firewall
+     * that was added for this network.
+     */
+    virFirewall *fwRemoval;
+
     /* Immutable pointer, self locking APIs */
     virMacMap *macmap;
 
@@ -239,6 +244,28 @@ virNetworkObjSetFloorSum(virNetworkObj *obj,
 }
 
 
+virFirewall **
+virNetworkObjGetFwRemovalPtr(virNetworkObj *obj)
+{
+    return &obj->fwRemoval;
+}
+
+
+virFirewall *
+virNetworkObjGetFwRemoval(virNetworkObj *obj)
+{
+    return obj->fwRemoval;
+}
+
+
+void
+virNetworkObjSetFwRemoval(virNetworkObj *obj,
+                          virFirewall *fwRemoval)
+{
+    obj->fwRemoval = fwRemoval;
+}
+
+
 void
 virNetworkObjSetMacMap(virNetworkObj *obj,
                        virMacMap **macmap)
@@ -444,6 +471,7 @@ virNetworkObjDispose(void *opaque)
     virNetworkDefFree(obj->newDef);
     virBitmapFree(obj->classIdMap);
     virObjectUnref(obj->macmap);
+    virFirewallFree(obj->fwRemoval);
 }
 
 
@@ -792,6 +820,9 @@ virNetworkObjFormat(virNetworkObj *obj,
     if (virNetworkDefFormatBuf(&buf, obj->def, xmlopt, flags) < 0)
         return NULL;
 
+    if (obj->fwRemoval && virFirewallFormat(&buf, obj->fwRemoval) < 0)
+        return NULL;
+
     virBufferAdjustIndent(&buf, -2);
     virBufferAddLit(&buf, "</networkstatus>");
 
@@ -826,6 +857,7 @@ virNetworkLoadState(virNetworkObjList *nets,
     g_autofree char *configFile = NULL;
     g_autoptr(virNetworkDef) def = NULL;
     virNetworkObj *obj = NULL;
+    g_autoptr(virFirewall) fwRemoval = NULL;
     g_autoptr(xmlDoc) xml = NULL;
     xmlNodePtr node = NULL;
     g_autoptr(xmlXPathContext) ctxt = NULL;
@@ -868,6 +900,7 @@ virNetworkLoadState(virNetworkObjList *nets,
         g_autofree char *classIdStr = NULL;
         g_autofree char *floor_sum = NULL;
         g_autofree xmlNodePtr *nodes = NULL;
+        xmlNodePtr fwNode;
 
         ctxt->node = node;
         if ((classIdStr = virXPathString("string(./class_id[1]/@bitmap)",
@@ -902,6 +935,10 @@ virNetworkLoadState(virNetworkObjList *nets,
                 taint |= (1 << flag);
             }
         }
+        if ((fwNode = virXPathNode("./firewall", ctxt)) &&
+            virFirewallParseXML(&fwRemoval, fwNode, ctxt) < 0) {
+            return NULL;
+        }
     }
 
     /* create the object */
@@ -910,6 +947,8 @@ virNetworkLoadState(virNetworkObjList *nets,
 
     def = NULL;
 
+    virNetworkObjSetFwRemoval(obj, g_steal_pointer(&fwRemoval));
+
     /* assign status data stored in the network object */
     if (classIdMap) {
         virBitmapFree(obj->classIdMap);
diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h
index d3847d3422..d35e495961 100644
--- a/src/conf/virnetworkobj.h
+++ b/src/conf/virnetworkobj.h
@@ -23,6 +23,7 @@
 
 #include "network_conf.h"
 #include "virnetworkportdef.h"
+#include "virfirewall.h"
 
 typedef struct _virNetworkObj virNetworkObj;
 
@@ -76,6 +77,16 @@ void
 virNetworkObjSetFloorSum(virNetworkObj *obj,
                          unsigned long long floor_sum);
 
+virFirewall **
+virNetworkObjGetFwRemovalPtr(virNetworkObj *obj);
+
+virFirewall *
+virNetworkObjGetFwRemoval(virNetworkObj *obj);
+
+void
+virNetworkObjSetFwRemoval(virNetworkObj *obj,
+                          virFirewall *fwRemoval);
+
 void
 virNetworkObjSetMacMap(virNetworkObj *obj,
                        virMacMap **macmap);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index aa253a238b..b69cf5a060 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1299,6 +1299,8 @@ virNetworkObjGetClassIdMap;
 virNetworkObjGetDef;
 virNetworkObjGetDnsmasqPid;
 virNetworkObjGetFloorSum;
+virNetworkObjGetFwRemoval;
+virNetworkObjGetFwRemovalPtr;
 virNetworkObjGetMacMap;
 virNetworkObjGetMetadata;
 virNetworkObjGetNewDef;
@@ -1330,6 +1332,7 @@ virNetworkObjSetDef;
 virNetworkObjSetDefTransient;
 virNetworkObjSetDnsmasqPid;
 virNetworkObjSetFloorSum;
+virNetworkObjSetFwRemoval;
 virNetworkObjSetMacMap;
 virNetworkObjSetMetadata;
 virNetworkObjTaint;
-- 
2.44.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux