applied new changes from NATT team
DPD only done when no IPsec and IKE traffic processed minor changes here and there
This commit is contained in:
@@ -327,7 +327,6 @@ static status_t install(private_child_sa_t *this, proposal_t *proposal, prf_plus
|
||||
|
||||
static status_t add(private_child_sa_t *this, proposal_t *proposal, prf_plus_t *prf_plus)
|
||||
{
|
||||
linked_list_t *list;
|
||||
u_int32_t outbound_spi, inbound_spi;
|
||||
|
||||
/* backup outbound spi, as alloc overwrites it */
|
||||
@@ -539,6 +538,94 @@ static void log_status(private_child_sa_t *this, logger_t *logger, char* name)
|
||||
iterator->destroy(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of child_sa_t.get_use_time
|
||||
*/
|
||||
static status_t get_use_time(private_child_sa_t *this, bool inbound, time_t *use_time)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
sa_policy_t *policy;
|
||||
struct protoent *proto;
|
||||
char proto_buf[8] = "";
|
||||
char *proto_name = proto_buf;
|
||||
status_t status;
|
||||
|
||||
*use_time = UNDEFINED_TIME;
|
||||
|
||||
iterator = this->policies->create_iterator(this->policies, TRUE);
|
||||
while (iterator->iterate(iterator, (void**)&policy))
|
||||
{
|
||||
time_t ut;
|
||||
|
||||
if (policy->upper_proto)
|
||||
{
|
||||
proto = getprotobynumber(policy->upper_proto);
|
||||
if (proto)
|
||||
{
|
||||
proto_name = proto->p_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(proto_buf, sizeof(proto_buf), "<%d>", policy->upper_proto);
|
||||
}
|
||||
}
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1,
|
||||
"quering policy: %s/%d==%s==%s/%d",
|
||||
policy->me.net->get_address(policy->me.net), policy->me.net_mask,
|
||||
proto_name,
|
||||
policy->other.net->get_address(policy->other.net), policy->other.net_mask);
|
||||
|
||||
if (inbound)
|
||||
{
|
||||
status = charon->kernel_interface->query_policy(charon->kernel_interface,
|
||||
this->other.addr, this->me.addr,
|
||||
policy->other.net, policy->me.net,
|
||||
policy->other.net_mask, policy->me.net_mask,
|
||||
XFRM_POLICY_IN, policy->upper_proto,
|
||||
&ut);
|
||||
|
||||
/* also check forward policy in tunnel mode */
|
||||
if (status == SUCCESS /*&& mode == TUNNEL XXX */)
|
||||
{
|
||||
time_t fwd;
|
||||
|
||||
status = charon->kernel_interface->query_policy(charon->kernel_interface,
|
||||
this->other.addr, this->me.addr,
|
||||
policy->other.net, policy->me.net,
|
||||
policy->other.net_mask, policy->me.net_mask,
|
||||
XFRM_POLICY_FWD, policy->upper_proto,
|
||||
&fwd);
|
||||
|
||||
if (status == SUCCESS)
|
||||
{
|
||||
ut = max(ut, fwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = charon->kernel_interface->query_policy(charon->kernel_interface,
|
||||
this->me.addr, this->other.addr,
|
||||
policy->me.net, policy->other.net,
|
||||
policy->me.net_mask, policy->other.net_mask,
|
||||
XFRM_POLICY_OUT, policy->upper_proto,
|
||||
&ut);
|
||||
}
|
||||
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
iterator->destroy(iterator);
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
*use_time = max(*use_time, ut);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the host adress/port of a SA
|
||||
*/
|
||||
@@ -772,6 +859,7 @@ child_sa_t * child_sa_create(u_int32_t rekey, host_t *me, host_t* other,
|
||||
this->public.add = (status_t(*)(child_sa_t*,proposal_t*,prf_plus_t*))add;
|
||||
this->public.update = (status_t(*)(child_sa_t*,proposal_t*,prf_plus_t*))update;
|
||||
this->public.add_policies = (status_t (*)(child_sa_t*, linked_list_t*,linked_list_t*))add_policies;
|
||||
this->public.get_use_time = (status_t (*)(child_sa_t*,bool,time_t*))get_use_time;
|
||||
this->public.set_rekeyed = (void (*)(child_sa_t*))set_rekeyed;
|
||||
this->public.log_status = (void (*)(child_sa_t*, logger_t*, char*))log_status;
|
||||
this->public.destroy = (void(*)(child_sa_t*))destroy;
|
||||
|
||||
@@ -157,6 +157,16 @@ struct child_sa_t {
|
||||
*/
|
||||
status_t (*add_policies) (child_sa_t *this, linked_list_t *my_ts_list, linked_list_t *other_ts_list);
|
||||
|
||||
/**
|
||||
* @brief Get the time of this child_sa_t's last use (i.e. last use of any of its policies)
|
||||
*
|
||||
* @param this calling object
|
||||
* @param inbound query for in- or outbound usage
|
||||
* @param use_time the time
|
||||
* @return SUCCESS or FAILED
|
||||
*/
|
||||
status_t (*get_use_time) (child_sa_t *this, bool inbound, time_t *use_time);
|
||||
|
||||
/**
|
||||
* @brief Mark this child_sa as rekeyed.
|
||||
*
|
||||
|
||||
+95
-20
@@ -67,6 +67,16 @@ struct private_ike_sa_t {
|
||||
*/
|
||||
protected_ike_sa_t protected;
|
||||
|
||||
/**
|
||||
* Update a timestamp on ike traffic
|
||||
*/
|
||||
void (*update_timestamp)(private_ike_sa_t *this, bool in);
|
||||
|
||||
/**
|
||||
* Returns the time since last traffic on kernel policies
|
||||
*/
|
||||
struct timeval (*get_last_esp_traffic_tv)(private_ike_sa_t * this, bool inbound);
|
||||
|
||||
/**
|
||||
* Identifier for the current IKE_SA.
|
||||
*/
|
||||
@@ -194,9 +204,14 @@ struct private_ike_sa_t {
|
||||
bool nat_there;
|
||||
|
||||
/**
|
||||
* Timestamp of last IKE message sent or received on this SA
|
||||
* Timestamp of last IKE message received on this SA
|
||||
*/
|
||||
struct timeval last_msg_tv;
|
||||
struct timeval last_msg_in_tv;
|
||||
|
||||
/**
|
||||
* Timestamp of last IKE message sent on this SA
|
||||
*/
|
||||
struct timeval last_msg_out_tv;
|
||||
|
||||
/*
|
||||
* Message ID of last DPD message
|
||||
@@ -330,7 +345,7 @@ static host_t* get_my_host(private_ike_sa_t *this)
|
||||
*/
|
||||
static host_t* get_other_host(private_ike_sa_t *this)
|
||||
{
|
||||
return this->connection->get_other_host(this->connection);;
|
||||
return this->connection->get_other_host(this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +353,7 @@ static host_t* get_other_host(private_ike_sa_t *this)
|
||||
*/
|
||||
static identification_t* get_my_id(private_ike_sa_t *this)
|
||||
{
|
||||
return this->policy->get_my_id(this->policy);;
|
||||
return this->policy->get_my_id(this->policy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,7 +361,7 @@ static identification_t* get_my_id(private_ike_sa_t *this)
|
||||
*/
|
||||
static identification_t* get_other_id(private_ike_sa_t *this)
|
||||
{
|
||||
return this->policy->get_other_id(this->policy);;
|
||||
return this->policy->get_other_id(this->policy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +390,7 @@ static status_t retransmit_request(private_ike_sa_t *this, u_int32_t message_id)
|
||||
this->logger->log(this->logger, CONTROL | LEVEL1, "Going to retransmit message with id %d",message_id);
|
||||
packet = this->last_requested_message->get_packet(this->last_requested_message);
|
||||
charon->send_queue->add(charon->send_queue, packet);
|
||||
|
||||
this->update_timestamp(this, FALSE);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -606,6 +621,20 @@ static signer_t *get_signer_responder(private_ike_sa_t *this)
|
||||
return this->signer_responder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of protected_ike_sa_t.update_timestamp
|
||||
*/
|
||||
static void update_timestamp(private_ike_sa_t *this, bool in)
|
||||
{
|
||||
/* bump last message sent timestamp */
|
||||
struct timeval *tv = in ? &this->last_msg_in_tv : &this->last_msg_out_tv;
|
||||
if (0 > gettimeofday(tv, NULL))
|
||||
{
|
||||
this->logger->log(this->logger, ERROR|LEVEL1,
|
||||
"Warning: Failed to get time of day.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of protected_ike_sa_t.send_request.
|
||||
*/
|
||||
@@ -678,11 +707,7 @@ static status_t send_request(private_ike_sa_t *this, message_t *message)
|
||||
this->message_id_out);
|
||||
this->message_id_out++;
|
||||
|
||||
/* bump last message sent timestamp */
|
||||
if (gettimeofday(&this->last_msg_tv, NULL) < 0)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR|LEVEL1, "failed to get time of day");
|
||||
}
|
||||
this->update_timestamp(this, FALSE);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -740,6 +765,8 @@ static status_t send_response(private_ike_sa_t *this, message_t *message)
|
||||
this->logger->log(this->logger, CONTROL|LEVEL3, "Increase message counter for incoming messages");
|
||||
this->message_id_in++;
|
||||
|
||||
this->update_timestamp(this, FALSE);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -780,6 +807,8 @@ static void send_notify(private_ike_sa_t *this, exchange_type_t exchange_type, n
|
||||
charon->send_queue->add(charon->send_queue, packet);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "Destroy message");
|
||||
response->destroy(response);
|
||||
|
||||
this->update_timestamp(this, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -842,6 +871,7 @@ static status_t process_message(private_ike_sa_t *this, message_t *message)
|
||||
packet_t *packet = this->last_responded_message->get_packet(this->last_responded_message);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "Resent request detected. Send stored reply.");
|
||||
charon->send_queue->add(charon->send_queue, packet);
|
||||
this->update_timestamp(this, FALSE);
|
||||
return SUCCESS;
|
||||
}
|
||||
else
|
||||
@@ -875,6 +905,8 @@ static status_t process_message(private_ike_sa_t *this, message_t *message)
|
||||
}
|
||||
}
|
||||
|
||||
this->update_timestamp(this, TRUE);
|
||||
|
||||
/* now the message is processed by the current state object.
|
||||
* The specific state object is responsible to check if a message can be received in
|
||||
* the state it represents.
|
||||
@@ -1412,14 +1444,50 @@ static void set_other_host_behind_nat (private_ike_sa_t *this, bool nat)
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ike_sa_t.get_last_msg_tv.
|
||||
* Implementation of private_ike_sa_t.get_last_esp_traffic_tv
|
||||
*/
|
||||
static struct timeval get_last_msg_tv (private_ike_sa_t *this)
|
||||
static struct timeval get_last_esp_traffic_tv(private_ike_sa_t * this, bool inbound)
|
||||
{
|
||||
/*
|
||||
* XXX: query kernel for last activity time
|
||||
*/
|
||||
return this->last_msg_tv;
|
||||
iterator_t *iterator;
|
||||
child_sa_t *child_sa;
|
||||
bool ret = TRUE;
|
||||
time_t use_time = 0;
|
||||
struct timeval tv = {0, 0};
|
||||
|
||||
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
||||
while (iterator->iterate(iterator, (void**)&child_sa))
|
||||
{
|
||||
if (child_sa->get_use_time(child_sa, inbound, &use_time) == SUCCESS
|
||||
&& use_time != 0)
|
||||
{
|
||||
tv.tv_sec = max(tv.tv_sec, use_time);
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
return tv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ike_sa_t.get_last_traffic_in_tv.
|
||||
*/
|
||||
static struct timeval get_last_traffic_in_tv (private_ike_sa_t *this)
|
||||
{
|
||||
struct timeval esp_tv = this->get_last_esp_traffic_tv(this, TRUE);
|
||||
return this->last_msg_in_tv.tv_sec > esp_tv.tv_sec ? this->last_msg_in_tv
|
||||
: this->last_msg_in_tv.tv_sec < esp_tv.tv_sec ? esp_tv
|
||||
: this->last_msg_in_tv.tv_usec > esp_tv.tv_usec ? this->last_msg_in_tv : esp_tv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ike_sa_t.get_last_traffic_out_tv.
|
||||
*/
|
||||
static struct timeval get_last_traffic_out_tv (private_ike_sa_t *this)
|
||||
{
|
||||
struct timeval esp_tv = this->get_last_esp_traffic_tv(this, FALSE);
|
||||
return this->last_msg_out_tv.tv_sec > esp_tv.tv_sec ? this->last_msg_out_tv
|
||||
: this->last_msg_out_tv.tv_sec < esp_tv.tv_sec ? esp_tv
|
||||
: this->last_msg_out_tv.tv_usec > esp_tv.tv_usec ? this->last_msg_out_tv : esp_tv;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1543,7 +1611,8 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
||||
this->protected.public.is_my_host_behind_nat = (bool(*)(ike_sa_t*)) is_my_host_behind_nat;
|
||||
this->protected.public.is_other_host_behind_nat = (bool(*)(ike_sa_t*)) is_other_host_behind_nat;
|
||||
this->protected.public.is_any_host_behind_nat = (bool(*)(ike_sa_t*)) is_any_host_behind_nat;
|
||||
this->protected.public.get_last_msg_tv = (struct timeval (*)(ike_sa_t*)) get_last_msg_tv;
|
||||
this->protected.public.get_last_traffic_in_tv = (struct timeval (*)(ike_sa_t*)) get_last_traffic_in_tv;
|
||||
this->protected.public.get_last_traffic_out_tv = (struct timeval (*)(ike_sa_t*)) get_last_traffic_out_tv;
|
||||
this->protected.public.send_dpd_request = (status_t (*)(ike_sa_t*)) send_dpd_request;
|
||||
|
||||
/* protected functions */
|
||||
@@ -1579,6 +1648,10 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
||||
this->protected.get_last_dpd_message_id = (u_int32_t (*) (protected_ike_sa_t*)) get_last_dpd_message_id;
|
||||
this->protected.update_connection_hosts = (status_t (*) (protected_ike_sa_t *, host_t*, host_t*)) update_connection_hosts;
|
||||
|
||||
/* private functions */
|
||||
this->update_timestamp = (void (*) (private_ike_sa_t*,bool))update_timestamp;
|
||||
this->get_last_esp_traffic_tv = (struct timeval (*) (private_ike_sa_t *,bool))get_last_esp_traffic_tv;
|
||||
|
||||
/* initialize private fields */
|
||||
this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
|
||||
|
||||
@@ -1604,8 +1677,10 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
||||
this->nat_hasher = hasher_create(HASH_SHA1);
|
||||
this->nat_here = FALSE;
|
||||
this->nat_there = FALSE;
|
||||
this->last_msg_tv.tv_sec = 0;
|
||||
this->last_msg_tv.tv_usec = 0;
|
||||
this->last_msg_in_tv.tv_sec = 0;
|
||||
this->last_msg_in_tv.tv_usec = 0;
|
||||
this->last_msg_out_tv.tv_sec = 0;
|
||||
this->last_msg_out_tv.tv_usec = 0;
|
||||
this->last_dpd_message_id = 0;
|
||||
|
||||
/* at creation time, IKE_SA is in a initiator state */
|
||||
|
||||
+12
-4
@@ -236,12 +236,20 @@ struct ike_sa_t {
|
||||
bool (*is_any_host_behind_nat) (ike_sa_t *this);
|
||||
|
||||
/**
|
||||
* @brief Query timeval of last message sent.
|
||||
* @brief Query timeval of last inbound IKE or ESP traffic.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return time when the last message was sent
|
||||
* @param this calling object
|
||||
* @return time when the last traffic was seen
|
||||
*/
|
||||
struct timeval (*get_last_msg_tv) (ike_sa_t *this);
|
||||
struct timeval (*get_last_traffic_in_tv) (ike_sa_t *this);
|
||||
|
||||
/**
|
||||
* @brief Query timeval of last outbound IKE or ESP traffic.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return time when the last traffic was seen
|
||||
*/
|
||||
struct timeval (*get_last_traffic_out_tv) (ike_sa_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get the state of type of associated state object.
|
||||
|
||||
@@ -554,14 +554,6 @@ static status_t process_message(private_ike_sa_established_t *this, message_t *m
|
||||
signer_t *signer;
|
||||
status_t status;
|
||||
|
||||
/* only requests are allowed, responses are handled in other state */
|
||||
if (!message->get_request(message))
|
||||
{
|
||||
this->logger->log(this->logger, ERROR|LEVEL1,
|
||||
"Response not handled in state ike_sa_established");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/* get signer for verification and crypter for decryption */
|
||||
ike_sa_id = this->ike_sa->public.get_id(&this->ike_sa->public);
|
||||
if (!ike_sa_id->is_initiator(ike_sa_id))
|
||||
@@ -590,6 +582,28 @@ static status_t process_message(private_ike_sa_established_t *this, message_t *m
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* process responses */
|
||||
if (!message->get_request(message))
|
||||
{
|
||||
switch (message->get_exchange_type(message))
|
||||
{
|
||||
case INFORMATIONAL:
|
||||
status = process_informational_response(this, message);
|
||||
break;
|
||||
default:
|
||||
this->logger->log(this->logger, ERROR | LEVEL1,
|
||||
"Only INFORMATIONAL responses are handled in state ike_sa_established");
|
||||
status = FAILED;
|
||||
break;
|
||||
}
|
||||
|
||||
/* we don't really reply to this message but the retransmit mechanism relies on this */
|
||||
this->ike_sa->set_last_replied_message_id(this->ike_sa, message->get_message_id(message));
|
||||
|
||||
/* return here */
|
||||
return status;
|
||||
}
|
||||
|
||||
/* prepare a reply of the same type */
|
||||
this->ike_sa->build_message(this->ike_sa, message->get_exchange_type(message), FALSE, &response);
|
||||
@@ -609,6 +623,7 @@ static status_t process_message(private_ike_sa_established_t *this, message_t *m
|
||||
mapping_find(exchange_type_m, message->get_exchange_type(message)));
|
||||
status = NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ struct private_initiator_init_t {
|
||||
* @param request message_t object to add the NONCE payload
|
||||
*/
|
||||
status_t (*build_nonce_payload) (private_initiator_init_t *this,message_t *request);
|
||||
|
||||
/**
|
||||
* Builds the NAT-T Notify(NAT_DETECTION_SOURCE_IP) and
|
||||
* Notify(NAT_DETECTION_DESTINATION_IP) payloads for this state.
|
||||
|
||||
@@ -388,6 +388,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
|
||||
response->destroy(response);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* build Notify(NAT-D) payloads */
|
||||
this->build_natd_payloads(this, response);
|
||||
|
||||
@@ -616,6 +617,7 @@ static status_t process_notify_payload(private_responder_init_t *this, notify_pa
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "process notify type %s",
|
||||
mapping_find(notify_message_type_m, notify_message_type));
|
||||
|
||||
switch (notify_message_type)
|
||||
{
|
||||
case NAT_DETECTION_DESTINATION_IP:
|
||||
|
||||
Reference in New Issue
Block a user