2005-11-08 13:33:28 +00:00
|
|
|
/*
|
2012-03-09 09:15:21 +00:00
|
|
|
* Copyright (C) 2006-2012 Tobias Brunner
|
2007-10-03 15:10:41 +00:00
|
|
|
* Copyright (C) 2006 Daniel Roethlisberger
|
2009-04-14 10:34:24 +00:00
|
|
|
* Copyright (C) 2005-2009 Martin Willi
|
2006-07-07 08:49:06 +00:00
|
|
|
* Copyright (C) 2005 Jan Hutter
|
2005-11-08 13:33:28 +00:00
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
2006-06-22 06:36:28 +00:00
|
|
|
|
2006-04-10 08:07:38 +00:00
|
|
|
#include <string.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sys/stat.h>
|
2007-04-12 08:52:36 +00:00
|
|
|
#include <errno.h>
|
2008-11-05 08:32:38 +00:00
|
|
|
#include <time.h>
|
2005-11-08 13:33:28 +00:00
|
|
|
|
2005-11-11 13:52:11 +00:00
|
|
|
#include "ike_sa.h"
|
|
|
|
|
2006-10-31 12:27:59 +00:00
|
|
|
#include <library.h>
|
2010-03-24 16:46:29 +00:00
|
|
|
#include <hydra.h>
|
2010-07-05 11:52:05 +00:00
|
|
|
#include <daemon.h>
|
2005-11-23 09:24:35 +00:00
|
|
|
#include <utils/linked_list.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <utils/lexparser.h>
|
2007-04-10 06:01:03 +00:00
|
|
|
#include <processing/jobs/retransmit_job.h>
|
|
|
|
#include <processing/jobs/delete_ike_sa_job.h>
|
|
|
|
#include <processing/jobs/send_dpd_job.h>
|
|
|
|
#include <processing/jobs/send_keepalive_job.h>
|
|
|
|
#include <processing/jobs/rekey_ike_sa_job.h>
|
2012-05-25 13:30:32 +00:00
|
|
|
#include <processing/jobs/retry_initiate_job.h>
|
2012-03-20 16:56:18 +00:00
|
|
|
#include <sa/ikev2/tasks/ike_auth_lifetime.h>
|
2005-11-08 13:33:28 +00:00
|
|
|
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2011-12-19 12:10:29 +00:00
|
|
|
#include <sa/ikev2/tasks/ike_me.h>
|
2007-12-04 10:48:27 +00:00
|
|
|
#include <processing/jobs/initiate_mediation_job.h>
|
2007-10-03 15:10:41 +00:00
|
|
|
#endif
|
2007-02-28 14:04:36 +00:00
|
|
|
|
2008-10-14 08:52:13 +00:00
|
|
|
ENUM(ike_sa_state_names, IKE_CREATED, IKE_DESTROYING,
|
2006-10-18 11:46:13 +00:00
|
|
|
"CREATED",
|
|
|
|
"CONNECTING",
|
|
|
|
"ESTABLISHED",
|
2008-11-28 10:49:14 +00:00
|
|
|
"PASSIVE",
|
2006-10-18 11:46:13 +00:00
|
|
|
"REKEYING",
|
|
|
|
"DELETING",
|
2008-10-14 08:52:13 +00:00
|
|
|
"DESTROYING",
|
2006-10-18 11:46:13 +00:00
|
|
|
);
|
2005-11-08 13:33:28 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
typedef struct private_ike_sa_t private_ike_sa_t;
|
2009-04-24 14:13:52 +00:00
|
|
|
typedef struct attribute_entry_t attribute_entry_t;
|
2005-11-25 13:42:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data of an ike_sa_t object.
|
|
|
|
*/
|
|
|
|
struct private_ike_sa_t {
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* Public members
|
2006-06-23 14:02:30 +00:00
|
|
|
*/
|
2006-07-05 10:53:20 +00:00
|
|
|
ike_sa_t public;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2005-12-03 16:52:54 +00:00
|
|
|
* Identifier for the current IKE_SA.
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
|
|
|
ike_sa_id_t *ike_sa_id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-11-17 15:26:52 +00:00
|
|
|
/**
|
|
|
|
* IKE version of this SA.
|
|
|
|
*/
|
|
|
|
ike_version_t version;
|
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* unique numerical ID for this IKE_SA.
|
|
|
|
*/
|
|
|
|
u_int32_t unique_id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Current state of the IKE_SA
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2009-04-24 14:13:52 +00:00
|
|
|
ike_sa_state_t state;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-12-01 17:16:10 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* IKE configuration used to set up this IKE_SA
|
2005-12-01 17:16:10 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
ike_cfg_t *ike_cfg;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* Peer and authentication information to establish IKE_SA.
|
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
peer_cfg_t *peer_cfg;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-13 14:14:44 +00:00
|
|
|
/**
|
2009-04-14 10:34:24 +00:00
|
|
|
* currently used authentication ruleset, local (as auth_cfg_t)
|
2008-03-13 14:14:44 +00:00
|
|
|
*/
|
2009-04-14 10:34:24 +00:00
|
|
|
auth_cfg_t *my_auth;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-12-01 10:35:30 +00:00
|
|
|
/**
|
|
|
|
* list of completed local authentication rounds
|
|
|
|
*/
|
|
|
|
linked_list_t *my_auths;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* list of completed remote authentication rounds
|
|
|
|
*/
|
|
|
|
linked_list_t *other_auths;
|
|
|
|
|
2008-03-13 14:14:44 +00:00
|
|
|
/**
|
2009-04-14 10:34:24 +00:00
|
|
|
* currently used authentication constraints, remote (as auth_cfg_t)
|
2008-03-13 14:14:44 +00:00
|
|
|
*/
|
2009-04-14 10:34:24 +00:00
|
|
|
auth_cfg_t *other_auth;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-30 12:58:54 +00:00
|
|
|
/**
|
|
|
|
* Selected IKE proposal
|
|
|
|
*/
|
|
|
|
proposal_t *proposal;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* Juggles tasks to process messages
|
|
|
|
*/
|
|
|
|
task_manager_t *task_manager;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
|
|
|
* Address of local host
|
|
|
|
*/
|
|
|
|
host_t *my_host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
|
|
|
* Address of remote host
|
|
|
|
*/
|
|
|
|
host_t *other_host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2008-04-09 18:12:22 +00:00
|
|
|
/**
|
|
|
|
* Are we mediation server
|
|
|
|
*/
|
|
|
|
bool is_mediation_server;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-10-03 15:10:41 +00:00
|
|
|
/**
|
|
|
|
* Server reflexive host
|
|
|
|
*/
|
|
|
|
host_t *server_reflexive_host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-01 11:38:18 +00:00
|
|
|
/**
|
|
|
|
* Connect ID
|
|
|
|
*/
|
|
|
|
chunk_t connect_id;
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
|
|
|
* Identification used for us
|
|
|
|
*/
|
|
|
|
identification_t *my_id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-12-01 17:16:10 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Identification used for other
|
2005-12-01 17:16:10 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
identification_t *other_id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-18 10:32:01 +00:00
|
|
|
/**
|
|
|
|
* set of extensions the peer supports
|
|
|
|
*/
|
|
|
|
ike_extension_t extensions;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-21 15:25:28 +00:00
|
|
|
/**
|
|
|
|
* set of condition flags currently enabled for this IKE_SA
|
|
|
|
*/
|
|
|
|
ike_condition_t conditions;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Linked List containing the child sa's of the current IKE_SA.
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
linked_list_t *child_sas;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-06-22 11:24:33 +00:00
|
|
|
/**
|
2008-10-28 16:07:06 +00:00
|
|
|
* keymat of this IKE_SA
|
2008-06-22 11:24:33 +00:00
|
|
|
*/
|
2008-10-28 16:07:06 +00:00
|
|
|
keymat_t *keymat;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
/**
|
2012-08-21 11:50:32 +00:00
|
|
|
* Virtual IPs on local host
|
2006-07-05 10:53:20 +00:00
|
|
|
*/
|
2012-08-21 11:50:32 +00:00
|
|
|
linked_list_t *my_vips;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
2012-08-21 11:50:32 +00:00
|
|
|
* Virtual IPs on remote host
|
2007-02-28 14:04:36 +00:00
|
|
|
*/
|
2012-08-21 11:50:32 +00:00
|
|
|
linked_list_t *other_vips;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-01-10 08:18:52 +00:00
|
|
|
/**
|
2009-04-24 14:13:52 +00:00
|
|
|
* List of configuration attributes (attribute_entry_t)
|
2007-01-10 08:18:52 +00:00
|
|
|
*/
|
2009-04-24 14:13:52 +00:00
|
|
|
linked_list_t *attributes;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-21 15:25:28 +00:00
|
|
|
/**
|
2012-03-09 09:15:21 +00:00
|
|
|
* list of peer's addresses, additional ones transmitted via MOBIKE
|
2007-06-21 15:25:28 +00:00
|
|
|
*/
|
2012-03-09 09:15:21 +00:00
|
|
|
linked_list_t *peer_addresses;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-06 13:37:04 +00:00
|
|
|
/**
|
|
|
|
* previously value of received DESTINATION_IP hash
|
|
|
|
*/
|
|
|
|
chunk_t nat_detection_dest;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-07-03 12:32:38 +00:00
|
|
|
/**
|
|
|
|
* number pending UPDATE_SA_ADDRESS (MOBIKE)
|
|
|
|
*/
|
|
|
|
u_int32_t pending_updates;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-09-03 18:49:06 +00:00
|
|
|
/**
|
|
|
|
* NAT keep alive interval
|
|
|
|
*/
|
|
|
|
u_int32_t keepalive_interval;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-05-25 13:30:32 +00:00
|
|
|
/**
|
|
|
|
* interval for retries during initiation (e.g. if DNS resolution failed),
|
|
|
|
* 0 to disable (default)
|
|
|
|
*/
|
|
|
|
u_int32_t retry_initiate_interval;
|
|
|
|
|
2012-05-25 14:09:31 +00:00
|
|
|
/**
|
|
|
|
* TRUE if a retry_initiate_job has been queued
|
|
|
|
*/
|
|
|
|
bool retry_initiate_queued;
|
|
|
|
|
2006-06-22 06:36:28 +00:00
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Timestamps for this IKE_SA
|
2006-06-22 06:36:28 +00:00
|
|
|
*/
|
2008-10-27 14:51:00 +00:00
|
|
|
u_int32_t stats[STAT_MAX];
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-20 08:16:16 +00:00
|
|
|
/**
|
|
|
|
* how many times we have retried so far (keyingtries)
|
|
|
|
*/
|
|
|
|
u_int32_t keyingtry;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/**
|
|
|
|
* local host address to be used for IKE, set via MIGRATE kernel message
|
|
|
|
*/
|
|
|
|
host_t *local_host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/**
|
|
|
|
* remote host address to be used for IKE, set via MIGRATE kernel message
|
|
|
|
*/
|
|
|
|
host_t *remote_host;
|
2011-12-15 10:01:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush auth configs once established?
|
|
|
|
*/
|
|
|
|
bool flush_auth_cfg;
|
2005-11-25 13:42:02 +00:00
|
|
|
};
|
|
|
|
|
2009-04-24 14:13:52 +00:00
|
|
|
/**
|
|
|
|
* Entry to maintain install configuration attributes during IKE_SA lifetime
|
|
|
|
*/
|
|
|
|
struct attribute_entry_t {
|
|
|
|
/** handler used to install this attribute */
|
|
|
|
attribute_handler_t *handler;
|
|
|
|
/** attribute type */
|
|
|
|
configuration_attribute_type_t type;
|
|
|
|
/** attribute data */
|
|
|
|
chunk_t data;
|
|
|
|
};
|
|
|
|
|
2005-11-21 10:59:45 +00:00
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* get the time of the latest traffic processed by the kernel
|
2005-11-21 10:59:45 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static time_t get_use_time(private_ike_sa_t* this, bool inbound)
|
2005-11-18 12:01:53 +00:00
|
|
|
{
|
2008-10-24 08:02:35 +00:00
|
|
|
enumerator_t *enumerator;
|
2006-07-05 10:53:20 +00:00
|
|
|
child_sa_t *child_sa;
|
2009-08-06 14:46:02 +00:00
|
|
|
time_t use_time, current;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
if (inbound)
|
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
use_time = this->stats[STAT_INBOUND];
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
use_time = this->stats[STAT_OUTBOUND];
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2008-10-24 08:02:35 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, &child_sa))
|
|
|
|
{
|
2009-08-06 14:46:02 +00:00
|
|
|
child_sa->get_usestats(child_sa, inbound, ¤t, NULL);
|
|
|
|
use_time = max(use_time, current);
|
2008-10-24 08:02:35 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-24 08:02:35 +00:00
|
|
|
return use_time;
|
2005-12-01 17:16:10 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_unique_id, u_int32_t,
|
|
|
|
private_ike_sa_t *this)
|
2005-11-25 13:42:02 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
return this->unique_id;
|
2005-11-25 13:42:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_name, char*,
|
|
|
|
private_ike_sa_t *this)
|
2005-12-02 19:26:01 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
if (this->peer_cfg)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->peer_cfg->get_name(this->peer_cfg);
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
return "(unnamed)";
|
2005-12-02 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_statistic, u_int32_t,
|
|
|
|
private_ike_sa_t *this, statistic_t kind)
|
2007-04-11 12:14:51 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
if (kind < STAT_MAX)
|
2007-04-11 12:14:51 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
return this->stats[kind];
|
2007-04-11 12:14:51 +00:00
|
|
|
}
|
2007-11-20 12:06:40 +00:00
|
|
|
return 0;
|
2007-04-11 12:14:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-25 13:48:57 +00:00
|
|
|
METHOD(ike_sa_t, set_statistic, void,
|
|
|
|
private_ike_sa_t *this, statistic_t kind, u_int32_t value)
|
|
|
|
{
|
|
|
|
if (kind < STAT_MAX)
|
|
|
|
{
|
|
|
|
this->stats[kind] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_my_host, host_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->my_host;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_my_host, void,
|
|
|
|
private_ike_sa_t *this, host_t *me)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
DESTROY_IF(this->my_host);
|
|
|
|
this->my_host = me;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_other_host, host_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-09-25 06:38:58 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->other_host;
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_other_host, void,
|
|
|
|
private_ike_sa_t *this, host_t *other)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
DESTROY_IF(this->other_host);
|
|
|
|
this->other_host = other;
|
2006-09-25 06:38:58 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_peer_cfg, peer_cfg_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->peer_cfg;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_peer_cfg, void,
|
|
|
|
private_ike_sa_t *this, peer_cfg_t *peer_cfg)
|
2006-07-27 12:18:40 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
peer_cfg->get_ref(peer_cfg);
|
2011-11-04 08:24:51 +00:00
|
|
|
DESTROY_IF(this->peer_cfg);
|
2007-04-10 06:01:03 +00:00
|
|
|
this->peer_cfg = peer_cfg;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
if (this->ike_cfg == NULL)
|
|
|
|
{
|
|
|
|
this->ike_cfg = peer_cfg->get_ike_cfg(peer_cfg);
|
|
|
|
this->ike_cfg->get_ref(this->ike_cfg);
|
|
|
|
}
|
2008-03-13 14:14:44 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_auth_cfg, auth_cfg_t*,
|
|
|
|
private_ike_sa_t *this, bool local)
|
2008-03-13 14:14:44 +00:00
|
|
|
{
|
2009-04-14 10:34:24 +00:00
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
return this->my_auth;
|
|
|
|
}
|
2008-03-13 14:14:44 +00:00
|
|
|
return this->other_auth;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, add_auth_cfg, void,
|
|
|
|
private_ike_sa_t *this, bool local, auth_cfg_t *cfg)
|
2009-12-01 10:35:30 +00:00
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
this->my_auths->insert_last(this->my_auths, cfg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->other_auths->insert_last(this->other_auths, cfg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, create_auth_cfg_enumerator, enumerator_t*,
|
|
|
|
private_ike_sa_t *this, bool local)
|
2009-12-01 10:35:30 +00:00
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
return this->my_auths->create_enumerator(this->my_auths);
|
|
|
|
}
|
|
|
|
return this->other_auths->create_enumerator(this->other_auths);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush the stored authentication round information
|
|
|
|
*/
|
|
|
|
static void flush_auth_cfgs(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
auth_cfg_t *cfg;
|
|
|
|
|
2011-12-15 10:01:06 +00:00
|
|
|
this->my_auth->purge(this->my_auth, FALSE);
|
|
|
|
this->other_auth->purge(this->other_auth, FALSE);
|
|
|
|
|
2010-06-07 12:59:39 +00:00
|
|
|
while (this->my_auths->remove_last(this->my_auths,
|
|
|
|
(void**)&cfg) == SUCCESS)
|
2009-12-01 10:35:30 +00:00
|
|
|
{
|
2010-06-07 12:59:39 +00:00
|
|
|
cfg->destroy(cfg);
|
|
|
|
}
|
|
|
|
while (this->other_auths->remove_last(this->other_auths,
|
|
|
|
(void**)&cfg) == SUCCESS)
|
|
|
|
{
|
|
|
|
cfg->destroy(cfg);
|
2009-12-01 10:35:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_proposal, proposal_t*,
|
|
|
|
private_ike_sa_t *this)
|
2008-10-30 12:58:54 +00:00
|
|
|
{
|
|
|
|
return this->proposal;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_proposal, void,
|
|
|
|
private_ike_sa_t *this, proposal_t *proposal)
|
2008-10-30 12:58:54 +00:00
|
|
|
{
|
|
|
|
DESTROY_IF(this->proposal);
|
|
|
|
this->proposal = proposal->clone(proposal);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_message_id, void,
|
|
|
|
private_ike_sa_t *this, bool initiate, u_int32_t mid)
|
2008-11-24 12:46:06 +00:00
|
|
|
{
|
|
|
|
if (initiate)
|
|
|
|
{
|
2008-11-24 13:59:30 +00:00
|
|
|
this->task_manager->reset(this->task_manager, mid, UINT_MAX);
|
2008-11-24 12:46:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-24 13:59:30 +00:00
|
|
|
this->task_manager->reset(this->task_manager, UINT_MAX, mid);
|
2008-11-24 12:46:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, send_keepalive, void,
|
|
|
|
private_ike_sa_t *this)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
send_keepalive_job_t *job;
|
|
|
|
time_t last_out, now, diff;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-09-03 19:00:08 +00:00
|
|
|
if (!(this->conditions & COND_NAT_HERE) || this->keepalive_interval == 0)
|
2007-07-02 12:55:07 +00:00
|
|
|
{ /* disable keep alives if we are not NATed anymore */
|
|
|
|
return;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
last_out = get_use_time(this, FALSE);
|
2009-08-31 15:59:00 +00:00
|
|
|
now = time_monotonic(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
diff = now - last_out;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-09-03 18:49:06 +00:00
|
|
|
if (diff >= this->keepalive_interval)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
packet_t *packet;
|
|
|
|
chunk_t data;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
packet = packet_create();
|
|
|
|
packet->set_source(packet, this->my_host->clone(this->my_host));
|
|
|
|
packet->set_destination(packet, this->other_host->clone(this->other_host));
|
|
|
|
data.ptr = malloc(1);
|
|
|
|
data.ptr[0] = 0xFF;
|
|
|
|
data.len = 1;
|
|
|
|
packet->set_data(packet, data);
|
2012-06-28 12:32:52 +00:00
|
|
|
DBG1(DBG_IKE, "sending keep alive to %#H", this->other_host);
|
2012-02-24 12:09:09 +00:00
|
|
|
charon->sender->send_no_marker(charon->sender, packet);
|
2007-06-26 13:04:13 +00:00
|
|
|
diff = 0;
|
|
|
|
}
|
|
|
|
job = send_keepalive_job_create(this->ike_sa_id);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, (job_t*)job,
|
|
|
|
this->keepalive_interval - diff);
|
2007-06-26 13:04:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_ike_cfg, ike_cfg_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->ike_cfg;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
2006-02-09 16:25:02 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_ike_cfg, void,
|
|
|
|
private_ike_sa_t *this, ike_cfg_t *ike_cfg)
|
2006-07-27 12:18:40 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
ike_cfg->get_ref(ike_cfg);
|
|
|
|
this->ike_cfg = ike_cfg;
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
2008-04-10 07:24:30 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, enable_extension, void,
|
|
|
|
private_ike_sa_t *this, ike_extension_t extension)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
this->extensions |= extension;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, supports_extension, bool,
|
|
|
|
private_ike_sa_t *this, ike_extension_t extension)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
return (this->extensions & extension) != FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, has_condition, bool,
|
|
|
|
private_ike_sa_t *this, ike_condition_t condition)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
return (this->conditions & condition) != FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_condition, void,
|
|
|
|
private_ike_sa_t *this, ike_condition_t condition, bool enable)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
if (has_condition(this, condition) != enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
2007-06-27 13:10:55 +00:00
|
|
|
this->conditions |= condition;
|
2007-06-26 13:04:13 +00:00
|
|
|
switch (condition)
|
|
|
|
{
|
|
|
|
case COND_NAT_HERE:
|
|
|
|
DBG1(DBG_IKE, "local host is behind NAT, sending keep alives");
|
|
|
|
this->conditions |= COND_NAT_ANY;
|
|
|
|
send_keepalive(this);
|
|
|
|
break;
|
|
|
|
case COND_NAT_THERE:
|
|
|
|
DBG1(DBG_IKE, "remote host is behind NAT");
|
|
|
|
this->conditions |= COND_NAT_ANY;
|
|
|
|
break;
|
2007-10-01 12:19:39 +00:00
|
|
|
case COND_NAT_FAKE:
|
2007-10-01 16:41:34 +00:00
|
|
|
DBG1(DBG_IKE, "faking NAT situation to enforce UDP encapsulation");
|
2007-10-01 12:19:39 +00:00
|
|
|
this->conditions |= COND_NAT_ANY;
|
|
|
|
break;
|
2007-06-26 13:04:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-27 13:10:55 +00:00
|
|
|
this->conditions &= ~condition;
|
2007-06-26 13:04:13 +00:00
|
|
|
switch (condition)
|
|
|
|
{
|
2007-06-27 13:10:55 +00:00
|
|
|
case COND_NAT_HERE:
|
2007-10-01 12:19:39 +00:00
|
|
|
case COND_NAT_FAKE:
|
2007-06-27 13:10:55 +00:00
|
|
|
case COND_NAT_THERE:
|
|
|
|
set_condition(this, COND_NAT_ANY,
|
|
|
|
has_condition(this, COND_NAT_HERE) ||
|
2007-10-01 12:19:39 +00:00
|
|
|
has_condition(this, COND_NAT_THERE) ||
|
|
|
|
has_condition(this, COND_NAT_FAKE));
|
2007-06-27 13:10:55 +00:00
|
|
|
break;
|
2007-06-26 13:04:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-27 12:18:40 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, send_dpd, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2009-04-21 15:16:56 +00:00
|
|
|
job_t *job;
|
2007-03-20 08:16:16 +00:00
|
|
|
time_t diff, delay;
|
2012-09-07 16:05:22 +00:00
|
|
|
bool task_queued = FALSE;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2008-04-11 08:14:48 +00:00
|
|
|
delay = this->peer_cfg->get_dpd(this->peer_cfg);
|
2007-03-20 08:16:16 +00:00
|
|
|
if (this->task_manager->busy(this->task_manager))
|
|
|
|
{
|
|
|
|
/* an exchange is in the air, no need to start a DPD check */
|
|
|
|
diff = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* check if there was any inbound traffic */
|
|
|
|
time_t last_in, now;
|
|
|
|
last_in = get_use_time(this, TRUE);
|
2009-08-31 15:59:00 +00:00
|
|
|
now = time_monotonic(NULL);
|
2007-03-20 08:16:16 +00:00
|
|
|
diff = now - last_in;
|
2010-10-29 13:36:19 +00:00
|
|
|
if (!delay || diff >= delay)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2012-09-07 16:05:22 +00:00
|
|
|
/* too long ago, initiate dead peer detection */
|
2007-03-20 08:16:16 +00:00
|
|
|
DBG1(DBG_IKE, "sending DPD request");
|
2011-12-19 12:49:09 +00:00
|
|
|
this->task_manager->queue_dpd(this->task_manager);
|
2012-09-07 16:05:22 +00:00
|
|
|
task_queued = TRUE;
|
2011-12-19 12:49:09 +00:00
|
|
|
diff = 0;
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* recheck in "interval" seconds */
|
2010-10-29 13:36:19 +00:00
|
|
|
if (delay)
|
|
|
|
{
|
|
|
|
job = (job_t*)send_dpd_job_create(this->ike_sa_id);
|
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job, delay - diff);
|
|
|
|
}
|
2012-09-07 16:05:22 +00:00
|
|
|
if (task_queued)
|
|
|
|
{
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_state, ike_sa_state_t,
|
|
|
|
private_ike_sa_t *this)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_state, void,
|
|
|
|
private_ike_sa_t *this, ike_sa_state_t state)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2012-02-02 09:33:40 +00:00
|
|
|
bool trigger_dpd = FALSE;
|
|
|
|
|
2008-07-28 14:01:45 +00:00
|
|
|
DBG2(DBG_IKE, "IKE_SA %s[%d] state change: %N => %N",
|
2008-07-22 17:10:10 +00:00
|
|
|
get_name(this), this->unique_id,
|
2007-03-20 08:16:16 +00:00
|
|
|
ike_sa_state_names, this->state,
|
|
|
|
ike_sa_state_names, state);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-20 16:13:21 +00:00
|
|
|
switch (state)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2007-03-20 16:13:21 +00:00
|
|
|
case IKE_ESTABLISHED:
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2008-11-28 16:19:19 +00:00
|
|
|
if (this->state == IKE_CONNECTING ||
|
|
|
|
this->state == IKE_PASSIVE)
|
2007-03-20 16:13:21 +00:00
|
|
|
{
|
|
|
|
job_t *job;
|
2007-11-20 12:06:40 +00:00
|
|
|
u_int32_t t;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-11-20 12:06:40 +00:00
|
|
|
/* calculate rekey, reauth and lifetime */
|
2009-08-31 15:59:00 +00:00
|
|
|
this->stats[STAT_ESTABLISHED] = time_monotonic(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-11-20 12:06:40 +00:00
|
|
|
/* schedule rekeying if we have a time which is smaller than
|
|
|
|
* an already scheduled rekeying */
|
2011-11-24 10:38:37 +00:00
|
|
|
t = this->peer_cfg->get_rekey_time(this->peer_cfg, TRUE);
|
2009-09-02 15:26:36 +00:00
|
|
|
if (t && (this->stats[STAT_REKEY] == 0 ||
|
2008-10-27 14:51:00 +00:00
|
|
|
(this->stats[STAT_REKEY] > t + this->stats[STAT_ESTABLISHED])))
|
2007-03-20 16:13:21 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_REKEY] = t + this->stats[STAT_ESTABLISHED];
|
2007-11-20 12:06:40 +00:00
|
|
|
job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, FALSE);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job, t);
|
2007-11-20 12:06:40 +00:00
|
|
|
DBG1(DBG_IKE, "scheduling rekeying in %ds", t);
|
2007-03-20 16:13:21 +00:00
|
|
|
}
|
2011-11-24 10:38:37 +00:00
|
|
|
t = this->peer_cfg->get_reauth_time(this->peer_cfg, TRUE);
|
2009-09-02 15:26:36 +00:00
|
|
|
if (t && (this->stats[STAT_REAUTH] == 0 ||
|
2008-10-27 14:51:00 +00:00
|
|
|
(this->stats[STAT_REAUTH] > t + this->stats[STAT_ESTABLISHED])))
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_REAUTH] = t + this->stats[STAT_ESTABLISHED];
|
2007-11-20 12:06:40 +00:00
|
|
|
job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job, t);
|
2007-11-20 12:06:40 +00:00
|
|
|
DBG1(DBG_IKE, "scheduling reauthentication in %ds", t);
|
|
|
|
}
|
|
|
|
t = this->peer_cfg->get_over_time(this->peer_cfg);
|
2008-10-27 14:51:00 +00:00
|
|
|
if (this->stats[STAT_REKEY] || this->stats[STAT_REAUTH])
|
2007-03-20 16:13:21 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
if (this->stats[STAT_REAUTH] == 0)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] = this->stats[STAT_REKEY];
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2008-10-27 14:51:00 +00:00
|
|
|
else if (this->stats[STAT_REKEY] == 0)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] = this->stats[STAT_REAUTH];
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] = min(this->stats[STAT_REKEY],
|
|
|
|
this->stats[STAT_REAUTH]);
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] += t;
|
|
|
|
t = this->stats[STAT_DELETE] - this->stats[STAT_ESTABLISHED];
|
2007-03-20 16:13:21 +00:00
|
|
|
job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job, t);
|
2007-11-20 12:06:40 +00:00
|
|
|
DBG1(DBG_IKE, "maximum IKE_SA lifetime %ds", t);
|
2007-03-20 16:13:21 +00:00
|
|
|
}
|
2012-02-02 09:33:40 +00:00
|
|
|
trigger_dpd = this->peer_cfg->get_dpd(this->peer_cfg);
|
2007-03-20 16:13:21 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
2007-03-20 16:13:21 +00:00
|
|
|
default:
|
|
|
|
break;
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
2008-10-14 08:52:13 +00:00
|
|
|
charon->bus->ike_state_change(charon->bus, &this->public, state);
|
2007-03-20 08:16:16 +00:00
|
|
|
this->state = state;
|
2012-02-02 09:33:40 +00:00
|
|
|
|
|
|
|
if (trigger_dpd)
|
|
|
|
{
|
2012-02-02 09:33:40 +00:00
|
|
|
if (supports_extension(this, EXT_DPD))
|
|
|
|
{
|
|
|
|
send_dpd(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "DPD not supported by peer, disabled");
|
|
|
|
}
|
2012-02-02 09:33:40 +00:00
|
|
|
}
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, reset, void,
|
|
|
|
private_ike_sa_t *this)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
|
|
|
/* the responder ID is reset, as peer may choose another one */
|
|
|
|
if (this->ike_sa_id->is_initiator(this->ike_sa_id))
|
|
|
|
{
|
|
|
|
this->ike_sa_id->set_responder_spi(this->ike_sa_id, 0);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-20 08:16:16 +00:00
|
|
|
set_state(this, IKE_CREATED);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-06-07 12:59:39 +00:00
|
|
|
flush_auth_cfgs(this);
|
|
|
|
|
|
|
|
this->keymat->destroy(this->keymat);
|
2011-11-17 15:45:14 +00:00
|
|
|
this->keymat = keymat_create(this->version,
|
|
|
|
this->ike_sa_id->is_initiator(this->ike_sa_id));
|
2010-06-07 12:59:39 +00:00
|
|
|
|
2008-11-24 12:46:06 +00:00
|
|
|
this->task_manager->reset(this->task_manager, 0, 0);
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_keymat, keymat_t*,
|
|
|
|
private_ike_sa_t *this)
|
2008-10-28 16:07:06 +00:00
|
|
|
{
|
|
|
|
return this->keymat;
|
|
|
|
}
|
|
|
|
|
2012-08-21 11:50:32 +00:00
|
|
|
METHOD(ike_sa_t, add_virtual_ip, void,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this, bool local, host_t *ip)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
2007-09-24 12:15:25 +00:00
|
|
|
DBG1(DBG_IKE, "installing new virtual IP %H", ip);
|
2010-07-12 09:14:54 +00:00
|
|
|
if (hydra->kernel_interface->add_ip(hydra->kernel_interface, ip,
|
|
|
|
this->my_host) == SUCCESS)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
2012-08-21 11:50:32 +00:00
|
|
|
this->my_vips->insert_last(this->my_vips, ip->clone(ip));
|
2007-06-28 15:24:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "installing virtual IP %H failed", ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-21 11:50:32 +00:00
|
|
|
this->other_vips->insert_last(this->other_vips, ip->clone(ip));
|
2007-06-28 15:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 11:16:31 +00:00
|
|
|
|
|
|
|
METHOD(ike_sa_t, clear_virtual_ips, void,
|
|
|
|
private_ike_sa_t *this, bool local)
|
|
|
|
{
|
|
|
|
linked_list_t *vips = local ? this->my_vips : this->other_vips;
|
|
|
|
host_t *vip;
|
|
|
|
|
|
|
|
while (vips->remove_first(vips, (void**)&vip) == SUCCESS)
|
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
hydra->kernel_interface->del_ip(hydra->kernel_interface, vip);
|
|
|
|
}
|
|
|
|
vip->destroy(vip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-21 11:50:32 +00:00
|
|
|
METHOD(ike_sa_t, create_virtual_ip_enumerator, enumerator_t*,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this, bool local)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
2012-08-21 11:50:32 +00:00
|
|
|
return this->my_vips->create_enumerator(this->my_vips);
|
2007-06-28 15:24:24 +00:00
|
|
|
}
|
2012-08-21 11:50:32 +00:00
|
|
|
return this->other_vips->create_enumerator(this->other_vips);
|
2007-06-28 15:24:24 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 09:15:21 +00:00
|
|
|
METHOD(ike_sa_t, add_peer_address, void,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this, host_t *host)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
2012-03-09 09:15:21 +00:00
|
|
|
this->peer_addresses->insert_last(this->peer_addresses, host);
|
2007-06-28 15:24:24 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-03-09 09:15:21 +00:00
|
|
|
METHOD(ike_sa_t, create_peer_address_enumerator, enumerator_t*,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
2012-05-08 14:48:51 +00:00
|
|
|
if (this->peer_addresses->get_count(this->peer_addresses))
|
|
|
|
{
|
|
|
|
return this->peer_addresses->create_enumerator(this->peer_addresses);
|
|
|
|
}
|
|
|
|
/* in case we don't have MOBIKE */
|
|
|
|
return enumerator_create_single(this->other_host, NULL);
|
2011-05-19 16:05:53 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 09:15:21 +00:00
|
|
|
METHOD(ike_sa_t, clear_peer_addresses, void,
|
2011-05-19 16:05:53 +00:00
|
|
|
private_ike_sa_t *this)
|
|
|
|
{
|
2012-05-08 14:48:51 +00:00
|
|
|
enumerator_t *enumerator;
|
2011-05-19 16:05:53 +00:00
|
|
|
host_t *host;
|
2012-03-09 09:15:21 +00:00
|
|
|
|
2012-05-08 14:48:51 +00:00
|
|
|
enumerator = this->peer_addresses->create_enumerator(this->peer_addresses);
|
2011-05-19 16:05:53 +00:00
|
|
|
while (enumerator->enumerate(enumerator, (void**)&host))
|
|
|
|
{
|
2012-03-09 09:15:21 +00:00
|
|
|
this->peer_addresses->remove_at(this->peer_addresses,
|
|
|
|
enumerator);
|
2011-05-19 16:05:53 +00:00
|
|
|
host->destroy(host);
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2007-06-28 15:24:24 +00:00
|
|
|
}
|
2008-10-06 13:37:04 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, has_mapping_changed, bool,
|
|
|
|
private_ike_sa_t *this, chunk_t hash)
|
2008-10-06 13:37:04 +00:00
|
|
|
{
|
|
|
|
if (this->nat_detection_dest.ptr == NULL)
|
|
|
|
{
|
|
|
|
this->nat_detection_dest = chunk_clone(hash);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (chunk_equals(hash, this->nat_detection_dest))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
free(this->nat_detection_dest.ptr);
|
|
|
|
this->nat_detection_dest = chunk_clone(hash);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_pending_updates, void,
|
|
|
|
private_ike_sa_t *this, u_int32_t updates)
|
2007-07-03 12:32:38 +00:00
|
|
|
{
|
|
|
|
this->pending_updates = updates;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_pending_updates, u_int32_t,
|
|
|
|
private_ike_sa_t *this)
|
2007-07-03 12:32:38 +00:00
|
|
|
{
|
|
|
|
return this->pending_updates;
|
|
|
|
}
|
2007-06-28 15:24:24 +00:00
|
|
|
|
2010-08-30 10:19:37 +00:00
|
|
|
METHOD(ike_sa_t, float_ports, void,
|
|
|
|
private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
/* do not switch if we have a custom port from MOBIKE/NAT */
|
2012-04-20 08:59:14 +00:00
|
|
|
if (this->my_host->get_port(this->my_host) ==
|
|
|
|
charon->socket->get_port(charon->socket, FALSE))
|
2010-08-30 10:19:37 +00:00
|
|
|
{
|
2012-04-20 08:59:14 +00:00
|
|
|
this->my_host->set_port(this->my_host,
|
|
|
|
charon->socket->get_port(charon->socket, TRUE));
|
2010-08-30 10:19:37 +00:00
|
|
|
}
|
|
|
|
if (this->other_host->get_port(this->other_host) == IKEV2_UDP_PORT)
|
|
|
|
{
|
|
|
|
this->other_host->set_port(this->other_host, IKEV2_NATT_PORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, update_hosts, void,
|
2011-01-12 12:54:46 +00:00
|
|
|
private_ike_sa_t *this, host_t *me, host_t *other, bool force)
|
2005-12-02 19:26:01 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
bool update = FALSE;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
if (me == NULL)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
me = this->my_host;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
2007-06-26 13:04:13 +00:00
|
|
|
if (other == NULL)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
other = this->other_host;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
/* apply hosts on first received message */
|
|
|
|
if (this->my_host->is_anyaddr(this->my_host) ||
|
|
|
|
this->other_host->is_anyaddr(this->other_host))
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
set_my_host(this, me->clone(me));
|
|
|
|
set_other_host(this, other->clone(other));
|
|
|
|
update = TRUE;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
/* update our address in any case */
|
|
|
|
if (!me->equals(me, this->my_host))
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
set_my_host(this, me->clone(me));
|
|
|
|
update = TRUE;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
if (!other->equals(other, this->other_host))
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2011-07-20 13:57:53 +00:00
|
|
|
/* update others address if we are NOT NATed */
|
2011-01-12 12:54:46 +00:00
|
|
|
if (force || !has_condition(this, COND_NAT_HERE))
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
set_other_host(this, other->clone(other));
|
|
|
|
update = TRUE;
|
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
/* update all associated CHILD_SAs, if required */
|
|
|
|
if (update)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator_t *enumerator;
|
2007-06-26 13:04:13 +00:00
|
|
|
child_sa_t *child_sa;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)&child_sa))
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
if (child_sa->update(child_sa, this->my_host,
|
2012-08-21 11:50:32 +00:00
|
|
|
this->other_host, this->my_vips,
|
2008-11-11 09:22:00 +00:00
|
|
|
has_condition(this, COND_NAT_ANY)) == NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
this->public.rekey_child_sa(&this->public,
|
|
|
|
child_sa->get_protocol(child_sa),
|
|
|
|
child_sa->get_spi(child_sa, TRUE));
|
|
|
|
}
|
2007-06-26 13:04:13 +00:00
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, generate_message, status_t,
|
|
|
|
private_ike_sa_t *this, message_t *message, packet_t **packet)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2012-01-19 15:22:25 +00:00
|
|
|
status_t status;
|
|
|
|
|
2010-11-24 17:09:06 +00:00
|
|
|
if (message->is_encoded(message))
|
|
|
|
{ /* already done */
|
|
|
|
*packet = message->get_packet(message);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-08-31 15:59:00 +00:00
|
|
|
this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
|
2007-02-28 14:04:36 +00:00
|
|
|
message->set_ike_sa_id(message, this->ike_sa_id);
|
2012-01-19 15:22:25 +00:00
|
|
|
charon->bus->message(charon->bus, message, FALSE, TRUE);
|
|
|
|
status = message->generate(message, this->keymat, packet);
|
|
|
|
if (status == SUCCESS)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2012-01-19 15:22:25 +00:00
|
|
|
charon->bus->message(charon->bus, message, FALSE, FALSE);
|
2005-11-28 15:20:51 +00:00
|
|
|
}
|
2012-01-19 15:22:25 +00:00
|
|
|
return status;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_kmaddress, void,
|
|
|
|
private_ike_sa_t *this, host_t *local, host_t *remote)
|
2008-11-11 06:37:37 +00:00
|
|
|
{
|
|
|
|
DESTROY_IF(this->local_host);
|
|
|
|
DESTROY_IF(this->remote_host);
|
|
|
|
this->local_host = local->clone(local);
|
|
|
|
this->remote_host = remote->clone(remote);
|
|
|
|
}
|
|
|
|
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, act_as_mediation_server, void,
|
|
|
|
private_ike_sa_t *this)
|
2008-04-09 18:12:22 +00:00
|
|
|
{
|
|
|
|
charon->mediation_manager->update_sa_id(charon->mediation_manager,
|
|
|
|
this->other_id, this->ike_sa_id);
|
|
|
|
this->is_mediation_server = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_server_reflexive_host, host_t*,
|
|
|
|
private_ike_sa_t *this)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
|
|
|
return this->server_reflexive_host;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_server_reflexive_host, void,
|
|
|
|
private_ike_sa_t *this, host_t *host)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
|
|
|
DESTROY_IF(this->server_reflexive_host);
|
|
|
|
this->server_reflexive_host = host;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_connect_id, chunk_t,
|
|
|
|
private_ike_sa_t *this)
|
2008-04-01 11:38:18 +00:00
|
|
|
{
|
|
|
|
return this->connect_id;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, respond, status_t,
|
|
|
|
private_ike_sa_t *this, identification_t *peer_id, chunk_t connect_id)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-03-26 18:40:19 +00:00
|
|
|
ike_me_t *task = ike_me_create(&this->public, TRUE);
|
|
|
|
task->respond(task, peer_id, connect_id);
|
2007-10-03 15:10:41 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, callback, status_t,
|
|
|
|
private_ike_sa_t *this, identification_t *peer_id)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-03-26 18:40:19 +00:00
|
|
|
ike_me_t *task = ike_me_create(&this->public, TRUE);
|
2007-10-03 15:10:41 +00:00
|
|
|
task->callback(task, peer_id);
|
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, relay, status_t,
|
|
|
|
private_ike_sa_t *this, identification_t *requester, chunk_t connect_id,
|
|
|
|
chunk_t connect_key, linked_list_t *endpoints, bool response)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-03-26 18:40:19 +00:00
|
|
|
ike_me_t *task = ike_me_create(&this->public, TRUE);
|
|
|
|
task->relay(task, requester, connect_id, connect_key, endpoints, response);
|
2007-10-03 15:10:41 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, initiate_mediation, status_t,
|
|
|
|
private_ike_sa_t *this, peer_cfg_t *mediated_cfg)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-03-26 18:40:19 +00:00
|
|
|
ike_me_t *task = ike_me_create(&this->public, TRUE);
|
2007-10-03 15:10:41 +00:00
|
|
|
task->connect(task, mediated_cfg->get_peer_id(mediated_cfg));
|
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, initiate_mediated, status_t,
|
|
|
|
private_ike_sa_t *this, host_t *me, host_t *other, chunk_t connect_id)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-04-03 15:13:25 +00:00
|
|
|
set_my_host(this, me->clone(me));
|
|
|
|
set_other_host(this, other->clone(other));
|
2008-04-10 12:51:04 +00:00
|
|
|
chunk_free(&this->connect_id);
|
2008-04-01 11:38:18 +00:00
|
|
|
this->connect_id = chunk_clone(connect_id);
|
2007-10-03 15:10:41 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2007-10-03 15:10:41 +00:00
|
|
|
|
2008-06-06 15:05:54 +00:00
|
|
|
/**
|
|
|
|
* Resolve DNS host in configuration
|
|
|
|
*/
|
|
|
|
static void resolve_hosts(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
host_t *host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (this->remote_host)
|
|
|
|
{
|
|
|
|
host = this->remote_host->clone(this->remote_host);
|
|
|
|
host->set_port(host, IKEV2_UDP_PORT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-08 11:01:08 +00:00
|
|
|
char *other_addr;
|
|
|
|
u_int16_t other_port;
|
|
|
|
|
|
|
|
other_addr = this->ike_cfg->get_other_addr(this->ike_cfg, NULL);
|
|
|
|
other_port = this->ike_cfg->get_other_port(this->ike_cfg);
|
|
|
|
host = host_create_from_dns(other_addr, 0, other_port);
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
2008-06-06 15:05:54 +00:00
|
|
|
if (host)
|
|
|
|
{
|
2008-07-09 14:16:19 +00:00
|
|
|
set_other_host(this, host);
|
2008-06-06 15:05:54 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (this->local_host)
|
2008-07-09 14:16:19 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
host = this->local_host->clone(this->local_host);
|
2012-04-20 08:59:14 +00:00
|
|
|
host->set_port(host, charon->socket->get_port(charon->socket, FALSE));
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-08 11:01:08 +00:00
|
|
|
char *my_addr;
|
|
|
|
u_int16_t my_port;
|
2009-09-21 13:19:39 +00:00
|
|
|
int family = 0;
|
|
|
|
|
|
|
|
/* use same address family as for other */
|
|
|
|
if (!this->other_host->is_anyaddr(this->other_host))
|
|
|
|
{
|
|
|
|
family = this->other_host->get_family(this->other_host);
|
|
|
|
}
|
2012-06-08 11:01:08 +00:00
|
|
|
my_addr = this->ike_cfg->get_my_addr(this->ike_cfg, NULL);
|
|
|
|
my_port = this->ike_cfg->get_my_port(this->ike_cfg);
|
|
|
|
host = host_create_from_dns(my_addr, family, my_port);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (host && host->is_anyaddr(host) &&
|
|
|
|
!this->other_host->is_anyaddr(this->other_host))
|
2008-07-17 11:06:31 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
host->destroy(host);
|
2010-07-12 09:14:54 +00:00
|
|
|
host = hydra->kernel_interface->get_source_addr(
|
|
|
|
hydra->kernel_interface, this->other_host, NULL);
|
2008-11-11 06:37:37 +00:00
|
|
|
if (host)
|
|
|
|
{
|
2010-02-22 17:34:11 +00:00
|
|
|
host->set_port(host, this->ike_cfg->get_my_port(this->ike_cfg));
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
2009-03-16 14:23:36 +00:00
|
|
|
else
|
|
|
|
{ /* fallback to address family specific %any(6), if configured */
|
2012-06-08 11:01:08 +00:00
|
|
|
host = host_create_from_dns(my_addr, 0, my_port);
|
2009-03-16 14:23:36 +00:00
|
|
|
}
|
2008-07-17 11:06:31 +00:00
|
|
|
}
|
2008-07-09 14:16:19 +00:00
|
|
|
}
|
2008-06-06 15:05:54 +00:00
|
|
|
if (host)
|
|
|
|
{
|
2008-07-09 14:16:19 +00:00
|
|
|
set_my_host(this, host);
|
2008-06-06 15:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, initiate, status_t,
|
|
|
|
private_ike_sa_t *this, child_cfg_t *child_cfg, u_int32_t reqid,
|
|
|
|
traffic_selector_t *tsi, traffic_selector_t *tsr)
|
2005-11-25 13:42:02 +00:00
|
|
|
{
|
2012-05-25 13:30:32 +00:00
|
|
|
bool defer_initiate = FALSE;
|
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
if (this->state == IKE_CREATED)
|
2006-07-20 14:57:49 +00:00
|
|
|
{
|
2012-01-20 12:54:39 +00:00
|
|
|
if (this->my_host->is_anyaddr(this->my_host) ||
|
|
|
|
this->other_host->is_anyaddr(this->other_host))
|
|
|
|
{
|
|
|
|
resolve_hosts(this);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-10-03 15:10:41 +00:00
|
|
|
if (this->other_host->is_anyaddr(this->other_host)
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2007-10-03 15:10:41 +00:00
|
|
|
&& !this->peer_cfg->get_mediated_by(this->peer_cfg)
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2007-10-03 15:10:41 +00:00
|
|
|
)
|
2007-03-21 07:00:04 +00:00
|
|
|
{
|
2012-06-08 11:01:08 +00:00
|
|
|
char *addr = this->ike_cfg->get_other_addr(this->ike_cfg, NULL);
|
2012-05-25 13:30:32 +00:00
|
|
|
bool is_anyaddr = streq(addr, "%any") || streq(addr, "%any6");
|
|
|
|
|
|
|
|
if (is_anyaddr || !this->retry_initiate_interval)
|
|
|
|
{
|
|
|
|
if (is_anyaddr)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "unable to initiate to %s", addr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "unable to resolve %s, initiate aborted",
|
|
|
|
addr);
|
|
|
|
}
|
|
|
|
DESTROY_IF(child_cfg);
|
|
|
|
charon->bus->alert(charon->bus, ALERT_PEER_ADDR_FAILED);
|
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
|
|
|
DBG1(DBG_IKE, "unable to resolve %s, retrying in %ds",
|
|
|
|
addr, this->retry_initiate_interval);
|
|
|
|
defer_initiate = TRUE;
|
2007-03-21 07:00:04 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-12 16:07:17 +00:00
|
|
|
set_condition(this, COND_ORIGINAL_INITIATOR, TRUE);
|
2011-12-19 13:15:02 +00:00
|
|
|
this->task_manager->queue_ike(this->task_manager);
|
2007-10-03 15:10:41 +00:00
|
|
|
}
|
|
|
|
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2008-04-10 12:51:04 +00:00
|
|
|
if (this->peer_cfg->is_mediation(this->peer_cfg))
|
2008-11-11 13:12:05 +00:00
|
|
|
{
|
|
|
|
if (this->state == IKE_ESTABLISHED)
|
|
|
|
{
|
2009-09-02 15:26:36 +00:00
|
|
|
/* mediation connection is already established, retrigger state
|
|
|
|
* change to notify bus listeners */
|
2008-11-11 13:12:05 +00:00
|
|
|
DBG1(DBG_IKE, "mediation connection is already up");
|
|
|
|
set_state(this, IKE_ESTABLISHED);
|
|
|
|
}
|
2008-04-02 18:21:03 +00:00
|
|
|
DESTROY_IF(child_cfg);
|
2007-10-03 15:10:41 +00:00
|
|
|
}
|
|
|
|
else
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2012-01-03 10:58:40 +00:00
|
|
|
if (child_cfg)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2007-12-04 10:48:27 +00:00
|
|
|
/* normal IKE_SA with CHILD_SA */
|
2011-12-19 13:15:21 +00:00
|
|
|
this->task_manager->queue_child(this->task_manager, child_cfg, reqid,
|
|
|
|
tsi, tsr);
|
2008-04-10 12:51:04 +00:00
|
|
|
#ifdef ME
|
|
|
|
if (this->peer_cfg->get_mediated_by(this->peer_cfg))
|
|
|
|
{
|
|
|
|
/* mediated connection, initiate mediation process */
|
|
|
|
job_t *job = (job_t*)initiate_mediation_job_create(this->ike_sa_id);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->processor->queue_job(lib->processor, job);
|
2008-04-10 12:51:04 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
#endif /* ME */
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-05-25 13:30:32 +00:00
|
|
|
if (defer_initiate)
|
|
|
|
{
|
2012-05-25 14:09:31 +00:00
|
|
|
if (!this->retry_initiate_queued)
|
|
|
|
{
|
|
|
|
job_t *job = (job_t*)retry_initiate_job_create(this->ike_sa_id);
|
|
|
|
lib->scheduler->schedule_job(lib->scheduler, (job_t*)job,
|
|
|
|
this->retry_initiate_interval);
|
|
|
|
this->retry_initiate_queued = TRUE;
|
|
|
|
}
|
2012-05-25 13:30:32 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2012-05-25 14:09:31 +00:00
|
|
|
this->retry_initiate_queued = FALSE;
|
2007-02-28 14:04:36 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2005-11-25 13:42:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 14:09:31 +00:00
|
|
|
METHOD(ike_sa_t, retry_initiate, status_t,
|
|
|
|
private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
if (this->retry_initiate_queued)
|
|
|
|
{
|
|
|
|
this->retry_initiate_queued = FALSE;
|
|
|
|
return initiate(this, NULL, 0, NULL, NULL);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, process_message, status_t,
|
|
|
|
private_ike_sa_t *this, message_t *message)
|
2007-08-27 09:10:12 +00:00
|
|
|
{
|
|
|
|
status_t status;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-28 10:49:14 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{ /* do not handle messages in passive state */
|
|
|
|
return FAILED;
|
|
|
|
}
|
2012-08-02 10:50:31 +00:00
|
|
|
switch (message->get_exchange_type(message))
|
|
|
|
{
|
|
|
|
case ID_PROT:
|
|
|
|
case AGGRESSIVE:
|
|
|
|
case IKE_SA_INIT:
|
|
|
|
case IKE_AUTH:
|
|
|
|
if (this->state != IKE_CREATED &&
|
|
|
|
this->state != IKE_CONNECTING)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "ignoring %N in established IKE_SA state",
|
|
|
|
exchange_type_names, message->get_exchange_type(message));
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-12-20 15:23:12 +00:00
|
|
|
if (message->get_major_version(message) != this->version)
|
2007-08-27 09:10:12 +00:00
|
|
|
{
|
2011-12-20 15:23:12 +00:00
|
|
|
DBG1(DBG_IKE, "ignoring %N IKEv%u exchange on %N SA",
|
2007-08-27 09:10:12 +00:00
|
|
|
exchange_type_names, message->get_exchange_type(message),
|
2011-12-20 15:23:12 +00:00
|
|
|
message->get_major_version(message),
|
|
|
|
ike_version_names, this->version);
|
|
|
|
/* TODO-IKEv1: fall back to IKEv1 if we receive an IKEv1
|
|
|
|
* INVALID_MAJOR_VERSION on an IKEv2 SA. */
|
|
|
|
return FAILED;
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
2011-11-25 14:53:23 +00:00
|
|
|
status = this->task_manager->process_message(this->task_manager, message);
|
2011-12-15 10:01:06 +00:00
|
|
|
if (this->flush_auth_cfg && this->state == IKE_ESTABLISHED)
|
2007-08-27 09:10:12 +00:00
|
|
|
{
|
2011-12-15 10:01:06 +00:00
|
|
|
/* authentication completed */
|
|
|
|
this->flush_auth_cfg = FALSE;
|
2011-11-25 14:53:23 +00:00
|
|
|
flush_auth_cfgs(this);
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
2009-12-01 10:35:30 +00:00
|
|
|
return status;
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
2006-07-20 10:09:32 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_id, ike_sa_id_t*,
|
|
|
|
private_ike_sa_t *this)
|
2005-12-02 14:07:36 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
return this->ike_sa_id;
|
2005-12-02 14:07:36 +00:00
|
|
|
}
|
|
|
|
|
2011-11-17 15:26:52 +00:00
|
|
|
METHOD(ike_sa_t, get_version, ike_version_t,
|
|
|
|
private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->version;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_my_id, identification_t*,
|
|
|
|
private_ike_sa_t *this)
|
2005-12-02 19:26:01 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
return this->my_id;
|
2005-12-03 14:47:58 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_my_id, void,
|
|
|
|
private_ike_sa_t *this, identification_t *me)
|
2005-12-03 14:47:58 +00:00
|
|
|
{
|
2006-07-20 14:57:49 +00:00
|
|
|
DESTROY_IF(this->my_id);
|
2006-07-20 10:09:32 +00:00
|
|
|
this->my_id = me;
|
2005-12-02 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_other_id, identification_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-02-16 09:55:07 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
return this->other_id;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2006-07-20 10:09:32 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_other_eap_id, identification_t*,
|
|
|
|
private_ike_sa_t *this)
|
2010-03-24 13:23:56 +00:00
|
|
|
{
|
|
|
|
identification_t *id = NULL, *current;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
auth_cfg_t *cfg;
|
|
|
|
|
|
|
|
enumerator = this->other_auths->create_enumerator(this->other_auths);
|
|
|
|
while (enumerator->enumerate(enumerator, &cfg))
|
|
|
|
{
|
|
|
|
/* prefer EAP-Identity of last round */
|
|
|
|
current = cfg->get(cfg, AUTH_RULE_EAP_IDENTITY);
|
|
|
|
if (!current || current->get_type(current) == ID_ANY)
|
2012-01-04 16:32:41 +00:00
|
|
|
{
|
|
|
|
current = cfg->get(cfg, AUTH_RULE_XAUTH_IDENTITY);
|
|
|
|
}
|
|
|
|
if (!current || current->get_type(current) == ID_ANY)
|
2010-03-24 13:23:56 +00:00
|
|
|
{
|
|
|
|
current = cfg->get(cfg, AUTH_RULE_IDENTITY);
|
|
|
|
}
|
|
|
|
if (current && current->get_type(current) != ID_ANY)
|
|
|
|
{
|
|
|
|
id = current;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
return this->other_id;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_other_id, void,
|
|
|
|
private_ike_sa_t *this, identification_t *other)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2006-07-20 14:57:49 +00:00
|
|
|
DESTROY_IF(this->other_id);
|
2006-07-20 10:09:32 +00:00
|
|
|
this->other_id = other;
|
2006-02-16 09:55:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, add_child_sa, void,
|
|
|
|
private_ike_sa_t *this, child_sa_t *child_sa)
|
2006-05-31 14:23:15 +00:00
|
|
|
{
|
2006-07-05 10:53:20 +00:00
|
|
|
this->child_sas->insert_last(this->child_sas, child_sa);
|
2006-05-31 14:23:15 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_child_sa, child_sa_t*,
|
|
|
|
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi, bool inbound)
|
2006-06-09 15:12:43 +00:00
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator_t *enumerator;
|
2006-06-09 15:12:43 +00:00
|
|
|
child_sa_t *current, *found = NULL;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)¤t))
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2006-07-07 07:04:07 +00:00
|
|
|
if (current->get_spi(current, inbound) == spi &&
|
2006-10-24 14:20:45 +00:00
|
|
|
current->get_protocol(current) == protocol)
|
2006-06-09 15:12:43 +00:00
|
|
|
{
|
|
|
|
found = current;
|
|
|
|
}
|
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2006-06-09 15:12:43 +00:00
|
|
|
return found;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2011-05-19 15:27:32 +00:00
|
|
|
METHOD(ike_sa_t, get_child_count, int,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this)
|
2006-08-23 07:30:43 +00:00
|
|
|
{
|
2011-05-19 15:27:32 +00:00
|
|
|
return this->child_sas->get_count(this->child_sas);
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(ike_sa_t, create_child_sa_enumerator, enumerator_t*,
|
|
|
|
private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(ike_sa_t, remove_child_sa, void,
|
|
|
|
private_ike_sa_t *this, enumerator_t *enumerator)
|
|
|
|
{
|
|
|
|
this->child_sas->remove_at(this->child_sas, enumerator);
|
2006-08-23 07:30:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, rekey_child_sa, status_t,
|
|
|
|
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2011-12-19 13:20:33 +00:00
|
|
|
this->task_manager->queue_child_rekey(this->task_manager, protocol, spi);
|
2008-12-01 18:38:28 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-07-07 07:04:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, delete_child_sa, status_t,
|
2012-01-02 14:40:31 +00:00
|
|
|
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi, bool expired)
|
2006-07-07 07:04:07 +00:00
|
|
|
{
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2012-01-02 14:40:31 +00:00
|
|
|
this->task_manager->queue_child_delete(this->task_manager,
|
|
|
|
protocol, spi, expired);
|
2008-12-01 18:38:28 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-07-07 07:04:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, destroy_child_sa, status_t,
|
|
|
|
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
|
2006-07-07 07:04:07 +00:00
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator_t *enumerator;
|
2006-07-07 07:04:07 +00:00
|
|
|
child_sa_t *child_sa;
|
|
|
|
status_t status = NOT_FOUND;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)&child_sa))
|
2006-07-07 07:04:07 +00:00
|
|
|
{
|
|
|
|
if (child_sa->get_protocol(child_sa) == protocol &&
|
|
|
|
child_sa->get_spi(child_sa, TRUE) == spi)
|
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
this->child_sas->remove_at(this->child_sas, enumerator);
|
2006-07-07 07:04:07 +00:00
|
|
|
child_sa->destroy(child_sa);
|
|
|
|
status = SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2006-07-07 07:04:07 +00:00
|
|
|
return status;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, delete_, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2006-12-19 07:30:07 +00:00
|
|
|
{
|
|
|
|
switch (this->state)
|
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
case IKE_REKEYING:
|
2012-01-04 16:50:19 +00:00
|
|
|
if (this->version == IKEV1)
|
|
|
|
{ /* SA has been reauthenticated, delete */
|
2012-01-16 15:47:18 +00:00
|
|
|
charon->bus->ike_updown(charon->bus, &this->public, FALSE);
|
2012-01-04 16:50:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALL */
|
|
|
|
case IKE_ESTABLISHED:
|
2011-12-19 13:29:57 +00:00
|
|
|
this->task_manager->queue_ike_delete(this->task_manager);
|
2007-02-28 14:04:36 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2007-08-27 09:10:12 +00:00
|
|
|
case IKE_CREATED:
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "deleting unestablished IKE_SA");
|
2007-08-27 09:10:12 +00:00
|
|
|
break;
|
2008-11-28 10:49:14 +00:00
|
|
|
case IKE_PASSIVE:
|
|
|
|
break;
|
2006-12-19 07:30:07 +00:00
|
|
|
default:
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "destroying IKE_SA in state %N "
|
2007-08-27 09:10:12 +00:00
|
|
|
"without notification", ike_sa_state_names, this->state);
|
2010-04-06 09:58:29 +00:00
|
|
|
charon->bus->ike_updown(charon->bus, &this->public, FALSE);
|
2007-02-28 14:04:36 +00:00
|
|
|
break;
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
return DESTROY_ME;
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, rekey, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2006-07-27 12:18:40 +00:00
|
|
|
{
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2011-12-19 13:35:14 +00:00
|
|
|
this->task_manager->queue_ike_rekey(this->task_manager);
|
2007-02-28 14:04:36 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, reauth, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2006-12-19 07:30:07 +00:00
|
|
|
{
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2007-11-20 12:06:40 +00:00
|
|
|
/* we can't reauthenticate as responder when we use EAP or virtual IPs.
|
|
|
|
* If the peer does not support RFC4478, there is no way to keep the
|
|
|
|
* IKE_SA up. */
|
2008-11-12 16:07:17 +00:00
|
|
|
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "initiator did not reauthenticate as requested");
|
2012-08-21 11:50:32 +00:00
|
|
|
if (this->other_vips->get_count(this->other_vips) != 0 ||
|
2012-01-03 10:28:45 +00:00
|
|
|
has_condition(this, COND_XAUTH_AUTHENTICATED) ||
|
2008-04-10 08:42:27 +00:00
|
|
|
has_condition(this, COND_EAP_AUTHENTICATED)
|
|
|
|
#ifdef ME
|
2009-09-02 15:26:36 +00:00
|
|
|
/* as mediation server we too cannot reauth the IKE_SA */
|
2008-04-10 08:42:27 +00:00
|
|
|
|| this->is_mediation_server
|
|
|
|
#endif /* ME */
|
|
|
|
)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2012-02-21 13:05:11 +00:00
|
|
|
time_t del, now;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-02-21 13:05:11 +00:00
|
|
|
del = this->stats[STAT_DELETE];
|
|
|
|
now = time_monotonic(NULL);
|
2012-02-22 15:16:15 +00:00
|
|
|
DBG1(DBG_IKE, "IKE_SA %s[%d] will timeout in %V",
|
|
|
|
get_name(this), this->unique_id, &now, &del);
|
2007-11-20 12:06:40 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-22 15:16:15 +00:00
|
|
|
DBG0(DBG_IKE, "reauthenticating IKE_SA %s[%d] actively",
|
|
|
|
get_name(this), this->unique_id);
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-22 15:16:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG0(DBG_IKE, "reauthenticating IKE_SA %s[%d]",
|
|
|
|
get_name(this), this->unique_id);
|
|
|
|
}
|
2012-09-06 09:23:11 +00:00
|
|
|
set_condition(this, COND_REAUTHENTICATING, TRUE);
|
2011-12-19 13:39:05 +00:00
|
|
|
this->task_manager->queue_ike_reauth(this->task_manager);
|
2007-06-14 08:13:05 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
2007-07-02 09:49:22 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, reestablish, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
|
|
|
ike_sa_t *new;
|
|
|
|
host_t *host;
|
2008-04-14 08:17:18 +00:00
|
|
|
action_t action;
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator_t *enumerator;
|
2008-04-11 08:14:48 +00:00
|
|
|
child_sa_t *child_sa;
|
|
|
|
child_cfg_t *child_cfg;
|
2009-09-24 12:14:30 +00:00
|
|
|
bool restart = FALSE;
|
2008-04-11 08:14:48 +00:00
|
|
|
status_t status = FAILED;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-09-06 09:23:11 +00:00
|
|
|
if (has_condition(this, COND_REAUTHENTICATING))
|
2012-05-09 13:14:34 +00:00
|
|
|
{ /* only reauthenticate if we have children */
|
|
|
|
if (this->child_sas->get_count(this->child_sas) == 0
|
|
|
|
#ifdef ME
|
|
|
|
/* allow reauth of mediation connections without CHILD_SAs */
|
|
|
|
&& !this->peer_cfg->is_mediation(this->peer_cfg)
|
|
|
|
#endif /* ME */
|
|
|
|
)
|
2008-04-14 08:17:18 +00:00
|
|
|
{
|
2012-05-09 13:14:34 +00:00
|
|
|
DBG1(DBG_IKE, "unable to reauthenticate IKE_SA, no CHILD_SA "
|
|
|
|
"to recreate");
|
2008-04-14 08:17:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-09 13:14:34 +00:00
|
|
|
restart = TRUE;
|
2008-04-14 08:17:18 +00:00
|
|
|
}
|
2012-05-09 13:14:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* check if we have children to keep up at all */
|
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)&child_sa))
|
2008-04-14 07:55:23 +00:00
|
|
|
{
|
2012-05-09 13:14:34 +00:00
|
|
|
if (this->state == IKE_DELETING)
|
|
|
|
{
|
|
|
|
action = child_sa->get_close_action(child_sa);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
action = child_sa->get_dpd_action(child_sa);
|
|
|
|
}
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case ACTION_RESTART:
|
|
|
|
restart = TRUE;
|
|
|
|
break;
|
|
|
|
case ACTION_ROUTE:
|
|
|
|
charon->traps->install(charon->traps, this->peer_cfg,
|
|
|
|
child_sa->get_config(child_sa));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-04-14 07:55:23 +00:00
|
|
|
}
|
2012-05-09 13:14:34 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2008-04-14 07:55:23 +00:00
|
|
|
#ifdef ME
|
2012-05-09 13:14:34 +00:00
|
|
|
/* mediation connections have no children, keep them up anyway */
|
|
|
|
if (this->peer_cfg->is_mediation(this->peer_cfg))
|
|
|
|
{
|
|
|
|
restart = TRUE;
|
|
|
|
}
|
2008-04-14 07:55:23 +00:00
|
|
|
#endif /* ME */
|
2012-05-09 13:14:34 +00:00
|
|
|
}
|
2009-09-24 12:14:30 +00:00
|
|
|
if (!restart)
|
2008-04-14 07:55:23 +00:00
|
|
|
{
|
|
|
|
return FAILED;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-14 07:55:23 +00:00
|
|
|
/* check if we are able to reestablish this IKE_SA */
|
2008-11-12 16:07:17 +00:00
|
|
|
if (!has_condition(this, COND_ORIGINAL_INITIATOR) &&
|
2012-08-21 11:50:32 +00:00
|
|
|
(this->other_vips->get_count(this->other_vips) != 0 ||
|
2008-04-11 08:14:48 +00:00
|
|
|
has_condition(this, COND_EAP_AUTHENTICATED)
|
|
|
|
#ifdef ME
|
|
|
|
|| this->is_mediation_server
|
|
|
|
#endif /* ME */
|
|
|
|
))
|
|
|
|
{
|
2011-04-28 10:50:30 +00:00
|
|
|
DBG1(DBG_IKE, "unable to reestablish IKE_SA due to asymmetric setup");
|
2008-04-11 08:14:48 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-11-17 15:26:52 +00:00
|
|
|
new = charon->ike_sa_manager->checkout_new(charon->ike_sa_manager,
|
|
|
|
this->version, TRUE);
|
2011-12-21 11:05:34 +00:00
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
return FAILED;
|
|
|
|
}
|
2008-04-11 08:14:48 +00:00
|
|
|
new->set_peer_cfg(new, this->peer_cfg);
|
|
|
|
host = this->other_host;
|
|
|
|
new->set_other_host(new, host->clone(host));
|
|
|
|
host = this->my_host;
|
|
|
|
new->set_my_host(new, host->clone(host));
|
|
|
|
/* if we already have a virtual IP, we reuse it */
|
2012-08-21 11:50:32 +00:00
|
|
|
enumerator = this->my_vips->create_enumerator(this->my_vips);
|
|
|
|
while (enumerator->enumerate(enumerator, &host))
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2012-08-21 11:50:32 +00:00
|
|
|
new->add_virtual_ip(new, TRUE, host);
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2012-08-21 11:50:32 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-11 08:14:48 +00:00
|
|
|
#ifdef ME
|
|
|
|
if (this->peer_cfg->is_mediation(this->peer_cfg))
|
|
|
|
{
|
2009-05-20 09:44:43 +00:00
|
|
|
status = new->initiate(new, NULL, 0, NULL, NULL);
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2008-04-14 07:55:23 +00:00
|
|
|
else
|
2008-04-11 08:14:48 +00:00
|
|
|
#endif /* ME */
|
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)&child_sa))
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2012-09-06 09:23:11 +00:00
|
|
|
if (has_condition(this, COND_REAUTHENTICATING))
|
2008-04-14 08:17:18 +00:00
|
|
|
{
|
2012-05-09 13:14:34 +00:00
|
|
|
switch (child_sa->get_state(child_sa))
|
|
|
|
{
|
|
|
|
case CHILD_ROUTED:
|
|
|
|
{ /* move routed child directly */
|
|
|
|
this->child_sas->remove_at(this->child_sas, enumerator);
|
|
|
|
new->add_child_sa(new, child_sa);
|
|
|
|
action = ACTION_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{ /* initiate/queue all other CHILD_SAs */
|
|
|
|
action = ACTION_RESTART;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-14 08:17:18 +00:00
|
|
|
}
|
|
|
|
else
|
2012-05-09 13:14:34 +00:00
|
|
|
{ /* only restart CHILD_SAs that are configured accordingly */
|
|
|
|
if (this->state == IKE_DELETING)
|
|
|
|
{
|
|
|
|
action = child_sa->get_close_action(child_sa);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
action = child_sa->get_dpd_action(child_sa);
|
|
|
|
}
|
2008-04-14 08:17:18 +00:00
|
|
|
}
|
|
|
|
switch (action)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2008-04-14 07:55:23 +00:00
|
|
|
case ACTION_RESTART:
|
2010-06-02 09:41:46 +00:00
|
|
|
child_cfg = child_sa->get_config(child_sa);
|
2008-07-22 17:10:10 +00:00
|
|
|
DBG1(DBG_IKE, "restarting CHILD_SA %s",
|
2008-04-14 07:55:23 +00:00
|
|
|
child_cfg->get_name(child_cfg));
|
|
|
|
child_cfg->get_ref(child_cfg);
|
2009-05-20 09:44:43 +00:00
|
|
|
status = new->initiate(new, child_cfg, 0, NULL, NULL);
|
2008-04-11 08:14:48 +00:00
|
|
|
break;
|
2008-04-14 07:55:23 +00:00
|
|
|
default:
|
|
|
|
continue;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2008-04-14 07:55:23 +00:00
|
|
|
if (status == DESTROY_ME)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2008-04-14 07:55:23 +00:00
|
|
|
break;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-14 07:55:23 +00:00
|
|
|
if (status == DESTROY_ME)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2008-04-14 07:55:23 +00:00
|
|
|
charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, new);
|
2009-06-02 13:26:29 +00:00
|
|
|
status = FAILED;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-05 09:34:50 +00:00
|
|
|
charon->bus->ike_reestablish(charon->bus, &this->public, new);
|
2008-04-14 07:55:23 +00:00
|
|
|
charon->ike_sa_manager->checkin(charon->ike_sa_manager, new);
|
2009-06-02 13:26:29 +00:00
|
|
|
status = SUCCESS;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2009-06-02 13:26:29 +00:00
|
|
|
charon->bus->set_sa(charon->bus, &this->public);
|
|
|
|
return status;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, retransmit, status_t,
|
|
|
|
private_ike_sa_t *this, u_int32_t message_id)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2009-08-31 15:59:00 +00:00
|
|
|
this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
|
2008-04-11 08:14:48 +00:00
|
|
|
if (this->task_manager->retransmit(this->task_manager, message_id) != SUCCESS)
|
|
|
|
{
|
|
|
|
/* send a proper signal to brief interested bus listeners */
|
|
|
|
switch (this->state)
|
|
|
|
{
|
|
|
|
case IKE_CONNECTING:
|
|
|
|
{
|
2011-12-20 17:02:01 +00:00
|
|
|
/* retry IKE_SA_INIT/Main Mode if we have multiple keyingtries */
|
2008-04-11 08:14:48 +00:00
|
|
|
u_int32_t tries = this->peer_cfg->get_keyingtries(this->peer_cfg);
|
|
|
|
this->keyingtry++;
|
|
|
|
if (tries == 0 || tries > this->keyingtry)
|
|
|
|
{
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "peer not responding, trying again (%d/%d)",
|
|
|
|
this->keyingtry + 1, tries);
|
2008-04-11 08:14:48 +00:00
|
|
|
reset(this);
|
2012-02-14 10:29:34 +00:00
|
|
|
resolve_hosts(this);
|
2011-12-19 13:46:56 +00:00
|
|
|
this->task_manager->queue_ike(this->task_manager);
|
2008-04-11 08:14:48 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "establishing IKE_SA failed, peer not responding");
|
2008-04-11 08:14:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IKE_DELETING:
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "proper IKE_SA delete failed, peer not responding");
|
2012-09-06 09:23:11 +00:00
|
|
|
if (has_condition(this, COND_REAUTHENTICATING))
|
2012-05-09 13:15:43 +00:00
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "delete during reauthentication failed, "
|
|
|
|
"trying to reestablish IKE_SA anyway");
|
|
|
|
reestablish(this);
|
|
|
|
}
|
2008-04-11 08:14:48 +00:00
|
|
|
break;
|
2008-04-14 08:17:18 +00:00
|
|
|
case IKE_REKEYING:
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "rekeying IKE_SA failed, peer not responding");
|
2008-04-14 08:17:18 +00:00
|
|
|
/* FALL */
|
2008-04-11 08:14:48 +00:00
|
|
|
default:
|
2008-04-14 08:17:18 +00:00
|
|
|
reestablish(this);
|
2008-04-11 08:14:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-09-05 14:03:20 +00:00
|
|
|
if (this->state != IKE_CONNECTING)
|
|
|
|
{
|
|
|
|
charon->bus->ike_updown(charon->bus, &this->public, FALSE);
|
|
|
|
}
|
2008-04-11 08:14:48 +00:00
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-02-22 15:07:31 +00:00
|
|
|
METHOD(ike_sa_t, set_auth_lifetime, status_t,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this, u_int32_t lifetime)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2012-02-21 13:05:57 +00:00
|
|
|
u_int32_t diff, hard, soft, now;
|
2012-02-22 15:07:31 +00:00
|
|
|
ike_auth_lifetime_t *task;
|
|
|
|
bool send_update;
|
2007-11-20 12:06:40 +00:00
|
|
|
|
2012-02-21 13:05:57 +00:00
|
|
|
diff = this->peer_cfg->get_over_time(this->peer_cfg);
|
|
|
|
now = time_monotonic(NULL);
|
|
|
|
hard = now + lifetime;
|
|
|
|
soft = hard - diff;
|
|
|
|
|
2012-02-22 15:07:31 +00:00
|
|
|
/* check if we have to send an AUTH_LIFETIME to enforce the new lifetime.
|
|
|
|
* We send the notify in IKE_AUTH if not yet ESTABLISHED. */
|
2012-03-20 16:56:18 +00:00
|
|
|
send_update = this->state == IKE_ESTABLISHED && this->version == IKEV2 &&
|
2012-02-22 15:07:31 +00:00
|
|
|
!has_condition(this, COND_ORIGINAL_INITIATOR) &&
|
2012-08-21 11:50:32 +00:00
|
|
|
(this->other_vips->get_count(this->other_vips) != 0 ||
|
2012-02-22 15:07:31 +00:00
|
|
|
has_condition(this, COND_EAP_AUTHENTICATED));
|
|
|
|
|
2012-02-21 13:05:57 +00:00
|
|
|
if (lifetime < diff)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2012-02-21 13:05:57 +00:00
|
|
|
this->stats[STAT_REAUTH] = now;
|
2012-02-22 15:07:31 +00:00
|
|
|
|
|
|
|
if (!send_update)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, "
|
|
|
|
"starting reauthentication", lifetime);
|
|
|
|
lib->processor->queue_job(lib->processor,
|
2009-09-04 12:58:05 +00:00
|
|
|
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE));
|
2012-02-22 15:07:31 +00:00
|
|
|
}
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2008-10-27 14:51:00 +00:00
|
|
|
else if (this->stats[STAT_REAUTH] == 0 ||
|
2012-02-21 13:05:57 +00:00
|
|
|
this->stats[STAT_REAUTH] > soft)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2012-02-21 13:05:57 +00:00
|
|
|
this->stats[STAT_REAUTH] = soft;
|
2012-02-22 15:07:31 +00:00
|
|
|
if (!send_update)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, scheduling "
|
|
|
|
"reauthentication in %ds", lifetime, lifetime - diff);
|
|
|
|
lib->scheduler->schedule_job(lib->scheduler,
|
2009-04-21 15:16:56 +00:00
|
|
|
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE),
|
2012-02-21 13:05:57 +00:00
|
|
|
lifetime - diff);
|
2012-02-22 15:07:31 +00:00
|
|
|
}
|
2008-07-28 13:53:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-31 15:59:00 +00:00
|
|
|
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, "
|
|
|
|
"reauthentication already scheduled in %ds", lifetime,
|
|
|
|
this->stats[STAT_REAUTH] - time_monotonic(NULL));
|
2012-02-22 15:07:31 +00:00
|
|
|
send_update = FALSE;
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2012-02-21 13:05:57 +00:00
|
|
|
/* give at least some seconds to reauthenticate */
|
|
|
|
this->stats[STAT_DELETE] = max(hard, now + 10);
|
2012-02-22 15:07:31 +00:00
|
|
|
|
|
|
|
if (send_update)
|
|
|
|
{
|
|
|
|
task = ike_auth_lifetime_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, &task->task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
|
|
|
|
2010-10-05 15:49:50 +00:00
|
|
|
/**
|
|
|
|
* Check if the current combination of source and destination address is still
|
|
|
|
* valid.
|
|
|
|
*/
|
|
|
|
static bool is_current_path_valid(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
bool valid = FALSE;
|
|
|
|
host_t *src;
|
|
|
|
src = hydra->kernel_interface->get_source_addr(hydra->kernel_interface,
|
|
|
|
this->other_host, this->my_host);
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
if (src->ip_equals(src, this->my_host))
|
|
|
|
{
|
|
|
|
valid = TRUE;
|
|
|
|
}
|
|
|
|
src->destroy(src);
|
|
|
|
}
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we have any path avialable for this IKE SA.
|
|
|
|
*/
|
|
|
|
static bool is_any_path_valid(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
bool valid = FALSE;
|
|
|
|
enumerator_t *enumerator;
|
2012-04-06 08:53:47 +00:00
|
|
|
host_t *src = NULL, *addr;
|
2012-03-09 09:22:21 +00:00
|
|
|
|
2010-10-05 15:49:50 +00:00
|
|
|
DBG1(DBG_IKE, "old path is not available anymore, try to find another");
|
2012-05-08 14:48:51 +00:00
|
|
|
enumerator = create_peer_address_enumerator(this);
|
2012-03-09 09:22:21 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &addr))
|
2010-10-05 15:49:50 +00:00
|
|
|
{
|
2012-03-09 09:22:21 +00:00
|
|
|
DBG1(DBG_IKE, "looking for a route to %H ...", addr);
|
|
|
|
src = hydra->kernel_interface->get_source_addr(
|
|
|
|
hydra->kernel_interface, addr, NULL);
|
|
|
|
if (src)
|
2010-10-05 15:49:50 +00:00
|
|
|
{
|
2012-03-09 09:22:21 +00:00
|
|
|
break;
|
2010-10-05 15:49:50 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 09:22:21 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2010-10-05 15:49:50 +00:00
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
valid = TRUE;
|
|
|
|
src->destroy(src);
|
|
|
|
}
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, roam, status_t,
|
|
|
|
private_ike_sa_t *this, bool address)
|
2007-06-21 15:25:28 +00:00
|
|
|
{
|
2008-06-04 14:31:06 +00:00
|
|
|
switch (this->state)
|
|
|
|
{
|
|
|
|
case IKE_CREATED:
|
|
|
|
case IKE_DELETING:
|
2009-07-02 08:56:13 +00:00
|
|
|
case IKE_DESTROYING:
|
2008-11-28 10:49:14 +00:00
|
|
|
case IKE_PASSIVE:
|
2008-06-04 14:31:06 +00:00
|
|
|
return SUCCESS;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-08 08:23:46 +00:00
|
|
|
/* keep existing path if possible */
|
2010-10-05 15:49:50 +00:00
|
|
|
if (is_current_path_valid(this))
|
2007-07-02 09:49:22 +00:00
|
|
|
{
|
2010-10-05 15:49:50 +00:00
|
|
|
DBG2(DBG_IKE, "keeping connection path %H - %H",
|
|
|
|
this->my_host, this->other_host);
|
|
|
|
set_condition(this, COND_STALE, FALSE);
|
2010-10-05 15:55:32 +00:00
|
|
|
|
|
|
|
if (supports_extension(this, EXT_MOBIKE) && address)
|
|
|
|
{ /* if any addresses changed, send an updated list */
|
|
|
|
DBG1(DBG_IKE, "sending address list update using MOBIKE");
|
2011-12-19 14:04:28 +00:00
|
|
|
this->task_manager->queue_mobike(this->task_manager, FALSE, TRUE);
|
2010-10-05 15:55:32 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2010-10-05 15:49:50 +00:00
|
|
|
return SUCCESS;
|
2009-07-02 08:56:13 +00:00
|
|
|
}
|
2010-10-05 15:55:32 +00:00
|
|
|
|
2010-10-05 15:49:50 +00:00
|
|
|
if (!is_any_path_valid(this))
|
2009-07-02 08:56:13 +00:00
|
|
|
{
|
2010-10-05 15:49:50 +00:00
|
|
|
DBG1(DBG_IKE, "no route found to reach %H, MOBIKE update deferred",
|
|
|
|
this->other_host);
|
|
|
|
set_condition(this, COND_STALE, TRUE);
|
|
|
|
return SUCCESS;
|
2007-06-21 15:25:28 +00:00
|
|
|
}
|
2009-07-02 08:56:13 +00:00
|
|
|
set_condition(this, COND_STALE, FALSE);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-07-02 09:49:22 +00:00
|
|
|
/* update addresses with mobike, if supported ... */
|
|
|
|
if (supports_extension(this, EXT_MOBIKE))
|
|
|
|
{
|
2010-10-05 16:01:41 +00:00
|
|
|
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
|
|
|
|
{ /* responder updates the peer about changed address config */
|
|
|
|
DBG1(DBG_IKE, "sending address list update using MOBIKE, "
|
|
|
|
"implicitly requesting an address change");
|
|
|
|
address = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "requesting address change using MOBIKE");
|
|
|
|
}
|
2011-12-19 14:04:28 +00:00
|
|
|
this->task_manager->queue_mobike(this->task_manager, TRUE, address);
|
2007-07-02 09:49:22 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2010-10-05 16:01:41 +00:00
|
|
|
|
2008-04-11 08:14:48 +00:00
|
|
|
/* ... reauth if not */
|
2010-10-05 16:01:41 +00:00
|
|
|
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
|
|
|
|
{ /* responder does not reauthenticate */
|
|
|
|
set_condition(this, COND_STALE, TRUE);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
DBG1(DBG_IKE, "reauthenticating IKE_SA due to address change");
|
2012-05-09 13:46:17 +00:00
|
|
|
/* since our previous path is not valid anymore, try and find a new one */
|
|
|
|
resolve_hosts(this);
|
2008-04-11 08:14:48 +00:00
|
|
|
return reauth(this);
|
2007-06-21 15:25:28 +00:00
|
|
|
}
|
2006-12-19 07:30:07 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, add_configuration_attribute, void,
|
|
|
|
private_ike_sa_t *this, attribute_handler_t *handler,
|
|
|
|
configuration_attribute_type_t type, chunk_t data)
|
2009-04-24 14:13:52 +00:00
|
|
|
{
|
2009-11-17 13:51:50 +00:00
|
|
|
attribute_entry_t *entry = malloc_thing(attribute_entry_t);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-11-17 13:51:50 +00:00
|
|
|
entry->handler = handler;
|
|
|
|
entry->type = type;
|
|
|
|
entry->data = chunk_clone(data);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-11-17 13:51:50 +00:00
|
|
|
this->attributes->insert_last(this->attributes, entry);
|
2009-04-24 14:13:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:37:55 +00:00
|
|
|
METHOD(ike_sa_t, create_task_enumerator, enumerator_t*,
|
|
|
|
private_ike_sa_t *this, task_queue_t queue)
|
|
|
|
{
|
|
|
|
return this->task_manager->create_task_enumerator(this->task_manager, queue);
|
|
|
|
}
|
|
|
|
|
2012-05-21 12:05:01 +00:00
|
|
|
METHOD(ike_sa_t, flush_queue, void,
|
|
|
|
private_ike_sa_t *this, task_queue_t queue)
|
|
|
|
{
|
|
|
|
this->task_manager->flush_queue(this->task_manager, queue);
|
|
|
|
}
|
|
|
|
|
2011-12-08 15:19:54 +00:00
|
|
|
METHOD(ike_sa_t, queue_task, void,
|
|
|
|
private_ike_sa_t *this, task_t *task)
|
|
|
|
{
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
}
|
|
|
|
|
2011-03-15 14:20:09 +00:00
|
|
|
METHOD(ike_sa_t, inherit, void,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this, ike_sa_t *other_public)
|
2006-08-23 07:30:43 +00:00
|
|
|
{
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *other = (private_ike_sa_t*)other_public;
|
2007-02-28 14:04:36 +00:00
|
|
|
child_sa_t *child_sa;
|
2009-04-24 14:13:52 +00:00
|
|
|
attribute_entry_t *entry;
|
2011-07-25 12:08:18 +00:00
|
|
|
enumerator_t *enumerator;
|
|
|
|
auth_cfg_t *cfg;
|
2012-08-21 11:50:32 +00:00
|
|
|
host_t *vip;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/* apply hosts and ids */
|
|
|
|
this->my_host->destroy(this->my_host);
|
|
|
|
this->other_host->destroy(this->other_host);
|
|
|
|
this->my_id->destroy(this->my_id);
|
|
|
|
this->other_id->destroy(this->other_id);
|
|
|
|
this->my_host = other->my_host->clone(other->my_host);
|
|
|
|
this->other_host = other->other_host->clone(other->other_host);
|
|
|
|
this->my_id = other->my_id->clone(other->my_id);
|
|
|
|
this->other_id = other->other_id->clone(other->other_id);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-08-21 11:50:32 +00:00
|
|
|
/* apply assigned virtual IPs... */
|
|
|
|
while (this->my_vips->remove_last(this->my_vips, (void**)&vip) == SUCCESS)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2012-08-21 11:50:32 +00:00
|
|
|
other->my_vips->insert_first(other->my_vips, vip);
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2012-08-21 11:50:32 +00:00
|
|
|
while (this->other_vips->remove_last(this->other_vips,
|
|
|
|
(void**)&vip) == SUCCESS)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2012-08-21 11:50:32 +00:00
|
|
|
other->other_vips->insert_first(other->other_vips, vip);
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-07-25 12:08:18 +00:00
|
|
|
/* authentication information */
|
|
|
|
enumerator = other->my_auths->create_enumerator(other->my_auths);
|
|
|
|
while (enumerator->enumerate(enumerator, &cfg))
|
|
|
|
{
|
|
|
|
this->my_auths->insert_last(this->my_auths, cfg->clone(cfg));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
enumerator = other->other_auths->create_enumerator(other->other_auths);
|
|
|
|
while (enumerator->enumerate(enumerator, &cfg))
|
|
|
|
{
|
|
|
|
this->other_auths->insert_last(this->other_auths, cfg->clone(cfg));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
2009-04-24 14:13:52 +00:00
|
|
|
/* ... and configuration attributes */
|
2009-09-02 15:26:36 +00:00
|
|
|
while (other->attributes->remove_last(other->attributes,
|
2009-04-24 14:13:52 +00:00
|
|
|
(void**)&entry) == SUCCESS)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2009-04-24 14:13:52 +00:00
|
|
|
this->attributes->insert_first(this->attributes, entry);
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2008-01-29 01:41:47 +00:00
|
|
|
|
2008-11-12 16:07:17 +00:00
|
|
|
/* inherit all conditions */
|
2008-01-29 01:41:47 +00:00
|
|
|
this->conditions = other->conditions;
|
|
|
|
if (this->conditions & COND_NAT_HERE)
|
|
|
|
{
|
|
|
|
send_keepalive(this);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-09 18:12:22 +00:00
|
|
|
#ifdef ME
|
|
|
|
if (other->is_mediation_server)
|
|
|
|
{
|
|
|
|
act_as_mediation_server(this);
|
|
|
|
}
|
|
|
|
else if (other->server_reflexive_host)
|
|
|
|
{
|
|
|
|
this->server_reflexive_host = other->server_reflexive_host->clone(
|
|
|
|
other->server_reflexive_host);
|
|
|
|
}
|
|
|
|
#endif /* ME */
|
2008-01-29 01:41:47 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/* adopt all children */
|
|
|
|
while (other->child_sas->remove_last(other->child_sas,
|
2009-09-04 12:58:05 +00:00
|
|
|
(void**)&child_sa) == SUCCESS)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
|
|
|
this->child_sas->insert_first(this->child_sas, (void*)child_sa);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-27 13:32:12 +00:00
|
|
|
/* move pending tasks to the new IKE_SA */
|
|
|
|
this->task_manager->adopt_tasks(this->task_manager, other->task_manager);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-11-20 12:06:40 +00:00
|
|
|
/* reauthentication timeout survives a rekeying */
|
2008-10-27 14:51:00 +00:00
|
|
|
if (other->stats[STAT_REAUTH])
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2009-08-31 15:59:00 +00:00
|
|
|
time_t reauth, delete, now = time_monotonic(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_REAUTH] = other->stats[STAT_REAUTH];
|
|
|
|
reauth = this->stats[STAT_REAUTH] - now;
|
2007-11-20 12:06:40 +00:00
|
|
|
delete = reauth + this->peer_cfg->get_over_time(this->peer_cfg);
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] = this->stats[STAT_REAUTH] + delete;
|
2007-11-20 12:06:40 +00:00
|
|
|
DBG1(DBG_IKE, "rescheduling reauthentication in %ds after rekeying, "
|
|
|
|
"lifetime reduced to %ds", reauth, delete);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler,
|
2009-04-21 15:16:56 +00:00
|
|
|
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE), reauth);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler,
|
2009-04-21 15:16:56 +00:00
|
|
|
(job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE), delete);
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2006-08-23 07:30:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, destroy, void,
|
|
|
|
private_ike_sa_t *this)
|
2006-10-18 11:46:13 +00:00
|
|
|
{
|
2009-04-24 14:13:52 +00:00
|
|
|
attribute_entry_t *entry;
|
2012-08-21 11:50:32 +00:00
|
|
|
host_t *vip;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-14 08:38:53 +00:00
|
|
|
charon->bus->set_sa(charon->bus, &this->public);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-14 08:52:13 +00:00
|
|
|
set_state(this, IKE_DESTROYING);
|
2011-12-21 11:05:34 +00:00
|
|
|
DESTROY_IF(this->task_manager);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-24 14:13:52 +00:00
|
|
|
/* remove attributes first, as we pass the IKE_SA to the handler */
|
2009-09-02 15:26:36 +00:00
|
|
|
while (this->attributes->remove_last(this->attributes,
|
2009-04-24 14:13:52 +00:00
|
|
|
(void**)&entry) == SUCCESS)
|
|
|
|
{
|
2010-03-24 16:46:29 +00:00
|
|
|
hydra->attributes->release(hydra->attributes, entry->handler,
|
|
|
|
this->other_id, entry->type, entry->data);
|
2009-04-24 14:13:52 +00:00
|
|
|
free(entry->data.ptr);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
this->attributes->destroy(this->attributes);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-10-24 08:46:17 +00:00
|
|
|
this->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-16 11:48:18 +00:00
|
|
|
/* unset SA after here to avoid usage by the listeners */
|
|
|
|
charon->bus->set_sa(charon->bus, NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-12-21 11:05:34 +00:00
|
|
|
DESTROY_IF(this->keymat);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-08-21 11:50:32 +00:00
|
|
|
while (this->my_vips->remove_last(this->my_vips, (void**)&vip) == SUCCESS)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2012-08-21 11:50:32 +00:00
|
|
|
hydra->kernel_interface->del_ip(hydra->kernel_interface, vip);
|
|
|
|
vip->destroy(vip);
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2012-08-21 11:50:32 +00:00
|
|
|
this->my_vips->destroy(this->my_vips);
|
|
|
|
while (this->other_vips->remove_last(this->other_vips,
|
|
|
|
(void**)&vip) == SUCCESS)
|
2008-04-09 12:54:47 +00:00
|
|
|
{
|
2012-08-24 12:31:24 +00:00
|
|
|
if (this->peer_cfg)
|
2008-04-09 12:54:47 +00:00
|
|
|
{
|
2012-09-11 09:19:56 +00:00
|
|
|
linked_list_t *pools;
|
|
|
|
identification_t *id;
|
|
|
|
|
|
|
|
id = get_other_eap_id(this);
|
|
|
|
pools = linked_list_create_from_enumerator(
|
|
|
|
this->peer_cfg->create_pool_enumerator(this->peer_cfg));
|
|
|
|
hydra->attributes->release_address(hydra->attributes, pools, vip, id);
|
|
|
|
pools->destroy(pools);
|
2008-04-09 12:54:47 +00:00
|
|
|
}
|
2012-08-21 11:50:32 +00:00
|
|
|
vip->destroy(vip);
|
2008-04-09 12:54:47 +00:00
|
|
|
}
|
2012-08-21 11:50:32 +00:00
|
|
|
this->other_vips->destroy(this->other_vips);
|
2012-03-09 09:15:21 +00:00
|
|
|
this->peer_addresses->destroy_offset(this->peer_addresses,
|
|
|
|
offsetof(host_t, destroy));
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2008-04-09 18:12:22 +00:00
|
|
|
if (this->is_mediation_server)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2009-09-02 15:26:36 +00:00
|
|
|
charon->mediation_manager->remove(charon->mediation_manager,
|
|
|
|
this->ike_sa_id);
|
2007-10-03 15:10:41 +00:00
|
|
|
}
|
|
|
|
DESTROY_IF(this->server_reflexive_host);
|
2008-04-01 11:38:18 +00:00
|
|
|
chunk_free(&this->connect_id);
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2008-10-06 13:37:04 +00:00
|
|
|
free(this->nat_detection_dest.ptr);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
DESTROY_IF(this->my_host);
|
|
|
|
DESTROY_IF(this->other_host);
|
|
|
|
DESTROY_IF(this->my_id);
|
|
|
|
DESTROY_IF(this->other_id);
|
2008-11-11 06:37:37 +00:00
|
|
|
DESTROY_IF(this->local_host);
|
|
|
|
DESTROY_IF(this->remote_host);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
DESTROY_IF(this->ike_cfg);
|
|
|
|
DESTROY_IF(this->peer_cfg);
|
2008-10-30 12:58:54 +00:00
|
|
|
DESTROY_IF(this->proposal);
|
2009-04-14 10:34:24 +00:00
|
|
|
this->my_auth->destroy(this->my_auth);
|
|
|
|
this->other_auth->destroy(this->other_auth);
|
2009-12-01 10:35:30 +00:00
|
|
|
this->my_auths->destroy_offset(this->my_auths,
|
|
|
|
offsetof(auth_cfg_t, destroy));
|
|
|
|
this->other_auths->destroy_offset(this->other_auths,
|
|
|
|
offsetof(auth_cfg_t, destroy));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-03-20 15:43:26 +00:00
|
|
|
this->ike_sa_id->destroy(this->ike_sa_id);
|
2006-04-10 08:07:38 +00:00
|
|
|
free(this);
|
2005-11-08 13:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-12-07 09:03:34 +00:00
|
|
|
* Described in header.
|
2005-11-08 13:33:28 +00:00
|
|
|
*/
|
2011-11-21 16:18:43 +00:00
|
|
|
ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator,
|
|
|
|
ike_version_t version)
|
2005-11-08 13:33:28 +00:00
|
|
|
{
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this;
|
2007-02-28 14:04:36 +00:00
|
|
|
static u_int32_t unique_id = 0;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-12-21 11:05:34 +00:00
|
|
|
if (version == IKE_ANY)
|
|
|
|
{ /* prefer IKEv2 if protocol not specified */
|
|
|
|
#ifdef USE_IKEV2
|
|
|
|
version = IKEV2;
|
|
|
|
#else
|
|
|
|
version = IKEV1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
INIT(this,
|
|
|
|
.public = {
|
2011-11-17 15:26:52 +00:00
|
|
|
.get_version = _get_version,
|
2010-06-07 09:30:27 +00:00
|
|
|
.get_state = _get_state,
|
|
|
|
.set_state = _set_state,
|
|
|
|
.get_name = _get_name,
|
|
|
|
.get_statistic = _get_statistic,
|
2011-11-25 13:48:57 +00:00
|
|
|
.set_statistic = _set_statistic,
|
2010-06-07 09:30:27 +00:00
|
|
|
.process_message = _process_message,
|
|
|
|
.initiate = _initiate,
|
2012-05-25 14:09:31 +00:00
|
|
|
.retry_initiate = _retry_initiate,
|
2010-06-07 09:30:27 +00:00
|
|
|
.get_ike_cfg = _get_ike_cfg,
|
|
|
|
.set_ike_cfg = _set_ike_cfg,
|
|
|
|
.get_peer_cfg = _get_peer_cfg,
|
|
|
|
.set_peer_cfg = _set_peer_cfg,
|
|
|
|
.get_auth_cfg = _get_auth_cfg,
|
|
|
|
.create_auth_cfg_enumerator = _create_auth_cfg_enumerator,
|
|
|
|
.add_auth_cfg = _add_auth_cfg,
|
|
|
|
.get_proposal = _get_proposal,
|
|
|
|
.set_proposal = _set_proposal,
|
|
|
|
.get_id = _get_id,
|
|
|
|
.get_my_host = _get_my_host,
|
|
|
|
.set_my_host = _set_my_host,
|
|
|
|
.get_other_host = _get_other_host,
|
|
|
|
.set_other_host = _set_other_host,
|
|
|
|
.set_message_id = _set_message_id,
|
2010-08-30 10:19:37 +00:00
|
|
|
.float_ports = _float_ports,
|
2010-06-07 09:30:27 +00:00
|
|
|
.update_hosts = _update_hosts,
|
|
|
|
.get_my_id = _get_my_id,
|
|
|
|
.set_my_id = _set_my_id,
|
|
|
|
.get_other_id = _get_other_id,
|
|
|
|
.set_other_id = _set_other_id,
|
|
|
|
.get_other_eap_id = _get_other_eap_id,
|
|
|
|
.enable_extension = _enable_extension,
|
|
|
|
.supports_extension = _supports_extension,
|
|
|
|
.set_condition = _set_condition,
|
|
|
|
.has_condition = _has_condition,
|
|
|
|
.set_pending_updates = _set_pending_updates,
|
|
|
|
.get_pending_updates = _get_pending_updates,
|
2012-03-09 09:15:21 +00:00
|
|
|
.create_peer_address_enumerator = _create_peer_address_enumerator,
|
|
|
|
.add_peer_address = _add_peer_address,
|
|
|
|
.clear_peer_addresses = _clear_peer_addresses,
|
2010-06-07 09:30:27 +00:00
|
|
|
.has_mapping_changed = _has_mapping_changed,
|
|
|
|
.retransmit = _retransmit,
|
|
|
|
.delete = _delete_,
|
|
|
|
.destroy = _destroy,
|
|
|
|
.send_dpd = _send_dpd,
|
|
|
|
.send_keepalive = _send_keepalive,
|
|
|
|
.get_keymat = _get_keymat,
|
|
|
|
.add_child_sa = _add_child_sa,
|
|
|
|
.get_child_sa = _get_child_sa,
|
2011-05-19 15:27:32 +00:00
|
|
|
.get_child_count = _get_child_count,
|
|
|
|
.create_child_sa_enumerator = _create_child_sa_enumerator,
|
|
|
|
.remove_child_sa = _remove_child_sa,
|
2010-06-07 09:30:27 +00:00
|
|
|
.rekey_child_sa = _rekey_child_sa,
|
|
|
|
.delete_child_sa = _delete_child_sa,
|
|
|
|
.destroy_child_sa = _destroy_child_sa,
|
|
|
|
.rekey = _rekey,
|
|
|
|
.reauth = _reauth,
|
|
|
|
.reestablish = _reestablish,
|
|
|
|
.set_auth_lifetime = _set_auth_lifetime,
|
|
|
|
.roam = _roam,
|
|
|
|
.inherit = _inherit,
|
|
|
|
.generate_message = _generate_message,
|
|
|
|
.reset = _reset,
|
|
|
|
.get_unique_id = _get_unique_id,
|
2012-08-21 11:50:32 +00:00
|
|
|
.add_virtual_ip = _add_virtual_ip,
|
2012-09-05 11:16:31 +00:00
|
|
|
.clear_virtual_ips = _clear_virtual_ips,
|
2012-08-21 11:50:32 +00:00
|
|
|
.create_virtual_ip_enumerator = _create_virtual_ip_enumerator,
|
2010-06-07 09:30:27 +00:00
|
|
|
.add_configuration_attribute = _add_configuration_attribute,
|
|
|
|
.set_kmaddress = _set_kmaddress,
|
2010-06-07 09:37:55 +00:00
|
|
|
.create_task_enumerator = _create_task_enumerator,
|
2012-05-21 12:05:01 +00:00
|
|
|
.flush_queue = _flush_queue,
|
2011-12-08 15:19:54 +00:00
|
|
|
.queue_task = _queue_task,
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2010-06-07 09:30:27 +00:00
|
|
|
.act_as_mediation_server = _act_as_mediation_server,
|
|
|
|
.get_server_reflexive_host = _get_server_reflexive_host,
|
|
|
|
.set_server_reflexive_host = _set_server_reflexive_host,
|
|
|
|
.get_connect_id = _get_connect_id,
|
|
|
|
.initiate_mediation = _initiate_mediation,
|
|
|
|
.initiate_mediated = _initiate_mediated,
|
|
|
|
.relay = _relay,
|
|
|
|
.callback = _callback,
|
|
|
|
.respond = _respond,
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2010-06-07 09:30:27 +00:00
|
|
|
},
|
|
|
|
.ike_sa_id = ike_sa_id->clone(ike_sa_id),
|
2011-11-17 15:26:52 +00:00
|
|
|
.version = version,
|
2010-06-07 09:30:27 +00:00
|
|
|
.child_sas = linked_list_create(),
|
|
|
|
.my_host = host_create_any(AF_INET),
|
|
|
|
.other_host = host_create_any(AF_INET),
|
|
|
|
.my_id = identification_create_from_encoding(ID_ANY, chunk_empty),
|
|
|
|
.other_id = identification_create_from_encoding(ID_ANY, chunk_empty),
|
2011-11-21 16:18:43 +00:00
|
|
|
.keymat = keymat_create(version, initiator),
|
2010-06-07 09:30:27 +00:00
|
|
|
.state = IKE_CREATED,
|
|
|
|
.stats[STAT_INBOUND] = time_monotonic(NULL),
|
|
|
|
.stats[STAT_OUTBOUND] = time_monotonic(NULL),
|
|
|
|
.my_auth = auth_cfg_create(),
|
|
|
|
.other_auth = auth_cfg_create(),
|
|
|
|
.my_auths = linked_list_create(),
|
|
|
|
.other_auths = linked_list_create(),
|
|
|
|
.unique_id = ++unique_id,
|
2012-03-09 09:15:21 +00:00
|
|
|
.peer_addresses = linked_list_create(),
|
2012-08-21 11:50:32 +00:00
|
|
|
.my_vips = linked_list_create(),
|
|
|
|
.other_vips = linked_list_create(),
|
2010-06-07 09:30:27 +00:00
|
|
|
.attributes = linked_list_create(),
|
|
|
|
.keepalive_interval = lib->settings->get_time(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.keep_alive", KEEPALIVE_INTERVAL, charon->name),
|
2012-05-25 13:30:32 +00:00
|
|
|
.retry_initiate_interval = lib->settings->get_time(lib->settings,
|
|
|
|
"%s.retry_initiate_interval", 0, charon->name),
|
2011-12-15 10:01:06 +00:00
|
|
|
.flush_auth_cfg = lib->settings->get_bool(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.flush_auth_cfg", FALSE, charon->name),
|
2010-06-07 09:30:27 +00:00
|
|
|
);
|
2011-11-17 15:45:14 +00:00
|
|
|
|
2012-01-10 16:40:07 +00:00
|
|
|
if (version == IKEV2)
|
|
|
|
{ /* always supported with IKEv2 */
|
|
|
|
enable_extension(this, EXT_DPD);
|
|
|
|
}
|
|
|
|
|
2011-08-01 11:08:15 +00:00
|
|
|
this->task_manager = task_manager_create(&this->public);
|
2012-04-20 08:59:14 +00:00
|
|
|
this->my_host->set_port(this->my_host,
|
|
|
|
charon->socket->get_port(charon->socket, FALSE));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-12-21 11:05:34 +00:00
|
|
|
if (!this->task_manager || !this->keymat)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "IKE version %d not supported", this->version);
|
|
|
|
destroy(this);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
return &this->public;
|
2005-11-08 13:33:28 +00:00
|
|
|
}
|