Use enum to define IKE version on peer_cfg_t.
[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);
50 while (enumerator->enumerate(enumerator, &peer_cfg))
51 {
52 if (peer_cfg->get_ike_version(peer_cfg) != IKEV2)
53 {
54 continue;
55 }
56
57 children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
58 while (children->enumerate(children, &child_cfg))
59 {
60 name = child_cfg->get_name(child_cfg);
61
62 switch (child_cfg->get_start_action(child_cfg))
63 {
64 case ACTION_RESTART:
65 DBG1(DBG_JOB, "start action: initiate '%s'", name);
66 charon->controller->initiate(charon->controller,
67 peer_cfg->get_ref(peer_cfg),
68 child_cfg->get_ref(child_cfg),
69 NULL, NULL, 0);
70 break;
71 case ACTION_ROUTE:
72 DBG1(DBG_JOB, "start action: route '%s'", name);
73 mode = child_cfg->get_mode(child_cfg);
74 if (mode == MODE_PASS || mode == MODE_DROP)
75 {
76 charon->shunts->install(charon->shunts, child_cfg);
77 }
78 else
79 {
80 charon->traps->install(charon->traps, peer_cfg,
81 child_cfg);
82 }
83 break;
84 case ACTION_NONE:
85 break;
86 }
87 }
88 children->destroy(children);
89 }
90 enumerator->destroy(enumerator);
91 destroy(this);
92 }
93
94 METHOD(job_t, get_priority, job_priority_t,
95 private_start_action_job_t *this)
96 {
97 return JOB_PRIO_MEDIUM;
98 }
99
100 /*
101 * Described in header
102 */
103 start_action_job_t *start_action_job_create(void)
104 {
105 private_start_action_job_t *this;
106
107 INIT(this,
108 .public = {
109 .job_interface = {
110 .execute = _execute,
111 .get_priority = _get_priority,
112 .destroy = _destroy,
113 },
114 },
115 );
116 return &this->public;
117 }
118