Implemented Traffic Flow Confidentiality padding in kernel_interface
[strongswan.git] / src / libcharon / 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 METHOD(kernel_ipsec_t, get_spi, status_t,
38 private_load_tester_ipsec_t *this, host_t *src, host_t *dst,
39 u_int8_t protocol, u_int32_t reqid, u_int32_t *spi)
40 {
41 *spi = ++this->spi;
42 return SUCCESS;
43 }
44
45 METHOD(kernel_ipsec_t, get_cpi, status_t,
46 private_load_tester_ipsec_t *this, host_t *src, host_t *dst,
47 u_int32_t reqid, u_int16_t *cpi)
48 {
49 return FAILED;
50 }
51
52 METHOD(kernel_ipsec_t, add_sa, status_t,
53 private_load_tester_ipsec_t *this, host_t *src, host_t *dst,
54 u_int32_t spi, u_int8_t protocol, u_int32_t reqid, mark_t mark,
55 u_int32_t tfc, lifetime_cfg_t *lifetime, u_int16_t enc_alg, chunk_t enc_key,
56 u_int16_t int_alg, chunk_t int_key, ipsec_mode_t mode, u_int16_t ipcomp,
57 u_int16_t cpi, bool encap, bool inbound, traffic_selector_t *src_ts,
58 traffic_selector_t *dst_ts)
59 {
60 return SUCCESS;
61 }
62
63 METHOD(kernel_ipsec_t, update_sa, status_t,
64 private_load_tester_ipsec_t *this, u_int32_t spi, u_int8_t protocol,
65 u_int16_t cpi, host_t *src, host_t *dst, host_t *new_src,
66 host_t *new_dst, bool encap, bool new_encap, mark_t mark)
67 {
68 return SUCCESS;
69 }
70
71 METHOD(kernel_ipsec_t, query_sa, status_t,
72 private_load_tester_ipsec_t *this, host_t *src, host_t *dst,
73 u_int32_t spi, u_int8_t protocol, mark_t mark, u_int64_t *bytes)
74 {
75 return NOT_SUPPORTED;
76 }
77
78 METHOD(kernel_ipsec_t, del_sa, status_t,
79 private_load_tester_ipsec_t *this, host_t *src, host_t *dst,
80 u_int32_t spi, u_int8_t protocol, u_int16_t cpi, mark_t mark)
81 {
82 return SUCCESS;
83 }
84
85 METHOD(kernel_ipsec_t, add_policy, status_t,
86 private_load_tester_ipsec_t *this, host_t *src, host_t *dst,
87 traffic_selector_t *src_ts, traffic_selector_t *dst_ts,
88 policy_dir_t direction, policy_type_t type, ipsec_sa_cfg_t *sa,
89 mark_t mark, bool routed)
90 {
91 return SUCCESS;
92 }
93
94 METHOD(kernel_ipsec_t, query_policy, status_t,
95 private_load_tester_ipsec_t *this, traffic_selector_t *src_ts,
96 traffic_selector_t *dst_ts, policy_dir_t direction, mark_t mark,
97 u_int32_t *use_time)
98 {
99 *use_time = time_monotonic(NULL);
100 return SUCCESS;
101 }
102
103 METHOD(kernel_ipsec_t, del_policy, status_t,
104 private_load_tester_ipsec_t *this, traffic_selector_t *src_ts,
105 traffic_selector_t *dst_ts, policy_dir_t direction, mark_t mark,
106 bool unrouted)
107 {
108 return SUCCESS;
109 }
110
111 METHOD(kernel_ipsec_t, bypass_socket, bool,
112 private_load_tester_ipsec_t *this, int fd, int family)
113 {
114 return TRUE;
115 }
116
117 METHOD(kernel_ipsec_t, destroy, void,
118 private_load_tester_ipsec_t *this)
119 {
120 free(this);
121 }
122
123 /*
124 * Described in header.
125 */
126 load_tester_ipsec_t *load_tester_ipsec_create()
127 {
128 private_load_tester_ipsec_t *this;
129
130 INIT(this,
131 .public = {
132 .interface = {
133 .get_spi = _get_spi,
134 .get_cpi = _get_cpi,
135 .add_sa = _add_sa,
136 .update_sa = _update_sa,
137 .query_sa = _query_sa,
138 .del_sa = _del_sa,
139 .add_policy = _add_policy,
140 .query_policy = _query_policy,
141 .del_policy = _del_policy,
142 .bypass_socket = _bypass_socket,
143 .destroy = _destroy,
144 },
145 },
146 .spi = 0,
147 );
148
149 return &this->public;
150 }
151