/*
 * Copyright (c) 2017 SUSE LLC.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vlib/vlib.h>
#include <vnet/pg/pg.h>
#include <vnet/geneve/geneve.h>

vlib_node_registration_t geneve4_input_node;
vlib_node_registration_t geneve6_input_node;

typedef struct
{
  u32 next_index;
  u32 tunnel_index;
  u32 error;
  u32 vni_rsvd;
} geneve_rx_trace_t;

static u8 *
format_geneve_rx_trace (u8 * s, va_list * args)
{
  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
  geneve_rx_trace_t *t = va_arg (*args, geneve_rx_trace_t *);

  if (t->tunnel_index != ~0)
    {
      s =
	format (s,
		"GENEVE decap from geneve_tunnel%d vni %d next %d error %d",
		t->tunnel_index, t->vni_rsvd, t->next_index, t->error);
    }
  else
    {
      s = format (s, "GENEVE decap error - tunnel for vni %d does not exist",
		  t->vni_rsvd);
    }
  return s;
}

always_inline u32
validate_geneve_fib (vlib_buffer_t * b, geneve_tunnel_t * t, u32 is_ip4)
{
  u32 fib_index, sw_if_index;

  sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];

  if (is_ip4)
    fib_index = (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
      vec_elt (ip4_main.fib_index_by_sw_if_index, sw_if_index) :
      vnet_buffer (b)->sw_if_index[VLIB_TX];
  else
    fib_index = (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
      vec_elt (ip6_main.fib_index_by_sw_if_index, sw_if_index) :
      vnet_buffer (b)->sw_if_index[VLIB_TX];

  return (fib_index == t->encap_fib_index);
}

always_inline uword
geneve_input (vlib_main_t * vm,
	      vlib_node_runtime_t * node,
	      vlib_frame_t * from_frame, u32 is_ip4)
{
  u32 n_left_from, next_index, *from, *to_next;
  geneve_main_t *vxm = &geneve_main;
  vnet_main_t *vnm = vxm->vnet_main;
  vnet_interface_main_t *im = &vnm->interface_main;
  u32 last_tunnel_index = ~0;
  geneve4_tunnel_key_t last_key4;
  geneve6_tunnel_key_t last_key6;
  u32 pkts_decapsulated = 0;
  u32 thread_index = vm->thread_index;
  u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;

  if (is_ip4)
    last_key4.as_u64 = ~0;
  else
    memset (&last_key6, 0xff, sizeof (last_key6));

  from = vlib_frame_vector_args (from_frame);
  n_left_from = from_frame->n_vectors;

  next_index = node->cached_next_index;
  stats_sw_if_index = node->runtime_data[0];
  stats_n_packets = stats_n_bytes = 0;

  while (n_left_from > 0)
    {
      u32 n_left_to_next;

      vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
      while (n_left_from >= 4 && n_left_to_next >= 2)
	{
	  u32 bi0, bi1;
	  vlib_buffer_t *b0, *b1;
	  u32 next0, next1;
	  ip4_header_t *ip4_0, *ip4_1;
	  ip6_header_t *ip6_0, *ip6_1;
	  geneve_header_t *geneve0, *geneve1;
	  uword *p0, *p1;
	  u32 tunnel_index0, tunnel_index1;
	  geneve_tunnel_t *t0, *t1, *mt0 = NULL, *mt1 = NULL;
	  geneve4_tunnel_key_t key4_0, key4_1;
	  geneve6_tunnel_key_t key6_0, key6_1;
	  u32 error0, error1;
	  u32 sw_if_index0, sw_if_index1, len0, len1;

	  /* 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, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
	    CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, 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);

	  /* udp leaves current_data pointing at the geneve header */
	  geneve0 = vlib_buffer_get_current (b0);
	  geneve1 = vlib_buffer_get_current (b1);

	  vnet_geneve_hdr_1word_ntoh (geneve0);
	  vnet_geneve_hdr_1word_ntoh (geneve1);

	  if (is_ip4)
	    {
	      vlib_buffer_advance
		(b0, -(word) (sizeof (udp_header_t) + sizeof (ip4_header_t)));
	      vlib_buffer_advance
		(b1, -(word) (sizeof (udp_header_t) + sizeof (ip4_header_t)));
	      ip4_0 = vlib_buffer_get_current (b0);
	      ip4_1 = vlib_buffer_get_current (b1);
	    }
	  else
	    {
	      vlib_buffer_advance
		(b0, -(word) (sizeof (udp_header_t) + sizeof (ip6_header_t)));
	      vlib_buffer_advance
		(b1, -(word) (sizeof (udp_header_t) + sizeof (ip6_header_t)));
	      ip6_0 = vlib_buffer_get_current (b0);
	      ip6_1 = vlib_buffer_get_current (b1);
	    }

	  /* pop (ip, udp, geneve) */
	  if (is_ip4)
	    {
	      vlib_buffer_advance
		(b0,
		 sizeof (*ip4_0) + sizeof (udp_header_t) +
		 GENEVE_BASE_HEADER_LENGTH +
		 vnet_get_geneve_options_len (geneve0));
	      vlib_buffer_advance (b1,
				   sizeof (*ip4_1) + sizeof (udp_header_t) +
				   GENEVE_BASE_HEADER_LENGTH +
				   vnet_get_geneve_options_len (geneve1));
	    }
	  else
	    {
	      vlib_buffer_advance
		(b0,
		 sizeof (*ip6_0) + sizeof (udp_header_t) +
		 GENEVE_BASE_HEADER_LENGTH +
		 vnet_get_geneve_options_len (geneve0));
	      vlib_buffer_advance (b0,
				   sizeof (*ip6_0) + sizeof (udp_header_t) +
				   GENEVE_BASE_HEADER_LENGTH +
				   vnet_get_geneve_options_len (geneve1));
	    }

	  tunnel_index0 = ~0;
	  error0 = 0;

	  tunnel_index1 = ~0;
	  error1 = 0;

	  if (PREDICT_FALSE
	      (vnet_get_geneve_version (geneve0) != GENEVE_VERSION))
	    {
	      error0 = GENEVE_ERROR_BAD_FLAGS;
	      next0 = GENEVE_INPUT_NEXT_DROP;
	      goto trace0;
	    }
#if SUPPORT_OPTIONS_HEADER==1
	  if (PREDICT_FALSE (vnet_get_geneve_critical_bit (geneve0) == 1))
	    {
	      error0 = GENEVE_ERROR_BAD_FLAGS;
	      next0 = GENEVE_INPUT_NEXT_DROP;
	      goto trace0;
	    }
#endif
	  if (is_ip4)
	    {
	      key4_0.remote = ip4_0->src_address.as_u32;
	      key4_0.vni = vnet_get_geneve_vni_bigendian (geneve0);

	      /* Make sure GENEVE tunnel exist according to packet SIP and VNI */
	      if (PREDICT_FALSE (key4_0.as_u64 != last_key4.as_u64))
		{
		  p0 = hash_get (vxm->geneve4_tunnel_by_key, key4_0.as_u64);
		  if (PREDICT_FALSE (p0 == NULL))
		    {
		      error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		      next0 = GENEVE_INPUT_NEXT_DROP;
		      goto trace0;
		    }
		  last_key4.as_u64 = key4_0.as_u64;
		  tunnel_index0 = last_tunnel_index = p0[0];
		}
	      else
		tunnel_index0 = last_tunnel_index;
	      t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0);

	      /* Validate GENEVE tunnel encap-fib index agaist packet */
	      if (PREDICT_FALSE (validate_geneve_fib (b0, t0, is_ip4) == 0))
		{
		  error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		  next0 = GENEVE_INPUT_NEXT_DROP;
		  goto trace0;
		}

	      /* Validate GENEVE tunnel SIP against packet DIP */
	      if (PREDICT_TRUE
		  (ip4_0->dst_address.as_u32 == t0->local.ip4.as_u32))
		goto next0;	/* valid packet */
	      if (PREDICT_FALSE
		  (ip4_address_is_multicast (&ip4_0->dst_address)))
		{
		  key4_0.remote = ip4_0->dst_address.as_u32;
		  key4_0.vni = vnet_get_geneve_vni_bigendian (geneve0);
		  /* Make sure mcast GENEVE tunnel exist by packet DIP and VNI */
		  p0 = hash_get (vxm->geneve4_tunnel_by_key, key4_0.as_u64);
		  if (PREDICT_TRUE (p0 != NULL))
		    {
		      mt0 = pool_elt_at_index (vxm->tunnels, p0[0]);
		      goto next0;	/* valid packet */
		    }
		}
	      error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
	      next0 = GENEVE_INPUT_NEXT_DROP;
	      goto trace0;

	    }
	  else			/* !is_ip4 */
	    {
	      key6_0.remote.as_u64[0] = ip6_0->src_address.as_u64[0];
	      key6_0.remote.as_u64[1] = ip6_0->src_address.as_u64[1];
	      key6_0.vni = vnet_get_geneve_vni_bigendian (geneve0);

	      /* Make sure GENEVE tunnel exist according to packet SIP and VNI */
	      if (PREDICT_FALSE
		  (memcmp (&key6_0, &last_key6, sizeof (last_key6)) != 0))
		{
		  p0 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_0);
		  if (PREDICT_FALSE (p0 == NULL))
		    {
		      error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		      next0 = GENEVE_INPUT_NEXT_DROP;
		      goto trace0;
		    }
		  clib_memcpy (&last_key6, &key6_0, sizeof (key6_0));
		  tunnel_index0 = last_tunnel_index = p0[0];
		}
	      else
		tunnel_index0 = last_tunnel_index;
	      t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0);

	      /* Validate GENEVE tunnel encap-fib index agaist packet */
	      if (PREDICT_FALSE (validate_geneve_fib (b0, t0, is_ip4) == 0))
		{
		  error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		  next0 = GENEVE_INPUT_NEXT_DROP;
		  goto trace0;
		}

	      /* Validate GENEVE tunnel SIP against packet DIP */
	      if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address,
						      &t0->local.ip6)))
		goto next0;	/* valid packet */
	      if (PREDICT_FALSE
		  (ip6_address_is_multicast (&ip6_0->dst_address)))
		{
		  key6_0.remote.as_u64[0] = ip6_0->dst_address.as_u64[0];
		  key6_0.remote.as_u64[1] = ip6_0->dst_address.as_u64[1];
		  key6_0.vni = vnet_get_geneve_vni_bigendian (geneve0);
		  p0 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_0);
		  if (PREDICT_TRUE (p0 != NULL))
		    {
		      mt0 = pool_elt_at_index (vxm->tunnels, p0[0]);
		      goto next0;	/* valid packet */
		    }
		}
	      error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
	      next0 = GENEVE_INPUT_NEXT_DROP;
	      goto trace0;
	    }

	next0:
	  next0 = t0->decap_next_index;
	  sw_if_index0 = t0->sw_if_index;
	  len0 = vlib_buffer_length_in_chain (vm, b0);

	  /* Required to make the l2 tag push / pop code work on l2 subifs */
	  if (PREDICT_TRUE (next0 == GENEVE_INPUT_NEXT_L2_INPUT))
	    vnet_update_l2_len (b0);

	  /* Set packet input sw_if_index to unicast GENEVE tunnel for learning */
	  vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index0;
	  sw_if_index0 = (mt0) ? mt0->sw_if_index : sw_if_index0;

	  pkts_decapsulated++;
	  stats_n_packets += 1;
	  stats_n_bytes += len0;

	  /* Batch stats increment on the same geneve tunnel so counter
	     is not incremented per packet */
	  if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
	    {
	      stats_n_packets -= 1;
	      stats_n_bytes -= len0;
	      if (stats_n_packets)
		vlib_increment_combined_counter
		  (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
		   thread_index, stats_sw_if_index,
		   stats_n_packets, stats_n_bytes);
	      stats_n_packets = 1;
	      stats_n_bytes = len0;
	      stats_sw_if_index = sw_if_index0;
	    }

	trace0:
	  b0->error = error0 ? node->errors[error0] : 0;

	  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
	    {
	      geneve_rx_trace_t *tr
		= vlib_add_trace (vm, node, b0, sizeof (*tr));
	      tr->next_index = next0;
	      tr->error = error0;
	      tr->tunnel_index = tunnel_index0;
	      tr->vni_rsvd = vnet_get_geneve_vni (geneve0);
	    }

	  if (PREDICT_FALSE
	      (vnet_get_geneve_version (geneve1) != GENEVE_VERSION))
	    {
	      error1 = GENEVE_ERROR_BAD_FLAGS;
	      next1 = GENEVE_INPUT_NEXT_DROP;
	      goto trace1;
	    }
#if SUPPORT_OPTIONS_HEADER==1
	  if (PREDICT_FALSE (vnet_get_geneve_critical_bit (geneve1) == 1))
	    {
	      error1 = GENEVE_ERROR_BAD_FLAGS;
	      next1 = GENEVE_INPUT_NEXT_DROP;
	      goto trace1;
	    }
#endif
	  if (is_ip4)
	    {
	      key4_1.remote = ip4_1->src_address.as_u32;
	      key4_1.vni = vnet_get_geneve_vni_bigendian (geneve1);

	      /* Make sure unicast GENEVE tunnel exist by packet SIP and VNI */
	      if (PREDICT_FALSE (key4_1.as_u64 != last_key4.as_u64))
		{
		  p1 = hash_get (vxm->geneve4_tunnel_by_key, key4_1.as_u64);
		  if (PREDICT_FALSE (p1 == NULL))
		    {
		      error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		      next1 = GENEVE_INPUT_NEXT_DROP;
		      goto trace1;
		    }
		  last_key4.as_u64 = key4_1.as_u64;
		  tunnel_index1 = last_tunnel_index = p1[0];
		}
	      else
		tunnel_index1 = last_tunnel_index;
	      t1 = pool_elt_at_index (vxm->tunnels, tunnel_index1);

	      /* Validate GENEVE tunnel encap-fib index agaist packet */
	      if (PREDICT_FALSE (validate_geneve_fib (b1, t1, is_ip4) == 0))
		{
		  error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		  next1 = GENEVE_INPUT_NEXT_DROP;
		  goto trace1;
		}

	      /* Validate GENEVE tunnel SIP against packet DIP */
	      if (PREDICT_TRUE
		  (ip4_1->dst_address.as_u32 == t1->local.ip4.as_u32))
		goto next1;	/* valid packet */
	      if (PREDICT_FALSE
		  (ip4_address_is_multicast (&ip4_1->dst_address)))
		{
		  key4_1.remote = ip4_1->dst_address.as_u32;
		  key4_1.vni = vnet_get_geneve_vni_bigendian (geneve1);
		  /* Make sure mcast GENEVE tunnel exist by packet DIP and VNI */
		  p1 = hash_get (vxm->geneve4_tunnel_by_key, key4_1.as_u64);
		  if (PREDICT_TRUE (p1 != NULL))
		    {
		      mt1 = pool_elt_at_index (vxm->tunnels, p1[0]);
		      goto next1;	/* valid packet */
		    }
		}
	      error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
	      next1 = GENEVE_INPUT_NEXT_DROP;
	      goto trace1;

	    }
	  else			/* !is_ip4 */
	    {
	      key6_1.remote.as_u64[0] = ip6_1->src_address.as_u64[0];
	      key6_1.remote.as_u64[1] = ip6_1->src_address.as_u64[1];
	      key6_1.vni = vnet_get_geneve_vni_bigendian (geneve1);

	      /* Make sure GENEVE tunnel exist according to packet SIP and VNI */
	      if (PREDICT_FALSE
		  (memcmp (&key6_1, &last_key6, sizeof (last_key6)) != 0))
		{
		  p1 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_1);

		  if (PREDICT_FALSE (p1 == NULL))
		    {
		      error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		      next1 = GENEVE_INPUT_NEXT_DROP;
		      goto trace1;
		    }

		  clib_memcpy (&last_key6, &key6_1, sizeof (key6_1));
		  tunnel_index1 = last_tunnel_index = p1[0];
		}
	      else
		tunnel_index1 = last_tunnel_index;
	      t1 = pool_elt_at_index (vxm->tunnels, tunnel_index1);

	      /* Validate GENEVE tunnel encap-fib index agaist packet */
	      if (PREDICT_FALSE (validate_geneve_fib (b1, t1, is_ip4) == 0))
		{
		  error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		  next1 = GENEVE_INPUT_NEXT_DROP;
		  goto trace1;
		}

	      /* Validate GENEVE tunnel SIP against packet DIP */
	      if (PREDICT_TRUE (ip6_address_is_equal (&ip6_1->dst_address,
						      &t1->local.ip6)))
		goto next1;	/* valid packet */
	      if (PREDICT_FALSE
		  (ip6_address_is_multicast (&ip6_1->dst_address)))
		{
		  key6_1.remote.as_u64[0] = ip6_1->dst_address.as_u64[0];
		  key6_1.remote.as_u64[1] = ip6_1->dst_address.as_u64[1];
		  key6_1.vni = vnet_get_geneve_vni_bigendian (geneve1);
		  p1 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_1);
		  if (PREDICT_TRUE (p1 != NULL))
		    {
		      mt1 = pool_elt_at_index (vxm->tunnels, p1[0]);
		      goto next1;	/* valid packet */
		    }
		}
	      error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
	      next1 = GENEVE_INPUT_NEXT_DROP;
	      goto trace1;
	    }

	next1:
	  next1 = t1->decap_next_index;
	  sw_if_index1 = t1->sw_if_index;
	  len1 = vlib_buffer_length_in_chain (vm, b1);

	  /* Required to make the l2 tag push / pop code work on l2 subifs */
	  if (PREDICT_TRUE (next1 == GENEVE_INPUT_NEXT_L2_INPUT))
	    vnet_update_l2_len (b1);

	  /* Set packet input sw_if_index to unicast GENEVE tunnel for learning */
	  vnet_buffer (b1)->sw_if_index[VLIB_RX] = sw_if_index1;
	  sw_if_index1 = (mt1) ? mt1->sw_if_index : sw_if_index1;

	  pkts_decapsulated++;
	  stats_n_packets += 1;
	  stats_n_bytes += len1;

	  /* Batch stats increment on the same geneve tunnel so counter
	     is not incremented per packet */
	  if (PREDICT_FALSE (sw_if_index1 != stats_sw_if_index))
	    {
	      stats_n_packets -= 1;
	      stats_n_bytes -= len1;
	      if (stats_n_packets)
		vlib_increment_combined_counter
		  (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
		   thread_index, stats_sw_if_index,
		   stats_n_packets, stats_n_bytes);
	      stats_n_packets = 1;
	      stats_n_bytes = len1;
	      stats_sw_if_index = sw_if_index1;
	    }

	trace1:
	  b1->error = error1 ? node->errors[error1] : 0;

	  if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
	    {
	      geneve_rx_trace_t *tr
		= vlib_add_trace (vm, node, b1, sizeof (*tr));
	      tr->next_index = next1;
	      tr->error = error1;
	      tr->tunnel_index = tunnel_index1;
	      tr->vni_rsvd = vnet_get_geneve_vni (geneve1);
	    }

	  vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
					   to_next, n_left_to_next,
					   bi0, bi1, next0, next1);
	}

      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  u32 bi0;
	  vlib_buffer_t *b0;
	  u32 next0;
	  ip4_header_t *ip4_0;
	  ip6_header_t *ip6_0;
	  geneve_header_t *geneve0;
	  uword *p0;
	  u32 tunnel_index0;
	  geneve_tunnel_t *t0, *mt0 = NULL;
	  geneve4_tunnel_key_t key4_0;
	  geneve6_tunnel_key_t key6_0;
	  u32 error0;
	  u32 sw_if_index0, len0;

	  bi0 = from[0];
	  to_next[0] = bi0;
	  from += 1;
	  to_next += 1;
	  n_left_from -= 1;
	  n_left_to_next -= 1;

	  b0 = vlib_get_buffer (vm, bi0);

	  /* udp leaves current_data pointing at the geneve header */
	  geneve0 = vlib_buffer_get_current (b0);
	  vnet_geneve_hdr_1word_ntoh (geneve0);

	  if (is_ip4)
	    {
	      vlib_buffer_advance
		(b0, -(word) (sizeof (udp_header_t) + sizeof (ip4_header_t)));
	      ip4_0 = vlib_buffer_get_current (b0);
	    }
	  else
	    {
	      vlib_buffer_advance
		(b0, -(word) (sizeof (udp_header_t) + sizeof (ip6_header_t)));
	      ip6_0 = vlib_buffer_get_current (b0);
	    }

	  /* pop (ip, udp, geneve) */
	  if (is_ip4)
	    {
	      vlib_buffer_advance
		(b0,
		 sizeof (*ip4_0) + sizeof (udp_header_t) +
		 GENEVE_BASE_HEADER_LENGTH +
		 vnet_get_geneve_options_len (geneve0));
	    }
	  else
	    {
	      vlib_buffer_advance
		(b0,
		 sizeof (*ip6_0) + sizeof (udp_header_t) +
		 GENEVE_BASE_HEADER_LENGTH +
		 vnet_get_geneve_options_len (geneve0));
	    }

	  tunnel_index0 = ~0;
	  error0 = 0;

	  if (PREDICT_FALSE
	      (vnet_get_geneve_version (geneve0) != GENEVE_VERSION))
	    {
	      error0 = GENEVE_ERROR_BAD_FLAGS;
	      next0 = GENEVE_INPUT_NEXT_DROP;
	      goto trace00;
	    }
#if SUPPORT_OPTIONS_HEADER==1
	  if (PREDICT_FALSE (vnet_get_geneve_critical_bit (geneve0) == 1))
	    {
	      error0 = GENEVE_ERROR_BAD_FLAGS;
	      next0 = GENEVE_INPUT_NEXT_DROP;
	      goto trace00;
	    }
#endif
	  if (is_ip4)
	    {
	      key4_0.remote = ip4_0->src_address.as_u32;
	      key4_0.vni = vnet_get_geneve_vni_bigendian (geneve0);

	      /* Make sure unicast GENEVE tunnel exist by packet SIP and VNI */
	      if (PREDICT_FALSE (key4_0.as_u64 != last_key4.as_u64))
		{
		  p0 = hash_get (vxm->geneve4_tunnel_by_key, key4_0.as_u64);
		  if (PREDICT_FALSE (p0 == NULL))
		    {
		      error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		      next0 = GENEVE_INPUT_NEXT_DROP;
		      goto trace00;
		    }
		  last_key4.as_u64 = key4_0.as_u64;
		  tunnel_index0 = last_tunnel_index = p0[0];
		}
	      else
		tunnel_index0 = last_tunnel_index;
	      t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0);

	      /* Validate GENEVE tunnel encap-fib index agaist packet */
	      if (PREDICT_FALSE (validate_geneve_fib (b0, t0, is_ip4) == 0))
		{
		  error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		  next0 = GENEVE_INPUT_NEXT_DROP;
		  goto trace00;
		}

	      /* Validate GENEVE tunnel SIP against packet DIP */
	      if (PREDICT_TRUE
		  (ip4_0->dst_address.as_u32 == t0->local.ip4.as_u32))
		goto next00;	/* valid packet */
	      if (PREDICT_FALSE
		  (ip4_address_is_multicast (&ip4_0->dst_address)))
		{
		  key4_0.remote = ip4_0->dst_address.as_u32;
		  key4_0.vni = vnet_get_geneve_vni_bigendian (geneve0);
		  /* Make sure mcast GENEVE tunnel exist by packet DIP and VNI */
		  p0 = hash_get (vxm->geneve4_tunnel_by_key, key4_0.as_u64);
		  if (PREDICT_TRUE (p0 != NULL))
		    {
		      mt0 = pool_elt_at_index (vxm->tunnels, p0[0]);
		      goto next00;	/* valid packet */
		    }
		}
	      error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
	      next0 = GENEVE_INPUT_NEXT_DROP;
	      goto trace00;

	    }
	  else			/* !is_ip4 */
	    {
	      key6_0.remote.as_u64[0] = ip6_0->src_address.as_u64[0];
	      key6_0.remote.as_u64[1] = ip6_0->src_address.as_u64[1];
	      key6_0.vni = vnet_get_geneve_vni_bigendian (geneve0);

	      /* Make sure GENEVE tunnel exist according to packet SIP and VNI */
	      if (PREDICT_FALSE
		  (memcmp (&key6_0, &last_key6, sizeof (last_key6)) != 0))
		{
		  p0 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_0);
		  if (PREDICT_FALSE (p0 == NULL))
		    {
		      error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		      next0 = GENEVE_INPUT_NEXT_DROP;
		      goto trace00;
		    }
		  clib_memcpy (&last_key6, &key6_0, sizeof (key6_0));
		  tunnel_index0 = last_tunnel_index = p0[0];
		}
	      else
		tunnel_index0 = last_tunnel_index;
	      t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0);

	      /* Validate GENEVE tunnel encap-fib index agaist packet */
	      if (PREDICT_FALSE (validate_geneve_fib (b0, t0, is_ip4) == 0))
		{
		  error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
		  next0 = GENEVE_INPUT_NEXT_DROP;
		  goto trace00;
		}

	      /* Validate GENEVE tunnel SIP against packet DIP */
	      if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address,
						      &t0->local.ip6)))
		goto next00;	/* valid packet */
	      if (PREDICT_FALSE
		  (ip6_address_is_multicast (&ip6_0->dst_address)))
		{
		  key6_0.remote.as_u64[0] = ip6_0->dst_address.as_u64[0];
		  key6_0.remote.as_u64[1] = ip6_0->dst_address.as_u64[1];
		  key6_0.vni = vnet_get_geneve_vni_bigendian (geneve0);
		  p0 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_0);
		  if (PREDICT_TRUE (p0 != NULL))
		    {
		      mt0 = pool_elt_at_index (vxm->tunnels, p0[0]);
		      goto next00;	/* valid packet */
		    }
		}
	      error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
	      next0 = GENEVE_INPUT_NEXT_DROP;
	      goto trace00;
	    }

	next00:
	  next0 = t0->decap_next_index;
	  sw_if_index0 = t0->sw_if_index;
	  len0 = vlib_buffer_length_in_chain (vm, b0);

	  /* Required to make the l2 tag push / pop code work on l2 subifs */
	  if (PREDICT_TRUE (next0 == GENEVE_INPUT_NEXT_L2_INPUT))
	    vnet_update_l2_len (b0);

	  /* Set packet input sw_if_index to unicast GENEVE tunnel for learning */
	  vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index0;
	  sw_if_index0 = (mt0) ? mt0->sw_if_index : sw_if_index0;

	  pkts_decapsulated++;
	  stats_n_packets += 1;
	  stats_n_bytes += len0;

	  /* Batch stats increment on the same geneve tunnel so counter
	     is not incremented per packet */
	  if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
	    {
	      stats_n_packets -= 1;
	      stats_n_bytes -= len0;
	      if (stats_n_packets)
		vlib_increment_combined_counter
		  (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
		   thread_index, stats_sw_if_index,
		   stats_n_packets, stats_n_bytes);
	      stats_n_packets = 1;
	      stats_n_bytes = len0;
	      stats_sw_if_index = sw_if_index0;
	    }

	trace00:
	  b0->error = error0 ? node->errors[error0] : 0;

	  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
	    {
	      geneve_rx_trace_t *tr
		= vlib_add_trace (vm, node, b0, sizeof (*tr));
	      tr->next_index = next0;
	      tr->error = error0;
	      tr->tunnel_index = tunnel_index0;
	      tr->vni_rsvd = vnet_get_geneve_vni (geneve0);
	    }
	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
					   to_next, n_left_to_next,
					   bi0, next0);
	}

      vlib_put_next_frame (vm, node, next_index, n_left_to_next);
    }
  /* Do we still need this now that tunnel tx stats is kept? */
  vlib_node_increment_counter (vm, is_ip4 ?
			       geneve4_input_node.
			       index : geneve6_input_node.index,
			       GENEVE_ERROR_DECAPSULATED, pkts_decapsulated);

  /* Increment any remaining batch stats */
  if (stats_n_packets)
    {
      vlib_increment_combined_counter
	(im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
	 thread_index, stats_sw_if_index, stats_n_packets, stats_n_bytes);
      node->runtime_data[0] = stats_sw_if_index;
    }

  return from_frame->n_vectors;
}

static uword
geneve4_input (vlib_main_t * vm,
	       vlib_node_runtime_t * node, vlib_frame_t * from_frame)
{
  return geneve_input (vm, node, from_frame, /* is_ip4 */ 1);
}

static uword
geneve6_input (vlib_main_t * vm,
	       vlib_node_runtime_t * node, vlib_frame_t * from_frame)
{
  return geneve_input (vm, node, from_frame, /* is_ip4 */ 0);
}

static char *geneve_error_strings[] = {
#define geneve_error(n,s) s,
#include <vnet/geneve/geneve_error.def>
#undef geneve_error
#undef _
};

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (geneve4_input_node) = {
  .function = geneve4_input,
  .name = "geneve4-input",
  /* Takes a vector of packets. */
  .vector_size = sizeof (u32),
  .n_errors = GENEVE_N_ERROR,
  .error_strings = geneve_error_strings,
  .n_next_nodes = GENEVE_INPUT_N_NEXT,
  .next_nodes = {
#define _(s,n) [GENEVE_INPUT_NEXT_##s] = n,
    foreach_geneve_input_next
#undef _
  },

//temp  .format_buffer = format_geneve_header,
  .format_trace = format_geneve_rx_trace,
  // $$$$ .unformat_buffer = unformat_geneve_header,
};

VLIB_NODE_FUNCTION_MULTIARCH (geneve4_input_node, geneve4_input)

VLIB_REGISTER_NODE (geneve6_input_node) = {
  .function = geneve6_input,
  .name = "geneve6-input",
  /* Takes a vector of packets. */
  .vector_size = sizeof (u32),
  .n_errors = GENEVE_N_ERROR,
  .error_strings = geneve_error_strings,
  .n_next_nodes = GENEVE_INPUT_N_NEXT,
  .next_nodes = {
#define _(s,n) [GENEVE_INPUT_NEXT_##s] = n,
  foreach_geneve_input_next
#undef _
  },
//temp  .format_buffer = format_geneve_header,
  .format_trace = format_geneve_rx_trace,
  // $$$$ .unformat_buffer = unformat_geneve_header,
};

VLIB_NODE_FUNCTION_MULTIARCH (geneve6_input_node, geneve6_input)
/* *INDENT-ON* */

typedef enum
{
  IP_GENEVE_BYPASS_NEXT_DROP,
  IP_GENEVE_BYPASS_NEXT_GENEVE,
  IP_GENEVE_BYPASS_N_NEXT,
} ip_vxan_bypass_next_t;

always_inline uword
ip_geneve_bypass_inline (vlib_main_t * vm,
			 vlib_node_runtime_t * node,
			 vlib_frame_t * frame, u32 is_ip4)
{
  geneve_main_t *vxm = &geneve_main;
  u32 *from, *to_next, n_left_from, n_left_to_next, next_index;
  vlib_node_runtime_t *error_node =
    vlib_node_get_runtime (vm, ip4_input_node.index);
  ip4_address_t addr4;		/* last IPv4 address matching a local VTEP address */
  ip6_address_t addr6;		/* last IPv6 address matching a local VTEP address */

  from = vlib_frame_vector_args (frame);
  n_left_from = frame->n_vectors;
  next_index = node->cached_next_index;

  if (node->flags & VLIB_NODE_FLAG_TRACE)
    ip4_forward_next_trace (vm, node, frame, VLIB_TX);

  if (is_ip4)
    addr4.data_u32 = ~0;
  else
    ip6_address_set_zero (&addr6);

  while (n_left_from > 0)
    {
      vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);

      while (n_left_from >= 4 && n_left_to_next >= 2)
	{
	  vlib_buffer_t *b0, *b1;
	  ip4_header_t *ip40, *ip41;
	  ip6_header_t *ip60, *ip61;
	  udp_header_t *udp0, *udp1;
	  u32 bi0, ip_len0, udp_len0, flags0, next0;
	  u32 bi1, ip_len1, udp_len1, flags1, next1;
	  i32 len_diff0, len_diff1;
	  u8 error0, good_udp0, proto0;
	  u8 error1, good_udp1, proto1;

	  /* 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, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
	    CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
	  }

	  bi0 = to_next[0] = from[0];
	  bi1 = to_next[1] = from[1];
	  from += 2;
	  n_left_from -= 2;
	  to_next += 2;
	  n_left_to_next -= 2;

	  b0 = vlib_get_buffer (vm, bi0);
	  b1 = vlib_get_buffer (vm, bi1);
	  if (is_ip4)
	    {
	      ip40 = vlib_buffer_get_current (b0);
	      ip41 = vlib_buffer_get_current (b1);
	    }
	  else
	    {
	      ip60 = vlib_buffer_get_current (b0);
	      ip61 = vlib_buffer_get_current (b1);
	    }

	  /* Setup packet for next IP feature */
	  vnet_feature_next (&next0, b0);
	  vnet_feature_next (&next1, b1);

	  if (is_ip4)
	    {
	      /* Treat IP frag packets as "experimental" protocol for now
	         until support of IP frag reassembly is implemented */
	      proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
	      proto1 = ip4_is_fragment (ip41) ? 0xfe : ip41->protocol;
	    }
	  else
	    {
	      proto0 = ip60->protocol;
	      proto1 = ip61->protocol;
	    }

	  /* Process packet 0 */
	  if (proto0 != IP_PROTOCOL_UDP)
	    goto exit0;		/* not UDP packet */

	  if (is_ip4)
	    udp0 = ip4_next_header (ip40);
	  else
	    udp0 = ip6_next_header (ip60);

	  if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_geneve))
	    goto exit0;		/* not GENEVE packet */

	  /* Validate DIP against VTEPs */
	  if (is_ip4)
	    {
	      if (addr4.as_u32 != ip40->dst_address.as_u32)
		{
		  if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
		    goto exit0;	/* no local VTEP for GENEVE packet */
		  addr4 = ip40->dst_address;
		}
	    }
	  else
	    {
	      if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
		{
		  if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
		    goto exit0;	/* no local VTEP for GENEVE packet */
		  addr6 = ip60->dst_address;
		}
	    }

	  flags0 = b0->flags;
	  good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;

	  /* Don't verify UDP checksum for packets with explicit zero checksum. */
	  good_udp0 |= udp0->checksum == 0;

	  /* Verify UDP length */
	  if (is_ip4)
	    ip_len0 = clib_net_to_host_u16 (ip40->length);
	  else
	    ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
	  udp_len0 = clib_net_to_host_u16 (udp0->length);
	  len_diff0 = ip_len0 - udp_len0;

	  /* Verify UDP checksum */
	  if (PREDICT_FALSE (!good_udp0))
	    {
	      if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
		{
		  if (is_ip4)
		    flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
		  else
		    flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
		  good_udp0 =
		    (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
		}
	    }

	  if (is_ip4)
	    {
	      error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
	      error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
	    }
	  else
	    {
	      error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
	      error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
	    }

	  next0 = error0 ?
	    IP_GENEVE_BYPASS_NEXT_DROP : IP_GENEVE_BYPASS_NEXT_GENEVE;
	  b0->error = error0 ? error_node->errors[error0] : 0;

	  /* geneve-input node expect current at GENEVE header */
	  if (is_ip4)
	    vlib_buffer_advance (b0,
				 sizeof (ip4_header_t) +
				 sizeof (udp_header_t));
	  else
	    vlib_buffer_advance (b0,
				 sizeof (ip6_header_t) +
				 sizeof (udp_header_t));

	exit0:
	  /* Process packet 1 */
	  if (proto1 != IP_PROTOCOL_UDP)
	    goto exit1;		/* not UDP packet */

	  if (is_ip4)
	    udp1 = ip4_next_header (ip41);
	  else
	    udp1 = ip6_next_header (ip61);

	  if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_geneve))
	    goto exit1;		/* not GENEVE packet */

	  /* Validate DIP against VTEPs */
	  if (is_ip4)
	    {
	      if (addr4.as_u32 != ip41->dst_address.as_u32)
		{
		  if (!hash_get (vxm->vtep4, ip41->dst_address.as_u32))
		    goto exit1;	/* no local VTEP for GENEVE packet */
		  addr4 = ip41->dst_address;
		}
	    }
	  else
	    {
	      if (!ip6_address_is_equal (&addr6, &ip61->dst_address))
		{
		  if (!hash_get_mem (vxm->vtep6, &ip61->dst_address))
		    goto exit1;	/* no local VTEP for GENEVE packet */
		  addr6 = ip61->dst_address;
		}
	    }

	  flags1 = b1->flags;
	  good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;

	  /* Don't verify UDP checksum for packets with explicit zero checksum. */
	  good_udp1 |= udp1->checksum == 0;

	  /* Verify UDP length */
	  if (is_ip4)
	    ip_len1 = clib_net_to_host_u16 (ip41->length);
	  else
	    ip_len1 = clib_net_to_host_u16 (ip61->payload_length);
	  udp_len1 = clib_net_to_host_u16 (udp1->length);
	  len_diff1 = ip_len1 - udp_len1;

	  /* Verify UDP checksum */
	  if (PREDICT_FALSE (!good_udp1))
	    {
	      if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
		{
		  if (is_ip4)
		    flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
		  else
		    flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
		  good_udp1 =
		    (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
		}
	    }

	  if (is_ip4)
	    {
	      error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
	      error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
	    }
	  else
	    {
	      error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
	      error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
	    }

	  next1 = error1 ?
	    IP_GENEVE_BYPASS_NEXT_DROP : IP_GENEVE_BYPASS_NEXT_GENEVE;
	  b1->error = error1 ? error_node->errors[error1] : 0;

	  /* geneve-input node expect current at GENEVE header */
	  if (is_ip4)
	    vlib_buffer_advance (b1,
				 sizeof (ip4_header_t) +
				 sizeof (udp_header_t));
	  else
	    vlib_buffer_advance (b1,
				 sizeof (ip6_header_t) +
				 sizeof (udp_header_t));

	exit1:
	  vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
					   to_next, n_left_to_next,
					   bi0, bi1, next0, next1);
	}

      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  vlib_buffer_t *b0;
	  ip4_header_t *ip40;
	  ip6_header_t *ip60;
	  udp_header_t *udp0;
	  u32 bi0, ip_len0, udp_len0, flags0, next0;
	  i32 len_diff0;
	  u8 error0, good_udp0, proto0;

	  bi0 = to_next[0] = from[0];
	  from += 1;
	  n_left_from -= 1;
	  to_next += 1;
	  n_left_to_next -= 1;

	  b0 = vlib_get_buffer (vm, bi0);
	  if (is_ip4)
	    ip40 = vlib_buffer_get_current (b0);
	  else
	    ip60 = vlib_buffer_get_current (b0);

	  /* Setup packet for next IP feature */
	  vnet_feature_next (&next0, b0);

	  if (is_ip4)
	    /* Treat IP4 frag packets as "experimental" protocol for now
	       until support of IP frag reassembly is implemented */
	    proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
	  else
	    proto0 = ip60->protocol;

	  if (proto0 != IP_PROTOCOL_UDP)
	    goto exit;		/* not UDP packet */

	  if (is_ip4)
	    udp0 = ip4_next_header (ip40);
	  else
	    udp0 = ip6_next_header (ip60);

	  if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_geneve))
	    goto exit;		/* not GENEVE packet */

	  /* Validate DIP against VTEPs */
	  if (is_ip4)
	    {
	      if (addr4.as_u32 != ip40->dst_address.as_u32)
		{
		  if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
		    goto exit;	/* no local VTEP for GENEVE packet */
		  addr4 = ip40->dst_address;
		}
	    }
	  else
	    {
	      if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
		{
		  if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
		    goto exit;	/* no local VTEP for GENEVE packet */
		  addr6 = ip60->dst_address;
		}
	    }

	  flags0 = b0->flags;
	  good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;

	  /* Don't verify UDP checksum for packets with explicit zero checksum. */
	  good_udp0 |= udp0->checksum == 0;

	  /* Verify UDP length */
	  if (is_ip4)
	    ip_len0 = clib_net_to_host_u16 (ip40->length);
	  else
	    ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
	  udp_len0 = clib_net_to_host_u16 (udp0->length);
	  len_diff0 = ip_len0 - udp_len0;

	  /* Verify UDP checksum */
	  if (PREDICT_FALSE (!good_udp0))
	    {
	      if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
		{
		  if (is_ip4)
		    flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
		  else
		    flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
		  good_udp0 =
		    (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
		}
	    }

	  if (is_ip4)
	    {
	      error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
	      error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
	    }
	  else
	    {
	      error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
	      error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
	    }

	  next0 = error0 ?
	    IP_GENEVE_BYPASS_NEXT_DROP : IP_GENEVE_BYPASS_NEXT_GENEVE;
	  b0->error = error0 ? error_node->errors[error0] : 0;

	  /* geneve-input node expect current at GENEVE header */
	  if (is_ip4)
	    vlib_buffer_advance (b0,
				 sizeof (ip4_header_t) +
				 sizeof (udp_header_t));
	  else
	    vlib_buffer_advance (b0,
				 sizeof (ip6_header_t) +
				 sizeof (udp_header_t));

	exit:
	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
					   to_next, n_left_to_next,
					   bi0, next0);
	}

      vlib_put_next_frame (vm, node, next_index, n_left_to_next);
    }

  return frame->n_vectors;
}

static uword
ip4_geneve_bypass (vlib_main_t * vm,
		   vlib_node_runtime_t * node, vlib_frame_t * frame)
{
  return ip_geneve_bypass_inline (vm, node, frame, /* is_ip4 */ 1);
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_geneve_bypass_node) =
{
  .function = ip4_geneve_bypass,.name = "ip4-geneve-bypass",.vector_size =
    sizeof (u32),.n_next_nodes = IP_GENEVE_BYPASS_N_NEXT,.next_nodes =
  {
  [IP_GENEVE_BYPASS_NEXT_DROP] = "error-drop",
      [IP_GENEVE_BYPASS_NEXT_GENEVE] = "geneve4-input",}
,.format_buffer = format_ip4_header,.format_trace =
    format_ip4_forward_next_trace,};

VLIB_NODE_FUNCTION_MULTIARCH (ip4_geneve_bypass_node, ip4_geneve_bypass)
/* Dummy init function to get us linked in. */
     clib_error_t *ip4_geneve_bypass_init (vlib_main_t * vm)
{
  return 0;
}

VLIB_INIT_FUNCTION (ip4_geneve_bypass_init);
/* *INDENT-ON* */

static uword
ip6_geneve_bypass (vlib_main_t * vm,
		   vlib_node_runtime_t * node, vlib_frame_t * frame)
{
  return ip_geneve_bypass_inline (vm, node, frame, /* is_ip4 */ 0);
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_geneve_bypass_node) =
{
  .function = ip6_geneve_bypass,.name = "ip6-geneve-bypass",.vector_size =
    sizeof (u32),.n_next_nodes = IP_GENEVE_BYPASS_N_NEXT,.next_nodes =
  {
  [IP_GENEVE_BYPASS_NEXT_DROP] = "error-drop",
      [IP_GENEVE_BYPASS_NEXT_GENEVE] = "geneve6-input",}
,.format_buffer = format_ip6_header,.format_trace =
    format_ip6_forward_next_trace,};
/* *INDENT-ON* */

VLIB_NODE_FUNCTION_MULTIARCH (ip6_geneve_bypass_node, ip6_geneve_bypass)
/* Dummy init function to get us linked in. */
     clib_error_t *ip6_geneve_bypass_init (vlib_main_t * vm)
{
  return 0;
}

VLIB_INIT_FUNCTION (ip6_geneve_bypass_init);

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
