virtio: fix the out of order descriptors in tx
[vpp.git] / src / plugins / ikev2 / ikev2_cli.c
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 #include <vlib/vlib.h>
16 #include <vnet/vnet.h>
17 #include <vnet/pg/pg.h>
18 #include <vppinfra/error.h>
19 #include <vnet/udp/udp.h>
20 #include <plugins/ikev2/ikev2.h>
21 #include <plugins/ikev2/ikev2_priv.h>
22
23 u8 *
24 format_ikev2_id_type_and_data (u8 * s, va_list * args)
25 {
26   ikev2_id_t *id = va_arg (*args, ikev2_id_t *);
27
28   if (id->type == 0 || vec_len (id->data) == 0)
29     return format (s, "none");
30
31   s = format (s, "%U", format_ikev2_id_type, id->type);
32
33   if (id->type == IKEV2_ID_TYPE_ID_FQDN ||
34       id->type == IKEV2_ID_TYPE_ID_RFC822_ADDR)
35     {
36       s = format (s, " %v", id->data);
37     }
38   else
39     {
40       s =
41         format (s, " %U", format_hex_bytes, &id->data,
42                 (uword) (vec_len (id->data)));
43     }
44
45   return s;
46 }
47
48
49 static clib_error_t *
50 show_ikev2_sa_command_fn (vlib_main_t * vm,
51                           unformat_input_t * input, vlib_cli_command_t * cmd)
52 {
53   ikev2_main_t *km = &ikev2_main;
54   ikev2_main_per_thread_data_t *tkm;
55   ikev2_sa_t *sa;
56   ikev2_ts_t *ts;
57   ikev2_child_sa_t *child;
58   ikev2_sa_transform_t *tr;
59
60   vec_foreach (tkm, km->per_thread_data)
61   {
62     /* *INDENT-OFF* */
63     pool_foreach (sa, tkm->sas, ({
64       u8 * s = 0;
65       vlib_cli_output(vm, " iip %U ispi %lx rip %U rspi %lx",
66                       format_ip4_address, &sa->iaddr, sa->ispi,
67                       format_ip4_address, &sa->raddr, sa->rspi);
68
69        tr = ikev2_sa_get_td_for_type(sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
70        s = format(s, "%U ", format_ikev2_sa_transform, tr);
71
72        tr = ikev2_sa_get_td_for_type(sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
73        s = format(s, "%U ", format_ikev2_sa_transform, tr);
74
75        tr = ikev2_sa_get_td_for_type(sa->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
76        s = format(s, "%U ", format_ikev2_sa_transform, tr);
77
78        tr = ikev2_sa_get_td_for_type(sa->r_proposals, IKEV2_TRANSFORM_TYPE_DH);
79        s = format(s, "%U ", format_ikev2_sa_transform, tr);
80
81       vlib_cli_output(vm, " %v", s);
82       vec_free(s);
83
84       vlib_cli_output(vm, "  nonce i:%U\n        r:%U",
85                       format_hex_bytes, sa->i_nonce,  vec_len(sa->i_nonce),
86                       format_hex_bytes, sa->r_nonce,  vec_len(sa->r_nonce));
87
88       vlib_cli_output(vm, "  SK_d    %U",
89                       format_hex_bytes, sa->sk_d,  vec_len(sa->sk_d));
90       vlib_cli_output(vm, "  SK_a  i:%U\n        r:%U",
91                       format_hex_bytes, sa->sk_ai, vec_len(sa->sk_ai),
92                       format_hex_bytes, sa->sk_ar, vec_len(sa->sk_ar));
93       vlib_cli_output(vm, "  SK_e  i:%U\n        r:%U",
94                       format_hex_bytes, sa->sk_ei, vec_len(sa->sk_ei),
95                       format_hex_bytes, sa->sk_er, vec_len(sa->sk_er));
96       vlib_cli_output(vm, "  SK_p  i:%U\n        r:%U",
97                       format_hex_bytes, sa->sk_pi, vec_len(sa->sk_pi),
98                       format_hex_bytes, sa->sk_pr, vec_len(sa->sk_pr));
99
100       vlib_cli_output(vm, "  identifier (i) %U",
101                       format_ikev2_id_type_and_data, &sa->i_id);
102       vlib_cli_output(vm, "  identifier (r) %U",
103                       format_ikev2_id_type_and_data, &sa->r_id);
104
105       vec_foreach(child, sa->childs)
106         {
107           vlib_cli_output(vm, "  child sa %u:", child - sa->childs);
108
109           tr = ikev2_sa_get_td_for_type(child->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
110           s = format(s, "%U ", format_ikev2_sa_transform, tr);
111
112           tr = ikev2_sa_get_td_for_type(child->r_proposals, IKEV2_TRANSFORM_TYPE_INTEG);
113           s = format(s, "%U ", format_ikev2_sa_transform, tr);
114
115           tr = ikev2_sa_get_td_for_type(child->r_proposals, IKEV2_TRANSFORM_TYPE_ESN);
116           s = format(s, "%U ", format_ikev2_sa_transform, tr);
117
118           vlib_cli_output(vm, "    %v", s);
119           vec_free(s);
120
121           vlib_cli_output(vm, "    spi(i) %lx spi(r) %lx",
122                           child->i_proposals ? child->i_proposals[0].spi : 0,
123                           child->r_proposals ? child->r_proposals[0].spi : 0);
124
125           vlib_cli_output(vm, "    SK_e  i:%U\n          r:%U",
126                           format_hex_bytes, child->sk_ei, vec_len(child->sk_ei),
127                           format_hex_bytes, child->sk_er, vec_len(child->sk_er));
128           if (child->sk_ai)
129             {
130               vlib_cli_output(vm, "    SK_a  i:%U\n          r:%U",
131                               format_hex_bytes, child->sk_ai, vec_len(child->sk_ai),
132                               format_hex_bytes, child->sk_ar, vec_len(child->sk_ar));
133               vlib_cli_output(vm, "    traffic selectors (i):");
134             }
135           vec_foreach(ts, child->tsi)
136             {
137               vlib_cli_output(vm, "      %u type %u protocol_id %u addr "
138                               "%U - %U port %u - %u",
139                               ts - child->tsi,
140                               ts->ts_type, ts->protocol_id,
141                               format_ip4_address, &ts->start_addr,
142                               format_ip4_address, &ts->end_addr,
143                               clib_net_to_host_u16( ts->start_port),
144                               clib_net_to_host_u16( ts->end_port));
145             }
146           vlib_cli_output(vm, "    traffic selectors (r):");
147           vec_foreach(ts, child->tsr)
148             {
149               vlib_cli_output(vm, "      %u type %u protocol_id %u addr "
150                               "%U - %U port %u - %u",
151                               ts - child->tsr,
152                               ts->ts_type, ts->protocol_id,
153                               format_ip4_address, &ts->start_addr,
154                               format_ip4_address, &ts->end_addr,
155                               clib_net_to_host_u16( ts->start_port),
156                               clib_net_to_host_u16( ts->end_port));
157             }
158         }
159       vlib_cli_output(vm, "");
160     }));
161     /* *INDENT-ON* */
162   }
163   return 0;
164 }
165
166 /* *INDENT-OFF* */
167 VLIB_CLI_COMMAND (show_ikev2_sa_command, static) = {
168     .path = "show ikev2 sa",
169     .short_help = "show ikev2 sa",
170     .function = show_ikev2_sa_command_fn,
171 };
172 /* *INDENT-ON* */
173
174 static clib_error_t *
175 ikev2_profile_add_del_command_fn (vlib_main_t * vm,
176                                   unformat_input_t * input,
177                                   vlib_cli_command_t * cmd)
178 {
179   vnet_main_t *vnm = vnet_get_main ();
180   unformat_input_t _line_input, *line_input = &_line_input;
181   u8 *name = 0;
182   clib_error_t *r = 0;
183   u32 id_type;
184   u8 *data = 0;
185   u32 tmp1, tmp2, tmp3;
186   u64 tmp4, tmp5;
187   ip4_address_t ip4;
188   ip4_address_t end_addr;
189   u32 responder_sw_if_index = (u32) ~ 0;
190   u32 tun_sw_if_index = (u32) ~ 0;
191   ip4_address_t responder_ip4;
192   ikev2_transform_encr_type_t crypto_alg;
193   ikev2_transform_integ_type_t integ_alg;
194   ikev2_transform_dh_type_t dh_type;
195
196   const char *valid_chars = "a-zA-Z0-9_";
197
198   if (!unformat_user (input, unformat_line_input, line_input))
199     return 0;
200
201   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
202     {
203       if (unformat (line_input, "add %U", unformat_token, valid_chars, &name))
204         {
205           r = ikev2_add_del_profile (vm, name, 1);
206           goto done;
207         }
208       else
209         if (unformat
210             (line_input, "del %U", unformat_token, valid_chars, &name))
211         {
212           r = ikev2_add_del_profile (vm, name, 0);
213           goto done;
214         }
215       else if (unformat (line_input, "set %U auth shared-key-mic string %v",
216                          unformat_token, valid_chars, &name, &data))
217         {
218           r =
219             ikev2_set_profile_auth (vm, name,
220                                     IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
221                                     0);
222           goto done;
223         }
224       else if (unformat (line_input, "set %U auth shared-key-mic hex %U",
225                          unformat_token, valid_chars, &name,
226                          unformat_hex_string, &data))
227         {
228           r =
229             ikev2_set_profile_auth (vm, name,
230                                     IKEV2_AUTH_METHOD_SHARED_KEY_MIC, data,
231                                     1);
232           goto done;
233         }
234       else if (unformat (line_input, "set %U auth rsa-sig cert-file %v",
235                          unformat_token, valid_chars, &name, &data))
236         {
237           r =
238             ikev2_set_profile_auth (vm, name, IKEV2_AUTH_METHOD_RSA_SIG, data,
239                                     0);
240           goto done;
241         }
242       else if (unformat (line_input, "set %U id local %U %U",
243                          unformat_token, valid_chars, &name,
244                          unformat_ikev2_id_type, &id_type,
245                          unformat_ip4_address, &ip4))
246         {
247           data = vec_new (u8, 4);
248           clib_memcpy (data, ip4.as_u8, 4);
249           r =
250             ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
251           goto done;
252         }
253       else if (unformat (line_input, "set %U id local %U 0x%U",
254                          unformat_token, valid_chars, &name,
255                          unformat_ikev2_id_type, &id_type,
256                          unformat_hex_string, &data))
257         {
258           r =
259             ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
260           goto done;
261         }
262       else if (unformat (line_input, "set %U id local %U %v",
263                          unformat_token, valid_chars, &name,
264                          unformat_ikev2_id_type, &id_type, &data))
265         {
266           r =
267             ikev2_set_profile_id (vm, name, (u8) id_type, data, /*local */ 1);
268           goto done;
269         }
270       else if (unformat (line_input, "set %U id remote %U %U",
271                          unformat_token, valid_chars, &name,
272                          unformat_ikev2_id_type, &id_type,
273                          unformat_ip4_address, &ip4))
274         {
275           data = vec_new (u8, 4);
276           clib_memcpy (data, ip4.as_u8, 4);
277           r = ikev2_set_profile_id (vm, name, (u8) id_type, data,       /*remote */
278                                     0);
279           goto done;
280         }
281       else if (unformat (line_input, "set %U id remote %U 0x%U",
282                          unformat_token, valid_chars, &name,
283                          unformat_ikev2_id_type, &id_type,
284                          unformat_hex_string, &data))
285         {
286           r = ikev2_set_profile_id (vm, name, (u8) id_type, data,       /*remote */
287                                     0);
288           goto done;
289         }
290       else if (unformat (line_input, "set %U id remote %U %v",
291                          unformat_token, valid_chars, &name,
292                          unformat_ikev2_id_type, &id_type, &data))
293         {
294           r = ikev2_set_profile_id (vm, name, (u8) id_type, data,       /*remote */
295                                     0);
296           goto done;
297         }
298       else if (unformat (line_input, "set %U traffic-selector local "
299                          "ip-range %U - %U port-range %u - %u protocol %u",
300                          unformat_token, valid_chars, &name,
301                          unformat_ip4_address, &ip4,
302                          unformat_ip4_address, &end_addr,
303                          &tmp1, &tmp2, &tmp3))
304         {
305           r =
306             ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
307                                   ip4, end_addr, /*local */ 1);
308           goto done;
309         }
310       else if (unformat (line_input, "set %U traffic-selector remote "
311                          "ip-range %U - %U port-range %u - %u protocol %u",
312                          unformat_token, valid_chars, &name,
313                          unformat_ip4_address, &ip4,
314                          unformat_ip4_address, &end_addr,
315                          &tmp1, &tmp2, &tmp3))
316         {
317           r =
318             ikev2_set_profile_ts (vm, name, (u8) tmp3, (u16) tmp1, (u16) tmp2,
319                                   ip4, end_addr, /*remote */ 0);
320           goto done;
321         }
322       else if (unformat (line_input, "set %U responder %U %U",
323                          unformat_token, valid_chars, &name,
324                          unformat_vnet_sw_interface, vnm,
325                          &responder_sw_if_index, unformat_ip4_address,
326                          &responder_ip4))
327         {
328           r =
329             ikev2_set_profile_responder (vm, name, responder_sw_if_index,
330                                          responder_ip4);
331           goto done;
332         }
333       else if (unformat (line_input, "set %U tunnel %U",
334                          unformat_token, valid_chars, &name,
335                          unformat_vnet_sw_interface, vnm, &tun_sw_if_index))
336         {
337           r = ikev2_set_profile_tunnel_interface (vm, name, tun_sw_if_index);
338           goto done;
339         }
340       else
341         if (unformat
342             (line_input,
343              "set %U ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U",
344              unformat_token, valid_chars, &name,
345              unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
346              unformat_ikev2_transform_integ_type, &integ_alg,
347              unformat_ikev2_transform_dh_type, &dh_type))
348         {
349           r =
350             ikev2_set_profile_ike_transforms (vm, name, crypto_alg, integ_alg,
351                                               dh_type, tmp1);
352           goto done;
353         }
354       else
355         if (unformat
356             (line_input,
357              "set %U esp-crypto-alg %U %u esp-integ-alg %U esp-dh %U",
358              unformat_token, valid_chars, &name,
359              unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
360              unformat_ikev2_transform_integ_type, &integ_alg,
361              unformat_ikev2_transform_dh_type, &dh_type))
362         {
363           r =
364             ikev2_set_profile_esp_transforms (vm, name, crypto_alg, integ_alg,
365                                               dh_type, tmp1);
366           goto done;
367         }
368       else if (unformat
369                (line_input,
370                 "set %U esp-crypto-alg %U %u esp-dh %U",
371                 unformat_token, valid_chars, &name,
372                 unformat_ikev2_transform_encr_type, &crypto_alg, &tmp1,
373                 unformat_ikev2_transform_dh_type, &dh_type))
374         {
375           r =
376             ikev2_set_profile_esp_transforms (vm, name, crypto_alg, 0,
377                                               dh_type, tmp1);
378           goto done;
379         }
380       else if (unformat (line_input, "set %U sa-lifetime %lu %u %u %lu",
381                          unformat_token, valid_chars, &name,
382                          &tmp4, &tmp1, &tmp2, &tmp5))
383         {
384           r =
385             ikev2_set_profile_sa_lifetime (vm, name, tmp4, tmp1, tmp2, tmp5);
386           goto done;
387         }
388       else if (unformat (line_input, "set %U udp-encap",
389                          unformat_token, valid_chars, &name))
390         {
391           r = ikev2_set_profile_udp_encap (vm, name);
392           goto done;
393         }
394       else
395         break;
396     }
397
398   r = clib_error_return (0, "parse error: '%U'",
399                          format_unformat_error, line_input);
400
401 done:
402   vec_free (name);
403   vec_free (data);
404   unformat_free (line_input);
405   return r;
406 }
407
408 /* *INDENT-OFF* */
409 VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = {
410     .path = "ikev2 profile",
411     .short_help =
412     "ikev2 profile [add|del] <id>\n"
413     "ikev2 profile set <id> auth [rsa-sig|shared-key-mic] [cert-file|string|hex]"
414     " <data>\n"
415     "ikev2 profile set <id> id <local|remote> <type> <data>\n"
416     "ikev2 profile set <id> tunnel <interface>\n"
417     "ikev2 profile set <id> udp-encap\n"
418     "ikev2 profile set <id> traffic-selector <local|remote> ip-range "
419     "<start-addr> - <end-addr> port-range <start-port> - <end-port> "
420     "protocol <protocol-number>\n"
421     "ikev2 profile set <id> responder <interface> <addr>\n"
422     "ikev2 profile set <id> ike-crypto-alg <crypto alg> <key size> ike-integ-alg <integ alg> ike-dh <dh type>\n"
423     "ikev2 profile set <id> esp-crypto-alg <crypto alg> <key size> "
424       "[esp-integ-alg <integ alg>] esp-dh <dh type>\n"
425     "ikev2 profile set <id> sa-lifetime <seconds> <jitter> <handover> <max bytes>",
426     .function = ikev2_profile_add_del_command_fn,
427 };
428 /* *INDENT-ON* */
429
430 static clib_error_t *
431 show_ikev2_profile_command_fn (vlib_main_t * vm,
432                                unformat_input_t * input,
433                                vlib_cli_command_t * cmd)
434 {
435   ikev2_main_t *km = &ikev2_main;
436   ikev2_profile_t *p;
437
438   /* *INDENT-OFF* */
439   pool_foreach (p, km->profiles, ({
440     vlib_cli_output(vm, "profile %v", p->name);
441
442     if (p->auth.data)
443       {
444         if (p->auth.hex)
445           vlib_cli_output(vm, "  auth-method %U auth data 0x%U",
446                           format_ikev2_auth_method, p->auth.method,
447                           format_hex_bytes, p->auth.data, vec_len(p->auth.data));
448         else
449           vlib_cli_output(vm, "  auth-method %U auth data %v",
450                    format_ikev2_auth_method, p->auth.method, p->auth.data);
451       }
452
453     if (p->loc_id.data)
454       {
455         if (p->loc_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR)
456           vlib_cli_output(vm, "  local id-type %U data %U",
457                           format_ikev2_id_type, p->loc_id.type,
458                           format_ip4_address, p->loc_id.data);
459         else if (p->loc_id.type == IKEV2_ID_TYPE_ID_KEY_ID)
460           vlib_cli_output(vm, "  local id-type %U data 0x%U",
461                           format_ikev2_id_type, p->loc_id.type,
462                           format_hex_bytes, p->loc_id.data,
463                           vec_len(p->loc_id.data));
464         else
465           vlib_cli_output(vm, "  local id-type %U data %v",
466                           format_ikev2_id_type, p->loc_id.type, p->loc_id.data);
467       }
468
469     if (p->rem_id.data)
470       {
471         if (p->rem_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR)
472           vlib_cli_output(vm, "  remote id-type %U data %U",
473                           format_ikev2_id_type, p->rem_id.type,
474                           format_ip4_address, p->rem_id.data);
475         else if (p->rem_id.type == IKEV2_ID_TYPE_ID_KEY_ID)
476           vlib_cli_output(vm, "  remote id-type %U data 0x%U",
477                           format_ikev2_id_type, p->rem_id.type,
478                           format_hex_bytes, p->rem_id.data,
479                           vec_len(p->rem_id.data));
480         else
481           vlib_cli_output(vm, "  remote id-type %U data %v",
482                           format_ikev2_id_type, p->rem_id.type, p->rem_id.data);
483       }
484
485     if (p->loc_ts.end_addr.as_u32)
486       vlib_cli_output(vm, "  local traffic-selector addr %U - %U port %u - %u"
487                       " protocol %u",
488                       format_ip4_address, &p->loc_ts.start_addr,
489                       format_ip4_address, &p->loc_ts.end_addr,
490                       p->loc_ts.start_port, p->loc_ts.end_port,
491                       p->loc_ts.protocol_id);
492
493     if (p->rem_ts.end_addr.as_u32)
494       vlib_cli_output(vm, "  remote traffic-selector addr %U - %U port %u - %u"
495                       " protocol %u",
496                       format_ip4_address, &p->rem_ts.start_addr,
497                       format_ip4_address, &p->rem_ts.end_addr,
498                       p->rem_ts.start_port, p->rem_ts.end_port,
499                       p->rem_ts.protocol_id);
500     if (~0 != p->tun_itf)
501       vlib_cli_output(vm, "  protected tunnel %U",
502                       format_vnet_sw_if_index_name, vnet_get_main(), p->tun_itf);
503     if (p->udp_encap)
504       vlib_cli_output(vm, "  udp-encap");
505   }));
506   /* *INDENT-ON* */
507
508   return 0;
509 }
510
511 /* *INDENT-OFF* */
512 VLIB_CLI_COMMAND (show_ikev2_profile_command, static) = {
513     .path = "show ikev2 profile",
514     .short_help = "show ikev2 profile",
515     .function = show_ikev2_profile_command_fn,
516 };
517 /* *INDENT-ON* */
518
519 static clib_error_t *
520 set_ikev2_local_key_command_fn (vlib_main_t * vm,
521                                 unformat_input_t * input,
522                                 vlib_cli_command_t * cmd)
523 {
524   unformat_input_t _line_input, *line_input = &_line_input;
525   clib_error_t *r = 0;
526   u8 *data = 0;
527
528   if (!unformat_user (input, unformat_line_input, line_input))
529     return 0;
530
531   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
532     {
533       if (unformat (line_input, "%s", &data))
534         {
535           r = ikev2_set_local_key (vm, data);
536           goto done;
537         }
538       else
539         break;
540     }
541
542   r = clib_error_return (0, "parse error: '%U'",
543                          format_unformat_error, line_input);
544
545 done:
546   vec_free (data);
547   unformat_free (line_input);
548   return r;
549 }
550
551 /* *INDENT-OFF* */
552 VLIB_CLI_COMMAND (set_ikev2_local_key_command, static) = {
553     .path = "set ikev2 local key",
554     .short_help =
555     "set ikev2 local key <file>",
556     .function = set_ikev2_local_key_command_fn,
557 };
558 /* *INDENT-ON* */
559
560
561 static clib_error_t *
562 ikev2_initiate_command_fn (vlib_main_t * vm,
563                            unformat_input_t * input, vlib_cli_command_t * cmd)
564 {
565   unformat_input_t _line_input, *line_input = &_line_input;
566   clib_error_t *r = 0;
567   u8 *name = 0;
568   u32 tmp1;
569   u64 tmp2;
570
571   const char *valid_chars = "a-zA-Z0-9_";
572
573   if (!unformat_user (input, unformat_line_input, line_input))
574     return 0;
575
576   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
577     {
578       if (unformat
579           (line_input, "sa-init %U", unformat_token, valid_chars, &name))
580         {
581           r = ikev2_initiate_sa_init (vm, name);
582           goto done;
583         }
584       else if (unformat (line_input, "del-child-sa %x", &tmp1))
585         {
586           r = ikev2_initiate_delete_child_sa (vm, tmp1);
587           goto done;
588         }
589       else if (unformat (line_input, "del-sa %lx", &tmp2))
590         {
591           r = ikev2_initiate_delete_ike_sa (vm, tmp2);
592           goto done;
593         }
594       else if (unformat (line_input, "rekey-child-sa %x", &tmp1))
595         {
596           r = ikev2_initiate_rekey_child_sa (vm, tmp1);
597           goto done;
598         }
599       else
600         break;
601     }
602
603   r = clib_error_return (0, "parse error: '%U'",
604                          format_unformat_error, line_input);
605
606 done:
607   vec_free (name);
608   unformat_free (line_input);
609   return r;
610 }
611
612 /* *INDENT-OFF* */
613 VLIB_CLI_COMMAND (ikev2_initiate_command, static) = {
614     .path = "ikev2 initiate",
615     .short_help =
616         "ikev2 initiate sa-init <profile id>\n"
617         "ikev2 initiate del-child-sa <child sa ispi>\n"
618         "ikev2 initiate del-sa <sa ispi>\n"
619         "ikev2 initiate rekey-child-sa <profile id> <child sa ispi>\n",
620     .function = ikev2_initiate_command_fn,
621 };
622 /* *INDENT-ON* */
623
624 void
625 ikev2_cli_reference (void)
626 {
627 }
628
629 static clib_error_t *
630 ikev2_set_log_level_command_fn (vlib_main_t * vm,
631                                 unformat_input_t * input,
632                                 vlib_cli_command_t * cmd)
633 {
634   unformat_input_t _line_input, *line_input = &_line_input;
635   u8 log_level = IKEV2_LOG_NONE;
636   clib_error_t *error = 0;
637
638   /* Get a line of input. */
639   if (!unformat_user (input, unformat_line_input, line_input))
640     return 0;
641
642   if (!unformat (line_input, "%d", &log_level))
643     {
644       error = clib_error_return (0, "unknown input '%U'",
645                                  format_unformat_error, line_input);
646       goto done;
647     }
648   int rc = ikev2_set_log_level (log_level);
649   if (rc < 0)
650     error = clib_error_return (0, "setting log level failed!");
651
652 done:
653   unformat_free (line_input);
654   return error;
655 }
656
657 /* *INDENT-OFF* */
658 VLIB_CLI_COMMAND (ikev2_set_log_level_command, static) = {
659   .path = "ikev2 set logging level",
660   .function = ikev2_set_log_level_command_fn,
661   .short_help = "ikev2 set logging level <0-5>",
662 };
663 /* *INDENT-ON* */
664
665 /*
666  * fd.io coding-style-patch-verification: ON
667  *
668  * Local Variables:
669  * eval: (c-set-style "gnu")
670  * End:
671  */