Annotation of embedaddon/strongswan/src/libcharon/sa/ikev2/tasks/ike_redirect.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2015 Tobias Brunner
3: * HSR 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 "ike_redirect.h"
17:
18: #include <daemon.h>
19: #include <processing/jobs/delete_ike_sa_job.h>
20:
21: typedef struct private_ike_redirect_t private_ike_redirect_t;
22:
23: /**
24: * Private members
25: */
26: struct private_ike_redirect_t {
27:
28: /**
29: * Public interface
30: */
31: ike_redirect_t public;
32:
33: /**
34: * Assigned IKE_SA
35: */
36: ike_sa_t *ike_sa;
37:
38: /**
39: * Gateway ID to redirect to
40: */
41: identification_t *gateway;
42: };
43:
44: METHOD(task_t, build_i, status_t,
45: private_ike_redirect_t *this, message_t *message)
46: {
47: chunk_t data;
48:
49: DBG1(DBG_IKE, "redirecting peer to %Y", this->gateway);
50: data = redirect_data_create(this->gateway, chunk_empty);
51: message->add_notify(message, FALSE, REDIRECT, data);
52: chunk_free(&data);
53: this->ike_sa->set_condition(this->ike_sa, COND_REDIRECTED, TRUE);
54: return NEED_MORE;
55: }
56:
57: METHOD(task_t, process_r, status_t,
58: private_ike_redirect_t *this, message_t *message)
59: {
60: notify_payload_t *notify;
61: identification_t *to;
62:
63: notify = message->get_notify(message, REDIRECT);
64: if (!notify)
65: {
66: return SUCCESS;
67: }
68:
69: to = redirect_data_parse(notify->get_notification_data(notify), NULL);
70: if (!to)
71: {
72: DBG1(DBG_IKE, "received invalid REDIRECT notify");
73: }
74: else
75: {
76: this->ike_sa->handle_redirect(this->ike_sa, to);
77: to->destroy(to);
78: }
79: return SUCCESS;
80: }
81:
82: METHOD(task_t, build_r, status_t,
83: private_ike_redirect_t *this, message_t *message)
84: {
85: /* not called because SUCCESS is returned above */
86: return SUCCESS;
87: }
88:
89: METHOD(task_t, process_i, status_t,
90: private_ike_redirect_t *this, message_t *message)
91: {
92: delete_ike_sa_job_t *job;
93:
94: /* if the peer does not delete the SA we do so after a while */
95: job = delete_ike_sa_job_create(this->ike_sa->get_id(this->ike_sa), TRUE);
96: lib->scheduler->schedule_job(lib->scheduler, (job_t*)job,
97: lib->settings->get_int(lib->settings,
98: "%s.half_open_timeout", HALF_OPEN_IKE_SA_TIMEOUT,
99: lib->ns));
100: return SUCCESS;
101: }
102:
103: METHOD(task_t, get_type, task_type_t,
104: private_ike_redirect_t *this)
105: {
106: return TASK_IKE_REDIRECT;
107: }
108:
109: METHOD(task_t, migrate, void,
110: private_ike_redirect_t *this, ike_sa_t *ike_sa)
111: {
112: this->ike_sa = ike_sa;
113: }
114:
115: METHOD(task_t, destroy, void,
116: private_ike_redirect_t *this)
117: {
118: DESTROY_IF(this->gateway);
119: free(this);
120: }
121:
122: /*
123: * Described in header.
124: */
125: ike_redirect_t *ike_redirect_create(ike_sa_t *ike_sa, identification_t *to)
126: {
127: private_ike_redirect_t *this;
128:
129: INIT(this,
130: .public = {
131: .task = {
132: .get_type = _get_type,
133: .build = _build_r,
134: .process = _process_r,
135: .migrate = _migrate,
136: .destroy = _destroy,
137: },
138: },
139: .ike_sa = ike_sa,
140: );
141:
142: if (to)
143: {
144: this->gateway = to->clone(to);
145: this->public.task.build = _build_i;
146: this->public.task.process = _process_i;
147: }
148:
149: return &this->public;
150: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>