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);
197 static clib_error_t *
198 show_ikev2_sa_command_fn (vlib_main_t * vm,
199 unformat_input_t * input, vlib_cli_command_t * cmd)
201 unformat_input_t _line_input, *line_input = &_line_input;
202 ikev2_main_t *km = &ikev2_main;
203 ikev2_main_per_thread_data_t *tkm;
207 int details = 0, show_one = 0;
209 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, "rspi %lx", &rspi))
217 else if (unformat (line_input, "details"))
222 unformat_free (line_input);
225 vec_foreach (tkm, km->per_thread_data)
228 pool_foreach (sa, tkm->sas) {
231 if (sa->rspi == rspi)
233 s = format (s, "%U\n", format_ikev2_sa, sa, 1);
238 s = format (s, "%U\n", format_ikev2_sa, sa, details);
243 vlib_cli_output (vm, "%v", s);
249 VLIB_CLI_COMMAND (show_ikev2_sa_command, static) = {
250 .path = "show ikev2 sa",
251 .short_help = "show ikev2 sa [rspi <rspi>] [details]",
252 .function = show_ikev2_sa_command_fn,
256 static clib_error_t *
257 ikev2_disable_dpd_command_fn (vlib_main_t * vm,
258 unformat_input_t * input,
259 vlib_cli_command_t * cmd)
261 ikev2_disable_dpd ();
266 VLIB_CLI_COMMAND (ikev2_cli_disable_dpd_command, static) = {
267 .path = "ikev2 dpd disable",
268 .short_help = "ikev2 dpd disable",
269 .function = ikev2_disable_dpd_command_fn,
274 unformat_ikev2_token (unformat_input_t * input, va_list * va)
276 u8 **string_return = va_arg (*va, u8 **);
277 const char *token_chars = "a-zA-Z0-9_";
280 /* if string_return was already allocated (eg. because of a previous
281 * partial match with a successful unformat_token()), we must free it
282 * before reusing the pointer, otherwise we'll be leaking memory
284 vec_free (*string_return);
287 return unformat_user (input, unformat_token, token_chars, string_return);
290 static clib_error_t *
291 ikev2_profile_add_del_command_fn (vlib_main_t * vm,
292 unformat_input_t * input,
293 vlib_cli_command_t * cmd)
295 vnet_main_t *vnm = vnet_get_main ();
296 unformat_input_t _line_input, *line_input = &_line_input;
301 u32 tmp1, tmp2, tmp3;
303 ip_address_t ip, end_addr;
304 u32 responder_sw_if_index = (u32) ~ 0;
305 u32 tun_sw_if_index = (u32) ~ 0;
306 ikev2_transform_encr_type_t crypto_alg;
307 ikev2_transform_integ_type_t integ_alg;
308 ikev2_transform_dh_type_t dh_type;
310 if (!unformat_user (input, unformat_line_input, line_input))
313 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
315 if (unformat (line_input, "add %U", unformat_ikev2_token, &name))
317 r = ikev2_add_del_profile (vm, name, 1);
320 else if (unformat (line_input, "del %U", unformat_ikev2_token, &name))
322 r = ikev2_add_del_profile (vm, name, 0);
325 else if (unformat (line_input, "set %U auth shared-key-mic string %v",
326 unformat_ikev2_token, &name, &data))
329 ikev2_set_profile_auth (vm, name,
330 IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
334 else if (unformat (line_input, "set %U auth shared-key-mic hex %U",
335 unformat_ikev2_token, &name,
336 unformat_hex_string, &data))
339 ikev2_set_profile_auth (vm, name,
340 IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
344 else if (unformat (line_input, "set %U auth rsa-sig cert-file %v",
345 unformat_ikev2_token, &name, &data))
348 ikev2_set_profile_auth (vm, name, IKEV2_AUTH_METHOD_RSA_SIG, data,
352 else if (unformat (line_input, "set %U id local %U %U",
353 unformat_ikev2_token, &name,
354 unformat_ikev2_id_type, &id_type,
355 unformat_ip_address, &ip))
357 data = vec_new (u8, ip_address_size (&ip));
358 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
360 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
363 else if (unformat (line_input, "set %U id local %U 0x%U",
364 unformat_ikev2_token, &name,
365 unformat_ikev2_id_type, &id_type,
366 unformat_hex_string, &data))
369 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
372 else if (unformat (line_input, "set %U id local %U %v",
373 unformat_ikev2_token, &name,
374 unformat_ikev2_id_type, &id_type, &data))
377 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
380 else if (unformat (line_input, "set %U id remote %U %U",
381 unformat_ikev2_token, &name,
382 unformat_ikev2_id_type, &id_type,
383 unformat_ip_address, &ip))
385 data = vec_new (u8, ip_address_size (&ip));
386 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
387 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
391 else if (unformat (line_input, "set %U id remote %U 0x%U",
392 unformat_ikev2_token, &name,
393 unformat_ikev2_id_type, &id_type,
394 unformat_hex_string, &data))
396 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
400 else if (unformat (line_input, "set %U id remote %U %v",
401 unformat_ikev2_token, &name,
402 unformat_ikev2_id_type, &id_type, &data))
404 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
408 else if (unformat (line_input, "set %U traffic-selector local "
409 "ip-range %U - %U port-range %u - %u protocol %u",
410 unformat_ikev2_token, &name,
411 unformat_ip_address, &ip,
412 unformat_ip_address, &end_addr, &tmp1, &tmp2, &tmp3))
415 ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
416 ip, end_addr, /*local */ 1);
419 else if (unformat (line_input, "set %U traffic-selector remote "
420 "ip-range %U - %U port-range %u - %u protocol %u",
421 unformat_ikev2_token, &name,
422 unformat_ip_address, &ip,
423 unformat_ip_address, &end_addr, &tmp1, &tmp2, &tmp3))
426 ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
427 ip, end_addr, /*remote */ 0);
430 else if (unformat (line_input, "set %U responder %U %U",
431 unformat_ikev2_token, &name,
432 unformat_vnet_sw_interface, vnm,
433 &responder_sw_if_index, unformat_ip_address, &ip))
436 ikev2_set_profile_responder (vm, name, responder_sw_if_index, ip);
439 else if (unformat (line_input, "set %U tunnel %U",
440 unformat_ikev2_token, &name,
441 unformat_vnet_sw_interface, vnm, &tun_sw_if_index))
443 r = ikev2_set_profile_tunnel_interface (vm, name, tun_sw_if_index);
449 "set %U ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
450 unformat_ikev2_token, &name,
451 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
452 unformat_ikev2_transform_integ_type, &integ_alg,
453 unformat_ikev2_transform_dh_type, &dh_type))
456 ikev2_set_profile_ike_transforms (vm, name, crypto_alg, integ_alg,
463 "set %U ike-crypto-alg %U %u ike-dh %U",
464 unformat_ikev2_token, &name,
465 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
466 unformat_ikev2_transform_dh_type, &dh_type))
469 ikev2_set_profile_ike_transforms (vm, name, crypto_alg,
470 IKEV2_TRANSFORM_INTEG_TYPE_NONE,
477 "set %U esp-crypto-alg %U %u esp-integ-alg %U",
478 unformat_ikev2_token, &name,
479 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
480 unformat_ikev2_transform_integ_type, &integ_alg))
483 ikev2_set_profile_esp_transforms (vm, name, crypto_alg, integ_alg,
489 "set %U esp-crypto-alg %U %u",
490 unformat_ikev2_token, &name,
491 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1))
494 ikev2_set_profile_esp_transforms (vm, name, crypto_alg, 0, tmp1);
497 else if (unformat (line_input, "set %U sa-lifetime %lu %u %u %lu",
498 unformat_ikev2_token, &name,
499 &tmp4, &tmp1, &tmp2, &tmp5))
502 ikev2_set_profile_sa_lifetime (vm, name, tmp4, tmp1, tmp2, tmp5);
505 else if (unformat (line_input, "set %U udp-encap",
506 unformat_ikev2_token, &name))
508 r = ikev2_set_profile_udp_encap (vm, name);
511 else if (unformat (line_input, "set %U ipsec-over-udp port %u",
512 unformat_ikev2_token, &name, &tmp1))
514 int rv = ikev2_set_profile_ipsec_udp_port (vm, name, tmp1, 1);
516 r = clib_error_return (0, "Error: %U", format_vnet_api_errno, rv);
519 else if (unformat (line_input, "set %U disable natt",
520 unformat_ikev2_token, &name))
522 r = ikev2_profile_natt_disable (name);
529 r = clib_error_return (0, "parse error: '%U'",
530 format_unformat_error, line_input);
535 unformat_free (line_input);
540 VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = {
541 .path = "ikev2 profile",
543 "ikev2 profile [add|del] <id>\n"
544 "ikev2 profile set <id> auth [rsa-sig|shared-key-mic] [cert-file|string|hex]"
546 "ikev2 profile set <id> id <local|remote> <type> <data>\n"
547 "ikev2 profile set <id> tunnel <interface>\n"
548 "ikev2 profile set <id> udp-encap\n"
549 "ikev2 profile set <id> traffic-selector <local|remote> ip-range "
550 "<start-addr> - <end-addr> port-range <start-port> - <end-port> "
551 "protocol <protocol-number>\n"
552 "ikev2 profile set <id> responder <interface> <addr>\n"
553 "ikev2 profile set <id> ike-crypto-alg <crypto alg> <key size> ike-integ-alg <integ alg> ike-dh <dh type>\n"
554 "ikev2 profile set <id> esp-crypto-alg <crypto alg> <key size> "
555 "[esp-integ-alg <integ alg>]\n"
556 "ikev2 profile set <id> sa-lifetime <seconds> <jitter> <handover> <max bytes>"
557 "ikev2 profile set <id> disable natt\n",
558 .function = ikev2_profile_add_del_command_fn,
562 static clib_error_t *
563 show_ikev2_profile_command_fn (vlib_main_t * vm,
564 unformat_input_t * input,
565 vlib_cli_command_t * cmd)
567 ikev2_main_t *km = &ikev2_main;
571 pool_foreach (p, km->profiles) {
572 vlib_cli_output(vm, "profile %v", p->name);
577 vlib_cli_output(vm, " auth-method %U auth data 0x%U",
578 format_ikev2_auth_method, p->auth.method,
579 format_hex_bytes, p->auth.data, vec_len(p->auth.data));
581 vlib_cli_output(vm, " auth-method %U auth data %v",
582 format_ikev2_auth_method, p->auth.method, p->auth.data);
586 vlib_cli_output(vm, " local %U", format_ikev2_id_type_and_data, &p->loc_id);
589 vlib_cli_output(vm, " remote %U", format_ikev2_id_type_and_data, &p->rem_id);
591 if (!ip_address_is_zero (&p->loc_ts.start_addr))
592 vlib_cli_output(vm, " local traffic-selector addr %U - %U port %u - %u"
594 format_ip_address, &p->loc_ts.start_addr,
595 format_ip_address, &p->loc_ts.end_addr,
596 p->loc_ts.start_port, p->loc_ts.end_port,
597 p->loc_ts.protocol_id);
599 if (!ip_address_is_zero (&p->rem_ts.start_addr))
600 vlib_cli_output(vm, " remote traffic-selector addr %U - %U port %u - %u"
602 format_ip_address, &p->rem_ts.start_addr,
603 format_ip_address, &p->rem_ts.end_addr,
604 p->rem_ts.start_port, p->rem_ts.end_port,
605 p->rem_ts.protocol_id);
606 if (~0 != p->tun_itf)
607 vlib_cli_output(vm, " protected tunnel %U",
608 format_vnet_sw_if_index_name, vnet_get_main(), p->tun_itf);
609 if (~0 != p->responder.sw_if_index)
610 vlib_cli_output(vm, " responder %U %U",
611 format_vnet_sw_if_index_name, vnet_get_main(), p->responder.sw_if_index,
612 format_ip_address, &p->responder.addr);
614 vlib_cli_output(vm, " udp-encap");
616 if (p->natt_disabled)
617 vlib_cli_output(vm, " NAT-T disabled");
619 if (p->ipsec_over_udp_port != IPSEC_UDP_PORT_NONE)
620 vlib_cli_output(vm, " ipsec-over-udp port %d", p->ipsec_over_udp_port);
622 if (p->ike_ts.crypto_alg || p->ike_ts.integ_alg || p->ike_ts.dh_type || p->ike_ts.crypto_key_size)
623 vlib_cli_output(vm, " ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
624 format_ikev2_transform_encr_type, p->ike_ts.crypto_alg, p->ike_ts.crypto_key_size,
625 format_ikev2_transform_integ_type, p->ike_ts.integ_alg,
626 format_ikev2_transform_dh_type, p->ike_ts.dh_type);
628 if (p->esp_ts.crypto_alg || p->esp_ts.integ_alg || p->esp_ts.dh_type)
629 vlib_cli_output(vm, " esp-crypto-alg %U %u esp-integ-alg %U",
630 format_ikev2_transform_encr_type, p->esp_ts.crypto_alg, p->esp_ts.crypto_key_size,
631 format_ikev2_transform_integ_type, p->esp_ts.integ_alg);
633 vlib_cli_output(vm, " lifetime %d jitter %d handover %d maxdata %d",
634 p->lifetime, p->lifetime_jitter, p->handover, p->lifetime_maxdata);
642 VLIB_CLI_COMMAND (show_ikev2_profile_command, static) = {
643 .path = "show ikev2 profile",
644 .short_help = "show ikev2 profile",
645 .function = show_ikev2_profile_command_fn,
649 static clib_error_t *
650 set_ikev2_liveness_period_fn (vlib_main_t * vm,
651 unformat_input_t * input,
652 vlib_cli_command_t * cmd)
654 unformat_input_t _line_input, *line_input = &_line_input;
656 u32 period = 0, max_retries = 0;
658 if (!unformat_user (input, unformat_line_input, line_input))
661 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
663 if (unformat (line_input, "%d %d", &period, &max_retries))
665 r = ikev2_set_liveness_params (period, max_retries);
672 r = clib_error_return (0, "parse error: '%U'",
673 format_unformat_error, line_input);
676 unformat_free (line_input);
681 VLIB_CLI_COMMAND (set_ikev2_liveness_command, static) = {
682 .path = "ikev2 set liveness",
683 .short_help = "ikev2 set liveness <period> <max-retires>",
684 .function = set_ikev2_liveness_period_fn,
688 static clib_error_t *
689 set_ikev2_local_key_command_fn (vlib_main_t * vm,
690 unformat_input_t * input,
691 vlib_cli_command_t * cmd)
693 unformat_input_t _line_input, *line_input = &_line_input;
697 if (!unformat_user (input, unformat_line_input, line_input))
700 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
702 if (unformat (line_input, "%s", &data))
704 r = ikev2_set_local_key (vm, data);
711 r = clib_error_return (0, "parse error: '%U'",
712 format_unformat_error, line_input);
716 unformat_free (line_input);
721 VLIB_CLI_COMMAND (set_ikev2_local_key_command, static) = {
722 .path = "set ikev2 local key",
724 "set ikev2 local key <file>",
725 .function = set_ikev2_local_key_command_fn,
730 static clib_error_t *
731 ikev2_initiate_command_fn (vlib_main_t * vm,
732 unformat_input_t * input, vlib_cli_command_t * cmd)
734 unformat_input_t _line_input, *line_input = &_line_input;
740 if (!unformat_user (input, unformat_line_input, line_input))
743 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
745 if (unformat (line_input, "sa-init %U", unformat_ikev2_token, &name))
747 r = ikev2_initiate_sa_init (vm, name);
750 else if (unformat (line_input, "del-child-sa %x", &tmp1))
752 r = ikev2_initiate_delete_child_sa (vm, tmp1);
755 else if (unformat (line_input, "del-sa %lx", &tmp2))
757 r = ikev2_initiate_delete_ike_sa (vm, tmp2);
760 else if (unformat (line_input, "rekey-child-sa %x", &tmp1))
762 r = ikev2_initiate_rekey_child_sa (vm, tmp1);
769 r = clib_error_return (0, "parse error: '%U'",
770 format_unformat_error, line_input);
774 unformat_free (line_input);
779 VLIB_CLI_COMMAND (ikev2_initiate_command, static) = {
780 .path = "ikev2 initiate",
782 "ikev2 initiate sa-init <profile id>\n"
783 "ikev2 initiate del-child-sa <child sa ispi>\n"
784 "ikev2 initiate del-sa <sa ispi>\n"
785 "ikev2 initiate rekey-child-sa <child sa ispi>\n",
786 .function = ikev2_initiate_command_fn,
791 ikev2_cli_reference (void)
795 static clib_error_t *
796 ikev2_set_log_level_command_fn (vlib_main_t * vm,
797 unformat_input_t * input,
798 vlib_cli_command_t * cmd)
800 unformat_input_t _line_input, *line_input = &_line_input;
801 u32 log_level = IKEV2_LOG_NONE;
802 clib_error_t *error = 0;
804 /* Get a line of input. */
805 if (!unformat_user (input, unformat_line_input, line_input))
808 if (!unformat (line_input, "%d", &log_level))
810 error = clib_error_return (0, "unknown input '%U'",
811 format_unformat_error, line_input);
814 int rc = ikev2_set_log_level (log_level);
816 error = clib_error_return (0, "setting log level failed!");
819 unformat_free (line_input);
824 VLIB_CLI_COMMAND (ikev2_set_log_level_command, static) = {
825 .path = "ikev2 set logging level",
826 .function = ikev2_set_log_level_command_fn,
827 .short_help = "ikev2 set logging level <0-5>",
832 * fd.io coding-style-patch-verification: ON
835 * eval: (c-set-style "gnu")