2005-12-04 19:05:52 +00:00
|
|
|
/*
|
2008-05-08 16:19:11 +00:00
|
|
|
* Copyright (C) 2006-2008 Tobias Brunner
|
2008-10-14 08:52:13 +00:00
|
|
|
* Copyright (C) 2005-2008 Martin Willi
|
2008-05-08 16:19:11 +00:00
|
|
|
* Copyright (C) 2006 Daniel Roethlisberger
|
2006-07-07 08:49:06 +00:00
|
|
|
* Copyright (C) 2005 Jan Hutter
|
2005-12-04 19:05:52 +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-10-18 11:46:13 +00:00
|
|
|
#define _GNU_SOURCE
|
2006-04-26 12:28:02 +00:00
|
|
|
#include "child_sa.h"
|
2005-12-04 19:05:52 +00:00
|
|
|
|
2006-09-08 13:10:52 +00:00
|
|
|
#include <stdio.h>
|
2006-08-28 08:45:22 +00:00
|
|
|
#include <string.h>
|
2008-11-05 08:32:38 +00:00
|
|
|
#include <time.h>
|
2006-08-28 08:45:22 +00:00
|
|
|
|
2006-02-10 08:20:06 +00:00
|
|
|
#include <daemon.h>
|
|
|
|
|
2008-10-14 08:52:13 +00:00
|
|
|
ENUM(child_sa_state_names, CHILD_CREATED, CHILD_DESTROYING,
|
2006-10-18 11:46:13 +00:00
|
|
|
"CREATED",
|
|
|
|
"ROUTED",
|
2008-11-11 09:22:00 +00:00
|
|
|
"INSTALLING",
|
2006-10-18 11:46:13 +00:00
|
|
|
"INSTALLED",
|
2008-10-16 11:48:18 +00:00
|
|
|
"UPDATING",
|
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
|
|
|
);
|
2006-07-13 08:26:54 +00:00
|
|
|
|
2005-12-04 19:05:52 +00:00
|
|
|
typedef struct private_child_sa_t private_child_sa_t;
|
|
|
|
|
|
|
|
/**
|
2007-07-03 13:49:29 +00:00
|
|
|
* Private data of a child_sa_t object.
|
2005-12-04 19:05:52 +00:00
|
|
|
*/
|
|
|
|
struct private_child_sa_t {
|
|
|
|
/**
|
2005-12-07 08:13:22 +00:00
|
|
|
* Public interface of child_sa_t.
|
2005-12-04 19:05:52 +00:00
|
|
|
*/
|
|
|
|
child_sa_t public;
|
|
|
|
|
2008-10-29 16:06:16 +00:00
|
|
|
/**
|
|
|
|
* address of us
|
|
|
|
*/
|
|
|
|
host_t *my_addr;
|
2006-02-10 08:20:06 +00:00
|
|
|
|
2006-06-15 11:06:22 +00:00
|
|
|
/**
|
2008-10-29 16:06:16 +00:00
|
|
|
* address of remote
|
2006-06-15 11:06:22 +00:00
|
|
|
*/
|
2008-10-29 16:06:16 +00:00
|
|
|
host_t *other_addr;
|
2006-06-15 11:06:22 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-29 16:06:16 +00:00
|
|
|
* our actually used SPI, 0 if unused
|
2006-06-15 11:06:22 +00:00
|
|
|
*/
|
2008-10-29 16:06:16 +00:00
|
|
|
u_int32_t my_spi;
|
2006-06-15 11:06:22 +00:00
|
|
|
|
2006-02-10 08:20:06 +00:00
|
|
|
/**
|
2008-10-29 16:06:16 +00:00
|
|
|
* others used SPI, 0 if unused
|
2006-02-10 08:20:06 +00:00
|
|
|
*/
|
2008-10-29 16:06:16 +00:00
|
|
|
u_int32_t other_spi;
|
2006-02-16 09:55:07 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
2008-10-29 16:06:16 +00:00
|
|
|
* our Compression Parameter Index (CPI) used, 0 if unused
|
2006-07-20 10:09:32 +00:00
|
|
|
*/
|
2008-10-29 16:06:16 +00:00
|
|
|
u_int16_t my_cpi;
|
2006-07-20 10:09:32 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-29 16:06:16 +00:00
|
|
|
* others Compression Parameter Index (CPI) used, 0 if unused
|
2006-07-20 10:09:32 +00:00
|
|
|
*/
|
2008-10-29 16:06:16 +00:00
|
|
|
u_int16_t other_cpi;
|
2006-07-20 10:09:32 +00:00
|
|
|
|
2006-03-01 15:56:51 +00:00
|
|
|
/**
|
2008-10-29 16:06:16 +00:00
|
|
|
* List for local traffic selectors
|
2006-03-01 15:56:51 +00:00
|
|
|
*/
|
2008-10-29 16:06:16 +00:00
|
|
|
linked_list_t *my_ts;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List for remote traffic selectors
|
|
|
|
*/
|
|
|
|
linked_list_t *other_ts;
|
2006-03-01 15:56:51 +00:00
|
|
|
|
2006-07-20 14:57:49 +00:00
|
|
|
/**
|
2008-10-29 16:06:16 +00:00
|
|
|
* Protocol used to protect this SA, ESP|AH
|
2006-07-20 14:57:49 +00:00
|
|
|
*/
|
2008-10-29 16:06:16 +00:00
|
|
|
protocol_id_t protocol;
|
2008-03-26 10:06:45 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-29 16:06:16 +00:00
|
|
|
* reqid used for this child_sa
|
2008-03-26 10:06:45 +00:00
|
|
|
*/
|
2008-10-29 16:06:16 +00:00
|
|
|
u_int32_t reqid;
|
2006-07-20 14:57:49 +00:00
|
|
|
|
2006-06-12 07:33:20 +00:00
|
|
|
/**
|
2008-10-24 08:02:35 +00:00
|
|
|
* absolute time when rekeying is scheduled
|
2006-06-12 07:33:20 +00:00
|
|
|
*/
|
2008-10-24 08:02:35 +00:00
|
|
|
time_t rekey_time;
|
2006-06-12 07:33:20 +00:00
|
|
|
|
2007-03-20 14:56:41 +00:00
|
|
|
/**
|
2008-10-24 08:02:35 +00:00
|
|
|
* absolute time when the SA expires
|
2007-03-20 14:56:41 +00:00
|
|
|
*/
|
2008-10-24 08:02:35 +00:00
|
|
|
time_t expire_time;
|
2007-03-20 14:56:41 +00:00
|
|
|
|
2006-07-13 08:26:54 +00:00
|
|
|
/**
|
|
|
|
* state of the CHILD_SA
|
|
|
|
*/
|
|
|
|
child_sa_state_t state;
|
2006-09-25 05:58:45 +00:00
|
|
|
|
2006-09-08 06:12:02 +00:00
|
|
|
/**
|
2007-06-27 13:10:55 +00:00
|
|
|
* Specifies if UDP encapsulation is enabled (NAT traversal)
|
2006-09-08 06:12:02 +00:00
|
|
|
*/
|
2007-06-27 13:10:55 +00:00
|
|
|
bool encap;
|
2006-12-21 14:35:17 +00:00
|
|
|
|
2008-05-08 16:19:11 +00:00
|
|
|
/**
|
|
|
|
* Specifies the IPComp transform used (IPCOMP_NONE if disabled)
|
|
|
|
*/
|
|
|
|
ipcomp_transform_t ipcomp;
|
|
|
|
|
2006-12-21 14:35:17 +00:00
|
|
|
/**
|
|
|
|
* mode this SA uses, tunnel/transport
|
|
|
|
*/
|
2008-09-25 13:56:23 +00:00
|
|
|
ipsec_mode_t mode;
|
2007-02-28 14:04:36 +00:00
|
|
|
|
2008-10-29 16:06:16 +00:00
|
|
|
/**
|
|
|
|
* selected proposal
|
|
|
|
*/
|
|
|
|
proposal_t *proposal;
|
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* config used to create this child
|
2007-02-28 14:04:36 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
child_cfg_t *config;
|
2005-12-04 19:05:52 +00:00
|
|
|
};
|
|
|
|
|
2008-10-14 15:17:44 +00:00
|
|
|
/**
|
2008-11-11 06:37:37 +00:00
|
|
|
* Implementation of child_sa_t.get_name
|
2006-08-25 09:07:37 +00:00
|
|
|
*/
|
|
|
|
static char *get_name(private_child_sa_t *this)
|
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->config->get_name(this->config);
|
2006-08-25 09:07:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-31 14:23:15 +00:00
|
|
|
/**
|
|
|
|
* Implements child_sa_t.get_reqid
|
|
|
|
*/
|
|
|
|
static u_int32_t get_reqid(private_child_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->reqid;
|
|
|
|
}
|
2008-11-19 15:31:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements child_sa_t.get_config
|
|
|
|
*/
|
|
|
|
static child_cfg_t* get_config(private_child_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements child_sa_t.set_state
|
|
|
|
*/
|
|
|
|
static void set_state(private_child_sa_t *this, child_sa_state_t state)
|
|
|
|
{
|
|
|
|
charon->bus->child_state_change(charon->bus, &this->public, state);
|
|
|
|
this->state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements child_sa_t.get_state
|
|
|
|
*/
|
|
|
|
static child_sa_state_t get_state(private_child_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
2006-06-07 13:26:23 +00:00
|
|
|
/**
|
|
|
|
* Implements child_sa_t.get_spi
|
|
|
|
*/
|
|
|
|
u_int32_t get_spi(private_child_sa_t *this, bool inbound)
|
|
|
|
{
|
2008-10-29 16:06:16 +00:00
|
|
|
return inbound ? this->my_spi : this->other_spi;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2008-07-22 12:03:58 +00:00
|
|
|
/**
|
|
|
|
* Implements child_sa_t.get_cpi
|
|
|
|
*/
|
|
|
|
u_int16_t get_cpi(private_child_sa_t *this, bool inbound)
|
|
|
|
{
|
2008-10-29 16:06:16 +00:00
|
|
|
return inbound ? this->my_cpi : this->other_cpi;
|
2008-07-22 12:03:58 +00:00
|
|
|
}
|
|
|
|
|
2006-06-07 13:26:23 +00:00
|
|
|
/**
|
|
|
|
* Implements child_sa_t.get_protocol
|
|
|
|
*/
|
|
|
|
protocol_id_t get_protocol(private_child_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->protocol;
|
|
|
|
}
|
2006-05-31 14:23:15 +00:00
|
|
|
|
2008-11-19 15:31:27 +00:00
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.set_protocol
|
|
|
|
*/
|
|
|
|
static void set_protocol(private_child_sa_t *this, protocol_id_t protocol)
|
|
|
|
{
|
|
|
|
this->protocol = protocol;
|
|
|
|
}
|
|
|
|
|
2008-10-29 16:06:16 +00:00
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.get_mode
|
|
|
|
*/
|
|
|
|
static ipsec_mode_t get_mode(private_child_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->mode;
|
|
|
|
}
|
|
|
|
|
2008-11-19 15:31:27 +00:00
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.set_mode
|
|
|
|
*/
|
|
|
|
static void set_mode(private_child_sa_t *this, ipsec_mode_t mode)
|
|
|
|
{
|
|
|
|
this->mode = mode;
|
|
|
|
}
|
|
|
|
|
2008-10-24 09:51:48 +00:00
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.has_encap
|
|
|
|
*/
|
|
|
|
static bool has_encap(private_child_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->encap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.get_ipcomp
|
|
|
|
*/
|
|
|
|
static ipcomp_transform_t get_ipcomp(private_child_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->ipcomp;
|
|
|
|
}
|
|
|
|
|
2006-07-13 08:26:54 +00:00
|
|
|
/**
|
2008-11-19 15:31:27 +00:00
|
|
|
* Implementation of child_sa_t.set_ipcomp.
|
2006-07-13 08:26:54 +00:00
|
|
|
*/
|
2008-11-19 15:31:27 +00:00
|
|
|
static void set_ipcomp(private_child_sa_t *this, ipcomp_transform_t ipcomp)
|
2006-07-13 08:26:54 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
this->ipcomp = ipcomp;
|
2006-07-13 08:26:54 +00:00
|
|
|
}
|
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
2008-11-19 15:31:27 +00:00
|
|
|
* Implementation of child_sa_t.get_proposal
|
2007-02-28 14:04:36 +00:00
|
|
|
*/
|
2008-11-19 15:31:27 +00:00
|
|
|
static proposal_t* get_proposal(private_child_sa_t *this)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
return this->proposal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.set_proposal
|
|
|
|
*/
|
|
|
|
static void set_proposal(private_child_sa_t *this, proposal_t *proposal)
|
|
|
|
{
|
|
|
|
this->proposal = proposal->clone(proposal);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.get_traffic_selectors.
|
|
|
|
*/
|
|
|
|
static linked_list_t *get_traffic_selectors(private_child_sa_t *this, bool local)
|
|
|
|
{
|
|
|
|
return local ? this->my_ts : this->other_ts;
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
|
2008-10-15 12:24:44 +00:00
|
|
|
typedef struct policy_enumerator_t policy_enumerator_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private policy enumerator
|
|
|
|
*/
|
|
|
|
struct policy_enumerator_t {
|
|
|
|
/** implements enumerator_t */
|
|
|
|
enumerator_t public;
|
|
|
|
/** enumerator over own TS */
|
|
|
|
enumerator_t *mine;
|
|
|
|
/** enumerator over others TS */
|
|
|
|
enumerator_t *other;
|
|
|
|
/** list of others TS, to recreate enumerator */
|
|
|
|
linked_list_t *list;
|
2008-10-21 10:57:40 +00:00
|
|
|
/** currently enumerating TS for "me" side */
|
|
|
|
traffic_selector_t *ts;
|
2008-10-15 12:24:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enumerator function of create_policy_enumerator()
|
|
|
|
*/
|
|
|
|
static bool policy_enumerate(policy_enumerator_t *this,
|
|
|
|
traffic_selector_t **my_out, traffic_selector_t **other_out)
|
|
|
|
{
|
2008-10-21 10:57:40 +00:00
|
|
|
traffic_selector_t *other_ts;
|
|
|
|
|
|
|
|
while (this->ts || this->mine->enumerate(this->mine, &this->ts))
|
2008-10-15 12:24:44 +00:00
|
|
|
{
|
2008-10-21 10:57:40 +00:00
|
|
|
if (!this->other->enumerate(this->other, &other_ts))
|
|
|
|
{ /* end of others list, restart with new of mine */
|
|
|
|
this->other->destroy(this->other);
|
|
|
|
this->other = this->list->create_enumerator(this->list);
|
|
|
|
this->ts = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (this->ts->get_type(this->ts) != other_ts->get_type(other_ts))
|
|
|
|
{ /* family mismatch */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (this->ts->get_protocol(this->ts) &&
|
|
|
|
other_ts->get_protocol(other_ts) &&
|
|
|
|
this->ts->get_protocol(this->ts) != other_ts->get_protocol(other_ts))
|
|
|
|
{ /* protocol mismatch */
|
|
|
|
continue;
|
2008-10-15 12:24:44 +00:00
|
|
|
}
|
2008-10-21 10:57:40 +00:00
|
|
|
*my_out = this->ts;
|
|
|
|
*other_out = other_ts;
|
|
|
|
return TRUE;
|
2008-10-15 12:24:44 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* destroy function of create_policy_enumerator()
|
|
|
|
*/
|
|
|
|
static void policy_destroy(policy_enumerator_t *this)
|
|
|
|
{
|
|
|
|
this->mine->destroy(this->mine);
|
|
|
|
this->other->destroy(this->other);
|
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.create_policy_enumerator
|
|
|
|
*/
|
|
|
|
static enumerator_t* create_policy_enumerator(private_child_sa_t *this)
|
|
|
|
{
|
|
|
|
policy_enumerator_t *e = malloc_thing(policy_enumerator_t);
|
|
|
|
|
|
|
|
e->public.enumerate = (void*)policy_enumerate;
|
|
|
|
e->public.destroy = (void*)policy_destroy;
|
|
|
|
e->mine = this->my_ts->create_enumerator(this->my_ts);
|
|
|
|
e->other = this->other_ts->create_enumerator(this->other_ts);
|
|
|
|
e->list = this->other_ts;
|
2008-10-21 10:57:40 +00:00
|
|
|
e->ts = NULL;
|
2008-10-15 12:24:44 +00:00
|
|
|
|
|
|
|
return &e->public;
|
|
|
|
}
|
|
|
|
|
2007-04-11 12:14:51 +00:00
|
|
|
/**
|
2008-10-24 08:02:35 +00:00
|
|
|
* Implementation of child_sa_t.get_usetime
|
2007-04-11 12:14:51 +00:00
|
|
|
*/
|
2008-10-24 08:02:35 +00:00
|
|
|
static u_int32_t get_usetime(private_child_sa_t *this, bool inbound)
|
2007-04-11 12:14:51 +00:00
|
|
|
{
|
2008-10-15 12:24:44 +00:00
|
|
|
enumerator_t *enumerator;
|
2008-10-24 08:02:35 +00:00
|
|
|
traffic_selector_t *my_ts, *other_ts;
|
|
|
|
u_int32_t last_use = 0;
|
|
|
|
|
2008-10-15 12:24:44 +00:00
|
|
|
enumerator = create_policy_enumerator(this);
|
|
|
|
while (enumerator->enumerate(enumerator, &my_ts, &other_ts))
|
2007-04-11 12:14:51 +00:00
|
|
|
{
|
2008-10-24 08:02:35 +00:00
|
|
|
u_int32_t in, out, fwd;
|
|
|
|
|
|
|
|
if (inbound)
|
2007-04-11 12:14:51 +00:00
|
|
|
{
|
2008-10-24 08:02:35 +00:00
|
|
|
if (charon->kernel_interface->query_policy(charon->kernel_interface,
|
|
|
|
other_ts, my_ts, POLICY_IN, &in) == SUCCESS)
|
|
|
|
{
|
|
|
|
last_use = max(last_use, in);
|
|
|
|
}
|
2008-11-12 16:47:19 +00:00
|
|
|
if (this->mode != MODE_TRANSPORT)
|
2008-10-24 08:02:35 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
if (charon->kernel_interface->query_policy(charon->kernel_interface,
|
|
|
|
other_ts, my_ts, POLICY_FWD, &fwd) == SUCCESS)
|
|
|
|
{
|
|
|
|
last_use = max(last_use, fwd);
|
|
|
|
}
|
2008-10-24 08:02:35 +00:00
|
|
|
}
|
2007-04-11 12:14:51 +00:00
|
|
|
}
|
2008-10-24 08:02:35 +00:00
|
|
|
else
|
2007-04-11 12:14:51 +00:00
|
|
|
{
|
2008-10-24 08:02:35 +00:00
|
|
|
if (charon->kernel_interface->query_policy(charon->kernel_interface,
|
|
|
|
my_ts, other_ts, POLICY_OUT, &out) == SUCCESS)
|
|
|
|
{
|
|
|
|
last_use = max(last_use, out);
|
|
|
|
}
|
2007-04-11 12:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-15 12:24:44 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2008-10-24 08:02:35 +00:00
|
|
|
return last_use;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.get_lifetime
|
|
|
|
*/
|
|
|
|
static u_int32_t get_lifetime(private_child_sa_t *this, bool hard)
|
|
|
|
{
|
2008-10-29 16:06:16 +00:00
|
|
|
return hard ? this->expire_time : this->rekey_time;
|
2007-04-11 12:14:51 +00:00
|
|
|
}
|
|
|
|
|
2006-07-13 08:26:54 +00:00
|
|
|
/**
|
2008-11-19 15:31:27 +00:00
|
|
|
* Implementation of child_sa_t.alloc_spi
|
2006-06-22 06:36:28 +00:00
|
|
|
*/
|
2008-11-19 15:31:27 +00:00
|
|
|
static u_int32_t alloc_spi(private_child_sa_t *this, protocol_id_t protocol)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
switch (protocol)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
case PROTO_AH:
|
|
|
|
if (charon->kernel_interface->get_spi(charon->kernel_interface,
|
|
|
|
this->other_addr, this->my_addr, PROTO_AH,
|
|
|
|
this->reqid, &this->my_spi) == SUCCESS)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
return this->my_spi;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
2008-11-19 15:31:27 +00:00
|
|
|
break;
|
|
|
|
case PROTO_ESP:
|
|
|
|
if (charon->kernel_interface->get_spi(charon->kernel_interface,
|
|
|
|
this->other_addr, this->my_addr, PROTO_ESP,
|
|
|
|
this->reqid, &this->my_spi) == SUCCESS)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
return this->my_spi;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
2008-11-19 15:31:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
2008-11-19 15:31:27 +00:00
|
|
|
return 0;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
|
|
|
|
2005-12-04 19:05:52 +00:00
|
|
|
/**
|
2008-11-19 15:31:27 +00:00
|
|
|
* Implementation of child_sa_t.alloc_cpi
|
2005-12-04 19:05:52 +00:00
|
|
|
*/
|
2008-11-19 15:31:27 +00:00
|
|
|
static u_int16_t alloc_cpi(private_child_sa_t *this)
|
2005-12-04 19:05:52 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
if (charon->kernel_interface->get_cpi(charon->kernel_interface,
|
|
|
|
this->other_addr, this->my_addr, this->reqid,
|
|
|
|
&this->my_cpi) == SUCCESS)
|
2006-02-16 09:55:07 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
return this->my_cpi;
|
2006-02-16 09:55:07 +00:00
|
|
|
}
|
2008-11-19 15:31:27 +00:00
|
|
|
return 0;
|
2005-12-04 19:05:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-29 16:06:16 +00:00
|
|
|
/**
|
2008-11-19 15:31:27 +00:00
|
|
|
* Implementation of child_sa_t.install
|
2008-10-29 16:06:16 +00:00
|
|
|
*/
|
2008-11-19 15:31:27 +00:00
|
|
|
static status_t install(private_child_sa_t *this, chunk_t encr, chunk_t integ,
|
|
|
|
u_int32_t spi, u_int16_t cpi, bool inbound)
|
2005-12-04 19:05:52 +00:00
|
|
|
{
|
2008-10-29 16:06:16 +00:00
|
|
|
u_int16_t enc_alg = ENCR_UNDEFINED, int_alg = AUTH_UNDEFINED, size;
|
2008-11-19 15:31:27 +00:00
|
|
|
u_int32_t soft, hard, now;
|
2008-10-14 15:17:44 +00:00
|
|
|
host_t *src, *dst;
|
2006-02-16 09:55:07 +00:00
|
|
|
status_t status;
|
2008-11-19 15:31:27 +00:00
|
|
|
bool update = FALSE;
|
2006-06-07 13:26:23 +00:00
|
|
|
|
2008-10-29 16:06:16 +00:00
|
|
|
/* now we have to decide which spi to use. Use self allocated, if "in",
|
|
|
|
* or the one in the proposal, if not "in" (others). Additionally,
|
2006-06-15 11:06:22 +00:00
|
|
|
* source and dest host switch depending on the role */
|
2008-11-19 15:31:27 +00:00
|
|
|
if (inbound)
|
2006-02-10 08:20:06 +00:00
|
|
|
{
|
2008-10-29 16:06:16 +00:00
|
|
|
dst = this->my_addr;
|
|
|
|
src = this->other_addr;
|
2008-11-19 15:31:27 +00:00
|
|
|
if (this->my_spi == spi)
|
|
|
|
{ /* alloc_spi has been called, do an SA update */
|
|
|
|
update = TRUE;
|
|
|
|
}
|
|
|
|
this->my_spi = spi;
|
|
|
|
this->my_cpi = cpi;
|
2006-02-10 08:20:06 +00:00
|
|
|
}
|
2006-06-07 13:26:23 +00:00
|
|
|
else
|
|
|
|
{
|
2008-10-29 16:06:16 +00:00
|
|
|
src = this->my_addr;
|
|
|
|
dst = this->other_addr;
|
2008-11-19 15:31:27 +00:00
|
|
|
this->other_spi = spi;
|
|
|
|
this->other_cpi = cpi;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2008-11-19 15:31:27 +00:00
|
|
|
DBG2(DBG_CHD, "adding %s %N SA", inbound ? "inbound" : "outbound",
|
2006-10-18 11:46:13 +00:00
|
|
|
protocol_id_names, this->protocol);
|
2006-06-09 07:31:30 +00:00
|
|
|
|
|
|
|
/* send SA down to the kernel */
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG2(DBG_CHD, " SPI 0x%.8x, src %H dst %H", ntohl(spi), src, dst);
|
2008-05-08 16:19:11 +00:00
|
|
|
|
2008-11-19 15:31:27 +00:00
|
|
|
this->proposal->get_algorithm(this->proposal, ENCRYPTION_ALGORITHM,
|
|
|
|
&enc_alg, &size);
|
|
|
|
this->proposal->get_algorithm(this->proposal, INTEGRITY_ALGORITHM,
|
|
|
|
&int_alg, &size);
|
2008-10-29 16:06:16 +00:00
|
|
|
|
2008-10-14 15:17:44 +00:00
|
|
|
soft = this->config->get_lifetime(this->config, TRUE);
|
|
|
|
hard = this->config->get_lifetime(this->config, FALSE);
|
2008-11-19 15:31:27 +00:00
|
|
|
|
2008-10-29 16:06:16 +00:00
|
|
|
status = charon->kernel_interface->add_sa(charon->kernel_interface,
|
|
|
|
src, dst, spi, this->protocol, this->reqid,
|
2008-11-19 15:31:27 +00:00
|
|
|
inbound ? soft : 0, hard, enc_alg, encr, int_alg, integ,
|
|
|
|
this->mode, this->ipcomp, cpi, this->encap, update);
|
2008-10-14 15:17:44 +00:00
|
|
|
|
2008-10-24 08:02:35 +00:00
|
|
|
now = time(NULL);
|
|
|
|
this->rekey_time = now + soft;
|
|
|
|
this->expire_time = now + hard;
|
2006-06-07 13:26:23 +00:00
|
|
|
return status;
|
2006-02-16 09:55:07 +00:00
|
|
|
}
|
|
|
|
|
2008-10-29 16:06:16 +00:00
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.add_policies
|
|
|
|
*/
|
2006-12-21 14:35:17 +00:00
|
|
|
static status_t add_policies(private_child_sa_t *this,
|
2008-11-19 15:31:27 +00:00
|
|
|
linked_list_t *my_ts_list, linked_list_t *other_ts_list)
|
2006-02-22 16:14:40 +00:00
|
|
|
{
|
2008-10-15 12:24:44 +00:00
|
|
|
enumerator_t *enumerator;
|
2006-03-01 15:56:51 +00:00
|
|
|
traffic_selector_t *my_ts, *other_ts;
|
2008-10-15 12:24:44 +00:00
|
|
|
status_t status = SUCCESS;
|
2008-11-11 09:22:00 +00:00
|
|
|
bool routed = (this->state == CHILD_CREATED);
|
2006-02-22 16:14:40 +00:00
|
|
|
|
2008-10-15 12:24:44 +00:00
|
|
|
/* apply traffic selectors */
|
|
|
|
enumerator = my_ts_list->create_enumerator(my_ts_list);
|
|
|
|
while (enumerator->enumerate(enumerator, &my_ts))
|
2006-02-22 16:14:40 +00:00
|
|
|
{
|
2008-10-15 12:24:44 +00:00
|
|
|
this->my_ts->insert_last(this->my_ts, my_ts->clone(my_ts));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
enumerator = other_ts_list->create_enumerator(other_ts_list);
|
|
|
|
while (enumerator->enumerate(enumerator, &other_ts))
|
|
|
|
{
|
|
|
|
this->other_ts->insert_last(this->other_ts, other_ts->clone(other_ts));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (this->config->install_policy(this->config))
|
2008-10-15 12:24:44 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
/* enumerate pairs of traffic selectors */
|
|
|
|
enumerator = create_policy_enumerator(this);
|
|
|
|
while (enumerator->enumerate(enumerator, &my_ts, &other_ts))
|
|
|
|
{
|
|
|
|
/* install 3 policies: out, in and forward */
|
|
|
|
status |= charon->kernel_interface->add_policy(charon->kernel_interface,
|
|
|
|
this->my_addr, this->other_addr, my_ts, other_ts, POLICY_OUT,
|
2008-11-19 15:31:27 +00:00
|
|
|
this->other_spi, this->protocol, this->reqid, this->mode,
|
|
|
|
this->ipcomp, this->other_cpi, routed);
|
2008-11-11 09:22:00 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
status |= charon->kernel_interface->add_policy(charon->kernel_interface,
|
|
|
|
this->other_addr, this->my_addr, other_ts, my_ts, POLICY_IN,
|
2008-11-19 15:31:27 +00:00
|
|
|
this->my_spi, this->protocol, this->reqid, this->mode,
|
|
|
|
this->ipcomp, this->my_cpi, routed);
|
|
|
|
if (this->mode != MODE_TRANSPORT)
|
2008-11-11 06:37:37 +00:00
|
|
|
{
|
|
|
|
status |= charon->kernel_interface->add_policy(charon->kernel_interface,
|
2008-11-11 09:22:00 +00:00
|
|
|
this->other_addr, this->my_addr, other_ts, my_ts, POLICY_FWD,
|
2008-11-19 15:31:27 +00:00
|
|
|
this->my_spi, this->protocol, this->reqid, this->mode,
|
|
|
|
this->ipcomp, this->my_cpi, routed);
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
2008-11-12 15:09:24 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (status != SUCCESS)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2006-03-01 15:56:51 +00:00
|
|
|
}
|
2008-11-11 06:37:37 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2006-03-01 15:56:51 +00:00
|
|
|
}
|
2008-11-12 15:09:24 +00:00
|
|
|
|
2008-11-19 15:31:27 +00:00
|
|
|
if (status == SUCCESS && this->state == CHILD_CREATED)
|
|
|
|
{ /* switch to routed state if no SAD entry set up */
|
|
|
|
set_state(this, CHILD_ROUTED);
|
2006-07-21 13:31:53 +00:00
|
|
|
}
|
2008-10-15 12:24:44 +00:00
|
|
|
return status;
|
2006-02-16 09:55:07 +00:00
|
|
|
}
|
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
2008-11-19 15:31:27 +00:00
|
|
|
* Implementation of child_sa_t.update.
|
2006-07-20 10:09:32 +00:00
|
|
|
*/
|
2008-11-19 15:31:27 +00:00
|
|
|
static status_t update(private_child_sa_t *this, host_t *me, host_t *other,
|
|
|
|
host_t *vip, bool encap)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2008-10-16 11:48:18 +00:00
|
|
|
child_sa_state_t old;
|
2008-11-17 00:01:34 +00:00
|
|
|
bool transport_proxy_mode;
|
2008-10-16 11:48:18 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
/* anything changed at all? */
|
2008-10-29 16:06:16 +00:00
|
|
|
if (me->equals(me, this->my_addr) &&
|
|
|
|
other->equals(other, this->other_addr) && this->encap == encap)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2008-10-16 11:48:18 +00:00
|
|
|
|
|
|
|
old = this->state;
|
|
|
|
set_state(this, CHILD_UPDATING);
|
2008-11-17 00:01:34 +00:00
|
|
|
transport_proxy_mode = this->config->use_proxy_mode(this->config) &&
|
|
|
|
this->mode == MODE_TRANSPORT;
|
2007-07-02 09:49:22 +00:00
|
|
|
|
2008-11-17 00:01:34 +00:00
|
|
|
if (!transport_proxy_mode)
|
2008-11-11 09:22:00 +00:00
|
|
|
{
|
2008-11-16 21:19:58 +00:00
|
|
|
/* update our (initator) SA */
|
|
|
|
if (this->my_spi)
|
|
|
|
{
|
|
|
|
if (charon->kernel_interface->update_sa(charon->kernel_interface,
|
|
|
|
this->my_spi, this->protocol,
|
|
|
|
this->ipcomp != IPCOMP_NONE ? this->my_cpi : 0,
|
|
|
|
this->other_addr, this->my_addr, other, me,
|
|
|
|
this->encap, encap) == NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
return NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update his (responder) SA */
|
|
|
|
if (this->other_spi)
|
|
|
|
{
|
|
|
|
if (charon->kernel_interface->update_sa(charon->kernel_interface,
|
|
|
|
this->other_spi, this->protocol,
|
|
|
|
this->ipcomp != IPCOMP_NONE ? this->other_cpi : 0,
|
|
|
|
this->my_addr, this->other_addr, me, other,
|
|
|
|
this->encap, encap) == NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
return NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
2008-11-11 09:22:00 +00:00
|
|
|
}
|
2006-06-22 06:36:28 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (this->config->install_policy(this->config))
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
/* update policies */
|
|
|
|
if (!me->ip_equals(me, this->my_addr) ||
|
|
|
|
!other->ip_equals(other, this->other_addr))
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
enumerator_t *enumerator;
|
|
|
|
traffic_selector_t *my_ts, *other_ts;
|
2008-11-12 15:09:24 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/* always use high priorities, as hosts getting updated are INSTALLED */
|
|
|
|
enumerator = create_policy_enumerator(this);
|
|
|
|
while (enumerator->enumerate(enumerator, &my_ts, &other_ts))
|
|
|
|
{
|
|
|
|
/* remove old policies first */
|
|
|
|
charon->kernel_interface->del_policy(charon->kernel_interface,
|
2008-11-12 16:47:19 +00:00
|
|
|
my_ts, other_ts, POLICY_OUT, FALSE);
|
2008-11-11 06:37:37 +00:00
|
|
|
charon->kernel_interface->del_policy(charon->kernel_interface,
|
2008-11-12 16:47:19 +00:00
|
|
|
other_ts, my_ts, POLICY_IN, FALSE);
|
|
|
|
if (this->mode != MODE_TRANSPORT)
|
2008-11-11 06:37:37 +00:00
|
|
|
{
|
|
|
|
charon->kernel_interface->del_policy(charon->kernel_interface,
|
2008-11-12 16:47:19 +00:00
|
|
|
other_ts, my_ts, POLICY_FWD, FALSE);
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
2008-11-12 15:09:24 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/* check whether we have to update a "dynamic" traffic selector */
|
|
|
|
if (!me->ip_equals(me, this->my_addr) &&
|
|
|
|
my_ts->is_host(my_ts, this->my_addr))
|
|
|
|
{
|
|
|
|
my_ts->set_address(my_ts, me);
|
|
|
|
}
|
|
|
|
if (!other->ip_equals(other, this->other_addr) &&
|
|
|
|
other_ts->is_host(other_ts, this->other_addr))
|
|
|
|
{
|
|
|
|
other_ts->set_address(other_ts, other);
|
|
|
|
}
|
2008-11-12 15:09:24 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/* we reinstall the virtual IP to handle interface roaming
|
|
|
|
* correctly */
|
|
|
|
if (vip)
|
|
|
|
{
|
|
|
|
charon->kernel_interface->del_ip(charon->kernel_interface, vip);
|
|
|
|
charon->kernel_interface->add_ip(charon->kernel_interface, vip, me);
|
|
|
|
}
|
2008-11-12 15:09:24 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/* reinstall updated policies */
|
|
|
|
charon->kernel_interface->add_policy(charon->kernel_interface,
|
2008-11-11 09:22:00 +00:00
|
|
|
me, other, my_ts, other_ts, POLICY_OUT, this->other_spi,
|
|
|
|
this->protocol, this->reqid, this->mode, this->ipcomp,
|
|
|
|
this->other_cpi, FALSE);
|
2008-11-11 06:37:37 +00:00
|
|
|
charon->kernel_interface->add_policy(charon->kernel_interface,
|
2008-11-11 09:22:00 +00:00
|
|
|
other, me, other_ts, my_ts, POLICY_IN, this->my_spi,
|
|
|
|
this->protocol, this->reqid, this->mode, this->ipcomp,
|
|
|
|
this->my_cpi, FALSE);
|
2008-11-12 16:47:19 +00:00
|
|
|
if (this->mode != MODE_TRANSPORT)
|
2008-11-11 06:37:37 +00:00
|
|
|
{
|
|
|
|
charon->kernel_interface->add_policy(charon->kernel_interface,
|
2008-11-11 09:22:00 +00:00
|
|
|
other, me, other_ts, my_ts, POLICY_FWD, this->my_spi,
|
|
|
|
this->protocol, this->reqid, this->mode, this->ipcomp,
|
|
|
|
this->my_cpi, FALSE);
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-16 21:19:58 +00:00
|
|
|
|
2008-11-17 00:01:34 +00:00
|
|
|
if (!transport_proxy_mode)
|
|
|
|
{
|
|
|
|
/* apply hosts */
|
|
|
|
if (!me->equals(me, this->my_addr))
|
|
|
|
{
|
|
|
|
this->my_addr->destroy(this->my_addr);
|
|
|
|
this->my_addr = me->clone(me);
|
|
|
|
}
|
|
|
|
if (!other->equals(other, this->other_addr))
|
|
|
|
{
|
|
|
|
this->other_addr->destroy(this->other_addr);
|
|
|
|
this->other_addr = other->clone(other);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-11 09:22:00 +00:00
|
|
|
this->encap = encap;
|
2008-10-16 11:48:18 +00:00
|
|
|
set_state(this, old);
|
2008-11-16 21:19:58 +00:00
|
|
|
|
2006-06-22 06:36:28 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-02-16 09:55:07 +00:00
|
|
|
/**
|
|
|
|
* Implementation of child_sa_t.destroy.
|
|
|
|
*/
|
|
|
|
static void destroy(private_child_sa_t *this)
|
|
|
|
{
|
2008-10-15 12:24:44 +00:00
|
|
|
enumerator_t *enumerator;
|
|
|
|
traffic_selector_t *my_ts, *other_ts;
|
2008-11-11 09:22:00 +00:00
|
|
|
bool unrouted = (this->state == CHILD_ROUTED);
|
2006-03-01 15:56:51 +00:00
|
|
|
|
2008-10-14 08:52:13 +00:00
|
|
|
set_state(this, CHILD_DESTROYING);
|
|
|
|
|
2006-03-01 15:56:51 +00:00
|
|
|
/* delete SAs in the kernel, if they are set up */
|
2008-10-29 16:06:16 +00:00
|
|
|
if (this->my_spi)
|
2006-03-01 15:56:51 +00:00
|
|
|
{
|
|
|
|
charon->kernel_interface->del_sa(charon->kernel_interface,
|
2009-04-30 11:37:54 +00:00
|
|
|
this->other_addr, this->my_addr, this->my_spi,
|
|
|
|
this->protocol, this->my_cpi);
|
2006-06-15 11:06:22 +00:00
|
|
|
}
|
2008-10-29 16:06:16 +00:00
|
|
|
if (this->other_spi)
|
2006-06-15 11:06:22 +00:00
|
|
|
{
|
2006-03-01 15:56:51 +00:00
|
|
|
charon->kernel_interface->del_sa(charon->kernel_interface,
|
2009-04-30 11:37:54 +00:00
|
|
|
this->my_addr, this->other_addr, this->other_spi,
|
|
|
|
this->protocol, this->other_cpi);
|
2008-05-08 16:19:11 +00:00
|
|
|
}
|
2006-06-09 15:12:43 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (this->config->install_policy(this->config))
|
2006-06-09 15:12:43 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
/* delete all policies in the kernel */
|
|
|
|
enumerator = create_policy_enumerator(this);
|
|
|
|
while (enumerator->enumerate(enumerator, &my_ts, &other_ts))
|
|
|
|
{
|
|
|
|
charon->kernel_interface->del_policy(charon->kernel_interface,
|
2008-11-12 16:47:19 +00:00
|
|
|
my_ts, other_ts, POLICY_OUT, unrouted);
|
2008-11-11 06:37:37 +00:00
|
|
|
charon->kernel_interface->del_policy(charon->kernel_interface,
|
2008-11-12 16:47:19 +00:00
|
|
|
other_ts, my_ts, POLICY_IN, unrouted);
|
|
|
|
if (this->mode != MODE_TRANSPORT)
|
2008-11-11 06:37:37 +00:00
|
|
|
{
|
|
|
|
charon->kernel_interface->del_policy(charon->kernel_interface,
|
2008-11-12 16:47:19 +00:00
|
|
|
other_ts, my_ts, POLICY_FWD, unrouted);
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2006-03-01 15:56:51 +00:00
|
|
|
}
|
2008-11-12 15:09:24 +00:00
|
|
|
|
2008-10-15 12:24:44 +00:00
|
|
|
this->my_ts->destroy_offset(this->my_ts, offsetof(traffic_selector_t, destroy));
|
|
|
|
this->other_ts->destroy_offset(this->other_ts, offsetof(traffic_selector_t, destroy));
|
2008-10-29 16:06:16 +00:00
|
|
|
this->my_addr->destroy(this->my_addr);
|
|
|
|
this->other_addr->destroy(this->other_addr);
|
|
|
|
DESTROY_IF(this->proposal);
|
2007-04-10 06:01:03 +00:00
|
|
|
this->config->destroy(this->config);
|
2006-04-10 08:07:38 +00:00
|
|
|
free(this);
|
2006-02-16 09:55:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Described in header.
|
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
child_sa_t * child_sa_create(host_t *me, host_t* other,
|
2007-06-27 13:10:55 +00:00
|
|
|
child_cfg_t *config, u_int32_t rekey, bool encap)
|
2006-02-16 09:55:07 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
static u_int32_t reqid = 0;
|
2006-04-10 08:07:38 +00:00
|
|
|
private_child_sa_t *this = malloc_thing(private_child_sa_t);
|
2006-02-16 09:55:07 +00:00
|
|
|
|
|
|
|
/* public functions */
|
2006-08-25 09:07:37 +00:00
|
|
|
this->public.get_name = (char*(*)(child_sa_t*))get_name;
|
2006-05-31 14:23:15 +00:00
|
|
|
this->public.get_reqid = (u_int32_t(*)(child_sa_t*))get_reqid;
|
2008-11-19 15:31:27 +00:00
|
|
|
this->public.get_config = (child_cfg_t*(*)(child_sa_t*))get_config;
|
|
|
|
this->public.get_state = (child_sa_state_t(*)(child_sa_t*))get_state;
|
|
|
|
this->public.set_state = (void(*)(child_sa_t*,child_sa_state_t))set_state;
|
2006-06-07 13:26:23 +00:00
|
|
|
this->public.get_spi = (u_int32_t(*)(child_sa_t*, bool))get_spi;
|
2008-07-22 12:03:58 +00:00
|
|
|
this->public.get_cpi = (u_int16_t(*)(child_sa_t*, bool))get_cpi;
|
2006-06-07 13:26:23 +00:00
|
|
|
this->public.get_protocol = (protocol_id_t(*)(child_sa_t*))get_protocol;
|
2008-11-19 15:31:27 +00:00
|
|
|
this->public.set_protocol = (void(*)(child_sa_t*, protocol_id_t protocol))set_protocol;
|
2008-10-24 08:02:35 +00:00
|
|
|
this->public.get_mode = (ipsec_mode_t(*)(child_sa_t*))get_mode;
|
2008-11-19 15:31:27 +00:00
|
|
|
this->public.set_mode = (void(*)(child_sa_t*, ipsec_mode_t mode))set_mode;
|
|
|
|
this->public.get_proposal = (proposal_t*(*)(child_sa_t*))get_proposal;
|
|
|
|
this->public.set_proposal = (void(*)(child_sa_t*, proposal_t *proposal))set_proposal;
|
2008-10-24 08:02:35 +00:00
|
|
|
this->public.get_lifetime = (u_int32_t(*)(child_sa_t*, bool))get_lifetime;
|
|
|
|
this->public.get_usetime = (u_int32_t(*)(child_sa_t*, bool))get_usetime;
|
2008-11-19 15:31:27 +00:00
|
|
|
this->public.has_encap = (bool(*)(child_sa_t*))has_encap;
|
|
|
|
this->public.get_ipcomp = (ipcomp_transform_t(*)(child_sa_t*))get_ipcomp;
|
|
|
|
this->public.set_ipcomp = (void(*)(child_sa_t*,ipcomp_transform_t))set_ipcomp;
|
|
|
|
this->public.alloc_spi = (u_int32_t(*)(child_sa_t*, protocol_id_t protocol))alloc_spi;
|
|
|
|
this->public.alloc_cpi = (u_int16_t(*)(child_sa_t*))alloc_cpi;
|
|
|
|
this->public.install = (status_t(*)(child_sa_t*, chunk_t encr, chunk_t integ, u_int32_t spi, u_int16_t cpi, bool inbound))install;
|
|
|
|
this->public.update = (status_t (*)(child_sa_t*,host_t*,host_t*,host_t*,bool))update;
|
|
|
|
this->public.add_policies = (status_t (*)(child_sa_t*, linked_list_t*,linked_list_t*))add_policies;
|
2007-04-10 06:01:03 +00:00
|
|
|
this->public.get_traffic_selectors = (linked_list_t*(*)(child_sa_t*,bool))get_traffic_selectors;
|
2008-10-15 12:24:44 +00:00
|
|
|
this->public.create_policy_enumerator = (enumerator_t*(*)(child_sa_t*))create_policy_enumerator;
|
2006-02-16 09:55:07 +00:00
|
|
|
this->public.destroy = (void(*)(child_sa_t*))destroy;
|
2008-11-19 15:31:27 +00:00
|
|
|
|
2006-02-16 09:55:07 +00:00
|
|
|
/* private data */
|
2008-10-29 16:06:16 +00:00
|
|
|
this->my_addr = me->clone(me);
|
|
|
|
this->other_addr = other->clone(other);
|
|
|
|
this->my_spi = 0;
|
|
|
|
this->other_spi = 0;
|
2008-11-19 15:31:27 +00:00
|
|
|
this->my_cpi = 0;
|
2008-10-29 16:06:16 +00:00
|
|
|
this->other_cpi = 0;
|
2007-06-27 13:10:55 +00:00
|
|
|
this->encap = encap;
|
2008-05-08 16:19:11 +00:00
|
|
|
this->ipcomp = IPCOMP_NONE;
|
2006-07-13 08:26:54 +00:00
|
|
|
this->state = CHILD_CREATED;
|
2006-06-12 08:36:41 +00:00
|
|
|
/* reuse old reqid if we are rekeying an existing CHILD_SA */
|
|
|
|
this->reqid = rekey ? rekey : ++reqid;
|
2006-07-20 10:09:32 +00:00
|
|
|
this->my_ts = linked_list_create();
|
|
|
|
this->other_ts = linked_list_create();
|
2006-06-07 13:26:23 +00:00
|
|
|
this->protocol = PROTO_NONE;
|
2006-12-21 14:35:17 +00:00
|
|
|
this->mode = MODE_TUNNEL;
|
2008-10-29 16:06:16 +00:00
|
|
|
this->proposal = NULL;
|
2007-04-10 06:01:03 +00:00
|
|
|
this->config = config;
|
|
|
|
config->get_ref(config);
|
2008-11-19 15:31:27 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/* MIPv6 proxy transport mode sets SA endpoints to TS hosts */
|
|
|
|
if (config->get_mode(config) == MODE_TRANSPORT &&
|
|
|
|
config->use_proxy_mode(config))
|
|
|
|
{
|
|
|
|
ts_type_t type;
|
|
|
|
int family;
|
|
|
|
chunk_t addr;
|
|
|
|
host_t *host;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
linked_list_t *my_ts_list, *other_ts_list;
|
|
|
|
traffic_selector_t *my_ts, *other_ts;
|
2008-11-19 15:31:27 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
this->mode = MODE_TRANSPORT;
|
2008-11-19 15:31:27 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
my_ts_list = config->get_traffic_selectors(config, TRUE, NULL, me);
|
|
|
|
enumerator = my_ts_list->create_enumerator(my_ts_list);
|
|
|
|
if (enumerator->enumerate(enumerator, &my_ts))
|
|
|
|
{
|
|
|
|
if (my_ts->is_host(my_ts, NULL) &&
|
|
|
|
!my_ts->is_host(my_ts, this->my_addr))
|
|
|
|
{
|
|
|
|
type = my_ts->get_type(my_ts);
|
|
|
|
family = (type == TS_IPV4_ADDR_RANGE) ? AF_INET : AF_INET6;
|
|
|
|
addr = my_ts->get_from_address(my_ts);
|
|
|
|
host = host_create_from_chunk(family, addr, 0);
|
|
|
|
free(addr.ptr);
|
|
|
|
DBG1(DBG_CHD, "my address: %H is a transport mode proxy for %H",
|
|
|
|
this->my_addr, host);
|
|
|
|
this->my_addr->destroy(this->my_addr);
|
|
|
|
this->my_addr = host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
my_ts_list->destroy_offset(my_ts_list, offsetof(traffic_selector_t, destroy));
|
2008-11-19 15:31:27 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
other_ts_list = config->get_traffic_selectors(config, FALSE, NULL, other);
|
|
|
|
enumerator = other_ts_list->create_enumerator(other_ts_list);
|
|
|
|
if (enumerator->enumerate(enumerator, &other_ts))
|
|
|
|
{
|
|
|
|
if (other_ts->is_host(other_ts, NULL) &&
|
|
|
|
!other_ts->is_host(other_ts, this->other_addr))
|
|
|
|
{
|
|
|
|
type = other_ts->get_type(other_ts);
|
|
|
|
family = (type == TS_IPV4_ADDR_RANGE) ? AF_INET : AF_INET6;
|
|
|
|
addr = other_ts->get_from_address(other_ts);
|
|
|
|
host = host_create_from_chunk(family, addr, 0);
|
|
|
|
free(addr.ptr);
|
|
|
|
DBG1(DBG_CHD, "other address: %H is a transport mode proxy for %H",
|
|
|
|
this->other_addr, host);
|
|
|
|
this->other_addr->destroy(this->other_addr);
|
|
|
|
this->other_addr = host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
other_ts_list->destroy_offset(other_ts_list, offsetof(traffic_selector_t, destroy));
|
|
|
|
}
|
2005-12-04 19:05:52 +00:00
|
|
|
|
2006-06-22 06:36:28 +00:00
|
|
|
return &this->public;
|
2005-12-04 19:05:52 +00:00
|
|
|
}
|