]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
child-cfg: Generalize get_dh_group() method
authorTobias Brunner <tobias@strongswan.org>
Fri, 20 Jul 2018 09:11:00 +0000 (11:11 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 14 May 2019 08:54:45 +0000 (10:54 +0200)
src/libcharon/config/child_cfg.c
src/libcharon/config/child_cfg.h
src/libcharon/sa/ikev1/tasks/quick_mode.c
src/libcharon/sa/ikev2/tasks/child_create.c

index 6d8f197c4d49b69d96f9a69b72a36271b229715b..53fd3461ef800b9b4c0e63d7491c270daf8cf0a4 100644 (file)
@@ -533,23 +533,23 @@ METHOD(child_cfg_t, get_close_action, action_t,
        return this->close_action;
 }
 
-METHOD(child_cfg_t, get_dh_group, diffie_hellman_group_t,
-       private_child_cfg_t *this)
+METHOD(child_cfg_t, get_algorithm, uint16_t,
+       private_child_cfg_t *this, transform_type_t type)
 {
        enumerator_t *enumerator;
        proposal_t *proposal;
-       uint16_t dh_group = MODP_NONE;
+       uint16_t alg = 0;
 
        enumerator = this->proposals->create_enumerator(this->proposals);
        while (enumerator->enumerate(enumerator, &proposal))
        {
-               if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP, &dh_group, NULL))
+               if (proposal->get_algorithm(proposal, type, &alg, NULL))
                {
                        break;
                }
        }
        enumerator->destroy(enumerator);
-       return dh_group;
+       return alg;
 }
 
 METHOD(child_cfg_t, get_inactivity, uint32_t,
@@ -713,7 +713,7 @@ child_cfg_t *child_cfg_create(char *name, child_cfg_create_t *data)
                        .get_dpd_action = _get_dpd_action,
                        .get_close_action = _get_close_action,
                        .get_lifetime = _get_lifetime,
-                       .get_dh_group = _get_dh_group,
+                       .get_algorithm = _get_algorithm,
                        .get_inactivity = _get_inactivity,
                        .get_reqid = _get_reqid,
                        .get_if_id = _get_if_id,
index b80268513c1fd973c1fefaaa14647210b1a87a52..9ced08885ac7b3e44611f81bf867554428669317 100644 (file)
@@ -206,11 +206,16 @@ struct child_cfg_t {
        action_t (*get_close_action) (child_cfg_t *this);
 
        /**
-        * Get the DH group to use for CHILD_SA setup.
+        * Get the first algorithm of a certain transform type that's contained in
+        * any of the configured proposals.
         *
-        * @return                              dh group to use
+        * For instance, use with DIFFIE_HELLMAN_GROUP to get the DH group to use
+        * for the CHILD_SA initiation.
+        *
+        * @param type                  transform type to look for
+        * @return                              algorithm identifier (0 for none)
         */
-       diffie_hellman_group_t (*get_dh_group)(child_cfg_t *this);
+       uint16_t (*get_algorithm)(child_cfg_t *this, transform_type_t type);
 
        /**
         * Get the inactivity timeout value.
index 1b941589df7d8a883f74fedcbffe693739cab604..cab607ace6df104b1e32fe197ac05ee76fdde7d4 100644 (file)
@@ -865,7 +865,8 @@ METHOD(task_t, build_i, status_t,
                                return FAILED;
                        }
 
-                       group = this->config->get_dh_group(this->config);
+                       group = this->config->get_algorithm(this->config,
+                                                                                               DIFFIE_HELLMAN_GROUP);
                        if (group != MODP_NONE)
                        {
                                proposal_t *proposal;
index 9901e8507843ea7f839216369d4b327cc75ad45f..d732c9f397600ac6c36c88c04069d9d215cca23f 100644 (file)
@@ -1085,7 +1085,8 @@ METHOD(task_t, build_i, status_t,
                        }
                        if (!this->retry && this->dh_group == MODP_NONE)
                        {       /* during a rekeying the group might already be set */
-                               this->dh_group = this->config->get_dh_group(this->config);
+                               this->dh_group = this->config->get_algorithm(this->config,
+                                                                                                               DIFFIE_HELLMAN_GROUP);
                        }
                        break;
                case IKE_AUTH: