/src/strongswan/src/libcharon/processing/jobs/roam_job.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2007 Martin Willi |
3 | | * |
4 | | * Copyright (C) secunet Security Networks AG |
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 <stdlib.h> |
18 | | |
19 | | #include "roam_job.h" |
20 | | |
21 | | #include <sa/ike_sa.h> |
22 | | #include <daemon.h> |
23 | | |
24 | | |
25 | | typedef struct private_roam_job_t private_roam_job_t; |
26 | | |
27 | | /** |
28 | | * Private data of an roam_job_t Object |
29 | | */ |
30 | | struct private_roam_job_t { |
31 | | /** |
32 | | * public roam_job_t interface |
33 | | */ |
34 | | roam_job_t public; |
35 | | |
36 | | /** |
37 | | * has the address list changed, or the routing only? |
38 | | */ |
39 | | bool address; |
40 | | }; |
41 | | |
42 | | METHOD(job_t, destroy, void, |
43 | | private_roam_job_t *this) |
44 | 0 | { |
45 | 0 | free(this); |
46 | 0 | } |
47 | | |
48 | | METHOD(job_t, execute, job_requeue_t, |
49 | | private_roam_job_t *this) |
50 | 0 | { |
51 | 0 | ike_sa_t *ike_sa; |
52 | 0 | linked_list_t *list; |
53 | 0 | ike_sa_id_t *id; |
54 | 0 | enumerator_t *enumerator; |
55 | | |
56 | | /* enumerator over all IKE_SAs gives us no way to checkin_and_destroy |
57 | | * after a DESTROY_ME, so we check out each available IKE_SA by hand. */ |
58 | 0 | list = linked_list_create(); |
59 | 0 | enumerator = charon->ike_sa_manager->create_enumerator( |
60 | 0 | charon->ike_sa_manager, TRUE); |
61 | 0 | while (enumerator->enumerate(enumerator, &ike_sa)) |
62 | 0 | { |
63 | 0 | id = ike_sa->get_id(ike_sa); |
64 | 0 | list->insert_last(list, id->clone(id)); |
65 | 0 | } |
66 | 0 | enumerator->destroy(enumerator); |
67 | |
|
68 | 0 | while (list->remove_last(list, (void**)&id) == SUCCESS) |
69 | 0 | { |
70 | 0 | ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, id); |
71 | 0 | if (ike_sa) |
72 | 0 | { |
73 | 0 | if (ike_sa->roam(ike_sa, this->address) == DESTROY_ME) |
74 | 0 | { |
75 | 0 | charon->ike_sa_manager->checkin_and_destroy( |
76 | 0 | charon->ike_sa_manager, ike_sa); |
77 | 0 | } |
78 | 0 | else |
79 | 0 | { |
80 | 0 | charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); |
81 | 0 | } |
82 | 0 | } |
83 | 0 | id->destroy(id); |
84 | 0 | } |
85 | 0 | list->destroy(list); |
86 | 0 | return JOB_REQUEUE_NONE; |
87 | 0 | } |
88 | | |
89 | | METHOD(job_t, get_priority, job_priority_t, |
90 | | private_roam_job_t *this) |
91 | 0 | { |
92 | 0 | return JOB_PRIO_MEDIUM; |
93 | 0 | } |
94 | | |
95 | | /* |
96 | | * Described in header |
97 | | */ |
98 | | roam_job_t *roam_job_create(bool address) |
99 | 0 | { |
100 | 0 | private_roam_job_t *this; |
101 | |
|
102 | 0 | INIT(this, |
103 | 0 | .public = { |
104 | 0 | .job_interface = { |
105 | 0 | .execute = _execute, |
106 | 0 | .get_priority = _get_priority, |
107 | 0 | .destroy = _destroy, |
108 | 0 | }, |
109 | 0 | }, |
110 | 0 | .address = address, |
111 | 0 | ); |
112 | |
|
113 | 0 | return &this->public; |
114 | 0 | } |
115 | | |