blob: eed910edb9309ce3701b155e438dc8960c76d166 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * decap.c : IPSec tunnel support
3 *
4 * Copyright (c) 2015 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <vnet/vnet.h>
19#include <vnet/api_errno.h>
20#include <vnet/ip/ip.h>
21#include <vnet/interface.h>
Pierre Pfister4c422f92018-12-10 11:19:08 +010022#include <vnet/fib/fib.h>
Neale Ranns12989b52019-09-26 16:20:19 +000023#include <vnet/ipip/ipip.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070024
25#include <vnet/ipsec/ipsec.h>
Neale Rannsc87b66c2019-02-07 07:26:12 -080026#include <vnet/ipsec/ipsec_tun.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070027
28static clib_error_t *
29set_interface_spd_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070030 unformat_input_t * input,
31 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -070032{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070033 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -070034 ipsec_main_t *im = &ipsec_main;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070035 u32 sw_if_index = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070036 u32 spd_id;
37 int is_add = 1;
Billy McFalla9a20e72017-02-15 11:39:12 -050038 clib_error_t *error = NULL;
Benoît Ganne40aa27e2020-11-06 14:14:23 +010039 int err;
Ed Warnickecb9cada2015-12-08 15:45:58 -070040
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070041 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -070042 return 0;
43
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070044 if (unformat
45 (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main,
46 &sw_if_index, &spd_id))
Ed Warnickecb9cada2015-12-08 15:45:58 -070047 ;
48 else if (unformat (line_input, "del"))
49 is_add = 0;
50 else
Billy McFalla9a20e72017-02-15 11:39:12 -050051 {
52 error = clib_error_return (0, "parse error: '%U'",
53 format_unformat_error, line_input);
54 goto done;
55 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070056
Benoît Ganne40aa27e2020-11-06 14:14:23 +010057 err = ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add);
58 switch (err)
59 {
60 case VNET_API_ERROR_SYSCALL_ERROR_1:
61 error = clib_error_return (0, "no such spd-id");
62 break;
63 case VNET_API_ERROR_SYSCALL_ERROR_2:
64 error = clib_error_return (0, "spd already assigned");
65 break;
66 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070067
Billy McFalla9a20e72017-02-15 11:39:12 -050068done:
69 unformat_free (line_input);
70
71 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -070072}
73
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070074/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070075VLIB_CLI_COMMAND (set_interface_spd_command, static) = {
76 .path = "set interface ipsec spd",
77 .short_help =
78 "set interface ipsec spd <int> <id>",
79 .function = set_interface_spd_command_fn,
80};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070081/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070082
83static clib_error_t *
84ipsec_sa_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070085 unformat_input_t * input,
86 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -070087{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070088 unformat_input_t _line_input, *line_input = &_line_input;
Neale Ranns8d7c5022019-02-06 01:41:05 -080089 ipsec_crypto_alg_t crypto_alg;
90 ipsec_integ_alg_t integ_alg;
91 ipsec_protocol_t proto;
92 ipsec_sa_flags_t flags;
93 clib_error_t *error;
Kingwel Xied3d12052019-03-07 06:34:30 -050094 ipsec_key_t ck = { 0 };
95 ipsec_key_t ik = { 0 };
Neale Rannsabc56602020-04-01 09:45:23 +000096 u32 id, spi, salt, sai;
Mohammed Hawari048189e2021-02-05 19:04:42 +010097 int i = 0;
Neale Rannsabc56602020-04-01 09:45:23 +000098 u16 udp_src, udp_dst;
Neale Ranns8d7c5022019-02-06 01:41:05 -080099 int is_add, rv;
Benoît Gannebdd8b572020-07-28 15:56:15 +0200100 u32 m_args = 0;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000101 tunnel_t tun;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102
Neale Ranns8dc75c02019-12-10 01:08:19 +0000103 salt = 0;
Neale Ranns8d7c5022019-02-06 01:41:05 -0800104 error = NULL;
105 is_add = 0;
106 flags = IPSEC_SA_FLAG_NONE;
107 proto = IPSEC_PROTOCOL_ESP;
Neale Rannse6be7022019-06-04 15:37:34 +0000108 integ_alg = IPSEC_INTEG_ALG_NONE;
109 crypto_alg = IPSEC_CRYPTO_ALG_NONE;
Neale Rannsabc56602020-04-01 09:45:23 +0000110 udp_src = udp_dst = IPSEC_UDP_PORT_NONE;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700112 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113 return 0;
114
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700115 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
116 {
Neale Ranns8d7c5022019-02-06 01:41:05 -0800117 if (unformat (line_input, "add %u", &id))
Benoît Gannebdd8b572020-07-28 15:56:15 +0200118 {
119 is_add = 1;
120 m_args |= 1 << 0;
121 }
Neale Ranns8d7c5022019-02-06 01:41:05 -0800122 else if (unformat (line_input, "del %u", &id))
Benoît Gannebdd8b572020-07-28 15:56:15 +0200123 {
124 is_add = 0;
125 m_args |= 1 << 0;
126 }
Neale Ranns8d7c5022019-02-06 01:41:05 -0800127 else if (unformat (line_input, "spi %u", &spi))
Benoît Gannebdd8b572020-07-28 15:56:15 +0200128 m_args |= 1 << 1;
Neale Rannsc87b66c2019-02-07 07:26:12 -0800129 else if (unformat (line_input, "salt 0x%x", &salt))
Neale Ranns80f6fd52019-04-16 02:41:34 +0000130 ;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700131 else if (unformat (line_input, "esp"))
Neale Ranns8d7c5022019-02-06 01:41:05 -0800132 proto = IPSEC_PROTOCOL_ESP;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700133 else if (unformat (line_input, "ah"))
Neale Ranns8d7c5022019-02-06 01:41:05 -0800134 proto = IPSEC_PROTOCOL_AH;
135 else if (unformat (line_input, "crypto-key %U",
136 unformat_ipsec_key, &ck))
137 ;
138 else if (unformat (line_input, "crypto-alg %U",
139 unformat_ipsec_crypto_alg, &crypto_alg))
140 ;
141 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
142 ;
143 else if (unformat (line_input, "integ-alg %U",
144 unformat_ipsec_integ_alg, &integ_alg))
145 ;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000146 else if (unformat (line_input, " %U", unformat_tunnel, &tun))
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700147 {
Neale Ranns8d7c5022019-02-06 01:41:05 -0800148 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000149 if (AF_IP6 == tunnel_get_af (&tun))
Neale Ranns8d7c5022019-02-06 01:41:05 -0800150 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700151 }
Mohammed Hawari048189e2021-02-05 19:04:42 +0100152 else if (unformat (line_input, "udp-src-port %d", &i))
153 udp_src = i;
154 else if (unformat (line_input, "udp-dst-port %d", &i))
155 udp_dst = i;
Christian Hopps99975382020-07-17 09:53:18 -0400156 else if (unformat (line_input, "inbound"))
157 flags |= IPSEC_SA_FLAG_IS_INBOUND;
158 else if (unformat (line_input, "use-anti-replay"))
159 flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
160 else if (unformat (line_input, "use-esn"))
161 flags |= IPSEC_SA_FLAG_USE_ESN;
Radu Nicolau717de092018-08-03 10:37:24 +0100162 else if (unformat (line_input, "udp-encap"))
Neale Ranns8d7c5022019-02-06 01:41:05 -0800163 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700164 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500165 {
166 error = clib_error_return (0, "parse error: '%U'",
167 format_unformat_error, line_input);
168 goto done;
169 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700170 }
Christian Hopps99975382020-07-17 09:53:18 -0400171 if ((flags & IPSEC_SA_FLAG_IS_INBOUND)
172 && !(flags & IPSEC_SA_FLAG_IS_TUNNEL))
173 {
174 error = clib_error_return (0, "inbound specified on non-tunnel SA");
175 goto done;
176 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177
Benoît Gannebdd8b572020-07-28 15:56:15 +0200178 if (!(m_args & 1))
179 {
180 error = clib_error_return (0, "missing id");
181 goto done;
182 }
183
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000184 if (is_add)
Benoît Gannebdd8b572020-07-28 15:56:15 +0200185 {
186 if (!(m_args & 2))
187 {
188 error = clib_error_return (0, "missing spi");
189 goto done;
190 }
Neale Ranns9ec846c2021-02-09 14:04:02 +0000191 rv = ipsec_sa_add_and_lock (id, spi, proto, crypto_alg, &ck, integ_alg,
192 &ik, flags, clib_host_to_net_u32 (salt),
193 udp_src, udp_dst, &tun, &sai);
Benoît Gannebdd8b572020-07-28 15:56:15 +0200194 }
Neale Ranns8d7c5022019-02-06 01:41:05 -0800195 else
Benoît Gannebdd8b572020-07-28 15:56:15 +0200196 {
197 rv = ipsec_sa_unlock_id (id);
198 }
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000199
Neale Ranns8d7c5022019-02-06 01:41:05 -0800200 if (rv)
Neale Rannse6be7022019-06-04 15:37:34 +0000201 error = clib_error_return (0, "failed");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202
Billy McFalla9a20e72017-02-15 11:39:12 -0500203done:
204 unformat_free (line_input);
205
206 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207}
208
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700209/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
211 .path = "ipsec sa",
212 .short_help =
213 "ipsec sa [add|del]",
214 .function = ipsec_sa_add_del_command_fn,
215};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700216/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700217
218static clib_error_t *
219ipsec_spd_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700220 unformat_input_t * input,
221 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700222{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700223 unformat_input_t _line_input, *line_input = &_line_input;
Damjan Marion3f54b182016-08-16 11:27:02 +0200224 u32 spd_id = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700225 int is_add = ~0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500226 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700227
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700228 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700229 return 0;
230
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700231 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
232 {
233 if (unformat (line_input, "add"))
234 is_add = 1;
235 else if (unformat (line_input, "del"))
236 is_add = 0;
237 else if (unformat (line_input, "%u", &spd_id))
238 ;
239 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500240 {
241 error = clib_error_return (0, "parse error: '%U'",
242 format_unformat_error, line_input);
243 goto done;
244 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700245 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700246
Damjan Marion3f54b182016-08-16 11:27:02 +0200247 if (spd_id == ~0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500248 {
249 error = clib_error_return (0, "please specify SPD ID");
250 goto done;
251 }
Damjan Marion3f54b182016-08-16 11:27:02 +0200252
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700253 ipsec_add_del_spd (vm, spd_id, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254
Billy McFalla9a20e72017-02-15 11:39:12 -0500255done:
256 unformat_free (line_input);
257
258 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259}
260
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700261/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700262VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
263 .path = "ipsec spd",
264 .short_help =
265 "ipsec spd [add|del] <id>",
266 .function = ipsec_spd_add_del_command_fn,
267};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700268/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269
270
271static clib_error_t *
272ipsec_policy_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700273 unformat_input_t * input,
274 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700275{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700276 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700277 ipsec_policy_t p;
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800278 int rv, is_add = 0;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000279 u32 tmp, tmp2, stat_index, local_range_set, remote_range_set;
Billy McFalla9a20e72017-02-15 11:39:12 -0500280 clib_error_t *error = NULL;
Neale Ranns9f231d42019-03-19 10:06:00 +0000281 u32 is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700282
Dave Barachb7b92992018-10-17 10:38:51 -0400283 clib_memset (&p, 0, sizeof (p));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284 p.lport.stop = p.rport.stop = ~0;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000285 remote_range_set = local_range_set = is_outbound = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700287 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700288 return 0;
289
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700290 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
291 {
292 if (unformat (line_input, "add"))
293 is_add = 1;
294 else if (unformat (line_input, "del"))
295 is_add = 0;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000296 else if (unformat (line_input, "ip6"))
297 p.is_ipv6 = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700298 else if (unformat (line_input, "spd %u", &p.id))
299 ;
300 else if (unformat (line_input, "inbound"))
Neale Ranns9f231d42019-03-19 10:06:00 +0000301 is_outbound = 0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700302 else if (unformat (line_input, "outbound"))
Neale Ranns9f231d42019-03-19 10:06:00 +0000303 is_outbound = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700304 else if (unformat (line_input, "priority %d", &p.priority))
305 ;
306 else if (unformat (line_input, "protocol %u", &tmp))
307 p.protocol = (u8) tmp;
308 else
309 if (unformat
310 (line_input, "action %U", unformat_ipsec_policy_action,
311 &p.policy))
312 {
313 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
Billy McFalla9a20e72017-02-15 11:39:12 -0500314 {
315 error = clib_error_return (0, "unsupported action: 'resolve'");
316 goto done;
317 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700318 }
319 else if (unformat (line_input, "sa %u", &p.sa_id))
320 ;
321 else if (unformat (line_input, "local-ip-range %U - %U",
322 unformat_ip4_address, &p.laddr.start.ip4,
323 unformat_ip4_address, &p.laddr.stop.ip4))
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000324 local_range_set = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700325 else if (unformat (line_input, "remote-ip-range %U - %U",
326 unformat_ip4_address, &p.raddr.start.ip4,
327 unformat_ip4_address, &p.raddr.stop.ip4))
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000328 remote_range_set = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700329 else if (unformat (line_input, "local-ip-range %U - %U",
330 unformat_ip6_address, &p.laddr.start.ip6,
331 unformat_ip6_address, &p.laddr.stop.ip6))
332 {
333 p.is_ipv6 = 1;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000334 local_range_set = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700335 }
336 else if (unformat (line_input, "remote-ip-range %U - %U",
337 unformat_ip6_address, &p.raddr.start.ip6,
338 unformat_ip6_address, &p.raddr.stop.ip6))
339 {
340 p.is_ipv6 = 1;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000341 remote_range_set = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700342 }
343 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
344 {
345 p.lport.start = tmp;
346 p.lport.stop = tmp2;
347 }
348 else
349 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
350 {
351 p.rport.start = tmp;
352 p.rport.stop = tmp2;
353 }
354 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500355 {
356 error = clib_error_return (0, "parse error: '%U'",
357 format_unformat_error, line_input);
358 goto done;
359 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700360 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700361
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000362 if (!remote_range_set)
363 {
364 if (p.is_ipv6)
365 clib_memset (&p.raddr.stop.ip6, 0xff, 16);
366 else
367 clib_memset (&p.raddr.stop.ip4, 0xff, 4);
368 }
369 if (!local_range_set)
370 {
371 if (p.is_ipv6)
372 clib_memset (&p.laddr.stop.ip6, 0xff, 16);
373 else
374 clib_memset (&p.laddr.stop.ip4, 0xff, 4);
375 }
376
Neale Ranns9f231d42019-03-19 10:06:00 +0000377 rv = ipsec_policy_mk_type (is_outbound, p.is_ipv6, p.policy, &p.type);
378
379 if (rv)
380 {
381 error = clib_error_return (0, "unsupported policy type for:",
382 " outboud:%s %s action:%U",
383 (is_outbound ? "yes" : "no"),
384 (p.is_ipv6 ? "IPv4" : "IPv6"),
385 format_ipsec_policy_action, p.policy);
386 goto done;
387 }
388
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800389 rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index);
390
391 if (!rv)
392 vlib_cli_output (vm, "policy-index:%d", stat_index);
393 else
394 vlib_cli_output (vm, "error:%d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500395
396done:
397 unformat_free (line_input);
398
399 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700400}
401
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700402/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700403VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
404 .path = "ipsec policy",
405 .short_help =
406 "ipsec policy [add|del] spd <id> priority <n> ",
407 .function = ipsec_policy_add_del_command_fn,
408};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700409/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410
Neale Rannsb294f102019-04-03 13:17:50 +0000411static void
Neale Ranns670027a2019-08-27 12:47:17 +0000412ipsec_sa_show_all (vlib_main_t * vm, ipsec_main_t * im, u8 detail)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700413{
Neale Rannsb294f102019-04-03 13:17:50 +0000414 u32 sai;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700415
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700416 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100417 pool_foreach_index (sai, im->sad) {
Neale Ranns670027a2019-08-27 12:47:17 +0000418 vlib_cli_output(vm, "%U", format_ipsec_sa, sai,
419 (detail ? IPSEC_FORMAT_DETAIL : IPSEC_FORMAT_BRIEF));
Damjan Marionb2c31b62020-12-13 21:47:40 +0100420 }
Neale Rannsb294f102019-04-03 13:17:50 +0000421 /* *INDENT-ON* */
422}
423
424static void
425ipsec_spd_show_all (vlib_main_t * vm, ipsec_main_t * im)
426{
427 u32 spdi;
428
429 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100430 pool_foreach_index (spdi, im->spds) {
Neale Rannsb294f102019-04-03 13:17:50 +0000431 vlib_cli_output(vm, "%U", format_ipsec_spd, spdi);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100432 }
Neale Rannsb294f102019-04-03 13:17:50 +0000433 /* *INDENT-ON* */
434}
435
436static void
437ipsec_spd_bindings_show_all (vlib_main_t * vm, ipsec_main_t * im)
438{
439 u32 spd_id, sw_if_index;
Neale Rannsd83c4a82019-06-14 06:48:27 -0700440 ipsec_spd_t *spd;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700441
Neale Ranns311124e2019-01-24 04:52:25 -0800442 vlib_cli_output (vm, "SPD Bindings:");
Neale Ranns8d7c5022019-02-06 01:41:05 -0800443
Neale Rannsb294f102019-04-03 13:17:50 +0000444 /* *INDENT-OFF* */
Neale Ranns311124e2019-01-24 04:52:25 -0800445 hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({
Neale Rannsd83c4a82019-06-14 06:48:27 -0700446 spd = pool_elt_at_index (im->spds, spd_id);
447 vlib_cli_output (vm, " %d -> %U", spd->id,
Neale Ranns8d7c5022019-02-06 01:41:05 -0800448 format_vnet_sw_if_index_name, im->vnet_main,
449 sw_if_index);
Neale Ranns311124e2019-01-24 04:52:25 -0800450 }));
451 /* *INDENT-ON* */
Neale Rannsb294f102019-04-03 13:17:50 +0000452}
Neale Ranns311124e2019-01-24 04:52:25 -0800453
Neale Ranns12989b52019-09-26 16:20:19 +0000454static walk_rc_t
455ipsec_tun_protect_show_one (index_t itpi, void *ctx)
Neale Rannsb294f102019-04-03 13:17:50 +0000456{
Neale Ranns28287212019-12-16 00:53:11 +0000457 vlib_cli_output (ctx, "%U", format_ipsec_tun_protect_index, itpi);
Neale Rannsb294f102019-04-03 13:17:50 +0000458
Neale Ranns12989b52019-09-26 16:20:19 +0000459 return (WALK_CONTINUE);
460}
461
462static void
463ipsec_tunnel_show_all (vlib_main_t * vm)
464{
465 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
Neale Rannsb294f102019-04-03 13:17:50 +0000466}
467
468static clib_error_t *
469show_ipsec_command_fn (vlib_main_t * vm,
470 unformat_input_t * input, vlib_cli_command_t * cmd)
471{
472 ipsec_main_t *im = &ipsec_main;
473
Neale Ranns670027a2019-08-27 12:47:17 +0000474 ipsec_sa_show_all (vm, im, 0);
Neale Rannsb294f102019-04-03 13:17:50 +0000475 ipsec_spd_show_all (vm, im);
476 ipsec_spd_bindings_show_all (vm, im);
Neale Ranns12989b52019-09-26 16:20:19 +0000477 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
Neale Rannsb294f102019-04-03 13:17:50 +0000478
Fan Zhangf5395782020-04-29 14:00:03 +0100479 vlib_cli_output (vm, "IPSec async mode: %s",
480 (im->async_mode ? "on" : "off"));
481
Ed Warnickecb9cada2015-12-08 15:45:58 -0700482 return 0;
483}
484
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700485/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700486VLIB_CLI_COMMAND (show_ipsec_command, static) = {
Neale Rannsb294f102019-04-03 13:17:50 +0000487 .path = "show ipsec all",
488 .short_help = "show ipsec all",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700489 .function = show_ipsec_command_fn,
490};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700491/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700492
493static clib_error_t *
Neale Rannsb294f102019-04-03 13:17:50 +0000494show_ipsec_sa_command_fn (vlib_main_t * vm,
495 unformat_input_t * input, vlib_cli_command_t * cmd)
496{
497 ipsec_main_t *im = &ipsec_main;
498 u32 sai = ~0;
Neale Ranns670027a2019-08-27 12:47:17 +0000499 u8 detail = 0;
Neale Rannsb294f102019-04-03 13:17:50 +0000500
501 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
502 {
503 if (unformat (input, "%u", &sai))
504 ;
Neale Ranns670027a2019-08-27 12:47:17 +0000505 if (unformat (input, "detail"))
506 detail = 1;
Neale Rannsb294f102019-04-03 13:17:50 +0000507 else
508 break;
509 }
510
511 if (~0 == sai)
Neale Ranns670027a2019-08-27 12:47:17 +0000512 ipsec_sa_show_all (vm, im, detail);
Neale Rannsb294f102019-04-03 13:17:50 +0000513 else
Christian E. Hopps01d61e72019-09-27 14:43:22 -0400514 vlib_cli_output (vm, "%U", format_ipsec_sa, sai,
515 IPSEC_FORMAT_DETAIL | IPSEC_FORMAT_INSECURE);
Neale Rannsb294f102019-04-03 13:17:50 +0000516
517 return 0;
518}
519
Neale Rannsc87b66c2019-02-07 07:26:12 -0800520static clib_error_t *
521clear_ipsec_sa_command_fn (vlib_main_t * vm,
522 unformat_input_t * input, vlib_cli_command_t * cmd)
523{
524 ipsec_main_t *im = &ipsec_main;
525 u32 sai = ~0;
526
527 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
528 {
529 if (unformat (input, "%u", &sai))
530 ;
531 else
532 break;
533 }
534
535 if (~0 == sai)
536 {
537 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100538 pool_foreach_index (sai, im->sad) {
Neale Rannsc87b66c2019-02-07 07:26:12 -0800539 ipsec_sa_clear(sai);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100540 }
Neale Rannsc87b66c2019-02-07 07:26:12 -0800541 /* *INDENT-ON* */
542 }
543 else
544 {
545 if (pool_is_free_index (im->sad, sai))
546 return clib_error_return (0, "unknown SA index: %d", sai);
547 else
548 ipsec_sa_clear (sai);
549 }
550
551 return 0;
552}
553
Neale Rannsb294f102019-04-03 13:17:50 +0000554/* *INDENT-OFF* */
555VLIB_CLI_COMMAND (show_ipsec_sa_command, static) = {
556 .path = "show ipsec sa",
557 .short_help = "show ipsec sa [index]",
558 .function = show_ipsec_sa_command_fn,
559};
Neale Rannsc87b66c2019-02-07 07:26:12 -0800560
561VLIB_CLI_COMMAND (clear_ipsec_sa_command, static) = {
562 .path = "clear ipsec sa",
563 .short_help = "clear ipsec sa [index]",
564 .function = clear_ipsec_sa_command_fn,
565};
Neale Rannsb294f102019-04-03 13:17:50 +0000566/* *INDENT-ON* */
567
568static clib_error_t *
569show_ipsec_spd_command_fn (vlib_main_t * vm,
570 unformat_input_t * input, vlib_cli_command_t * cmd)
571{
572 ipsec_main_t *im = &ipsec_main;
573 u8 show_bindings = 0;
574 u32 spdi = ~0;
575
576 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
577 {
578 if (unformat (input, "%u", &spdi))
579 ;
580 else if (unformat (input, "bindings"))
581 show_bindings = 1;
582 else
583 break;
584 }
585
586 if (show_bindings)
587 ipsec_spd_bindings_show_all (vm, im);
588 else if (~0 != spdi)
589 vlib_cli_output (vm, "%U", format_ipsec_spd, spdi);
590 else
591 ipsec_spd_show_all (vm, im);
592
593 return 0;
594}
595
596/* *INDENT-OFF* */
597VLIB_CLI_COMMAND (show_ipsec_spd_command, static) = {
598 .path = "show ipsec spd",
599 .short_help = "show ipsec spd [index]",
600 .function = show_ipsec_spd_command_fn,
601};
602/* *INDENT-ON* */
603
604static clib_error_t *
605show_ipsec_tunnel_command_fn (vlib_main_t * vm,
606 unformat_input_t * input,
607 vlib_cli_command_t * cmd)
608{
Neale Ranns12989b52019-09-26 16:20:19 +0000609 ipsec_tunnel_show_all (vm);
Neale Rannsb294f102019-04-03 13:17:50 +0000610
611 return 0;
612}
613
614/* *INDENT-OFF* */
615VLIB_CLI_COMMAND (show_ipsec_tunnel_command, static) = {
616 .path = "show ipsec tunnel",
Neale Ranns12989b52019-09-26 16:20:19 +0000617 .short_help = "show ipsec tunnel",
Neale Rannsb294f102019-04-03 13:17:50 +0000618 .function = show_ipsec_tunnel_command_fn,
619};
620/* *INDENT-ON* */
621
622static clib_error_t *
Klement Sekerab4d30532018-11-08 13:00:02 +0100623ipsec_show_backends_command_fn (vlib_main_t * vm,
624 unformat_input_t * input,
625 vlib_cli_command_t * cmd)
626{
627 ipsec_main_t *im = &ipsec_main;
628 u32 verbose = 0;
629
630 (void) unformat (input, "verbose %u", &verbose);
631
632 vlib_cli_output (vm, "IPsec AH backends available:");
633 u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
634 ipsec_ah_backend_t *ab;
635 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100636 pool_foreach (ab, im->ah_backends) {
Klement Sekerab4d30532018-11-08 13:00:02 +0100637 s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
638 ab - im->ah_backends == im->ah_current_backend ? "yes" : "no");
639 if (verbose) {
640 vlib_node_t *n;
641 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
642 s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
643 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
644 s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
645 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
646 s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
647 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
648 s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
649 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100650 }
Klement Sekerab4d30532018-11-08 13:00:02 +0100651 /* *INDENT-ON* */
652 vlib_cli_output (vm, "%v", s);
653 _vec_len (s) = 0;
654 vlib_cli_output (vm, "IPsec ESP backends available:");
655 s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
656 ipsec_esp_backend_t *eb;
657 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100658 pool_foreach (eb, im->esp_backends) {
Klement Sekerab4d30532018-11-08 13:00:02 +0100659 s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
660 eb - im->esp_backends == im->esp_current_backend ? "yes"
661 : "no");
662 if (verbose) {
663 vlib_node_t *n;
664 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
665 s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
666 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
667 s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
668 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
669 s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
670 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
671 s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
672 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100673 }
Klement Sekerab4d30532018-11-08 13:00:02 +0100674 /* *INDENT-ON* */
675 vlib_cli_output (vm, "%v", s);
676
677 vec_free (s);
678 return 0;
679}
680
681/* *INDENT-OFF* */
682VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = {
683 .path = "show ipsec backends",
684 .short_help = "show ipsec backends",
685 .function = ipsec_show_backends_command_fn,
686};
687/* *INDENT-ON* */
688
689static clib_error_t *
690ipsec_select_backend_command_fn (vlib_main_t * vm,
691 unformat_input_t * input,
692 vlib_cli_command_t * cmd)
693{
Klement Sekerab4d30532018-11-08 13:00:02 +0100694 unformat_input_t _line_input, *line_input = &_line_input;
Neale Rannse8915fc2019-04-23 20:57:55 -0400695 ipsec_main_t *im = &ipsec_main;
696 clib_error_t *error;
697 u32 backend_index;
698
699 error = ipsec_rsc_in_use (im);
700
701 if (error)
702 return error;
703
Klement Sekerab4d30532018-11-08 13:00:02 +0100704 /* Get a line of input. */
705 if (!unformat_user (input, unformat_line_input, line_input))
706 return 0;
707
708 if (unformat (line_input, "ah"))
709 {
710 if (unformat (line_input, "%u", &backend_index))
711 {
712 if (ipsec_select_ah_backend (im, backend_index) < 0)
713 {
714 return clib_error_return (0, "Invalid AH backend index `%u'",
715 backend_index);
716 }
717 }
718 else
719 {
720 return clib_error_return (0, "Invalid backend index `%U'",
721 format_unformat_error, line_input);
722 }
723 }
724 else if (unformat (line_input, "esp"))
725 {
726 if (unformat (line_input, "%u", &backend_index))
727 {
728 if (ipsec_select_esp_backend (im, backend_index) < 0)
729 {
730 return clib_error_return (0, "Invalid ESP backend index `%u'",
731 backend_index);
732 }
733 }
734 else
735 {
736 return clib_error_return (0, "Invalid backend index `%U'",
737 format_unformat_error, line_input);
738 }
739 }
740 else
741 {
742 return clib_error_return (0, "Unknown input `%U'",
743 format_unformat_error, line_input);
744 }
745
746 return 0;
747}
748
749/* *INDENT-OFF* */
750VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = {
751 .path = "ipsec select backend",
752 .short_help = "ipsec select backend <ah|esp> <backend index>",
753 .function = ipsec_select_backend_command_fn,
754};
755
756/* *INDENT-ON* */
757
758static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700759clear_ipsec_counters_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700760 unformat_input_t * input,
761 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700762{
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800763 vlib_clear_combined_counters (&ipsec_spd_policy_counters);
Neale Rannseba31ec2019-02-17 18:04:27 +0000764 vlib_clear_combined_counters (&ipsec_sa_counters);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700765
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800766 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700767}
768
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700769/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700770VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
771 .path = "clear ipsec counters",
772 .short_help = "clear ipsec counters",
773 .function = clear_ipsec_counters_command_fn,
774};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700775/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700776
Neale Rannsc87b66c2019-02-07 07:26:12 -0800777static clib_error_t *
778ipsec_tun_protect_cmd (vlib_main_t * vm,
779 unformat_input_t * input, vlib_cli_command_t * cmd)
780{
781 unformat_input_t _line_input, *line_input = &_line_input;
782 u32 sw_if_index, is_del, sa_in, sa_out, *sa_ins = NULL;
Neale Ranns28287212019-12-16 00:53:11 +0000783 ip_address_t peer = { };
Neale Rannsc87b66c2019-02-07 07:26:12 -0800784 vnet_main_t *vnm;
785
786 is_del = 0;
787 sw_if_index = ~0;
788 vnm = vnet_get_main ();
789
790 if (!unformat_user (input, unformat_line_input, line_input))
791 return 0;
792
793 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
794 {
795 if (unformat (line_input, "del"))
796 is_del = 1;
797 else if (unformat (line_input, "add"))
798 is_del = 0;
799 else if (unformat (line_input, "sa-in %d", &sa_in))
800 vec_add1 (sa_ins, sa_in);
801 else if (unformat (line_input, "sa-out %d", &sa_out))
802 ;
803 else if (unformat (line_input, "%U",
804 unformat_vnet_sw_interface, vnm, &sw_if_index))
805 ;
Neale Ranns28287212019-12-16 00:53:11 +0000806 else if (unformat (line_input, "%U", unformat_ip_address, &peer))
807 ;
Neale Rannsc87b66c2019-02-07 07:26:12 -0800808 else
809 return (clib_error_return (0, "unknown input '%U'",
810 format_unformat_error, line_input));
811 }
812
813 if (!is_del)
Neale Ranns28287212019-12-16 00:53:11 +0000814 ipsec_tun_protect_update (sw_if_index, &peer, sa_out, sa_ins);
Eric Kinzie609d5792020-10-13 20:02:11 -0400815 else
816 ipsec_tun_protect_del (sw_if_index, &peer);
Neale Rannsc87b66c2019-02-07 07:26:12 -0800817
818 unformat_free (line_input);
819 return NULL;
820}
821
822/**
823 * Protect tunnel with IPSEC
824 */
825/* *INDENT-OFF* */
826VLIB_CLI_COMMAND (ipsec_tun_protect_cmd_node, static) =
827{
828 .path = "ipsec tunnel protect",
829 .function = ipsec_tun_protect_cmd,
Eric Kinzie609d5792020-10-13 20:02:11 -0400830 .short_help = "ipsec tunnel protect <interface> input-sa <SA> output-sa <SA> [add|del]",
Neale Rannsc87b66c2019-02-07 07:26:12 -0800831 // this is not MP safe
832};
833/* *INDENT-ON* */
834
Neale Rannsc87b66c2019-02-07 07:26:12 -0800835
836static clib_error_t *
837ipsec_tun_protect_show (vlib_main_t * vm,
838 unformat_input_t * input, vlib_cli_command_t * cmd)
839{
840 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
841
842 return NULL;
843}
844
845/**
846 * show IPSEC tunnel protection
847 */
848/* *INDENT-OFF* */
849VLIB_CLI_COMMAND (ipsec_tun_protect_show_node, static) =
850{
851 .path = "show ipsec protect",
852 .function = ipsec_tun_protect_show,
853 .short_help = "show ipsec protect",
854};
855/* *INDENT-ON* */
856
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000857static int
Neale Ranns302b25a2020-10-19 13:23:33 +0000858ipsec_tun_protect4_hash_show_one (clib_bihash_kv_8_16_t * kv, void *arg)
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000859{
860 ipsec4_tunnel_kv_t *ikv = (ipsec4_tunnel_kv_t *) kv;
861 vlib_main_t *vm = arg;
862
863 vlib_cli_output (vm, " %U", format_ipsec4_tunnel_kv, ikv);
864
865 return (BIHASH_WALK_CONTINUE);
866}
867
868static int
Neale Ranns302b25a2020-10-19 13:23:33 +0000869ipsec_tun_protect6_hash_show_one (clib_bihash_kv_24_16_t * kv, void *arg)
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000870{
871 ipsec6_tunnel_kv_t *ikv = (ipsec6_tunnel_kv_t *) kv;
872 vlib_main_t *vm = arg;
873
874 vlib_cli_output (vm, " %U", format_ipsec6_tunnel_kv, ikv);
875
876 return (BIHASH_WALK_CONTINUE);
877}
878
Neale Ranns41afb332019-07-16 06:19:35 -0700879static clib_error_t *
880ipsec_tun_protect_hash_show (vlib_main_t * vm,
881 unformat_input_t * input,
882 vlib_cli_command_t * cmd)
883{
884 ipsec_main_t *im = &ipsec_main;
885
886 {
Neale Ranns41afb332019-07-16 06:19:35 -0700887 vlib_cli_output (vm, "IPv4:");
888
Neale Ranns302b25a2020-10-19 13:23:33 +0000889 clib_bihash_foreach_key_value_pair_8_16
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000890 (&im->tun4_protect_by_key, ipsec_tun_protect4_hash_show_one, vm);
Neale Ranns41afb332019-07-16 06:19:35 -0700891
892 vlib_cli_output (vm, "IPv6:");
893
Neale Ranns302b25a2020-10-19 13:23:33 +0000894 clib_bihash_foreach_key_value_pair_24_16
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000895 (&im->tun6_protect_by_key, ipsec_tun_protect6_hash_show_one, vm);
Neale Ranns41afb332019-07-16 06:19:35 -0700896 }
897
898 return NULL;
899}
900
901/**
902 * show IPSEC tunnel protection hash tables
903 */
904/* *INDENT-OFF* */
905VLIB_CLI_COMMAND (ipsec_tun_protect_hash_show_node, static) =
906{
907 .path = "show ipsec protect-hash",
908 .function = ipsec_tun_protect_hash_show,
909 .short_help = "show ipsec protect-hash",
910};
911/* *INDENT-ON* */
912
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913clib_error_t *
914ipsec_cli_init (vlib_main_t * vm)
915{
916 return 0;
917}
918
919VLIB_INIT_FUNCTION (ipsec_cli_init);
920
Fan Zhangf5395782020-04-29 14:00:03 +0100921static clib_error_t *
922set_async_mode_command_fn (vlib_main_t * vm, unformat_input_t * input,
923 vlib_cli_command_t * cmd)
924{
925 unformat_input_t _line_input, *line_input = &_line_input;
926 int async_enable = 0;
927
928 if (!unformat_user (input, unformat_line_input, line_input))
929 return 0;
930
931 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
932 {
933 if (unformat (line_input, "on"))
934 async_enable = 1;
935 else if (unformat (line_input, "off"))
936 async_enable = 0;
937 else
938 return (clib_error_return (0, "unknown input '%U'",
939 format_unformat_error, line_input));
940 }
941
942 vnet_crypto_request_async_mode (async_enable);
943 ipsec_set_async_mode (async_enable);
944
945 unformat_free (line_input);
946 return (NULL);
947}
948
949/* *INDENT-OFF* */
950VLIB_CLI_COMMAND (set_async_mode_command, static) = {
951 .path = "set ipsec async mode",
952 .short_help = "set ipsec async mode on|off",
953 .function = set_async_mode_command_fn,
954};
955/* *INDENT-ON* */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700956
957/*
958 * fd.io coding-style-patch-verification: ON
959 *
960 * Local Variables:
961 * eval: (c-set-style "gnu")
962 * End:
963 */