Moving charon to libcharon.
[strongswan.git] / src / libcharon / processing / jobs / delete_child_sa_job.c
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * 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 "delete_child_sa_job.h"
17
18 #include <daemon.h>
19
20
21 typedef struct private_delete_child_sa_job_t private_delete_child_sa_job_t;
22
23 /**
24 * Private data of an delete_child_sa_job_t object.
25 */
26 struct private_delete_child_sa_job_t {
27 /**
28
29 * Public delete_child_sa_job_t interface.
30 */
31 delete_child_sa_job_t public;
32
33 /**
34 * reqid of the CHILD_SA
35 */
36 u_int32_t reqid;
37
38 /**
39 * protocol of the CHILD_SA (ESP/AH)
40 */
41 protocol_id_t protocol;
42
43 /**
44 * inbound SPI of the CHILD_SA
45 */
46 u_int32_t spi;
47 };
48
49 /**
50 * Implementation of job_t.destroy.
51 */
52 static void destroy(private_delete_child_sa_job_t *this)
53 {
54 free(this);
55 }
56
57 /**
58 * Implementation of job_t.execute.
59 */
60 static void execute(private_delete_child_sa_job_t *this)
61 {
62 ike_sa_t *ike_sa;
63
64 ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
65 this->reqid, TRUE);
66 if (ike_sa == NULL)
67 {
68 DBG1(DBG_JOB, "CHILD_SA with reqid %d not found for delete",
69 this->reqid);
70 }
71 else
72 {
73 ike_sa->delete_child_sa(ike_sa, this->protocol, this->spi);
74
75 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
76 }
77 destroy(this);
78 }
79
80 /*
81 * Described in header
82 */
83 delete_child_sa_job_t *delete_child_sa_job_create(u_int32_t reqid,
84 protocol_id_t protocol,
85 u_int32_t spi)
86 {
87 private_delete_child_sa_job_t *this = malloc_thing(private_delete_child_sa_job_t);
88
89 /* interface functions */
90 this->public.job_interface.execute = (void (*) (job_t *)) execute;
91 this->public.job_interface.destroy = (void (*)(job_t*)) destroy;
92
93 /* private variables */
94 this->reqid = reqid;
95 this->protocol = protocol;
96 this->spi = spi;
97
98 return &this->public;
99 }
100