VPP-323: Add LISP locator set index to reply API message
[vpp.git] / vpp / vpp-api / api.c
index 3e3548d..17893f1 100644 (file)
@@ -82,6 +82,7 @@
 #include <vnet/policer/policer.h>
 #include <vnet/devices/netmap/netmap.h>
 #include <vnet/flow/flow_report.h>
+#include <vnet/ipsec-gre/ipsec_gre.h>
 
 #undef BIHASH_TYPE
 #undef __included_bihash_template_h__
@@ -382,7 +383,9 @@ _(PG_ENABLE_DISABLE, pg_enable_disable)                                 \
 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL,                               \
   ip_source_and_port_range_check_add_del)                               \
 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL,                     \
-  ip_source_and_port_range_check_interface_add_del)
+  ip_source_and_port_range_check_interface_add_del)                     \
+_(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel)                   \
+_(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump)
 
 #define QUOTE_(x) #x
 #define QUOTE(x) QUOTE_(x)
@@ -1452,10 +1455,14 @@ vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
   ip6_main_t *ip6m = &ip6_main;
   ip_lookup_main_t *ip4lm = &ip4m->lookup_main;
   ip_lookup_main_t *ip6lm = &ip6m->lookup_main;
-  ip_config_main_t *rx_cm4u = &ip4lm->rx_config_mains[VNET_UNICAST];
-  ip_config_main_t *rx_cm4m = &ip4lm->rx_config_mains[VNET_MULTICAST];
-  ip_config_main_t *rx_cm6u = &ip6lm->rx_config_mains[VNET_UNICAST];
-  ip_config_main_t *rx_cm6m = &ip6lm->rx_config_mains[VNET_MULTICAST];
+  ip_config_main_t *rx_cm4u =
+    &ip4lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
+  ip_config_main_t *rx_cm4m =
+    &ip4lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
+  ip_config_main_t *rx_cm6u =
+    &ip6lm->feature_config_mains[VNET_IP_RX_UNICAST_FEAT];
+  ip_config_main_t *rx_cm6m =
+    &ip6lm->feature_config_mains[VNET_IP_RX_MULTICAST_FEAT];
 
   VALIDATE_SW_IF_INDEX (mp);
 
@@ -2591,7 +2598,7 @@ vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
   int rv = 0;
 
   if (mp->sw_if_index != ~0)
-    VALIDATE_SW_IF_INDEX(mp);
+    VALIDATE_SW_IF_INDEX (mp);
 
   vec_reset_length (my_vnet_mains);
 
@@ -5153,7 +5160,12 @@ vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
   vec_free (locator_name);
   vec_free (a->locators);
 
-  REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY);
+  /* *INDENT-OFF* */
+  REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
+  ({
+    rmp->ls_index = clib_host_to_net_u32 (ls_index);
+  }));
+  /* *INDENT-ON* */
 }
 
 static void
@@ -5496,7 +5508,7 @@ static void
   /* NOTE: for now this works as a static remote mapping, i.e.,
    * not authoritative and ttl infinite. */
   rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
-                                 mp->is_add, 0);
+                                 mp->is_add, 1 /* is_static */ , 0);
 
   if (mp->del_all)
     vnet_lisp_clear_all_remote_adjacencies ();
@@ -5668,16 +5680,16 @@ send_lisp_eid_table_details (mapping_t * mapit,
 
   switch (filter)
     {
-    case 0: /* all mappings */
+    case 0:                    /* all mappings */
       break;
 
-    case 1: /* local only */
+    case 1:                    /* local only */
       if (!mapit->local)
-        return;
+       return;
       break;
-    case 2: /* remote only */
+    case 2:                    /* remote only */
       if (mapit->local)
-        return;
+       return;
       break;
     default:
       clib_warning ("Filter error, unknown filter: %d", filter);
@@ -5754,7 +5766,7 @@ vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
 
       mapit = pool_elt_at_index (lcm->mapping_pool, mi);
       send_lisp_eid_table_details (mapit, q, mp->context,
-                                   0 /* ignore filter */);
+                                  0 /* ignore filter */ );
     }
   else
     {
@@ -5862,7 +5874,7 @@ vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
 {
   unix_shared_memory_queue_t *q = NULL;
   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
-  ip_address_t *ip = NULL;
+  map_resolver_t *mr;
 
   q = vl_api_client_index_to_input_queue (mp->client_index);
   if (q == 0)
@@ -5870,11 +5882,10 @@ vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
       return;
     }
 
-  vec_foreach (ip, lcm->map_resolvers)
+  vec_foreach (mr, lcm->map_resolvers)
   {
-    send_lisp_map_resolver_details (ip, q, mp->context);
+    send_lisp_map_resolver_details (&mr->address, q, mp->context);
   }
-
 }
 
 static void
@@ -7100,7 +7111,7 @@ send_mpls_gre_tunnel_entry (vpe_api_main_t * am,
   e = pool_elt_at_index (mm->encaps, gt->encap_index);
   nlabels = vec_len (e->labels);
 
-  mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof(u32));
+  mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
   memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_MPLS_GRE_TUNNEL_DETAILS);
   mp->context = context;
@@ -7143,11 +7154,11 @@ vl_api_mpls_gre_tunnel_dump_t_handler (vl_api_mpls_gre_tunnel_dump_t * mp)
   if (index != ~0)
     {
       if (!pool_is_free_index (mm->gre_tunnels, index))
-        {
-          gt = pool_elt_at_index (mm->gre_tunnels, index);
-          send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
-                                      mp->context);
-        }
+       {
+         gt = pool_elt_at_index (mm->gre_tunnels, index);
+         send_mpls_gre_tunnel_entry (am, q, gt, gt - mm->gre_tunnels,
+                                     mp->context);
+       }
     }
   else
     {
@@ -7182,7 +7193,7 @@ send_mpls_eth_tunnel_entry (vpe_api_main_t * am,
   e = pool_elt_at_index (mm->encaps, et->encap_index);
   nlabels = vec_len (e->labels);
 
-  mp = vl_msg_api_alloc (sizeof (*mp) + nlabels*sizeof(u32));
+  mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
   memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_MPLS_ETH_TUNNEL_DETAILS);
   mp->context = context;
@@ -7223,12 +7234,12 @@ vl_api_mpls_eth_tunnel_dump_t_handler (vl_api_mpls_eth_tunnel_dump_t * mp)
 
   if (index != ~0)
     {
-      if (!pool_is_free_index(mm->eth_tunnels, index))
-        {
-          et = pool_elt_at_index (mm->eth_tunnels, index);
-          send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
-                                      mp->context);
-        }
+      if (!pool_is_free_index (mm->eth_tunnels, index))
+       {
+         et = pool_elt_at_index (mm->eth_tunnels, index);
+         send_mpls_eth_tunnel_entry (am, q, et, et - mm->eth_tunnels,
+                                     mp->context);
+       }
     }
   else
     {
@@ -7262,7 +7273,7 @@ send_mpls_fib_encap_details (vpe_api_main_t * am,
   e = pool_elt_at_index (mm->encaps, s->entry_index);
   nlabels = vec_len (e->labels);
 
-  mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof(u32));
+  mp = vl_msg_api_alloc (sizeof (*mp) + nlabels * sizeof (u32));
   memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_ENCAP_DETAILS);
   mp->context = context;
@@ -7988,6 +7999,97 @@ reply:
   REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY);
 }
 
+static void
+vl_api_ipsec_gre_add_del_tunnel_t_handler (vl_api_ipsec_gre_add_del_tunnel_t *
+                                          mp)
+{
+  vl_api_ipsec_gre_add_del_tunnel_reply_t *rmp;
+  int rv = 0;
+  vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a;
+  u32 sw_if_index = ~0;
+
+  /* Check src & dst are different */
+  if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
+    {
+      rv = VNET_API_ERROR_SAME_SRC_DST;
+      goto out;
+    }
+
+  memset (a, 0, sizeof (*a));
+
+  /* ip addresses sent in network byte order */
+  clib_memcpy (&(a->src), mp->src_address, 4);
+  clib_memcpy (&(a->dst), mp->dst_address, 4);
+  a->is_add = mp->is_add;
+  a->lsa = ntohl (mp->local_sa_id);
+  a->rsa = ntohl (mp->remote_sa_id);
+
+  rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
+
+out:
+    /* *INDENT-OFF* */
+    REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
+    ({
+        rmp->sw_if_index = ntohl (sw_if_index);
+    }));
+    /* *INDENT-ON* */
+}
+
+static void send_ipsec_gre_tunnel_details
+  (ipsec_gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
+{
+  vl_api_ipsec_gre_tunnel_details_t *rmp;
+
+  rmp = vl_msg_api_alloc (sizeof (*rmp));
+  memset (rmp, 0, sizeof (*rmp));
+  rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
+  clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
+  clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
+  rmp->sw_if_index = htonl (t->sw_if_index);
+  rmp->local_sa_id = htonl (t->local_sa_id);
+  rmp->remote_sa_id = htonl (t->remote_sa_id);
+  rmp->context = context;
+
+  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+}
+
+static void vl_api_ipsec_gre_tunnel_dump_t_handler
+  (vl_api_ipsec_gre_tunnel_dump_t * mp)
+{
+  unix_shared_memory_queue_t *q;
+  ipsec_gre_main_t *igm = &ipsec_gre_main;
+  ipsec_gre_tunnel_t *t;
+  u32 sw_if_index;
+
+  q = vl_api_client_index_to_input_queue (mp->client_index);
+  if (q == 0)
+    {
+      return;
+    }
+
+  sw_if_index = ntohl (mp->sw_if_index);
+
+  if (~0 == sw_if_index)
+    {
+        /* *INDENT-OFF* */
+        pool_foreach (t, igm->tunnels,
+        ({
+            send_ipsec_gre_tunnel_details(t, q, mp->context);
+        }));
+        /* *INDENT-ON* */
+    }
+  else
+    {
+      if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
+         (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
+       {
+         return;
+       }
+      t = &igm->tunnels[igm->tunnel_index_by_sw_if_index[sw_if_index]];
+      send_ipsec_gre_tunnel_details (t, q, mp->context);
+    }
+}
+
 #define BOUNCE_HANDLER(nn)                                              \
 static void vl_api_##nn##_t_handler (                                   \
     vl_api_##nn##_t *mp)                                                \
@@ -8112,13 +8214,14 @@ static clib_error_t *
 api_segment_config (vlib_main_t * vm, unformat_input_t * input)
 {
   u8 *chroot_path;
+  u64 baseva, size, pvt_heap_size;
   int uid, gid, rv;
   const int max_buf_size = 4096;
   char *s, *buf;
   struct passwd _pw, *pw;
   struct group _grp, *grp;
   clib_error_t *e;
-  buf = vec_new(char,128);
+  buf = vec_new (char, 128);
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
       if (unformat (input, "prefix %s", &chroot_path))
@@ -8130,14 +8233,40 @@ api_segment_config (vlib_main_t * vm, unformat_input_t * input)
        vl_set_memory_uid (uid);
       else if (unformat (input, "gid %d", &gid))
        vl_set_memory_gid (gid);
+      else if (unformat (input, "baseva %llx", &baseva))
+       vl_set_global_memory_baseva (baseva);
+      else if (unformat (input, "global-size %lldM", &size))
+       vl_set_global_memory_size (size * (1ULL << 20));
+      else if (unformat (input, "global-size %lldG", &size))
+       vl_set_global_memory_size (size * (1ULL << 30));
+      else if (unformat (input, "global-size %lld", &size))
+       vl_set_global_memory_size (size);
+      else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
+       vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
+      else if (unformat (input, "global-pvt-heap-size size %lld",
+                        &pvt_heap_size))
+       vl_set_global_pvt_heap_size (pvt_heap_size);
+      else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
+       vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
+      else if (unformat (input, "api-pvt-heap-size size %lld",
+                        &pvt_heap_size))
+       vl_set_api_pvt_heap_size (pvt_heap_size);
+      else if (unformat (input, "api-size %lldM", &size))
+       vl_set_api_memory_size (size * (1ULL << 20));
+      else if (unformat (input, "api-size %lldG", &size))
+       vl_set_api_memory_size (size * (1ULL << 30));
+      else if (unformat (input, "api-size %lld", &size))
+       vl_set_api_memory_size (size);
       else if (unformat (input, "uid %s", &s))
        {
          /* lookup the username */
          pw = NULL;
-         while (((rv = getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE) && ( vec_len(buf) <= max_buf_size ))
-        {
-            vec_resize(buf,vec_len(buf)*2);
-        }
+         while (((rv =
+                  getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
+                && (vec_len (buf) <= max_buf_size))
+           {
+             vec_resize (buf, vec_len (buf) * 2);
+           }
          if (rv < 0)
            {
              e = clib_error_return_code (0, rv,
@@ -8145,7 +8274,7 @@ api_segment_config (vlib_main_t * vm, unformat_input_t * input)
                                          CLIB_ERROR_FATAL,
                                          "cannot fetch username %s", s);
              vec_free (s);
-          vec_free (buf);
+             vec_free (buf);
              return e;
            }
          if (pw == NULL)
@@ -8153,7 +8282,7 @@ api_segment_config (vlib_main_t * vm, unformat_input_t * input)
              e =
                clib_error_return_fatal (0, "username %s does not exist", s);
              vec_free (s);
-          vec_free (buf);
+             vec_free (buf);
              return e;
            }
          vec_free (s);
@@ -8163,10 +8292,12 @@ api_segment_config (vlib_main_t * vm, unformat_input_t * input)
        {
          /* lookup the group name */
          grp = NULL;
-         while ( ( (rv = getgrnam_r (s, &_grp, buf, vec_len(buf), &grp)) == ERANGE ) && ( vec_len(buf) <= max_buf_size ) )
-        {
-            vec_resize(buf,vec_len(buf)*2);
-        }
+         while (((rv =
+                  getgrnam_r (s, &_grp, buf, vec_len (buf), &grp)) == ERANGE)
+                && (vec_len (buf) <= max_buf_size))
+           {
+             vec_resize (buf, vec_len (buf) * 2);
+           }
          if (rv != 0)
            {
              e = clib_error_return_code (0, rv,
@@ -8174,18 +8305,18 @@ api_segment_config (vlib_main_t * vm, unformat_input_t * input)
                                          CLIB_ERROR_FATAL,
                                          "cannot fetch group %s", s);
              vec_free (s);
-          vec_free (buf);
+             vec_free (buf);
              return e;
            }
          if (grp == NULL)
            {
              e = clib_error_return_fatal (0, "group %s does not exist", s);
              vec_free (s);
-          vec_free (buf);
+             vec_free (buf);
              return e;
            }
          vec_free (s);
-      vec_free (buf);
+         vec_free (buf);
          vl_set_memory_gid (grp->gr_gid);
        }
       else