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