- u32 bi0, bi1;
- vlib_buffer_t *b0, *b1;
- gre_header_t *h0, *h1;
- u16 version0, version1;
- int verr0, verr1;
- u32 i0, i1, next0, next1, protocol0, protocol1;
- ip4_header_t *ip4_0, *ip4_1;
- ip6_header_t *ip6_0, *ip6_1;
- u32 ip4_tun_src0, ip4_tun_dst0;
- u32 ip4_tun_src1, ip4_tun_dst1;
- u64 ip6_tun_src0[2], ip6_tun_dst0[2];
- u64 ip6_tun_src1[2], ip6_tun_dst1[2];
-
- /* Prefetch next iteration. */
- {
- vlib_buffer_t *p2, *p3;
-
- p2 = vlib_get_buffer (vm, from[2]);
- p3 = vlib_get_buffer (vm, from[3]);
-
- vlib_prefetch_buffer_header (p2, LOAD);
- vlib_prefetch_buffer_header (p3, LOAD);
-
- CLIB_PREFETCH (p2->data, sizeof (h0[0]), LOAD);
- CLIB_PREFETCH (p3->data, sizeof (h1[0]), LOAD);
- }
-
- bi0 = from[0];
- bi1 = from[1];
- to_next[0] = bi0;
- to_next[1] = bi1;
- from += 2;
- to_next += 2;
- n_left_to_next -= 2;
- n_left_from -= 2;
-
- b0 = vlib_get_buffer (vm, bi0);
- b1 = vlib_get_buffer (vm, bi1);
-
- if (!is_ipv6)
- {
- /* ip4_local hands us the ip header, not the gre header */
- ip4_0 = vlib_buffer_get_current (b0);
- ip4_1 = vlib_buffer_get_current (b1);
- /* Save src + dst ip4 address, e.g. for mpls-o-gre */
- ip4_tun_src0 = ip4_0->src_address.as_u32;
- ip4_tun_dst0 = ip4_0->dst_address.as_u32;
- ip4_tun_src1 = ip4_1->src_address.as_u32;
- ip4_tun_dst1 = ip4_1->dst_address.as_u32;
-
- vlib_buffer_advance (b0, sizeof (*ip4_0));
- vlib_buffer_advance (b1, sizeof (*ip4_1));
- }
- else
- {
- /* ip6_local hands us the ip header, not the gre header */
- ip6_0 = vlib_buffer_get_current (b0);
- ip6_1 = vlib_buffer_get_current (b1);
- /* Save src + dst ip6 address, e.g. for mpls-o-gre */
- ip6_tun_src0[0] = ip6_0->src_address.as_u64[0];
- ip6_tun_src0[1] = ip6_0->src_address.as_u64[1];
- ip6_tun_dst0[0] = ip6_0->dst_address.as_u64[0];
- ip6_tun_dst0[1] = ip6_0->dst_address.as_u64[1];
- ip6_tun_src1[0] = ip6_1->src_address.as_u64[0];
- ip6_tun_src1[1] = ip6_1->src_address.as_u64[1];
- ip6_tun_dst1[0] = ip6_1->dst_address.as_u64[0];
- ip6_tun_dst1[1] = ip6_1->dst_address.as_u64[1];
-
- vlib_buffer_advance (b0, sizeof (*ip6_0));
- vlib_buffer_advance (b1, sizeof (*ip6_1));
- }
-
- h0 = vlib_buffer_get_current (b0);
- h1 = vlib_buffer_get_current (b1);
-
- /* Index sparse array with network byte order. */
- protocol0 = h0->protocol;
- protocol1 = h1->protocol;
- sparse_vec_index2 (gm->next_by_protocol, protocol0, protocol1,
- &i0, &i1);
- next0 = vec_elt (gm->next_by_protocol, i0);
- next1 = vec_elt (gm->next_by_protocol, i1);
-
- b0->error =
- node->errors[i0 ==
- SPARSE_VEC_INVALID_INDEX ? GRE_ERROR_UNKNOWN_PROTOCOL
- : GRE_ERROR_NONE];
- b1->error =
- node->errors[i1 ==
- SPARSE_VEC_INVALID_INDEX ? GRE_ERROR_UNKNOWN_PROTOCOL
- : GRE_ERROR_NONE];
-
- version0 = clib_net_to_host_u16 (h0->flags_and_version);
- verr0 = version0 & GRE_VERSION_MASK;
- version1 = clib_net_to_host_u16 (h1->flags_and_version);
- verr1 = version1 & GRE_VERSION_MASK;
-
- b0->error = verr0 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION]
- : b0->error;
- next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0;
- b1->error = verr1 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION]
- : b1->error;
- next1 = verr1 ? GRE_INPUT_NEXT_DROP : next1;
-
-
- /* RPF check for ip4/ip6 input */
- if (PREDICT_TRUE (next0 == GRE_INPUT_NEXT_IP4_INPUT
- || next0 == GRE_INPUT_NEXT_IP6_INPUT
- || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
- || next0 == GRE_INPUT_NEXT_MPLS_INPUT))
- {
-
- u64 key4, key6[4];
- if (!is_ipv6)
- {
- key4 = ((u64) (ip4_tun_dst0) << 32) | (u64) (ip4_tun_src0);
- }
- else
- {
- key6[0] = ip6_tun_dst0[0];
- key6[1] = ip6_tun_dst0[1];
- key6[2] = ip6_tun_src0[0];
- key6[3] = ip6_tun_src0[1];
- }
-
- if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
- (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
- cached_tunnel_key6[1] != key6[1] &&
- cached_tunnel_key6[2] != key6[2] &&
- cached_tunnel_key6[3] != key6[3]))
- {
- vnet_hw_interface_t *hi;
- gre_tunnel_t *t;
- uword *p;
-
- if (!is_ipv6)
- p = hash_get (gm->tunnel_by_key4, key4);
- else
- p = hash_get_mem (gm->tunnel_by_key6, key6);
- if (!p)
- {
- next0 = GRE_INPUT_NEXT_DROP;
- b0->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL];
- goto drop0;
- }
- t = pool_elt_at_index (gm->tunnels, p[0]);
- hi = vnet_get_hw_interface (gm->vnet_main, t->hw_if_index);
- tunnel_sw_if_index = hi->sw_if_index;
-
- cached_tunnel_sw_if_index = tunnel_sw_if_index;
- }
- else
- {
- tunnel_sw_if_index = cached_tunnel_sw_if_index;
- }
- }
- else
- {
- next0 = GRE_INPUT_NEXT_DROP;
- goto drop0;
- }
- len = vlib_buffer_length_in_chain (vm, b0);
- vlib_increment_combined_counter (im->combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- thread_index,
- tunnel_sw_if_index,