reintegrated bus-refactoring branch

This commit is contained in:
Martin Willi
2008-10-14 08:52:13 +00:00
parent 1adaa02bb2
commit a985db3ff3
30 changed files with 967 additions and 939 deletions
+147 -69
View File
@@ -22,10 +22,7 @@
#include <daemon.h> #include <daemon.h>
#include <utils/mutex.h> #include <utils/mutex.h>
ENUM(signal_names, SIG_ANY, SIG_MAX, ENUM(debug_names, DBG_DMN, DBG_LIB,
/** should not get printed */
"SIG_ANY",
/** debugging message types */
"DMN", "DMN",
"MGR", "MGR",
"IKE", "IKE",
@@ -36,19 +33,6 @@ ENUM(signal_names, SIG_ANY, SIG_MAX,
"NET", "NET",
"ENC", "ENC",
"LIB", "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; typedef struct private_bus_t private_bus_t;
@@ -93,7 +77,7 @@ struct entry_t {
/** /**
* registered listener interface * registered listener interface
*/ */
bus_listener_t *listener; listener_t *listener;
/** /**
* is this a active listen() call with a blocking thread * is this a active listen() call with a blocking thread
@@ -114,7 +98,7 @@ struct entry_t {
/** /**
* create a listener entry * 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); 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. * 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->mutex->lock(this->mutex);
this->listeners->insert_last(this->listeners, entry_create(listener, FALSE)); 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. * 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; entry_t *entry;
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
iterator = this->listeners->create_iterator(this->listeners, TRUE); enumerator = this->listeners->create_enumerator(this->listeners);
while (iterator->iterate(iterator, (void**)&entry)) while (enumerator->enumerate(enumerator, &entry))
{ {
if (entry->listener == listener) if (entry->listener == listener)
{ {
iterator->remove(iterator); this->listeners->remove_at(this->listeners, enumerator);
entry_destroy(entry); entry_destroy(entry);
break; break;
} }
} }
iterator->destroy(iterator); enumerator->destroy(enumerator);
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
@@ -207,26 +191,14 @@ struct cleanup_data_t {
*/ */
static void listener_cleanup(cleanup_data_t *data) static void listener_cleanup(cleanup_data_t *data)
{ {
iterator_t *iterator; data->this->listeners->remove(data->this->listeners, data->entry, NULL);
entry_t *entry; entry_destroy(data->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);
} }
/** /**
* Implementation of bus_t.listen. * 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; int old;
cleanup_data_t data; cleanup_data_t data;
@@ -267,33 +239,31 @@ typedef struct {
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
/** invoking thread */ /** invoking thread */
long thread; long thread;
/** signal type */ /** debug group */
signal_t signal; debug_t group;
/** signal level */ /** debug level */
level_t level; level_t level;
/** signal specific user data */
void *user;
/** format string */ /** format string */
char *format; char *format;
/** argument list */ /** argument list */
va_list args; 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; va_list args;
if (entry->calling) if (entry->calling || !entry->listener->log)
{ /* avoid recursive calls */ { /* avoid recursive calls */
return FALSE; return FALSE;
} }
entry->calling = TRUE; entry->calling = TRUE;
va_copy(args, data->args); va_copy(args, data->args);
if (!entry->listener->signal(entry->listener, data->signal, data->level, if (!entry->listener->log(entry->listener, data->group, data->level,
data->thread, data->ike_sa, data->user, data->format, args)) data->thread, data->ike_sa, data->format, args))
{ {
if (entry->blocker) if (entry->blocker)
{ {
@@ -314,42 +284,147 @@ 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, static void vlog(private_bus_t *this, debug_t group, level_t level,
void *user, char* format, va_list args) char* format, va_list args)
{ {
signal_data_t data; log_data_t data;
data.ike_sa = pthread_getspecific(this->thread_sa); data.ike_sa = pthread_getspecific(this->thread_sa);
data.thread = get_thread_number(this); data.thread = get_thread_number(this);
data.signal = signal; data.group = group;
data.level = level; data.level = level;
data.user = user;
data.format = format; data.format = format;
va_copy(data.args, args); va_copy(data.args, args);
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
/* we use the remove() method to invoke all listeners with small overhead */ /* We use the remove() method to invoke all listeners. This is cheap and
this->listeners->remove(this->listeners, &data, (void*)signal_cb); * does not require an allocation for this performance critical function. */
this->listeners->remove(this->listeners, &data, (void*)log_cb);
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
va_end(data.args); 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, static void log_(private_bus_t *this, debug_t group, level_t level,
void* data, char* format, ...) char* format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vsignal(this, signal, level, data, format, args); vlog(this, group, level, format, args);
va_end(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. * Implementation of bus_t.destroy.
*/ */
@@ -367,12 +442,15 @@ bus_t *bus_create()
{ {
private_bus_t *this = malloc_thing(private_bus_t); private_bus_t *this = malloc_thing(private_bus_t);
this->public.add_listener = (void(*)(bus_t*,bus_listener_t*))add_listener; this->public.add_listener = (void(*)(bus_t*,listener_t*))add_listener;
this->public.remove_listener = (void(*)(bus_t*,bus_listener_t*))remove_listener; this->public.remove_listener = (void(*)(bus_t*,listener_t*))remove_listener;
this->public.listen = (void(*)(bus_t*, bus_listener_t *listener, job_t *job))listen_; 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.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.log = (void(*)(bus_t*,debug_t,level_t,char*,...))log_;
this->public.vsignal = (void(*)(bus_t*,signal_t,level_t,void*,char*,va_list))vsignal; 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->public.destroy = (void(*)(bus_t*)) destroy;
this->listeners = linked_list_create(); this->listeners = linked_list_create();
+137 -189
View File
@@ -23,9 +23,9 @@
#ifndef BUS_H_ #ifndef BUS_H_
#define BUS_H_ #define BUS_H_
typedef enum signal_t signal_t; typedef enum debug_t debug_t;
typedef enum level_t level_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; typedef struct bus_t bus_t;
#include <stdarg.h> #include <stdarg.h>
@@ -34,145 +34,82 @@ typedef struct bus_t bus_t;
#include <sa/child_sa.h> #include <sa/child_sa.h>
#include <processing/jobs/job.h> #include <processing/jobs/job.h>
/** /**
* signals emitted by the daemon. * Debug message group.
*
* 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.
*/ */
enum signal_t { enum debug_t {
/** pseudo signal, representing any other signal */ /** daemon main loop */
SIG_ANY,
/** debugging message from daemon main loop */
DBG_DMN, DBG_DMN,
/** debugging message from IKE_SA_MANAGER */ /** IKE_SA_MANAGER */
DBG_MGR, DBG_MGR,
/** debugging message from an IKE_SA */ /** IKE_SA */
DBG_IKE, DBG_IKE,
/** debugging message from a CHILD_SA */ /** CHILD_SA */
DBG_CHD, DBG_CHD,
/** debugging message from job processing */ /** job processing */
DBG_JOB, DBG_JOB,
/** debugging message from configuration backends */ /** configuration backends */
DBG_CFG, DBG_CFG,
/** debugging message from kernel interface */ /** kernel interface */
DBG_KNL, DBG_KNL,
/** debugging message from networking */ /** networking/sockets */
DBG_NET, DBG_NET,
/** debugging message from message encoding/decoding */ /** message encoding/decoding */
DBG_ENC, DBG_ENC,
/** debugging message from libstrongswan via logging hook */ /** libstrongswan via logging hook */
DBG_LIB, DBG_LIB,
/** number of groups */
/** number of debug signals */
DBG_MAX, DBG_MAX,
/** pseudo group with all groups */
/** signals for IKE_SA establishment */ DBG_ANY = DBG_MAX,
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
}; };
/** /**
* 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 { enum level_t {
/** numerical levels from 0 to 4 */ /** absolutely silent */
LEVEL_0 = 0, LEVEL_SILENT = -1,
LEVEL_1 = 1, /** most important auditing logs */
LEVEL_2 = 2, LEVEL_AUDIT = 0,
LEVEL_3 = 3, /** control flow */
LEVEL_4 = 4, LEVEL_CTRL = 1,
/** absolutely silent, no signal is emitted with this level */ /** diagnose problems */
LEVEL_SILENT = -1, LEVEL_DIAG = 2,
/** alias for numberical levels */ /** raw binary blobs */
LEVEL_AUDIT = LEVEL_0, LEVEL_RAW = 3,
LEVEL_CTRL = LEVEL_1, /** including sensitive data (private keys) */
LEVEL_CTRLMORE = LEVEL_2, LEVEL_PRIVATE = 4,
LEVEL_RAW = LEVEL_3,
LEVEL_PRIVATE = LEVEL_4,
}; };
#ifndef DEBUG_LEVEL #ifndef DEBUG_LEVEL
# define DEBUG_LEVEL 4 # define DEBUG_LEVEL 4
#endif /* DEBUG_LEVEL */ #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 #if DEBUG_LEVEL >= 1
/** #define DBG1(group, format, ...) charon->bus->log(charon->bus, group, 1, format, ##__VA_ARGS__)
* Log a debug message via the signal bus. #endif /* DEBUG_LEVEL >= 1 */
*
* @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 */
#if DEBUG_LEVEL >= 2 #if DEBUG_LEVEL >= 2
#define DBG2(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_2, NULL, format, ##__VA_ARGS__) #define DBG2(group, format, ...) charon->bus->log(charon->bus, group, 2, format, ##__VA_ARGS__)
#endif /* DEBUG_LEVEL */ #endif /* DEBUG_LEVEL >= 2 */
#if DEBUG_LEVEL >= 3 #if DEBUG_LEVEL >= 3
#define DBG3(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_3, NULL, format, ##__VA_ARGS__) #define DBG3(group, format, ...) charon->bus->log(charon->bus, group, 3, format, ##__VA_ARGS__)
#endif /* DEBUG_LEVEL */ #endif /* DEBUG_LEVEL >= 3 */
#if DEBUG_LEVEL >= 4 #if DEBUG_LEVEL >= 4
#define DBG4(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_4, NULL, format, ##__VA_ARGS__) #define DBG4(group, format, ...) charon->bus->log(charon->bus, group, 4, format, ##__VA_ARGS__)
#endif /* DEBUG_LEVEL */ #endif /* DEBUG_LEVEL >= 4 */
#ifndef DBG0
# define DBG0(...) {}
#endif /* DBG0 */
#ifndef DBG1 #ifndef DBG1
# define DBG1(...) {} # define DBG1(...) {}
#endif /* DBG1 */ #endif /* DBG1 */
@@ -186,101 +123,90 @@ enum level_t {
# define DBG4(...) {} # define DBG4(...) {}
#endif /* 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. * Listener interface, listens to events if registered to the bus.
*
* @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__) struct listener_t {
/**
* 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.
*/
struct bus_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 * The implementing signal function returns TRUE to stay registered
* to the bus, or FALSE to unregister itself. * 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. * but the bus does not invoke listeners recursively.
* *
* @param singal kind of the signal (up, down, rekeyed, ...) * @param singal kind of the signal (up, down, rekeyed, ...)
* @param level verbosity level of the signal * @param level verbosity level of the signal
* @param thread ID of the thread raised this signal * @param thread ID of the thread raised this signal
* @param ike_sa IKE_SA associated to the event * @param ike_sa IKE_SA associated to the event
* @param data additional signal specific user data
* @param format printf() style format string * @param format printf() style format string
* @param args vprintf() style va_list argument list * @param args vprintf() style va_list argument list
" @return TRUE to stay registered, FALSE to unregister " @return TRUE to stay registered, FALSE to unregister
*/ */
bool (*signal) (bus_listener_t *this, signal_t signal, level_t level, bool (*log) (listener_t *this, debug_t group, level_t level, int thread,
int thread, ike_sa_t *ike_sa, void *data, ike_sa_t *ike_sa, char* format, va_list args);
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 * Any events sent to are delivered to all registered listeners. Threads
* in receiving event signals registers at the bus. Any signals sent to * may wait actively to events using the blocking listen() call.
* are delivered to all registered listeners.
* To deliver signals to threads, the blocking listen() call may be used
* to wait for a signal.
*/ */
struct bus_t { struct bus_t {
/** /**
* Register a listener to the bus. * Register a listener to the bus.
* *
* A registered listener receives all signals which are sent to the bus. * A registered listener receives all events which are sent to the bus.
* The listener is passive; the thread which emitted the signal * The listener is passive; the thread which emitted the event
* processes the listener routine. * processes the listener routine.
* *
* @param listener listener to register. * @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. * Unregister a listener from the bus.
* *
* @param listener listener to unregister. * @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. * 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 * This call registers a listener and blocks the calling thread until
* its listeners function returns FALSE. This allows to wait for certain * its listeners function returns FALSE. This allows to wait for certain
* events. The associated job is executed after the listener has been * events. The associated job is executed after the listener has been
* registered, this allows to listen on events we initiate with the job * registered: This allows to listen on events we initiate with the job,
* without missing any signals. * without missing any events to job may fire.
* *
* @param listener listener to register * @param listener listener to register
* @param job job to execute asynchronously when registered, or NULL * @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. * Set the IKE_SA the calling thread is using.
* *
* To associate an received signal to an IKE_SA without passing it as * To associate an received log message to an IKE_SA without passing it as
* parameter each time, the thread registers it's used IKE_SA each * parameter each time, the thread registers the currenlty used IKE_SA
* time it checked it out. Before checking it in, the thread unregisters * during check-out. Before check-in, the thread unregisters the IKE_SA.
* the IKE_SA (by passing NULL). This IKE_SA is stored per-thread, so each * This IKE_SA is stored per-thread, so each thread has its own IKE_SA
* thread has one IKE_SA registered (or not). * registered.
* *
* @param ike_sa ike_sa to register, or NULL to unregister * @param ike_sa ike_sa to register, or NULL to unregister
*/ */
void (*set_sa) (bus_t *this, ike_sa_t *ike_sa); 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 * The signal specifies the type of the event occured. The format string
* specifies an additional informational or error message with a * specifies an additional informational or error message with a
* printf() like variable argument list. * printf() like variable argument list.
* Some useful macros are available to shorten this call. * Use the DBG() macros.
* @see SIG(), DBG1()
* *
* @param singal kind of the signal (up, down, rekeyed, ...) * @param group debugging group
* @param level verbosity level of the signal * @param level verbosity level of the signal
* @param data additional signal specific user data
* @param format printf() style format string * @param format printf() style format string
* @param ... printf() style argument list * @param ... printf() style argument list
*/ */
void (*signal) (bus_t *this, signal_t signal, level_t level, void (*log)(bus_t *this, debug_t group, level_t level, char* format, ...);
void *data, 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. * 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 level verbosity level of the signal
* @param data additional signal specific user data
* @param format printf() style format string * @param format printf() style format string
* @param args va_list arguments * @param args va_list arguments
*/ */
void (*vsignal) (bus_t *this, signal_t signal, level_t level, void (*vlog)(bus_t *this, debug_t group, level_t level,
void *data, char* format, va_list args); char* format, va_list args);
/** /**
* Destroy the signal bus. * 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 event bus.
*/ */
void (*destroy) (bus_t *this); 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(); bus_t *bus_create();
+20 -20
View File
@@ -39,20 +39,18 @@ struct private_file_logger_t {
FILE *out; FILE *out;
/** /**
* Maximum level to log * Maximum level to log, for each group
*/ */
level_t levels[DBG_MAX]; 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, static bool log_(private_file_logger_t *this, debug_t group, level_t level,
int thread, ike_sa_t* ike_sa, void *data, int thread, ike_sa_t* ike_sa, char *format, va_list args)
char *format, va_list args)
{ {
if (level <= this->levels[SIG_TYPE(signal)]) if (level <= this->levels[group])
{ {
char buffer[8192]; char buffer[8192];
char *current = buffer, *next; char *current = buffer, *next;
@@ -68,7 +66,8 @@ static bool signal_(private_file_logger_t *this, signal_t signal, level_t level,
{ {
*(next++) = '\0'; *(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; 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. * 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; this->levels[group] = level;
for (i = 0; i < DBG_MAX; i++)
{
this->levels[i] = level;
}
} }
else else
{ {
for (group = 0; group < DBG_MAX; group++)
this->levels[SIG_TYPE(signal)] = level; {
this->levels[group] = level;
}
} }
} }
@@ -109,16 +106,19 @@ static void destroy(private_file_logger_t *this)
*/ */
file_logger_t *file_logger_create(FILE *out) file_logger_t *file_logger_create(FILE *out)
{ {
debug_t group;
private_file_logger_t *this = malloc_thing(private_file_logger_t); private_file_logger_t *this = malloc_thing(private_file_logger_t);
/* public functions */ /* public functions */
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.set_level = (void(*)(file_logger_t*,signal_t,level_t))set_level; 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; this->public.destroy = (void(*)(file_logger_t*))destroy;
/* private variables */ /* private variables */
this->out = out; this->out = out;
set_level(this, SIG_ANY, LEVEL_SILENT); set_level(this, DBG_ANY, LEVEL_SILENT);
return &this->public; return &this->public;
} }
+6 -6
View File
@@ -28,22 +28,22 @@ typedef struct file_logger_t file_logger_t;
#include <bus/bus.h> #include <bus/bus.h>
/** /**
* Logger to files which implements bus_listener_t. * Logger to files which implements listener_t.
*/ */
struct file_logger_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) * @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. * Destroys a file_logger_t object.
+17 -20
View File
@@ -40,20 +40,18 @@ struct private_sys_logger_t {
int facility; int facility;
/** /**
* Maximum level to log * Maximum level to log, for each group
*/ */
level_t levels[DBG_MAX]; 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, static bool log_(private_sys_logger_t *this, debug_t group, level_t level,
int thread, ike_sa_t* ike_sa, void *data, int thread, ike_sa_t* ike_sa, char *format, va_list args)
char *format, va_list args)
{ {
if (level <= this->levels[SIG_TYPE(signal)]) if (level <= this->levels[group])
{ {
char buffer[8192]; char buffer[8192];
char *current = buffer, *next; char *current = buffer, *next;
@@ -70,7 +68,7 @@ static bool signal_(private_sys_logger_t *this, signal_t signal, level_t level,
*(next++) = '\0'; *(next++) = '\0';
} }
syslog(this->facility|LOG_INFO, "%.2d[%N] %s\n", syslog(this->facility|LOG_INFO, "%.2d[%N] %s\n",
thread, signal_names, signal, current); thread, debug_names, group, current);
current = next; 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. * 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; this->levels[group] = level;
for (i = 0; i < DBG_MAX; i++)
{
this->levels[i] = level;
}
} }
else else
{ {
for (group = 0; group < DBG_MAX; group++)
this->levels[SIG_TYPE(signal)] = level; {
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); private_sys_logger_t *this = malloc_thing(private_sys_logger_t);
/* public functions */ /* public functions */
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.set_level = (void(*)(sys_logger_t*,signal_t,level_t))set_level; 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; this->public.destroy = (void(*)(sys_logger_t*))destroy;
/* private variables */ /* private variables */
this->facility = facility; this->facility = facility;
set_level(this, SIG_ANY, LEVEL_SILENT); set_level(this, DBG_ANY, LEVEL_SILENT);
return &this->public; return &this->public;
} }
+7 -7
View File
@@ -30,22 +30,22 @@ typedef struct sys_logger_t sys_logger_t;
#include <bus/bus.h> #include <bus/bus.h>
/** /**
* Logger for syslog which implements bus_listener_t. * Logger for syslog which implements listener_t.
*/ */
struct sys_logger_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 group debug group to set
* @param level max level to log * @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. * Destroys a sys_logger_t object.
+281 -278
View File
@@ -27,7 +27,7 @@
typedef struct private_controller_t private_controller_t; 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. * Private data of an stroke_t object.
@@ -40,27 +40,21 @@ struct private_controller_t {
controller_t public; 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 * public bus listener interface
*/ */
bus_listener_t public; listener_t public;
/** /**
* status of the operation, return to method callers * status of the operation, return to method callers
*/ */
status_t status; status_t status;
/**
* IKE SA to filter log output
*/
ike_sa_t *ike_sa;
/** /**
* interface callback (listener gets redirected to here) * interface callback (listener gets redirected to here)
*/ */
@@ -81,6 +75,16 @@ struct interface_bus_listener_t {
*/ */
peer_cfg_t *peer_cfg; 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 * unique ID, used for various methods
*/ */
@@ -102,9 +106,108 @@ struct interface_job_t {
/** /**
* associated listener * associated listener
*/ */
interface_bus_listener_t listener; interface_listener_t listener;
}; };
/**
* listener log function
*/
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)
{
if (this->ike_sa == ike_sa)
{
if (!this->callback(this->param, group, level, ike_sa, format, args))
{
return FALSE;
}
}
return TRUE;
}
/**
* Implementation of listener_t.ike_state_change
*/
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)
{
switch (state)
{
#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;
}
}
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 CHILD_ROUTED:
case CHILD_INSTALLED:
this->status = SUCCESS;
return FALSE;
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;
}
}
return TRUE;
}
/**
* 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. * Implementation of controller_t.create_ike_sa_iterator.
*/ */
@@ -113,42 +216,13 @@ static enumerator_t* create_ike_sa_enumerator(controller_t *this)
return charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager); return charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager);
} }
/**
* listener function for initiate
*/
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)
{
if (this->ike_sa == ike_sa)
{
if (!this->callback(this->param, signal, level, ike_sa, data,
format, args))
{
return FALSE;
}
switch (signal)
{
case CHD_UP_SUCCESS:
this->status = SUCCESS;
return FALSE;
case IKE_UP_FAILED:
case CHD_UP_FAILED:
return FALSE;
default:
break;
}
}
return TRUE;
}
/** /**
* execute function for initiate * execute function for initiate
*/ */
static status_t initiate_execute(interface_job_t *job) static status_t initiate_execute(interface_job_t *job)
{ {
ike_sa_t *ike_sa; 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; peer_cfg_t *peer_cfg = listener->peer_cfg;
ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager, 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, peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
controller_cb_t callback, void *param) controller_cb_t callback, void *param)
{ {
interface_job_t job; interface_job_t job = {
.listener = {
job.listener.public.signal = (void*)initiate_listener; .public = {
job.listener.ike_sa = NULL; .log = (void*)listener_log,
job.listener.callback = callback; .ike_state_change = (void*)listener_ike_state,
job.listener.param = param; .child_state_change = (void*)listener_child_state,
job.listener.status = FAILED; },
job.listener.child_cfg = child_cfg; .callback = callback,
job.listener.peer_cfg = peer_cfg; .param = param,
job.public.execute = (void*)initiate_execute; .status = FAILED,
job.public.destroy = nop; .child_cfg = child_cfg,
.peer_cfg = peer_cfg,
},
.public = {
.execute = (void*)initiate_execute,
.destroy = (void*)recheckin,
},
};
if (callback == NULL) if (callback == NULL)
{ {
return initiate_execute(&job); 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; 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 * execute function for terminate_ike
*/ */
static status_t terminate_ike_execute(interface_job_t *job) static status_t terminate_ike_execute(interface_job_t *job)
{ {
ike_sa_t *ike_sa; interface_listener_t *listener = &job->listener;
interface_bus_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, 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;
charon->bus->set_sa(charon->bus, ike_sa);
if (ike_sa->delete(ike_sa) == DESTROY_ME) if (ike_sa->delete(ike_sa) == DESTROY_ME)
{ {
return charon->ike_sa_manager->checkin_and_destroy( return charon->ike_sa_manager->checkin_and_destroy(
@@ -256,94 +299,52 @@ static status_t terminate_ike_execute(interface_job_t *job)
static status_t terminate_ike(controller_t *this, u_int32_t unique_id, static status_t terminate_ike(controller_t *this, u_int32_t unique_id,
controller_cb_t callback, void *param) 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) if (callback == NULL)
{ {
return terminate_ike_execute(&job); 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; return job.listener.status;
} }
/**
* listener 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)
{
if (this->ike_sa == ike_sa)
{
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 TRUE;
}
/** /**
* execute function for terminate_child * execute function for terminate_child
*/ */
static status_t terminate_child_execute(interface_job_t *job) static status_t terminate_child_execute(interface_job_t *job)
{ {
ike_sa_t *ike_sa; interface_listener_t *listener = &job->listener;
child_sa_t *child_sa; ike_sa_t *ike_sa = listener->ike_sa;
iterator_t *iterator; child_sa_t *child_sa = listener->child_sa;
interface_bus_listener_t *listener = &job->listener;
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 terminate, CHILD_SA with "
"ID %d not found", listener->id);
return NOT_FOUND;
}
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)
{
break;
}
child_sa = NULL;
}
iterator->destroy(iterator);
if (child_sa == NULL)
{
SIG_CHD(DOWN_FAILED, NULL, "unable to terminate, established "
"CHILD_SA with ID %d not found", listener->id);
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
return NOT_FOUND;
}
charon->bus->set_sa(charon->bus, ike_sa);
if (ike_sa->delete_child_sa(ike_sa, child_sa->get_protocol(child_sa), if (ike_sa->delete_child_sa(ike_sa, child_sa->get_protocol(child_sa),
child_sa->get_spi(child_sa, TRUE)) == DESTROY_ME) child_sa->get_spi(child_sa, TRUE)) == DESTROY_ME)
{ {
@@ -359,69 +360,75 @@ static status_t terminate_child_execute(interface_job_t *job)
static status_t terminate_child(controller_t *this, u_int32_t reqid, static status_t terminate_child(controller_t *this, u_int32_t reqid,
controller_cb_t callback, void *param) controller_cb_t callback, void *param)
{ {
interface_job_t job; ike_sa_t *ike_sa;
child_sa_t *child_sa;
iterator_t *iterator;
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,
},
};
job.listener.public.signal = (void*)terminate_child_listener; ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
job.listener.ike_sa = NULL; reqid, TRUE);
job.listener.callback = callback; if (ike_sa == NULL)
job.listener.param = param; {
job.listener.status = FAILED; DBG1(DBG_IKE, "unable to terminate, CHILD_SA with ID %d not found",
job.listener.id = reqid; reqid);
job.public.execute = (void*)terminate_child_execute; return NOT_FOUND;
job.public.destroy = nop; }
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) == reqid)
{
break;
}
child_sa = NULL;
}
iterator->destroy(iterator);
if (child_sa == NULL)
{
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;
}
job.listener.child_sa = child_sa;
if (callback == NULL) if (callback == NULL)
{ {
return terminate_child_execute(&job); 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; 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 * execute function for route
*/ */
static status_t route_execute(interface_job_t *job) static status_t route_execute(interface_job_t *job)
{ {
ike_sa_t *ike_sa; interface_listener_t *listener = &job->listener;
interface_bus_listener_t *listener = &job->listener; ike_sa_t *ike_sa = listener->ike_sa;
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;
if (ike_sa->get_peer_cfg(ike_sa) == NULL) charon->bus->set_sa(charon->bus, ike_sa);
{
ike_sa->set_peer_cfg(ike_sa, peer_cfg);
}
if (ike_sa->route(ike_sa, listener->child_cfg) == DESTROY_ME) if (ike_sa->route(ike_sa, listener->child_cfg) == DESTROY_ME)
{ {
return charon->ike_sa_manager->checkin_and_destroy( 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, peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
controller_cb_t callback, void *param) 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; ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager,
job.listener.ike_sa = NULL; peer_cfg);
job.listener.callback = callback; if (ike_sa->get_peer_cfg(ike_sa) == NULL)
job.listener.param = param; {
job.listener.status = FAILED; ike_sa->set_peer_cfg(ike_sa, peer_cfg);
job.listener.peer_cfg = peer_cfg; }
job.listener.child_cfg = child_cfg; job.listener.ike_sa = ike_sa;
job.public.execute = (void*)route_execute;
job.public.destroy = nop;
if (callback == NULL) if (callback == NULL)
{ {
return route_execute(&job); 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; 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 * execute function for unroute
*/ */
static status_t unroute_execute(interface_job_t *job) static status_t unroute_execute(interface_job_t *job)
{ {
ike_sa_t *ike_sa; interface_listener_t *listener = &job->listener;
interface_bus_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) if (ike_sa->unroute(ike_sa, listener->id) == DESTROY_ME)
{ {
return charon->ike_sa_manager->checkin_and_destroy( 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, static status_t unroute(controller_t *this, u_int32_t reqid,
controller_cb_t callback, void *param) 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; ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
job.listener.ike_sa = NULL; reqid, TRUE);
job.listener.callback = callback; if (ike_sa == NULL)
job.listener.param = param; {
job.listener.status = FAILED; DBG1(DBG_IKE, "unable to unroute, CHILD_SA with ID %d not found", reqid);
job.listener.id = reqid; return NOT_FOUND;
job.public.execute = (void*)unroute_execute; }
job.public.destroy = nop; job.listener.ike_sa = ike_sa;
if (callback == NULL) if (callback == NULL)
{ {
return unroute_execute(&job); 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; return job.listener.status;
} }
/** /**
* See header * See header
*/ */
bool controller_cb_empty(void *param, signal_t signal, level_t level, bool controller_cb_empty(void *param, debug_t group, level_t level,
ike_sa_t *ike_sa, void *data, char *format, va_list args) ike_sa_t *ike_sa, char *format, va_list args)
{ {
return TRUE; return TRUE;
} }
+6 -8
View File
@@ -29,26 +29,24 @@
* callback to log things triggered by controller. * callback to log things triggered by controller.
* *
* @param param echoed parameter supplied when function invoked * @param param echoed parameter supplied when function invoked
* @param signal type of signal * @param group debugging group
* @param level verbosity level if log * @param level verbosity level if log
* @param ike_sa associated IKE_SA, if any * @param ike_sa associated IKE_SA, if any
* @param format printf like format string * @param format printf like format string
* @param args list of arguments to use for format * @param args list of arguments to use for format
* @return FALSE to return from invoked function * @return FALSE to return from invoked function
*/ */
typedef bool(*controller_cb_t)(void* param, signal_t signal, level_t level, typedef bool(*controller_cb_t)(void* param, debug_t group, level_t level,
ike_sa_t* ike_sa, void *data, ike_sa_t* ike_sa, char* format, va_list args);
char* format, va_list args);
/** /**
* Empty callback function for controller_t functions. * 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. * this function to the controllers methods.
*/ */
bool controller_cb_empty(void *param, signal_t signal, level_t level, bool controller_cb_empty(void *param, debug_t group, level_t level,
ike_sa_t *ike_sa, void *data, ike_sa_t *ike_sa, char *format, va_list args);
char *format, va_list args);
typedef struct controller_t controller_t; typedef struct controller_t controller_t;
+21 -21
View File
@@ -99,7 +99,7 @@ static void dbg_bus(int level, char *fmt, ...)
va_list args; va_list args;
va_start(args, fmt); 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); 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[]) static bool initialize(private_daemon_t *this, bool syslog, level_t levels[])
{ {
signal_t signal; debug_t group;
/* for uncritical pseudo random numbers */ /* for uncritical pseudo random numbers */
srandom(time(NULL) + getpid()); 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.syslog->listener);
this->public.bus->add_listener(this->public.bus, &this->public.outlog->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.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 */ /* set up hook to log dbg message in library via charons message bus */
dbg = dbg_bus; dbg = dbg_bus;
/* apply loglevels */ /* apply loglevels */
for (signal = 0; signal < DBG_MAX; signal++) for (group = 0; group < DBG_MAX; group++)
{ {
this->public.syslog->set_level(this->public.syslog, this->public.syslog->set_level(this->public.syslog,
signal, levels[signal]); group, levels[group]);
if (!syslog) if (!syslog)
{ {
this->public.outlog->set_level(this->public.outlog, 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; FILE *pid_file;
struct stat stb; struct stat stb;
level_t levels[DBG_MAX]; level_t levels[DBG_MAX];
int signal; int group;
/* logging for library during initialization, as we have no bus yet */ /* logging for library during initialization, as we have no bus yet */
dbg = dbg_stderr; dbg = dbg_stderr;
@@ -572,9 +572,9 @@ int main(int argc, char *argv[])
lookup_uid_gid(private_charon); lookup_uid_gid(private_charon);
/* use CTRL loglevel for default */ /* 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 */ /* handle arguments */
@@ -585,16 +585,16 @@ int main(int argc, char *argv[])
{ "version", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'v' },
{ "use-syslog", no_argument, NULL, 'l' }, { "use-syslog", no_argument, NULL, 'l' },
/* TODO: handle "debug-all" */ /* TODO: handle "debug-all" */
{ "debug-dmn", required_argument, &signal, DBG_DMN }, { "debug-dmn", required_argument, &group, DBG_DMN },
{ "debug-mgr", required_argument, &signal, DBG_MGR }, { "debug-mgr", required_argument, &group, DBG_MGR },
{ "debug-ike", required_argument, &signal, DBG_IKE }, { "debug-ike", required_argument, &group, DBG_IKE },
{ "debug-chd", required_argument, &signal, DBG_CHD }, { "debug-chd", required_argument, &group, DBG_CHD },
{ "debug-job", required_argument, &signal, DBG_JOB }, { "debug-job", required_argument, &group, DBG_JOB },
{ "debug-cfg", required_argument, &signal, DBG_CFG }, { "debug-cfg", required_argument, &group, DBG_CFG },
{ "debug-knl", required_argument, &signal, DBG_KNL }, { "debug-knl", required_argument, &group, DBG_KNL },
{ "debug-net", required_argument, &signal, DBG_NET }, { "debug-net", required_argument, &group, DBG_NET },
{ "debug-enc", required_argument, &signal, DBG_ENC }, { "debug-enc", required_argument, &group, DBG_ENC },
{ "debug-lib", required_argument, &signal, DBG_LIB }, { "debug-lib", required_argument, &group, DBG_LIB },
{ 0,0,0,0 } { 0,0,0,0 }
}; };
@@ -613,8 +613,8 @@ int main(int argc, char *argv[])
use_syslog = TRUE; use_syslog = TRUE;
continue; continue;
case 0: case 0:
/* option is in signal */ /* option is in group */
levels[signal] = atoi(optarg); levels[group] = atoi(optarg);
continue; continue;
default: default:
usage(""); usage("");
+49 -22
View File
@@ -34,7 +34,7 @@ G_DEFINE_TYPE(NMStrongswanPlugin, nm_strongswan_plugin, NM_TYPE_VPN_PLUGIN)
* Private data of NMStrongswanPlugin * Private data of NMStrongswanPlugin
*/ */
typedef struct { typedef struct {
bus_listener_t listener; listener_t listener;
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
NMVPNPlugin *plugin; NMVPNPlugin *plugin;
nm_creds_t *creds; 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, static void signal_failure(NMVPNPlugin *plugin)
int thread, ike_sa_t *ike_sa, void *data, {
char* format, va_list args) /* 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; NMStrongswanPluginPrivate *private = (NMStrongswanPluginPrivate*)listener;
if (private->ike_sa == ike_sa) if (private->ike_sa == ike_sa)
{ {
switch (signal) switch (state)
{ {
case CHD_UP_SUCCESS: case IKE_DESTROYING:
if (data) signal_failure(private->plugin);
{ return FALSE;
signal_ipv4_config(private->plugin, (child_sa_t*)data); default:
return FALSE; break;
} }
/* FALL */ }
case IKE_UP_FAILED: return TRUE;
case CHD_UP_FAILED: }
/* TODO: NM does not handle this failure!?
nm_vpn_plugin_failure(private->plugin, /**
NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED); */ * Implementation of listener_t.child_state_change
nm_vpn_plugin_set_state(private->plugin, */
NM_VPN_SERVICE_STATE_STOPPED); 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; return FALSE;
default: default:
break; break;
@@ -435,8 +457,13 @@ static gboolean disconnect(NMVPNPlugin *plugin, GError **err)
*/ */
static void nm_strongswan_plugin_init(NMStrongswanPlugin *plugin) static void nm_strongswan_plugin_init(NMStrongswanPlugin *plugin)
{ {
NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin)->plugin = NM_VPN_PLUGIN(plugin); NMStrongswanPluginPrivate *private;
NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin)->listener.signal = listen_bus;
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;
} }
/** /**
+3 -3
View File
@@ -359,15 +359,15 @@ static void request_query_config(xmlTextReaderPtr reader, xmlTextWriterPtr write
/** /**
* callback which logs to a XML writer * callback which logs to a XML writer
*/ */
static bool xml_callback(xmlTextWriterPtr writer, signal_t signal, level_t level, static bool xml_callback(xmlTextWriterPtr writer, debug_t group, level_t level,
ike_sa_t* ike_sa, void *data, char* format, va_list args) ike_sa_t* ike_sa, char* format, va_list args)
{ {
if (level <= 1) if (level <= 1)
{ {
/* <item> */ /* <item> */
xmlTextWriterStartElement(writer, "item"); xmlTextWriterStartElement(writer, "item");
xmlTextWriterWriteFormatAttribute(writer, "level", "%d", level); 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()); xmlTextWriterWriteFormatAttribute(writer, "thread", "%u", pthread_self());
xmlTextWriterWriteVFormatString(writer, format, args); xmlTextWriterWriteVFormatString(writer, format, args);
xmlTextWriterEndElement(writer); xmlTextWriterEndElement(writer);
+6 -7
View File
@@ -49,13 +49,11 @@ struct private_sql_logger_t {
bool recursive; 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, static bool log_(private_sql_logger_t *this, debug_t group, level_t level,
int thread, ike_sa_t* ike_sa, void *data, int thread, ike_sa_t* ike_sa, char *format, va_list args)
char *format, va_list args)
{ {
if (this->recursive) 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)); DB_BLOB, remote_host->get_address(remote_host));
this->db->execute(this->db, NULL, "INSERT INTO logs (" this->db->execute(this->db, NULL, "INSERT INTO logs ("
"local_spi, signal, level, msg) VALUES (?, ?, ?, ?)", "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); DB_TEXT, buffer);
} }
this->recursive = FALSE; 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); 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->public.destroy = (void(*)(sql_logger_t*))destroy;
this->db = db; this->db = db;
+1 -1
View File
@@ -36,7 +36,7 @@ struct sql_logger_t {
/** /**
* Implements bus_listener_t interface * Implements bus_listener_t interface
*/ */
bus_listener_t listener; listener_t listener;
/** /**
* Destry the backend. * Destry the backend.
+2 -2
View File
@@ -55,8 +55,8 @@ struct stroke_log_info_t {
/** /**
* logging to the stroke interface * logging to the stroke interface
*/ */
static bool stroke_log(stroke_log_info_t *info, signal_t signal, level_t level, static bool stroke_log(stroke_log_info_t *info, debug_t group, level_t level,
ike_sa_t *ike_sa, void *data, char *format, va_list args) ike_sa_t *ike_sa, char *format, va_list args)
{ {
if (level <= info->level) if (level <= info->level)
{ {
+11 -9
View File
@@ -336,9 +336,9 @@ static void stroke_purge(private_stroke_socket_t *this,
CERT_X509_OCSP_RESPONSE); 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, "mgr") == 0) return DBG_MGR;
else if (strcasecmp(type, "ike") == 0) return DBG_IKE; else if (strcasecmp(type, "ike") == 0) return DBG_IKE;
else if (strcasecmp(type, "chd") == 0) return DBG_CHD; 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 * 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)); pop_string(msg, &(msg->loglevel.type));
DBG1(DBG_CFG, "received stroke: loglevel %d for %s", DBG1(DBG_CFG, "received stroke: loglevel %d for %s",
msg->loglevel.level, msg->loglevel.type); msg->loglevel.level, msg->loglevel.type);
signal = get_signal_from_logtype(msg->loglevel.type); group = get_group_from_name(msg->loglevel.type);
if (signal < 0) if (group < 0)
{ {
fprintf(out, "invalid type (%s)!\n", msg->loglevel.type); fprintf(out, "invalid type (%s)!\n", msg->loglevel.type);
return; return;
} }
charon->outlog->set_level(charon->outlog, signal, msg->loglevel.level); charon->outlog->set_level(charon->outlog, group, msg->loglevel.level);
charon->syslog->set_level(charon->syslog, signal, msg->loglevel.level); charon->syslog->set_level(charon->syslog, group, msg->loglevel.level);
} }
/** /**
* set various config options * 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); this->cred->cachecrl(this->cred, msg->config.cachecrl);
} }
@@ -53,37 +53,19 @@ static void destroy(private_initiate_mediation_job_t *this)
free(this); free(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. * Implementation of job_t.execute.
*/ */
static void initiate(private_initiate_mediation_job_t *this) static void initiate(private_initiate_mediation_job_t *this)
{ /* FIXME: check the logging */ {
ike_sa_t *mediated_sa, *mediation_sa; ike_sa_t *mediated_sa, *mediation_sa;
peer_cfg_t *mediated_cfg, *mediation_cfg; peer_cfg_t *mediated_cfg, *mediation_cfg;
mediated_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, mediated_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager,
this->mediated_sa_id); this->mediated_sa_id);
if (mediated_sa) if (mediated_sa)
{ {
mediated_cfg = mediated_sa->get_peer_cfg(mediated_sa); mediated_cfg = mediated_sa->get_peer_cfg(mediated_sa);
/* get_peer_cfg returns an internal object */
mediated_cfg->get_ref(mediated_cfg); mediated_cfg->get_ref(mediated_cfg);
charon->ike_sa_manager->checkin(charon->ike_sa_manager, mediated_sa); 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); mediated_cfg->destroy(mediated_cfg);
mediation_cfg->destroy(mediation_cfg); mediation_cfg->destroy(mediation_cfg);
/* this pointer should still be valid */
charon->bus->set_sa(charon->bus, mediated_sa); mediated_sa = charon->ike_sa_manager->checkout(
DBG1(DBG_IKE, "mediation with the same peer is already in progress, queued"); 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); destroy(this);
return; 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 * we do not check the status, but NEED_MORE would be returned on success
* because the registered callback returns FALSE then * because the registered callback returns FALSE then
* this->mediation_sa_id is set in the callback */ * this->mediation_sa_id is set in the callback */
charon->controller->initiate(charon->controller, charon->controller->initiate(charon->controller, mediation_cfg, NULL,
mediation_cfg, NULL, (controller_cb_t)initiate_callback, this); controller_cb_empty, this);
if (!this->mediation_sa_id) if (!this->mediation_sa_id)
{ {
DBG1(DBG_JOB, "initiating mediation connection '%s' failed",
mediation_cfg->get_name(mediation_cfg));
mediation_cfg->destroy(mediation_cfg); mediation_cfg->destroy(mediation_cfg);
mediated_cfg->destroy(mediated_cfg); mediated_cfg->destroy(mediated_cfg);
charon->bus->set_sa(charon->bus, mediated_sa); mediated_sa = charon->ike_sa_manager->checkout(
SIG_IKE(UP_FAILED, "mediation failed"); 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); destroy(this);
return; return;
} }
@@ -131,15 +124,20 @@ static void initiate(private_initiate_mediation_job_t *this)
if (mediation_sa) 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); mediated_cfg->destroy(mediated_cfg);
charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, mediation_sa); charon->ike_sa_manager->checkin_and_destroy(
charon->ike_sa_manager, mediation_sa);
charon->bus->set_sa(charon->bus, mediated_sa); mediated_sa = charon->ike_sa_manager->checkout(
SIG_IKE(UP_FAILED, "mediation failed"); 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); destroy(this);
return; return;
} }
@@ -156,7 +154,7 @@ static void initiate(private_initiate_mediation_job_t *this)
* Implementation of job_t.execute. * Implementation of job_t.execute.
*/ */
static void reinitiate(private_initiate_mediation_job_t *this) static void reinitiate(private_initiate_mediation_job_t *this)
{ /* FIXME: check the logging */ {
ike_sa_t *mediated_sa, *mediation_sa; ike_sa_t *mediated_sa, *mediation_sa;
peer_cfg_t *mediated_cfg; 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->get_name(mediated_cfg));
mediated_cfg->destroy(mediated_cfg); mediated_cfg->destroy(mediated_cfg);
charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, mediation_sa); charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, mediation_sa);
mediated_sa = charon->ike_sa_manager->checkout(
charon->bus->set_sa(charon->bus, mediated_sa); charon->ike_sa_manager, this->mediated_sa_id);
SIG_IKE(UP_FAILED, "mediation failed"); 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); destroy(this);
return; return;
} }
charon->ike_sa_manager->checkin(charon->ike_sa_manager, mediation_sa); charon->ike_sa_manager->checkin(charon->ike_sa_manager, mediation_sa);
} }
+8 -4
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2006-2008 Tobias Brunner * 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) 2006 Daniel Roethlisberger
* Copyright (C) 2005 Jan Hutter * Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
@@ -26,12 +26,13 @@
#include <daemon.h> #include <daemon.h>
ENUM(child_sa_state_names, CHILD_CREATED, CHILD_DELETING, ENUM(child_sa_state_names, CHILD_CREATED, CHILD_DESTROYING,
"CREATED", "CREATED",
"ROUTED", "ROUTED",
"INSTALLED", "INSTALLED",
"REKEYING", "REKEYING",
"DELETING", "DELETING",
"DESTROYING",
); );
typedef struct sa_policy_t sa_policy_t; 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) static void set_state(private_child_sa_t *this, child_sa_state_t state)
{ {
this->state = state;
if (state == CHILD_INSTALLED) if (state == CHILD_INSTALLED)
{ {
updown(this, TRUE); 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 */ /* switch to routed state if no SAD entry set up */
if (this->state == CHILD_CREATED) if (this->state == CHILD_CREATED)
{ {
this->state = CHILD_ROUTED; set_state(this, CHILD_ROUTED);
} }
/* needed to update hosts */ /* needed to update hosts */
this->mode = mode; this->mode = mode;
@@ -961,6 +963,8 @@ static void destroy(private_child_sa_t *this)
updown(this, FALSE); updown(this, FALSE);
} }
set_state(this, CHILD_DESTROYING);
/* delete SAs in the kernel, if they are set up */ /* delete SAs in the kernel, if they are set up */
if (this->me.spi) if (this->me.spi)
{ {
+5
View File
@@ -63,6 +63,11 @@ enum child_sa_state_t {
* CHILD_SA in progress of delete * CHILD_SA in progress of delete
*/ */
CHILD_DELETING, CHILD_DELETING,
/**
* CHILD_SA object gets destroyed
*/
CHILD_DESTROYING,
}; };
/** /**
+1 -1
View 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); 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) 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_and_destroy(charon->ike_sa_manager, sa);
} }
charon->ike_sa_manager->checkin(charon->ike_sa_manager, sa); charon->ike_sa_manager->checkin(charon->ike_sa_manager, sa);
+28 -34
View File
@@ -72,12 +72,13 @@
#define RESOLV_CONF "/etc/resolv.conf" #define RESOLV_CONF "/etc/resolv.conf"
#endif #endif
ENUM(ike_sa_state_names, IKE_CREATED, IKE_DELETING, ENUM(ike_sa_state_names, IKE_CREATED, IKE_DESTROYING,
"CREATED", "CREATED",
"CONNECTING", "CONNECTING",
"ESTABLISHED", "ESTABLISHED",
"REKEYING", "REKEYING",
"DELETING", "DELETING",
"DESTROYING",
); );
typedef struct private_ike_sa_t private_ike_sa_t; 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: default:
break; break;
} }
charon->bus->ike_state_change(charon->bus, &this->public, state);
this->state = 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); child_cfg->destroy(child_cfg);
SIG_IKE(UP_START, "initiating IKE_SA"); DBG1(DBG_IKE, "unable to initiate to %%any");
SIG_IKE(UP_FAILED, "unable to initiate to %%any");
return DESTROY_ME; 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 #ifdef ME
if (this->peer_cfg->is_mediation(this->peer_cfg)) if (this->peer_cfg->is_mediation(this->peer_cfg))
{ { /* mediation connection is already established, retrigger state change
/* mediation connection */ * to notify bus listeners */
if (this->state == IKE_ESTABLISHED) DBG1(DBG_IKE, "mediation connection is already up");
{ /* FIXME: we should try to find a better solution to this */ set_state(this, IKE_ESTABLISHED);
SIG_CHD(UP_SUCCESS, NULL, "mediation connection is already up and running");
}
DESTROY_IF(child_cfg); DESTROY_IF(child_cfg);
} }
else else
@@ -1216,9 +1214,8 @@ static status_t acquire(private_ike_sa_t *this, u_int32_t reqid)
if (this->state == IKE_DELETING) if (this->state == IKE_DELETING)
{ {
SIG_CHD(UP_START, NULL, "acquiring CHILD_SA on kernel request"); DBG1(DBG_IKE, "acquiring CHILD_SA {reqid %d} failed: "
SIG_CHD(UP_FAILED, NULL, "acquiring CHILD_SA {reqid %d} failed: " "IKE_SA is deleting", reqid);
"IKE_SA is deleting", reqid);
return FAILED; return FAILED;
} }
@@ -1235,9 +1232,8 @@ static status_t acquire(private_ike_sa_t *this, u_int32_t reqid)
iterator->destroy(iterator); iterator->destroy(iterator);
if (!child_sa) if (!child_sa)
{ {
SIG_CHD(UP_START, NULL, "acquiring CHILD_SA on kernel request"); DBG1(DBG_IKE, "acquiring CHILD_SA {reqid %d} failed: "
SIG_CHD(UP_FAILED, NULL, "acquiring CHILD_SA {reqid %d} failed: " "CHILD_SA not found", reqid);
"CHILD_SA not found", reqid);
return FAILED; return FAILED;
} }
@@ -1258,8 +1254,6 @@ static status_t route(private_ike_sa_t *this, child_cfg_t *child_cfg)
host_t *me, *other; host_t *me, *other;
status_t status; status_t status;
SIG_CHD(ROUTE_START, NULL, "routing CHILD_SA");
/* check if not already routed*/ /* check if not already routed*/
iterator = this->child_sas->create_iterator(this->child_sas, TRUE); iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
while (iterator->iterate(iterator, (void**)&child_sa)) 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))) streq(child_sa->get_name(child_sa), child_cfg->get_name(child_cfg)))
{ {
iterator->destroy(iterator); 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; 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_DELETING:
case IKE_REKEYING: case IKE_REKEYING:
SIG_CHD(ROUTE_FAILED, NULL, DBG1(DBG_IKE, "routing CHILD_SA failed: IKE_SA is %N",
"unable to route CHILD_SA, as its IKE_SA gets deleted"); ike_sa_state_names, this->state);
return FAILED; return FAILED;
case IKE_CREATED: case IKE_CREATED:
case IKE_CONNECTING: case IKE_CONNECTING:
@@ -1313,11 +1307,11 @@ static status_t route(private_ike_sa_t *this, child_cfg_t *child_cfg)
if (status == SUCCESS) if (status == SUCCESS)
{ {
this->child_sas->insert_last(this->child_sas, child_sa); 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 else
{ {
SIG_CHD(ROUTE_FAILED, child_sa, "routing CHILD_SA failed"); DBG1(DBG_IKE, "routing CHILD_SA failed");
} }
return status; return status;
} }
@@ -1331,8 +1325,6 @@ static status_t unroute(private_ike_sa_t *this, u_int32_t reqid)
child_sa_t *child_sa; child_sa_t *child_sa;
bool found = FALSE; bool found = FALSE;
SIG_CHD(UNROUTE_START, NULL, "unrouting CHILD_SA");
/* find CHILD_SA in ROUTED state */ /* find CHILD_SA in ROUTED state */
iterator = this->child_sas->create_iterator(this->child_sas, TRUE); iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
while (iterator->iterate(iterator, (void**)&child_sa)) 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) child_sa->get_reqid(child_sa) == reqid)
{ {
iterator->remove(iterator); iterator->remove(iterator);
SIG_CHD(UNROUTE_SUCCESS, child_sa, "CHILD_SA unrouted"); DBG1(DBG_IKE, "CHILD_SA unrouted");
child_sa->destroy(child_sa); child_sa->destroy(child_sa);
found = TRUE; found = TRUE;
break; break;
@@ -1351,7 +1343,7 @@ static status_t unroute(private_ike_sa_t *this, u_int32_t reqid)
if (!found) 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; return FAILED;
} }
/* if we are not established, and we have no more routed childs, remove whole SA */ /* 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); this->task_manager->queue_task(this->task_manager, &ike_delete->task);
return this->task_manager->initiate(this->task_manager); return this->task_manager->initiate(this->task_manager);
case IKE_CREATED: case IKE_CREATED:
SIG_IKE(DOWN_SUCCESS, "deleting unestablished IKE_SA"); DBG1(DBG_IKE, "deleting unestablished IKE_SA");
break; break;
default: 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); "without notification", ike_sa_state_names, this->state);
break; break;
} }
@@ -2146,19 +2138,19 @@ static status_t retransmit(private_ike_sa_t *this, u_int32_t message_id)
this->keyingtry++; this->keyingtry++;
if (tries == 0 || tries > this->keyingtry) if (tries == 0 || tries > this->keyingtry)
{ {
SIG_IKE(UP_FAILED, "peer not responding, trying again " DBG1(DBG_IKE, "peer not responding, trying again (%d/%d)",
"(%d/%d) in background ", this->keyingtry + 1, tries); this->keyingtry + 1, tries);
reset(this); reset(this);
return this->task_manager->initiate(this->task_manager); 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; break;
} }
case IKE_DELETING: 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; break;
case IKE_REKEYING: 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 */ /* FALL */
default: default:
reestablish(this); 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) 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->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
this->task_manager->destroy(this->task_manager); this->task_manager->destroy(this->task_manager);
+5
View File
@@ -201,6 +201,11 @@ enum ike_sa_state_t {
* IKE_SA is in progress of deletion * IKE_SA is in progress of deletion
*/ */
IKE_DELETING, IKE_DELETING,
/**
* IKE_SA object gets destroyed
*/
IKE_DESTROYING,
}; };
/** /**
+5 -30
View File
@@ -151,38 +151,11 @@ static void flush(private_task_manager_t *this)
offsetof(task_t, destroy)); offsetof(task_t, destroy));
this->passive_tasks->destroy_offset(this->passive_tasks, this->passive_tasks->destroy_offset(this->passive_tasks,
offsetof(task_t, destroy)); offsetof(task_t, destroy));
this->active_tasks->destroy_offset(this->active_tasks,
/* emmit outstanding signals for tasks */ offsetof(task_t, destroy));
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->queued_tasks = linked_list_create(); this->queued_tasks = linked_list_create();
this->passive_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); DESTROY_IF(this->responding.packet);
status = this->ike_sa->generate_message(this->ike_sa, message, status = this->ike_sa->generate_message(this->ike_sa, message,
&this->responding.packet); &this->responding.packet);
charon->bus->message(charon->bus, message, FALSE);
message->destroy(message); message->destroy(message);
if (status != SUCCESS) 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) if (mid == this->responding.mid)
{ {
charon->bus->message(charon->bus, msg, TRUE);
if (process_request(this, msg) != SUCCESS) if (process_request(this, msg) != SUCCESS)
{ {
flush(this); flush(this);
+44 -48
View File
@@ -199,12 +199,12 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
if (this->proposals == NULL) 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; return FAILED;
} }
if (this->tsi == NULL || this->tsr == NULL) 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; return NOT_FOUND;
} }
@@ -232,7 +232,7 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
no_dh); no_dh);
if (this->proposal == NULL) if (this->proposal == NULL)
{ {
SIG_CHD(UP_FAILED, this->child_sa, "no acceptable proposal found"); DBG1(DBG_IKE, "no acceptable proposal found");
return FAILED; 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, if (this->proposal->get_algorithm(this->proposal, DIFFIE_HELLMAN_GROUP,
&group, NULL)) &group, NULL))
{ {
SIG_CHD(UP_FAILED, this->child_sa, "DH group %N inacceptable, " DBG1(DBG_IKE, "DH group %N inacceptable, requesting %N",
"requesting %N", diffie_hellman_group_names, this->dh_group, diffie_hellman_group_names, this->dh_group,
diffie_hellman_group_names, group); diffie_hellman_group_names, group);
this->dh_group = group; this->dh_group = group;
return INVALID_ARG; return INVALID_ARG;
} }
else else
{ {
SIG_CHD(UP_FAILED, this->child_sa, "no acceptable proposal found"); DBG1(DBG_IKE, "no acceptable proposal found");
return FAILED; 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)); my_ts->destroy_offset(my_ts, offsetof(traffic_selector_t, destroy));
other_ts->destroy_offset(other_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; 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) 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; return FAILED;
} }
DBG3(DBG_IKE, "DH secret %B", &secret); 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)); this->mode, this->proposal->get_protocol(this->proposal));
if (status != SUCCESS) if (status != SUCCESS)
{ {
SIG_CHD(UP_FAILED, this->child_sa, DBG1(DBG_IKE, "unable to install IPsec policies (SPD) in kernel");
"unable to install IPsec policies (SPD) in kernel");
return NOT_FOUND; return NOT_FOUND;
} }
@@ -372,8 +371,7 @@ static status_t select_and_install(private_child_create_t *this, bool no_dh)
if (status != SUCCESS) if (status != SUCCESS)
{ {
SIG_CHD(UP_FAILED, this->child_sa, DBG1(DBG_IKE, "unable to install IPsec SA (SAD) in kernel");
"unable to install IPsec SA (SAD) in kernel");
return FAILED; return FAILED;
} }
/* add to IKE_SA, and remove from task */ /* 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) if (this->reqid)
{ {
SIG_CHD(UP_START, NULL, "establishing CHILD_SA %s{%d}", DBG1(DBG_IKE, "establishing CHILD_SA %s{%d}",
this->config->get_name(this->config), this->reqid); this->config->get_name(this->config), this->reqid);
} }
else else
{ {
SIG_CHD(UP_START, NULL, "establishing CHILD_SA %s", DBG1(DBG_IKE, "establishing CHILD_SA %s",
this->config->get_name(this->config)); this->config->get_name(this->config));
} }
/* reuse virtual IP if we already have one */ /* 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) if (this->child_sa->alloc(this->child_sa, this->proposals) != SUCCESS)
{ {
SIG_CHD(UP_FAILED, this->child_sa, DBG1(DBG_IKE, "unable to allocate SPIs from kernel");
"unable to allocate SPIs from kernel");
return FAILED; 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) if (this->ike_sa->get_state(this->ike_sa) == IKE_REKEYING)
{ {
SIG_CHD(UP_FAILED, NULL, DBG1(DBG_IKE, "unable to create CHILD_SA while rekeying IKE_SA");
"unable to create CHILD_SA while rekeying IKE_SA");
message->add_notify(message, TRUE, NO_ADDITIONAL_SAS, chunk_empty); message->add_notify(message, TRUE, NO_ADDITIONAL_SAS, chunk_empty);
return SUCCESS; return SUCCESS;
} }
if (this->config == NULL) if (this->config == NULL)
{ {
SIG_CHD(UP_FAILED, NULL, "traffic selectors %#R=== %#R inacceptable", DBG1(DBG_IKE, "traffic selectors %#R=== %#R inacceptable",
this->tsr, this->tsi); this->tsr, this->tsi);
message->add_notify(message, FALSE, TS_UNACCEPTABLE, chunk_empty); message->add_notify(message, FALSE, TS_UNACCEPTABLE, chunk_empty);
handle_child_sa_failure(this, message); handle_child_sa_failure(this, message);
return SUCCESS; return SUCCESS;
@@ -813,8 +809,8 @@ static status_t build_r(private_child_create_t *this, message_t *message)
case INTERNAL_ADDRESS_FAILURE: case INTERNAL_ADDRESS_FAILURE:
case FAILED_CP_REQUIRED: case FAILED_CP_REQUIRED:
{ {
SIG_CHD(UP_FAILED, NULL, "configuration payload negotation " DBG1(DBG_IKE,"configuration payload negotation "
"failed, no CHILD_SA built"); "failed, no CHILD_SA built");
iterator->destroy(iterator); iterator->destroy(iterator);
handle_child_sa_failure(this, message); handle_child_sa_failure(this, message);
return SUCCESS; return SUCCESS;
@@ -870,14 +866,14 @@ static status_t build_r(private_child_create_t *this, message_t *message)
build_payloads(this, message); build_payloads(this, message);
SIG_CHD(UP_SUCCESS, this->child_sa, "CHILD_SA %s{%d} established " DBG0(DBG_IKE, "CHILD_SA %s{%d} established "
"with SPIs %.8x_i %.8x_o and TS %#R=== %#R", "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
this->child_sa->get_name(this->child_sa), this->child_sa->get_name(this->child_sa),
this->child_sa->get_reqid(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, TRUE)),
ntohl(this->child_sa->get_spi(this->child_sa, FALSE)), 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, TRUE),
this->child_sa->get_traffic_selectors(this->child_sa, FALSE)); this->child_sa->get_traffic_selectors(this->child_sa, FALSE));
return SUCCESS; return SUCCESS;
} }
@@ -929,8 +925,8 @@ static status_t process_i(private_child_create_t *this, message_t *message)
case TS_UNACCEPTABLE: case TS_UNACCEPTABLE:
case INVALID_SELECTORS: case INVALID_SELECTORS:
{ {
SIG_CHD(UP_FAILED, this->child_sa, "received %N notify, " DBG1(DBG_IKE, "received %N notify, no CHILD_SA built",
"no CHILD_SA built", notify_type_names, type); notify_type_names, type);
iterator->destroy(iterator); iterator->destroy(iterator);
handle_child_sa_failure(this, message); handle_child_sa_failure(this, message);
/* an error in CHILD_SA creation is not critical */ /* 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) if (this->ipcomp == IPCOMP_NONE && this->ipcomp_received != IPCOMP_NONE)
{ {
SIG_CHD(UP_FAILED, this->child_sa, "received an IPCOMP_SUPPORTED notify" DBG1(DBG_IKE, "received an IPCOMP_SUPPORTED notify without requesting"
" but we did not send one previously, no CHILD_SA built"); " one, no CHILD_SA built");
handle_child_sa_failure(this, message); handle_child_sa_failure(this, message);
return SUCCESS; return SUCCESS;
} }
else if (this->ipcomp != IPCOMP_NONE && this->ipcomp_received == IPCOMP_NONE) else if (this->ipcomp != IPCOMP_NONE && this->ipcomp_received == IPCOMP_NONE)
{ {
DBG1(DBG_IKE, "peer didn't accept our proposed IPComp transforms, " DBG1(DBG_IKE, "peer didn't accept our proposed IPComp transforms, "
"IPComp is disabled"); "IPComp is disabled");
this->ipcomp = IPCOMP_NONE; this->ipcomp = IPCOMP_NONE;
} }
else if (this->ipcomp != IPCOMP_NONE && this->ipcomp != this->ipcomp_received) else if (this->ipcomp != IPCOMP_NONE && this->ipcomp != this->ipcomp_received)
{ {
SIG_CHD(UP_FAILED, this->child_sa, "received an IPCOMP_SUPPORTED notify" DBG1(DBG_IKE, "received an IPCOMP_SUPPORTED notify we didn't propose, "
" for a transform we did not propose, no CHILD_SA built"); "no CHILD_SA built");
handle_child_sa_failure(this, message); handle_child_sa_failure(this, message);
return SUCCESS; return SUCCESS;
} }
if (select_and_install(this, no_dh) == SUCCESS) if (select_and_install(this, no_dh) == SUCCESS)
{ {
SIG_CHD(UP_SUCCESS, this->child_sa, "CHILD_SA %s{%d} established " DBG0(DBG_IKE, "CHILD_SA %s{%d} established "
"with SPIs %.8x_i %.8x_o and TS %#R=== %#R", "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
this->child_sa->get_name(this->child_sa), this->child_sa->get_name(this->child_sa),
this->child_sa->get_reqid(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, TRUE)),
ntohl(this->child_sa->get_spi(this->child_sa, FALSE)), 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, TRUE),
this->child_sa->get_traffic_selectors(this->child_sa, FALSE)); this->child_sa->get_traffic_selectors(this->child_sa, FALSE));
} }
else else
{ {
+9 -10
View File
@@ -222,14 +222,13 @@ static void log_children(private_child_delete_t *this)
iterator = this->child_sas->create_iterator(this->child_sas, TRUE); iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
while (iterator->iterate(iterator, (void**)&child_sa)) while (iterator->iterate(iterator, (void**)&child_sa))
{ {
SIG_CHD(DOWN_START, child_sa, "closing CHILD_SA %s{%d} " DBG0(DBG_IKE, "closing CHILD_SA %s{%d} "
"with SPIs %.8x_i %.8x_o and TS %#R=== %#R", "with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
child_sa->get_name(child_sa), child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
child_sa->get_reqid(child_sa), ntohl(child_sa->get_spi(child_sa, TRUE)),
ntohl(child_sa->get_spi(child_sa, TRUE)), ntohl(child_sa->get_spi(child_sa, FALSE)),
ntohl(child_sa->get_spi(child_sa, FALSE)), child_sa->get_traffic_selectors(child_sa, TRUE),
child_sa->get_traffic_selectors(child_sa, TRUE), child_sa->get_traffic_selectors(child_sa, FALSE));
child_sa->get_traffic_selectors(child_sa, FALSE));
} }
iterator->destroy(iterator); 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(); this->child_sas = linked_list_create();
process_payloads(this, message); process_payloads(this, message);
SIG_CHD(DOWN_SUCCESS, NULL, "CHILD_SA closed"); DBG1(DBG_IKE, "CHILD_SA closed");
return destroy_and_reestablish(this); 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); build_payloads(this, message);
} }
SIG_CHD(DOWN_SUCCESS, NULL, "CHILD_SA closed"); DBG1(DBG_IKE, "CHILD_SA closed");
return destroy_and_reestablish(this); return destroy_and_reestablish(this);
} }
+52 -52
View 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); config = this->ike_sa->get_peer_cfg(this->ike_sa);
if (!config) 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; return FAILED;
} }
auth = authenticator_create_from_class(this->ike_sa, get_auth_class(config)); auth = authenticator_create_from_class(this->ike_sa, get_auth_class(config));
if (auth == NULL) if (auth == NULL)
{ {
SIG_IKE(UP_FAILED, "configured authentication class %N not supported", DBG1(DBG_IKE, "configured authentication class %N not supported",
auth_class_names, get_auth_class(config)); auth_class_names, get_auth_class(config));
return FAILED; return FAILED;
} }
@@ -218,7 +218,7 @@ static status_t build_auth(private_ike_auth_t *this, message_t *message)
auth->destroy(auth); auth->destroy(auth);
if (status != SUCCESS) if (status != SUCCESS)
{ {
SIG_IKE(UP_FAILED, "generating authentication data failed"); DBG1(DBG_IKE, "generating authentication data failed");
return FAILED; return FAILED;
} }
message->add_payload(message, (payload_t*)auth_payload); 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); me = config->get_my_id(config);
if (me->contains_wildcards(me)) if (me->contains_wildcards(me))
{ {
SIG_IKE(UP_FAILED, "negotiation of own ID failed"); DBG1(DBG_IKE, "negotiation of own ID failed");
return FAILED; return FAILED;
} }
this->ike_sa->set_my_id(this->ike_sa, me->clone(me)); 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)); auth_payload->get_auth_method(auth_payload));
if (auth == NULL) if (auth == NULL)
{ {
SIG_IKE(UP_FAILED, "authentication method %N used by '%D' not " DBG1(DBG_IKE, "authentication method %N used by '%D' not supported",
"supported", auth_method_names, auth_method, auth_method_names, auth_method,
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
return NOT_SUPPORTED; return NOT_SUPPORTED;
} }
@@ -294,7 +294,7 @@ static status_t process_auth(private_ike_auth_t *this, message_t *message)
auth->destroy(auth); auth->destroy(auth);
if (status != SUCCESS) 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), this->ike_sa->get_other_id(this->ike_sa),
auth_method_names, auth_method); auth_method_names, auth_method);
return FAILED; 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)) 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; 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); req = this->ike_sa->get_other_id(this->ike_sa);
if (!id->matches(id, req)) 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); id->destroy(id);
return FAILED; 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), if (auth->build(auth, this->my_packet->get_data(this->my_packet),
this->other_nonce, &auth_payload) != SUCCESS) this->other_nonce, &auth_payload) != SUCCESS)
{ {
SIG_IKE(UP_FAILED, "generating authentication data failed"); DBG1(DBG_IKE, "generating authentication data failed");
if (!this->initiator) if (!this->initiator)
{ {
message->add_notify(message, TRUE, AUTHENTICATION_FAILED, chunk_empty); 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) if (!this->initiator)
{ {
this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED); this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED);
SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]", 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_name(this->ike_sa),
this->ike_sa->get_unique_id(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_host(this->ike_sa),
this->ike_sa->get_my_id(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_host(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
return SUCCESS; return SUCCESS;
} }
return NEED_MORE; 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) 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), this->ike_sa->get_other_id(this->ike_sa),
auth_class_names, AUTH_CLASS_EAP); auth_class_names, AUTH_CLASS_EAP);
if (this->initiator) if (this->initiator)
@@ -460,13 +460,13 @@ static status_t process_auth_eap(private_ike_auth_t *this, message_t *message)
if (this->initiator) if (this->initiator)
{ {
this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED); this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED);
SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]", 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_name(this->ike_sa),
this->ike_sa->get_unique_id(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_host(this->ike_sa),
this->ike_sa->get_my_id(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_host(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
return SUCCESS; return SUCCESS;
} }
return NEED_MORE; 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); eap = (eap_payload_t*)message->get_payload(message, EXTENSIBLE_AUTHENTICATION);
if (eap == NULL) if (eap == NULL)
{ {
SIG_IKE(UP_FAILED, "EAP payload missing"); DBG1(DBG_IKE, "EAP payload missing");
return FAILED; return FAILED;
} }
switch (this->eap_auth->process(this->eap_auth, eap, &eap)) 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; return NEED_MORE;
default: default:
this->eap_payload = NULL; 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)); this->ike_sa->get_other_id(this->ike_sa));
return FAILED; 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) if (this->eap_payload == NULL)
{ {
SIG_IKE(UP_FAILED, "EAP payload missing"); DBG1(DBG_IKE, "EAP payload missing");
return FAILED; 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; this->public.task.process = (status_t(*)(task_t*,message_t*))process_auth_eap;
break; break;
default: default:
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), this->ike_sa->get_other_id(this->ike_sa),
auth_class_names, AUTH_CLASS_EAP); auth_class_names, AUTH_CLASS_EAP);
status = FAILED; status = FAILED;
break; 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); config = this->ike_sa->get_peer_cfg(this->ike_sa);
if (config == NULL) if (config == NULL)
{ {
SIG_IKE(UP_FAILED, "no matching config found for '%D'...'%D'", DBG1(DBG_IKE, "no matching config found for '%D'...'%D'",
this->ike_sa->get_my_id(this->ike_sa), this->ike_sa->get_my_id(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
message->add_notify(message, TRUE, AUTHENTICATION_FAILED, chunk_empty); message->add_notify(message, TRUE, AUTHENTICATION_FAILED, chunk_empty);
return FAILED; return FAILED;
} }
@@ -689,13 +689,13 @@ static status_t build_r(private_ike_auth_t *this, message_t *message)
if (this->peer_authenticated) if (this->peer_authenticated)
{ {
this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED); this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED);
SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]", 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_name(this->ike_sa),
this->ike_sa->get_unique_id(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_host(this->ike_sa),
this->ike_sa->get_my_id(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_host(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
return SUCCESS; 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); message->add_payload(message, (payload_t*)eap_payload);
if (status != NEED_MORE) if (status != NEED_MORE)
{ {
SIG_IKE(UP_FAILED, "unable to initiate EAP authentication"); DBG1(DBG_IKE, "unable to initiate EAP authentication");
return FAILED; return FAILED;
} }
@@ -766,7 +766,7 @@ static status_t process_i(private_ike_auth_t *this, message_t *message)
{ {
if (type < 16383) if (type < 16383)
{ {
SIG_IKE(UP_FAILED, "received %N notify error", DBG1(DBG_IKE, "received %N notify error",
notify_type_names, type); notify_type_names, type);
iterator->destroy(iterator); iterator->destroy(iterator);
return FAILED; 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); auth = this->ike_sa->get_other_auth(this->ike_sa);
if (!auth->complies(auth, config->get_auth(config))) 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)); this->ike_sa->get_other_id(this->ike_sa), config->get_name(config));
return FAILED; return FAILED;
} }
this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED); this->ike_sa->set_state(this->ike_sa, IKE_ESTABLISHED);
SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]", 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_name(this->ike_sa),
this->ike_sa->get_unique_id(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_host(this->ike_sa),
this->ike_sa->get_my_id(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_host(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
return SUCCESS; return SUCCESS;
} }
+19 -19
View File
@@ -56,21 +56,21 @@ static status_t build_i(private_ike_delete_t *this, message_t *message)
{ {
delete_payload_t *delete_payload; delete_payload_t *delete_payload;
SIG_IKE(DOWN_START, "deleting IKE_SA %s[%d] between %H[%D]...%H[%D]", 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_name(this->ike_sa),
this->ike_sa->get_unique_id(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_host(this->ike_sa),
this->ike_sa->get_my_id(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_host(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
delete_payload = delete_payload_create(PROTO_IKE); delete_payload = delete_payload_create(PROTO_IKE);
message->add_payload(message, (payload_t*)delete_payload); message->add_payload(message, (payload_t*)delete_payload);
this->ike_sa->set_state(this->ike_sa, IKE_DELETING); this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
DBG1(DBG_IKE, "sending DELETE for IKE_SA %s[%d]", DBG1(DBG_IKE, "sending DELETE for IKE_SA %s[%d]",
this->ike_sa->get_name(this->ike_sa), this->ike_sa->get_name(this->ike_sa),
this->ike_sa->get_unique_id(this->ike_sa)); this->ike_sa->get_unique_id(this->ike_sa));
return NEED_MORE; 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 /* we don't even scan the payloads, as the message wouldn't have
* come so far without being correct */ * come so far without being correct */
DBG1(DBG_IKE, "received DELETE for IKE_SA %s[%d]", DBG1(DBG_IKE, "received DELETE for IKE_SA %s[%d]",
this->ike_sa->get_name(this->ike_sa), this->ike_sa->get_name(this->ike_sa),
this->ike_sa->get_unique_id(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]", 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_name(this->ike_sa),
this->ike_sa->get_unique_id(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_host(this->ike_sa),
this->ike_sa->get_my_id(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_host(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
switch (this->ike_sa->get_state(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) 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) if (this->simultaneous)
{ {
+18 -19
View File
@@ -230,15 +230,15 @@ static status_t build_i(private_ike_init_t *this, message_t *message)
rng_t *rng; rng_t *rng;
this->config = this->ike_sa->get_ike_cfg(this->ike_sa); this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
SIG_IKE(UP_START, "initiating IKE_SA %s[%d] to %H", DBG1(DBG_IKE, "initiating IKE_SA %s[%d] to %H",
this->ike_sa->get_name(this->ike_sa), this->ike_sa->get_name(this->ike_sa),
this->ike_sa->get_unique_id(this->ike_sa), this->ike_sa->get_unique_id(this->ike_sa),
this->ike_sa->get_other_host(this->ike_sa)); this->ike_sa->get_other_host(this->ike_sa));
this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING); this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
if (this->retry++ >= MAX_RETRIES) 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; 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); this->dh = lib->crypto->create_dh(lib->crypto, this->dh_group);
if (this->dh == NULL) 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); diffie_hellman_group_names, this->dh_group);
return FAILED; 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); rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK);
if (!rng) if (!rng)
{ {
SIG_IKE(UP_FAILED, "error generating nonce"); DBG1(DBG_IKE, "error generating nonce");
return FAILED; return FAILED;
} }
rng->allocate_bytes(rng, NONCE_SIZE, &this->my_nonce); 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; rng_t *rng;
this->config = this->ike_sa->get_ike_cfg(this->ike_sa); this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
SIG_IKE(UP_START, "%H is initiating an IKE_SA", DBG1(DBG_IKE, "%H is initiating an IKE_SA", message->get_source(message));
message->get_source(message));
this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING); this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK); 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 || if (this->proposal == NULL ||
this->other_nonce.len == 0 || this->my_nonce.len == 0) 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); message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
return FAILED; 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, if (this->proposal->get_algorithm(this->proposal, DIFFIE_HELLMAN_GROUP,
&group, NULL)) &group, NULL))
{ {
SIG_CHD(UP_FAILED, NULL, "DH group %N inacceptable, requesting %N", DBG1(DBG_IKE, "DH group %N inacceptable, requesting %N",
diffie_hellman_group_names, this->dh_group, diffie_hellman_group_names, this->dh_group,
diffie_hellman_group_names, group); diffie_hellman_group_names, group);
this->dh_group = group; this->dh_group = group;
group = htons(group); group = htons(group);
message->add_notify(message, FALSE, INVALID_KE_PAYLOAD, 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 else
{ {
SIG_IKE(UP_FAILED, "no acceptable proposal found"); DBG1(DBG_IKE, "no acceptable proposal found");
} }
return FAILED; return FAILED;
} }
@@ -430,7 +429,7 @@ static status_t build_r(private_ike_init_t *this, message_t *message)
} }
if (status != SUCCESS) 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); message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
return FAILED; return FAILED;
} }
@@ -505,7 +504,7 @@ static status_t process_i(private_ike_init_t *this, message_t *message)
{ {
if (type < 16383) if (type < 16383)
{ {
SIG_IKE(UP_FAILED, "received %N notify error", DBG1(DBG_IKE, "received %N notify error",
notify_type_names, type); notify_type_names, type);
iterator->destroy(iterator); iterator->destroy(iterator);
return FAILED; return FAILED;
@@ -525,7 +524,7 @@ static status_t process_i(private_ike_init_t *this, message_t *message)
if (this->proposal == NULL || if (this->proposal == NULL ||
this->other_nonce.len == 0 || this->my_nonce.len == 0) 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; 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->proposal->has_dh_group(this->proposal, this->dh_group) ||
this->dh->get_shared_secret(this->dh, &secret) != SUCCESS) 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; return FAILED;
} }
@@ -562,7 +561,7 @@ static status_t process_i(private_ike_init_t *this, message_t *message)
} }
if (status != SUCCESS) if (status != SUCCESS)
{ {
SIG_IKE(UP_FAILED, "key derivation failed"); DBG1(DBG_IKE, "key derivation failed");
return FAILED; return FAILED;
} }
+2 -4
View 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)); this->ike_sa->set_server_reflexive_host(this->ike_sa, endpoint->clone(endpoint));
} }
/* FIXME: what if it failed? e.g. AUTH failure */ /* FIXME: what if it failed? e.g. AUTH failure */
SIG_CHD(UP_SUCCESS, NULL, "established mediation connection " DBG1(DBG_IKE, "established mediation connection successfully");
"without CHILD_SA successfully");
break; 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 */ /* FIXME: we actually must delete any existing IKE_SAs with the same remote id */
this->ike_sa->act_as_mediation_server(this->ike_sa); this->ike_sa->act_as_mediation_server(this->ike_sa);
SIG_CHD(UP_SUCCESS, NULL, "established mediation connection " DBG1(DBG_IKE, "established mediation connection successfully");
"without CHILD_SA successfully");
break; break;
} }
-1
View File
@@ -65,7 +65,6 @@ static status_t process_i(private_ike_reauth_t *this, message_t *message)
/* process delete response first */ /* process delete response first */
this->ike_delete->task.process(&this->ike_delete->task, message); 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); peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
+14 -14
View 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->ike_sa->set_state(this->ike_sa, IKE_REKEYING);
this->new_sa->set_state(this->new_sa, IKE_ESTABLISHED); this->new_sa->set_state(this->new_sa, IKE_ESTABLISHED);
SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]", 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_name(this->new_sa),
this->new_sa->get_unique_id(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_host(this->ike_sa),
this->ike_sa->get_my_id(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_host(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
return SUCCESS; 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); this->new_sa->set_state(this->new_sa, IKE_ESTABLISHED);
SIG_IKE(UP_SUCCESS, "IKE_SA %s[%d] established between %H[%D]...%H[%D]", 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_name(this->new_sa),
this->new_sa->get_unique_id(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_host(this->ike_sa),
this->ike_sa->get_my_id(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_host(this->ike_sa),
this->ike_sa->get_other_id(this->ike_sa)); this->ike_sa->get_other_id(this->ike_sa));
to_delete = this->ike_sa->get_id(this->ike_sa); to_delete = this->ike_sa->get_id(this->ike_sa);