2 * decap.c : IPSec tunnel support
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/vnet.h>
19 #include <vnet/api_errno.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/interface.h>
22 #include <vnet/fib/fib.h>
23 #include <vnet/ipip/ipip.h>
25 #include <vnet/ipsec/ipsec.h>
26 #include <vnet/ipsec/ipsec_tun.h>
29 set_interface_spd_command_fn (vlib_main_t * vm,
30 unformat_input_t * input,
31 vlib_cli_command_t * cmd)
33 unformat_input_t _line_input, *line_input = &_line_input;
34 ipsec_main_t *im = &ipsec_main;
35 u32 sw_if_index = (u32) ~ 0;
38 clib_error_t *error = NULL;
41 if (!unformat_user (input, unformat_line_input, line_input))
45 (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main,
46 &sw_if_index, &spd_id))
48 else if (unformat (line_input, "del"))
52 error = clib_error_return (0, "parse error: '%U'",
53 format_unformat_error, line_input);
57 err = ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add);
60 case VNET_API_ERROR_SYSCALL_ERROR_1:
61 error = clib_error_return (0, "no such spd-id");
63 case VNET_API_ERROR_SYSCALL_ERROR_2:
64 error = clib_error_return (0, "spd already assigned");
69 unformat_free (line_input);
75 VLIB_CLI_COMMAND (set_interface_spd_command, static) = {
76 .path = "set interface ipsec spd",
78 "set interface ipsec spd <int> <id>",
79 .function = set_interface_spd_command_fn,
84 ipsec_sa_add_del_command_fn (vlib_main_t * vm,
85 unformat_input_t * input,
86 vlib_cli_command_t * cmd)
88 unformat_input_t _line_input, *line_input = &_line_input;
89 ipsec_crypto_alg_t crypto_alg;
90 ipsec_integ_alg_t integ_alg;
91 u32 anti_replay_window_size;
92 ipsec_protocol_t proto;
93 ipsec_sa_flags_t flags;
95 ipsec_key_t ck = { 0 };
96 ipsec_key_t ik = { 0 };
97 u32 id, spi, salt, sai;
107 flags = IPSEC_SA_FLAG_NONE;
108 proto = IPSEC_PROTOCOL_ESP;
109 anti_replay_window_size = 0;
110 integ_alg = IPSEC_INTEG_ALG_NONE;
111 crypto_alg = IPSEC_CRYPTO_ALG_NONE;
112 udp_src = udp_dst = IPSEC_UDP_PORT_NONE;
114 if (!unformat_user (input, unformat_line_input, line_input))
117 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
119 if (unformat (line_input, "add %u", &id))
124 else if (unformat (line_input, "del %u", &id))
129 else if (unformat (line_input, "spi %u", &spi))
131 else if (unformat (line_input, "salt 0x%x", &salt))
133 else if (unformat (line_input, "esp"))
134 proto = IPSEC_PROTOCOL_ESP;
135 else if (unformat (line_input, "ah"))
136 proto = IPSEC_PROTOCOL_AH;
137 else if (unformat (line_input, "crypto-key %U",
138 unformat_ipsec_key, &ck))
140 else if (unformat (line_input, "crypto-alg %U",
141 unformat_ipsec_crypto_alg, &crypto_alg))
143 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
145 else if (unformat (line_input, "integ-alg %U",
146 unformat_ipsec_integ_alg, &integ_alg))
148 else if (unformat (line_input, "%U", unformat_tunnel, &tun))
150 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
151 if (AF_IP6 == tunnel_get_af (&tun))
152 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
154 else if (unformat (line_input, "udp-src-port %d", &i))
156 else if (unformat (line_input, "udp-dst-port %d", &i))
158 else if (unformat (line_input, "anti-replay-size %d",
159 &anti_replay_window_size))
160 flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
161 else if (unformat (line_input, "inbound"))
162 flags |= IPSEC_SA_FLAG_IS_INBOUND;
163 else if (unformat (line_input, "use-anti-replay"))
164 flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
165 else if (unformat (line_input, "use-esn"))
166 flags |= IPSEC_SA_FLAG_USE_ESN;
167 else if (unformat (line_input, "udp-encap"))
168 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
169 else if (unformat (line_input, "async"))
170 flags |= IPSEC_SA_FLAG_IS_ASYNC;
173 error = clib_error_return (0, "parse error: '%U'",
174 format_unformat_error, line_input);
181 error = clib_error_return (0, "missing id");
189 error = clib_error_return (0, "missing spi");
193 ipsec_sa_add_and_lock (id, spi, proto, crypto_alg, &ck, integ_alg, &ik,
194 flags, clib_host_to_net_u32 (salt), udp_src,
195 udp_dst, anti_replay_window_size, &tun, &sai);
199 rv = ipsec_sa_unlock_id (id);
203 error = clib_error_return (0, "failed: %d", rv);
206 unformat_free (line_input);
212 VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
215 "ipsec sa [add|del]",
216 .function = ipsec_sa_add_del_command_fn,
220 static clib_error_t *
221 ipsec_sa_bind_cli (vlib_main_t *vm, unformat_input_t *input,
222 vlib_cli_command_t *cmd)
224 unformat_input_t _line_input, *line_input = &_line_input;
229 clib_error_t *error = NULL;
231 if (!unformat_user (input, unformat_line_input, line_input))
234 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
236 if (unformat (line_input, "unbind"))
238 else if (id == ~0 && unformat (line_input, "%u", &id))
240 else if (unformat (line_input, "%u", &worker))
244 error = clib_error_return (0, "parse error: '%U'",
245 format_unformat_error, line_input);
252 error = clib_error_return (0, "please specify SA ID");
256 if (bind && ~0 == worker)
258 error = clib_error_return (0, "please specify worker to bind to");
262 rv = ipsec_sa_bind (id, worker, bind);
265 case VNET_API_ERROR_INVALID_VALUE:
266 error = clib_error_return (0, "please specify a valid SA ID");
268 case VNET_API_ERROR_INVALID_WORKER:
269 error = clib_error_return (0, "please specify a valid worker index");
274 unformat_free (line_input);
279 VLIB_CLI_COMMAND (ipsec_sa_bind_cmd, static) = {
280 .path = "ipsec sa bind",
281 .short_help = "ipsec sa [unbind] <sa-id> <worker>",
282 .function = ipsec_sa_bind_cli,
285 static clib_error_t *
286 ipsec_spd_add_del_command_fn (vlib_main_t * vm,
287 unformat_input_t * input,
288 vlib_cli_command_t * cmd)
290 unformat_input_t _line_input, *line_input = &_line_input;
293 clib_error_t *error = NULL;
295 if (!unformat_user (input, unformat_line_input, line_input))
298 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
300 if (unformat (line_input, "add"))
302 else if (unformat (line_input, "del"))
304 else if (unformat (line_input, "%u", &spd_id))
308 error = clib_error_return (0, "parse error: '%U'",
309 format_unformat_error, line_input);
316 error = clib_error_return (0, "please specify SPD ID");
320 ipsec_add_del_spd (vm, spd_id, is_add);
323 unformat_free (line_input);
329 VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
332 "ipsec spd [add|del] <id>",
333 .function = ipsec_spd_add_del_command_fn,
338 static clib_error_t *
339 ipsec_policy_add_del_command_fn (vlib_main_t * vm,
340 unformat_input_t * input,
341 vlib_cli_command_t * cmd)
343 unformat_input_t _line_input, *line_input = &_line_input;
346 u32 tmp, tmp2, stat_index, local_range_set, remote_range_set;
347 clib_error_t *error = NULL;
350 clib_memset (&p, 0, sizeof (p));
351 p.lport.stop = p.rport.stop = ~0;
352 remote_range_set = local_range_set = is_outbound = 0;
353 p.protocol = IPSEC_POLICY_PROTOCOL_ANY;
355 if (!unformat_user (input, unformat_line_input, line_input))
358 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
360 if (unformat (line_input, "add"))
362 else if (unformat (line_input, "del"))
364 else if (unformat (line_input, "ip6"))
366 else if (unformat (line_input, "spd %u", &p.id))
368 else if (unformat (line_input, "inbound"))
370 else if (unformat (line_input, "outbound"))
372 else if (unformat (line_input, "priority %d", &p.priority))
374 else if (unformat (line_input, "protocol %u", &tmp))
375 p.protocol = (u8) tmp;
378 (line_input, "action %U", unformat_ipsec_policy_action,
381 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
383 error = clib_error_return (0, "unsupported action: 'resolve'");
387 else if (unformat (line_input, "sa %u", &p.sa_id))
389 else if (unformat (line_input, "local-ip-range %U - %U",
390 unformat_ip4_address, &p.laddr.start.ip4,
391 unformat_ip4_address, &p.laddr.stop.ip4))
393 else if (unformat (line_input, "remote-ip-range %U - %U",
394 unformat_ip4_address, &p.raddr.start.ip4,
395 unformat_ip4_address, &p.raddr.stop.ip4))
396 remote_range_set = 1;
397 else if (unformat (line_input, "local-ip-range %U - %U",
398 unformat_ip6_address, &p.laddr.start.ip6,
399 unformat_ip6_address, &p.laddr.stop.ip6))
404 else if (unformat (line_input, "remote-ip-range %U - %U",
405 unformat_ip6_address, &p.raddr.start.ip6,
406 unformat_ip6_address, &p.raddr.stop.ip6))
409 remote_range_set = 1;
411 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
417 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
424 error = clib_error_return (0, "parse error: '%U'",
425 format_unformat_error, line_input);
430 if (!remote_range_set)
433 clib_memset (&p.raddr.stop.ip6, 0xff, 16);
435 clib_memset (&p.raddr.stop.ip4, 0xff, 4);
437 if (!local_range_set)
440 clib_memset (&p.laddr.stop.ip6, 0xff, 16);
442 clib_memset (&p.laddr.stop.ip4, 0xff, 4);
445 rv = ipsec_policy_mk_type (is_outbound, p.is_ipv6, p.policy, &p.type);
449 error = clib_error_return (0, "unsupported policy type for:",
450 " outboud:%s %s action:%U",
451 (is_outbound ? "yes" : "no"),
452 (p.is_ipv6 ? "IPv4" : "IPv6"),
453 format_ipsec_policy_action, p.policy);
457 rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index);
460 vlib_cli_output (vm, "policy-index:%d", stat_index);
462 vlib_cli_output (vm, "error:%d", rv);
465 unformat_free (line_input);
471 VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
472 .path = "ipsec policy",
474 "ipsec policy [add|del] spd <id> priority <n> ",
475 .function = ipsec_policy_add_del_command_fn,
480 ipsec_sa_show_all (vlib_main_t * vm, ipsec_main_t * im, u8 detail)
485 pool_foreach_index (sai, ipsec_sa_pool)
487 vlib_cli_output (vm, "%U", format_ipsec_sa, sai,
488 (detail ? IPSEC_FORMAT_DETAIL : IPSEC_FORMAT_BRIEF));
494 ipsec_spd_show_all (vlib_main_t * vm, ipsec_main_t * im)
499 pool_foreach_index (spdi, im->spds) {
500 vlib_cli_output(vm, "%U", format_ipsec_spd, spdi);
503 if (im->output_flow_cache_flag)
505 vlib_cli_output (vm, "%U", format_ipsec_out_spd_flow_cache);
507 if (im->input_flow_cache_flag)
509 vlib_cli_output (vm, "%U", format_ipsec_in_spd_flow_cache);
515 ipsec_spd_bindings_show_all (vlib_main_t * vm, ipsec_main_t * im)
517 u32 spd_id, sw_if_index;
520 vlib_cli_output (vm, "SPD Bindings:");
523 hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({
524 spd = pool_elt_at_index (im->spds, spd_id);
525 vlib_cli_output (vm, " %d -> %U", spd->id,
526 format_vnet_sw_if_index_name, im->vnet_main,
533 ipsec_tun_protect_show_one (index_t itpi, void *ctx)
535 vlib_cli_output (ctx, "%U", format_ipsec_tun_protect_index, itpi);
537 return (WALK_CONTINUE);
541 ipsec_tunnel_show_all (vlib_main_t * vm)
543 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
546 static clib_error_t *
547 show_ipsec_command_fn (vlib_main_t * vm,
548 unformat_input_t * input, vlib_cli_command_t * cmd)
550 ipsec_main_t *im = &ipsec_main;
552 ipsec_sa_show_all (vm, im, 0);
553 ipsec_spd_show_all (vm, im);
554 ipsec_spd_bindings_show_all (vm, im);
555 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
557 vlib_cli_output (vm, "IPSec async mode: %s",
558 (im->async_mode ? "on" : "off"));
564 VLIB_CLI_COMMAND (show_ipsec_command, static) = {
565 .path = "show ipsec all",
566 .short_help = "show ipsec all",
567 .function = show_ipsec_command_fn,
571 static clib_error_t *
572 show_ipsec_sa_command_fn (vlib_main_t * vm,
573 unformat_input_t * input, vlib_cli_command_t * cmd)
575 ipsec_main_t *im = &ipsec_main;
579 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
581 if (unformat (input, "%u", &sai))
583 if (unformat (input, "detail"))
590 ipsec_sa_show_all (vm, im, detail);
592 vlib_cli_output (vm, "%U", format_ipsec_sa, sai,
593 IPSEC_FORMAT_DETAIL | IPSEC_FORMAT_INSECURE);
598 static clib_error_t *
599 clear_ipsec_sa_command_fn (vlib_main_t * vm,
600 unformat_input_t * input, vlib_cli_command_t * cmd)
604 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
606 if (unformat (input, "%u", &sai))
615 pool_foreach_index (sai, ipsec_sa_pool)
617 ipsec_sa_clear (sai);
623 if (pool_is_free_index (ipsec_sa_pool, sai))
624 return clib_error_return (0, "unknown SA index: %d", sai);
626 ipsec_sa_clear (sai);
633 VLIB_CLI_COMMAND (show_ipsec_sa_command, static) = {
634 .path = "show ipsec sa",
635 .short_help = "show ipsec sa [index]",
636 .function = show_ipsec_sa_command_fn,
639 VLIB_CLI_COMMAND (clear_ipsec_sa_command, static) = {
640 .path = "clear ipsec sa",
641 .short_help = "clear ipsec sa [index]",
642 .function = clear_ipsec_sa_command_fn,
646 static clib_error_t *
647 show_ipsec_spd_command_fn (vlib_main_t * vm,
648 unformat_input_t * input, vlib_cli_command_t * cmd)
650 ipsec_main_t *im = &ipsec_main;
651 u8 show_bindings = 0;
654 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
656 if (unformat (input, "%u", &spdi))
658 else if (unformat (input, "bindings"))
665 ipsec_spd_bindings_show_all (vm, im);
667 vlib_cli_output (vm, "%U", format_ipsec_spd, spdi);
669 ipsec_spd_show_all (vm, im);
675 VLIB_CLI_COMMAND (show_ipsec_spd_command, static) = {
676 .path = "show ipsec spd",
677 .short_help = "show ipsec spd [index]",
678 .function = show_ipsec_spd_command_fn,
682 static clib_error_t *
683 show_ipsec_tunnel_command_fn (vlib_main_t * vm,
684 unformat_input_t * input,
685 vlib_cli_command_t * cmd)
687 ipsec_tunnel_show_all (vm);
693 VLIB_CLI_COMMAND (show_ipsec_tunnel_command, static) = {
694 .path = "show ipsec tunnel",
695 .short_help = "show ipsec tunnel",
696 .function = show_ipsec_tunnel_command_fn,
700 static clib_error_t *
701 ipsec_show_backends_command_fn (vlib_main_t * vm,
702 unformat_input_t * input,
703 vlib_cli_command_t * cmd)
705 ipsec_main_t *im = &ipsec_main;
708 (void) unformat (input, "verbose %u", &verbose);
710 vlib_cli_output (vm, "IPsec AH backends available:");
711 u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
712 ipsec_ah_backend_t *ab;
714 pool_foreach (ab, im->ah_backends) {
715 s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
716 ab - im->ah_backends == im->ah_current_backend ? "yes" : "no");
719 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
720 s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
721 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
722 s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
723 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
724 s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
725 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
726 s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
730 vlib_cli_output (vm, "%v", s);
732 vlib_cli_output (vm, "IPsec ESP backends available:");
733 s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
734 ipsec_esp_backend_t *eb;
736 pool_foreach (eb, im->esp_backends) {
737 s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
738 eb - im->esp_backends == im->esp_current_backend ? "yes"
742 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
743 s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
744 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
745 s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
746 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
747 s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
748 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
749 s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
753 vlib_cli_output (vm, "%v", s);
760 VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = {
761 .path = "show ipsec backends",
762 .short_help = "show ipsec backends",
763 .function = ipsec_show_backends_command_fn,
767 static clib_error_t *
768 ipsec_select_backend_command_fn (vlib_main_t * vm,
769 unformat_input_t * input,
770 vlib_cli_command_t * cmd)
772 unformat_input_t _line_input, *line_input = &_line_input;
773 ipsec_main_t *im = &ipsec_main;
777 error = ipsec_rsc_in_use (im);
782 /* Get a line of input. */
783 if (!unformat_user (input, unformat_line_input, line_input))
786 if (unformat (line_input, "ah"))
788 if (unformat (line_input, "%u", &backend_index))
790 if (ipsec_select_ah_backend (im, backend_index) < 0)
792 return clib_error_return (0, "Invalid AH backend index `%u'",
798 return clib_error_return (0, "Invalid backend index `%U'",
799 format_unformat_error, line_input);
802 else if (unformat (line_input, "esp"))
804 if (unformat (line_input, "%u", &backend_index))
806 if (ipsec_select_esp_backend (im, backend_index) < 0)
808 return clib_error_return (0, "Invalid ESP backend index `%u'",
814 return clib_error_return (0, "Invalid backend index `%U'",
815 format_unformat_error, line_input);
820 return clib_error_return (0, "Unknown input `%U'",
821 format_unformat_error, line_input);
828 VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = {
829 .path = "ipsec select backend",
830 .short_help = "ipsec select backend <ah|esp> <backend index>",
831 .function = ipsec_select_backend_command_fn,
836 static clib_error_t *
837 clear_ipsec_counters_command_fn (vlib_main_t * vm,
838 unformat_input_t * input,
839 vlib_cli_command_t * cmd)
841 vlib_clear_combined_counters (&ipsec_spd_policy_counters);
842 vlib_clear_combined_counters (&ipsec_sa_counters);
843 for (int i = 0; i < IPSEC_SA_N_ERRORS; i++)
844 vlib_clear_simple_counters (&ipsec_sa_err_counters[i]);
850 VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
851 .path = "clear ipsec counters",
852 .short_help = "clear ipsec counters",
853 .function = clear_ipsec_counters_command_fn,
857 static clib_error_t *
858 ipsec_tun_protect_cmd (vlib_main_t * vm,
859 unformat_input_t * input, vlib_cli_command_t * cmd)
861 unformat_input_t _line_input, *line_input = &_line_input;
862 u32 sw_if_index, is_del, sa_in, sa_out, *sa_ins = NULL;
863 ip_address_t peer = { };
868 vnm = vnet_get_main ();
870 if (!unformat_user (input, unformat_line_input, line_input))
873 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
875 if (unformat (line_input, "del"))
877 else if (unformat (line_input, "add"))
879 else if (unformat (line_input, "sa-in %d", &sa_in))
880 vec_add1 (sa_ins, sa_in);
881 else if (unformat (line_input, "sa-out %d", &sa_out))
883 else if (unformat (line_input, "%U",
884 unformat_vnet_sw_interface, vnm, &sw_if_index))
886 else if (unformat (line_input, "%U", unformat_ip_address, &peer))
889 return (clib_error_return (0, "unknown input '%U'",
890 format_unformat_error, line_input));
894 ipsec_tun_protect_update (sw_if_index, &peer, sa_out, sa_ins);
896 ipsec_tun_protect_del (sw_if_index, &peer);
898 unformat_free (line_input);
903 * Protect tunnel with IPSEC
906 VLIB_CLI_COMMAND (ipsec_tun_protect_cmd_node, static) =
908 .path = "ipsec tunnel protect",
909 .function = ipsec_tun_protect_cmd,
910 .short_help = "ipsec tunnel protect <interface> input-sa <SA> output-sa <SA> [add|del]",
911 // this is not MP safe
916 static clib_error_t *
917 ipsec_tun_protect_show (vlib_main_t * vm,
918 unformat_input_t * input, vlib_cli_command_t * cmd)
920 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
926 * show IPSEC tunnel protection
929 VLIB_CLI_COMMAND (ipsec_tun_protect_show_node, static) =
931 .path = "show ipsec protect",
932 .function = ipsec_tun_protect_show,
933 .short_help = "show ipsec protect",
938 ipsec_tun_protect4_hash_show_one (clib_bihash_kv_8_16_t * kv, void *arg)
940 ipsec4_tunnel_kv_t *ikv = (ipsec4_tunnel_kv_t *) kv;
941 vlib_main_t *vm = arg;
943 vlib_cli_output (vm, " %U", format_ipsec4_tunnel_kv, ikv);
945 return (BIHASH_WALK_CONTINUE);
949 ipsec_tun_protect6_hash_show_one (clib_bihash_kv_24_16_t * kv, void *arg)
951 ipsec6_tunnel_kv_t *ikv = (ipsec6_tunnel_kv_t *) kv;
952 vlib_main_t *vm = arg;
954 vlib_cli_output (vm, " %U", format_ipsec6_tunnel_kv, ikv);
956 return (BIHASH_WALK_CONTINUE);
959 static clib_error_t *
960 ipsec_tun_protect_hash_show (vlib_main_t * vm,
961 unformat_input_t * input,
962 vlib_cli_command_t * cmd)
964 ipsec_main_t *im = &ipsec_main;
967 vlib_cli_output (vm, "IPv4:");
969 clib_bihash_foreach_key_value_pair_8_16
970 (&im->tun4_protect_by_key, ipsec_tun_protect4_hash_show_one, vm);
972 vlib_cli_output (vm, "IPv6:");
974 clib_bihash_foreach_key_value_pair_24_16
975 (&im->tun6_protect_by_key, ipsec_tun_protect6_hash_show_one, vm);
982 * show IPSEC tunnel protection hash tables
985 VLIB_CLI_COMMAND (ipsec_tun_protect_hash_show_node, static) =
987 .path = "show ipsec protect-hash",
988 .function = ipsec_tun_protect_hash_show,
989 .short_help = "show ipsec protect-hash",
994 ipsec_cli_init (vlib_main_t * vm)
999 VLIB_INIT_FUNCTION (ipsec_cli_init);
1001 static clib_error_t *
1002 set_async_mode_command_fn (vlib_main_t * vm, unformat_input_t * input,
1003 vlib_cli_command_t * cmd)
1005 unformat_input_t _line_input, *line_input = &_line_input;
1006 int async_enable = 0;
1008 if (!unformat_user (input, unformat_line_input, line_input))
1011 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1013 if (unformat (line_input, "on"))
1015 else if (unformat (line_input, "off"))
1018 return (clib_error_return (0, "unknown input '%U'",
1019 format_unformat_error, line_input));
1022 ipsec_set_async_mode (async_enable);
1024 unformat_free (line_input);
1029 VLIB_CLI_COMMAND (set_async_mode_command, static) = {
1030 .path = "set ipsec async mode",
1031 .short_help = "set ipsec async mode on|off",
1032 .function = set_async_mode_command_fn,
1037 * fd.io coding-style-patch-verification: ON
1040 * eval: (c-set-style "gnu")