lisp: fix crash with arp and packet trace on
[vpp.git] / src / vnet / lisp-cp / control.c
index 0eb7b1d..60d8561 100644 (file)
@@ -123,41 +123,6 @@ ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index,
   return 1;
 }
 
-/**
- * convert from a LISP address to a FIB prefix
- */
-void
-ip_address_to_fib_prefix (const ip_address_t * addr, fib_prefix_t * prefix)
-{
-  if (addr->version == AF_IP4)
-    {
-      prefix->fp_len = 32;
-      prefix->fp_proto = FIB_PROTOCOL_IP4;
-      clib_memset (&prefix->fp_addr.pad, 0, sizeof (prefix->fp_addr.pad));
-      memcpy (&prefix->fp_addr.ip4, &addr->ip.ip4,
-             sizeof (prefix->fp_addr.ip4));
-    }
-  else
-    {
-      prefix->fp_len = 128;
-      prefix->fp_proto = FIB_PROTOCOL_IP6;
-      memcpy (&prefix->fp_addr.ip6, &addr->ip.ip6,
-             sizeof (prefix->fp_addr.ip6));
-    }
-  prefix->___fp___pad = 0;
-}
-
-/**
- * convert from a LISP to a FIB prefix
- */
-void
-ip_prefix_to_fib_prefix (const ip_prefix_t * ip_prefix,
-                        fib_prefix_t * fib_prefix)
-{
-  ip_address_to_fib_prefix (&ip_prefix->addr, fib_prefix);
-  fib_prefix->fp_len = ip_prefix->len;
-}
-
 /**
  * Find the sw_if_index of the interface that would be used to egress towards
  * dst.
@@ -1238,12 +1203,6 @@ remove_overlapping_sub_prefixes (lisp_cp_main_t * lcm, gid_address_t * eid,
   vec_free (a.eids_to_be_deleted);
 }
 
-static void
-mapping_delete_timer (lisp_cp_main_t * lcm, u32 mi)
-{
-  timing_wheel_delete (&lcm->wheel, mi);
-}
-
 static int
 is_local_ip (lisp_cp_main_t * lcm, ip_address_t * addr)
 {
@@ -1409,7 +1368,7 @@ vnet_lisp_del_mapping (gid_address_t * eid, u32 * res_map_index)
 
   /* delete timer associated to the mapping if any */
   if (old_map->timer_set)
-    mapping_delete_timer (lcm, mi);
+    TW (tw_timer_stop) (&lcm->wheel, old_map->timer_handle);
 
   /* delete locator set */
   vnet_lisp_add_del_locator_set (ls_args, 0);
@@ -1705,7 +1664,7 @@ vnet_lisp_use_petr (ip_address_t * ip, u8 is_add)
 
   if (is_add)
     {
-      /* Create dummy petr locator-set */
+      /* Create placeholder petr locator-set */
       clib_memset (&loc, 0, sizeof (loc));
       gid_address_from_ip (&loc.address, ip);
       loc.priority = 1;
@@ -2089,14 +2048,9 @@ vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a,
              ls->name = vec_dup (a->name);
 
              if (!lcm->locator_set_index_by_name)
-               lcm->locator_set_index_by_name = hash_create_vec (
-                                                                  /* size */
-                                                                  0,
-                                                                  sizeof
-                                                                  (ls->name
-                                                                   [0]),
-                                                                  sizeof
-                                                                  (uword));
+               lcm->locator_set_index_by_name =
+                 hash_create_vec ( /* size */ 0, sizeof (ls->name[0]),
+                                  sizeof (uword));
              hash_set_mem (lcm->locator_set_index_by_name, ls->name,
                            ls_index);
 
@@ -2883,7 +2837,7 @@ lisp_cp_output (vlib_main_t * vm, vlib_node_runtime_t * node,
   return 0;
 }
 
-/* dummy node used only for statistics */
+/* placeholder node used only for statistics */
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (lisp_cp_output_node) = {
   .function = lisp_cp_output,
@@ -3598,7 +3552,11 @@ lisp_cp_lookup_inline (vlib_main_t * vm,
                                                           sizeof (*tr));
 
              clib_memset (tr, 0, sizeof (*tr));
-             gid_address_copy (&tr->dst_eid, &dst);
+             if ((gid_address_type (&dst) == GID_ADDR_NDP) ||
+                 (gid_address_type (&dst) == GID_ADDR_ARP))
+               clib_memcpy (&tr->dst_eid, &dst, sizeof (gid_address_t));
+             else
+               gid_address_copy (&tr->dst_eid, &dst);
              ip_address_copy (&tr->map_resolver_ip,
                               &lcm->active_map_resolver);
            }
@@ -3777,8 +3735,8 @@ remove_expired_mapping (lisp_cp_main_t * lcm, u32 mi)
   if (vnet_lisp_add_del_adjacency (adj_args))
     clib_warning ("failed to del adjacency!");
 
+  TW (tw_timer_stop) (&lcm->wheel, m->timer_handle);
   vnet_lisp_del_mapping (&m->eid, NULL);
-  mapping_delete_timer (lcm, mi);
 }
 
 static void
@@ -3793,7 +3751,7 @@ mapping_start_expiration_timer (lisp_cp_main_t * lcm, u32 mi,
   m = pool_elt_at_index (lcm->mapping_pool, mi);
 
   m->timer_set = 1;
-  timing_wheel_insert (&lcm->wheel, exp_clock_time, mi);
+  m->timer_handle = TW (tw_timer_start) (&lcm->wheel, mi, 0, exp_clock_time);
 }
 
 static void
@@ -4546,8 +4504,9 @@ lisp_cp_init (vlib_main_t * vm)
   hash_set (lcm->table_id_by_vni, 0, 0);
   hash_set (lcm->vni_by_table_id, 0, 0);
 
-  u64 now = clib_cpu_time_now ();
-  timing_wheel_init (&lcm->wheel, now, vm->clib_time.clocks_per_second);
+  TW (tw_timer_wheel_init) (&lcm->wheel, 0 /* no callback */ ,
+                           1e-3 /* timer period 1ms */ ,
+                           ~0 /* max expirations per call */ );
   lcm->nsh_map_index = ~0;
   lcm->map_register_ttl = MAP_REGISTER_DEFAULT_TTL;
   lcm->max_expired_map_registers = MAX_EXPIRED_MAP_REGISTERS_DEFAULT;
@@ -4869,9 +4828,8 @@ send_map_resolver_service (vlib_main_t * vm,
       update_map_register (lcm, period);
       update_rloc_probing (lcm, period);
 
-      u64 now = clib_cpu_time_now ();
-
-      expired = timing_wheel_advance (&lcm->wheel, now, expired, 0);
+      expired = TW (tw_timer_expire_timers_vec) (&lcm->wheel,
+                                                vlib_time_now (vm), expired);
       if (vec_len (expired) > 0)
        {
          u32 *mi = 0;