ipsec: IPSec protection for multi-point tunnel interfaces
[vpp.git] / src / vnet / fib / fib_urpf_list.c
index 263812a..bd22514 100644 (file)
 fib_urpf_list_t *fib_urpf_list_pool;
 
 u8 *
-format_fib_urpf_list (u8 *s, va_list args)
+format_fib_urpf_list (u8 *s, va_list *args)
 {
     fib_urpf_list_t *urpf;
     index_t ui;
     u32 *swi;
 
-    ui = va_arg(args, index_t);
-    urpf = fib_urpf_list_get(ui);
+    ui = va_arg(*args, index_t);
+
+    if (INDEX_INVALID != ui)
+    {
+        urpf = fib_urpf_list_get(ui);
 
-    s = format(s, "uPRF-list:%d len:%d itfs:[",
-              ui, vec_len(urpf->furpf_itfs));
+        s = format(s, "uPRF-list:%d len:%d itfs:[",
+                   ui, vec_len(urpf->furpf_itfs));
 
-    vec_foreach(swi, urpf->furpf_itfs)
+        vec_foreach(swi, urpf->furpf_itfs)
+        {
+            s = format(s, "%d, ", *swi);
+        }
+        s = format(s, "]");
+    }
+    else
     {
-       s = format(s, "%d, ", *swi);
+        s = format(s, "uRPF-list: None");
     }
-    s = format(s, "]");
 
     return (s);
 }
@@ -49,7 +57,7 @@ fib_urpf_list_alloc_and_lock (void)
     fib_urpf_list_t *urpf;
 
     pool_get(fib_urpf_list_pool, urpf);
-    memset(urpf, 0, sizeof(*urpf));
+    clib_memset(urpf, 0, sizeof(*urpf));
 
     urpf->furpf_locks++;
 
@@ -124,8 +132,7 @@ static int
 fib_urpf_itf_cmp_for_sort (void * v1,
                           void * v2)
 {
-    fib_node_index_t *i1 = v1, *i2 = v2;
-
+    const adj_index_t *i1 = v1, *i2 = v2;
     return (*i2 < *i1);
 }
 
@@ -143,49 +150,21 @@ fib_urpf_list_bake (index_t ui)
     ASSERT(!(urpf->furpf_flags & FIB_URPF_LIST_BAKED));
 
     if (vec_len(urpf->furpf_itfs) > 1)
-    {
-       u32 i,j;
-
-       /*
-        * cat list | sort | uniq > rpf_list
-        */
-       vec_sort_with_function(urpf->furpf_itfs, fib_urpf_itf_cmp_for_sort);
-
-       i = 0, j = 1;
-       while (j < vec_len(urpf->furpf_itfs))
-       {
-           if (urpf->furpf_itfs[i] == urpf->furpf_itfs[j])
-           {
-               /*
-                * the itfacenct entries are the same.
-                * search forward for a unique one
-                */
-               while (urpf->furpf_itfs[i] == urpf->furpf_itfs[j] &&
-                      j < vec_len(urpf->furpf_itfs))
-               {
-                   j++;
-               }
-               if (j == vec_len(urpf->furpf_itfs))
-               {
-                   /*
-                    * ran off the end without finding a unique index.
-                    * we are done.
-                    */
-                   break;
-               }
-               else
-               {
-                   urpf->furpf_itfs[i+1] = urpf->furpf_itfs[j];
-               }
-           }
-           i++, j++;
-       }
-
-       /*
-        * set the length of the vector to the number of unique itfs
-        */
-       _vec_len(urpf->furpf_itfs) = i+1;
-    }
+      {
+        u32 i, j;
+        /*
+         * cat list | sort | uniq > rpf_list
+         */
+        /* sort */
+        vec_sort_with_function(urpf->furpf_itfs, fib_urpf_itf_cmp_for_sort);
+        /* remove duplicates */
+        i = 0;
+        for (j=1; j<vec_len(urpf->furpf_itfs); j++)
+          if (urpf->furpf_itfs[i] != urpf->furpf_itfs[j])
+            urpf->furpf_itfs[++i] = urpf->furpf_itfs[j];
+        /* set the length of the vector to the number of unique itfs */
+        _vec_len(urpf->furpf_itfs) = i+1;
+      }
 
     urpf->furpf_flags |= FIB_URPF_LIST_BAKED;
 }