merging kernel_klips plugin back into trunk
[strongswan.git] / src / charon / plugins / load_tester / load_tester_ipsec.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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 * $Id$
16 */
17
18 #include "load_tester_ipsec.h"
19
20 #include <time.h>
21
22 typedef struct private_load_tester_ipsec_t private_load_tester_ipsec_t;
23
24 /**
25 * Private variables and functions of kernel_pfkey class.
26 */
27 struct private_load_tester_ipsec_t {
28 /**
29 * Public interface.
30 */
31 load_tester_ipsec_t public;
32
33 /**
34 * faked SPI counter
35 */
36 u_int32_t spi;
37 };
38
39 /**
40 * Implementation of kernel_interface_t.get_spi.
41 */
42 static status_t get_spi(private_load_tester_ipsec_t *this,
43 host_t *src, host_t *dst,
44 protocol_id_t protocol, u_int32_t reqid,
45 u_int32_t *spi)
46 {
47 *spi = ++this->spi;
48 return SUCCESS;
49 }
50
51 /**
52 * Implementation of kernel_interface_t.get_cpi.
53 */
54 static status_t get_cpi(private_load_tester_ipsec_t *this,
55 host_t *src, host_t *dst,
56 u_int32_t reqid, u_int16_t *cpi)
57 {
58 return FAILED;
59 }
60
61 /**
62 * Implementation of kernel_interface_t.add_sa.
63 */
64 static status_t add_sa(private_load_tester_ipsec_t *this,
65 host_t *src, host_t *dst, u_int32_t spi,
66 protocol_id_t protocol, u_int32_t reqid,
67 u_int64_t expire_soft, u_int64_t expire_hard,
68 u_int16_t enc_alg, chunk_t enc_key,
69 u_int16_t int_alg, chunk_t int_key,
70 ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
71 bool encap, bool inbound)
72 {
73 return SUCCESS;
74 }
75
76 /**
77 * Implementation of kernel_interface_t.update_sa.
78 */
79 static status_t update_sa(private_load_tester_ipsec_t *this,
80 u_int32_t spi, protocol_id_t protocol, u_int16_t cpi,
81 host_t *src, host_t *dst,
82 host_t *new_src, host_t *new_dst,
83 bool encap, bool new_encap)
84 {
85 return SUCCESS;
86 }
87
88 /**
89 * Implementation of kernel_interface_t.del_sa.
90 */
91 static status_t del_sa(private_load_tester_ipsec_t *this, host_t *dst,
92 u_int32_t spi, protocol_id_t protocol, u_int16_t cpi)
93 {
94 return SUCCESS;
95 }
96
97 /**
98 * Implementation of kernel_interface_t.add_policy.
99 */
100 static status_t add_policy(private_load_tester_ipsec_t *this,
101 host_t *src, host_t *dst,
102 traffic_selector_t *src_ts,
103 traffic_selector_t *dst_ts,
104 policy_dir_t direction, protocol_id_t protocol,
105 u_int32_t reqid, ipsec_mode_t mode, u_int16_t ipcomp,
106 u_int16_t cpi, bool routed)
107 {
108 return SUCCESS;
109 }
110
111 /**
112 * Implementation of kernel_interface_t.query_policy.
113 */
114 static status_t query_policy(private_load_tester_ipsec_t *this,
115 traffic_selector_t *src_ts,
116 traffic_selector_t *dst_ts,
117 policy_dir_t direction, u_int32_t *use_time)
118 {
119 *use_time = time(NULL);
120 return SUCCESS;
121 }
122
123 /**
124 * Implementation of kernel_interface_t.del_policy.
125 */
126 static status_t del_policy(private_load_tester_ipsec_t *this,
127 traffic_selector_t *src_ts,
128 traffic_selector_t *dst_ts,
129 policy_dir_t direction, bool unrouted)
130 {
131 return SUCCESS;
132 }
133
134 /**
135 * Implementation of kernel_interface_t.destroy.
136 */
137 static void destroy(private_load_tester_ipsec_t *this)
138 {
139 free(this);
140 }
141
142 /*
143 * Described in header.
144 */
145 load_tester_ipsec_t *load_tester_ipsec_create()
146 {
147 private_load_tester_ipsec_t *this = malloc_thing(private_load_tester_ipsec_t);
148
149 /* public functions */
150 this->public.interface.get_spi = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,protocol_id_t,u_int32_t,u_int32_t*))get_spi;
151 this->public.interface.get_cpi = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,u_int32_t,u_int16_t*))get_cpi;
152 this->public.interface.add_sa = (status_t(*)(kernel_ipsec_t *,host_t*,host_t*,u_int32_t,protocol_id_t,u_int32_t,u_int64_t,u_int64_t,u_int16_t,chunk_t,u_int16_t,chunk_t,ipsec_mode_t,u_int16_t,u_int16_t,bool,bool))add_sa;
153 this->public.interface.update_sa = (status_t(*)(kernel_ipsec_t*,u_int32_t,protocol_id_t,u_int16_t,host_t*,host_t*,host_t*,host_t*,bool,bool))update_sa;
154 this->public.interface.del_sa = (status_t(*)(kernel_ipsec_t*,host_t*,u_int32_t,protocol_id_t,u_int16_t))del_sa;
155 this->public.interface.add_policy = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,traffic_selector_t*,traffic_selector_t*,policy_dir_t,protocol_id_t,u_int32_t,ipsec_mode_t,u_int16_t,u_int16_t,bool))add_policy;
156 this->public.interface.query_policy = (status_t(*)(kernel_ipsec_t*,traffic_selector_t*,traffic_selector_t*,policy_dir_t,u_int32_t*))query_policy;
157 this->public.interface.del_policy = (status_t(*)(kernel_ipsec_t*,traffic_selector_t*,traffic_selector_t*,policy_dir_t,bool))del_policy;
158 this->public.interface.destroy = (void(*)(kernel_ipsec_t*)) destroy;
159
160 this->spi = 0;
161
162 return &this->public;
163 }
164