- pid re-replaced with thread_ids, since nptl does not distinguish pids between threads
/* could be right one, check my_host for default route*/
if (config_my_host->is_default_route(config_my_host))
{
- printf("is default route\n");
*init_config = entry->init_config;
status = SUCCESS;
break;
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
-#include <unistd.h>
#include "daemon.h"
sigset_t signal_set;
/**
- * pid of main-thread
+ * thread_id of main-thread
*/
- pid_t main_thread_pid;
+ pthread_t main_thread_id;
/**
* main loop
{
/* we send SIGTERM, so the daemon can cleanly shut down */
this->logger->log(this->logger, ERROR, "Killing daemon: %s", reason);
- if (this->main_thread_pid == getpid())
+ if (this->main_thread_id == pthread_self())
{
/* initialization failed, terminate daemon */
this->destroy(this);
static void build_test_jobs(private_daemon_t *this)
{
int i;
- for(i = 0; i<1; i++)
+ for(i = 0; i<100; i++)
{
initiate_ike_sa_job_t *initiate_job;
initiate_job = initiate_ike_sa_job_create("localhost");
- this->public.job_queue->add(this->public.job_queue, (job_t*)initiate_job);
+ this->public.event_queue->add_relative(this->public.event_queue, (job_t*)initiate_job, i * 5000);
}
}
this->public.sender = sender_create();
this->public.receiver = receiver_create();
this->public.scheduler = scheduler_create();
- this->public.prime_pool = prime_pool_create(0);
+ this->public.prime_pool = prime_pool_create(10);
this->public.thread_pool = thread_pool_create(NUMBER_OF_WORKING_THREADS);
}
this->public.scheduler = NULL;
this->public.thread_pool = NULL;
- this->main_thread_pid = getpid();
+ this->main_thread_id = pthread_self();
/* setup signal handling */
sigemptyset(&(this->signal_set));
* maximum allowed level for ever context, the definiton
* of the context may be less verbose.
*/
-#define DEFAULT_LOGLEVEL FULL
+#define DEFAULT_LOGLEVEL CONTROL
typedef struct daemon_t daemon_t;
size_t new_buffer_size = old_buffer_size + GENERATOR_DATA_BUFFER_INCREASE_VALUE;
size_t out_position_offset = ((this->out_position) - (this->buffer));
- this->logger->log(this->logger, CONTROL|MOST, "increased gen buffer from %d to %d byte",
+ this->logger->log(this->logger, CONTROL|ALL, "increased gen buffer from %d to %d byte",
old_buffer_size, new_buffer_size);
/* Reallocate space for new buffer */
payload_start = this->out_position;
- this->logger->log(this->logger, CONTROL, "generating payload of type %s",
+ this->logger->log(this->logger, CONTROL|MORE, "generating payload of type %s",
mapping_find(payload_type_m,payload_type));
/* each payload has its own encoding rules */
for (i = 0; i < rule_count;i++)
{
- this->logger->log(this->logger, CONTROL|MORE, " generating rule %d %s",
+ this->logger->log(this->logger, CONTROL|MOST, " generating rule %d %s",
i, mapping_find(encoding_type_m,rules[i].type));
switch (rules[i].type)
{
{
if (this->attribute_format == FALSE)
{
- this->logger->log(this->logger, CONTROL|MOST, "attribute value has not fixed size");
+ this->logger->log(this->logger, CONTROL|ALL, "attribute value has not fixed size");
/* the attribute value is generated */
this->generate_from_chunk(this,rules[i].offset);
}
status_t status;
- this->logger->log(this->logger, CONTROL, "parsing Header of message");
+ this->logger->log(this->logger, CONTROL|MORE, "parsing Header of message");
this->parser->reset_context(this->parser);
status = this->parser->parse_payload(this->parser,HEADER,(payload_t **) &ike_header);
this->minor_version = ike_header->get_min_version(ike_header);
this->first_payload = ike_header->payload_interface.get_next_type(&(ike_header->payload_interface));
-
- this->logger->log(this->logger, CONTROL, "Parsing and verification of header successfully");
+ this->logger->log(this->logger, CONTROL, "Parsed a %s %s", mapping_find(exchange_type_m, this->exchange_type),
+ this->is_request ? "request" : "response");
ike_header->destroy(ike_header);
return SUCCESS;
status_t status = SUCCESS;
payload_type_t current_payload_type = this->first_payload;
- this->logger->log(this->logger, CONTROL, "Parsing body of message, first payload %s",
+ this->logger->log(this->logger, CONTROL|MORE, "Parsing body of message, first payload %s",
mapping_find(payload_type_m, current_payload_type));
while ((current_payload_type != NO_PAYLOAD))
{
payload_t *current_payload;
- this->logger->log(this->logger, CONTROL|MORE, "Start parsing payload of type %s",
+ this->logger->log(this->logger, CONTROL|MOST, "Start parsing payload of type %s",
mapping_find(payload_type_m, current_payload_type));
status = this->parser->parse_payload(this->parser,current_payload_type,(payload_t **) ¤t_payload);
/* get next payload type */
current_payload_type = current_payload->get_next_type(current_payload);
}
+
+ this->logger->log(this->logger, CONTROL, "Message a %s %s contains %d payloads",
+ mapping_find(exchange_type_m, this->exchange_type),
+ this->is_request ? "request" : "response",
+ this->payloads->get_count(this->payloads));
status = this->decrypt_and_verify_payloads(this,crypter,signer);
if (status != SUCCESS)
{
if (this->byte_pos + sizeof(u_int8_t) > this->input_roof)
{
- this->logger->log(this->logger, ERROR, " not enough input to parse rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " not enough input to parse rule %d %s",
rule_number, mapping_find(encoding_type_m,
this->rules[rule_number].type));
return PARSE_ERROR;
{
if (this->byte_pos + sizeof(u_int8_t) > this->input_roof)
{
- this->logger->log(this->logger, ERROR, " not enough input to parse rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " not enough input to parse rule %d %s",
rule_number, mapping_find(encoding_type_m,
this->rules[rule_number].type));
return PARSE_ERROR;
{
if (this->byte_pos + sizeof(u_int16_t) > this->input_roof)
{
- this->logger->log(this->logger, ERROR, " not enough input to parse rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " not enough input to parse rule %d %s",
rule_number, mapping_find(encoding_type_m,
this->rules[rule_number].type));
return PARSE_ERROR;
{
if (this->byte_pos + sizeof(u_int16_t) > this->input_roof)
{
- this->logger->log(this->logger, ERROR, " not enough input to parse rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " not enough input to parse rule %d %s",
rule_number, mapping_find(encoding_type_m, this->rules[rule_number].type));
return PARSE_ERROR;
}
{
if (this->byte_pos + sizeof(u_int32_t) > this->input_roof)
{
- this->logger->log(this->logger, ERROR, " not enough input to parse rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " not enough input to parse rule %d %s",
rule_number, mapping_find(encoding_type_m, this->rules[rule_number].type));
return PARSE_ERROR;
}
{
if (this->byte_pos + sizeof(u_int64_t) > this->input_roof)
{
- this->logger->log(this->logger, ERROR, " not enough input to parse rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " not enough input to parse rule %d %s",
rule_number, mapping_find(encoding_type_m, this->rules[rule_number].type));
return PARSE_ERROR;
}
{
if (this->byte_pos + bytes > this->input_roof)
{
- this->logger->log(this->logger, ERROR, " not enough input to parse rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " not enough input to parse rule %d %s",
rule_number, mapping_find(encoding_type_m, this->rules[rule_number].type));
return PARSE_ERROR;
}
{
if (this->byte_pos + sizeof(u_int8_t) > this->input_roof)
{
- this->logger->log(this->logger, ERROR, " not enough input to parse rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " not enough input to parse rule %d %s",
rule_number, mapping_find(encoding_type_m, this->rules[rule_number].type));
return PARSE_ERROR;
}
if (length < 0)
{
- this->logger->log(this->logger, ERROR, " invalid length for rule %d %s",
+ this->logger->log(this->logger, ERROR|MORE, " invalid length for rule %d %s",
rule_number, mapping_find(encoding_type_m, this->rules[rule_number].type));
return PARSE_ERROR;
}
int rule_number;
encoding_rule_t *rule;
- this->logger->log(this->logger, CONTROL, "parsing %s payload, %d bytes left",
+ this->logger->log(this->logger, CONTROL|MORE, "parsing %s payload, %d bytes left",
mapping_find(payload_type_m, payload_type),
this->input_roof-this->byte_pos);
for (rule_number = 0; rule_number < rule_count; rule_number++)
{
rule = &(this->rules[rule_number]);
- this->logger->log(this->logger, CONTROL|MORE, " parsing rule %d %s",
+ this->logger->log(this->logger, CONTROL|MOST, " parsing rule %d %s",
rule_number, mapping_find(encoding_type_m, rule->type));
switch (rule->type)
{
{
static u_int8_t default_route[4] = {0x00,0x00,0x00,0x00};
struct sockaddr_in *sin = (struct sockaddr_in*)&(this->address);
- printf("host address: %ul\n", sin->sin_addr.s_addr);
if (memcmp(default_route,&(sin->sin_addr.s_addr),4) == 0)
{
#include <stdlib.h>
#include <pthread.h>
-#include <unistd.h>
#include "receiver.h"
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- this->logger->log(this->logger, CONTROL, "receiver thread running, pid %d", getpid());
+ this->logger->log(this->logger, CONTROL, "receiver thread running, thread_id %u", (int)pthread_self());
while (1)
{
#include <stdlib.h>
#include <pthread.h>
-#include <unistd.h>
#include "scheduler.h"
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- this->logger->log(this->logger, CONTROL, "scheduler thread running, pid %d", getpid());
+ this->logger->log(this->logger, CONTROL, "scheduler thread running, thread_id %u", (int)pthread_self());
for (;;)
{
#include <stdlib.h>
#include <pthread.h>
-#include <unistd.h>
#include "sender.h"
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- this->logger->log(this->logger, CONTROL, "sender thread running, pid %d", getpid());
+ this->logger->log(this->logger, CONTROL, "sender thread running, thread_id %u", (int)pthread_self());
while (1)
{
#include <pthread.h>
#include <string.h>
#include <errno.h>
-#include <unistd.h>
#include "thread_pool.h"
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- this->worker_logger->log(this->worker_logger, CONTROL, "worker thread running, pid: %d", getpid());
+ this->worker_logger->log(this->worker_logger, CONTROL, "worker thread running, thread_id: %u", (int)pthread_self());
for (;;) {
job_t *job;
#include <stdio.h>
#include <time.h>
#include <pthread.h>
-#include <unistd.h>
#include "logger.h"
FILE *output;
/**
- * Should a pid be included in the log?
+ * Should a thread_id be included in the log?
*/
- bool log_pid;
+ bool log_thread_id;
/**
* Applies a prefix to string and stores it in buffer.
log_details = '0';
}
- if (this->log_pid)
+ if (this->log_thread_id)
{
- snprintf(buffer, MAX_LOG, "[%c%c] [%s] @%d %s", log_type, log_details, this->name, getpid(), string);
+ snprintf(buffer, MAX_LOG, "[%c%c] [%s] @%u %s", log_type, log_details, this->name, (int)pthread_self(), string);
}
else
{
/*
* Described in header.
*/
-logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_pid, FILE * output)
+logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_thread_id, FILE * output)
{
private_logger_t *this = allocator_alloc_thing(private_logger_t);
/* private variables */
this->level = log_level;
- this->log_pid = log_pid;
+ this->log_thread_id = log_thread_id;
this->name = allocator_alloc(strlen(logger_name) + 1);
strcpy(this->name,logger_name);
*
* @param this logger_t object
* @param loglevel or'ed set of loglevels
- * @param label a labeling name, logged with the bytes
- * @param bytes pointer to the bytes to dump
+ * @param label a labeling name, logged with the bytes
+ * @param bytes pointer to the bytes to dump
* @param len number of bytes to dump
*/
void (*log_bytes) (logger_t *this, logger_level_t loglevel, char *label, char *bytes, size_t len);
*
* @param this logger_t object
* @param loglevel or'ed set of loglevels
- * @param label a labeling name, logged with the bytes
+ * @param label a labeling name, logged with the bytes
* @param chunk pointer to a chunk to log
*/
void (*log_chunk) (logger_t *this, logger_level_t loglevel, char *label, chunk_t *chunk);
*
* @param logger_name name for the logger_t object
* @param log_level or'ed set of log_levels to assign to the new logger_t object
- * @param log_pid TRUE if thread id should also be logged
- * @param output FILE * if log has to go on a file output, NULL for syslog
+ * @param log_thread_id TRUE if thread id should also be logged
+ * @param output FILE * if log has to go on a file output, NULL for syslog
* @return logger_t object
*
* @ingroup utils
*/
-logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_pid, FILE * output);
+logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_thread_id, FILE * output);
#endif /*LOGGER_H_*/
{DAEMON, "DAEMON"},
{CONFIGURATION_MANAGER, "CONFIG"},
{ENCRYPTION_PAYLOAD, "ENCPLD"},
+ {PRIME_POOL, "PRIMEP"},
+ {MAPPING_END, NULL},
};
/**
/* output to stdout, since we are debugging all days */
output = stdout;
+
+ /* defaults */
+ log_thread_ids = FALSE;
+ logger_level = this->public.get_logger_level(&(this->public),context);;
switch(context)
{
case TESTER:
- log_thread_ids = FALSE;
output = stdout;
- logger_level |= FULL;
break;
- case IKE_SA:
- logger_level |= FULL;
case IKE_SA_MANAGER:
- case WORKER:
+ log_thread_ids = TRUE;
+ break;
+ case IKE_SA:
+ log_thread_ids = TRUE;
+ break;
case CONFIGURATION_MANAGER:
- logger_level |= ALL;
+ log_thread_ids = TRUE;
+ break;
case MESSAGE:
+ log_thread_ids = TRUE;
+ break;
case ENCRYPTION_PAYLOAD:
-
+ log_thread_ids = TRUE;
+ break;
case GENERATOR:
+ log_thread_ids = TRUE;
+ break;
+ case PARSER:
+ log_thread_ids = TRUE;
+ break;
+ case WORKER:
+ log_thread_ids = TRUE;
+ break;
case THREAD_POOL:
+ break;
+ case PRIME_POOL:
+ break;
case SCHEDULER:
+ break;
case SENDER:
+ break;
case RECEIVER:
+ break;
case SOCKET:
+ break;
case DAEMON:
- logger_level |= CONTROL;
- case PARSER:
- log_thread_ids = FALSE;
- logger_level |= ERROR;
break;
}
- /* reduce to global definiton of loglevel */
- logger_level &= this->public.get_logger_level(&(this->public),context);
-
/* logger manager is thread save */
pthread_mutex_lock(&(this->mutex));
if (name != NULL)
DAEMON,
CONFIGURATION_MANAGER,
ENCRYPTION_PAYLOAD,
+ PRIME_POOL,
};
typedef struct logger_manager_t logger_manager_t;