Use enum to define IKE version on peer_cfg_t.
authorTobias Brunner <tobias@strongswan.org>
Wed, 16 Nov 2011 16:28:06 +0000 (17:28 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 20 Mar 2012 16:30:41 +0000 (17:30 +0100)
Replaced all those magic numbers.

17 files changed:
src/conftest/config.c
src/libcharon/config/peer_cfg.c
src/libcharon/config/peer_cfg.h
src/libcharon/plugins/android/android_service.c
src/libcharon/plugins/ha/ha_tunnel.c
src/libcharon/plugins/load_tester/load_tester_config.c
src/libcharon/plugins/maemo/maemo_service.c
src/libcharon/plugins/medcli/medcli_config.c
src/libcharon/plugins/medsrv/medsrv_config.c
src/libcharon/plugins/nm/nm_service.c
src/libcharon/plugins/smp/smp.c
src/libcharon/plugins/sql/sql_config.c
src/libcharon/plugins/stroke/stroke_config.c
src/libcharon/plugins/stroke/stroke_control.c
src/libcharon/plugins/stroke/stroke_list.c
src/libcharon/plugins/uci/uci_config.c
src/libcharon/processing/jobs/start_action_job.c

index 9521412..51d491d 100644 (file)
@@ -251,7 +251,7 @@ static peer_cfg_t *load_peer_config(private_config_t *this,
        uintptr_t strength;
 
        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,
                                                           NULL, NULL, FALSE, NULL, NULL);
 
index c623cbc..73b5f5f 100644 (file)
 #include <utils/linked_list.h>
 #include <utils/identification.h>
 
+ENUM(ike_version_names, IKEV1, IKEV2,
+       "IKEv1",
+       "IKEv2",
+);
+
 ENUM(cert_policy_names, CERT_ALWAYS_SEND, CERT_NEVER_SEND,
        "CERT_ALWAYS_SEND",
        "CERT_SEND_IF_ASKED",
@@ -62,7 +67,7 @@ struct private_peer_cfg_t {
        /**
         * IKE version to use for initiation
         */
-       u_int ike_version;
+       ike_version_t ike_version;
 
        /**
         * IKE config associated to this peer config
@@ -169,7 +174,7 @@ METHOD(peer_cfg_t, get_name, char*,
        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)
 {
        return this->ike_version;
@@ -563,13 +568,13 @@ METHOD(peer_cfg_t, destroy, void,
 /*
  * Described in header-file
  */
-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,
-                                                       u_int32_t keyingtries, u_int32_t rekey_time,
-                                                       u_int32_t reauth_time, u_int32_t jitter_time,
-                                                       u_int32_t over_time, bool mobike, u_int32_t dpd,
-                                                       host_t *virtual_ip, char *pool,
-                                                       bool mediation, peer_cfg_t *mediated_by,
+peer_cfg_t *peer_cfg_create(char *name, ike_version_t ike_version,
+                                                       ike_cfg_t *ike_cfg, cert_policy_t cert_policy,
+                                                       unique_policy_t unique, u_int32_t keyingtries,
+                                                       u_int32_t rekey_time, u_int32_t reauth_time,
+                                                       u_int32_t jitter_time, u_int32_t over_time,
+                                                       bool mobike, u_int32_t dpd, host_t *virtual_ip,
+                                                       char *pool, bool mediation, peer_cfg_t *mediated_by,
                                                        identification_t *peer_id)
 {
        private_peer_cfg_t *this;
index f644fb5..6096f64 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef 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 unique_policy_t unique_policy_t;
 typedef struct peer_cfg_t peer_cfg_t;
@@ -39,6 +40,21 @@ typedef struct peer_cfg_t peer_cfg_t;
 #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
  * requests when using this definition for the other peer. If
  * it is CERT_NEVER_SEND, a certreq is omitted, otherwise its
@@ -130,7 +146,7 @@ struct peer_cfg_t {
         *
         * @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.
@@ -347,13 +363,13 @@ struct peer_cfg_t {
  * @param peer_id                      ID that identifies our peer at the mediation server
  * @return                                     peer_cfg_t object
  */
-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,
-                                                       u_int32_t keyingtries, u_int32_t rekey_time,
-                                                       u_int32_t reauth_time, u_int32_t jitter_time,
-                                                       u_int32_t over_time, bool mobike, u_int32_t dpd,
-                                                       host_t *virtual_ip, char *pool,
-                                                       bool mediation, peer_cfg_t *mediated_by,
+peer_cfg_t *peer_cfg_create(char *name, ike_version_t ike_version,
+                                                       ike_cfg_t *ike_cfg, cert_policy_t cert_policy,
+                                                       unique_policy_t unique, u_int32_t keyingtries,
+                                                       u_int32_t rekey_time, u_int32_t reauth_time,
+                                                       u_int32_t jitter_time, u_int32_t over_time,
+                                                       bool mobike, u_int32_t dpd, host_t *virtual_ip,
+                                                       char *pool, bool mediation, peer_cfg_t *mediated_by,
                                                        identification_t *peer_id);
 
 #endif /** PEER_CFG_H_ @}*/
index 487567f..96603ab 100644 (file)
@@ -273,7 +273,7 @@ static job_requeue_t initiate(private_android_service_t *this)
                                                         hostname, IKEV2_UDP_PORT);
        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 */
                                                           36000, 0, /* rekey 10h, reauth none */
                                                           600, 600, /* jitter, over 10min */
index 299053e..1f87c3d 100644 (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,
                                                         remote, IKEV2_UDP_PORT);
        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,
                                                NULL, NULL, FALSE, NULL, NULL);
 
index 6bc6f91..301c9cc 100644 (file)
@@ -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);
        }
        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 */
                                                           this->ike_rekey, 0, /* rekey, reauth */
                                                           0, this->ike_rekey, /* jitter, overtime */
index 6675e1d..58361a4 100644 (file)
@@ -327,7 +327,8 @@ static gboolean initiate_connection(private_maemo_service_t *this,
                                                         hostname, IKEV2_UDP_PORT);
        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 */
                                                           36000, 0, /* rekey 10h, reauth none */
                                                           600, 600, /* jitter, over 10min */
index ee3e954..f768eeb 100644 (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);
        ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
        med_cfg = peer_cfg_create(
-               "mediation", 2, ike_cfg,
+               "mediation", IKEV2, ike_cfg,
                CERT_NEVER_SEND, UNIQUE_REPLACE,
                1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
                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;
        }
        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,
                1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
                this->rekey*5, this->rekey*3,   /* jitter, overtime */
@@ -234,7 +234,7 @@ METHOD(enumerator_t, peer_enumerator_enumerate, bool,
                return FALSE;
        }
        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,
                                1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
                                this->rekey*5, this->rekey*3,   /* jitter, overtime */
index 6cacb34..fc3963a 100644 (file)
@@ -88,7 +88,7 @@ METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
                if (e->enumerate(e, &name))
                {
                        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,
                                1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
                                this->rekey*5, this->rekey*3,   /* jitter, overtime */
index a6783fc..8135476 100644 (file)
@@ -499,7 +499,7 @@ static gboolean connect_(NMVPNPlugin *plugin, NMConnection *connection,
        ike_cfg = ike_cfg_create(TRUE, encap,
                                        "0.0.0.0", IKEV2_UDP_PORT, (char*)address, IKEV2_UDP_PORT);
        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 */
                                        36000, 0, /* rekey 10h, reauth none */
                                        600, 600, /* jitter, over 10min */
index 68935aa..2743b72 100644 (file)
@@ -302,7 +302,7 @@ static void request_query_config(xmlTextReaderPtr reader, xmlTextWriterPtr write
                ike_cfg_t *ike_cfg;
                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 */
                        continue;
                }
index dc01601..ef181f6 100644 (file)
@@ -368,7 +368,7 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
                if (ike)
                {
                        peer_cfg = peer_cfg_create(
-                                       name, 2, ike, cert_policy, uniqueid,
+                                       name, IKEV2, ike, cert_policy, uniqueid,
                                        keyingtries, rekeytime, reauthtime, jitter, overtime,
                                        mobike, dpd_delay, vip, pool,
                                        mediation, mediated_cfg, peer_id);
index f09c741..4a49704 100644 (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
         * uses to serve pool addresses. */
        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.rekey.tries, rekey, reauth, jitter, over,
                msg->add_conn.mobike, msg->add_conn.dpd.delay,
index f0d8f3b..5897862 100644 (file)
@@ -126,10 +126,10 @@ METHOD(stroke_control_t, initiate, void,
                                                                                                          msg->initiate.name);
        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",
-                                peer_cfg->get_ike_version(peer_cfg));
+                       DBG1(DBG_CFG, "ignoring initiation request for %N config",
+                                ike_version_names, peer_cfg->get_ike_version(peer_cfg));
                        peer_cfg->destroy(peer_cfg);
                        return;
                }
@@ -161,7 +161,7 @@ METHOD(stroke_control_t, initiate, void,
                                                                                                        NULL, NULL, NULL, NULL);
                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;
                        }
@@ -568,10 +568,10 @@ METHOD(stroke_control_t, route, void,
                                                                                                          msg->route.name);
        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",
-                                peer_cfg->get_ike_version(peer_cfg));
+                       DBG1(DBG_CFG, "ignoring initiation request for %N config",
+                                ike_version_names, peer_cfg->get_ike_version(peer_cfg));
                        peer_cfg->destroy(peer_cfg);
                        return;
                }
@@ -603,7 +603,7 @@ METHOD(stroke_control_t, route, void,
                                                                                                        NULL, NULL, NULL, NULL);
                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;
                        }
index af06115..4145a79 100644 (file)
@@ -489,7 +489,7 @@ METHOD(stroke_list_t, status, void,
                                                                        charon->backends, NULL, NULL, NULL, NULL);
                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))))
                        {
                                continue;
index 2f5e59b..4e48b93 100644 (file)
@@ -172,7 +172,7 @@ METHOD(enumerator_t, peer_enumerator_enumerate, bool,
                                        local_addr, IKEV2_UDP_PORT, remote_addr, IKEV2_UDP_PORT);
                ike_cfg->add_proposal(ike_cfg, create_proposal(ike_proposal, PROTO_IKE));
                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 */
                                        1800, 900,                                              /* jitter, overtime */
                                        TRUE, 60,                                               /* mobike, dpddelay */
index b65181e..0019a11 100644 (file)
@@ -49,7 +49,7 @@ METHOD(job_t, execute, void,
                                                                                                        NULL, NULL, NULL, NULL);
        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;
                }