Add missing format_ip6_address() functions to plugin_api.

Specifically, the ACL plugin needed format_ip6_address()
and the ip46 variant as well.

Change-Id: Iec35b8acd4cab4bcbc73053dcca2ee91bd9c72cd
Signed-off-by: Jon Loeliger <jdl@netgate.com>
diff --git a/src/vat/plugin_api.c b/src/vat/plugin_api.c
index 4e1eb89..37c97c9 100644
--- a/src/vat/plugin_api.c
+++ b/src/vat/plugin_api.c
@@ -194,6 +194,82 @@
 }
 
 u8 *
+format_ip6_address (u8 * s, va_list * args)
+{
+  ip6_address_t *a = va_arg (*args, ip6_address_t *);
+  u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
+
+  i_max_n_zero = ARRAY_LEN (a->as_u16);
+  max_n_zeros = 0;
+  i_first_zero = i_max_n_zero;
+  n_zeros = 0;
+  for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
+    {
+      u32 is_zero = a->as_u16[i] == 0;
+      if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
+	{
+	  i_first_zero = i;
+	  n_zeros = 0;
+	}
+      n_zeros += is_zero;
+      if ((!is_zero && n_zeros > max_n_zeros)
+	  || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
+	{
+	  i_max_n_zero = i_first_zero;
+	  max_n_zeros = n_zeros;
+	  i_first_zero = ARRAY_LEN (a->as_u16);
+	  n_zeros = 0;
+	}
+    }
+
+  last_double_colon = 0;
+  for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
+    {
+      if (i == i_max_n_zero && max_n_zeros > 1)
+	{
+	  s = format (s, "::");
+	  i += max_n_zeros - 1;
+	  last_double_colon = 1;
+	}
+      else
+	{
+	  s = format (s, "%s%x",
+		      (last_double_colon || i == 0) ? "" : ":",
+		      clib_net_to_host_u16 (a->as_u16[i]));
+	  last_double_colon = 0;
+	}
+    }
+
+  return s;
+}
+
+/* Format an IP46 address. */
+u8 *
+format_ip46_address (u8 * s, va_list * args)
+{
+  ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
+  ip46_type_t type = va_arg (*args, ip46_type_t);
+  int is_ip4 = 1;
+
+  switch (type)
+    {
+    case IP46_TYPE_ANY:
+      is_ip4 = ip46_address_is_ip4 (ip46);
+      break;
+    case IP46_TYPE_IP4:
+      is_ip4 = 1;
+      break;
+    case IP46_TYPE_IP6:
+      is_ip4 = 0;
+      break;
+    }
+
+  return is_ip4 ?
+    format (s, "%U", format_ip4_address, &ip46->ip4) :
+    format (s, "%U", format_ip6_address, &ip46->ip6);
+}
+
+u8 *
 format_ethernet_address (u8 * s, va_list * args)
 {
   u8 *a = va_arg (*args, u8 *);
diff --git a/src/vat/vat.h b/src/vat/vat.h
index 831bdf5..233a1c4 100644
--- a/src/vat/vat.h
+++ b/src/vat/vat.h
@@ -229,6 +229,8 @@
 					      va_list * args);
 uword unformat_ip6_address (unformat_input_t * input, va_list * args);
 u8 *format_ip4_address (u8 * s, va_list * args);
+u8 *format_ip6_address (u8 * s, va_list * args);
+u8 *format_ip46_address (u8 * s, va_list * args);
 u8 *format_ethernet_address (u8 * s, va_list * args);
 
 #if VPP_API_TEST_BUILTIN