Annotation of embedaddon/strongswan/src/libcharon/processing/jobs/start_action_job.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2011 Andreas Steffen
        !             3:  * HSR Hochschule fuer Technik Rapperswil
        !             4:  *
        !             5:  * This program is free software; you can redistribute it and/or modify it
        !             6:  * under the terms of the GNU General Public License as published by the
        !             7:  * Free Software Foundation; either version 2 of the License, or (at your
        !             8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !             9:  *
        !            10:  * This program is distributed in the hope that it will be useful, but
        !            11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            13:  * for more details.
        !            14:  */
        !            15: 
        !            16: #include "start_action_job.h"
        !            17: 
        !            18: #include <daemon.h>
        !            19: 
        !            20: 
        !            21: typedef struct private_start_action_job_t private_start_action_job_t;
        !            22: 
        !            23: /**
        !            24:  * Private data of an start_action_job_t object.
        !            25:  */
        !            26: struct private_start_action_job_t {
        !            27:        /**
        !            28:         * Public start_action_job_t interface.
        !            29:         */
        !            30:        start_action_job_t public;
        !            31: };
        !            32: 
        !            33: METHOD(job_t, destroy, void,
        !            34:        private_start_action_job_t *this)
        !            35: {
        !            36:        free(this);
        !            37: }
        !            38: 
        !            39: METHOD(job_t, execute, job_requeue_t,
        !            40:        private_start_action_job_t *this)
        !            41: {
        !            42:        enumerator_t *enumerator, *children;
        !            43:        peer_cfg_t *peer_cfg;
        !            44:        child_cfg_t *child_cfg;
        !            45:        ipsec_mode_t mode;
        !            46:        char *name;
        !            47: 
        !            48:        enumerator = charon->backends->create_peer_cfg_enumerator(charon->backends,
        !            49:                                                                                        NULL, NULL, NULL, NULL, IKE_ANY);
        !            50:        while (enumerator->enumerate(enumerator, &peer_cfg))
        !            51:        {
        !            52:                children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
        !            53:                while (children->enumerate(children, &child_cfg))
        !            54:                {
        !            55:                        name = child_cfg->get_name(child_cfg);
        !            56: 
        !            57:                        switch (child_cfg->get_start_action(child_cfg))
        !            58:                        {
        !            59:                                case ACTION_RESTART:
        !            60:                                        DBG1(DBG_JOB, "start action: initiate '%s'", name);
        !            61:                                        charon->controller->initiate(charon->controller,
        !            62:                                                                                                 peer_cfg->get_ref(peer_cfg),
        !            63:                                                                                                 child_cfg->get_ref(child_cfg),
        !            64:                                                                                                 NULL, NULL, 0, FALSE);
        !            65:                                        break;
        !            66:                                case ACTION_ROUTE:
        !            67:                                        DBG1(DBG_JOB, "start action: route '%s'", name);
        !            68:                                        mode = child_cfg->get_mode(child_cfg);
        !            69:                                        if (mode == MODE_PASS || mode == MODE_DROP)
        !            70:                                        {
        !            71:                                                charon->shunts->install(charon->shunts,
        !            72:                                                                                                peer_cfg->get_name(peer_cfg),
        !            73:                                                                                                child_cfg);
        !            74:                                        }
        !            75:                                        else
        !            76:                                        {
        !            77:                                                charon->traps->install(charon->traps, peer_cfg,
        !            78:                                                                                           child_cfg);
        !            79:                                        }
        !            80:                                        break;
        !            81:                                case ACTION_NONE:
        !            82:                                        break;
        !            83:                        }
        !            84:                }
        !            85:                children->destroy(children);
        !            86:        }
        !            87:        enumerator->destroy(enumerator);
        !            88:        return JOB_REQUEUE_NONE;
        !            89: }
        !            90: 
        !            91: METHOD(job_t, get_priority, job_priority_t,
        !            92:        private_start_action_job_t *this)
        !            93: {
        !            94:        return JOB_PRIO_MEDIUM;
        !            95: }
        !            96: 
        !            97: /*
        !            98:  * Described in header
        !            99:  */
        !           100: start_action_job_t *start_action_job_create(void)
        !           101: {
        !           102:        private_start_action_job_t *this;
        !           103: 
        !           104:        INIT(this,
        !           105:                .public = {
        !           106:                        .job_interface = {
        !           107:                                .execute = _execute,
        !           108:                                .get_priority = _get_priority,
        !           109:                                .destroy = _destroy,
        !           110:                        },
        !           111:                },
        !           112:        );
        !           113:        return &this->public;
        !           114: }
        !           115: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>