- a->is_add = mp->is_add;
- rv = vnet_lisp_add_del_adjacency (a);
-
-send_reply:
- REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
-}
-
-static void
-send_lisp_locator_details (lisp_cp_main_t * lcm,
- locator_t * loc,
- unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_lisp_locator_details_t *rmp;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
- rmp->context = context;
-
- rmp->local = loc->local;
- if (loc->local)
- {
- rmp->sw_if_index = ntohl (loc->sw_if_index);
- }
- else
- {
- rmp->is_ipv6 = gid_address_ip_version (&loc->address);
- ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
- }
- rmp->priority = loc->priority;
- rmp->weight = loc->weight;
-
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void
-vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
-{
- u8 *ls_name = 0;
- unix_shared_memory_queue_t *q = 0;
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- locator_set_t *lsit = 0;
- locator_t *loc = 0;
- u32 ls_index = ~0, *locit = 0;
- uword *p = 0;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- if (mp->is_index_set)
- ls_index = htonl (mp->ls_index);
- else
- {
- /* make sure we get a proper C-string */
- mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
- ls_name = format (0, "%s", mp->ls_name);
- p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
- if (!p)
- goto out;
- ls_index = p[0];
- }
-
- if (pool_is_free_index (lcm->locator_set_pool, ls_index))
- return;
-
- lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
-
- vec_foreach (locit, lsit->locator_indices)
- {
- loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
- send_lisp_locator_details (lcm, loc, q, mp->context);
- };
-out:
- vec_free (ls_name);
-}
-
-static void
-send_lisp_locator_set_details (lisp_cp_main_t * lcm,
- locator_set_t * lsit,
- unix_shared_memory_queue_t * q,
- u32 context, u32 ls_index)
-{
- vl_api_lisp_locator_set_details_t *rmp;
- u8 *str = 0;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
- rmp->context = context;
-
- rmp->ls_index = htonl (ls_index);
- if (lsit->local)
- {
- ASSERT (lsit->name != NULL);
- strncpy ((char *) rmp->ls_name, (char *) lsit->name,
- vec_len (lsit->name));
- }
- else
- {
- str = format (0, "<remote-%d>", ls_index);
- strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
- vec_free (str);
- }
-
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void
-vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
-{
- unix_shared_memory_queue_t *q = NULL;
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- locator_set_t *lsit = NULL;
- u8 filter;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- filter = mp->filter;
- /* *INDENT-OFF* */
- pool_foreach (lsit, lcm->locator_set_pool,
- ({
- if (filter && !((1 == filter && lsit->local) ||
- (2 == filter && !lsit->local)))
- {
- continue;
- }
- send_lisp_locator_set_details (lcm, lsit, q, mp->context,
- lsit - lcm->locator_set_pool);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
-{
- ASSERT (prefix_length);
- ip_prefix_t *ippref = &fid_addr_ippref (src);
-
- switch (fid_addr_type (src))
- {
- case FID_ADDR_IP_PREF:
- if (ip_prefix_version (ippref) == IP4)
- clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
- else
- clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
- prefix_length[0] = ip_prefix_len (ippref);
- break;
-
- case FID_ADDR_MAC:
- prefix_length[0] = 0;
- clib_memcpy (dst, fid_addr_mac (src), 6);
- break;
-
- default:
- clib_warning ("Unknown FID type %d!", fid_addr_type (src));
- break;
- }
-}
-
-static u8
-fid_type_to_api_type (fid_address_t * fid)
-{
- ip_prefix_t *ippref;
-
- switch (fid_addr_type (fid))
- {
- case FID_ADDR_IP_PREF:
- ippref = &fid_addr_ippref (fid);
- if (ip_prefix_version (ippref) == IP4)
- return 0;
- else if (ip_prefix_version (ippref) == IP6)
- return 1;
- else
- return ~0;
-
- case FID_ADDR_MAC:
- return 2;
- }
-
- return ~0;
-}
-
-static void
-send_lisp_eid_table_details (mapping_t * mapit,
- unix_shared_memory_queue_t * q,
- u32 context, u8 filter)
-{
- fid_address_t *fid;
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- locator_set_t *ls = 0;
- vl_api_lisp_eid_table_details_t *rmp = NULL;
- gid_address_t *gid = NULL;
- u8 *mac = 0;
- ip_prefix_t *ip_prefix = NULL;
-
- switch (filter)
- {
- case 0: /* all mappings */
- break;
-
- case 1: /* local only */
- if (!mapit->local)
- return;
- break;
- case 2: /* remote only */
- if (mapit->local)
- return;
- break;
- default:
- clib_warning ("Filter error, unknown filter: %d", filter);
- return;
- }
-
- gid = &mapit->eid;
- ip_prefix = &gid_address_ippref (gid);
- mac = gid_address_mac (gid);
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
-
- ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
- if (vec_len (ls->locator_indices) == 0)
- rmp->locator_set_index = ~0;
- else
- rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
-
- rmp->is_local = mapit->local;
- rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
- rmp->action = mapit->action;
- rmp->authoritative = mapit->authoritative;
-
- switch (gid_address_type (gid))
- {
- case GID_ADDR_SRC_DST:
- rmp->is_src_dst = 1;
- fid = &gid_address_sd_src (gid);
- rmp->eid_type = fid_type_to_api_type (fid);
- lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
- &rmp->seid_prefix_len);
- lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
- &rmp->eid_prefix_len);
- break;
- case GID_ADDR_IP_PREFIX:
- rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
- if (ip_prefix_version (ip_prefix) == IP4)
- {
- rmp->eid_type = 0; /* ipv4 type */
- clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
- sizeof (ip_prefix_v4 (ip_prefix)));
- }
- else
- {
- rmp->eid_type = 1; /* ipv6 type */
- clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
- sizeof (ip_prefix_v6 (ip_prefix)));
- }
- break;
- case GID_ADDR_MAC:
- rmp->eid_type = 2; /* l2 mac type */
- clib_memcpy (rmp->eid, mac, 6);
- break;
- default:
- ASSERT (0);
- }
- rmp->context = context;
- rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
- rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
- memcpy (rmp->key, mapit->key, vec_len (mapit->key));
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void
-vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
-{
- u32 mi;
- unix_shared_memory_queue_t *q = NULL;
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- mapping_t *mapit = NULL;
- gid_address_t _eid, *eid = &_eid;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- if (mp->eid_set)
- {
- memset (eid, 0, sizeof (*eid));
-
- unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
- mp->eid_type, mp->eid, mp->prefix_length);
-
- mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
- if ((u32) ~ 0 == mi)
- return;
-
- mapit = pool_elt_at_index (lcm->mapping_pool, mi);
- send_lisp_eid_table_details (mapit, q, mp->context,
- 0 /* ignore filter */ );
- }
- else
- {
- /* *INDENT-OFF* */
- pool_foreach (mapit, lcm->mapping_pool,
- ({
- send_lisp_eid_table_details(mapit, q, mp->context,
- mp->filter);
- }));
- /* *INDENT-ON* */
- }
-}
-
-static void
-send_lisp_gpe_fwd_entry_details (lisp_gpe_fwd_entry_t * lfe,
- unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_lisp_gpe_tunnel_details_t *rmp;
- lisp_gpe_main_t *lgm = &lisp_gpe_main;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_LISP_GPE_TUNNEL_DETAILS);
-
- rmp->tunnels = lfe - lgm->lisp_fwd_entry_pool;
-
- rmp->is_ipv6 = ip_prefix_version (&(lfe->key->rmt.ippref)) == IP6 ? 1 : 0;
- ip_address_copy_addr (rmp->source_ip,
- &ip_prefix_addr (&(lfe->key->rmt.ippref)));
- ip_address_copy_addr (rmp->destination_ip,
- &ip_prefix_addr (&(lfe->key->rmt.ippref)));
-
- rmp->encap_fib_id = htonl (0);
- rmp->decap_fib_id = htonl (lfe->eid_fib_index);
- rmp->iid = htonl (lfe->key->vni);
- rmp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void
-vl_api_lisp_gpe_tunnel_dump_t_handler (vl_api_lisp_gpe_tunnel_dump_t * mp)
-{
- unix_shared_memory_queue_t *q = NULL;
- lisp_gpe_main_t *lgm = &lisp_gpe_main;
- lisp_gpe_fwd_entry_t *lfe = NULL;
-
- if (pool_elts (lgm->lisp_fwd_entry_pool) == 0)
- {
- return;
- }
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- /* *INDENT-OFF* */
- pool_foreach(lfe, lgm->lisp_fwd_entry_pool,
- ({
- send_lisp_gpe_fwd_entry_details(lfe, q, mp->context);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-send_lisp_map_server_details (ip_address_t * ip,
- unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_lisp_map_server_details_t *rmp = NULL;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_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_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
-{
- unix_shared_memory_queue_t *q = NULL;
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- lisp_msmr_t *mr;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- vec_foreach (mr, lcm->map_servers)
- {
- send_lisp_map_server_details (&mr->address, q, mp->context);
- }
-}
-
-static void
-send_lisp_map_resolver_details (ip_address_t * ip,
- unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_lisp_map_resolver_details_t *rmp = NULL;
-
- 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 ();
- lisp_msmr_t *mr;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- vec_foreach (mr, lcm->map_resolvers)
- {
- send_lisp_map_resolver_details (&mr->address, q, mp->context);
- }
-}
-
-static void
-send_eid_table_map_pair (hash_pair_t * p,
- unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_lisp_eid_table_map_details_t *rmp = NULL;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
-
- rmp->vni = clib_host_to_net_u32 (p->key);
- rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
- rmp->context = context;
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-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;
- uword *vni_table = 0;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- if (mp->is_l2)
- {
- vni_table = lcm->bd_id_by_vni;
- }
- else
- {
- vni_table = lcm->table_id_by_vni;
- }
-
- /* *INDENT-OFF* */
- hash_foreach_pair (p, vni_table,
- ({
- send_eid_table_map_pair (p, q, mp->context);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_lisp_eid_table_vni_details_t *rmp = 0;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
- rmp->context = context;
- rmp->vni = clib_host_to_net_u32 (vni);
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void
-lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
-{
- lisp_adjacency_t *adj;
- vl_api_lisp_adjacency_t a;
- u32 i, n = vec_len (adjs);
-
- for (i = 0; i < n; i++)
- {
- adj = vec_elt_at_index (adjs, i);
- memset (&a, 0, sizeof (a));
-
- switch (gid_address_type (&adj->reid))
- {
- case GID_ADDR_IP_PREFIX:
- a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
- a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
- if (gid_address_ip_version (&adj->reid) == IP4)
- {
- a.eid_type = 0; /* ipv4 type */
- clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
- clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
- }
- else
- {
- a.eid_type = 1; /* ipv6 type */
- clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
- clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
- }
- break;
- case GID_ADDR_MAC:
- a.eid_type = 2; /* l2 mac type */
- mac_copy (a.reid, gid_address_mac (&adj->reid));
- mac_copy (a.leid, gid_address_mac (&adj->leid));
- break;
- default:
- ASSERT (0);
- }
- dst[i] = a;
- }
-}
-
-static void
- vl_api_show_lisp_rloc_probe_state_t_handler
- (vl_api_show_lisp_rloc_probe_state_t * mp)
-{
- vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
- int rv = 0;
-
- /* *INDENT-OFF* */
- REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
- {
- rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
- });
- /* *INDENT-ON* */
-}
-
-static void
- vl_api_show_lisp_map_register_state_t_handler
- (vl_api_show_lisp_map_register_state_t * mp)
-{
- vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
- int rv = 0;
-
- /* *INDENT-OFF* */
- REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
- {
- rmp->is_enabled = vnet_lisp_map_register_state_get ();
- });
- /* *INDENT-ON* */
-}
-
-static void
-vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
-{
- vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
- lisp_adjacency_t *adjs = 0;
- int rv = 0;
- vl_api_lisp_adjacency_t a;
- u32 size = ~0;
- u32 vni = clib_net_to_host_u32 (mp->vni);
-
- adjs = vnet_lisp_adjacencies_get_by_vni (vni);
- size = vec_len (adjs) * sizeof (a);
-
- /* *INDENT-OFF* */
- REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
- {
- rmp->count = clib_host_to_net_u32 (vec_len (adjs));
- lisp_adjacency_copy (rmp->adjacencies, adjs);
- });
- /* *INDENT-ON* */
-
- vec_free (adjs);
-}
-
-static void
-vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
- mp)
-{
- hash_pair_t *p;
- u32 *vnis = 0;
- unix_shared_memory_queue_t *q = 0;
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- /* *INDENT-OFF* */
- hash_foreach_pair (p, lcm->table_id_by_vni,
- ({
- hash_set (vnis, p->key, 0);
- }));
-
- hash_foreach_pair (p, lcm->bd_id_by_vni,
- ({
- hash_set (vnis, p->key, 0);
- }));
-
- hash_foreach_pair (p, vnis,
- ({
- send_eid_table_vni (p->key, q, mp->context);
- }));
- /* *INDENT-ON* */
-
- hash_free (vnis);
-}
-
-static void
-vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
-{
- unix_shared_memory_queue_t *q = NULL;
- vl_api_show_lisp_status_reply_t *rmp = NULL;
- int rv = 0;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
- ({
- rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
- rmp->feature_status = vnet_lisp_enable_disable_status ();
- }));
- /* *INDENT-ON* */
-}
-
-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);
- }
-
- /* *INDENT-OFF* */
- 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);
- }));
- /* *INDENT-ON* */
-
- vec_free (tmp_str);
-}
-
-static void
-vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
-{
- unix_shared_memory_queue_t *q = NULL;
- vl_api_show_lisp_pitr_reply_t *rmp = NULL;
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- mapping_t *m;
- locator_set_t *ls = 0;
- u8 *tmp_str = 0;
- int rv = 0;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- if (!lcm->lisp_pitr)
- {
- tmp_str = format (0, "N/A");
- }
- else
- {
- m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
- if (~0 != m->locator_set_index)
- {
- ls =
- pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
- tmp_str = format (0, "%s", ls->name);
- }
- else
- {
- tmp_str = format (0, "N/A");
- }
- }
- vec_add1 (tmp_str, 0);
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
- ({
- rmp->status = lcm->lisp_pitr;
- strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
- ARRAY_LEN(rmp->locator_set_name) - 1);
- }));
- /* *INDENT-ON* */
-}
-
-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);
- /* *INDENT-OFF* */
- 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 &&
- (!event->mac_ip ||
- /* for BD case, also check IP address with 10 sec timeout */
- (address == event->address &&
- (now - arp_event_last_time) < 10.0)))
- return 1;
- }
- /* *INDENT-ON* */
-
- arp_event_last_time = now;
- event->sw_if_index = sw_if_index;
- if (event->mac_ip)
- event->address = address;
- return 0;
-}
-
-static int
-nd_change_data_callback (u32 pool_index, u8 * new_mac,
- u32 sw_if_index, ip6_address_t * address)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vlib_main_t *vm = am->vlib_main;
- vl_api_ip6_nd_event_t *event;
- static f64 nd_event_last_time;
- f64 now = vlib_time_now (vm);
-
- if (pool_is_free_index (am->nd_events, pool_index))
- return 1;
-
- event = pool_elt_at_index (am->nd_events, pool_index);
-
- /* *INDENT-OFF* */
- 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 &&
- (!event->mac_ip ||
- /* for BD case, also check IP address with 10 sec timeout */
- (ip6_address_is_equal (address,
- (ip6_address_t *) event->address) &&
- (now - nd_event_last_time) < 10.0)))
- return 1;
- }
- /* *INDENT-ON* */
-
- nd_event_last_time = now;
- event->sw_if_index = sw_if_index;
- if (event->mac_ip)
- clib_memcpy (event->address, address, sizeof (event->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 int
-nd_change_delete_callback (u32 pool_index, u8 * notused)
-{
- vpe_api_main_t *am = &vpe_api_main;
-
- if (pool_is_free_index (am->nd_events, pool_index))
- return 1;
-
- pool_put_index (am->nd_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;
- if (mp->address == 0)
- event->mac_ip = 1;
-
- 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_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vnet_main_t *vnm = vnet_get_main ();
- vl_api_want_ip6_nd_events_reply_t *rmp;
- vl_api_ip6_nd_event_t *event;
- int rv;
-
- if (mp->enable_disable)
- {
- pool_get (am->nd_events, event);
- memset (event, 0, sizeof (*event));
-
- event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT);
- event->client_index = mp->client_index;
- event->context = mp->context;
- clib_memcpy (event->address, mp->address, 16);
- event->pid = mp->pid;
- if (ip6_address_is_zero ((ip6_address_t *) mp->address))
- event->mac_ip = 1;
-
- rv = vnet_add_del_ip6_nd_change_event
- (vnm, nd_change_data_callback,
- mp->pid, mp->address /* addr, in net byte order */ ,
- vpe_resolver_process_node.index,
- IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ );
- }
- else
- {
- rv = vnet_add_del_ip6_nd_change_event
- (vnm, nd_change_delete_callback,
- mp->pid, mp->address /* addr, in net byte order */ ,
- vpe_resolver_process_node.index,
- IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ );
- }
- REPLY_MACRO (VL_API_WANT_IP6_ND_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;
-
- if (mp->is_ipv6 || mp->is_ip_any)
- {
- 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);
- }
- else
- {
- clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
- clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
- clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
- clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
- }
- 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_N_ALG)
- {
- 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 DPDK_CRYPTO==1
- if (mp->integrity_algorithm < IPSEC_INTEG_ALG_NONE ||
-#else
- if (mp->integrity_algorithm < IPSEC_INTEG_ALG_SHA1_96 ||
-#endif
- mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
- {
- clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
- mp->integrity_algorithm);
- rv = VNET_API_ERROR_UNIMPLEMENTED;
- goto out;
- }
-
-#if DPDK_CRYPTO==1
- /*Special cases, aes-gcm-128 encryption */
- if (mp->crypto_algorithm == IPSEC_CRYPTO_ALG_AES_GCM_128)
- {
- if (mp->integrity_algorithm != IPSEC_INTEG_ALG_NONE
- && mp->integrity_algorithm != IPSEC_INTEG_ALG_AES_GCM_128)
- {
- clib_warning
- ("unsupported: aes-gcm-128 crypto-alg needs none as integ-alg");
- rv = VNET_API_ERROR_UNIMPLEMENTED;
- goto out;
- }
- else /*set integ-alg internally to aes-gcm-128 */
- mp->integrity_algorithm = IPSEC_INTEG_ALG_AES_GCM_128;
- }
- else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_AES_GCM_128)
- {
- clib_warning ("unsupported integ-alg: aes-gcm-128");
- rv = VNET_API_ERROR_UNIMPLEMENTED;
- goto out;
- }
- else if (mp->integrity_algorithm == IPSEC_INTEG_ALG_NONE)
- {
- clib_warning ("unsupported integ-alg: none");
- rv = VNET_API_ERROR_UNIMPLEMENTED;
- goto out;
- }
-#endif
-
- 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;
- if (sa.is_tunnel_ip6)
- {
- clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
- clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);