339 lines
9.0 KiB
C
339 lines
9.0 KiB
C
/*
|
|
* Copyright (C) 2006-2008 Tobias Brunner
|
|
* Copyright (C) 2006-2007 Martin Willi
|
|
* Copyright (C) 2006 Daniel Roethlisberger
|
|
* 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.
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
/**
|
|
* @defgroup child_sa child_sa
|
|
* @{ @ingroup sa
|
|
*/
|
|
|
|
#ifndef CHILD_SA_H_
|
|
#define CHILD_SA_H_
|
|
|
|
typedef enum child_sa_state_t child_sa_state_t;
|
|
typedef struct child_sa_t child_sa_t;
|
|
|
|
#include <library.h>
|
|
#include <crypto/prf_plus.h>
|
|
#include <encoding/payloads/proposal_substructure.h>
|
|
#include <config/proposal.h>
|
|
#include <config/child_cfg.h>
|
|
|
|
/**
|
|
* States of a CHILD_SA
|
|
*/
|
|
enum child_sa_state_t {
|
|
|
|
/**
|
|
* Just created, uninstalled CHILD_SA
|
|
*/
|
|
CHILD_CREATED,
|
|
|
|
/**
|
|
* Installed SPD, but no SAD entries
|
|
*/
|
|
CHILD_ROUTED,
|
|
|
|
/**
|
|
* Installed an in-use CHILD_SA
|
|
*/
|
|
CHILD_INSTALLED,
|
|
|
|
/**
|
|
* While updating hosts, in update_hosts()
|
|
*/
|
|
CHILD_UPDATING,
|
|
|
|
/**
|
|
* CHILD_SA which is rekeying
|
|
*/
|
|
CHILD_REKEYING,
|
|
|
|
/**
|
|
* CHILD_SA in progress of delete
|
|
*/
|
|
CHILD_DELETING,
|
|
|
|
/**
|
|
* CHILD_SA object gets destroyed
|
|
*/
|
|
CHILD_DESTROYING,
|
|
};
|
|
|
|
/**
|
|
* enum strings for child_sa_state_t.
|
|
*/
|
|
extern enum_name_t *child_sa_state_names;
|
|
|
|
/**
|
|
* Represents an IPsec SAs between two hosts.
|
|
*
|
|
* A child_sa_t contains two SAs. SAs for both
|
|
* directions are managed in one child_sa_t object. Both
|
|
* SAs and the policies have the same reqid.
|
|
*
|
|
* The procedure for child sa setup is as follows:
|
|
* - A gets SPIs for a proposal via child_sa_t.alloc
|
|
* - A send the updated proposal to B
|
|
* - B selects a suitable proposal
|
|
* - B calls child_sa_t.add to add and update the selected proposal
|
|
* - B sends the updated proposal to A
|
|
* - A calls child_sa_t.update to update the already allocated SPIs with the chosen proposal
|
|
*
|
|
* Once SAs are set up, policies can be added using add_policies.
|
|
*/
|
|
struct child_sa_t {
|
|
|
|
/**
|
|
* Get the name of the config this CHILD_SA uses.
|
|
*
|
|
* @return name
|
|
*/
|
|
char* (*get_name) (child_sa_t *this);
|
|
|
|
/**
|
|
* Get the reqid of the CHILD SA.
|
|
*
|
|
* Every CHILD_SA has a reqid. The kernel uses this ID to
|
|
* identify it.
|
|
*
|
|
* @return reqid of the CHILD SA
|
|
*/
|
|
u_int32_t (*get_reqid)(child_sa_t *this);
|
|
|
|
/**
|
|
* Get the SPI of this CHILD_SA.
|
|
*
|
|
* Set the boolean parameter inbound to TRUE to
|
|
* get the SPI for which we receive packets, use
|
|
* FALSE to get those we use for sending packets.
|
|
*
|
|
* @param inbound TRUE to get inbound SPI, FALSE for outbound.
|
|
* @return SPI of the CHILD SA
|
|
*/
|
|
u_int32_t (*get_spi) (child_sa_t *this, bool inbound);
|
|
|
|
/**
|
|
* Get the CPI of this CHILD_SA.
|
|
*
|
|
* Set the boolean parameter inbound to TRUE to
|
|
* get the CPI for which we receive packets, use
|
|
* FALSE to get those we use for sending packets.
|
|
*
|
|
* @param inbound TRUE to get inbound CPI, FALSE for outbound.
|
|
* @return CPI of the CHILD SA
|
|
*/
|
|
u_int16_t (*get_cpi) (child_sa_t *this, bool inbound);
|
|
|
|
/**
|
|
* Get the protocol which this CHILD_SA uses to protect traffic.
|
|
*
|
|
* @return AH | ESP
|
|
*/
|
|
protocol_id_t (*get_protocol) (child_sa_t *this);
|
|
|
|
/**
|
|
* Get the IPsec mode of this CHILD_SA.
|
|
*
|
|
* @return TUNNEL | TRANSPORT | BEET
|
|
*/
|
|
ipsec_mode_t (*get_mode)(child_sa_t *this);
|
|
|
|
/**
|
|
* Get the used IPComp algorithm.
|
|
*
|
|
* @return IPComp compression algorithm.
|
|
*/
|
|
ipcomp_transform_t (*get_ipcomp)(child_sa_t *this);
|
|
|
|
/**
|
|
* Check if this CHILD_SA uses UDP encapsulation.
|
|
*
|
|
* @return TRUE if SA encapsulates ESP packets
|
|
*/
|
|
bool (*has_encap)(child_sa_t *this);
|
|
|
|
/**
|
|
* Get the lifetime of the CHILD_SA.
|
|
*
|
|
* @param hard TRUE for hard lifetime, FALSE for soft (rekey) lifetime
|
|
* @return lifetime in seconds
|
|
*/
|
|
u_int32_t (*get_lifetime)(child_sa_t *this, bool hard);
|
|
|
|
/**
|
|
* Get last use time of the CHILD_SA.
|
|
*
|
|
* @param inbound TRUE for inbound traffic, FALSE for outbound
|
|
* @return time of last use in seconds
|
|
*/
|
|
u_int32_t (*get_usetime)(child_sa_t *this, bool inbound);
|
|
|
|
/**
|
|
* Allocate SPIs for given proposals.
|
|
*
|
|
* Since the kernel manages SPIs for us, we need
|
|
* to allocate them. If a proposal contains more
|
|
* than one protocol, for each protocol an SPI is
|
|
* allocated. SPIs are stored internally and written
|
|
* back to the proposal.
|
|
*
|
|
* @param proposals list of proposals for which SPIs are allocated
|
|
*/
|
|
status_t (*alloc)(child_sa_t *this, linked_list_t* proposals);
|
|
|
|
/**
|
|
* Install the kernel SAs for a proposal, without previous SPI allocation.
|
|
*
|
|
* @param proposal proposal for which SPIs are allocated
|
|
* @param mode mode for the CHILD_SA
|
|
* @param integ_in integrity key for inbound traffic
|
|
* @param integ_out integrity key for outbound traffic
|
|
* @param encr_in encryption key for inbound traffic
|
|
* @param enc_out encryption key for outbound traffic
|
|
* @return SUCCESS or FAILED
|
|
*/
|
|
status_t (*add)(child_sa_t *this, proposal_t *proposal, ipsec_mode_t mode,
|
|
chunk_t integ_in, chunk_t integ_out,
|
|
chunk_t encr_in, chunk_t encr_out);
|
|
/**
|
|
* Install the kernel SAs for a proposal, after SPIs have been allocated.
|
|
*
|
|
* Updates an SA, for which SPIs are already allocated via alloc().
|
|
*
|
|
* @param proposal proposal for which SPIs are allocated
|
|
* @param mode mode for the CHILD_SA
|
|
* @param integ_in integrity key for inbound traffic
|
|
* @param integ_out integrity key for outbound traffic
|
|
* @param encr_in encryption key for inbound traffic
|
|
* @param enc_out encryption key for outbound traffic
|
|
* @return SUCCESS or FAILED
|
|
*/
|
|
status_t (*update)(child_sa_t *this, proposal_t *proposal, ipsec_mode_t mode,
|
|
chunk_t integ_in, chunk_t integ_out,
|
|
chunk_t encr_in, chunk_t encr_out);
|
|
/**
|
|
* Get the selected proposal passed to add()/update().
|
|
*
|
|
* @return selected proposal
|
|
*/
|
|
proposal_t* (*get_proposal)(child_sa_t *this);
|
|
|
|
/**
|
|
* Update the hosts in the kernel SAs and policies.
|
|
*
|
|
* The CHILD must be INSTALLED to do this update.
|
|
*
|
|
* @param me the new local host
|
|
* @param other the new remote host
|
|
* @param vip virtual IP, if any
|
|
* @param TRUE to use UDP encapsulation for NAT traversal
|
|
* @return SUCCESS or FAILED
|
|
*/
|
|
status_t (*update_hosts)(child_sa_t *this, host_t *me, host_t *other,
|
|
host_t *vip, bool encap);
|
|
|
|
/**
|
|
* Install the policies using some traffic selectors.
|
|
*
|
|
* Supplied lists of traffic_selector_t's specify the policies
|
|
* to use for this child sa.
|
|
*
|
|
* @param my_ts traffic selectors for local site
|
|
* @param other_ts traffic selectors for remote site
|
|
* @param mode mode for the SA: tunnel/transport
|
|
* @param proto protocol for policy, ESP/AH
|
|
* @return SUCCESS or FAILED
|
|
*/
|
|
status_t (*add_policies)(child_sa_t *this, linked_list_t *my_ts_list,
|
|
linked_list_t *other_ts_list, ipsec_mode_t mode,
|
|
protocol_id_t proto);
|
|
|
|
/**
|
|
* Get the traffic selectors of added policies of local host.
|
|
*
|
|
* @param local TRUE for own traffic selectors, FALSE for remote
|
|
* @return list of traffic selectors
|
|
*/
|
|
linked_list_t* (*get_traffic_selectors) (child_sa_t *this, bool local);
|
|
|
|
/**
|
|
* Create an enumerator over installed policies.
|
|
*
|
|
* @return enumerator over pairs of traffic selectors.
|
|
*/
|
|
enumerator_t* (*create_policy_enumerator)(child_sa_t *this);
|
|
|
|
/**
|
|
* Get the state of the CHILD_SA.
|
|
*/
|
|
child_sa_state_t (*get_state) (child_sa_t *this);
|
|
|
|
/**
|
|
* Set the state of the CHILD_SA.
|
|
*
|
|
* @param state state to set on CHILD_SA
|
|
*/
|
|
void (*set_state) (child_sa_t *this, child_sa_state_t state);
|
|
|
|
/**
|
|
* Get the config used to set up this child sa.
|
|
*
|
|
* @return child_cfg
|
|
*/
|
|
child_cfg_t* (*get_config) (child_sa_t *this);
|
|
|
|
/**
|
|
* Activate IPComp by setting the transform ID and CPI values.
|
|
*
|
|
* @param ipcomp the IPComp transform to use
|
|
* @param other_cpi other Compression Parameter Index
|
|
*/
|
|
void (*activate_ipcomp) (child_sa_t *this, ipcomp_transform_t ipcomp,
|
|
u_int16_t other_cpi);
|
|
|
|
/**
|
|
* Returns the Compression Parameter Index (CPI) allocated from the kernel.
|
|
*
|
|
* @return allocated CPI
|
|
*/
|
|
u_int16_t (*allocate_cpi) (child_sa_t *this);
|
|
|
|
/**
|
|
* Destroys a child_sa.
|
|
*/
|
|
void (*destroy) (child_sa_t *this);
|
|
};
|
|
|
|
/**
|
|
* Constructor to create a new child_sa_t.
|
|
*
|
|
* @param me own address
|
|
* @param other remote address
|
|
* @param my_id id of own peer
|
|
* @param other_id id of remote peer
|
|
* @param config config to use for this CHILD_SA
|
|
* @param reqid reqid of old CHILD_SA when rekeying, 0 otherwise
|
|
* @param encap TRUE to enable UDP encapsulation (NAT traversal)
|
|
* @return child_sa_t object
|
|
*/
|
|
child_sa_t * child_sa_create(host_t *me, host_t *other, child_cfg_t *config,
|
|
u_int32_t reqid, bool encap);
|
|
|
|
#endif /*CHILD_SA_H_ @} */
|