VPP-448 Fix LISP APIs using binary data 57/3157/5
authorFilip Tehlar <ftehlar@cisco.com>
Tue, 27 Sep 2016 11:28:01 +0000 (13:28 +0200)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 27 Sep 2016 17:28:13 +0000 (17:28 +0000)
* use zero length array in LISP API to avoid confusion
* add missing LISP data structure definitions in API documentation
* fix wrong memory allocation in VAT

Change-Id: I9b5e656a071fc24cb698c164db953c09b66deeeb
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
vpp-api-test/vat/api_format.c
vpp/vpp-api/vpe.api

index 27c80d9..4b1d41f 100644 (file)
@@ -11870,6 +11870,7 @@ api_lisp_add_del_locator_set (vat_main_t * vam)
   u8 locator_set_name_set = 0;
   ls_locator_t locator, *locators = 0;
   u32 sw_if_index, priority, weight;
+  u32 data_len = 0;
 
   /* Parse args required to build the message */
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
@@ -11918,8 +11919,10 @@ api_lisp_add_del_locator_set (vat_main_t * vam)
     }
   vec_add1 (locator_set_name, 0);
 
+  data_len = sizeof (ls_locator_t) * vec_len (locators);
+
   /* Construct the API message */
-  M (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
+  M2 (LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set, data_len);
 
   mp->is_add = is_add;
   clib_memcpy (mp->locator_set_name, locator_set_name,
@@ -11928,8 +11931,7 @@ api_lisp_add_del_locator_set (vat_main_t * vam)
 
   mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
   if (locators)
-    clib_memcpy (mp->locators, locators,
-                (sizeof (ls_locator_t) * vec_len (locators)));
+    clib_memcpy (mp->locators, locators, data_len);
   vec_free (locators);
 
   /* send it... */
@@ -12667,7 +12669,7 @@ api_lisp_add_del_remote_mapping (vat_main_t * vam)
   lisp_eid_vat_t _eid, *eid = &_eid;
   lisp_eid_vat_t _seid, *seid = &_seid;
   u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
-  u32 action = ~0, p, w;
+  u32 action = ~0, p, w, data_len;
   ip4_address_t rloc4;
   ip6_address_t rloc6;
   rloc_t *rlocs = 0, rloc, *curr_rloc = 0;
@@ -12749,7 +12751,9 @@ api_lisp_add_del_remote_mapping (vat_main_t * vam)
       return -99;
     }
 
-  M (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
+  data_len = vec_len (rlocs) * sizeof (rloc_t);
+
+  M2 (LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping, data_len);
   mp->is_add = is_add;
   mp->vni = htonl (vni);
   mp->action = (u8) action;
@@ -12762,7 +12766,7 @@ api_lisp_add_del_remote_mapping (vat_main_t * vam)
   lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
 
   mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
-  clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
+  clib_memcpy (mp->rlocs, rlocs, data_len);
   vec_free (rlocs);
 
   /* send it... */
index 33793b0..8f28e19 100644 (file)
@@ -2366,7 +2366,14 @@ define vxlan_gpe_tunnel_details
     @param is_add - add address if non-zero, else delete
     @param locator_set_name - locator name
     @param locator_num - number of locators
-    @param locators - Lisp locator data
+    @param locators - LISP locator records
+        Structure of one locator record is as follows:
+
+        define locator_t {
+          u32 sw_if_index;
+          u8 priority;
+          u8 weight;
+        }
 */
 define lisp_add_del_locator_set
 {
@@ -2375,7 +2382,7 @@ define lisp_add_del_locator_set
   u8 is_add;
   u8 locator_set_name[64];
   u32 locator_num;
-  u8 locators[locator_num];
+  u8 locators[0];
 };
 
 /** \brief Reply for locator_set add/del
@@ -2683,7 +2690,15 @@ define show_lisp_map_request_mode_reply
     @param deid - dst EID
     @param seid - src EID, valid only if is_src_dst is enabled
     @param rloc_num - number of remote locators
-    @param rlocs - remote locator data
+    @param rlocs - remote locator records
+        Structure of remote locator:
+
+        define rloc_t {
+          u8 is_ip4;
+          u8 priority;
+          u8 weight;
+          u8 addr[16];
+        }
 */
 define lisp_add_del_remote_mapping
 {
@@ -2700,7 +2715,7 @@ define lisp_add_del_remote_mapping
   u8 seid[16];
   u8 seid_len;
   u32 rloc_num;
-  u8 rlocs[rloc_num];
+  u8 rlocs[0];
 };
 
 /** \brief Reply for lisp_add_del_remote_mapping