reintegrated bus-refactoring branch
authorMartin Willi <martin@strongswan.org>
Tue, 14 Oct 2008 08:52:13 +0000 (08:52 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 14 Oct 2008 08:52:13 +0000 (08:52 -0000)
30 files changed:
src/charon/bus/bus.c
src/charon/bus/bus.h
src/charon/bus/listeners/file_logger.c
src/charon/bus/listeners/file_logger.h
src/charon/bus/listeners/sys_logger.c
src/charon/bus/listeners/sys_logger.h
src/charon/control/controller.c
src/charon/control/controller.h
src/charon/daemon.c
src/charon/plugins/nm/nm_service.c
src/charon/plugins/smp/smp.c
src/charon/plugins/sql/sql_logger.c
src/charon/plugins/sql/sql_logger.h
src/charon/plugins/stroke/stroke_control.c
src/charon/plugins/stroke/stroke_socket.c
src/charon/processing/jobs/initiate_mediation_job.c
src/charon/sa/child_sa.c
src/charon/sa/child_sa.h
src/charon/sa/connect_manager.c
src/charon/sa/ike_sa.c
src/charon/sa/ike_sa.h
src/charon/sa/task_manager.c
src/charon/sa/tasks/child_create.c
src/charon/sa/tasks/child_delete.c
src/charon/sa/tasks/ike_auth.c
src/charon/sa/tasks/ike_delete.c
src/charon/sa/tasks/ike_init.c
src/charon/sa/tasks/ike_me.c
src/charon/sa/tasks/ike_reauth.c
src/charon/sa/tasks/ike_rekey.c

index c080387..763ea0b 100644 (file)
 #include <daemon.h>
 #include <utils/mutex.h>
 
-ENUM(signal_names, SIG_ANY, SIG_MAX,
-       /** should not get printed */
-       "SIG_ANY",
-       /** debugging message types */
+ENUM(debug_names, DBG_DMN, DBG_LIB,
        "DMN",
        "MGR",
        "IKE",
@@ -36,19 +33,6 @@ ENUM(signal_names, SIG_ANY, SIG_MAX,
        "NET",
        "ENC",
        "LIB",
-       /** should not get printed */
-       "SIG_DBG_MAX",
-       /** all level0 signals are AUDIT signals */
-       "AUD", "AUD", "AUD",
-       "AUD", "AUD", "AUD",
-       "AUD", "AUD", "AUD",
-       "AUD", "AUD", "AUD",
-       "AUD", "AUD", "AUD",
-       "AUD", "AUD", "AUD",
-       "AUD", "AUD", "AUD",
-       "AUD", "AUD", "AUD",
-       /** should not get printed */
-       "SIG_MAX",
 );
 
 typedef struct private_bus_t private_bus_t;
@@ -93,7 +77,7 @@ struct entry_t {
        /**
         * registered listener interface
         */
-       bus_listener_t *listener;
+       listener_t *listener;
        
        /**
         * is this a active listen() call with a blocking thread
@@ -114,7 +98,7 @@ struct entry_t {
 /**
  * create a listener entry
  */
-static entry_t *entry_create(bus_listener_t *listener, bool blocker)
+static entry_t *entry_create(listener_t *listener, bool blocker)
 {
        entry_t *this = malloc_thing(entry_t);
        
@@ -160,7 +144,7 @@ static int get_thread_number(private_bus_t *this)
 /**
  * Implementation of bus_t.add_listener.
  */
-static void add_listener(private_bus_t *this, bus_listener_t *listener)
+static void add_listener(private_bus_t *this, listener_t *listener)
 {
        this->mutex->lock(this->mutex);
        this->listeners->insert_last(this->listeners, entry_create(listener, FALSE));
@@ -170,23 +154,23 @@ static void add_listener(private_bus_t *this, bus_listener_t *listener)
 /**
  * Implementation of bus_t.remove_listener.
  */
-static void remove_listener(private_bus_t *this, bus_listener_t *listener)
+static void remove_listener(private_bus_t *this, listener_t *listener)
 {
-       iterator_t *iterator;
+       enumerator_t *enumerator;
        entry_t *entry;
 
        this->mutex->lock(this->mutex);
-       iterator = this->listeners->create_iterator(this->listeners, TRUE);
-       while (iterator->iterate(iterator, (void**)&entry))
+       enumerator = this->listeners->create_enumerator(this->listeners);
+       while (enumerator->enumerate(enumerator, &entry))
        {
                if (entry->listener == listener)
                {
-                       iterator->remove(iterator);
+                       this->listeners->remove_at(this->listeners, enumerator);
                        entry_destroy(entry);
                        break;
                }
        }
-       iterator->destroy(iterator);
+       enumerator->destroy(enumerator);
        this->mutex->unlock(this->mutex);
 }
 
@@ -207,26 +191,14 @@ struct cleanup_data_t {
  */
 static void listener_cleanup(cleanup_data_t *data)
 {
-       iterator_t *iterator;
-       entry_t *entry;
-
-       iterator = data->this->listeners->create_iterator(data->this->listeners, TRUE);
-       while (iterator->iterate(iterator, (void**)&entry))
-       {
-               if (entry == data->entry)
-               {
-                       iterator->remove(iterator);
-                       entry_destroy(entry);
-                       break;
-               }
-       }
-       iterator->destroy(iterator);
+       data->this->listeners->remove(data->this->listeners, data->entry, NULL);
+       entry_destroy(data->entry);
 }
 
 /**
  * Implementation of bus_t.listen.
  */
-static void listen_(private_bus_t *this, bus_listener_t *listener, job_t *job)
+static void listen_(private_bus_t *this, listener_t *listener, job_t *job)
 {
        int old;
        cleanup_data_t data;
@@ -267,33 +239,31 @@ typedef struct {
        ike_sa_t *ike_sa;
        /** invoking thread */
        long thread;
-       /** signal type */
-       signal_t signal;
-       /** signal level */
+       /** debug group */
+       debug_t group;
+       /** debug level */
        level_t level;
-       /** signal specific user data */
-       void *user;
        /** format string */
        char *format;
        /** argument list */
        va_list args;
-} signal_data_t;
+} log_data_t;
 
 /**
- * listener invocation as a list remove callback
+ * listener->log() invocation as a list remove callback
  */
-static bool signal_cb(entry_t *entry, signal_data_t *data)
+static bool log_cb(entry_t *entry, log_data_t *data)
 {
        va_list args;
 
-       if (entry->calling)
+       if (entry->calling || !entry->listener->log)
        {       /* avoid recursive calls */
                return FALSE;
        }
        entry->calling = TRUE;
        va_copy(args, data->args);
-       if (!entry->listener->signal(entry->listener, data->signal, data->level,
-                                       data->thread, data->ike_sa, data->user, data->format, args))
+       if (!entry->listener->log(entry->listener, data->group, data->level,
+                                                         data->thread, data->ike_sa, data->format, args))
        {
                if (entry->blocker)
                {
@@ -314,43 +284,148 @@ static bool signal_cb(entry_t *entry, signal_data_t *data)
 }
 
 /**
- * Implementation of bus_t.vsignal.
+ * Implementation of bus_t.vlog.
  */
-static void vsignal(private_bus_t *this, signal_t signal, level_t level,
-                                       void *user, char* format, va_list args)
+static void vlog(private_bus_t *this, debug_t group, level_t level,
+                                char* format, va_list args)
 {
-       signal_data_t data;
+       log_data_t data;
        
        data.ike_sa = pthread_getspecific(this->thread_sa);
        data.thread = get_thread_number(this);
-       data.signal = signal;
+       data.group = group;
        data.level = level;
-       data.user = user;
        data.format = format;
        va_copy(data.args, args);
        
        this->mutex->lock(this->mutex);
-       /* we use the remove() method to invoke all listeners with small overhead */
-       this->listeners->remove(this->listeners, &data, (void*)signal_cb);
+       /* We use the remove() method to invoke all listeners. This is cheap and
+        * does not require an allocation for this performance critical function. */
+       this->listeners->remove(this->listeners, &data, (void*)log_cb);
        this->mutex->unlock(this->mutex);
        
        va_end(data.args);
 }
 
 /**
- * Implementation of bus_t.signal.
+ * Implementation of bus_t.log.
  */
-static void signal_(private_bus_t *this, signal_t signal, level_t level, 
-                                       void* data, char* format, ...)
+static void log_(private_bus_t *this, debug_t group, level_t level,
+                                char* format, ...)
 {
        va_list args;
        
        va_start(args, format);
-       vsignal(this, signal, level, data, format, args);
+       vlog(this, group, level, format, args);
        va_end(args);
 }
 
 /**
+ * Implementation of bus_t.ike_state_change
+ */
+static void ike_state_change(private_bus_t *this, ike_sa_t *ike_sa,
+                                                        ike_sa_state_t state)
+{
+       enumerator_t *enumerator;
+       entry_t *entry;
+       
+       this->mutex->lock(this->mutex);
+       enumerator = this->listeners->create_enumerator(this->listeners);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (entry->listener->ike_state_change &&
+                       !entry->listener->ike_state_change(entry->listener, ike_sa, state))
+               {
+                       if (entry->blocker)
+                       {
+                               entry->blocker = FALSE;
+                               entry->condvar->signal(entry->condvar);
+                       }
+                       else
+                       {
+                               entry_destroy(entry);
+                       }
+                       this->listeners->remove_at(this->listeners, enumerator);
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       this->mutex->unlock(this->mutex);
+}
+
+/**
+ * Implementation of bus_t.child_state_change
+ */
+static void child_state_change(private_bus_t *this, child_sa_t *child_sa,
+                                                          child_sa_state_t state)
+{
+       enumerator_t *enumerator;
+       ike_sa_t *ike_sa;
+       entry_t *entry;
+       
+       ike_sa = pthread_getspecific(this->thread_sa);
+       
+       this->mutex->lock(this->mutex);
+       enumerator = this->listeners->create_enumerator(this->listeners);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (entry->listener->child_state_change &&
+                       !entry->listener->child_state_change(entry->listener, ike_sa,
+                                                                                                child_sa, state))
+               {
+                       if (entry->blocker)
+                       {
+                               entry->blocker = FALSE;
+                               entry->condvar->signal(entry->condvar);
+                       }
+                       else
+                       {
+                               entry_destroy(entry);
+                       }
+                       this->listeners->remove_at(this->listeners, enumerator);
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       this->mutex->unlock(this->mutex);
+}
+
+/**
+ * Implementation of bus_t.message
+ */
+static void message(private_bus_t *this, message_t *message, bool incoming)
+{
+       enumerator_t *enumerator;
+       ike_sa_t *ike_sa;
+       entry_t *entry;
+       
+       ike_sa = pthread_getspecific(this->thread_sa);
+       
+       this->mutex->lock(this->mutex);
+       enumerator = this->listeners->create_enumerator(this->listeners);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (entry->listener->message &&
+                       !entry->listener->message(entry->listener, ike_sa, message, incoming))
+               {
+                       if (entry->blocker)
+                       {
+                               entry->blocker = FALSE;
+                               entry->condvar->signal(entry->condvar);
+                       }
+                       else
+                       {
+                               entry_destroy(entry);
+                       }
+                       this->listeners->remove_at(this->listeners, enumerator);
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       this->mutex->unlock(this->mutex);
+}
+
+/**
  * Implementation of bus_t.destroy.
  */
 static void destroy(private_bus_t *this)
@@ -367,12 +442,15 @@ bus_t *bus_create()
 {
        private_bus_t *this = malloc_thing(private_bus_t);
        
-       this->public.add_listener = (void(*)(bus_t*,bus_listener_t*))add_listener;
-       this->public.remove_listener = (void(*)(bus_t*,bus_listener_t*))remove_listener;
-       this->public.listen = (void(*)(bus_t*, bus_listener_t *listener, job_t *job))listen_;
+       this->public.add_listener = (void(*)(bus_t*,listener_t*))add_listener;
+       this->public.remove_listener = (void(*)(bus_t*,listener_t*))remove_listener;
+       this->public.listen = (void(*)(bus_t*, listener_t *listener, job_t *job))listen_;
        this->public.set_sa = (void(*)(bus_t*,ike_sa_t*))set_sa;
-       this->public.signal = (void(*)(bus_t*,signal_t,level_t,void*,char*,...))signal_;
-       this->public.vsignal = (void(*)(bus_t*,signal_t,level_t,void*,char*,va_list))vsignal;
+       this->public.log = (void(*)(bus_t*,debug_t,level_t,char*,...))log_;
+       this->public.vlog = (void(*)(bus_t*,debug_t,level_t,char*,va_list))vlog;
+       this->public.ike_state_change = (void(*)(bus_t*,ike_sa_t*,ike_sa_state_t))ike_state_change;
+       this->public.child_state_change = (void(*)(bus_t*,child_sa_t*,child_sa_state_t))child_state_change;
+       this->public.message = (void(*)(bus_t*, message_t *message, bool incoming))message;
        this->public.destroy = (void(*)(bus_t*)) destroy;
        
        this->listeners = linked_list_create();
index 30f6e97..041cfad 100644 (file)
@@ -23,9 +23,9 @@
 #ifndef BUS_H_
 #define BUS_H_
 
-typedef enum signal_t signal_t;
+typedef enum debug_t debug_t;
 typedef enum level_t level_t;
-typedef struct bus_listener_t bus_listener_t;
+typedef struct listener_t listener_t;
 typedef struct bus_t bus_t;
 
 #include <stdarg.h>
@@ -34,145 +34,82 @@ typedef struct bus_t bus_t;
 #include <sa/child_sa.h>
 #include <processing/jobs/job.h>
 
-
 /**
- * signals emitted by the daemon.
- *
- * Signaling is for different purporses. First, it allows debugging via
- * "debugging signal messages", sencondly, it allows to follow certain
- * mechanisms currently going on in the daemon. As we are multithreaded,
- * and multiple transactions are involved, it's not possible to follow
- * one connection setup without further infrastructure. These infrastructure
- * is provided by the bus and the signals the daemon emits to the bus.
- *
- * There are different scenarios to follow these signals, but all have
- * the same scheme. First, a START signal is emitted to indicate the daemon
- * has started to do something. After a start signal, a SUCCESS or a FAILED
- * signal of the same type follows. This allows to track the operation. Any
- * Debug signal betwee a START and a SUCCESS/FAILED belongs to that operation
- * if the IKE_SA is the same. The thread may change, as multiple threads
- * may be involved in a complex scenario.
+ * Debug message group.
  */
-enum signal_t {
-       /** pseudo signal, representing any other signal */
-       SIG_ANY,
-       
-       /** debugging message from daemon main loop */
+enum debug_t {
+       /** daemon main loop */
        DBG_DMN,
-       /** debugging message from IKE_SA_MANAGER */
+       /** IKE_SA_MANAGER */
        DBG_MGR,
-       /** debugging message from an IKE_SA */
+       /** IKE_SA */
        DBG_IKE,
-       /** debugging message from a CHILD_SA */
+       /** CHILD_SA */
        DBG_CHD,
-       /** debugging message from job processing */
+       /** job processing */
        DBG_JOB,
-       /** debugging message from configuration backends */
+       /** configuration backends */
        DBG_CFG,
-       /** debugging message from kernel interface */
+       /** kernel interface */
        DBG_KNL,
-       /** debugging message from networking */
+       /** networking/sockets */
        DBG_NET,
-       /** debugging message from message encoding/decoding */
+       /** message encoding/decoding */
        DBG_ENC,
-       /** debugging message from libstrongswan via logging hook */
+       /** libstrongswan via logging hook */
        DBG_LIB,
-       
-       /** number of debug signals */
+       /** number of groups */
        DBG_MAX,
-       
-       /** signals for IKE_SA establishment */
-       IKE_UP_START,
-       IKE_UP_SUCCESS,
-       IKE_UP_FAILED,
-       
-       /** signals for IKE_SA delete */
-       IKE_DOWN_START,
-       IKE_DOWN_SUCCESS,
-       IKE_DOWN_FAILED,
-       
-       /** signals for IKE_SA rekeying */
-       IKE_REKEY_START,
-       IKE_REKEY_SUCCESS,
-       IKE_REKEY_FAILED,
-       
-       /** signals for CHILD_SA establishment */
-       CHD_UP_START,
-       CHD_UP_SUCCESS,
-       CHD_UP_FAILED,
-       
-       /** signals for CHILD_SA delete */
-       CHD_DOWN_START,
-       CHD_DOWN_SUCCESS,
-       CHD_DOWN_FAILED,
-       
-       /** signals for CHILD_SA rekeying */
-       CHD_REKEY_START,
-       CHD_REKEY_SUCCESS,
-       CHD_REKEY_FAILED,
-       
-       /** signals for CHILD_SA routing */
-       CHD_ROUTE_START,
-       CHD_ROUTE_SUCCESS,
-       CHD_ROUTE_FAILED,
-       
-       /** signals for CHILD_SA routing */
-       CHD_UNROUTE_START,
-       CHD_UNROUTE_SUCCESS,
-       CHD_UNROUTE_FAILED,
-       
-       SIG_MAX
+       /** pseudo group with all groups */
+       DBG_ANY = DBG_MAX,
 };
 
 /**
- * short names of signals using 3 chars
+ * short names of debug message group.
  */
-extern enum_name_t *signal_names;
+extern enum_name_t *debug_names;
 
 /**
- * Signal levels used to control output verbosity.
+ * Debug levels used to control output verbosity.
  */
 enum level_t {
-       /** numerical levels from 0 to 4 */
-       LEVEL_0 = 0,
-       LEVEL_1 = 1,
-       LEVEL_2 = 2,
-       LEVEL_3 = 3,
-       LEVEL_4 = 4,
-       /** absolutely silent, no signal is emitted with this level */
-       LEVEL_SILENT = -1,
-       /** alias for numberical levels */
-       LEVEL_AUDIT = LEVEL_0,
-       LEVEL_CTRL = LEVEL_1,
-       LEVEL_CTRLMORE = LEVEL_2,
-       LEVEL_RAW = LEVEL_3,
-       LEVEL_PRIVATE = LEVEL_4,
+       /** absolutely silent */
+       LEVEL_SILENT =  -1,
+       /** most important auditing logs */
+       LEVEL_AUDIT =    0,
+       /** control flow */
+       LEVEL_CTRL =     1,
+       /** diagnose problems */
+       LEVEL_DIAG =     2,
+       /** raw binary blobs */
+       LEVEL_RAW =      3,
+       /** including sensitive data (private keys) */
+       LEVEL_PRIVATE =  4,
 };
 
 #ifndef DEBUG_LEVEL
 # define DEBUG_LEVEL 4
 #endif /* DEBUG_LEVEL */
 
+#if DEBUG_LEVEL >= 0
+#define DBG0(group, format, ...) charon->bus->log(charon->bus, group, 0, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL >= 0 */
 #if DEBUG_LEVEL >= 1
-/**
- * Log a debug message via the signal bus.
- *
- * @param signal       signal_t signal description
- * @param format       printf() style format string
- * @param ...          printf() style agument list
- */
-# define DBG1(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_1, NULL, format, ##__VA_ARGS__)
-#endif /* DEBUG_LEVEL */
+#define DBG1(group, format, ...) charon->bus->log(charon->bus, group, 1, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL >= 1 */
 #if DEBUG_LEVEL >= 2
-#define DBG2(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_2, NULL, format, ##__VA_ARGS__)
-#endif /* DEBUG_LEVEL */
+#define DBG2(group, format, ...) charon->bus->log(charon->bus, group, 2, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL >= 2 */
 #if DEBUG_LEVEL >= 3
-#define DBG3(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_3, NULL, format, ##__VA_ARGS__)
-#endif /* DEBUG_LEVEL */
+#define DBG3(group, format, ...) charon->bus->log(charon->bus, group, 3, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL >= 3 */
 #if DEBUG_LEVEL >= 4
-#define DBG4(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_4, NULL, format, ##__VA_ARGS__)
-#endif /* DEBUG_LEVEL */
+#define DBG4(group, format, ...) charon->bus->log(charon->bus, group, 4, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL >= 4 */
 
+#ifndef DBG0
+# define DBG0(...) {}
+#endif /* DBG0 */
 #ifndef DBG1
 # define DBG1(...) {}
 #endif /* DBG1 */
@@ -186,101 +123,90 @@ enum level_t {
 # define DBG4(...) {}
 #endif /* DBG4 */
 
-/**
- * Raise a signal for an IKE_SA event.
- *
- * @param sig          signal_t signal description
- * @param format       printf() style format string
- * @param ...          printf() style agument list
- */
-#define SIG_IKE(sig, format, ...) charon->bus->signal(charon->bus, IKE_##sig, LEVEL_0, NULL, format, ##__VA_ARGS__)
-
-/**
- * Raise a signal for an IKE event.
- *
- * @param sig          signal_t signal description
- * @param format       printf() style format string
- * @param ...          printf() style agument list
- */
-#define SIG_CHD(sig, chd, format, ...) charon->bus->signal(charon->bus, CHD_##sig, LEVEL_0, chd, format, ##__VA_ARGS__)
-
-/**
- * Get the type of a signal.
- *
- * A signal may be a debugging signal with a specific context. They have
- * a level specific for their context > 0. All audit signals use the
- * type 0. This allows filtering of singals by their type.
- *
- * @param signal       signal to get the type from
- * @return                     type of the signal, between 0..(DBG_MAX-1)
- */
-#define SIG_TYPE(sig) (sig > DBG_MAX ? SIG_ANY : sig)
-
 
 /**
- * Interface for registering at the signal bus.
- *
- * To receive signals from the bus, the client implementing the
- * bus_listener_t interface registers itself at the signal bus.
+ * Listener interface, listens to events if registered to the bus.
  */
-struct bus_listener_t {
+struct listener_t {
        
        /**
-        * Send a signal to a bus listener.
+        * Log a debugging message.
         *
-        * A numerical identification for the thread is included, as the
-        * associated IKE_SA, if any. Signal specifies the type of
-        * the event occured. The format string specifies
-        * an additional informational or error message with a printf() like
-        * variable argument list. This is in the va_list form, as forwarding
-        * a "..." parameters to functions is not (cleanly) possible.
         * The implementing signal function returns TRUE to stay registered
         * to the bus, or FALSE to unregister itself.
-        * Calling bus_t.signal() inside of a registered listener is possible,
+        * Calling bus_t.log() inside of a registered listener is possible,
         * but the bus does not invoke listeners recursively.
         *
         * @param singal        kind of the signal (up, down, rekeyed, ...)
         * @param level         verbosity level of the signal
         * @param thread        ID of the thread raised this signal
         * @param ike_sa        IKE_SA associated to the event
-        * @param data          additional signal specific user data
         * @param format        printf() style format string
         * @param args          vprintf() style va_list argument list
         " @return                      TRUE to stay registered, FALSE to unregister
         */
-       bool (*signal) (bus_listener_t *this, signal_t signal, level_t level,
-                                       int thread, ike_sa_t *ike_sa, void *data, 
-                                       char* format, va_list args);
+       bool (*log) (listener_t *this, debug_t group, level_t level, int thread,
+                                ike_sa_t *ike_sa, char* format, va_list args);
+       
+       /**
+        * Handle state changes in an IKE_SA.
+        *
+        * @param ike_sa        IKE_SA which changes its state
+        * @param state         new IKE_SA state this IKE_SA changes to
+        * @return                      TRUE to stay registered, FALSE to unregister
+        */
+       bool (*ike_state_change)(listener_t *this, ike_sa_t *ike_sa,
+                                                        ike_sa_state_t state);
+       
+       /**
+        * Handle state changes in a CHILD_SA.
+        *
+        * @param ike_sa        IKE_SA containing the affected CHILD_SA
+        * @param child_sa      CHILD_SA which changes its state
+        * @param state         new CHILD_SA state this CHILD_SA changes to
+        * @return                      TRUE to stay registered, FALSE to unregister
+        */
+       bool (*child_state_change)(listener_t *this, ike_sa_t *ike_sa,
+                                                          child_sa_t *child_sa, child_sa_state_t state);
+       
+       /**
+        * Hook called for received/sent messages of an IKE_SA.
+        *
+        * @param ike_sa        IKE_SA sending/receving a message
+        * @param message       message object
+        * @param incoming      TRUE for incoming messages, FALSE for outgoing
+        * @return                      TRUE to stay registered, FALSE to unregister
+        */
+       bool (*message)(listener_t *this, ike_sa_t *ike_sa, message_t *message,
+                                       bool incoming);
+
 };
 
 /**
- * Signal bus which sends signals to registered listeners.
+ * The bus receives events and sends them to all registered listeners.
  *
- * The signal bus is not much more than a multiplexer. A listener interested
- * in receiving event signals registers at the bus. Any signals sent to
- * are delivered to all registered listeners.
- * To deliver signals to threads, the blocking listen() call may be used
- * to wait for a signal.
+ * Any events sent to are delivered to all registered listeners. Threads
+ * may wait actively to events using the blocking listen() call.
  */
 struct bus_t {
        
        /**
         * Register a listener to the bus.
         *
-        * A registered listener receives all signals which are sent to the bus.
-        * The listener is passive; the thread which emitted the signal
+        * A registered listener receives all events which are sent to the bus.
+        * The listener is passive; the thread which emitted the event
         * processes the listener routine.
         *
         * @param listener      listener to register.
         */
-       void (*add_listener) (bus_t *this, bus_listener_t *listener);
+       void (*add_listener) (bus_t *this, listener_t *listener);
        
        /**
         * Unregister a listener from the bus.
         *
         * @param listener      listener to unregister.
         */
-       void (*remove_listener) (bus_t *this, bus_listener_t *listener);
+       void (*remove_listener) (bus_t *this, listener_t *listener);
        
        /**
         * Register a listener and block the calling thread.
@@ -288,69 +214,91 @@ struct bus_t {
         * This call registers a listener and blocks the calling thread until
         * its listeners function returns FALSE. This allows to wait for certain
         * events. The associated job is executed after the listener has been
-        * registered, this allows to listen on events we initiate with the job
-        * without missing any signals.
+        * registered: This allows to listen on events we initiate with the job,
+        * without missing any events to job may fire.
         *
         * @param listener      listener to register
         * @param job           job to execute asynchronously when registered, or NULL
         */
-       void (*listen)(bus_t *this, bus_listener_t *listener, job_t *job);
+       void (*listen)(bus_t *this, listener_t *listener, job_t *job);
        
        /**
         * Set the IKE_SA the calling thread is using.
         *
-        * To associate an received signal to an IKE_SA without passing it as
-        * parameter each time, the thread registers it's used IKE_SA each
-        * time it checked it out. Before checking it in, the thread unregisters
-        * the IKE_SA (by passing NULL). This IKE_SA is stored per-thread, so each
-        * thread has one IKE_SA registered (or not).
+        * To associate an received log message to an IKE_SA without passing it as
+        * parameter each time, the thread registers the currenlty used IKE_SA
+        * during check-out. Before check-in, the thread unregisters the IKE_SA. 
+        * This IKE_SA is stored per-thread, so each thread has its own IKE_SA
+        * registered.
         * 
         * @param ike_sa        ike_sa to register, or NULL to unregister
         */
        void (*set_sa) (bus_t *this, ike_sa_t *ike_sa);
        
        /**
-        * Send a signal to the bus.
+        * Send a log message to the bus.
         *
         * The signal specifies the type of the event occured. The format string
         * specifies an additional informational or error message with a
         * printf() like variable argument list.
-        * Some useful macros are available to shorten this call.
-        * @see SIG(), DBG1()
+        * Use the DBG() macros.
         *
-        * @param singal        kind of the signal (up, down, rekeyed, ...)
+        * @param group         debugging group
         * @param level         verbosity level of the signal
-        * @param data          additional signal specific user data
         * @param format        printf() style format string
         * @param ...           printf() style argument list
         */
-       void (*signal) (bus_t *this, signal_t signal, level_t level,
-                                       void *data, char* format, ...);
+       void (*log)(bus_t *this, debug_t group, level_t level, char* format, ...);
        
        /**
-        * Send a signal to the bus using va_list arguments.
+        * Send a log message to the bus using va_list arguments.
         *
         * Same as bus_t.signal(), but uses va_list argument list.
         *
-        * @param singal        kind of the signal (up, down, rekeyed, ...)
+        * @param group         kind of the signal (up, down, rekeyed, ...)
         * @param level         verbosity level of the signal
-        * @param data          additional signal specific user data
         * @param format        printf() style format string
         * @param args          va_list arguments
         */
-       void (*vsignal) (bus_t *this, signal_t signal, level_t level,
-                                        void *data, char* format, va_list args);
+       void (*vlog)(bus_t *this, debug_t group, level_t level,
+                                char* format, va_list args);
+       
+       /**
+        * Send a IKE_SA state change event to the bus.
+        *
+        * @param ike_sa        IKE_SA which changes its state
+        * @param state         new state IKE_SA changes to
+        */
+       void (*ike_state_change)(bus_t *this, ike_sa_t *ike_sa,
+                                                        ike_sa_state_t state);
+       
+       /**
+        * Send a CHILD_SA state change event to the bus.
+        *
+        * @param child_sa      CHILD_SA which changes its state
+        * @param state         new state CHILD_SA changes to
+        */
+       void (*child_state_change)(bus_t *this, child_sa_t *child_sa,
+                                                          child_sa_state_t state);
+       
+       /**
+        * Message send/receive hook.
+        *
+        * @param message       message to send/receive
+        * @param incoming      TRUE for incoming messages, FALSE for outgoing
+        */
+       void (*message)(bus_t *this, message_t *message, bool incoming);
        
        /**
-        * Destroy the signal bus.
+        * Destroy the event bus.
         */
        void (*destroy) (bus_t *this);
 };
 
 /**
- * Create the signal bus which multiplexes signals to its listeners.
+ * Create the event bus which forwards events to its listeners.
  *
- * @return             signal bus instance
+ * @return             event bus instance
  */
 bus_t *bus_create();
 
index d329067..82d5c27 100644 (file)
@@ -39,20 +39,18 @@ struct private_file_logger_t {
        FILE *out;
        
        /**
-        * Maximum level to log
+        * Maximum level to log, for each group
         */
        level_t levels[DBG_MAX];
 };
 
-
 /**
- * Implementation of bus_listener_t.signal.
+ * Implementation of bus_listener_t.log.
  */
-static bool signal_(private_file_logger_t *this, signal_t signal, level_t level,
-                                       int thread, ike_sa_t* ike_sa, void *data,
-                                       char *format, va_list args)
+static bool log_(private_file_logger_t *this, debug_t group, level_t level,
+                                int thread, ike_sa_t* ike_sa, char *format, va_list args)
 {
-       if (level <= this->levels[SIG_TYPE(signal)])
+       if (level <= this->levels[group])
        {
                char buffer[8192];
                char *current = buffer, *next;
@@ -68,7 +66,8 @@ static bool signal_(private_file_logger_t *this, signal_t signal, level_t level,
                        {
                                *(next++) = '\0';
                        }
-                       fprintf(this->out, "%.2d[%N] %s\n", thread, signal_names, signal, current);
+                       fprintf(this->out, "%.2d[%N] %s\n",
+                                       thread, debug_names, group, current);
                        current = next;
                }
        }
@@ -79,20 +78,18 @@ static bool signal_(private_file_logger_t *this, signal_t signal, level_t level,
 /**
  * Implementation of file_logger_t.set_level.
  */
-static void set_level(private_file_logger_t *this, signal_t signal, level_t level)
+static void set_level(private_file_logger_t *this, debug_t group, level_t level)
 {
-       if (signal == SIG_ANY)
+       if (group < DBG_ANY)
        {
-               int i;
-               for (i = 0; i < DBG_MAX; i++)
-               {
-                       this->levels[i] = level;
-               }
+               this->levels[group] = level;
        }
        else
        {
-               
-               this->levels[SIG_TYPE(signal)] = level;
+               for (group = 0; group < DBG_MAX; group++)
+               {
+                       this->levels[group] = level;
+               }
        }
 }
 
@@ -109,16 +106,19 @@ static void destroy(private_file_logger_t *this)
  */
 file_logger_t *file_logger_create(FILE *out)
 {
+       debug_t group;
        private_file_logger_t *this = malloc_thing(private_file_logger_t);
        
        /* public functions */
-       this->public.listener.signal = (bool(*)(bus_listener_t*,signal_t,level_t,int,ike_sa_t*,void*,char*,va_list))signal_;
-       this->public.set_level = (void(*)(file_logger_t*,signal_t,level_t))set_level;
+       memset(&this->public.listener, 0, sizeof(listener_t));
+       this->public.listener.log = (bool(*)(listener_t*,debug_t,level_t,int,ike_sa_t*,char*,va_list))log_;
+       this->public.set_level = (void(*)(file_logger_t*,debug_t,level_t))set_level;
        this->public.destroy = (void(*)(file_logger_t*))destroy;
        
        /* private variables */
        this->out = out;
-       set_level(this, SIG_ANY, LEVEL_SILENT);
+       set_level(this, DBG_ANY, LEVEL_SILENT);
        
        return &this->public;
 }
+
index 6b716c6..3603ca0 100644 (file)
@@ -28,22 +28,22 @@ typedef struct file_logger_t file_logger_t;
 #include <bus/bus.h>
 
 /**
- * Logger to files which implements bus_listener_t.
+ * Logger to files which implements listener_t.
  */
 struct file_logger_t {
        
        /**
-        * Implements the bus_listener_t interface.
+        * Implements the listener_t interface.
         */
-       bus_listener_t listener;
+       listener_t listener;
        
        /**
-        * Set the loglevel for a signal type.
+        * Set the loglevel for a debug group.
         *
-        * @param singal        type of signal
+        * @param group         debug group to set
         * @param level         max level to log (0..4)
         */
-       void (*set_level) (file_logger_t *this, signal_t signal, level_t level);
+       void (*set_level) (file_logger_t *this, debug_t group, level_t level);
        
        /**
         * Destroys a file_logger_t object.
index 3bc0bc7..af7968b 100644 (file)
@@ -40,20 +40,18 @@ struct private_sys_logger_t {
        int facility;
        
        /**
-        * Maximum level to log
+        * Maximum level to log, for each group
         */
        level_t levels[DBG_MAX];
 };
 
-
 /**
- * Implementation of bus_listener_t.signal.
+ * Implementation of listener_t.log.
  */
-static bool signal_(private_sys_logger_t *this, signal_t signal, level_t level,
-                                       int thread, ike_sa_t* ike_sa, void *data, 
-                                       char *format, va_list args)
+static bool log_(private_sys_logger_t *this, debug_t group, level_t level,
+                                int thread, ike_sa_t* ike_sa, char *format, va_list args)
 {
-       if (level <= this->levels[SIG_TYPE(signal)])
+       if (level <= this->levels[group])
        {
                char buffer[8192];
                char *current = buffer, *next;
@@ -70,7 +68,7 @@ static bool signal_(private_sys_logger_t *this, signal_t signal, level_t level,
                                *(next++) = '\0';
                        }
                        syslog(this->facility|LOG_INFO, "%.2d[%N] %s\n",
-                                  thread, signal_names, signal, current);
+                                  thread, debug_names, group, current);
                        current = next;
                }
        }
@@ -81,20 +79,18 @@ static bool signal_(private_sys_logger_t *this, signal_t signal, level_t level,
 /**
  * Implementation of sys_logger_t.set_level.
  */
-static void set_level(private_sys_logger_t *this, signal_t signal, level_t level)
+static void set_level(private_sys_logger_t *this, debug_t group, level_t level)
 {
-       if (signal == SIG_ANY)
+       if (group < DBG_ANY)
        {
-               int i;
-               for (i = 0; i < DBG_MAX; i++)
-               {
-                       this->levels[i] = level;
-               }
+               this->levels[group] = level;
        }
        else
        {
-               
-               this->levels[SIG_TYPE(signal)] = level;
+               for (group = 0; group < DBG_MAX; group++)
+               {
+                       this->levels[group] = level;
+               }
        }
 }
 
@@ -115,13 +111,14 @@ sys_logger_t *sys_logger_create(int facility)
        private_sys_logger_t *this = malloc_thing(private_sys_logger_t);
        
        /* public functions */
-       this->public.listener.signal = (bool(*)(bus_listener_t*,signal_t,level_t,int,ike_sa_t*,void*,char*,va_list))signal_;
-       this->public.set_level = (void(*)(sys_logger_t*,signal_t,level_t))set_level;
+       memset(&this->public.listener, 0, sizeof(listener_t));
+       this->public.listener.log = (bool(*)(listener_t*,debug_t,level_t,int,ike_sa_t*,char*,va_list))log_;
+       this->public.set_level = (void(*)(sys_logger_t*,debug_t,level_t))set_level;
        this->public.destroy = (void(*)(sys_logger_t*))destroy;
        
        /* private variables */
        this->facility = facility;
-       set_level(this, SIG_ANY, LEVEL_SILENT);
+       set_level(this, DBG_ANY, LEVEL_SILENT);
        
        return &this->public;
 }
index 1a04c2a..e746fce 100644 (file)
@@ -30,22 +30,22 @@ typedef struct sys_logger_t sys_logger_t;
 #include <bus/bus.h>
 
 /**
- * Logger for syslog which implements bus_listener_t.
+ * Logger for syslog which implements listener_t.
  */
 struct sys_logger_t {
        
        /**
-        * Implements the bus_listener_t interface.
+        * Implements the listener_t interface.
         */
-       bus_listener_t listener;
+       listener_t listener;
        
        /**
-        * Set the loglevel for a signal type.
+        * Set the loglevel for a debug group.
         *
-        * @param singal        type of signal
-        * @param level         max level to log
+        * @param group         debug group to set
+        * @param level         max level to log (0..4)
         */
-       void (*set_level) (sys_logger_t *this, signal_t signal, level_t level);
+       void (*set_level) (sys_logger_t *this, debug_t group, level_t level);
        
        /**
         * Destroys a sys_logger_t object.
index 945ec1c..a460bb8 100644 (file)
@@ -27,7 +27,7 @@
 
 
 typedef struct private_controller_t private_controller_t;
-typedef struct interface_bus_listener_t interface_bus_listener_t;
+typedef struct interface_listener_t interface_listener_t;
 
 /**
  * Private data of an stroke_t object.
@@ -40,16 +40,15 @@ struct private_controller_t {
        controller_t public;
 };
 
-
 /**
- * helper struct to map bus listener callbacks to interface callbacks
+ * helper struct to map listener callbacks to interface callbacks
  */
-struct interface_bus_listener_t {
+struct interface_listener_t {
 
        /**
         * public bus listener interface
         */
-       bus_listener_t public;
+       listener_t public;
        
        /**
         * status of the operation, return to method callers
@@ -57,11 +56,6 @@ struct interface_bus_listener_t {
        status_t status;
        
        /**
-        * IKE SA to filter log output
-        */
-       ike_sa_t *ike_sa;
-       
-       /**
         *  interface callback (listener gets redirected to here)
         */
        controller_cb_t callback;
@@ -82,6 +76,16 @@ struct interface_bus_listener_t {
        peer_cfg_t *peer_cfg;
        
        /**
+        * IKE_SA to handle
+        */
+       ike_sa_t *ike_sa;
+       
+       /**
+        * CHILD_SA to handle
+        */
+       child_sa_t *child_sa;
+       
+       /**
         * unique ID, used for various methods
         */
        u_int32_t id;
@@ -102,38 +106,88 @@ struct interface_job_t {
        /** 
         * associated listener 
         */
-       interface_bus_listener_t listener;
+       interface_listener_t listener;
 };
 
 /**
- * Implementation of controller_t.create_ike_sa_iterator.
+ * listener log function
  */
-static enumerator_t* create_ike_sa_enumerator(controller_t *this)
+static bool listener_log(interface_listener_t *this, debug_t group,
+                                                level_t level, int thread, ike_sa_t *ike_sa,
+                                                char* format, va_list args)
 {
-       return charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager);
+       if (this->ike_sa == ike_sa)
+       {
+               if (!this->callback(this->param, group, level, ike_sa, format, args))
+               {
+                       return FALSE;
+               }
+       }
+       return TRUE;
 }
 
 /**
- * listener function for initiate
+ * Implementation of listener_t.ike_state_change
  */
-static bool initiate_listener(interface_bus_listener_t *this, signal_t signal,
-                                                         level_t level, int thread, ike_sa_t *ike_sa,
-                                                         void* data, char* format, va_list args)
+static bool listener_ike_state(interface_listener_t *this, ike_sa_t *ike_sa,
+                                                          ike_sa_state_t state)
 {
        if (this->ike_sa == ike_sa)
        {
-               if (!this->callback(this->param, signal, level, ike_sa, data,
-                                                       format, args))
+               switch (state)
                {
-                       return FALSE;
+#ifdef ME
+                       case IKE_ESTABLISHED:
+                       {       /* mediation connections are complete without CHILD_SA */
+                               peer_cfg_t *peer_cfg = ike_sa->get_peer_cfg(ike_sa);
+                               
+                               if (peer_cfg->is_mediation(peer_cfg))
+                               {
+                                       this->status = SUCCESS;
+                                       return FALSE;
+                               }
+                               break;
+                       }
+#endif /* ME */
+                       case IKE_DESTROYING:
+                               if (ike_sa->get_state(ike_sa) == IKE_DELETING)
+                               {       /* proper termination */
+                                       this->status = SUCCESS;
+                               }
+                               return FALSE;
+                       default:
+                               break;
                }
-               switch (signal)
+       }
+       return TRUE;
+}
+
+/**
+ * Implementation of listener_t.child_state_change
+ */
+static bool listener_child_state(interface_listener_t *this, ike_sa_t *ike_sa,
+                                                                child_sa_t *child_sa, child_sa_state_t state)
+{
+       if (this->ike_sa == ike_sa)
+       {
+               switch (state)
                {
-                       case CHD_UP_SUCCESS:
+                       case CHILD_ROUTED:
+                       case CHILD_INSTALLED:
                                this->status = SUCCESS;
                                return FALSE;
-                       case IKE_UP_FAILED:
-                       case CHD_UP_FAILED:
+                       case CHILD_DESTROYING:
+                               switch (child_sa->get_state(child_sa))
+                               {
+                                       case CHILD_ROUTED:
+                                               /* has been unrouted */
+                                       case CHILD_DELETING:
+                                               /* proper delete */
+                                               this->status = SUCCESS;
+                                               break;
+                                       default:
+                                               break;
+                               }
                                return FALSE;
                        default:
                                break;
@@ -143,12 +197,32 @@ static bool initiate_listener(interface_bus_listener_t *this, signal_t signal,
 }
 
 /**
+ * cleanup job if job is never executed
+ */
+static void recheckin(interface_job_t *job)
+{
+       if (job->listener.ike_sa)
+       {
+               charon->ike_sa_manager->checkin(charon->ike_sa_manager,
+                                                                               job->listener.ike_sa);
+       }
+}
+
+/**
+ * Implementation of controller_t.create_ike_sa_iterator.
+ */
+static enumerator_t* create_ike_sa_enumerator(controller_t *this)
+{
+       return charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager);
+}
+
+/**
  * execute function for initiate
  */
 static status_t initiate_execute(interface_job_t *job)
 {
        ike_sa_t *ike_sa;
-       interface_bus_listener_t *listener = &job->listener;
+       interface_listener_t *listener = &job->listener;
        peer_cfg_t *peer_cfg = listener->peer_cfg;
        
        ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager,
@@ -176,72 +250,41 @@ static status_t initiate(private_controller_t *this,
                                                 peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
                                                 controller_cb_t callback, void *param)
 {
-       interface_job_t job;
-
-       job.listener.public.signal = (void*)initiate_listener;
-       job.listener.ike_sa = NULL;
-       job.listener.callback = callback;
-       job.listener.param = param;
-       job.listener.status = FAILED;
-       job.listener.child_cfg = child_cfg;
-       job.listener.peer_cfg = peer_cfg;
-       job.public.execute = (void*)initiate_execute;
-       job.public.destroy = nop;
-
+       interface_job_t job = {
+               .listener = {
+                       .public = {
+                               .log = (void*)listener_log,
+                               .ike_state_change = (void*)listener_ike_state,
+                               .child_state_change = (void*)listener_child_state,
+                       },
+                       .callback = callback,
+                       .param = param,
+                       .status = FAILED,
+                       .child_cfg = child_cfg,
+                       .peer_cfg = peer_cfg,
+               },
+               .public = {
+                       .execute = (void*)initiate_execute,
+                       .destroy = (void*)recheckin,
+               },
+       };
        if (callback == NULL)
        {
                return initiate_execute(&job);
        }
-       charon->bus->listen(charon->bus, (bus_listener_t*)&job.listener, (job_t*)&job);
+       charon->bus->listen(charon->bus, &job.listener.public, (job_t*)&job);
        return job.listener.status;
 }
 
 /**
- * listener function for terminate_ike
- */
-static bool terminate_ike_listener(interface_bus_listener_t *this, signal_t signal,
-                                                                  level_t level, int thread, ike_sa_t *ike_sa,
-                                                                  void* data, char* format, va_list args)
-{
-       if (this->ike_sa == ike_sa)
-       {
-               if (!this->callback(this->param, signal, level, ike_sa,
-                                                       data, format, args))
-               {
-                       return FALSE;
-               }
-               switch (signal)
-               {
-                       case IKE_DOWN_SUCCESS:
-                               this->status = SUCCESS;
-                               return FALSE;
-                       case IKE_DOWN_FAILED:
-                               return FALSE;
-                       default:
-                               break;
-               }
-       }
-       return TRUE;
-}
-
-/**
  * execute function for terminate_ike
  */
 static status_t terminate_ike_execute(interface_job_t *job)
 {
-       ike_sa_t *ike_sa;
-       interface_bus_listener_t *listener = &job->listener;
-       
-       ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
-                                                                                                       listener->id, FALSE);
-       if (ike_sa == NULL)
-       {
-               SIG_IKE(DOWN_FAILED, "unable to terminate, IKE_SA with "
-                       "ID %d not found", listener->id);
-               return NOT_FOUND;
-       }       
-       listener->ike_sa = ike_sa;                                              
+       interface_listener_t *listener = &job->listener;
+       ike_sa_t *ike_sa = listener->ike_sa;
        
+       charon->bus->set_sa(charon->bus, ike_sa);
        if (ike_sa->delete(ike_sa) == DESTROY_ME)
        {
                return charon->ike_sa_manager->checkin_and_destroy(
@@ -256,79 +299,103 @@ static status_t terminate_ike_execute(interface_job_t *job)
 static status_t terminate_ike(controller_t *this, u_int32_t unique_id, 
                                                          controller_cb_t callback, void *param)
 {
-       interface_job_t job;
+       ike_sa_t *ike_sa;
+       interface_job_t job = {
+               .listener = {
+                       .public = {
+                               .log = (void*)listener_log,
+                               .ike_state_change = (void*)listener_ike_state,
+                               .child_state_change = (void*)listener_child_state,
+                       },
+                       .callback = callback,
+                       .param = param,
+                       .status = FAILED,
+                       .id = unique_id,
+               },
+               .public = {
+                       .execute = (void*)terminate_ike_execute,
+                       .destroy = (void*)recheckin,
+               },
+       };
+       
+       ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
+                                                                                                       unique_id, FALSE);
+       if (ike_sa == NULL)
+       {
+               DBG1(DBG_IKE, "unable to terminate IKE_SA: ID %d not found", unique_id);
+               return NOT_FOUND;
+       }
+       job.listener.ike_sa = ike_sa;
        
-       job.listener.public.signal = (void*)terminate_ike_listener;
-       job.listener.ike_sa = NULL;
-       job.listener.callback = callback;
-       job.listener.param = param;
-       job.listener.status = FAILED;
-       job.listener.id = unique_id;
-       job.public.execute = (void*)terminate_ike_execute;
-       job.public.destroy = nop;
-
        if (callback == NULL)
        {
                return terminate_ike_execute(&job);
        }
-       charon->bus->listen(charon->bus, (bus_listener_t*)&job.listener, (job_t*)&job);
+       charon->bus->listen(charon->bus, &job.listener.public, (job_t*)&job);
        return job.listener.status;
 }
+
 /**
- * listener function for terminate_child
+ * execute function for terminate_child
  */
-static bool terminate_child_listener(interface_bus_listener_t *this, signal_t signal,
-                                                                        level_t level, int thread, ike_sa_t *ike_sa,
-                                                                        void* data, char* format, va_list args)
+static status_t terminate_child_execute(interface_job_t *job)
 {
-       if (this->ike_sa == ike_sa)
+       interface_listener_t *listener = &job->listener;
+       ike_sa_t *ike_sa = listener->ike_sa;
+       child_sa_t *child_sa = listener->child_sa;
+       
+       charon->bus->set_sa(charon->bus, ike_sa);
+       if (ike_sa->delete_child_sa(ike_sa, child_sa->get_protocol(child_sa),
+                                                               child_sa->get_spi(child_sa, TRUE)) == DESTROY_ME)
        {
-               if (!this->callback(this->param, signal, level, ike_sa,
-                                                       data, format, args))
-               {
-                       return FALSE;
-               }
-               switch (signal)
-               {
-                       case CHD_DOWN_SUCCESS:
-                       case IKE_DOWN_SUCCESS:
-                               this->status = SUCCESS;
-                               return FALSE;
-                       case IKE_DOWN_FAILED:
-                       case CHD_DOWN_FAILED:
-                               return FALSE;
-                       default:
-                               break;
-               }
+               return charon->ike_sa_manager->checkin_and_destroy(
+                                                                                               charon->ike_sa_manager, ike_sa);
        }
-       return TRUE;
+       return charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
 }
 
 /**
- * execute function for terminate_child
+ * Implementation of controller_t.terminate_child.
  */
-static status_t terminate_child_execute(interface_job_t *job)
+static status_t terminate_child(controller_t *this, u_int32_t reqid, 
+                                                               controller_cb_t callback, void *param)
 {
        ike_sa_t *ike_sa;
        child_sa_t *child_sa;
        iterator_t *iterator;
-       interface_bus_listener_t *listener = &job->listener;
+       interface_job_t job = {
+               .listener = {
+                       .public = {
+                               .log = (void*)listener_log,
+                               .ike_state_change = (void*)listener_ike_state,
+                               .child_state_change = (void*)listener_child_state,
+                       },
+                       .callback = callback,
+                       .param = param,
+                       .status = FAILED,
+                       .id = reqid,
+               },
+               .public = {
+                       .execute = (void*)terminate_child_execute,
+                       .destroy = (void*)recheckin,
+               },
+       };
        
        ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
-                                                                                                       listener->id, TRUE);                                                    
+                                                                                                       reqid, TRUE);                                                   
        if (ike_sa == NULL)
        {
-               SIG_CHD(DOWN_FAILED, NULL, "unable to terminate, CHILD_SA with "
-                               "ID %d not found", listener->id);
+               DBG1(DBG_IKE, "unable to terminate, CHILD_SA with ID %d not found",
+                        reqid);
                return NOT_FOUND;
        }
-       listener->ike_sa = ike_sa;
+       job.listener.ike_sa = ike_sa;
        
        iterator = ike_sa->create_child_sa_iterator(ike_sa);
        while (iterator->iterate(iterator, (void**)&child_sa))
        {
                if (child_sa->get_state(child_sa) != CHILD_ROUTED &&
-                       child_sa->get_reqid(child_sa) == listener->id)
+                       child_sa->get_reqid(child_sa) == reqid)
                {
                        break;
                }
@@ -338,90 +405,30 @@ static status_t terminate_child_execute(interface_job_t *job)
        
        if (child_sa == NULL)
        {
-               SIG_CHD(DOWN_FAILED, NULL, "unable to terminate, established "
-                               "CHILD_SA with ID %d not found", listener->id);
+               DBG1(DBG_IKE, "unable to terminate, established "
+                        "CHILD_SA with ID %d not found", reqid);
                charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
                return NOT_FOUND;
        }
-       
-       if (ike_sa->delete_child_sa(ike_sa, child_sa->get_protocol(child_sa),
-                                                               child_sa->get_spi(child_sa, TRUE)) == DESTROY_ME)
-       {
-               return charon->ike_sa_manager->checkin_and_destroy(
-                                                                                               charon->ike_sa_manager, ike_sa);
-       }
-       return charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
-}
-
-/**
- * Implementation of controller_t.terminate_child.
- */
-static status_t terminate_child(controller_t *this, u_int32_t reqid, 
-                                                               controller_cb_t callback, void *param)
-{
-       interface_job_t job;
-       
-       job.listener.public.signal = (void*)terminate_child_listener;
-       job.listener.ike_sa = NULL;
-       job.listener.callback = callback;
-       job.listener.param = param;
-       job.listener.status = FAILED;
-       job.listener.id = reqid;
-       job.public.execute = (void*)terminate_child_execute;
-       job.public.destroy = nop;
+       job.listener.child_sa = child_sa;
 
        if (callback == NULL)
        {
                return terminate_child_execute(&job);
        }
-       charon->bus->listen(charon->bus, (bus_listener_t*)&job.listener, (job_t*)&job); 
+       charon->bus->listen(charon->bus, &job.listener.public, (job_t*)&job);
        return job.listener.status;
 }
 
 /**
- * listener function for route
- */
-static bool route_listener(interface_bus_listener_t *this, signal_t signal,
-                                                  level_t level, int thread, ike_sa_t *ike_sa,
-                                                  void* data, char* format, va_list args)
-{
-       if (this->ike_sa == ike_sa)
-       {
-               if (!this->callback(this->param, signal, level, ike_sa,
-                                                       data, format, args))
-               {
-                       return FALSE;
-               }
-               switch (signal)
-               {
-                       case CHD_ROUTE_SUCCESS:
-                               this->status = SUCCESS;
-                               return FALSE;
-                       case CHD_ROUTE_FAILED:
-                               return FALSE;
-                       default:
-                               break;
-               }
-       }
-       return TRUE;
-}
-
-/**
  * execute function for route
  */
 static status_t route_execute(interface_job_t *job)
 {
-       ike_sa_t *ike_sa;
-       interface_bus_listener_t *listener = &job->listener;
-       peer_cfg_t *peer_cfg = listener->peer_cfg;
-       ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager,
-                                                                                                               peer_cfg);
-       listener->ike_sa = ike_sa;
+       interface_listener_t *listener = &job->listener;
+       ike_sa_t *ike_sa = listener->ike_sa;
        
-       if (ike_sa->get_peer_cfg(ike_sa) == NULL)
-       {
-               ike_sa->set_peer_cfg(ike_sa, peer_cfg);
-       }
+       charon->bus->set_sa(charon->bus, ike_sa);
        if (ike_sa->route(ike_sa, listener->child_cfg) == DESTROY_ME)
        {
                return charon->ike_sa_manager->checkin_and_destroy(
@@ -437,70 +444,49 @@ static status_t route(controller_t *this,
                                          peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
                                          controller_cb_t callback, void *param)
 {
-       interface_job_t job;
+       ike_sa_t *ike_sa;
+       interface_job_t job = {
+               .listener = {
+                       .public = {
+                               .log = (void*)listener_log,
+                               .ike_state_change = (void*)listener_ike_state,
+                               .child_state_change = (void*)listener_child_state,
+                       },
+                       .callback = callback,
+                       .param = param,
+                       .status = FAILED,
+                       .peer_cfg = peer_cfg,
+                       .child_cfg = child_cfg,
+               },
+               .public = {
+                       .execute = (void*)route_execute,
+                       .destroy = (void*)recheckin,
+               },
+       };
        
-       job.listener.public.signal = (void*)route_listener;
-       job.listener.ike_sa = NULL;
-       job.listener.callback = callback;
-       job.listener.param = param;
-       job.listener.status = FAILED;
-       job.listener.peer_cfg = peer_cfg;
-       job.listener.child_cfg = child_cfg;
-       job.public.execute = (void*)route_execute;
-       job.public.destroy = nop;
-
+       ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager,
+                                                                                                               peer_cfg);
+       if (ike_sa->get_peer_cfg(ike_sa) == NULL)
+       {
+               ike_sa->set_peer_cfg(ike_sa, peer_cfg);
+       }
+       job.listener.ike_sa = ike_sa;
        if (callback == NULL)
        {
                return route_execute(&job);
        }
-       charon->bus->listen(charon->bus, (bus_listener_t*)&job.listener, (job_t*)&job);
+       charon->bus->listen(charon->bus, &job.listener.public, (job_t*)&job);
        return job.listener.status;
 }
 
 /**
- * listener function for unroute
- */
-static bool unroute_listener(interface_bus_listener_t *this, signal_t signal,
-                                                    level_t level, int thread, ike_sa_t *ike_sa,
-                                                    void* data, char* format, va_list args)
-{
-       if (this->ike_sa == ike_sa)
-       {
-               if (!this->callback(this->param, signal, level, ike_sa, 
-                                                       data, format, args))
-               {
-                       return FALSE;
-               }
-               switch (signal)
-               {
-                       case CHD_UNROUTE_SUCCESS:
-                               this->status = SUCCESS;
-                               return FALSE;
-                       case CHD_UNROUTE_FAILED:
-                               return FALSE;
-                       default:
-                               break;
-               }
-       }
-       return TRUE;
-}
-/**
  * execute function for unroute
  */
 static status_t unroute_execute(interface_job_t *job)
 {
-       ike_sa_t *ike_sa;
-       interface_bus_listener_t *listener = &job->listener;
+       interface_listener_t *listener = &job->listener;
+       ike_sa_t *ike_sa = listener->ike_sa;
        
-       ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
-                                                                                                       listener->id, TRUE);
-       if (ike_sa == NULL)
-       {
-               SIG_CHD(DOWN_FAILED, NULL, "unable to unroute, CHILD_SA with "
-                               "ID %d not found", listener->id);
-               return NOT_FOUND;
-       }
-       listener->ike_sa = ike_sa;
        if (ike_sa->unroute(ike_sa, listener->id) == DESTROY_ME)
        {
                return charon->ike_sa_manager->checkin_and_destroy(
@@ -515,30 +501,47 @@ static status_t unroute_execute(interface_job_t *job)
 static status_t unroute(controller_t *this, u_int32_t reqid, 
                                                controller_cb_t callback, void *param)
 {
-       interface_job_t job;
+       ike_sa_t *ike_sa;
+       interface_job_t job = {
+               .listener = {
+                       .public = {
+                               .log = (void*)listener_log,
+                               .ike_state_change = (void*)listener_ike_state,
+                               .child_state_change = (void*)listener_child_state,
+                       },
+                       .callback = callback,
+                       .param = param,
+                       .status = FAILED,
+                       .id = reqid,
+               },
+               .public = {
+                       .execute = (void*)unroute_execute,
+                       .destroy = (void*)recheckin,
+               },
+       };
        
-       job.listener.public.signal = (void*)unroute_listener;
-       job.listener.ike_sa = NULL;
-       job.listener.callback = callback;
-       job.listener.param = param;
-       job.listener.status = FAILED;
-       job.listener.id = reqid;
-       job.public.execute = (void*)unroute_execute;
-       job.public.destroy = nop;
+       ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
+                                                                                                       reqid, TRUE);
+       if (ike_sa == NULL)
+       {
+               DBG1(DBG_IKE, "unable to unroute, CHILD_SA with ID %d not found", reqid);
+               return NOT_FOUND;
+       }
+       job.listener.ike_sa = ike_sa;
 
        if (callback == NULL)
        {
                return unroute_execute(&job);
        }
-       charon->bus->listen(charon->bus, (bus_listener_t*)&job.listener, (job_t*)&job); 
+       charon->bus->listen(charon->bus, &job.listener.public, (job_t*)&job);   
        return job.listener.status;
 }
 
 /**
  * See header
  */
-bool controller_cb_empty(void *param, signal_t signal, level_t level,
-                                       ike_sa_t *ike_sa, void *data, char *format, va_list args)
+bool controller_cb_empty(void *param, debug_t group, level_t level,
+                                       ike_sa_t *ike_sa, char *format, va_list args)
 {
        return TRUE;
 }
index 95202d7..0dd6aec 100644 (file)
  * callback to log things triggered by controller.
  *
  * @param param                        echoed parameter supplied when function invoked
- * @param signal               type of signal
+ * @param group                        debugging group
  * @param level                        verbosity level if log
  * @param ike_sa               associated IKE_SA, if any
  * @param format               printf like format string
  * @param args                 list of arguments to use for format
  * @return                             FALSE to return from invoked function
  */
-typedef bool(*controller_cb_t)(void* param, signal_t signal, level_t level,
-                                                          ike_sa_t* ike_sa, void *data,
-                                                          char* format, va_list args);
+typedef bool(*controller_cb_t)(void* param, debug_t group, level_t level,
+                                                          ike_sa_t* ike_sa, char* format, va_list args);
 
 /**
  * Empty callback function for controller_t functions.
  *
- * If you wan't to do a syncrhonous call, but don't need a callback, pass
+ * If you want to do a syncrhonous call, but don't need a callback, pass
  * this function to the controllers methods.
  */
-bool controller_cb_empty(void *param, signal_t signal, level_t level,
-                                                ike_sa_t *ike_sa, void *data,
-                                                char *format, va_list args);
+bool controller_cb_empty(void *param, debug_t group, level_t level,
+                                                ike_sa_t *ike_sa, char *format, va_list args);
 
 typedef struct controller_t controller_t;
 
index 065f7d7..3bfb32d 100644 (file)
@@ -99,7 +99,7 @@ static void dbg_bus(int level, char *fmt, ...)
        va_list args;
        
        va_start(args, fmt);
-       charon->bus->vsignal(charon->bus, DBG_LIB, level, NULL, fmt, args);
+       charon->bus->vlog(charon->bus, DBG_LIB, level, fmt, args);
        va_end(args);
 }
 
@@ -321,7 +321,7 @@ static void lookup_uid_gid(private_daemon_t *this)
  */
 static bool initialize(private_daemon_t *this, bool syslog, level_t levels[])
 {
-       signal_t signal;
+       debug_t group;
        
        /* for uncritical pseudo random numbers */
        srandom(time(NULL) + getpid());
@@ -334,19 +334,19 @@ static bool initialize(private_daemon_t *this, bool syslog, level_t levels[])
        this->public.bus->add_listener(this->public.bus, &this->public.syslog->listener);
        this->public.bus->add_listener(this->public.bus, &this->public.outlog->listener);
        this->public.bus->add_listener(this->public.bus, &this->public.authlog->listener);
-       this->public.authlog->set_level(this->public.authlog, SIG_ANY, LEVEL_AUDIT);
+       this->public.authlog->set_level(this->public.authlog, DBG_ANY, LEVEL_AUDIT);
        /* set up hook to log dbg message in library via charons message bus */
        dbg = dbg_bus;
        
        /* apply loglevels */
-       for (signal = 0; signal < DBG_MAX; signal++)
+       for (group = 0; group < DBG_MAX; group++)
        {
                this->public.syslog->set_level(this->public.syslog,
-                                                                          signal, levels[signal]);
+                                                                          group, levels[group]);
                if (!syslog)
                {
                        this->public.outlog->set_level(this->public.outlog,
-                                                                                  signal, levels[signal]);
+                                                                                  group, levels[group]);
                }
        }
        
@@ -555,7 +555,7 @@ int main(int argc, char *argv[])
        FILE *pid_file;
        struct stat stb;
        level_t levels[DBG_MAX];
-       int signal;
+       int group;
        
        /* logging for library during initialization, as we have no bus yet */
        dbg = dbg_stderr;
@@ -572,9 +572,9 @@ int main(int argc, char *argv[])
        lookup_uid_gid(private_charon);
        
        /* use CTRL loglevel for default */
-       for (signal = 0; signal < DBG_MAX; signal++)
+       for (group = 0; group < DBG_MAX; group++)
        {
-               levels[signal] = LEVEL_CTRL;
+               levels[group] = LEVEL_CTRL;
        }
        
        /* handle arguments */
@@ -585,16 +585,16 @@ int main(int argc, char *argv[])
                        { "version", no_argument, NULL, 'v' },
                        { "use-syslog", no_argument, NULL, 'l' },
                        /* TODO: handle "debug-all" */
-                       { "debug-dmn", required_argument, &signal, DBG_DMN },
-                       { "debug-mgr", required_argument, &signal, DBG_MGR },
-                       { "debug-ike", required_argument, &signal, DBG_IKE },
-                       { "debug-chd", required_argument, &signal, DBG_CHD },
-                       { "debug-job", required_argument, &signal, DBG_JOB },
-                       { "debug-cfg", required_argument, &signal, DBG_CFG },
-                       { "debug-knl", required_argument, &signal, DBG_KNL },
-                       { "debug-net", required_argument, &signal, DBG_NET },
-                       { "debug-enc", required_argument, &signal, DBG_ENC },
-                       { "debug-lib", required_argument, &signal, DBG_LIB },
+                       { "debug-dmn", required_argument, &group, DBG_DMN },
+                       { "debug-mgr", required_argument, &group, DBG_MGR },
+                       { "debug-ike", required_argument, &group, DBG_IKE },
+                       { "debug-chd", required_argument, &group, DBG_CHD },
+                       { "debug-job", required_argument, &group, DBG_JOB },
+                       { "debug-cfg", required_argument, &group, DBG_CFG },
+                       { "debug-knl", required_argument, &group, DBG_KNL },
+                       { "debug-net", required_argument, &group, DBG_NET },
+                       { "debug-enc", required_argument, &group, DBG_ENC },
+                       { "debug-lib", required_argument, &group, DBG_LIB },
                        { 0,0,0,0 }
                };
                
@@ -613,8 +613,8 @@ int main(int argc, char *argv[])
                                use_syslog = TRUE;
                                continue;
                        case 0:
-                               /* option is in signal */
-                               levels[signal] = atoi(optarg);
+                               /* option is in group */
+                               levels[group] = atoi(optarg);
                                continue;
                        default:
                                usage("");
index 22cef47..2d6f86e 100644 (file)
@@ -34,7 +34,7 @@ G_DEFINE_TYPE(NMStrongswanPlugin, nm_strongswan_plugin, NM_TYPE_VPN_PLUGIN)
  * Private data of NMStrongswanPlugin
  */
 typedef struct {
-       bus_listener_t listener;
+       listener_t listener;
        ike_sa_t *ike_sa;
        NMVPNPlugin *plugin;
        nm_creds_t *creds;
@@ -95,32 +95,54 @@ static void signal_ipv4_config(NMVPNPlugin *plugin, child_sa_t *child_sa)
 }
 
 /**
- * Bus listen function to wait for SA establishing
+ * signal failure to NM, connecting failed
  */
-bool listen_bus(bus_listener_t *listener, signal_t signal, level_t level,
-                               int thread, ike_sa_t *ike_sa, void *data, 
-                               char* format, va_list args)
+static void signal_failure(NMVPNPlugin *plugin)
+{
+       /* TODO: NM does not handle this failure!? 
+       nm_vpn_plugin_failure(plugin, NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED); */
+       nm_vpn_plugin_set_state(plugin, NM_VPN_SERVICE_STATE_STOPPED);
+}
+
+/**
+ * Implementation of listener_t.ike_state_change
+ */
+static bool ike_state_change(listener_t *listener, ike_sa_t *ike_sa,
+                                                        ike_sa_state_t state)
 {
        NMStrongswanPluginPrivate *private = (NMStrongswanPluginPrivate*)listener;
        
        if (private->ike_sa == ike_sa)
        {
-               switch (signal)
+               switch (state)
                {
-                       case CHD_UP_SUCCESS:
-                               if (data)
-                               {
-                                       signal_ipv4_config(private->plugin, (child_sa_t*)data);
-                                       return FALSE;
-                               }
-                               /* FALL */
-                       case IKE_UP_FAILED:
-                       case CHD_UP_FAILED:
-                               /* TODO: NM does not handle this failure!? 
-                               nm_vpn_plugin_failure(private->plugin,
-                                                                         NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED); */
-                               nm_vpn_plugin_set_state(private->plugin,
-                                                                               NM_VPN_SERVICE_STATE_STOPPED);
+                       case IKE_DESTROYING:
+                               signal_failure(private->plugin);
+                               return FALSE;
+                       default:
+                               break;
+               }
+       }
+       return TRUE;
+}
+
+/**
+ * Implementation of listener_t.child_state_change
+ */
+static bool child_state_change(listener_t *listener, ike_sa_t *ike_sa,
+                                                          child_sa_t *child_sa, child_sa_state_t state)
+{
+       NMStrongswanPluginPrivate *private = (NMStrongswanPluginPrivate*)listener;
+
+       if (private->ike_sa == ike_sa)
+       {
+               switch (state)
+               {
+                       case CHILD_INSTALLED:
+                               signal_ipv4_config(private->plugin, child_sa);
+                               return FALSE;
+                       case CHILD_DESTROYING:
+                               signal_failure(private->plugin);
                                return FALSE;
                        default:
                                break;
@@ -435,8 +457,13 @@ static gboolean disconnect(NMVPNPlugin *plugin, GError **err)
  */
 static void nm_strongswan_plugin_init(NMStrongswanPlugin *plugin)
 {
-       NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin)->plugin = NM_VPN_PLUGIN(plugin);
-       NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin)->listener.signal = listen_bus;
+       NMStrongswanPluginPrivate *private;
+       
+       private = NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin);
+       private->plugin = NM_VPN_PLUGIN(plugin);
+       memset(&private->listener.log, 0, sizeof(listener_t));
+       private->listener.ike_state_change = ike_state_change;
+       private->listener.child_state_change = child_state_change;
 }
 
 /**
index 6f90b7c..d6b606c 100644 (file)
@@ -359,15 +359,15 @@ static void request_query_config(xmlTextReaderPtr reader, xmlTextWriterPtr write
 /**
  * callback which logs to a XML writer
  */
-static bool xml_callback(xmlTextWriterPtr writer, signal_t signal, level_t level,
-                                                ike_sa_t* ike_sa, void *data, char* format, va_list args)
+static bool xml_callback(xmlTextWriterPtr writer, debug_t group, level_t level,
+                                                ike_sa_t* ike_sa, char* format, va_list args)
 {
        if (level <= 1)
        {
                /* <item> */
                xmlTextWriterStartElement(writer, "item");
                xmlTextWriterWriteFormatAttribute(writer, "level", "%d", level);
-               xmlTextWriterWriteFormatAttribute(writer, "source", "%N", signal_names, signal);
+               xmlTextWriterWriteFormatAttribute(writer, "source", "%N", debug_names, group);
                xmlTextWriterWriteFormatAttribute(writer, "thread", "%u", pthread_self());
                xmlTextWriterWriteVFormatString(writer, format, args);
                xmlTextWriterEndElement(writer);
index 6a87f9f..4cbaaa3 100644 (file)
@@ -49,13 +49,11 @@ struct private_sql_logger_t {
        bool recursive;
 };
 
-
 /**
- * Implementation of bus_listener_t.signal.
+ * Implementation of bus_listener_t.log.
  */
-static bool signal_(private_sql_logger_t *this, signal_t signal, level_t level,
-                                       int thread, ike_sa_t* ike_sa, void *data,
-                                       char *format, va_list args)
+static bool log_(private_sql_logger_t *this, debug_t group, level_t level,
+                                int thread, ike_sa_t* ike_sa, char *format, va_list args)
 {
        if (this->recursive)
        {
@@ -111,7 +109,7 @@ static bool signal_(private_sql_logger_t *this, signal_t signal, level_t level,
                                                  DB_BLOB, remote_host->get_address(remote_host));
                this->db->execute(this->db, NULL, "INSERT INTO logs ("
                                                  "local_spi, signal, level, msg) VALUES (?, ?, ?, ?)",
-                                                 DB_BLOB, local_spi, DB_INT, signal, DB_INT, level,
+                                                 DB_BLOB, local_spi, DB_INT, group, DB_INT, level,
                                                  DB_TEXT, buffer);
        }
        this->recursive = FALSE;
@@ -134,7 +132,8 @@ sql_logger_t *sql_logger_create(database_t *db)
 {
        private_sql_logger_t *this = malloc_thing(private_sql_logger_t);
        
-       this->public.listener.signal = (bool(*)(bus_listener_t*,signal_t,level_t,int,ike_sa_t*,void*,char*,va_list))signal_;
+       memset(&this->public.listener, 0, sizeof(listener_t));
+       this->public.listener.log = (bool(*)(listener_t*,debug_t,level_t,int,ike_sa_t*,char*,va_list))log_;
        this->public.destroy = (void(*)(sql_logger_t*))destroy;
        
        this->db = db;
index 30507bc..a2c6fb5 100644 (file)
@@ -36,7 +36,7 @@ struct sql_logger_t {
        /**
         * Implements bus_listener_t interface
         */
-       bus_listener_t listener;
+       listener_t listener;
        
        /**
         * Destry the backend.
index ed9dd7b..08d5051 100644 (file)
@@ -55,8 +55,8 @@ struct stroke_log_info_t {
 /**
  * logging to the stroke interface
  */
-static bool stroke_log(stroke_log_info_t *info, signal_t signal, level_t level,
-                                          ike_sa_t *ike_sa, void *data, char *format, va_list args)
+static bool stroke_log(stroke_log_info_t *info, debug_t group, level_t level,
+                                          ike_sa_t *ike_sa, char *format, va_list args)
 {
        if (level <= info->level)
        {
index 175322a..70f12ea 100644 (file)
@@ -336,9 +336,9 @@ static void stroke_purge(private_stroke_socket_t *this,
                                                                         CERT_X509_OCSP_RESPONSE);
 }
 
-signal_t get_signal_from_logtype(char *type)
+debug_t get_group_from_name(char *type)
 {
-       if      (strcasecmp(type, "any") == 0) return SIG_ANY;
+       if (strcasecmp(type, "any") == 0) return DBG_ANY;
        else if (strcasecmp(type, "mgr") == 0) return DBG_MGR;
        else if (strcasecmp(type, "ike") == 0) return DBG_IKE;
        else if (strcasecmp(type, "chd") == 0) return DBG_CHD;
@@ -354,29 +354,31 @@ signal_t get_signal_from_logtype(char *type)
 /**
  * set the verbosity debug output
  */
-static void stroke_loglevel(private_stroke_socket_t *this, stroke_msg_t *msg, FILE *out)
+static void stroke_loglevel(private_stroke_socket_t *this,
+                                                       stroke_msg_t *msg, FILE *out)
 {
-       signal_t signal;
+       debug_t group;
        
        pop_string(msg, &(msg->loglevel.type));
        DBG1(DBG_CFG, "received stroke: loglevel %d for %s",
                 msg->loglevel.level, msg->loglevel.type);
        
-       signal = get_signal_from_logtype(msg->loglevel.type);
-       if (signal < 0)
+       group = get_group_from_name(msg->loglevel.type);
+       if (group < 0)
        {
                fprintf(out, "invalid type (%s)!\n", msg->loglevel.type);
                return;
        }
        
-       charon->outlog->set_level(charon->outlog, signal, msg->loglevel.level);
-       charon->syslog->set_level(charon->syslog, signal, msg->loglevel.level);
+       charon->outlog->set_level(charon->outlog, group, msg->loglevel.level);
+       charon->syslog->set_level(charon->syslog, group, msg->loglevel.level);
 }
 
 /**
  * set various config options
  */
-static void stroke_config(private_stroke_socket_t *this, stroke_msg_t *msg, FILE *out)
+static void stroke_config(private_stroke_socket_t *this,
+                                                 stroke_msg_t *msg, FILE *out)
 {
        this->cred->cachecrl(this->cred, msg->config.cachecrl);
 }
index ef728bf..ed247e0 100644 (file)
@@ -54,36 +54,18 @@ static void destroy(private_initiate_mediation_job_t *this)
 }
 
 /**
- * Callback to handle initiation of mediation connection
- */
-static bool initiate_callback(private_initiate_mediation_job_t *this,
-                                                         signal_t signal, level_t level, ike_sa_t *ike_sa,
-                                                         void *data, char *format, va_list args)
-{
-       if (signal == CHD_UP_SUCCESS)
-       {
-               /* mediation connection is up */
-               this->mediation_sa_id = ike_sa->get_id(ike_sa);
-               this->mediation_sa_id = this->mediation_sa_id->clone(this->mediation_sa_id);
-               return FALSE;
-       }
-       return TRUE;
-}
-
-/**
  * Implementation of job_t.execute.
  */ 
 static void initiate(private_initiate_mediation_job_t *this)
-{      /* FIXME: check the logging */
+{
        ike_sa_t *mediated_sa, *mediation_sa;
        peer_cfg_t *mediated_cfg, *mediation_cfg;
        
        mediated_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager,
-                                                                                         this->mediated_sa_id);
+                                                                                                  this->mediated_sa_id);
        if (mediated_sa)
        {
                mediated_cfg = mediated_sa->get_peer_cfg(mediated_sa);
-               /* get_peer_cfg returns an internal object */
                mediated_cfg->get_ref(mediated_cfg); 
                
                charon->ike_sa_manager->checkin(charon->ike_sa_manager, mediated_sa);
@@ -98,9 +80,16 @@ static void initiate(private_initiate_mediation_job_t *this)
                {
                        mediated_cfg->destroy(mediated_cfg);
                        mediation_cfg->destroy(mediation_cfg);
-                       /* this pointer should still be valid */
-                       charon->bus->set_sa(charon->bus, mediated_sa);
-                       DBG1(DBG_IKE, "mediation with the same peer is already in progress, queued");
+                       
+                       mediated_sa = charon->ike_sa_manager->checkout(
+                                                               charon->ike_sa_manager, this->mediated_sa_id);
+                       if (mediated_sa)
+                       {
+                               DBG1(DBG_IKE, "mediation with the same peer is already in "
+                                        "progress, queued");
+                               charon->ike_sa_manager->checkin(
+                                                               charon->ike_sa_manager, mediated_sa);
+                       }
                        destroy(this);
                        return;
                }
@@ -111,16 +100,20 @@ static void initiate(private_initiate_mediation_job_t *this)
                 * we do not check the status, but NEED_MORE would be returned on success
                 * because the registered callback returns FALSE then
                 * this->mediation_sa_id is set in the callback */
-               charon->controller->initiate(charon->controller,
-                               mediation_cfg, NULL, (controller_cb_t)initiate_callback, this);
+               charon->controller->initiate(charon->controller, mediation_cfg, NULL,
+                                                                        controller_cb_empty, this);
                if (!this->mediation_sa_id)
                {
-                       DBG1(DBG_JOB, "initiating mediation connection '%s' failed",
-                                       mediation_cfg->get_name(mediation_cfg));
                        mediation_cfg->destroy(mediation_cfg);
                        mediated_cfg->destroy(mediated_cfg);
-                       charon->bus->set_sa(charon->bus, mediated_sa);
-                       SIG_IKE(UP_FAILED, "mediation failed");
+                       mediated_sa = charon->ike_sa_manager->checkout(
+                                                               charon->ike_sa_manager, this->mediated_sa_id);
+                       if (mediated_sa)
+                       {
+                               DBG1(DBG_IKE, "initiating mediation connection failed");
+                               charon->ike_sa_manager->checkin_and_destroy(
+                                                                       charon->ike_sa_manager, mediated_sa);
+                       }
                        destroy(this);
                        return;
                }
@@ -131,15 +124,20 @@ static void initiate(private_initiate_mediation_job_t *this)
                
                if (mediation_sa)
                {
-                       if (mediation_sa->initiate_mediation(mediation_sa, mediated_cfg) != SUCCESS)
+                       if (mediation_sa->initiate_mediation(mediation_sa,
+                                                                                                mediated_cfg) != SUCCESS)
                        {
-                               DBG1(DBG_JOB, "initiating mediated connection '%s' failed",
-                                               mediated_cfg->get_name(mediated_cfg));
                                mediated_cfg->destroy(mediated_cfg);
-                               charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, mediation_sa);
-                               
-                               charon->bus->set_sa(charon->bus, mediated_sa);
-                               SIG_IKE(UP_FAILED, "mediation failed");
+                               charon->ike_sa_manager->checkin_and_destroy(
+                                                               charon->ike_sa_manager, mediation_sa);
+                               mediated_sa = charon->ike_sa_manager->checkout(
+                                                               charon->ike_sa_manager, this->mediated_sa_id);
+                               if (mediated_sa)
+                               {
+                                       DBG1(DBG_IKE, "establishing mediation connection failed");
+                                       charon->ike_sa_manager->checkin_and_destroy(
+                                                                               charon->ike_sa_manager, mediated_sa);
+                               }
                                destroy(this);
                                return;
                        }
@@ -156,7 +154,7 @@ static void initiate(private_initiate_mediation_job_t *this)
  * Implementation of job_t.execute.
  */ 
 static void reinitiate(private_initiate_mediation_job_t *this)
-{      /* FIXME: check the logging */
+{
        ike_sa_t *mediated_sa, *mediation_sa;
        peer_cfg_t *mediated_cfg;
        
@@ -178,13 +176,17 @@ static void reinitiate(private_initiate_mediation_job_t *this)
                                                mediated_cfg->get_name(mediated_cfg));
                                mediated_cfg->destroy(mediated_cfg);
                                charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, mediation_sa);
-                               
-                               charon->bus->set_sa(charon->bus, mediated_sa);
-                               SIG_IKE(UP_FAILED, "mediation failed");
+                               mediated_sa = charon->ike_sa_manager->checkout(
+                                                               charon->ike_sa_manager, this->mediated_sa_id);
+                               if (mediated_sa)
+                               {
+                                       DBG1(DBG_IKE, "establishing mediation connection failed");
+                                       charon->ike_sa_manager->checkin_and_destroy(
+                                                                               charon->ike_sa_manager, mediated_sa);
+                               }
                                destroy(this);
                                return;
                        }
-                       
                        charon->ike_sa_manager->checkin(charon->ike_sa_manager, mediation_sa);
                }
                
index 58c9d55..29454dd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2006-2008 Tobias Brunner
- * Copyright (C) 2005-2007 Martin Willi
+ * Copyright (C) 2005-2008 Martin Willi
  * Copyright (C) 2006 Daniel Roethlisberger
  * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
 
 #include <daemon.h>
 
-ENUM(child_sa_state_names, CHILD_CREATED, CHILD_DELETING,
+ENUM(child_sa_state_names, CHILD_CREATED, CHILD_DESTROYING,
        "CREATED",
        "ROUTED",
        "INSTALLED",
        "REKEYING",
        "DELETING",
+       "DESTROYING",
 );
 
 typedef struct sa_policy_t sa_policy_t;
@@ -453,11 +454,12 @@ static void updown(private_child_sa_t *this, bool up)
  */
 static void set_state(private_child_sa_t *this, child_sa_state_t state)
 {
-       this->state = state;
        if (state == CHILD_INSTALLED)
        {
                updown(this, TRUE);
        }
+       charon->bus->child_state_change(charon->bus, &this->public, state);
+       this->state = state;
 }
 
 /**
@@ -751,7 +753,7 @@ static status_t add_policies(private_child_sa_t *this,
        /* switch to routed state if no SAD entry set up */
        if (this->state == CHILD_CREATED)
        {
-               this->state = CHILD_ROUTED;
+               set_state(this, CHILD_ROUTED);
        }
        /* needed to update hosts */
        this->mode = mode;
@@ -961,6 +963,8 @@ static void destroy(private_child_sa_t *this)
                updown(this, FALSE);
        }
        
+       set_state(this, CHILD_DESTROYING);
+       
        /* delete SAs in the kernel, if they are set up */
        if (this->me.spi)
        {
index ad8f29d..8b71bd6 100644 (file)
@@ -63,6 +63,11 @@ enum child_sa_state_t {
         * CHILD_SA in progress of delete
         */
        CHILD_DELETING,
+       
+       /**
+        * CHILD_SA object gets destroyed
+        */
+       CHILD_DESTROYING,
 };
 
 /**
index d087383..ef54b83 100644 (file)
@@ -1160,7 +1160,7 @@ static job_requeue_t initiate_mediated(initiate_data_t *data)
                        ike_sa_t *sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, waiting_sa);
                        if (sa->initiate_mediated(sa, pair->local, pair->remote, checklist->connect_id) != SUCCESS)
                        {
-                               SIG_IKE(UP_FAILED, "establishing the mediated connection failed");
+                               DBG1(DBG_IKE, "establishing mediated connection failed");
                                charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, sa);
                        }
                        charon->ike_sa_manager->checkin(charon->ike_sa_manager, sa);
index af2c7d0..5dd522d 100644 (file)
 #define RESOLV_CONF "/etc/resolv.conf"
 #endif
 
-ENUM(ike_sa_state_names, IKE_CREATED, IKE_DELETING,
+ENUM(ike_sa_state_names, IKE_CREATED, IKE_DESTROYING,
        "CREATED",
        "CONNECTING",
        "ESTABLISHED",
        "REKEYING",
        "DELETING",
+       "DESTROYING",
 );
 
 typedef struct private_ike_sa_t private_ike_sa_t;
@@ -750,7 +751,7 @@ static void set_state(private_ike_sa_t *this, ike_sa_state_t state)
                default:
                        break;
        }
-       
+       charon->bus->ike_state_change(charon->bus, &this->public, state);
        this->state = state;
 }
 
@@ -1128,8 +1129,7 @@ static status_t initiate_with_reqid(private_ike_sa_t *this, child_cfg_t *child_c
                        )
                {
                        child_cfg->destroy(child_cfg);
-                       SIG_IKE(UP_START, "initiating IKE_SA");
-                       SIG_IKE(UP_FAILED, "unable to initiate to %%any");
+                       DBG1(DBG_IKE, "unable to initiate to %%any");
                        return DESTROY_ME;
                }
                
@@ -1162,12 +1162,10 @@ static status_t initiate_with_reqid(private_ike_sa_t *this, child_cfg_t *child_c
 
 #ifdef ME
        if (this->peer_cfg->is_mediation(this->peer_cfg))
-       {
-               /* mediation connection */
-               if (this->state == IKE_ESTABLISHED)
-               {       /* FIXME: we should try to find a better solution to this */
-                       SIG_CHD(UP_SUCCESS, NULL, "mediation connection is already up and running");
-               }
+       {       /* mediation connection is already established, retrigger state change
+                * to notify bus listeners */
+               DBG1(DBG_IKE, "mediation connection is already up");
+               set_state(this, IKE_ESTABLISHED);
                DESTROY_IF(child_cfg);
        }
        else
@@ -1216,9 +1214,8 @@ static status_t acquire(private_ike_sa_t *this, u_int32_t reqid)
        
        if (this->state == IKE_DELETING)
        {
-               SIG_CHD(UP_START, NULL, "acquiring CHILD_SA on kernel request");
-               SIG_CHD(UP_FAILED, NULL, "acquiring CHILD_SA {reqid %d} failed: "
-                       "IKE_SA is deleting", reqid);
+               DBG1(DBG_IKE, "acquiring CHILD_SA {reqid %d} failed: "
+                        "IKE_SA is deleting", reqid);
                return FAILED;
        }
        
@@ -1235,9 +1232,8 @@ static status_t acquire(private_ike_sa_t *this, u_int32_t reqid)
        iterator->destroy(iterator);
        if (!child_sa)
        {
-               SIG_CHD(UP_START, NULL, "acquiring CHILD_SA on kernel request");
-               SIG_CHD(UP_FAILED, NULL, "acquiring CHILD_SA {reqid %d} failed: "
-                       "CHILD_SA not found", reqid);
+               DBG1(DBG_IKE, "acquiring CHILD_SA {reqid %d} failed: "
+                        "CHILD_SA not found", reqid);
                return FAILED;
        }
        
@@ -1258,8 +1254,6 @@ static status_t route(private_ike_sa_t *this, child_cfg_t *child_cfg)
        host_t *me, *other;
        status_t status;
        
-       SIG_CHD(ROUTE_START, NULL, "routing CHILD_SA");
-       
        /* check if not already routed*/
        iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
        while (iterator->iterate(iterator, (void**)&child_sa))
@@ -1268,7 +1262,7 @@ static status_t route(private_ike_sa_t *this, child_cfg_t *child_cfg)
                        streq(child_sa->get_name(child_sa), child_cfg->get_name(child_cfg)))
                {
                        iterator->destroy(iterator);
-                       SIG_CHD(ROUTE_FAILED, child_sa, "CHILD_SA with such a config already routed");
+                       DBG1(DBG_IKE, "routing CHILD_SA failed: already routed");
                        return FAILED;
                }
        }
@@ -1278,8 +1272,8 @@ static status_t route(private_ike_sa_t *this, child_cfg_t *child_cfg)
        {
                case IKE_DELETING:
                case IKE_REKEYING:
-                       SIG_CHD(ROUTE_FAILED, NULL, 
-                               "unable to route CHILD_SA, as its IKE_SA gets deleted");
+                       DBG1(DBG_IKE, "routing CHILD_SA failed: IKE_SA is %N",
+                                ike_sa_state_names, this->state);
                        return FAILED;
                case IKE_CREATED:
                case IKE_CONNECTING:
@@ -1313,11 +1307,11 @@ static status_t route(private_ike_sa_t *this, child_cfg_t *child_cfg)
        if (status == SUCCESS)
        {
                this->child_sas->insert_last(this->child_sas, child_sa);
-               SIG_CHD(ROUTE_SUCCESS, child_sa, "CHILD_SA routed");
+               DBG1(DBG_IKE, "CHILD_SA routed");
        }
        else
        {
-               SIG_CHD(ROUTE_FAILED, child_sa, "routing CHILD_SA failed");
+               DBG1(DBG_IKE, "routing CHILD_SA failed");
        }
        return status;
 }
@@ -1331,8 +1325,6 @@ static status_t unroute(private_ike_sa_t *this, u_int32_t reqid)
        child_sa_t *child_sa;
        bool found = FALSE;
        
-       SIG_CHD(UNROUTE_START, NULL, "unrouting CHILD_SA");
-       
        /* find CHILD_SA in ROUTED state */
        iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
        while (iterator->iterate(iterator, (void**)&child_sa))
@@ -1341,7 +1333,7 @@ static status_t unroute(private_ike_sa_t *this, u_int32_t reqid)
                        child_sa->get_reqid(child_sa) == reqid)
                {
                        iterator->remove(iterator);
-                       SIG_CHD(UNROUTE_SUCCESS, child_sa, "CHILD_SA unrouted");
+                       DBG1(DBG_IKE, "CHILD_SA unrouted");
                        child_sa->destroy(child_sa);
                        found = TRUE;
                        break;
@@ -1351,7 +1343,7 @@ static status_t unroute(private_ike_sa_t *this, u_int32_t reqid)
        
        if (!found)
        {
-               SIG_CHD(UNROUTE_FAILED, NULL, "CHILD_SA to unroute not found");
+               DBG1(DBG_IKE, "unrouting CHILD_SA failed: reqid %d not found", reqid);
                return FAILED;
        }
        /* if we are not established, and we have no more routed childs, remove whole SA */
@@ -1939,10 +1931,10 @@ static status_t delete_(private_ike_sa_t *this)
                        this->task_manager->queue_task(this->task_manager, &ike_delete->task);
                        return this->task_manager->initiate(this->task_manager);
                case IKE_CREATED:
-                       SIG_IKE(DOWN_SUCCESS, "deleting unestablished IKE_SA");
+                       DBG1(DBG_IKE, "deleting unestablished IKE_SA");
                        break;
                default:
-                       SIG_IKE(DOWN_SUCCESS, "destroying IKE_SA in state %N "
+                       DBG1(DBG_IKE, "destroying IKE_SA in state %N "
                                "without notification", ike_sa_state_names, this->state);
                        break;
        }
@@ -2146,19 +2138,19 @@ static status_t retransmit(private_ike_sa_t *this, u_int32_t message_id)
                                this->keyingtry++;
                                if (tries == 0 || tries > this->keyingtry)
                                {
-                                       SIG_IKE(UP_FAILED, "peer not responding, trying again "
-                                               "(%d/%d) in background ", this->keyingtry + 1, tries);
+                                       DBG1(DBG_IKE, "peer not responding, trying again (%d/%d)",
+                                                this->keyingtry + 1, tries);
                                        reset(this);
                                        return this->task_manager->initiate(this->task_manager);
                                }
-                               SIG_IKE(UP_FAILED, "establishing IKE_SA failed, peer not responding");
+                               DBG1(DBG_IKE, "establishing IKE_SA failed, peer not responding");
                                break;
                        }
                        case IKE_DELETING:
-                               SIG_IKE(DOWN_FAILED, "proper IKE_SA delete failed, peer not responding");
+                               DBG1(DBG_IKE, "proper IKE_SA delete failed, peer not responding");
                                break;
                        case IKE_REKEYING:
-                               SIG_IKE(REKEY_FAILED, "rekeying IKE_SA failed, peer not responding");
+                               DBG1(DBG_IKE, "rekeying IKE_SA failed, peer not responding");
                                /* FALL */
                        default:
                                reestablish(this);
@@ -2485,6 +2477,8 @@ static void add_dns_server(private_ike_sa_t *this, host_t *dns)
  */
 static void destroy(private_ike_sa_t *this)
 {
+       set_state(this, IKE_DESTROYING);
+       
        this->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
        
        this->task_manager->destroy(this->task_manager);
index 3cd9e00..64267b1 100644 (file)
@@ -201,6 +201,11 @@ enum ike_sa_state_t {
         * IKE_SA is in progress of deletion
         */
        IKE_DELETING,
+       
+       /**
+        * IKE_SA object gets destroyed
+        */
+       IKE_DESTROYING,
 };
 
 /**
index 2cec816..02cb62c 100644 (file)
@@ -151,38 +151,11 @@ static void flush(private_task_manager_t *this)
                                                                                offsetof(task_t, destroy));
        this->passive_tasks->destroy_offset(this->passive_tasks,
                                                                                offsetof(task_t, destroy));
-       
-       /* emmit outstanding signals for tasks */
-       while (this->active_tasks->remove_last(this->active_tasks,
-                                                                                  (void**)&task) == SUCCESS)
-       {
-               switch (task->get_type(task))
-               {
-                       case IKE_AUTH:
-                               SIG_IKE(UP_FAILED, "establishing IKE_SA failed");
-                               break;
-                       case IKE_DELETE:
-                               SIG_IKE(DOWN_FAILED, "IKE_SA deleted");
-                               break;
-                       case IKE_REKEY:
-                               SIG_IKE(REKEY_FAILED, "rekeying IKE_SA failed");
-                               break;
-                       case CHILD_CREATE:
-                               SIG_CHD(UP_FAILED, NULL, "establishing CHILD_SA failed");
-                               break;
-                       case CHILD_DELETE:
-                               SIG_CHD(DOWN_FAILED, NULL, "deleting CHILD_SA failed");
-                               break;
-                       case CHILD_REKEY:
-                               SIG_IKE(REKEY_FAILED, "rekeying CHILD_SA failed");
-                               break;
-                       default:
-                               break;
-               }
-               task->destroy(task);
-       }
+       this->active_tasks->destroy_offset(this->active_tasks,
+                                                                               offsetof(task_t, destroy));
        this->queued_tasks = linked_list_create();
        this->passive_tasks = linked_list_create();
+       this->active_tasks = linked_list_create();
 }
 
 /**
@@ -648,6 +621,7 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
        DESTROY_IF(this->responding.packet);
        status = this->ike_sa->generate_message(this->ike_sa, message,
                                                                                        &this->responding.packet);
+       charon->bus->message(charon->bus, message, FALSE);
        message->destroy(message);
        if (status != SUCCESS)
        {
@@ -867,6 +841,7 @@ static status_t process_message(private_task_manager_t *this, message_t *msg)
        {
                if (mid == this->responding.mid)
                {
+                       charon->bus->message(charon->bus, msg, TRUE);
                        if (process_request(this, msg) != SUCCESS)
                        {
                                flush(this);
index 9a2af52..6c67392 100644 (file)
@@ -199,12 +199,12 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
        
        if (this->proposals == NULL)
        {
-               SIG_CHD(UP_FAILED, this->child_sa, "SA payload missing in message");
+               DBG1(DBG_IKE, "SA payload missing in message");
                return FAILED;
        }
        if (this->tsi == NULL || this->tsr == NULL)
        {
-               SIG_CHD(UP_FAILED, this->child_sa, "TS payloads missing in message");
+               DBG1(DBG_IKE, "TS payloads missing in message");
                return NOT_FOUND;
        }
        
@@ -232,7 +232,7 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
                                                                                                   no_dh);
        if (this->proposal == NULL)
        {
-               SIG_CHD(UP_FAILED, this->child_sa, "no acceptable proposal found");
+               DBG1(DBG_IKE, "no acceptable proposal found");
                return FAILED;
        }
        
@@ -243,15 +243,15 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
                if (this->proposal->get_algorithm(this->proposal, DIFFIE_HELLMAN_GROUP,
                                                                                  &group, NULL))
                {
-                       SIG_CHD(UP_FAILED, this->child_sa, "DH group %N inacceptable, "
-                                       "requesting %N", diffie_hellman_group_names, this->dh_group,
-                                       diffie_hellman_group_names, group);
+                       DBG1(DBG_IKE, "DH group %N inacceptable, requesting %N",
+                                diffie_hellman_group_names, this->dh_group,
+                                diffie_hellman_group_names, group);
                        this->dh_group = group;
                        return INVALID_ARG;
                }
                else
                {
-                       SIG_CHD(UP_FAILED, this->child_sa, "no acceptable proposal found");
+                       DBG1(DBG_IKE, "no acceptable proposal found");
                        return FAILED;
                }
        }
@@ -279,7 +279,7 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
        {
                my_ts->destroy_offset(my_ts, offsetof(traffic_selector_t, destroy));
                other_ts->destroy_offset(other_ts, offsetof(traffic_selector_t, destroy));
-               SIG_CHD(UP_FAILED, this->child_sa, "no acceptable traffic selectors found");
+               DBG1(DBG_IKE, "no acceptable traffic selectors found");
                return NOT_FOUND;
        }
        
@@ -331,7 +331,7 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
        {
                if (this->dh->get_shared_secret(this->dh, &secret) != SUCCESS)
                {
-                       SIG_CHD(UP_FAILED, this->child_sa, "DH exchange incomplete");
+                       DBG1(DBG_IKE, "DH exchange incomplete");
                        return FAILED;
                }
                DBG3(DBG_IKE, "DH secret %B", &secret);
@@ -352,8 +352,7 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
                                        this->mode, this->proposal->get_protocol(this->proposal));
        if (status != SUCCESS)
        {       
-               SIG_CHD(UP_FAILED, this->child_sa, 
-                               "unable to install IPsec policies (SPD) in kernel");
+               DBG1(DBG_IKE, "unable to install IPsec policies (SPD) in kernel");
                return NOT_FOUND;
        }
        
@@ -372,8 +371,7 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
        
        if (status != SUCCESS)
        {
-               SIG_CHD(UP_FAILED, this->child_sa, 
-                               "unable to install IPsec SA (SAD) in kernel");
+               DBG1(DBG_IKE, "unable to install IPsec SA (SAD) in kernel");
                return FAILED;
        }
        /* add to IKE_SA, and remove from task */
@@ -592,13 +590,13 @@ static status_t build_i(private_child_create_t *this, message_t *message)
        
        if (this->reqid)
        {
-               SIG_CHD(UP_START, NULL, "establishing CHILD_SA %s{%d}",
-                               this->config->get_name(this->config), this->reqid);
+               DBG1(DBG_IKE, "establishing CHILD_SA %s{%d}",
+                        this->config->get_name(this->config), this->reqid);
        }
        else
        {
-               SIG_CHD(UP_START, NULL, "establishing CHILD_SA %s",
-                               this->config->get_name(this->config));
+               DBG1(DBG_IKE, "establishing CHILD_SA %s",
+                        this->config->get_name(this->config));
        }
        
        /* reuse virtual IP if we already have one */
@@ -650,8 +648,7 @@ static status_t build_i(private_child_create_t *this, message_t *message)
        
        if (this->child_sa->alloc(this->child_sa, this->proposals) != SUCCESS)
        {
-               SIG_CHD(UP_FAILED, this->child_sa,
-                               "unable to allocate SPIs from kernel");
+               DBG1(DBG_IKE, "unable to allocate SPIs from kernel");
                return FAILED;
        }
        
@@ -785,16 +782,15 @@ static status_t build_r(private_child_create_t *this, message_t *message)
        
        if (this->ike_sa->get_state(this->ike_sa) == IKE_REKEYING)
        {
-               SIG_CHD(UP_FAILED, NULL,
-                               "unable to create CHILD_SA while rekeying IKE_SA");
+               DBG1(DBG_IKE, "unable to create CHILD_SA while rekeying IKE_SA");
                message->add_notify(message, TRUE, NO_ADDITIONAL_SAS, chunk_empty);
                return SUCCESS;
        }
        
        if (this->config == NULL)
        {
-               SIG_CHD(UP_FAILED, NULL, "traffic selectors %#R=== %#R inacceptable",
-                       this->tsr, this->tsi);
+               DBG1(DBG_IKE, "traffic selectors %#R=== %#R inacceptable",
+                        this->tsr, this->tsi);
                message->add_notify(message, FALSE, TS_UNACCEPTABLE, chunk_empty);
                handle_child_sa_failure(this, message);
                return SUCCESS;
@@ -813,8 +809,8 @@ static status_t build_r(private_child_create_t *this, message_t *message)
                                case INTERNAL_ADDRESS_FAILURE:
                                case FAILED_CP_REQUIRED:
                                {
-                                       SIG_CHD(UP_FAILED, NULL, "configuration payload negotation "
-                                               "failed, no CHILD_SA built");
+                                       DBG1(DBG_IKE,"configuration payload negotation "
+                                                "failed, no CHILD_SA built");
                                        iterator->destroy(iterator);
                                        handle_child_sa_failure(this, message);
                                        return SUCCESS;
@@ -870,14 +866,14 @@ static status_t build_r(private_child_create_t *this, message_t *message)
        
        build_payloads(this, message);
        
-       SIG_CHD(UP_SUCCESS, this->child_sa, "CHILD_SA %s{%d} established "
-                       "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
-                       this->child_sa->get_name(this->child_sa),
-                       this->child_sa->get_reqid(this->child_sa),
-                       ntohl(this->child_sa->get_spi(this->child_sa, TRUE)),
-                       ntohl(this->child_sa->get_spi(this->child_sa, FALSE)),
-                       this->child_sa->get_traffic_selectors(this->child_sa, TRUE),
-                       this->child_sa->get_traffic_selectors(this->child_sa, FALSE));
+       DBG0(DBG_IKE, "CHILD_SA %s{%d} established "
+                "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
+                this->child_sa->get_name(this->child_sa),
+                this->child_sa->get_reqid(this->child_sa),
+                ntohl(this->child_sa->get_spi(this->child_sa, TRUE)),
+                ntohl(this->child_sa->get_spi(this->child_sa, FALSE)),
+                this->child_sa->get_traffic_selectors(this->child_sa, TRUE),
+                this->child_sa->get_traffic_selectors(this->child_sa, FALSE));
 
        return SUCCESS;
 }
@@ -929,8 +925,8 @@ static status_t process_i(private_child_create_t *this, message_t *message)
                                case TS_UNACCEPTABLE:
                                case INVALID_SELECTORS:
                                {
-                                       SIG_CHD(UP_FAILED, this->child_sa, "received %N notify, "
-                                                       "no CHILD_SA built", notify_type_names, type);
+                                       DBG1(DBG_IKE, "received %N notify, no CHILD_SA built",
+                                                notify_type_names, type);
                                        iterator->destroy(iterator);
                                        handle_child_sa_failure(this, message);
                                        /* an error in CHILD_SA creation is not critical */
@@ -963,35 +959,35 @@ static status_t process_i(private_child_create_t *this, message_t *message)
        
        if (this->ipcomp == IPCOMP_NONE && this->ipcomp_received != IPCOMP_NONE)
        {
-               SIG_CHD(UP_FAILED, this->child_sa, "received an IPCOMP_SUPPORTED notify"
-                               " but we did not send one previously, no CHILD_SA built");
+               DBG1(DBG_IKE, "received an IPCOMP_SUPPORTED notify without requesting"
+                        " one, no CHILD_SA built");
                handle_child_sa_failure(this, message);
                return SUCCESS;
        }
        else if (this->ipcomp != IPCOMP_NONE && this->ipcomp_received == IPCOMP_NONE)
        {
                DBG1(DBG_IKE, "peer didn't accept our proposed IPComp transforms, "
-                               "IPComp is disabled");
+                        "IPComp is disabled");
                this->ipcomp = IPCOMP_NONE;
        }
        else if (this->ipcomp != IPCOMP_NONE && this->ipcomp != this->ipcomp_received)
        {
-               SIG_CHD(UP_FAILED, this->child_sa, "received an IPCOMP_SUPPORTED notify"
-                               " for a transform we did not propose, no CHILD_SA built");
+               DBG1(DBG_IKE, "received an IPCOMP_SUPPORTED notify we didn't propose, "
+                        "no CHILD_SA built");
                handle_child_sa_failure(this, message);
                return SUCCESS;
        }
        
        if (select_and_install(this, no_dh) == SUCCESS)
        {
-               SIG_CHD(UP_SUCCESS, this->child_sa, "CHILD_SA %s{%d} established "
-                               "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
-                               this->child_sa->get_name(this->child_sa),
-                               this->child_sa->get_reqid(this->child_sa),
-                               ntohl(this->child_sa->get_spi(this->child_sa, TRUE)),
-                               ntohl(this->child_sa->get_spi(this->child_sa, FALSE)),
-                               this->child_sa->get_traffic_selectors(this->child_sa, TRUE),
-                               this->child_sa->get_traffic_selectors(this->child_sa, FALSE));
+               DBG0(DBG_IKE, "CHILD_SA %s{%d} established "
+                        "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
+                        this->child_sa->get_name(this->child_sa),
+                        this->child_sa->get_reqid(this->child_sa),
+                        ntohl(this->child_sa->get_spi(this->child_sa, TRUE)),
+                        ntohl(this->child_sa->get_spi(this->child_sa, FALSE)),
+                        this->child_sa->get_traffic_selectors(this->child_sa, TRUE),
+                        this->child_sa->get_traffic_selectors(this->child_sa, FALSE));
        }
        else
        {
index 1318a9b..45c7775 100644 (file)
@@ -222,14 +222,13 @@ static void log_children(private_child_delete_t *this)
        iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
        while (iterator->iterate(iterator, (void**)&child_sa))
        {
-               SIG_CHD(DOWN_START, child_sa, "closing CHILD_SA %s{%d} "
-                               "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
-                               child_sa->get_name(child_sa),
-                               child_sa->get_reqid(child_sa),
-                               ntohl(child_sa->get_spi(child_sa, TRUE)),
-                               ntohl(child_sa->get_spi(child_sa, FALSE)),
-                               child_sa->get_traffic_selectors(child_sa, TRUE),
-                               child_sa->get_traffic_selectors(child_sa, FALSE));
+               DBG0(DBG_IKE, "closing CHILD_SA %s{%d} "
+                        "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
+                        child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
+                        ntohl(child_sa->get_spi(child_sa, TRUE)),
+                        ntohl(child_sa->get_spi(child_sa, FALSE)),
+                        child_sa->get_traffic_selectors(child_sa, TRUE),
+                        child_sa->get_traffic_selectors(child_sa, FALSE));
        }
        iterator->destroy(iterator);
 }
@@ -254,7 +253,7 @@ static status_t process_i(private_child_delete_t *this, message_t *message)
        this->child_sas = linked_list_create();
        
        process_payloads(this, message);
-       SIG_CHD(DOWN_SUCCESS, NULL, "CHILD_SA closed");
+       DBG1(DBG_IKE, "CHILD_SA closed");
        return destroy_and_reestablish(this);
 }
 
@@ -278,7 +277,7 @@ static status_t build_r(private_child_delete_t *this, message_t *message)
        {
                build_payloads(this, message);  
        }
-       SIG_CHD(DOWN_SUCCESS, NULL, "CHILD_SA closed");
+       DBG1(DBG_IKE, "CHILD_SA closed");
        return destroy_and_reestablish(this);
 }
 
index 2954963..2286c7c 100644 (file)
@@ -201,15 +201,15 @@ static status_t build_auth(private_ike_auth_t *this, message_t *message)
        config = this->ike_sa->get_peer_cfg(this->ike_sa);
        if (!config)
        {
-               SIG_IKE(UP_FAILED, "unable to authenticate, no peer config found");
+               DBG1(DBG_IKE, "unable to authenticate, no peer config found");
                return FAILED;
        }
        
        auth = authenticator_create_from_class(this->ike_sa, get_auth_class(config));
        if (auth == NULL)
        {
-               SIG_IKE(UP_FAILED, "configured authentication class %N not supported",
-                       auth_class_names, get_auth_class(config));
+               DBG1(DBG_IKE, "configured authentication class %N not supported",
+                        auth_class_names, get_auth_class(config));
                return FAILED;
        }
        
@@ -218,7 +218,7 @@ static status_t build_auth(private_ike_auth_t *this, message_t *message)
        auth->destroy(auth);
        if (status != SUCCESS)
        {
-               SIG_IKE(UP_FAILED, "generating authentication data failed");
+               DBG1(DBG_IKE, "generating authentication data failed");
                return FAILED;
        }
        message->add_payload(message, (payload_t*)auth_payload);
@@ -243,7 +243,7 @@ static status_t build_id(private_ike_auth_t *this, message_t *message)
                me = config->get_my_id(config);
                if (me->contains_wildcards(me))
                {
-                       SIG_IKE(UP_FAILED, "negotiation of own ID failed");
+                       DBG1(DBG_IKE, "negotiation of own ID failed");
                        return FAILED;
                }
                this->ike_sa->set_my_id(this->ike_sa, me->clone(me));
@@ -284,8 +284,8 @@ static status_t process_auth(private_ike_auth_t *this, message_t *message)
                                                                        auth_payload->get_auth_method(auth_payload));
        if (auth == NULL)
        {
-               SIG_IKE(UP_FAILED, "authentication method %N used by '%D' not "
-                       "supported", auth_method_names, auth_method,
+               DBG1(DBG_IKE, "authentication method %N used by '%D' not supported",
+                       auth_method_names, auth_method,
                        this->ike_sa->get_other_id(this->ike_sa));
                return NOT_SUPPORTED;
        }
@@ -294,7 +294,7 @@ static status_t process_auth(private_ike_auth_t *this, message_t *message)
        auth->destroy(auth);
        if (status != SUCCESS)
        {
-               SIG_IKE(UP_FAILED, "authentication of '%D' with %N failed",
+               DBG0(DBG_IKE, "authentication of '%D' with %N failed",
                         this->ike_sa->get_other_id(this->ike_sa), 
                         auth_method_names, auth_method);       
                return FAILED;
@@ -315,7 +315,7 @@ static status_t process_id(private_ike_auth_t *this, message_t *message)
 
        if ((this->initiator && idr == NULL) || (!this->initiator && idi == NULL))
        {
-               SIG_IKE(UP_FAILED, "ID payload missing in message");
+               DBG1(DBG_IKE, "ID payload missing in message");
                return FAILED;
        }
        
@@ -325,7 +325,7 @@ static status_t process_id(private_ike_auth_t *this, message_t *message)
                req = this->ike_sa->get_other_id(this->ike_sa);
                if (!id->matches(id, req))
                {
-                       SIG_IKE(UP_FAILED, "peer ID '%D' unacceptable, '%D' required", id, req);
+                       DBG0(DBG_IKE, "peer ID '%D' unacceptable, '%D' required", id, req);
                        id->destroy(id);
                        return FAILED;
                }
@@ -402,7 +402,7 @@ static status_t build_auth_eap(private_ike_auth_t *this, message_t *message)
        if (auth->build(auth, this->my_packet->get_data(this->my_packet),
                this->other_nonce, &auth_payload) != SUCCESS)
        {
-               SIG_IKE(UP_FAILED, "generating authentication data failed");
+               DBG1(DBG_IKE, "generating authentication data failed");
                if (!this->initiator)
                {
                        message->add_notify(message, TRUE, AUTHENTICATION_FAILED, chunk_empty);
@@ -413,13 +413,13 @@ static status_t build_auth_eap(private_ike_auth_t *this, message_t *message)
        if (!this->initiator)
        {
                this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED);
-               SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
-                       this->ike_sa->get_name(this->ike_sa),
-                       this->ike_sa->get_unique_id(this->ike_sa),
-                       this->ike_sa->get_my_host(this->ike_sa),
-                       this->ike_sa->get_my_id(this->ike_sa), 
-                       this->ike_sa->get_other_host(this->ike_sa),
-                       this->ike_sa->get_other_id(this->ike_sa));
+               DBG0(DBG_IKE, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
+                        this->ike_sa->get_name(this->ike_sa),
+                        this->ike_sa->get_unique_id(this->ike_sa),
+                        this->ike_sa->get_my_host(this->ike_sa),
+                        this->ike_sa->get_my_id(this->ike_sa), 
+                        this->ike_sa->get_other_host(this->ike_sa),
+                        this->ike_sa->get_other_id(this->ike_sa));
                return SUCCESS;
        }
        return NEED_MORE;
@@ -448,7 +448,7 @@ static status_t process_auth_eap(private_ike_auth_t *this, message_t *message)
 
        if (!this->peer_authenticated)
        {
-               SIG_IKE(UP_FAILED, "authentication of '%D' with %N failed",
+               DBG0(DBG_IKE, "authentication of '%D' with %N failed",
                         this->ike_sa->get_other_id(this->ike_sa), 
                         auth_class_names, AUTH_CLASS_EAP);
                if (this->initiator)
@@ -460,13 +460,13 @@ static status_t process_auth_eap(private_ike_auth_t *this, message_t *message)
        if (this->initiator)
        {
                this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED);
-               SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
-                       this->ike_sa->get_name(this->ike_sa),
-                       this->ike_sa->get_unique_id(this->ike_sa),
-                       this->ike_sa->get_my_host(this->ike_sa),
-                       this->ike_sa->get_my_id(this->ike_sa), 
-                       this->ike_sa->get_other_host(this->ike_sa),
-                       this->ike_sa->get_other_id(this->ike_sa));
+               DBG0(DBG_IKE, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
+                        this->ike_sa->get_name(this->ike_sa),
+                        this->ike_sa->get_unique_id(this->ike_sa),
+                        this->ike_sa->get_my_host(this->ike_sa),
+                        this->ike_sa->get_my_id(this->ike_sa), 
+                        this->ike_sa->get_other_host(this->ike_sa),
+                        this->ike_sa->get_other_id(this->ike_sa));
                return SUCCESS;
        }
        return NEED_MORE;
@@ -482,7 +482,7 @@ static status_t process_eap_i(private_ike_auth_t *this, message_t *message)
        eap = (eap_payload_t*)message->get_payload(message, EXTENSIBLE_AUTHENTICATION);
        if (eap == NULL)
        {       
-               SIG_IKE(UP_FAILED, "EAP payload missing");
+               DBG1(DBG_IKE, "EAP payload missing");
                return FAILED;
        }
        switch (this->eap_auth->process(this->eap_auth, eap, &eap))
@@ -498,7 +498,7 @@ static status_t process_eap_i(private_ike_auth_t *this, message_t *message)
                        return NEED_MORE;
                default:
                        this->eap_payload = NULL;
-                       SIG_IKE(UP_FAILED, "failed to authenticate against '%D' using EAP",
+                       DBG0(DBG_IKE, "failed to authenticate against '%D' using EAP",
                                this->ike_sa->get_other_id(this->ike_sa));
                        return FAILED;
        }
@@ -533,7 +533,7 @@ static status_t build_eap_r(private_ike_auth_t *this, message_t *message)
                
        if (this->eap_payload == NULL)
        {
-               SIG_IKE(UP_FAILED, "EAP payload missing");
+               DBG1(DBG_IKE, "EAP payload missing");
                return FAILED;
        }
        
@@ -548,9 +548,9 @@ static status_t build_eap_r(private_ike_auth_t *this, message_t *message)
                        this->public.task.process = (status_t(*)(task_t*,message_t*))process_auth_eap;
                        break;
                default:
-                       SIG_IKE(UP_FAILED, "authentication of '%D' with %N failed",
-                               this->ike_sa->get_other_id(this->ike_sa),
-                               auth_class_names, AUTH_CLASS_EAP);
+                       DBG0(DBG_IKE, "authentication of '%D' with %N failed",
+                                this->ike_sa->get_other_id(this->ike_sa),
+                                auth_class_names, AUTH_CLASS_EAP);
                        status = FAILED;
                        break;
        }
@@ -665,9 +665,9 @@ static status_t build_r(private_ike_auth_t *this, message_t *message)
        config = this->ike_sa->get_peer_cfg(this->ike_sa);
        if (config == NULL)
        {
-               SIG_IKE(UP_FAILED, "no matching config found for '%D'...'%D'",
-                       this->ike_sa->get_my_id(this->ike_sa),
-                       this->ike_sa->get_other_id(this->ike_sa));
+               DBG1(DBG_IKE, "no matching config found for '%D'...'%D'",
+                        this->ike_sa->get_my_id(this->ike_sa),
+                        this->ike_sa->get_other_id(this->ike_sa));
                message->add_notify(message, TRUE, AUTHENTICATION_FAILED, chunk_empty);
                return FAILED;
        }
@@ -689,13 +689,13 @@ static status_t build_r(private_ike_auth_t *this, message_t *message)
        if (this->peer_authenticated)
        {
                this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED);
-               SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
-                       this->ike_sa->get_name(this->ike_sa),
-                       this->ike_sa->get_unique_id(this->ike_sa),
-                       this->ike_sa->get_my_host(this->ike_sa),
-                       this->ike_sa->get_my_id(this->ike_sa), 
-                       this->ike_sa->get_other_host(this->ike_sa),
-                       this->ike_sa->get_other_id(this->ike_sa));
+               DBG0(DBG_IKE, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
+                        this->ike_sa->get_name(this->ike_sa),
+                        this->ike_sa->get_unique_id(this->ike_sa),
+                        this->ike_sa->get_my_host(this->ike_sa),
+                        this->ike_sa->get_my_id(this->ike_sa), 
+                        this->ike_sa->get_other_host(this->ike_sa),
+                        this->ike_sa->get_other_id(this->ike_sa));
                return SUCCESS;
        }
        
@@ -706,7 +706,7 @@ static status_t build_r(private_ike_auth_t *this, message_t *message)
        message->add_payload(message, (payload_t*)eap_payload);
        if (status != NEED_MORE)
        {
-               SIG_IKE(UP_FAILED, "unable to initiate EAP authentication");
+               DBG1(DBG_IKE, "unable to initiate EAP authentication");
                return FAILED;
        }
        
@@ -766,7 +766,7 @@ static status_t process_i(private_ike_auth_t *this, message_t *message)
                                {
                                        if (type < 16383)
                                        {
-                                               SIG_IKE(UP_FAILED, "received %N notify error",
+                                               DBG1(DBG_IKE, "received %N notify error",
                                                         notify_type_names, type);
                                                iterator->destroy(iterator);
                                                return FAILED;  
@@ -798,18 +798,18 @@ static status_t process_i(private_ike_auth_t *this, message_t *message)
        auth = this->ike_sa->get_other_auth(this->ike_sa);
        if (!auth->complies(auth, config->get_auth(config)))
        {
-               SIG_IKE(UP_FAILED, "authorization of '%D' for config %s failed",
+               DBG0(DBG_IKE, "authorization of '%D' for config %s failed",
                        this->ike_sa->get_other_id(this->ike_sa), config->get_name(config));
                return FAILED;
        }
        this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED);
-       SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
-               this->ike_sa->get_name(this->ike_sa),
-               this->ike_sa->get_unique_id(this->ike_sa),
-               this->ike_sa->get_my_host(this->ike_sa),
-               this->ike_sa->get_my_id(this->ike_sa),
-               this->ike_sa->get_other_host(this->ike_sa),
-               this->ike_sa->get_other_id(this->ike_sa));
+       DBG0(DBG_IKE, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
+                this->ike_sa->get_name(this->ike_sa),
+                this->ike_sa->get_unique_id(this->ike_sa),
+                this->ike_sa->get_my_host(this->ike_sa),
+                this->ike_sa->get_my_id(this->ike_sa),
+                this->ike_sa->get_other_host(this->ike_sa),
+                this->ike_sa->get_other_id(this->ike_sa));
        return SUCCESS;
 }
 
index d685320..15645e0 100644 (file)
@@ -56,21 +56,21 @@ static status_t build_i(private_ike_delete_t *this, message_t *message)
 {
        delete_payload_t *delete_payload;
 
-       SIG_IKE(DOWN_START, "deleting IKE_SA %s[%d] between %H[%D]...%H[%D]",
-                       this->ike_sa->get_name(this->ike_sa),
-                       this->ike_sa->get_unique_id(this->ike_sa),
-                       this->ike_sa->get_my_host(this->ike_sa),
-                       this->ike_sa->get_my_id(this->ike_sa),
-                       this->ike_sa->get_other_host(this->ike_sa),
-                       this->ike_sa->get_other_id(this->ike_sa));
+       DBG0(DBG_IKE, "deleting IKE_SA %s[%d] between %H[%D]...%H[%D]",
+                this->ike_sa->get_name(this->ike_sa),
+                this->ike_sa->get_unique_id(this->ike_sa),
+                this->ike_sa->get_my_host(this->ike_sa),
+                this->ike_sa->get_my_id(this->ike_sa),
+                this->ike_sa->get_other_host(this->ike_sa),
+                this->ike_sa->get_other_id(this->ike_sa));
 
        delete_payload = delete_payload_create(PROTO_IKE);
        message->add_payload(message, (payload_t*)delete_payload);
        this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
 
        DBG1(DBG_IKE, "sending DELETE for IKE_SA %s[%d]",
-                       this->ike_sa->get_name(this->ike_sa),
-                       this->ike_sa->get_unique_id(this->ike_sa));
+                this->ike_sa->get_name(this->ike_sa),
+                this->ike_sa->get_unique_id(this->ike_sa));
 
        return NEED_MORE;
 }
@@ -92,15 +92,15 @@ static status_t process_r(private_ike_delete_t *this, message_t *message)
        /* we don't even scan the payloads, as the message wouldn't have
         * come so far without being correct */
        DBG1(DBG_IKE, "received DELETE for IKE_SA %s[%d]",
-                       this->ike_sa->get_name(this->ike_sa),
-                       this->ike_sa->get_unique_id(this->ike_sa));
-       SIG_IKE(DOWN_START, "deleting IKE_SA %s[%d] between %H[%D]...%H[%D]",
-                       this->ike_sa->get_name(this->ike_sa),
-                       this->ike_sa->get_unique_id(this->ike_sa),
-                       this->ike_sa->get_my_host(this->ike_sa),
-                       this->ike_sa->get_my_id(this->ike_sa),
-                       this->ike_sa->get_other_host(this->ike_sa),
-                       this->ike_sa->get_other_id(this->ike_sa));
+                this->ike_sa->get_name(this->ike_sa),
+                this->ike_sa->get_unique_id(this->ike_sa));
+       DBG1(DBG_IKE, "deleting IKE_SA %s[%d] between %H[%D]...%H[%D]",
+                this->ike_sa->get_name(this->ike_sa),
+                this->ike_sa->get_unique_id(this->ike_sa),
+                this->ike_sa->get_my_host(this->ike_sa),
+                this->ike_sa->get_my_id(this->ike_sa),
+                this->ike_sa->get_other_host(this->ike_sa),
+                this->ike_sa->get_other_id(this->ike_sa));
 
        switch (this->ike_sa->get_state(this->ike_sa))
        {
@@ -123,7 +123,7 @@ static status_t process_r(private_ike_delete_t *this, message_t *message)
  */
 static status_t build_r(private_ike_delete_t *this, message_t *message)
 {
-       SIG_IKE(DOWN_SUCCESS, "IKE_SA deleted");
+       DBG1(DBG_IKE, "IKE_SA deleted");
 
        if (this->simultaneous)
        {
index bd4feb0..388d9f4 100644 (file)
@@ -230,15 +230,15 @@ static status_t build_i(private_ike_init_t *this, message_t *message)
        rng_t *rng;
        
        this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
-       SIG_IKE(UP_START, "initiating IKE_SA %s[%d] to %H",
-               this->ike_sa->get_name(this->ike_sa),
-               this->ike_sa->get_unique_id(this->ike_sa),
-               this->ike_sa->get_other_host(this->ike_sa));
+       DBG1(DBG_IKE, "initiating IKE_SA %s[%d] to %H",
+                this->ike_sa->get_name(this->ike_sa),
+                this->ike_sa->get_unique_id(this->ike_sa),
+                this->ike_sa->get_other_host(this->ike_sa));
        this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
        
        if (this->retry++ >= MAX_RETRIES)
        {
-               SIG_IKE(UP_FAILED, "giving up after %d retries", MAX_RETRIES);
+               DBG1(DBG_IKE, "giving up after %d retries", MAX_RETRIES);
                return FAILED;
        }
 
@@ -249,7 +249,7 @@ static status_t build_i(private_ike_init_t *this, message_t *message)
                this->dh = lib->crypto->create_dh(lib->crypto, this->dh_group);
                if (this->dh == NULL)
                {
-                       SIG_IKE(UP_FAILED, "configured DH group %N not supported",
+                       DBG1(DBG_IKE, "configured DH group %N not supported",
                                diffie_hellman_group_names, this->dh_group);
                        return FAILED;
                }
@@ -261,7 +261,7 @@ static status_t build_i(private_ike_init_t *this, message_t *message)
                rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK);
                if (!rng)
                {
-                       SIG_IKE(UP_FAILED, "error generating nonce");
+                       DBG1(DBG_IKE, "error generating nonce");
                        return FAILED;
                }
                rng->allocate_bytes(rng, NONCE_SIZE, &this->my_nonce);
@@ -296,8 +296,7 @@ static status_t process_r(private_ike_init_t *this, message_t *message)
        rng_t *rng;
        
        this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
-       SIG_IKE(UP_START, "%H is initiating an IKE_SA",
-               message->get_source(message));
+       DBG1(DBG_IKE, "%H is initiating an IKE_SA", message->get_source(message));
        this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
 
        rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK);
@@ -376,7 +375,7 @@ static status_t build_r(private_ike_init_t *this, message_t *message)
        if (this->proposal == NULL ||
                this->other_nonce.len == 0 || this->my_nonce.len == 0)
        {
-               SIG_IKE(UP_FAILED, "received proposals inacceptable");
+               DBG1(DBG_IKE, "received proposals inacceptable");
                message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
                return FAILED;
        }
@@ -390,9 +389,9 @@ static status_t build_r(private_ike_init_t *this, message_t *message)
                if (this->proposal->get_algorithm(this->proposal, DIFFIE_HELLMAN_GROUP,
                                                                                  &group, NULL))
                {
-                       SIG_CHD(UP_FAILED, NULL, "DH group %N inacceptable, requesting %N",
-                               diffie_hellman_group_names, this->dh_group,
-                               diffie_hellman_group_names, group);
+                       DBG1(DBG_IKE, "DH group %N inacceptable, requesting %N",
+                                diffie_hellman_group_names, this->dh_group,
+                                diffie_hellman_group_names, group);
                        this->dh_group = group;
                        group = htons(group);
                        message->add_notify(message, FALSE, INVALID_KE_PAYLOAD,
@@ -400,7 +399,7 @@ static status_t build_r(private_ike_init_t *this, message_t *message)
                }
                else
                {
-                       SIG_IKE(UP_FAILED, "no acceptable proposal found");
+                       DBG1(DBG_IKE, "no acceptable proposal found");
                }
                return FAILED;
        }
@@ -430,7 +429,7 @@ static status_t build_r(private_ike_init_t *this, message_t *message)
        }
        if (status != SUCCESS)
        {
-               SIG_IKE(UP_FAILED, "key derivation failed");
+               DBG1(DBG_IKE, "key derivation failed");
                message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
                return FAILED;
        }
@@ -505,7 +504,7 @@ static status_t process_i(private_ike_init_t *this, message_t *message)
                                {
                                        if (type < 16383)
                                        {
-                                               SIG_IKE(UP_FAILED, "received %N notify error",
+                                               DBG1(DBG_IKE, "received %N notify error",
                                                         notify_type_names, type);
                                                iterator->destroy(iterator);
                                                return FAILED;  
@@ -525,7 +524,7 @@ static status_t process_i(private_ike_init_t *this, message_t *message)
        if (this->proposal == NULL ||
                this->other_nonce.len == 0 || this->my_nonce.len == 0)
        {
-               SIG_IKE(UP_FAILED, "peer's proposal selection invalid");
+               DBG1(DBG_IKE, "peers proposal selection invalid");
                return FAILED;
        }
        
@@ -533,7 +532,7 @@ static status_t process_i(private_ike_init_t *this, message_t *message)
                !this->proposal->has_dh_group(this->proposal, this->dh_group) ||
                this->dh->get_shared_secret(this->dh, &secret) != SUCCESS)
        {
-               SIG_IKE(UP_FAILED, "peer's DH group selection invalid");
+               DBG1(DBG_IKE, "peer DH group selection invalid");
                return FAILED;
        }
        
@@ -562,7 +561,7 @@ static status_t process_i(private_ike_init_t *this, message_t *message)
        }
        if (status != SUCCESS)
        {
-               SIG_IKE(UP_FAILED, "key derivation failed");
+               DBG1(DBG_IKE, "key derivation failed");
                return FAILED;
        }
 
index 541b68c..1ffb4c7 100644 (file)
@@ -461,8 +461,7 @@ static status_t process_i(private_ike_me_t *this, message_t *message)
                                this->ike_sa->set_server_reflexive_host(this->ike_sa, endpoint->clone(endpoint));
                        }
                        /* FIXME: what if it failed? e.g. AUTH failure */
-                       SIG_CHD(UP_SUCCESS, NULL, "established mediation connection "
-                                       "without CHILD_SA successfully");
+                       DBG1(DBG_IKE, "established mediation connection successfully");
                        
                        break;
                }
@@ -642,8 +641,7 @@ static status_t build_r_ms(private_ike_me_t *this, message_t *message)
                        /* FIXME: we actually must delete any existing IKE_SAs with the same remote id */
                        this->ike_sa->act_as_mediation_server(this->ike_sa);
                        
-                       SIG_CHD(UP_SUCCESS, NULL, "established mediation connection "
-                                       "without CHILD_SA successfully");
+                       DBG1(DBG_IKE, "established mediation connection successfully");
                        
                        break;
                }
index 30de16c..317a2d9 100644 (file)
@@ -65,7 +65,6 @@ static status_t process_i(private_ike_reauth_t *this, message_t *message)
        
        /* process delete response first */
        this->ike_delete->task.process(&this->ike_delete->task, message);
-       SIG_IKE(DOWN_SUCCESS, "IKE_SA deleted");
 
        peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
        
index 4a13f30..9dff7af 100644 (file)
@@ -152,13 +152,13 @@ static status_t build_r(private_ike_rekey_t *this, message_t *message)
        
        this->ike_sa->set_state(this->ike_sa, IKE_REKEYING);
        this->new_sa->set_state(this->new_sa, IKE_ESTABLISHED);
-       SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
-               this->new_sa->get_name(this->new_sa),
-               this->new_sa->get_unique_id(this->new_sa),
-               this->ike_sa->get_my_host(this->ike_sa),
-               this->ike_sa->get_my_id(this->ike_sa),
-               this->ike_sa->get_other_host(this->ike_sa),
-               this->ike_sa->get_other_id(this->ike_sa));
+       DBG0(DBG_IKE, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
+                this->new_sa->get_name(this->new_sa),
+                this->new_sa->get_unique_id(this->new_sa),
+                this->ike_sa->get_my_host(this->ike_sa),
+                this->ike_sa->get_my_id(this->ike_sa),
+                this->ike_sa->get_other_host(this->ike_sa),
+                this->ike_sa->get_other_id(this->ike_sa));
        
        return SUCCESS;
 }
@@ -198,13 +198,13 @@ static status_t process_i(private_ike_rekey_t *this, message_t *message)
        }
 
        this->new_sa->set_state(this->new_sa, IKE_ESTABLISHED);
-       SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
-               this->new_sa->get_name(this->new_sa),
-               this->new_sa->get_unique_id(this->new_sa),
-               this->ike_sa->get_my_host(this->ike_sa),
-               this->ike_sa->get_my_id(this->ike_sa),
-               this->ike_sa->get_other_host(this->ike_sa),
-               this->ike_sa->get_other_id(this->ike_sa));
+       DBG0(DBG_IKE, "IKE_SA %s[%d] established between %H[%D]...%H[%D]",
+                this->new_sa->get_name(this->new_sa),
+                this->new_sa->get_unique_id(this->new_sa),
+                this->ike_sa->get_my_host(this->ike_sa),
+                this->ike_sa->get_my_id(this->ike_sa),
+                this->ike_sa->get_other_host(this->ike_sa),
+                this->ike_sa->get_other_id(this->ike_sa));
 
        to_delete = this->ike_sa->get_id(this->ike_sa);