pipes: fix the l2.l2_len and the l[23]_hdr_offset setting behavior of pipe-rx node to match that of ethernet-input node

Since pipe-rx is a sibling node of ethernet-input, it ought to perform similarly: set l2/l3 header offsets,
and l2.l2_len value if the interface is in the l2 mode.

The use cases of pipes do not assume the tagged traffic, so
assume the simple ethernet header.

Change-Id: I7c9b5f4f2b1402cfbd10513f76cdd59b2db7a7a6
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
diff --git a/src/vnet/devices/pipe/pipe.c b/src/vnet/devices/pipe/pipe.c
index 9d38886..6154a66 100644
--- a/src/vnet/devices/pipe/pipe.c
+++ b/src/vnet/devices/pipe/pipe.c
@@ -359,35 +359,37 @@
 	  pipe0 = &pipe_main.pipes[sw_if_index0];
 	  pipe1 = &pipe_main.pipes[sw_if_index1];
 
+	  vnet_buffer (b0)->l2_hdr_offset = b0->current_data;
+	  vnet_buffer (b1)->l2_hdr_offset = b1->current_data;
+
 	  vnet_buffer (b0)->l3_hdr_offset =
-	    vnet_buffer (b0)->l2_hdr_offset + vnet_buffer (b0)->l2.l2_len;
+	    vnet_buffer (b0)->l2_hdr_offset + sizeof (ethernet_header_t);
 	  vnet_buffer (b1)->l3_hdr_offset =
-	    vnet_buffer (b1)->l2_hdr_offset + vnet_buffer (b1)->l2.l2_len;
-	  b0->flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
-	  b1->flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
+	    vnet_buffer (b1)->l2_hdr_offset + sizeof (ethernet_header_t);
+	  b0->flags |=
+	    VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
+	    VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
+	  b1->flags |=
+	    VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
+	    VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
 
 	  is_l20 = pipe0->subint.flags & SUBINT_CONFIG_L2;
 	  is_l21 = pipe1->subint.flags & SUBINT_CONFIG_L2;
+
+	  /*
+	   * from discussion with Neale - we do not support the tagged traffic.
+	   * So assume a simple ethernet header
+	   */
+	  vnet_buffer (b0)->l2.l2_len = sizeof (ethernet_header_t);
+	  vnet_buffer (b1)->l2.l2_len = sizeof (ethernet_header_t);
+	  vlib_buffer_advance (b0, is_l20 ? 0 : sizeof (ethernet_header_t));
+	  vlib_buffer_advance (b1, is_l21 ? 0 : sizeof (ethernet_header_t));
+
 	  pipe_determine_next_node (&ethernet_main, is_l20, type0, b0,
 				    &next0);
 	  pipe_determine_next_node (&ethernet_main, is_l21, type1, b1,
 				    &next1);
 
-	  if (!is_l20)
-	    vlib_buffer_advance (b0, sizeof (ethernet_header_t));
-	  else
-	    {
-	      u32 eth_start = vnet_buffer (b0)->l2_hdr_offset;
-	      vnet_buffer (b0)->l2.l2_len = b0->current_data - eth_start;
-	    }
-	  if (!is_l21)
-	    vlib_buffer_advance (b1, sizeof (ethernet_header_t));
-	  else
-	    {
-	      u32 eth_start = vnet_buffer (b1)->l2_hdr_offset;
-	      vnet_buffer (b1)->l2.l2_len = b1->current_data - eth_start;
-	    }
-
 	  vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
 					   to_next, n_left_to_next,
 					   bi0, bi1, next0, next1);
@@ -416,22 +418,21 @@
 	  type0 = clib_net_to_host_u16 (e0->type);
 	  pipe0 = &pipe_main.pipes[sw_if_index0];
 
+	  vnet_buffer (b0)->l2_hdr_offset = b0->current_data;
 	  vnet_buffer (b0)->l3_hdr_offset =
-	    vnet_buffer (b0)->l2_hdr_offset + vnet_buffer (b0)->l2.l2_len;
-	  b0->flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
+	    vnet_buffer (b0)->l2_hdr_offset + sizeof (ethernet_header_t);
+	  b0->flags |=
+	    VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
+	    VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
 
 	  is_l20 = pipe0->subint.flags & SUBINT_CONFIG_L2;
+
+	  vnet_buffer (b0)->l2.l2_len = sizeof (ethernet_header_t);
+	  vlib_buffer_advance (b0, is_l20 ? 0 : sizeof (ethernet_header_t));
+
 	  pipe_determine_next_node (&ethernet_main, is_l20, type0, b0,
 				    &next0);
 
-	  if (!is_l20)
-	    vlib_buffer_advance (b0, sizeof (ethernet_header_t));
-	  else
-	    {
-	      u32 eth_start = vnet_buffer (b0)->l2_hdr_offset;
-	      vnet_buffer (b0)->l2.l2_len = b0->current_data - eth_start;
-	    }
-
 	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
 					   to_next, n_left_to_next,
 					   bi0, next0);