- first attempt for connection loading and starting via "stroke"
- some improvements here and there
This commit is contained in:
@@ -368,32 +368,6 @@ static status_t update(private_child_sa_t *this, proposal_t *proposal, prf_plus_
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static u_int8_t get_mask(chunk_t start, chunk_t end)
|
||||
{
|
||||
int byte, bit, mask = 0;
|
||||
|
||||
if (start.len != end.len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for (byte = 0; byte < start.len; byte++)
|
||||
{
|
||||
for (bit = 7; bit >= 0; bit--)
|
||||
{
|
||||
if ((*(start.ptr + byte) | (1<<bit)) ==
|
||||
(*(end.ptr + byte) | (1<<bit)))
|
||||
{
|
||||
mask++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
return start.len * 8;
|
||||
}
|
||||
|
||||
static status_t add_policies(private_child_sa_t *this, linked_list_t *my_ts_list, linked_list_t *other_ts_list)
|
||||
{
|
||||
iterator_t *my_iter, *other_iter;
|
||||
@@ -410,7 +384,7 @@ static status_t add_policies(private_child_sa_t *this, linked_list_t *my_ts_list
|
||||
{
|
||||
/* set up policies for every entry in my_ts_list to every entry in other_ts_list */
|
||||
int family;
|
||||
chunk_t from_addr, to_addr;
|
||||
chunk_t from_addr;
|
||||
u_int16_t from_port, to_port;
|
||||
policy_t *policy;
|
||||
status_t status;
|
||||
@@ -428,26 +402,22 @@ static status_t add_policies(private_child_sa_t *this, linked_list_t *my_ts_list
|
||||
/* calculate net and ports for local side */
|
||||
family = my_ts->get_type(my_ts) == TS_IPV4_ADDR_RANGE ? AF_INET : AF_INET6;
|
||||
from_addr = my_ts->get_from_address(my_ts);
|
||||
to_addr = my_ts->get_to_address(my_ts);
|
||||
from_port = my_ts->get_from_port(my_ts);
|
||||
to_port = my_ts->get_to_port(my_ts);
|
||||
from_port = (from_port != to_port) ? 0 : from_port;
|
||||
policy->my_net = host_create_from_chunk(family, from_addr, from_port);
|
||||
policy->my_net_mask = get_mask(from_addr, to_addr);
|
||||
policy->my_net_mask = my_ts->get_netmask(my_ts);
|
||||
allocator_free_chunk(&from_addr);
|
||||
allocator_free_chunk(&to_addr);
|
||||
|
||||
/* calculate net and ports for remote side */
|
||||
family = other_ts->get_type(other_ts) == TS_IPV4_ADDR_RANGE ? AF_INET : AF_INET6;
|
||||
from_addr = other_ts->get_from_address(other_ts);
|
||||
to_addr = other_ts->get_to_address(other_ts);
|
||||
from_port = other_ts->get_from_port(other_ts);
|
||||
to_port = other_ts->get_to_port(other_ts);
|
||||
from_port = (from_port != to_port) ? 0 : from_port;
|
||||
policy->other_net = host_create_from_chunk(family, from_addr, from_port);
|
||||
policy->other_net_mask = get_mask(from_addr, to_addr);
|
||||
policy->other_net_mask = other_ts->get_netmask(other_ts);
|
||||
allocator_free_chunk(&from_addr);
|
||||
allocator_free_chunk(&to_addr);
|
||||
|
||||
/* install 3 policies: out, in and forward */
|
||||
status = charon->kernel_interface->add_policy(charon->kernel_interface,
|
||||
|
||||
@@ -1031,45 +1031,36 @@ static void destroy (private_ike_sa_t *this)
|
||||
this->ike_sa_id->get_responder_spi(this->ike_sa_id),
|
||||
this->ike_sa_id->is_initiator(this->ike_sa_id) ? "initiator" : "responder");
|
||||
|
||||
/* destroy child sa's */
|
||||
/* inform other peer of delete */
|
||||
send_delete_ike_sa_request(this);
|
||||
|
||||
while (this->child_sas->remove_last(this->child_sas, (void**)&child_sa) == SUCCESS)
|
||||
{
|
||||
child_sa->destroy(child_sa);
|
||||
}
|
||||
this->child_sas->destroy(this->child_sas);
|
||||
|
||||
if (this->crypter_initiator != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy initiator crypter_t object");
|
||||
this->crypter_initiator->destroy(this->crypter_initiator);
|
||||
}
|
||||
|
||||
if (this->crypter_responder != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy responder crypter_t object");
|
||||
this->crypter_responder->destroy(this->crypter_responder);
|
||||
}
|
||||
|
||||
if (this->signer_initiator != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy initiator signer_t object");
|
||||
this->signer_initiator->destroy(this->signer_initiator);
|
||||
}
|
||||
|
||||
if (this->signer_responder != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy responder signer_t object");
|
||||
this->signer_responder->destroy(this->signer_responder);
|
||||
}
|
||||
|
||||
if (this->prf != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy prf_t object");
|
||||
this->prf->destroy(this->prf);
|
||||
}
|
||||
if (this->child_prf != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy child_prf object");
|
||||
this->child_prf->destroy(this->child_prf);
|
||||
}
|
||||
if (this->prf_auth_i != NULL)
|
||||
@@ -1080,45 +1071,25 @@ static void destroy (private_ike_sa_t *this)
|
||||
{
|
||||
this->prf_auth_r->destroy(this->prf_auth_r);
|
||||
}
|
||||
|
||||
/* destroy ike_sa_id */
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy ike_sa_id object");
|
||||
this->ike_sa_id->destroy(this->ike_sa_id);
|
||||
|
||||
/* destroy stored requested message */
|
||||
if (this->last_requested_message != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy last requested message");
|
||||
this->last_requested_message->destroy(this->last_requested_message);
|
||||
}
|
||||
|
||||
/* destroy stored responded messages */
|
||||
if (this->last_responded_message != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy last responded message");
|
||||
this->last_responded_message->destroy(this->last_responded_message);
|
||||
}
|
||||
|
||||
/* destroy stored host_t objects */
|
||||
if (this->me.host != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy my host_t object");
|
||||
this->me.host->destroy(this->me.host);
|
||||
}
|
||||
|
||||
/* destroy stored host_t objects */
|
||||
if (this->other.host != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy other host_t object");
|
||||
this->other.host->destroy(this->other.host);
|
||||
}
|
||||
|
||||
this->randomizer->destroy(this->randomizer);
|
||||
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy current state object");
|
||||
this->current_state->destroy(this->current_state);
|
||||
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy logger of IKE_SA");
|
||||
charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
|
||||
|
||||
allocator_free(this);
|
||||
|
||||
@@ -47,15 +47,6 @@ struct private_ike_sa_established_t {
|
||||
*/
|
||||
logger_t *logger;
|
||||
|
||||
/**
|
||||
* Process received DELETE payload and build DELETE payload for INFORMATIONAL response.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param request DELETE payload received in INFORMATIONAL request
|
||||
* @param response The created DELETE payload is added to this message_t object
|
||||
*/
|
||||
status_t (*build_delete_payload) (private_ike_sa_established_t *this, delete_payload_t *request, message_t *response);
|
||||
|
||||
/**
|
||||
* Process a notify payload
|
||||
*
|
||||
@@ -145,6 +136,7 @@ static status_t process_message(private_ike_sa_established_t *this, message_t *m
|
||||
case DELETE:
|
||||
{
|
||||
delete_request = (delete_payload_t *) payload;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
@@ -158,16 +150,21 @@ static status_t process_message(private_ike_sa_established_t *this, message_t *m
|
||||
payloads->destroy(payloads);
|
||||
|
||||
if (delete_request)
|
||||
{
|
||||
status = this->build_delete_payload(this, delete_request, response);
|
||||
if (status == DELETE_ME)
|
||||
{
|
||||
if (delete_request->get_protocol_id(delete_request) == IKE)
|
||||
{
|
||||
this->logger->log(this->logger, AUDIT, "DELETE request for IKE_SA received");
|
||||
response->destroy(response);
|
||||
return status;
|
||||
return DELETE_ME;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->logger->log(this->logger, AUDIT, "DELETE request for CHILD_SA received. Ignored");
|
||||
response->destroy(response);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status = this->ike_sa->send_response(this->ike_sa, response);
|
||||
/* message can now be sent (must not be destroyed) */
|
||||
if (status != SUCCESS)
|
||||
@@ -180,23 +177,6 @@ static status_t process_message(private_ike_sa_established_t *this, message_t *m
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_ike_sa_established_t.build_sa_payload;
|
||||
*/
|
||||
static status_t build_delete_payload (private_ike_sa_established_t *this, delete_payload_t *request, message_t *response_message)
|
||||
{
|
||||
if (request->get_protocol_id(request) == IKE)
|
||||
{
|
||||
this->logger->log(this->logger, AUDIT, "DELETE request for IKE_SA received. Don't reply.");
|
||||
/* IKE_SA has to get deleted */
|
||||
return DELETE_ME;
|
||||
}
|
||||
|
||||
this->logger->log(this->logger, AUDIT, "DELETE payload for CHILD_SAs not supported and handled.");
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_ike_sa_established_t.process_notify_payload;
|
||||
*/
|
||||
@@ -250,7 +230,6 @@ ike_sa_established_t *ike_sa_established_create(protected_ike_sa_t *ike_sa)
|
||||
|
||||
/* private functions */
|
||||
this->process_notify_payload = process_notify_payload;
|
||||
this->build_delete_payload = build_delete_payload;
|
||||
|
||||
/* private data */
|
||||
this->ike_sa = ike_sa;
|
||||
|
||||
@@ -159,7 +159,6 @@ status_t retry_initiate_connection (private_initiator_init_t *this, diffie_hellm
|
||||
if (dh_group == MODP_UNDEFINED)
|
||||
{
|
||||
this->logger->log(this->logger, AUDIT, "No DH group acceptable for initialization, Aborting");
|
||||
message->destroy(message);
|
||||
return DELETE_ME;
|
||||
}
|
||||
|
||||
@@ -280,7 +279,7 @@ static void build_nonce_payload(private_initiator_init_t *this, message_t *reque
|
||||
*/
|
||||
static status_t process_message(private_initiator_init_t *this, message_t *message)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "In state INITIATOR_INIT no message is processed");
|
||||
this->logger->log(this->logger, ERROR, "In state INITIATOR_INIT, no message is processed");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
@@ -302,12 +301,10 @@ static void destroy(private_initiator_init_t *this)
|
||||
/* destroy diffie hellman object */
|
||||
if (this->diffie_hellman != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy diffie_hellman_t object");
|
||||
this->diffie_hellman->destroy(this->diffie_hellman);
|
||||
}
|
||||
if (this->sent_nonce.ptr != NULL)
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL | LEVEL3, "Free memory of sent nonce");
|
||||
allocator_free(this->sent_nonce.ptr);
|
||||
}
|
||||
allocator_free(this);
|
||||
|
||||
Reference in New Issue
Block a user