blob: c48d6855169cc9e866ea204eb764731ce16b1261 [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 Rannsf16e9a52021-02-25 19:09:24 +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;
Neale Rannsf16e9a52021-02-25 19:09:24 +0000164 else if (unformat (line_input, "async"))
165 flags |= IPSEC_SA_FLAG_IS_ASYNC;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700166 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500167 {
168 error = clib_error_return (0, "parse error: '%U'",
169 format_unformat_error, line_input);
170 goto done;
171 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700172 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700173
Benoît Gannebdd8b572020-07-28 15:56:15 +0200174 if (!(m_args & 1))
175 {
176 error = clib_error_return (0, "missing id");
177 goto done;
178 }
179
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000180 if (is_add)
Benoît Gannebdd8b572020-07-28 15:56:15 +0200181 {
182 if (!(m_args & 2))
183 {
184 error = clib_error_return (0, "missing spi");
185 goto done;
186 }
Neale Ranns9ec846c2021-02-09 14:04:02 +0000187 rv = ipsec_sa_add_and_lock (id, spi, proto, crypto_alg, &ck, integ_alg,
188 &ik, flags, clib_host_to_net_u32 (salt),
189 udp_src, udp_dst, &tun, &sai);
Benoît Gannebdd8b572020-07-28 15:56:15 +0200190 }
Neale Ranns8d7c5022019-02-06 01:41:05 -0800191 else
Benoît Gannebdd8b572020-07-28 15:56:15 +0200192 {
193 rv = ipsec_sa_unlock_id (id);
194 }
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000195
Neale Ranns8d7c5022019-02-06 01:41:05 -0800196 if (rv)
Neale Rannsf16e9a52021-02-25 19:09:24 +0000197 error = clib_error_return (0, "failed: %d", rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700198
Billy McFalla9a20e72017-02-15 11:39:12 -0500199done:
200 unformat_free (line_input);
201
202 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700203}
204
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700205/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700206VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
207 .path = "ipsec sa",
208 .short_help =
209 "ipsec sa [add|del]",
210 .function = ipsec_sa_add_del_command_fn,
211};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700212/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700213
214static clib_error_t *
215ipsec_spd_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700216 unformat_input_t * input,
217 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700218{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700219 unformat_input_t _line_input, *line_input = &_line_input;
Damjan Marion3f54b182016-08-16 11:27:02 +0200220 u32 spd_id = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700221 int is_add = ~0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500222 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700223
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700224 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700225 return 0;
226
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700227 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
228 {
229 if (unformat (line_input, "add"))
230 is_add = 1;
231 else if (unformat (line_input, "del"))
232 is_add = 0;
233 else if (unformat (line_input, "%u", &spd_id))
234 ;
235 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500236 {
237 error = clib_error_return (0, "parse error: '%U'",
238 format_unformat_error, line_input);
239 goto done;
240 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700241 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700242
Damjan Marion3f54b182016-08-16 11:27:02 +0200243 if (spd_id == ~0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500244 {
245 error = clib_error_return (0, "please specify SPD ID");
246 goto done;
247 }
Damjan Marion3f54b182016-08-16 11:27:02 +0200248
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700249 ipsec_add_del_spd (vm, spd_id, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250
Billy McFalla9a20e72017-02-15 11:39:12 -0500251done:
252 unformat_free (line_input);
253
254 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255}
256
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700257/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700258VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
259 .path = "ipsec spd",
260 .short_help =
261 "ipsec spd [add|del] <id>",
262 .function = ipsec_spd_add_del_command_fn,
263};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700264/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265
266
267static clib_error_t *
268ipsec_policy_add_del_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700269 unformat_input_t * input,
270 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700271{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700272 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700273 ipsec_policy_t p;
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800274 int rv, is_add = 0;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000275 u32 tmp, tmp2, stat_index, local_range_set, remote_range_set;
Billy McFalla9a20e72017-02-15 11:39:12 -0500276 clib_error_t *error = NULL;
Neale Ranns9f231d42019-03-19 10:06:00 +0000277 u32 is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278
Dave Barachb7b92992018-10-17 10:38:51 -0400279 clib_memset (&p, 0, sizeof (p));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700280 p.lport.stop = p.rport.stop = ~0;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000281 remote_range_set = local_range_set = is_outbound = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700282
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700283 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284 return 0;
285
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700286 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
287 {
288 if (unformat (line_input, "add"))
289 is_add = 1;
290 else if (unformat (line_input, "del"))
291 is_add = 0;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000292 else if (unformat (line_input, "ip6"))
293 p.is_ipv6 = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700294 else if (unformat (line_input, "spd %u", &p.id))
295 ;
296 else if (unformat (line_input, "inbound"))
Neale Ranns9f231d42019-03-19 10:06:00 +0000297 is_outbound = 0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700298 else if (unformat (line_input, "outbound"))
Neale Ranns9f231d42019-03-19 10:06:00 +0000299 is_outbound = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700300 else if (unformat (line_input, "priority %d", &p.priority))
301 ;
302 else if (unformat (line_input, "protocol %u", &tmp))
303 p.protocol = (u8) tmp;
304 else
305 if (unformat
306 (line_input, "action %U", unformat_ipsec_policy_action,
307 &p.policy))
308 {
309 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
Billy McFalla9a20e72017-02-15 11:39:12 -0500310 {
311 error = clib_error_return (0, "unsupported action: 'resolve'");
312 goto done;
313 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700314 }
315 else if (unformat (line_input, "sa %u", &p.sa_id))
316 ;
317 else if (unformat (line_input, "local-ip-range %U - %U",
318 unformat_ip4_address, &p.laddr.start.ip4,
319 unformat_ip4_address, &p.laddr.stop.ip4))
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000320 local_range_set = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700321 else if (unformat (line_input, "remote-ip-range %U - %U",
322 unformat_ip4_address, &p.raddr.start.ip4,
323 unformat_ip4_address, &p.raddr.stop.ip4))
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000324 remote_range_set = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700325 else if (unformat (line_input, "local-ip-range %U - %U",
326 unformat_ip6_address, &p.laddr.start.ip6,
327 unformat_ip6_address, &p.laddr.stop.ip6))
328 {
329 p.is_ipv6 = 1;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000330 local_range_set = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700331 }
332 else if (unformat (line_input, "remote-ip-range %U - %U",
333 unformat_ip6_address, &p.raddr.start.ip6,
334 unformat_ip6_address, &p.raddr.stop.ip6))
335 {
336 p.is_ipv6 = 1;
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000337 remote_range_set = 1;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700338 }
339 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
340 {
341 p.lport.start = tmp;
342 p.lport.stop = tmp2;
343 }
344 else
345 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
346 {
347 p.rport.start = tmp;
348 p.rport.stop = tmp2;
349 }
350 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500351 {
352 error = clib_error_return (0, "parse error: '%U'",
353 format_unformat_error, line_input);
354 goto done;
355 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700356 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357
Neale Rannsb1fd80f2020-05-12 13:33:56 +0000358 if (!remote_range_set)
359 {
360 if (p.is_ipv6)
361 clib_memset (&p.raddr.stop.ip6, 0xff, 16);
362 else
363 clib_memset (&p.raddr.stop.ip4, 0xff, 4);
364 }
365 if (!local_range_set)
366 {
367 if (p.is_ipv6)
368 clib_memset (&p.laddr.stop.ip6, 0xff, 16);
369 else
370 clib_memset (&p.laddr.stop.ip4, 0xff, 4);
371 }
372
Neale Ranns9f231d42019-03-19 10:06:00 +0000373 rv = ipsec_policy_mk_type (is_outbound, p.is_ipv6, p.policy, &p.type);
374
375 if (rv)
376 {
377 error = clib_error_return (0, "unsupported policy type for:",
378 " outboud:%s %s action:%U",
379 (is_outbound ? "yes" : "no"),
380 (p.is_ipv6 ? "IPv4" : "IPv6"),
381 format_ipsec_policy_action, p.policy);
382 goto done;
383 }
384
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800385 rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index);
386
387 if (!rv)
388 vlib_cli_output (vm, "policy-index:%d", stat_index);
389 else
390 vlib_cli_output (vm, "error:%d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500391
392done:
393 unformat_free (line_input);
394
395 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700396}
397
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700398/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700399VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
400 .path = "ipsec policy",
401 .short_help =
402 "ipsec policy [add|del] spd <id> priority <n> ",
403 .function = ipsec_policy_add_del_command_fn,
404};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700405/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700406
Neale Rannsb294f102019-04-03 13:17:50 +0000407static void
Neale Ranns670027a2019-08-27 12:47:17 +0000408ipsec_sa_show_all (vlib_main_t * vm, ipsec_main_t * im, u8 detail)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700409{
Neale Rannsb294f102019-04-03 13:17:50 +0000410 u32 sai;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700411
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700412 /* *INDENT-OFF* */
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000413 pool_foreach_index (sai, ipsec_sa_pool)
414 {
415 vlib_cli_output (vm, "%U", format_ipsec_sa, sai,
416 (detail ? IPSEC_FORMAT_DETAIL : IPSEC_FORMAT_BRIEF));
417 }
Neale Rannsb294f102019-04-03 13:17:50 +0000418 /* *INDENT-ON* */
419}
420
421static void
422ipsec_spd_show_all (vlib_main_t * vm, ipsec_main_t * im)
423{
424 u32 spdi;
425
426 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100427 pool_foreach_index (spdi, im->spds) {
Neale Rannsb294f102019-04-03 13:17:50 +0000428 vlib_cli_output(vm, "%U", format_ipsec_spd, spdi);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100429 }
Govindarajan Mohandoss6d7dfcb2021-03-19 19:20:49 +0000430
431 if (im->flow_cache_flag)
432 {
433 vlib_cli_output (vm, "%U", format_ipsec_spd_flow_cache);
434 }
Neale Rannsb294f102019-04-03 13:17:50 +0000435 /* *INDENT-ON* */
436}
437
438static void
439ipsec_spd_bindings_show_all (vlib_main_t * vm, ipsec_main_t * im)
440{
441 u32 spd_id, sw_if_index;
Neale Rannsd83c4a82019-06-14 06:48:27 -0700442 ipsec_spd_t *spd;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700443
Neale Ranns311124e2019-01-24 04:52:25 -0800444 vlib_cli_output (vm, "SPD Bindings:");
Neale Ranns8d7c5022019-02-06 01:41:05 -0800445
Neale Rannsb294f102019-04-03 13:17:50 +0000446 /* *INDENT-OFF* */
Neale Ranns311124e2019-01-24 04:52:25 -0800447 hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({
Neale Rannsd83c4a82019-06-14 06:48:27 -0700448 spd = pool_elt_at_index (im->spds, spd_id);
449 vlib_cli_output (vm, " %d -> %U", spd->id,
Neale Ranns8d7c5022019-02-06 01:41:05 -0800450 format_vnet_sw_if_index_name, im->vnet_main,
451 sw_if_index);
Neale Ranns311124e2019-01-24 04:52:25 -0800452 }));
453 /* *INDENT-ON* */
Neale Rannsb294f102019-04-03 13:17:50 +0000454}
Neale Ranns311124e2019-01-24 04:52:25 -0800455
Neale Ranns12989b52019-09-26 16:20:19 +0000456static walk_rc_t
457ipsec_tun_protect_show_one (index_t itpi, void *ctx)
Neale Rannsb294f102019-04-03 13:17:50 +0000458{
Neale Ranns28287212019-12-16 00:53:11 +0000459 vlib_cli_output (ctx, "%U", format_ipsec_tun_protect_index, itpi);
Neale Rannsb294f102019-04-03 13:17:50 +0000460
Neale Ranns12989b52019-09-26 16:20:19 +0000461 return (WALK_CONTINUE);
462}
463
464static void
465ipsec_tunnel_show_all (vlib_main_t * vm)
466{
467 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
Neale Rannsb294f102019-04-03 13:17:50 +0000468}
469
470static clib_error_t *
471show_ipsec_command_fn (vlib_main_t * vm,
472 unformat_input_t * input, vlib_cli_command_t * cmd)
473{
474 ipsec_main_t *im = &ipsec_main;
475
Neale Ranns670027a2019-08-27 12:47:17 +0000476 ipsec_sa_show_all (vm, im, 0);
Neale Rannsb294f102019-04-03 13:17:50 +0000477 ipsec_spd_show_all (vm, im);
478 ipsec_spd_bindings_show_all (vm, im);
Neale Ranns12989b52019-09-26 16:20:19 +0000479 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
Neale Rannsb294f102019-04-03 13:17:50 +0000480
Fan Zhangf5395782020-04-29 14:00:03 +0100481 vlib_cli_output (vm, "IPSec async mode: %s",
482 (im->async_mode ? "on" : "off"));
483
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484 return 0;
485}
486
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700487/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700488VLIB_CLI_COMMAND (show_ipsec_command, static) = {
Neale Rannsb294f102019-04-03 13:17:50 +0000489 .path = "show ipsec all",
490 .short_help = "show ipsec all",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700491 .function = show_ipsec_command_fn,
492};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700493/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700494
495static clib_error_t *
Neale Rannsb294f102019-04-03 13:17:50 +0000496show_ipsec_sa_command_fn (vlib_main_t * vm,
497 unformat_input_t * input, vlib_cli_command_t * cmd)
498{
499 ipsec_main_t *im = &ipsec_main;
500 u32 sai = ~0;
Neale Ranns670027a2019-08-27 12:47:17 +0000501 u8 detail = 0;
Neale Rannsb294f102019-04-03 13:17:50 +0000502
503 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
504 {
505 if (unformat (input, "%u", &sai))
506 ;
Neale Ranns670027a2019-08-27 12:47:17 +0000507 if (unformat (input, "detail"))
508 detail = 1;
Neale Rannsb294f102019-04-03 13:17:50 +0000509 else
510 break;
511 }
512
513 if (~0 == sai)
Neale Ranns670027a2019-08-27 12:47:17 +0000514 ipsec_sa_show_all (vm, im, detail);
Neale Rannsb294f102019-04-03 13:17:50 +0000515 else
Christian E. Hopps01d61e72019-09-27 14:43:22 -0400516 vlib_cli_output (vm, "%U", format_ipsec_sa, sai,
517 IPSEC_FORMAT_DETAIL | IPSEC_FORMAT_INSECURE);
Neale Rannsb294f102019-04-03 13:17:50 +0000518
519 return 0;
520}
521
Neale Rannsc87b66c2019-02-07 07:26:12 -0800522static clib_error_t *
523clear_ipsec_sa_command_fn (vlib_main_t * vm,
524 unformat_input_t * input, vlib_cli_command_t * cmd)
525{
Neale Rannsc87b66c2019-02-07 07:26:12 -0800526 u32 sai = ~0;
527
528 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
529 {
530 if (unformat (input, "%u", &sai))
531 ;
532 else
533 break;
534 }
535
536 if (~0 == sai)
537 {
538 /* *INDENT-OFF* */
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000539 pool_foreach_index (sai, ipsec_sa_pool)
540 {
541 ipsec_sa_clear (sai);
542 }
Neale Rannsc87b66c2019-02-07 07:26:12 -0800543 /* *INDENT-ON* */
544 }
545 else
546 {
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000547 if (pool_is_free_index (ipsec_sa_pool, sai))
Neale Rannsc87b66c2019-02-07 07:26:12 -0800548 return clib_error_return (0, "unknown SA index: %d", sai);
549 else
550 ipsec_sa_clear (sai);
551 }
552
553 return 0;
554}
555
Neale Rannsb294f102019-04-03 13:17:50 +0000556/* *INDENT-OFF* */
557VLIB_CLI_COMMAND (show_ipsec_sa_command, static) = {
558 .path = "show ipsec sa",
559 .short_help = "show ipsec sa [index]",
560 .function = show_ipsec_sa_command_fn,
561};
Neale Rannsc87b66c2019-02-07 07:26:12 -0800562
563VLIB_CLI_COMMAND (clear_ipsec_sa_command, static) = {
564 .path = "clear ipsec sa",
565 .short_help = "clear ipsec sa [index]",
566 .function = clear_ipsec_sa_command_fn,
567};
Neale Rannsb294f102019-04-03 13:17:50 +0000568/* *INDENT-ON* */
569
570static clib_error_t *
571show_ipsec_spd_command_fn (vlib_main_t * vm,
572 unformat_input_t * input, vlib_cli_command_t * cmd)
573{
574 ipsec_main_t *im = &ipsec_main;
575 u8 show_bindings = 0;
576 u32 spdi = ~0;
577
578 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
579 {
580 if (unformat (input, "%u", &spdi))
581 ;
582 else if (unformat (input, "bindings"))
583 show_bindings = 1;
584 else
585 break;
586 }
587
588 if (show_bindings)
589 ipsec_spd_bindings_show_all (vm, im);
590 else if (~0 != spdi)
591 vlib_cli_output (vm, "%U", format_ipsec_spd, spdi);
592 else
593 ipsec_spd_show_all (vm, im);
594
595 return 0;
596}
597
598/* *INDENT-OFF* */
599VLIB_CLI_COMMAND (show_ipsec_spd_command, static) = {
600 .path = "show ipsec spd",
601 .short_help = "show ipsec spd [index]",
602 .function = show_ipsec_spd_command_fn,
603};
604/* *INDENT-ON* */
605
606static clib_error_t *
607show_ipsec_tunnel_command_fn (vlib_main_t * vm,
608 unformat_input_t * input,
609 vlib_cli_command_t * cmd)
610{
Neale Ranns12989b52019-09-26 16:20:19 +0000611 ipsec_tunnel_show_all (vm);
Neale Rannsb294f102019-04-03 13:17:50 +0000612
613 return 0;
614}
615
616/* *INDENT-OFF* */
617VLIB_CLI_COMMAND (show_ipsec_tunnel_command, static) = {
618 .path = "show ipsec tunnel",
Neale Ranns12989b52019-09-26 16:20:19 +0000619 .short_help = "show ipsec tunnel",
Neale Rannsb294f102019-04-03 13:17:50 +0000620 .function = show_ipsec_tunnel_command_fn,
621};
622/* *INDENT-ON* */
623
624static clib_error_t *
Klement Sekerab4d30532018-11-08 13:00:02 +0100625ipsec_show_backends_command_fn (vlib_main_t * vm,
626 unformat_input_t * input,
627 vlib_cli_command_t * cmd)
628{
629 ipsec_main_t *im = &ipsec_main;
630 u32 verbose = 0;
631
632 (void) unformat (input, "verbose %u", &verbose);
633
634 vlib_cli_output (vm, "IPsec AH backends available:");
635 u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
636 ipsec_ah_backend_t *ab;
637 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100638 pool_foreach (ab, im->ah_backends) {
Klement Sekerab4d30532018-11-08 13:00:02 +0100639 s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
640 ab - im->ah_backends == im->ah_current_backend ? "yes" : "no");
641 if (verbose) {
642 vlib_node_t *n;
643 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
644 s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
645 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
646 s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
647 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
648 s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
649 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
650 s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
651 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100652 }
Klement Sekerab4d30532018-11-08 13:00:02 +0100653 /* *INDENT-ON* */
654 vlib_cli_output (vm, "%v", s);
Damjan Marion8bea5892022-04-04 22:40:45 +0200655 vec_set_len (s, 0);
Klement Sekerab4d30532018-11-08 13:00:02 +0100656 vlib_cli_output (vm, "IPsec ESP backends available:");
657 s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
658 ipsec_esp_backend_t *eb;
659 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100660 pool_foreach (eb, im->esp_backends) {
Klement Sekerab4d30532018-11-08 13:00:02 +0100661 s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
662 eb - im->esp_backends == im->esp_current_backend ? "yes"
663 : "no");
664 if (verbose) {
665 vlib_node_t *n;
666 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
667 s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
668 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
669 s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
670 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
671 s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
672 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
673 s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
674 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100675 }
Klement Sekerab4d30532018-11-08 13:00:02 +0100676 /* *INDENT-ON* */
677 vlib_cli_output (vm, "%v", s);
678
679 vec_free (s);
680 return 0;
681}
682
683/* *INDENT-OFF* */
684VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = {
685 .path = "show ipsec backends",
686 .short_help = "show ipsec backends",
687 .function = ipsec_show_backends_command_fn,
688};
689/* *INDENT-ON* */
690
691static clib_error_t *
692ipsec_select_backend_command_fn (vlib_main_t * vm,
693 unformat_input_t * input,
694 vlib_cli_command_t * cmd)
695{
Klement Sekerab4d30532018-11-08 13:00:02 +0100696 unformat_input_t _line_input, *line_input = &_line_input;
Neale Rannse8915fc2019-04-23 20:57:55 -0400697 ipsec_main_t *im = &ipsec_main;
698 clib_error_t *error;
699 u32 backend_index;
700
701 error = ipsec_rsc_in_use (im);
702
703 if (error)
704 return error;
705
Klement Sekerab4d30532018-11-08 13:00:02 +0100706 /* Get a line of input. */
707 if (!unformat_user (input, unformat_line_input, line_input))
708 return 0;
709
710 if (unformat (line_input, "ah"))
711 {
712 if (unformat (line_input, "%u", &backend_index))
713 {
714 if (ipsec_select_ah_backend (im, backend_index) < 0)
715 {
716 return clib_error_return (0, "Invalid AH backend index `%u'",
717 backend_index);
718 }
719 }
720 else
721 {
722 return clib_error_return (0, "Invalid backend index `%U'",
723 format_unformat_error, line_input);
724 }
725 }
726 else if (unformat (line_input, "esp"))
727 {
728 if (unformat (line_input, "%u", &backend_index))
729 {
730 if (ipsec_select_esp_backend (im, backend_index) < 0)
731 {
732 return clib_error_return (0, "Invalid ESP backend index `%u'",
733 backend_index);
734 }
735 }
736 else
737 {
738 return clib_error_return (0, "Invalid backend index `%U'",
739 format_unformat_error, line_input);
740 }
741 }
742 else
743 {
744 return clib_error_return (0, "Unknown input `%U'",
745 format_unformat_error, line_input);
746 }
747
748 return 0;
749}
750
751/* *INDENT-OFF* */
752VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = {
753 .path = "ipsec select backend",
754 .short_help = "ipsec select backend <ah|esp> <backend index>",
755 .function = ipsec_select_backend_command_fn,
756};
757
758/* *INDENT-ON* */
759
760static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700761clear_ipsec_counters_command_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700762 unformat_input_t * input,
763 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700764{
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800765 vlib_clear_combined_counters (&ipsec_spd_policy_counters);
Neale Rannseba31ec2019-02-17 18:04:27 +0000766 vlib_clear_combined_counters (&ipsec_sa_counters);
Neale Rannse11203e2021-09-21 12:34:19 +0000767 vlib_clear_simple_counters (&ipsec_sa_lost_counters);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700768
Neale Rannsa09c1ff2019-02-04 01:10:30 -0800769 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700770}
771
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700772/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700773VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
774 .path = "clear ipsec counters",
775 .short_help = "clear ipsec counters",
776 .function = clear_ipsec_counters_command_fn,
777};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700778/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700779
Neale Rannsc87b66c2019-02-07 07:26:12 -0800780static clib_error_t *
781ipsec_tun_protect_cmd (vlib_main_t * vm,
782 unformat_input_t * input, vlib_cli_command_t * cmd)
783{
784 unformat_input_t _line_input, *line_input = &_line_input;
785 u32 sw_if_index, is_del, sa_in, sa_out, *sa_ins = NULL;
Neale Ranns28287212019-12-16 00:53:11 +0000786 ip_address_t peer = { };
Neale Rannsc87b66c2019-02-07 07:26:12 -0800787 vnet_main_t *vnm;
788
789 is_del = 0;
790 sw_if_index = ~0;
791 vnm = vnet_get_main ();
792
793 if (!unformat_user (input, unformat_line_input, line_input))
794 return 0;
795
796 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
797 {
798 if (unformat (line_input, "del"))
799 is_del = 1;
800 else if (unformat (line_input, "add"))
801 is_del = 0;
802 else if (unformat (line_input, "sa-in %d", &sa_in))
803 vec_add1 (sa_ins, sa_in);
804 else if (unformat (line_input, "sa-out %d", &sa_out))
805 ;
806 else if (unformat (line_input, "%U",
807 unformat_vnet_sw_interface, vnm, &sw_if_index))
808 ;
Neale Ranns28287212019-12-16 00:53:11 +0000809 else if (unformat (line_input, "%U", unformat_ip_address, &peer))
810 ;
Neale Rannsc87b66c2019-02-07 07:26:12 -0800811 else
812 return (clib_error_return (0, "unknown input '%U'",
813 format_unformat_error, line_input));
814 }
815
816 if (!is_del)
Neale Ranns28287212019-12-16 00:53:11 +0000817 ipsec_tun_protect_update (sw_if_index, &peer, sa_out, sa_ins);
Eric Kinzie609d5792020-10-13 20:02:11 -0400818 else
819 ipsec_tun_protect_del (sw_if_index, &peer);
Neale Rannsc87b66c2019-02-07 07:26:12 -0800820
821 unformat_free (line_input);
822 return NULL;
823}
824
825/**
826 * Protect tunnel with IPSEC
827 */
828/* *INDENT-OFF* */
829VLIB_CLI_COMMAND (ipsec_tun_protect_cmd_node, static) =
830{
831 .path = "ipsec tunnel protect",
832 .function = ipsec_tun_protect_cmd,
Eric Kinzie609d5792020-10-13 20:02:11 -0400833 .short_help = "ipsec tunnel protect <interface> input-sa <SA> output-sa <SA> [add|del]",
Neale Rannsc87b66c2019-02-07 07:26:12 -0800834 // this is not MP safe
835};
836/* *INDENT-ON* */
837
Neale Rannsc87b66c2019-02-07 07:26:12 -0800838
839static clib_error_t *
840ipsec_tun_protect_show (vlib_main_t * vm,
841 unformat_input_t * input, vlib_cli_command_t * cmd)
842{
843 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
844
845 return NULL;
846}
847
848/**
849 * show IPSEC tunnel protection
850 */
851/* *INDENT-OFF* */
852VLIB_CLI_COMMAND (ipsec_tun_protect_show_node, static) =
853{
854 .path = "show ipsec protect",
855 .function = ipsec_tun_protect_show,
856 .short_help = "show ipsec protect",
857};
858/* *INDENT-ON* */
859
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000860static int
Neale Ranns302b25a2020-10-19 13:23:33 +0000861ipsec_tun_protect4_hash_show_one (clib_bihash_kv_8_16_t * kv, void *arg)
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000862{
863 ipsec4_tunnel_kv_t *ikv = (ipsec4_tunnel_kv_t *) kv;
864 vlib_main_t *vm = arg;
865
866 vlib_cli_output (vm, " %U", format_ipsec4_tunnel_kv, ikv);
867
868 return (BIHASH_WALK_CONTINUE);
869}
870
871static int
Neale Ranns302b25a2020-10-19 13:23:33 +0000872ipsec_tun_protect6_hash_show_one (clib_bihash_kv_24_16_t * kv, void *arg)
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000873{
874 ipsec6_tunnel_kv_t *ikv = (ipsec6_tunnel_kv_t *) kv;
875 vlib_main_t *vm = arg;
876
877 vlib_cli_output (vm, " %U", format_ipsec6_tunnel_kv, ikv);
878
879 return (BIHASH_WALK_CONTINUE);
880}
881
Neale Ranns41afb332019-07-16 06:19:35 -0700882static clib_error_t *
883ipsec_tun_protect_hash_show (vlib_main_t * vm,
884 unformat_input_t * input,
885 vlib_cli_command_t * cmd)
886{
887 ipsec_main_t *im = &ipsec_main;
888
889 {
Neale Ranns41afb332019-07-16 06:19:35 -0700890 vlib_cli_output (vm, "IPv4:");
891
Neale Ranns302b25a2020-10-19 13:23:33 +0000892 clib_bihash_foreach_key_value_pair_8_16
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000893 (&im->tun4_protect_by_key, ipsec_tun_protect4_hash_show_one, vm);
Neale Ranns41afb332019-07-16 06:19:35 -0700894
895 vlib_cli_output (vm, "IPv6:");
896
Neale Ranns302b25a2020-10-19 13:23:33 +0000897 clib_bihash_foreach_key_value_pair_24_16
Neale Ranns7b4e52f2020-05-24 16:17:50 +0000898 (&im->tun6_protect_by_key, ipsec_tun_protect6_hash_show_one, vm);
Neale Ranns41afb332019-07-16 06:19:35 -0700899 }
900
901 return NULL;
902}
903
904/**
905 * show IPSEC tunnel protection hash tables
906 */
907/* *INDENT-OFF* */
908VLIB_CLI_COMMAND (ipsec_tun_protect_hash_show_node, static) =
909{
910 .path = "show ipsec protect-hash",
911 .function = ipsec_tun_protect_hash_show,
912 .short_help = "show ipsec protect-hash",
913};
914/* *INDENT-ON* */
915
Ed Warnickecb9cada2015-12-08 15:45:58 -0700916clib_error_t *
917ipsec_cli_init (vlib_main_t * vm)
918{
919 return 0;
920}
921
922VLIB_INIT_FUNCTION (ipsec_cli_init);
923
Fan Zhangf5395782020-04-29 14:00:03 +0100924static clib_error_t *
925set_async_mode_command_fn (vlib_main_t * vm, unformat_input_t * input,
926 vlib_cli_command_t * cmd)
927{
928 unformat_input_t _line_input, *line_input = &_line_input;
929 int async_enable = 0;
930
931 if (!unformat_user (input, unformat_line_input, line_input))
932 return 0;
933
934 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
935 {
936 if (unformat (line_input, "on"))
937 async_enable = 1;
938 else if (unformat (line_input, "off"))
939 async_enable = 0;
940 else
941 return (clib_error_return (0, "unknown input '%U'",
942 format_unformat_error, line_input));
943 }
944
Fan Zhangf5395782020-04-29 14:00:03 +0100945 ipsec_set_async_mode (async_enable);
946
947 unformat_free (line_input);
948 return (NULL);
949}
950
951/* *INDENT-OFF* */
952VLIB_CLI_COMMAND (set_async_mode_command, static) = {
953 .path = "set ipsec async mode",
954 .short_help = "set ipsec async mode on|off",
955 .function = set_async_mode_command_fn,
956};
957/* *INDENT-ON* */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700958
959/*
960 * fd.io coding-style-patch-verification: ON
961 *
962 * Local Variables:
963 * eval: (c-set-style "gnu")
964 * End:
965 */