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;
95 if (!unformat_user (input, unformat_line_input, line_input))
98 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
100 if (unformat (line_input, "add %u", &id))
102 else if (unformat (line_input, "del %u", &id))
104 else if (unformat (line_input, "spi %u", &spi))
106 else if (unformat (line_input, "salt %u", &salt))
108 else if (unformat (line_input, "esp"))
109 proto = IPSEC_PROTOCOL_ESP;
110 else if (unformat (line_input, "ah"))
111 proto = IPSEC_PROTOCOL_AH;
112 else if (unformat (line_input, "crypto-key %U",
113 unformat_ipsec_key, &ck))
115 else if (unformat (line_input, "crypto-alg %U",
116 unformat_ipsec_crypto_alg, &crypto_alg))
118 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
120 else if (unformat (line_input, "integ-alg %U",
121 unformat_ipsec_integ_alg, &integ_alg))
123 else if (unformat (line_input, "tunnel-src %U",
124 unformat_ip46_address, &tun_src, IP46_TYPE_ANY))
126 flags |= IPSEC_SA_FLAG_IS_TUNNEL;
127 if (!ip46_address_is_ip4 (&tun_src))
128 flags |= IPSEC_SA_FLAG_IS_TUNNEL_V6;
130 else if (unformat (line_input, "tunnel-dst %U",
131 unformat_ip46_address, &tun_dst, IP46_TYPE_ANY))
133 else if (unformat (line_input, "udp-encap"))
134 flags |= IPSEC_SA_FLAG_UDP_ENCAP;
137 error = clib_error_return (0, "parse error: '%U'",
138 format_unformat_error, line_input);
144 rv = ipsec_sa_add (id, spi, proto, crypto_alg,
145 &ck, integ_alg, &ik, flags,
146 0, clib_host_to_net_u32 (salt),
147 &tun_src, &tun_dst, NULL);
149 rv = ipsec_sa_del (id);
152 clib_error_return (0, "failed");
155 unformat_free (line_input);
161 VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
164 "ipsec sa [add|del]",
165 .function = ipsec_sa_add_del_command_fn,
169 static clib_error_t *
170 ipsec_spd_add_del_command_fn (vlib_main_t * vm,
171 unformat_input_t * input,
172 vlib_cli_command_t * cmd)
174 unformat_input_t _line_input, *line_input = &_line_input;
177 clib_error_t *error = NULL;
179 if (!unformat_user (input, unformat_line_input, line_input))
182 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
184 if (unformat (line_input, "add"))
186 else if (unformat (line_input, "del"))
188 else if (unformat (line_input, "%u", &spd_id))
192 error = clib_error_return (0, "parse error: '%U'",
193 format_unformat_error, line_input);
200 error = clib_error_return (0, "please specify SPD ID");
204 ipsec_add_del_spd (vm, spd_id, is_add);
207 unformat_free (line_input);
213 VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
216 "ipsec spd [add|del] <id>",
217 .function = ipsec_spd_add_del_command_fn,
222 static clib_error_t *
223 ipsec_policy_add_del_command_fn (vlib_main_t * vm,
224 unformat_input_t * input,
225 vlib_cli_command_t * cmd)
227 unformat_input_t _line_input, *line_input = &_line_input;
230 u32 tmp, tmp2, stat_index;
231 clib_error_t *error = NULL;
234 clib_memset (&p, 0, sizeof (p));
235 p.lport.stop = p.rport.stop = ~0;
236 p.laddr.stop.ip4.as_u32 = p.raddr.stop.ip4.as_u32 = (u32) ~ 0;
237 p.laddr.stop.ip6.as_u64[0] = p.laddr.stop.ip6.as_u64[1] = (u64) ~ 0;
238 p.raddr.stop.ip6.as_u64[0] = p.raddr.stop.ip6.as_u64[1] = (u64) ~ 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))
297 p.lport.start = clib_host_to_net_u16 (p.lport.start);
298 p.lport.stop = clib_host_to_net_u16 (p.lport.stop);
301 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
305 p.rport.start = clib_host_to_net_u16 (p.rport.start);
306 p.rport.stop = clib_host_to_net_u16 (p.rport.stop);
310 error = clib_error_return (0, "parse error: '%U'",
311 format_unformat_error, line_input);
316 rv = ipsec_policy_mk_type (is_outbound, p.is_ipv6, p.policy, &p.type);
320 error = clib_error_return (0, "unsupported policy type for:",
321 " outboud:%s %s action:%U",
322 (is_outbound ? "yes" : "no"),
323 (p.is_ipv6 ? "IPv4" : "IPv6"),
324 format_ipsec_policy_action, p.policy);
328 rv = ipsec_add_del_policy (vm, &p, is_add, &stat_index);
331 vlib_cli_output (vm, "policy-index:%d", stat_index);
333 vlib_cli_output (vm, "error:%d", rv);
336 unformat_free (line_input);
342 VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
343 .path = "ipsec policy",
345 "ipsec policy [add|del] spd <id> priority <n> ",
346 .function = ipsec_policy_add_del_command_fn,
350 static clib_error_t *
351 set_ipsec_sa_key_command_fn (vlib_main_t * vm,
352 unformat_input_t * input,
353 vlib_cli_command_t * cmd)
355 unformat_input_t _line_input, *line_input = &_line_input;
356 ipsec_key_t ck = { }, ik =
359 clib_error_t *error = NULL;
362 if (!unformat_user (input, unformat_line_input, line_input))
365 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
367 if (unformat (line_input, "%u", &id))
370 if (unformat (line_input, "crypto-key %U", unformat_ipsec_key, &ck))
372 else if (unformat (line_input, "integ-key %U", unformat_ipsec_key, &ik))
376 error = clib_error_return (0, "parse error: '%U'",
377 format_unformat_error, line_input);
382 ipsec_set_sa_key (id, &ck, &ik);
385 unformat_free (line_input);
391 VLIB_CLI_COMMAND (set_ipsec_sa_key_command, static) = {
392 .path = "set ipsec sa",
393 .short_help = "set ipsec sa <id> crypto-key <key> integ-key <key>",
394 .function = set_ipsec_sa_key_command_fn,
399 ipsec_sa_show_all (vlib_main_t * vm, ipsec_main_t * im)
404 pool_foreach_index (sai, im->sad, ({
405 vlib_cli_output(vm, "%U", format_ipsec_sa, sai, IPSEC_FORMAT_BRIEF);
411 ipsec_spd_show_all (vlib_main_t * vm, ipsec_main_t * im)
416 pool_foreach_index (spdi, im->spds, ({
417 vlib_cli_output(vm, "%U", format_ipsec_spd, spdi);
423 ipsec_spd_bindings_show_all (vlib_main_t * vm, ipsec_main_t * im)
425 u32 spd_id, sw_if_index;
427 vlib_cli_output (vm, "SPD Bindings:");
430 hash_foreach(sw_if_index, spd_id, im->spd_index_by_sw_if_index, ({
431 vlib_cli_output (vm, " %d -> %U", spd_id,
432 format_vnet_sw_if_index_name, im->vnet_main,
439 ipsec_tunnel_show_all (vlib_main_t * vm, ipsec_main_t * im)
443 vlib_cli_output (vm, "Tunnel interfaces");
445 pool_foreach_index (ti, im->tunnel_interfaces, ({
446 vlib_cli_output(vm, " %U", format_ipsec_tunnel, ti);
451 static clib_error_t *
452 show_ipsec_command_fn (vlib_main_t * vm,
453 unformat_input_t * input, vlib_cli_command_t * cmd)
455 ipsec_main_t *im = &ipsec_main;
457 ipsec_sa_show_all (vm, im);
458 ipsec_spd_show_all (vm, im);
459 ipsec_spd_bindings_show_all (vm, im);
460 ipsec_tunnel_show_all (vm, im);
466 VLIB_CLI_COMMAND (show_ipsec_command, static) = {
467 .path = "show ipsec all",
468 .short_help = "show ipsec all",
469 .function = show_ipsec_command_fn,
473 static clib_error_t *
474 show_ipsec_sa_command_fn (vlib_main_t * vm,
475 unformat_input_t * input, vlib_cli_command_t * cmd)
477 ipsec_main_t *im = &ipsec_main;
480 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
482 if (unformat (input, "%u", &sai))
489 ipsec_sa_show_all (vm, im);
491 vlib_cli_output (vm, "%U", format_ipsec_sa, sai, IPSEC_FORMAT_DETAIL);
497 VLIB_CLI_COMMAND (show_ipsec_sa_command, static) = {
498 .path = "show ipsec sa",
499 .short_help = "show ipsec sa [index]",
500 .function = show_ipsec_sa_command_fn,
504 static clib_error_t *
505 show_ipsec_spd_command_fn (vlib_main_t * vm,
506 unformat_input_t * input, vlib_cli_command_t * cmd)
508 ipsec_main_t *im = &ipsec_main;
509 u8 show_bindings = 0;
512 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
514 if (unformat (input, "%u", &spdi))
516 else if (unformat (input, "bindings"))
523 ipsec_spd_bindings_show_all (vm, im);
525 vlib_cli_output (vm, "%U", format_ipsec_spd, spdi);
527 ipsec_spd_show_all (vm, im);
533 VLIB_CLI_COMMAND (show_ipsec_spd_command, static) = {
534 .path = "show ipsec spd",
535 .short_help = "show ipsec spd [index]",
536 .function = show_ipsec_spd_command_fn,
540 static clib_error_t *
541 show_ipsec_tunnel_command_fn (vlib_main_t * vm,
542 unformat_input_t * input,
543 vlib_cli_command_t * cmd)
545 ipsec_main_t *im = &ipsec_main;
548 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
550 if (unformat (input, "%u", &ti))
557 vlib_cli_output (vm, "%U", format_ipsec_tunnel, ti);
559 ipsec_tunnel_show_all (vm, im);
565 VLIB_CLI_COMMAND (show_ipsec_tunnel_command, static) = {
566 .path = "show ipsec tunnel",
567 .short_help = "show ipsec tunnel [index]",
568 .function = show_ipsec_tunnel_command_fn,
572 static clib_error_t *
573 ipsec_show_backends_command_fn (vlib_main_t * vm,
574 unformat_input_t * input,
575 vlib_cli_command_t * cmd)
577 ipsec_main_t *im = &ipsec_main;
580 (void) unformat (input, "verbose %u", &verbose);
582 vlib_cli_output (vm, "IPsec AH backends available:");
583 u8 *s = format (NULL, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
584 ipsec_ah_backend_t *ab;
586 pool_foreach (ab, im->ah_backends, {
587 s = format (s, "%=25s %=25u %=10s\n", ab->name, ab - im->ah_backends,
588 ab - im->ah_backends == im->ah_current_backend ? "yes" : "no");
591 n = vlib_get_node (vm, ab->ah4_encrypt_node_index);
592 s = format (s, " enc4 %s (next %d)\n", n->name, ab->ah4_encrypt_next_index);
593 n = vlib_get_node (vm, ab->ah4_decrypt_node_index);
594 s = format (s, " dec4 %s (next %d)\n", n->name, ab->ah4_decrypt_next_index);
595 n = vlib_get_node (vm, ab->ah6_encrypt_node_index);
596 s = format (s, " enc6 %s (next %d)\n", n->name, ab->ah6_encrypt_next_index);
597 n = vlib_get_node (vm, ab->ah6_decrypt_node_index);
598 s = format (s, " dec6 %s (next %d)\n", n->name, ab->ah6_decrypt_next_index);
602 vlib_cli_output (vm, "%v", s);
604 vlib_cli_output (vm, "IPsec ESP backends available:");
605 s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
606 ipsec_esp_backend_t *eb;
608 pool_foreach (eb, im->esp_backends, {
609 s = format (s, "%=25s %=25u %=10s\n", eb->name, eb - im->esp_backends,
610 eb - im->esp_backends == im->esp_current_backend ? "yes"
614 n = vlib_get_node (vm, eb->esp4_encrypt_node_index);
615 s = format (s, " enc4 %s (next %d)\n", n->name, eb->esp4_encrypt_next_index);
616 n = vlib_get_node (vm, eb->esp4_decrypt_node_index);
617 s = format (s, " dec4 %s (next %d)\n", n->name, eb->esp4_decrypt_next_index);
618 n = vlib_get_node (vm, eb->esp6_encrypt_node_index);
619 s = format (s, " enc6 %s (next %d)\n", n->name, eb->esp6_encrypt_next_index);
620 n = vlib_get_node (vm, eb->esp6_decrypt_node_index);
621 s = format (s, " dec6 %s (next %d)\n", n->name, eb->esp6_decrypt_next_index);
625 vlib_cli_output (vm, "%v", s);
632 VLIB_CLI_COMMAND (ipsec_show_backends_command, static) = {
633 .path = "show ipsec backends",
634 .short_help = "show ipsec backends",
635 .function = ipsec_show_backends_command_fn,
639 static clib_error_t *
640 ipsec_select_backend_command_fn (vlib_main_t * vm,
641 unformat_input_t * input,
642 vlib_cli_command_t * cmd)
644 unformat_input_t _line_input, *line_input = &_line_input;
645 ipsec_main_t *im = &ipsec_main;
649 error = ipsec_rsc_in_use (im);
654 /* Get a line of input. */
655 if (!unformat_user (input, unformat_line_input, line_input))
658 if (unformat (line_input, "ah"))
660 if (unformat (line_input, "%u", &backend_index))
662 if (ipsec_select_ah_backend (im, backend_index) < 0)
664 return clib_error_return (0, "Invalid AH backend index `%u'",
670 return clib_error_return (0, "Invalid backend index `%U'",
671 format_unformat_error, line_input);
674 else if (unformat (line_input, "esp"))
676 if (unformat (line_input, "%u", &backend_index))
678 if (ipsec_select_esp_backend (im, backend_index) < 0)
680 return clib_error_return (0, "Invalid ESP backend index `%u'",
686 return clib_error_return (0, "Invalid backend index `%U'",
687 format_unformat_error, line_input);
692 return clib_error_return (0, "Unknown input `%U'",
693 format_unformat_error, line_input);
700 VLIB_CLI_COMMAND (ipsec_select_backend_command, static) = {
701 .path = "ipsec select backend",
702 .short_help = "ipsec select backend <ah|esp> <backend index>",
703 .function = ipsec_select_backend_command_fn,
708 static clib_error_t *
709 clear_ipsec_counters_command_fn (vlib_main_t * vm,
710 unformat_input_t * input,
711 vlib_cli_command_t * cmd)
713 vlib_clear_combined_counters (&ipsec_spd_policy_counters);
714 vlib_clear_combined_counters (&ipsec_sa_counters);
720 VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
721 .path = "clear ipsec counters",
722 .short_help = "clear ipsec counters",
723 .function = clear_ipsec_counters_command_fn,
727 static clib_error_t *
728 create_ipsec_tunnel_command_fn (vlib_main_t * vm,
729 unformat_input_t * input,
730 vlib_cli_command_t * cmd)
732 unformat_input_t _line_input, *line_input = &_line_input;
733 ipsec_add_del_tunnel_args_t a;
738 clib_error_t *error = NULL;
739 ipsec_key_t rck = { 0 };
740 ipsec_key_t lck = { 0 };
741 ipsec_key_t lik = { 0 };
742 ipsec_key_t rik = { 0 };
744 clib_memset (&a, 0, sizeof (a));
747 /* Get a line of input. */
748 if (!unformat_user (input, unformat_line_input, line_input))
751 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
754 (line_input, "local-ip %U", unformat_ip46_address, &a.local_ip,
757 ip46_address_is_ip4 (&a.local_ip) ? (ipv4_set = 1) : (ipv6_set = 1);
762 (line_input, "remote-ip %U", unformat_ip46_address, &a.remote_ip,
765 ip46_address_is_ip4 (&a.remote_ip) ? (ipv4_set = 1) : (ipv6_set =
769 else if (unformat (line_input, "local-spi %u", &a.local_spi))
771 else if (unformat (line_input, "remote-spi %u", &a.remote_spi))
773 else if (unformat (line_input, "instance %u", &a.show_instance))
775 else if (unformat (line_input, "salt 0x%x", &a.salt))
777 else if (unformat (line_input, "udp-encap"))
779 else if (unformat (line_input, "use-esn"))
781 else if (unformat (line_input, "use-anti-replay"))
783 else if (unformat (line_input, "tx-table %u", &a.tx_table_id))
787 (line_input, "local-crypto-key %U", unformat_ipsec_key, &lck))
791 (line_input, "remote-crypto-key %U", unformat_ipsec_key, &rck))
793 else if (unformat (line_input, "crypto-alg %U",
794 unformat_ipsec_crypto_alg, &a.crypto_alg))
798 (line_input, "local-integ-key %U", unformat_ipsec_key, &lik))
802 (line_input, "remote-integ-key %U", unformat_ipsec_key, &rik))
804 else if (unformat (line_input, "integ-alg %U",
805 unformat_ipsec_integ_alg, &a.integ_alg))
807 else if (unformat (line_input, "del"))
811 error = clib_error_return (0, "unknown input `%U'",
812 format_unformat_error, line_input);
819 error = clib_error_return (0, "mandatory argument(s) missing");
823 if (ipv4_set && ipv6_set)
824 return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
828 clib_memcpy (a.local_crypto_key, lck.data, lck.len);
829 a.local_crypto_key_len = lck.len;
830 clib_memcpy (a.remote_crypto_key, rck.data, rck.len);
831 a.remote_crypto_key_len = rck.len;
833 clib_memcpy (a.local_integ_key, lik.data, lik.len);
834 a.local_integ_key_len = lck.len;
835 clib_memcpy (a.remote_integ_key, rik.data, rik.len);
836 a.remote_integ_key_len = rck.len;
838 rv = ipsec_add_del_tunnel_if (&a);
844 case VNET_API_ERROR_INVALID_VALUE:
846 error = clib_error_return (0,
847 "IPSec tunnel interface already exists...");
849 error = clib_error_return (0, "IPSec tunnel interface not exists...");
852 error = clib_error_return (0, "ipsec_register_interface returned %d",
858 unformat_free (line_input);
864 VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = {
865 .path = "create ipsec tunnel",
866 .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> "
867 "remote-ip <addr> remote-spi <spi> [instance <inst_num>] [udp-encap] [use-esn] [use-anti-replay] "
868 "[tx-table <table-id>]",
869 .function = create_ipsec_tunnel_command_fn,
873 static clib_error_t *
874 set_interface_key_command_fn (vlib_main_t * vm,
875 unformat_input_t * input,
876 vlib_cli_command_t * cmd)
878 unformat_input_t _line_input, *line_input = &_line_input;
879 ipsec_main_t *im = &ipsec_main;
880 ipsec_if_set_key_type_t type = IPSEC_IF_SET_KEY_TYPE_NONE;
881 u32 hw_if_index = (u32) ~ 0;
884 clib_error_t *error = NULL;
886 if (!unformat_user (input, unformat_line_input, line_input))
889 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
891 if (unformat (line_input, "%U",
892 unformat_vnet_hw_interface, im->vnet_main, &hw_if_index))
896 (line_input, "local crypto %U", unformat_ipsec_crypto_alg, &alg))
897 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO;
900 (line_input, "remote crypto %U", unformat_ipsec_crypto_alg, &alg))
901 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO;
904 (line_input, "local integ %U", unformat_ipsec_integ_alg, &alg))
905 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG;
908 (line_input, "remote integ %U", unformat_ipsec_integ_alg, &alg))
909 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG;
910 else if (unformat (line_input, "%U", unformat_hex_string, &key))
914 error = clib_error_return (0, "parse error: '%U'",
915 format_unformat_error, line_input);
920 if (type == IPSEC_IF_SET_KEY_TYPE_NONE)
922 error = clib_error_return (0, "unknown key type");
926 if (alg > 0 && vec_len (key) == 0)
928 error = clib_error_return (0, "key is not specified");
932 if (hw_if_index == (u32) ~ 0)
934 error = clib_error_return (0, "interface not specified");
938 ipsec_set_interface_key (im->vnet_main, hw_if_index, type, alg, key);
942 unformat_free (line_input);
948 VLIB_CLI_COMMAND (set_interface_key_command, static) = {
949 .path = "set interface ipsec key",
951 "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>",
952 .function = set_interface_key_command_fn,
957 ipsec_cli_init (vlib_main_t * vm)
962 VLIB_INIT_FUNCTION (ipsec_cli_init);
966 * fd.io coding-style-patch-verification: ON
969 * eval: (c-set-style "gnu")