diff options
Diffstat (limited to 'Source/charon/threads')
-rw-r--r-- | Source/charon/threads/kernel_interface.c | 8 | ||||
-rw-r--r-- | Source/charon/threads/receiver.c | 5 | ||||
-rw-r--r-- | Source/charon/threads/scheduler.c | 7 | ||||
-rw-r--r-- | Source/charon/threads/sender.c | 6 | ||||
-rwxr-xr-x | Source/charon/threads/stroke.c | 82 | ||||
-rw-r--r-- | Source/charon/threads/thread_pool.c | 14 |
6 files changed, 68 insertions, 54 deletions
diff --git a/Source/charon/threads/kernel_interface.c b/Source/charon/threads/kernel_interface.c index c42a09129..87238d079 100644 --- a/Source/charon/threads/kernel_interface.c +++ b/Source/charon/threads/kernel_interface.c @@ -216,7 +216,7 @@ static status_t get_spi(private_kernel_interface_t *this, request.spi.info.id.daddr = dest->get_xfrm_addr(dest); request.spi.info.mode = TRUE; /* tunnel mode */ request.spi.info.reqid = reqid; - request.spi.info.id.proto = (protocol == ESP) ? KERNEL_ESP : KERNEL_AH; + request.spi.info.id.proto = (protocol == PROTO_ESP) ? KERNEL_ESP : KERNEL_AH; request.spi.info.family = PF_INET; request.spi.min = 0xc0000000; request.spi.max = 0xcFFFFFFF; @@ -270,7 +270,7 @@ static status_t add_sa( private_kernel_interface_t *this, request.sa.id.daddr = other->get_xfrm_addr(other); request.sa.id.spi = spi; - 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 = TRUE; /* tunnel mode */ request.sa.replay_window = 32; @@ -348,7 +348,7 @@ static status_t del_sa( private_kernel_interface_t *this, request.sa_id.daddr = dst->get_xfrm_addr(dst); request.sa_id.spi = spi; - request.sa_id.proto = (protocol == ESP) ? KERNEL_ESP : KERNEL_AH; + 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))); @@ -686,6 +686,6 @@ kernel_interface_t *kernel_interface_create() charon->kill(charon, "Unable to create netlink thread"); } - charon->logger_manager->enable_logger_level(charon->logger_manager, TESTER, FULL); + charon->logger_manager->enable_log_level(charon->logger_manager, TESTER, FULL); return (&this->public); } diff --git a/Source/charon/threads/receiver.c b/Source/charon/threads/receiver.c index 3b22c822c..9058ecbc4 100644 --- a/Source/charon/threads/receiver.c +++ b/Source/charon/threads/receiver.c @@ -102,8 +102,6 @@ static void destroy(private_receiver_t *this) pthread_join(this->assigned_thread, NULL); this->logger->log(this->logger, CONTROL | LEVEL1, "Receiver thread terminated"); - - charon->logger_manager->destroy_logger(charon->logger_manager, this->logger); allocator_free(this); } @@ -118,12 +116,11 @@ receiver_t * receiver_create() this->public.destroy = (void(*)(receiver_t*)) destroy; this->receive_packets = receive_packets; - this->logger = charon->logger_manager->create_logger(charon->logger_manager, RECEIVER, NULL); + this->logger = charon->logger_manager->get_logger(charon->logger_manager, RECEIVER); if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->receive_packets, this) != 0) { this->logger->log(this->logger, ERROR, "Receiver thread could not be started"); - charon->logger_manager->destroy_logger(charon->logger_manager, this->logger); allocator_free(this); charon->kill(charon, "Unable to create receiver thread"); } diff --git a/Source/charon/threads/scheduler.c b/Source/charon/threads/scheduler.c index 8205cfd45..8750cdae9 100644 --- a/Source/charon/threads/scheduler.c +++ b/Source/charon/threads/scheduler.c @@ -96,9 +96,7 @@ static void destroy(private_scheduler_t *this) pthread_cancel(this->assigned_thread); pthread_join(this->assigned_thread, NULL); - this->logger->log(this->logger, CONTROL | LEVEL1, "Scheduler thread terminated"); - - charon->logger_manager->destroy_logger(charon->logger_manager, this->logger); + this->logger->log(this->logger, CONTROL | LEVEL1, "Scheduler thread terminated"); allocator_free(this); } @@ -113,13 +111,12 @@ scheduler_t * scheduler_create() this->public.destroy = (void(*)(scheduler_t*)) destroy; this->get_events = get_events; - this->logger = charon->logger_manager->create_logger(charon->logger_manager, SCHEDULER, NULL); + this->logger = charon->logger_manager->get_logger(charon->logger_manager, SCHEDULER); if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->get_events, this) != 0) { /* thread could not be created */ this->logger->log(this->logger, ERROR, "Scheduler thread could not be created!"); - charon->logger_manager->destroy_logger(charon->logger_manager, this->logger); allocator_free(this); charon->kill(charon, "Unable to create scheduler thread"); } diff --git a/Source/charon/threads/sender.c b/Source/charon/threads/sender.c index 82aa2b2e3..90d9e409c 100644 --- a/Source/charon/threads/sender.c +++ b/Source/charon/threads/sender.c @@ -99,9 +99,7 @@ static void destroy(private_sender_t *this) pthread_cancel(this->assigned_thread); pthread_join(this->assigned_thread, NULL); - this->logger->log(this->logger, CONTROL | LEVEL1, "Sender thread terminated"); - - charon->logger_manager->destroy_logger(charon->logger_manager, this->logger); + this->logger->log(this->logger, CONTROL | LEVEL1, "Sender thread terminated"); allocator_free(this); } @@ -116,7 +114,7 @@ sender_t * sender_create() this->send_packets = send_packets; this->public.destroy = (void(*)(sender_t*)) destroy; - this->logger = charon->logger_manager->create_logger(charon->logger_manager, SENDER, NULL); + this->logger = charon->logger_manager->get_logger(charon->logger_manager, SENDER); if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->send_packets, this) != 0) { diff --git a/Source/charon/threads/stroke.c b/Source/charon/threads/stroke.c index 1bc94c85d..40b3cecee 100755 --- a/Source/charon/threads/stroke.c +++ b/Source/charon/threads/stroke.c @@ -224,7 +224,7 @@ static void stroke_receive(private_stroke_t *this) continue; } - this->logger->log_bytes(this->logger, CONTROL, "stroke message", (void*)msg, msg_length); + this->logger->log_bytes(this->logger, RAW, "stroke message", (void*)msg, msg_length); switch (msg->type) { @@ -327,35 +327,70 @@ static void stroke_receive(private_stroke_t *this) break; } - this->logger->log(this->logger, CONTROL, "my ID %s, others ID %s", - my_id->get_string(my_id), - other_id->get_string(other_id)); + my_ts = traffic_selector_create_from_subnet(my_subnet, *msg->add_conn.me.subnet ? msg->add_conn.me.subnet_mask : 32); + my_subnet->destroy(my_subnet); + other_ts = traffic_selector_create_from_subnet(other_subnet, *msg->add_conn.other.subnet ? msg->add_conn.other.subnet_mask : 32); + other_subnet->destroy(other_subnet); + + if (charon->socket->is_listening_on(charon->socket, other_host)) + { + this->logger->log(this->logger, CONTROL|LEVEL1, "left is other host, switching"); + + host_t *tmp_host = my_host; + identification_t *tmp_id = my_id; + traffic_selector_t *tmp_ts = my_ts; + + my_host = other_host; + other_host = tmp_host; + my_id = other_id; + other_id = tmp_id; + my_ts = other_ts; + other_ts = tmp_ts; + } + else if (charon->socket->is_listening_on(charon->socket, my_host)) + { + this->logger->log(this->logger, CONTROL|LEVEL1, "left is own host, not switching"); + } + else + { + this->logger->log(this->logger, ERROR, "left nor right host is our, aborting"); + + my_host->destroy(my_host); + other_host->destroy(other_host); + my_id->destroy(my_id); + other_id->destroy(other_id); + my_ts->destroy(my_ts); + other_ts->destroy(other_ts); + break; + } connection = connection_create(my_host, other_host, my_id->clone(my_id), other_id->clone(other_id), SHARED_KEY_MESSAGE_INTEGRITY_CODE); proposal = proposal_create(1); - proposal->add_algorithm(proposal, IKE, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16); - proposal->add_algorithm(proposal, IKE, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0); - proposal->add_algorithm(proposal, IKE, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA1, 0); - proposal->add_algorithm(proposal, IKE, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0); + proposal->add_algorithm(proposal, PROTO_IKE, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16); + proposal->add_algorithm(proposal, PROTO_IKE, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0); + proposal->add_algorithm(proposal, PROTO_IKE, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0); + proposal->add_algorithm(proposal, PROTO_IKE, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA1, 0); + proposal->add_algorithm(proposal, PROTO_IKE, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_MD5, 0); + proposal->add_algorithm(proposal, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0); + proposal->add_algorithm(proposal, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_1536_BIT, 0); + proposal->add_algorithm(proposal, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0); + proposal->add_algorithm(proposal, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_4096_BIT, 0); + proposal->add_algorithm(proposal, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_8192_BIT, 0); connection->add_proposal(connection, proposal); policy = policy_create(my_id, other_id); proposal = proposal_create(1); - proposal->add_algorithm(proposal, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16); - proposal->add_algorithm(proposal, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0); + proposal->add_algorithm(proposal, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16); + proposal->add_algorithm(proposal, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0); + proposal->add_algorithm(proposal, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 0); policy->add_proposal(policy, proposal); - - my_ts = traffic_selector_create_from_subnet(my_subnet, *msg->add_conn.me.subnet ? msg->add_conn.me.subnet_mask : 32); - my_subnet->destroy(my_subnet); policy->add_my_traffic_selector(policy, my_ts); - other_ts = traffic_selector_create_from_subnet(other_subnet, *msg->add_conn.other.subnet ? msg->add_conn.other.subnet_mask : 32); - other_subnet->destroy(other_subnet); policy->add_other_traffic_selector(policy, other_ts); this->configurations->insert_last(this->configurations, configuration_entry_create(msg->add_conn.name, connection, policy)); - this->logger->log(this->logger, CONTROL, "connection \"%s\" added (%d in store)", + this->logger->log(this->logger, CONTROL|LEVEL1, "connection \"%s\" added (%d in store)", msg->add_conn.name, this->configurations->get_count(this->configurations)); break; @@ -395,7 +430,7 @@ static connection_t *get_connection_by_hosts(connection_store_t *store, host_t * config_other_host = entry->connection->get_other_host(entry->connection); /* first check if ip is equal */ - if(config_other_host->ip_is_equal(config_other_host, other_host)) + if(config_other_host->ip_equals(config_other_host, other_host)) { this->logger->log(this->logger, CONTROL|LEVEL2, "config entry with remote host %s", config_other_host->get_address(config_other_host)); @@ -406,7 +441,7 @@ static connection_t *get_connection_by_hosts(connection_store_t *store, host_t * break; } /* check now if host informations are the same */ - else if (config_my_host->ip_is_equal(config_my_host,my_host)) + else if (config_my_host->ip_equals(config_my_host,my_host)) { found = entry->connection->clone(entry->connection); break; @@ -425,7 +460,7 @@ static connection_t *get_connection_by_hosts(connection_store_t *store, host_t * break; } /* check now if host informations are the same */ - else if (config_my_host->ip_is_equal(config_my_host,my_host)) + else if (config_my_host->ip_equals(config_my_host,my_host)) { found = entry->connection->clone(entry->connection); break; @@ -562,7 +597,7 @@ static policy_t *get_policy(policy_store_t *store,identification_t *my_id, ident */ static status_t get_shared_secret(credential_store_t *this, identification_t *identification, chunk_t *preshared_secret) { - char *secret = "schluessel"; + char *secret = "schluessel\n"; preshared_secret->ptr = secret; preshared_secret->len = strlen(secret) + 1; @@ -613,7 +648,6 @@ static void destroy(private_stroke_t *this) } this->rsa_public_keys->destroy(this->rsa_public_keys); - charon->logger_manager->destroy_logger(charon->logger_manager,this->logger); close(this->socket); unlink(socket_addr.sun_path); allocator_free(this); @@ -653,14 +687,13 @@ stroke_t *stroke_create() this->stroke_receive = stroke_receive; this->get_connection_by_name = get_connection_by_name; - this->logger = charon->logger_manager->create_logger(charon->logger_manager,CONFIG,NULL); + this->logger = charon->logger_manager->get_logger(charon->logger_manager, CONFIG); /* set up unix socket */ this->socket = socket(AF_UNIX, SOCK_STREAM, 0); if (this->socket == -1) { this->logger->log(this->logger, ERROR, "could not create whack socket"); - charon->logger_manager->destroy_logger(charon->logger_manager,this->logger); allocator_free(this); return NULL; } @@ -669,7 +702,6 @@ stroke_t *stroke_create() if (bind(this->socket, (struct sockaddr *)&socket_addr, sizeof(socket_addr)) < 0) { this->logger->log(this->logger, ERROR, "could not bind stroke socket: %s", strerror(errno)); - charon->logger_manager->destroy_logger(charon->logger_manager,this->logger); close(this->socket); allocator_free(this); return NULL; @@ -679,7 +711,6 @@ stroke_t *stroke_create() if (listen(this->socket, 0) < 0) { this->logger->log(this->logger, ERROR, "could not listen on stroke socket: %s", strerror(errno)); - charon->logger_manager->destroy_logger(charon->logger_manager,this->logger); close(this->socket); unlink(socket_addr.sun_path); allocator_free(this); @@ -690,7 +721,6 @@ stroke_t *stroke_create() if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->stroke_receive, this) != 0) { this->logger->log(this->logger, ERROR, "Could not spawn stroke thread"); - charon->logger_manager->destroy_logger(charon->logger_manager, this->logger); close(this->socket); unlink(socket_addr.sun_path); allocator_free(this); diff --git a/Source/charon/threads/thread_pool.c b/Source/charon/threads/thread_pool.c index f3e2fd8e6..1f1584ec3 100644 --- a/Source/charon/threads/thread_pool.c +++ b/Source/charon/threads/thread_pool.c @@ -296,11 +296,7 @@ static void process_incoming_packet_job(private_thread_pool_t *this, incoming_pa this->create_delete_half_open_ike_sa_job(this,ike_sa_id,charon->configuration->get_half_open_ike_sa_timeout(charon->configuration)); } - status = ike_sa->process_message(ike_sa, message); - if ((status != SUCCESS) && (status != DELETE_ME)) - { - this->worker_logger->log(this->worker_logger, ERROR, "Message could not be processed by IKE SA"); - } + status = ike_sa->process_message(ike_sa, message); this->worker_logger->log(this->worker_logger, CONTROL|LEVEL3, "%s IKE SA %lld:%lld, role %s", (status == DELETE_ME) ? "Checkin and delete" : "Checkin", @@ -558,8 +554,6 @@ static void destroy(private_thread_pool_t *this) } /* free mem */ - charon->logger_manager->destroy_logger(charon->logger_manager, this->pool_logger); - charon->logger_manager->destroy_logger(charon->logger_manager, this->worker_logger); allocator_free(this->threads); allocator_free(this); } @@ -589,9 +583,9 @@ thread_pool_t *thread_pool_create(size_t pool_size) this->threads = allocator_alloc(sizeof(pthread_t) * pool_size); - this->pool_logger = charon->logger_manager->create_logger(charon->logger_manager,THREAD_POOL,NULL); + this->pool_logger = charon->logger_manager->get_logger(charon->logger_manager, THREAD_POOL); - this->worker_logger = charon->logger_manager->create_logger(charon->logger_manager,WORKER,NULL); + this->worker_logger = charon->logger_manager->get_logger(charon->logger_manager, WORKER); /* try to create as many threads as possible, up tu pool_size */ for (current = 0; current < pool_size; current++) @@ -606,8 +600,6 @@ thread_pool_t *thread_pool_create(size_t pool_size) if (current == 0) { this->pool_logger->log(this->pool_logger, ERROR, "Could not create any thread"); - charon->logger_manager->destroy_logger(charon->logger_manager, this->pool_logger); - charon->logger_manager->destroy_logger(charon->logger_manager, this->worker_logger); allocator_free(this->threads); allocator_free(this); return NULL; |