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);
124 static char *stateNames[] = {
125 #define _(v, f, s) s,
131 format_ikev2_sa (u8 * s, va_list * va)
133 ikev2_sa_t *sa = va_arg (*va, ikev2_sa_t *);
134 int details = va_arg (*va, int);
135 ikev2_sa_transform_t *tr;
136 ikev2_child_sa_t *child;
139 ikev2_main_t *km = &ikev2_main;
142 p = pool_elt_at_index (km->profiles, sa->profile_index);
144 s = format (s, "iip %U ispi %lx rip %U rspi %lx",
145 format_ip_address, &sa->iaddr, sa->ispi,
146 format_ip_address, &sa->raddr, sa->rspi);
150 s = format (s, "\n%U", format_white_space, indent);
152 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
153 s = format (s, "%U ", format_ikev2_sa_transform, tr);
155 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
156 s = format (s, "%U ", format_ikev2_sa_transform, tr);
158 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
159 s = format (s, "%U ", format_ikev2_sa_transform, tr);
161 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_DH);
162 s = format (s, "%U", format_ikev2_sa_transform, tr);
164 s = format (s, "\n profile: %v", p->name);
166 if (sa->state <= IKEV2_STATE_NO_PROPOSAL_CHOSEN)
168 s = format (s, "\n state: %s", stateNames[sa->state]);
171 s = format (s, "\n%U", format_white_space, indent);
173 s = format (s, "nonce i:%U\n%Ur:%U\n",
174 format_hex_bytes, sa->i_nonce, vec_len (sa->i_nonce),
175 format_white_space, indent + 6,
176 format_hex_bytes, sa->r_nonce, vec_len (sa->r_nonce));
178 s = format (s, "%USK_d %U\n", format_white_space, indent,
179 format_hex_bytes, sa->sk_d, vec_len (sa->sk_d));
182 s = format (s, "%USK_a i:%U\n%Ur:%U\n",
183 format_white_space, indent,
184 format_hex_bytes, sa->sk_ai, vec_len (sa->sk_ai),
185 format_white_space, indent + 6,
186 format_hex_bytes, sa->sk_ar, vec_len (sa->sk_ar));
188 s = format (s, "%USK_e i:%U\n%Ur:%U\n",
189 format_white_space, indent,
190 format_hex_bytes, sa->sk_ei, vec_len (sa->sk_ei),
191 format_white_space, indent + 6,
192 format_hex_bytes, sa->sk_er, vec_len (sa->sk_er));
193 s = format (s, "%USK_p i:%U\n%Ur:%U\n",
194 format_white_space, indent,
195 format_hex_bytes, sa->sk_pi, vec_len (sa->sk_pi),
196 format_white_space, indent + 6,
197 format_hex_bytes, sa->sk_pr, vec_len (sa->sk_pr));
199 s = format (s, "%Uidentifier (i) %U\n",
200 format_white_space, indent,
201 format_ikev2_id_type_and_data, &sa->i_id);
202 s = format (s, "%Uidentifier (r) %U\n",
203 format_white_space, indent,
204 format_ikev2_id_type_and_data, &sa->r_id);
206 vec_foreach (child, sa->childs)
208 s = format (s, "%U%U", format_white_space, indent + 2,
209 format_ikev2_child_sa, child, child - sa->childs);
212 s = format (s, "Stats:\n");
213 s = format (s, " keepalives :%u\n", sa->stats.n_keepalives);
214 s = format (s, " rekey :%u\n", sa->stats.n_rekey_req);
215 s = format (s, " SA init :%u (retransmit: %u)\n", sa->stats.n_sa_init_req,
216 sa->stats.n_init_retransmit);
217 s = format (s, " retransmit: %u\n", sa->stats.n_retransmit);
218 s = format (s, " SA auth :%u\n", sa->stats.n_sa_auth_req);
223 static clib_error_t *
224 show_ikev2_sa_command_fn (vlib_main_t * vm,
225 unformat_input_t * input, vlib_cli_command_t * cmd)
227 unformat_input_t _line_input, *line_input = &_line_input;
228 ikev2_main_t *km = &ikev2_main;
229 ikev2_main_per_thread_data_t *tkm;
233 int details = 0, show_one = 0;
235 if (unformat_user (input, unformat_line_input, line_input))
237 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
239 if (unformat (line_input, "rspi %lx", &rspi))
243 else if (unformat (line_input, "details"))
248 unformat_free (line_input);
251 vec_foreach (tkm, km->per_thread_data)
253 pool_foreach (sa, tkm->sas) {
256 if (sa->rspi == rspi)
258 s = format (s, "%U\n", format_ikev2_sa, sa, 1);
263 s = format (s, "%U\n", format_ikev2_sa, sa, details);
267 vlib_cli_output (vm, "%v", s);
272 VLIB_CLI_COMMAND (show_ikev2_sa_command, static) = {
273 .path = "show ikev2 sa",
274 .short_help = "show ikev2 sa [rspi <rspi>] [details]",
275 .function = show_ikev2_sa_command_fn,
278 static clib_error_t *
279 ikev2_disable_dpd_command_fn (vlib_main_t * vm,
280 unformat_input_t * input,
281 vlib_cli_command_t * cmd)
283 ikev2_disable_dpd ();
287 VLIB_CLI_COMMAND (ikev2_cli_disable_dpd_command, static) = {
288 .path = "ikev2 dpd disable",
289 .short_help = "ikev2 dpd disable",
290 .function = ikev2_disable_dpd_command_fn,
294 unformat_ikev2_token (unformat_input_t * input, va_list * va)
296 u8 **string_return = va_arg (*va, u8 **);
297 const char *token_chars = "a-zA-Z0-9_";
300 /* if string_return was already allocated (eg. because of a previous
301 * partial match with a successful unformat_token()), we must free it
302 * before reusing the pointer, otherwise we'll be leaking memory
304 vec_free (*string_return);
307 return unformat_user (input, unformat_token, token_chars, string_return);
310 static clib_error_t *
311 ikev2_profile_add_del_command_fn (vlib_main_t * vm,
312 unformat_input_t * input,
313 vlib_cli_command_t * cmd)
315 vnet_main_t *vnm = vnet_get_main ();
316 unformat_input_t _line_input, *line_input = &_line_input;
321 u32 tmp1, tmp2, tmp3;
323 ip_address_t ip, end_addr;
324 u32 responder_sw_if_index = (u32) ~ 0;
325 u32 tun_sw_if_index = (u32) ~ 0;
326 ikev2_transform_encr_type_t crypto_alg;
327 ikev2_transform_integ_type_t integ_alg;
328 ikev2_transform_dh_type_t dh_type;
330 if (!unformat_user (input, unformat_line_input, line_input))
333 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
335 if (unformat (line_input, "add %U", unformat_ikev2_token, &name))
337 r = ikev2_add_del_profile (vm, name, 1);
340 else if (unformat (line_input, "del %U", unformat_ikev2_token, &name))
342 r = ikev2_add_del_profile (vm, name, 0);
345 else if (unformat (line_input, "set %U auth shared-key-mic string %v",
346 unformat_ikev2_token, &name, &data))
349 ikev2_set_profile_auth (vm, name,
350 IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
354 else if (unformat (line_input, "set %U auth shared-key-mic hex %U",
355 unformat_ikev2_token, &name,
356 unformat_hex_string, &data))
359 ikev2_set_profile_auth (vm, name,
360 IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
364 else if (unformat (line_input, "set %U auth rsa-sig cert-file %v",
365 unformat_ikev2_token, &name, &data))
368 ikev2_set_profile_auth (vm, name, IKEV2_AUTH_METHOD_RSA_SIG, data,
372 else if (unformat (line_input, "set %U id local %U %U",
373 unformat_ikev2_token, &name,
374 unformat_ikev2_id_type, &id_type,
375 unformat_ip_address, &ip))
377 data = vec_new (u8, ip_address_size (&ip));
378 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
380 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
383 else if (unformat (line_input, "set %U id local %U 0x%U",
384 unformat_ikev2_token, &name,
385 unformat_ikev2_id_type, &id_type,
386 unformat_hex_string, &data))
389 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
392 else if (unformat (line_input, "set %U id local %U %v",
393 unformat_ikev2_token, &name,
394 unformat_ikev2_id_type, &id_type, &data))
397 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
400 else if (unformat (line_input, "set %U id remote %U %U",
401 unformat_ikev2_token, &name,
402 unformat_ikev2_id_type, &id_type,
403 unformat_ip_address, &ip))
405 data = vec_new (u8, ip_address_size (&ip));
406 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
407 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
411 else if (unformat (line_input, "set %U id remote %U 0x%U",
412 unformat_ikev2_token, &name,
413 unformat_ikev2_id_type, &id_type,
414 unformat_hex_string, &data))
416 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
420 else if (unformat (line_input, "set %U id remote %U %v",
421 unformat_ikev2_token, &name,
422 unformat_ikev2_id_type, &id_type, &data))
424 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
428 else if (unformat (line_input, "set %U traffic-selector local "
429 "ip-range %U - %U port-range %u - %u protocol %u",
430 unformat_ikev2_token, &name,
431 unformat_ip_address, &ip,
432 unformat_ip_address, &end_addr, &tmp1, &tmp2, &tmp3))
435 ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
436 ip, end_addr, /*local */ 1);
439 else if (unformat (line_input, "set %U traffic-selector remote "
440 "ip-range %U - %U port-range %u - %u protocol %u",
441 unformat_ikev2_token, &name,
442 unformat_ip_address, &ip,
443 unformat_ip_address, &end_addr, &tmp1, &tmp2, &tmp3))
446 ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
447 ip, end_addr, /*remote */ 0);
450 else if (unformat (line_input, "set %U responder %U %U",
451 unformat_ikev2_token, &name,
452 unformat_vnet_sw_interface, vnm,
453 &responder_sw_if_index, unformat_ip_address, &ip))
456 ikev2_set_profile_responder (vm, name, responder_sw_if_index, ip);
459 else if (unformat (line_input, "set %U responder %U %v",
460 unformat_ikev2_token, &name,
461 unformat_vnet_sw_interface, vnm,
462 &responder_sw_if_index, &data))
464 r = ikev2_set_profile_responder_hostname (vm, name, data,
465 responder_sw_if_index);
468 else if (unformat (line_input, "set %U tunnel %U",
469 unformat_ikev2_token, &name,
470 unformat_vnet_sw_interface, vnm, &tun_sw_if_index))
472 r = ikev2_set_profile_tunnel_interface (vm, name, tun_sw_if_index);
478 "set %U ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
479 unformat_ikev2_token, &name,
480 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
481 unformat_ikev2_transform_integ_type, &integ_alg,
482 unformat_ikev2_transform_dh_type, &dh_type))
485 ikev2_set_profile_ike_transforms (vm, name, crypto_alg, integ_alg,
492 "set %U ike-crypto-alg %U %u ike-dh %U",
493 unformat_ikev2_token, &name,
494 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
495 unformat_ikev2_transform_dh_type, &dh_type))
498 ikev2_set_profile_ike_transforms (vm, name, crypto_alg,
499 IKEV2_TRANSFORM_INTEG_TYPE_NONE,
506 "set %U esp-crypto-alg %U %u esp-integ-alg %U",
507 unformat_ikev2_token, &name,
508 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
509 unformat_ikev2_transform_integ_type, &integ_alg))
512 ikev2_set_profile_esp_transforms (vm, name, crypto_alg, integ_alg,
518 "set %U esp-crypto-alg %U %u",
519 unformat_ikev2_token, &name,
520 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1))
523 ikev2_set_profile_esp_transforms (vm, name, crypto_alg, 0, tmp1);
526 else if (unformat (line_input, "set %U sa-lifetime %lu %u %u %lu",
527 unformat_ikev2_token, &name,
528 &tmp4, &tmp1, &tmp2, &tmp5))
531 ikev2_set_profile_sa_lifetime (vm, name, tmp4, tmp1, tmp2, tmp5);
534 else if (unformat (line_input, "set %U udp-encap",
535 unformat_ikev2_token, &name))
537 r = ikev2_set_profile_udp_encap (vm, name);
540 else if (unformat (line_input, "set %U ipsec-over-udp port %u",
541 unformat_ikev2_token, &name, &tmp1))
543 int rv = ikev2_set_profile_ipsec_udp_port (vm, name, tmp1, 1);
545 r = clib_error_return (0, "Error: %U", format_vnet_api_errno, rv);
548 else if (unformat (line_input, "set %U disable natt",
549 unformat_ikev2_token, &name))
551 r = ikev2_profile_natt_disable (name);
558 r = clib_error_return (0, "parse error: '%U'",
559 format_unformat_error, line_input);
564 unformat_free (line_input);
568 VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = {
569 .path = "ikev2 profile",
571 "ikev2 profile [add|del] <id>\n"
572 "ikev2 profile set <id> auth [rsa-sig|shared-key-mic] [cert-file|string|hex]"
574 "ikev2 profile set <id> id <local|remote> <type> <data>\n"
575 "ikev2 profile set <id> tunnel <interface>\n"
576 "ikev2 profile set <id> udp-encap\n"
577 "ikev2 profile set <id> traffic-selector <local|remote> ip-range "
578 "<start-addr> - <end-addr> port-range <start-port> - <end-port> "
579 "protocol <protocol-number>\n"
580 "ikev2 profile set <id> responder <interface> <addr>\n"
581 "ikev2 profile set <id> ike-crypto-alg <crypto alg> <key size> ike-integ-alg <integ alg> ike-dh <dh type>\n"
582 "ikev2 profile set <id> esp-crypto-alg <crypto alg> <key size> "
583 "[esp-integ-alg <integ alg>]\n"
584 "ikev2 profile set <id> sa-lifetime <seconds> <jitter> <handover> <max bytes>"
585 "ikev2 profile set <id> disable natt\n",
586 .function = ikev2_profile_add_del_command_fn,
589 static clib_error_t *
590 show_ikev2_profile_command_fn (vlib_main_t * vm,
591 unformat_input_t * input,
592 vlib_cli_command_t * cmd)
594 ikev2_main_t *km = &ikev2_main;
597 pool_foreach (p, km->profiles) {
598 vlib_cli_output(vm, "profile %v", p->name);
603 vlib_cli_output(vm, " auth-method %U auth data 0x%U",
604 format_ikev2_auth_method, p->auth.method,
605 format_hex_bytes, p->auth.data, vec_len(p->auth.data));
607 vlib_cli_output(vm, " auth-method %U auth data %v",
608 format_ikev2_auth_method, p->auth.method, p->auth.data);
612 vlib_cli_output(vm, " local %U", format_ikev2_id_type_and_data, &p->loc_id);
615 vlib_cli_output(vm, " remote %U", format_ikev2_id_type_and_data, &p->rem_id);
617 if (!ip_address_is_zero (&p->loc_ts.start_addr))
618 vlib_cli_output(vm, " local traffic-selector addr %U - %U port %u - %u"
620 format_ip_address, &p->loc_ts.start_addr,
621 format_ip_address, &p->loc_ts.end_addr,
622 p->loc_ts.start_port, p->loc_ts.end_port,
623 p->loc_ts.protocol_id);
625 if (!ip_address_is_zero (&p->rem_ts.start_addr))
626 vlib_cli_output(vm, " remote traffic-selector addr %U - %U port %u - %u"
628 format_ip_address, &p->rem_ts.start_addr,
629 format_ip_address, &p->rem_ts.end_addr,
630 p->rem_ts.start_port, p->rem_ts.end_port,
631 p->rem_ts.protocol_id);
632 if (~0 != p->tun_itf)
633 vlib_cli_output(vm, " protected tunnel %U",
634 format_vnet_sw_if_index_name, vnet_get_main(), p->tun_itf);
635 if (~0 != p->responder.sw_if_index)
636 vlib_cli_output (vm, " responder %U %U %v",
637 format_vnet_sw_if_index_name, vnet_get_main (),
638 p->responder.sw_if_index, format_ip_address,
639 &p->responder.addr, p->responder.hostname);
641 vlib_cli_output(vm, " udp-encap");
643 if (p->natt_disabled)
644 vlib_cli_output(vm, " NAT-T disabled");
646 if (p->ipsec_over_udp_port != IPSEC_UDP_PORT_NONE)
647 vlib_cli_output(vm, " ipsec-over-udp port %d", p->ipsec_over_udp_port);
649 if (p->ike_ts.crypto_alg || p->ike_ts.integ_alg || p->ike_ts.dh_type || p->ike_ts.crypto_key_size)
650 vlib_cli_output(vm, " ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
651 format_ikev2_transform_encr_type, p->ike_ts.crypto_alg, p->ike_ts.crypto_key_size,
652 format_ikev2_transform_integ_type, p->ike_ts.integ_alg,
653 format_ikev2_transform_dh_type, p->ike_ts.dh_type);
655 if (p->esp_ts.crypto_alg || p->esp_ts.integ_alg || p->esp_ts.dh_type)
656 vlib_cli_output(vm, " esp-crypto-alg %U %u esp-integ-alg %U",
657 format_ikev2_transform_encr_type, p->esp_ts.crypto_alg, p->esp_ts.crypto_key_size,
658 format_ikev2_transform_integ_type, p->esp_ts.integ_alg);
660 vlib_cli_output(vm, " lifetime %d jitter %d handover %d maxdata %d",
661 p->lifetime, p->lifetime_jitter, p->handover, p->lifetime_maxdata);
667 VLIB_CLI_COMMAND (show_ikev2_profile_command, static) = {
668 .path = "show ikev2 profile",
669 .short_help = "show ikev2 profile",
670 .function = show_ikev2_profile_command_fn,
673 static clib_error_t *
674 set_ikev2_liveness_period_fn (vlib_main_t * vm,
675 unformat_input_t * input,
676 vlib_cli_command_t * cmd)
678 unformat_input_t _line_input, *line_input = &_line_input;
680 u32 period = 0, max_retries = 0;
682 if (!unformat_user (input, unformat_line_input, line_input))
685 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
687 if (unformat (line_input, "%d %d", &period, &max_retries))
689 r = ikev2_set_liveness_params (period, max_retries);
696 r = clib_error_return (0, "parse error: '%U'",
697 format_unformat_error, line_input);
700 unformat_free (line_input);
704 VLIB_CLI_COMMAND (set_ikev2_liveness_command, static) = {
705 .path = "ikev2 set liveness",
706 .short_help = "ikev2 set liveness <period> <max-retires>",
707 .function = set_ikev2_liveness_period_fn,
710 static clib_error_t *
711 set_ikev2_local_key_command_fn (vlib_main_t * vm,
712 unformat_input_t * input,
713 vlib_cli_command_t * cmd)
715 unformat_input_t _line_input, *line_input = &_line_input;
719 if (!unformat_user (input, unformat_line_input, line_input))
722 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
724 if (unformat (line_input, "%s", &data))
726 r = ikev2_set_local_key (vm, data);
733 r = clib_error_return (0, "parse error: '%U'",
734 format_unformat_error, line_input);
738 unformat_free (line_input);
742 VLIB_CLI_COMMAND (set_ikev2_local_key_command, static) = {
743 .path = "set ikev2 local key",
745 "set ikev2 local key <file>",
746 .function = set_ikev2_local_key_command_fn,
750 static clib_error_t *
751 ikev2_initiate_command_fn (vlib_main_t * vm,
752 unformat_input_t * input, vlib_cli_command_t * cmd)
754 unformat_input_t _line_input, *line_input = &_line_input;
760 if (!unformat_user (input, unformat_line_input, line_input))
763 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
765 if (unformat (line_input, "sa-init %U", unformat_ikev2_token, &name))
767 r = ikev2_initiate_sa_init (vm, name);
770 else if (unformat (line_input, "del-child-sa %x", &tmp1))
772 r = ikev2_initiate_delete_child_sa (vm, tmp1);
775 else if (unformat (line_input, "del-sa %lx", &tmp2))
777 r = ikev2_initiate_delete_ike_sa (vm, tmp2);
780 else if (unformat (line_input, "rekey-child-sa %x", &tmp1))
782 r = ikev2_initiate_rekey_child_sa (vm, tmp1);
789 r = clib_error_return (0, "parse error: '%U'",
790 format_unformat_error, line_input);
794 unformat_free (line_input);
798 VLIB_CLI_COMMAND (ikev2_initiate_command, static) = {
799 .path = "ikev2 initiate",
801 "ikev2 initiate sa-init <profile id>\n"
802 "ikev2 initiate del-child-sa <child sa ispi>\n"
803 "ikev2 initiate del-sa <sa ispi>\n"
804 "ikev2 initiate rekey-child-sa <child sa ispi>\n",
805 .function = ikev2_initiate_command_fn,
808 static clib_error_t *
809 ikev2_set_log_level_command_fn (vlib_main_t * vm,
810 unformat_input_t * input,
811 vlib_cli_command_t * cmd)
813 unformat_input_t _line_input, *line_input = &_line_input;
814 u32 log_level = IKEV2_LOG_NONE;
815 clib_error_t *error = 0;
817 /* Get a line of input. */
818 if (!unformat_user (input, unformat_line_input, line_input))
821 if (!unformat (line_input, "%d", &log_level))
823 error = clib_error_return (0, "unknown input '%U'",
824 format_unformat_error, line_input);
827 int rc = ikev2_set_log_level (log_level);
829 error = clib_error_return (0, "setting log level failed!");
832 unformat_free (line_input);
836 VLIB_CLI_COMMAND (ikev2_set_log_level_command, static) = {
837 .path = "ikev2 set logging level",
838 .function = ikev2_set_log_level_command_fn,
839 .short_help = "ikev2 set logging level <0-5>",
843 * fd.io coding-style-patch-verification: ON
846 * eval: (c-set-style "gnu")