]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-wfp: Register for WFP Net events
authorMartin Willi <martin@revosec.ch>
Thu, 19 Dec 2013 08:48:43 +0000 (09:48 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 14:32:09 +0000 (16:32 +0200)
src/libcharon/plugins/kernel_wfp/kernel_wfp_compat.c
src/libcharon/plugins/kernel_wfp/kernel_wfp_ipsec.c

index 2be3691595410573d55d24e48bb07c365cc7861f..4296e147c24d3cd071cf639211da3a050a08d17a 100644 (file)
@@ -112,3 +112,10 @@ STUB(fwpuclnt, DWORD, IPsecSaContextUpdate0, 24,
 STUB(fwpuclnt, DWORD, IPsecSaContextEnum1, 40,
        HANDLE engineHandle, HANDLE enumHandle, UINT32 numEntriesRequested,
        void ***entries, UINT32 *numEntriesReturned)
+
+STUB(fwpuclnt, DWORD, FwpmNetEventSubscribe0, 40,
+       HANDLE engineHandle, const void *subscription, void(*callback)(),
+       void *context, HANDLE *eventsHandle)
+
+STUB(fwpuclnt, DWORD, FwpmNetEventUnsubscribe0, 16,
+       HANDLE engineHandle, HANDLE eventsHandle)
index a658fd150bf64892b266389d75bdbb8e66225e8f..da5e3cea915a4446fc5c589830cb466ead06b814 100644 (file)
@@ -80,6 +80,11 @@ struct private_kernel_wfp_ipsec_t {
         * Provider charon registers as
         */
        FWPM_PROVIDER0 provider;
+
+       /**
+        * Event handle
+        */
+       HANDLE event;
 };
 
 /**
@@ -1262,6 +1267,32 @@ static bool install(private_kernel_wfp_ipsec_t *this, entry_t *entry)
        }
 }
 
+/**
+ * FwpmNetEventSubscribe0() callback
+ */
+static void event_callback(private_kernel_wfp_ipsec_t *this,
+                                                  const FWPM_NET_EVENT1 *event)
+{
+}
+
+/**
+ * Register for net events
+ */
+static bool register_events(private_kernel_wfp_ipsec_t *this)
+{
+       FWPM_NET_EVENT_SUBSCRIPTION0 subscription = {};
+       DWORD res;
+
+       res = FwpmNetEventSubscribe0(this->handle, &subscription,
+                                                                (void*)event_callback, this, &this->event);
+       if (res != ERROR_SUCCESS)
+       {
+               DBG1(DBG_KNL, "registering for WFP events failed: 0x%08x", res);
+               return FALSE;
+       }
+       return TRUE;
+}
+
 METHOD(kernel_ipsec_t, get_features, kernel_feature_t,
        private_kernel_wfp_ipsec_t *this)
 {
@@ -1800,6 +1831,10 @@ METHOD(kernel_ipsec_t, destroy, void,
 {
        if (this->handle)
        {
+               if (this->event)
+               {
+                       FwpmNetEventUnsubscribe0(this->handle, this->event);
+               }
                FwpmProviderDeleteByKey0(this->handle, &this->provider.providerKey);
                FwpmEngineClose0(this->handle);
        }
@@ -1883,5 +1918,11 @@ kernel_wfp_ipsec_t *kernel_wfp_ipsec_create()
                return NULL;
        }
 
+       if (!register_events(this))
+       {
+               destroy(this);
+               return NULL;
+       }
+
        return &this->public;
 }