vat: add ip api types parser definitions 43/25443/5
authorJakub Grajciar <jgrajcia@cisco.com>
Wed, 26 Feb 2020 10:01:43 +0000 (11:01 +0100)
committerOle Trøan <otroan@employees.org>
Wed, 26 Feb 2020 12:45:11 +0000 (12:45 +0000)
build vat with src/vnet/ip/ip_types_api.c

Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: Iab0f18bf7a89cf9512beab0629bc3a349edec383
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
src/vat/CMakeLists.txt
src/vat/api_format.c
src/vat/ip_types_api.c [new symlink]
src/vat/protocols.def [new symlink]
src/vnet/ip/ip_types_api.c

index d512d9c..84a42f3 100644 (file)
@@ -29,6 +29,8 @@ add_vpp_executable(vpp_api_test ENABLE_EXPORTS
   plugin.c
   json_format.c
   types.c
+  ip_types_api.c
+  protocols.def
 
   DEPENDS api_headers
 
@@ -65,4 +67,3 @@ add_vpp_executable(vpp_restart
   SOURCES restart.c
   LINK_LIBRARIES svm svmdb vppinfra Threads::Threads rt
 )
-
index 2cb459b..5721185 100644 (file)
@@ -264,6 +264,26 @@ unformat_ethernet_type_host_byte_order (unformat_input_t * input,
   return 0;
 }
 
+/* Parse an IP46 address. */
+uword
+unformat_ip46_address (unformat_input_t * input, va_list * args)
+{
+  ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
+  ip46_type_t type = va_arg (*args, ip46_type_t);
+  if ((type != IP46_TYPE_IP6) &&
+      unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
+    {
+      ip46_address_mask_ip4 (ip46);
+      return 1;
+    }
+  else if ((type != IP46_TYPE_IP4) &&
+          unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
+    {
+      return 1;
+    }
+  return 0;
+}
+
 /* Parse an IP6 address. */
 uword
 unformat_ip6_address (unformat_input_t * input, va_list * args)
@@ -759,6 +779,16 @@ set_ip4_address (vl_api_address_t * a, u32 v)
     }
 }
 
+void
+ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
+{
+  if (is_ip4)
+    dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
+  else
+    clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
+                     sizeof (ip6_address_t));
+}
+
 static void
 increment_mac_address (u8 * mac)
 {
diff --git a/src/vat/ip_types_api.c b/src/vat/ip_types_api.c
new file mode 120000 (symlink)
index 0000000..9a9dfb8
--- /dev/null
@@ -0,0 +1 @@
+../vnet/ip/ip_types_api.c
\ No newline at end of file
diff --git a/src/vat/protocols.def b/src/vat/protocols.def
new file mode 120000 (symlink)
index 0000000..dbd32f5
--- /dev/null
@@ -0,0 +1 @@
+../vnet/ip/protocols.def
\ No newline at end of file
index 2e92e72..d201d38 100644 (file)
@@ -253,8 +253,24 @@ 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