summaryrefslogtreecommitdiffstats
path: root/src/vnet/interface.c
AgeCommit message (Collapse)AuthorFilesLines
2018-02-16Allow providers to override glean behaviourNeale Ranns1-1/+3
and update glean address on local interface MAC change Change-Id: I530826d60c7e9db2b0fa2d45754139d82c5ea807 Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
2018-02-15Revert "Allow interface types to override glean adjacency behaivour"Ole Trøan1-3/+1
This reverts commit 8b30e471df4d42214619e1d6c50cc8298426b45f. Change-Id: I99edb236eb0a7f8ba3fba333c3481a710ebcb59c Signed-off-by: Ole Troan <ot@cisco.com>
2018-02-15Allow interface types to override glean adjacency behaivourNeale Ranns1-1/+3
update the glean adj on a local interface MAC change Change-Id: Ia5c5cde424ed0fea3431532cc5abf22b364bbab5 Signed-off-by: Neale Ranns <nranns@cisco.com>
2018-02-12Improve MTU handlingNeale Ranns1-0/+16
- setting MTU on an interface updates the L3 max bytes too - value cached in the adjacency is also updated - MTU exceeded generates ICMP to sender Change-Id: I343ec71d8e903b529594c4bd0543f04bc7f370b3 Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
2018-01-24Improve tunnel interface creation performanceJohn Lo1-21/+29
Modify interface creation to allow creation of tunnel interfaces without dedicated per tunnel output and tx nodes which are not used for most tunnel types. Also changed interface-output node function vnet_per_buffer_interface_output() so it does not rely on hw_if_index as the next node index which is not flexible nor efficient for large scale tunnel interfaces. The improvenemts are done for VXLAN, VXLAN-GPE, GENEVE and GTPU tunnels. GRE tunnel is still using per tunnel output nodes which will be changed in a separate patch with other GRE enhencements. Change-Id: I4123c01c0d2ead814417a867adb8c8a407e4df55 Signed-off-by: John Lo <loj@cisco.com>
2018-01-19Sub-Interface deletion not cleanup hash's properly (VPP-1136)John Lo1-4/+11
On deleting sub-interfaces, functions vnet_delete_sub_interface() and vnet_delete_hw_interface() are not cleaning up sub-interface related hash tables and memory properly. Change-Id: I17c7c4b2078c062c77bfe48889beb677610035ca Signed-off-by: John Lo <loj@cisco.com> (cherry picked from commit 7f5bec647c9dc743c015d461d040e63a77fd0a08)
2017-10-31Fix set interface mac address API to be endian neutralJohn Lo1-4/+5
Store and pass MAC address as 6 byte u8 array instead of u64 to make MAC address handling in set interface MAC endian neutral. The previous API handler only works for little endian. Change-Id: Ie4ec33a840bc5122ab1f17e25977e58f3466253b Signed-off-by: John Lo <loj@cisco.com>
2017-10-19VPP-1024: rewrite buffer trajectory tracerDave Barach1-6/+9
Use a proper u16 * vector to capture node indices, since vpp w/ plugins now exceeds 255 graph nodes Change-Id: Ic48cad676fa3a6116413ddf08c083dd9660783f1 Signed-off-by: Dave Barach <dave@barachs.net>
2017-08-13default update adjacency function deos not return multicast adjacencyNeale Ranns1-6/+40
by not returning a multicast adjacency type when requested, but instead returning a nbr type, the mcast adj was never correctly deleted. hence when reused the adjacency object was not realocated from the pool and when it was freed a second time a crash occured. Change-Id: Ia74ae3e889db0dfba8ec3c6a0cccfef215587ff6 Signed-off-by: Neale Ranns <nranns@cisco.com>
2017-08-01P2P EthernetPavel Kotucek1-0/+4
Change-Id: Idb97e573961b3bc2acdeef77582314590795f8c3 Signed-off-by: Pavel Kotucek <pkotucek@cisco.com>
2017-07-27Fix interface reuse when running multithreadedDamjan Marion1-4/+12
Node function pointer was not set on all node runtimes causing crash if new interface is different type. Change-Id: I4661fe883befc6cd3fc6dfc14fd44f6fa5faf27c Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-07-12Deprecate support for flattened output nodesDamjan Marion1-6/+2
Change-Id: Id117e219146d9994340fb38c00233ea67db8929b Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-06-21Introduce default rx mode for device driversDamjan Marion1-0/+1
If interface is down and queues are not configured then we are not able to change rx-mode. This change introducess default mode which is stored per interface and applied if driver wants. Change-Id: I70149c21c1530eafc148d5e4aa03fbee53dec62f Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-06-20vlib: make runtime_data handling thread-localIgor Mikhailov (imichail)1-16/+26
Change-Id: Ic2f2dc234199a5f882846880cbacff20fc8d477b Signed-off-by: Igor Mikhailov (imichail) <imichail@cisco.com>
2017-05-10vnet: introduce error state for sw interfacesDamjan Marion1-0/+7
Interfaces with error state are not allowed to go admin up Change-Id: I09fc09a5b28130aead219dccbc2e0f30ea7414cf Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-04-10Common device-input interrupt infraDamjan Marion1-0/+2
Change-Id: I23b588eb56a3f5690158449a1f9bc8053cd3d251 Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-04-07MPLS McastNeale Ranns1-1/+1
1 - interface-DPO Used in the Data-plane to change a packet's input interface 2 - MPLS multicast FIB entry Same as a unicast entry but it links to a replicate not a load-balance DPO 3 - Multicast MPLS tunnel Update MPLS tunnels to use a FIB path-list to describe the endpoint[s]. Use the path-list to generate the forwarding chain (DPOs) to link to . 4 - Resolve a path via a local label (of an mLDP LSP) For IP multicast entries to use an LSP in the replication list, we need to decribe the 'resolve-via-label' where the label is that of a multicast LSP. 5 - MPLS disposition path sets RPF-ID For a interface-less LSP (i.e. mLDP not RSVP-TE) at the tail of the LSP we still need to perform an RPF check. An MPLS disposition DPO performs the MPLS pop validation checks and sets the RPF-ID in the packet. 6 - RPF check with per-entry RPF-ID An RPF-ID is used instead of a real interface SW if index in the case the IP traffic arrives from an LSP that does not have an associated interface. Change-Id: Ib92e177be919147bafeb599729abf3d1abc2f4b3 Signed-off-by: Neale Ranns <nranns@cisco.com>
2017-02-13Basic support for LISP-GPE encapsulated NSH packetsFlorin Coras1-0/+1
Change-Id: I97fedb0f70dd18ed9bbe985407cc5fe714e8a2e2 Signed-off-by: Florin Coras <fcoras@cisco.com>
2017-01-03Fix crash on vhost-user deletion - VPP-571Wojciech Dec1-7/+10
Fixes VPP-571. VPP crashes when deleting created vhost interfaces which have not been configured with L3 or bridge-domain. Change-Id: I7fe6f2e52d4d5d77ec3c122758aa4bf43250b1d1 Signed-off-by: Wojciech Dec <wdec@cisco.com>
2016-12-28Reorganize source tree to use single autotools instanceDamjan Marion1-0/+1398
Change-Id: I7b51f88292e057c6443b12224486f2d0c9f8ae23 Signed-off-by: Damjan Marion <damarion@cisco.com>
ghlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * esp_decrypt.c : IPSec ESP decrypt node
 *
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * 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 <vnet/vnet.h>
#include <vnet/api_errno.h>
#include <vnet/ip/ip.h>

#include <vnet/ipsec/ipsec.h>
#include <vnet/ipsec/esp.h>
#include <vnet/ipsec/ipsec_io.h>

#define foreach_esp_decrypt_next                \
_(DROP, "error-drop")                           \
_(IP4_INPUT, "ip4-input-no-checksum")           \
_(IP6_INPUT, "ip6-input")                       \
_(IPSEC_GRE_INPUT, "ipsec-gre-input")

#define _(v, s) ESP_DECRYPT_NEXT_##v,
typedef enum
{
  foreach_esp_decrypt_next
#undef _
    ESP_DECRYPT_N_NEXT,
} esp_decrypt_next_t;


#define foreach_esp_decrypt_error                   \
 _(RX_PKTS, "ESP pkts received")                    \
 _(NO_BUFFER, "No buffer (packed dropped)")         \
 _(DECRYPTION_FAILED, "ESP decryption failed")      \
 _(INTEG_ERROR, "Integrity check failed")           \
 _(REPLAY, "SA replayed packet")                    \
 _(NOT_IP, "Not IP packet (dropped)")


typedef enum
{
#define _(sym,str) ESP_DECRYPT_ERROR_##sym,
  foreach_esp_decrypt_error
#undef _
    ESP_DECRYPT_N_ERROR,
} esp_decrypt_error_t;

static char *esp_decrypt_error_strings[] = {
#define _(sym,string) string,
  foreach_esp_decrypt_error
#undef _
};

typedef struct
{
  ipsec_crypto_alg_t crypto_alg;
  ipsec_integ_alg_t integ_alg;
} esp_decrypt_trace_t;

/* packet trace format function */
static u8 *
format_esp_decrypt_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 *);
  esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *);

  s = format (s, "esp: crypto %U integrity %U",
	      format_ipsec_crypto_alg, t->crypto_alg,
	      format_ipsec_integ_alg, t->integ_alg);
  return s;
}

always_inline void
esp_decrypt_cbc (vlib_main_t * vm, ipsec_sa_t * sa,
		 u8 * in, u8 * out, size_t in_len, u8 * key, u8 * iv)
{
  vnet_crypto_op_t _op, *op = &_op;


  if (PREDICT_FALSE (sa->crypto_dec_op_type == VNET_CRYPTO_OP_NONE))
    return;

  op->op = sa->crypto_dec_op_type;
  op->iv = iv;
  op->src = in;
  op->dst = out;
  op->len = in_len;
  op->key = key;

  vnet_crypto_process_ops (vm, op, 1);
}

always_inline uword
esp_decrypt_inline (vlib_main_t * vm,
		    vlib_node_runtime_t * node, vlib_frame_t * from_frame,
		    int is_ip6)
{
  ipsec_main_t *im = &ipsec_main;
  u32 *from = vlib_frame_vector_args (from_frame);
  u32 n_left_from = from_frame->n_vectors;
  u32 new_bufs[VLIB_FRAME_SIZE];
  vlib_buffer_t *i_bufs[VLIB_FRAME_SIZE], **ib = i_bufs;
  vlib_buffer_t *o_bufs[VLIB_FRAME_SIZE], **ob = o_bufs;
  u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
  u32 n_alloc, thread_index = vm->thread_index;

  n_alloc = vlib_buffer_alloc (vm, new_bufs, n_left_from);
  if (n_alloc != n_left_from)
    {
      vlib_node_increment_counter (vm, node->node_index,
				   ESP_DECRYPT_ERROR_NO_BUFFER,
				   n_left_from - n_alloc);
      if (n_alloc == 0)
	goto done;
      n_left_from = n_alloc;
    }

  vlib_get_buffers (vm, from, ib, n_left_from);
  vlib_get_buffers (vm, new_bufs, ob, n_left_from);

  while (n_left_from > 0)
    {
      esp_header_t *esp0;
      ipsec_sa_t *sa0;
      u32 sa_index0 = ~0;
      ip4_header_t *ih4 = 0, *oh4 = 0;
      ip6_header_t *ih6 = 0, *oh6 = 0;
      u8 tunnel_mode = 1;

      next[0] = ESP_DECRYPT_NEXT_DROP;

      esp0 = vlib_buffer_get_current (ib[0]);
      sa_index0 = vnet_buffer (ib[0])->ipsec.sad_index;
      sa0 = pool_elt_at_index (im->sad, sa_index0);

      /* anti-replay check */
      if (ipsec_sa_anti_replay_check (sa0, &esp0->seq))
	{
	  u32 tmp, off = n_alloc - n_left_from;
	  /* send original packet to drop node */
	  tmp = from[off];
	  from[off] = new_bufs[off];
	  new_bufs[off] = tmp;
	  ib[0]->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
	  next[0] = ESP_DECRYPT_NEXT_DROP;
	  goto trace;
	}

      vlib_increment_combined_counter
	(&ipsec_sa_counters, thread_index, sa_index0,
	 1, ib[0]->current_length);

      if (PREDICT_TRUE (sa0->integ_alg != IPSEC_INTEG_ALG_NONE))
	{
	  u8 sig[64];
	  int icv_size = sa0->integ_trunc_size;
	  clib_memset (sig, 0, sizeof (sig));
	  u8 *icv = vlib_buffer_get_current (ib[0]) + ib[0]->current_length -
	    icv_size;
	  ib[0]->current_length -= icv_size;

	  hmac_calc (vm, sa0, (u8 *) esp0, ib[0]->current_length, sig);

	  if (PREDICT_FALSE (memcmp (icv, sig, icv_size)))
	    {
	      u32 tmp, off = n_alloc - n_left_from;
	      /* send original packet to drop node */
	      tmp = from[off];
	      from[off] = new_bufs[off];
	      new_bufs[off] = tmp;
	      ib[0]->error = node->errors[ESP_DECRYPT_ERROR_INTEG_ERROR];
	      next[0] = ESP_DECRYPT_NEXT_DROP;
	      goto trace;
	    }
	}

      ipsec_sa_anti_replay_advance (sa0, &esp0->seq);

      if ((sa0->crypto_alg >= IPSEC_CRYPTO_ALG_AES_CBC_128 &&
	   sa0->crypto_alg <= IPSEC_CRYPTO_ALG_AES_CBC_256) ||
	  (sa0->crypto_alg >= IPSEC_CRYPTO_ALG_DES_CBC &&
	   sa0->crypto_alg <= IPSEC_CRYPTO_ALG_3DES_CBC))
	{
	  const int BLOCK_SIZE = sa0->crypto_block_size;
	  const int IV_SIZE = sa0->crypto_block_size;
	  esp_footer_t *f0;
	  u8 ip_hdr_size = 0;

	  int blocks =
	    (ib[0]->current_length - sizeof (esp_header_t) -
	     IV_SIZE) / BLOCK_SIZE;

	  ob[0]->current_data = sizeof (ethernet_header_t);

	  /* transport mode */
	  if (PREDICT_FALSE (!ipsec_sa_is_set_IS_TUNNEL (sa0) &&
			     !ipsec_sa_is_set_IS_TUNNEL_V6 (sa0)))
	    {
	      tunnel_mode = 0;

	      if (is_ip6)
		{
		  ip_hdr_size = sizeof (ip6_header_t);
		  ih6 = (ip6_header_t *) ((u8 *) esp0 - ip_hdr_size);
		  oh6 = vlib_buffer_get_current (ob[0]);
		}
	      else
		{
		  ip_hdr_size = sizeof (ip4_header_t);
		  if (ipsec_sa_is_set_UDP_ENCAP (sa0))
		    ih4 = (ip4_header_t *) ((u8 *) esp0 - ip_hdr_size -
					    sizeof (udp_header_t));
		  else
		    ih4 = (ip4_header_t *) ((u8 *) esp0 - ip_hdr_size);
		  oh4 = vlib_buffer_get_current (ob[0]);
		}
	    }

	  esp_decrypt_cbc (vm, sa0, esp0->data + IV_SIZE,
			   (u8 *) vlib_buffer_get_current (ob[0]) +
			   ip_hdr_size, BLOCK_SIZE * blocks,
			   sa0->crypto_key.data, esp0->data);

	  ob[0]->current_length = (blocks * BLOCK_SIZE) - 2 + ip_hdr_size;
	  ob[0]->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
	  f0 = (esp_footer_t *) ((u8 *) vlib_buffer_get_current (ob[0]) +
				 ob[0]->current_length);
	  ob[0]->current_length -= f0->pad_length;

	  /* tunnel mode */
	  if (PREDICT_TRUE (tunnel_mode))
	    {
	      if (PREDICT_TRUE (f0->next_header == IP_PROTOCOL_IP_IN_IP))
		{
		  next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
		  oh4 = vlib_buffer_get_current (ob[0]);
		}
	      else if (f0->next_header == IP_PROTOCOL_IPV6)
		next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
	      else
		{
		  vlib_node_increment_counter (vm, node->node_index,
					       ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
					       1);
		  ob[0] = 0;
		  goto trace;
		}
	    }
	  /* transport mode */
	  else
	    {
	      u32 len = vlib_buffer_length_in_chain (vm, ob[0]);
	      if (is_ip6)
		{
		  next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
		  oh6->ip_version_traffic_class_and_flow_label =
		    ih6->ip_version_traffic_class_and_flow_label;
		  oh6->protocol = f0->next_header;
		  oh6->hop_limit = ih6->hop_limit;
		  oh6->src_address.as_u64[0] = ih6->src_address.as_u64[0];
		  oh6->src_address.as_u64[1] = ih6->src_address.as_u64[1];
		  oh6->dst_address.as_u64[0] = ih6->dst_address.as_u64[0];
		  oh6->dst_address.as_u64[1] = ih6->dst_address.as_u64[1];
		  len -= sizeof (ip6_header_t);
		  oh6->payload_length = clib_host_to_net_u16 (len);
		}
	      else
		{
		  next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
		  oh4->ip_version_and_header_length = 0x45;
		  oh4->tos = ih4->tos;
		  oh4->fragment_id = 0;
		  oh4->flags_and_fragment_offset = 0;
		  oh4->ttl = ih4->ttl;
		  oh4->protocol = f0->next_header;
		  oh4->src_address.as_u32 = ih4->src_address.as_u32;
		  oh4->dst_address.as_u32 = ih4->dst_address.as_u32;
		  oh4->length = clib_host_to_net_u16 (len);
		  oh4->checksum = ip4_header_checksum (oh4);
		}
	    }

	  /* for IPSec-GRE tunnel next node is ipsec-gre-input */
	  if (PREDICT_FALSE
	      ((vnet_buffer (ib[0])->ipsec.flags) &
	       IPSEC_FLAG_IPSEC_GRE_TUNNEL))
	    next[0] = ESP_DECRYPT_NEXT_IPSEC_GRE_INPUT;

	  vnet_buffer (ob[0])->sw_if_index[VLIB_TX] = (u32) ~ 0;
	  vnet_buffer (ob[0])->sw_if_index[VLIB_RX] =
	    vnet_buffer (ib[0])->sw_if_index[VLIB_RX];
	}

    trace:
      if (PREDICT_FALSE (ib[0]->flags & VLIB_BUFFER_IS_TRACED))
	{
	  if (ob[0])
	    {
	      ob[0]->flags |= VLIB_BUFFER_IS_TRACED;
	      ob[0]->trace_index = ib[0]->trace_index;
	      esp_decrypt_trace_t *tr =
		vlib_add_trace (vm, node, ob[0], sizeof (*tr));
	      tr->crypto_alg = sa0->crypto_alg;
	      tr->integ_alg = sa0->integ_alg;
	    }
	}

      /* next */
      n_left_from -= 1;
      ib += 1;
      ob += 1;
      next += 1;
    }

  vlib_node_increment_counter (vm, node->node_index,
			       ESP_DECRYPT_ERROR_RX_PKTS, n_alloc);

  vlib_buffer_enqueue_to_next (vm, node, new_bufs, nexts, n_alloc);
done:
  vlib_buffer_free (vm, from, from_frame->n_vectors);
  return n_alloc;
}

VLIB_NODE_FN (esp4_decrypt_node) (vlib_main_t * vm,
				  vlib_node_runtime_t * node,
				  vlib_frame_t * from_frame)
{
  return esp_decrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ );
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (esp4_decrypt_node) = {
  .name = "esp4-decrypt",
  .vector_size = sizeof (u32),
  .format_trace = format_esp_decrypt_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,

  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
  .error_strings = esp_decrypt_error_strings,

  .n_next_nodes = ESP_DECRYPT_N_NEXT,
  .next_nodes = {
#define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
    foreach_esp_decrypt_next
#undef _
  },
};
/* *INDENT-ON* */

VLIB_NODE_FN (esp6_decrypt_node) (vlib_main_t * vm,
				  vlib_node_runtime_t * node,
				  vlib_frame_t * from_frame)
{
  return esp_decrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ );
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (esp6_decrypt_node) = {
  .name = "esp6-decrypt",
  .vector_size = sizeof (u32),
  .format_trace = format_esp_decrypt_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,

  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
  .error_strings = esp_decrypt_error_strings,

  .n_next_nodes = ESP_DECRYPT_N_NEXT,
  .next_nodes = {
#define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
    foreach_esp_decrypt_next
#undef _
  },
};
/* *INDENT-ON* */

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