acbde70c3a4e40ef8fedf8ef43ac0f2f11029ade
[strongswan.git] / src / charon / queues / jobs / send_dpd_job.c
1 /**
2 * @file send_dpd_job.c
3 *
4 * @brief Implementation of send_dpd_job_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23
24 #include <stdlib.h>
25
26 #include "send_dpd_job.h"
27
28 #include <sa/ike_sa.h>
29 #include <daemon.h>
30
31
32 typedef struct private_send_dpd_job_t private_send_dpd_job_t;
33
34 /**
35 * Private data of an send_dpd_job_t Object
36 */
37 struct private_send_dpd_job_t {
38 /**
39 * public send_dpd_job_t interface
40 */
41 send_dpd_job_t public;
42
43 /**
44 * ID of the IKE_SA which the message belongs to.
45 */
46 ike_sa_id_t *ike_sa_id;
47
48 /**
49 * Logger reference.
50 */
51 logger_t *logger;
52 };
53
54 /**
55 * Implements send_dpd_job_t.get_type.
56 */
57 static job_type_t get_type(private_send_dpd_job_t *this)
58 {
59 return SEND_DPD;
60 }
61
62 /**
63 * Implementation of job_t.execute.
64 */
65 static status_t execute(private_send_dpd_job_t *this)
66 {
67 ike_sa_t *ike_sa;
68 status_t status;
69
70 this->logger->log(this->logger, CONTROL|LEVEL2, "Checking out IKE SA %lld:%lld, role %s",
71 this->ike_sa_id->get_initiator_spi(this->ike_sa_id),
72 this->ike_sa_id->get_responder_spi(this->ike_sa_id),
73 this->ike_sa_id->is_initiator(this->ike_sa_id) ? "initiator" : "responder");
74
75 status = charon->ike_sa_manager->checkout(charon->ike_sa_manager,
76 this->ike_sa_id, &ike_sa);
77 if (status != SUCCESS)
78 {
79 this->logger->log(this->logger, ERROR|LEVEL1,
80 "IKE SA could not be checked out. Already deleted?");
81 return DESTROY_ME;
82 }
83
84 ike_sa->send_dpd_request(ike_sa);
85 this->logger->log(this->logger, CONTROL|LEVEL1,
86 "DPD request packet scheduled");
87
88 this->logger->log(this->logger, CONTROL|LEVEL2,
89 "Checkin IKE SA %lld:%lld, role %s",
90 this->ike_sa_id->get_initiator_spi(this->ike_sa_id),
91 this->ike_sa_id->get_responder_spi(this->ike_sa_id),
92 this->ike_sa_id->is_initiator(this->ike_sa_id) ? "initiator" : "responder");
93
94 status = charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
95 if (status != SUCCESS)
96 {
97 this->logger->log(this->logger, ERROR, "Checkin of IKE SA failed!");
98 }
99
100 return SUCCESS;
101 }
102
103 /**
104 * Implements job_t.destroy.
105 */
106 static void destroy(private_send_dpd_job_t *this)
107 {
108 this->ike_sa_id->destroy(this->ike_sa_id);
109 free(this);
110 }
111
112 /*
113 * Described in header
114 */
115 send_dpd_job_t *send_dpd_job_create(ike_sa_id_t *ike_sa_id)
116 {
117 private_send_dpd_job_t *this = malloc_thing(private_send_dpd_job_t);
118
119 /* interface functions */
120 this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
121 this->public.job_interface.destroy = (void (*) (job_t *)) destroy;
122 this->public.job_interface.execute = (status_t (*) (job_t *)) execute;
123
124 /* public functions */
125 this->public.destroy = (void (*)(send_dpd_job_t *)) destroy;
126
127 /* private variables */
128 this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
129 this->logger = logger_manager->get_logger(logger_manager, WORKER);
130
131 return &(this->public);
132 }