Migrated peer_cfg_t to INIT/METHOD macros.

This commit is contained in:
Tobias Brunner
2011-08-03 15:17:34 +02:00
parent 61e13630f8
commit 6b444c5934
2 changed files with 122 additions and 173 deletions
+117 -169
View File
@@ -163,34 +163,26 @@ struct private_peer_cfg_t {
#endif /* ME */ #endif /* ME */
}; };
/** METHOD(peer_cfg_t, get_name, char*,
* Implementation of peer_cfg_t.get_name private_peer_cfg_t *this)
*/
static char *get_name(private_peer_cfg_t *this)
{ {
return this->name; return this->name;
} }
/** METHOD(peer_cfg_t, get_ike_version, u_int,
* Implementation of peer_cfg_t.get_ike_version private_peer_cfg_t *this)
*/
static u_int get_ike_version(private_peer_cfg_t *this)
{ {
return this->ike_version; return this->ike_version;
} }
/** METHOD(peer_cfg_t, get_ike_cfg, ike_cfg_t*,
* Implementation of peer_cfg_t.get_ike_cfg private_peer_cfg_t *this)
*/
static ike_cfg_t* get_ike_cfg(private_peer_cfg_t *this)
{ {
return this->ike_cfg; return this->ike_cfg;
} }
/** METHOD(peer_cfg_t, add_child_cfg, void,
* Implementation of peer_cfg_t.add_child_cfg. private_peer_cfg_t *this, child_cfg_t *child_cfg)
*/
static void add_child_cfg(private_peer_cfg_t *this, child_cfg_t *child_cfg)
{ {
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
this->child_cfgs->insert_last(this->child_cfgs, child_cfg); this->child_cfgs->insert_last(this->child_cfgs, child_cfg);
@@ -206,44 +198,39 @@ typedef struct {
mutex_t *mutex; mutex_t *mutex;
} child_cfg_enumerator_t; } child_cfg_enumerator_t;
/** METHOD(peer_cfg_t, remove_child_cfg, void,
* Implementation of peer_cfg_t.remove_child_cfg. private_peer_cfg_t *this, child_cfg_enumerator_t *enumerator)
*/
static void remove_child_cfg(private_peer_cfg_t *this,
child_cfg_enumerator_t *enumerator)
{ {
this->child_cfgs->remove_at(this->child_cfgs, enumerator->wrapped); this->child_cfgs->remove_at(this->child_cfgs, enumerator->wrapped);
} }
/** METHOD(enumerator_t, child_cfg_enumerator_destroy, void,
* Implementation of child_cfg_enumerator_t.destroy child_cfg_enumerator_t *this)
*/
static void child_cfg_enumerator_destroy(child_cfg_enumerator_t *this)
{ {
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
this->wrapped->destroy(this->wrapped); this->wrapped->destroy(this->wrapped);
free(this); free(this);
} }
/** METHOD(enumerator_t, child_cfg_enumerate, bool,
* Implementation of child_cfg_enumerator_t.enumerate child_cfg_enumerator_t *this, child_cfg_t **chd)
*/
static bool child_cfg_enumerate(child_cfg_enumerator_t *this, child_cfg_t **chd)
{ {
return this->wrapped->enumerate(this->wrapped, chd); return this->wrapped->enumerate(this->wrapped, chd);
} }
/** METHOD(peer_cfg_t, create_child_cfg_enumerator, enumerator_t*,
* Implementation of peer_cfg_t.create_child_cfg_enumerator. private_peer_cfg_t *this)
*/
static enumerator_t* create_child_cfg_enumerator(private_peer_cfg_t *this)
{ {
child_cfg_enumerator_t *enumerator = malloc_thing(child_cfg_enumerator_t); child_cfg_enumerator_t *enumerator;
enumerator->public.enumerate = (void*)child_cfg_enumerate; INIT(enumerator,
enumerator->public.destroy = (void*)child_cfg_enumerator_destroy; .public = {
enumerator->mutex = this->mutex; .enumerate = (void*)_child_cfg_enumerate,
enumerator->wrapped = this->child_cfgs->create_enumerator(this->child_cfgs); .destroy = (void*)_child_cfg_enumerator_destroy,
},
.mutex = this->mutex,
.wrapped = this->child_cfgs->create_enumerator(this->child_cfgs),
);
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
return &enumerator->public; return &enumerator->public;
@@ -292,13 +279,9 @@ static int get_ts_match(child_cfg_t *cfg, bool local,
return match; return match;
} }
/** METHOD(peer_cfg_t, select_child_cfg, child_cfg_t*,
* Implementation of peer_cfg_t.select_child_cfg private_peer_cfg_t *this, linked_list_t *my_ts, linked_list_t *other_ts,
*/ host_t *my_host, host_t *other_host)
static child_cfg_t* select_child_cfg(private_peer_cfg_t *this,
linked_list_t *my_ts,
linked_list_t *other_ts,
host_t *my_host, host_t *other_host)
{ {
child_cfg_t *current, *found = NULL; child_cfg_t *current, *found = NULL;
enumerator_t *enumerator; enumerator_t *enumerator;
@@ -334,34 +317,26 @@ static child_cfg_t* select_child_cfg(private_peer_cfg_t *this,
return found; return found;
} }
/** METHOD(peer_cfg_t, get_cert_policy, cert_policy_t,
* Implementation of peer_cfg_t.get_cert_policy. private_peer_cfg_t *this)
*/
static cert_policy_t get_cert_policy(private_peer_cfg_t *this)
{ {
return this->cert_policy; return this->cert_policy;
} }
/** METHOD(peer_cfg_t, get_unique_policy, unique_policy_t,
* Implementation of peer_cfg_t.get_unique_policy. private_peer_cfg_t *this)
*/
static unique_policy_t get_unique_policy(private_peer_cfg_t *this)
{ {
return this->unique; return this->unique;
} }
/** METHOD(peer_cfg_t, get_keyingtries, u_int32_t,
* Implementation of peer_cfg_t.get_keyingtries. private_peer_cfg_t *this)
*/
static u_int32_t get_keyingtries(private_peer_cfg_t *this)
{ {
return this->keyingtries; return this->keyingtries;
} }
/** METHOD(peer_cfg_t, get_rekey_time, u_int32_t,
* Implementation of peer_cfg_t.get_rekey_time. private_peer_cfg_t *this)
*/
static u_int32_t get_rekey_time(private_peer_cfg_t *this)
{ {
if (this->rekey_time == 0) if (this->rekey_time == 0)
{ {
@@ -374,10 +349,8 @@ static u_int32_t get_rekey_time(private_peer_cfg_t *this)
return this->rekey_time - (random() % this->jitter_time); return this->rekey_time - (random() % this->jitter_time);
} }
/** METHOD(peer_cfg_t, get_reauth_time, u_int32_t,
* Implementation of peer_cfg_t.get_reauth_time. private_peer_cfg_t *this)
*/
static u_int32_t get_reauth_time(private_peer_cfg_t *this)
{ {
if (this->reauth_time == 0) if (this->reauth_time == 0)
{ {
@@ -390,51 +363,38 @@ static u_int32_t get_reauth_time(private_peer_cfg_t *this)
return this->reauth_time - (random() % this->jitter_time); return this->reauth_time - (random() % this->jitter_time);
} }
/** METHOD(peer_cfg_t, get_over_time, u_int32_t,
* Implementation of peer_cfg_t.get_over_time. private_peer_cfg_t *this)
*/
static u_int32_t get_over_time(private_peer_cfg_t *this)
{ {
return this->over_time; return this->over_time;
} }
/** METHOD(peer_cfg_t, use_mobike, bool,
* Implementation of peer_cfg_t.use_mobike. private_peer_cfg_t *this)
*/
static bool use_mobike(private_peer_cfg_t *this)
{ {
return this->use_mobike; return this->use_mobike;
} }
/** METHOD(peer_cfg_t, get_dpd, u_int32_t,
* Implements peer_cfg_t.get_dpd private_peer_cfg_t *this)
*/
static u_int32_t get_dpd(private_peer_cfg_t *this)
{ {
return this->dpd; return this->dpd;
} }
/** METHOD(peer_cfg_t, get_virtual_ip, host_t*,
* Implementation of peer_cfg_t.get_virtual_ip. private_peer_cfg_t *this)
*/
static host_t* get_virtual_ip(private_peer_cfg_t *this)
{ {
return this->virtual_ip; return this->virtual_ip;
} }
/** METHOD(peer_cfg_t, get_pool, char*,
* Implementation of peer_cfg_t.get_pool. private_peer_cfg_t *this)
*/
static char* get_pool(private_peer_cfg_t *this)
{ {
return this->pool; return this->pool;
} }
/** METHOD(peer_cfg_t, add_auth_cfg, void,
* Implementation of peer_cfg_t.add_auth_cfg private_peer_cfg_t *this, auth_cfg_t *cfg, bool local)
*/
static void add_auth_cfg(private_peer_cfg_t *this,
auth_cfg_t *cfg, bool local)
{ {
if (local) if (local)
{ {
@@ -446,11 +406,8 @@ static void add_auth_cfg(private_peer_cfg_t *this,
} }
} }
/** METHOD(peer_cfg_t, create_auth_cfg_enumerator, enumerator_t*,
* Implementation of peer_cfg_t.create_auth_cfg_enumerator private_peer_cfg_t *this, bool local)
*/
static enumerator_t* create_auth_cfg_enumerator(private_peer_cfg_t *this,
bool local)
{ {
if (local) if (local)
{ {
@@ -460,26 +417,20 @@ static enumerator_t* create_auth_cfg_enumerator(private_peer_cfg_t *this,
} }
#ifdef ME #ifdef ME
/** METHOD(peer_cfg_t, is_mediation, bool,
* Implementation of peer_cfg_t.is_mediation. private_peer_cfg_t *this)
*/
static bool is_mediation(private_peer_cfg_t *this)
{ {
return this->mediation; return this->mediation;
} }
/** METHOD(peer_cfg_t, get_mediated_by, peer_cfg_t*,
* Implementation of peer_cfg_t.get_mediated_by. private_peer_cfg_t *this)
*/
static peer_cfg_t* get_mediated_by(private_peer_cfg_t *this)
{ {
return this->mediated_by; return this->mediated_by;
} }
/** METHOD(peer_cfg_t, get_peer_id, identification_t*,
* Implementation of peer_cfg_t.get_peer_id. private_peer_cfg_t *this)
*/
static identification_t* get_peer_id(private_peer_cfg_t *this)
{ {
return this->peer_id; return this->peer_id;
} }
@@ -539,10 +490,8 @@ static bool auth_cfg_equal(private_peer_cfg_t *this, private_peer_cfg_t *other)
return equal; return equal;
} }
/** METHOD(peer_cfg_t, equals, bool,
* Implementation of peer_cfg_t.equals. private_peer_cfg_t *this, private_peer_cfg_t *other)
*/
static bool equals(private_peer_cfg_t *this, private_peer_cfg_t *other)
{ {
if (this == other) if (this == other)
{ {
@@ -580,19 +529,15 @@ static bool equals(private_peer_cfg_t *this, private_peer_cfg_t *other)
); );
} }
/** METHOD(peer_cfg_t, get_ref, peer_cfg_t*,
* Implements peer_cfg_t.get_ref. private_peer_cfg_t *this)
*/
static peer_cfg_t* get_ref(private_peer_cfg_t *this)
{ {
ref_get(&this->refcount); ref_get(&this->refcount);
return &this->public; return &this->public;
} }
/** METHOD(peer_cfg_t, destroy, void,
* Implements peer_cfg_t.destroy. private_peer_cfg_t *this)
*/
static void destroy(private_peer_cfg_t *this)
{ {
if (ref_put(&this->refcount)) if (ref_put(&this->refcount))
{ {
@@ -627,48 +572,8 @@ peer_cfg_t *peer_cfg_create(char *name, u_int ike_version, ike_cfg_t *ike_cfg,
bool mediation, peer_cfg_t *mediated_by, bool mediation, peer_cfg_t *mediated_by,
identification_t *peer_id) identification_t *peer_id)
{ {
private_peer_cfg_t *this = malloc_thing(private_peer_cfg_t); private_peer_cfg_t *this;
/* public functions */
this->public.get_name = (char* (*) (peer_cfg_t *))get_name;
this->public.get_ike_version = (u_int(*) (peer_cfg_t *))get_ike_version;
this->public.get_ike_cfg = (ike_cfg_t* (*) (peer_cfg_t *))get_ike_cfg;
this->public.add_child_cfg = (void (*) (peer_cfg_t *, child_cfg_t*))add_child_cfg;
this->public.remove_child_cfg = (void(*)(peer_cfg_t*, enumerator_t*))remove_child_cfg;
this->public.create_child_cfg_enumerator = (enumerator_t* (*) (peer_cfg_t *))create_child_cfg_enumerator;
this->public.select_child_cfg = (child_cfg_t* (*) (peer_cfg_t *,linked_list_t*,linked_list_t*,host_t*,host_t*))select_child_cfg;
this->public.get_cert_policy = (cert_policy_t (*) (peer_cfg_t *))get_cert_policy;
this->public.get_unique_policy = (unique_policy_t (*) (peer_cfg_t *))get_unique_policy;
this->public.get_keyingtries = (u_int32_t (*) (peer_cfg_t *))get_keyingtries;
this->public.get_rekey_time = (u_int32_t(*)(peer_cfg_t*))get_rekey_time;
this->public.get_reauth_time = (u_int32_t(*)(peer_cfg_t*))get_reauth_time;
this->public.get_over_time = (u_int32_t(*)(peer_cfg_t*))get_over_time;
this->public.use_mobike = (bool (*) (peer_cfg_t *))use_mobike;
this->public.get_dpd = (u_int32_t (*) (peer_cfg_t *))get_dpd;
this->public.get_virtual_ip = (host_t* (*) (peer_cfg_t *))get_virtual_ip;
this->public.get_pool = (char*(*)(peer_cfg_t*))get_pool;
this->public.add_auth_cfg = (void(*)(peer_cfg_t*, auth_cfg_t *cfg, bool local))add_auth_cfg;
this->public.create_auth_cfg_enumerator = (enumerator_t*(*)(peer_cfg_t*, bool local))create_auth_cfg_enumerator;
this->public.equals = (bool(*)(peer_cfg_t*, peer_cfg_t *other))equals;
this->public.get_ref = (peer_cfg_t*(*)(peer_cfg_t *))get_ref;
this->public.destroy = (void(*)(peer_cfg_t *))destroy;
#ifdef ME
this->public.is_mediation = (bool (*) (peer_cfg_t *))is_mediation;
this->public.get_mediated_by = (peer_cfg_t* (*) (peer_cfg_t *))get_mediated_by;
this->public.get_peer_id = (identification_t* (*) (peer_cfg_t *))get_peer_id;
#endif /* ME */
/* apply init values */
this->name = strdup(name);
this->ike_version = ike_version;
this->ike_cfg = ike_cfg;
this->child_cfgs = linked_list_create();
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
this->cert_policy = cert_policy;
this->unique = unique;
this->keyingtries = keyingtries;
this->rekey_time = rekey_time;
this->reauth_time = reauth_time;
if (rekey_time && jitter_time > rekey_time) if (rekey_time && jitter_time > rekey_time)
{ {
jitter_time = rekey_time; jitter_time = rekey_time;
@@ -677,15 +582,58 @@ peer_cfg_t *peer_cfg_create(char *name, u_int ike_version, ike_cfg_t *ike_cfg,
{ {
jitter_time = reauth_time; jitter_time = reauth_time;
} }
this->jitter_time = jitter_time;
this->over_time = over_time; INIT(this,
this->use_mobike = mobike; .public = {
this->dpd = dpd; .get_name = _get_name,
this->virtual_ip = virtual_ip; .get_ike_version = _get_ike_version,
this->pool = strdupnull(pool); .get_ike_cfg = _get_ike_cfg,
this->local_auth = linked_list_create(); .add_child_cfg = _add_child_cfg,
this->remote_auth = linked_list_create(); .remove_child_cfg = (void*)_remove_child_cfg,
this->refcount = 1; .create_child_cfg_enumerator = _create_child_cfg_enumerator,
.select_child_cfg = _select_child_cfg,
.get_cert_policy = _get_cert_policy,
.get_unique_policy = _get_unique_policy,
.get_keyingtries = _get_keyingtries,
.get_rekey_time = _get_rekey_time,
.get_reauth_time = _get_reauth_time,
.get_over_time = _get_over_time,
.use_mobike = _use_mobike,
.get_dpd = _get_dpd,
.get_virtual_ip = _get_virtual_ip,
.get_pool = _get_pool,
.add_auth_cfg = _add_auth_cfg,
.create_auth_cfg_enumerator = _create_auth_cfg_enumerator,
.equals = (void*)_equals,
.get_ref = _get_ref,
.destroy = _destroy,
#ifdef ME
.is_mediation = _is_mediation,
.get_mediated_by = _get_mediated_by,
.get_peer_id = _get_peer_id,
#endif /* ME */
},
.name = strdup(name),
.ike_version = ike_version,
.ike_cfg = ike_cfg,
.child_cfgs = linked_list_create(),
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
.cert_policy = cert_policy,
.unique = unique,
.keyingtries = keyingtries,
.rekey_time = rekey_time,
.reauth_time = reauth_time,
.jitter_time = jitter_time,
.over_time = over_time,
.use_mobike = mobike,
.dpd = dpd,
.virtual_ip = virtual_ip,
.pool = strdupnull(pool),
.local_auth = linked_list_create(),
.remote_auth = linked_list_create(),
.refcount = 1,
);
#ifdef ME #ifdef ME
this->mediation = mediation; this->mediation = mediation;
this->mediated_by = mediated_by; this->mediated_by = mediated_by;
+5 -4
View File
@@ -82,8 +82,9 @@ extern enum_name_t *unique_policy_names;
* Configuration of a peer, specified by IDs. * Configuration of a peer, specified by IDs.
* *
* The peer config defines a connection between two given IDs. It contains * The peer config defines a connection between two given IDs. It contains
* exactly one ike_cfg_t, which is use for initiation. Additionally, it contains * exactly one ike_cfg_t, which is used for initiation. Additionally, it
* multiple child_cfg_t defining which CHILD_SAs are allowed for this peer. * contains multiple child_cfg_t defining which CHILD_SAs are allowed for this
* peer.
* @verbatim * @verbatim
+-------------------+ +---------------+ +-------------------+ +---------------+
+---------------+ | peer_cfg | +---------------+ | +---------------+ | peer_cfg | +---------------+ |
@@ -127,7 +128,7 @@ struct peer_cfg_t {
/** /**
* Get the IKE version to use for initiating. * Get the IKE version to use for initiating.
* *
* @return IKE major version * @return IKE major version
*/ */
u_int (*get_ike_version)(peer_cfg_t *this); u_int (*get_ike_version)(peer_cfg_t *this);
@@ -344,7 +345,7 @@ struct peer_cfg_t {
* @param mediation TRUE if this is a mediation connection * @param mediation TRUE if this is a mediation connection
* @param mediated_by peer_cfg_t of the mediation connection to mediate through * @param mediated_by peer_cfg_t of the mediation connection to mediate through
* @param peer_id ID that identifies our peer at the mediation server * @param peer_id ID that identifies our peer at the mediation server
* @return peer_cfg_t object * @return peer_cfg_t object
*/ */
peer_cfg_t *peer_cfg_create(char *name, u_int ike_version, ike_cfg_t *ike_cfg, peer_cfg_t *peer_cfg_create(char *name, u_int ike_version, ike_cfg_t *ike_cfg,
cert_policy_t cert_policy, unique_policy_t unique, cert_policy_t cert_policy, unique_policy_t unique,