2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #include <vlib/vlib.h>
16 #include <vnet/vnet.h>
17 #include <vppinfra/error.h>
18 #include <vnet/ipsec/ipsec_sa.h>
19 #include <plugins/ikev2/ikev2.h>
20 #include <plugins/ikev2/ikev2_priv.h>
23 format_ikev2_id_type_and_data (u8 * s, va_list * args)
25 ikev2_id_t *id = va_arg (*args, ikev2_id_t *);
27 if (id->type == 0 || vec_len (id->data) == 0)
28 return format (s, "none");
30 s = format (s, "id-type %U data ", format_ikev2_id_type, id->type);
34 case IKEV2_ID_TYPE_ID_IPV4_ADDR:
35 s = format (s, "%U", format_ip4_address, id->data);
37 case IKEV2_ID_TYPE_ID_IPV6_ADDR:
38 s = format (s, "%U", format_ip6_address, id->data);
40 case IKEV2_ID_TYPE_ID_FQDN: /* fallthrough */
41 case IKEV2_ID_TYPE_ID_RFC822_ADDR:
42 s = format (s, "%v", id->data);
45 s = format (s, "0x%U", format_hex_bytes, &id->data,
46 (uword) (vec_len (id->data)));
54 format_ikev2_traffic_selector (u8 * s, va_list * va)
56 ikev2_ts_t *ts = va_arg (*va, ikev2_ts_t *);
57 u32 index = va_arg (*va, u32);
59 s = format (s, "%u type %u protocol_id %u addr "
60 "%U - %U port %u - %u\n",
61 index, ts->ts_type, ts->protocol_id,
62 format_ip_address, &ts->start_addr,
63 format_ip_address, &ts->end_addr,
64 clib_net_to_host_u16 (ts->start_port),
65 clib_net_to_host_u16 (ts->end_port));
70 format_ikev2_child_sa (u8 * s, va_list * va)
72 ikev2_child_sa_t *child = va_arg (*va, ikev2_child_sa_t *);
73 u32 index = va_arg (*va, u32);
75 ikev2_sa_transform_t *tr;
78 u32 indent = format_get_indent (s);
81 s = format (s, "child sa %u:", index);
83 tr = ikev2_sa_get_td_for_type (child->r_proposals,
84 IKEV2_TRANSFORM_TYPE_ENCR);
85 c = format (c, "%U ", format_ikev2_sa_transform, tr);
87 tr = ikev2_sa_get_td_for_type (child->r_proposals,
88 IKEV2_TRANSFORM_TYPE_INTEG);
89 c = format (c, "%U ", format_ikev2_sa_transform, tr);
91 tr = ikev2_sa_get_td_for_type (child->r_proposals,
92 IKEV2_TRANSFORM_TYPE_ESN);
93 c = format (c, "%U ", format_ikev2_sa_transform, tr);
95 s = format (s, "%v\n", c);
98 s = format (s, "%Uspi(i) %lx spi(r) %lx\n", format_white_space, indent,
99 child->i_proposals ? child->i_proposals[0].spi : 0,
100 child->r_proposals ? child->r_proposals[0].spi : 0);
102 s = format (s, "%USK_e i:%U\n%Ur:%U\n",
103 format_white_space, indent,
104 format_hex_bytes, child->sk_ei, vec_len (child->sk_ei),
105 format_white_space, indent + 6,
106 format_hex_bytes, child->sk_er, vec_len (child->sk_er));
109 s = format (s, "%USK_a i:%U\n%Ur:%U\n",
110 format_white_space, indent,
111 format_hex_bytes, child->sk_ai, vec_len (child->sk_ai),
112 format_white_space, indent + 6,
113 format_hex_bytes, child->sk_ar, vec_len (child->sk_ar));
115 s = format (s, "%Utraffic selectors (i):", format_white_space, indent);
116 vec_foreach (ts, child->tsi)
117 s = format (s, "%U", format_ikev2_traffic_selector, ts, ts - child->tsi);
118 s = format (s, "%Utraffic selectors (r):", format_white_space, indent);
119 vec_foreach (ts, child->tsr)
120 s = format (s, "%U", format_ikev2_traffic_selector, ts, ts - child->tsr);
125 format_ikev2_sa (u8 * s, va_list * va)
127 ikev2_sa_t *sa = va_arg (*va, ikev2_sa_t *);
128 int details = va_arg (*va, int);
129 ikev2_sa_transform_t *tr;
130 ikev2_child_sa_t *child;
133 s = format (s, "iip %U ispi %lx rip %U rspi %lx",
134 format_ip_address, &sa->iaddr, sa->ispi,
135 format_ip_address, &sa->raddr, sa->rspi);
139 s = format (s, "\n%U", format_white_space, indent);
141 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
142 s = format (s, "%U ", format_ikev2_sa_transform, tr);
144 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
145 s = format (s, "%U ", format_ikev2_sa_transform, tr);
147 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
148 s = format (s, "%U ", format_ikev2_sa_transform, tr);
150 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_DH);
151 s = format (s, "%U", format_ikev2_sa_transform, tr);
153 s = format (s, "\n%U", format_white_space, indent);
155 s = format (s, "nonce i:%U\n%Ur:%U\n",
156 format_hex_bytes, sa->i_nonce, vec_len (sa->i_nonce),
157 format_white_space, indent + 6,
158 format_hex_bytes, sa->r_nonce, vec_len (sa->r_nonce));
160 s = format (s, "%USK_d %U\n", format_white_space, indent,
161 format_hex_bytes, sa->sk_d, vec_len (sa->sk_d));
164 s = format (s, "%USK_a i:%U\n%Ur:%U\n",
165 format_white_space, indent,
166 format_hex_bytes, sa->sk_ai, vec_len (sa->sk_ai),
167 format_white_space, indent + 6,
168 format_hex_bytes, sa->sk_ar, vec_len (sa->sk_ar));
170 s = format (s, "%USK_e i:%U\n%Ur:%U\n",
171 format_white_space, indent,
172 format_hex_bytes, sa->sk_ei, vec_len (sa->sk_ei),
173 format_white_space, indent + 6,
174 format_hex_bytes, sa->sk_er, vec_len (sa->sk_er));
175 s = format (s, "%USK_p i:%U\n%Ur:%U\n",
176 format_white_space, indent,
177 format_hex_bytes, sa->sk_pi, vec_len (sa->sk_pi),
178 format_white_space, indent + 6,
179 format_hex_bytes, sa->sk_pr, vec_len (sa->sk_pr));
181 s = format (s, "%Uidentifier (i) %U\n",
182 format_white_space, indent,
183 format_ikev2_id_type_and_data, &sa->i_id);
184 s = format (s, "%Uidentifier (r) %U\n",
185 format_white_space, indent,
186 format_ikev2_id_type_and_data, &sa->r_id);
188 vec_foreach (child, sa->childs)
190 s = format (s, "%U%U", format_white_space, indent + 2,
191 format_ikev2_child_sa, child, child - sa->childs);
194 s = format (s, "Stats:\n");
195 s = format (s, " keepalives :%u\n", sa->stats.n_keepalives);
196 s = format (s, " rekey :%u\n", sa->stats.n_rekey_req);
197 s = format (s, " SA init :%u (retransmit: %u)\n", sa->stats.n_sa_init_req,
198 sa->stats.n_init_retransmit);
199 s = format (s, " retransmit: %u\n", sa->stats.n_retransmit);
200 s = format (s, " SA auth :%u\n", sa->stats.n_sa_auth_req);
205 static clib_error_t *
206 show_ikev2_sa_command_fn (vlib_main_t * vm,
207 unformat_input_t * input, vlib_cli_command_t * cmd)
209 unformat_input_t _line_input, *line_input = &_line_input;
210 ikev2_main_t *km = &ikev2_main;
211 ikev2_main_per_thread_data_t *tkm;
215 int details = 0, show_one = 0;
217 if (unformat_user (input, unformat_line_input, line_input))
219 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
221 if (unformat (line_input, "rspi %lx", &rspi))
225 else if (unformat (line_input, "details"))
230 unformat_free (line_input);
233 vec_foreach (tkm, km->per_thread_data)
236 pool_foreach (sa, tkm->sas) {
239 if (sa->rspi == rspi)
241 s = format (s, "%U\n", format_ikev2_sa, sa, 1);
246 s = format (s, "%U\n", format_ikev2_sa, sa, details);
251 vlib_cli_output (vm, "%v", s);
257 VLIB_CLI_COMMAND (show_ikev2_sa_command, static) = {
258 .path = "show ikev2 sa",
259 .short_help = "show ikev2 sa [rspi <rspi>] [details]",
260 .function = show_ikev2_sa_command_fn,
264 static clib_error_t *
265 ikev2_disable_dpd_command_fn (vlib_main_t * vm,
266 unformat_input_t * input,
267 vlib_cli_command_t * cmd)
269 ikev2_disable_dpd ();
274 VLIB_CLI_COMMAND (ikev2_cli_disable_dpd_command, static) = {
275 .path = "ikev2 dpd disable",
276 .short_help = "ikev2 dpd disable",
277 .function = ikev2_disable_dpd_command_fn,
282 unformat_ikev2_token (unformat_input_t * input, va_list * va)
284 u8 **string_return = va_arg (*va, u8 **);
285 const char *token_chars = "a-zA-Z0-9_";
288 /* if string_return was already allocated (eg. because of a previous
289 * partial match with a successful unformat_token()), we must free it
290 * before reusing the pointer, otherwise we'll be leaking memory
292 vec_free (*string_return);
295 return unformat_user (input, unformat_token, token_chars, string_return);
298 static clib_error_t *
299 ikev2_profile_add_del_command_fn (vlib_main_t * vm,
300 unformat_input_t * input,
301 vlib_cli_command_t * cmd)
303 vnet_main_t *vnm = vnet_get_main ();
304 unformat_input_t _line_input, *line_input = &_line_input;
309 u32 tmp1, tmp2, tmp3;
311 ip_address_t ip, end_addr;
312 u32 responder_sw_if_index = (u32) ~ 0;
313 u32 tun_sw_if_index = (u32) ~ 0;
314 ikev2_transform_encr_type_t crypto_alg;
315 ikev2_transform_integ_type_t integ_alg;
316 ikev2_transform_dh_type_t dh_type;
318 if (!unformat_user (input, unformat_line_input, line_input))
321 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
323 if (unformat (line_input, "add %U", unformat_ikev2_token, &name))
325 r = ikev2_add_del_profile (vm, name, 1);
328 else if (unformat (line_input, "del %U", unformat_ikev2_token, &name))
330 r = ikev2_add_del_profile (vm, name, 0);
333 else if (unformat (line_input, "set %U auth shared-key-mic string %v",
334 unformat_ikev2_token, &name, &data))
337 ikev2_set_profile_auth (vm, name,
338 IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
342 else if (unformat (line_input, "set %U auth shared-key-mic hex %U",
343 unformat_ikev2_token, &name,
344 unformat_hex_string, &data))
347 ikev2_set_profile_auth (vm, name,
348 IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
352 else if (unformat (line_input, "set %U auth rsa-sig cert-file %v",
353 unformat_ikev2_token, &name, &data))
356 ikev2_set_profile_auth (vm, name, IKEV2_AUTH_METHOD_RSA_SIG, data,
360 else if (unformat (line_input, "set %U id local %U %U",
361 unformat_ikev2_token, &name,
362 unformat_ikev2_id_type, &id_type,
363 unformat_ip_address, &ip))
365 data = vec_new (u8, ip_address_size (&ip));
366 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
368 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
371 else if (unformat (line_input, "set %U id local %U 0x%U",
372 unformat_ikev2_token, &name,
373 unformat_ikev2_id_type, &id_type,
374 unformat_hex_string, &data))
377 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
380 else if (unformat (line_input, "set %U id local %U %v",
381 unformat_ikev2_token, &name,
382 unformat_ikev2_id_type, &id_type, &data))
385 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
388 else if (unformat (line_input, "set %U id remote %U %U",
389 unformat_ikev2_token, &name,
390 unformat_ikev2_id_type, &id_type,
391 unformat_ip_address, &ip))
393 data = vec_new (u8, ip_address_size (&ip));
394 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
395 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
399 else if (unformat (line_input, "set %U id remote %U 0x%U",
400 unformat_ikev2_token, &name,
401 unformat_ikev2_id_type, &id_type,
402 unformat_hex_string, &data))
404 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
408 else if (unformat (line_input, "set %U id remote %U %v",
409 unformat_ikev2_token, &name,
410 unformat_ikev2_id_type, &id_type, &data))
412 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
416 else if (unformat (line_input, "set %U traffic-selector local "
417 "ip-range %U - %U port-range %u - %u protocol %u",
418 unformat_ikev2_token, &name,
419 unformat_ip_address, &ip,
420 unformat_ip_address, &end_addr, &tmp1, &tmp2, &tmp3))
423 ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
424 ip, end_addr, /*local */ 1);
427 else if (unformat (line_input, "set %U traffic-selector remote "
428 "ip-range %U - %U port-range %u - %u protocol %u",
429 unformat_ikev2_token, &name,
430 unformat_ip_address, &ip,
431 unformat_ip_address, &end_addr, &tmp1, &tmp2, &tmp3))
434 ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
435 ip, end_addr, /*remote */ 0);
438 else if (unformat (line_input, "set %U responder %U %U",
439 unformat_ikev2_token, &name,
440 unformat_vnet_sw_interface, vnm,
441 &responder_sw_if_index, unformat_ip_address, &ip))
444 ikev2_set_profile_responder (vm, name, responder_sw_if_index, ip);
447 else if (unformat (line_input, "set %U tunnel %U",
448 unformat_ikev2_token, &name,
449 unformat_vnet_sw_interface, vnm, &tun_sw_if_index))
451 r = ikev2_set_profile_tunnel_interface (vm, name, tun_sw_if_index);
457 "set %U ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
458 unformat_ikev2_token, &name,
459 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
460 unformat_ikev2_transform_integ_type, &integ_alg,
461 unformat_ikev2_transform_dh_type, &dh_type))
464 ikev2_set_profile_ike_transforms (vm, name, crypto_alg, integ_alg,
471 "set %U ike-crypto-alg %U %u ike-dh %U",
472 unformat_ikev2_token, &name,
473 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
474 unformat_ikev2_transform_dh_type, &dh_type))
477 ikev2_set_profile_ike_transforms (vm, name, crypto_alg,
478 IKEV2_TRANSFORM_INTEG_TYPE_NONE,
485 "set %U esp-crypto-alg %U %u esp-integ-alg %U",
486 unformat_ikev2_token, &name,
487 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
488 unformat_ikev2_transform_integ_type, &integ_alg))
491 ikev2_set_profile_esp_transforms (vm, name, crypto_alg, integ_alg,
497 "set %U esp-crypto-alg %U %u",
498 unformat_ikev2_token, &name,
499 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1))
502 ikev2_set_profile_esp_transforms (vm, name, crypto_alg, 0, tmp1);
505 else if (unformat (line_input, "set %U sa-lifetime %lu %u %u %lu",
506 unformat_ikev2_token, &name,
507 &tmp4, &tmp1, &tmp2, &tmp5))
510 ikev2_set_profile_sa_lifetime (vm, name, tmp4, tmp1, tmp2, tmp5);
513 else if (unformat (line_input, "set %U udp-encap",
514 unformat_ikev2_token, &name))
516 r = ikev2_set_profile_udp_encap (vm, name);
519 else if (unformat (line_input, "set %U ipsec-over-udp port %u",
520 unformat_ikev2_token, &name, &tmp1))
522 int rv = ikev2_set_profile_ipsec_udp_port (vm, name, tmp1, 1);
524 r = clib_error_return (0, "Error: %U", format_vnet_api_errno, rv);
527 else if (unformat (line_input, "set %U disable natt",
528 unformat_ikev2_token, &name))
530 r = ikev2_profile_natt_disable (name);
537 r = clib_error_return (0, "parse error: '%U'",
538 format_unformat_error, line_input);
543 unformat_free (line_input);
548 VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = {
549 .path = "ikev2 profile",
551 "ikev2 profile [add|del] <id>\n"
552 "ikev2 profile set <id> auth [rsa-sig|shared-key-mic] [cert-file|string|hex]"
554 "ikev2 profile set <id> id <local|remote> <type> <data>\n"
555 "ikev2 profile set <id> tunnel <interface>\n"
556 "ikev2 profile set <id> udp-encap\n"
557 "ikev2 profile set <id> traffic-selector <local|remote> ip-range "
558 "<start-addr> - <end-addr> port-range <start-port> - <end-port> "
559 "protocol <protocol-number>\n"
560 "ikev2 profile set <id> responder <interface> <addr>\n"
561 "ikev2 profile set <id> ike-crypto-alg <crypto alg> <key size> ike-integ-alg <integ alg> ike-dh <dh type>\n"
562 "ikev2 profile set <id> esp-crypto-alg <crypto alg> <key size> "
563 "[esp-integ-alg <integ alg>]\n"
564 "ikev2 profile set <id> sa-lifetime <seconds> <jitter> <handover> <max bytes>"
565 "ikev2 profile set <id> disable natt\n",
566 .function = ikev2_profile_add_del_command_fn,
570 static clib_error_t *
571 show_ikev2_profile_command_fn (vlib_main_t * vm,
572 unformat_input_t * input,
573 vlib_cli_command_t * cmd)
575 ikev2_main_t *km = &ikev2_main;
579 pool_foreach (p, km->profiles) {
580 vlib_cli_output(vm, "profile %v", p->name);
585 vlib_cli_output(vm, " auth-method %U auth data 0x%U",
586 format_ikev2_auth_method, p->auth.method,
587 format_hex_bytes, p->auth.data, vec_len(p->auth.data));
589 vlib_cli_output(vm, " auth-method %U auth data %v",
590 format_ikev2_auth_method, p->auth.method, p->auth.data);
594 vlib_cli_output(vm, " local %U", format_ikev2_id_type_and_data, &p->loc_id);
597 vlib_cli_output(vm, " remote %U", format_ikev2_id_type_and_data, &p->rem_id);
599 if (!ip_address_is_zero (&p->loc_ts.start_addr))
600 vlib_cli_output(vm, " local traffic-selector addr %U - %U port %u - %u"
602 format_ip_address, &p->loc_ts.start_addr,
603 format_ip_address, &p->loc_ts.end_addr,
604 p->loc_ts.start_port, p->loc_ts.end_port,
605 p->loc_ts.protocol_id);
607 if (!ip_address_is_zero (&p->rem_ts.start_addr))
608 vlib_cli_output(vm, " remote traffic-selector addr %U - %U port %u - %u"
610 format_ip_address, &p->rem_ts.start_addr,
611 format_ip_address, &p->rem_ts.end_addr,
612 p->rem_ts.start_port, p->rem_ts.end_port,
613 p->rem_ts.protocol_id);
614 if (~0 != p->tun_itf)
615 vlib_cli_output(vm, " protected tunnel %U",
616 format_vnet_sw_if_index_name, vnet_get_main(), p->tun_itf);
617 if (~0 != p->responder.sw_if_index)
618 vlib_cli_output(vm, " responder %U %U",
619 format_vnet_sw_if_index_name, vnet_get_main(), p->responder.sw_if_index,
620 format_ip_address, &p->responder.addr);
622 vlib_cli_output(vm, " udp-encap");
624 if (p->natt_disabled)
625 vlib_cli_output(vm, " NAT-T disabled");
627 if (p->ipsec_over_udp_port != IPSEC_UDP_PORT_NONE)
628 vlib_cli_output(vm, " ipsec-over-udp port %d", p->ipsec_over_udp_port);
630 if (p->ike_ts.crypto_alg || p->ike_ts.integ_alg || p->ike_ts.dh_type || p->ike_ts.crypto_key_size)
631 vlib_cli_output(vm, " ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
632 format_ikev2_transform_encr_type, p->ike_ts.crypto_alg, p->ike_ts.crypto_key_size,
633 format_ikev2_transform_integ_type, p->ike_ts.integ_alg,
634 format_ikev2_transform_dh_type, p->ike_ts.dh_type);
636 if (p->esp_ts.crypto_alg || p->esp_ts.integ_alg || p->esp_ts.dh_type)
637 vlib_cli_output(vm, " esp-crypto-alg %U %u esp-integ-alg %U",
638 format_ikev2_transform_encr_type, p->esp_ts.crypto_alg, p->esp_ts.crypto_key_size,
639 format_ikev2_transform_integ_type, p->esp_ts.integ_alg);
641 vlib_cli_output(vm, " lifetime %d jitter %d handover %d maxdata %d",
642 p->lifetime, p->lifetime_jitter, p->handover, p->lifetime_maxdata);
650 VLIB_CLI_COMMAND (show_ikev2_profile_command, static) = {
651 .path = "show ikev2 profile",
652 .short_help = "show ikev2 profile",
653 .function = show_ikev2_profile_command_fn,
657 static clib_error_t *
658 set_ikev2_liveness_period_fn (vlib_main_t * vm,
659 unformat_input_t * input,
660 vlib_cli_command_t * cmd)
662 unformat_input_t _line_input, *line_input = &_line_input;
664 u32 period = 0, max_retries = 0;
666 if (!unformat_user (input, unformat_line_input, line_input))
669 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
671 if (unformat (line_input, "%d %d", &period, &max_retries))
673 r = ikev2_set_liveness_params (period, max_retries);
680 r = clib_error_return (0, "parse error: '%U'",
681 format_unformat_error, line_input);
684 unformat_free (line_input);
689 VLIB_CLI_COMMAND (set_ikev2_liveness_command, static) = {
690 .path = "ikev2 set liveness",
691 .short_help = "ikev2 set liveness <period> <max-retires>",
692 .function = set_ikev2_liveness_period_fn,
696 static clib_error_t *
697 set_ikev2_local_key_command_fn (vlib_main_t * vm,
698 unformat_input_t * input,
699 vlib_cli_command_t * cmd)
701 unformat_input_t _line_input, *line_input = &_line_input;
705 if (!unformat_user (input, unformat_line_input, line_input))
708 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
710 if (unformat (line_input, "%s", &data))
712 r = ikev2_set_local_key (vm, data);
719 r = clib_error_return (0, "parse error: '%U'",
720 format_unformat_error, line_input);
724 unformat_free (line_input);
729 VLIB_CLI_COMMAND (set_ikev2_local_key_command, static) = {
730 .path = "set ikev2 local key",
732 "set ikev2 local key <file>",
733 .function = set_ikev2_local_key_command_fn,
738 static clib_error_t *
739 ikev2_initiate_command_fn (vlib_main_t * vm,
740 unformat_input_t * input, vlib_cli_command_t * cmd)
742 unformat_input_t _line_input, *line_input = &_line_input;
748 if (!unformat_user (input, unformat_line_input, line_input))
751 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
753 if (unformat (line_input, "sa-init %U", unformat_ikev2_token, &name))
755 r = ikev2_initiate_sa_init (vm, name);
758 else if (unformat (line_input, "del-child-sa %x", &tmp1))
760 r = ikev2_initiate_delete_child_sa (vm, tmp1);
763 else if (unformat (line_input, "del-sa %lx", &tmp2))
765 r = ikev2_initiate_delete_ike_sa (vm, tmp2);
768 else if (unformat (line_input, "rekey-child-sa %x", &tmp1))
770 r = ikev2_initiate_rekey_child_sa (vm, tmp1);
777 r = clib_error_return (0, "parse error: '%U'",
778 format_unformat_error, line_input);
782 unformat_free (line_input);
787 VLIB_CLI_COMMAND (ikev2_initiate_command, static) = {
788 .path = "ikev2 initiate",
790 "ikev2 initiate sa-init <profile id>\n"
791 "ikev2 initiate del-child-sa <child sa ispi>\n"
792 "ikev2 initiate del-sa <sa ispi>\n"
793 "ikev2 initiate rekey-child-sa <child sa ispi>\n",
794 .function = ikev2_initiate_command_fn,
799 ikev2_cli_reference (void)
803 static clib_error_t *
804 ikev2_set_log_level_command_fn (vlib_main_t * vm,
805 unformat_input_t * input,
806 vlib_cli_command_t * cmd)
808 unformat_input_t _line_input, *line_input = &_line_input;
809 u32 log_level = IKEV2_LOG_NONE;
810 clib_error_t *error = 0;
812 /* Get a line of input. */
813 if (!unformat_user (input, unformat_line_input, line_input))
816 if (!unformat (line_input, "%d", &log_level))
818 error = clib_error_return (0, "unknown input '%U'",
819 format_unformat_error, line_input);
822 int rc = ikev2_set_log_level (log_level);
824 error = clib_error_return (0, "setting log level failed!");
827 unformat_free (line_input);
832 VLIB_CLI_COMMAND (ikev2_set_log_level_command, static) = {
833 .path = "ikev2 set logging level",
834 .function = ikev2_set_log_level_command_fn,
835 .short_help = "ikev2 set logging level <0-5>",
840 * fd.io coding-style-patch-verification: ON
843 * eval: (c-set-style "gnu")