aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authoreyal bari <royalbee@gmail.com>2018-04-17 11:20:27 +0300
committerJohn Lo <loj@cisco.com>2018-06-13 02:52:10 +0000
commitaf86a48733c548931f8983984328b906f7e7aef8 (patch)
treef3f612fe25f6ad14c2085c674955352187cb5ac8 /src/vnet
parent02ff5f7ce08a13477ffaae5c413a0de6aac68afd (diff)
vxlan:offload RX flow
ip4 vxlan cli/api (using flow infra) to create flows and enable them on different hardware (currently tested with i40e) to offload a vxlan tunnel onto hw: set flow-offload vxlan hw TwentyFiveGigabitEthernet3/0/0 rx vxlan_tunnel1 to remove offload: set flow-offload vxlan hw TwentyFiveGigabitEthernet3/0/0 rx vxlan_tunnel1 del TODO:ipv6 handling Change-Id: I70e61f792ef8e3f007d03d7df70e97ea4725b101 Signed-off-by: Eyal Bari <ebari@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/vxlan/decap.c372
-rw-r--r--src/vnet/vxlan/vxlan.api16
-rw-r--r--src/vnet/vxlan/vxlan.c128
-rw-r--r--src/vnet/vxlan/vxlan.h8
-rw-r--r--src/vnet/vxlan/vxlan_api.c56
5 files changed, 579 insertions, 1 deletions
diff --git a/src/vnet/vxlan/decap.c b/src/vnet/vxlan/decap.c
index 45745f7b735..e65091941bc 100644
--- a/src/vnet/vxlan/decap.c
+++ b/src/vnet/vxlan/decap.c
@@ -947,3 +947,375 @@ clib_error_t * ip6_vxlan_bypass_init (vlib_main_t * vm)
{ return 0; }
VLIB_INIT_FUNCTION (ip6_vxlan_bypass_init);
+
+#define foreach_vxlan_flow_input_next \
+_(DROP, "error-drop") \
+_(L2_INPUT, "l2-input")
+
+typedef enum
+{
+#define _(s,n) VXLAN_FLOW_NEXT_##s,
+ foreach_vxlan_flow_input_next
+#undef _
+ VXLAN_FLOW_N_NEXT,
+} vxlan_flow_input_next_t;
+
+#define foreach_vxlan_flow_error \
+ _(NONE, "no error") \
+ _(IP_CHECKSUM_ERROR, "Rx ip checksum errors") \
+ _(IP_HEADER_ERROR, "Rx ip header errors") \
+ _(UDP_CHECKSUM_ERROR, "Rx udp checksum errors") \
+ _(UDP_LENGTH_ERROR, "Rx udp length errors")
+
+typedef enum
+{
+#define _(f,s) VXLAN_FLOW_ERROR_##f,
+ foreach_vxlan_flow_error
+#undef _
+ VXLAN_FLOW_N_ERROR,
+} vxlan_flow_error_t;
+
+static char *vxlan_flow_error_strings[] = {
+#define _(n,s) s,
+ foreach_vxlan_flow_error
+#undef _
+};
+
+
+static_always_inline u8
+vxlan_validate_udp_csum (vlib_main_t * vm, vlib_buffer_t *b)
+{
+ u32 flags = b->flags;
+ enum { offset = sizeof(ip4_header_t) + sizeof(udp_header_t) + sizeof(vxlan_header_t), };
+
+ /* Verify UDP checksum */
+ if ((flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
+ {
+ vlib_buffer_advance (b, -offset);
+ flags = ip4_tcp_udp_validate_checksum (vm, b);
+ vlib_buffer_advance (b, offset);
+ }
+
+ return (flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
+}
+
+static_always_inline u8
+vxlan_check_udp_csum (vlib_main_t * vm, vlib_buffer_t *b)
+{
+ ip4_vxlan_header_t * hdr = vlib_buffer_get_current(b) - sizeof *hdr;
+ udp_header_t * udp = &hdr->udp;
+ /* Don't verify UDP checksum for packets with explicit zero checksum. */
+ u8 good_csum = (b->flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0 ||
+ udp->checksum == 0;
+
+ return !good_csum;
+}
+
+static_always_inline u8
+vxlan_check_ip (vlib_buffer_t *b, u16 payload_len)
+{
+ ip4_vxlan_header_t * hdr = vlib_buffer_get_current(b) - sizeof *hdr;
+ u16 ip_len = clib_net_to_host_u16 (hdr->ip4.length);
+ u16 expected = payload_len + sizeof *hdr;
+ return ip_len > expected || hdr->ip4.ttl == 0 || hdr->ip4.ip_version_and_header_length != 0x45;
+}
+
+static_always_inline u8
+vxlan_check_ip_udp_len (vlib_buffer_t *b)
+{
+ ip4_vxlan_header_t * hdr = vlib_buffer_get_current(b) - sizeof *hdr;
+ u16 ip_len = clib_net_to_host_u16 (hdr->ip4.length);
+ u16 udp_len = clib_net_to_host_u16 (hdr->udp.length);
+ return udp_len > ip_len;
+}
+
+static_always_inline u8
+vxlan_err_code (u8 ip_err0, u8 udp_err0, u8 csum_err0)
+{
+ u8 error0 = VXLAN_FLOW_ERROR_NONE;
+ if (ip_err0)
+ error0 = VXLAN_FLOW_ERROR_IP_HEADER_ERROR;
+ if (udp_err0)
+ error0 = VXLAN_FLOW_ERROR_UDP_LENGTH_ERROR;
+ if (csum_err0)
+ error0 = VXLAN_FLOW_ERROR_UDP_CHECKSUM_ERROR;
+ return error0;
+}
+
+uword
+CLIB_MULTIARCH_FN (vxlan_flow_input) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * f)
+{
+ enum { payload_offset = sizeof(ip4_vxlan_header_t) };
+
+ vxlan_main_t * vxm = &vxlan_main;
+ vnet_interface_main_t * im = &vnet_main.interface_main;
+ vlib_combined_counter_main_t * rx_counter[VXLAN_FLOW_N_NEXT] = {
+ [VXLAN_FLOW_NEXT_DROP] = im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_DROP,
+ [VXLAN_FLOW_NEXT_L2_INPUT] = im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
+ };
+ u32 thread_index = vlib_get_thread_index();
+
+ u32 * from = vlib_frame_vector_args (f);
+ u32 n_left_from = f->n_vectors;
+ u32 next_index = VXLAN_FLOW_NEXT_L2_INPUT;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next, *to_next;
+
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 3 && n_left_to_next > 3)
+ {
+ u32 bi0 = to_next[0] = from[0];
+ u32 bi1 = to_next[1] = from[1];
+ u32 bi2 = to_next[2] = from[2];
+ u32 bi3 = to_next[3] = from[3];
+ from+=4;
+ n_left_from-=4;
+ to_next+=4;
+ n_left_to_next-=4;
+
+ vlib_buffer_t * b0 = vlib_get_buffer (vm, bi0);
+ vlib_buffer_t * b1 = vlib_get_buffer (vm, bi1);
+ vlib_buffer_t * b2 = vlib_get_buffer (vm, bi2);
+ vlib_buffer_t * b3 = vlib_get_buffer (vm, bi3);
+
+ vlib_buffer_advance (b0, payload_offset);
+ vlib_buffer_advance (b1, payload_offset);
+ vlib_buffer_advance (b2, payload_offset);
+ vlib_buffer_advance (b3, payload_offset);
+
+ u16 len0 = vlib_buffer_length_in_chain (vm, b0);
+ u16 len1 = vlib_buffer_length_in_chain (vm, b1);
+ u16 len2 = vlib_buffer_length_in_chain (vm, b2);
+ u16 len3 = vlib_buffer_length_in_chain (vm, b3);
+
+ u32 next0 = VXLAN_FLOW_NEXT_L2_INPUT, next1 = VXLAN_FLOW_NEXT_L2_INPUT,
+ next2 = VXLAN_FLOW_NEXT_L2_INPUT, next3 = VXLAN_FLOW_NEXT_L2_INPUT;
+
+ u8 ip_err0 = vxlan_check_ip (b0, len0);
+ u8 ip_err1 = vxlan_check_ip (b1, len1);
+ u8 ip_err2 = vxlan_check_ip (b2, len2);
+ u8 ip_err3 = vxlan_check_ip (b3, len3);
+ u8 ip_err = ip_err0 | ip_err1 | ip_err2 | ip_err3;
+
+ u8 udp_err0 = vxlan_check_ip_udp_len (b0);
+ u8 udp_err1 = vxlan_check_ip_udp_len (b1);
+ u8 udp_err2 = vxlan_check_ip_udp_len (b2);
+ u8 udp_err3 = vxlan_check_ip_udp_len (b3);
+ u8 udp_err = udp_err0 | udp_err1 | udp_err2 | udp_err3;
+
+ u8 csum_err0 = vxlan_check_udp_csum (vm, b0);
+ u8 csum_err1 = vxlan_check_udp_csum (vm, b1);
+ u8 csum_err2 = vxlan_check_udp_csum (vm, b2);
+ u8 csum_err3 = vxlan_check_udp_csum (vm, b3);
+ u8 csum_err = csum_err0 | csum_err1 | csum_err2 | csum_err3;
+
+ if (PREDICT_FALSE(csum_err))
+ {
+ if (csum_err0)
+ csum_err0 = !vxlan_validate_udp_csum (vm, b0);
+ if (csum_err1)
+ csum_err1 = !vxlan_validate_udp_csum (vm, b1);
+ if (csum_err2)
+ csum_err2 = !vxlan_validate_udp_csum (vm, b2);
+ if (csum_err3)
+ csum_err3 = !vxlan_validate_udp_csum (vm, b3);
+ csum_err = csum_err0 | csum_err1 | csum_err2 | csum_err3;
+ }
+
+ if (PREDICT_FALSE(ip_err || udp_err || csum_err))
+ {
+ if (ip_err0 || udp_err0 || csum_err0)
+ {
+ next0 = VXLAN_FLOW_NEXT_DROP;
+ u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0);
+ b0->error = node->errors[error0];
+ }
+ if (ip_err1 || udp_err1 || csum_err1)
+ {
+ next1 = VXLAN_FLOW_NEXT_DROP;
+ u8 error1 = vxlan_err_code (ip_err1, udp_err1, csum_err1);
+ b1->error = node->errors[error1];
+ }
+ if (ip_err2 || udp_err2 || csum_err2)
+ {
+ next2 = VXLAN_FLOW_NEXT_DROP;
+ u8 error2 = vxlan_err_code (ip_err2, udp_err2, csum_err2);
+ b2->error = node->errors[error2];
+ }
+ if (ip_err3 || udp_err3 || csum_err3)
+ {
+ next3 = VXLAN_FLOW_NEXT_DROP;
+ u8 error3 = vxlan_err_code (ip_err3, udp_err3, csum_err3);
+ b3->error = node->errors[error3];
+ }
+ }
+
+ vnet_update_l2_len (b0);
+ vnet_update_l2_len (b1);
+ vnet_update_l2_len (b2);
+ vnet_update_l2_len (b3);
+
+ ASSERT (b0->flow_id != 0);
+ ASSERT (b1->flow_id != 0);
+ ASSERT (b2->flow_id != 0);
+ ASSERT (b3->flow_id != 0);
+
+ u32 t_index0 = b0->flow_id - vxm->flow_id_start;
+ u32 t_index1 = b1->flow_id - vxm->flow_id_start;
+ u32 t_index2 = b2->flow_id - vxm->flow_id_start;
+ u32 t_index3 = b3->flow_id - vxm->flow_id_start;
+
+ vxlan_tunnel_t * t0 = &vxm->tunnels[t_index0];
+ vxlan_tunnel_t * t1 = &vxm->tunnels[t_index1];
+ vxlan_tunnel_t * t2 = &vxm->tunnels[t_index2];
+ vxlan_tunnel_t * t3 = &vxm->tunnels[t_index3];
+
+ /* flow id consumed */
+ b0->flow_id = 0;
+ b1->flow_id = 0;
+ b2->flow_id = 0;
+ b3->flow_id = 0;
+
+ u32 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
+ u32 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX] = t1->sw_if_index;
+ u32 sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_RX] = t2->sw_if_index;
+ u32 sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_RX] = t3->sw_if_index;
+
+ vlib_increment_combined_counter (rx_counter[next0], thread_index, sw_if_index0, 1, len0);
+ vlib_increment_combined_counter (rx_counter[next1], thread_index, sw_if_index1, 1, len1);
+ vlib_increment_combined_counter (rx_counter[next2], thread_index, sw_if_index2, 1, len2);
+ vlib_increment_combined_counter (rx_counter[next3], thread_index, sw_if_index3, 1, len3);
+
+ u32 flags = b0->flags | b1->flags | b2->flags | b3->flags;
+
+ if (PREDICT_FALSE(flags & VLIB_BUFFER_IS_TRACED))
+ {
+ if (b0->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ vxlan_rx_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof *tr);
+ u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0);
+ *tr = (vxlan_rx_trace_t) {
+ .next_index = next0, .error = error0, .tunnel_index = t_index0, .vni = t0->vni };
+ }
+ if (b1->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ vxlan_rx_trace_t *tr = vlib_add_trace (vm, node, b1, sizeof *tr);
+ u8 error1 = vxlan_err_code (ip_err1, udp_err1, csum_err1);
+ *tr = (vxlan_rx_trace_t) {
+ .next_index = next1, .error = error1, .tunnel_index = t_index1, .vni = t1->vni };
+ }
+ if (b2->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ vxlan_rx_trace_t *tr = vlib_add_trace (vm, node, b2, sizeof *tr);
+ u8 error2 = vxlan_err_code (ip_err2, udp_err2, csum_err2);
+ *tr = (vxlan_rx_trace_t) {
+ .next_index = next2, .error = error2, .tunnel_index = t_index2, .vni = t2->vni };
+ }
+ if (b3->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ vxlan_rx_trace_t *tr = vlib_add_trace (vm, node, b3, sizeof *tr);
+ u8 error3 = vxlan_err_code (ip_err3, udp_err3, csum_err3);
+ *tr = (vxlan_rx_trace_t) {
+ .next_index = next3, .error = error3, .tunnel_index = t_index3, .vni = t3->vni };
+ }
+ }
+ vlib_validate_buffer_enqueue_x4
+ (vm, node, next_index, to_next, n_left_to_next,
+ bi0, bi1, bi2, bi3, next0, next1, next2, next3);
+ }
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0 = to_next[0] = from[0];
+ from++;
+ n_left_from--;
+ to_next++;
+ n_left_to_next--;
+
+ vlib_buffer_t * b0 = vlib_get_buffer (vm, bi0);
+ vlib_buffer_advance (b0, payload_offset);
+
+ u16 len0 = vlib_buffer_length_in_chain (vm, b0);
+ u32 next0 = VXLAN_FLOW_NEXT_L2_INPUT;
+
+ u8 ip_err0 = vxlan_check_ip (b0, len0);
+ u8 udp_err0 = vxlan_check_ip_udp_len (b0);
+ u8 csum_err0 = vxlan_check_udp_csum (vm, b0);
+
+ if (csum_err0)
+ csum_err0 = !vxlan_validate_udp_csum (vm, b0);
+ if (ip_err0 || udp_err0 || csum_err0)
+ {
+ next0 = VXLAN_FLOW_NEXT_DROP;
+ u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0);
+ b0->error = node->errors[error0];
+ }
+
+ vnet_update_l2_len (b0);
+
+ ASSERT (b0->flow_id != 0);
+ u32 t_index0 = b0->flow_id - vxm->flow_id_start;
+ vxlan_tunnel_t * t0 = &vxm->tunnels[t_index0];
+ b0->flow_id = 0;
+
+ u32 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
+ vlib_increment_combined_counter (rx_counter[next0], thread_index, sw_if_index0, 1, len0);
+
+ if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ vxlan_rx_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof *tr);
+ u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0);
+ *tr = (vxlan_rx_trace_t) {
+ .next_index = next0, .error = error0, .tunnel_index = t_index0, .vni = t0->vni };
+ }
+ 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 f->n_vectors;
+}
+
+/* *INDENT-OFF* */
+#ifndef CLIB_MULTIARCH_VARIANT
+VLIB_REGISTER_NODE (vxlan4_flow_input_node) = {
+ .name = "vxlan-flow-input",
+ .function = vxlan_flow_input,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .vector_size = sizeof (u32),
+
+ .format_trace = format_vxlan_rx_trace,
+
+ .n_errors = VXLAN_FLOW_N_ERROR,
+ .error_strings = vxlan_flow_error_strings,
+
+ .n_next_nodes = VXLAN_FLOW_N_NEXT,
+ .next_nodes = {
+#define _(s,n) [VXLAN_FLOW_NEXT_##s] = n,
+ foreach_vxlan_flow_input_next
+#undef _
+ },
+};
+#endif
+/* *INDENT-ON* */
+
+vlib_node_function_t __clib_weak vxlan_flow_input_avx512;
+vlib_node_function_t __clib_weak vxlan_flow_input_avx2;
+
+#if __x86_64__
+static void __clib_constructor
+vxlan_flow_input_multiarch_select (void)
+{
+ if (vxlan_flow_input_avx512 && clib_cpu_supports_avx512f ())
+ vxlan4_flow_input_node.function = vxlan_flow_input_avx512;
+ else if (vxlan_flow_input_avx2 && clib_cpu_supports_avx2 ())
+ vxlan4_flow_input_node.function = vxlan_flow_input_avx2;
+}
+#endif
diff --git a/src/vnet/vxlan/vxlan.api b/src/vnet/vxlan/vxlan.api
index dae96af6e10..9e969de7bc5 100644
--- a/src/vnet/vxlan/vxlan.api
+++ b/src/vnet/vxlan/vxlan.api
@@ -86,3 +86,19 @@ autoreply define sw_interface_set_vxlan_bypass
u8 is_ipv6;
u8 enable;
};
+
+/** \brief Offload vxlan rx request
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param hw_if_index - rx hw interface
+ @param sw_if_index - vxlan interface to offload
+ @param enable - if non-zero enable, else disable
+*/
+autoreply define vxlan_offload_rx
+{
+ u32 client_index;
+ u32 context;
+ u32 hw_if_index;
+ u32 sw_if_index;
+ u8 enable;
+};
diff --git a/src/vnet/vxlan/vxlan.c b/src/vnet/vxlan/vxlan.c
index 4f966fc323b..6b0b6c43840 100644
--- a/src/vnet/vxlan/vxlan.c
+++ b/src/vnet/vxlan/vxlan.c
@@ -20,6 +20,7 @@
#include <vnet/adj/adj_mcast.h>
#include <vnet/adj/rewrite.h>
#include <vnet/interface.h>
+#include <vnet/flow/flow.h>
#include <vlib/vlib.h>
/**
@@ -73,6 +74,10 @@ format_vxlan_tunnel (u8 * s, va_list * args)
if (PREDICT_FALSE (ip46_address_is_multicast (&t->dst)))
s = format (s, "mcast-sw-if-idx %d ", t->mcast_sw_if_index);
+ if (t->flow_index != ~0)
+ s = format (s, "flow-index %d [%U]", t->flow_index,
+ format_flow_enabled_hw, t->flow_index);
+
return s;
}
@@ -424,6 +429,7 @@ int vnet_vxlan_add_del_tunnel
t->dev_instance = dev_instance; /* actual */
t->user_instance = user_instance; /* name */
+ t->flow_index = ~0;
/* copy the key */
if (is_ip6)
@@ -572,6 +578,9 @@ int vnet_vxlan_add_del_tunnel
if (!ip46_address_is_multicast (&t->dst))
{
+ if (t->flow_index != ~0)
+ vnet_flow_del (vnm, t->flow_index);
+
vtep_addr_unref (&t->src);
fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
@@ -1020,6 +1029,122 @@ VLIB_CLI_COMMAND (set_interface_ip6_vxlan_bypass_command, static) = {
};
/* *INDENT-ON* */
+int
+vnet_vxlan_add_del_rx_flow (u32 hw_if_index, u32 t_index, int is_add)
+{
+ vxlan_main_t *vxm = &vxlan_main;
+ vxlan_tunnel_t *t = pool_elt_at_index (vxm->tunnels, t_index);
+ vnet_main_t *vnm = vnet_get_main ();
+ if (is_add)
+ {
+ if (t->flow_index == ~0)
+ {
+ vxlan_main_t *vxm = &vxlan_main;
+ vnet_flow_t flow = {
+ .actions =
+ VNET_FLOW_ACTION_REDIRECT_TO_NODE | VNET_FLOW_ACTION_MARK,
+ .mark_flow_id = t->dev_instance + vxm->flow_id_start,
+ .redirect_node_index = vxlan4_flow_input_node.index,
+ .type = VNET_FLOW_TYPE_IP4_VXLAN,
+ .ip4_vxlan = {
+ .src_addr = t->dst.ip4,
+ .dst_addr = t->src.ip4,
+ .dst_port = UDP_DST_PORT_vxlan,
+ .vni = t->vni,
+ }
+ ,
+ };
+ vnet_flow_add (vnm, &flow, &t->flow_index);
+ }
+ return vnet_flow_enable (vnm, t->flow_index, hw_if_index);
+ }
+ /* flow index is removed when the tunnel is deleted */
+ return vnet_flow_disable (vnm, t->flow_index, hw_if_index);
+}
+
+u32
+vnet_vxlan_get_tunnel_index (u32 sw_if_index)
+{
+ vxlan_main_t *vxm = &vxlan_main;
+
+ if (sw_if_index > vec_len (vxm->tunnel_index_by_sw_if_index))
+ return ~0;
+ return vxm->tunnel_index_by_sw_if_index[sw_if_index];
+}
+
+static clib_error_t *
+vxlan_offload_command_fn (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ unformat_input_t _line_input, *line_input = &_line_input;
+
+ /* Get a line of input. */
+ if (!unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ vnet_main_t *vnm = vnet_get_main ();
+ u32 rx_sw_if_index = ~0;
+ u32 hw_if_index = ~0;
+ int is_add = 1;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "hw %U", unformat_vnet_hw_interface, vnm,
+ &hw_if_index))
+ continue;
+ if (unformat (line_input, "rx %U", unformat_vnet_sw_interface, vnm,
+ &rx_sw_if_index))
+ continue;
+ if (unformat (line_input, "del"))
+ {
+ is_add = 0;
+ continue;
+ }
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, line_input);
+ }
+
+ if (rx_sw_if_index == ~0)
+ return clib_error_return (0, "missing rx interface");
+ if (hw_if_index == ~0)
+ return clib_error_return (0, "missing hw interface");
+
+ u32 t_index = vnet_vxlan_get_tunnel_index (rx_sw_if_index);;
+ if (t_index == ~0)
+ return clib_error_return (0, "%U is not a vxlan tunnel",
+ format_vnet_sw_if_index_name, vnm,
+ rx_sw_if_index);
+
+ vxlan_main_t *vxm = &vxlan_main;
+ vxlan_tunnel_t *t = pool_elt_at_index (vxm->tunnels, t_index);
+
+ if (!ip46_address_is_ip4 (&t->dst))
+ return clib_error_return (0, "currently only IPV4 tunnels are supported");
+
+ vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
+ ip4_main_t *im = &ip4_main;
+ u32 rx_fib_index =
+ vec_elt (im->fib_index_by_sw_if_index, hw_if->sw_if_index);
+
+ if (t->encap_fib_index != rx_fib_index)
+ return clib_error_return (0, "interface/tunnel fib mismatch");
+
+ if (vnet_vxlan_add_del_rx_flow (hw_if_index, t_index, is_add))
+ return clib_error_return (0, "error %s flow",
+ is_add ? "enabling" : "disabling");
+
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (vxlan_offload_command, static) = {
+ .path = "set flow-offload vxlan",
+ .short_help =
+ "set flow-offload vxlan hw <inerface-name> rx <tunnel-name> [del]",
+ .function = vxlan_offload_command_fn,
+};
+/* *INDENT-ON* */
+
clib_error_t *
vxlan_init (vlib_main_t * vm)
{
@@ -1028,6 +1153,9 @@ vxlan_init (vlib_main_t * vm)
vxm->vnet_main = vnet_get_main ();
vxm->vlib_main = vm;
+ vnet_flow_get_range (vxm->vnet_main, "vxlan", 1024 * 1024,
+ &vxm->flow_id_start);
+
/* initialize the ip6 hash */
vxm->vxlan6_tunnel_by_key = hash_create_mem (0,
sizeof (vxlan6_tunnel_key_t),
diff --git a/src/vnet/vxlan/vxlan.h b/src/vnet/vxlan/vxlan.h
index 3c74bfd4e8e..0f226aa3e72 100644
--- a/src/vnet/vxlan/vxlan.h
+++ b/src/vnet/vxlan/vxlan.h
@@ -112,6 +112,7 @@ typedef struct {
*/
u32 sibling_index;
+ u32 flow_index; /* infra flow index */
u32 dev_instance; /* Real device instance in tunnel vector */
u32 user_instance; /* Instance name being shown to user */
@@ -161,6 +162,7 @@ typedef struct {
/* Record used instances */
uword *instance_used;
+ u32 flow_id_start;
} vxlan_main_t;
extern vxlan_main_t vxlan_main;
@@ -169,6 +171,7 @@ extern vlib_node_registration_t vxlan4_input_node;
extern vlib_node_registration_t vxlan6_input_node;
extern vlib_node_registration_t vxlan4_encap_node;
extern vlib_node_registration_t vxlan6_encap_node;
+extern vlib_node_registration_t vxlan4_flow_input_node;
u8 * format_vxlan_encap_trace (u8 * s, va_list * args);
@@ -191,6 +194,11 @@ int vnet_vxlan_add_del_tunnel
void vnet_int_vxlan_bypass_mode
(u32 sw_if_index, u8 is_ip6, u8 is_enable);
+
+int vnet_vxlan_add_del_rx_flow
+(u32 hw_if_index, u32 t_imdex, int is_add);
+
+u32 vnet_vxlan_get_tunnel_index (u32 sw_if_index);
#endif /* included_vnet_vxlan_h */
/*
diff --git a/src/vnet/vxlan/vxlan_api.c b/src/vnet/vxlan/vxlan_api.c
index 8b19c3a5c44..41de44eba15 100644
--- a/src/vnet/vxlan/vxlan_api.c
+++ b/src/vnet/vxlan/vxlan_api.c
@@ -47,7 +47,61 @@
#define foreach_vpe_api_msg \
_(SW_INTERFACE_SET_VXLAN_BYPASS, sw_interface_set_vxlan_bypass) \
_(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
-_(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump)
+_(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
+_(VXLAN_OFFLOAD_RX, vxlan_offload_rx)
+
+static void
+vl_api_vxlan_offload_rx_t_handler (vl_api_vxlan_offload_rx_t * mp)
+{
+ vl_api_vxlan_offload_rx_reply_t *rmp;
+ int rv = 0;
+ u32 hw_if_index = ntohl (mp->hw_if_index);
+ u32 sw_if_index = ntohl (mp->sw_if_index);
+
+ if (!vnet_hw_interface_is_valid (vnet_get_main (), hw_if_index))
+ {
+ rv = VNET_API_ERROR_NO_SUCH_ENTRY;
+ goto err;
+ }
+ VALIDATE_SW_IF_INDEX (mp);
+
+ u32 t_index = vnet_vxlan_get_tunnel_index (sw_if_index);
+ if (t_index == ~0)
+ {
+ rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
+ goto err;
+ }
+
+ vxlan_main_t *vxm = &vxlan_main;
+ vxlan_tunnel_t *t = pool_elt_at_index (vxm->tunnels, t_index);
+ if (!ip46_address_is_ip4 (&t->dst))
+ {
+ rv = VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
+ goto err;
+ }
+
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
+ ip4_main_t *im = &ip4_main;
+ u32 rx_fib_index =
+ vec_elt (im->fib_index_by_sw_if_index, hw_if->sw_if_index);
+
+ if (t->encap_fib_index != rx_fib_index)
+ {
+ rv = VNET_API_ERROR_NO_SUCH_FIB;
+ goto err;
+ }
+
+ if (vnet_vxlan_add_del_rx_flow (hw_if_index, t_index, mp->enable))
+ {
+ rv = VNET_API_ERROR_UNSPECIFIED;
+ goto err;
+ }
+ BAD_SW_IF_INDEX_LABEL;
+err:
+
+ REPLY_MACRO (VL_API_VXLAN_OFFLOAD_RX_REPLY);
+}
static void
vl_api_sw_interface_set_vxlan_bypass_t_handler