- fixed bad bugs in kernel interface
[strongswan.git] / Source / charon / threads / kernel_interface.c
index f5273e1..679cf69 100644 (file)
@@ -26,7 +26,6 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <linux/netlink.h>
-#include <linux/xfrm.h>
 #include <pthread.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include "kernel_interface.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
 #define KERNEL_ESP 50
 #define KERNEL_AH 51
 
+#define SPD_PRIORITY 1024
+
+#define XFRM_DATA_LENGTH 512
+
+
+typedef struct xfrm_data_t xfrm_data_t;
+
+/**
+ * Lenght/Type/data struct for userdata in xfrm
+ * We dont use the "I-don't-know-where-they-come-from"-structs
+ * used in the kernel.
+ */
+struct xfrm_data_t {
+       /**
+        * length of the data
+        */
+       u_int16_t length;
+       
+       /**
+        * type of data 
+        */
+       u_int16_t type;
+       
+       /**
+        * and the data itself, for different purposes
+        */
+       union {
+               /** algorithm */
+               struct xfrm_algo algo;
+               /** policy tmpl */
+               struct xfrm_user_tmpl tmpl[2];
+       };
+};
+
 
 typedef struct netlink_message_t netlink_message_t;
 
@@ -57,25 +89,22 @@ struct netlink_message_t {
        struct nlmsghdr hdr;
 
        union {
+               /** error message */
                struct nlmsgerr e;
-               struct xfrm_userspi_info spi;                       
-               struct {
-                       struct xfrm_usersa_info sa;
-                       u_int8_t data[512];
-               };
+               /** message for spi allocation */
+               struct xfrm_userspi_info spi;
+               /** message for SA manipulation */
+               struct xfrm_usersa_id sa_id;
+               /** message for SA installation */
+               struct xfrm_usersa_info sa;
+               /** message for policy manipulation */
+               struct xfrm_userpolicy_id policy_id;
+               /** message for policy installation */
+               struct xfrm_userpolicy_info policy;
        };
+       u_int8_t data[XFRM_DATA_LENGTH];
 };
 
-typedef struct netlink_algo_t netlink_algo_t;
-
-/**
- * Add length and type to xfrm_algo
- */
-struct netlink_algo_t {
-       u_int16_t length;
-       u_int16_t type;
-       struct xfrm_algo algo;
-};
 
 typedef struct private_kernel_interface_t private_kernel_interface_t;
 
@@ -94,7 +123,11 @@ struct private_kernel_interface_t {
         */
        int socket;
        
+       /**
+        * Process id of kernel thread
+        */
        pid_t pid;
+       
        /**
         * Sequence number for messages.
         */
@@ -121,6 +154,11 @@ struct private_kernel_interface_t {
        pthread_cond_t condvar;
        
        /**
+        * Logger for XFRM stuff
+        */
+       logger_t *logger;
+       
+       /**
         * Function for the thread, receives messages.
         */
        void (*receive_messages) (private_kernel_interface_t *this);
@@ -131,6 +169,12 @@ struct private_kernel_interface_t {
        status_t (*send_message) (private_kernel_interface_t *this, netlink_message_t *request, netlink_message_t **response);
 };
 
+/**
+ * In the kernel, algorithms are identified as strings, we use our
+ * mapping functions...
+ * Algorithms for encryption.
+ * TODO: Add missing algorithm strings
+ */
 mapping_t kernel_encryption_algs_m[] = {
        {ENCR_DES_IV64, ""},
        {ENCR_DES, "des"},
@@ -146,7 +190,12 @@ mapping_t kernel_encryption_algs_m[] = {
        {ENCR_AES_CTR, ""},
        {MAPPING_END, NULL}
 };
-
+/**
+ * In the kernel, algorithms are identified as strings, we use our
+ * mapping functions...
+ * Algorithms for integrity protection.
+ * TODO: Add missing algorithm strings
+ */
 mapping_t kernel_integrity_algs_m[] = {
        {AUTH_HMAC_MD5_96, "md5"},
        {AUTH_HMAC_SHA1_96, "sha1"},
@@ -157,9 +206,19 @@ mapping_t kernel_integrity_algs_m[] = {
 };
 
 
-static status_t get_spi(private_kernel_interface_t *this, host_t *src, host_t *dest, protocol_id_t protocol, bool tunnel_mode, u_int32_t *spi)
+/**
+ * Implementation of kernel_interface_t.get_spi.
+ */
+static status_t get_spi(private_kernel_interface_t *this, 
+                                               host_t *src, host_t *dest, 
+                                               protocol_id_t protocol, u_int32_t reqid,
+                                               u_int32_t *spi)
 {
        netlink_message_t request, *response;
+       status_t status = SUCCESS;
+       
+       
+       this->logger->log(this->logger, CONTROL|LEVEL2, "getting spi");
        
        memset(&request, 0, sizeof(request));
        request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.spi)));
@@ -167,44 +226,52 @@ static status_t get_spi(private_kernel_interface_t *this, host_t *src, host_t *d
        request.hdr.nlmsg_type = XFRM_MSG_ALLOCSPI;
        request.spi.info.saddr = src->get_xfrm_addr(src);
        request.spi.info.id.daddr = dest->get_xfrm_addr(dest);
-       request.spi.info.mode = tunnel_mode;
-       /* TODO: this should be done with getprotobyname() */
-       request.spi.info.id.proto = (protocol == ESP) ? KERNEL_ESP : KERNEL_AH;
+       request.spi.info.mode = TRUE; /* tunnel mode */
+       request.spi.info.reqid = reqid;
+       request.spi.info.id.proto = (protocol == PROTO_ESP) ? KERNEL_ESP : KERNEL_AH;
        request.spi.info.family = PF_INET;
-       request.spi.min = 100;
-       request.spi.max = 200;
+       request.spi.min = 0xc0000000;
+       request.spi.max = 0xcFFFFFFF;
        
        if (this->send_message(this, &request, &response) != SUCCESS)
        {
+               this->logger->log(this->logger, ERROR, "netlink communication failed");
                return FAILED;
        }
-       
-       if (response->hdr.nlmsg_type == NLMSG_ERROR)
+       else if (response->hdr.nlmsg_type == NLMSG_ERROR)
        {
-               return FAILED;
+               this->logger->log(this->logger, ERROR, "netlink request XFRM_MSG_ALLOCSPI got an error: %s",
+                                                 strerror(-response->e.error));
+               status = FAILED;
        }
-       
-       if (response->hdr.nlmsg_type != XFRM_MSG_NEWSA)
+       else if (response->hdr.nlmsg_type != XFRM_MSG_NEWSA)
        {
-               return FAILED;
+               this->logger->log(this->logger, ERROR, "netlink request XFRM_MSG_ALLOCSPI got a unknown reply");
+               status = FAILED;
        }
        else if (response->hdr.nlmsg_len < NLMSG_LENGTH(sizeof(response->sa)))
        {
-               return FAILED;
+               this->logger->log(this->logger, ERROR, "netlink request XFRM_MSG_ALLOCSPI got an invalid reply");
+               status = FAILED;
        }
+       else
+       {
+               *spi = response->sa.id.spi;
+       }
+       free(response);
        
-       *spi = response->sa.id.spi;
-       allocator_free(response);
-       
-       return SUCCESS;
+       return status;
 }
 
+/**
+ * Implementation of kernel_interface_t.add_sa.
+ */
 static status_t add_sa(        private_kernel_interface_t *this,
                                                host_t *me,
                                                host_t *other,
                                                u_int32_t spi,
                                                int protocol,
-                                               bool tunnel_mode,
+                                               u_int32_t reqid,
                                                encryption_algorithm_t enc_alg,
                                                chunk_t encryption_key,
                                                integrity_algorithm_t int_alg,
@@ -213,7 +280,9 @@ static status_t add_sa(     private_kernel_interface_t *this,
 {
        netlink_message_t request, *response;
        memset(&request, 0, sizeof(request));
+       status_t status = SUCCESS;
        
+       this->logger->log(this->logger, CONTROL|LEVEL2, "adding SA");
        
        request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
        request.hdr.nlmsg_type = replace ? XFRM_MSG_UPDSA : XFRM_MSG_NEWSA;
@@ -222,12 +291,11 @@ static status_t add_sa(   private_kernel_interface_t *this,
        request.sa.id.daddr = other->get_xfrm_addr(other);
        
        request.sa.id.spi = spi;
-       /* TODO: this should be done with getprotobyname() */
-       request.sa.id.proto = (protocol == ESP) ? KERNEL_ESP : KERNEL_AH;
+       request.sa.id.proto = (protocol == PROTO_ESP) ? KERNEL_ESP : KERNEL_AH;
        request.sa.family = me->get_family(me);
-       request.sa.mode = tunnel_mode;
-       request.sa.replay_window = 0; //sa->replay_window; ???
-       request.sa.reqid = 0; //sa->reqid; ???
+       request.sa.mode = TRUE; /* tunnel mode */
+       request.sa.replay_window = 32;
+       request.sa.reqid = reqid;
        request.sa.lft.soft_byte_limit = XFRM_INF;
        request.sa.lft.soft_packet_limit = XFRM_INF;
        request.sa.lft.hard_byte_limit = XFRM_INF;
@@ -237,44 +305,250 @@ static status_t add_sa(  private_kernel_interface_t *this,
        
        if (enc_alg != ENCR_UNDEFINED)
        {
-               netlink_algo_t *nla = (netlink_algo_t*)(((u_int8_t*)&request) + request.hdr.nlmsg_len);
-               
-               nla->type = XFRMA_ALG_CRYPT;
-               nla->length = sizeof(netlink_algo_t) + encryption_key.len;
-               nla->algo.alg_key_len = encryption_key.len * 8;
+               xfrm_data_t *data = (xfrm_data_t*)(((u_int8_t*)&request) + request.hdr.nlmsg_len);
                
-               strcpy(nla->algo.alg_name, mapping_find(kernel_encryption_algs_m, enc_alg));
-               memcpy(nla->algo.alg_key, encryption_key.ptr, encryption_key.len);
-       
-               request.hdr.nlmsg_len += nla->length;
+               data->type = XFRMA_ALG_CRYPT;
+               data->length = 4 + sizeof(data->algo) + encryption_key.len;
+               data->algo.alg_key_len = encryption_key.len * 8;
+               request.hdr.nlmsg_len += data->length;
+               if (request.hdr.nlmsg_len > sizeof(request))
+               {
+                       return FAILED;
+               }
+               strcpy(data->algo.alg_name, mapping_find(kernel_encryption_algs_m, enc_alg));
+               memcpy(data->algo.alg_key, encryption_key.ptr, encryption_key.len);
        }
        
        if (int_alg != AUTH_UNDEFINED)
        {
-               netlink_algo_t *nla = (netlink_algo_t*)(((u_int8_t*)&request) + request.hdr.nlmsg_len);
+               xfrm_data_t *data = (xfrm_data_t*)(((u_int8_t*)&request) + request.hdr.nlmsg_len);
                
-               nla->type = XFRMA_ALG_AUTH;
-               nla->length = sizeof(netlink_algo_t) + integrity_key.len;
-               nla->algo.alg_key_len = integrity_key.len * 8;
-               strcpy(nla->algo.alg_name, mapping_find(kernel_integrity_algs_m, int_alg));
-               memcpy(nla->algo.alg_key, integrity_key.ptr, integrity_key.len);
+               data->type = XFRMA_ALG_AUTH;
+               data->length = 4 + sizeof(data->algo) + integrity_key.len;
+               data->algo.alg_key_len = integrity_key.len * 8;
+               request.hdr.nlmsg_len += data->length;
+               if (request.hdr.nlmsg_len > sizeof(request))
+               {
+                       return FAILED;
+               }
+               strcpy(data->algo.alg_name, mapping_find(kernel_integrity_algs_m, int_alg));
+               memcpy(data->algo.alg_key, integrity_key.ptr, integrity_key.len);
+       }
+       
+       /* TODO: add IPComp here*/
+       
+       if (this->send_message(this, &request, &response) != SUCCESS)
+       {
+               this->logger->log(this->logger, ERROR, "netlink communication failed");
+               return FAILED;
+       }
+       else if (response->hdr.nlmsg_type != NLMSG_ERROR)
+       {
+               this->logger->log(this->logger, ERROR, "netlink request XFRM_MSG_NEWSA not acknowledged");
+               status = FAILED;
+       }
+       else if (response->e.error)
+       {
+               this->logger->log(this->logger, ERROR, "netlink request XFRM_MSG_NEWSA got error %s",
+                                                 strerror(-response->e.error));
+               status = FAILED;
+       }
+       
+       free(response);
+       return status;
+}
+
+static status_t del_sa(        private_kernel_interface_t *this,
+                                               host_t *dst,
+                                               u_int32_t spi,
+                                               protocol_id_t protocol)
+{
+       netlink_message_t request, *response;
+       memset(&request, 0, sizeof(request));
+       status_t status = SUCCESS;
+       
+       this->logger->log(this->logger, CONTROL|LEVEL2, "deleting SA");
+       
+       request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
+       request.hdr.nlmsg_type = XFRM_MSG_DELSA;
+       
+       request.sa_id.daddr = dst->get_xfrm_addr(dst);
        
-               request.hdr.nlmsg_len += nla->length;
+       request.sa_id.spi = spi;
+       request.sa_id.proto = (protocol == PROTO_ESP) ? KERNEL_ESP : KERNEL_AH;
+       request.sa_id.family = dst->get_family(dst);
+       
+       request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.sa_id)));
+       
+       if (this->send_message(this, &request, &response) != SUCCESS)
+       {
+               return FAILED;
        }
+       else if (response->hdr.nlmsg_type != NLMSG_ERROR)
+       {
+               status = FAILED;
+       }
+       else if (response->e.error)
+       {
+               status = FAILED;
+       }
+       
+       free(response);
+       return status;
+}
+
+/**
+ * Implementation of kernel_interface_t.add_policy.
+ */
+static status_t add_policy(private_kernel_interface_t *this, 
+                                                 host_t *me, host_t *other, 
+                                                 host_t *src, host_t *dst,
+                                                 u_int8_t src_hostbits, u_int8_t dst_hostbits,
+                                                 int direction, int upper_proto, 
+                                                 bool ah, bool esp,
+                                                 u_int32_t reqid)
+{
+       netlink_message_t request, *response;
+       status_t status = SUCCESS;
+       
+       this->logger->log(this->logger, CONTROL|LEVEL2, "adding policy");
+       
+       memset(&request, 0, sizeof(request));
+       request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
+
+       request.policy.sel.sport = htons(src->get_port(src));
+       request.policy.sel.dport = htons(dst->get_port(dst));
+       request.policy.sel.sport_mask = (request.policy.sel.sport) ? ~0 : 0;
+       request.policy.sel.dport_mask = (request.policy.sel.dport) ? ~0 : 0;
+       request.policy.sel.saddr = src->get_xfrm_addr(src);
+       request.policy.sel.daddr = dst->get_xfrm_addr(dst);
+       request.policy.sel.prefixlen_s = src_hostbits;
+       request.policy.sel.prefixlen_d = dst_hostbits;
+       request.policy.sel.proto = upper_proto;
+       request.policy.sel.family = src->get_family(src);
+
+       request.hdr.nlmsg_type = XFRM_MSG_NEWPOLICY;
+       request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.policy)));
+
+       request.policy.dir = direction;
+       request.policy.priority = SPD_PRIORITY;
+       request.policy.action = XFRM_POLICY_ALLOW;
+       request.policy.share = XFRM_SHARE_ANY;
+       
+       request.policy.lft.soft_byte_limit = XFRM_INF;
+       request.policy.lft.soft_packet_limit = XFRM_INF;
+       request.policy.lft.hard_byte_limit = XFRM_INF;
+       request.policy.lft.hard_packet_limit = XFRM_INF;
        
-       /* add IPComp here*/
+       if (esp || ah)
+       {
+               xfrm_data_t *data;
+               int tmpl_pos = 0;
+               data = (xfrm_data_t*)(((u_int8_t*)&request) + request.hdr.nlmsg_len);
+               data->type = XFRMA_TMPL;
+               if (esp)
+               {
+                       data->tmpl[tmpl_pos].reqid = reqid;
+                       data->tmpl[tmpl_pos].id.proto = KERNEL_ESP;
+                       data->tmpl[tmpl_pos].aalgos = data->tmpl[tmpl_pos].ealgos = data->tmpl[tmpl_pos].calgos = ~0;
+                       data->tmpl[tmpl_pos].mode = TRUE;
+                       
+                       data->tmpl[tmpl_pos].saddr = me->get_xfrm_addr(me);
+                       data->tmpl[tmpl_pos].id.daddr = me->get_xfrm_addr(other);
+                       
+                       tmpl_pos++;
+               }       
+               if (ah)
+               {
+                       data->tmpl[tmpl_pos].reqid = reqid;
+                       data->tmpl[tmpl_pos].id.proto = KERNEL_AH;
+                       data->tmpl[tmpl_pos].aalgos = data->tmpl[tmpl_pos].ealgos = data->tmpl[tmpl_pos].calgos = ~0;
+                       data->tmpl[tmpl_pos].mode = TRUE;
+                       
+                       data->tmpl[tmpl_pos].saddr = me->get_xfrm_addr(me);
+                       data->tmpl[tmpl_pos].id.daddr = other->get_xfrm_addr(other);
+                       
+                       tmpl_pos++;
+               }
+               data->length = 4 + sizeof(struct xfrm_user_tmpl) * tmpl_pos;
+               request.hdr.nlmsg_len += data->length;
+       }
        
        if (this->send_message(this, &request, &response) != SUCCESS)
        {
-               allocator_free(response);
-               return FAILED;  
+               this->logger->log(this->logger, ERROR, "netlink communication failed");
+               return FAILED;
+       }
+       else if (response->hdr.nlmsg_type != NLMSG_ERROR)
+       {
+               this->logger->log(this->logger, ERROR, "netlink request XFRM_MSG_NEWPOLICY not acknowledged");
+               status = FAILED;
+       }
+       else if (response->e.error)
+       {
+               this->logger->log(this->logger, ERROR, "netlink request XFRM_MSG_NEWPOLICY got error %s",
+                                                 strerror(-response->e.error));
+               status = FAILED;
        }
        
-       allocator_free(response);
-       return SUCCESS;
+       free(response);
+       return status;
 }
 
+/**
+ * Implementation of kernel_interface_t.del_policy.
+ */
+static status_t del_policy(private_kernel_interface_t *this, 
+                                                  host_t *me, host_t *other, 
+                                                  host_t *src, host_t *dst,
+                                                  u_int8_t src_hostbits, u_int8_t dst_hostbits,
+                                                  int direction, int upper_proto)
+{
+       netlink_message_t request, *response;
+       status_t status = SUCCESS;
+       
+       
+       this->logger->log(this->logger, CONTROL|LEVEL2, "deleting policy");
+       
+       memset(&request, 0, sizeof(request));
+       request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
 
+       request.policy_id.sel.sport = htons(src->get_port(src));
+       request.policy_id.sel.dport = htons(dst->get_port(dst));
+       request.policy_id.sel.sport_mask = (request.policy.sel.sport) ? ~0 : 0;
+       request.policy_id.sel.dport_mask = (request.policy.sel.dport) ? ~0 : 0;
+       request.policy_id.sel.saddr = src->get_xfrm_addr(src);
+       request.policy_id.sel.daddr = dst->get_xfrm_addr(dst);
+       request.policy_id.sel.prefixlen_s = src_hostbits;
+       request.policy_id.sel.prefixlen_d = dst_hostbits;
+       request.policy_id.sel.proto = upper_proto;
+       request.policy_id.sel.family = src->get_family(src);
+       
+       request.policy_id.dir = direction;
+
+       request.hdr.nlmsg_type = XFRM_MSG_DELPOLICY;
+       request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.policy_id)));
+       
+       if (this->send_message(this, &request, &response) != SUCCESS)
+       {
+               return FAILED;
+       }
+       else if (response->hdr.nlmsg_type != NLMSG_ERROR)
+       {
+               status = FAILED;
+       }
+       else if (response->e.error)
+       {
+               status = FAILED;
+       }
+       
+       free(response);
+       return status;
+}
+
+/**
+ * Implementation of private_kernel_interface_t.send_message.
+ */
 static status_t send_message(private_kernel_interface_t *this, netlink_message_t *request, netlink_message_t **response)
 {
        size_t length;
@@ -325,7 +599,7 @@ static status_t send_message(private_kernel_interface_t *this, netlink_message_t
                {
                        break;
                }
-               /* we should time out, if something goes wrong */
+               /* TODO: we should time out, if something goes wrong!??? */
                pthread_cond_wait(&(this->condvar), &(this->mutex));
        }
        
@@ -334,7 +608,9 @@ static status_t send_message(private_kernel_interface_t *this, netlink_message_t
        return SUCCESS;
 }
 
-
+/**
+ * Implementation of private_kernel_interface_t.receive_messages.
+ */
 static void receive_messages(private_kernel_interface_t *this)
 {
        while(TRUE) 
@@ -383,7 +659,7 @@ static void receive_messages(private_kernel_interface_t *this)
                else
                {
                        /* add response to queue */                     
-                       listed_response = allocator_alloc(sizeof(response));
+                       listed_response = malloc(sizeof(response));
                        memcpy(listed_response, &response, sizeof(response));
 
                        pthread_mutex_lock(&(this->mutex));
@@ -396,8 +672,6 @@ static void receive_messages(private_kernel_interface_t *this)
        }
 }
 
-
-
 /**
  * Implementation of kernel_interface_t.destroy.
  */
@@ -407,7 +681,7 @@ static void destroy(private_kernel_interface_t *this)
        pthread_join(this->thread, NULL);
        close(this->socket);
        this->responses->destroy(this->responses);
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -415,13 +689,14 @@ static void destroy(private_kernel_interface_t *this)
  */
 kernel_interface_t *kernel_interface_create()
 {
-       private_kernel_interface_t *this = allocator_alloc_thing(private_kernel_interface_t);
+       private_kernel_interface_t *this = malloc_thing(private_kernel_interface_t);
        
        /* public functions */
-       this->public.get_spi = (status_t(*)(kernel_interface_t*,host_t*,host_t*,protocol_id_t,bool,u_int32_t*))get_spi;
-       
-       this->public.add_sa  = (status_t(*)(kernel_interface_t *,host_t*,host_t*,u_int32_t,int,bool,encryption_algorithm_t,chunk_t,integrity_algorithm_t,chunk_t,bool))add_sa;
-       
+       this->public.get_spi = (status_t(*)(kernel_interface_t*,host_t*,host_t*,protocol_id_t,u_int32_t,u_int32_t*))get_spi;
+       this->public.add_sa  = (status_t(*)(kernel_interface_t *,host_t*,host_t*,u_int32_t,protocol_id_t,u_int32_t,encryption_algorithm_t,chunk_t,integrity_algorithm_t,chunk_t,bool))add_sa;
+       this->public.add_policy = (status_t(*)(kernel_interface_t*,host_t*, host_t*,host_t*,host_t*,u_int8_t,u_int8_t,int,int,bool,bool,u_int32_t))add_policy;
+       this->public.del_sa = (status_t(*)(kernel_interface_t*,host_t*,u_int32_t,protocol_id_t))del_sa;
+       this->public.del_policy = (status_t(*)(kernel_interface_t*,host_t*,host_t*,host_t*,host_t*,u_int8_t,u_int8_t,int,int))del_policy;
        
        this->public.destroy = (void(*)(kernel_interface_t*)) destroy;
 
@@ -430,23 +705,25 @@ kernel_interface_t *kernel_interface_create()
        this->send_message = send_message;
        this->pid = getpid();
        this->responses = linked_list_create();
+       this->logger = logger_manager->get_logger(logger_manager, XFRM);
        pthread_mutex_init(&(this->mutex),NULL);
        pthread_cond_init(&(this->condvar),NULL);
        this->seq = 0;
        this->socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_XFRM);
        if (this->socket <= 0)
        {
-               allocator_free(this);
+               this->responses->destroy(this->responses);
+               free(this);
                charon->kill(charon, "Unable to create netlink socket");        
        }
        
        if (pthread_create(&(this->thread), NULL, (void*(*)(void*))this->receive_messages, this) != 0)
        {
+               this->responses->destroy(this->responses);
                close(this->socket);
-               allocator_free(this);
+               free(this);
                charon->kill(charon, "Unable to create netlink thread");
        }
        
-       charon->logger_manager->enable_logger_level(charon->logger_manager, TESTER, FULL);
        return (&this->public);
 }