hs-test: more debug output in http3 test
[vpp.git] / src / plugins / map / map_api.c
index 418f6a0..1dbff4c 100644 (file)
@@ -40,7 +40,7 @@ vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
   u32 index;
   u8 flags = 0;
 
-  u8 *tag = format (0, "%s", mp->tag);
+  mp->tag[ARRAY_LEN (mp->tag) - 1] = '\0';
   rv =
     map_create_domain ((ip4_address_t *) & mp->ip4_prefix.address,
                       mp->ip4_prefix.len,
@@ -48,14 +48,13 @@ vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
                       mp->ip6_prefix.len,
                       (ip6_address_t *) & mp->ip6_src.address,
                       mp->ip6_src.len, mp->ea_bits_len, mp->psid_offset,
-                      mp->psid_length, &index, ntohs (mp->mtu), flags, tag);
-  vec_free (tag);
-  /* *INDENT-OFF* */
-  REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
+                      mp->psid_length, &index, mp->mtu, flags, mp->tag);
+
+  REPLY_MACRO2_END(VL_API_MAP_ADD_DOMAIN_REPLY,
   ({
-    rmp->index = ntohl(index);
+    rmp->index = index;
   }));
-  /* *INDENT-ON* */
+
 }
 
 static void
@@ -85,38 +84,27 @@ vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
 }
 
 static void
-vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
+send_domain_details (u32 map_domain_index, vl_api_registration_t * rp,
+                    u32 context)
 {
-  vl_api_map_domain_details_t *rmp;
   map_main_t *mm = &map_main;
-  map_domain_t *d;
-  map_domain_extra_t *de;
-  vl_api_registration_t *reg;
-  u32 map_domain_index;
+  vl_api_map_domain_details_t *rmp;
+  map_domain_t *d = pool_elt_at_index (mm->domains, map_domain_index);
 
-  if (pool_elts (mm->domains) == 0)
-    return;
+  /* Make sure every field is initiated (or don't skip the clib_memset()) */
+  map_domain_extra_t *de =
+    vec_elt_at_index (mm->domain_extras, map_domain_index);
+  int tag_len = clib_min (ARRAY_LEN (rmp->tag), vec_len (de->tag) + 1);
 
-  reg = vl_api_client_index_to_registration (mp->client_index);
-  if (!reg)
-    return;
-
-  /* *INDENT-OFF* */
-  pool_foreach(d, mm->domains,
+  REPLY_MACRO_DETAILS4(VL_API_MAP_DOMAIN_DETAILS, rp, context,
   ({
-    map_domain_index = d - mm->domains;
-    de = vec_elt_at_index(mm->domain_extras, map_domain_index);
-    int tag_len = clib_min(ARRAY_LEN(rmp->tag), vec_len(de->tag) + 1);
-
-    /* Make sure every field is initiated (or don't skip the clib_memset()) */
-    rmp = vl_msg_api_alloc (sizeof (*rmp) + tag_len);
-
-    rmp->_vl_msg_id = htons(VL_API_MAP_DOMAIN_DETAILS + mm->msg_id_base);
-    rmp->context = mp->context;
-    rmp->domain_index = htonl(map_domain_index);
-    clib_memcpy(&rmp->ip6_prefix.address, &d->ip6_prefix, sizeof(rmp->ip6_prefix.address));
-    clib_memcpy(&rmp->ip4_prefix.address, &d->ip4_prefix, sizeof(rmp->ip4_prefix.address));
-    clib_memcpy(&rmp->ip6_src.address, &d->ip6_src, sizeof(rmp->ip6_src.address));
+    rmp->domain_index = htonl (map_domain_index);
+    clib_memcpy (&rmp->ip6_prefix.address, &d->ip6_prefix,
+                sizeof (rmp->ip6_prefix.address));
+    clib_memcpy (&rmp->ip4_prefix.address, &d->ip4_prefix,
+                sizeof (rmp->ip4_prefix.address));
+    clib_memcpy (&rmp->ip6_src.address, &d->ip6_src,
+                sizeof (rmp->ip6_src.address));
     rmp->ip6_prefix.len = d->ip6_prefix_len;
     rmp->ip4_prefix.len = d->ip4_prefix_len;
     rmp->ip6_src.len = d->ip6_src_len;
@@ -124,13 +112,44 @@ vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
     rmp->psid_offset = d->psid_offset;
     rmp->psid_length = d->psid_length;
     rmp->flags = d->flags;
-    rmp->mtu = htons(d->mtu);
-    memcpy(rmp->tag, de->tag, tag_len-1);
-    rmp->tag[tag_len-1] = '\0';
+    rmp->mtu = htons (d->mtu);
+    memcpy (rmp->tag, de->tag, tag_len - 1);
+    rmp->tag[tag_len - 1] = '\0';
+  }));
+}
+
+static void
+vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
+{
+  map_main_t *mm = &map_main;
+  int i;
+  vl_api_registration_t *reg;
+
+  if (pool_elts (mm->domains) == 0)
+    return;
 
-    vl_api_send_msg (reg, (u8 *) rmp);
+  reg = vl_api_client_index_to_registration (mp->client_index);
+  if (!reg)
+    return;
+
+  pool_foreach_index (i, mm->domains)
+   {
+    send_domain_details(i, reg, mp->context);
+  }
+}
+
+static void
+vl_api_map_domains_get_t_handler (vl_api_map_domains_get_t * mp)
+{
+  map_main_t *mm = &map_main;
+  vl_api_map_domains_get_reply_t *rmp;
+
+  i32 rv = 0;
+
+  REPLY_AND_DETAILS_MACRO (VL_API_MAP_DOMAINS_GET_REPLY, mm->domains,
+  ({
+    send_domain_details (cursor, rp, mp->context);
   }));
-  /* *INDENT-ON* */
 }
 
 static void
@@ -526,6 +545,7 @@ map_plugin_api_hookup (vlib_main_t * vm)
   map_main_t *mm = &map_main;
 
   mm->msg_id_base = setup_message_id_table ();
+
   return 0;
 }