-/** Used for transferring locators via VPP API */
-/* *INDENT-OFF* */
-typedef CLIB_PACKED (struct {
- u8 is_ip4; /**< is locator an IPv4 address */
- u8 priority; /**< locator priority */
- u8 weight; /**< locator weight */
- u8 addr[16]; /**< IPv4/IPv6 address */
-}) rloc_t;
-/* *INDENT-ON* */
-
-static locator_pair_t *
-unformat_lisp_loc_pairs (void *lcl_locs, void *rmt_locs, u32 rloc_num)
-{
- u32 i;
- locator_pair_t *pairs = 0, pair;
- rloc_t *r;
-
- for (i = 0; i < rloc_num; i++)
- {
- /* local locator */
- r = &((rloc_t *) lcl_locs)[i];
- memset (&pair.lcl_loc, 0, sizeof (pair.lcl_loc));
- ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
-
- /* remote locators */
- r = &((rloc_t *) rmt_locs)[i];
- memset (&pair.rmt_loc, 0, sizeof (pair.rmt_loc));
- ip_address_set (&pair.rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
-
- pair.priority = r->priority;
- pair.weight = r->weight;
-
- vec_add1 (pairs, pair);
- }
- return pairs;
-}
-
-static locator_t *
-unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
-{
- u32 i;
- locator_t *locs = 0, loc;
- rloc_t *r;
-
- for (i = 0; i < rloc_num; i++)
- {
- /* remote locators */
- r = &((rloc_t *) rmt_locs)[i];
- memset (&loc, 0, sizeof (loc));
- gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
-
- loc.priority = r->priority;
- loc.weight = r->weight;
-
- vec_add1 (locs, loc);
- }
- return locs;
-}
-
-static void
- vl_api_lisp_gpe_add_del_fwd_entry_t_handler
- (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
-{
- vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
- vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
- locator_pair_t *pairs = 0;
- int rv = 0;
-
- memset (a, 0, sizeof (a[0]));
-
- rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
- mp->rmt_eid, mp->rmt_len);
- rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
- mp->lcl_eid, mp->lcl_len);
-
- pairs = unformat_lisp_loc_pairs (mp->lcl_locs, mp->rmt_locs, mp->loc_num);
-
- if (rv || 0 == pairs)
- goto send_reply;
-
- a->is_add = mp->is_add;
- a->locator_pairs = pairs;
- a->dp_table = mp->dp_table;
- a->vni = mp->vni;
- a->action = mp->action;
-
- rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
- vec_free (pairs);
-send_reply:
- REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
-}
-
-static void
-vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
- * mp)
-{
- vl_api_lisp_add_del_map_resolver_reply_t *rmp;
- int rv = 0;
- vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
-
- memset (a, 0, sizeof (a[0]));
-
- a->is_add = mp->is_add;
- ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
-
- rv = vnet_lisp_add_del_map_resolver (a);
-
- REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
-}
-
-static void
-vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
- mp)
-{
- vl_api_lisp_gpe_enable_disable_reply_t *rmp;
- int rv = 0;
- vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
-
- a->is_en = mp->is_en;
- vnet_lisp_gpe_enable_disable (a);
-
- REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
-}
-
-static void
-vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
-{
- vl_api_lisp_enable_disable_reply_t *rmp;
- int rv = 0;
-
- vnet_lisp_enable_disable (mp->is_en);
- REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
-}
-
-static void
-vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
-{
- vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
- int rv = 0;
- vnet_lisp_gpe_add_del_iface_args_t _a, *a = &_a;
-
- a->is_add = mp->is_add;
- a->dp_table = mp->dp_table;
- a->vni = mp->vni;
- a->is_l2 = mp->is_l2;
- rv = vnet_lisp_gpe_add_del_iface (a, 0);
-
- REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
-}
-
-static void
-vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
- * mp)
-{
- vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
- int rv = 0;
- u8 *ls_name = 0;
-
- ls_name = format (0, "%s", mp->ls_name);
- rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
- vec_free (ls_name);
-
- REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
-}
-
-static void
- vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
- (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
-{
- vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
- int rv = 0;
- u8 *locator_set_name = NULL;
- vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
-
- locator_set_name = format (0, "%s", mp->locator_set_name);
-
- a->is_add = mp->is_add;
- a->locator_set_name = locator_set_name;
-
- rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
-
- vec_free (locator_set_name);
-
- REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
-}
-
-static void
- vl_api_lisp_add_del_remote_mapping_t_handler
- (vl_api_lisp_add_del_remote_mapping_t * mp)
-{
- locator_t *rlocs = 0;
- vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
- int rv = 0;
- gid_address_t _eid, *eid = &_eid;
-
- memset (eid, 0, sizeof (eid[0]));
-
- rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
- mp->eid_type, mp->eid, mp->eid_len);
- if (rv)
- goto send_reply;
-
- rlocs = unformat_lisp_locs (mp->rlocs, mp->rloc_num);
- if (0 == rlocs)
- goto send_reply;
-
- if (!mp->is_add)
- {
- vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
- gid_address_copy (&a->deid, eid);
- a->is_add = 0;
- rv = vnet_lisp_add_del_adjacency (a);
- if (rv)
- {
- goto out;
- }
- }
-
- /* NOTE: for now this works as a static remote mapping, i.e.,
- * not authoritative and ttl infinite. */
- rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
- mp->is_add, 0);
-
- if (mp->del_all)
- vnet_lisp_clear_all_remote_adjacencies ();
-
-out:
- vec_free (rlocs);
-send_reply:
- REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
-}
-
-static void
-vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
-{
- vl_api_lisp_add_del_adjacency_reply_t *rmp;
- vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
-
- int rv = 0;
- memset (a, 0, sizeof (a[0]));
-
- rv = unformat_lisp_eid_api (&a->seid, clib_net_to_host_u32 (mp->vni),
- mp->eid_type, mp->seid, mp->seid_len);
- rv |= unformat_lisp_eid_api (&a->deid, clib_net_to_host_u32 (mp->vni),
- mp->eid_type, mp->deid, mp->deid_len);
-
- if (rv)
- goto send_reply;
-
- 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)
-{
- 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;
- u8 filter;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- ls_index = htonl (mp->locator_set_index);
-
- lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
-
- filter = mp->filter;
- if (filter && !((1 == filter && lsit->local) ||
- (2 == filter && !lsit->local)))
- {
- return;
- }
-
- 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);
- };
-}
-
-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->local = lsit->local;
- rmp->locator_set_index = htonl (ls_index);
- if (lsit->local)
- {
- ASSERT (lsit->name != NULL);
- strncpy ((char *) rmp->locator_set_name,
- (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1);
- }
- else
- {
- str = format (0, "remote-%d", ls_index);
- strncpy ((char *) rmp->locator_set_name, (char *) str,
- ARRAY_LEN (rmp->locator_set_name) - 1);
- 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;
- u32 index;
- u8 filter;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- filter = mp->filter;
- index = 0;
- /* *INDENT-OFF* */
- pool_foreach (lsit, lcm->locator_set_pool,
- ({
- if (filter && !((1 == filter && lsit->local) ||
- (2 == filter && !lsit->local))) {
- index++;
- continue;
- }
- send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-send_lisp_eid_table_details (mapping_t * mapit,
- unix_shared_memory_queue_t * q,
- u32 context, u8 filter)
-{
- 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);
- rmp->locator_set_index = mapit->locator_set_index;
- rmp->is_local = mapit->local;
- rmp->ttl = mapit->ttl;
- rmp->authoritative = mapit->authoritative;
-
- switch (gid_address_type (gid))
- {
- 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));
- 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, mp->eid_type,
- clib_net_to_host_u32 (mp->vni), 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_tunnel_details (lisp_gpe_tunnel_t * tunnel,
- 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 = tunnel - lgm->tunnels;
-
- rmp->is_ipv6 = ip_addr_version (&tunnel->src) == IP6 ? 1 : 0;
- ip_address_copy_addr (rmp->source_ip, &tunnel->src);
- ip_address_copy_addr (rmp->destination_ip, &tunnel->dst);
-
- rmp->encap_fib_id = htonl (tunnel->encap_fib_index);
- rmp->decap_fib_id = htonl (tunnel->decap_fib_index);
- rmp->dcap_next = htonl (tunnel->decap_next_index);
- rmp->lisp_ver = tunnel->ver_res;
- rmp->next_protocol = tunnel->next_protocol;
- rmp->flags = tunnel->flags;
- rmp->ver_res = tunnel->ver_res;
- rmp->res = tunnel->res;
- rmp->iid = htonl (tunnel->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_tunnel_t *tunnel = NULL;
-
- if (pool_elts (lgm->tunnels) == 0)
- {
- return;
- }
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- /* *INDENT-OFF* */
- pool_foreach(tunnel, lgm->tunnels,
- ({
- send_lisp_gpe_tunnel_details(tunnel, q, mp->context);
- }));
- /* *INDENT-ON* */
-}
-
-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 ();
- 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
-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->vrf = 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;
-
- 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,
- ({
- send_eid_table_map_pair (p, q, mp->context);
- }));
- /* *INDENT-ON* */
-}
-
-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);
- }