+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ memset (rmp, 0, sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs(VL_API_LISP_MAP_RESOLVER_DETAILS);
+
+ switch (ip_addr_version(ip)) {
+ case IP4:
+ rmp->is_ipv6 = 0;
+ clib_memcpy(rmp->ip_address, &ip_addr_v4(ip), sizeof(ip_addr_v4(ip)));
+ break;
+
+ case IP6:
+ rmp->is_ipv6 = 1;
+ clib_memcpy(rmp->ip_address, &ip_addr_v6(ip), sizeof(ip_addr_v6(ip)));
+ break;
+
+ default:
+ ASSERT(0);
+ }
+ rmp->context = context;
+
+ vl_msg_api_send_shmem (q, (u8 *)&rmp);
+}
+
+static void
+vl_api_lisp_map_resolver_dump_t_handler (
+ vl_api_lisp_map_resolver_dump_t *mp)
+{
+ unix_shared_memory_queue_t * q = NULL;
+ lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
+ ip_address_t *ip = NULL;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0) {
+ return;
+ }
+
+ vec_foreach(ip, lcm->map_resolvers) {
+ send_lisp_map_resolver_details(ip, q, mp->context);
+ }
+
+}
+
+static void
+vl_api_lisp_eid_table_map_dump_t_handler (
+ vl_api_lisp_eid_table_map_dump_t *mp)
+{
+ unix_shared_memory_queue_t * q = NULL;
+ lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
+ hash_pair_t * p;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0) {
+ return;
+ }
+ hash_foreach_pair (p, lcm->table_id_by_vni, {
+ vl_api_lisp_eid_table_map_details_t * rmp = NULL;
+ memset (rmp, 0, sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs(VL_API_LISP_EID_TABLE_MAP_DETAILS);
+ rmp->vni = p->key;
+ rmp->vrf = p->value[0];
+ rmp->context = mp->context;
+ });
+}
+
+static void
+send_lisp_enable_disable_details (unix_shared_memory_queue_t *q,
+ u32 context)
+{
+ vl_api_lisp_enable_disable_status_details_t *rmp = NULL;
+
+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ memset (rmp, 0, sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs(VL_API_LISP_ENABLE_DISABLE_STATUS_DETAILS);
+
+ rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
+ rmp->feature_status = vnet_lisp_enable_disable_status ();
+ rmp->context = context;
+
+ vl_msg_api_send_shmem (q, (u8 *)&rmp);
+}
+
+static void
+vl_api_lisp_enable_disable_status_dump_t_handler
+(vl_api_lisp_enable_disable_status_dump_t *mp)
+{
+ unix_shared_memory_queue_t * q = NULL;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0) {
+ return;
+ }
+
+ send_lisp_enable_disable_details(q, mp->context);
+}
+
+static void
+vl_api_lisp_get_map_request_itr_rlocs_t_handler (
+ vl_api_lisp_get_map_request_itr_rlocs_t *mp)
+{
+ unix_shared_memory_queue_t * q = NULL;
+ vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
+ lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
+ locator_set_t * loc_set = 0;
+ u8 * tmp_str = 0;
+ int rv = 0;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0) {
+ return;
+ }
+
+ if (~0 == lcm->mreq_itr_rlocs) {
+ tmp_str = format(0, " ");
+ } else {
+ loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
+ tmp_str = format(0, "%s", loc_set->name);
+ }
+
+ REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
+ ({
+ strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
+ ARRAY_LEN(rmp->locator_set_name) - 1);
+ }));
+
+ vec_free(tmp_str);
+}
+
+static void
+vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp)
+{
+ vl_api_interface_name_renumber_reply_t * rmp;
+ int rv = 0;
+
+ VALIDATE_SW_IF_INDEX(mp);
+
+ rv = vnet_interface_name_renumber
+ (ntohl(mp->sw_if_index), ntohl(mp->new_show_dev_instance));
+
+ BAD_SW_IF_INDEX_LABEL;
+
+ REPLY_MACRO(VL_API_INTERFACE_NAME_RENUMBER_REPLY);
+}
+
+static int arp_change_data_callback (u32 pool_index, u8 * new_mac,
+ u32 sw_if_index, u32 address)
+{
+ vpe_api_main_t * am = &vpe_api_main;
+ vlib_main_t * vm = am->vlib_main;
+ vl_api_ip4_arp_event_t * event;
+ static f64 arp_event_last_time;
+ f64 now = vlib_time_now (vm);
+
+ if (pool_is_free_index (am->arp_events, pool_index))
+ return 1;
+
+ event = pool_elt_at_index (am->arp_events, pool_index);
+ if (memcmp (&event->new_mac, new_mac, sizeof (event->new_mac))) {
+ clib_memcpy (event->new_mac, new_mac, sizeof(event->new_mac));
+ } else { /* same mac */
+ if ((sw_if_index == event->sw_if_index) &&
+ ((address == 0) ||
+ /* for BD case, also check IP address with 10 sec timeout */
+ ((address == event->address) &&
+ ((now - arp_event_last_time) < 10.0))))
+ return 1;
+ }
+
+ arp_event_last_time = now;
+ event->sw_if_index = sw_if_index;
+ if (address) event->address = address;
+ return 0;
+}
+
+static int arp_change_delete_callback (u32 pool_index, u8 * notused)
+{
+ vpe_api_main_t * am = &vpe_api_main;
+
+ if (pool_is_free_index (am->arp_events, pool_index))
+ return 1;
+
+ pool_put_index (am->arp_events, pool_index);
+ return 0;
+}
+
+static void
+vl_api_want_ip4_arp_events_t_handler
+(vl_api_want_ip4_arp_events_t * mp)
+{
+ vpe_api_main_t * am = &vpe_api_main;
+ vnet_main_t * vnm = vnet_get_main();
+ vl_api_want_ip4_arp_events_reply_t *rmp;
+ vl_api_ip4_arp_event_t * event;
+ int rv;
+
+ if (mp->enable_disable) {
+ pool_get (am->arp_events, event);
+ memset (event, 0, sizeof (*event));
+
+ event->_vl_msg_id = ntohs(VL_API_IP4_ARP_EVENT);
+ event->client_index = mp->client_index;
+ event->context = mp->context;
+ event->address = mp->address;
+ event->pid = mp->pid;
+
+ rv = vnet_add_del_ip4_arp_change_event
+ (vnm, arp_change_data_callback,
+ mp->pid,
+ &mp->address /* addr, in net byte order */,
+ vpe_resolver_process_node.index,
+ IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */);
+ } else {
+ rv = vnet_add_del_ip4_arp_change_event
+ (vnm, arp_change_delete_callback,
+ mp->pid,
+ &mp->address /* addr, in net byte order */,
+ vpe_resolver_process_node.index,
+ IP4_ARP_EVENT, ~0 /* pool index */, 0 /* is_add */);
+ }
+ REPLY_MACRO(VL_API_WANT_IP4_ARP_EVENTS_REPLY);
+}
+
+static void vl_api_input_acl_set_interface_t_handler
+(vl_api_input_acl_set_interface_t * mp)
+{
+ vlib_main_t *vm = vlib_get_main();
+ vl_api_input_acl_set_interface_reply_t * rmp;
+ int rv;
+ u32 sw_if_index, ip4_table_index, ip6_table_index, l2_table_index;
+
+ ip4_table_index = ntohl(mp->ip4_table_index);
+ ip6_table_index = ntohl(mp->ip6_table_index);
+ l2_table_index = ntohl(mp->l2_table_index);
+ sw_if_index = ntohl(mp->sw_if_index);
+
+ VALIDATE_SW_IF_INDEX(mp);
+
+ rv = vnet_set_input_acl_intfc (vm, sw_if_index, ip4_table_index,
+ ip6_table_index, l2_table_index,
+ mp->is_add);
+
+ BAD_SW_IF_INDEX_LABEL;
+
+ REPLY_MACRO(VL_API_INPUT_ACL_SET_INTERFACE_REPLY);
+}
+
+static void vl_api_ipsec_spd_add_del_t_handler
+(vl_api_ipsec_spd_add_del_t * mp)
+{
+#if IPSEC == 0
+ clib_warning ("unimplemented");
+#else
+
+ vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
+ vl_api_ipsec_spd_add_del_reply_t * rmp;
+ int rv;
+
+#if DPDK > 0
+ rv = ipsec_add_del_spd (vm, ntohl(mp->spd_id), mp->is_add);
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+#endif
+
+ REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_REPLY);
+#endif
+}
+
+static void vl_api_ipsec_interface_add_del_spd_t_handler
+(vl_api_ipsec_interface_add_del_spd_t * mp)
+{
+ vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
+ vl_api_ipsec_interface_add_del_spd_reply_t * rmp;
+ int rv;
+ u32 sw_if_index __attribute__((unused));
+ u32 spd_id __attribute__((unused));
+
+ sw_if_index = ntohl(mp->sw_if_index);
+ spd_id = ntohl(mp->spd_id);
+
+ VALIDATE_SW_IF_INDEX(mp);
+
+#if IPSEC > 0
+ rv = ipsec_set_interface_spd(vm, sw_if_index, spd_id, mp->is_add);
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+#endif
+
+ BAD_SW_IF_INDEX_LABEL;
+
+ REPLY_MACRO(VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
+}
+
+static void vl_api_ipsec_spd_add_del_entry_t_handler
+(vl_api_ipsec_spd_add_del_entry_t * mp)
+{
+ vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
+ vl_api_ipsec_spd_add_del_entry_reply_t * rmp;
+ int rv;
+
+#if IPSEC > 0
+ ipsec_policy_t p;
+
+ memset(&p, 0, sizeof(p));
+
+ p.id = ntohl(mp->spd_id);
+ p.priority = ntohl(mp->priority);
+ p.is_outbound = mp->is_outbound;
+ p.is_ipv6 = mp->is_ipv6;
+
+ clib_memcpy(&p.raddr.start, mp->remote_address_start, 16);
+ clib_memcpy(&p.raddr.stop, mp->remote_address_stop, 16);
+ clib_memcpy(&p.laddr.start, mp->local_address_start, 16);
+ clib_memcpy(&p.laddr.stop, mp->local_address_stop, 16);
+
+ p.protocol = mp->protocol;
+ p.rport.start = ntohs(mp->remote_port_start);
+ p.rport.stop = ntohs(mp->remote_port_stop);
+ p.lport.start = ntohs(mp->local_port_start);
+ p.lport.stop = ntohs(mp->local_port_stop);
+ /* policy action resolve unsupported */
+ if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE) {
+ clib_warning("unsupported action: 'resolve'");
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+ goto out;
+ }
+ p.policy = mp->policy;
+ p.sa_id = ntohl(mp->sa_id);
+
+ rv = ipsec_add_del_policy(vm, &p, mp->is_add);
+ if (rv)
+ goto out;
+
+ if (mp->is_ip_any) {
+ p.is_ipv6 = 1;
+ rv = ipsec_add_del_policy(vm, &p, mp->is_add);
+ }
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+ goto out;
+#endif
+
+out:
+ REPLY_MACRO(VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
+}
+
+static void vl_api_ipsec_sad_add_del_entry_t_handler
+(vl_api_ipsec_sad_add_del_entry_t * mp)
+{
+ vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
+ vl_api_ipsec_sad_add_del_entry_reply_t * rmp;
+ int rv;
+#if IPSEC > 0
+ ipsec_sa_t sa;
+
+ memset(&sa, 0, sizeof(sa));
+
+ sa.id = ntohl(mp->sad_id);
+ sa.spi = ntohl(mp->spi);
+ /* security protocol AH unsupported */
+ if (mp->protocol == IPSEC_PROTOCOL_AH) {
+ clib_warning("unsupported security protocol 'AH'");
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+ goto out;
+ }
+ sa.protocol = mp->protocol;
+ /* check for unsupported crypto-alg */
+ if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
+ mp->crypto_algorithm > IPSEC_CRYPTO_ALG_AES_CBC_256) {
+ clib_warning("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
+ mp->crypto_algorithm);
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+ goto out;
+ }
+ sa.crypto_alg = mp->crypto_algorithm;
+ sa.crypto_key_len = mp->crypto_key_length;
+ clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
+ /* check for unsupported integ-alg */
+ if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
+ mp->integrity_algorithm > IPSEC_INTEG_ALG_SHA_512_256) {
+ clib_warning("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
+ mp->integrity_algorithm);
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+ goto out;
+ }
+ sa.integ_alg = mp->integrity_algorithm;
+ sa.integ_key_len = mp->integrity_key_length;
+ clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
+ sa.use_esn = mp->use_extended_sequence_number;
+ sa.is_tunnel = mp->is_tunnel;
+ sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
+ clib_memcpy(&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
+ clib_memcpy(&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
+
+ rv = ipsec_add_del_sa(vm, &sa, mp->is_add);
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+ goto out;
+#endif
+
+out:
+ REPLY_MACRO(VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
+}
+
+static void
+vl_api_ikev2_profile_add_del_t_handler
+(vl_api_ikev2_profile_add_del_t * mp)
+{
+ vl_api_ikev2_profile_add_del_reply_t * rmp;
+ int rv = 0;
+
+#if IPSEC > 0
+ vlib_main_t * vm = vlib_get_main();
+ clib_error_t * error;
+ u8 * tmp = format(0, "%s", mp->name);
+ error = ikev2_add_del_profile(vm, tmp, mp->is_add);
+ vec_free (tmp);
+ if (error)
+ rv = VNET_API_ERROR_UNSPECIFIED;
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+#endif
+
+ REPLY_MACRO(VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
+}
+
+static void
+vl_api_ikev2_profile_set_auth_t_handler
+(vl_api_ikev2_profile_set_auth_t * mp)
+{
+ vl_api_ikev2_profile_set_auth_reply_t * rmp;
+ int rv = 0;
+
+#if IPSEC > 0
+ vlib_main_t * vm = vlib_get_main();
+ clib_error_t * error;
+ u8 * tmp = format(0, "%s", mp->name);
+ u8 * data = vec_new (u8, mp->data_len);
+ clib_memcpy(data, mp->data, mp->data_len);
+ error = ikev2_set_profile_auth(vm, tmp, mp->auth_method, data, mp->is_hex);
+ vec_free (tmp);
+ vec_free (data);
+ if (error)
+ rv = VNET_API_ERROR_UNSPECIFIED;
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+#endif
+
+ REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
+}
+
+static void
+vl_api_ikev2_profile_set_id_t_handler
+(vl_api_ikev2_profile_set_id_t * mp)
+{
+ vl_api_ikev2_profile_add_del_reply_t * rmp;
+ int rv = 0;
+
+#if IPSEC > 0
+ vlib_main_t * vm = vlib_get_main();
+ clib_error_t * error;
+ u8 * tmp = format(0, "%s", mp->name);
+ u8 * data = vec_new (u8, mp->data_len);
+ clib_memcpy(data, mp->data, mp->data_len);
+ error = ikev2_set_profile_id(vm, tmp, mp->id_type, data, mp->is_local);
+ vec_free (tmp);
+ vec_free (data);
+ if (error)
+ rv = VNET_API_ERROR_UNSPECIFIED;
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+#endif
+
+ REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_ID_REPLY);
+}
+
+static void
+vl_api_ikev2_profile_set_ts_t_handler
+(vl_api_ikev2_profile_set_ts_t * mp)
+{
+ vl_api_ikev2_profile_set_ts_reply_t * rmp;
+ int rv = 0;
+
+#if IPSEC > 0
+ vlib_main_t * vm = vlib_get_main();
+ clib_error_t * error;
+ u8 * tmp = format(0, "%s", mp->name);
+ error = ikev2_set_profile_ts(vm, tmp, mp->proto, mp->start_port,
+ mp->end_port, (ip4_address_t) mp->start_addr,
+ (ip4_address_t) mp->end_addr, mp->is_local);
+ vec_free (tmp);
+ if (error)
+ rv = VNET_API_ERROR_UNSPECIFIED;
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+#endif
+
+ REPLY_MACRO(VL_API_IKEV2_PROFILE_SET_TS_REPLY);
+}
+
+static void
+vl_api_ikev2_set_local_key_t_handler
+(vl_api_ikev2_set_local_key_t * mp)
+{
+ vl_api_ikev2_profile_set_ts_reply_t * rmp;
+ int rv = 0;
+
+#if IPSEC > 0
+ vlib_main_t * vm = vlib_get_main();
+ clib_error_t * error;
+
+ error = ikev2_set_local_key(vm, mp->key_file);
+ if (error)
+ rv = VNET_API_ERROR_UNSPECIFIED;
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+#endif
+
+ REPLY_MACRO(VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
+}
+
+static void
+vl_api_map_add_domain_t_handler
+(vl_api_map_add_domain_t * mp)
+{
+ vl_api_map_add_domain_reply_t * rmp;
+ int rv = 0;
+ u32 index;
+ u8 flags = mp->is_translation ? MAP_DOMAIN_TRANSLATION : 0;
+ rv = map_create_domain((ip4_address_t *)&mp->ip4_prefix, mp->ip4_prefix_len,
+ (ip6_address_t *)&mp->ip6_prefix, mp->ip6_prefix_len,
+ (ip6_address_t *)&mp->ip6_src, mp->ip6_src_prefix_len,
+ mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs(mp->mtu), flags);
+
+ REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
+ ({
+ rmp->index = ntohl(index);
+ }));
+}
+
+static void
+vl_api_map_del_domain_t_handler
+(vl_api_map_del_domain_t * mp)
+{
+ vl_api_map_del_domain_reply_t * rmp;
+ int rv = 0;
+
+ rv = map_delete_domain(ntohl(mp->index));
+
+ REPLY_MACRO(VL_API_MAP_DEL_DOMAIN_REPLY);
+}
+
+static void
+vl_api_map_add_del_rule_t_handler
+(vl_api_map_add_del_rule_t * mp)
+{
+ vl_api_map_del_domain_reply_t * rmp;
+ int rv = 0;
+
+ rv = map_add_del_psid(ntohl(mp->index), ntohs(mp->psid), (ip6_address_t *)mp->ip6_dst, mp->is_add);
+
+ REPLY_MACRO(VL_API_MAP_ADD_DEL_RULE_REPLY);
+}
+
+static void
+vl_api_map_domain_dump_t_handler
+(vl_api_map_domain_dump_t * mp)
+{
+ vl_api_map_domain_details_t * rmp;
+ map_main_t *mm = &map_main;
+ map_domain_t *d;
+ unix_shared_memory_queue_t * q;
+
+ if (pool_elts (mm->domains) == 0)
+ return;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0) {
+ return;
+ }
+
+ pool_foreach(d, mm->domains, ({
+ /* Make sure every field is initiated (or don't skip the memset()) */
+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs(VL_API_MAP_DOMAIN_DETAILS);
+ rmp->domain_index = htonl(d - mm->domains);
+ rmp->ea_bits_len = d->ea_bits_len;
+ rmp->psid_offset = d->psid_offset;
+ rmp->psid_length = d->psid_length;
+ clib_memcpy(rmp->ip4_prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix));
+ rmp->ip4_prefix_len = d->ip4_prefix_len;
+ clib_memcpy(rmp->ip6_prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix));
+ rmp->ip6_prefix_len = d->ip6_prefix_len;
+ clib_memcpy(rmp->ip6_src, &d->ip6_src, sizeof(rmp->ip6_src));
+ rmp->ip6_src_len = d->ip6_src_len;
+ rmp->mtu = htons(d->mtu);
+ rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION);
+ rmp->context = mp->context;
+
+ vl_msg_api_send_shmem (q, (u8 *)&rmp);
+ }));
+}
+
+static void
+vl_api_map_rule_dump_t_handler
+(vl_api_map_rule_dump_t * mp)
+{
+ unix_shared_memory_queue_t * q;
+ u16 i;
+ ip6_address_t dst;
+ vl_api_map_rule_details_t * rmp;
+ map_main_t *mm = &map_main;
+ u32 domain_index = ntohl(mp->domain_index);
+ map_domain_t *d;
+
+ if (pool_elts (mm->domains) == 0)
+ return;
+
+ d = pool_elt_at_index(mm->domains, domain_index);
+ if (!d || !d->rules) {
+ return;
+ }
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0) {
+ return;
+ }
+
+ for (i = 0; i < (0x1 << d->psid_length); i++) {
+ dst = d->rules[i];
+ if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) {
+ continue;
+ }
+ rmp = vl_msg_api_alloc(sizeof(*rmp));
+ memset(rmp, 0, sizeof(*rmp));
+ rmp->_vl_msg_id = ntohs(VL_API_MAP_RULE_DETAILS);
+ rmp->psid = htons(i);
+ clib_memcpy(rmp->ip6_dst, &dst, sizeof(rmp->ip6_dst));
+ rmp->context = mp->context;
+ vl_msg_api_send_shmem(q, (u8 *)&rmp);
+ }
+}
+
+static void
+vl_api_map_summary_stats_t_handler (
+ vl_api_map_summary_stats_t *mp)
+{
+ vl_api_map_summary_stats_reply_t *rmp;
+ vlib_combined_counter_main_t *cm;
+ vlib_counter_t v;
+ int i, which;
+ u64 total_pkts[VLIB_N_RX_TX];
+ u64 total_bytes[VLIB_N_RX_TX];
+ map_main_t *mm = &map_main;
+ unix_shared_memory_queue_t *q =
+ vl_api_client_index_to_input_queue(mp->client_index);
+
+ if (!q)
+ return;
+
+ rmp = vl_msg_api_alloc (sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs(VL_API_MAP_SUMMARY_STATS_REPLY);
+ rmp->context = mp->context;
+ rmp->retval = 0;
+
+ memset (total_pkts, 0, sizeof (total_pkts));
+ memset (total_bytes, 0, sizeof (total_bytes));
+
+ map_domain_counter_lock (mm);
+ vec_foreach(cm, mm->domain_counters) {
+ which = cm - mm->domain_counters;
+
+ for (i = 0; i < vec_len(cm->maxi); i++) {
+ vlib_get_combined_counter (cm, i, &v);
+ total_pkts[which] += v.packets;
+ total_bytes[which] += v.bytes;
+ }
+ }
+
+ map_domain_counter_unlock (mm);
+
+ /* Note: in network byte order! */
+ rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_RX]);
+ rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_RX]);
+ rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_pkts[MAP_DOMAIN_COUNTER_TX]);
+ rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(total_bytes[MAP_DOMAIN_COUNTER_TX]);
+ rmp->total_bindings = clib_host_to_net_u64(pool_elts(mm->domains));
+ rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
+ rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
+ rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] = clib_host_to_net_u64(map_error_counter_get(ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
+
+ vl_msg_api_send_shmem(q, (u8 *)&rmp);
+}
+
+static void vl_api_ipsec_sa_set_key_t_handler
+(vl_api_ipsec_sa_set_key_t * mp)
+{
+ vlib_main_t *vm __attribute__((unused)) = vlib_get_main();
+ vl_api_ipsec_sa_set_key_reply_t *rmp;
+ int rv;
+#if IPSEC > 0
+ ipsec_sa_t sa;
+ sa.id = ntohl(mp->sa_id);
+ sa.crypto_key_len = mp->crypto_key_length;
+ clib_memcpy(&sa.crypto_key, mp->crypto_key, sizeof(sa.crypto_key));
+ sa.integ_key_len = mp->integrity_key_length;
+ clib_memcpy(&sa.integ_key, mp->integrity_key, sizeof(sa.integ_key));
+
+ rv = ipsec_set_sa_key(vm, &sa);
+#else
+ rv = VNET_API_ERROR_UNIMPLEMENTED;
+#endif
+
+ REPLY_MACRO(VL_API_IPSEC_SA_SET_KEY_REPLY);
+}
+
+static void vl_api_cop_interface_enable_disable_t_handler
+(vl_api_cop_interface_enable_disable_t * mp)
+{
+ vl_api_cop_interface_enable_disable_reply_t * rmp;
+ int rv;
+ u32 sw_if_index = ntohl(mp->sw_if_index);
+ int enable_disable;
+
+ VALIDATE_SW_IF_INDEX(mp);
+
+ enable_disable = (int) mp->enable_disable;
+
+ rv = cop_interface_enable_disable (sw_if_index, enable_disable);
+
+ BAD_SW_IF_INDEX_LABEL;
+
+ REPLY_MACRO(VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY);
+}
+
+static void vl_api_cop_whitelist_enable_disable_t_handler
+(vl_api_cop_whitelist_enable_disable_t * mp)
+{
+ vl_api_cop_whitelist_enable_disable_reply_t * rmp;
+ cop_whitelist_enable_disable_args_t _a, *a=&_a;
+ u32 sw_if_index = ntohl(mp->sw_if_index);
+ int rv;
+
+ VALIDATE_SW_IF_INDEX(mp);
+
+ a->sw_if_index = sw_if_index;
+ a->ip4 = mp->ip4;
+ a->ip6 = mp->ip6;
+ a->default_cop = mp->default_cop;
+ a->fib_id = ntohl(mp->fib_id);
+
+ rv = cop_whitelist_enable_disable (a);
+
+ BAD_SW_IF_INDEX_LABEL;
+
+ REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
+}
+
+static void vl_api_get_node_graph_t_handler
+(vl_api_get_node_graph_t * mp)
+{
+ int rv = 0;
+ u8 * vector = 0;
+ api_main_t * am = &api_main;
+ vlib_main_t * vm = vlib_get_main();
+ void * oldheap;
+ vl_api_get_node_graph_reply_t * rmp;
+
+ pthread_mutex_lock (&am->vlib_rp->mutex);
+ oldheap = svm_push_data_heap (am->vlib_rp);
+
+ /*
+ * Keep the number of memcpy ops to a minimum (e.g. 1).
+ */
+ vec_validate (vector, 16384);
+ vec_reset_length (vector);
+
+ /* $$$$ FIXME */
+ vector = vlib_node_serialize (&vm->node_main, vector,
+ (u32)~0 /* all threads */,
+ 1 /* include nexts */,
+ 1 /* include stats */);
+
+ svm_pop_heap (oldheap);
+ pthread_mutex_unlock (&am->vlib_rp->mutex);
+
+ REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
+ rmp->reply_in_shmem = (uword) vector);
+}
+
+static void vl_api_trace_profile_add_t_handler
+(vl_api_trace_profile_add_t *mp)
+{
+ int rv = 0;
+ vl_api_trace_profile_add_reply_t * rmp;
+ clib_error_t *error;
+
+ /* Ignoring the profile id as currently a single profile
+ * is supported */
+ error = ip6_ioam_trace_profile_set(mp->trace_num_elt, mp->trace_type,
+ ntohl(mp->node_id), ntohl(mp->trace_app_data),
+ mp->pow_enable, mp->trace_tsp,
+ mp->trace_ppc);
+ if (error) {
+ clib_error_report(error);
+ rv = clib_error_get_code(error);
+ }
+
+ REPLY_MACRO(VL_API_TRACE_PROFILE_ADD_REPLY);
+}
+
+static void vl_api_trace_profile_apply_t_handler
+(vl_api_trace_profile_apply_t *mp)
+{
+ int rv = 0;
+ vl_api_trace_profile_apply_reply_t * rmp;
+
+ if (mp->enable != 0) {
+ rv = ip6_ioam_set_destination ((ip6_address_t *)(&mp->dest_ipv6),
+ ntohl(mp->prefix_length),
+ ntohl(mp->vrf_id),
+ mp->trace_op == IOAM_HBYH_ADD,
+ mp->trace_op == IOAM_HBYH_POP,
+ mp->trace_op == IOAM_HBYH_MOD);
+ } else {
+ //ip6_ioam_clear_destination(&ip6, mp->prefix_length, mp->vrf_id);
+ }
+ REPLY_MACRO(VL_API_TRACE_PROFILE_APPLY_REPLY);
+}
+
+static void vl_api_trace_profile_del_t_handler
+(vl_api_trace_profile_del_t *mp)
+{
+ int rv = 0;
+ vl_api_trace_profile_del_reply_t * rmp;
+ clib_error_t *error;
+
+ error = clear_ioam_rewrite_fn();
+ if (error) {
+ clib_error_report(error);
+ rv = clib_error_get_code(error);
+ }
+
+ REPLY_MACRO(VL_API_TRACE_PROFILE_DEL_REPLY);
+}
+
+static void
+vl_api_af_packet_create_t_handler
+(vl_api_af_packet_create_t *mp)
+{
+ vlib_main_t *vm = vlib_get_main();
+ vl_api_af_packet_create_reply_t *rmp;
+ int rv = 0;
+ u8 *host_if_name = NULL;
+ u32 sw_if_index;
+
+ host_if_name = format(0, "%s", mp->host_if_name);
+ vec_add1 (host_if_name, 0);
+
+ rv = af_packet_create_if(vm, host_if_name,
+ mp->use_random_hw_addr ? 0 : mp->hw_addr, &sw_if_index);
+
+ vec_free(host_if_name);
+
+ REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY,
+ rmp->sw_if_index = clib_host_to_net_u32(sw_if_index));
+}
+
+static void
+vl_api_af_packet_delete_t_handler
+(vl_api_af_packet_delete_t *mp)
+{
+ vlib_main_t * vm = vlib_get_main();
+ vl_api_af_packet_delete_reply_t *rmp;
+ int rv = 0;
+ u8 *host_if_name = NULL;
+
+ host_if_name = format(0, "%s", mp->host_if_name);
+ vec_add1 (host_if_name, 0);
+
+ rv = af_packet_delete_if(vm, host_if_name);
+
+ vec_free(host_if_name);
+
+ REPLY_MACRO(VL_API_AF_PACKET_DELETE_REPLY);
+}
+
+static void
+vl_api_policer_add_del_t_handler
+(vl_api_policer_add_del_t *mp)
+{
+ vlib_main_t * vm = vlib_get_main();
+ vl_api_policer_add_del_reply_t *rmp;
+ int rv = 0;
+ u8 *name = NULL;
+ sse2_qos_pol_cfg_params_st cfg;
+ clib_error_t * error;
+
+ name = format(0, "%s", mp->name);
+
+ memset (&cfg, 0, sizeof (cfg));
+ cfg.rfc = mp->type;
+ cfg.rnd_type = mp->round_type;
+ cfg.rate_type = mp->rate_type;
+ cfg.rb.kbps.cir_kbps = mp->cir;
+ cfg.rb.kbps.eir_kbps = mp->eir;
+ cfg.rb.kbps.cb_bytes = mp->cb;
+ cfg.rb.kbps.eb_bytes = mp->eb;
+
+ error = policer_add_del(vm, name, &cfg, mp->is_add);
+
+ if (error)
+ rv = VNET_API_ERROR_UNSPECIFIED;
+
+ REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
+}
+
+static void
+send_policer_details (u8 *name,
+ sse2_qos_pol_cfg_params_st *config,
+ policer_read_response_type_st *templ,
+ unix_shared_memory_queue_t *q,
+ u32 context)
+{
+ vl_api_policer_details_t * mp;
+
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ memset (mp, 0, sizeof (*mp));
+ mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS);
+ mp->context = context;
+ mp->cir = htonl(config->rb.kbps.cir_kbps);
+ mp->eir = htonl(config->rb.kbps.eir_kbps);
+ mp->cb = htonl(config->rb.kbps.cb_bytes);
+ mp->eb = htonl(config->rb.kbps.eb_bytes);
+ mp->rate_type = config->rate_type;
+ mp->round_type = config->rnd_type;
+ mp->type = config->rfc;
+ mp->single_rate = templ->single_rate ? 1 : 0;
+ mp->color_aware = templ->color_aware ? 1 : 0;
+ mp->scale = htonl(templ->scale);
+ mp->cir_tokens_per_period = htonl(templ->cir_tokens_per_period);
+ mp->pir_tokens_per_period = htonl(templ->pir_tokens_per_period);
+ mp->current_limit = htonl(templ->current_limit);
+ mp->current_bucket = htonl(templ->current_bucket);
+ mp->extended_limit = htonl(templ->extended_limit);
+ mp->extended_bucket = htonl(templ->extended_bucket);
+ mp->last_update_time = clib_host_to_net_u64(templ->last_update_time);
+
+ strncpy ((char *) mp->name, (char *) name, ARRAY_LEN(mp->name) - 1);
+
+ vl_msg_api_send_shmem (q, (u8 *)&mp);
+}
+
+static void
+vl_api_policer_dump_t_handler
+(vl_api_policer_dump_t *mp)
+{
+ unix_shared_memory_queue_t * q;
+ vnet_policer_main_t * pm = &vnet_policer_main;
+ hash_pair_t * hp;
+ uword * p;
+ u32 pool_index;
+ u8 * match_name = 0;
+ u8 * name;
+ sse2_qos_pol_cfg_params_st *config;
+ policer_read_response_type_st *templ;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0)
+ return;
+
+ if (mp->match_name_valid) {
+ match_name = format(0, "%s%c", mp->match_name, 0);
+ }
+
+ if (mp->match_name_valid) {
+ p = hash_get_mem (pm->policer_config_by_name, match_name);
+ if (p) {
+ pool_index = p[0];
+ config = pool_elt_at_index (pm->configs, pool_index);
+ templ = pool_elt_at_index (pm->policer_templates, pool_index);
+ send_policer_details(match_name, config, templ, q, mp->context);
+ }
+ } else {
+ hash_foreach_pair (hp, pm->policer_config_by_name,
+ ({
+ name = (u8 *) hp->key;
+ pool_index = hp->value[0];
+ config = pool_elt_at_index (pm->configs, pool_index);
+ templ = pool_elt_at_index (pm->policer_templates, pool_index);
+ send_policer_details(name, config, templ, q, mp->context);
+ }));
+ }
+}
+
+static void
+vl_api_netmap_create_t_handler
+(vl_api_netmap_create_t *mp)
+{
+ vlib_main_t *vm = vlib_get_main();
+ vl_api_netmap_create_reply_t *rmp;
+ int rv = 0;
+ u8 *if_name = NULL;
+
+ if_name = format(0, "%s", mp->netmap_if_name);
+ vec_add1 (if_name, 0);
+
+ rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
+ mp->is_pipe, mp->is_master, 0);
+
+ vec_free(if_name);
+
+ REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
+}
+
+static void
+vl_api_netmap_delete_t_handler
+(vl_api_netmap_delete_t *mp)
+{
+ vlib_main_t * vm = vlib_get_main();
+ vl_api_netmap_delete_reply_t *rmp;
+ int rv = 0;
+ u8 *if_name = NULL;
+
+ if_name = format(0, "%s", mp->netmap_if_name);
+ vec_add1 (if_name, 0);
+
+ rv = netmap_delete_if(vm, if_name);
+
+ vec_free(if_name);
+
+ REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
+}
+
+static void vl_api_mpls_gre_tunnel_details_t_handler (
+ vl_api_mpls_gre_tunnel_details_t * mp)
+{
+ clib_warning ("BUG");
+}
+
+static void send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
+ unix_shared_memory_queue_t *q,
+ mpls_gre_tunnel_t * gt,
+ u32 index,
+ u32 context)
+{
+ vl_api_mpls_gre_tunnel_details_t * mp;
+
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ memset (mp, 0, sizeof (*mp));
+ mp->_vl_msg_id = ntohs(VL_API_MPLS_GRE_TUNNEL_DETAILS);
+ mp->context = context;
+
+ if (gt != NULL) {
+ mp->tunnel_index = htonl(index);
+ mp->tunnel_src = gt->tunnel_src.as_u32;
+ mp->tunnel_dst = gt->tunnel_dst.as_u32;
+ mp->intfc_address = gt->intfc_address.as_u32;
+ mp->mask_width = htonl(gt->mask_width);
+ mp->inner_fib_index = htonl(gt->inner_fib_index);
+ mp->outer_fib_index = htonl(gt->outer_fib_index);
+ mp->encap_index = htonl(gt->encap_index);
+ mp->hw_if_index = htonl(gt->hw_if_index);
+ mp->l2_only = htonl(gt->l2_only);
+ }
+
+ mpls_main_t * mm = &mpls_main;
+ mpls_encap_t * e;
+ int i;
+ u32 len = 0;
+
+ e = pool_elt_at_index (mm->encaps, gt->encap_index);
+ len = vec_len (e->labels);
+ mp->nlabels = htonl(len);
+
+ for (i = 0; i < len; i++) {
+ mp->labels[i] = htonl(vnet_mpls_uc_get_label(
+ clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
+ }
+
+ vl_msg_api_send_shmem (q, (u8 *)&mp);
+}
+
+static void
+vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t *mp)
+{
+ vpe_api_main_t * am = &vpe_api_main;
+ unix_shared_memory_queue_t * q;
+ vlib_main_t * vm = &vlib_global_main;
+ mpls_main_t * mm = &mpls_main;
+ mpls_gre_tunnel_t * gt;
+ u32 index = ntohl(mp->tunnel_index);
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0)
+ return;
+
+ if (pool_elts (mm->gre_tunnels)) {
+ if(mp->tunnel_index >= 0) {
+ vlib_cli_output (vm, "MPLS-GRE tunnel %u", index);
+ gt = pool_elt_at_index (mm->gre_tunnels, index);
+ send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
+ } else {
+ vlib_cli_output (vm, "MPLS-GRE tunnels");
+ pool_foreach (gt, mm->gre_tunnels,
+ ({
+ send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels, mp->context);
+ }));
+ }
+ } else {
+ vlib_cli_output (vm, "No MPLS-GRE tunnels");
+ }
+}
+
+static void vl_api_mpls_eth_tunnel_details_t_handler (
+ vl_api_mpls_eth_tunnel_details_t * mp)
+{
+ clib_warning ("BUG");
+}
+
+static void send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
+ unix_shared_memory_queue_t *q,
+ mpls_eth_tunnel_t * et,
+ u32 index,
+ u32 context)
+{
+ vl_api_mpls_eth_tunnel_details_t * mp;
+
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ memset (mp, 0, sizeof (*mp));
+ mp->_vl_msg_id = ntohs(VL_API_MPLS_ETH_TUNNEL_DETAILS);
+ mp->context = context;
+
+ if (et != NULL) {
+ mp->tunnel_index = htonl(index);
+ memcpy(mp->tunnel_dst_mac, et->tunnel_dst, 6);
+ mp->intfc_address = et->intfc_address.as_u32;
+ mp->tx_sw_if_index = htonl(et->tx_sw_if_index);
+ mp->inner_fib_index = htonl(et->inner_fib_index);
+ mp->mask_width = htonl(et->mask_width);
+ mp->encap_index = htonl(et->encap_index);
+ mp->hw_if_index = htonl(et->hw_if_index);
+ mp->l2_only = htonl(et->l2_only);
+ }
+
+ mpls_main_t * mm = &mpls_main;
+ mpls_encap_t * e;
+ int i;
+ u32 len = 0;
+
+ e = pool_elt_at_index (mm->encaps, et->encap_index);
+ len = vec_len (e->labels);
+ mp->nlabels = htonl(len);
+
+ for (i = 0; i < len; i++) {
+ mp->labels[i] = htonl(vnet_mpls_uc_get_label(
+ clib_host_to_net_u32(e->labels[i].label_exp_s_ttl)));
+ }
+
+ vl_msg_api_send_shmem (q, (u8 *)&mp);
+}
+
+static void
+vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t *mp)
+{
+ vpe_api_main_t * am = &vpe_api_main;
+ unix_shared_memory_queue_t * q;
+ vlib_main_t * vm = &vlib_global_main;
+ mpls_main_t * mm = &mpls_main;
+ mpls_eth_tunnel_t * et;
+ u32 index = ntohl(mp->tunnel_index);
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0)
+ return;
+
+ clib_warning("Received mpls_eth_tunnel_dump");
+ clib_warning("Received tunnel index: %u from client %u", index, mp->client_index);
+
+ if (pool_elts (mm->eth_tunnels)) {
+ if(mp->tunnel_index >= 0) {
+ vlib_cli_output (vm, "MPLS-Ethernet tunnel %u", index);
+ et = pool_elt_at_index (mm->eth_tunnels, index);
+ send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
+ } else {
+ clib_warning("MPLS-Ethernet tunnels");
+ pool_foreach (et, mm->eth_tunnels,
+ ({
+ send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels, mp->context);
+ }));
+ }
+ } else {
+ clib_warning("No MPLS-Ethernet tunnels");
+ }
+}
+
+static void vl_api_mpls_fib_encap_details_t_handler (
+ vl_api_mpls_fib_encap_details_t * mp)
+{
+ clib_warning ("BUG");
+}
+
+static void send_mpls_fib_encap_details (vpe_api_main_t * am,
+ unix_shared_memory_queue_t *q,
+ show_mpls_fib_t *s,
+ u32 context)
+{
+ vl_api_mpls_fib_encap_details_t * mp;
+
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ memset (mp, 0, sizeof (*mp));
+ mp->_vl_msg_id = ntohs(VL_API_MPLS_FIB_ENCAP_DETAILS);
+ mp->context = context;
+
+ mp->fib_index = htonl(s->fib_index);
+ mp->entry_index = htonl(s->entry_index);
+ mp->dest = s->dest;
+ mp->s_bit = htonl(s->s_bit);
+
+ mpls_main_t * mm = &mpls_main;
+ mpls_encap_t * e;
+ int i;
+ u32 len = 0;