vppinfra: make _vec_len() read-only

Use of _vec_len() to set vector length breaks address sanitizer.
Users should use vec_set_len(), vec_inc_len(), vec_dec_len () instead.

Type: improvement
Change-Id: I441ae948771eb21c23a61f3ff9163bdad74a2cb8
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/examples/vlib/main_stub.c b/src/examples/vlib/main_stub.c
index 3735055..ef6475c 100644
--- a/src/examples/vlib/main_stub.c
+++ b/src/examples/vlib/main_stub.c
@@ -181,7 +181,7 @@
 	  vlib_cli_output (vm, "%U %v: completion #%d type %d data 0x%wx",
 			   format_time_interval, "h:m:s:u",
 			   vlib_time_now (vm), node->name, i, type, data[0]);
-	  _vec_len (data) = 0;
+	  vec_set_len (data, 0);
 	}
 
       vec_free (data);
diff --git a/src/examples/vlib/mc_test.c b/src/examples/vlib/mc_test.c
index 464d07c..6d63be3 100644
--- a/src/examples/vlib/mc_test.c
+++ b/src/examples/vlib/mc_test.c
@@ -241,7 +241,7 @@
 	}
 
       if (event_data)
-	_vec_len (event_data) = 0;
+	vec_set_len (event_data, 0);
     }
 }
 
diff --git a/src/plugins/acl/acl.c b/src/plugins/acl/acl.c
index 01a1e87..a7b8104 100644
--- a/src/plugins/acl/acl.c
+++ b/src/plugins/acl/acl.c
@@ -3736,7 +3736,7 @@
 	vec_validate (pw->expired,
 		      ACL_N_TIMEOUTS *
 		      am->fa_max_deleted_sessions_per_interval);
-	_vec_len (pw->expired) = 0;
+	vec_set_len (pw->expired, 0);
 	vec_validate_init_empty (pw->fa_conn_list_head, ACL_N_TIMEOUTS - 1,
 				 FA_SESSION_BOGUS_INDEX);
 	vec_validate_init_empty (pw->fa_conn_list_tail, ACL_N_TIMEOUTS - 1,
diff --git a/src/plugins/acl/acl_test.c b/src/plugins/acl/acl_test.c
index 44abf30..7514a8e 100644
--- a/src/plugins/acl/acl_test.c
+++ b/src/plugins/acl/acl_test.c
@@ -493,10 +493,10 @@
         if (vec_len(tag) >= sizeof(mp->tag))
           {
             tag[sizeof(mp->tag)-1] = 0;
-            _vec_len(tag) = sizeof(mp->tag);
-          }
-        clib_memcpy(mp->tag, tag, vec_len(tag));
-        vec_free(tag);
+	    vec_set_len (tag, sizeof (mp->tag));
+	  }
+	clib_memcpy (mp->tag, tag, vec_len (tag));
+	vec_free (tag);
       }
     mp->acl_index = ntohl(acl_index);
     mp->count = htonl(n_rules);
@@ -1333,10 +1333,10 @@
         if (vec_len(tag) >= sizeof(mp->tag))
           {
             tag[sizeof(mp->tag)-1] = 0;
-            _vec_len(tag) = sizeof(mp->tag);
-          }
-        clib_memcpy(mp->tag, tag, vec_len(tag));
-        vec_free(tag);
+	    vec_set_len (tag, sizeof (mp->tag));
+	  }
+	clib_memcpy (mp->tag, tag, vec_len (tag));
+	vec_free (tag);
       }
 
     mp->count = htonl(n_rules);
@@ -1475,10 +1475,10 @@
         if (vec_len(tag) >= sizeof(mp->tag))
           {
             tag[sizeof(mp->tag)-1] = 0;
-            _vec_len(tag) = sizeof(mp->tag);
-          }
-        clib_memcpy(mp->tag, tag, vec_len(tag));
-        vec_free(tag);
+	    vec_set_len (tag, sizeof (mp->tag));
+	  }
+	clib_memcpy (mp->tag, tag, vec_len (tag));
+	vec_free (tag);
       }
 
     mp->acl_index = ntohl(acl_index);
diff --git a/src/plugins/acl/hash_lookup.c b/src/plugins/acl/hash_lookup.c
index 85b54b3..c137b15 100644
--- a/src/plugins/acl/hash_lookup.c
+++ b/src/plugins/acl/hash_lookup.c
@@ -682,7 +682,7 @@
   if (vec_len(ha->rules) > 0) {
     int old_vec_len = vec_len(*applied_hash_aces);
     vec_validate((*applied_hash_aces), old_vec_len + vec_len(ha->rules) - 1);
-    _vec_len((*applied_hash_aces)) = old_vec_len;
+    vec_set_len ((*applied_hash_aces), old_vec_len);
   }
 
   /* add the rules from the ACL to the hash table for lookup and append to the vector*/
@@ -903,7 +903,7 @@
     move_applied_ace_hash_entry(am, lc_index, applied_hash_aces, tail_offset + i, base_offset + i);
   }
   /* trim the end of the vector */
-  _vec_len((*applied_hash_aces)) -= vec_len(ha->rules);
+  vec_dec_len ((*applied_hash_aces), vec_len (ha->rules));
 
   remake_hash_applied_mask_info_vec(am, applied_hash_aces, lc_index);
 
diff --git a/src/plugins/acl/sess_mgmt_node.c b/src/plugins/acl/sess_mgmt_node.c
index f9a3064..d0ec593 100644
--- a/src/plugins/acl/sess_mgmt_node.c
+++ b/src/plugins/acl/sess_mgmt_node.c
@@ -188,8 +188,7 @@
       }
   }
   if (pw->wip_session_change_requests)
-    _vec_len (pw->wip_session_change_requests) = 0;
-
+    vec_set_len (pw->wip_session_change_requests, 0);
 
   {
     u8 tt = 0;
@@ -309,7 +308,7 @@
   total_expired = vec_len (pw->expired);
   /* zero out the vector which we have acted on */
   if (pw->expired)
-    _vec_len (pw->expired) = 0;
+    vec_set_len (pw->expired, 0);
   /* if we were advancing and reached the end
    * (no more sessions to recycle), reset the fast-forward timestamp */
 
@@ -788,7 +787,7 @@
       send_interrupts_to_workers (vm, am);
 
       if (event_data)
-	_vec_len (event_data) = 0;
+	vec_set_len (event_data, 0);
 
       /*
        * If the interrupts were not processed yet, ensure we wait a bit,
diff --git a/src/plugins/builtinurl/builtins.c b/src/plugins/builtinurl/builtins.c
index 14b68ce..24323cd 100644
--- a/src/plugins/builtinurl/builtins.c
+++ b/src/plugins/builtinurl/builtins.c
@@ -54,7 +54,7 @@
 	   * like a c-string.
 	   */
 	  *cp = 0;
-	  _vec_len (s) = cp - s;
+	  vec_set_len (s, cp - s);
 	  break;
 	}
       cp++;
diff --git a/src/plugins/cdp/cdp_input.c b/src/plugins/cdp/cdp_input.c
index 76a3d70..c6198d8 100644
--- a/src/plugins/cdp/cdp_input.c
+++ b/src/plugins/cdp/cdp_input.c
@@ -167,25 +167,24 @@
 _(platform,DEBUG_TLV_DUMP)                      \
 _(port_id,DEBUG_TLV_DUMP)
 
-#define _(z,dbg)                                                        \
-static                                                                  \
-cdp_error_t process_##z##_tlv (cdp_main_t *cm, cdp_neighbor_t *n,       \
-                                  cdp_tlv_t *t)                         \
-{                                                                       \
-    int i;                                                              \
-    if (dbg)                                                            \
-       fformat(stdout, "%U\n", format_text_tlv, t);                     \
-                                                                        \
-    if (n->z)                                                           \
-        _vec_len(n->z) = 0;                                             \
-                                                                        \
-    for (i = 0; i < (t->l - sizeof (*t)); i++)                          \
-        vec_add1(n->z, t->v[i]);                                        \
-                                                                        \
-    vec_add1(n->z, 0);                                                  \
-                                                                        \
-    return CDP_ERROR_NONE;                                              \
-}
+#define _(z, dbg)                                                             \
+  static cdp_error_t process_##z##_tlv (cdp_main_t *cm, cdp_neighbor_t *n,    \
+					cdp_tlv_t *t)                         \
+  {                                                                           \
+    int i;                                                                    \
+    if (dbg)                                                                  \
+      fformat (stdout, "%U\n", format_text_tlv, t);                           \
+                                                                              \
+    if (n->z)                                                                 \
+      vec_set_len (n->z, 0);                                                  \
+                                                                              \
+    for (i = 0; i < (t->l - sizeof (*t)); i++)                                \
+      vec_add1 (n->z, t->v[i]);                                               \
+                                                                              \
+    vec_add1 (n->z, 0);                                                       \
+                                                                              \
+    return CDP_ERROR_NONE;                                                    \
+  }
 
 foreach_text_to_struct_tlv
 #undef _
@@ -354,7 +353,7 @@
    */
 
   if (n->last_rx_pkt)
-    _vec_len (n->last_rx_pkt) = 0;
+    vec_set_len (n->last_rx_pkt, 0);
 
   /* cdp disabled on this interface, we're done */
   if (n->disabled)
diff --git a/src/plugins/cdp/cdp_periodic.c b/src/plugins/cdp/cdp_periodic.c
index c73d86b..295cf8f 100644
--- a/src/plugins/cdp/cdp_periodic.c
+++ b/src/plugins/cdp/cdp_periodic.c
@@ -394,9 +394,9 @@
       delete_neighbor (cm, n, 1);
     }
   if (delete_list)
-    _vec_len (delete_list) = 0;
+    vec_set_len (delete_list, 0);
   if (n_list)
-    _vec_len (n_list) = 0;
+    vec_set_len (n_list, 0);
 }
 
 static clib_error_t *
diff --git a/src/plugins/dhcp/dhcp6_pd_client_cp.c b/src/plugins/dhcp/dhcp6_pd_client_cp.c
index f6d30fa..b1784bd 100644
--- a/src/plugins/dhcp/dhcp6_pd_client_cp.c
+++ b/src/plugins/dhcp/dhcp6_pd_client_cp.c
@@ -992,7 +992,7 @@
 	  return VNET_API_ERROR_DUPLICATE_IF_ADDRESS;
 	cp_ip6_address_add_del_now (address_info, 0 /* del */ );
 	*address_info = apm->addresses[n - 1];
-	_vec_len (apm->addresses) = n - 1;
+	vec_set_len (apm->addresses, n - 1);
 	return 0;
       }
   }
diff --git a/src/plugins/dns/dns.c b/src/plugins/dns/dns.c
index 76ce3da..ac6d122 100644
--- a/src/plugins/dns/dns.c
+++ b/src/plugins/dns/dns.c
@@ -829,7 +829,7 @@
   clib_memset (ep, 0, sizeof (*ep));
 
   ep->name = format (0, "%s%c", name, 0);
-  _vec_len (ep->name) = vec_len (ep->name) - 1;
+  vec_set_len (ep->name, vec_len (ep->name) - 1);
 
   hash_set_mem (dm->cache_entry_by_name, ep->name, ep - dm->entries);
 
@@ -988,7 +988,7 @@
   cname = vnet_dns_labels_to_name (rr->rdata, reply, &pos2);
   /* Save the cname */
   vec_add1 (cname, 0);
-  _vec_len (cname) -= 1;
+  vec_dec_len (cname, 1);
   ep = pool_elt_at_index (dm->entries, ep_index);
   ep->cname = cname;
   ep->flags |= (DNS_CACHE_ENTRY_FLAG_CNAME | DNS_CACHE_ENTRY_FLAG_VALID);
@@ -1007,7 +1007,7 @@
   clib_memset (next_ep, 0, sizeof (*next_ep));
   next_ep->name = vec_dup (cname);
   vec_add1 (next_ep->name, 0);
-  _vec_len (next_ep->name) -= 1;
+  vec_dec_len (next_ep->name, 1);
 
   hash_set_mem (dm->cache_entry_by_name, next_ep->name,
 		next_ep - dm->entries);
@@ -2611,7 +2611,7 @@
   if (unformat (input, "%v", &name))
     {
       vec_add1 (name, 0);
-      _vec_len (name) -= 1;
+      vec_dec_len (name, 1);
     }
   else
     return clib_error_return (0, "no name provided");
diff --git a/src/plugins/dns/request_node.c b/src/plugins/dns/request_node.c
index 72a76d1..9179bf8 100644
--- a/src/plugins/dns/request_node.c
+++ b/src/plugins/dns/request_node.c
@@ -214,7 +214,7 @@
 	   */
 	  name0 = vnet_dns_labels_to_name (label0, (u8 *) d0, (u8 **) & q0);
 	  vec_add1 (name0, 0);
-	  _vec_len (name0) -= 1;
+	  vec_dec_len (name0, 1);
 
 	  t0->request_type = DNS_PEER_PENDING_NAME_TO_IP;
 
diff --git a/src/plugins/dpdk/device/cli.c b/src/plugins/dpdk/device/cli.c
index f49a94f..af522a5 100644
--- a/src/plugins/dpdk/device/cli.c
+++ b/src/plugins/dpdk/device/cli.c
@@ -142,7 +142,7 @@
 	  err = clib_error_return_unix (0, "read");
 	  goto error;
 	}
-      _vec_len (s) = len + (n < 0 ? 0 : n);
+      vec_set_len (s, len + (n < 0 ? 0 : n));
     }
 
   vlib_cli_output (vm, "%v", s);
@@ -198,7 +198,7 @@
 
       first = vec_len (allocated_buffers) - n_free;
       vlib_buffer_free (vm, allocated_buffers + first, n_free);
-      _vec_len (allocated_buffers) = first;
+      vec_set_len (allocated_buffers, first);
     }
   if (n_alloc)
     {
@@ -208,7 +208,7 @@
 
       actual_alloc = vlib_buffer_alloc (vm, allocated_buffers + first,
 					n_alloc);
-      _vec_len (allocated_buffers) = first + actual_alloc;
+      vec_set_len (allocated_buffers, first + actual_alloc);
 
       if (actual_alloc < n_alloc)
 	vlib_cli_output (vm, "WARNING: only allocated %d buffers",
diff --git a/src/plugins/dpdk/device/dpdk_priv.h b/src/plugins/dpdk/device/dpdk_priv.h
index 4e4438a..ed30cd8 100644
--- a/src/plugins/dpdk/device/dpdk_priv.h
+++ b/src/plugins/dpdk/device/dpdk_priv.h
@@ -63,11 +63,11 @@
   ret = rte_eth_xstats_get (xd->port_id, xd->xstats, len);
   if (ret < 0 || ret > len)
     {
-      _vec_len (xd->xstats) = 0;
+      vec_set_len (xd->xstats, 0);
       return;
     }
 
-  _vec_len (xd->xstats) = len;
+  vec_set_len (xd->xstats, len);
 }
 
 #define DPDK_UPDATE_COUNTER(vnm, tidx, xd, stat, cnt)                         \
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index a94f83b..9d68775 100644
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -921,7 +921,7 @@
       n = read (uf->file_descriptor, s + len, n_try);
       if (n < 0 && errno != EAGAIN)
 	return clib_error_return_unix (0, "read");
-      _vec_len (s) = len + (n < 0 ? 0 : n);
+      vec_set_len (s, len + (n < 0 ? 0 : n));
     }
 
   unformat_init_vector (&input, s);
@@ -1254,7 +1254,7 @@
 
   /* NULL terminate the "argv" vector, in case of stupidity */
   vec_add1 (conf->eal_init_args, 0);
-  _vec_len (conf->eal_init_args) -= 1;
+  vec_dec_len (conf->eal_init_args, 1);
 
   /* Set up DPDK eal and packet mbuf pool early. */
 
diff --git a/src/plugins/gtpu/gtpu.c b/src/plugins/gtpu/gtpu.c
index db59670..33af26d 100644
--- a/src/plugins/gtpu/gtpu.c
+++ b/src/plugins/gtpu/gtpu.c
@@ -292,7 +292,7 @@
 
   t->rewrite = r.rw;
   /* Now only support 8-byte gtpu header. TBD */
-  _vec_len (t->rewrite) = sizeof (ip4_gtpu_header_t) - 4;
+  vec_set_len (t->rewrite, sizeof (ip4_gtpu_header_t) - 4);
 
   return;
 }
@@ -419,7 +419,7 @@
 	  vnet_interface_main_t *im = &vnm->interface_main;
 	  hw_if_index = gtm->free_gtpu_tunnel_hw_if_indices
 	    [vec_len (gtm->free_gtpu_tunnel_hw_if_indices) - 1];
-	  _vec_len (gtm->free_gtpu_tunnel_hw_if_indices) -= 1;
+	  vec_dec_len (gtm->free_gtpu_tunnel_hw_if_indices, 1);
 
 	  hi = vnet_get_hw_interface (vnm, hw_if_index);
 	  hi->dev_instance = t - gtm->tunnels;
diff --git a/src/plugins/hs_apps/echo_client.c b/src/plugins/hs_apps/echo_client.c
index 1d33a85..b7bc85b 100644
--- a/src/plugins/hs_apps/echo_client.c
+++ b/src/plugins/hs_apps/echo_client.c
@@ -248,7 +248,7 @@
 			conn_indices + vec_len (conn_indices) -
 			  nconns_this_batch,
 			nconns_this_batch * sizeof (u32));
-      _vec_len (conn_indices) -= nconns_this_batch;
+      vec_dec_len (conn_indices, nconns_this_batch);
     }
 
   /*
diff --git a/src/plugins/hs_apps/http_cli.c b/src/plugins/hs_apps/http_cli.c
index fec1427..d742121 100644
--- a/src/plugins/hs_apps/http_cli.c
+++ b/src/plugins/hs_apps/http_cli.c
@@ -221,7 +221,7 @@
       else if (request[i] == ' ')
 	{
 	  /* vlib_cli_input is vector-based, no need for a NULL */
-	  _vec_len (request) = i;
+	  vec_set_len (request, i);
 	  break;
 	}
       i++;
@@ -269,7 +269,7 @@
     {
       n = vlib_get_node (vm, hcm->free_http_cli_process_node_indices[l - 1]);
       vlib_node_set_state (vm, n->index, VLIB_NODE_STATE_POLLING);
-      _vec_len (hcm->free_http_cli_process_node_indices) = l - 1;
+      vec_set_len (hcm->free_http_cli_process_node_indices, l - 1);
     }
   else
     {
diff --git a/src/plugins/http/http.c b/src/plugins/http/http.c
index 828e57d..f40715f 100644
--- a/src/plugins/http/http.c
+++ b/src/plugins/http/http.c
@@ -329,7 +329,7 @@
   if (svm_fifo_is_empty (ts->rx_fifo))
     svm_fifo_unset_event (ts->rx_fifo);
 
-  _vec_len (hc->rx_buf) = cursize + n_read;
+  vec_set_len (hc->rx_buf, cursize + n_read);
   return 0;
 }
 
diff --git a/src/plugins/http_static/builtinurl/json_urls.c b/src/plugins/http_static/builtinurl/json_urls.c
index 0d83d39..808893a 100644
--- a/src/plugins/http_static/builtinurl/json_urls.c
+++ b/src/plugins/http_static/builtinurl/json_urls.c
@@ -51,7 +51,7 @@
 	   * like a c-string.
 	   */
 	  *cp = 0;
-	  _vec_len (s) = cp - s;
+	  vec_set_len (s, cp - s);
 	  break;
 	}
       cp++;
diff --git a/src/plugins/http_static/static_server.c b/src/plugins/http_static/static_server.c
index 4eafb1f..b92af89 100644
--- a/src/plugins/http_static/static_server.c
+++ b/src/plugins/http_static/static_server.c
@@ -224,7 +224,7 @@
   u32 plen;
 
   /* Remove the trailing space */
-  _vec_len (path) -= 1;
+  vec_dec_len (path, 1);
   plen = vec_len (path);
 
   /* Append "index.html" */
diff --git a/src/plugins/ikev2/ikev2_crypto.c b/src/plugins/ikev2/ikev2_crypto.c
index a9ab1bc..3d4ad0a 100644
--- a/src/plugins/ikev2/ikev2_crypto.c
+++ b/src/plugins/ikev2/ikev2_crypto.c
@@ -488,7 +488,7 @@
     {
       vec_insert (to, pad, 0);
       clib_memset (to, 0, pad);
-      _vec_len (to) -= pad;
+      vec_dec_len (to, pad);
     }
   return tolen;
 }
@@ -553,7 +553,7 @@
 	    {
 	      vec_insert (sa->dh_shared_key, pad, 0);
 	      clib_memset (sa->dh_shared_key, 0, pad);
-	      _vec_len (sa->dh_shared_key) -= pad;
+	      vec_dec_len (sa->dh_shared_key, pad);
 	    }
 	  BN_clear_free (ex);
 	}
@@ -679,7 +679,7 @@
 	{
 	  vec_insert (sa->dh_shared_key, pad, 0);
 	  clib_memset (sa->dh_shared_key, 0, pad);
-	  _vec_len (sa->dh_shared_key) -= pad;
+	  vec_dec_len (sa->dh_shared_key, pad);
 	}
       BN_clear_free (ex);
       DH_free (dh);
diff --git a/src/plugins/ioam/export-common/ioam_export.h b/src/plugins/ioam/export-common/ioam_export.h
index f242ad7..1b764f6 100644
--- a/src/plugins/ioam/export-common/ioam_export.h
+++ b/src/plugins/ioam/export-common/ioam_export.h
@@ -287,7 +287,7 @@
 				     (DEFAULT_EXPORT_RECORDS *
 				      DEFAULT_EXPORT_SIZE));
   ip->checksum = ip4_header_checksum (ip);
-  _vec_len (rewrite) = sizeof (ip4_ipfix_data_packet_t);
+  vec_set_len (rewrite, sizeof (ip4_ipfix_data_packet_t));
   em->record_header = rewrite;
   return (1);
 }
diff --git a/src/plugins/l2tp/l2tp.c b/src/plugins/l2tp/l2tp.c
index 08fa6d1..a975fa7 100644
--- a/src/plugins/l2tp/l2tp.c
+++ b/src/plugins/l2tp/l2tp.c
@@ -377,7 +377,7 @@
     {
       hw_if_index = lm->free_l2tpv3_tunnel_hw_if_indices
 	[vec_len (lm->free_l2tpv3_tunnel_hw_if_indices) - 1];
-      _vec_len (lm->free_l2tpv3_tunnel_hw_if_indices) -= 1;
+      vec_dec_len (lm->free_l2tpv3_tunnel_hw_if_indices, 1);
 
       hi = vnet_get_hw_interface (vnm, hw_if_index);
       hi->dev_instance = s - lm->sessions;
diff --git a/src/plugins/lacp/input.c b/src/plugins/lacp/input.c
index 3997af8..3145028 100644
--- a/src/plugins/lacp/input.c
+++ b/src/plugins/lacp/input.c
@@ -155,7 +155,7 @@
     {
       mif->last_marker_pdu_recd_time = vlib_time_now (vm);
       if (mif->last_marker_pkt)
-	_vec_len (mif->last_marker_pkt) = 0;
+	vec_set_len (mif->last_marker_pkt, 0);
       vec_validate (mif->last_marker_pkt,
 		    vlib_buffer_length_in_chain (vm, b0) - 1);
       nbytes = vlib_buffer_contents (vm, bi0, mif->last_marker_pkt);
@@ -176,7 +176,7 @@
    * and reuse it.
    */
   if (mif->last_rx_pkt)
-    _vec_len (mif->last_rx_pkt) = 0;
+    vec_set_len (mif->last_rx_pkt, 0);
 
   /*
    * Make sure the per-neighbor rx buffer is big enough to hold
@@ -225,7 +225,7 @@
   mif->pdu_received++;
 
   if (mif->last_rx_pkt)
-    _vec_len (mif->last_rx_pkt) = 0;
+    vec_set_len (mif->last_rx_pkt, 0);
 
   return e;
 }
diff --git a/src/plugins/lb/lb.c b/src/plugins/lb/lb.c
index 5bc7cf2..dfdc506 100644
--- a/src/plugins/lb/lb.c
+++ b/src/plugins/lb/lb.c
@@ -422,7 +422,7 @@
       sort_arr[i].as_index = as - lbm->ass;
       i++;
   }
-  _vec_len(sort_arr) = i;
+  vec_set_len (sort_arr, i);
 
   vec_sort_with_function(sort_arr, lb_pseudorand_compare);
 
diff --git a/src/plugins/lisp/lisp-cp/control.c b/src/plugins/lisp/lisp-cp/control.c
index 7293e03..24dd50b 100644
--- a/src/plugins/lisp/lisp-cp/control.c
+++ b/src/plugins/lisp/lisp-cp/control.c
@@ -4830,7 +4830,7 @@
 	  {
 	    process_expired_mapping (lcm, mi[0]);
 	  }
-	  _vec_len (expired) = 0;
+	  vec_set_len (expired, 0);
 	}
     }
 
diff --git a/src/plugins/lisp/lisp-gpe/interface.c b/src/plugins/lisp/lisp-gpe/interface.c
index 9dcf52d..05669ae 100644
--- a/src/plugins/lisp/lisp-gpe/interface.c
+++ b/src/plugins/lisp/lisp-gpe/interface.c
@@ -429,7 +429,7 @@
   if (flen > 0)
     {
       hw_if_index = lgm->free_tunnel_hw_if_indices[flen - 1];
-      _vec_len (lgm->free_tunnel_hw_if_indices) -= 1;
+      vec_dec_len (lgm->free_tunnel_hw_if_indices, 1);
 
       hi = vnet_get_hw_interface (vnm, hw_if_index);
 
diff --git a/src/plugins/lldp/lldp_input.c b/src/plugins/lldp/lldp_input.c
index 327ef10..b8aa846 100644
--- a/src/plugins/lldp/lldp_input.c
+++ b/src/plugins/lldp/lldp_input.c
@@ -48,13 +48,13 @@
 
   if (n->chassis_id)
     {
-      _vec_len (n->chassis_id) = 0;
+      vec_set_len (n->chassis_id, 0);
     }
   vec_add (n->chassis_id, chassis_id, a->chassis_id_len);
   n->chassis_id_subtype = a->chassis_id_subtype;
   if (n->port_id)
     {
-      _vec_len (n->port_id) = 0;
+      vec_set_len (n->port_id, 0);
     }
   vec_add (n->port_id, portid, a->portid_len);
   n->port_id_subtype = a->portid_subtype;
diff --git a/src/plugins/lldp/lldp_node.c b/src/plugins/lldp/lldp_node.c
index dbb54af..d4b6d52 100644
--- a/src/plugins/lldp/lldp_node.c
+++ b/src/plugins/lldp/lldp_node.c
@@ -220,7 +220,7 @@
 #endif
       if (event_data)
 	{
-	  _vec_len (event_data) = 0;
+	  vec_set_len (event_data, 0);
 	}
     }
 
diff --git a/src/plugins/memif/device.c b/src/plugins/memif/device.c
index 9478922..f049a7b 100644
--- a/src/plugins/memif/device.c
+++ b/src/plugins/memif/device.c
@@ -194,8 +194,8 @@
 	      else
 		{
 		  /* we need to rollback vectors before bailing out */
-		  _vec_len (ptd->buffers) = saved_ptd_buffers_len;
-		  _vec_len (ptd->copy_ops) = saved_ptd_copy_ops_len;
+		  vec_set_len (ptd->buffers, saved_ptd_buffers_len);
+		  vec_set_len (ptd->copy_ops, saved_ptd_copy_ops_len);
 		  vlib_error_count (vm, node->node_index,
 				    MEMIF_TX_ERROR_ROLLBACK, 1);
 		  slot = saved_slot;
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index b89665f..f4543c8 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -991,8 +991,6 @@
 	  bt->total_length_not_including_first_buffer = 0;
 	  vnet_buffer (bt)->sw_if_index[VLIB_TX] = (u32) ~ 0;
 
-	  /* initially prealloc copy_ops so we can use
-	     _vec_len instead of vec_elen */
 	  vec_validate_aligned (ptd->copy_ops, 0, CLIB_CACHE_LINE_BYTES);
 	  vec_reset_length (ptd->copy_ops);
 	  vec_validate_aligned (ptd->buffers, 0, CLIB_CACHE_LINE_BYTES);
diff --git a/src/plugins/memif/memif_api.c b/src/plugins/memif/memif_api.c
index a50e7ce..593306a 100644
--- a/src/plugins/memif/memif_api.c
+++ b/src/plugins/memif/memif_api.c
@@ -289,7 +289,7 @@
 			vnm, swif, 0);
 
       send_memif_details (reg, mif, swif, if_name, mp->context);
-      _vec_len (if_name) = 0;
+      vec_set_len (if_name, 0);
     }
   /* *INDENT-ON* */
 
diff --git a/src/plugins/nsh/nsh_api.c b/src/plugins/nsh/nsh_api.c
index 1faaea3..4a9eab4 100644
--- a/src/plugins/nsh/nsh_api.c
+++ b/src/plugins/nsh/nsh_api.c
@@ -346,7 +346,7 @@
 	{
 	  nsh_hw_if = nm->free_nsh_tunnel_hw_if_indices
 	    [vec_len (nm->free_nsh_tunnel_hw_if_indices) - 1];
-	  _vec_len (nm->free_nsh_tunnel_hw_if_indices) -= 1;
+	  vec_dec_len (nm->free_nsh_tunnel_hw_if_indices, 1);
 
 	  hi = vnet_get_hw_interface (vnm, nsh_hw_if);
 	  hi->dev_instance = map_index;
diff --git a/src/plugins/pppoe/pppoe.c b/src/plugins/pppoe/pppoe.c
index 182f93b..2bdbd3a 100644
--- a/src/plugins/pppoe/pppoe.c
+++ b/src/plugins/pppoe/pppoe.c
@@ -374,7 +374,7 @@
 	  vnet_interface_main_t *im = &vnm->interface_main;
 	  hw_if_index = pem->free_pppoe_session_hw_if_indices
 	    [vec_len (pem->free_pppoe_session_hw_if_indices) - 1];
-	  _vec_len (pem->free_pppoe_session_hw_if_indices) -= 1;
+	  vec_dec_len (pem->free_pppoe_session_hw_if_indices, 1);
 
 	  hi = vnet_get_hw_interface (vnm, hw_if_index);
 	  hi->dev_instance = t - pem->sessions;
diff --git a/src/plugins/snort/enqueue.c b/src/plugins/snort/enqueue.c
index 147d3a4..409c0e4 100644
--- a/src/plugins/snort/enqueue.c
+++ b/src/plugins/snort/enqueue.c
@@ -197,7 +197,7 @@
 	}
 
       __atomic_store_n (qp->enq_head, head, __ATOMIC_RELEASE);
-      _vec_len (qp->freelist) = freelist_len;
+      vec_set_len (qp->freelist, freelist_len);
       if (sm->input_mode == VLIB_NODE_STATE_INTERRUPT)
 	{
 	  if (write (qp->enq_fd, &ctr, sizeof (ctr)) < 0)
diff --git a/src/plugins/unittest/bihash_test.c b/src/plugins/unittest/bihash_test.c
index c5cc752..0789735 100644
--- a/src/plugins/unittest/bihash_test.c
+++ b/src/plugins/unittest/bihash_test.c
@@ -512,7 +512,7 @@
   /* Preallocate hash table, key vector */
   tm->key_hash = hash_create (tm->nitems, sizeof (uword));
   vec_validate (tm->keys, tm->nitems - 1);
-  _vec_len (tm->keys) = 0;
+  vec_set_len (tm->keys, 0);
 
   switch (which)
     {
diff --git a/src/plugins/unittest/bitmap_test.c b/src/plugins/unittest/bitmap_test.c
index 04a06d3..adee976 100644
--- a/src/plugins/unittest/bitmap_test.c
+++ b/src/plugins/unittest/bitmap_test.c
@@ -30,7 +30,7 @@
   junk = clib_bitmap_next_clear (bm, 65);
 
   bm2 = clib_bitmap_set_multiple (bm2, 0, ~0ULL, BITS (uword));
-  _vec_len (bm2) = 1;
+  vec_set_len (bm2, 1);
   junk = clib_bitmap_next_clear (bm2, 0);
 
 
diff --git a/src/plugins/unittest/fib_test.c b/src/plugins/unittest/fib_test.c
index 57ab29e..d417d5f 100644
--- a/src/plugins/unittest/fib_test.c
+++ b/src/plugins/unittest/fib_test.c
@@ -10628,7 +10628,7 @@
     fib_route_path_t *r_paths2 = NULL;
 
     r_paths2 = vec_dup(r_paths);
-    _vec_len(r_paths2) = 3;
+    vec_set_len (r_paths2, 3);
 
     pl_index = fib_path_list_create(FIB_PATH_LIST_FLAG_SHARED, r_paths2);
     fib_path_list_lock(pl_index);
@@ -10699,7 +10699,7 @@
     fib_route_path_t *r_paths3 = NULL;
 
     r_paths3 = vec_dup(r_paths);
-    _vec_len(r_paths3) = 3;
+    vec_set_len (r_paths3, 3);
 
     r_paths3[0].frp_weight = 3;
 
diff --git a/src/plugins/unittest/svm_fifo_test.c b/src/plugins/unittest/svm_fifo_test.c
index a57795c..8e186a8 100644
--- a/src/plugins/unittest/svm_fifo_test.c
+++ b/src/plugins/unittest/svm_fifo_test.c
@@ -2519,7 +2519,7 @@
       fifo_segment_free_fifo (sp, f);
     }
 
-  _vec_len (flist) = 0;
+  vec_set_len (flist, 0);
 
   for (i = 0; i < 1000; i++)
     {
diff --git a/src/plugins/vmxnet3/vmxnet3_api.c b/src/plugins/vmxnet3/vmxnet3_api.c
index 9060808..36fa7bd 100644
--- a/src/plugins/vmxnet3/vmxnet3_api.c
+++ b/src/plugins/vmxnet3/vmxnet3_api.c
@@ -179,7 +179,7 @@
       if_name = format (if_name, "%U%c", format_vnet_sw_interface_name, vnm,
 			swif, 0);
       send_vmxnet3_details (reg, vd, swif, if_name, mp->context);
-      _vec_len (if_name) = 0;
+      vec_set_len (if_name, 0);
     }
   /* *INDENT-ON* */
 
@@ -220,7 +220,7 @@
 	  if_name = format (if_name, "%U%c", format_vnet_sw_interface_name, vnm,
 			    swif, 0);
 	  send_vmxnet3_details (reg, vd, swif, if_name, mp->context);
-	  _vec_len (if_name) = 0;
+	  vec_set_len (if_name, 0);
 	}
     }
   /* *INDENT-ON* */
diff --git a/src/svm/svmdb.c b/src/svm/svmdb.c
index 2c3d351..7628c0a 100644
--- a/src/svm/svmdb.c
+++ b/src/svm/svmdb.c
@@ -281,7 +281,7 @@
       if (vec_len (oldvalue->notifications))
 	notify_value (oldvalue, SVMDB_ACTION_UNSET);
       /* zero length value means unset */
-      _vec_len (oldvalue->value) = 0;
+      vec_set_len (oldvalue->value, 0);
     }
   client->shm->namespaces[namespace] = h;
 }
@@ -317,7 +317,7 @@
       oldvalue = pool_elt_at_index (client->shm->values, hp->value[0]);
       vec_alloc (oldvalue->value, vec_len (val) * elsize);
       clib_memcpy (oldvalue->value, val, vec_len (val) * elsize);
-      _vec_len (oldvalue->value) = vec_len (val);
+      vec_set_len (oldvalue->value, vec_len (val));
       notify_value (oldvalue, SVMDB_ACTION_SET);
     }
   else
@@ -328,7 +328,7 @@
       newvalue->elsize = elsize;
       vec_alloc (newvalue->value, vec_len (val) * elsize);
       clib_memcpy (newvalue->value, val, vec_len (val) * elsize);
-      _vec_len (newvalue->value) = vec_len (val);
+      vec_set_len (newvalue->value, vec_len (val));
       name = format (0, "%s%c", var, 0);
       hash_set_mem (h, name, newvalue - shm->values);
     }
@@ -589,7 +589,7 @@
       /* Make a copy in process-local memory */
       vec_alloc (copy, vec_len (rv) * elsize);
       clib_memcpy (copy, rv, vec_len (rv) * elsize);
-      _vec_len (copy) = vec_len (rv);
+      vec_set_len (copy, vec_len (rv));
       region_unlock (client->db_rp);
       return (copy);
     }
@@ -653,7 +653,7 @@
       clib_memset (newvalue, 0, sizeof (*newvalue));
       newvalue->elsize = 1;
       vec_alloc (newvalue->value, nbytes);
-      _vec_len (newvalue->value) = nbytes;
+      vec_set_len (newvalue->value, nbytes);
       name = format (0, "%s%c", var, 0);
       hash_set_mem (h, name, newvalue - shm->values);
       shm->namespaces[SVMDB_NAMESPACE_VEC] = h;
diff --git a/src/tools/perftool/cpel_util.c b/src/tools/perftool/cpel_util.c
index 4f5f98a..4dc1eaf 100644
--- a/src/tools/perftool/cpel_util.c
+++ b/src/tools/perftool/cpel_util.c
@@ -424,7 +424,7 @@
           alpha_compare_tracks);
 
     vec_validate(track_alpha_map, vec_len(the_tracks));
-    _vec_len(track_alpha_map) = vec_len(the_tracks);
+    vec_set_len (track_alpha_map, vec_len (the_tracks));
 
     for (i = 0; i < vec_len(the_tracks); i++) {
         this_track = &the_tracks[i];
diff --git a/src/tools/perftool/cpelinreg.c b/src/tools/perftool/cpelinreg.c
index 115afad..4439990 100644
--- a/src/tools/perftool/cpelinreg.c
+++ b/src/tools/perftool/cpelinreg.c
@@ -617,12 +617,12 @@
             } else {
                 dup_events++;
             }
-            _vec_len(tp->start_datum) = sp;
-            _vec_len(tp->start_time) = sp;
-            _vec_len(tp->dup_event) = sp;
-        }
+	    vec_set_len (tp->start_datum, sp);
+	    vec_set_len (tp->start_time, sp);
+	    vec_set_len (tp->dup_event, sp);
+	}
 
-        ep++;
+	ep++;
     }
     last_end_time = now;
 
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 4827d55..14546b5 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -1427,7 +1427,7 @@
       if (match == 0)
 	clib_warning ("BUG: match 0");
 
-      _vec_len (mask) = match * sizeof (u32x4);
+      vec_set_len (mask, match * sizeof (u32x4));
 
       *matchp = match;
       *maskp = mask;
@@ -1994,7 +1994,7 @@
 	 sizeof (u32x4));
 
       /* Set size, include skipped vectors */
-      _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
+      vec_set_len (match, (match_n_vectors + skip_n_vectors) * sizeof (u32x4));
 
       *matchp = match;
 
diff --git a/src/vat/main.c b/src/vat/main.c
index 1640c5d..e7c0818 100644
--- a/src/vat/main.c
+++ b/src/vat/main.c
@@ -98,7 +98,7 @@
 	    rv = write (1, "exec# ", 6);
 	}
 
-      _vec_len (vam->inbuf) = 4096;
+      vec_set_len (vam->inbuf, 4096);
 
       if (vam->do_exit ||
 	  fgets ((char *) vam->inbuf, vec_len (vam->inbuf), vam->ifp) == 0)
diff --git a/src/vat/plugin.c b/src/vat/plugin.c
index 09a96fd..bc78000 100644
--- a/src/vat/plugin.c
+++ b/src/vat/plugin.c
@@ -155,7 +155,7 @@
 	      if (load_one_plugin (pm, pi))
 		{
 		  vec_free (plugin_name);
-		  _vec_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1;
+		  vec_set_len (pm->plugin_info, vec_len (pm->plugin_info) - 1);
 		  continue;
 		}
 	      hash_set_mem (pm->plugin_by_name_hash, plugin_name,
diff --git a/src/vat2/plugin.c b/src/vat2/plugin.c
index 6b6d55a..3ad8705 100644
--- a/src/vat2/plugin.c
+++ b/src/vat2/plugin.c
@@ -165,7 +165,7 @@
 		{
 		  res = -1;
 		  vec_free (plugin_name);
-		  _vec_len (plugin_info) = vec_len (plugin_info) - 1;
+		  vec_set_len (plugin_info, vec_len (plugin_info) - 1);
 		  continue;
 		}
 	      clib_memset (pi, 0, sizeof (*pi));
diff --git a/src/vcl/vcl_cfg.c b/src/vcl/vcl_cfg.c
index 4e0b583..ac768c4 100644
--- a/src/vcl/vcl_cfg.c
+++ b/src/vcl/vcl_cfg.c
@@ -431,7 +431,7 @@
 	      u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id);
 	      if (nsid_vec_len > max_nsid_vec_len)
 		{
-		  _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len;
+		  vec_set_len (vcl_cfg->namespace_id, max_nsid_vec_len);
 		  VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long,"
 			    " truncated to %d characters!",
 			    getpid (), max_nsid_vec_len);
diff --git a/src/vlib/cli.c b/src/vlib/cli.c
index b7c4c00..dcabe8d 100644
--- a/src/vlib/cli.c
+++ b/src/vlib/cli.c
@@ -617,7 +617,7 @@
 		      vec_add1 (c_error->what, 0);
 		      ed->err = elog_string (vlib_get_elog_main (),
 					     (char *) c_error->what);
-		      _vec_len (c_error->what) -= 1;
+		      vec_dec_len (c_error->what, 1);
 		    }
 		  else
 		    ed->err = elog_string (vlib_get_elog_main (), "OK");
@@ -1179,7 +1179,7 @@
 
   /* Remove any extra space at end. */
   if (l > 0 && s[l - 1] == ' ')
-    _vec_len (s) -= 1;
+    vec_dec_len (s, 1);
 
   *result = s;
   return index_of_last_space;
diff --git a/src/vlib/lex.c b/src/vlib/lex.c
index 1cc8f16..7facba5 100644
--- a/src/vlib/lex.c
+++ b/src/vlib/lex.c
@@ -113,7 +113,7 @@
 				lm->lex_token_names[VLIB_LEX_word],
 				rv->value.as_pointer);
 	      }
-	    _vec_len (lm->token_buffer) = 0;
+	    vec_set_len (lm->token_buffer, 0);
 
 	    /* Rescan the character which terminated the keyword/word. */
 	    lm->current_index--;
@@ -233,7 +233,7 @@
 vlib_lex_reset (vlib_lex_main_t * lm, u8 * input_vector)
 {
   if (lm->pushback_vector)
-    _vec_len (lm->pushback_vector) = 0;
+    vec_set_len (lm->pushback_vector, 0);
   lm->pushback_sp = -1;
 
   lm->input_vector = input_vector;
@@ -255,7 +255,7 @@
 #undef _
 
   vec_validate (lm->token_buffer, 127);
-  _vec_len (lm->token_buffer) = 0;
+  vec_set_len (lm->token_buffer, 0);
 
   return 0;
 }
diff --git a/src/vlib/main.c b/src/vlib/main.c
index fd0c1fc..a9efe7e 100644
--- a/src/vlib/main.c
+++ b/src/vlib/main.c
@@ -81,7 +81,7 @@
     {
       /* Allocate from end of free list. */
       f = fs->free_frames[l - 1];
-      _vec_len (fs->free_frames) = l - 1;
+      vec_set_len (fs->free_frames, l - 1);
     }
   else
     {
@@ -1458,7 +1458,7 @@
   if (is_main)
     {
       vec_resize (nm->pending_frames, 32);
-      _vec_len (nm->pending_frames) = 0;
+      vec_set_len (nm->pending_frames, 0);
     }
 
   /* Mark time of main loop start. */
@@ -1584,7 +1584,7 @@
       for (i = 0; i < _vec_len (nm->pending_frames); i++)
 	cpu_time_now = dispatch_pending_node (vm, i, cpu_time_now);
       /* Reset pending vector for next iteration. */
-      _vec_len (nm->pending_frames) = 0;
+      vec_set_len (nm->pending_frames, 0);
 
       if (is_main)
 	{
@@ -1670,7 +1670,7 @@
 			dispatch_suspended_process (vm, di, cpu_time_now);
 		    }
 		}
-	      _vec_len (nm->data_from_advancing_timing_wheel) = 0;
+	      vec_set_len (nm->data_from_advancing_timing_wheel, 0);
 	    }
 	}
       vlib_increment_main_loop_counter (vm);
@@ -1946,7 +1946,7 @@
 					     CLIB_CACHE_LINE_BYTES);
 
   vec_validate (nm->data_from_advancing_timing_wheel, 10);
-  _vec_len (nm->data_from_advancing_timing_wheel) = 0;
+  vec_set_len (nm->data_from_advancing_timing_wheel, 0);
 
   /* Create the process timing wheel */
   TW (tw_timer_wheel_init) ((TWT (tw_timer_wheel) *) nm->timing_wheel,
@@ -1955,9 +1955,9 @@
 			    ~0 /* max expirations per call */ );
 
   vec_validate (vm->pending_rpc_requests, 0);
-  _vec_len (vm->pending_rpc_requests) = 0;
+  vec_set_len (vm->pending_rpc_requests, 0);
   vec_validate (vm->processing_rpc_requests, 0);
-  _vec_len (vm->processing_rpc_requests) = 0;
+  vec_set_len (vm->processing_rpc_requests, 0);
 
   /* Default params for the buffer allocator fault injector, if configured */
   if (VLIB_BUFFER_ALLOC_FAULT_INJECTOR > 0)
diff --git a/src/vlib/node_funcs.h b/src/vlib/node_funcs.h
index de6fd48..df8ec7c 100644
--- a/src/vlib/node_funcs.h
+++ b/src/vlib/node_funcs.h
@@ -604,7 +604,7 @@
   l = _vec_len (p->pending_event_data_by_type_index[t]);
   if (data_vector)
     vec_add (*data_vector, p->pending_event_data_by_type_index[t], l);
-  _vec_len (p->pending_event_data_by_type_index[t]) = 0;
+  vec_set_len (p->pending_event_data_by_type_index[t], 0);
 
   et = pool_elt_at_index (p->event_type_pool, t);
 
@@ -628,7 +628,7 @@
   l = _vec_len (p->pending_event_data_by_type_index[t]);
   if (data_vector)
     vec_add (*data_vector, p->pending_event_data_by_type_index[t], l);
-  _vec_len (p->pending_event_data_by_type_index[t]) = 0;
+  vec_set_len (p->pending_event_data_by_type_index[t], 0);
 
   vlib_process_maybe_free_event_type (p, t);
 
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 567ba62..36a8080 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -235,7 +235,7 @@
 
   /* Set up thread 0 */
   vec_validate_aligned (vlib_worker_threads, 0, CLIB_CACHE_LINE_BYTES);
-  _vec_len (vlib_worker_threads) = 1;
+  vec_set_len (vlib_worker_threads, 1);
   w = vlib_worker_threads;
   w->thread_mheap = clib_mem_get_heap ();
   w->thread_stack = vlib_thread_stacks[0];
@@ -558,7 +558,7 @@
 
   vec_validate_aligned (vgm->vlib_mains, n_vlib_mains - 1,
 			CLIB_CACHE_LINE_BYTES);
-  _vec_len (vgm->vlib_mains) = 0;
+  vec_set_len (vgm->vlib_mains, 0);
   vec_add1_aligned (vgm->vlib_mains, vm, CLIB_CACHE_LINE_BYTES);
 
   if (n_vlib_mains > 1)
@@ -640,7 +640,7 @@
 	      vm_clone->thread_index = worker_thread_index;
 	      vm_clone->pending_rpc_requests = 0;
 	      vec_validate (vm_clone->pending_rpc_requests, 0);
-	      _vec_len (vm_clone->pending_rpc_requests) = 0;
+	      vec_set_len (vm_clone->pending_rpc_requests, 0);
 	      clib_memset (&vm_clone->random_buffer, 0,
 			   sizeof (vm_clone->random_buffer));
 	      clib_spinlock_init
@@ -670,7 +670,7 @@
 	      /* fork the frame dispatch queue */
 	      nm_clone->pending_frames = 0;
 	      vec_validate (nm_clone->pending_frames, 10);
-	      _vec_len (nm_clone->pending_frames) = 0;
+	      vec_set_len (nm_clone->pending_frames, 0);
 
 	      /* fork nodes */
 	      nm_clone->nodes = 0;
@@ -1616,7 +1616,7 @@
   fqm->frame_queue_nelts = frame_queue_nelts;
 
   vec_validate (fqm->vlib_frame_queues, tm->n_vlib_mains - 1);
-  _vec_len (fqm->vlib_frame_queues) = 0;
+  vec_set_len (fqm->vlib_frame_queues, 0);
   for (i = 0; i < tm->n_vlib_mains; i++)
     {
       fq = vlib_frame_queue_alloc (frame_queue_nelts);
diff --git a/src/vlib/trace.c b/src/vlib/trace.c
index 4bbd950..49b521e 100644
--- a/src/vlib/trace.c
+++ b/src/vlib/trace.c
@@ -272,7 +272,7 @@
   for (index = 0; index < vec_len (traces_to_remove); index++)
     {
       trace_index = traces_to_remove[index] - tm->trace_buffer_pool;
-      _vec_len (tm->trace_buffer_pool[trace_index]) = 0;
+      vec_set_len (tm->trace_buffer_pool[trace_index], 0);
       pool_put_index (tm->trace_buffer_pool, trace_index);
     }
 
diff --git a/src/vlib/trace_funcs.h b/src/vlib/trace_funcs.h
index 9313d41..3ed4768 100644
--- a/src/vlib/trace_funcs.h
+++ b/src/vlib/trace_funcs.h
@@ -125,7 +125,7 @@
   vlib_trace_main_t *tm = &vm->trace_main;
   u32 trace_index = vlib_buffer_get_trace_index (b);
   vlib_validate_trace (tm, b);
-  _vec_len (tm->trace_buffer_pool[trace_index]) = 0;
+  vec_set_len (tm->trace_buffer_pool[trace_index], 0);
   pool_put_index (tm->trace_buffer_pool, trace_index);
 }
 
diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c
index c546948..244c8df 100644
--- a/src/vlib/unix/cli.c
+++ b/src/vlib/unix/cli.c
@@ -1610,7 +1610,7 @@
 
       /* Delete the desired text from the command */
       memmove (cf->current_command, cf->current_command + j, delta);
-      _vec_len (cf->current_command) = delta;
+      vec_set_len (cf->current_command, delta);
 
       /* Print the new contents */
       unix_vlib_cli_output_cooked (cf, uf, cf->current_command, delta);
@@ -1635,7 +1635,7 @@
 	unix_vlib_cli_output_cursor_left (cf, uf);
 
       /* Truncate the line at the cursor */
-      _vec_len (cf->current_command) = cf->cursor;
+      vec_set_len (cf->current_command, cf->cursor);
 
       cf->search_mode = 0;
       break;
@@ -1677,7 +1677,7 @@
 		unix_vlib_cli_output_cooked (cf, uf, (u8 *) " ", 1);
 	      for (; (cf->current_command + cf->cursor) > save; cf->cursor--)
 		unix_vlib_cli_output_cursor_left (cf, uf);
-	      _vec_len (cf->current_command) -= delta;
+	      vec_dec_len (cf->current_command, delta);
 	    }
 	}
       cf->search_mode = 0;
@@ -1734,13 +1734,13 @@
 	  if (cf->excursion == vec_len (cf->command_history))
 	    {
 	      /* down-arrowed to last entry - want a blank line */
-	      _vec_len (cf->current_command) = 0;
+	      vec_set_len (cf->current_command, 0);
 	    }
 	  else if (cf->excursion < 0)
 	    {
 	      /* up-arrowed over the start to the end, want a blank line */
 	      cf->excursion = vec_len (cf->command_history);
-	      _vec_len (cf->current_command) = 0;
+	      vec_set_len (cf->current_command, 0);
 	    }
 	  else
 	    {
@@ -1753,7 +1753,7 @@
 	      vec_validate (cf->current_command, vec_len (prev) - 1);
 
 	      clib_memcpy (cf->current_command, prev, vec_len (prev));
-	      _vec_len (cf->current_command) = vec_len (prev);
+	      vec_set_len (cf->current_command, vec_len (prev));
 	      unix_vlib_cli_output_cooked (cf, uf, cf->current_command,
 					   vec_len (cf->current_command));
 	    }
@@ -1840,7 +1840,7 @@
 	      cf->cursor++;
 	      unix_vlib_cli_output_cursor_left (cf, uf);
 	      cf->cursor--;
-	      _vec_len (cf->current_command)--;
+	      vec_dec_len (cf->current_command, 1);
 	    }
 	  else if (cf->cursor > 0)
 	    {
@@ -1848,7 +1848,7 @@
 	      j = vec_len (cf->current_command) - cf->cursor;
 	      memmove (cf->current_command + cf->cursor - 1,
 		       cf->current_command + cf->cursor, j);
-	      _vec_len (cf->current_command)--;
+	      vec_dec_len (cf->current_command, 1);
 
 	      /* redraw the rest of the line */
 	      unix_vlib_cli_output_cursor_left (cf, uf);
@@ -1884,7 +1884,7 @@
 	      j = vec_len (cf->current_command) - cf->cursor - 1;
 	      memmove (cf->current_command + cf->cursor,
 		       cf->current_command + cf->cursor + 1, j);
-	      _vec_len (cf->current_command)--;
+	      vec_dec_len (cf->current_command, 1);
 	      /* redraw the rest of the line */
 	      unix_vlib_cli_output_cooked (cf, uf,
 					   cf->current_command + cf->cursor,
@@ -1956,7 +1956,7 @@
 	      vec_resize (save, vec_len (cf->current_command) - cf->cursor);
 	      clib_memcpy (save, cf->current_command + cf->cursor,
 			   vec_len (cf->current_command) - cf->cursor);
-	      _vec_len (cf->current_command) = cf->cursor;
+	      vec_set_len (cf->current_command, cf->cursor);
 	    }
 	  else
 	    {
@@ -1978,7 +1978,7 @@
 	      cf->cursor--;
 	      j--;
 	    }
-	  _vec_len (cf->current_command) = j;
+	  vec_set_len (cf->current_command, j);
 
 	  /* replace it with the newly expanded command */
 	  vec_append (cf->current_command, completed);
@@ -2385,7 +2385,7 @@
 
 	      vec_validate (cf->current_command, vec_len (item) - 1);
 	      clib_memcpy (cf->current_command, item, vec_len (item));
-	      _vec_len (cf->current_command) = vec_len (item);
+	      vec_set_len (cf->current_command, vec_len (item));
 
 	      unix_vlib_cli_output_cooked (cf, uf, cf->current_command,
 					   vec_len (cf->current_command));
@@ -2599,7 +2599,7 @@
 					 0 /* level */ ,
 					 8 /* max_level */ );
       /* Macro processor NULL terminates the return */
-      _vec_len (expanded) -= 1;
+      vec_dec_len (expanded, 1);
       vec_reset_length (cf->current_command);
       vec_append (cf->current_command, expanded);
       vec_free (expanded);
@@ -2754,7 +2754,7 @@
 	}
 
       if (data)
-	_vec_len (data) = 0;
+	vec_set_len (data, 0);
     }
 
 done:
@@ -2836,7 +2836,7 @@
 	return clib_error_return_unix (0, "read");
 
       n_read = n < 0 ? 0 : n;
-      _vec_len (cf->input_vector) = l + n_read;
+      vec_set_len (cf->input_vector, l + n_read);
     }
 
   if (!(n < 0))
@@ -2918,7 +2918,7 @@
       vec_free (old_name);
 
       vlib_node_set_state (vm, n->index, VLIB_NODE_STATE_POLLING);
-      _vec_len (cm->unused_cli_process_node_indices) = l - 1;
+      vec_set_len (cm->unused_cli_process_node_indices, l - 1);
     }
   else
     {
@@ -2954,7 +2954,7 @@
   cf->output_vector = 0;
   cf->input_vector = 0;
   vec_validate (cf->current_command, 0);
-  _vec_len (cf->current_command) = 0;
+  vec_set_len (cf->current_command, 0);
 
   vlib_start_process (vm, n->runtime_index);
 
@@ -3445,7 +3445,7 @@
 					 0 /* level */ ,
 					 8 /* max_level */ );
       /* Macro processor NULL terminates the return */
-      _vec_len (expanded) -= 1;
+      vec_dec_len (expanded, 1);
       vec_reset_length (sub_input.buffer);
       vec_append (sub_input.buffer, expanded);
       vec_free (expanded);
diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c
index 0b73597..3710d8e 100644
--- a/src/vlib/unix/main.c
+++ b/src/vlib/unix/main.c
@@ -316,7 +316,7 @@
 	  n = read (fd, buf + l, 4096);
 	  if (n > 0)
 	    {
-	      _vec_len (buf) = l + n;
+	      vec_set_len (buf, l + n);
 	      if (n < 4096)
 		break;
 	    }
diff --git a/src/vlib/unix/mc_socket.c b/src/vlib/unix/mc_socket.c
index 9800b1e..1f3b4e9 100644
--- a/src/vlib/unix/mc_socket.c
+++ b/src/vlib/unix/mc_socket.c
@@ -90,7 +90,7 @@
   h.msg_namelen = sizeof (tx_addr[0]);
 
   if (msm->iovecs)
-    _vec_len (msm->iovecs) = 0;
+    vec_set_len (msm->iovecs, 0);
 
   n_bytes = append_buffer_index_to_iovec (vm, buffer_index, &msm->iovecs);
   ASSERT (n_bytes <= msm->mc_main.transport.max_packet_size);
@@ -177,7 +177,7 @@
       vec_validate (msm->rx_buffers, max_alloc - 1);
       n_alloc =
 	vlib_buffer_alloc (vm, msm->rx_buffers + n_left, max_alloc - n_left);
-      _vec_len (msm->rx_buffers) = n_left + n_alloc;
+      vec_set_len (msm->rx_buffers, n_left + n_alloc);
     }
 
   ASSERT (vec_len (msm->rx_buffers) >= n_mtu);
@@ -192,7 +192,7 @@
       msm->iovecs[i].iov_base = b->data;
       msm->iovecs[i].iov_len = buffer_size;
     }
-  _vec_len (msm->iovecs) = n_mtu;
+  vec_set_len (msm->iovecs, n_mtu);
 
   {
     struct msghdr h;
@@ -237,7 +237,7 @@
       b->next_buffer = msm->rx_buffers[i_rx];
     }
 
-  _vec_len (msm->rx_buffers) = i_rx;
+  vec_set_len (msm->rx_buffers, i_rx);
 
   return 0 /* no error */ ;
 }
@@ -418,7 +418,7 @@
 	}
     }
 
-  _vec_len (c->input_vector) = l + n;
+  vec_set_len (c->input_vector, l + n);
 
   if (is_eof && vec_len (c->input_vector) > 0)
     {
@@ -426,7 +426,7 @@
 	{
 	  mc_msg_catchup_request_handler (mcm, (void *) c->input_vector,
 					  c - msm->catchups);
-	  _vec_len (c->input_vector) = 0;
+	  vec_set_len (c->input_vector, 0);
 	}
       else
 	{
diff --git a/src/vlib/unix/util.c b/src/vlib/unix/util.c
index 03aef36..04cd6f5 100644
--- a/src/vlib/unix/util.c
+++ b/src/vlib/unix/util.c
@@ -86,8 +86,8 @@
       s = format (s, "%s/%s", dir_name, e->d_name);
       t = format (t, "%s", e->d_name);
       error = f (arg, s, t);
-      _vec_len (s) = 0;
-      _vec_len (t) = 0;
+      vec_set_len (s, 0);
+      vec_set_len (t, 0);
 
       if (error)
 	break;
@@ -116,7 +116,7 @@
 	      error = clib_error_return_unix (0, "mkdir '%s'", c);
 	      goto done;
 	    }
-	  _vec_len (c)--;
+	  vec_dec_len (c, 1);
 	}
       vec_add1 (c, path[i]);
       i++;
diff --git a/src/vlibapi/node_serialize.c b/src/vlibapi/node_serialize.c
index b50d79e..061f763 100644
--- a/src/vlibapi/node_serialize.c
+++ b/src/vlibapi/node_serialize.c
@@ -176,7 +176,7 @@
   nstat_vms = unserialize_likely_small_unsigned_integer (sm);
 
   vec_validate (nodes_by_thread, nstat_vms - 1);
-  _vec_len (nodes_by_thread) = 0;
+  vec_set_len (nodes_by_thread, 0);
 
   for (i = 0; i < nstat_vms; i++)
     {
diff --git a/src/vlibmemory/memclnt_api.c b/src/vlibmemory/memclnt_api.c
index 87bb36a..289a4c5 100644
--- a/src/vlibmemory/memclnt_api.c
+++ b/src/vlibmemory/memclnt_api.c
@@ -500,7 +500,7 @@
       if (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
 	{
 	  ASSERT (long_msg != 0);
-	  _vec_len (long_msg) = 0;
+	  vec_set_len (long_msg, 0);
 	  vec_add (long_msg, msg, msg_len);
 	  while (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
 	    {
diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c
index 1716f27..5244b27 100644
--- a/src/vlibmemory/memory_shared.c
+++ b/src/vlibmemory/memory_shared.c
@@ -545,8 +545,8 @@
   if (strstr (region_name, vpe_api_region_suffix))
     {
       u8 *root_path = format (0, "%s", region_name);
-      _vec_len (root_path) = (vec_len (root_path) -
-			      strlen (vpe_api_region_suffix));
+      vec_set_len (root_path,
+		   vec_len (root_path) - strlen (vpe_api_region_suffix));
       vec_terminate_c_string (root_path);
       a->root_path = (const char *) root_path;
       am->root_path = (const char *) root_path;
diff --git a/src/vlibmemory/socket_client.c b/src/vlibmemory/socket_client.c
index 7082d8b..237d222 100644
--- a/src/vlibmemory/socket_client.c
+++ b/src/vlibmemory/socket_client.c
@@ -93,7 +93,7 @@
 	  current_rx_index = vec_len (scm->socket_rx_buffer);
 	  vec_validate (scm->socket_rx_buffer, current_rx_index
 			+ scm->socket_buffer_size - 1);
-	  _vec_len (scm->socket_rx_buffer) = current_rx_index;
+	  vec_set_len (scm->socket_rx_buffer, current_rx_index);
 	  n = read (scm->socket_fd, scm->socket_rx_buffer + current_rx_index,
 		    scm->socket_buffer_size);
 	  if (n < 0)
@@ -104,7 +104,7 @@
 	      clib_unix_warning ("socket_read");
 	      return -1;
 	    }
-	  _vec_len (scm->socket_rx_buffer) += n;
+	  vec_inc_len (scm->socket_rx_buffer, n);
 	}
 
 #if CLIB_DEBUG > 1
@@ -116,7 +116,7 @@
       data_len = ntohl (mbp->data_len);
       current_rx_index = vec_len (scm->socket_rx_buffer);
       vec_validate (scm->socket_rx_buffer, current_rx_index + data_len);
-      _vec_len (scm->socket_rx_buffer) = current_rx_index;
+      vec_set_len (scm->socket_rx_buffer, current_rx_index);
       mbp = (msgbuf_t *) (scm->socket_rx_buffer);
       msg_size = data_len + sizeof (*mbp);
 
@@ -133,7 +133,7 @@
 	      clib_unix_warning ("socket_read");
 	      return -1;
 	    }
-	  _vec_len (scm->socket_rx_buffer) += n;
+	  vec_inc_len (scm->socket_rx_buffer, n);
 	}
 
       if (vec_len (scm->socket_rx_buffer) >= data_len + sizeof (*mbp))
@@ -141,7 +141,7 @@
 	  vl_msg_api_socket_handler ((void *) (mbp->data), data_len);
 
 	  if (vec_len (scm->socket_rx_buffer) == data_len + sizeof (*mbp))
-	    _vec_len (scm->socket_rx_buffer) = 0;
+	    vec_set_len (scm->socket_rx_buffer, 0);
 	  else
 	    vec_delete (scm->socket_rx_buffer, data_len + sizeof (*mbp), 0);
 	  mbp = 0;
@@ -480,8 +480,8 @@
     SOCKET_CLIENT_DEFAULT_BUFFER_SIZE;
   vec_validate (scm->socket_tx_buffer, scm->socket_buffer_size - 1);
   vec_validate (scm->socket_rx_buffer, scm->socket_buffer_size - 1);
-  _vec_len (scm->socket_rx_buffer) = 0;
-  _vec_len (scm->socket_tx_buffer) = 0;
+  vec_set_len (scm->socket_rx_buffer, 0);
+  vec_set_len (scm->socket_tx_buffer, 0);
   scm->name = format (0, "%s", client_name);
 
   mp = vl_socket_client_msg_alloc2 (scm, sizeof (*mp));
diff --git a/src/vlibmemory/vlib_api_cli.c b/src/vlibmemory/vlib_api_cli.c
index e3e7ee3..732ced7 100644
--- a/src/vlibmemory/vlib_api_cli.c
+++ b/src/vlibmemory/vlib_api_cli.c
@@ -673,7 +673,7 @@
 	  break;
 	}
 
-      _vec_len (tmpbuf) = 0;
+      vec_set_len (tmpbuf, 0);
       msg += size;
     }
 
@@ -1285,7 +1285,7 @@
   rv = vec_dup (s);
 
   while (vec_len (rv) && rv[vec_len (rv)] != '_')
-    _vec_len (rv)--;
+    vec_dec_len (rv, 0);
 
   rv[vec_len (rv)] = 0;
 
diff --git a/src/vnet/bfd/bfd_main.c b/src/vnet/bfd/bfd_main.c
index f77d66c..4f5b36b 100644
--- a/src/vnet/bfd/bfd_main.c
+++ b/src/vnet/bfd/bfd_main.c
@@ -1266,11 +1266,11 @@
       bfd_unlock (bm);
       if (expired)
 	{
-	  _vec_len (expired) = 0;
+	  vec_set_len (expired, 0);
 	}
       if (event_data)
 	{
-	  _vec_len (event_data) = 0;
+	  vec_set_len (event_data, 0);
 	}
     }
 
diff --git a/src/vnet/classify/vnet_classify.c b/src/vnet/classify/vnet_classify.c
index 1bdbee7..c9a6fc6 100644
--- a/src/vnet/classify/vnet_classify.c
+++ b/src/vnet/classify/vnet_classify.c
@@ -1320,7 +1320,7 @@
       if (match == 0)
 	clib_warning ("BUG: match 0");
 
-      _vec_len (mask) = match * sizeof (u32x4);
+      vec_set_len (mask, match * sizeof (u32x4));
 
       *matchp = match;
       *maskp = mask;
@@ -2770,8 +2770,8 @@
 	 sizeof (u32x4));
 
       /* Set size, include skipped vectors */
-      _vec_len (match) =
-	(t->match_n_vectors + t->skip_n_vectors) * sizeof (u32x4);
+      vec_set_len (match,
+		   (t->match_n_vectors + t->skip_n_vectors) * sizeof (u32x4));
 
       *matchp = match;
 
diff --git a/src/vnet/config.c b/src/vnet/config.c
index 4ff001a..c05da66 100644
--- a/src/vnet/config.c
+++ b/src/vnet/config.c
@@ -97,7 +97,7 @@
   config_string = cm->config_string_temp;
   cm->config_string_temp = 0;
   if (config_string)
-    _vec_len (config_string) = 0;
+    vec_set_len (config_string, 0);
 
   vec_foreach (f, feature_vector)
   {
@@ -296,7 +296,7 @@
       if (new_features[last].node_index == cm->default_end_node_index)
 	{
 	  vec_free (new_features->feature_config);
-	  _vec_len (new_features) = last;
+	  vec_set_len (new_features, last);
 	}
     }
 
diff --git a/src/vnet/devices/af_packet/node.c b/src/vnet/devices/af_packet/node.c
index 323508b..631bbac 100644
--- a/src/vnet/devices/af_packet/node.c
+++ b/src/vnet/devices/af_packet/node.c
@@ -293,7 +293,7 @@
 			n_required + n_free_bufs - 1);
 	  n_free_bufs += vlib_buffer_alloc (
 	    vm, &apm->rx_buffers[thread_index][n_free_bufs], n_required);
-	  _vec_len (apm->rx_buffers[thread_index]) = n_free_bufs;
+	  vec_set_len (apm->rx_buffers[thread_index], n_free_bufs);
 	}
 
       while (num_pkts && (n_free_bufs >= min_bufs))
@@ -341,7 +341,8 @@
 		  u32 last_empty_buffer =
 		    vec_len (apm->rx_buffers[thread_index]) - 1;
 		  bi0 = apm->rx_buffers[thread_index][last_empty_buffer];
-		  _vec_len (apm->rx_buffers[thread_index]) = last_empty_buffer;
+		  vec_set_len (apm->rx_buffers[thread_index],
+			       last_empty_buffer);
 		  n_free_bufs--;
 
 		  /* copy data */
diff --git a/src/vnet/dpo/load_balance.c b/src/vnet/dpo/load_balance.c
index 4666c9a..9001a35 100644
--- a/src/vnet/dpo/load_balance.c
+++ b/src/vnet/dpo/load_balance.c
@@ -408,7 +408,7 @@
     {
         nhs[0] = raw_next_hops[0];
         nhs[0].path_weight = 1;
-        _vec_len (nhs) = 1;
+        vec_set_len (nhs, 1);
         sum_weight = 1;
         goto done;
     }
@@ -425,7 +425,7 @@
         if (nhs[0].path_weight == nhs[1].path_weight)
         {
             nhs[0].path_weight = nhs[1].path_weight = 1;
-            _vec_len (nhs) = 2;
+            vec_set_len (nhs, 2);
             sum_weight = 2;
             goto done;
         }
@@ -491,7 +491,7 @@
         if (error <= multipath_next_hop_error_tolerance*n_adj)
         {
             /* Truncate any next hops with zero weight. */
-            _vec_len (nhs) = i;
+            vec_set_len (nhs, i);
             break;
         }
     }
diff --git a/src/vnet/dpo/load_balance_map.c b/src/vnet/dpo/load_balance_map.c
index 5524974..765cd85 100644
--- a/src/vnet/dpo/load_balance_map.c
+++ b/src/vnet/dpo/load_balance_map.c
@@ -317,7 +317,7 @@
             bucket += lbmp->lbmp_weight;
         }
     }
-    _vec_len(tmp_buckets) = jj;
+    vec_set_len (tmp_buckets, jj);
 
     /*
      * If the number of temporaries written is as many as we need, implying
diff --git a/src/vnet/fib/fib_path_list.c b/src/vnet/fib/fib_path_list.c
index d7e860e..ebd2c0e 100644
--- a/src/vnet/fib/fib_path_list.c
+++ b/src/vnet/fib/fib_path_list.c
@@ -964,8 +964,7 @@
         }
         if (duplicate)
         {
-            _vec_len(path_list->fpl_paths) =
-                vec_len(path_list->fpl_paths) - 1;
+            vec_set_len(path_list->fpl_paths, vec_len(path_list->fpl_paths) - 1);
             fib_path_destroy(new_path_index);
         }
         else
diff --git a/src/vnet/fib/fib_urpf_list.c b/src/vnet/fib/fib_urpf_list.c
index 55f3b8a..b1bbe73 100644
--- a/src/vnet/fib/fib_urpf_list.c
+++ b/src/vnet/fib/fib_urpf_list.c
@@ -173,7 +173,7 @@
           if (urpf->furpf_itfs[i] != urpf->furpf_itfs[j])
             urpf->furpf_itfs[++i] = urpf->furpf_itfs[j];
         /* set the length of the vector to the number of unique itfs */
-        _vec_len(urpf->furpf_itfs) = i+1;
+        vec_set_len (urpf->furpf_itfs, i+1);
       }
 
     urpf->furpf_flags |= FIB_URPF_LIST_BAKED;
diff --git a/src/vnet/gso/node.c b/src/vnet/gso/node.c
index 093cd66..97bccc8 100644
--- a/src/vnet/gso/node.c
+++ b/src/vnet/gso/node.c
@@ -759,7 +759,7 @@
 					     to_next, n_left_to_next);
 		    }
 		  /* The buffers were enqueued. Reset the length */
-		  _vec_len (ptd->split_buffers) = 0;
+		  vec_set_len (ptd->split_buffers, 0);
 		  /* Free the now segmented buffer */
 		  vlib_buffer_free_one (vm, bi0);
 		  b += 1;
diff --git a/src/vnet/interface.c b/src/vnet/interface.c
index c44f264..9ce7f6f 100644
--- a/src/vnet/interface.c
+++ b/src/vnet/interface.c
@@ -163,7 +163,7 @@
   vec_serialize (m, sts, serialize_vec_vnet_sw_hw_interface_state);
 
   if (sts)
-    _vec_len (sts) = 0;
+    vec_set_len (sts, 0);
 
   /* *INDENT-OFF* */
   pool_foreach (hif, im->hw_interfaces)  {
@@ -992,7 +992,7 @@
 					  VLIB_NODE_RUNTIME_PERF_RESET);
 	}
 
-      _vec_len (im->deleted_hw_interface_nodes) -= 1;
+      vec_dec_len (im->deleted_hw_interface_nodes, 1);
     }
   else
     {
diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c
index 452849e..4de908f 100644
--- a/src/vnet/interface_cli.c
+++ b/src/vnet/interface_cli.c
@@ -415,7 +415,7 @@
       /* Gather interfaces. */
       sorted_sis =
 	vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
-      _vec_len (sorted_sis) = 0;
+      vec_set_len (sorted_sis, 0);
       /* *INDENT-OFF* */
       pool_foreach (si, im->sw_interfaces)
        {
@@ -1236,7 +1236,7 @@
     {
       sorted_sis =
 	vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
-      _vec_len (sorted_sis) = 0;
+      vec_set_len (sorted_sis, 0);
       /* *INDENT-OFF* */
       pool_foreach (si, im->sw_interfaces)
        {
diff --git a/src/vnet/interface_format.c b/src/vnet/interface_format.c
index 1ef4704..e34b6fb 100644
--- a/src/vnet/interface_format.c
+++ b/src/vnet/interface_format.c
@@ -369,11 +369,11 @@
       n_printed += 2;
 
       if (n)
-	_vec_len (n) = 0;
+	vec_set_len (n, 0);
       n = format (n, "%s packets", cm->name);
       s = format (s, "%-16v%16Ld", n, vtotal.packets);
 
-      _vec_len (n) = 0;
+      vec_set_len (n, 0);
       n = format (n, "%s bytes", cm->name);
       s = format (s, "\n%U%-16v%16Ld",
 		  format_white_space, indent, n, vtotal.bytes);
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c
index 3ff3a6c..ae4ee0c 100644
--- a/src/vnet/ip/ip_api.c
+++ b/src/vnet/ip/ip_api.c
@@ -1237,7 +1237,7 @@
 
   /* Gather interfaces. */
   sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
-  _vec_len (sorted_sis) = 0;
+  vec_set_len (sorted_sis, 0);
   /* *INDENT-OFF* */
   pool_foreach (si, im->sw_interfaces)
    {
diff --git a/src/vnet/ip/reass/ip4_full_reass.c b/src/vnet/ip/reass/ip4_full_reass.c
index 2201172..e4839aa 100644
--- a/src/vnet/ip/reass/ip4_full_reass.c
+++ b/src/vnet/ip/reass/ip4_full_reass.c
@@ -1615,7 +1615,7 @@
       vec_free (pool_indexes_to_free);
       if (event_data)
 	{
-	  _vec_len (event_data) = 0;
+	  vec_set_len (event_data, 0);
 	}
     }
 
diff --git a/src/vnet/ip/reass/ip4_sv_reass.c b/src/vnet/ip/reass/ip4_sv_reass.c
index 9971daf..dfe3f57 100644
--- a/src/vnet/ip/reass/ip4_sv_reass.c
+++ b/src/vnet/ip/reass/ip4_sv_reass.c
@@ -924,7 +924,8 @@
 						 to_next, n_left_to_next, bi0,
 						 next0);
 	      }
-	      _vec_len (reass->cached_buffers) = 0;	// buffers are owned by frame now
+	      vec_set_len (reass->cached_buffers,
+			   0); // buffers are owned by frame now
 	    }
 	  goto next_packet;
 
@@ -1303,7 +1304,7 @@
       vec_free (pool_indexes_to_free);
       if (event_data)
 	{
-	  _vec_len (event_data) = 0;
+	  vec_set_len (event_data, 0);
 	}
     }
 
diff --git a/src/vnet/ip/reass/ip6_full_reass.c b/src/vnet/ip/reass/ip6_full_reass.c
index 1bcb6bd..3b61d14 100644
--- a/src/vnet/ip/reass/ip6_full_reass.c
+++ b/src/vnet/ip/reass/ip6_full_reass.c
@@ -1647,7 +1647,7 @@
       vec_free (vec_icmp_bi);
       if (event_data)
 	{
-	  _vec_len (event_data) = 0;
+	  vec_set_len (event_data, 0);
 	}
     }
 
diff --git a/src/vnet/ip/reass/ip6_sv_reass.c b/src/vnet/ip/reass/ip6_sv_reass.c
index 23ae678..e1493c9 100644
--- a/src/vnet/ip/reass/ip6_sv_reass.c
+++ b/src/vnet/ip/reass/ip6_sv_reass.c
@@ -734,7 +734,8 @@
 						 to_next, n_left_to_next, bi0,
 						 next0);
 	      }
-	      _vec_len (reass->cached_buffers) = 0;	// buffers are owned by frame now
+	      vec_set_len (reass->cached_buffers,
+			   0); // buffers are owned by frame now
 	    }
 	  goto next_packet;
 
@@ -1050,7 +1051,7 @@
       vec_free (pool_indexes_to_free);
       if (event_data)
 	{
-	  _vec_len (event_data) = 0;
+	  vec_set_len (event_data, 0);
 	}
     }
 
diff --git a/src/vnet/ipsec/ipsec_cli.c b/src/vnet/ipsec/ipsec_cli.c
index 95e8145..c48d685 100644
--- a/src/vnet/ipsec/ipsec_cli.c
+++ b/src/vnet/ipsec/ipsec_cli.c
@@ -652,7 +652,7 @@
   }
   /* *INDENT-ON* */
   vlib_cli_output (vm, "%v", s);
-  _vec_len (s) = 0;
+  vec_set_len (s, 0);
   vlib_cli_output (vm, "IPsec ESP backends available:");
   s = format (s, "%=25s %=25s %=10s\n", "Name", "Index", "Active");
   ipsec_esp_backend_t *eb;
diff --git a/src/vnet/l2/l2_input.c b/src/vnet/l2/l2_input.c
index de22cef..b09555a 100644
--- a/src/vnet/l2/l2_input.c
+++ b/src/vnet/l2/l2_input.c
@@ -809,7 +809,7 @@
     {
       /* Gather interfaces. */
       sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
-      _vec_len (sis) = 0;
+      vec_set_len (sis, 0);
       /* *INDENT-OFF* */
       pool_foreach (si, im->sw_interfaces) { vec_add1 (sis, si[0]); }
       /* *INDENT-ON* */
diff --git a/src/vnet/pg/input.c b/src/vnet/pg/input.c
index 14c8b98..6f38ed0 100644
--- a/src/vnet/pg/input.c
+++ b/src/vnet/pg/input.c
@@ -965,7 +965,7 @@
   if (vec_len (unused_buffers) > 0)
     {
       vlib_buffer_free_no_next (vm, unused_buffers, vec_len (unused_buffers));
-      _vec_len (unused_buffers) = 0;
+      vec_set_len (unused_buffers, 0);
     }
 }
 
diff --git a/src/vnet/pg/pg.h b/src/vnet/pg/pg.h
index 963d23a..e69ee64 100644
--- a/src/vnet/pg/pg.h
+++ b/src/vnet/pg/pg.h
@@ -296,7 +296,7 @@
 
   pg_edit_group_free (g);
   clib_memset (g, 0, sizeof (g[0]));
-  _vec_len (s->edit_groups) = i;
+  vec_set_len (s->edit_groups, i);
 }
 
 typedef enum pg_interface_mode_t_
diff --git a/src/vnet/tcp/tcp_debug.c b/src/vnet/tcp/tcp_debug.c
index e3d7452..309b695 100644
--- a/src/vnet/tcp/tcp_debug.c
+++ b/src/vnet/tcp/tcp_debug.c
@@ -26,7 +26,7 @@
   if (fl_len)
     {
       track_index = tdm->free_track_indices[fl_len - 1];
-      _vec_len (tdm->free_track_indices) -= 1;
+      vec_dec_len (tdm->free_track_indices, 1);
       et->track_index_plus_one = track_index + 1;
     }
   else
diff --git a/src/vnet/tcp/tcp_input.c b/src/vnet/tcp/tcp_input.c
index 160619d..4950553 100644
--- a/src/vnet/tcp/tcp_input.c
+++ b/src/vnet/tcp/tcp_input.c
@@ -594,7 +594,7 @@
 
       tc->burst_acked = 0;
     }
-  _vec_len (wrk->pending_deq_acked) = 0;
+  vec_set_len (wrk->pending_deq_acked, 0);
 }
 
 static void
@@ -1099,7 +1099,7 @@
 	  tcp_disconnect_pending_off (tc);
 	  session_transport_closing_notify (&tc->connection);
 	}
-      _vec_len (wrk->pending_disconnects) = 0;
+      vec_set_len (wrk->pending_disconnects, 0);
     }
 
   if (vec_len (wrk->pending_resets))
@@ -1112,7 +1112,7 @@
 	  tcp_disconnect_pending_off (tc);
 	  tcp_handle_rst (tc);
 	}
-      _vec_len (wrk->pending_resets) = 0;
+      vec_set_len (wrk->pending_resets, 0);
     }
 }
 
diff --git a/src/vnet/udp/udp_inlines.h b/src/vnet/udp/udp_inlines.h
index d79dc9a..915f891 100644
--- a/src/vnet/udp/udp_inlines.h
+++ b/src/vnet/udp/udp_inlines.h
@@ -142,7 +142,7 @@
   udp_header_t *udp0, *udp1;
   int payload_ip4 = (payload_family == AF_IP4);
 
-  ASSERT (_vec_len (ec0) == _vec_len (ec1));
+  ASSERT (vec_len (ec0) == vec_len (ec1));
 
   if (payload_family < N_AF)
     {
diff --git a/src/vnet/unix/tuntap.c b/src/vnet/unix/tuntap.c
index c588cfd..1ce13e7 100644
--- a/src/vnet/unix/tuntap.c
+++ b/src/vnet/unix/tuntap.c
@@ -172,7 +172,7 @@
 
       /* Re-set iovecs if present. */
       if (tm->threads[thread_index].iovecs)
-	_vec_len (tm->threads[thread_index].iovecs) = 0;
+	vec_set_len (tm->threads[thread_index].iovecs, 0);
 
       /** VLIB buffer chain -> Unix iovec(s). */
       vec_add2 (tm->threads[thread_index].iovecs, iov, 1);
@@ -260,7 +260,7 @@
 	  vlib_buffer_alloc (vm,
 			     tm->threads[thread_index].rx_buffers + n_left,
 			     VLIB_FRAME_SIZE - n_left);
-	_vec_len (tm->threads[thread_index].rx_buffers) = n_left + n_alloc;
+	vec_set_len (tm->threads[thread_index].rx_buffers, n_left + n_alloc);
       }
   }
 
@@ -324,7 +324,7 @@
        + VNET_INTERFACE_COUNTER_RX,
        thread_index, tm->sw_if_index, 1, n_bytes_in_packet);
 
-    _vec_len (tm->threads[thread_index].rx_buffers) = i_rx;
+    vec_set_len (tm->threads[thread_index].rx_buffers, i_rx);
   }
 
   b = vlib_get_buffer (vm, bi);
diff --git a/src/vnet/vxlan-gpe/vxlan_gpe.c b/src/vnet/vxlan-gpe/vxlan_gpe.c
index 8ef94d4..a926847 100644
--- a/src/vnet/vxlan-gpe/vxlan_gpe.c
+++ b/src/vnet/vxlan-gpe/vxlan_gpe.c
@@ -544,7 +544,7 @@
 	  vnet_interface_main_t *im = &vnm->interface_main;
 	  hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
 	    [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) - 1];
-	  _vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) -= 1;
+	  vec_dec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices, 1);
 
 	  hi = vnet_get_hw_interface (vnm, hw_if_index);
 	  hi->dev_instance = t - ngm->tunnels;
diff --git a/src/vpp/api/api_main.c b/src/vpp/api/api_main.c
index 63bb5f2..47d9748 100644
--- a/src/vpp/api/api_main.c
+++ b/src/vpp/api/api_main.c
@@ -176,7 +176,7 @@
   maybe_register_api_client (vam);
 
   /* vec_validated in the init routine */
-  _vec_len (vam->inbuf) = 0;
+  vec_set_len (vam->inbuf, 0);
 
   vam->input = &_input;
 
diff --git a/src/vpp/api/plugin.c b/src/vpp/api/plugin.c
index 3d89161..e7ca874 100644
--- a/src/vpp/api/plugin.c
+++ b/src/vpp/api/plugin.c
@@ -170,7 +170,7 @@
 		{
 		  vec_free (file_name);
 		  vec_free (plugin_name);
-		  _vec_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1;
+		  vec_set_len (pm->plugin_info, vec_len (pm->plugin_info) - 1);
 		  continue;
 		}
 	      hash_set_mem (pm->plugin_by_name_hash, plugin_name,
diff --git a/src/vppinfra/bitmap.h b/src/vppinfra/bitmap.h
index 096d3f1..02f9c7e 100644
--- a/src/vppinfra/bitmap.h
+++ b/src/vppinfra/bitmap.h
@@ -142,7 +142,7 @@
       for (i = _vec_len (a) - 1; i >= 0; i--)
 	if (a[i] != 0)
 	  break;
-      _vec_len (a) = i + 1;
+      vec_set_len (a, i + 1);
     }
   return a;
 }
@@ -518,29 +518,32 @@
 always_inline uword *clib_bitmap_xor (uword * ai, uword * bi);
 
 /* ALU function definition macro for functions taking two bitmaps. */
-#define _(name, body, check_zero)				\
-always_inline uword *						\
-clib_bitmap_##name (uword * ai, uword * bi)			\
-{								\
-  uword i, a, b, bi_len, n_trailing_zeros;			\
-								\
-  n_trailing_zeros = 0;						\
-  bi_len = vec_len (bi);					\
-  if (bi_len > 0)						\
-    clib_bitmap_vec_validate (ai, bi_len - 1);			\
-  for (i = 0; i < vec_len (ai); i++)				\
-    {								\
-      a = ai[i];						\
-      b = i < bi_len ? bi[i] : 0;				\
-      do { body; } while (0);					\
-      ai[i] = a;						\
-      if (check_zero)						\
-	n_trailing_zeros = a ? 0 : (n_trailing_zeros + 1);	\
-    }								\
-  if (check_zero)						\
-    _vec_len (ai) -= n_trailing_zeros;				\
-  return ai;							\
-}
+#define _(name, body, check_zero)                                             \
+  always_inline uword *clib_bitmap_##name (uword *ai, uword *bi)              \
+  {                                                                           \
+    uword i, a, b, bi_len, n_trailing_zeros;                                  \
+                                                                              \
+    n_trailing_zeros = 0;                                                     \
+    bi_len = vec_len (bi);                                                    \
+    if (bi_len > 0)                                                           \
+      clib_bitmap_vec_validate (ai, bi_len - 1);                              \
+    for (i = 0; i < vec_len (ai); i++)                                        \
+      {                                                                       \
+	a = ai[i];                                                            \
+	b = i < bi_len ? bi[i] : 0;                                           \
+	do                                                                    \
+	  {                                                                   \
+	    body;                                                             \
+	  }                                                                   \
+	while (0);                                                            \
+	ai[i] = a;                                                            \
+	if (check_zero)                                                       \
+	  n_trailing_zeros = a ? 0 : (n_trailing_zeros + 1);                  \
+      }                                                                       \
+    if (check_zero)                                                           \
+      vec_dec_len (ai, n_trailing_zeros);                                     \
+    return ai;                                                                \
+  }
 
 /* ALU functions: */
 /* *INDENT-OFF* */
diff --git a/src/vppinfra/elf.c b/src/vppinfra/elf.c
index 7a74fad..d11fd7e 100644
--- a/src/vppinfra/elf.c
+++ b/src/vppinfra/elf.c
@@ -1975,7 +1975,7 @@
   if ((p = hash_get_mem (em->section_by_name, section_name)))
     {
       s = vec_elt_at_index (em->sections, p[0]);
-      _vec_len (s->contents) = 0;
+      vec_set_len (s->contents, 0);
       c = s->contents;
     }
   else
diff --git a/src/vppinfra/elog.c b/src/vppinfra/elog.c
index 8ae752e..ddc09a3 100644
--- a/src/vppinfra/elog.c
+++ b/src/vppinfra/elog.c
@@ -494,7 +494,7 @@
   em->event_ring_size = n_events = max_pow2 (n_events);
 
   vec_validate_aligned (em->event_ring, n_events, CLIB_CACHE_LINE_BYTES);
-  _vec_len (em->event_ring) = n_events;
+  vec_set_len (em->event_ring, n_events);
 }
 
 __clib_export void
diff --git a/src/vppinfra/fifo.h b/src/vppinfra/fifo.h
index 611fadb..b6a8b8f 100644
--- a/src/vppinfra/fifo.h
+++ b/src/vppinfra/fifo.h
@@ -91,7 +91,7 @@
   if (v)
     {
       f->head_index = f->tail_index = 0;
-      _vec_len (v) = 0;
+      vec_set_len (v, 0);
     }
 }
 
diff --git a/src/vppinfra/format.c b/src/vppinfra/format.c
index ccd999e..cf17b8a 100644
--- a/src/vppinfra/format.c
+++ b/src/vppinfra/format.c
@@ -114,7 +114,7 @@
     l0 = l1;
 
   if (l1 > l0)
-    _vec_len (s) = l0;
+    vec_set_len (s, l0);
   else if (l0 > l1)
     {
       uword n = l0 - l1;
diff --git a/src/vppinfra/hash.c b/src/vppinfra/hash.c
index df740c5..7deff4a 100644
--- a/src/vppinfra/hash.c
+++ b/src/vppinfra/hash.c
@@ -342,7 +342,7 @@
       else
 	zero_pair (h, q);
       if (is_vec)
-	_vec_len (pi->pairs) -= 1;
+	vec_dec_len (pi->pairs, 1);
       else
 	indirect_pair_set (pi, indirect_pair_get_log2_bytes (pi), len - 1);
     }
diff --git a/src/vppinfra/heap.c b/src/vppinfra/heap.c
index 47b6cf5..066756b 100644
--- a/src/vppinfra/heap.c
+++ b/src/vppinfra/heap.c
@@ -139,7 +139,7 @@
   if (e < l)
     vec_add1 (h->free_elts, e - h->elts);
   else
-    _vec_len (h->elts)--;
+    vec_dec_len (h->elts, 1);
 }
 
 /*
@@ -200,7 +200,7 @@
   if ((l = vec_len (h->free_elts)) > 0)
     {
       e = elt_at (h, h->free_elts[l - 1]);
-      _vec_len (h->free_elts) -= 1;
+      vec_dec_len (h->free_elts, 1);
     }
   else
     vec_add2 (h->elts, e, 1);
@@ -276,7 +276,7 @@
       h->free_lists[b][i] = t;
       set_free_elt (v, elt_at (h, t), i);
     }
-  _vec_len (h->free_lists[b]) = l - 1;
+  vec_set_len (h->free_lists[b], l - 1);
 }
 
 static heap_elt_t *
@@ -425,7 +425,7 @@
 	v = _vec_realloc (v, offset + align_size, elt_bytes, sizeof (h[0]),
 			  HEAP_DATA_ALIGN, 0);
       else
-	_vec_len (v) += align_size;
+	vec_inc_len (v, align_size);
 
       if (offset == 0)
 	{
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 6c3e036..9cf598d 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -261,7 +261,7 @@
 
   /* memfd_create maximum string size is 249 chars without trailing zero */
   if (vec_len (s) > 249)
-    _vec_len (s) = 249;
+    vec_set_len (s, 249);
   vec_add1 (s, 0);
 
   /* memfd_create introduced in kernel 3.17, we don't support older kernels */
diff --git a/src/vppinfra/linux/sysfs.c b/src/vppinfra/linux/sysfs.c
index 758eaa1..a3e122c 100644
--- a/src/vppinfra/linux/sysfs.c
+++ b/src/vppinfra/linux/sysfs.c
@@ -70,7 +70,7 @@
       return clib_error_return_unix (0, "read `%s'", file_name);
     }
 
-  _vec_len (s) = sz;
+  vec_set_len (s, sz);
   unformat_init_vector (&input, s);
 
   va_list va;
@@ -154,7 +154,7 @@
       goto done;
     }
 
-  _vec_len (p) -= 1;
+  vec_dec_len (p, 1);
   p = format (p, "/hugepages/hugepages-%ukB/nr_hugepages%c", page_size, 0);
   clib_sysfs_write ((char *) p, "%d", nr);
 
@@ -207,7 +207,7 @@
       goto done;
     }
 
-  _vec_len (p) -= 1;
+  vec_dec_len (p, 1);
   p = format (p, "/hugepages/hugepages-%ukB/%s_hugepages%c", page_size,
 	      type, 0);
   error = clib_sysfs_read ((char *) p, "%d", val);
diff --git a/src/vppinfra/macros.c b/src/vppinfra/macros.c
index b8a8e17..27a92a8 100644
--- a/src/vppinfra/macros.c
+++ b/src/vppinfra/macros.c
@@ -175,7 +175,7 @@
 	      /* add results to answer */
 	      vec_append (rv, ts);
 	      /* Remove NULL termination or the results are sad */
-	      _vec_len (rv) = vec_len (rv) - 1;
+	      vec_set_len (rv, vec_len (rv) - 1);
 	      vec_free (ts);
 	    }
 	  else
@@ -183,8 +183,7 @@
 	      if (complain)
 		clib_warning ("Undefined Variable Reference: %s\n", varname);
 	      vec_append (rv, format (0, "UNSET "));
-	      _vec_len (rv) = vec_len (rv) - 1;
-
+	      vec_set_len (rv, vec_len (rv) - 1);
 	    }
 	  vec_free (varname);
 	}
diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c
index 3829e7c..fdde720 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -101,7 +101,7 @@
       if (i > 0)
 	{
 	  trace_index = tm->trace_free_list[i - 1];
-	  _vec_len (tm->trace_free_list) = i - 1;
+	  vec_set_len (tm->trace_free_list, i - 1);
 	}
       else
 	{
diff --git a/src/vppinfra/mhash.c b/src/vppinfra/mhash.c
index c556312..f0f1aa4 100644
--- a/src/vppinfra/mhash.c
+++ b/src/vppinfra/mhash.c
@@ -295,7 +295,7 @@
 	{
 	  i = h->key_vector_free_indices[l - 1];
 	  k = vec_elt_at_index (h->key_vector_or_heap, i);
-	  _vec_len (h->key_vector_free_indices) = l - 1;
+	  vec_set_len (h->key_vector_free_indices, l - 1);
 	}
       else
 	{
@@ -332,10 +332,10 @@
 	  if (key_alloc_from_free_list)
 	    {
 	      h->key_vector_free_indices[l] = i;
-	      _vec_len (h->key_vector_free_indices) = l + 1;
+	      vec_set_len (h->key_vector_free_indices, l + 1);
 	    }
 	  else
-	    _vec_len (h->key_vector_or_heap) -= h->n_key_bytes;
+	    vec_dec_len (h->key_vector_or_heap, h->n_key_bytes);
 	}
     }
 
diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h
index 4db1f7b..9f9194f 100644
--- a/src/vppinfra/pool.h
+++ b/src/vppinfra/pool.h
@@ -184,7 +184,7 @@
 	  e = p + index * elt_sz;
 	  ph->free_bitmap =
 	    clib_bitmap_andnoti_notrim (ph->free_bitmap, index);
-	  _vec_len (ph->free_indices) = n_free - 1;
+	  vec_set_len (ph->free_indices, n_free - 1);
 	  CLIB_MEM_UNPOISON (e, elt_sz);
 	  goto done;
 	}
@@ -294,7 +294,7 @@
   if (ph->max_elts)
     {
       ph->free_indices[_vec_len (ph->free_indices)] = index;
-      _vec_len (ph->free_indices) += 1;
+      vec_inc_len (ph->free_indices, 1);
     }
   else
     vec_add1 (ph->free_indices, index);
@@ -321,12 +321,12 @@
 
   pp[0] = _vec_realloc_inline (pp[0], len + n_elts, elt_sz,
 			       sizeof (pool_header_t), align, heap);
-  _vec_len (pp[0]) = len;
+  _vec_set_len (pp[0], len, elt_sz);
   CLIB_MEM_POISON (pp[0] + len * elt_sz, n_elts * elt_sz);
 
   ph = pool_header (pp[0]);
   vec_resize (ph->free_indices, n_elts);
-  _vec_len (ph->free_indices) -= n_elts;
+  vec_dec_len (ph->free_indices, n_elts);
   clib_bitmap_vec_validate (ph->free_bitmap, len + n_elts - 1);
 }
 
diff --git a/src/vppinfra/random_buffer.h b/src/vppinfra/random_buffer.h
index dded531..078e960 100644
--- a/src/vppinfra/random_buffer.h
+++ b/src/vppinfra/random_buffer.h
@@ -100,7 +100,7 @@
     clib_random_buffer_fill (b, n_words);
 
   i = vec_len (b->buffer) - n_words;
-  _vec_len (b->buffer) = i;
+  vec_set_len (b->buffer, i);
 
   if (n_bytes < sizeof (uword))
     {
diff --git a/src/vppinfra/serialize.c b/src/vppinfra/serialize.c
index 95eca96..d84d7ca 100644
--- a/src/vppinfra/serialize.c
+++ b/src/vppinfra/serialize.c
@@ -714,7 +714,7 @@
 	  n_left_b -= n;
 	  n_left_o -= n;
 	  if (n_left_o == 0)
-	    _vec_len (s->overflow_buffer) = 0;
+	    vec_set_len (s->overflow_buffer, 0);
 	  else
 	    vec_delete (s->overflow_buffer, n, 0);
 	}
@@ -771,7 +771,7 @@
   if (n_left_o == 0 && s->overflow_buffer)
     {
       s->current_overflow_index = 0;
-      _vec_len (s->overflow_buffer) = 0;
+      vec_set_len (s->overflow_buffer, 0);
     }
 
   n_left_to_read = n_bytes_to_read;
@@ -923,7 +923,7 @@
   serialize_close (m);		/* frees overflow buffer */
 
   if (s->buffer)
-    _vec_len (s->buffer) = s->current_buffer_index;
+    vec_set_len (s->buffer, s->current_buffer_index);
   result = s->buffer;
   clib_memset (m, 0, sizeof (m[0]));
   return result;
@@ -1161,7 +1161,7 @@
 	serialize_error (m, clib_error_return_unix (0, "write"));
     }
   if (n == s->current_buffer_index)
-    _vec_len (s->buffer) = 0;
+    vec_set_len (s->buffer, 0);
   else
     vec_delete (s->buffer, n, 0);
   s->current_buffer_index = vec_len (s->buffer);
@@ -1197,7 +1197,7 @@
   if (!is_read)
     {
       m->stream.n_buffer_bytes = vec_len (m->stream.buffer);
-      _vec_len (m->stream.buffer) = 0;
+      vec_set_len (m->stream.buffer, 0);
     }
 
   m->header.data_function = is_read ? clib_file_read : clib_file_write;
diff --git a/src/vppinfra/socket.c b/src/vppinfra/socket.c
index a09a390..a3024ae 100644
--- a/src/vppinfra/socket.c
+++ b/src/vppinfra/socket.c
@@ -230,7 +230,7 @@
   else if (written > 0)
     {
       if (written == tx_len)
-	_vec_len (s->tx_buffer) = 0;
+	vec_set_len (s->tx_buffer, 0);
       else
 	vec_delete (s->tx_buffer, written, 0);
     }
@@ -278,7 +278,7 @@
     sock->flags |= CLIB_SOCKET_F_RX_END_OF_FILE;
 
 non_fatal:
-  _vec_len (sock->rx_buffer) += n_read - n_bytes;
+  vec_inc_len (sock->rx_buffer, n_read - n_bytes);
 
   return 0;
 }
diff --git a/src/vppinfra/sparse_vec.h b/src/vppinfra/sparse_vec.h
index 6cab868..dc9cb00 100644
--- a/src/vppinfra/sparse_vec.h
+++ b/src/vppinfra/sparse_vec.h
@@ -81,7 +81,7 @@
 		    /* heap */ 0);
 
   /* Make space for invalid entry (entry 0). */
-  _vec_len (v) = 1;
+  _vec_find (v)->len = 1;
 
   h = sparse_vec_header (v);
 
diff --git a/src/vppinfra/test_bihash_template.c b/src/vppinfra/test_bihash_template.c
index ffed5c7..155b8bd 100644
--- a/src/vppinfra/test_bihash_template.c
+++ b/src/vppinfra/test_bihash_template.c
@@ -522,8 +522,7 @@
   /* Preallocate hash table, key vector */
   tm->key_hash = hash_create (tm->nitems, sizeof (uword));
   vec_validate (tm->keys, tm->nitems - 1);
-  _vec_len (tm->keys) = 0;
-
+  vec_set_len (tm->keys, 0);
 
   switch (which)
     {
diff --git a/src/vppinfra/test_fpool.c b/src/vppinfra/test_fpool.c
index e2d67f1..02d9d21 100644
--- a/src/vppinfra/test_fpool.c
+++ b/src/vppinfra/test_fpool.c
@@ -30,7 +30,7 @@
   clib_mem_init (0, 3ULL << 30);
 
   vec_validate (indices, NELTS - 1);
-  _vec_len (indices) = 0;
+  vec_set_len (indices, 0);
 
   pool_init_fixed (tp, NELTS);
 
diff --git a/src/vppinfra/test_socket.c b/src/vppinfra/test_socket.c
index ea0ae65..3a0e6b2 100644
--- a/src/vppinfra/test_socket.c
+++ b/src/vppinfra/test_socket.c
@@ -99,7 +99,7 @@
 	break;
 
       if_verbose ("%v", s->rx_buffer);
-      _vec_len (s->rx_buffer) = 0;
+      vec_set_len (s->rx_buffer, 0);
     }
 
   error = clib_socket_close (s);
diff --git a/src/vppinfra/timing_wheel.c b/src/vppinfra/timing_wheel.c
index 2c46d72..edd8782 100644
--- a/src/vppinfra/timing_wheel.c
+++ b/src/vppinfra/timing_wheel.c
@@ -185,7 +185,7 @@
   /* Poison free elements so we never use them by mistake. */
   if (CLIB_DEBUG > 0)
     clib_memset (ev, ~0, vec_len (ev) * sizeof (ev[0]));
-  _vec_len (ev) = 0;
+  vec_set_len (ev, 0);
   vec_add1 (w->free_elt_vectors, ev);
 }
 
@@ -459,7 +459,7 @@
 
   /* Adjust for deleted elts. */
   if (j < e_len)
-    _vec_len (expired_user_data) -= e_len - j;
+    vec_dec_len (expired_user_data, e_len - j);
 
   free_elt_vector (w, e);
 
@@ -613,7 +613,7 @@
     if (PREDICT_FALSE (current_ti != advance_ti))
       {
 	if (w->unexpired_elts_pending_insert)
-	  _vec_len (w->unexpired_elts_pending_insert) = 0;
+	  vec_set_len (w->unexpired_elts_pending_insert, 0);
 
 	level_index = 0;
 	while (current_ti != advance_ti)
@@ -684,7 +684,7 @@
     {
       timing_wheel_elt_t *e;
       vec_foreach (e, w->unexpired_elts_pending_insert) insert_elt (w, e);
-      _vec_len (w->unexpired_elts_pending_insert) = 0;
+      vec_set_len (w->unexpired_elts_pending_insert, 0);
     }
 
   /* Don't advance until necessary. */
diff --git a/src/vppinfra/tw_timer_template.c b/src/vppinfra/tw_timer_template.c
index 97c70b2..6e8a58d 100644
--- a/src/vppinfra/tw_timer_template.c
+++ b/src/vppinfra/tw_timer_template.c
@@ -424,7 +424,7 @@
   tw->ticks_per_second = 1.0 / timer_interval_in_seconds;
 
   vec_validate (tw->expired_timer_handles, 0);
-  _vec_len (tw->expired_timer_handles) = 0;
+  vec_set_len (tw->expired_timer_handles, 0);
 
   for (ring = 0; ring < TW_TIMER_WHEELS; ring++)
     {
@@ -536,7 +536,7 @@
 
   if (callback_vector_arg == 0)
     {
-      _vec_len (tw->expired_timer_handles) = 0;
+      vec_set_len (tw->expired_timer_handles, 0);
       callback_vector = tw->expired_timer_handles;
     }
   else
diff --git a/src/vppinfra/unformat.c b/src/vppinfra/unformat.c
index 3904b45..e8e5c28 100644
--- a/src/vppinfra/unformat.c
+++ b/src/vppinfra/unformat.c
@@ -952,7 +952,7 @@
     if (!input_matches_format)
       input->index = input->buffer_marks[l - 1];
 
-    _vec_len (input->buffer_marks) = l - 1;
+    vec_set_len (input->buffer_marks, l - 1);
   }
 
   return input_matches_format;
@@ -987,7 +987,7 @@
   if (!result && input->index != UNFORMAT_END_OF_INPUT)
     input->index = input->buffer_marks[l];
 
-  _vec_len (input->buffer_marks) = l;
+  vec_set_len (input->buffer_marks, l);
 
   return result;
 }
@@ -1037,7 +1037,7 @@
   vec_resize (input->buffer, 4096);
   n = read (fd, input->buffer + l, 4096);
   if (n > 0)
-    _vec_len (input->buffer) = l + n;
+    vec_set_len (input->buffer, l + n);
 
   if (n <= 0)
     return UNFORMAT_END_OF_INPUT;
diff --git a/src/vppinfra/unix-misc.c b/src/vppinfra/unix-misc.c
index 5559a23..e73d01a 100644
--- a/src/vppinfra/unix-misc.c
+++ b/src/vppinfra/unix-misc.c
@@ -158,7 +158,7 @@
 
       if (bytes == 0)
 	{
-	  _vec_len (rv) = pos;
+	  vec_set_len (rv, pos);
 	  break;
 	}
       pos += bytes;
diff --git a/src/vppinfra/vec.c b/src/vppinfra/vec.c
index 805fdc0..8bd0ec0 100644
--- a/src/vppinfra/vec.c
+++ b/src/vppinfra/vec.c
@@ -83,7 +83,7 @@
     }
 
   CLIB_MEM_POISON (p + new_data_size, alloc_size - new_data_size);
-  _vec_len (v) = n_elts;
+  _vec_find (v)->len = n_elts;
   return v;
 }
 
diff --git a/src/vppinfra/vec_bootstrap.h b/src/vppinfra/vec_bootstrap.h
index d6451f3..0054802 100644
--- a/src/vppinfra/vec_bootstrap.h
+++ b/src/vppinfra/vec_bootstrap.h
@@ -116,21 +116,21 @@
   return v + vec_get_header_size (v);
 }
 
-/** \brief Number of elements in vector (lvalue-capable)
-
-   _vec_len (v) does not check for null, but can be used as an lvalue
-   (e.g. _vec_len (v) = 99).
-*/
-
-#define _vec_len(v)	(_vec_find(v)->len)
-
 /** \brief Number of elements in vector (rvalue-only, NULL tolerant)
 
     vec_len (v) checks for NULL, but cannot be used as an lvalue.
     If in doubt, use vec_len...
 */
 
+static_always_inline u32
+__vec_len (void *v)
+{
+  return _vec_find (v)->len;
+}
+
+#define _vec_len(v)	__vec_len ((void *) (v))
 #define vec_len(v)	((v) ? _vec_len(v) : 0)
+
 u32 vec_len_not_inline (void *v);
 
 /** \brief Number of data bytes in vector. */
@@ -180,10 +180,12 @@
   else if (len > old_len)
     CLIB_MEM_POISON (v + len * elt_sz, (old_len - len) * elt_sz);
 
-  _vec_len (v) = len;
+  _vec_find (v)->len = len;
 }
 
 #define vec_set_len(v, l) _vec_set_len ((void *) v, l, _vec_elt_sz (v))
+#define vec_inc_len(v, l) vec_set_len (v, _vec_len (v) + (l))
+#define vec_dec_len(v, l) vec_set_len (v, _vec_len (v) - (l))
 
 /** \brief Reset vector length to zero
     NULL-pointer tolerant