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>
24 #include <vnet/ipsec/ipsec.h>
25 #include <vnet/ipsec/ipsec_tun.h>
28 set_interface_spd_command_fn (vlib_main_t * vm,
29 unformat_input_t * input,
30 vlib_cli_command_t * cmd)
32 unformat_input_t _line_input, *line_input = &_line_input;
33 ipsec_main_t *im = &ipsec_main;
34 u32 sw_if_index = (u32) ~ 0;
37 clib_error_t *error = NULL;
39 if (!unformat_user (input, unformat_line_input, line_input))
43 (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main,
44 &sw_if_index, &spd_id))
46 else if (unformat (line_input, "del"))
50 error = clib_error_return (0, "parse error: '%U'",
51 format_unformat_error, line_input);
55 ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add);
58 unformat_free (line_input);
64 VLIB_CLI_COMMAND (set_interface_spd_command, static) = {
65 .path = "set interface ipsec spd",
67 "set interface ipsec spd <int> <id>",
68 .function = set_interface_spd_command_fn,
73 ipsec_sa_add_del_command_fn (vlib_main_t * vm,
74 unformat_input_t * input,
75 vlib_cli_command_t * cmd)
77 unformat_input_t _line_input, *line_input = &_line_input;
78 ip46_address_t tun_src = { }, tun_dst =
81 ipsec_crypto_alg_t crypto_alg;
82 ipsec_integ_alg_t integ_alg;
83 ipsec_protocol_t proto;
84 ipsec_sa_flags_t flags;
86 ipsec_key_t ck = { 0 };
87 ipsec_key_t ik = { 0 };
93 flags = IPSEC_SA_FLAG_NONE;
94 proto = IPSEC_PROTOCOL_ESP;
95 integ_alg = IPSEC_INTEG_ALG_NONE;
96 crypto_alg = IPSEC_CRYPTO_ALG_NONE;
98 if (!unformat_user (input, unformat_line_input, line_input))
101 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
103 if (unformat (line_input, "add %u", &id))
105 else if (unformat (line_input, "del %u", &id))
107 else if (unformat (line_input, "spi %u", &spi))
109 else if (unformat (line_input, "salt 0x%x", &salt))
111 else if (unformat (line_input, "esp"))
112 proto = IPSEC_PROTOCOL_ESP;
113 else if (unformat (line_input, "ah"))
114 proto = IPSEC_PROTOCOL_AH;
115 else if (unformat (line_input, "crypto-key %U",
116 unformat_ipsec_key, &ck))
118 else if (unformat (line_input, "crypto-alg %U",
119 unformat_ipsec_crypto_alg, &crypto_alg))
121 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
123 else if (unformat (line_input, "integ-alg %U",
124 unformat_ipsec_integ_alg, &integ_alg))
126 else if (unformat (line_input, "tunnel-src %U",
127 unformat_ip46_address, &tun_src, IP46_TYPE_ANY))
129 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
130 if (!ip46_address_is_ip4 (&tun_src))
131 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
133 else if (unformat (line_input, "tunnel-dst %U",
134 unformat_ip46_address, &tun_dst, IP46_TYPE_ANY))
136 else if (unformat (line_input, "udp-encap"))
137 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
140 error = clib_error_return (0, "parse error: '%U'",
141 format_unformat_error, line_input);
147 rv = ipsec_sa_add_and_lock (id, spi, proto, crypto_alg,
148 &ck, integ_alg, &ik, flags,
149 0, clib_host_to_net_u32 (salt),
150 &tun_src, &tun_dst, NULL);
152 rv = ipsec_sa_unlock_id (id);
155 error = clib_error_return (0, "failed");
158 unformat_free (line_input);
164 VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
167 "ipsec sa [add|del]",
168 .function = ipsec_sa_add_del_command_fn,
172 static clib_error_t *
173 ipsec_spd_add_del_command_fn (vlib_main_t * vm,
174 unformat_input_t * input,
175 vlib_cli_command_t * cmd)
177 unformat_input_t _line_input, *line_input = &_line_input;
180 clib_error_t *error = NULL;
182 if (!unformat_user (input, unformat_line_input, line_input))
185 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
187 if (unformat (line_input, "add"))
189 else if (unformat (line_input, "del"))
191 else if (unformat (line_input, "%u", &spd_id))
195 error = clib_error_return (0, "parse error: '%U'",
196 format_unformat_error, line_input);
203 error = clib_error_return (0, "please specify SPD ID");
207 ipsec_add_del_spd (vm, spd_id, is_add);
210 unformat_free (line_input);
216 VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
219 "ipsec spd [add|del] <id>",
220 .function = ipsec_spd_add_del_command_fn,
225 static clib_error_t *
226 ipsec_policy_add_del_command_fn (vlib_main_t * vm,
227 unformat_input_t * input,
228 vlib_cli_command_t * cmd)
230 unformat_input_t _line_input, *line_input = &_line_input;
233 u32 tmp, tmp2, stat_index;
234 clib_error_t *error = NULL;
237 clib_memset (&p, 0, sizeof (p));
238 p.lport.stop = p.rport.stop = ~0;
241 if (!unformat_user (input, unformat_line_input, line_input))
244 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
246 if (unformat (line_input, "add"))
248 else if (unformat (line_input, "del"))
250 else if (unformat (line_input, "spd %u", &p.id))
252 else if (unformat (line_input, "inbound"))
254 else if (unformat (line_input, "outbound"))
256 else if (unformat (line_input, "priority %d", &p.priority))
258 else if (unformat (line_input, "protocol %u", &tmp))
259 p.protocol = (u8) tmp;
262 (line_input, "action %U", unformat_ipsec_policy_action,
265 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
267 error = clib_error_return (0, "unsupported action: 'resolve'");
271 else if (unformat (line_input, "sa %u", &p.sa_id))
273 else if (unformat (line_input, "local-ip-range %U - %U",
274 unformat_ip4_address, &p.laddr.start.ip4,
275 unformat_ip4_address, &p.laddr.stop.ip4))
277 else if (unformat (line_input, "remote-ip-range %U - %U",
278 unformat_ip4_address, &p.raddr.start.ip4,
279 unformat_ip4_address, &p.raddr.stop.ip4))
281 else if (unformat (line_input, "local-ip-range %U - %U",
282 unformat_ip6_address, &p.laddr.start.ip6,
283 unformat_ip6_address, &p.laddr.stop.ip6))
287 else if (unformat (line_input, "remote-ip-range %U - %U",
288 unformat_ip6_address, &p.raddr.start.ip6,
289 unformat_ip6_address, &p.raddr.stop.ip6))
293 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
299 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
306 error = clib_error_return (0, "parse error: '%U'",
307 format_unformat_error, line_input);
312 rv = ipsec_policy_mk_type (is_outbound, p.is_ipv6, p.policy, &p.type);
316 error = clib_error_return (0, "unsupported policy type for:",
317 " outboud:%s %s action:%U",
318 (is_outbound ? "yes" : "no"),
319 (p.is_ipv6 ? "IPv4" : "IPv6"),
320 format_ipsec_policy_action, p.policy);
324 rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index);
327 vlib_cli_output (vm, "policy-index:%d", stat_index);
329 vlib_cli_output (vm, "error:%d", rv);
332 unformat_free (line_input);
338 VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
339 .path = "ipsec policy",
341 "ipsec policy [add|del] spd <id> priority <n> ",
342 .function = ipsec_policy_add_del_command_fn,
347 ipsec_sa_show_all (vlib_main_t * vm, ipsec_main_t * im, u8 detail)
352 pool_foreach_index (sai, im->sad, ({
353 vlib_cli_output(vm, "%U", format_ipsec_sa, sai,
354 (detail ? IPSEC_FORMAT_DETAIL : IPSEC_FORMAT_BRIEF));
360 ipsec_spd_show_all (vlib_main_t * vm, ipsec_main_t * im)
365 pool_foreach_index (spdi, im->spds, ({
366 vlib_cli_output(vm, "%U", format_ipsec_spd, spdi);
372 ipsec_spd_bindings_show_all (vlib_main_t * vm, ipsec_main_t * im)
374 u32 spd_id, sw_if_index;
377 vlib_cli_output (vm, "SPD Bindings:");
380 hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({
381 spd = pool_elt_at_index (im->spds, spd_id);
382 vlib_cli_output (vm, " %d -> %U", spd->id,
383 format_vnet_sw_if_index_name, im->vnet_main,
390 ipsec_tunnel_show_all (vlib_main_t * vm, ipsec_main_t * im)
394 vlib_cli_output (vm, "Tunnel interfaces");
396 pool_foreach_index (ti, im->tunnel_interfaces, ({
397 vlib_cli_output(vm, " %U", format_ipsec_tunnel, ti);
402 static clib_error_t *
403 show_ipsec_command_fn (vlib_main_t * vm,
404 unformat_input_t * input, vlib_cli_command_t * cmd)
406 ipsec_main_t *im = &ipsec_main;
408 ipsec_sa_show_all (vm, im, 0);
409 ipsec_spd_show_all (vm, im);
410 ipsec_spd_bindings_show_all (vm, im);
411 ipsec_tunnel_show_all (vm, im);
417 VLIB_CLI_COMMAND (show_ipsec_command, static) = {
418 .path = "show ipsec all",
419 .short_help = "show ipsec all",
420 .function = show_ipsec_command_fn,
424 static clib_error_t *
425 show_ipsec_sa_command_fn (vlib_main_t * vm,
426 unformat_input_t * input, vlib_cli_command_t * cmd)
428 ipsec_main_t *im = &ipsec_main;
432 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
434 if (unformat (input, "%u", &sai))
436 if (unformat (input, "detail"))
443 ipsec_sa_show_all (vm, im, detail);
445 vlib_cli_output (vm, "%U", format_ipsec_sa, sai,
446 IPSEC_FORMAT_DETAIL | IPSEC_FORMAT_INSECURE);
451 static clib_error_t *
452 clear_ipsec_sa_command_fn (vlib_main_t * vm,
453 unformat_input_t * input, vlib_cli_command_t * cmd)
455 ipsec_main_t *im = &ipsec_main;
458 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
460 if (unformat (input, "%u", &sai))
469 pool_foreach_index (sai, im->sad, ({
476 if (pool_is_free_index (im->sad, sai))
477 return clib_error_return (0, "unknown SA index: %d", sai);
479 ipsec_sa_clear (sai);
486 VLIB_CLI_COMMAND (show_ipsec_sa_command, static) = {
487 .path = "show ipsec sa",
488 .short_help = "show ipsec sa [index]",
489 .function = show_ipsec_sa_command_fn,
492 VLIB_CLI_COMMAND (clear_ipsec_sa_command, static) = {
493 .path = "clear ipsec sa",
494 .short_help = "clear ipsec sa [index]",
495 .function = clear_ipsec_sa_command_fn,
499 static clib_error_t *
500 show_ipsec_spd_command_fn (vlib_main_t * vm,
501 unformat_input_t * input, vlib_cli_command_t * cmd)
503 ipsec_main_t *im = &ipsec_main;
504 u8 show_bindings = 0;
507 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
509 if (unformat (input, "%u", &spdi))
511 else if (unformat (input, "bindings"))
518 ipsec_spd_bindings_show_all (vm, im);
520 vlib_cli_output (vm, "%U", format_ipsec_spd, spdi);
522 ipsec_spd_show_all (vm, im);
528 VLIB_CLI_COMMAND (show_ipsec_spd_command, static) = {
529 .path = "show ipsec spd",
530 .short_help = "show ipsec spd [index]",
531 .function = show_ipsec_spd_command_fn,
535 static clib_error_t *
536 show_ipsec_tunnel_command_fn (vlib_main_t * vm,
537 unformat_input_t * input,
538 vlib_cli_command_t * cmd)
540 ipsec_main_t *im = &ipsec_main;
543 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
545 if (unformat (input, "%u", &ti))
552 vlib_cli_output (vm, "%U", format_ipsec_tunnel, ti);
554 ipsec_tunnel_show_all (vm, im);
560 VLIB_CLI_COMMAND (show_ipsec_tunnel_command, static) = {
561 .path = "show ipsec tunnel",
562 .short_help = "show ipsec tunnel [index]",
563 .function = show_ipsec_tunnel_command_fn,
567 static clib_error_t *
568 ipsec_show_backends_command_fn (vlib_main_t * vm,
569 unformat_input_t * input,
570 vlib_cli_command_t * cmd)
572 ipsec_main_t *im = &ipsec_main;
575 (void) unformat (input, "verbose %u", &verbose);
577 vlib_cli_output (vm, "IPsec AH backends available:");
578 u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
579 ipsec_ah_backend_t *ab;
581 pool_foreach (ab, im->ah_backends, {
582 s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
583 ab - im->ah_backends == im->ah_current_backend ? "yes" : "no");
586 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
587 s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
588 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
589 s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
590 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
591 s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
592 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
593 s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
597 vlib_cli_output (vm, "%v", s);
599 vlib_cli_output (vm, "IPsec ESP backends available:");
600 s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
601 ipsec_esp_backend_t *eb;
603 pool_foreach (eb, im->esp_backends, {
604 s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
605 eb - im->esp_backends == im->esp_current_backend ? "yes"
609 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
610 s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
611 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
612 s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
613 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
614 s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
615 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
616 s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
620 vlib_cli_output (vm, "%v", s);
627 VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = {
628 .path = "show ipsec backends",
629 .short_help = "show ipsec backends",
630 .function = ipsec_show_backends_command_fn,
634 static clib_error_t *
635 ipsec_select_backend_command_fn (vlib_main_t * vm,
636 unformat_input_t * input,
637 vlib_cli_command_t * cmd)
639 unformat_input_t _line_input, *line_input = &_line_input;
640 ipsec_main_t *im = &ipsec_main;
644 error = ipsec_rsc_in_use (im);
649 /* Get a line of input. */
650 if (!unformat_user (input, unformat_line_input, line_input))
653 if (unformat (line_input, "ah"))
655 if (unformat (line_input, "%u", &backend_index))
657 if (ipsec_select_ah_backend (im, backend_index) < 0)
659 return clib_error_return (0, "Invalid AH backend index `%u'",
665 return clib_error_return (0, "Invalid backend index `%U'",
666 format_unformat_error, line_input);
669 else if (unformat (line_input, "esp"))
671 if (unformat (line_input, "%u", &backend_index))
673 if (ipsec_select_esp_backend (im, backend_index) < 0)
675 return clib_error_return (0, "Invalid ESP backend index `%u'",
681 return clib_error_return (0, "Invalid backend index `%U'",
682 format_unformat_error, line_input);
687 return clib_error_return (0, "Unknown input `%U'",
688 format_unformat_error, line_input);
695 VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = {
696 .path = "ipsec select backend",
697 .short_help = "ipsec select backend <ah|esp> <backend index>",
698 .function = ipsec_select_backend_command_fn,
703 static clib_error_t *
704 clear_ipsec_counters_command_fn (vlib_main_t * vm,
705 unformat_input_t * input,
706 vlib_cli_command_t * cmd)
708 vlib_clear_combined_counters (&ipsec_spd_policy_counters);
709 vlib_clear_combined_counters (&ipsec_sa_counters);
715 VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
716 .path = "clear ipsec counters",
717 .short_help = "clear ipsec counters",
718 .function = clear_ipsec_counters_command_fn,
722 static clib_error_t *
723 create_ipsec_tunnel_command_fn (vlib_main_t * vm,
724 unformat_input_t * input,
725 vlib_cli_command_t * cmd)
727 unformat_input_t _line_input, *line_input = &_line_input;
728 ipsec_add_del_tunnel_args_t a;
733 clib_error_t *error = NULL;
734 ipsec_key_t rck = { 0 };
735 ipsec_key_t lck = { 0 };
736 ipsec_key_t lik = { 0 };
737 ipsec_key_t rik = { 0 };
739 clib_memset (&a, 0, sizeof (a));
742 /* Get a line of input. */
743 if (!unformat_user (input, unformat_line_input, line_input))
746 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
749 (line_input, "local-ip %U", unformat_ip46_address, &a.local_ip,
752 ip46_address_is_ip4 (&a.local_ip) ? (ipv4_set = 1) : (ipv6_set = 1);
757 (line_input, "remote-ip %U", unformat_ip46_address, &a.remote_ip,
760 ip46_address_is_ip4 (&a.remote_ip) ? (ipv4_set = 1) : (ipv6_set =
764 else if (unformat (line_input, "local-spi %u", &a.local_spi))
766 else if (unformat (line_input, "remote-spi %u", &a.remote_spi))
768 else if (unformat (line_input, "instance %u", &a.show_instance))
770 else if (unformat (line_input, "salt 0x%x", &a.salt))
772 else if (unformat (line_input, "udp-encap"))
774 else if (unformat (line_input, "use-esn"))
776 else if (unformat (line_input, "use-anti-replay"))
778 else if (unformat (line_input, "tx-table %u", &a.tx_table_id))
782 (line_input, "local-crypto-key %U", unformat_ipsec_key, &lck))
786 (line_input, "remote-crypto-key %U", unformat_ipsec_key, &rck))
788 else if (unformat (line_input, "crypto-alg %U",
789 unformat_ipsec_crypto_alg, &a.crypto_alg))
793 (line_input, "local-integ-key %U", unformat_ipsec_key, &lik))
797 (line_input, "remote-integ-key %U", unformat_ipsec_key, &rik))
799 else if (unformat (line_input, "integ-alg %U",
800 unformat_ipsec_integ_alg, &a.integ_alg))
802 else if (unformat (line_input, "del"))
806 error = clib_error_return (0, "unknown input `%U'",
807 format_unformat_error, line_input);
814 error = clib_error_return (0, "mandatory argument(s) missing");
818 if (ipv4_set && ipv6_set)
819 return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
823 clib_memcpy (a.local_crypto_key, lck.data, lck.len);
824 a.local_crypto_key_len = lck.len;
825 clib_memcpy (a.remote_crypto_key, rck.data, rck.len);
826 a.remote_crypto_key_len = rck.len;
828 clib_memcpy (a.local_integ_key, lik.data, lik.len);
829 a.local_integ_key_len = lck.len;
830 clib_memcpy (a.remote_integ_key, rik.data, rik.len);
831 a.remote_integ_key_len = rck.len;
833 rv = ipsec_add_del_tunnel_if (&a);
839 case VNET_API_ERROR_INVALID_VALUE:
841 error = clib_error_return (0,
842 "IPSec tunnel interface already exists...");
844 error = clib_error_return (0, "IPSec tunnel interface not exists...");
847 error = clib_error_return (0, "ipsec_register_interface returned %d",
853 unformat_free (line_input);
859 VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = {
860 .path = "create ipsec tunnel",
861 .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> "
862 "remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap] [use-esn] [use-anti-replay] "
863 "[tx-table <table-id>]",
864 .function = create_ipsec_tunnel_command_fn,
868 static clib_error_t *
869 ipsec_tun_protect_cmd (vlib_main_t * vm,
870 unformat_input_t * input, vlib_cli_command_t * cmd)
872 unformat_input_t _line_input, *line_input = &_line_input;
873 u32 sw_if_index, is_del, sa_in, sa_out, *sa_ins = NULL;
878 vnm = vnet_get_main ();
880 if (!unformat_user (input, unformat_line_input, line_input))
883 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
885 if (unformat (line_input, "del"))
887 else if (unformat (line_input, "add"))
889 else if (unformat (line_input, "sa-in %d", &sa_in))
890 vec_add1 (sa_ins, sa_in);
891 else if (unformat (line_input, "sa-out %d", &sa_out))
893 else if (unformat (line_input, "%U",
894 unformat_vnet_sw_interface, vnm, &sw_if_index))
897 return (clib_error_return (0, "unknown input '%U'",
898 format_unformat_error, line_input));
902 ipsec_tun_protect_update (sw_if_index, sa_out, sa_ins);
904 unformat_free (line_input);
909 * Protect tunnel with IPSEC
912 VLIB_CLI_COMMAND (ipsec_tun_protect_cmd_node, static) =
914 .path = "ipsec tunnel protect",
915 .function = ipsec_tun_protect_cmd,
916 .short_help = "ipsec tunnel protect <interface> input-sa <SA> output-sa <SA>",
917 // this is not MP safe
922 ipsec_tun_protect_show_one (index_t itpi, void *ctx)
924 vlib_cli_output (ctx, "%U", format_ipsec_tun_protect, itpi);
926 return (WALK_CONTINUE);
929 static clib_error_t *
930 ipsec_tun_protect_show (vlib_main_t * vm,
931 unformat_input_t * input, vlib_cli_command_t * cmd)
933 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
939 * show IPSEC tunnel protection
942 VLIB_CLI_COMMAND (ipsec_tun_protect_show_node, static) =
944 .path = "show ipsec protect",
945 .function = ipsec_tun_protect_show,
946 .short_help = "show ipsec protect",
950 static clib_error_t *
951 ipsec_tun_protect_hash_show (vlib_main_t * vm,
952 unformat_input_t * input,
953 vlib_cli_command_t * cmd)
955 ipsec_main_t *im = &ipsec_main;
958 ipsec_tun_lkup_result_t value;
959 ipsec4_tunnel_key_t key;
961 vlib_cli_output (vm, "IPv4:");
964 hash_foreach(key.as_u64, value.as_u64, im->tun4_protect_by_key,
966 vlib_cli_output (vm, " %U", format_ipsec4_tunnel_key, &key);
967 vlib_cli_output (vm, " tun:%d sa:%d", value.tun_index, value.sa_index);
973 ipsec_tun_lkup_result_t value;
974 ipsec6_tunnel_key_t *key;
976 vlib_cli_output (vm, "IPv6:");
979 hash_foreach_mem(key, value.as_u64, im->tun6_protect_by_key,
981 vlib_cli_output (vm, " %U", format_ipsec6_tunnel_key, key);
982 vlib_cli_output (vm, " tun:%d sa:%d", value.tun_index, value.sa_index);
991 * show IPSEC tunnel protection hash tables
994 VLIB_CLI_COMMAND (ipsec_tun_protect_hash_show_node, static) =
996 .path = "show ipsec protect-hash",
997 .function = ipsec_tun_protect_hash_show,
998 .short_help = "show ipsec protect-hash",
1003 ipsec_cli_init (vlib_main_t * vm)
1008 VLIB_INIT_FUNCTION (ipsec_cli_init);
1012 * fd.io coding-style-patch-verification: ON
1015 * eval: (c-set-style "gnu")