Fix length in LCAF header
[vpp.git] / vnet / vnet / lisp-cp / lisp_types.c
index 1f527d6..5ab4a5e 100644 (file)
@@ -269,6 +269,31 @@ unformat_fid_address (unformat_input_t * i, va_list * args)
   return 1;
 }
 
+uword
+unformat_hmac_key_id (unformat_input_t * input, va_list * args)
+{
+  u32 *key_id = va_arg (*args, u32 *);
+  u8 *s = 0;
+
+  if (unformat (input, "%s", &s))
+    {
+      if (!strcmp ((char *) s, "sha1"))
+       key_id[0] = HMAC_SHA_1_96;
+      else if (!strcmp ((char *) s, "sha256"))
+       key_id[0] = HMAC_SHA_256_128;
+      else
+       {
+         clib_warning ("invalid key_id: '%s'", s);
+         key_id[0] = HMAC_NO_KEY;
+       }
+    }
+  else
+    return 0;
+
+  vec_free (s);
+  return 1;
+}
+
 uword
 unformat_gid_address (unformat_input_t * input, va_list * args)
 {
@@ -333,6 +358,24 @@ unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
   return 1;
 }
 
+u8 *
+format_hmac_key_id (u8 * s, va_list * args)
+{
+  lisp_key_type_t key_id = va_arg (*args, lisp_key_type_t);
+
+  switch (key_id)
+    {
+    case HMAC_SHA_1_96:
+      return format (0, "sha1");
+    case HMAC_SHA_256_128:
+      return format (0, "sha256");
+    default:
+      return 0;
+    }
+
+  return 0;
+}
+
 u8 *
 format_negative_mapping_action (u8 * s, va_list * args)
 {
@@ -678,6 +721,14 @@ gid_address_free (gid_address_t * a)
   (*lcaf_free_fcts[lcaf_type]) (lcaf);
 }
 
+void
+gid_address_from_ip (gid_address_t * g, ip_address_t * ip)
+{
+  memset (g, 0, sizeof (g[0]));
+  ip_address_set (&gid_address_ip (g), ip, ip_addr_version (ip));
+  gid_address_ippref_len (g) = 32;
+}
+
 int
 ip_address_cmp (const ip_address_t * ip1, const ip_address_t * ip2)
 {
@@ -698,7 +749,17 @@ ip_address_cmp (const ip_address_t * ip1, const ip_address_t * ip2)
 void
 ip_address_copy (ip_address_t * dst, const ip_address_t * src)
 {
-  clib_memcpy (dst, src, sizeof (ip_address_t));
+  if (IP4 == ip_addr_version (src))
+    {
+      /* don't copy any garbe from the union */
+      memset (dst, 0, sizeof (*dst));
+      dst->ip.v4 = src->ip.v4;
+      dst->version = IP4;
+    }
+  else
+    {
+      clib_memcpy (dst, src, sizeof (ip_address_t));
+    }
 }
 
 void
@@ -714,6 +775,26 @@ ip_address_set (ip_address_t * dst, const void *src, u8 version)
   ip_addr_version (dst) = version;
 }
 
+void
+ip_address_to_46 (const ip_address_t * addr,
+                 ip46_address_t * a, fib_protocol_t * proto)
+{
+  *proto = (IP4 == ip_addr_version (addr) ?
+           FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
+  switch (*proto)
+    {
+    case FIB_PROTOCOL_IP4:
+      ip46_address_set_ip4 (a, &addr->ip.v4);
+      break;
+    case FIB_PROTOCOL_IP6:
+      a->ip6 = addr->ip.v6;
+      break;
+    default:
+      ASSERT (0);
+      break;
+    }
+}
+
 static void
 ip_prefix_normalize_ip4 (ip4_address_t * ip4, u8 preflen)
 {
@@ -1018,7 +1099,7 @@ sd_write (u8 * p, void *a)
   size += sizeof (u16);
   memset (h, 0, sizeof (h[0]));
   LCAF_TYPE (h) = LCAF_SOURCE_DEST;
-  u16 lcaf_len = 4 + sizeof (lcaf_src_dst_hdr_t)
+  u16 lcaf_len = sizeof (lcaf_src_dst_hdr_t)
     + fid_addr_size_to_write (&sd_src (sd))
     + fid_addr_size_to_write (&sd_dst (sd));
   LCAF_LENGTH (h) = clib_host_to_net_u16 (lcaf_len);