+ return s;
+}
+
+static int
+api_ikev2_profile_disable_natt (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_ikev2_profile_disable_natt_t *mp;
+ u8 *name = 0;
+ int ret;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "%U", unformat_token, valid_chars, &name))
+ vec_add1 (name, 0);
+ else
+ {
+ errmsg ("parse error '%U'", format_unformat_error, i);
+ return -99;
+ }
+ }
+
+ if (!vec_len (name))
+ {
+ errmsg ("profile name must be specified");
+ return -99;
+ }
+
+ if (vec_len (name) > 64)
+ {
+ errmsg ("profile name too long");
+ return -99;
+ }
+
+ M (IKEV2_PROFILE_DISABLE_NATT, mp);
+
+ clib_memcpy (mp->name, name, vec_len (name));
+ vec_free (name);
+
+ S (mp);
+ W (ret);
+ return ret;
+}
+
+static int
+api_ikev2_profile_dump (vat_main_t * vam)
+{
+ ikev2_test_main_t *ik = &ikev2_test_main;
+ vl_api_ikev2_profile_dump_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ int ret;
+
+ /* Construct the API message */
+ M (IKEV2_PROFILE_DUMP, mp);
+
+ /* send it... */
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ if (!ik->ping_id)
+ ik->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
+ mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
+ mp_ping->_vl_msg_id = htons (ik->ping_id);
+ mp_ping->client_index = vam->my_client_index;
+
+ vam->result_ready = 0;
+ S (mp_ping);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static void vl_api_ikev2_profile_details_t_handler
+ (vl_api_ikev2_profile_details_t * mp)
+{
+ vat_main_t *vam = ikev2_test_main.vat_main;
+ vl_api_ikev2_profile_t *p = &mp->profile;
+
+ fformat (vam->ofp, "profile %s\n", p->name);
+
+ if (p->auth.method)
+ {
+ if (p->auth.hex)
+ fformat (vam->ofp, " auth-method %U auth data 0x%U\n",
+ format_ikev2_auth_method, p->auth.method,
+ format_hex_bytes, p->auth.data,
+ clib_net_to_host_u32 (p->auth.data_len));
+ else
+ fformat (vam->ofp, " auth-method %U auth data %v\n",
+ format_ikev2_auth_method, p->auth.method, format (0,
+ "%s",
+ p->
+ auth.data));
+ }
+
+ if (p->loc_id.type)
+ {
+ fformat (vam->ofp, " local id-type data %U\n",
+ format_ikev2_id_type_and_data, &p->loc_id);
+ }
+
+ if (p->rem_id.type)
+ {
+ fformat (vam->ofp, " remote id-type data %U\n",
+ format_ikev2_id_type_and_data, &p->rem_id);
+ }
+
+ fformat (vam->ofp, " local traffic-selector addr %U - %U port %u - %u"
+ " protocol %u\n",
+ format_ip_address, &p->loc_ts.start_addr,
+ format_ip_address, &p->loc_ts.end_addr,
+ clib_net_to_host_u16 (p->loc_ts.start_port),
+ clib_net_to_host_u16 (p->loc_ts.end_port), p->loc_ts.protocol_id);
+
+ fformat (vam->ofp, " remote traffic-selector addr %U - %U port %u - %u"
+ " protocol %u\n",
+ format_ip_address, &p->rem_ts.start_addr,
+ format_ip_address, &p->rem_ts.end_addr,
+ clib_net_to_host_u16 (p->rem_ts.start_port),
+ clib_net_to_host_u16 (p->rem_ts.end_port), p->rem_ts.protocol_id);
+ u32 tun_itf = clib_net_to_host_u32 (p->tun_itf);
+ if (~0 != tun_itf)
+ fformat (vam->ofp, " protected tunnel idx %d\n", tun_itf);
+
+ u32 sw_if_index = clib_net_to_host_u32 (p->responder.sw_if_index);
+ if (~0 != sw_if_index)
+ fformat (vam->ofp, " responder idx %d %U\n",
+ sw_if_index, format_ip_address, &p->responder.addr);
+
+ if (p->udp_encap)
+ fformat (vam->ofp, " udp-encap\n");
+
+ if (p->natt_disabled)
+ fformat (vam->ofp, " NAT-T disabled\n");
+
+ u32 ipsec_over_udp_port = clib_net_to_host_u16 (p->ipsec_over_udp_port);
+ if (ipsec_over_udp_port != IPSEC_UDP_PORT_NONE)
+ fformat (vam->ofp, " ipsec-over-udp port %d\n", ipsec_over_udp_port);
+
+ u32 crypto_key_size = clib_net_to_host_u32 (p->ike_ts.crypto_key_size);
+ if (p->ike_ts.crypto_alg || p->ike_ts.integ_alg || p->ike_ts.dh_group
+ || crypto_key_size)
+ fformat (vam->ofp, " ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U\n",
+ format_ikev2_transform_encr_type, p->ike_ts.crypto_alg,
+ crypto_key_size, format_ikev2_transform_integ_type,
+ p->ike_ts.integ_alg, format_ikev2_transform_dh_type,
+ p->ike_ts.dh_group);
+
+ crypto_key_size = clib_net_to_host_u32 (p->esp_ts.crypto_key_size);
+ if (p->esp_ts.crypto_alg || p->esp_ts.integ_alg)
+ fformat (vam->ofp, " esp-crypto-alg %U %u esp-integ-alg %U\n",
+ format_ikev2_transform_encr_type, p->esp_ts.crypto_alg,
+ crypto_key_size,
+ format_ikev2_transform_integ_type, p->esp_ts.integ_alg);
+
+ fformat (vam->ofp, " lifetime %d jitter %d handover %d maxdata %d\n",
+ clib_net_to_host_u64 (p->lifetime),
+ clib_net_to_host_u32 (p->lifetime_jitter),
+ clib_net_to_host_u32 (p->handover),
+ clib_net_to_host_u64 (p->lifetime_maxdata));
+
+ vam->result_ready = 1;
+}
+
+static int
+api_ikev2_sa_dump (vat_main_t * vam)
+{
+ ikev2_test_main_t *im = &ikev2_test_main;
+ vl_api_ikev2_sa_dump_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ int ret;
+
+ /* Construct the API message */
+ M (IKEV2_SA_DUMP, mp);
+
+ /* send it... */
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ if (!im->ping_id)
+ im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
+ mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
+ mp_ping->_vl_msg_id = htons (im->ping_id);
+ mp_ping->client_index = vam->my_client_index;
+ vam->result_ready = 0;
+
+ S (mp_ping);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static void
+vl_api_ikev2_sa_details_t_handler (vl_api_ikev2_sa_details_t * mp)
+{
+ vat_main_t *vam = ikev2_test_main.vat_main;
+ vl_api_ikev2_sa_t *sa = &mp->sa;
+ ip_address_t iaddr;
+ ip_address_t raddr;
+ vl_api_ikev2_keys_t *k = &sa->keys;
+ vl_api_ikev2_sa_t_endian (sa);
+
+ ip_address_decode2 (&sa->iaddr, &iaddr);
+ ip_address_decode2 (&sa->raddr, &raddr);
+
+ fformat (vam->ofp, "profile index %d sa index: %d\n",
+ mp->sa.profile_index, mp->sa.sa_index);
+ fformat (vam->ofp, " iip %U ispi %lx rip %U rspi %lx\n", format_ip_address,
+ &iaddr, sa->ispi, format_ip_address, &raddr, sa->rspi);
+ fformat (vam->ofp, " %U ", format_ikev2_sa_transform, &sa->encryption);
+ fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &sa->prf);
+ fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &sa->integrity);
+ fformat (vam->ofp, "%U \n", format_ikev2_sa_transform, &sa->dh);
+
+ fformat (vam->ofp, " SK_d %U\n",
+ format_hex_bytes, k->sk_d, k->sk_d_len);
+
+ fformat (vam->ofp, " SK_a i:%U\n r:%U\n",
+ format_hex_bytes, k->sk_ai, k->sk_ai_len, format_hex_bytes,
+ k->sk_ar, k->sk_ar_len);
+
+ fformat (vam->ofp, " SK_e i:%U\n r:%U\n", format_hex_bytes,
+ k->sk_ei, k->sk_ei_len, format_hex_bytes, k->sk_er, k->sk_er_len);
+
+ fformat (vam->ofp, " SK_p i:%U\n r:%U\n", format_hex_bytes,
+ k->sk_pi, k->sk_pi_len, format_hex_bytes, k->sk_pr, k->sk_pr_len);
+
+ fformat (vam->ofp, " identifier (i) %U\n",
+ format_ikev2_id_type_and_data, &sa->i_id);
+ fformat (vam->ofp, " identifier (r) %U\n",
+ format_ikev2_id_type_and_data, &sa->r_id);
+
+ vam->result_ready = 1;
+}
+
+static int
+api_ikev2_child_sa_dump (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ ikev2_test_main_t *im = &ikev2_test_main;
+ vl_api_ikev2_child_sa_dump_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ int ret;
+ u32 sa_index = ~0;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "sa_index %d", &sa_index))
+ ;
+ else
+ {
+ errmsg ("parse error '%U'", format_unformat_error, i);
+ return -99;
+ }
+ }
+
+ if (sa_index == ~0)
+ return -99;
+
+ /* Construct the API message */
+ M (IKEV2_CHILD_SA_DUMP, mp);
+
+ mp->sa_index = clib_net_to_host_u32 (sa_index);
+
+ /* send it... */
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ if (!im->ping_id)
+ im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
+ mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
+ mp_ping->_vl_msg_id = htons (im->ping_id);
+ mp_ping->client_index = vam->my_client_index;
+ vam->result_ready = 0;
+
+ S (mp_ping);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static void
+vl_api_ikev2_child_sa_details_t_handler (vl_api_ikev2_child_sa_details_t * mp)
+{
+ vat_main_t *vam = ikev2_test_main.vat_main;
+ vl_api_ikev2_child_sa_t *child_sa = &mp->child_sa;
+ vl_api_ikev2_keys_t *k = &child_sa->keys;
+ vl_api_ikev2_child_sa_t_endian (child_sa);
+
+ fformat (vam->ofp, " child sa %u:\n", child_sa->child_sa_index);
+
+ fformat (vam->ofp, " %U ", format_ikev2_sa_transform,
+ &child_sa->encryption);
+ fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &child_sa->integrity);
+ fformat (vam->ofp, "%U \n", format_ikev2_sa_transform, &child_sa->esn);
+
+ fformat (vam->ofp, " spi(i) %lx spi(r) %lx\n",
+ child_sa->i_spi, child_sa->r_spi);
+
+ fformat (vam->ofp, " SK_e i:%U\n r:%U\n",
+ format_hex_bytes, k->sk_ei, k->sk_ei_len,
+ format_hex_bytes, k->sk_er, k->sk_er_len);
+ if (k->sk_ai_len)
+ {
+ fformat (vam->ofp, " SK_a i:%U\n r:%U\n",
+ format_hex_bytes, k->sk_ai, k->sk_ai_len,
+ format_hex_bytes, k->sk_ar, k->sk_ar_len);
+ }
+ vam->result_ready = 1;
+}
+
+static int
+api_ikev2_traffic_selector_dump (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ ikev2_test_main_t *im = &ikev2_test_main;
+ vl_api_ikev2_traffic_selector_dump_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ int is_initiator = ~0;
+ int sa_index = ~0;
+ int child_sa_index = ~0;
+ int ret;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "initiator"))
+ is_initiator = 1;
+ else if (unformat (i, "responder"))
+ is_initiator = 0;
+ else if (unformat (i, "sa_index %d", &sa_index))
+ ;
+ else if (unformat (i, "child_sa_index %d", &child_sa_index))
+ ;
+ else
+ {
+ errmsg ("parse error '%U'", format_unformat_error, i);
+ return -99;
+ }
+ }
+
+ if (child_sa_index == ~0 || sa_index == ~0 || is_initiator == ~0)
+ return -99;
+
+ /* Construct the API message */
+ M (IKEV2_TRAFFIC_SELECTOR_DUMP, mp);
+
+ mp->is_initiator = is_initiator;
+ mp->sa_index = clib_host_to_net_u32 (sa_index);
+ mp->child_sa_index = clib_host_to_net_u32 (child_sa_index);
+
+ /* send it... */
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ if (!im->ping_id)
+ im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
+ mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
+ mp_ping->_vl_msg_id = htons (im->ping_id);
+ mp_ping->client_index = vam->my_client_index;
+ vam->result_ready = 0;
+
+ S (mp_ping);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static void
+ vl_api_ikev2_traffic_selector_details_t_handler
+ (vl_api_ikev2_traffic_selector_details_t * mp)
+{
+ vat_main_t *vam = ikev2_test_main.vat_main;
+ vl_api_ikev2_ts_t *ts = &mp->ts;
+ ip_address_t start_addr, end_addr;
+ vl_api_ikev2_ts_t_endian (ts);
+
+ ip_address_decode2 (&ts->start_addr, &start_addr);
+ ip_address_decode2 (&ts->end_addr, &end_addr);
+
+ fformat (vam->ofp, " %s protocol_id %u addr "
+ "%U - %U port %u - %u\n",
+ ts->is_local, ts->protocol_id,
+ format_ip_address, &start_addr,
+ format_ip_address, &end_addr, ts->start_port, ts->end_port);
+ vam->result_ready = 1;
+}
+
+static int
+api_ikev2_nonce_get (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ ikev2_test_main_t *im = &ikev2_test_main;
+ vl_api_ikev2_nonce_get_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ u32 is_initiator = ~0;
+ u32 sa_index = ~0;
+ int ret;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "initiator"))
+ is_initiator = 1;
+ else if (unformat (i, "responder"))
+ is_initiator = 0;
+ else if (unformat (i, "sa_index %d", &sa_index))
+ ;
+ else
+ {
+ errmsg ("parse error '%U'", format_unformat_error, i);
+ return -99;
+ }
+ }
+
+ if (sa_index == ~0 || is_initiator == ~0)
+ return -99;
+
+ /* Construct the API message */
+ M (IKEV2_NONCE_GET, mp);
+
+ mp->is_initiator = is_initiator;
+ mp->sa_index = clib_host_to_net_u32 (sa_index);
+
+ /* send it... */
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ if (!im->ping_id)
+ im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
+ mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
+ mp_ping->_vl_msg_id = htons (im->ping_id);
+ mp_ping->client_index = vam->my_client_index;
+ vam->result_ready = 0;
+
+ S (mp_ping);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static void
+vl_api_ikev2_nonce_get_reply_t_handler (vl_api_ikev2_nonce_get_reply_t * mp)
+{
+ vat_main_t *vam = ikev2_test_main.vat_main;
+ mp->data_len = clib_net_to_host_u32 (mp->data_len);
+
+ fformat (vam->ofp, " nonce:%U\n",
+ format_hex_bytes, mp->nonce, mp->data_len);
+
+ vam->result_ready = 1;
+}
+
+static int
+api_ikev2_plugin_get_version (vat_main_t * vam)
+{
+ ikev2_test_main_t *sm = &ikev2_test_main;
+ vl_api_ikev2_plugin_get_version_t *mp;
+ u32 msg_size = sizeof (*mp);
+ int ret;
+
+ vam->result_ready = 0;
+ mp = vl_msg_api_alloc_as_if_client (msg_size);
+ clib_memset (mp, 0, msg_size);
+ mp->_vl_msg_id = ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION + sm->msg_id_base);
+ mp->client_index = vam->my_client_index;
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+static void vl_api_ikev2_plugin_get_version_reply_t_handler
+ (vl_api_ikev2_plugin_get_version_reply_t * mp)
+{
+ vat_main_t *vam = ikev2_test_main.vat_main;
+ clib_warning ("IKEv2 plugin version: %d.%d", ntohl (mp->major),
+ ntohl (mp->minor));
+ vam->result_ready = 1;
+}
+
+static int
+api_ikev2_profile_set_ipsec_udp_port (vat_main_t * vam)
+{
+ return 0;
+}
+
+static int
+api_ikev2_profile_set_liveness (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_ikev2_profile_set_liveness_t *mp;
+ u32 period = 0, max_retries = 0;
+ int ret;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (!unformat (i, "period %d max-retries %d", &period, &max_retries))
+ {
+ errmsg ("parse error '%U'", format_unformat_error, i);
+ return -99;
+ }
+ }
+
+ M (IKEV2_PROFILE_SET_LIVENESS, mp);
+
+ mp->period = clib_host_to_net_u32 (period);
+ mp->max_retries = clib_host_to_net_u32 (max_retries);
+
+ S (mp);
+ W (ret);
+
+ return ret;
+}