]>
Commit | Line | Data |
---|---|---|
357e960e MW |
1 | /* |
2 | * Copyright (C) 2010 Martin Willi | |
19ef2aec TB |
3 | * |
4 | * Copyright (C) secunet Security Networks AG | |
357e960e MW |
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 "hook.h" | |
18 | ||
19 | #include <encoding/payloads/unknown_payload.h> | |
20 | ||
21 | typedef struct private_set_ike_initiator_t private_set_ike_initiator_t; | |
22 | ||
23 | /** | |
24 | * Private data of an set_ike_initiator_t object. | |
25 | */ | |
26 | struct private_set_ike_initiator_t { | |
27 | ||
28 | /** | |
29 | * Implements the hook_t interface. | |
30 | */ | |
31 | hook_t hook; | |
32 | ||
33 | /** | |
34 | * Alter requests or responses? | |
35 | */ | |
36 | bool req; | |
37 | ||
38 | /** | |
39 | * ID of message to alter. | |
40 | */ | |
41 | int id; | |
42 | }; | |
43 | ||
44 | METHOD(listener_t, message, bool, | |
45 | private_set_ike_initiator_t *this, ike_sa_t *ike_sa, message_t *message, | |
47b8f6ef | 46 | bool incoming, bool plain) |
357e960e | 47 | { |
47b8f6ef | 48 | if (!incoming && plain && |
357e960e MW |
49 | message->get_request(message) == this->req && |
50 | message->get_message_id(message) == this->id) | |
51 | { | |
52 | ike_sa_id_t *id; | |
53 | ||
54 | DBG1(DBG_CFG, "toggling IKE message initiator flag"); | |
55 | id = message->get_ike_sa_id(message); | |
56 | id->switch_initiator(id); | |
57 | } | |
58 | return TRUE; | |
59 | } | |
60 | ||
61 | METHOD(hook_t, destroy, void, | |
62 | private_set_ike_initiator_t *this) | |
63 | { | |
64 | free(this); | |
65 | } | |
66 | ||
67 | /** | |
68 | * Create the IKE_AUTH fill hook | |
69 | */ | |
70 | hook_t *set_ike_initiator_hook_create(char *name) | |
71 | { | |
72 | private_set_ike_initiator_t *this; | |
73 | ||
74 | INIT(this, | |
75 | .hook = { | |
76 | .listener = { | |
77 | .message = _message, | |
78 | }, | |
79 | .destroy = _destroy, | |
80 | }, | |
81 | .req = conftest->test->get_bool(conftest->test, | |
82 | "hooks.%s.request", TRUE, name), | |
83 | .id = conftest->test->get_int(conftest->test, | |
84 | "hooks.%s.id", 0, name), | |
85 | ); | |
86 | ||
87 | return &this->hook; | |
88 | } |