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>
23 #include <vnet/ipsec/ipsec.h>
26 set_interface_spd_command_fn (vlib_main_t * vm,
27 unformat_input_t * input,
28 vlib_cli_command_t * cmd)
30 unformat_input_t _line_input, *line_input = &_line_input;
31 ipsec_main_t *im = &ipsec_main;
32 u32 sw_if_index = (u32) ~ 0;
35 clib_error_t *error = NULL;
37 if (!unformat_user (input, unformat_line_input, line_input))
41 (line_input, "%U %u", unformat_vnet_sw_interface, im->vnet_main,
42 &sw_if_index, &spd_id))
44 else if (unformat (line_input, "del"))
48 error = clib_error_return (0, "parse error: '%U'",
49 format_unformat_error, line_input);
53 ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add);
56 unformat_free (line_input);
62 VLIB_CLI_COMMAND (set_interface_spd_command, static) = {
63 .path = "set interface ipsec spd",
65 "set interface ipsec spd <int> <id>",
66 .function = set_interface_spd_command_fn,
71 ipsec_sa_add_del_command_fn (vlib_main_t * vm,
72 unformat_input_t * input,
73 vlib_cli_command_t * cmd)
75 ipsec_main_t *im = &ipsec_main;
76 unformat_input_t _line_input, *line_input = &_line_input;
80 clib_error_t *error = NULL;
82 memset (&sa, 0, sizeof (sa));
84 if (!unformat_user (input, unformat_line_input, line_input))
87 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
89 if (unformat (line_input, "add %u", &sa.id))
91 else if (unformat (line_input, "del %u", &sa.id))
93 else if (unformat (line_input, "spi %u", &sa.spi))
95 else if (unformat (line_input, "esp"))
96 sa.protocol = IPSEC_PROTOCOL_ESP;
97 else if (unformat (line_input, "ah"))
99 //sa.protocol = IPSEC_PROTOCOL_AH;
100 error = clib_error_return (0, "unsupported security protocol 'AH'");
104 if (unformat (line_input, "crypto-key %U", unformat_hex_string, &ck))
105 sa.crypto_key_len = vec_len (ck);
108 (line_input, "crypto-alg %U", unformat_ipsec_crypto_alg,
111 if (sa.crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
112 sa.crypto_alg >= IPSEC_CRYPTO_N_ALG)
114 error = clib_error_return (0, "unsupported crypto-alg: '%U'",
115 format_ipsec_crypto_alg,
121 if (unformat (line_input, "integ-key %U", unformat_hex_string, &ik))
122 sa.integ_key_len = vec_len (ik);
123 else if (unformat (line_input, "integ-alg %U", unformat_ipsec_integ_alg,
126 if (sa.integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
127 sa.integ_alg >= IPSEC_INTEG_N_ALG)
129 error = clib_error_return (0, "unsupported integ-alg: '%U'",
130 format_ipsec_integ_alg,
135 else if (unformat (line_input, "tunnel-src %U",
136 unformat_ip4_address, &sa.tunnel_src_addr.ip4))
138 else if (unformat (line_input, "tunnel-dst %U",
139 unformat_ip4_address, &sa.tunnel_dst_addr.ip4))
141 else if (unformat (line_input, "tunnel-src %U",
142 unformat_ip6_address, &sa.tunnel_src_addr.ip6))
145 sa.is_tunnel_ip6 = 1;
147 else if (unformat (line_input, "tunnel-dst %U",
148 unformat_ip6_address, &sa.tunnel_dst_addr.ip6))
151 sa.is_tunnel_ip6 = 1;
155 error = clib_error_return (0, "parse error: '%U'",
156 format_unformat_error, line_input);
161 if (sa.crypto_key_len > sizeof (sa.crypto_key))
162 sa.crypto_key_len = sizeof (sa.crypto_key);
164 if (sa.integ_key_len > sizeof (sa.integ_key))
165 sa.integ_key_len = sizeof (sa.integ_key);
168 strncpy ((char *) sa.crypto_key, (char *) ck, sa.crypto_key_len);
171 strncpy ((char *) sa.integ_key, (char *) ik, sa.integ_key_len);
175 ASSERT (im->cb.check_support_cb);
176 error = im->cb.check_support_cb (&sa);
181 ipsec_add_del_sa (vm, &sa, is_add);
184 unformat_free (line_input);
190 VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
193 "ipsec sa [add|del]",
194 .function = ipsec_sa_add_del_command_fn,
198 static clib_error_t *
199 ipsec_spd_add_del_command_fn (vlib_main_t * vm,
200 unformat_input_t * input,
201 vlib_cli_command_t * cmd)
203 unformat_input_t _line_input, *line_input = &_line_input;
206 clib_error_t *error = NULL;
208 if (!unformat_user (input, unformat_line_input, line_input))
211 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
213 if (unformat (line_input, "add"))
215 else if (unformat (line_input, "del"))
217 else if (unformat (line_input, "%u", &spd_id))
221 error = clib_error_return (0, "parse error: '%U'",
222 format_unformat_error, line_input);
229 error = clib_error_return (0, "please specify SPD ID");
233 ipsec_add_del_spd (vm, spd_id, is_add);
236 unformat_free (line_input);
242 VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
245 "ipsec spd [add|del] <id>",
246 .function = ipsec_spd_add_del_command_fn,
251 static clib_error_t *
252 ipsec_policy_add_del_command_fn (vlib_main_t * vm,
253 unformat_input_t * input,
254 vlib_cli_command_t * cmd)
256 unformat_input_t _line_input, *line_input = &_line_input;
261 clib_error_t *error = NULL;
263 memset (&p, 0, sizeof (p));
264 p.lport.stop = p.rport.stop = ~0;
265 p.laddr.stop.ip4.as_u32 = p.raddr.stop.ip4.as_u32 = (u32) ~ 0;
266 p.laddr.stop.ip6.as_u64[0] = p.laddr.stop.ip6.as_u64[1] = (u64) ~ 0;
267 p.raddr.stop.ip6.as_u64[0] = p.raddr.stop.ip6.as_u64[1] = (u64) ~ 0;
269 if (!unformat_user (input, unformat_line_input, line_input))
272 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
274 if (unformat (line_input, "add"))
276 else if (unformat (line_input, "del"))
278 else if (unformat (line_input, "spd %u", &p.id))
280 else if (unformat (line_input, "inbound"))
282 else if (unformat (line_input, "outbound"))
284 else if (unformat (line_input, "priority %d", &p.priority))
286 else if (unformat (line_input, "protocol %u", &tmp))
287 p.protocol = (u8) tmp;
290 (line_input, "action %U", unformat_ipsec_policy_action,
293 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
295 error = clib_error_return (0, "unsupported action: 'resolve'");
299 else if (unformat (line_input, "sa %u", &p.sa_id))
301 else if (unformat (line_input, "local-ip-range %U - %U",
302 unformat_ip4_address, &p.laddr.start.ip4,
303 unformat_ip4_address, &p.laddr.stop.ip4))
305 else if (unformat (line_input, "remote-ip-range %U - %U",
306 unformat_ip4_address, &p.raddr.start.ip4,
307 unformat_ip4_address, &p.raddr.stop.ip4))
309 else if (unformat (line_input, "local-ip-range %U - %U",
310 unformat_ip6_address, &p.laddr.start.ip6,
311 unformat_ip6_address, &p.laddr.stop.ip6))
316 else if (unformat (line_input, "remote-ip-range %U - %U",
317 unformat_ip6_address, &p.raddr.start.ip6,
318 unformat_ip6_address, &p.raddr.stop.ip6))
323 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
329 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
336 error = clib_error_return (0, "parse error: '%U'",
337 format_unformat_error, line_input);
342 ipsec_add_del_policy (vm, &p, is_add);
346 ipsec_add_del_policy (vm, &p, is_add);
350 unformat_free (line_input);
356 VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
357 .path = "ipsec policy",
359 "ipsec policy [add|del] spd <id> priority <n> ",
360 .function = ipsec_policy_add_del_command_fn,
364 static clib_error_t *
365 set_ipsec_sa_key_command_fn (vlib_main_t * vm,
366 unformat_input_t * input,
367 vlib_cli_command_t * cmd)
369 unformat_input_t _line_input, *line_input = &_line_input;
372 clib_error_t *error = NULL;
374 memset (&sa, 0, sizeof (sa));
376 if (!unformat_user (input, unformat_line_input, line_input))
379 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
381 if (unformat (line_input, "%u", &sa.id))
384 if (unformat (line_input, "crypto-key %U", unformat_hex_string, &ck))
385 sa.crypto_key_len = vec_len (ck);
387 if (unformat (line_input, "integ-key %U", unformat_hex_string, &ik))
388 sa.integ_key_len = vec_len (ik);
391 error = clib_error_return (0, "parse error: '%U'",
392 format_unformat_error, line_input);
397 if (sa.crypto_key_len > sizeof (sa.crypto_key))
398 sa.crypto_key_len = sizeof (sa.crypto_key);
400 if (sa.integ_key_len > sizeof (sa.integ_key))
401 sa.integ_key_len = sizeof (sa.integ_key);
404 strncpy ((char *) sa.crypto_key, (char *) ck, sa.crypto_key_len);
407 strncpy ((char *) sa.integ_key, (char *) ik, sa.integ_key_len);
409 ipsec_set_sa_key (vm, &sa);
412 unformat_free (line_input);
418 VLIB_CLI_COMMAND (set_ipsec_sa_key_command, static) = {
419 .path = "set ipsec sa",
421 "set ipsec sa <id> crypto-key <key> integ-key <key>",
422 .function = set_ipsec_sa_key_command_fn,
426 static clib_error_t *
427 show_ipsec_command_fn (vlib_main_t * vm,
428 unformat_input_t * input, vlib_cli_command_t * cmd)
433 ipsec_main_t *im = &ipsec_main;
435 ipsec_tunnel_if_t *t;
436 vnet_hw_interface_t *hi;
439 pool_foreach (sa, im->sad, ({
441 vlib_cli_output(vm, "sa %u spi %u mode %s protocol %s", sa->id, sa->spi,
442 sa->is_tunnel ? "tunnel" : "transport",
443 sa->protocol ? "esp" : "ah");
444 if (sa->protocol == IPSEC_PROTOCOL_ESP) {
445 vlib_cli_output(vm, " crypto alg %U%s%U integrity alg %U%s%U",
446 format_ipsec_crypto_alg, sa->crypto_alg,
447 sa->crypto_alg ? " key " : "",
448 format_hex_bytes, sa->crypto_key, sa->crypto_key_len,
449 format_ipsec_integ_alg, sa->integ_alg,
450 sa->integ_alg ? " key " : "",
451 format_hex_bytes, sa->integ_key, sa->integ_key_len);
453 if (sa->is_tunnel && sa->is_tunnel_ip6) {
454 vlib_cli_output(vm, " tunnel src %U dst %U",
455 format_ip6_address, &sa->tunnel_src_addr.ip6,
456 format_ip6_address, &sa->tunnel_dst_addr.ip6);
457 } else if (sa->is_tunnel) {
458 vlib_cli_output(vm, " tunnel src %U dst %U",
459 format_ip4_address, &sa->tunnel_src_addr.ip4,
460 format_ip4_address, &sa->tunnel_dst_addr.ip4);
467 pool_foreach (spd, im->spds, ({
468 vlib_cli_output(vm, "spd %u", spd->id);
470 vlib_cli_output(vm, " outbound policies");
471 vec_foreach(i, spd->ipv4_outbound_policies)
473 p = pool_elt_at_index(spd->policies, *i);
474 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
476 format_ipsec_policy_action, p->policy,
478 format(0, "%U", format_ip_protocol, p->protocol) :
480 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
481 format(0, " sa %u", p->sa_id) :
483 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
484 format_ip4_address, &p->laddr.start.ip4,
485 format_ip4_address, &p->laddr.stop.ip4,
486 p->lport.start, p->lport.stop);
487 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
488 format_ip4_address, &p->raddr.start.ip4,
489 format_ip4_address, &p->raddr.stop.ip4,
490 p->rport.start, p->rport.stop);
491 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
494 vec_foreach(i, spd->ipv6_outbound_policies)
496 p = pool_elt_at_index(spd->policies, *i);
497 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
499 format_ipsec_policy_action, p->policy,
501 format(0, "%U", format_ip_protocol, p->protocol) :
503 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
504 format(0, " sa %u", p->sa_id) :
506 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
507 format_ip6_address, &p->laddr.start.ip6,
508 format_ip6_address, &p->laddr.stop.ip6,
509 p->lport.start, p->lport.stop);
510 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
511 format_ip6_address, &p->raddr.start.ip6,
512 format_ip6_address, &p->raddr.stop.ip6,
513 p->rport.start, p->rport.stop);
514 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
517 vlib_cli_output(vm, " inbound policies");
518 vec_foreach(i, spd->ipv4_inbound_protect_policy_indices)
520 p = pool_elt_at_index(spd->policies, *i);
521 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
523 format_ipsec_policy_action, p->policy,
525 format(0, "%U", format_ip_protocol, p->protocol) :
527 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
528 format(0, " sa %u", p->sa_id) :
530 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
531 format_ip4_address, &p->laddr.start.ip4,
532 format_ip4_address, &p->laddr.stop.ip4,
533 p->lport.start, p->lport.stop);
534 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
535 format_ip4_address, &p->raddr.start.ip4,
536 format_ip4_address, &p->raddr.stop.ip4,
537 p->rport.start, p->rport.stop);
538 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
541 vec_foreach(i, spd->ipv4_inbound_policy_discard_and_bypass_indices)
543 p = pool_elt_at_index(spd->policies, *i);
544 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
546 format_ipsec_policy_action, p->policy,
548 format(0, "%U", format_ip_protocol, p->protocol) :
550 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
551 format(0, " sa %u", p->sa_id) :
553 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
554 format_ip4_address, &p->laddr.start.ip4,
555 format_ip4_address, &p->laddr.stop.ip4,
556 p->lport.start, p->lport.stop);
557 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
558 format_ip4_address, &p->raddr.start.ip4,
559 format_ip4_address, &p->raddr.stop.ip4,
560 p->rport.start, p->rport.stop);
561 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
564 vec_foreach(i, spd->ipv6_inbound_protect_policy_indices)
566 p = pool_elt_at_index(spd->policies, *i);
567 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
569 format_ipsec_policy_action, p->policy,
571 format(0, "%U", format_ip_protocol, p->protocol) :
573 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
574 format(0, " sa %u", p->sa_id) :
576 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
577 format_ip6_address, &p->laddr.start.ip6,
578 format_ip6_address, &p->laddr.stop.ip6,
579 p->lport.start, p->lport.stop);
580 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
581 format_ip6_address, &p->raddr.start.ip6,
582 format_ip6_address, &p->raddr.stop.ip6,
583 p->rport.start, p->rport.stop);
584 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
587 vec_foreach(i, spd->ipv6_inbound_policy_discard_and_bypass_indices)
589 p = pool_elt_at_index(spd->policies, *i);
590 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
592 format_ipsec_policy_action, p->policy,
594 format(0, "%U", format_ip_protocol, p->protocol) :
596 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
597 format(0, " sa %u", p->sa_id) :
599 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
600 format_ip6_address, &p->laddr.start.ip6,
601 format_ip6_address, &p->laddr.stop.ip6,
602 p->lport.start, p->lport.stop);
603 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
604 format_ip6_address, &p->raddr.start.ip6,
605 format_ip6_address, &p->raddr.stop.ip6,
606 p->rport.start, p->rport.stop);
607 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
613 vlib_cli_output (vm, "tunnel interfaces");
615 pool_foreach (t, im->tunnel_interfaces, ({
616 if (t->hw_if_index == ~0)
618 hi = vnet_get_hw_interface (im->vnet_main, t->hw_if_index);
619 vlib_cli_output(vm, " %s seq", hi->name);
620 sa = pool_elt_at_index(im->sad, t->output_sa_index);
621 vlib_cli_output(vm, " seq %u seq-hi %u esn %u anti-replay %u",
622 sa->seq, sa->seq_hi, sa->use_esn, sa->use_anti_replay);
623 vlib_cli_output(vm, " local-spi %u local-ip %U", sa->spi,
624 format_ip4_address, &sa->tunnel_src_addr.ip4);
625 vlib_cli_output(vm, " local-crypto %U %U",
626 format_ipsec_crypto_alg, sa->crypto_alg,
627 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
628 vlib_cli_output(vm, " local-integrity %U %U",
629 format_ipsec_integ_alg, sa->integ_alg,
630 format_hex_bytes, sa->integ_key, sa->integ_key_len);
631 sa = pool_elt_at_index(im->sad, t->input_sa_index);
632 vlib_cli_output(vm, " last-seq %u last-seq-hi %u esn %u anti-replay %u window %U",
633 sa->last_seq, sa->last_seq_hi, sa->use_esn,
635 format_ipsec_replay_window, sa->replay_window);
636 vlib_cli_output(vm, " remote-spi %u remote-ip %U", sa->spi,
637 format_ip4_address, &sa->tunnel_src_addr.ip4);
638 vlib_cli_output(vm, " remote-crypto %U %U",
639 format_ipsec_crypto_alg, sa->crypto_alg,
640 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
641 vlib_cli_output(vm, " remote-integrity %U %U",
642 format_ipsec_integ_alg, sa->integ_alg,
643 format_hex_bytes, sa->integ_key, sa->integ_key_len);
650 VLIB_CLI_COMMAND (show_ipsec_command, static) = {
651 .path = "show ipsec",
652 .short_help = "show ipsec",
653 .function = show_ipsec_command_fn,
657 static clib_error_t *
658 clear_ipsec_counters_command_fn (vlib_main_t * vm,
659 unformat_input_t * input,
660 vlib_cli_command_t * cmd)
662 ipsec_main_t *im = &ipsec_main;
667 pool_foreach (spd, im->spds, ({
668 pool_foreach(p, spd->policies, ({
669 p->counter.packets = p->counter.bytes = 0;
678 VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
679 .path = "clear ipsec counters",
680 .short_help = "clear ipsec counters",
681 .function = clear_ipsec_counters_command_fn,
685 static clib_error_t *
686 create_ipsec_tunnel_command_fn (vlib_main_t * vm,
687 unformat_input_t * input,
688 vlib_cli_command_t * cmd)
690 unformat_input_t _line_input, *line_input = &_line_input;
691 ipsec_add_del_tunnel_args_t a;
694 clib_error_t *error = NULL;
696 memset (&a, 0, sizeof (a));
699 /* Get a line of input. */
700 if (!unformat_user (input, unformat_line_input, line_input))
703 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
706 (line_input, "local-ip %U", unformat_ip4_address, &a.local_ip))
710 (line_input, "remote-ip %U", unformat_ip4_address, &a.remote_ip))
712 else if (unformat (line_input, "local-spi %u", &a.local_spi))
714 else if (unformat (line_input, "remote-spi %u", &a.remote_spi))
716 else if (unformat (line_input, "del"))
720 error = clib_error_return (0, "unknown input `%U'",
721 format_unformat_error, line_input);
728 error = clib_error_return (0, "mandatory argument(s) missing");
732 rv = ipsec_add_del_tunnel_if (&a);
738 case VNET_API_ERROR_INVALID_VALUE:
740 error = clib_error_return (0,
741 "IPSec tunnel interface already exists...");
743 error = clib_error_return (0, "IPSec tunnel interface not exists...");
746 error = clib_error_return (0, "ipsec_register_interface returned %d",
752 unformat_free (line_input);
758 VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = {
759 .path = "create ipsec tunnel",
760 .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> remote-ip <addr> remote-spi <spi>",
761 .function = create_ipsec_tunnel_command_fn,
765 static clib_error_t *
766 set_interface_key_command_fn (vlib_main_t * vm,
767 unformat_input_t * input,
768 vlib_cli_command_t * cmd)
770 unformat_input_t _line_input, *line_input = &_line_input;
771 ipsec_main_t *im = &ipsec_main;
772 ipsec_if_set_key_type_t type = IPSEC_IF_SET_KEY_TYPE_NONE;
773 u32 hw_if_index = (u32) ~ 0;
776 clib_error_t *error = NULL;
778 if (!unformat_user (input, unformat_line_input, line_input))
781 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
783 if (unformat (line_input, "%U",
784 unformat_vnet_hw_interface, im->vnet_main, &hw_if_index))
788 (line_input, "local crypto %U", unformat_ipsec_crypto_alg, &alg))
789 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO;
792 (line_input, "remote crypto %U", unformat_ipsec_crypto_alg, &alg))
793 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO;
796 (line_input, "local integ %U", unformat_ipsec_integ_alg, &alg))
797 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG;
800 (line_input, "remote integ %U", unformat_ipsec_integ_alg, &alg))
801 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG;
802 else if (unformat (line_input, "%U", unformat_hex_string, &key))
806 error = clib_error_return (0, "parse error: '%U'",
807 format_unformat_error, line_input);
812 if (type == IPSEC_IF_SET_KEY_TYPE_NONE)
814 error = clib_error_return (0, "unknown key type");
818 if (alg > 0 && vec_len (key) == 0)
820 error = clib_error_return (0, "key is not specified");
824 if (hw_if_index == (u32) ~ 0)
826 error = clib_error_return (0, "interface not specified");
830 ipsec_set_interface_key (im->vnet_main, hw_if_index, type, alg, key);
834 unformat_free (line_input);
840 VLIB_CLI_COMMAND (set_interface_key_command, static) = {
841 .path = "set interface ipsec key",
843 "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>",
844 .function = set_interface_key_command_fn,
849 ipsec_cli_init (vlib_main_t * vm)
854 VLIB_INIT_FUNCTION (ipsec_cli_init);
858 * fd.io coding-style-patch-verification: ON
861 * eval: (c-set-style "gnu")