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;
102 if (unformat (line_input, "crypto-key %U", unformat_hex_string, &ck))
103 sa.crypto_key_len = vec_len (ck);
106 (line_input, "crypto-alg %U", unformat_ipsec_crypto_alg,
109 if (sa.crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
110 sa.crypto_alg >= IPSEC_CRYPTO_N_ALG)
112 error = clib_error_return (0, "unsupported crypto-alg: '%U'",
113 format_ipsec_crypto_alg,
119 if (unformat (line_input, "integ-key %U", unformat_hex_string, &ik))
120 sa.integ_key_len = vec_len (ik);
121 else if (unformat (line_input, "integ-alg %U", unformat_ipsec_integ_alg,
124 if (sa.integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
125 sa.integ_alg >= IPSEC_INTEG_N_ALG)
127 error = clib_error_return (0, "unsupported integ-alg: '%U'",
128 format_ipsec_integ_alg,
133 else if (unformat (line_input, "tunnel-src %U",
134 unformat_ip4_address, &sa.tunnel_src_addr.ip4))
136 else if (unformat (line_input, "tunnel-dst %U",
137 unformat_ip4_address, &sa.tunnel_dst_addr.ip4))
139 else if (unformat (line_input, "tunnel-src %U",
140 unformat_ip6_address, &sa.tunnel_src_addr.ip6))
143 sa.is_tunnel_ip6 = 1;
145 else if (unformat (line_input, "tunnel-dst %U",
146 unformat_ip6_address, &sa.tunnel_dst_addr.ip6))
149 sa.is_tunnel_ip6 = 1;
153 error = clib_error_return (0, "parse error: '%U'",
154 format_unformat_error, line_input);
159 if (sa.crypto_key_len > sizeof (sa.crypto_key))
160 sa.crypto_key_len = sizeof (sa.crypto_key);
162 if (sa.integ_key_len > sizeof (sa.integ_key))
163 sa.integ_key_len = sizeof (sa.integ_key);
166 strncpy ((char *) sa.crypto_key, (char *) ck, sa.crypto_key_len);
169 strncpy ((char *) sa.integ_key, (char *) ik, sa.integ_key_len);
173 ASSERT (im->cb.check_support_cb);
174 error = im->cb.check_support_cb (&sa);
179 ipsec_add_del_sa (vm, &sa, is_add);
182 unformat_free (line_input);
188 VLIB_CLI_COMMAND (ipsec_sa_add_del_command, static) = {
191 "ipsec sa [add|del]",
192 .function = ipsec_sa_add_del_command_fn,
196 static clib_error_t *
197 ipsec_spd_add_del_command_fn (vlib_main_t * vm,
198 unformat_input_t * input,
199 vlib_cli_command_t * cmd)
201 unformat_input_t _line_input, *line_input = &_line_input;
204 clib_error_t *error = NULL;
206 if (!unformat_user (input, unformat_line_input, line_input))
209 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
211 if (unformat (line_input, "add"))
213 else if (unformat (line_input, "del"))
215 else if (unformat (line_input, "%u", &spd_id))
219 error = clib_error_return (0, "parse error: '%U'",
220 format_unformat_error, line_input);
227 error = clib_error_return (0, "please specify SPD ID");
231 ipsec_add_del_spd (vm, spd_id, is_add);
234 unformat_free (line_input);
240 VLIB_CLI_COMMAND (ipsec_spd_add_del_command, static) = {
243 "ipsec spd [add|del] <id>",
244 .function = ipsec_spd_add_del_command_fn,
249 static clib_error_t *
250 ipsec_policy_add_del_command_fn (vlib_main_t * vm,
251 unformat_input_t * input,
252 vlib_cli_command_t * cmd)
254 unformat_input_t _line_input, *line_input = &_line_input;
259 clib_error_t *error = NULL;
261 memset (&p, 0, sizeof (p));
262 p.lport.stop = p.rport.stop = ~0;
263 p.laddr.stop.ip4.as_u32 = p.raddr.stop.ip4.as_u32 = (u32) ~ 0;
264 p.laddr.stop.ip6.as_u64[0] = p.laddr.stop.ip6.as_u64[1] = (u64) ~ 0;
265 p.raddr.stop.ip6.as_u64[0] = p.raddr.stop.ip6.as_u64[1] = (u64) ~ 0;
267 if (!unformat_user (input, unformat_line_input, line_input))
270 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
272 if (unformat (line_input, "add"))
274 else if (unformat (line_input, "del"))
276 else if (unformat (line_input, "spd %u", &p.id))
278 else if (unformat (line_input, "inbound"))
280 else if (unformat (line_input, "outbound"))
282 else if (unformat (line_input, "priority %d", &p.priority))
284 else if (unformat (line_input, "protocol %u", &tmp))
285 p.protocol = (u8) tmp;
288 (line_input, "action %U", unformat_ipsec_policy_action,
291 if (p.policy == IPSEC_POLICY_ACTION_RESOLVE)
293 error = clib_error_return (0, "unsupported action: 'resolve'");
297 else if (unformat (line_input, "sa %u", &p.sa_id))
299 else if (unformat (line_input, "local-ip-range %U - %U",
300 unformat_ip4_address, &p.laddr.start.ip4,
301 unformat_ip4_address, &p.laddr.stop.ip4))
303 else if (unformat (line_input, "remote-ip-range %U - %U",
304 unformat_ip4_address, &p.raddr.start.ip4,
305 unformat_ip4_address, &p.raddr.stop.ip4))
307 else if (unformat (line_input, "local-ip-range %U - %U",
308 unformat_ip6_address, &p.laddr.start.ip6,
309 unformat_ip6_address, &p.laddr.stop.ip6))
314 else if (unformat (line_input, "remote-ip-range %U - %U",
315 unformat_ip6_address, &p.raddr.start.ip6,
316 unformat_ip6_address, &p.raddr.stop.ip6))
321 else if (unformat (line_input, "local-port-range %u - %u", &tmp, &tmp2))
327 if (unformat (line_input, "remote-port-range %u - %u", &tmp, &tmp2))
334 error = clib_error_return (0, "parse error: '%U'",
335 format_unformat_error, line_input);
340 /* Check if SA is for IPv6/AH which is not supported. Return error if TRUE. */
344 ipsec_main_t *im = &ipsec_main;
346 p1 = hash_get (im->sa_index_by_sa_id, p.sa_id);
347 sa = pool_elt_at_index (im->sad, p1[0]);
348 if (sa && sa->protocol == IPSEC_PROTOCOL_AH && is_add && p.is_ipv6)
350 error = clib_error_return (0, "AH not supported for IPV6: '%U'",
351 format_unformat_error, line_input);
355 ipsec_add_del_policy (vm, &p, is_add);
359 ipsec_add_del_policy (vm, &p, is_add);
363 unformat_free (line_input);
369 VLIB_CLI_COMMAND (ipsec_policy_add_del_command, static) = {
370 .path = "ipsec policy",
372 "ipsec policy [add|del] spd <id> priority <n> ",
373 .function = ipsec_policy_add_del_command_fn,
377 static clib_error_t *
378 set_ipsec_sa_key_command_fn (vlib_main_t * vm,
379 unformat_input_t * input,
380 vlib_cli_command_t * cmd)
382 unformat_input_t _line_input, *line_input = &_line_input;
385 clib_error_t *error = NULL;
387 memset (&sa, 0, sizeof (sa));
389 if (!unformat_user (input, unformat_line_input, line_input))
392 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
394 if (unformat (line_input, "%u", &sa.id))
397 if (unformat (line_input, "crypto-key %U", unformat_hex_string, &ck))
398 sa.crypto_key_len = vec_len (ck);
400 if (unformat (line_input, "integ-key %U", unformat_hex_string, &ik))
401 sa.integ_key_len = vec_len (ik);
404 error = clib_error_return (0, "parse error: '%U'",
405 format_unformat_error, line_input);
410 if (sa.crypto_key_len > sizeof (sa.crypto_key))
411 sa.crypto_key_len = sizeof (sa.crypto_key);
413 if (sa.integ_key_len > sizeof (sa.integ_key))
414 sa.integ_key_len = sizeof (sa.integ_key);
417 strncpy ((char *) sa.crypto_key, (char *) ck, sa.crypto_key_len);
420 strncpy ((char *) sa.integ_key, (char *) ik, sa.integ_key_len);
422 ipsec_set_sa_key (vm, &sa);
425 unformat_free (line_input);
431 VLIB_CLI_COMMAND (set_ipsec_sa_key_command, static) = {
432 .path = "set ipsec sa",
434 "set ipsec sa <id> crypto-key <key> integ-key <key>",
435 .function = set_ipsec_sa_key_command_fn,
439 static clib_error_t *
440 show_ipsec_command_fn (vlib_main_t * vm,
441 unformat_input_t * input, vlib_cli_command_t * cmd)
446 ipsec_main_t *im = &ipsec_main;
448 ipsec_tunnel_if_t *t;
449 vnet_hw_interface_t *hi;
452 pool_foreach (sa, im->sad, ({
454 vlib_cli_output(vm, "sa %u spi %u mode %s protocol %s", sa->id, sa->spi,
455 sa->is_tunnel ? "tunnel" : "transport",
456 sa->protocol ? "esp" : "ah");
457 if (sa->protocol == IPSEC_PROTOCOL_ESP) {
458 vlib_cli_output(vm, " crypto alg %U%s%U integrity alg %U%s%U",
459 format_ipsec_crypto_alg, sa->crypto_alg,
460 sa->crypto_alg ? " key " : "",
461 format_hex_bytes, sa->crypto_key, sa->crypto_key_len,
462 format_ipsec_integ_alg, sa->integ_alg,
463 sa->integ_alg ? " key " : "",
464 format_hex_bytes, sa->integ_key, sa->integ_key_len);
466 if (sa->is_tunnel && sa->is_tunnel_ip6) {
467 vlib_cli_output(vm, " tunnel src %U dst %U",
468 format_ip6_address, &sa->tunnel_src_addr.ip6,
469 format_ip6_address, &sa->tunnel_dst_addr.ip6);
470 } else if (sa->is_tunnel) {
471 vlib_cli_output(vm, " tunnel src %U dst %U",
472 format_ip4_address, &sa->tunnel_src_addr.ip4,
473 format_ip4_address, &sa->tunnel_dst_addr.ip4);
480 pool_foreach (spd, im->spds, ({
481 vlib_cli_output(vm, "spd %u", spd->id);
483 vlib_cli_output(vm, " outbound policies");
484 vec_foreach(i, spd->ipv4_outbound_policies)
486 p = pool_elt_at_index(spd->policies, *i);
487 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
489 format_ipsec_policy_action, p->policy,
491 format(0, "%U", format_ip_protocol, p->protocol) :
493 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
494 format(0, " sa %u", p->sa_id) :
496 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
497 format_ip4_address, &p->laddr.start.ip4,
498 format_ip4_address, &p->laddr.stop.ip4,
499 p->lport.start, p->lport.stop);
500 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
501 format_ip4_address, &p->raddr.start.ip4,
502 format_ip4_address, &p->raddr.stop.ip4,
503 p->rport.start, p->rport.stop);
504 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
507 vec_foreach(i, spd->ipv6_outbound_policies)
509 p = pool_elt_at_index(spd->policies, *i);
510 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
512 format_ipsec_policy_action, p->policy,
514 format(0, "%U", format_ip_protocol, p->protocol) :
516 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
517 format(0, " sa %u", p->sa_id) :
519 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
520 format_ip6_address, &p->laddr.start.ip6,
521 format_ip6_address, &p->laddr.stop.ip6,
522 p->lport.start, p->lport.stop);
523 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
524 format_ip6_address, &p->raddr.start.ip6,
525 format_ip6_address, &p->raddr.stop.ip6,
526 p->rport.start, p->rport.stop);
527 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
530 vlib_cli_output(vm, " inbound policies");
531 vec_foreach(i, spd->ipv4_inbound_protect_policy_indices)
533 p = pool_elt_at_index(spd->policies, *i);
534 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
536 format_ipsec_policy_action, p->policy,
538 format(0, "%U", format_ip_protocol, p->protocol) :
540 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
541 format(0, " sa %u", p->sa_id) :
543 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
544 format_ip4_address, &p->laddr.start.ip4,
545 format_ip4_address, &p->laddr.stop.ip4,
546 p->lport.start, p->lport.stop);
547 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
548 format_ip4_address, &p->raddr.start.ip4,
549 format_ip4_address, &p->raddr.stop.ip4,
550 p->rport.start, p->rport.stop);
551 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
554 vec_foreach(i, spd->ipv4_inbound_policy_discard_and_bypass_indices)
556 p = pool_elt_at_index(spd->policies, *i);
557 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
559 format_ipsec_policy_action, p->policy,
561 format(0, "%U", format_ip_protocol, p->protocol) :
563 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
564 format(0, " sa %u", p->sa_id) :
566 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
567 format_ip4_address, &p->laddr.start.ip4,
568 format_ip4_address, &p->laddr.stop.ip4,
569 p->lport.start, p->lport.stop);
570 vlib_cli_output(vm, " remte addr range %U - %U port range %u - %u",
571 format_ip4_address, &p->raddr.start.ip4,
572 format_ip4_address, &p->raddr.stop.ip4,
573 p->rport.start, p->rport.stop);
574 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
577 vec_foreach(i, spd->ipv6_inbound_protect_policy_indices)
579 p = pool_elt_at_index(spd->policies, *i);
580 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
582 format_ipsec_policy_action, p->policy,
584 format(0, "%U", format_ip_protocol, p->protocol) :
586 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
587 format(0, " sa %u", p->sa_id) :
589 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
590 format_ip6_address, &p->laddr.start.ip6,
591 format_ip6_address, &p->laddr.stop.ip6,
592 p->lport.start, p->lport.stop);
593 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
594 format_ip6_address, &p->raddr.start.ip6,
595 format_ip6_address, &p->raddr.stop.ip6,
596 p->rport.start, p->rport.stop);
597 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
600 vec_foreach(i, spd->ipv6_inbound_policy_discard_and_bypass_indices)
602 p = pool_elt_at_index(spd->policies, *i);
603 vlib_cli_output(vm, " priority %d action %U protocol %s%s",
605 format_ipsec_policy_action, p->policy,
607 format(0, "%U", format_ip_protocol, p->protocol) :
609 p->policy == IPSEC_POLICY_ACTION_PROTECT ?
610 format(0, " sa %u", p->sa_id) :
612 vlib_cli_output(vm, " local addr range %U - %U port range %u - %u",
613 format_ip6_address, &p->laddr.start.ip6,
614 format_ip6_address, &p->laddr.stop.ip6,
615 p->lport.start, p->lport.stop);
616 vlib_cli_output(vm, " remote addr range %U - %U port range %u - %u",
617 format_ip6_address, &p->raddr.start.ip6,
618 format_ip6_address, &p->raddr.stop.ip6,
619 p->rport.start, p->rport.stop);
620 vlib_cli_output(vm, " packets %u bytes %u", p->counter.packets,
626 vlib_cli_output (vm, "tunnel interfaces");
628 pool_foreach (t, im->tunnel_interfaces, ({
629 if (t->hw_if_index == ~0)
631 hi = vnet_get_hw_interface (im->vnet_main, t->hw_if_index);
632 vlib_cli_output(vm, " %s seq", hi->name);
633 sa = pool_elt_at_index(im->sad, t->output_sa_index);
634 vlib_cli_output(vm, " seq %u seq-hi %u esn %u anti-replay %u",
635 sa->seq, sa->seq_hi, sa->use_esn, sa->use_anti_replay);
636 vlib_cli_output(vm, " local-spi %u local-ip %U", sa->spi,
637 format_ip4_address, &sa->tunnel_src_addr.ip4);
638 vlib_cli_output(vm, " local-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, " local-integrity %U %U",
642 format_ipsec_integ_alg, sa->integ_alg,
643 format_hex_bytes, sa->integ_key, sa->integ_key_len);
644 sa = pool_elt_at_index(im->sad, t->input_sa_index);
645 vlib_cli_output(vm, " last-seq %u last-seq-hi %u esn %u anti-replay %u window %U",
646 sa->last_seq, sa->last_seq_hi, sa->use_esn,
648 format_ipsec_replay_window, sa->replay_window);
649 vlib_cli_output(vm, " remote-spi %u remote-ip %U", sa->spi,
650 format_ip4_address, &sa->tunnel_src_addr.ip4);
651 vlib_cli_output(vm, " remote-crypto %U %U",
652 format_ipsec_crypto_alg, sa->crypto_alg,
653 format_hex_bytes, sa->crypto_key, sa->crypto_key_len);
654 vlib_cli_output(vm, " remote-integrity %U %U",
655 format_ipsec_integ_alg, sa->integ_alg,
656 format_hex_bytes, sa->integ_key, sa->integ_key_len);
663 VLIB_CLI_COMMAND (show_ipsec_command, static) = {
664 .path = "show ipsec",
665 .short_help = "show ipsec",
666 .function = show_ipsec_command_fn,
670 static clib_error_t *
671 clear_ipsec_counters_command_fn (vlib_main_t * vm,
672 unformat_input_t * input,
673 vlib_cli_command_t * cmd)
675 ipsec_main_t *im = &ipsec_main;
680 pool_foreach (spd, im->spds, ({
681 pool_foreach(p, spd->policies, ({
682 p->counter.packets = p->counter.bytes = 0;
691 VLIB_CLI_COMMAND (clear_ipsec_counters_command, static) = {
692 .path = "clear ipsec counters",
693 .short_help = "clear ipsec counters",
694 .function = clear_ipsec_counters_command_fn,
698 static clib_error_t *
699 create_ipsec_tunnel_command_fn (vlib_main_t * vm,
700 unformat_input_t * input,
701 vlib_cli_command_t * cmd)
703 unformat_input_t _line_input, *line_input = &_line_input;
704 ipsec_add_del_tunnel_args_t a;
707 clib_error_t *error = NULL;
709 memset (&a, 0, sizeof (a));
712 /* Get a line of input. */
713 if (!unformat_user (input, unformat_line_input, line_input))
716 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
719 (line_input, "local-ip %U", unformat_ip4_address, &a.local_ip))
723 (line_input, "remote-ip %U", unformat_ip4_address, &a.remote_ip))
725 else if (unformat (line_input, "local-spi %u", &a.local_spi))
727 else if (unformat (line_input, "remote-spi %u", &a.remote_spi))
729 else if (unformat (line_input, "del"))
733 error = clib_error_return (0, "unknown input `%U'",
734 format_unformat_error, line_input);
741 error = clib_error_return (0, "mandatory argument(s) missing");
745 rv = ipsec_add_del_tunnel_if (&a);
751 case VNET_API_ERROR_INVALID_VALUE:
753 error = clib_error_return (0,
754 "IPSec tunnel interface already exists...");
756 error = clib_error_return (0, "IPSec tunnel interface not exists...");
759 error = clib_error_return (0, "ipsec_register_interface returned %d",
765 unformat_free (line_input);
771 VLIB_CLI_COMMAND (create_ipsec_tunnel_command, static) = {
772 .path = "create ipsec tunnel",
773 .short_help = "create ipsec tunnel local-ip <addr> local-spi <spi> remote-ip <addr> remote-spi <spi>",
774 .function = create_ipsec_tunnel_command_fn,
778 static clib_error_t *
779 set_interface_key_command_fn (vlib_main_t * vm,
780 unformat_input_t * input,
781 vlib_cli_command_t * cmd)
783 unformat_input_t _line_input, *line_input = &_line_input;
784 ipsec_main_t *im = &ipsec_main;
785 ipsec_if_set_key_type_t type = IPSEC_IF_SET_KEY_TYPE_NONE;
786 u32 hw_if_index = (u32) ~ 0;
789 clib_error_t *error = NULL;
791 if (!unformat_user (input, unformat_line_input, line_input))
794 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
796 if (unformat (line_input, "%U",
797 unformat_vnet_hw_interface, im->vnet_main, &hw_if_index))
801 (line_input, "local crypto %U", unformat_ipsec_crypto_alg, &alg))
802 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO;
805 (line_input, "remote crypto %U", unformat_ipsec_crypto_alg, &alg))
806 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO;
809 (line_input, "local integ %U", unformat_ipsec_integ_alg, &alg))
810 type = IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG;
813 (line_input, "remote integ %U", unformat_ipsec_integ_alg, &alg))
814 type = IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG;
815 else if (unformat (line_input, "%U", unformat_hex_string, &key))
819 error = clib_error_return (0, "parse error: '%U'",
820 format_unformat_error, line_input);
825 if (type == IPSEC_IF_SET_KEY_TYPE_NONE)
827 error = clib_error_return (0, "unknown key type");
831 if (alg > 0 && vec_len (key) == 0)
833 error = clib_error_return (0, "key is not specified");
837 if (hw_if_index == (u32) ~ 0)
839 error = clib_error_return (0, "interface not specified");
843 ipsec_set_interface_key (im->vnet_main, hw_if_index, type, alg, key);
847 unformat_free (line_input);
853 VLIB_CLI_COMMAND (set_interface_key_command, static) = {
854 .path = "set interface ipsec key",
856 "set interface ipsec key <int> <local|remote> <crypto|integ> <key type> <key>",
857 .function = set_interface_key_command_fn,
862 ipsec_cli_init (vlib_main_t * vm)
867 VLIB_INIT_FUNCTION (ipsec_cli_init);
871 * fd.io coding-style-patch-verification: ON
874 * eval: (c-set-style "gnu")