ETH:fix l2_len/vlan count mismatch for > 2 tags
[vpp.git] / src / vnet / ethernet / node.c
index f7787ed..4529ca6 100755 (executable)
@@ -142,6 +142,8 @@ parse_header (ethernet_input_variant_t variant,
       tag = clib_net_to_host_u16 (h0->priority_cfi_and_id);
 
       *outer_id = tag & 0xfff;
+      if (0 == *outer_id)
+       *match_flags &= ~SUBINT_CONFIG_MATCH_1_TAG;
 
       *type = clib_net_to_host_u16 (h0->type);
 
@@ -163,11 +165,12 @@ parse_header (ethernet_input_variant_t variant,
 
          vlib_buffer_advance (b0, sizeof (h0[0]));
          vlan_count = 2;
-
          if (*type == ETHERNET_TYPE_VLAN)
            {
              // More than double tagged packet
              *match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_3_TAG;
+
+             vlib_buffer_advance (b0, sizeof (h0[0]));
              vlan_count = 3;   // "unknown" number, aka, 3-or-more
            }
        }
@@ -237,6 +240,8 @@ determine_next_node (ethernet_main_t * em,
       // record the L2 len and reset the buffer so the L2 header is preserved
       u32 eth_start = vnet_buffer (b0)->ethernet.start_of_ethernet_header;
       vnet_buffer (b0)->l2.l2_len = b0->current_data - eth_start;
+      ASSERT (vnet_buffer (b0)->l2.l2_len ==
+             ethernet_buffer_header_size (b0));
       vlib_buffer_advance (b0, -ethernet_buffer_header_size (b0));
 
       // check for common IP/MPLS ethertypes
@@ -249,7 +254,7 @@ determine_next_node (ethernet_main_t * em,
     {
       *next0 = em->l3_next.input_next_ip6;
     }
-  else if (type0 == ETHERNET_TYPE_MPLS_UNICAST)
+  else if (type0 == ETHERNET_TYPE_MPLS)
     {
       *next0 = em->l3_next.input_next_mpls;
 
@@ -412,9 +417,11 @@ ethernet_input_inline (vlib_main_t * vm,
              else
                {
                  if (!ethernet_address_cast (e0->dst_address) &&
+                     (hi->hw_address != 0) &&
                      !eth_mac_equal ((u8 *) e0, hi->hw_address))
                    error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
                  if (!ethernet_address_cast (e1->dst_address) &&
+                     (hi->hw_address != 0) &&
                      !eth_mac_equal ((u8 *) e1, hi->hw_address))
                    error1 = ETHERNET_ERROR_L3_MAC_MISMATCH;
                  determine_next_node (em, variant, 0, type0, b0,
@@ -628,6 +635,7 @@ ethernet_input_inline (vlib_main_t * vm,
              else
                {
                  if (!ethernet_address_cast (e0->dst_address) &&
+                     (hi->hw_address != 0) &&
                      !eth_mac_equal ((u8 *) e0, hi->hw_address))
                    error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
                  determine_next_node (em, variant, 0, type0, b0,
@@ -1252,7 +1260,7 @@ next_by_ethertype_register (next_by_ethertype_t * l3_next,
        {
          l3_next->input_next_ip6 = next_index;
        }
-      else if (ethertype == ETHERNET_TYPE_MPLS_UNICAST)
+      else if (ethertype == ETHERNET_TYPE_MPLS)
        {
          l3_next->input_next_mpls = next_index;
        }