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>
27 set_interface_spd_command_fn (vlib_main_t * vm,
28 unformat_input_t * input,
29 vlib_cli_command_t * cmd)
31 unformat_input_t _line_input, *line_input = &_line_input;
32 ipsec_main_t *im = &ipsec_main;
33 u32 sw_if_index = (u32) ~ 0;
36 clib_error_t *error = NULL;
38 if (!unformat_user (input, unformat_line_input, line_input))
42 (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main,
43 &sw_if_index, &spd_id))
45 else if (unformat (line_input, "del"))
49 error = clib_error_return (0, "parse error: '%U'",
50 format_unformat_error, line_input);
54 ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add);
57 unformat_free (line_input);
63 VLIB_CLI_COMMAND (set_interface_spd_command, static) = {
64 .path = "set interface ipsec spd",
66 "set interface ipsec spd <int> <id>",
67 .function = set_interface_spd_command_fn,
72 ipsec_sa_add_del_command_fn (vlib_main_t * vm,
73 unformat_input_t * input,
74 vlib_cli_command_t * cmd)
76 unformat_input_t _line_input, *line_input = &_line_input;
77 ip46_address_t tun_src = { }, tun_dst =
80 ipsec_crypto_alg_t crypto_alg;
81 ipsec_integ_alg_t integ_alg;
82 ipsec_protocol_t proto;
83 ipsec_sa_flags_t flags;
85 ipsec_key_t ck = { 0 };
86 ipsec_key_t ik = { 0 };
92 flags = IPSEC_SA_FLAG_NONE;
93 proto = IPSEC_PROTOCOL_ESP;
94 integ_alg = IPSEC_INTEG_ALG_NONE;
95 crypto_alg = IPSEC_CRYPTO_ALG_NONE;
97 if (!unformat_user (input, unformat_line_input, line_input))
100 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
102 if (unformat (line_input, "add %u", &id))
104 else if (unformat (line_input, "del %u", &id))
106 else if (unformat (line_input, "spi %u", &spi))
108 else if (unformat (line_input, "salt %u", &salt))
110 else if (unformat (line_input, "esp"))
111 proto = IPSEC_PROTOCOL_ESP;
112 else if (unformat (line_input, "ah"))
113 proto = IPSEC_PROTOCOL_AH;
114 else if (unformat (line_input, "crypto-key %U",
115 unformat_ipsec_key, &ck))
117 else if (unformat (line_input, "crypto-alg %U",
118 unformat_ipsec_crypto_alg, &crypto_alg))
120 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
122 else if (unformat (line_input, "integ-alg %U",
123 unformat_ipsec_integ_alg, &integ_alg))
125 else if (unformat (line_input, "tunnel-src %U",
126 unformat_ip46_address, &tun_src, IP46_TYPE_ANY))
128 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
129 if (!ip46_address_is_ip4 (&tun_src))
130 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
132 else if (unformat (line_input, "tunnel-dst %U",
133 unformat_ip46_address, &tun_dst, IP46_TYPE_ANY))
135 else if (unformat (line_input, "udp-encap"))
136 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
139 error = clib_error_return (0, "parse error: '%U'",
140 format_unformat_error, line_input);
146 rv = ipsec_sa_add (id, spi, proto, crypto_alg,
147 &ck, integ_alg, &ik, flags,
148 0, clib_host_to_net_u32 (salt),
149 &tun_src, &tun_dst, NULL);
151 rv = ipsec_sa_del (id);
154 error = clib_error_return (0, "failed");
157 unformat_free (line_input);
163 VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
166 "ipsec sa [add|del]",
167 .function = ipsec_sa_add_del_command_fn,
171 static clib_error_t *
172 ipsec_spd_add_del_command_fn (vlib_main_t * vm,
173 unformat_input_t * input,
174 vlib_cli_command_t * cmd)
176 unformat_input_t _line_input, *line_input = &_line_input;
179 clib_error_t *error = NULL;
181 if (!unformat_user (input, unformat_line_input, line_input))
184 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
186 if (unformat (line_input, "add"))
188 else if (unformat (line_input, "del"))
190 else if (unformat (line_input, "%u", &spd_id))
194 error = clib_error_return (0, "parse error: '%U'",
195 format_unformat_error, line_input);
202 error = clib_error_return (0, "please specify SPD ID");
206 ipsec_add_del_spd (vm, spd_id, is_add);
209 unformat_free (line_input);
215 VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
218 "ipsec spd [add|del] <id>",
219 .function = ipsec_spd_add_del_command_fn,
224 static clib_error_t *
225 ipsec_policy_add_del_command_fn (vlib_main_t * vm,
226 unformat_input_t * input,
227 vlib_cli_command_t * cmd)
229 unformat_input_t _line_input, *line_input = &_line_input;
232 u32 tmp, tmp2, stat_index;
233 clib_error_t *error = NULL;
236 clib_memset (&p, 0, sizeof (p));
237 p.lport.stop = p.rport.stop = ~0;
240 if (!unformat_user (input, unformat_line_input, line_input))
243 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
245 if (unformat (line_input, "add"))
247 else if (unformat (line_input, "del"))
249 else if (unformat (line_input, "spd %u", &p.id))
251 else if (unformat (line_input, "inbound"))
253 else if (unformat (line_input, "outbound"))
255 else if (unformat (line_input, "priority %d", &p.priority))
257 else if (unformat (line_input, "protocol %u", &tmp))
258 p.protocol = (u8) tmp;
261 (line_input, "action %U", unformat_ipsec_policy_action,
264 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
266 error = clib_error_return (0, "unsupported action: 'resolve'");
270 else if (unformat (line_input, "sa %u", &p.sa_id))
272 else if (unformat (line_input, "local-ip-range %U - %U",
273 unformat_ip4_address, &p.laddr.start.ip4,
274 unformat_ip4_address, &p.laddr.stop.ip4))
276 else if (unformat (line_input, "remote-ip-range %U - %U",
277 unformat_ip4_address, &p.raddr.start.ip4,
278 unformat_ip4_address, &p.raddr.stop.ip4))
280 else if (unformat (line_input, "local-ip-range %U - %U",
281 unformat_ip6_address, &p.laddr.start.ip6,
282 unformat_ip6_address, &p.laddr.stop.ip6))
286 else if (unformat (line_input, "remote-ip-range %U - %U",
287 unformat_ip6_address, &p.raddr.start.ip6,
288 unformat_ip6_address, &p.raddr.stop.ip6))
292 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
296 p.lport.start = clib_host_to_net_u16 (p.lport.start);
297 p.lport.stop = clib_host_to_net_u16 (p.lport.stop);
300 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
304 p.rport.start = clib_host_to_net_u16 (p.rport.start);
305 p.rport.stop = clib_host_to_net_u16 (p.rport.stop);
309 error = clib_error_return (0, "parse error: '%U'",
310 format_unformat_error, line_input);
315 rv = ipsec_policy_mk_type (is_outbound, p.is_ipv6, p.policy, &p.type);
319 error = clib_error_return (0, "unsupported policy type for:",
320 " outboud:%s %s action:%U",
321 (is_outbound ? "yes" : "no"),
322 (p.is_ipv6 ? "IPv4" : "IPv6"),
323 format_ipsec_policy_action, p.policy);
327 rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index);
330 vlib_cli_output (vm, "policy-index:%d", stat_index);
332 vlib_cli_output (vm, "error:%d", rv);
335 unformat_free (line_input);
341 VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
342 .path = "ipsec policy",
344 "ipsec policy [add|del] spd <id> priority <n> ",
345 .function = ipsec_policy_add_del_command_fn,
349 static clib_error_t *
350 set_ipsec_sa_key_command_fn (vlib_main_t * vm,
351 unformat_input_t * input,
352 vlib_cli_command_t * cmd)
354 unformat_input_t _line_input, *line_input = &_line_input;
355 ipsec_key_t ck = { }, ik =
358 clib_error_t *error = NULL;
361 if (!unformat_user (input, unformat_line_input, line_input))
364 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
366 if (unformat (line_input, "%u", &id))
369 if (unformat (line_input, "crypto-key %U", unformat_ipsec_key, &ck))
371 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
375 error = clib_error_return (0, "parse error: '%U'",
376 format_unformat_error, line_input);
381 ipsec_set_sa_key (id, &ck, &ik);
384 unformat_free (line_input);
390 VLIB_CLI_COMMAND (set_ipsec_sa_key_command, static) = {
391 .path = "set ipsec sa",
392 .short_help = "set ipsec sa <id> crypto-key <key> integ-key <key>",
393 .function = set_ipsec_sa_key_command_fn,
398 ipsec_sa_show_all (vlib_main_t * vm, ipsec_main_t * im)
403 pool_foreach_index (sai, im->sad, ({
404 vlib_cli_output(vm, "%U", format_ipsec_sa, sai, IPSEC_FORMAT_BRIEF);
410 ipsec_spd_show_all (vlib_main_t * vm, ipsec_main_t * im)
415 pool_foreach_index (spdi, im->spds, ({
416 vlib_cli_output(vm, "%U", format_ipsec_spd, spdi);
422 ipsec_spd_bindings_show_all (vlib_main_t * vm, ipsec_main_t * im)
424 u32 spd_id, sw_if_index;
426 vlib_cli_output (vm, "SPD Bindings:");
429 hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({
430 vlib_cli_output (vm, " %d -> %U", spd_id,
431 format_vnet_sw_if_index_name, im->vnet_main,
438 ipsec_tunnel_show_all (vlib_main_t * vm, ipsec_main_t * im)
442 vlib_cli_output (vm, "Tunnel interfaces");
444 pool_foreach_index (ti, im->tunnel_interfaces, ({
445 vlib_cli_output(vm, " %U", format_ipsec_tunnel, ti);
450 static clib_error_t *
451 show_ipsec_command_fn (vlib_main_t * vm,
452 unformat_input_t * input, vlib_cli_command_t * cmd)
454 ipsec_main_t *im = &ipsec_main;
456 ipsec_sa_show_all (vm, im);
457 ipsec_spd_show_all (vm, im);
458 ipsec_spd_bindings_show_all (vm, im);
459 ipsec_tunnel_show_all (vm, im);
465 VLIB_CLI_COMMAND (show_ipsec_command, static) = {
466 .path = "show ipsec all",
467 .short_help = "show ipsec all",
468 .function = show_ipsec_command_fn,
472 static clib_error_t *
473 show_ipsec_sa_command_fn (vlib_main_t * vm,
474 unformat_input_t * input, vlib_cli_command_t * cmd)
476 ipsec_main_t *im = &ipsec_main;
479 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
481 if (unformat (input, "%u", &sai))
488 ipsec_sa_show_all (vm, im);
490 vlib_cli_output (vm, "%U", format_ipsec_sa, sai, IPSEC_FORMAT_DETAIL);
496 VLIB_CLI_COMMAND (show_ipsec_sa_command, static) = {
497 .path = "show ipsec sa",
498 .short_help = "show ipsec sa [index]",
499 .function = show_ipsec_sa_command_fn,
503 static clib_error_t *
504 show_ipsec_spd_command_fn (vlib_main_t * vm,
505 unformat_input_t * input, vlib_cli_command_t * cmd)
507 ipsec_main_t *im = &ipsec_main;
508 u8 show_bindings = 0;
511 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
513 if (unformat (input, "%u", &spdi))
515 else if (unformat (input, "bindings"))
522 ipsec_spd_bindings_show_all (vm, im);
524 vlib_cli_output (vm, "%U", format_ipsec_spd, spdi);
526 ipsec_spd_show_all (vm, im);
532 VLIB_CLI_COMMAND (show_ipsec_spd_command, static) = {
533 .path = "show ipsec spd",
534 .short_help = "show ipsec spd [index]",
535 .function = show_ipsec_spd_command_fn,
539 static clib_error_t *
540 show_ipsec_tunnel_command_fn (vlib_main_t * vm,
541 unformat_input_t * input,
542 vlib_cli_command_t * cmd)
544 ipsec_main_t *im = &ipsec_main;
547 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
549 if (unformat (input, "%u", &ti))
556 vlib_cli_output (vm, "%U", format_ipsec_tunnel, ti);
558 ipsec_tunnel_show_all (vm, im);
564 VLIB_CLI_COMMAND (show_ipsec_tunnel_command, static) = {
565 .path = "show ipsec tunnel",
566 .short_help = "show ipsec tunnel [index]",
567 .function = show_ipsec_tunnel_command_fn,
571 static clib_error_t *
572 ipsec_show_backends_command_fn (vlib_main_t * vm,
573 unformat_input_t * input,
574 vlib_cli_command_t * cmd)
576 ipsec_main_t *im = &ipsec_main;
579 (void) unformat (input, "verbose %u", &verbose);
581 vlib_cli_output (vm, "IPsec AH backends available:");
582 u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
583 ipsec_ah_backend_t *ab;
585 pool_foreach (ab, im->ah_backends, {
586 s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
587 ab - im->ah_backends == im->ah_current_backend ? "yes" : "no");
590 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
591 s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
592 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
593 s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
594 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
595 s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
596 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
597 s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
601 vlib_cli_output (vm, "%v", s);
603 vlib_cli_output (vm, "IPsec ESP backends available:");
604 s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
605 ipsec_esp_backend_t *eb;
607 pool_foreach (eb, im->esp_backends, {
608 s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
609 eb - im->esp_backends == im->esp_current_backend ? "yes"
613 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
614 s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
615 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
616 s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
617 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
618 s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
619 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
620 s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
624 vlib_cli_output (vm, "%v", s);
631 VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = {
632 .path = "show ipsec backends",
633 .short_help = "show ipsec backends",
634 .function = ipsec_show_backends_command_fn,
638 static clib_error_t *
639 ipsec_select_backend_command_fn (vlib_main_t * vm,
640 unformat_input_t * input,
641 vlib_cli_command_t * cmd)
643 unformat_input_t _line_input, *line_input = &_line_input;
644 ipsec_main_t *im = &ipsec_main;
648 error = ipsec_rsc_in_use (im);
653 /* Get a line of input. */
654 if (!unformat_user (input, unformat_line_input, line_input))
657 if (unformat (line_input, "ah"))
659 if (unformat (line_input, "%u", &backend_index))
661 if (ipsec_select_ah_backend (im, backend_index) < 0)
663 return clib_error_return (0, "Invalid AH backend index `%u'",
669 return clib_error_return (0, "Invalid backend index `%U'",
670 format_unformat_error, line_input);
673 else if (unformat (line_input, "esp"))
675 if (unformat (line_input, "%u", &backend_index))
677 if (ipsec_select_esp_backend (im, backend_index) < 0)
679 return clib_error_return (0, "Invalid ESP backend index `%u'",
685 return clib_error_return (0, "Invalid backend index `%U'",
686 format_unformat_error, line_input);
691 return clib_error_return (0, "Unknown input `%U'",
692 format_unformat_error, line_input);
699 VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = {
700 .path = "ipsec select backend",
701 .short_help = "ipsec select backend <ah|esp> <backend index>",
702 .function = ipsec_select_backend_command_fn,
707 static clib_error_t *
708 clear_ipsec_counters_command_fn (vlib_main_t * vm,
709 unformat_input_t * input,
710 vlib_cli_command_t * cmd)
712 vlib_clear_combined_counters (&ipsec_spd_policy_counters);
713 vlib_clear_combined_counters (&ipsec_sa_counters);
719 VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
720 .path = "clear ipsec counters",
721 .short_help = "clear ipsec counters",
722 .function = clear_ipsec_counters_command_fn,
726 static clib_error_t *
727 create_ipsec_tunnel_command_fn (vlib_main_t * vm,
728 unformat_input_t * input,
729 vlib_cli_command_t * cmd)
731 unformat_input_t _line_input, *line_input = &_line_input;
732 ipsec_add_del_tunnel_args_t a;
737 clib_error_t *error = NULL;
738 ipsec_key_t rck = { 0 };
739 ipsec_key_t lck = { 0 };
740 ipsec_key_t lik = { 0 };
741 ipsec_key_t rik = { 0 };
743 clib_memset (&a, 0, sizeof (a));
746 /* Get a line of input. */
747 if (!unformat_user (input, unformat_line_input, line_input))
750 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
753 (line_input, "local-ip %U", unformat_ip46_address, &a.local_ip,
756 ip46_address_is_ip4 (&a.local_ip) ? (ipv4_set = 1) : (ipv6_set = 1);
761 (line_input, "remote-ip %U", unformat_ip46_address, &a.remote_ip,
764 ip46_address_is_ip4 (&a.remote_ip) ? (ipv4_set = 1) : (ipv6_set =
768 else if (unformat (line_input, "local-spi %u", &a.local_spi))
770 else if (unformat (line_input, "remote-spi %u", &a.remote_spi))
772 else if (unformat (line_input, "instance %u", &a.show_instance))
774 else if (unformat (line_input, "salt 0x%x", &a.salt))
776 else if (unformat (line_input, "udp-encap"))
778 else if (unformat (line_input, "use-esn"))
780 else if (unformat (line_input, "use-anti-replay"))
782 else if (unformat (line_input, "tx-table %u", &a.tx_table_id))
786 (line_input, "local-crypto-key %U", unformat_ipsec_key, &lck))
790 (line_input, "remote-crypto-key %U", unformat_ipsec_key, &rck))
792 else if (unformat (line_input, "crypto-alg %U",
793 unformat_ipsec_crypto_alg, &a.crypto_alg))
797 (line_input, "local-integ-key %U", unformat_ipsec_key, &lik))
801 (line_input, "remote-integ-key %U", unformat_ipsec_key, &rik))
803 else if (unformat (line_input, "integ-alg %U",
804 unformat_ipsec_integ_alg, &a.integ_alg))
806 else if (unformat (line_input, "del"))
810 error = clib_error_return (0, "unknown input `%U'",
811 format_unformat_error, line_input);
818 error = clib_error_return (0, "mandatory argument(s) missing");
822 if (ipv4_set && ipv6_set)
823 return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
827 clib_memcpy (a.local_crypto_key, lck.data, lck.len);
828 a.local_crypto_key_len = lck.len;
829 clib_memcpy (a.remote_crypto_key, rck.data, rck.len);
830 a.remote_crypto_key_len = rck.len;
832 clib_memcpy (a.local_integ_key, lik.data, lik.len);
833 a.local_integ_key_len = lck.len;
834 clib_memcpy (a.remote_integ_key, rik.data, rik.len);
835 a.remote_integ_key_len = rck.len;
837 rv = ipsec_add_del_tunnel_if (&a);
843 case VNET_API_ERROR_INVALID_VALUE:
845 error = clib_error_return (0,
846 "IPSec tunnel interface already exists...");
848 error = clib_error_return (0, "IPSec tunnel interface not exists...");
851 error = clib_error_return (0, "ipsec_register_interface returned %d",
857 unformat_free (line_input);
863 VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = {
864 .path = "create ipsec tunnel",
865 .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> "
866 "remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap] [use-esn] [use-anti-replay] "
867 "[tx-table <table-id>]",
868 .function = create_ipsec_tunnel_command_fn,
872 static clib_error_t *
873 set_interface_key_command_fn (vlib_main_t * vm,
874 unformat_input_t * input,
875 vlib_cli_command_t * cmd)
877 unformat_input_t _line_input, *line_input = &_line_input;
878 ipsec_main_t *im = &ipsec_main;
879 ipsec_if_set_key_type_t type = IPSEC_IF_SET_KEY_TYPE_NONE;
880 u32 hw_if_index = (u32) ~ 0;
883 clib_error_t *error = NULL;
885 if (!unformat_user (input, unformat_line_input, line_input))
888 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
890 if (unformat (line_input, "%U",
891 unformat_vnet_hw_interface, im->vnet_main, &hw_if_index))
895 (line_input, "local crypto %U", unformat_ipsec_crypto_alg, &alg))
896 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO;
899 (line_input, "remote crypto %U", unformat_ipsec_crypto_alg, &alg))
900 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO;
903 (line_input, "local integ %U", unformat_ipsec_integ_alg, &alg))
904 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG;
907 (line_input, "remote integ %U", unformat_ipsec_integ_alg, &alg))
908 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG;
909 else if (unformat (line_input, "%U", unformat_hex_string, &key))
913 error = clib_error_return (0, "parse error: '%U'",
914 format_unformat_error, line_input);
919 if (type == IPSEC_IF_SET_KEY_TYPE_NONE)
921 error = clib_error_return (0, "unknown key type");
925 if (alg > 0 && vec_len (key) == 0)
927 error = clib_error_return (0, "key is not specified");
931 if (hw_if_index == (u32) ~ 0)
933 error = clib_error_return (0, "interface not specified");
937 ipsec_set_interface_key (im->vnet_main, hw_if_index, type, alg, key);
941 unformat_free (line_input);
947 VLIB_CLI_COMMAND (set_interface_key_command, static) = {
948 .path = "set interface ipsec key",
950 "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>",
951 .function = set_interface_key_command_fn,
956 ipsec_cli_init (vlib_main_t * vm)
961 VLIB_INIT_FUNCTION (ipsec_cli_init);
965 * fd.io coding-style-patch-verification: ON
968 * eval: (c-set-style "gnu")