controller: Use the CHILD_SA unique_id to terminate CHILD_SAs
authorMartin Willi <martin@revosec.ch>
Mon, 27 Oct 2014 13:03:32 +0000 (14:03 +0100)
committerMartin Willi <martin@revosec.ch>
Fri, 20 Feb 2015 12:34:50 +0000 (13:34 +0100)
src/conftest/actions.c
src/libcharon/control/controller.c
src/libcharon/control/controller.h
src/libcharon/plugins/stroke/stroke_control.c
src/libcharon/plugins/vici/vici_config.c
src/libcharon/plugins/vici/vici_control.c

index 7532e95..3f937b1 100644 (file)
@@ -236,7 +236,7 @@ static job_requeue_t close_child(char *config)
                {
                        if (streq(config, child_sa->get_name(child_sa)))
                        {
-                               id = child_sa->get_reqid(child_sa);
+                               id = child_sa->get_unique_id(child_sa);
                                break;
                        }
                }
index 60d186e..418b247 100644 (file)
@@ -534,17 +534,15 @@ METHOD(job_t, terminate_child_execute, job_requeue_t,
        interface_job_t *job)
 {
        interface_listener_t *listener = &job->listener;
-       u_int32_t reqid = listener->id;
-       enumerator_t *enumerator;
+       u_int32_t id = listener->id;
        child_sa_t *child_sa;
        ike_sa_t *ike_sa;
 
-       ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
-                                                                                                       reqid, TRUE);
+       ike_sa = charon->child_sa_manager->checkout_by_id(charon->child_sa_manager,
+                                                                                                         id, &child_sa);
        if (!ike_sa)
        {
-               DBG1(DBG_IKE, "unable to terminate, CHILD_SA with ID %d not found",
-                        reqid);
+               DBG1(DBG_IKE, "unable to terminate, CHILD_SA with ID %d not found", id);
                listener->status = NOT_FOUND;
                /* release listener */
                listener_done(listener);
@@ -554,22 +552,10 @@ METHOD(job_t, terminate_child_execute, job_requeue_t,
        listener->ike_sa = ike_sa;
        listener->lock->unlock(listener->lock);
 
-       enumerator = ike_sa->create_child_sa_enumerator(ike_sa);
-       while (enumerator->enumerate(enumerator, (void**)&child_sa))
-       {
-               if (child_sa->get_state(child_sa) != CHILD_ROUTED &&
-                       child_sa->get_reqid(child_sa) == reqid)
-               {
-                       break;
-               }
-               child_sa = NULL;
-       }
-       enumerator->destroy(enumerator);
-
-       if (!child_sa)
+       if (child_sa->get_state(child_sa) == CHILD_ROUTED)
        {
                DBG1(DBG_IKE, "unable to terminate, established "
-                        "CHILD_SA with ID %d not found", reqid);
+                        "CHILD_SA with ID %d not found", id);
                charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
                listener->status = NOT_FOUND;
                /* release listener */
@@ -596,7 +582,7 @@ METHOD(job_t, terminate_child_execute, job_requeue_t,
 }
 
 METHOD(controller_t, terminate_child, status_t,
-       controller_t *this, u_int32_t reqid,
+       controller_t *this, u_int32_t unique_id,
        controller_cb_t callback, void *param, u_int timeout)
 {
        interface_job_t *job;
@@ -617,7 +603,7 @@ METHOD(controller_t, terminate_child, status_t,
                                .param = param,
                        },
                        .status = FAILED,
-                       .id = reqid,
+                       .id = unique_id,
                        .lock = spinlock_create(),
                },
                .public = {
index 222285c..02f4ebb 100644 (file)
@@ -118,7 +118,7 @@ struct controller_t {
         * If a callback is provided the function is synchronous and thus blocks
         * until the CHILD_SA is properly deleted, or the call timed out.
         *
-        * @param reqid                 reqid of the CHILD_SA to terminate
+        * @param unique_id             CHILD_SA unique ID to terminate
         * @param cb                    logging callback
         * @param param                 parameter to include in each call of cb
         * @param timeout               timeout in ms to wait for callbacks, 0 to disable
@@ -128,7 +128,7 @@ struct controller_t {
         *                                              - NEED_MORE, if callback returned FALSE
         *                                              - OUT_OF_RES if timed out
         */
-       status_t (*terminate_child)(controller_t *this, u_int32_t reqid,
+       status_t (*terminate_child)(controller_t *this, u_int32_t unique_id,
                                                                controller_cb_t callback, void *param,
                                                                u_int timeout);
 
index f770d7c..99d07f5 100644 (file)
@@ -352,7 +352,7 @@ METHOD(stroke_control_t, terminate, void,
                                if (streq(name, child_sa->get_name(child_sa)))
                                {
                                        child_list->insert_last(child_list,
-                                                       (void*)(uintptr_t)child_sa->get_reqid(child_sa));
+                                                       (void*)(uintptr_t)child_sa->get_unique_id(child_sa));
                                        if (!all)
                                        {
                                                break;
index 113d480..43b3f07 100644 (file)
@@ -1551,8 +1551,8 @@ static void clear_start_action(private_vici_config_t *this,
        enumerator_t *enumerator, *children;
        child_sa_t *child_sa;
        ike_sa_t *ike_sa;
-       u_int32_t reqid = 0, *del;
-       array_t *reqids = NULL;
+       u_int32_t id = 0, *del;
+       array_t *ids = NULL;
        char *name;
 
        name = child_cfg->get_name(child_cfg);
@@ -1568,23 +1568,23 @@ static void clear_start_action(private_vici_config_t *this,
                                {
                                        if (streq(name, child_sa->get_name(child_sa)))
                                        {
-                                               reqid = child_sa->get_reqid(child_sa);
-                                               array_insert_create(&reqids, ARRAY_TAIL, &reqid);
+                                               id = child_sa->get_unique_id(child_sa);
+                                               array_insert_create(&ids, ARRAY_TAIL, &id);
                                        }
                                }
                                children->destroy(children);
                        }
                        enumerator->destroy(enumerator);
 
-                       if (array_count(reqids))
+                       if (array_count(ids))
                        {
-                               while (array_remove(reqids, ARRAY_HEAD, &del))
+                               while (array_remove(ids, ARRAY_HEAD, &del))
                                {
                                        DBG1(DBG_CFG, "closing '%s' #%u", name, *del);
                                        charon->controller->terminate_child(charon->controller,
                                                                                                                *del, NULL, NULL, 0);
                                }
-                               array_destroy(reqids);
+                               array_destroy(ids);
                        }
                        break;
                case ACTION_ROUTE:
@@ -1601,14 +1601,14 @@ static void clear_start_action(private_vici_config_t *this,
                                        {
                                                if (streq(name, child_sa->get_name(child_sa)))
                                                {
-                                                       reqid = child_sa->get_reqid(child_sa);
+                                                       id = child_sa->get_reqid(child_sa);
                                                        break;
                                                }
                                        }
                                        enumerator->destroy(enumerator);
-                                       if (reqid)
+                                       if (id)
                                        {
-                                               charon->traps->uninstall(charon->traps, reqid);
+                                               charon->traps->uninstall(charon->traps, id);
                                        }
                                        break;
                        }
index 292a400..01d5036 100644 (file)
@@ -264,11 +264,11 @@ CALLBACK(terminate, vici_message_t*,
                                {
                                        continue;
                                }
-                               if (child_id && child_sa->get_reqid(child_sa) != child_id)
+                               if (child_id && child_sa->get_unique_id(child_sa) != child_id)
                                {
                                        continue;
                                }
-                               current = child_sa->get_reqid(child_sa);
+                               current = child_sa->get_unique_id(child_sa);
                                array_insert(ids, ARRAY_TAIL, &current);
                        }
                        csas->destroy(csas);