Fix tcp tx buffer allocation
[vpp.git] / src / vnet / gre / gre_api.c
index 333838c..ceeb1d4 100644 (file)
@@ -55,17 +55,17 @@ static void vl_api_gre_add_del_tunnel_t_handler
   int rv = 0;
   vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
   u32 outer_fib_id;
-  uword *p;
-  ip4_main_t *im = &ip4_main;
+  u32 p;
   u32 sw_if_index = ~0;
 
-  p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
-  if (!p)
+  p = fib_table_find (!mp->is_ipv6 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6,
+                     ntohl (mp->outer_fib_id));
+  if (p == ~0)
     {
       rv = VNET_API_ERROR_NO_SUCH_FIB;
       goto out;
     }
-  outer_fib_id = p[0];
+  outer_fib_id = p;
 
   /* Check src & dst are different */
   if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
@@ -78,10 +78,19 @@ static void vl_api_gre_add_del_tunnel_t_handler
 
   a->is_add = mp->is_add;
   a->teb = mp->teb;
+  a->is_ipv6 = mp->is_ipv6;
 
   /* ip addresses sent in network byte order */
-  clib_memcpy (&(a->src), mp->src_address, 4);
-  clib_memcpy (&(a->dst), mp->dst_address, 4);
+  if (!mp->is_ipv6)
+    {
+      clib_memcpy (&(a->src.ip4), mp->src_address, 4);
+      clib_memcpy (&(a->dst.ip4), mp->dst_address, 4);
+    }
+  else
+    {
+      clib_memcpy (&(a->src.ip6), mp->src_address, 16);
+      clib_memcpy (&(a->dst.ip6), mp->dst_address, 16);
+    }
 
   a->outer_fib_id = outer_fib_id;
   rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
@@ -99,17 +108,30 @@ static void send_gre_tunnel_details
   (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
 {
   vl_api_gre_tunnel_details_t *rmp;
-  ip4_main_t *im = &ip4_main;
+  u8 is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
+  fib_table_t *ft;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
   memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
-  clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
-  clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
-  rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
+  if (!is_ipv6)
+    {
+      clib_memcpy (rmp->src_address, &(t->tunnel_src.ip4.as_u8), 4);
+      clib_memcpy (rmp->dst_address, &(t->tunnel_dst.fp_addr.ip4.as_u8), 4);
+      ft = fib_table_get (t->outer_fib_index, FIB_PROTOCOL_IP4);
+      rmp->outer_fib_id = ft->ft_table_id;
+    }
+  else
+    {
+      clib_memcpy (rmp->src_address, &(t->tunnel_src.ip6.as_u8), 16);
+      clib_memcpy (rmp->dst_address, &(t->tunnel_dst.fp_addr.ip6.as_u8), 16);
+      ft = fib_table_get (t->outer_fib_index, FIB_PROTOCOL_IP6);
+      rmp->outer_fib_id = ft->ft_table_id;
+    }
   rmp->teb = (GRE_TUNNEL_TYPE_TEB == t->type);
   rmp->sw_if_index = htonl (t->sw_if_index);
   rmp->context = context;
+  rmp->is_ipv6 = is_ipv6;
 
   vl_msg_api_send_shmem (q, (u8 *) & rmp);
 }