Use enum to define IKE version on peer_cfg_t.

Replaced all those magic numbers.
This commit is contained in:
Tobias Brunner
2012-03-20 17:30:41 +01:00
parent 3238faf8e6
commit f7a8fcedc0
17 changed files with 63 additions and 41 deletions
+1 -1
View File
@@ -251,7 +251,7 @@ static peer_cfg_t *load_peer_config(private_config_t *this,
uintptr_t strength; uintptr_t strength;
ike_cfg = load_ike_config(this, settings, config); ike_cfg = load_ike_config(this, settings, config);
peer_cfg = peer_cfg_create(config, 2, ike_cfg, CERT_ALWAYS_SEND, peer_cfg = peer_cfg_create(config, IKEV2, ike_cfg, CERT_ALWAYS_SEND,
UNIQUE_NO, 1, 0, 0, 0, 0, FALSE, 0, UNIQUE_NO, 1, 0, 0, 0, 0, FALSE, 0,
NULL, NULL, FALSE, NULL, NULL); NULL, NULL, FALSE, NULL, NULL);
+14 -9
View File
@@ -25,6 +25,11 @@
#include <utils/linked_list.h> #include <utils/linked_list.h>
#include <utils/identification.h> #include <utils/identification.h>
ENUM(ike_version_names, IKEV1, IKEV2,
"IKEv1",
"IKEv2",
);
ENUM(cert_policy_names, CERT_ALWAYS_SEND, CERT_NEVER_SEND, ENUM(cert_policy_names, CERT_ALWAYS_SEND, CERT_NEVER_SEND,
"CERT_ALWAYS_SEND", "CERT_ALWAYS_SEND",
"CERT_SEND_IF_ASKED", "CERT_SEND_IF_ASKED",
@@ -62,7 +67,7 @@ struct private_peer_cfg_t {
/** /**
* IKE version to use for initiation * IKE version to use for initiation
*/ */
u_int ike_version; ike_version_t ike_version;
/** /**
* IKE config associated to this peer config * IKE config associated to this peer config
@@ -169,7 +174,7 @@ METHOD(peer_cfg_t, get_name, char*,
return this->name; return this->name;
} }
METHOD(peer_cfg_t, get_ike_version, u_int, METHOD(peer_cfg_t, get_ike_version, ike_version_t,
private_peer_cfg_t *this) private_peer_cfg_t *this)
{ {
return this->ike_version; return this->ike_version;
@@ -563,13 +568,13 @@ METHOD(peer_cfg_t, destroy, void,
/* /*
* Described in header-file * Described in header-file
*/ */
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, ike_version_t ike_version,
cert_policy_t cert_policy, unique_policy_t unique, ike_cfg_t *ike_cfg, cert_policy_t cert_policy,
u_int32_t keyingtries, u_int32_t rekey_time, unique_policy_t unique, u_int32_t keyingtries,
u_int32_t reauth_time, u_int32_t jitter_time, u_int32_t rekey_time, u_int32_t reauth_time,
u_int32_t over_time, bool mobike, u_int32_t dpd, u_int32_t jitter_time, u_int32_t over_time,
host_t *virtual_ip, char *pool, bool mobike, u_int32_t dpd, host_t *virtual_ip,
bool mediation, peer_cfg_t *mediated_by, char *pool, bool mediation, peer_cfg_t *mediated_by,
identification_t *peer_id) identification_t *peer_id)
{ {
private_peer_cfg_t *this; private_peer_cfg_t *this;
+24 -8
View File
@@ -23,6 +23,7 @@
#ifndef PEER_CFG_H_ #ifndef PEER_CFG_H_
#define PEER_CFG_H_ #define PEER_CFG_H_
typedef enum ike_version_t ike_version_t;
typedef enum cert_policy_t cert_policy_t; typedef enum cert_policy_t cert_policy_t;
typedef enum unique_policy_t unique_policy_t; typedef enum unique_policy_t unique_policy_t;
typedef struct peer_cfg_t peer_cfg_t; typedef struct peer_cfg_t peer_cfg_t;
@@ -38,6 +39,21 @@ typedef struct peer_cfg_t peer_cfg_t;
#include <sa/authenticators/eap/eap_method.h> #include <sa/authenticators/eap/eap_method.h>
#include <credentials/auth_cfg.h> #include <credentials/auth_cfg.h>
/**
* IKE version.
*/
enum ike_version_t {
/** IKE version 1 */
IKEV1 = 1,
/** IKE version 2 */
IKEV2 = 2,
};
/**
* enum strings fro ike_version_t
*/
extern enum_name_t *ike_version_names;
/** /**
* Certificate sending policy. This is also used for certificate * Certificate sending policy. This is also used for certificate
* requests when using this definition for the other peer. If * requests when using this definition for the other peer. If
@@ -130,7 +146,7 @@ struct peer_cfg_t {
* *
* @return IKE major version * @return IKE major version
*/ */
u_int (*get_ike_version)(peer_cfg_t *this); ike_version_t (*get_ike_version)(peer_cfg_t *this);
/** /**
* Get the IKE config to use for initiaton. * Get the IKE config to use for initiaton.
@@ -347,13 +363,13 @@ struct peer_cfg_t {
* @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, ike_version_t ike_version,
cert_policy_t cert_policy, unique_policy_t unique, ike_cfg_t *ike_cfg, cert_policy_t cert_policy,
u_int32_t keyingtries, u_int32_t rekey_time, unique_policy_t unique, u_int32_t keyingtries,
u_int32_t reauth_time, u_int32_t jitter_time, u_int32_t rekey_time, u_int32_t reauth_time,
u_int32_t over_time, bool mobike, u_int32_t dpd, u_int32_t jitter_time, u_int32_t over_time,
host_t *virtual_ip, char *pool, bool mobike, u_int32_t dpd, host_t *virtual_ip,
bool mediation, peer_cfg_t *mediated_by, char *pool, bool mediation, peer_cfg_t *mediated_by,
identification_t *peer_id); identification_t *peer_id);
#endif /** PEER_CFG_H_ @}*/ #endif /** PEER_CFG_H_ @}*/
@@ -273,7 +273,7 @@ static job_requeue_t initiate(private_android_service_t *this)
hostname, IKEV2_UDP_PORT); hostname, IKEV2_UDP_PORT);
ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE)); ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
peer_cfg = peer_cfg_create("android", 2, ike_cfg, CERT_SEND_IF_ASKED, peer_cfg = peer_cfg_create("android", IKEV2, ike_cfg, CERT_SEND_IF_ASKED,
UNIQUE_REPLACE, 1, /* keyingtries */ UNIQUE_REPLACE, 1, /* keyingtries */
36000, 0, /* rekey 10h, reauth none */ 36000, 0, /* rekey 10h, reauth none */
600, 600, /* jitter, over 10min */ 600, 600, /* jitter, over 10min */
+1 -1
View File
@@ -206,7 +206,7 @@ static void setup_tunnel(private_ha_tunnel_t *this,
ike_cfg = ike_cfg_create(FALSE, FALSE, local, IKEV2_UDP_PORT, ike_cfg = ike_cfg_create(FALSE, FALSE, local, IKEV2_UDP_PORT,
remote, IKEV2_UDP_PORT); remote, IKEV2_UDP_PORT);
ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE)); ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
peer_cfg = peer_cfg_create("ha", 2, ike_cfg, CERT_NEVER_SEND, peer_cfg = peer_cfg_create("ha", IKEV2, ike_cfg, CERT_NEVER_SEND,
UNIQUE_KEEP, 0, 86400, 0, 7200, 3600, FALSE, 30, UNIQUE_KEEP, 0, 86400, 0, 7200, 3600, FALSE, 30,
NULL, NULL, FALSE, NULL, NULL); NULL, NULL, FALSE, NULL, NULL);
@@ -249,7 +249,7 @@ static peer_cfg_t* generate_config(private_load_tester_config_t *this, uint num)
"0.0.0.0", IKEV2_UDP_PORT, this->remote, IKEV2_UDP_PORT); "0.0.0.0", IKEV2_UDP_PORT, this->remote, IKEV2_UDP_PORT);
} }
ike_cfg->add_proposal(ike_cfg, this->proposal->clone(this->proposal)); ike_cfg->add_proposal(ike_cfg, this->proposal->clone(this->proposal));
peer_cfg = peer_cfg_create("load-test", 2, ike_cfg, peer_cfg = peer_cfg_create("load-test", IKEV2, ike_cfg,
CERT_SEND_IF_ASKED, UNIQUE_NO, 1, /* keytries */ CERT_SEND_IF_ASKED, UNIQUE_NO, 1, /* keytries */
this->ike_rekey, 0, /* rekey, reauth */ this->ike_rekey, 0, /* rekey, reauth */
0, this->ike_rekey, /* jitter, overtime */ 0, this->ike_rekey, /* jitter, overtime */
+2 -1
View File
@@ -327,7 +327,8 @@ static gboolean initiate_connection(private_maemo_service_t *this,
hostname, IKEV2_UDP_PORT); hostname, IKEV2_UDP_PORT);
ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE)); ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
peer_cfg = peer_cfg_create(this->current, 2, ike_cfg, CERT_SEND_IF_ASKED, peer_cfg = peer_cfg_create(this->current, IKEV2, ike_cfg,
CERT_SEND_IF_ASKED,
UNIQUE_REPLACE, 1, /* keyingtries */ UNIQUE_REPLACE, 1, /* keyingtries */
36000, 0, /* rekey 10h, reauth none */ 36000, 0, /* rekey 10h, reauth none */
600, 600, /* jitter, over 10min */ 600, 600, /* jitter, over 10min */
+3 -3
View File
@@ -122,7 +122,7 @@ METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
"0.0.0.0", IKEV2_UDP_PORT, address, IKEV2_UDP_PORT); "0.0.0.0", IKEV2_UDP_PORT, address, IKEV2_UDP_PORT);
ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE)); ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
med_cfg = peer_cfg_create( med_cfg = peer_cfg_create(
"mediation", 2, ike_cfg, "mediation", IKEV2, ike_cfg,
CERT_NEVER_SEND, UNIQUE_REPLACE, CERT_NEVER_SEND, UNIQUE_REPLACE,
1, this->rekey*60, 0, /* keytries, rekey, reauth */ 1, this->rekey*60, 0, /* keytries, rekey, reauth */
this->rekey*5, this->rekey*3, /* jitter, overtime */ this->rekey*5, this->rekey*3, /* jitter, overtime */
@@ -159,7 +159,7 @@ METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
return NULL; return NULL;
} }
peer_cfg = peer_cfg_create( peer_cfg = peer_cfg_create(
name, 2, this->ike->get_ref(this->ike), name, IKEV2, this->ike->get_ref(this->ike),
CERT_NEVER_SEND, UNIQUE_REPLACE, CERT_NEVER_SEND, UNIQUE_REPLACE,
1, this->rekey*60, 0, /* keytries, rekey, reauth */ 1, this->rekey*60, 0, /* keytries, rekey, reauth */
this->rekey*5, this->rekey*3, /* jitter, overtime */ this->rekey*5, this->rekey*3, /* jitter, overtime */
@@ -234,7 +234,7 @@ METHOD(enumerator_t, peer_enumerator_enumerate, bool,
return FALSE; return FALSE;
} }
this->current = peer_cfg_create( this->current = peer_cfg_create(
name, 2, this->ike->get_ref(this->ike), name, IKEV2, this->ike->get_ref(this->ike),
CERT_NEVER_SEND, UNIQUE_REPLACE, CERT_NEVER_SEND, UNIQUE_REPLACE,
1, this->rekey*60, 0, /* keytries, rekey, reauth */ 1, this->rekey*60, 0, /* keytries, rekey, reauth */
this->rekey*5, this->rekey*3, /* jitter, overtime */ this->rekey*5, this->rekey*3, /* jitter, overtime */
+1 -1
View File
@@ -88,7 +88,7 @@ METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
if (e->enumerate(e, &name)) if (e->enumerate(e, &name))
{ {
peer_cfg = peer_cfg_create( peer_cfg = peer_cfg_create(
name, 2, this->ike->get_ref(this->ike), name, IKEV2, this->ike->get_ref(this->ike),
CERT_NEVER_SEND, UNIQUE_REPLACE, CERT_NEVER_SEND, UNIQUE_REPLACE,
1, this->rekey*60, 0, /* keytries, rekey, reauth */ 1, this->rekey*60, 0, /* keytries, rekey, reauth */
this->rekey*5, this->rekey*3, /* jitter, overtime */ this->rekey*5, this->rekey*3, /* jitter, overtime */
+1 -1
View File
@@ -499,7 +499,7 @@ static gboolean connect_(NMVPNPlugin *plugin, NMConnection *connection,
ike_cfg = ike_cfg_create(TRUE, encap, ike_cfg = ike_cfg_create(TRUE, encap,
"0.0.0.0", IKEV2_UDP_PORT, (char*)address, IKEV2_UDP_PORT); "0.0.0.0", IKEV2_UDP_PORT, (char*)address, IKEV2_UDP_PORT);
ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE)); ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
peer_cfg = peer_cfg_create(priv->name, 2, ike_cfg, peer_cfg = peer_cfg_create(priv->name, IKEV2, ike_cfg,
CERT_SEND_IF_ASKED, UNIQUE_REPLACE, 1, /* keyingtries */ CERT_SEND_IF_ASKED, UNIQUE_REPLACE, 1, /* keyingtries */
36000, 0, /* rekey 10h, reauth none */ 36000, 0, /* rekey 10h, reauth none */
600, 600, /* jitter, over 10min */ 600, 600, /* jitter, over 10min */
+1 -1
View File
@@ -302,7 +302,7 @@ static void request_query_config(xmlTextReaderPtr reader, xmlTextWriterPtr write
ike_cfg_t *ike_cfg; ike_cfg_t *ike_cfg;
linked_list_t *list; linked_list_t *list;
if (peer_cfg->get_ike_version(peer_cfg) != 2) if (peer_cfg->get_ike_version(peer_cfg) != IKEV2)
{ /* only IKEv2 connections yet */ { /* only IKEv2 connections yet */
continue; continue;
} }
+1 -1
View File
@@ -368,7 +368,7 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
if (ike) if (ike)
{ {
peer_cfg = peer_cfg_create( peer_cfg = peer_cfg_create(
name, 2, ike, cert_policy, uniqueid, name, IKEV2, ike, cert_policy, uniqueid,
keyingtries, rekeytime, reauthtime, jitter, overtime, keyingtries, rekeytime, reauthtime, jitter, overtime,
mobike, dpd_delay, vip, pool, mobike, dpd_delay, vip, pool,
mediation, mediated_cfg, peer_id); mediation, mediated_cfg, peer_id);
+1 -1
View File
@@ -670,7 +670,7 @@ static peer_cfg_t *build_peer_cfg(private_stroke_config_t *this,
* the pool name as the connection name, which the attribute provider * the pool name as the connection name, which the attribute provider
* uses to serve pool addresses. */ * uses to serve pool addresses. */
peer_cfg = peer_cfg_create(msg->add_conn.name, peer_cfg = peer_cfg_create(msg->add_conn.name,
msg->add_conn.ikev2 ? 2 : 1, ike_cfg, msg->add_conn.ikev2 ? IKEV2 : IKEV1, ike_cfg,
msg->add_conn.me.sendcert, unique, msg->add_conn.me.sendcert, unique,
msg->add_conn.rekey.tries, rekey, reauth, jitter, over, msg->add_conn.rekey.tries, rekey, reauth, jitter, over,
msg->add_conn.mobike, msg->add_conn.dpd.delay, msg->add_conn.mobike, msg->add_conn.dpd.delay,
@@ -126,10 +126,10 @@ METHOD(stroke_control_t, initiate, void,
msg->initiate.name); msg->initiate.name);
if (peer_cfg) if (peer_cfg)
{ {
if (peer_cfg->get_ike_version(peer_cfg) != 2) if (peer_cfg->get_ike_version(peer_cfg) != IKEV2)
{ {
DBG1(DBG_CFG, "ignoring initiation request for IKEv%d config", DBG1(DBG_CFG, "ignoring initiation request for %N config",
peer_cfg->get_ike_version(peer_cfg)); ike_version_names, peer_cfg->get_ike_version(peer_cfg));
peer_cfg->destroy(peer_cfg); peer_cfg->destroy(peer_cfg);
return; return;
} }
@@ -161,7 +161,7 @@ METHOD(stroke_control_t, initiate, void,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
while (enumerator->enumerate(enumerator, &peer_cfg)) while (enumerator->enumerate(enumerator, &peer_cfg))
{ {
if (peer_cfg->get_ike_version(peer_cfg) != 2) if (peer_cfg->get_ike_version(peer_cfg) != IKEV2)
{ {
continue; continue;
} }
@@ -568,10 +568,10 @@ METHOD(stroke_control_t, route, void,
msg->route.name); msg->route.name);
if (peer_cfg) if (peer_cfg)
{ {
if (peer_cfg->get_ike_version(peer_cfg) != 2) if (peer_cfg->get_ike_version(peer_cfg) != IKEV2)
{ {
DBG1(DBG_CFG, "ignoring initiation request for IKEv%d config", DBG1(DBG_CFG, "ignoring initiation request for %N config",
peer_cfg->get_ike_version(peer_cfg)); ike_version_names, peer_cfg->get_ike_version(peer_cfg));
peer_cfg->destroy(peer_cfg); peer_cfg->destroy(peer_cfg);
return; return;
} }
@@ -603,7 +603,7 @@ METHOD(stroke_control_t, route, void,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
while (enumerator->enumerate(enumerator, &peer_cfg)) while (enumerator->enumerate(enumerator, &peer_cfg))
{ {
if (peer_cfg->get_ike_version(peer_cfg) != 2) if (peer_cfg->get_ike_version(peer_cfg) != IKEV2)
{ {
continue; continue;
} }
+1 -1
View File
@@ -489,7 +489,7 @@ METHOD(stroke_list_t, status, void,
charon->backends, NULL, NULL, NULL, NULL); charon->backends, NULL, NULL, NULL, NULL);
while (enumerator->enumerate(enumerator, &peer_cfg)) while (enumerator->enumerate(enumerator, &peer_cfg))
{ {
if (peer_cfg->get_ike_version(peer_cfg) != 2 || if (peer_cfg->get_ike_version(peer_cfg) != IKEV2 ||
(name && !streq(name, peer_cfg->get_name(peer_cfg)))) (name && !streq(name, peer_cfg->get_name(peer_cfg))))
{ {
continue; continue;
+1 -1
View File
@@ -172,7 +172,7 @@ METHOD(enumerator_t, peer_enumerator_enumerate, bool,
local_addr, IKEV2_UDP_PORT, remote_addr, IKEV2_UDP_PORT); local_addr, IKEV2_UDP_PORT, remote_addr, IKEV2_UDP_PORT);
ike_cfg->add_proposal(ike_cfg, create_proposal(ike_proposal, PROTO_IKE)); ike_cfg->add_proposal(ike_cfg, create_proposal(ike_proposal, PROTO_IKE));
this->peer_cfg = peer_cfg_create( this->peer_cfg = peer_cfg_create(
name, 2, ike_cfg, CERT_SEND_IF_ASKED, UNIQUE_NO, name, IKEV2, ike_cfg, CERT_SEND_IF_ASKED, UNIQUE_NO,
1, create_rekey(ike_rekey), 0, /* keytries, rekey, reauth */ 1, create_rekey(ike_rekey), 0, /* keytries, rekey, reauth */
1800, 900, /* jitter, overtime */ 1800, 900, /* jitter, overtime */
TRUE, 60, /* mobike, dpddelay */ TRUE, 60, /* mobike, dpddelay */
@@ -49,7 +49,7 @@ METHOD(job_t, execute, void,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
while (enumerator->enumerate(enumerator, &peer_cfg)) while (enumerator->enumerate(enumerator, &peer_cfg))
{ {
if (peer_cfg->get_ike_version(peer_cfg) != 2) if (peer_cfg->get_ike_version(peer_cfg) != IKEV2)
{ {
continue; continue;
} }