ip: ip_address_t uses ip46_address_t
[vpp.git] / src / vnet / ip / ip_types_api.c
index 0f7f0e5..bcf594c 100644 (file)
@@ -163,6 +163,22 @@ ip_address_decode (const vl_api_address_t * in, ip46_address_t * out)
   return (ip_address_union_decode (&in->un, in->af, out));
 }
 
+void
+ip_address_decode2 (const vl_api_address_t * in, ip_address_t * out)
+{
+  switch (ip_address_union_decode (&in->un, in->af, &out->ip))
+    {
+    case IP46_TYPE_IP4:
+      out->version = AF_IP4;
+      break;
+    case IP46_TYPE_IP6:
+      out->version = AF_IP6;
+      break;
+    default:
+      break;
+    }
+}
+
 static void
 ip_address_union_encode (const ip46_address_t * in,
                         vl_api_address_family_t af,
@@ -196,6 +212,21 @@ ip_address_encode (const ip46_address_t * in,
   ip_address_union_encode (in, out->af, &out->un);
 }
 
+void
+ip_address_encode2 (const ip_address_t * in, vl_api_address_t * out)
+{
+  switch (in->version)
+    {
+    case AF_IP4:
+      out->af = clib_net_to_host_u32 (ADDRESS_IP4);
+      break;
+    case AF_IP6:
+      out->af = clib_net_to_host_u32 (ADDRESS_IP6);
+      break;
+    }
+  ip_address_union_encode (&in->ip, out->af, &out->un);
+}
+
 void
 ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
 {
@@ -213,12 +244,46 @@ ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
   ip_address_decode (&in->address, &out->fp_addr);
 }
 
+int
+ip_prefix_decode2 (const vl_api_prefix_t * in, ip_prefix_t * out)
+{
+  out->len = in->len;
+  ip_address_decode2 (&in->address, &out->addr);
+
+  if (!ip_prefix_validate (out))
+    return (VNET_API_ERROR_IP_PREFIX_INVALID);
+  return (0);
+}
+
 void
 ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out)
 {
   out->len = in->fp_len;
-  ip_address_encode (&in->fp_addr,
-                    fib_proto_to_ip46 (in->fp_proto), &out->address);
+  ip46_type_t ip46_type;
+
+  switch (in->fp_proto)
+    {
+    case FIB_PROTOCOL_IP4:
+      ip46_type = (IP46_TYPE_IP4);
+      break;
+    case FIB_PROTOCOL_IP6:
+      ip46_type = (IP46_TYPE_IP6);
+      break;
+    case FIB_PROTOCOL_MPLS:
+      ip46_type = (IP46_TYPE_ANY);
+      break;
+    default:
+      ip46_type = (IP46_TYPE_ANY);
+    }
+
+  ip_address_encode (&in->fp_addr, ip46_type, &out->address);
+}
+
+void
+ip_prefix_encode2 (const ip_prefix_t * in, vl_api_prefix_t * out)
+{
+  out->len = in->len;
+  ip_address_encode2 (&in->addr, &out->address);
 }
 
 void