Annotation of embedaddon/strongswan/src/conftest/hooks/set_ike_version.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_version_t private_set_ike_version_t;
21:
22: /**
23: * Private data of an set_ike_version_t object.
24: */
25: struct private_set_ike_version_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: * Major version to set
44: */
45: int major;
46:
47: /**
48: * Minor version to set
49: */
50: int minor;
51:
52: /**
53: * Higher version supported?
54: */
55: bool higher;
56: };
57:
58: METHOD(listener_t, message, bool,
59: private_set_ike_version_t *this, ike_sa_t *ike_sa, message_t *message,
60: bool incoming, bool plain)
61: {
62: if (!incoming && plain &&
63: message->get_request(message) == this->req &&
64: message->get_message_id(message) == this->id)
65: {
66: DBG1(DBG_CFG, "setting IKE version of message ID %d to %d.%d",
67: this->id, this->major, this->minor);
68: message->set_major_version(message, this->major);
69: message->set_minor_version(message, this->minor);
70: if (this->higher)
71: {
72: message->set_version_flag(message);
73: }
74: }
75: return TRUE;
76: }
77:
78: METHOD(hook_t, destroy, void,
79: private_set_ike_version_t *this)
80: {
81: free(this);
82: }
83:
84: /**
85: * Create the IKE_AUTH fill hook
86: */
87: hook_t *set_ike_version_hook_create(char *name)
88: {
89: private_set_ike_version_t *this;
90:
91: INIT(this,
92: .hook = {
93: .listener = {
94: .message = _message,
95: },
96: .destroy = _destroy,
97: },
98: .req = conftest->test->get_bool(conftest->test,
99: "hooks.%s.request", TRUE, name),
100: .id = conftest->test->get_int(conftest->test,
101: "hooks.%s.id", 0, name),
102: .major = conftest->test->get_int(conftest->test,
103: "hooks.%s.major", 2, name),
104: .minor = conftest->test->get_int(conftest->test,
105: "hooks.%s.minor", 0, name),
106: .higher = conftest->test->get_bool(conftest->test,
107: "hooks.%s.higher", FALSE, name),
108: );
109:
110: return &this->hook;
111: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>