ipsec: IPSec protection for multi-point tunnel interfaces
[vpp.git] / src / vnet / pg / edit.c
index 8d1437e..df057d2 100644 (file)
@@ -129,16 +129,19 @@ unformat_pg_payload (unformat_input_t * input, va_list * args)
   pg_stream_t *s = va_arg (*args, pg_stream_t *);
   vlib_main_t *vm = vlib_get_main ();
   pg_edit_t *e;
-  u32 i, node_index, len, max_len, ilen;
+  u32 i, node_index, len, max_len;
   u8 *v;
 
   v = 0;
 
-  if (unformat (input, "incrementing %d", &ilen))
-    ;
+  if (unformat (input, "incrementing %d", &len))
+    {
+      vec_resize (v, len);
+      for (i = 0; i < len; i++)
+       v[i] = i % len;
+    }
   else if (unformat (input, "hex 0x%U", unformat_hex_string, &v))
     ;
-
   else if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
     {
       pg_node_t *pn = pg_get_node (node_index);
@@ -152,6 +155,7 @@ unformat_pg_payload (unformat_input_t * input, va_list * args)
 
   /* Length not including this payload. */
   max_len = pg_edit_group_n_bytes (s, 0);
+
   if (max_len >= s->max_packet_bytes)
     {
       /* no payload */
@@ -164,16 +168,14 @@ unformat_pg_payload (unformat_input_t * input, va_list * args)
     }
 
   vec_resize (v, len);
-  for (i = 0; i < len; i++)
-    v[i] = i % ilen;
 
-  e = pg_create_edit_group (s, sizeof (e[0]), vec_len (v), 0);
+  e = pg_create_edit_group (s, sizeof (e[0]), len, 0);
 
   e->type = PG_EDIT_FIXED;
-  e->n_bits = vec_len (v) * BITS (v[0]);
+  e->n_bits = len * BITS (v[0]);
 
   /* Least significant bit is at end of bitstream, since everything is always bigendian. */
-  e->lsb_bit_offset = e->n_bits - BITS (v[0]);
+  e->lsb_bit_offset = len > 0 ? e->n_bits - BITS (v[0]) : 0;
 
   e->values[PG_EDIT_LO] = v;