session svm: segment manager and fifo segment leaks
[vpp.git] / src / plugins / lb / lb.c
index b1e0b23..6fc7f0f 100644 (file)
@@ -17,7 +17,7 @@
 #include <vnet/plugin/plugin.h>
 #include <vpp/app/version.h>
 #include <vnet/api_errno.h>
-#include <vnet/udp/udp.h>
+#include <vnet/udp/udp_local.h>
 #include <vppinfra/lock.h>
 
 //GC runs at most once every so many seconds
@@ -26,6 +26,9 @@
 //After so many seconds. It is assumed that inter-core race condition will not occur.
 #define LB_CONCURRENCY_TIMEOUT 10
 
+// FIB source for adding routes
+static fib_source_t lb_fib_src;
+
 lb_main_t lb_main;
 
 #define lb_get_writer_lock() clib_spinlock_lock (&lb_main.writer_lock)
@@ -252,7 +255,7 @@ u8 *format_lb_vip_detailed (u8 * s, va_list * args)
 
   lb_as_t *as;
   u32 *as_index;
-  pool_foreach(as_index, vip->as_indexes, {
+  pool_foreach (as_index, vip->as_indexes) {
       as = &lbm->ass[*as_index];
       s = format(s, "%U    %U %u buckets   %Lu flows  dpo:%u %s\n",
                    format_white_space, indent,
@@ -261,7 +264,7 @@ u8 *format_lb_vip_detailed (u8 * s, va_list * args)
                    vlib_refcount_get(&lbm->as_refcount, as - lbm->ass),
                    as->dpo.dpoi_index,
                    (as->flags & LB_AS_FLAGS_USED)?"used":" removed");
-  });
+  }
 
   vec_free(count);
   return s;
@@ -299,7 +302,7 @@ static void lb_vip_garbage_collection(lb_vip_t *vip)
   vip->last_garbage_collection = now;
   lb_as_t *as;
   u32 *as_index;
-  pool_foreach(as_index, vip->as_indexes, {
+  pool_foreach (as_index, vip->as_indexes) {
       as = &lbm->ass[*as_index];
       if (!(as->flags & LB_AS_FLAGS_USED) && //Not used
           clib_u32_loop_gt(now, as->last_used + LB_CONCURRENCY_TIMEOUT) &&
@@ -348,7 +351,7 @@ static void lb_vip_garbage_collection(lb_vip_t *vip)
           pool_put(vip->as_indexes, as_index);
           pool_put(lbm->ass, as);
         }
-  });
+  }
 }
 
 void lb_garbage_collection()
@@ -357,14 +360,14 @@ void lb_garbage_collection()
   lb_get_writer_lock();
   lb_vip_t *vip;
   u32 *to_be_removed_vips = 0, *i;
-  pool_foreach(vip, lbm->vips, {
+  pool_foreach (vip, lbm->vips) {
       lb_vip_garbage_collection(vip);
 
       if (!(vip->flags & LB_VIP_FLAGS_USED) &&
           (pool_elts(vip->as_indexes) == 0)) {
         vec_add1(to_be_removed_vips, vip - lbm->vips);
       }
-  });
+  }
 
   vec_foreach(i, to_be_removed_vips) {
     vip = &lbm->vips[*i];
@@ -389,13 +392,13 @@ static void lb_vip_update_new_flow_table(lb_vip_t *vip)
 
   //Check if some AS is configured or not
   i = 0;
-  pool_foreach(as_index, vip->as_indexes, {
+  pool_foreach (as_index, vip->as_indexes) {
       as = &lbm->ass[*as_index];
       if (as->flags & LB_AS_FLAGS_USED) { //Not used anymore
         i = 1;
         goto out; //Not sure 'break' works in this macro-loop
       }
-  });
+  }
 
 out:
   if (i == 0) {
@@ -411,14 +414,14 @@ out:
   vec_alloc(sort_arr, pool_elts(vip->as_indexes));
 
   i = 0;
-  pool_foreach(as_index, vip->as_indexes, {
+  pool_foreach (as_index, vip->as_indexes) {
       as = &lbm->ass[*as_index];
       if (!(as->flags & LB_AS_FLAGS_USED)) //Not used anymore
         continue;
 
       sort_arr[i].as_index = as - lbm->ass;
       i++;
-  });
+  }
   _vec_len(sort_arr) = i;
 
   vec_sort_with_function(sort_arr, lb_pseudorand_compare);
@@ -500,7 +503,7 @@ int lb_vip_port_find_index(ip46_address_t *prefix, u8 plen,
   /* This must be called with the lock owned */
   CLIB_SPINLOCK_ASSERT_LOCKED (&lbm->writer_lock);
   ip46_prefix_normalize(prefix, plen);
-  pool_foreach(vip, lbm->vips, {
+  pool_foreach (vip, lbm->vips) {
       if ((vip->flags & LB_AS_FLAGS_USED) &&
           vip->plen == plen &&
           vip->prefix.as_u64[0] == prefix->as_u64[0] &&
@@ -519,7 +522,7 @@ int lb_vip_port_find_index(ip46_address_t *prefix, u8 plen,
               return 0;
             }
         }
-  });
+  }
   return VNET_API_ERROR_NO_SUCH_ENTRY;
 }
 
@@ -566,7 +569,7 @@ static int lb_as_find_index_vip(lb_vip_t *vip, ip46_address_t *address, u32 *as_
   CLIB_SPINLOCK_ASSERT_LOCKED (&lbm->writer_lock);
   lb_as_t *as;
   u32 *asi;
-  pool_foreach(asi, vip->as_indexes, {
+  pool_foreach (asi, vip->as_indexes) {
       as = &lbm->ass[*asi];
       if (as->vip_index == (vip - lbm->vips) &&
           as->address.as_u64[0] == address->as_u64[0] &&
@@ -575,7 +578,7 @@ static int lb_as_find_index_vip(lb_vip_t *vip, ip46_address_t *address, u32 *as_
         *as_index = as - lbm->ass;
         return 0;
       }
-  });
+  }
   return -1;
 }
 
@@ -903,6 +906,8 @@ static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip,
       if (!lb_vip_port_find_diff_port(&(vip->prefix), vip->plen,
                                       vip->protocol, vip->port, &vip_idx))
         {
+          lb_vip_t *exists_vip = lb_vip_get_by_index(vip_idx);
+          *vip_prefix_index = exists_vip ? exists_vip->vip_prefix_index : ~0;
           return;
         }
 
@@ -948,7 +953,7 @@ static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip,
   dpo_set(&dpo, dpo_type, proto, *vip_prefix_index);
   fib_table_entry_special_dpo_add(0,
                                   &pfx,
-                                  FIB_SOURCE_PLUGIN_HI,
+                                  lb_fib_src,
                                   FIB_ENTRY_FLAG_EXCLUSIVE,
                                   &dpo);
   dpo_reset(&dpo);
@@ -1037,7 +1042,7 @@ static void lb_vip_del_adjacency(lb_main_t *lbm, lb_vip_t *vip)
       pfx.fp_len = vip->plen;
       pfx.fp_proto = FIB_PROTOCOL_IP6;
   }
-  fib_table_entry_special_remove(0, &pfx, FIB_SOURCE_PLUGIN_HI);
+  fib_table_entry_special_remove(0, &pfx, lb_fib_src);
 }
 
 int lb_vip_add(lb_vip_add_args_t args, u32 *vip_index)
@@ -1219,10 +1224,10 @@ int lb_vip_del(u32 vip_index)
     lb_as_t *as;
     u32 *as_index;
 
-    pool_foreach(as_index, vip->as_indexes, {
+    pool_foreach (as_index, vip->as_indexes) {
         as = &lbm->ass[*as_index];
         vec_add1(ass, as->address);
-    });
+    }
     if (vec_len(ass))
       lb_vip_del_ass_withlock(vip_index, ass, vec_len(ass), 0);
     vec_free(ass);
@@ -1445,6 +1450,11 @@ lb_init (vlib_main_t * vm)
 #define _(a,b,c) lbm->vip_counters[c].name = b;
   lb_foreach_vip_counter
 #undef _
+
+  lb_fib_src = fib_source_allocate("lb",
+                                   FIB_SOURCE_PRIORITY_HI,
+                                   FIB_SOURCE_BH_SIMPLE);
+
   return NULL;
 }