Annotation of embedaddon/strongswan/src/conftest/hooks/set_ike_spi.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2010 Martin Willi
3: * Copyright (C) 2010 revosec AG
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 "hook.h"
17:
18: #include <encoding/payloads/unknown_payload.h>
19:
20: typedef struct private_set_ike_spi_t private_set_ike_spi_t;
21:
22: /**
23: * Private data of an set_ike_spi_t object.
24: */
25: struct private_set_ike_spi_t {
26:
27: /**
28: * Implements the hook_t interface.
29: */
30: hook_t hook;
31:
32: /**
33: * Alter requests or responses?
34: */
35: bool req;
36:
37: /**
38: * ID of message to alter.
39: */
40: int id;
41:
42: /**
43: * Initiator SPI
44: */
45: uint64_t spii;
46:
47: /**
48: * Responder SPI
49: */
50: uint64_t spir;
51: };
52:
53: METHOD(listener_t, message, bool,
54: private_set_ike_spi_t *this, ike_sa_t *ike_sa, message_t *message,
55: bool incoming, bool plain)
56: {
57: if (!incoming && plain &&
58: message->get_request(message) == this->req &&
59: message->get_message_id(message) == this->id)
60: {
61: ike_sa_id_t *id;
62:
63: DBG1(DBG_CFG, "setting IKE SPIs to: 0x%llx/0x%llx",
64: this->spii, this->spir);
65:
66: id = message->get_ike_sa_id(message);
67: id->set_initiator_spi(id, this->spii);
68: id->set_responder_spi(id, this->spir);
69: }
70: return TRUE;
71: }
72:
73: METHOD(hook_t, destroy, void,
74: private_set_ike_spi_t *this)
75: {
76: free(this);
77: }
78:
79: /**
80: * Create the IKE_AUTH fill hook
81: */
82: hook_t *set_ike_spi_hook_create(char *name)
83: {
84: private_set_ike_spi_t *this;
85:
86: INIT(this,
87: .hook = {
88: .listener = {
89: .message = _message,
90: },
91: .destroy = _destroy,
92: },
93: .req = conftest->test->get_bool(conftest->test,
94: "hooks.%s.request", TRUE, name),
95: .id = conftest->test->get_int(conftest->test,
96: "hooks.%s.id", 0, name),
97: .spii = strtoull(conftest->test->get_str(conftest->test,
98: "hooks.%s.spii", "0", name), NULL, 16),
99: .spir = strtoull(conftest->test->get_str(conftest->test,
100: "hooks.%s.spir", "0", name), NULL, 16),
101: );
102:
103: return &this->hook;
104: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>