improved signal handling and emitting

This commit is contained in:
Martin Willi
2006-10-26 09:46:56 +00:00
parent 80d35dd6d3
commit b83806d83d
46 changed files with 939 additions and 834 deletions
+54 -54
View File
@@ -357,12 +357,12 @@ static void receive_messages(private_kernel_interface_t *this)
}
if (reqid == 0)
{
DBG1(SIG_DBG_KNL, "received a XFRM_MSG_ACQUIRE, but no reqid found");
DBG1(DBG_KNL, "received a XFRM_MSG_ACQUIRE, but no reqid found");
}
else
{
DBG2(SIG_DBG_KNL, "received a XFRM_MSG_ACQUIRE");
DBG1(SIG_DBG_KNL, "creating acquire job for CHILD_SA with reqid %d",
DBG2(DBG_KNL, "received a XFRM_MSG_ACQUIRE");
DBG1(DBG_KNL, "creating acquire job for CHILD_SA with reqid %d",
reqid);
job = (job_t*)acquire_job_create(reqid);
charon->job_queue->add(charon->job_queue, job);
@@ -381,8 +381,8 @@ static void receive_messages(private_kernel_interface_t *this)
spi = expire->state.id.spi;
reqid = expire->state.reqid;
DBG2(SIG_DBG_KNL, "received a XFRM_MSG_EXPIRE");
DBG1(SIG_DBG_KNL, "creating %s job for %N CHILD_SA 0x%x (reqid %d)",
DBG2(DBG_KNL, "received a XFRM_MSG_EXPIRE");
DBG1(DBG_KNL, "creating %s job for %N CHILD_SA 0x%x (reqid %d)",
expire->hard ? "delete" : "rekey",
protocol_id_names, protocol, ntohl(spi),
reqid);
@@ -447,7 +447,7 @@ static status_t get_spi(private_kernel_interface_t *this,
memset(&request, 0, sizeof(request));
status_t status = SUCCESS;
DBG2(SIG_DBG_KNL, "getting spi");
DBG2(DBG_KNL, "getting spi");
hdr = (struct nlmsghdr*)request;
hdr->nlmsg_flags = NLM_F_REQUEST;
@@ -466,29 +466,29 @@ static status_t get_spi(private_kernel_interface_t *this,
if (send_message(this, hdr, &response) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
return FAILED;
}
else if (response->nlmsg_type == NLMSG_ERROR)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_ALLOCSPI got an error: %s",
DBG1(DBG_KNL, "netlink request XFRM_MSG_ALLOCSPI got an error: %s",
strerror(-((struct nlmsgerr*)NLMSG_DATA(response))->error));
status = FAILED;
}
else if (response->nlmsg_type != XFRM_MSG_NEWSA)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_ALLOCSPI got a unknown reply");
DBG1(DBG_KNL, "netlink request XFRM_MSG_ALLOCSPI got a unknown reply");
status = FAILED;
}
else if (response->nlmsg_len < NLMSG_LENGTH(sizeof(struct xfrm_usersa_info)))
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_ALLOCSPI got an invalid reply");
DBG1(DBG_KNL, "netlink request XFRM_MSG_ALLOCSPI got an invalid reply");
status = FAILED;
}
else
{
*spi = ((struct xfrm_usersa_info*)NLMSG_DATA(response))->id.spi;
DBG2(SIG_DBG_KNL, "SPI is 0x%x", *spi);
DBG2(DBG_KNL, "SPI is 0x%x", *spi);
}
free(response);
@@ -516,7 +516,7 @@ static status_t add_sa(private_kernel_interface_t *this,
memset(&request, 0, sizeof(request));
status_t status = SUCCESS;
DBG2(SIG_DBG_KNL, "adding SA");
DBG2(DBG_KNL, "adding SA");
hdr = (struct nlmsghdr*)request;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
@@ -551,11 +551,11 @@ static status_t add_sa(private_kernel_interface_t *this,
alg_name = lookup_algorithm(encryption_algs, enc_alg, &key_size);
if (alg_name == NULL)
{
DBG1(SIG_DBG_KNL, "algorithm %N not supported by kernel!",
DBG1(DBG_KNL, "algorithm %N not supported by kernel!",
encryption_algorithm_names, enc_alg->algorithm);
return FAILED;
}
DBG2(SIG_DBG_KNL, " using encryption algorithm %N with key size %d",
DBG2(DBG_KNL, " using encryption algorithm %N with key size %d",
encryption_algorithm_names, enc_alg->algorithm, key_size);
rthdr->rta_len = RTA_LENGTH(sizeof(struct xfrm_algo) + key_size);
@@ -579,11 +579,11 @@ static status_t add_sa(private_kernel_interface_t *this,
alg_name = lookup_algorithm(integrity_algs, int_alg, &key_size);
if (alg_name == NULL)
{
DBG1(SIG_DBG_KNL, "algorithm %N not supported by kernel!",
DBG1(DBG_KNL, "algorithm %N not supported by kernel!",
integrity_algorithm_names, int_alg->algorithm);
return FAILED;
}
DBG2(SIG_DBG_KNL, " using integrity algorithm %N with key size %d",
DBG2(DBG_KNL, " using integrity algorithm %N with key size %d",
integrity_algorithm_names, int_alg->algorithm, key_size);
rthdr->rta_len = RTA_LENGTH(sizeof(struct xfrm_algo) + key_size);
@@ -634,17 +634,17 @@ static status_t add_sa(private_kernel_interface_t *this,
if (send_message(this, hdr, &response) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
return FAILED;
}
else if (response->nlmsg_type != NLMSG_ERROR)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_NEWSA not acknowledged");
DBG1(DBG_KNL, "netlink request XFRM_MSG_NEWSA not acknowledged");
status = FAILED;
}
else if (((struct nlmsgerr*)NLMSG_DATA(response))->error)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_NEWSA got an error: %s",
DBG1(DBG_KNL, "netlink request XFRM_MSG_NEWSA got an error: %s",
strerror(-((struct nlmsgerr*)NLMSG_DATA(response))->error));
status = FAILED;
}
@@ -671,7 +671,7 @@ static status_t update_sa(
memset(&request, 0, sizeof(request));
status_t status = SUCCESS;
DBG2(SIG_DBG_KNL, "getting SA");
DBG2(DBG_KNL, "getting SA");
hdr = (struct nlmsghdr*)request;
hdr->nlmsg_flags = NLM_F_REQUEST;
@@ -686,30 +686,30 @@ static status_t update_sa(
if (send_message(this, hdr, &update) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
return FAILED;
}
else if (update->nlmsg_type == NLMSG_ERROR)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_GETSA got an error: %s",
DBG1(DBG_KNL, "netlink request XFRM_MSG_GETSA got an error: %s",
strerror(-((struct nlmsgerr*)NLMSG_DATA(update))->error));
free(update);
return FAILED;
}
else if (update->nlmsg_type != XFRM_MSG_NEWSA)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_GETSA got a unknown reply");
DBG1(DBG_KNL, "netlink request XFRM_MSG_GETSA got a unknown reply");
free(update);
return FAILED;
}
else if (update->nlmsg_len < NLMSG_LENGTH(sizeof(struct xfrm_usersa_info)))
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_GETSA got an invalid reply");
DBG1(DBG_KNL, "netlink request XFRM_MSG_GETSA got an invalid reply");
free(update);
return FAILED;
}
DBG2(SIG_DBG_KNL, "updating SA");
DBG2(DBG_KNL, "updating SA");
update->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
update->nlmsg_type = XFRM_MSG_UPDSA;
@@ -721,7 +721,7 @@ static status_t update_sa(
if (dst_changes & HOST_DIFF_ADDR)
{
DBG2(SIG_DBG_KNL, "destination address changed! replacing SA");
DBG2(DBG_KNL, "destination address changed! replacing SA");
update->nlmsg_type = XFRM_MSG_NEWSA;
host2xfrm(new_dst, &sa->id.daddr);
@@ -746,24 +746,24 @@ static status_t update_sa(
if (send_message(this, update, &response) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
free(update);
return FAILED;
}
else if (response->nlmsg_type != NLMSG_ERROR)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_XXXSA not acknowledged");
DBG1(DBG_KNL, "netlink request XFRM_MSG_XXXSA not acknowledged");
status = FAILED;
}
else if (((struct nlmsgerr*)NLMSG_DATA(response))->error)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_XXXSA got an error: %s",
DBG1(DBG_KNL, "netlink request XFRM_MSG_XXXSA got an error: %s",
strerror(-((struct nlmsgerr*)NLMSG_DATA(response))->error));
status = FAILED;
}
else if (dst_changes & HOST_DIFF_ADDR)
{
DBG2(SIG_DBG_KNL, "deleting old SA");
DBG2(DBG_KNL, "deleting old SA");
status = this->public.del_sa(&this->public, dst, spi, protocol);
}
@@ -784,7 +784,7 @@ static status_t query_sa(private_kernel_interface_t *this, host_t *dst,
struct xfrm_usersa_id *sa_id;
struct xfrm_usersa_info *sa_info;
DBG2(SIG_DBG_KNL, "querying SA");
DBG2(DBG_KNL, "querying SA");
memset(&request, 0, sizeof(request));
hdr = (struct nlmsghdr*)request;
@@ -800,18 +800,18 @@ static status_t query_sa(private_kernel_interface_t *this, host_t *dst,
if (send_message(this, hdr, &response) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
return FAILED;
}
else if (response->nlmsg_type != XFRM_MSG_NEWSA)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_GETSA not acknowledged");
DBG1(DBG_KNL, "netlink request XFRM_MSG_GETSA not acknowledged");
free(response);
return FAILED;
}
else if (response->nlmsg_len < NLMSG_LENGTH(sizeof(struct xfrm_usersa_info)))
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_GETSA got an invalid reply");
DBG1(DBG_KNL, "netlink request XFRM_MSG_GETSA got an invalid reply");
free(response);
return FAILED;
}
@@ -837,7 +837,7 @@ static status_t del_sa(private_kernel_interface_t *this, host_t *dst,
memset(&request, 0, sizeof(request));
status_t status = SUCCESS;
DBG2(SIG_DBG_KNL, "deleting SA");
DBG2(DBG_KNL, "deleting SA");
hdr = (struct nlmsghdr*)request;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
@@ -852,17 +852,17 @@ static status_t del_sa(private_kernel_interface_t *this, host_t *dst,
if (send_message(this, hdr, &response) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
return FAILED;
}
else if (response->nlmsg_type != NLMSG_ERROR)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_DELSA not acknowledged");
DBG1(DBG_KNL, "netlink request XFRM_MSG_DELSA not acknowledged");
status = FAILED;
}
else if (((struct nlmsgerr*)NLMSG_DATA(response))->error)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_DELSA got an error: %s",
DBG1(DBG_KNL, "netlink request XFRM_MSG_DELSA got an error: %s",
strerror(-((struct nlmsgerr*)NLMSG_DATA(response))->error));
status = FAILED;
}
@@ -1000,7 +1000,7 @@ static status_t add_policy(private_kernel_interface_t *this,
if (!update)
{
current->refcount++;
DBG2(SIG_DBG_KNL, "policy already exists, increasing refcount");
DBG2(DBG_KNL, "policy already exists, increasing refcount");
if (!high_prio)
{
/* if added policy is for a ROUTED child_sa, do not
@@ -1022,7 +1022,7 @@ static status_t add_policy(private_kernel_interface_t *this,
policy->refcount = 1;
}
DBG2(SIG_DBG_KNL, "adding policy");
DBG2(DBG_KNL, "adding policy");
memset(&request, 0, sizeof(request));
hdr = (struct nlmsghdr*)request;
@@ -1076,17 +1076,17 @@ static status_t add_policy(private_kernel_interface_t *this,
if (send_message(this, hdr, &response) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
return FAILED;
}
else if (response->nlmsg_type != NLMSG_ERROR)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_UPDPOLICY not acknowledged");
DBG1(DBG_KNL, "netlink request XFRM_MSG_UPDPOLICY not acknowledged");
status = FAILED;
}
else if (((struct nlmsgerr*)NLMSG_DATA(response))->error)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_UPDPOLICY got an error: %s",
DBG1(DBG_KNL, "netlink request XFRM_MSG_UPDPOLICY got an error: %s",
strerror(-((struct nlmsgerr*)NLMSG_DATA(response))->error));
status = FAILED;
}
@@ -1112,7 +1112,7 @@ static status_t query_policy(private_kernel_interface_t *this,
memset(&request, 0, sizeof(request));
status_t status = SUCCESS;
DBG2(SIG_DBG_KNL, "querying policy");
DBG2(DBG_KNL, "querying policy");
hdr = (struct nlmsghdr*)request;
hdr->nlmsg_flags = NLM_F_REQUEST;
@@ -1125,25 +1125,25 @@ static status_t query_policy(private_kernel_interface_t *this,
if (send_message(this, hdr, &response) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
return FAILED;
}
else if (response->nlmsg_type == NLMSG_ERROR)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_GETPOLICY got an error: %s",
DBG1(DBG_KNL, "netlink request XFRM_MSG_GETPOLICY got an error: %s",
strerror(-((struct nlmsgerr*)NLMSG_DATA(response))->error));
free(response);
return FAILED;
}
else if (response->nlmsg_type != XFRM_MSG_NEWPOLICY)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_GETPOLICY got an unknown reply");
DBG1(DBG_KNL, "netlink request XFRM_MSG_GETPOLICY got an unknown reply");
free(response);
return FAILED;
}
else if (response->nlmsg_len < NLMSG_LENGTH(sizeof(struct xfrm_userpolicy_info)))
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_GETPOLICY got an invalid reply");
DBG1(DBG_KNL, "netlink request XFRM_MSG_GETPOLICY got an invalid reply");
free(response);
return FAILED;
}
@@ -1172,7 +1172,7 @@ static status_t del_policy(private_kernel_interface_t *this,
iterator_t *iterator;
status_t status = SUCCESS;
DBG2(SIG_DBG_KNL, "deleting policy");
DBG2(DBG_KNL, "deleting policy");
/* create a policy */
memset(&policy, 0, sizeof(kernel_policy_t));
@@ -1191,7 +1191,7 @@ static status_t del_policy(private_kernel_interface_t *this,
if (--to_delete->refcount > 0)
{
/* is used by more SAs, keep in kernel */
DBG2(SIG_DBG_KNL, "is used by other SAs, not removed");
DBG2(DBG_KNL, "is used by other SAs, not removed");
iterator->destroy(iterator);
pthread_mutex_unlock(&this->pol_mutex);
return SUCCESS;
@@ -1205,7 +1205,7 @@ static status_t del_policy(private_kernel_interface_t *this,
pthread_mutex_unlock(&this->pol_mutex);
if (!to_delete)
{
DBG1(SIG_DBG_KNL, "no such policy found");
DBG1(DBG_KNL, "no such policy found");
return NOT_FOUND;
}
@@ -1224,17 +1224,17 @@ static status_t del_policy(private_kernel_interface_t *this,
if (send_message(this, hdr, &response) != SUCCESS)
{
DBG1(SIG_DBG_KNL, "netlink communication failed");
DBG1(DBG_KNL, "netlink communication failed");
return FAILED;
}
else if (response->nlmsg_type != NLMSG_ERROR)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_DELPOLICY not acknowledged");
DBG1(DBG_KNL, "netlink request XFRM_MSG_DELPOLICY not acknowledged");
status = FAILED;
}
else if (((struct nlmsgerr*)NLMSG_DATA(response))->error)
{
DBG1(SIG_DBG_KNL, "netlink request XFRM_MSG_DELPOLICY got an error: %s",
DBG1(DBG_KNL, "netlink request XFRM_MSG_DELPOLICY got an error: %s",
strerror(-((struct nlmsgerr*)NLMSG_DATA(response))->error));
status = FAILED;
}
+3 -3
View File
@@ -62,20 +62,20 @@ static void receive_packets(private_receiver_t * this)
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
DBG1(SIG_DBG_NET, "receiver thread running, thread_ID: %06u",
DBG1(DBG_NET, "receiver thread running, thread_ID: %06u",
(int)pthread_self());
while (TRUE)
{
while (charon->socket->receive(charon->socket,&current_packet) == SUCCESS)
{
DBG2(SIG_DBG_NET, "creating job from packet");
DBG2(DBG_NET, "creating job from packet");
current_job = (job_t *) incoming_packet_job_create(current_packet);
charon->job_queue->add(charon->job_queue,current_job);
}
/* bad bad, TODO: rebuild the socket ? */
DBG1(SIG_DBG_NET, "receiving from socket failed!");
DBG1(DBG_NET, "receiving from socket failed!");
}
}
+3 -3
View File
@@ -58,16 +58,16 @@ static void get_events(private_scheduler_t * this)
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
DBG1(SIG_DBG_JOB, "scheduler thread running, thread_ID: %06u",
DBG1(DBG_JOB, "scheduler thread running, thread_ID: %06u",
(int)pthread_self());
while (TRUE)
{
DBG2(SIG_DBG_JOB, "waiting for next event...");
DBG2(DBG_JOB, "waiting for next event...");
/* get a job, this block until one is available */
current_job = charon->event_queue->get(charon->event_queue);
/* queue the job in the job queue, workers will eat them */
DBG2(SIG_DBG_JOB, "got event, adding job %N to job-queue",
DBG2(DBG_JOB, "got event, adding job %N to job-queue",
job_type_names, current_job->get_type(current_job));
charon->job_queue->add(charon->job_queue, current_job);
}
+3 -3
View File
@@ -61,17 +61,17 @@ static void send_packets(private_sender_t * this)
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
DBG1(SIG_DBG_NET, "sender thread running, thread_ID: %06u",
DBG1(DBG_NET, "sender thread running, thread_ID: %06u",
(int)pthread_self());
while (TRUE)
{
current_packet = charon->send_queue->get(charon->send_queue);
DBG2(SIG_DBG_NET, "got a packet, sending it");
DBG2(DBG_NET, "got a packet, sending it");
status = charon->socket->send(charon->socket, current_packet);
if (status != SUCCESS)
{
DBG1(SIG_DBG_NET, "sending packet failed");
DBG1(DBG_NET, "sending packet failed");
}
current_packet->destroy(current_packet);
}
+57 -62
View File
@@ -133,7 +133,7 @@ static x509_t* load_end_certificate(const char *filename, identification_t **idp
if (ugh != NULL)
{
DBG1(SIG_DBG_CFG, "warning: certificate %s", ugh);
DBG1(DBG_CFG, "warning: certificate %s", ugh);
}
if (!id->equals(id, subject) && !cert->equals_subjectAltName(cert, id))
{
@@ -178,27 +178,27 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
pop_string(msg, &msg->add_conn.algorithms.ike);
pop_string(msg, &msg->add_conn.algorithms.esp);
DBG1(SIG_DBG_CFG, "received stroke: add connection '%s'", msg->add_conn.name);
DBG1(DBG_CFG, "received stroke: add connection '%s'", msg->add_conn.name);
DBG2(SIG_DBG_CFG, "conn %s", msg->add_conn.name);
DBG2(SIG_DBG_CFG, " right=%s", msg->add_conn.me.address);
DBG2(SIG_DBG_CFG, " left=%s", msg->add_conn.other.address);
DBG2(SIG_DBG_CFG, " rightsubnet=%s", msg->add_conn.me.subnet);
DBG2(SIG_DBG_CFG, " leftsubnet=%s", msg->add_conn.other.subnet);
DBG2(SIG_DBG_CFG, " rightid=%s", msg->add_conn.me.id);
DBG2(SIG_DBG_CFG, " leftid=%s", msg->add_conn.other.id);
DBG2(SIG_DBG_CFG, " rightcert=%s", msg->add_conn.me.cert);
DBG2(SIG_DBG_CFG, " leftcert=%s", msg->add_conn.other.cert);
DBG2(SIG_DBG_CFG, " rightca=%s", msg->add_conn.me.ca);
DBG2(SIG_DBG_CFG, " leftca=%s", msg->add_conn.other.ca);
DBG2(SIG_DBG_CFG, " ike=%s", msg->add_conn.algorithms.ike);
DBG2(SIG_DBG_CFG, " esp=%s", msg->add_conn.algorithms.esp);
DBG2(DBG_CFG, "conn %s", msg->add_conn.name);
DBG2(DBG_CFG, " right=%s", msg->add_conn.me.address);
DBG2(DBG_CFG, " left=%s", msg->add_conn.other.address);
DBG2(DBG_CFG, " rightsubnet=%s", msg->add_conn.me.subnet);
DBG2(DBG_CFG, " leftsubnet=%s", msg->add_conn.other.subnet);
DBG2(DBG_CFG, " rightid=%s", msg->add_conn.me.id);
DBG2(DBG_CFG, " leftid=%s", msg->add_conn.other.id);
DBG2(DBG_CFG, " rightcert=%s", msg->add_conn.me.cert);
DBG2(DBG_CFG, " leftcert=%s", msg->add_conn.other.cert);
DBG2(DBG_CFG, " rightca=%s", msg->add_conn.me.ca);
DBG2(DBG_CFG, " leftca=%s", msg->add_conn.other.ca);
DBG2(DBG_CFG, " ike=%s", msg->add_conn.algorithms.ike);
DBG2(DBG_CFG, " esp=%s", msg->add_conn.algorithms.esp);
my_host = msg->add_conn.me.address?
host_create_from_string(msg->add_conn.me.address, IKE_PORT) : NULL;
if (my_host == NULL)
{
DBG1(SIG_DBG_CFG, "invalid host: %s\n", msg->add_conn.me.address);
DBG1(DBG_CFG, "invalid host: %s\n", msg->add_conn.me.address);
return;
}
@@ -206,7 +206,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
host_create_from_string(msg->add_conn.other.address, IKE_PORT) : NULL;
if (other_host == NULL)
{
DBG1(SIG_DBG_CFG, "invalid host: %s\n", msg->add_conn.other.address);
DBG1(DBG_CFG, "invalid host: %s\n", msg->add_conn.other.address);
my_host->destroy(my_host);
return;
}
@@ -216,7 +216,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
stroke_end_t tmp_end;
host_t *tmp_host;
DBG2(SIG_DBG_CFG, "left is other host, swapping ends\n");
DBG2(DBG_CFG, "left is other host, swapping ends\n");
tmp_host = my_host;
my_host = other_host;
@@ -228,7 +228,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
}
else if (!charon->socket->is_local_address(charon->socket, my_host, NULL))
{
DBG1(SIG_DBG_CFG, "left nor right host is our side, aborting\n");
DBG1(DBG_CFG, "left nor right host is our side, aborting\n");
goto destroy_hosts;
}
@@ -236,7 +236,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
msg->add_conn.me.id : msg->add_conn.me.address);
if (my_id == NULL)
{
DBG1(SIG_DBG_CFG, "invalid ID: %s\n", msg->add_conn.me.id);
DBG1(DBG_CFG, "invalid ID: %s\n", msg->add_conn.me.id);
goto destroy_hosts;
}
@@ -244,7 +244,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
msg->add_conn.other.id : msg->add_conn.other.address);
if (other_id == NULL)
{
DBG1(SIG_DBG_CFG, "invalid ID: %s\n", msg->add_conn.other.id);
DBG1(DBG_CFG, "invalid ID: %s\n", msg->add_conn.other.id);
my_id->destroy(my_id);
goto destroy_hosts;
}
@@ -253,7 +253,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
msg->add_conn.me.subnet : msg->add_conn.me.address, IKE_PORT);
if (my_subnet == NULL)
{
DBG1(SIG_DBG_CFG, "invalid subnet: %s\n", msg->add_conn.me.subnet);
DBG1(DBG_CFG, "invalid subnet: %s\n", msg->add_conn.me.subnet);
goto destroy_ids;
}
@@ -261,7 +261,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
msg->add_conn.other.subnet : msg->add_conn.other.address, IKE_PORT);
if (other_subnet == NULL)
{
DBG1(SIG_DBG_CFG, "invalid subnet: %s\n", msg->add_conn.me.subnet);
DBG1(DBG_CFG, "invalid subnet: %s\n", msg->add_conn.me.subnet);
my_subnet->destroy(my_subnet);
goto destroy_ids;
}
@@ -336,9 +336,9 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
{
other_ca = identification_create_from_string("%any");
}
DBG2(SIG_DBG_CFG, " my ca: '%D'", my_ca);
DBG2(SIG_DBG_CFG, " other ca:'%D'", other_ca);
DBG2(SIG_DBG_CFG, " updown: '%s'", msg->add_conn.me.updown);
DBG2(DBG_CFG, " my ca: '%D'", my_ca);
DBG2(DBG_CFG, " other ca:'%D'", other_ca);
DBG2(DBG_CFG, " updown: '%s'", msg->add_conn.me.updown);
connection = connection_create(msg->add_conn.name,
msg->add_conn.ikev2,
@@ -366,7 +366,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
proposal = proposal_create_from_string(PROTO_IKE, proposal_string);
if (proposal == NULL)
{
DBG1(SIG_DBG_CFG, "invalid IKE proposal string: %s", proposal_string);
DBG1(DBG_CFG, "invalid IKE proposal string: %s", proposal_string);
my_id->destroy(my_id);
other_id->destroy(other_id);
my_ts->destroy(my_ts);
@@ -416,7 +416,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
proposal = proposal_create_from_string(PROTO_ESP, proposal_string);
if (proposal == NULL)
{
DBG1(SIG_DBG_CFG, "invalid ESP proposal string: %s", proposal_string);
DBG1(DBG_CFG, "invalid ESP proposal string: %s", proposal_string);
policy->destroy(policy);
connection->destroy(connection);
return;
@@ -437,7 +437,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
/* add to global connection list */
charon->connections->add_connection(charon->connections, connection);
DBG1(SIG_DBG_CFG, "added connection '%s': %H[%D]...%H[%D]",
DBG1(DBG_CFG, "added connection '%s': %H[%D]...%H[%D]",
msg->add_conn.name, my_host, my_id, other_host, other_id);
/* add to global policy list */
charon->policies->add_policy(charon->policies, policy);
@@ -463,7 +463,7 @@ static void stroke_del_conn(private_stroke_t *this, stroke_msg_t *msg)
status_t status;
pop_string(msg, &(msg->del_conn.name));
DBG1(SIG_DBG_CFG, "received stroke: delete '%s'", msg->del_conn.name);
DBG1(DBG_CFG, "received stroke: delete '%s'", msg->del_conn.name);
status = charon->connections->delete_connection(charon->connections,
msg->del_conn.name);
@@ -490,7 +490,7 @@ static void stroke_initiate(private_stroke_t *this, stroke_msg_t *msg)
signal_t signal;
pop_string(msg, &(msg->initiate.name));
DBG1(SIG_DBG_CFG, "received stroke: initiate '%s'", msg->initiate.name);
DBG1(DBG_CFG, "received stroke: initiate '%s'", msg->initiate.name);
connection = charon->connections->get_connection_by_name(charon->connections,
msg->initiate.name);
@@ -519,10 +519,6 @@ static void stroke_initiate(private_stroke_t *this, stroke_msg_t *msg)
connection->destroy(connection);
return;
}
if (msg->output_verbosity >= 0)
{
fprintf(this->out, "initiating connection '%s'\n", msg->initiate.name);
}
job = initiate_job_create(connection, policy);
@@ -552,17 +548,16 @@ static void stroke_initiate(private_stroke_t *this, stroke_msg_t *msg)
/* TODO: Handle INVALID_KE_PAYLOAD signal (ike_sa switch) */
switch (signal)
{
case SIG_IKE_UP:
case SIG_IKE_FAILED:
case SIG_CHILD_UP:
case SIG_CHILD_FAILED:
case CHILD_UP_SUCCESS:
case CHILD_UP_FAILED:
if (ike_sa == init_ike_sa)
{
charon->bus->set_listen_state(charon->bus, FALSE);
return;
}
continue;
case SIG_INITIATE:
case CHILD_UP_START:
case IKE_UP_START:
if (init_ike_sa == NULL)
{
init_ike_sa = ike_sa;
@@ -584,7 +579,7 @@ static void stroke_route(private_stroke_t *this, stroke_msg_t *msg, bool route)
policy_t *policy;
pop_string(msg, &(msg->route.name));
DBG1(SIG_DBG_CFG, "received stroke: %s '%s'",
DBG1(DBG_CFG, "received stroke: %s '%s'",
route ? "route" : "unroute", msg->route.name);
/* we wouldn't need a connection, but we only want to route policies
@@ -622,7 +617,7 @@ static void stroke_route(private_stroke_t *this, stroke_msg_t *msg, bool route)
static void stroke_terminate(private_stroke_t *this, stroke_msg_t *msg)
{
pop_string(msg, &(msg->terminate.name));
DBG1(SIG_DBG_CFG, "received stroke: terminate '%s'", msg->terminate.name);
DBG1(DBG_CFG, "received stroke: terminate '%s'", msg->terminate.name);
charon->ike_sa_manager->delete_by_name(charon->ike_sa_manager, msg->terminate.name);
}
@@ -843,15 +838,15 @@ static void stroke_reread(private_stroke_t *this, stroke_msg_t *msg)
signal_t get_signal_from_logtype(char *type)
{
if (strcasecmp(type, "any") == 0) return SIG_ANY;
else if (strcasecmp(type, "mgr") == 0) return SIG_DBG_MGR;
else if (strcasecmp(type, "ike") == 0) return SIG_DBG_IKE;
else if (strcasecmp(type, "chd") == 0) return SIG_DBG_CHD;
else if (strcasecmp(type, "job") == 0) return SIG_DBG_JOB;
else if (strcasecmp(type, "cfg") == 0) return SIG_DBG_CFG;
else if (strcasecmp(type, "knl") == 0) return SIG_DBG_KNL;
else if (strcasecmp(type, "net") == 0) return SIG_DBG_NET;
else if (strcasecmp(type, "enc") == 0) return SIG_DBG_ENC;
else if (strcasecmp(type, "lib") == 0) return SIG_DBG_LIB;
else if (strcasecmp(type, "mgr") == 0) return DBG_MGR;
else if (strcasecmp(type, "ike") == 0) return DBG_IKE;
else if (strcasecmp(type, "chd") == 0) return DBG_CHD;
else if (strcasecmp(type, "job") == 0) return DBG_JOB;
else if (strcasecmp(type, "cfg") == 0) return DBG_CFG;
else if (strcasecmp(type, "knl") == 0) return DBG_KNL;
else if (strcasecmp(type, "net") == 0) return DBG_NET;
else if (strcasecmp(type, "enc") == 0) return DBG_ENC;
else if (strcasecmp(type, "lib") == 0) return DBG_LIB;
else return -1;
}
@@ -863,7 +858,7 @@ static void stroke_loglevel(private_stroke_t *this, stroke_msg_t *msg)
signal_t signal;
pop_string(msg, &(msg->loglevel.type));
DBG1(SIG_DBG_CFG, "received stroke: loglevel %d for %s",
DBG1(DBG_CFG, "received stroke: loglevel %d for %s",
msg->loglevel.level, msg->loglevel.type);
signal = get_signal_from_logtype(msg->loglevel.type);
@@ -902,7 +897,7 @@ static void stroke_receive(private_stroke_t *this)
if (strokefd < 0)
{
DBG1(SIG_DBG_CFG, "accepting stroke connection failed: %m");
DBG1(DBG_CFG, "accepting stroke connection failed: %m");
continue;
}
@@ -910,7 +905,7 @@ static void stroke_receive(private_stroke_t *this)
bytes_read = recv(strokefd, &msg_length, sizeof(msg_length), MSG_PEEK);
if (bytes_read != sizeof(msg_length))
{
DBG1(SIG_DBG_CFG, "reading lenght of stroke message failed");
DBG1(DBG_CFG, "reading lenght of stroke message failed");
close(strokefd);
continue;
}
@@ -920,7 +915,7 @@ static void stroke_receive(private_stroke_t *this)
bytes_read = recv(strokefd, msg, msg_length, 0);
if (bytes_read != msg_length)
{
DBG1(SIG_DBG_CFG, "reading stroke message failed: %m");
DBG1(DBG_CFG, "reading stroke message failed: %m");
close(strokefd);
continue;
}
@@ -928,13 +923,13 @@ static void stroke_receive(private_stroke_t *this)
this->out = fdopen(dup(strokefd), "w");
if (this->out == NULL)
{
DBG1(SIG_DBG_CFG, "opening stroke output channel failed: %m");
DBG1(DBG_CFG, "opening stroke output channel failed: %m");
close(strokefd);
free(msg);
continue;
}
DBG3(SIG_DBG_CFG, "stroke message %b", (void*)msg, msg_length);
DBG3(DBG_CFG, "stroke message %b", (void*)msg, msg_length);
switch (msg->type)
{
@@ -972,7 +967,7 @@ static void stroke_receive(private_stroke_t *this)
stroke_reread(this, msg);
break;
default:
DBG1(SIG_DBG_CFG, "received unknown stroke");
DBG1(DBG_CFG, "received unknown stroke");
}
fclose(this->out);
close(strokefd);
@@ -1008,7 +1003,7 @@ stroke_t *stroke_create()
this->socket = socket(AF_UNIX, SOCK_STREAM, 0);
if (this->socket == -1)
{
DBG1(SIG_DBG_CFG, "could not create whack socket");
DBG1(DBG_CFG, "could not create whack socket");
free(this);
return NULL;
}
@@ -1016,7 +1011,7 @@ stroke_t *stroke_create()
old = umask(~S_IRWXU);
if (bind(this->socket, (struct sockaddr *)&socket_addr, sizeof(socket_addr)) < 0)
{
DBG1(SIG_DBG_CFG, "could not bind stroke socket: %m");
DBG1(DBG_CFG, "could not bind stroke socket: %m");
close(this->socket);
free(this);
return NULL;
@@ -1025,7 +1020,7 @@ stroke_t *stroke_create()
if (listen(this->socket, 0) < 0)
{
DBG1(SIG_DBG_CFG, "could not listen on stroke socket: %m");
DBG1(DBG_CFG, "could not listen on stroke socket: %m");
close(this->socket);
unlink(socket_addr.sun_path);
free(this);
@@ -1035,7 +1030,7 @@ stroke_t *stroke_create()
/* start a thread reading from the socket */
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))stroke_receive, this) != 0)
{
DBG1(SIG_DBG_CFG, "Could not spawn stroke thread");
DBG1(DBG_CFG, "could not spawn stroke thread");
close(this->socket);
unlink(socket_addr.sun_path);
free(this);
+7 -6
View File
@@ -70,11 +70,12 @@ static void process_jobs(private_thread_pool_t *this)
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
DBG1(SIG_DBG_JOB, "worker thread running, thread_ID: %06u",
DBG1(DBG_JOB, "worker thread running, thread_ID: %06u",
(int)pthread_self());
while (TRUE)
{
/* TODO: should be atomic, but is not mission critical */
this->idle_threads++;
job = charon->job_queue->get(charon->job_queue);
this->idle_threads--;
@@ -113,7 +114,7 @@ static void destroy(private_thread_pool_t *this)
/* flag thread for termination */
for (current = 0; current < this->pool_size; current++)
{
DBG1(SIG_DBG_JOB, "cancelling worker thread #%d", current+1);
DBG1(DBG_JOB, "cancelling worker thread #%d", current+1);
pthread_cancel(this->threads[current]);
}
@@ -121,11 +122,11 @@ static void destroy(private_thread_pool_t *this)
for (current = 0; current < this->pool_size; current++) {
if (pthread_join(this->threads[current], NULL) == 0)
{
DBG1(SIG_DBG_JOB, "worker thread #%d terminated", current+1);
DBG1(DBG_JOB, "worker thread #%d terminated", current+1);
}
else
{
DBG1(SIG_DBG_JOB, "could not terminate worker thread #%d", current+1);
DBG1(DBG_JOB, "could not terminate worker thread #%d", current+1);
}
}
@@ -158,7 +159,7 @@ thread_pool_t *thread_pool_create(size_t pool_size)
if (pthread_create(&(this->threads[current]), NULL,
(void*(*)(void*))process_jobs, this) == 0)
{
DBG1(SIG_DBG_JOB, "created worker thread #%d", current+1);
DBG1(DBG_JOB, "created worker thread #%d", current+1);
}
else
{
@@ -170,7 +171,7 @@ thread_pool_t *thread_pool_create(size_t pool_size)
charon->kill(charon, "could not create any worker threads");
}
/* not all threads could be created, but at least one :-/ */
DBG1(SIG_DBG_JOB, "could only create %d from requested %d threads!",
DBG1(DBG_JOB, "could only create %d from requested %d threads!",
current, pool_size);
this->pool_size = current;
break;