LCOV - code coverage report
Current view: top level - plugins/lisp/lisp-cp - one_api.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 4 729 0.5 %
Date: 2023-10-26 01:39:38 Functions: 3 68 4.4 %

          Line data    Source code
       1             : /*
       2             :  *------------------------------------------------------------------
       3             :  * one_api.c - Overlay Network Engine API
       4             :  *
       5             :  * Copyright (c) 2016-2017 Cisco and/or its affiliates.
       6             :  * Licensed under the Apache License, Version 2.0 (the "License");
       7             :  * you may not use this file except in compliance with the License.
       8             :  * You may obtain a copy of the License at:
       9             :  *
      10             :  *     http://www.apache.org/licenses/LICENSE-2.0
      11             :  *
      12             :  * Unless required by applicable law or agreed to in writing, software
      13             :  * distributed under the License is distributed on an "AS IS" BASIS,
      14             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15             :  * See the License for the specific language governing permissions and
      16             :  * limitations under the License.
      17             :  *------------------------------------------------------------------
      18             :  */
      19             : 
      20             : #include <vnet/vnet.h>
      21             : #include <vlibmemory/api.h>
      22             : 
      23             : #include <vnet/interface.h>
      24             : #include <vnet/api_errno.h>
      25             : #include <lisp/lisp-cp/control.h>
      26             : #include <lisp/lisp-gpe/lisp_gpe.h>
      27             : 
      28             : #include <vnet/ip/ip_types_api.h>
      29             : #include <vnet/ethernet/ethernet_types_api.h>
      30             : 
      31             : /* define message IDs */
      32             : #include <vnet/format_fns.h>
      33             : #include <lisp/lisp-cp/one.api_enum.h>
      34             : #include <lisp/lisp-cp/one.api_types.h>
      35             : 
      36             : /**
      37             :  * Base message ID fot the plugin
      38             :  */
      39             : static u32 one_base_msg_id;
      40             : #define REPLY_MSG_ID_BASE one_base_msg_id
      41             : 
      42             : #include <vlibapi/api_helper_macros.h>
      43             : 
      44             : #define REPLY_DETAILS(t, body)                                          \
      45             : do {                                                                    \
      46             :     vl_api_registration_t * reg;                                        \
      47             :     reg = vl_api_client_index_to_registration (mp->client_index);    \
      48             :     if (!reg)                                                           \
      49             :       return;                                                           \
      50             :                                                                   \
      51             :     rmp = vl_msg_api_alloc (sizeof (*rmp));                             \
      52             :     rmp->_vl_msg_id = ntohs((t));                                    \
      53             :     rmp->context = mp->context;                                   \
      54             :     do {body;} while (0);                                               \
      55             :     vl_api_send_msg (reg, (u8 *)&rmp);                                      \
      56             : } while(0);
      57             : 
      58             : #define foreach_vpe_api_msg                                                     \
      59             : _(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set)                     \
      60             : _(ONE_ADD_DEL_LOCATOR, one_add_del_locator)                             \
      61             : _(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid)                         \
      62             : _(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver)                   \
      63             : _(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server)                       \
      64             : _(ONE_ENABLE_DISABLE, one_enable_disable)                               \
      65             : _(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable)         \
      66             : _(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable)     \
      67             : _(ONE_MAP_REGISTER_FALLBACK_THRESHOLD,                                  \
      68             :   one_map_register_fallback_threshold)                                  \
      69             : _(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping)               \
      70             : _(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency)                         \
      71             : _(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set)                   \
      72             : _(ONE_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set)                     \
      73             : _(ONE_MAP_REQUEST_MODE, one_map_request_mode)                           \
      74             : _(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map)                 \
      75             : _(ONE_LOCATOR_SET_DUMP, one_locator_set_dump)                           \
      76             : _(ONE_LOCATOR_DUMP, one_locator_dump)                                   \
      77             : _(ONE_EID_TABLE_DUMP, one_eid_table_dump)                               \
      78             : _(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump)                         \
      79             : _(ONE_MAP_SERVER_DUMP, one_map_server_dump)                             \
      80             : _(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump)                       \
      81             : _(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump)                       \
      82             : _(ONE_ADJACENCIES_GET, one_adjacencies_get)                             \
      83             : _(ONE_MAP_REGISTER_SET_TTL, one_map_register_set_ttl)                   \
      84             : _(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping)                           \
      85             : _(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state)                 \
      86             : _(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state)             \
      87             : _(SHOW_ONE_MAP_REGISTER_TTL, show_one_map_register_ttl)                 \
      88             : _(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD,                             \
      89             :   show_one_map_register_fallback_threshold)                             \
      90             : _(SHOW_ONE_STATUS, show_one_status)                                     \
      91             : _(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS,                                    \
      92             :   one_add_del_map_request_itr_rlocs)                                    \
      93             : _(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs)         \
      94             : _(SHOW_ONE_PITR, show_one_pitr)                                         \
      95             : _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode)                 \
      96             : _(ONE_USE_PETR, one_use_petr)                                           \
      97             : _(SHOW_ONE_USE_PETR, show_one_use_petr)                                 \
      98             : _(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable)         \
      99             : _(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable)                   \
     100             : _(ONE_STATS_DUMP, one_stats_dump)                                       \
     101             : _(ONE_STATS_FLUSH, one_stats_flush)                                     \
     102             : _(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get)                                 \
     103             : _(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get)                       \
     104             : _(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry)                   \
     105             : _(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry)                         \
     106             : _(ONE_NDP_BD_GET, one_ndp_bd_get)                                       \
     107             : _(ONE_NDP_ENTRIES_GET, one_ndp_entries_get)                             \
     108             : _(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol)               \
     109             : _(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol)               \
     110             : _(ONE_ENABLE_DISABLE_XTR_MODE, one_enable_disable_xtr_mode)             \
     111             : _(ONE_SHOW_XTR_MODE, one_show_xtr_mode)                                 \
     112             : _(ONE_ENABLE_DISABLE_PITR_MODE, one_enable_disable_pitr_mode)           \
     113             : _(ONE_SHOW_PITR_MODE, one_show_pitr_mode)                               \
     114             : _(ONE_ENABLE_DISABLE_PETR_MODE, one_enable_disable_petr_mode)           \
     115             : _(ONE_SHOW_PETR_MODE, one_show_petr_mode)                               \
     116             : 
     117             : 
     118             : static locator_t *
     119           0 : unformat_one_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
     120             : {
     121             :   u32 i;
     122           0 :   locator_t *locs = 0, loc;
     123             :   vl_api_remote_locator_t *r;
     124             : 
     125           0 :   for (i = 0; i < rloc_num; i++)
     126             :     {
     127             :       /* remote locators */
     128           0 :       r = &rmt_locs[i];
     129           0 :       clib_memset (&loc, 0, sizeof (loc));
     130           0 :       ip_address_decode2 (&r->ip_address, &loc.address.ippref.addr);
     131           0 :       loc.address.ippref.len =
     132           0 :         ip_address_max_len (loc.address.ippref.addr.version);
     133             : 
     134           0 :       loc.priority = r->priority;
     135           0 :       loc.weight = r->weight;
     136             : 
     137           0 :       vec_add1 (locs, loc);
     138             :     }
     139           0 :   return locs;
     140             : }
     141             : 
     142             : static void
     143           0 : vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t *
     144             :                                            mp)
     145             : {
     146             :   vl_api_one_map_register_set_ttl_reply_t *rmp;
     147           0 :   int rv = 0;
     148             : 
     149           0 :   mp->ttl = clib_net_to_host_u32 (mp->ttl);
     150           0 :   rv = vnet_lisp_map_register_set_ttl (mp->ttl);
     151             : 
     152           0 :   REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY);
     153             : }
     154             : 
     155             : static void
     156           0 :   vl_api_show_one_map_register_ttl_t_handler
     157             :   (vl_api_show_one_map_register_ttl_t * mp)
     158             : {
     159             :   vl_api_show_one_map_register_ttl_reply_t *rmp;
     160           0 :   int rv = 0;
     161             : 
     162           0 :   u32 ttl = vnet_lisp_map_register_get_ttl ();
     163             :   /* *INDENT-OFF* */
     164           0 :   REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY,
     165             :   ({
     166             :     rmp->ttl = clib_host_to_net_u32 (ttl);
     167             :   }));
     168             :   /* *INDENT-ON* */
     169             : }
     170             : 
     171             : static void
     172           0 : vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
     173             :                                           mp)
     174             : {
     175             :   vl_api_one_add_del_locator_set_reply_t *rmp;
     176           0 :   int rv = 0;
     177           0 :   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
     178             :   locator_t locator;
     179             :   vl_api_local_locator_t *ls_loc;
     180           0 :   u32 ls_index = ~0, locator_num;
     181           0 :   u8 *locator_name = NULL;
     182             :   int i;
     183             : 
     184           0 :   clib_memset (a, 0, sizeof (a[0]));
     185             : 
     186           0 :   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
     187           0 :   locator_name = format (0, "%s", mp->locator_set_name);
     188           0 :   vec_terminate_c_string (locator_name);
     189             : 
     190           0 :   a->name = locator_name;
     191           0 :   a->is_add = mp->is_add;
     192           0 :   a->local = 1;
     193           0 :   locator_num = clib_net_to_host_u32 (mp->locator_num);
     194             : 
     195           0 :   clib_memset (&locator, 0, sizeof (locator));
     196           0 :   for (i = 0; i < locator_num; i++)
     197             :     {
     198           0 :       ls_loc = &mp->locators[i];
     199           0 :       VALIDATE_SW_IF_INDEX (ls_loc);
     200             : 
     201           0 :       locator.sw_if_index = htonl (ls_loc->sw_if_index);
     202           0 :       locator.priority = ls_loc->priority;
     203           0 :       locator.weight = ls_loc->weight;
     204           0 :       locator.local = 1;
     205           0 :       vec_add1 (a->locators, locator);
     206             :     }
     207             : 
     208           0 :   rv = vnet_lisp_add_del_locator_set (a, &ls_index);
     209             : 
     210           0 :   BAD_SW_IF_INDEX_LABEL;
     211             : 
     212           0 :   vec_free (locator_name);
     213           0 :   vec_free (a->locators);
     214             : 
     215             :   /* *INDENT-OFF* */
     216           0 :   REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
     217             :   ({
     218             :     rmp->ls_index = clib_host_to_net_u32 (ls_index);
     219             :   }));
     220             :   /* *INDENT-ON* */
     221             : }
     222             : 
     223             : static void
     224           0 : vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
     225             : {
     226             :   vl_api_one_add_del_locator_reply_t *rmp;
     227           0 :   int rv = 0;
     228           0 :   locator_t locator, *locators = NULL;
     229           0 :   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
     230           0 :   u32 ls_index = ~0;
     231           0 :   u8 *locator_name = NULL;
     232             : 
     233           0 :   clib_memset (&locator, 0, sizeof (locator));
     234           0 :   clib_memset (a, 0, sizeof (a[0]));
     235             : 
     236           0 :   locator.sw_if_index = ntohl (mp->sw_if_index);
     237           0 :   locator.priority = mp->priority;
     238           0 :   locator.weight = mp->weight;
     239           0 :   locator.local = 1;
     240           0 :   vec_add1 (locators, locator);
     241             : 
     242           0 :   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
     243           0 :   locator_name = format (0, "%s", mp->locator_set_name);
     244           0 :   vec_terminate_c_string (locator_name);
     245             : 
     246           0 :   a->name = locator_name;
     247           0 :   a->locators = locators;
     248           0 :   a->is_add = mp->is_add;
     249           0 :   a->local = 1;
     250             : 
     251           0 :   rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
     252             : 
     253           0 :   vec_free (locators);
     254           0 :   vec_free (locator_name);
     255             : 
     256           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
     257             : }
     258             : 
     259             : typedef struct
     260             : {
     261             :   u32 spi;
     262             :   u8 si;
     263             : } __attribute__ ((__packed__)) lisp_nsh_api_t;
     264             : 
     265             : static int
     266           0 : unformat_one_eid_api (gid_address_t * dst, u32 vni, vl_api_eid_t * eid)
     267             : {
     268             :   fib_prefix_t prefix;
     269             : 
     270           0 :   switch (eid->type)
     271             :     {
     272           0 :     case EID_TYPE_API_PREFIX:
     273           0 :       ip_prefix_decode (&eid->address.prefix, &prefix);
     274           0 :       gid_address_type (dst) = GID_ADDR_IP_PREFIX;
     275           0 :       if (prefix.fp_proto == FIB_PROTOCOL_IP4)
     276           0 :         gid_address_ip_set (dst, &prefix.fp_addr.ip4, AF_IP4);
     277           0 :       if (prefix.fp_proto == FIB_PROTOCOL_IP6)
     278           0 :         gid_address_ip_set (dst, &prefix.fp_addr.ip6, AF_IP6);
     279           0 :       gid_address_ippref_len (dst) = prefix.fp_len;
     280           0 :       ip_prefix_normalize (&gid_address_ippref (dst));
     281           0 :       break;
     282           0 :     case EID_TYPE_API_MAC:
     283           0 :       gid_address_type (dst) = GID_ADDR_MAC;
     284           0 :       mac_address_decode (eid->address.mac,
     285           0 :                           (mac_address_t *) & gid_address_mac (dst));
     286           0 :       break;
     287           0 :     case EID_TYPE_API_NSH:
     288           0 :       gid_address_type (dst) = GID_ADDR_NSH;
     289           0 :       gid_address_nsh_spi (dst) = clib_net_to_host_u32 (eid->address.nsh.spi);
     290           0 :       gid_address_nsh_si (dst) = eid->address.nsh.si;
     291           0 :       break;
     292           0 :     default:
     293             :       /* unknown type */
     294           0 :       return VNET_API_ERROR_INVALID_VALUE;
     295             :     }
     296             : 
     297           0 :   gid_address_vni (dst) = vni;
     298             : 
     299           0 :   return 0;
     300             : }
     301             : 
     302             : static void
     303           0 : fid_to_api_eid (fid_address_t * fid, vl_api_eid_t * eid)
     304             : {
     305             :   fib_prefix_t fib_prefix;
     306             :   u32 eid_type;
     307             : 
     308           0 :   switch (fid_addr_type (fid))
     309             :     {
     310           0 :     case FID_ADDR_IP_PREF:
     311           0 :       eid_type = EID_TYPE_API_PREFIX;
     312           0 :       ip_prefix_to_fib_prefix (&fid_addr_ippref (fid), &fib_prefix);
     313           0 :       ip_prefix_encode (&fib_prefix, &eid->address.prefix);
     314           0 :       break;
     315           0 :     case FID_ADDR_MAC:
     316           0 :       eid_type = EID_TYPE_API_MAC;
     317           0 :       mac_address_encode ((mac_address_t *) fid_addr_mac (fid),
     318           0 :                           eid->address.mac);
     319           0 :       break;
     320           0 :     default:
     321             :       /* unknown type */
     322           0 :       return;
     323             :     }
     324             : 
     325           0 :   eid->type = eid_type;
     326             : }
     327             : 
     328             : static void
     329           0 : vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
     330             : {
     331             :   vl_api_one_add_del_local_eid_reply_t *rmp;
     332           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     333           0 :   int rv = 0;
     334           0 :   gid_address_t _eid, *eid = &_eid;
     335           0 :   uword *p = NULL;
     336           0 :   u32 locator_set_index = ~0, map_index = ~0;
     337           0 :   vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
     338           0 :   u8 *name = NULL, *key = NULL;
     339           0 :   clib_memset (a, 0, sizeof (a[0]));
     340           0 :   clib_memset (eid, 0, sizeof (eid[0]));
     341             : 
     342           0 :   rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->eid);
     343           0 :   if (rv)
     344           0 :     goto out;
     345             : 
     346           0 :   if (gid_address_type (eid) == GID_ADDR_NSH)
     347             :     {
     348           0 :       rv = VNET_API_ERROR_INVALID_VALUE;
     349           0 :       goto out;
     350             :     }
     351             : 
     352           0 :   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
     353           0 :   name = format (0, "%s", mp->locator_set_name);
     354           0 :   vec_terminate_c_string (name);
     355           0 :   p = hash_get_mem (lcm->locator_set_index_by_name, name);
     356           0 :   if (!p)
     357             :     {
     358           0 :       rv = VNET_API_ERROR_INVALID_VALUE;
     359           0 :       goto out;
     360             :     }
     361           0 :   locator_set_index = p[0];
     362             : 
     363           0 :   if (mp->key.id != KEY_ID_API_HMAC_NO_KEY)
     364           0 :     key = format (0, "%s", mp->key.key);
     365             : 
     366             :   /* XXX treat batch configuration */
     367           0 :   a->is_add = mp->is_add;
     368           0 :   gid_address_copy (&a->eid, eid);
     369           0 :   a->locator_set_index = locator_set_index;
     370           0 :   a->local = 1;
     371           0 :   a->key = key;
     372           0 :   a->key_id = mp->key.id;
     373             : 
     374           0 :   rv = vnet_lisp_add_del_local_mapping (a, &map_index);
     375             : 
     376           0 : out:
     377           0 :   vec_free (name);
     378           0 :   vec_free (key);
     379           0 :   gid_address_free (&a->eid);
     380             : 
     381           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
     382             : }
     383             : 
     384             : static void
     385           0 :   vl_api_one_eid_table_add_del_map_t_handler
     386             :   (vl_api_one_eid_table_add_del_map_t * mp)
     387             : {
     388             :   vl_api_one_eid_table_add_del_map_reply_t *rmp;
     389           0 :   int rv = 0;
     390           0 :   rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
     391             :                                 clib_net_to_host_u32 (mp->dp_table),
     392           0 :                                 mp->is_l2, mp->is_add);
     393           0 : REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
     394             : 
     395             : static void
     396           0 : vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
     397             : {
     398             :   vl_api_one_add_del_map_server_reply_t *rmp;
     399           0 :   int rv = 0;
     400             :   ip_address_t addr;
     401             : 
     402           0 :   clib_memset (&addr, 0, sizeof (addr));
     403             : 
     404           0 :   ip_address_decode2 (&mp->ip_address, &addr);
     405             : 
     406           0 :   rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
     407             : 
     408           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
     409             : }
     410             : 
     411             : static void
     412           0 : vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
     413             :                                            * mp)
     414             : {
     415             :   vl_api_one_add_del_map_resolver_reply_t *rmp;
     416           0 :   int rv = 0;
     417           0 :   vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
     418             : 
     419           0 :   clib_memset (a, 0, sizeof (a[0]));
     420             : 
     421           0 :   ip_address_decode2 (&mp->ip_address, &a->address);
     422             : 
     423           0 :   a->is_add = mp->is_add;
     424             : 
     425           0 :   rv = vnet_lisp_add_del_map_resolver (a);
     426             : 
     427           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
     428             : }
     429             : 
     430             : static void
     431           0 :   vl_api_one_map_register_enable_disable_t_handler
     432             :   (vl_api_one_map_register_enable_disable_t * mp)
     433             : {
     434             :   vl_api_one_map_register_enable_disable_reply_t *rmp;
     435           0 :   int rv = 0;
     436             : 
     437           0 :   vnet_lisp_map_register_enable_disable (mp->is_enable);
     438           0 :   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
     439             : }
     440             : 
     441             : static void
     442           0 :   vl_api_one_rloc_probe_enable_disable_t_handler
     443             :   (vl_api_one_rloc_probe_enable_disable_t * mp)
     444             : {
     445             :   vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
     446           0 :   int rv = 0;
     447             : 
     448           0 :   vnet_lisp_rloc_probe_enable_disable (mp->is_enable);
     449           0 :   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
     450             : }
     451             : 
     452             : static void
     453           0 : vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
     454             : {
     455             :   vl_api_one_enable_disable_reply_t *rmp;
     456           0 :   int rv = 0;
     457             : 
     458           0 :   vnet_lisp_enable_disable (mp->is_enable);
     459           0 :   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
     460             : }
     461             : 
     462             : static void
     463           0 :   vl_api_show_one_map_request_mode_t_handler
     464             :   (vl_api_show_one_map_request_mode_t * mp)
     465             : {
     466           0 :   int rv = 0;
     467             :   vl_api_show_one_map_request_mode_reply_t *rmp;
     468             : 
     469             :   /* *INDENT-OFF* */
     470           0 :   REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
     471             :   ({
     472             :     rmp->mode = vnet_lisp_get_map_request_mode ();
     473             :   }));
     474             :   /* *INDENT-ON* */
     475             : }
     476             : 
     477             : static void
     478           0 : vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
     479             : {
     480             :   vl_api_one_map_request_mode_reply_t *rmp;
     481           0 :   int rv = 0;
     482             : 
     483           0 :   rv = vnet_lisp_set_map_request_mode (mp->mode);
     484             : 
     485           0 :   REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
     486             : }
     487             : 
     488             : static void
     489           0 : vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t
     490             :                                           * mp)
     491             : {
     492             :   vl_api_one_nsh_set_locator_set_reply_t *rmp;
     493           0 :   int rv = 0;
     494           0 :   u8 *ls_name = 0;
     495             : 
     496           0 :   mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
     497           0 :   ls_name = format (0, "%s", mp->ls_name);
     498           0 :   vec_terminate_c_string (ls_name);
     499           0 :   rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add);
     500           0 :   vec_free (ls_name);
     501             : 
     502           0 :   REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
     503             : }
     504             : 
     505             : static void
     506           0 : vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
     507             :                                            * mp)
     508             : {
     509             :   vl_api_one_pitr_set_locator_set_reply_t *rmp;
     510           0 :   int rv = 0;
     511           0 :   u8 *ls_name = 0;
     512             : 
     513           0 :   mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
     514           0 :   ls_name = format (0, "%s", mp->ls_name);
     515           0 :   vec_terminate_c_string (ls_name);
     516           0 :   rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
     517           0 :   vec_free (ls_name);
     518             : 
     519           0 :   REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
     520             : }
     521             : 
     522             : static void
     523           0 : vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
     524             : {
     525             :   vl_api_one_use_petr_reply_t *rmp;
     526           0 :   int rv = 0;
     527             :   ip_address_t addr;
     528             : 
     529           0 :   ip_address_decode2 (&mp->ip_address, &addr);
     530             : 
     531           0 :   rv = vnet_lisp_use_petr (&addr, mp->is_add);
     532             : 
     533           0 :   REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
     534             : }
     535             : 
     536             : static void
     537           0 : vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
     538             : {
     539           0 :   vl_api_show_one_use_petr_reply_t *rmp = NULL;
     540           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     541             :   mapping_t *m;
     542           0 :   locator_set_t *ls = 0;
     543           0 :   int rv = 0;
     544           0 :   locator_t *loc = 0;
     545           0 :   u8 status = 0;
     546             :   gid_address_t addr;
     547             : 
     548           0 :   clib_memset (&addr, 0, sizeof (addr));
     549           0 :   status = lcm->flags & LISP_FLAG_USE_PETR;
     550           0 :   if (status)
     551             :     {
     552           0 :       m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
     553           0 :       if (~0 != m->locator_set_index)
     554             :         {
     555           0 :           ls =
     556           0 :             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
     557           0 :           loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
     558           0 :           gid_address_copy (&addr, &loc->address);
     559             :         }
     560             :     }
     561             : 
     562             :   /* *INDENT-OFF* */
     563           0 :   REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
     564             :   {
     565             :     rmp->status = status;
     566             :     ip_address_t *ip = &gid_address_ip (&addr);
     567             : 
     568             :     ip_address_encode2 (ip, &rmp->ip_address);
     569             :   });
     570             :   /* *INDENT-ON* */
     571             : }
     572             : 
     573             : static void
     574           0 :   vl_api_one_add_del_map_request_itr_rlocs_t_handler
     575             :   (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
     576             : {
     577             :   vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
     578           0 :   int rv = 0;
     579           0 :   u8 *locator_set_name = NULL;
     580           0 :   vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
     581             : 
     582           0 :   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
     583           0 :   locator_set_name = format (0, "%s", mp->locator_set_name);
     584           0 :   vec_terminate_c_string (locator_set_name);
     585             : 
     586           0 :   a->is_add = mp->is_add;
     587           0 :   a->locator_set_name = locator_set_name;
     588             : 
     589           0 :   rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
     590             : 
     591           0 :   vec_free (locator_set_name);
     592             : 
     593           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
     594             : }
     595             : 
     596             : static void
     597           0 :   vl_api_one_add_del_remote_mapping_t_handler
     598             :   (vl_api_one_add_del_remote_mapping_t * mp)
     599             : {
     600           0 :   locator_t *rlocs = 0;
     601             :   vl_api_one_add_del_remote_mapping_reply_t *rmp;
     602           0 :   int rv = 0;
     603           0 :   gid_address_t _eid, *eid = &_eid;
     604           0 :   u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
     605             : 
     606           0 :   clib_memset (eid, 0, sizeof (eid[0]));
     607             : 
     608           0 :   rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->deid);
     609           0 :   if (rv)
     610           0 :     goto send_reply;
     611             : 
     612           0 :   rlocs = unformat_one_locs (mp->rlocs, rloc_num);
     613             : 
     614           0 :   if (!mp->is_add)
     615             :     {
     616           0 :       vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
     617           0 :       clib_memset (a, 0, sizeof (a[0]));
     618           0 :       gid_address_copy (&a->reid, eid);
     619           0 :       a->is_add = 0;
     620           0 :       rv = vnet_lisp_add_del_adjacency (a);
     621           0 :       if (rv)
     622             :         {
     623           0 :           goto out;
     624             :         }
     625             :     }
     626             : 
     627             :   /* NOTE: for now this works as a static remote mapping, i.e.,
     628             :    * not authoritative and ttl infinite. */
     629           0 :   if (mp->is_add)
     630             :     {
     631           0 :       vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
     632           0 :       clib_memset (m_args, 0, sizeof (m_args[0]));
     633           0 :       gid_address_copy (&m_args->eid, eid);
     634           0 :       m_args->action = mp->action;
     635           0 :       m_args->is_static = 1;
     636           0 :       m_args->ttl = ~0;
     637           0 :       m_args->authoritative = 0;
     638           0 :       rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
     639             :     }
     640             :   else
     641           0 :     rv = vnet_lisp_del_mapping (eid, NULL);
     642             : 
     643           0 :   if (mp->del_all)
     644           0 :     vnet_lisp_clear_all_remote_adjacencies ();
     645             : 
     646           0 : out:
     647           0 :   vec_free (rlocs);
     648           0 : send_reply:
     649           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
     650             : }
     651             : 
     652             : static void
     653           0 : vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
     654             : {
     655             :   vl_api_one_add_del_adjacency_reply_t *rmp;
     656           0 :   vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
     657             : 
     658           0 :   int rv = 0;
     659           0 :   clib_memset (a, 0, sizeof (a[0]));
     660             : 
     661             :   rv =
     662           0 :     unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
     663             :                           &mp->leid);
     664           0 :   rv |=
     665           0 :     unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
     666             :                           &mp->reid);
     667             : 
     668           0 :   if (rv)
     669           0 :     goto send_reply;
     670             : 
     671           0 :   a->is_add = mp->is_add;
     672           0 :   rv = vnet_lisp_add_del_adjacency (a);
     673             : 
     674           0 : send_reply:
     675           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
     676             : }
     677             : 
     678             : static void
     679           0 : send_one_locator_details (lisp_cp_main_t * lcm,
     680             :                           locator_t * loc, vl_api_registration_t * reg,
     681             :                           u32 context)
     682             : {
     683             :   vl_api_one_locator_details_t *rmp;
     684             : 
     685           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
     686           0 :   clib_memset (rmp, 0, sizeof (*rmp));
     687           0 :   rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
     688           0 :   rmp->context = context;
     689             : 
     690           0 :   rmp->local = loc->local;
     691           0 :   if (loc->local)
     692             :     {
     693           0 :       rmp->sw_if_index = ntohl (loc->sw_if_index);
     694             :     }
     695             :   else
     696             :     {
     697           0 :       ip_address_encode2 (&loc->address.ippref.addr, &rmp->ip_address);
     698             :     }
     699           0 :   rmp->priority = loc->priority;
     700           0 :   rmp->weight = loc->weight;
     701             : 
     702           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     703           0 : }
     704             : 
     705             : static void
     706           0 : vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
     707             : {
     708           0 :   u8 *ls_name = 0;
     709             :   vl_api_registration_t *reg;
     710           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     711           0 :   locator_set_t *lsit = 0;
     712           0 :   locator_t *loc = 0;
     713           0 :   u32 ls_index = ~0, *locit = 0;
     714           0 :   uword *p = 0;
     715             : 
     716           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     717           0 :   if (!reg)
     718           0 :     return;
     719             : 
     720           0 :   if (mp->is_index_set)
     721           0 :     ls_index = htonl (mp->ls_index);
     722             :   else
     723             :     {
     724             :       /* make sure we get a proper C-string */
     725           0 :       mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
     726           0 :       ls_name = format (0, "%s", mp->ls_name);
     727           0 :       vec_terminate_c_string (ls_name);
     728           0 :       p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
     729           0 :       if (!p)
     730           0 :         goto out;
     731           0 :       ls_index = p[0];
     732             :     }
     733             : 
     734           0 :   if (pool_is_free_index (lcm->locator_set_pool, ls_index))
     735           0 :     return;
     736             : 
     737           0 :   lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
     738             : 
     739           0 :   vec_foreach (locit, lsit->locator_indices)
     740             :   {
     741           0 :     loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
     742           0 :     send_one_locator_details (lcm, loc, reg, mp->context);
     743             :   };
     744           0 : out:
     745           0 :   vec_free (ls_name);
     746             : }
     747             : 
     748             : static void
     749           0 : send_one_locator_set_details (lisp_cp_main_t * lcm,
     750             :                               locator_set_t * lsit,
     751             :                               vl_api_registration_t * reg, u32 context,
     752             :                               u32 ls_index)
     753             : {
     754             :   vl_api_one_locator_set_details_t *rmp;
     755           0 :   u8 *str = 0;
     756             : 
     757           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
     758           0 :   clib_memset (rmp, 0, sizeof (*rmp));
     759           0 :   rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
     760           0 :   rmp->context = context;
     761             : 
     762           0 :   rmp->ls_index = htonl (ls_index);
     763           0 :   if (lsit->local)
     764             :     {
     765           0 :       ASSERT (lsit->name != NULL);
     766           0 :       strncpy ((char *) rmp->ls_name, (char *) lsit->name,
     767           0 :                vec_len (lsit->name));
     768             :     }
     769             :   else
     770             :     {
     771           0 :       str = format (0, "<remote-%d>", ls_index);
     772           0 :       strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
     773           0 :       vec_free (str);
     774             :     }
     775             : 
     776           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     777           0 : }
     778             : 
     779             : static void
     780           0 : vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
     781             : {
     782             :   vl_api_registration_t *reg;
     783           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     784           0 :   locator_set_t *lsit = NULL;
     785             :   u8 filter;
     786             : 
     787           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     788           0 :   if (!reg)
     789           0 :     return;
     790             : 
     791           0 :   filter = mp->filter;
     792             :   /* *INDENT-OFF* */
     793           0 :   pool_foreach (lsit, lcm->locator_set_pool)
     794             :    {
     795           0 :     if (filter && !((1 == filter && lsit->local) ||
     796           0 :                     (2 == filter && !lsit->local)))
     797             :       {
     798           0 :         continue;
     799             :       }
     800           0 :     send_one_locator_set_details (lcm, lsit, reg, mp->context,
     801           0 :                                    lsit - lcm->locator_set_pool);
     802             :   }
     803             :   /* *INDENT-ON* */
     804             : }
     805             : 
     806             : static void
     807           0 : send_one_eid_table_details (mapping_t * mapit,
     808             :                             vl_api_registration_t * reg, u32 context,
     809             :                             u8 filter)
     810             : {
     811           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     812           0 :   locator_set_t *ls = 0;
     813           0 :   vl_api_one_eid_table_details_t *rmp = NULL;
     814           0 :   gid_address_t *gid = NULL;
     815             :   u32 eid_type;
     816             :   fib_prefix_t fib_prefix;
     817             : 
     818           0 :   if (mapit->pitr_set || mapit->nsh_set)
     819           0 :     return;
     820             : 
     821           0 :   switch (filter)
     822             :     {
     823           0 :     case ONE_FILTER_API_ALL:    /* all mappings */
     824           0 :       break;
     825             : 
     826           0 :     case ONE_FILTER_API_LOCAL:  /* local only */
     827           0 :       if (!mapit->local)
     828           0 :         return;
     829           0 :       break;
     830           0 :     case ONE_FILTER_API_REMOTE: /* remote only */
     831           0 :       if (mapit->local)
     832           0 :         return;
     833           0 :       break;
     834           0 :     default:
     835           0 :       clib_warning ("Filter error, unknown filter: %d", filter);
     836           0 :       return;
     837             :     }
     838             : 
     839           0 :   gid = &mapit->eid;
     840             : 
     841           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
     842           0 :   clib_memset (rmp, 0, sizeof (*rmp));
     843           0 :   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
     844             : 
     845           0 :   ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
     846           0 :   if (vec_len (ls->locator_indices) == 0)
     847           0 :     rmp->locator_set_index = ~0;
     848             :   else
     849           0 :     rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
     850             : 
     851           0 :   rmp->is_local = mapit->local;
     852           0 :   rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
     853           0 :   rmp->action = mapit->action;
     854           0 :   rmp->authoritative = mapit->authoritative;
     855             : 
     856           0 :   switch (gid_address_type (gid))
     857             :     {
     858           0 :     case GID_ADDR_SRC_DST:
     859           0 :       fid_to_api_eid (&gid_address_sd_src (gid), &rmp->seid);
     860           0 :       fid_to_api_eid (&gid_address_sd_dst (gid), &rmp->deid);
     861           0 :       break;
     862           0 :     case GID_ADDR_IP_PREFIX:
     863           0 :       eid_type = EID_TYPE_API_PREFIX;
     864           0 :       rmp->seid.type = eid_type;
     865           0 :       ip_prefix_to_fib_prefix (&gid_address_ippref (gid), &fib_prefix);
     866           0 :       ip_prefix_encode (&fib_prefix, &rmp->seid.address.prefix);
     867           0 :       break;
     868           0 :     case GID_ADDR_MAC:
     869           0 :       eid_type = EID_TYPE_API_MAC;
     870           0 :       rmp->seid.type = eid_type;
     871           0 :       mac_address_encode ((mac_address_t *) gid_address_mac (gid),
     872           0 :                           rmp->seid.address.mac);
     873           0 :       break;
     874           0 :     case GID_ADDR_NSH:
     875           0 :       eid_type = EID_TYPE_API_NSH;
     876           0 :       rmp->seid.type = eid_type;
     877           0 :       rmp->seid.address.nsh.spi =
     878           0 :         clib_host_to_net_u32 (gid_address_nsh_spi (gid));
     879           0 :       rmp->seid.address.nsh.si = gid_address_nsh_si (gid);
     880           0 :       break;
     881           0 :     default:
     882             :       /* unknown type */
     883           0 :       return;
     884             :     }
     885             : 
     886           0 :   rmp->context = context;
     887           0 :   rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
     888           0 :   rmp->key.id = mapit->key_id;
     889           0 :   memcpy (rmp->key.key, mapit->key, vec_len (mapit->key));
     890           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     891             : }
     892             : 
     893             : static void
     894           0 : vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
     895             : {
     896             :   u32 mi;
     897             :   vl_api_registration_t *reg;
     898           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     899           0 :   mapping_t *mapit = NULL;
     900           0 :   gid_address_t _eid, *eid = &_eid;
     901             : 
     902           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     903           0 :   if (!reg)
     904           0 :     return;
     905             : 
     906           0 :   if (mp->eid_set)
     907             :     {
     908           0 :       clib_memset (eid, 0, sizeof (*eid));
     909             : 
     910           0 :       unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->eid);
     911             : 
     912           0 :       mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
     913           0 :       if ((u32) ~ 0 == mi)
     914           0 :         return;
     915             : 
     916           0 :       mapit = pool_elt_at_index (lcm->mapping_pool, mi);
     917           0 :       send_one_eid_table_details (mapit, reg, mp->context,
     918             :                                   0 /* ignore filter */ );
     919             :     }
     920             :   else
     921             :     {
     922             :       /* *INDENT-OFF* */
     923           0 :       pool_foreach (mapit, lcm->mapping_pool)
     924             :        {
     925           0 :         send_one_eid_table_details(mapit, reg, mp->context,
     926           0 :                                     mp->filter);
     927             :       }
     928             :       /* *INDENT-ON* */
     929             :     }
     930             : }
     931             : 
     932             : static void
     933           0 : send_one_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
     934             :                              u32 context)
     935             : {
     936           0 :   vl_api_one_map_server_details_t *rmp = NULL;
     937             : 
     938           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
     939           0 :   clib_memset (rmp, 0, sizeof (*rmp));
     940           0 :   rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
     941             : 
     942             : 
     943           0 :   ip_address_encode2 (ip, &rmp->ip_address);
     944             : 
     945           0 :   rmp->context = context;
     946             : 
     947           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     948           0 : }
     949             : 
     950             : static void
     951           0 : vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
     952             : {
     953             :   vl_api_registration_t *reg;
     954           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     955             :   lisp_msmr_t *mr;
     956             : 
     957           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     958           0 :   if (!reg)
     959           0 :     return;
     960             : 
     961           0 :   vec_foreach (mr, lcm->map_servers)
     962             :   {
     963           0 :     send_one_map_server_details (&mr->address, reg, mp->context);
     964             :   }
     965             : }
     966             : 
     967             : static void
     968           0 : send_one_map_resolver_details (ip_address_t * ip,
     969             :                                vl_api_registration_t * reg, u32 context)
     970             : {
     971           0 :   vl_api_one_map_resolver_details_t *rmp = NULL;
     972             : 
     973           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
     974           0 :   clib_memset (rmp, 0, sizeof (*rmp));
     975           0 :   rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
     976             : 
     977           0 :   ip_address_encode2 (ip, &rmp->ip_address);
     978           0 :   rmp->context = context;
     979             : 
     980           0 :   vl_api_send_msg (reg, (u8 *) rmp);
     981           0 : }
     982             : 
     983             : static void
     984           0 : vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
     985             : {
     986             :   vl_api_registration_t *reg;
     987           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     988             :   lisp_msmr_t *mr;
     989             : 
     990           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
     991           0 :   if (!reg)
     992           0 :     return;
     993             : 
     994           0 :   vec_foreach (mr, lcm->map_resolvers)
     995             :   {
     996           0 :     send_one_map_resolver_details (&mr->address, reg, mp->context);
     997             :   }
     998             : }
     999             : 
    1000             : static void
    1001           0 : send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg,
    1002             :                          u32 context)
    1003             : {
    1004           0 :   vl_api_one_eid_table_map_details_t *rmp = NULL;
    1005             : 
    1006           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
    1007           0 :   clib_memset (rmp, 0, sizeof (*rmp));
    1008           0 :   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
    1009             : 
    1010           0 :   rmp->vni = clib_host_to_net_u32 (p->key);
    1011           0 :   rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
    1012           0 :   rmp->context = context;
    1013           0 :   vl_api_send_msg (reg, (u8 *) rmp);
    1014           0 : }
    1015             : 
    1016             : static void
    1017           0 : vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
    1018             : {
    1019             :   vl_api_registration_t *reg;
    1020           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1021             :   hash_pair_t *p;
    1022           0 :   uword *vni_table = 0;
    1023             : 
    1024           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
    1025           0 :   if (!reg)
    1026           0 :     return;
    1027             : 
    1028           0 :   if (mp->is_l2)
    1029             :     {
    1030           0 :       vni_table = lcm->bd_id_by_vni;
    1031             :     }
    1032             :   else
    1033             :     {
    1034           0 :       vni_table = lcm->table_id_by_vni;
    1035             :     }
    1036             : 
    1037             :   /* *INDENT-OFF* */
    1038           0 :   hash_foreach_pair (p, vni_table,
    1039             :   ({
    1040             :     send_eid_table_map_pair (p, reg, mp->context);
    1041             :   }));
    1042             :   /* *INDENT-ON* */
    1043             : }
    1044             : 
    1045             : static void
    1046           0 : send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context)
    1047             : {
    1048           0 :   vl_api_one_eid_table_vni_details_t *rmp = 0;
    1049             : 
    1050           0 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
    1051           0 :   clib_memset (rmp, 0, sizeof (*rmp));
    1052           0 :   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
    1053           0 :   rmp->context = context;
    1054           0 :   rmp->vni = clib_host_to_net_u32 (vni);
    1055           0 :   vl_api_send_msg (reg, (u8 *) rmp);
    1056           0 : }
    1057             : 
    1058             : static void
    1059           0 : one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
    1060             : {
    1061             :   lisp_adjacency_t *adj;
    1062             :   vl_api_one_adjacency_t a;
    1063           0 :   u32 i, n = vec_len (adjs);
    1064             :   fib_prefix_t rfib_prefix, lfib_prefix;
    1065             :   u32 eid_type;
    1066             : 
    1067           0 :   for (i = 0; i < n; i++)
    1068             :     {
    1069           0 :       adj = vec_elt_at_index (adjs, i);
    1070           0 :       clib_memset (&a, 0, sizeof (a));
    1071             : 
    1072           0 :       switch (gid_address_type (&adj->reid))
    1073             :         {
    1074           0 :         case GID_ADDR_IP_PREFIX:
    1075           0 :           eid_type = EID_TYPE_API_PREFIX;
    1076           0 :           ip_prefix_to_fib_prefix (&gid_address_ippref (&adj->reid),
    1077             :                                    &rfib_prefix);
    1078           0 :           ip_prefix_to_fib_prefix (&gid_address_ippref (&adj->leid),
    1079             :                                    &lfib_prefix);
    1080           0 :           ip_prefix_encode (&rfib_prefix, &a.reid.address.prefix);
    1081           0 :           ip_prefix_encode (&lfib_prefix, &a.leid.address.prefix);
    1082           0 :           break;
    1083           0 :         case GID_ADDR_MAC:
    1084           0 :           eid_type = EID_TYPE_API_PREFIX;
    1085           0 :           mac_address_encode ((mac_address_t *) gid_address_mac (&adj->reid),
    1086             :                               a.reid.address.mac);
    1087           0 :           mac_address_encode ((mac_address_t *) gid_address_mac (&adj->leid),
    1088             :                               a.leid.address.mac);
    1089           0 :           break;
    1090           0 :         case GID_ADDR_NSH:
    1091           0 :           eid_type = EID_TYPE_API_PREFIX;
    1092           0 :           a.reid.address.nsh.spi =
    1093           0 :             clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid));
    1094           0 :           a.reid.address.nsh.si = gid_address_nsh_si (&adj->reid);
    1095           0 :           a.leid.address.nsh.spi =
    1096           0 :             clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid));
    1097           0 :           a.leid.address.nsh.si = gid_address_nsh_si (&adj->leid);
    1098           0 :           break;
    1099           0 :         default:
    1100           0 :           ALWAYS_ASSERT (0);
    1101             :         }
    1102           0 :       a.reid.type = eid_type;
    1103           0 :       a.leid.type = eid_type;
    1104           0 :       dst[i] = a;
    1105             :     }
    1106           0 : }
    1107             : 
    1108             : static void
    1109           0 :   vl_api_show_one_rloc_probe_state_t_handler
    1110             :   (vl_api_show_one_rloc_probe_state_t * mp)
    1111             : {
    1112           0 :   vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
    1113           0 :   int rv = 0;
    1114             : 
    1115             :   /* *INDENT-OFF* */
    1116           0 :   REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
    1117             :   {
    1118             :     rmp->is_enable = vnet_lisp_rloc_probe_state_get ();
    1119             :   });
    1120             :   /* *INDENT-ON* */
    1121             : }
    1122             : 
    1123             : static void
    1124           0 :   vl_api_show_one_map_register_state_t_handler
    1125             :   (vl_api_show_one_map_register_state_t * mp)
    1126             : {
    1127           0 :   vl_api_show_one_map_register_state_reply_t *rmp = 0;
    1128           0 :   int rv = 0;
    1129             : 
    1130             :   /* *INDENT-OFF* */
    1131           0 :   REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
    1132             :   {
    1133             :     rmp->is_enable = vnet_lisp_map_register_state_get ();
    1134             :   });
    1135             :   /* *INDENT-ON* */
    1136             : }
    1137             : 
    1138             : static void
    1139           0 : vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
    1140             : {
    1141           0 :   vl_api_one_adjacencies_get_reply_t *rmp = 0;
    1142           0 :   lisp_adjacency_t *adjs = 0;
    1143           0 :   int rv = 0;
    1144           0 :   u32 size = ~0;
    1145           0 :   u32 vni = clib_net_to_host_u32 (mp->vni);
    1146             : 
    1147           0 :   adjs = vnet_lisp_adjacencies_get_by_vni (vni);
    1148           0 :   size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
    1149             : 
    1150             :   /* *INDENT-OFF* */
    1151           0 :   REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
    1152             :   {
    1153             :     rmp->count = clib_host_to_net_u32 (vec_len (adjs));
    1154             :     one_adjacency_copy (rmp->adjacencies, adjs);
    1155             :   });
    1156             :   /* *INDENT-ON* */
    1157             : 
    1158           0 :   vec_free (adjs);
    1159             : }
    1160             : 
    1161             : static void
    1162           0 : vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
    1163             : {
    1164             :   hash_pair_t *p;
    1165           0 :   u32 *vnis = 0;
    1166             :   vl_api_registration_t *reg;
    1167           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1168             : 
    1169           0 :   reg = vl_api_client_index_to_registration (mp->client_index);
    1170           0 :   if (!reg)
    1171           0 :     return;
    1172             : 
    1173             :   /* *INDENT-OFF* */
    1174           0 :   hash_foreach_pair (p, lcm->table_id_by_vni,
    1175             :   ({
    1176             :     hash_set (vnis, p->key, 0);
    1177             :   }));
    1178             : 
    1179           0 :   hash_foreach_pair (p, lcm->bd_id_by_vni,
    1180             :   ({
    1181             :     hash_set (vnis, p->key, 0);
    1182             :   }));
    1183             : 
    1184           0 :   hash_foreach_pair (p, vnis,
    1185             :   ({
    1186             :     send_eid_table_vni (p->key, reg, mp->context);
    1187             :   }));
    1188             :   /* *INDENT-ON* */
    1189             : 
    1190           0 :   hash_free (vnis);
    1191             : }
    1192             : 
    1193             : static void
    1194           0 : vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
    1195             : {
    1196           0 :   vl_api_show_one_status_reply_t *rmp = NULL;
    1197           0 :   int rv = 0;
    1198             : 
    1199             :   /* *INDENT-OFF* */
    1200           0 :   REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
    1201             :   ({
    1202             :     rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
    1203             :     rmp->feature_status = vnet_lisp_enable_disable_status ();
    1204             :   }));
    1205             :   /* *INDENT-ON* */
    1206             : }
    1207             : 
    1208             : static void
    1209           0 :   vl_api_one_get_map_request_itr_rlocs_t_handler
    1210             :   (vl_api_one_get_map_request_itr_rlocs_t * mp)
    1211             : {
    1212           0 :   vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
    1213           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1214           0 :   locator_set_t *loc_set = 0;
    1215           0 :   u8 *tmp_str = 0;
    1216           0 :   int rv = 0;
    1217             : 
    1218           0 :   if (~0 == lcm->mreq_itr_rlocs)
    1219             :     {
    1220           0 :       tmp_str = format (0, " ");
    1221             :     }
    1222             :   else
    1223             :     {
    1224           0 :       loc_set =
    1225           0 :         pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
    1226           0 :       tmp_str = format (0, "%s", loc_set->name);
    1227             :     }
    1228             : 
    1229             :   /* *INDENT-OFF* */
    1230           0 :   REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
    1231             :   ({
    1232             :     strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
    1233             :             ARRAY_LEN(rmp->locator_set_name) - 1);
    1234             :   }));
    1235             :   /* *INDENT-ON* */
    1236             : 
    1237           0 :   vec_free (tmp_str);
    1238             : }
    1239             : 
    1240             : static void
    1241           0 : vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp)
    1242             : {
    1243           0 :   vl_api_show_one_nsh_mapping_reply_t *rmp = NULL;
    1244           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1245             :   mapping_t *m;
    1246           0 :   locator_set_t *ls = 0;
    1247           0 :   u8 *tmp_str = 0;
    1248           0 :   u8 is_set = 0;
    1249           0 :   int rv = 0;
    1250             : 
    1251           0 :   if (lcm->nsh_map_index == (u32) ~ 0)
    1252             :     {
    1253           0 :       tmp_str = format (0, "N/A");
    1254             :     }
    1255             :   else
    1256             :     {
    1257           0 :       m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
    1258           0 :       if (~0 != m->locator_set_index)
    1259             :         {
    1260           0 :           ls =
    1261           0 :             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
    1262           0 :           tmp_str = format (0, "%s", ls->name);
    1263           0 :           is_set = 1;
    1264             :         }
    1265             :       else
    1266             :         {
    1267           0 :           tmp_str = format (0, "N/A");
    1268             :         }
    1269             :     }
    1270           0 :   vec_add1 (tmp_str, 0);
    1271             : 
    1272             :   /* *INDENT-OFF* */
    1273           0 :   REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY,
    1274             :   ({
    1275             :     rmp->is_set = is_set;
    1276             :     strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
    1277             :             ARRAY_LEN(rmp->locator_set_name) - 1);
    1278             :   }));
    1279             :   /* *INDENT-ON* */
    1280             : }
    1281             : 
    1282             : static void
    1283           0 : vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
    1284             : {
    1285           0 :   vl_api_show_one_pitr_reply_t *rmp = NULL;
    1286           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1287             :   mapping_t *m;
    1288           0 :   locator_set_t *ls = 0;
    1289           0 :   u8 *tmp_str = 0;
    1290           0 :   int rv = 0;
    1291             : 
    1292           0 :   u8 is_enable = (lcm->flags & LISP_FLAG_PITR_MODE)
    1293           0 :     && lcm->pitr_map_index != ~0;
    1294             : 
    1295           0 :   if (!is_enable)
    1296             :     {
    1297           0 :       tmp_str = format (0, "N/A");
    1298             :     }
    1299             :   else
    1300             :     {
    1301           0 :       m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
    1302           0 :       if (~0 != m->locator_set_index)
    1303             :         {
    1304           0 :           ls =
    1305           0 :             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
    1306           0 :           tmp_str = format (0, "%s", ls->name);
    1307             :         }
    1308             :       else
    1309             :         {
    1310           0 :           tmp_str = format (0, "N/A");
    1311             :         }
    1312             :     }
    1313           0 :   vec_add1 (tmp_str, 0);
    1314             : 
    1315             :   /* *INDENT-OFF* */
    1316           0 :   REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
    1317             :   ({
    1318             :     rmp->status = lcm->flags & LISP_FLAG_PITR_MODE;
    1319             :     strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
    1320             :             ARRAY_LEN(rmp->locator_set_name) - 1);
    1321             :   }));
    1322             :   /* *INDENT-ON* */
    1323             : }
    1324             : 
    1325             : static void
    1326           0 :   vl_api_show_one_stats_enable_disable_t_handler
    1327             :   (vl_api_show_one_stats_enable_disable_t * mp)
    1328             : {
    1329           0 :   vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
    1330           0 :   vnet_api_error_t rv = 0;
    1331             : 
    1332             :   /* *INDENT-OFF* */
    1333           0 :   REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
    1334             :   ({
    1335             :     rmp->is_enable = vnet_lisp_stats_enable_disable_state ();
    1336             :   }));
    1337             :   /* *INDENT-ON* */
    1338             : }
    1339             : 
    1340             : static void
    1341           0 :   vl_api_one_stats_enable_disable_t_handler
    1342             :   (vl_api_one_stats_enable_disable_t * mp)
    1343             : {
    1344           0 :   vl_api_one_enable_disable_reply_t *rmp = NULL;
    1345             : 
    1346           0 :   vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_enable);
    1347           0 :   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
    1348             : }
    1349             : 
    1350             : static void
    1351           0 : vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
    1352             : {
    1353             :   vl_api_one_stats_flush_reply_t *rmp;
    1354             :   u8 rv;
    1355             : 
    1356           0 :   rv = vnet_lisp_flush_stats ();
    1357           0 :   REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
    1358             : }
    1359             : 
    1360             : static void
    1361           0 : vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
    1362             : {
    1363             :   vl_api_one_stats_details_t *rmp;
    1364             :   lisp_api_stats_t *stats, *stat;
    1365             : 
    1366           0 :   stats = vnet_lisp_get_stats ();
    1367           0 :   vec_foreach (stat, stats)
    1368             :   {
    1369             :       /* *INDENT-OFF* */
    1370           0 :       REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
    1371             :       ({
    1372             :         fid_to_api_eid (&stat->deid, &rmp->deid);
    1373             :         fid_to_api_eid (&stat->seid, &rmp->seid);
    1374             :         rmp->vni = clib_host_to_net_u32 (stat->vni);
    1375             : 
    1376             :         ip_address_encode2 (&stat->rmt_rloc, &rmp->rloc);
    1377             :         ip_address_encode2 (&stat->loc_rloc, &rmp->lloc);
    1378             : 
    1379             :         rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
    1380             :         rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
    1381             :       }));
    1382             :       /* *INDENT-ON* */
    1383             :   }
    1384             : }
    1385             : 
    1386             : static void
    1387           0 :   vl_api_one_add_del_l2_arp_entry_t_handler
    1388             :   (vl_api_one_add_del_l2_arp_entry_t * mp)
    1389             : {
    1390             :   vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
    1391           0 :   int rv = 0;
    1392           0 :   gid_address_t _arp, *arp = &_arp;
    1393             :   ip4_address_t ip4;
    1394             :   mac_address_t mac;
    1395           0 :   clib_memset (arp, 0, sizeof (*arp));
    1396             : 
    1397           0 :   gid_address_type (arp) = GID_ADDR_ARP;
    1398           0 :   gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
    1399             : 
    1400           0 :   ip4_address_decode (mp->entry.ip4, &ip4);
    1401           0 :   ip_address_set (&gid_address_arp_ndp_ip (arp), &ip4, AF_IP4);
    1402           0 :   mac_address_decode (mp->entry.mac, &mac);
    1403             : 
    1404           0 :   rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mac.bytes, mp->is_add);
    1405             : 
    1406           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
    1407             : }
    1408             : 
    1409             : static void
    1410           0 : vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp)
    1411             : {
    1412             :   vl_api_one_add_del_ndp_entry_reply_t *rmp;
    1413           0 :   int rv = 0;
    1414           0 :   gid_address_t _g, *g = &_g;
    1415             :   ip6_address_t ip6;
    1416             :   mac_address_t mac;
    1417           0 :   clib_memset (g, 0, sizeof (*g));
    1418             : 
    1419           0 :   gid_address_type (g) = GID_ADDR_NDP;
    1420           0 :   gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd);
    1421             : 
    1422           0 :   ip6_address_decode (mp->entry.ip6, &ip6);
    1423           0 :   ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, AF_IP6);
    1424           0 :   mac_address_decode (mp->entry.mac, &mac);
    1425             : 
    1426           0 :   rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mac.bytes, mp->is_add);
    1427             : 
    1428           0 :   REPLY_MACRO (VL_API_ONE_ADD_DEL_NDP_ENTRY_REPLY);
    1429             : }
    1430             : 
    1431             : static void
    1432           0 : vl_api_one_ndp_bd_get_t_handler (vl_api_one_ndp_bd_get_t * mp)
    1433             : {
    1434             :   vl_api_one_ndp_bd_get_reply_t *rmp;
    1435           0 :   int rv = 0;
    1436           0 :   u32 i = 0;
    1437             :   hash_pair_t *p;
    1438             : 
    1439           0 :   u32 *bds = vnet_lisp_ndp_bds_get ();
    1440           0 :   u32 size = hash_elts (bds) * sizeof (u32);
    1441             : 
    1442             :   /* *INDENT-OFF* */
    1443           0 :   REPLY_MACRO4 (VL_API_ONE_NDP_BD_GET_REPLY, size,
    1444             :   {
    1445             :     rmp->count = clib_host_to_net_u32 (hash_elts (bds));
    1446             :     hash_foreach_pair (p, bds,
    1447             :     ({
    1448             :       rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
    1449             :     }));
    1450             :   });
    1451             :   /* *INDENT-ON* */
    1452             : 
    1453           0 :   hash_free (bds);
    1454             : }
    1455             : 
    1456             : static void
    1457           0 : vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
    1458             : {
    1459             :   vl_api_one_l2_arp_bd_get_reply_t *rmp;
    1460           0 :   int rv = 0;
    1461           0 :   u32 i = 0;
    1462             :   hash_pair_t *p;
    1463             : 
    1464           0 :   u32 *bds = vnet_lisp_l2_arp_bds_get ();
    1465           0 :   u32 size = hash_elts (bds) * sizeof (u32);
    1466             : 
    1467             :   /* *INDENT-OFF* */
    1468           0 :   REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
    1469             :   {
    1470             :     rmp->count = clib_host_to_net_u32 (hash_elts (bds));
    1471             :     hash_foreach_pair (p, bds,
    1472             :     ({
    1473             :       rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
    1474             :     }));
    1475             :   });
    1476             :   /* *INDENT-ON* */
    1477             : 
    1478           0 :   hash_free (bds);
    1479             : }
    1480             : 
    1481             : static void
    1482           0 : vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
    1483             : {
    1484             :   vl_api_one_l2_arp_entries_get_reply_t *rmp;
    1485           0 :   lisp_api_l2_arp_entry_t *entries = 0, *e;
    1486           0 :   u32 i = 0;
    1487           0 :   int rv = 0;
    1488             : 
    1489           0 :   u32 bd = clib_net_to_host_u32 (mp->bd);
    1490             : 
    1491           0 :   entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
    1492           0 :   u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t);
    1493             : 
    1494             :   /* *INDENT-OFF* */
    1495           0 :   REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
    1496             :   {
    1497             :     rmp->count = clib_host_to_net_u32 (vec_len (entries));
    1498             :     vec_foreach (e, entries)
    1499             :       {
    1500             :         mac_address_encode ((mac_address_t *) e->mac, rmp->entries[i].mac);
    1501             :         ip4_address_encode ((ip4_address_t *) &e->ip4, rmp->entries[i].ip4);
    1502             :         i++;
    1503             :       }
    1504             :   });
    1505             :   /* *INDENT-ON* */
    1506             : 
    1507           0 :   vec_free (entries);
    1508             : }
    1509             : 
    1510             : static void
    1511           0 :   vl_api_one_map_register_fallback_threshold_t_handler
    1512             :   (vl_api_one_map_register_fallback_threshold_t * mp)
    1513             : {
    1514             :   vl_api_one_map_register_fallback_threshold_reply_t *rmp;
    1515           0 :   int rv = 0;
    1516             : 
    1517           0 :   mp->value = clib_net_to_host_u32 (mp->value);
    1518           0 :   rv = vnet_lisp_map_register_fallback_threshold_set (mp->value);
    1519           0 :   REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY);
    1520             : }
    1521             : 
    1522             : static void
    1523           0 :   vl_api_show_one_map_register_fallback_threshold_t_handler
    1524             :   (vl_api_show_one_map_register_fallback_threshold_t * mp)
    1525             : {
    1526             :   vl_api_show_one_map_register_fallback_threshold_reply_t *rmp;
    1527           0 :   int rv = 0;
    1528             : 
    1529           0 :   u32 value = vnet_lisp_map_register_fallback_threshold_get ();
    1530             : 
    1531             :   /* *INDENT-OFF* */
    1532           0 :   REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,
    1533             :   ({
    1534             :     rmp->value = clib_host_to_net_u32 (value);
    1535             :   }));
    1536             :   /* *INDENT-ON* */
    1537             : }
    1538             : 
    1539             : static void
    1540           0 :   vl_api_one_set_transport_protocol_t_handler
    1541             :   (vl_api_one_set_transport_protocol_t * mp)
    1542             : {
    1543             :   vl_api_one_set_transport_protocol_reply_t *rmp;
    1544           0 :   int rv = 0;
    1545             : 
    1546           0 :   rv = vnet_lisp_set_transport_protocol (mp->protocol);
    1547             : 
    1548           0 :   REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY);
    1549             : }
    1550             : 
    1551             : static void
    1552           0 :   vl_api_one_get_transport_protocol_t_handler
    1553             :   (vl_api_one_get_transport_protocol_t * mp)
    1554             : {
    1555             :   vl_api_one_get_transport_protocol_reply_t *rmp;
    1556           0 :   int rv = 0;
    1557           0 :   u8 proto = (u8) vnet_lisp_get_transport_protocol ();
    1558             : 
    1559             :   /* *INDENT-OFF* */
    1560           0 :   REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY,
    1561             :   ({
    1562             :     rmp->protocol = proto;
    1563             :   }));
    1564             :   /* *INDENT-ON* */
    1565             : }
    1566             : 
    1567             : static void
    1568           0 : vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp)
    1569             : {
    1570           0 :   vl_api_one_ndp_entries_get_reply_t *rmp = 0;
    1571           0 :   lisp_api_ndp_entry_t *entries = 0, *e;
    1572           0 :   u32 i = 0;
    1573           0 :   int rv = 0;
    1574             : 
    1575           0 :   u32 bd = clib_net_to_host_u32 (mp->bd);
    1576             : 
    1577           0 :   entries = vnet_lisp_ndp_entries_get_by_bd (bd);
    1578           0 :   u32 size = vec_len (entries) * sizeof (vl_api_one_ndp_entry_t);
    1579             : 
    1580             :   /* *INDENT-OFF* */
    1581           0 :   REPLY_MACRO4 (VL_API_ONE_NDP_ENTRIES_GET_REPLY, size,
    1582             :   {
    1583             :     rmp->count = clib_host_to_net_u32 (vec_len (entries));
    1584             :     vec_foreach (e, entries)
    1585             :       {
    1586             :         mac_address_encode ((mac_address_t *) e->mac, rmp->entries[i].mac);
    1587             :         ip6_address_encode ((ip6_address_t *) &e->ip6, rmp->entries[i].ip6);
    1588             :         i++;
    1589             :       }
    1590             :   });
    1591             :   /* *INDENT-ON* */
    1592             : 
    1593           0 :   vec_free (entries);
    1594             : }
    1595             : 
    1596             : static void
    1597           0 :   vl_api_one_enable_disable_xtr_mode_t_handler
    1598             :   (vl_api_one_enable_disable_xtr_mode_t * mp)
    1599             : {
    1600           0 :   vl_api_one_enable_disable_xtr_mode_reply_t *rmp = 0;
    1601           0 :   int rv = vnet_lisp_enable_disable_xtr_mode (mp->is_enable);
    1602             : 
    1603           0 :   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_XTR_MODE_REPLY);
    1604             : }
    1605             : 
    1606             : static void
    1607           0 : vl_api_one_show_xtr_mode_t_handler (vl_api_one_show_xtr_mode_t * mp)
    1608             : {
    1609           0 :   vl_api_one_show_xtr_mode_reply_t *rmp = 0;
    1610           0 :   int rv = 0;
    1611             : 
    1612             :   /* *INDENT-OFF* */
    1613           0 :   REPLY_MACRO2 (VL_API_ONE_SHOW_XTR_MODE_REPLY,
    1614             :   {
    1615             :     rmp->is_enable = vnet_lisp_get_xtr_mode ();
    1616             :   });
    1617             :   /* *INDENT-ON* */
    1618             : }
    1619             : 
    1620             : static void
    1621           0 :   vl_api_one_enable_disable_pitr_mode_t_handler
    1622             :   (vl_api_one_enable_disable_pitr_mode_t * mp)
    1623             : {
    1624           0 :   vl_api_one_enable_disable_pitr_mode_reply_t *rmp = 0;
    1625           0 :   int rv = vnet_lisp_enable_disable_pitr_mode (mp->is_enable);
    1626             : 
    1627           0 :   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PITR_MODE_REPLY);
    1628             : }
    1629             : 
    1630             : static void
    1631           0 : vl_api_one_show_pitr_mode_t_handler (vl_api_one_show_pitr_mode_t * mp)
    1632             : {
    1633           0 :   vl_api_one_show_pitr_mode_reply_t *rmp = 0;
    1634           0 :   int rv = 0;
    1635             : 
    1636             :   /* *INDENT-OFF* */
    1637           0 :   REPLY_MACRO2 (VL_API_ONE_SHOW_PITR_MODE_REPLY,
    1638             :   {
    1639             :     rmp->is_enable = vnet_lisp_get_pitr_mode ();
    1640             :   });
    1641             :   /* *INDENT-ON* */
    1642             : }
    1643             : 
    1644             : static void
    1645           0 :   vl_api_one_enable_disable_petr_mode_t_handler
    1646             :   (vl_api_one_enable_disable_petr_mode_t * mp)
    1647             : {
    1648           0 :   vl_api_one_enable_disable_petr_mode_reply_t *rmp = 0;
    1649           0 :   int rv = vnet_lisp_enable_disable_petr_mode (mp->is_enable);
    1650             : 
    1651           0 :   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PETR_MODE_REPLY);
    1652             : }
    1653             : 
    1654             : static void
    1655           0 : vl_api_one_show_petr_mode_t_handler (vl_api_one_show_petr_mode_t * mp)
    1656             : {
    1657           0 :   vl_api_one_show_petr_mode_reply_t *rmp = 0;
    1658           0 :   int rv = 0;
    1659             : 
    1660             :   /* *INDENT-OFF* */
    1661           0 :   REPLY_MACRO2 (VL_API_ONE_SHOW_PETR_MODE_REPLY,
    1662             :   {
    1663             :     rmp->is_enable = vnet_lisp_get_petr_mode ();
    1664             :   });
    1665             :   /* *INDENT-ON* */
    1666             : }
    1667             : 
    1668             : /*
    1669             :  * one_api_hookup
    1670             :  * Add vpe's API message handlers to the table.
    1671             :  * vlib has already mapped shared memory and
    1672             :  * added the client registration handlers.
    1673             :  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
    1674             :  */
    1675             : #include <lisp/lisp-cp/one.api.c>
    1676             : 
    1677             : static clib_error_t *
    1678         575 : one_api_hookup (vlib_main_t * vm)
    1679             : {
    1680         575 :   one_base_msg_id = setup_message_id_table ();
    1681             : 
    1682         575 :   return 0;
    1683             : }
    1684             : 
    1685        1151 : VLIB_API_INIT_FUNCTION (one_api_hookup);
    1686             : 
    1687             : #include <vlib/unix/plugin.h>
    1688             : #include <vpp/app/version.h>
    1689             : 
    1690             : /* *INDENT-OFF* */
    1691             : VLIB_PLUGIN_REGISTER () = {
    1692             :     .version = VPP_BUILD_VER,
    1693             :     .description = "Locator ID Separation Protocol (LISP)",
    1694             : };
    1695             : /* *INDENT-ON* */
    1696             : 
    1697             : /*
    1698             :  * fd.io coding-style-patch-verification: ON
    1699             :  *
    1700             :  * Local Variables:
    1701             :  * eval: (c-set-style "gnu")
    1702             :  * End:
    1703             :  */

Generated by: LCOV version 1.14