Punt: socket register for exception dispatched/punted packets based on reason
[vpp.git] / src / vnet / ip / ip_types_api.c
index 11b5276..d84c1ff 100644 (file)
@@ -13,6 +13,7 @@
  * limitations under the License.
  */
 
+#include <vlibapi/api_types.h>
 #include <vnet/ip/ip_types_api.h>
 
 #define vl_typedefs            /* define message structures */
 #include <vnet/vnet_all_api_h.h>
 #undef vl_printfun
 
+int
+ip_address_family_decode (int _af, ip_address_family_t * out)
+{
+  vl_api_address_family_t af = clib_host_to_net_u32 (_af);
+
+  switch (af)
+    {
+    case ADDRESS_IP4:
+      *out = AF_IP4;
+      return (0);
+    case ADDRESS_IP6:
+      *out = AF_IP6;
+      return (0);
+    }
+  return (-1);
+}
+
+int
+ip_address_family_encode (ip_address_family_t af)
+{
+  switch (af)
+    {
+    case AF_IP4:
+      return (clib_host_to_net_u32 (ADDRESS_IP4));
+    case AF_IP6:
+      return (clib_host_to_net_u32 (ADDRESS_IP6));
+    }
+
+  ASSERT (0);
+  return (clib_host_to_net_u32 (ADDRESS_IP4));
+}
+
+int
+ip_proto_decode (int _ipp, ip_protocol_t * out)
+{
+  vl_api_ip_proto_t ipp = clib_host_to_net_u32 (_ipp);
+
+  switch (ipp)
+    {
+    case IP_API_PROTO_TCP:
+      *out = IP_PROTOCOL_TCP;
+      return (0);
+    case IP_API_PROTO_UDP:
+      *out = IP_PROTOCOL_UDP;
+      return (0);
+    }
+  return (-1);
+}
+
+int
+ip_proto_encode (ip_protocol_t ipp)
+{
+  switch (ipp)
+    {
+    case IP_PROTOCOL_UDP:
+      return (clib_host_to_net_u32 (IP_API_PROTO_UDP));
+    case IP_PROTOCOL_TCP:
+      return (clib_host_to_net_u32 (IP_API_PROTO_TCP));
+    default:
+      break;
+    }
+
+  ASSERT (0);
+  return (clib_host_to_net_u32 (IP_API_PROTO_TCP));
+}
+
+void
+ip6_address_encode (const ip6_address_t * in, vl_api_ip6_address_t out)
+{
+  clib_memcpy (out, in, sizeof (*in));
+}
+
+void
+ip6_address_decode (const vl_api_ip6_address_t in, ip6_address_t * out)
+{
+  clib_memcpy (out, in, sizeof (*out));
+}
+
+void
+ip4_address_encode (const ip4_address_t * in, vl_api_ip4_address_t out)
+{
+  clib_memcpy (out, in, sizeof (*in));
+}
+
+void
+ip4_address_decode (const vl_api_ip4_address_t in, ip4_address_t * out)
+{
+  clib_memcpy (out, in, sizeof (*out));
+}
+
 static ip46_type_t
 ip_address_union_decode (const vl_api_address_union_t * in,
                         vl_api_address_family_t af, ip46_address_t * out)
@@ -67,9 +158,9 @@ ip_address_union_encode (const ip46_address_t * in,
                         vl_api_address_union_t * out)
 {
   if (ADDRESS_IP6 == clib_net_to_host_u32 (af))
-    memcpy (out->ip6.address, &in->ip6, sizeof (out->ip6));
+    ip6_address_encode (&in->ip6, out->ip6);
   else
-    memcpy (out->ip4.address, &in->ip4, sizeof (out->ip4));
+    ip4_address_encode (&in->ip4, out->ip4);
 }
 
 void
@@ -107,6 +198,7 @@ ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
       break;
     }
   out->fp_len = in->address_length;
+  out->___fp___pad = 0;
   ip_address_decode (&in->address, &out->fp_addr);
 }