2 * Copyright (C) 2010 Martin Willi
4 * Copyright (C) secunet Security Networks AG
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>.
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
19 typedef struct private_unencrypted_notify_t private_unencrypted_notify_t
;
22 * Private data of an unencrypted_notify_t object.
24 struct private_unencrypted_notify_t
{
27 * Implements the hook_t interface.
52 * TRUE for a ESP protocol notify, FALSE for IKE
57 METHOD(listener_t
, ike_updown
, bool,
58 private_unencrypted_notify_t
*this, ike_sa_t
*ike_sa
, bool up
)
65 notify_payload_t
*notify
;
66 chunk_t data
= chunk_empty
;
69 type
= atoi(this->type
);
72 if (!enum_from_name(notify_type_names
, this->type
, &type
))
74 DBG1(DBG_CFG
, "unknown notify: '%s', skipped", this->type
);
78 if (strncaseeq(this->data
, "0x", 2))
80 data
= chunk_skip(chunk_create(this->data
, strlen(this->data
)), 2);
81 data
= chunk_from_hex(data
, NULL
);
83 else if (strlen(this->data
))
85 data
= chunk_clone(chunk_create(this->data
, strlen(this->data
)));
87 notify
= notify_payload_create_from_protocol_and_type(PLV2_NOTIFY
,
88 this->esp
? PROTO_ESP
: PROTO_IKE
, type
);
89 notify
->set_spi(notify
, this->spi
);
92 notify
->set_notification_data(notify
, data
);
96 DBG1(DBG_CFG
, "injecting unencrypted INFORMATIONAL message");
98 message
= message_create(IKEV2_MAJOR_VERSION
, IKEV2_MINOR_VERSION
);
99 message
->set_message_id(message
, this->id
);
100 message
->set_ike_sa_id(message
, ike_sa
->get_id(ike_sa
));
101 message
->set_exchange_type(message
, INFORMATIONAL
);
102 message
->set_request(message
, TRUE
);
103 host
= ike_sa
->get_my_host(ike_sa
);
104 message
->set_source(message
, host
->clone(host
));
105 host
= ike_sa
->get_other_host(ike_sa
);
106 message
->set_destination(message
, host
->clone(host
));
107 message
->add_payload(message
, ¬ify
->payload_interface
);
108 if (message
->generate(message
, NULL
, &packet
) != SUCCESS
)
110 DBG1(DBG_CFG
, "generating message failed");
111 message
->destroy(message
);
114 message
->destroy(message
);
115 charon
->sender
->send(charon
->sender
, packet
);
120 METHOD(hook_t
, destroy
, void,
121 private_unencrypted_notify_t
*this)
127 * Create the IKE_AUTH fill hook
129 hook_t
*unencrypted_notify_hook_create(char *name
)
131 private_unencrypted_notify_t
*this;
136 .ike_updown
= _ike_updown
,
140 .id
= conftest
->test
->get_int(conftest
->test
,
141 "hooks.%s.id", 2, name
),
142 .type
= conftest
->test
->get_str(conftest
->test
,
143 "hooks.%s.type", "", name
),
144 .data
= conftest
->test
->get_str(conftest
->test
,
145 "hooks.%s.data", "", name
),
146 .spi
= conftest
->test
->get_int(conftest
->test
,
147 "hooks.%s.spi", 0, name
),
148 .esp
= conftest
->test
->get_bool(conftest
->test
,
149 "hooks.%s.esp", FALSE
, name
),