api: Remove the inlines file and replace with library functions
[vpp.git] / src / plugins / nat / nat_api.c
index fce557f..1dad4e4 100644 (file)
@@ -201,16 +201,20 @@ send_nat_worker_details (u32 worker_index, vl_api_registration_t * reg,
   snat_main_t *sm = &snat_main;
   vlib_worker_thread_t *w =
     vlib_worker_threads + worker_index + sm->first_worker_index;
+  u32 len = vec_len (w->name);
 
-  rmp = vl_msg_api_alloc (sizeof (*rmp) + ARRAY_LEN (w->name) - 1);
-  clib_memset (rmp, 0, sizeof (*rmp) + ARRAY_LEN (w->name) - 1);
+  if (len)
+    --len;
+
+  rmp = vl_msg_api_alloc (sizeof (*rmp) + len);
+  clib_memset (rmp, 0, sizeof (*rmp) + len);
   rmp->_vl_msg_id = ntohs (VL_API_NAT_WORKER_DETAILS + sm->msg_id_base);
   rmp->context = context;
   rmp->worker_index = htonl (worker_index);
   rmp->lcore_id = htonl (w->cpu_id);
 
-  vl_api_to_api_string (ARRAY_LEN (w->name) - 1, (char *) w->name,
-                       &rmp->name);
+  if (len)
+    vl_api_to_api_string (len, (char *) w->name, &rmp->name);
 
   vl_api_send_msg (reg, (u8 *) rmp);
 }
@@ -1186,6 +1190,14 @@ static void
       goto send_reply;
     }
 
+  len = vl_api_string_len (&mp->tag);
+
+  if (len > 64)
+    {
+      rv = VNET_API_ERROR_INVALID_VALUE;
+      goto send_reply;
+    }
+
   memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
   memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
 
@@ -1204,9 +1216,8 @@ static void
   else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT)
     twice_nat = TWICE_NAT_SELF;
 
-  len = vl_api_string_len (&mp->tag);
-
   tag = vec_new (u8, len);
+
   memcpy (tag, mp->tag.buf, len);
   vec_terminate_c_string (tag);