ipsec: IPSec protection for multi-point tunnel interfaces
[vpp.git] / src / vnet / lisp-cp / one_api.c
index 85c5d7e..d1117ee 100644 (file)
 
 #include <vnet/vnet_msg_enum.h>
 
-#define vl_api_one_remote_locator_t_endian vl_noop_handler
-#define vl_api_one_remote_locator_t_print vl_noop_handler
-#define vl_api_one_local_locator_t_endian vl_noop_handler
-#define vl_api_one_local_locator_t_print vl_noop_handler
-
 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
 
-#define vl_api_one_l2_arp_entry_t_endian vl_noop_handler
-#define vl_api_one_l2_arp_entry_t_print vl_noop_handler
 #define vl_api_one_add_del_l2_arp_entry vl_noop_handler
 #define vl_api_one_l2_arp_bd_get vl_noop_handler
 
-#define vl_api_one_ndp_entry_t_endian vl_noop_handler
-#define vl_api_one_ndp_entry_t_print vl_noop_handler
 #define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
 #define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
 
@@ -154,8 +145,9 @@ unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
     {
       /* remote locators */
       r = &rmt_locs[i];
-      memset (&loc, 0, sizeof (loc));
-      gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
+      clib_memset (&loc, 0, sizeof (loc));
+      gid_address_ip_set (&loc.address, &r->addr,
+                         r->is_ip4 ? AF_IP4 : AF_IP6);
 
       loc.priority = r->priority;
       loc.weight = r->weight;
@@ -207,7 +199,7 @@ vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
   u8 *locator_name = NULL;
   int i;
 
-  memset (a, 0, sizeof (a[0]));
+  clib_memset (a, 0, sizeof (a[0]));
 
   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
   locator_name = format (0, "%s", mp->locator_set_name);
@@ -218,7 +210,7 @@ vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
   a->local = 1;
   locator_num = clib_net_to_host_u32 (mp->locator_num);
 
-  memset (&locator, 0, sizeof (locator));
+  clib_memset (&locator, 0, sizeof (locator));
   for (i = 0; i < locator_num; i++)
     {
       ls_loc = &mp->locators[i];
@@ -256,8 +248,8 @@ vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
   u32 ls_index = ~0;
   u8 *locator_name = NULL;
 
-  memset (&locator, 0, sizeof (locator));
-  memset (a, 0, sizeof (a[0]));
+  clib_memset (&locator, 0, sizeof (locator));
+  clib_memset (a, 0, sizeof (a[0]));
 
   locator.sw_if_index = ntohl (mp->sw_if_index);
   locator.priority = mp->priority;
@@ -298,13 +290,13 @@ unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
     {
     case 0:                    /* ipv4 */
       gid_address_type (dst) = GID_ADDR_IP_PREFIX;
-      gid_address_ip_set (dst, src, IP4);
+      gid_address_ip_set (dst, src, AF_IP4);
       gid_address_ippref_len (dst) = len;
       ip_prefix_normalize (&gid_address_ippref (dst));
       break;
     case 1:                    /* ipv6 */
       gid_address_type (dst) = GID_ADDR_IP_PREFIX;
-      gid_address_ip_set (dst, src, IP6);
+      gid_address_ip_set (dst, src, AF_IP6);
       gid_address_ippref_len (dst) = len;
       ip_prefix_normalize (&gid_address_ippref (dst));
       break;
@@ -339,8 +331,8 @@ vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
   u32 locator_set_index = ~0, map_index = ~0;
   vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
   u8 *name = NULL, *key = NULL;
-  memset (a, 0, sizeof (a[0]));
-  memset (eid, 0, sizeof (eid[0]));
+  clib_memset (a, 0, sizeof (a[0]));
+  clib_memset (eid, 0, sizeof (eid[0]));
 
   rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
                             mp->eid_type, mp->eid, mp->prefix_len);
@@ -403,9 +395,9 @@ vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
   int rv = 0;
   ip_address_t addr;
 
-  memset (&addr, 0, sizeof (addr));
+  clib_memset (&addr, 0, sizeof (addr));
 
-  ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
+  ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? AF_IP6 : AF_IP4);
   rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
 
   REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
@@ -419,10 +411,10 @@ vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
   int rv = 0;
   vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
 
-  memset (a, 0, sizeof (a[0]));
+  clib_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);
+  ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? AF_IP6 : AF_IP4);
 
   rv = vnet_lisp_add_del_map_resolver (a);
 
@@ -528,7 +520,7 @@ vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
   int rv = 0;
   ip_address_t addr;
 
-  ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
+  ip_address_set (&addr, &mp->address, mp->is_ip4 ? AF_IP4 : AF_IP6);
   rv = vnet_lisp_use_petr (&addr, mp->is_add);
 
   REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
@@ -546,7 +538,7 @@ vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
   u8 status = 0;
   gid_address_t addr;
 
-  memset (&addr, 0, sizeof (addr));
+  clib_memset (&addr, 0, sizeof (addr));
   status = lcm->flags & LISP_FLAG_USE_PETR;
   if (status)
     {
@@ -567,12 +559,12 @@ vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
     ip_address_t *ip = &gid_address_ip (&addr);
     switch (ip_addr_version (ip))
       {
-      case IP4:
+      case AF_IP4:
         clib_memcpy (rmp->address, &ip_addr_v4 (ip),
                      sizeof (ip_addr_v4 (ip)));
         break;
 
-      case IP6:
+      case AF_IP6:
         clib_memcpy (rmp->address, &ip_addr_v6 (ip),
                      sizeof (ip_addr_v6 (ip)));
         break;
@@ -580,7 +572,7 @@ vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
       default:
         ASSERT (0);
       }
-    rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
+    rmp->is_ip4 = (gid_address_ip_version (&addr) == AF_IP4);
   });
   /* *INDENT-ON* */
 }
@@ -618,7 +610,7 @@ static void
   gid_address_t _eid, *eid = &_eid;
   u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
 
-  memset (eid, 0, sizeof (eid[0]));
+  clib_memset (eid, 0, sizeof (eid[0]));
 
   rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
                             mp->eid_type, mp->eid, mp->eid_len);
@@ -630,7 +622,7 @@ static void
   if (!mp->is_add)
     {
       vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
-      memset (a, 0, sizeof (a[0]));
+      clib_memset (a, 0, sizeof (a[0]));
       gid_address_copy (&a->reid, eid);
       a->is_add = 0;
       rv = vnet_lisp_add_del_adjacency (a);
@@ -645,7 +637,7 @@ static void
   if (mp->is_add)
     {
       vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
-      memset (m_args, 0, sizeof (m_args[0]));
+      clib_memset (m_args, 0, sizeof (m_args[0]));
       gid_address_copy (&m_args->eid, eid);
       m_args->action = mp->action;
       m_args->is_static = 1;
@@ -672,7 +664,7 @@ vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
   vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
 
   int rv = 0;
-  memset (a, 0, sizeof (a[0]));
+  clib_memset (a, 0, sizeof (a[0]));
 
   rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
                             mp->eid_type, mp->leid, mp->leid_len);
@@ -697,7 +689,7 @@ send_one_locator_details (lisp_cp_main_t * lcm,
   vl_api_one_locator_details_t *rmp;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
   rmp->context = context;
 
@@ -770,7 +762,7 @@ send_one_locator_set_details (lisp_cp_main_t * lcm,
   u8 *str = 0;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
   rmp->context = context;
 
@@ -827,7 +819,7 @@ one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
   switch (fid_addr_type (src))
     {
     case FID_ADDR_IP_PREF:
-      if (ip_prefix_version (ippref) == IP4)
+      if (ip_prefix_version (ippref) == AF_IP4)
        clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
       else
        clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
@@ -854,9 +846,9 @@ fid_type_to_api_type (fid_address_t * fid)
     {
     case FID_ADDR_IP_PREF:
       ippref = &fid_addr_ippref (fid);
-      if (ip_prefix_version (ippref) == IP4)
+      if (ip_prefix_version (ippref) == AF_IP4)
        return 0;
-      else if (ip_prefix_version (ippref) == IP6)
+      else if (ip_prefix_version (ippref) == AF_IP6)
        return 1;
       else
        return ~0;
@@ -909,7 +901,7 @@ send_one_eid_table_details (mapping_t * mapit,
   mac = gid_address_mac (gid);
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
 
   ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
@@ -936,7 +928,7 @@ send_one_eid_table_details (mapping_t * mapit,
       break;
     case GID_ADDR_IP_PREFIX:
       rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
-      if (ip_prefix_version (ip_prefix) == IP4)
+      if (ip_prefix_version (ip_prefix) == AF_IP4)
        {
          rmp->eid_type = 0;    /* ipv4 type */
          clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
@@ -985,7 +977,7 @@ vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
 
   if (mp->eid_set)
     {
-      memset (eid, 0, sizeof (*eid));
+      clib_memset (eid, 0, sizeof (*eid));
 
       unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
                            mp->eid_type, mp->eid, mp->prefix_length);
@@ -1017,18 +1009,18 @@ send_one_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
   vl_api_one_map_server_details_t *rmp = NULL;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
 
   switch (ip_addr_version (ip))
     {
-    case IP4:
+    case AF_IP4:
       rmp->is_ipv6 = 0;
       clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
                   sizeof (ip_addr_v4 (ip)));
       break;
 
-    case IP6:
+    case AF_IP6:
       rmp->is_ipv6 = 1;
       clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
                   sizeof (ip_addr_v6 (ip)));
@@ -1066,18 +1058,18 @@ send_one_map_resolver_details (ip_address_t * ip,
   vl_api_one_map_resolver_details_t *rmp = NULL;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
 
   switch (ip_addr_version (ip))
     {
-    case IP4:
+    case AF_IP4:
       rmp->is_ipv6 = 0;
       clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
                   sizeof (ip_addr_v4 (ip)));
       break;
 
-    case IP6:
+    case AF_IP6:
       rmp->is_ipv6 = 1;
       clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
                   sizeof (ip_addr_v6 (ip)));
@@ -1115,7 +1107,7 @@ send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg,
   vl_api_one_eid_table_map_details_t *rmp = NULL;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
 
   rmp->vni = clib_host_to_net_u32 (p->key);
@@ -1159,7 +1151,7 @@ send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context)
   vl_api_one_eid_table_vni_details_t *rmp = 0;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
   rmp->context = context;
   rmp->vni = clib_host_to_net_u32 (vni);
@@ -1177,14 +1169,14 @@ one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
   for (i = 0; i < n; i++)
     {
       adj = vec_elt_at_index (adjs, i);
-      memset (&a, 0, sizeof (a));
+      clib_memset (&a, 0, sizeof (a));
 
       switch (gid_address_type (&adj->reid))
        {
        case GID_ADDR_IP_PREFIX:
          a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
          a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
-         if (gid_address_ip_version (&adj->reid) == IP4)
+         if (gid_address_ip_version (&adj->reid) == AF_IP4)
            {
              a.eid_type = 0;   /* ipv4 type */
              clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
@@ -1469,7 +1461,7 @@ lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
     {
     case FID_ADDR_IP_PREF:
       *prefix_length = fid_addr_prefix_length (fid);
-      if (fid_addr_ip_version (fid) == IP4)
+      if (fid_addr_ip_version (fid) == AF_IP4)
        {
          *api_eid_type = 0;    /* ipv4 type */
          clib_memcpy (dst, &fid_addr_ippref (fid), 4);
@@ -1518,7 +1510,7 @@ vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
                               &rmp->seid_pref_len);
         rmp->vni = clib_host_to_net_u32 (stat->vni);
 
-        rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
+        rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == AF_IP4 ? 1 : 0;
         ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
         ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
 
@@ -1536,13 +1528,13 @@ static void
   vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
   int rv = 0;
   gid_address_t _arp, *arp = &_arp;
-  memset (arp, 0, sizeof (*arp));
+  clib_memset (arp, 0, sizeof (*arp));
 
   gid_address_type (arp) = GID_ADDR_ARP;
   gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
 
   /* vpp keeps ip4 addresses in network byte order */
-  ip_address_set (&gid_address_arp_ndp_ip (arp), &mp->ip4, IP4);
+  ip_address_set (&gid_address_arp_ndp_ip (arp), &mp->ip4, AF_IP4);
 
   rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mp->mac, mp->is_add);
 
@@ -1555,11 +1547,11 @@ vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp)
   vl_api_one_add_del_ndp_entry_reply_t *rmp;
   int rv = 0;
   gid_address_t _g, *g = &_g;
-  memset (g, 0, sizeof (*g));
+  clib_memset (g, 0, sizeof (*g));
 
   gid_address_type (g) = GID_ADDR_NDP;
   gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd);
-  ip_address_set (&gid_address_arp_ndp_ip (g), mp->ip6, IP6);
+  ip_address_set (&gid_address_arp_ndp_ip (g), mp->ip6, AF_IP6);
 
   rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mp->mac, mp->is_add);
 
@@ -1825,7 +1817,7 @@ setup_message_id_table (api_main_t * am)
 static clib_error_t *
 one_api_hookup (vlib_main_t * vm)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
 
 #define _(N,n)                                                  \
     vl_msg_api_set_handlers(VL_API_##N, #n,                     \