payload: Use common prefixes for all payload type identifiers
[strongswan.git] / src / libcharon / sa / ikev1 / tasks / isakmp_delete.c
1 /*
2 * Copyright (C) 2011 Martin Willi
3 * Copyright (C) 2011 revosec AG
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 "isakmp_delete.h"
17
18 #include <daemon.h>
19 #include <encoding/payloads/delete_payload.h>
20
21 typedef struct private_isakmp_delete_t private_isakmp_delete_t;
22
23 /**
24 * Private members of a isakmp_delete_t task.
25 */
26 struct private_isakmp_delete_t {
27
28 /**
29 * Public methods and task_t interface.
30 */
31 isakmp_delete_t public;
32
33 /**
34 * Assigned IKE_SA.
35 */
36 ike_sa_t *ike_sa;
37 };
38
39 METHOD(task_t, build_i, status_t,
40 private_isakmp_delete_t *this, message_t *message)
41 {
42 delete_payload_t *delete_payload;
43 ike_sa_id_t *id;
44
45 DBG0(DBG_IKE, "deleting IKE_SA %s[%d] between %H[%Y]...%H[%Y]",
46 this->ike_sa->get_name(this->ike_sa),
47 this->ike_sa->get_unique_id(this->ike_sa),
48 this->ike_sa->get_my_host(this->ike_sa),
49 this->ike_sa->get_my_id(this->ike_sa),
50 this->ike_sa->get_other_host(this->ike_sa),
51 this->ike_sa->get_other_id(this->ike_sa));
52
53 delete_payload = delete_payload_create(PLV1_DELETE, PROTO_IKE);
54 id = this->ike_sa->get_id(this->ike_sa);
55 delete_payload->set_ike_spi(delete_payload, id->get_initiator_spi(id),
56 id->get_responder_spi(id));
57 message->add_payload(message, (payload_t*)delete_payload);
58
59 DBG1(DBG_IKE, "sending DELETE for IKE_SA %s[%d]",
60 this->ike_sa->get_name(this->ike_sa),
61 this->ike_sa->get_unique_id(this->ike_sa));
62
63 this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
64 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
65 return SUCCESS;
66 }
67
68 METHOD(task_t, process_i, status_t,
69 private_isakmp_delete_t *this, message_t *message)
70 {
71 return FAILED;
72 }
73
74 METHOD(task_t, process_r, status_t,
75 private_isakmp_delete_t *this, message_t *message)
76 {
77 DBG1(DBG_IKE, "received DELETE for IKE_SA %s[%d]",
78 this->ike_sa->get_name(this->ike_sa),
79 this->ike_sa->get_unique_id(this->ike_sa));
80 DBG0(DBG_IKE, "deleting IKE_SA %s[%d] between %H[%Y]...%H[%Y]",
81 this->ike_sa->get_name(this->ike_sa),
82 this->ike_sa->get_unique_id(this->ike_sa),
83 this->ike_sa->get_my_host(this->ike_sa),
84 this->ike_sa->get_my_id(this->ike_sa),
85 this->ike_sa->get_other_host(this->ike_sa),
86 this->ike_sa->get_other_id(this->ike_sa));
87
88 if (this->ike_sa->get_state(this->ike_sa) == IKE_ESTABLISHED)
89 {
90 this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
91 this->ike_sa->reestablish(this->ike_sa);
92 }
93 this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
94 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
95 return DESTROY_ME;
96 }
97
98 METHOD(task_t, build_r, status_t,
99 private_isakmp_delete_t *this, message_t *message)
100 {
101 return FAILED;
102 }
103
104 METHOD(task_t, get_type, task_type_t,
105 private_isakmp_delete_t *this)
106 {
107 return TASK_ISAKMP_DELETE;
108 }
109
110 METHOD(task_t, migrate, void,
111 private_isakmp_delete_t *this, ike_sa_t *ike_sa)
112 {
113 this->ike_sa = ike_sa;
114 }
115
116 METHOD(task_t, destroy, void,
117 private_isakmp_delete_t *this)
118 {
119 free(this);
120 }
121
122 /*
123 * Described in header.
124 */
125 isakmp_delete_t *isakmp_delete_create(ike_sa_t *ike_sa, bool initiator)
126 {
127 private_isakmp_delete_t *this;
128
129 INIT(this,
130 .public = {
131 .task = {
132 .get_type = _get_type,
133 .migrate = _migrate,
134 .destroy = _destroy,
135 },
136 },
137 .ike_sa = ike_sa,
138 );
139
140 if (initiator)
141 {
142 this->public.task.build = _build_i;
143 this->public.task.process = _process_i;
144 }
145 else
146 {
147 this->public.task.build = _build_r;
148 this->public.task.process = _process_r;
149 }
150
151 return &this->public;
152 }