ip: change ip API enums address_family and ip_proto size to u8
[vpp.git] / src / vnet / fib / fib_api.c
index 5aa5c4e..d626ae2 100644 (file)
@@ -21,6 +21,7 @@
 #include <vnet/mfib/mfib_table.h>
 #include <vnet/bier/bier_disp_table.h>
 #include <vpp/api/types.h>
+#include <vnet/classify/vnet_classify.h>
 
 #include <vnet/vnet_msg_enum.h>
 
@@ -75,9 +76,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 +111,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 +187,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)
     {
@@ -212,7 +215,7 @@ fib_api_path_decode (vl_api_fib_path_t *in,
         break;
     case FIB_API_PATH_TYPE_CLASSIFY:
         out->frp_flags |= FIB_ROUTE_PATH_CLASSIFY;
-        
+
         if (pool_is_free_index (cm->tables, ntohl (in->nh.classify_table_index)))
         {
             return VNET_API_ERROR_NO_SUCH_TABLE;
@@ -415,6 +418,10 @@ fib_api_path_encode (const fib_route_path_t * rpath,
         out->type = FIB_API_PATH_TYPE_BIER_IMP;
         out->nh.obj_id = rpath->frp_bier_imp;
     }
+    else if (rpath->frp_flags & FIB_ROUTE_PATH_INTF_RX)
+    {
+        out->type = FIB_API_PATH_TYPE_INTERFACE_RX;
+    }
     else
     {
         out->type = FIB_API_PATH_TYPE_NORMAL;
@@ -449,7 +456,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 +464,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*
@@ -520,34 +537,35 @@ format_vl_api_fib_path (u8 * s, va_list * args)
     return (s);
 }
 
-fib_protocol_t
-fib_proto_from_api_address_family (int af)
+int
+fib_proto_from_api_address_family (vl_api_address_family_t af, fib_protocol_t * out)
 {
-    switch (clib_net_to_host_u32 (af))
+    switch (af)
     {
     case ADDRESS_IP4:
-        return (FIB_PROTOCOL_IP4);
+        *out = (FIB_PROTOCOL_IP4);
+        return (0);
     case ADDRESS_IP6:
-        return (FIB_PROTOCOL_IP6);
+        *out = (FIB_PROTOCOL_IP6);
+        return (0);
     }
 
-    ASSERT(0);
-    return (FIB_PROTOCOL_IP4);
+    return (VNET_API_ERROR_INVALID_ADDRESS_FAMILY);
 }
 
-int
+vl_api_address_family_t
 fib_proto_to_api_address_family (fib_protocol_t fproto)
 {
     switch (fproto)
     {
     case FIB_PROTOCOL_IP4:
-        return (clib_net_to_host_u32 (ADDRESS_IP4));
+        return (ADDRESS_IP4);
     case FIB_PROTOCOL_IP6:
-        return (clib_net_to_host_u32 (ADDRESS_IP6));
+        return (ADDRESS_IP6);
     default:
         break;
     }
 
     ASSERT(0);
-    return (clib_net_to_host_u32 (ADDRESS_IP4));
+    return (ADDRESS_IP4);
 }