Merge branch 'ikev1-clean' into ikev1-master
[strongswan.git] / src / libcharon / processing / jobs / start_action_job.c
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, void,
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);
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, child_cfg);
72 }
73 else
74 {
75 charon->traps->install(charon->traps, peer_cfg,
76 child_cfg);
77 }
78 break;
79 case ACTION_NONE:
80 break;
81 }
82 }
83 children->destroy(children);
84 }
85 enumerator->destroy(enumerator);
86 destroy(this);
87 }
88
89 METHOD(job_t, get_priority, job_priority_t,
90 private_start_action_job_t *this)
91 {
92 return JOB_PRIO_MEDIUM;
93 }
94
95 /*
96 * Described in header
97 */
98 start_action_job_t *start_action_job_create(void)
99 {
100 private_start_action_job_t *this;
101
102 INIT(this,
103 .public = {
104 .job_interface = {
105 .execute = _execute,
106 .get_priority = _get_priority,
107 .destroy = _destroy,
108 },
109 },
110 );
111 return &this->public;
112 }
113