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, "%U", format_ikev2_id_type, id->type);
32 if (id->type == IKEV2_ID_TYPE_ID_FQDN ||
33 id->type == IKEV2_ID_TYPE_ID_RFC822_ADDR)
35 s = format (s, " %v", id->data);
40 format (s, " %U", format_hex_bytes, &id->data,
41 (uword) (vec_len (id->data)));
48 format_ikev2_traffic_selector (u8 * s, va_list * va)
50 ikev2_ts_t *ts = va_arg (*va, ikev2_ts_t *);
51 u32 index = va_arg (*va, u32);
53 s = format (s, "%u type %u protocol_id %u addr "
54 "%U - %U port %u - %u\n",
55 index, ts->ts_type, ts->protocol_id,
56 format_ip_address, &ts->start_addr,
57 format_ip_address, &ts->end_addr,
58 clib_net_to_host_u16 (ts->start_port),
59 clib_net_to_host_u16 (ts->end_port));
64 format_ikev2_child_sa (u8 * s, va_list * va)
66 ikev2_child_sa_t *child = va_arg (*va, ikev2_child_sa_t *);
67 u32 index = va_arg (*va, u32);
69 ikev2_sa_transform_t *tr;
72 u32 indent = format_get_indent (s);
75 s = format (s, "child sa %u:", index);
77 tr = ikev2_sa_get_td_for_type (child->r_proposals,
78 IKEV2_TRANSFORM_TYPE_ENCR);
79 c = format (c, "%U ", format_ikev2_sa_transform, tr);
81 tr = ikev2_sa_get_td_for_type (child->r_proposals,
82 IKEV2_TRANSFORM_TYPE_INTEG);
83 c = format (c, "%U ", format_ikev2_sa_transform, tr);
85 tr = ikev2_sa_get_td_for_type (child->r_proposals,
86 IKEV2_TRANSFORM_TYPE_ESN);
87 c = format (c, "%U ", format_ikev2_sa_transform, tr);
89 s = format (s, "%v\n", c);
92 s = format (s, "%Uspi(i) %lx spi(r) %lx\n", format_white_space, indent,
93 child->i_proposals ? child->i_proposals[0].spi : 0,
94 child->r_proposals ? child->r_proposals[0].spi : 0);
96 s = format (s, "%USK_e i:%U\n%Ur:%U\n",
97 format_white_space, indent,
98 format_hex_bytes, child->sk_ei, vec_len (child->sk_ei),
99 format_white_space, indent + 6,
100 format_hex_bytes, child->sk_er, vec_len (child->sk_er));
103 s = format (s, "%USK_a i:%U\n%Ur:%U\n",
104 format_white_space, indent,
105 format_hex_bytes, child->sk_ai, vec_len (child->sk_ai),
106 format_white_space, indent + 6,
107 format_hex_bytes, child->sk_ar, vec_len (child->sk_ar));
109 s = format (s, "%Utraffic selectors (i):", format_white_space, indent);
110 vec_foreach (ts, child->tsi)
111 s = format (s, "%U", format_ikev2_traffic_selector, ts, ts - child->tsi);
112 s = format (s, "%Utraffic selectors (r):", format_white_space, indent);
113 vec_foreach (ts, child->tsr)
114 s = format (s, "%U", format_ikev2_traffic_selector, ts, ts - child->tsr);
119 format_ikev2_sa (u8 * s, va_list * va)
121 ikev2_sa_t *sa = va_arg (*va, ikev2_sa_t *);
122 int details = va_arg (*va, int);
123 ikev2_sa_transform_t *tr;
124 ikev2_child_sa_t *child;
127 s = format (s, "iip %U ispi %lx rip %U rspi %lx",
128 format_ip_address, &sa->iaddr, sa->ispi,
129 format_ip_address, &sa->raddr, sa->rspi);
133 s = format (s, "\n%U", format_white_space, indent);
135 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
136 s = format (s, "%U ", format_ikev2_sa_transform, tr);
138 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
139 s = format (s, "%U ", format_ikev2_sa_transform, tr);
141 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
142 s = format (s, "%U ", format_ikev2_sa_transform, tr);
144 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_DH);
145 s = format (s, "%U", format_ikev2_sa_transform, tr);
147 s = format (s, "\n%U", format_white_space, indent);
149 s = format (s, "nonce i:%U\n%Ur:%U\n",
150 format_hex_bytes, sa->i_nonce, vec_len (sa->i_nonce),
151 format_white_space, indent + 6,
152 format_hex_bytes, sa->r_nonce, vec_len (sa->r_nonce));
154 s = format (s, "%USK_d %U\n", format_white_space, indent,
155 format_hex_bytes, sa->sk_d, vec_len (sa->sk_d));
158 s = format (s, "%USK_a i:%U\n%Ur:%U\n",
159 format_white_space, indent,
160 format_hex_bytes, sa->sk_ai, vec_len (sa->sk_ai),
161 format_white_space, indent + 6,
162 format_hex_bytes, sa->sk_ar, vec_len (sa->sk_ar));
164 s = format (s, "%USK_e i:%U\n%Ur:%U\n",
165 format_white_space, indent,
166 format_hex_bytes, sa->sk_ei, vec_len (sa->sk_ei),
167 format_white_space, indent + 6,
168 format_hex_bytes, sa->sk_er, vec_len (sa->sk_er));
169 s = format (s, "%USK_p i:%U\n%Ur:%U\n",
170 format_white_space, indent,
171 format_hex_bytes, sa->sk_pi, vec_len (sa->sk_pi),
172 format_white_space, indent + 6,
173 format_hex_bytes, sa->sk_pr, vec_len (sa->sk_pr));
175 s = format (s, "%Uidentifier (i) %U\n",
176 format_white_space, indent,
177 format_ikev2_id_type_and_data, &sa->i_id);
178 s = format (s, "%Uidentifier (r) %U\n",
179 format_white_space, indent,
180 format_ikev2_id_type_and_data, &sa->r_id);
182 vec_foreach (child, sa->childs)
184 s = format (s, "%U%U", format_white_space, indent + 2,
185 format_ikev2_child_sa, child, child - sa->childs);
191 static clib_error_t *
192 show_ikev2_sa_command_fn (vlib_main_t * vm,
193 unformat_input_t * input, vlib_cli_command_t * cmd)
195 unformat_input_t _line_input, *line_input = &_line_input;
196 ikev2_main_t *km = &ikev2_main;
197 ikev2_main_per_thread_data_t *tkm;
201 int details = 0, show_one = 0;
203 if (unformat_user (input, unformat_line_input, line_input))
205 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
207 if (unformat (line_input, "rspi %lx", &rspi))
211 else if (unformat (line_input, "details"))
216 unformat_free (line_input);
219 vec_foreach (tkm, km->per_thread_data)
222 pool_foreach (sa, tkm->sas, ({
225 if (sa->rspi == rspi)
227 s = format (s, "%U\n", format_ikev2_sa, sa, 1);
232 s = format (s, "%U\n", format_ikev2_sa, sa, details);
237 vlib_cli_output (vm, "%v", s);
243 VLIB_CLI_COMMAND (show_ikev2_sa_command, static) = {
244 .path = "show ikev2 sa",
245 .short_help = "show ikev2 sa [rspi <rspi>] [details]",
246 .function = show_ikev2_sa_command_fn,
251 unformat_ikev2_token (unformat_input_t * input, va_list * va)
253 u8 **string_return = va_arg (*va, u8 **);
254 const char *token_chars = "a-zA-Z0-9_";
257 /* if string_return was already allocated (eg. because of a previous
258 * partial match with a successful unformat_token()), we must free it
259 * before reusing the pointer, otherwise we'll be leaking memory
261 vec_free (*string_return);
264 return unformat_user (input, unformat_token, token_chars, string_return);
267 static clib_error_t *
268 ikev2_profile_add_del_command_fn (vlib_main_t * vm,
269 unformat_input_t * input,
270 vlib_cli_command_t * cmd)
272 vnet_main_t *vnm = vnet_get_main ();
273 unformat_input_t _line_input, *line_input = &_line_input;
278 u32 tmp1, tmp2, tmp3;
280 ip_address_t ip, end_addr;
281 u32 responder_sw_if_index = (u32) ~ 0;
282 u32 tun_sw_if_index = (u32) ~ 0;
283 ikev2_transform_encr_type_t crypto_alg;
284 ikev2_transform_integ_type_t integ_alg;
285 ikev2_transform_dh_type_t dh_type;
287 if (!unformat_user (input, unformat_line_input, line_input))
290 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
292 if (unformat (line_input, "add %U", unformat_ikev2_token, &name))
294 r = ikev2_add_del_profile (vm, name, 1);
297 else if (unformat (line_input, "del %U", unformat_ikev2_token, &name))
299 r = ikev2_add_del_profile (vm, name, 0);
302 else if (unformat (line_input, "set %U auth shared-key-mic string %v",
303 unformat_ikev2_token, &name, &data))
306 ikev2_set_profile_auth (vm, name,
307 IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
311 else if (unformat (line_input, "set %U auth shared-key-mic hex %U",
312 unformat_ikev2_token, &name,
313 unformat_hex_string, &data))
316 ikev2_set_profile_auth (vm, name,
317 IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
321 else if (unformat (line_input, "set %U auth rsa-sig cert-file %v",
322 unformat_ikev2_token, &name, &data))
325 ikev2_set_profile_auth (vm, name, IKEV2_AUTH_METHOD_RSA_SIG, data,
329 else if (unformat (line_input, "set %U id local %U %U",
330 unformat_ikev2_token, &name,
331 unformat_ikev2_id_type, &id_type,
332 unformat_ip_address, &ip))
334 data = vec_new (u8, ip_address_size (&ip));
335 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
337 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
340 else if (unformat (line_input, "set %U id local %U 0x%U",
341 unformat_ikev2_token, &name,
342 unformat_ikev2_id_type, &id_type,
343 unformat_hex_string, &data))
346 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
349 else if (unformat (line_input, "set %U id local %U %v",
350 unformat_ikev2_token, &name,
351 unformat_ikev2_id_type, &id_type, &data))
354 ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
357 else if (unformat (line_input, "set %U id remote %U %U",
358 unformat_ikev2_token, &name,
359 unformat_ikev2_id_type, &id_type,
360 unformat_ip_address, &ip))
362 data = vec_new (u8, ip_address_size (&ip));
363 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
364 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
368 else if (unformat (line_input, "set %U id remote %U 0x%U",
369 unformat_ikev2_token, &name,
370 unformat_ikev2_id_type, &id_type,
371 unformat_hex_string, &data))
373 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
377 else if (unformat (line_input, "set %U id remote %U %v",
378 unformat_ikev2_token, &name,
379 unformat_ikev2_id_type, &id_type, &data))
381 r = ikev2_set_profile_id (vm, name, (u8) id_type, data, /*remote */
385 else if (unformat (line_input, "set %U traffic-selector local "
386 "ip-range %U - %U port-range %u - %u protocol %u",
387 unformat_ikev2_token, &name,
388 unformat_ip_address, &ip,
389 unformat_ip_address, &end_addr, &tmp1, &tmp2, &tmp3))
392 ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
393 ip, end_addr, /*local */ 1);
396 else if (unformat (line_input, "set %U traffic-selector remote "
397 "ip-range %U - %U port-range %u - %u protocol %u",
398 unformat_ikev2_token, &name,
399 unformat_ip_address, &ip,
400 unformat_ip_address, &end_addr, &tmp1, &tmp2, &tmp3))
403 ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
404 ip, end_addr, /*remote */ 0);
407 else if (unformat (line_input, "set %U responder %U %U",
408 unformat_ikev2_token, &name,
409 unformat_vnet_sw_interface, vnm,
410 &responder_sw_if_index, unformat_ip_address, &ip))
413 ikev2_set_profile_responder (vm, name, responder_sw_if_index, ip);
416 else if (unformat (line_input, "set %U tunnel %U",
417 unformat_ikev2_token, &name,
418 unformat_vnet_sw_interface, vnm, &tun_sw_if_index))
420 r = ikev2_set_profile_tunnel_interface (vm, name, tun_sw_if_index);
426 "set %U ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
427 unformat_ikev2_token, &name,
428 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
429 unformat_ikev2_transform_integ_type, &integ_alg,
430 unformat_ikev2_transform_dh_type, &dh_type))
433 ikev2_set_profile_ike_transforms (vm, name, crypto_alg, integ_alg,
440 "set %U ike-crypto-alg %U %u ike-dh %U",
441 unformat_ikev2_token, &name,
442 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
443 unformat_ikev2_transform_dh_type, &dh_type))
446 ikev2_set_profile_ike_transforms (vm, name, crypto_alg,
447 IKEV2_TRANSFORM_INTEG_TYPE_NONE,
454 "set %U esp-crypto-alg %U %u esp-integ-alg %U",
455 unformat_ikev2_token, &name,
456 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
457 unformat_ikev2_transform_integ_type, &integ_alg))
460 ikev2_set_profile_esp_transforms (vm, name, crypto_alg, integ_alg,
466 "set %U esp-crypto-alg %U %u",
467 unformat_ikev2_token, &name,
468 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1))
471 ikev2_set_profile_esp_transforms (vm, name, crypto_alg, 0, tmp1);
474 else if (unformat (line_input, "set %U sa-lifetime %lu %u %u %lu",
475 unformat_ikev2_token, &name,
476 &tmp4, &tmp1, &tmp2, &tmp5))
479 ikev2_set_profile_sa_lifetime (vm, name, tmp4, tmp1, tmp2, tmp5);
482 else if (unformat (line_input, "set %U udp-encap",
483 unformat_ikev2_token, &name))
485 r = ikev2_set_profile_udp_encap (vm, name);
488 else if (unformat (line_input, "set %U ipsec-over-udp port %u",
489 unformat_ikev2_token, &name, &tmp1))
491 int rv = ikev2_set_profile_ipsec_udp_port (vm, name, tmp1, 1);
493 r = clib_error_return (0, "Error: %U", format_vnet_api_errno, rv);
500 r = clib_error_return (0, "parse error: '%U'",
501 format_unformat_error, line_input);
506 unformat_free (line_input);
511 VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = {
512 .path = "ikev2 profile",
514 "ikev2 profile [add|del] <id>\n"
515 "ikev2 profile set <id> auth [rsa-sig|shared-key-mic] [cert-file|string|hex]"
517 "ikev2 profile set <id> id <local|remote> <type> <data>\n"
518 "ikev2 profile set <id> tunnel <interface>\n"
519 "ikev2 profile set <id> udp-encap\n"
520 "ikev2 profile set <id> traffic-selector <local|remote> ip-range "
521 "<start-addr> - <end-addr> port-range <start-port> - <end-port> "
522 "protocol <protocol-number>\n"
523 "ikev2 profile set <id> responder <interface> <addr>\n"
524 "ikev2 profile set <id> ike-crypto-alg <crypto alg> <key size> ike-integ-alg <integ alg> ike-dh <dh type>\n"
525 "ikev2 profile set <id> esp-crypto-alg <crypto alg> <key size> "
526 "[esp-integ-alg <integ alg>]\n"
527 "ikev2 profile set <id> sa-lifetime <seconds> <jitter> <handover> <max bytes>",
528 .function = ikev2_profile_add_del_command_fn,
532 static clib_error_t *
533 show_ikev2_profile_command_fn (vlib_main_t * vm,
534 unformat_input_t * input,
535 vlib_cli_command_t * cmd)
537 ikev2_main_t *km = &ikev2_main;
541 pool_foreach (p, km->profiles, ({
542 vlib_cli_output(vm, "profile %v", p->name);
547 vlib_cli_output(vm, " auth-method %U auth data 0x%U",
548 format_ikev2_auth_method, p->auth.method,
549 format_hex_bytes, p->auth.data, vec_len(p->auth.data));
551 vlib_cli_output(vm, " auth-method %U auth data %v",
552 format_ikev2_auth_method, p->auth.method, p->auth.data);
557 if (p->loc_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR)
558 vlib_cli_output(vm, " local id-type %U data %U",
559 format_ikev2_id_type, p->loc_id.type,
560 format_ip_address, p->loc_id.data);
561 else if (p->loc_id.type == IKEV2_ID_TYPE_ID_KEY_ID)
562 vlib_cli_output(vm, " local id-type %U data 0x%U",
563 format_ikev2_id_type, p->loc_id.type,
564 format_hex_bytes, p->loc_id.data,
565 vec_len(p->loc_id.data));
567 vlib_cli_output(vm, " local id-type %U data %v",
568 format_ikev2_id_type, p->loc_id.type, p->loc_id.data);
573 if (p->rem_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR)
574 vlib_cli_output(vm, " remote id-type %U data %U",
575 format_ikev2_id_type, p->rem_id.type,
576 format_ip_address, p->rem_id.data);
577 else if (p->rem_id.type == IKEV2_ID_TYPE_ID_KEY_ID)
578 vlib_cli_output(vm, " remote id-type %U data 0x%U",
579 format_ikev2_id_type, p->rem_id.type,
580 format_hex_bytes, p->rem_id.data,
581 vec_len(p->rem_id.data));
583 vlib_cli_output(vm, " remote id-type %U data %v",
584 format_ikev2_id_type, p->rem_id.type, p->rem_id.data);
587 if (!ip_address_is_zero (&p->loc_ts.start_addr))
588 vlib_cli_output(vm, " local traffic-selector addr %U - %U port %u - %u"
590 format_ip_address, &p->loc_ts.start_addr,
591 format_ip_address, &p->loc_ts.end_addr,
592 p->loc_ts.start_port, p->loc_ts.end_port,
593 p->loc_ts.protocol_id);
595 if (!ip_address_is_zero (&p->rem_ts.start_addr))
596 vlib_cli_output(vm, " remote traffic-selector addr %U - %U port %u - %u"
598 format_ip_address, &p->rem_ts.start_addr,
599 format_ip_address, &p->rem_ts.end_addr,
600 p->rem_ts.start_port, p->rem_ts.end_port,
601 p->rem_ts.protocol_id);
602 if (~0 != p->tun_itf)
603 vlib_cli_output(vm, " protected tunnel %U",
604 format_vnet_sw_if_index_name, vnet_get_main(), p->tun_itf);
605 if (~0 != p->responder.sw_if_index)
606 vlib_cli_output(vm, " responder %U %U",
607 format_vnet_sw_if_index_name, vnet_get_main(), p->responder.sw_if_index,
608 format_ip_address, &p->responder.addr);
610 vlib_cli_output(vm, " udp-encap");
612 if (p->ipsec_over_udp_port != IPSEC_UDP_PORT_NONE)
613 vlib_cli_output(vm, " ipsec-over-udp port %d", p->ipsec_over_udp_port);
615 if (p->ike_ts.crypto_alg || p->ike_ts.integ_alg || p->ike_ts.dh_type || p->ike_ts.crypto_key_size)
616 vlib_cli_output(vm, " ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
617 format_ikev2_transform_encr_type, p->ike_ts.crypto_alg, p->ike_ts.crypto_key_size,
618 format_ikev2_transform_integ_type, p->ike_ts.integ_alg,
619 format_ikev2_transform_dh_type, p->ike_ts.dh_type);
621 if (p->esp_ts.crypto_alg || p->esp_ts.integ_alg || p->esp_ts.dh_type)
622 vlib_cli_output(vm, " esp-crypto-alg %U %u esp-integ-alg %U",
623 format_ikev2_transform_encr_type, p->esp_ts.crypto_alg, p->esp_ts.crypto_key_size,
624 format_ikev2_transform_integ_type, p->esp_ts.integ_alg);
626 vlib_cli_output(vm, " lifetime %d jitter %d handover %d maxdata %d",
627 p->lifetime, p->lifetime_jitter, p->handover, p->lifetime_maxdata);
635 VLIB_CLI_COMMAND (show_ikev2_profile_command, static) = {
636 .path = "show ikev2 profile",
637 .short_help = "show ikev2 profile",
638 .function = show_ikev2_profile_command_fn,
642 static clib_error_t *
643 set_ikev2_liveness_period_fn (vlib_main_t * vm,
644 unformat_input_t * input,
645 vlib_cli_command_t * cmd)
647 unformat_input_t _line_input, *line_input = &_line_input;
649 u32 period = 0, max_retries = 0;
651 if (!unformat_user (input, unformat_line_input, line_input))
654 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
656 if (unformat (line_input, "%d %d", &period, &max_retries))
658 r = ikev2_set_liveness_params (period, max_retries);
665 r = clib_error_return (0, "parse error: '%U'",
666 format_unformat_error, line_input);
669 unformat_free (line_input);
674 VLIB_CLI_COMMAND (set_ikev2_liveness_command, static) = {
675 .path = "ikev2 set liveness",
676 .short_help = "ikev2 set liveness <period> <max-retires>",
677 .function = set_ikev2_liveness_period_fn,
681 static clib_error_t *
682 set_ikev2_local_key_command_fn (vlib_main_t * vm,
683 unformat_input_t * input,
684 vlib_cli_command_t * cmd)
686 unformat_input_t _line_input, *line_input = &_line_input;
690 if (!unformat_user (input, unformat_line_input, line_input))
693 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
695 if (unformat (line_input, "%s", &data))
697 r = ikev2_set_local_key (vm, data);
704 r = clib_error_return (0, "parse error: '%U'",
705 format_unformat_error, line_input);
709 unformat_free (line_input);
714 VLIB_CLI_COMMAND (set_ikev2_local_key_command, static) = {
715 .path = "set ikev2 local key",
717 "set ikev2 local key <file>",
718 .function = set_ikev2_local_key_command_fn,
723 static clib_error_t *
724 ikev2_initiate_command_fn (vlib_main_t * vm,
725 unformat_input_t * input, vlib_cli_command_t * cmd)
727 unformat_input_t _line_input, *line_input = &_line_input;
733 if (!unformat_user (input, unformat_line_input, line_input))
736 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
738 if (unformat (line_input, "sa-init %U", unformat_ikev2_token, &name))
740 r = ikev2_initiate_sa_init (vm, name);
743 else if (unformat (line_input, "del-child-sa %x", &tmp1))
745 r = ikev2_initiate_delete_child_sa (vm, tmp1);
748 else if (unformat (line_input, "del-sa %lx", &tmp2))
750 r = ikev2_initiate_delete_ike_sa (vm, tmp2);
753 else if (unformat (line_input, "rekey-child-sa %x", &tmp1))
755 r = ikev2_initiate_rekey_child_sa (vm, tmp1);
762 r = clib_error_return (0, "parse error: '%U'",
763 format_unformat_error, line_input);
767 unformat_free (line_input);
772 VLIB_CLI_COMMAND (ikev2_initiate_command, static) = {
773 .path = "ikev2 initiate",
775 "ikev2 initiate sa-init <profile id>\n"
776 "ikev2 initiate del-child-sa <child sa ispi>\n"
777 "ikev2 initiate del-sa <sa ispi>\n"
778 "ikev2 initiate rekey-child-sa <profile id> <child sa ispi>\n",
779 .function = ikev2_initiate_command_fn,
784 ikev2_cli_reference (void)
788 static clib_error_t *
789 ikev2_set_log_level_command_fn (vlib_main_t * vm,
790 unformat_input_t * input,
791 vlib_cli_command_t * cmd)
793 unformat_input_t _line_input, *line_input = &_line_input;
794 u32 log_level = IKEV2_LOG_NONE;
795 clib_error_t *error = 0;
797 /* Get a line of input. */
798 if (!unformat_user (input, unformat_line_input, line_input))
801 if (!unformat (line_input, "%d", &log_level))
803 error = clib_error_return (0, "unknown input '%U'",
804 format_unformat_error, line_input);
807 int rc = ikev2_set_log_level (log_level);
809 error = clib_error_return (0, "setting log level failed!");
812 unformat_free (line_input);
817 VLIB_CLI_COMMAND (ikev2_set_log_level_command, static) = {
818 .path = "ikev2 set logging level",
819 .function = ikev2_set_log_level_command_fn,
820 .short_help = "ikev2 set logging level <0-5>",
825 * fd.io coding-style-patch-verification: ON
828 * eval: (c-set-style "gnu")