lb: crashed with some specific commit under heavy traffic
[vpp.git] / src / plugins / lb / lb.c
index 5326433..75ca40f 100644 (file)
@@ -442,7 +442,7 @@ out:
   //Let's create a new flow table
   vec_validate(new_flow_table, vip->new_flow_table_mask);
   for (i=0; i<vec_len(new_flow_table); i++)
-    new_flow_table[i].as_index = ~0;
+    new_flow_table[i].as_index = 0;
 
   u32 done = 0;
   while (1) {
@@ -450,7 +450,7 @@ out:
       while (1) {
         u32 last = pr->last;
         pr->last = (pr->last + pr->skip) & vip->new_flow_table_mask;
-        if (new_flow_table[last].as_index == ~0) {
+        if (new_flow_table[last].as_index == 0) {
           new_flow_table[last].as_index = pr->as_index;
           break;
         }
@@ -773,7 +773,7 @@ lb_flush_vip_as (u32 vip_index, u32 as_index)
               vlib_refcount_add(&lbm->as_refcount, thread_index, b->value[i], -1);
               vlib_refcount_add(&lbm->as_refcount, thread_index, 0, 1);
               b->vip[i] = ~0;
-              b->value[i] = ~0;
+              b->value[i] = 0;
             }
         }
         if (vip_index == ~0)
@@ -984,10 +984,15 @@ static int lb_vip_del_port_filter(lb_main_t *lbm, lb_vip_t *vip)
   key.vip_prefix_index = vip->vip_prefix_index;
   key.protocol = vip->protocol;
   key.port = clib_host_to_net_u16(vip->port);
+  key.rsv = 0;
 
   kv.key = key.as_u64;
-  if(clib_bihash_search_8_8(&lbm->vip_index_per_port, &kv, &value) == 0)
-    m = pool_elt_at_index (lbm->vips, value.value);
+  if(clib_bihash_search_8_8(&lbm->vip_index_per_port, &kv, &value) != 0)
+    {
+      clib_warning("looking up vip_index_per_port failed.");
+      return VNET_API_ERROR_NO_SUCH_ENTRY;
+    }
+  m = pool_elt_at_index (lbm->vips, value.value);
   ASSERT (m);
 
   kv.value = m - lbm->vips;
@@ -1190,10 +1195,11 @@ int lb_vip_del(u32 vip_index)
 {
   lb_main_t *lbm = &lb_main;
   lb_vip_t *vip;
+  int rv = 0;
 
   /* Does not remove default vip, i.e. vip_index = 0 */
   if (vip_index == 0)
-    return 0;
+    return VNET_API_ERROR_INVALID_VALUE;
 
   lb_get_writer_lock();
   if (!(vip = lb_vip_get_by_index(vip_index))) {
@@ -1225,20 +1231,20 @@ int lb_vip_del(u32 vip_index)
   //Delete per-port vip filtering entry
   if (vip->port != 0)
     {
-      lb_vip_del_port_filter(lbm, vip);
+      rv = lb_vip_del_port_filter(lbm, vip);
     }
 
   //Set the VIP as unused
   vip->flags &= ~LB_VIP_FLAGS_USED;
 
   lb_put_writer_lock();
-  return 0;
+  return rv;
 }
 
 /* *INDENT-OFF* */
 VLIB_PLUGIN_REGISTER () = {
     .version = VPP_BUILD_VER,
-    .description = "Load Balancer",
+    .description = "Load Balancer (LB)",
 };
 /* *INDENT-ON* */
 
@@ -1369,6 +1375,7 @@ lb_init (vlib_main_t * vm)
   //Allocate and init default VIP.
   lbm->vips = 0;
   pool_get(lbm->vips, default_vip);
+  default_vip->new_flow_table_mask = 0;
   default_vip->prefix.ip6.as_u64[0] = 0xffffffffffffffffL;
   default_vip->prefix.ip6.as_u64[1] = 0xffffffffffffffffL;
   default_vip->protocol = ~0;
@@ -1412,6 +1419,12 @@ lb_init (vlib_main_t * vm)
   default_as->address.ip6.as_u64[0] = 0xffffffffffffffffL;
   default_as->address.ip6.as_u64[1] = 0xffffffffffffffffL;
 
+  /* Generate a valid flow table for default VIP */
+  default_vip->as_indexes = NULL;
+  lb_get_writer_lock();
+  lb_vip_update_new_flow_table(default_vip);
+  lb_put_writer_lock();
+
   lbm->vip_index_by_nodeport
     = hash_create_mem (0, sizeof(u16), sizeof (uword));