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;
40 if (!unformat_user (input, unformat_line_input, line_input))
44 (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main,
45 &sw_if_index, &spd_id))
47 else if (unformat (line_input, "del"))
51 error = clib_error_return (0, "parse error: '%U'",
52 format_unformat_error, line_input);
56 ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add);
59 unformat_free (line_input);
65 VLIB_CLI_COMMAND (set_interface_spd_command, static) = {
66 .path = "set interface ipsec spd",
68 "set interface ipsec spd <int> <id>",
69 .function = set_interface_spd_command_fn,
74 ipsec_sa_add_del_command_fn (vlib_main_t * vm,
75 unformat_input_t * input,
76 vlib_cli_command_t * cmd)
78 unformat_input_t _line_input, *line_input = &_line_input;
79 ip46_address_t tun_src = { }, tun_dst =
82 ipsec_crypto_alg_t crypto_alg;
83 ipsec_integ_alg_t integ_alg;
84 ipsec_protocol_t proto;
85 ipsec_sa_flags_t flags;
87 ipsec_key_t ck = { 0 };
88 ipsec_key_t ik = { 0 };
94 flags = IPSEC_SA_FLAG_NONE;
95 proto = IPSEC_PROTOCOL_ESP;
96 integ_alg = IPSEC_INTEG_ALG_NONE;
97 crypto_alg = IPSEC_CRYPTO_ALG_NONE;
99 if (!unformat_user (input, unformat_line_input, line_input))
102 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
104 if (unformat (line_input, "add %u", &id))
106 else if (unformat (line_input, "del %u", &id))
108 else if (unformat (line_input, "spi %u", &spi))
110 else if (unformat (line_input, "salt 0x%x", &salt))
112 else if (unformat (line_input, "esp"))
113 proto = IPSEC_PROTOCOL_ESP;
114 else if (unformat (line_input, "ah"))
115 proto = IPSEC_PROTOCOL_AH;
116 else if (unformat (line_input, "crypto-key %U",
117 unformat_ipsec_key, &ck))
119 else if (unformat (line_input, "crypto-alg %U",
120 unformat_ipsec_crypto_alg, &crypto_alg))
122 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
124 else if (unformat (line_input, "integ-alg %U",
125 unformat_ipsec_integ_alg, &integ_alg))
127 else if (unformat (line_input, "tunnel-src %U",
128 unformat_ip46_address, &tun_src, IP46_TYPE_ANY))
130 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
131 if (!ip46_address_is_ip4 (&tun_src))
132 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
134 else if (unformat (line_input, "tunnel-dst %U",
135 unformat_ip46_address, &tun_dst, IP46_TYPE_ANY))
137 else if (unformat (line_input, "udp-encap"))
138 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
141 error = clib_error_return (0, "parse error: '%U'",
142 format_unformat_error, line_input);
148 rv = ipsec_sa_add_and_lock (id, spi, proto, crypto_alg,
149 &ck, integ_alg, &ik, flags,
150 0, clib_host_to_net_u32 (salt),
151 &tun_src, &tun_dst, NULL);
153 rv = ipsec_sa_unlock_id (id);
156 error = clib_error_return (0, "failed");
159 unformat_free (line_input);
165 VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
168 "ipsec sa [add|del]",
169 .function = ipsec_sa_add_del_command_fn,
173 static clib_error_t *
174 ipsec_spd_add_del_command_fn (vlib_main_t * vm,
175 unformat_input_t * input,
176 vlib_cli_command_t * cmd)
178 unformat_input_t _line_input, *line_input = &_line_input;
181 clib_error_t *error = NULL;
183 if (!unformat_user (input, unformat_line_input, line_input))
186 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
188 if (unformat (line_input, "add"))
190 else if (unformat (line_input, "del"))
192 else if (unformat (line_input, "%u", &spd_id))
196 error = clib_error_return (0, "parse error: '%U'",
197 format_unformat_error, line_input);
204 error = clib_error_return (0, "please specify SPD ID");
208 ipsec_add_del_spd (vm, spd_id, is_add);
211 unformat_free (line_input);
217 VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
220 "ipsec spd [add|del] <id>",
221 .function = ipsec_spd_add_del_command_fn,
226 static clib_error_t *
227 ipsec_policy_add_del_command_fn (vlib_main_t * vm,
228 unformat_input_t * input,
229 vlib_cli_command_t * cmd)
231 unformat_input_t _line_input, *line_input = &_line_input;
234 u32 tmp, tmp2, stat_index;
235 clib_error_t *error = NULL;
238 clib_memset (&p, 0, sizeof (p));
239 p.lport.stop = p.rport.stop = ~0;
242 if (!unformat_user (input, unformat_line_input, line_input))
245 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
247 if (unformat (line_input, "add"))
249 else if (unformat (line_input, "del"))
251 else if (unformat (line_input, "spd %u", &p.id))
253 else if (unformat (line_input, "inbound"))
255 else if (unformat (line_input, "outbound"))
257 else if (unformat (line_input, "priority %d", &p.priority))
259 else if (unformat (line_input, "protocol %u", &tmp))
260 p.protocol = (u8) tmp;
263 (line_input, "action %U", unformat_ipsec_policy_action,
266 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
268 error = clib_error_return (0, "unsupported action: 'resolve'");
272 else if (unformat (line_input, "sa %u", &p.sa_id))
274 else if (unformat (line_input, "local-ip-range %U - %U",
275 unformat_ip4_address, &p.laddr.start.ip4,
276 unformat_ip4_address, &p.laddr.stop.ip4))
278 else if (unformat (line_input, "remote-ip-range %U - %U",
279 unformat_ip4_address, &p.raddr.start.ip4,
280 unformat_ip4_address, &p.raddr.stop.ip4))
282 else if (unformat (line_input, "local-ip-range %U - %U",
283 unformat_ip6_address, &p.laddr.start.ip6,
284 unformat_ip6_address, &p.laddr.stop.ip6))
288 else if (unformat (line_input, "remote-ip-range %U - %U",
289 unformat_ip6_address, &p.raddr.start.ip6,
290 unformat_ip6_address, &p.raddr.stop.ip6))
294 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
300 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
307 error = clib_error_return (0, "parse error: '%U'",
308 format_unformat_error, line_input);
313 rv = ipsec_policy_mk_type (is_outbound, p.is_ipv6, p.policy, &p.type);
317 error = clib_error_return (0, "unsupported policy type for:",
318 " outboud:%s %s action:%U",
319 (is_outbound ? "yes" : "no"),
320 (p.is_ipv6 ? "IPv4" : "IPv6"),
321 format_ipsec_policy_action, p.policy);
325 rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index);
328 vlib_cli_output (vm, "policy-index:%d", stat_index);
330 vlib_cli_output (vm, "error:%d", rv);
333 unformat_free (line_input);
339 VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
340 .path = "ipsec policy",
342 "ipsec policy [add|del] spd <id> priority <n> ",
343 .function = ipsec_policy_add_del_command_fn,
348 ipsec_sa_show_all (vlib_main_t * vm, ipsec_main_t * im, u8 detail)
353 pool_foreach_index (sai, im->sad, ({
354 vlib_cli_output(vm, "%U", format_ipsec_sa, sai,
355 (detail ? IPSEC_FORMAT_DETAIL : IPSEC_FORMAT_BRIEF));
361 ipsec_spd_show_all (vlib_main_t * vm, ipsec_main_t * im)
366 pool_foreach_index (spdi, im->spds, ({
367 vlib_cli_output(vm, "%U", format_ipsec_spd, spdi);
373 ipsec_spd_bindings_show_all (vlib_main_t * vm, ipsec_main_t * im)
375 u32 spd_id, sw_if_index;
378 vlib_cli_output (vm, "SPD Bindings:");
381 hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({
382 spd = pool_elt_at_index (im->spds, spd_id);
383 vlib_cli_output (vm, " %d -> %U", spd->id,
384 format_vnet_sw_if_index_name, im->vnet_main,
391 ipsec_tun_protect_show_one (index_t itpi, void *ctx)
393 vlib_cli_output (ctx, "%U", format_ipsec_tun_protect, itpi);
395 return (WALK_CONTINUE);
399 ipsec_tunnel_show_all (vlib_main_t * vm)
401 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
404 static clib_error_t *
405 show_ipsec_command_fn (vlib_main_t * vm,
406 unformat_input_t * input, vlib_cli_command_t * cmd)
408 ipsec_main_t *im = &ipsec_main;
410 ipsec_sa_show_all (vm, im, 0);
411 ipsec_spd_show_all (vm, im);
412 ipsec_spd_bindings_show_all (vm, im);
413 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
419 VLIB_CLI_COMMAND (show_ipsec_command, static) = {
420 .path = "show ipsec all",
421 .short_help = "show ipsec all",
422 .function = show_ipsec_command_fn,
426 static clib_error_t *
427 show_ipsec_sa_command_fn (vlib_main_t * vm,
428 unformat_input_t * input, vlib_cli_command_t * cmd)
430 ipsec_main_t *im = &ipsec_main;
434 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
436 if (unformat (input, "%u", &sai))
438 if (unformat (input, "detail"))
445 ipsec_sa_show_all (vm, im, detail);
447 vlib_cli_output (vm, "%U", format_ipsec_sa, sai,
448 IPSEC_FORMAT_DETAIL | IPSEC_FORMAT_INSECURE);
453 static clib_error_t *
454 clear_ipsec_sa_command_fn (vlib_main_t * vm,
455 unformat_input_t * input, vlib_cli_command_t * cmd)
457 ipsec_main_t *im = &ipsec_main;
460 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
462 if (unformat (input, "%u", &sai))
471 pool_foreach_index (sai, im->sad, ({
478 if (pool_is_free_index (im->sad, sai))
479 return clib_error_return (0, "unknown SA index: %d", sai);
481 ipsec_sa_clear (sai);
488 VLIB_CLI_COMMAND (show_ipsec_sa_command, static) = {
489 .path = "show ipsec sa",
490 .short_help = "show ipsec sa [index]",
491 .function = show_ipsec_sa_command_fn,
494 VLIB_CLI_COMMAND (clear_ipsec_sa_command, static) = {
495 .path = "clear ipsec sa",
496 .short_help = "clear ipsec sa [index]",
497 .function = clear_ipsec_sa_command_fn,
501 static clib_error_t *
502 show_ipsec_spd_command_fn (vlib_main_t * vm,
503 unformat_input_t * input, vlib_cli_command_t * cmd)
505 ipsec_main_t *im = &ipsec_main;
506 u8 show_bindings = 0;
509 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
511 if (unformat (input, "%u", &spdi))
513 else if (unformat (input, "bindings"))
520 ipsec_spd_bindings_show_all (vm, im);
522 vlib_cli_output (vm, "%U", format_ipsec_spd, spdi);
524 ipsec_spd_show_all (vm, im);
530 VLIB_CLI_COMMAND (show_ipsec_spd_command, static) = {
531 .path = "show ipsec spd",
532 .short_help = "show ipsec spd [index]",
533 .function = show_ipsec_spd_command_fn,
537 static clib_error_t *
538 show_ipsec_tunnel_command_fn (vlib_main_t * vm,
539 unformat_input_t * input,
540 vlib_cli_command_t * cmd)
542 ipsec_tunnel_show_all (vm);
548 VLIB_CLI_COMMAND (show_ipsec_tunnel_command, static) = {
549 .path = "show ipsec tunnel",
550 .short_help = "show ipsec tunnel",
551 .function = show_ipsec_tunnel_command_fn,
555 static clib_error_t *
556 ipsec_show_backends_command_fn (vlib_main_t * vm,
557 unformat_input_t * input,
558 vlib_cli_command_t * cmd)
560 ipsec_main_t *im = &ipsec_main;
563 (void) unformat (input, "verbose %u", &verbose);
565 vlib_cli_output (vm, "IPsec AH backends available:");
566 u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
567 ipsec_ah_backend_t *ab;
569 pool_foreach (ab, im->ah_backends, {
570 s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
571 ab - im->ah_backends == im->ah_current_backend ? "yes" : "no");
574 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
575 s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
576 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
577 s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
578 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
579 s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
580 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
581 s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
585 vlib_cli_output (vm, "%v", s);
587 vlib_cli_output (vm, "IPsec ESP backends available:");
588 s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
589 ipsec_esp_backend_t *eb;
591 pool_foreach (eb, im->esp_backends, {
592 s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
593 eb - im->esp_backends == im->esp_current_backend ? "yes"
597 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
598 s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
599 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
600 s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
601 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
602 s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
603 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
604 s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
608 vlib_cli_output (vm, "%v", s);
615 VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = {
616 .path = "show ipsec backends",
617 .short_help = "show ipsec backends",
618 .function = ipsec_show_backends_command_fn,
622 static clib_error_t *
623 ipsec_select_backend_command_fn (vlib_main_t * vm,
624 unformat_input_t * input,
625 vlib_cli_command_t * cmd)
627 unformat_input_t _line_input, *line_input = &_line_input;
628 ipsec_main_t *im = &ipsec_main;
632 error = ipsec_rsc_in_use (im);
637 /* Get a line of input. */
638 if (!unformat_user (input, unformat_line_input, line_input))
641 if (unformat (line_input, "ah"))
643 if (unformat (line_input, "%u", &backend_index))
645 if (ipsec_select_ah_backend (im, backend_index) < 0)
647 return clib_error_return (0, "Invalid AH backend index `%u'",
653 return clib_error_return (0, "Invalid backend index `%U'",
654 format_unformat_error, line_input);
657 else if (unformat (line_input, "esp"))
659 if (unformat (line_input, "%u", &backend_index))
661 if (ipsec_select_esp_backend (im, backend_index) < 0)
663 return clib_error_return (0, "Invalid ESP backend index `%u'",
669 return clib_error_return (0, "Invalid backend index `%U'",
670 format_unformat_error, line_input);
675 return clib_error_return (0, "Unknown input `%U'",
676 format_unformat_error, line_input);
683 VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = {
684 .path = "ipsec select backend",
685 .short_help = "ipsec select backend <ah|esp> <backend index>",
686 .function = ipsec_select_backend_command_fn,
691 static clib_error_t *
692 clear_ipsec_counters_command_fn (vlib_main_t * vm,
693 unformat_input_t * input,
694 vlib_cli_command_t * cmd)
696 vlib_clear_combined_counters (&ipsec_spd_policy_counters);
697 vlib_clear_combined_counters (&ipsec_sa_counters);
703 VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
704 .path = "clear ipsec counters",
705 .short_help = "clear ipsec counters",
706 .function = clear_ipsec_counters_command_fn,
711 ipsec_tun_mk_local_sa_id (u32 ti)
713 return (0x80000000 | ti);
717 ipsec_tun_mk_remote_sa_id (u32 ti)
719 return (0xc0000000 | ti);
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 ip46_address_t local_ip = ip46_address_initializer;
729 ip46_address_t remote_ip = ip46_address_initializer;
730 ipsec_crypto_alg_t crypto_alg;
731 ipsec_integ_alg_t integ_alg;
732 ipsec_sa_flags_t flags;
733 u32 local_spi, remote_spi, salt, table_id, fib_index;
740 clib_error_t *error = NULL;
741 ipsec_key_t rck = { 0 };
742 ipsec_key_t lck = { 0 };
743 ipsec_key_t lik = { 0 };
744 ipsec_key_t rik = { 0 };
747 flags = IPSEC_SA_FLAG_NONE;
749 /* Get a line of input. */
750 if (!unformat_user (input, unformat_line_input, line_input))
753 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
756 (line_input, "local-ip %U", unformat_ip46_address, &local_ip,
759 ip46_address_is_ip4 (&local_ip) ? (ipv4_set = 1) : (ipv6_set = 1);
764 (line_input, "remote-ip %U", unformat_ip46_address, &remote_ip,
767 ip46_address_is_ip4 (&remote_ip) ? (ipv4_set = 1) : (ipv6_set = 1);
770 else if (unformat (line_input, "local-spi %u", &local_spi))
772 else if (unformat (line_input, "remote-spi %u", &remote_spi))
774 else if (unformat (line_input, "salt 0x%x", &salt))
776 else if (unformat (line_input, "udp-encap"))
777 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
778 else if (unformat (line_input, "use-esn"))
779 flags |= IPSEC_SA_FLAG_USE_ESN;
780 else if (unformat (line_input, "use-anti-replay"))
781 flags |= IPSEC_SA_FLAG_USE_ANTI_REPLAY;
782 else if (unformat (line_input, "instance %u", &instance))
784 else if (unformat (line_input, "tx-table %u", &table_id))
788 (line_input, "local-crypto-key %U", unformat_ipsec_key, &lck))
792 (line_input, "remote-crypto-key %U", unformat_ipsec_key, &rck))
794 else if (unformat (line_input, "crypto-alg %U",
795 unformat_ipsec_crypto_alg, &crypto_alg))
799 (line_input, "local-integ-key %U", unformat_ipsec_key, &lik))
803 (line_input, "remote-integ-key %U", unformat_ipsec_key, &rik))
805 else if (unformat (line_input, "integ-alg %U",
806 unformat_ipsec_integ_alg, &integ_alg))
808 else if (unformat (line_input, "del"))
812 error = clib_error_return (0, "unknown input `%U'",
813 format_unformat_error, line_input);
820 error = clib_error_return (0, "mandatory argument(s) missing");
824 if (ipv4_set && ipv6_set)
825 return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
827 fib_index = fib_table_find (fib_ip_proto (ipv6_set), table_id);
831 rv = VNET_API_ERROR_NO_SUCH_FIB;
837 // remote = input, local = output
840 /* create an ip-ip tunnel, then the two SA, then bind them */
842 ipip_add_tunnel (ipv6_set ? IPIP_TRANSPORT_IP6 : IPIP_TRANSPORT_IP4,
843 instance, &local_ip, &remote_ip, fib_index, 0,
846 ipsec_sa_add_and_lock (ipsec_tun_mk_local_sa_id (sw_if_index),
847 local_spi, IPSEC_PROTOCOL_ESP, crypto_alg,
848 &lck, integ_alg, &lik, flags, table_id,
849 clib_host_to_net_u32 (salt), &local_ip,
852 ipsec_sa_add_and_lock (ipsec_tun_mk_remote_sa_id (sw_if_index),
853 remote_spi, IPSEC_PROTOCOL_ESP, crypto_alg,
854 &rck, integ_alg, &rik,
855 (flags | IPSEC_SA_FLAG_IS_INBOUND), table_id,
856 clib_host_to_net_u32 (salt), &remote_ip,
859 ipsec_tun_protect_update_one (sw_if_index,
860 ipsec_tun_mk_local_sa_id (sw_if_index),
861 ipsec_tun_mk_remote_sa_id
871 case VNET_API_ERROR_INVALID_VALUE:
872 error = clib_error_return (0,
873 "IPSec tunnel interface already exists...");
876 error = clib_error_return (0, "ipsec_register_interface returned %d",
882 unformat_free (line_input);
888 VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = {
889 .path = "create ipsec tunnel",
890 .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> "
891 "remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap] [use-esn] [use-anti-replay] "
892 "[tx-table <table-id>]",
893 .function = create_ipsec_tunnel_command_fn,
897 static clib_error_t *
898 ipsec_tun_protect_cmd (vlib_main_t * vm,
899 unformat_input_t * input, vlib_cli_command_t * cmd)
901 unformat_input_t _line_input, *line_input = &_line_input;
902 u32 sw_if_index, is_del, sa_in, sa_out, *sa_ins = NULL;
907 vnm = vnet_get_main ();
909 if (!unformat_user (input, unformat_line_input, line_input))
912 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
914 if (unformat (line_input, "del"))
916 else if (unformat (line_input, "add"))
918 else if (unformat (line_input, "sa-in %d", &sa_in))
919 vec_add1 (sa_ins, sa_in);
920 else if (unformat (line_input, "sa-out %d", &sa_out))
922 else if (unformat (line_input, "%U",
923 unformat_vnet_sw_interface, vnm, &sw_if_index))
926 return (clib_error_return (0, "unknown input '%U'",
927 format_unformat_error, line_input));
931 ipsec_tun_protect_update (sw_if_index, sa_out, sa_ins);
933 unformat_free (line_input);
938 * Protect tunnel with IPSEC
941 VLIB_CLI_COMMAND (ipsec_tun_protect_cmd_node, static) =
943 .path = "ipsec tunnel protect",
944 .function = ipsec_tun_protect_cmd,
945 .short_help = "ipsec tunnel protect <interface> input-sa <SA> output-sa <SA>",
946 // this is not MP safe
951 static clib_error_t *
952 ipsec_tun_protect_show (vlib_main_t * vm,
953 unformat_input_t * input, vlib_cli_command_t * cmd)
955 ipsec_tun_protect_walk (ipsec_tun_protect_show_one, vm);
961 * show IPSEC tunnel protection
964 VLIB_CLI_COMMAND (ipsec_tun_protect_show_node, static) =
966 .path = "show ipsec protect",
967 .function = ipsec_tun_protect_show,
968 .short_help = "show ipsec protect",
972 static clib_error_t *
973 ipsec_tun_protect_hash_show (vlib_main_t * vm,
974 unformat_input_t * input,
975 vlib_cli_command_t * cmd)
977 ipsec_main_t *im = &ipsec_main;
980 ipsec_tun_lkup_result_t value;
981 ipsec4_tunnel_key_t key;
983 vlib_cli_output (vm, "IPv4:");
986 hash_foreach(key.as_u64, value.as_u64, im->tun4_protect_by_key,
988 vlib_cli_output (vm, " %U", format_ipsec4_tunnel_key, &key);
989 vlib_cli_output (vm, " tun:%d sa:%d", value.tun_index, value.sa_index);
995 ipsec_tun_lkup_result_t value;
996 ipsec6_tunnel_key_t *key;
998 vlib_cli_output (vm, "IPv6:");
1001 hash_foreach_mem(key, value.as_u64, im->tun6_protect_by_key,
1003 vlib_cli_output (vm, " %U", format_ipsec6_tunnel_key, key);
1004 vlib_cli_output (vm, " tun:%d sa:%d", value.tun_index, value.sa_index);
1013 * show IPSEC tunnel protection hash tables
1016 VLIB_CLI_COMMAND (ipsec_tun_protect_hash_show_node, static) =
1018 .path = "show ipsec protect-hash",
1019 .function = ipsec_tun_protect_hash_show,
1020 .short_help = "show ipsec protect-hash",
1025 ipsec_cli_init (vlib_main_t * vm)
1030 VLIB_INIT_FUNCTION (ipsec_cli_init);
1034 * fd.io coding-style-patch-verification: ON
1037 * eval: (c-set-style "gnu")