]>
Commit | Line | Data |
---|---|---|
0d424d21 TB |
1 | /* |
2 | * Copyright (C) 2015 Tobias Brunner | |
19ef2aec TB |
3 | * |
4 | * Copyright (C) secunet Security Networks AG | |
0d424d21 TB |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2 of the License, or (at your | |
9 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | * for more details. | |
15 | */ | |
16 | ||
17 | #include <daemon.h> | |
18 | ||
19 | #include "redirect_job.h" | |
20 | ||
21 | typedef struct private_redirect_job_t private_redirect_job_t; | |
22 | ||
23 | /** | |
24 | * Private data | |
25 | */ | |
26 | struct private_redirect_job_t { | |
27 | ||
28 | /** | |
29 | * Public interface | |
30 | */ | |
31 | redirect_job_t public; | |
32 | ||
33 | /** | |
34 | * ID of the IKE_SA to redirect | |
35 | */ | |
36 | ike_sa_id_t *ike_sa_id; | |
37 | ||
38 | /** | |
39 | * Target gateway identity | |
40 | */ | |
41 | identification_t *gateway; | |
42 | }; | |
43 | ||
44 | ||
45 | METHOD(job_t, destroy, void, | |
46 | private_redirect_job_t *this) | |
47 | { | |
48 | this->ike_sa_id->destroy(this->ike_sa_id); | |
49 | this->gateway->destroy(this->gateway); | |
50 | free(this); | |
51 | } | |
52 | ||
53 | METHOD(job_t, execute, job_requeue_t, | |
54 | private_redirect_job_t *this) | |
55 | { | |
56 | ike_sa_t *ike_sa; | |
57 | ||
58 | ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, | |
59 | this->ike_sa_id); | |
60 | if (ike_sa) | |
61 | { | |
62 | if (ike_sa->get_state(ike_sa) == IKE_PASSIVE) | |
63 | { | |
64 | charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); | |
65 | return JOB_REQUEUE_NONE; | |
66 | } | |
67 | if (ike_sa->redirect(ike_sa, this->gateway) == DESTROY_ME) | |
68 | { | |
69 | charon->ike_sa_manager->checkin_and_destroy( | |
70 | charon->ike_sa_manager, ike_sa); | |
71 | } | |
72 | else | |
73 | { | |
74 | charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); | |
75 | } | |
76 | } | |
77 | return JOB_REQUEUE_NONE; | |
78 | } | |
79 | ||
80 | METHOD(job_t, get_priority, job_priority_t, | |
81 | private_redirect_job_t *this) | |
82 | { | |
83 | return JOB_PRIO_MEDIUM; | |
84 | } | |
85 | ||
86 | /* | |
87 | * Described in header | |
88 | */ | |
89 | redirect_job_t *redirect_job_create(ike_sa_id_t *ike_sa_id, | |
90 | identification_t *gateway) | |
91 | { | |
92 | private_redirect_job_t *this; | |
93 | ||
94 | INIT(this, | |
95 | .public = { | |
96 | .job_interface = { | |
97 | .execute = _execute, | |
98 | .get_priority = _get_priority, | |
99 | .destroy = _destroy, | |
100 | }, | |
101 | }, | |
102 | .ike_sa_id = ike_sa_id->clone(ike_sa_id), | |
103 | .gateway = gateway->clone(gateway), | |
104 | ); | |
105 | ||
106 | return &(this->public); | |
107 | } |