payload: Use common prefixes for all payload type identifiers
[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, job_requeue_t,
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) != PLV2_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 return JOB_REQUEUE_NONE;
63 }
64 #endif /* ME */
65
66 ike_sa = charon->ike_sa_manager->checkout_by_message(charon->ike_sa_manager,
67 this->message);
68 if (ike_sa)
69 {
70 DBG1(DBG_NET, "received packet: from %#H to %#H (%zu bytes)",
71 this->message->get_source(this->message),
72 this->message->get_destination(this->message),
73 this->message->get_packet_data(this->message).len);
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 return JOB_REQUEUE_NONE;
85 }
86
87 METHOD(job_t, get_priority, job_priority_t,
88 private_process_message_job_t *this)
89 {
90 switch (this->message->get_exchange_type(this->message))
91 {
92 case IKE_AUTH:
93 /* IKE auth is rather expensive and often blocking, low priority */
94 return JOB_PRIO_LOW;
95 case INFORMATIONAL:
96 /* INFORMATIONALs are inexpensive, for DPD we should have low
97 * reaction times */
98 return JOB_PRIO_HIGH;
99 case IKE_SA_INIT:
100 case CREATE_CHILD_SA:
101 default:
102 /* IKE_SA_INIT is expensive, but we will drop them in the receiver
103 * if we are overloaded */
104 return JOB_PRIO_MEDIUM;
105 }
106 }
107
108 /*
109 * Described in header
110 */
111 process_message_job_t *process_message_job_create(message_t *message)
112 {
113 private_process_message_job_t *this;
114
115 INIT(this,
116 .public = {
117 .job_interface = {
118 .execute = _execute,
119 .get_priority = _get_priority,
120 .destroy = _destroy,
121 },
122 },
123 .message = message,
124 );
125
126 return &(this->public);
127 }