Introduce priority classes for jobs
[strongswan.git] / src / libcharon / processing / jobs / process_message_job.c
1 /*
2 * Copyright (C) 2005-2007 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
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 "process_message_job.h"
18
19 #include <daemon.h>
20
21 typedef struct private_process_message_job_t private_process_message_job_t;
22
23 /**
24 * Private data of an process_message_job_t Object
25 */
26 struct private_process_message_job_t {
27 /**
28 * public process_message_job_t interface
29 */
30 process_message_job_t public;
31
32 /**
33 * Message associated with this job
34 */
35 message_t *message;
36 };
37
38 METHOD(job_t, destroy, void,
39 private_process_message_job_t *this)
40 {
41 this->message->destroy(this->message);
42 free(this);
43 }
44
45 METHOD(job_t, execute, void,
46 private_process_message_job_t *this)
47 {
48 ike_sa_t *ike_sa;
49
50 #ifdef ME
51 /* if this is an unencrypted INFORMATIONAL exchange it is likely a
52 * connectivity check. */
53 if (this->message->get_exchange_type(this->message) == INFORMATIONAL &&
54 this->message->get_first_payload_type(this->message) != ENCRYPTED)
55 {
56 /* theoretically this could also be an error message
57 * see RFC 4306, section 1.5. */
58 DBG1(DBG_NET, "received unencrypted informational: from %#H to %#H",
59 this->message->get_source(this->message),
60 this->message->get_destination(this->message));
61 charon->connect_manager->process_check(charon->connect_manager, this->message);
62 destroy(this);
63 return;
64 }
65 #endif /* ME */
66
67 ike_sa = charon->ike_sa_manager->checkout_by_message(charon->ike_sa_manager,
68 this->message);
69 if (ike_sa)
70 {
71 DBG1(DBG_NET, "received packet: from %#H to %#H",
72 this->message->get_source(this->message),
73 this->message->get_destination(this->message));
74 if (ike_sa->process_message(ike_sa, this->message) == DESTROY_ME)
75 {
76 charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager,
77 ike_sa);
78 }
79 else
80 {
81 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
82 }
83 }
84 destroy(this);
85 }
86
87 METHOD(job_t, get_priority, job_priority_t,
88 private_process_message_job_t *this)
89 {
90 return JOB_PRIO_MEDIUM;
91 }
92
93 /*
94 * Described in header
95 */
96 process_message_job_t *process_message_job_create(message_t *message)
97 {
98 private_process_message_job_t *this;
99
100 INIT(this,
101 .public = {
102 .job_interface = {
103 .execute = _execute,
104 .get_priority = _get_priority,
105 .destroy = _destroy,
106 },
107 },
108 .message = message,
109 );
110
111 return &(this->public);
112 }