fib: leverage well-optimized clib_memcpy
[vpp.git] / src / vnet / fib / fib_api.c
index 5aa5c4e..856271f 100644 (file)
@@ -75,9 +75,9 @@ fib_api_next_hop_decode (const vl_api_fib_path_t *in,
                          ip46_address_t *out)
 {
     if (in->proto == FIB_API_PATH_NH_PROTO_IP4)
-        memcpy (&out->ip4, &in->nh.address.ip4, sizeof (out->ip4));
+        clib_memcpy (&out->ip4, &in->nh.address.ip4, sizeof (out->ip4));
     else if (in->proto == FIB_API_PATH_NH_PROTO_IP6)
-        memcpy (&out->ip6, &in->nh.address.ip6, sizeof (out->ip6));
+        clib_memcpy (&out->ip6, &in->nh.address.ip6, sizeof (out->ip6));
 }
 
 static vl_api_fib_path_nh_proto_t
@@ -110,11 +110,11 @@ fib_api_next_hop_encode (const fib_route_path_t *rpath,
     fp->proto = fib_api_path_dpo_proto_to_nh(rpath->frp_proto);
 
     if (rpath->frp_proto == DPO_PROTO_IP4)
-        memcpy (&fp->nh.address.ip4,
+        clib_memcpy (&fp->nh.address.ip4,
                 &rpath->frp_addr.ip4,
                 sizeof (rpath->frp_addr.ip4));
     else if (rpath->frp_proto == DPO_PROTO_IP6)
-        memcpy (&fp->nh.address.ip6,
+        clib_memcpy (&fp->nh.address.ip6,
                 &rpath->frp_addr.ip6,
                 sizeof (rpath->frp_addr.ip6));
 }
@@ -186,6 +186,8 @@ fib_api_path_decode (vl_api_fib_path_t *in,
         out->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
     if (in->flags & FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED)
         out->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
+    if (in->flags & FIB_API_PATH_FLAG_POP_PW_CW)
+        out->frp_flags |= FIB_ROUTE_PATH_POP_PW_CW;
 
     switch (in->type)
     {
@@ -449,7 +451,7 @@ fib_api_path_encode (const fib_route_path_t * rpath,
     }
 }
 
-void
+int
 fib_api_route_add_del (u8 is_add,
                        u8 is_multipath,
                        u32 fib_index,
@@ -457,36 +459,46 @@ fib_api_route_add_del (u8 is_add,
                        fib_entry_flag_t entry_flags,
                        fib_route_path_t *rpaths)
 {
-  if (is_multipath)
+    if (is_multipath)
     {
-      /* Iterative path add/remove */
-      if (is_add)
-       fib_table_entry_path_add2 (fib_index,
-                                  prefix,
-                                  FIB_SOURCE_API,
-                                   entry_flags,
-                                   rpaths);
-      else
-       fib_table_entry_path_remove2 (fib_index,
-                                     prefix,
-                                      FIB_SOURCE_API,
-                                      rpaths);
+        if (vec_len(rpaths) == 0)
+            return (VNET_API_ERROR_NO_PATHS_IN_ROUTE);
+
+        /* Iterative path add/remove */
+        if (is_add)
+            fib_table_entry_path_add2 (fib_index,
+                                       prefix,
+                                       FIB_SOURCE_API,
+                                       entry_flags,
+                                       rpaths);
+        else
+            fib_table_entry_path_remove2 (fib_index,
+                                          prefix,
+                                          FIB_SOURCE_API,
+                                          rpaths);
     }
-  else
+    else
     {
-      if (is_add)
-        /* path replacement */
-       fib_table_entry_update (fib_index,
-                                prefix,
-                                FIB_SOURCE_API,
-                                entry_flags,
-                                rpaths);
-      else
-        /* entry delete */
-       fib_table_entry_delete (fib_index,
-                                prefix,
-                                FIB_SOURCE_API);
+        if (is_add)
+        {
+            if (vec_len(rpaths) == 0)
+                return (VNET_API_ERROR_NO_PATHS_IN_ROUTE);
+
+            /* path replacement */
+            fib_table_entry_update (fib_index,
+                                    prefix,
+                                    FIB_SOURCE_API,
+                                    entry_flags,
+                                    rpaths);
+        }
+        else
+            /* entry delete */
+            fib_table_entry_delete (fib_index,
+                                    prefix,
+                                    FIB_SOURCE_API);
     }
+
+    return (0);
 }
 
 u8*