aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/dpdk/device/node.c2
-rw-r--r--src/vat/api_format.c111
-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
-rw-r--r--src/vpp/api/custom_dump.c15
8 files changed, 701 insertions, 7 deletions
diff --git a/src/plugins/dpdk/device/node.c b/src/plugins/dpdk/device/node.c
index b4fadf0cebf..602891dbabe 100644
--- a/src/plugins/dpdk/device/node.c
+++ b/src/plugins/dpdk/device/node.c
@@ -500,7 +500,7 @@ dpdk_device_input (vlib_main_t * vm, dpdk_main_t * dm, dpdk_device_t * xd,
next_index = xd->per_interface_next_index;
}
- /* as all packets belong to thr same interface feature arc lookup
+ /* as all packets belong to the same interface feature arc lookup
can be don once and result stored in the buffer template */
if (PREDICT_FALSE (vnet_device_input_have_features (xd->sw_if_index)))
{
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 89843e41d08..635b4ef72ba 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -177,6 +177,12 @@ api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
return 1;
}
+static uword
+api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
+{
+ return 0;
+}
+
/* Parse an IP4 address %d.%d.%d.%d. */
uword
unformat_ip4_address (unformat_input_t * input, va_list * args)
@@ -440,14 +446,20 @@ api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
vat_main_t *vam __attribute__ ((unused)) = va_arg (*args, vat_main_t *);
vnet_main_t *vnm = vnet_get_main ();
u32 *result = va_arg (*args, u32 *);
- u32 sw_if_index;
- if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
- return 0;
+ return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
+}
- *result = sw_if_index;
- return 1;
+static uword
+api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
+{
+ vat_main_t *vam __attribute__ ((unused)) = va_arg (*args, vat_main_t *);
+ vnet_main_t *vnm = vnet_get_main ();
+ u32 *result = va_arg (*args, u32 *);
+
+ return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
}
+
#endif /* VPP_API_TEST_BUILTIN */
static uword
@@ -2274,6 +2286,38 @@ static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
vam->result_ready = 1;
}
+static void vl_api_vxlan_offload_rx_reply_t_handler
+ (vl_api_vxlan_offload_rx_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ i32 retval = ntohl (mp->retval);
+ if (vam->async_mode)
+ {
+ vam->async_errors += (retval < 0);
+ }
+ else
+ {
+ vam->retval = retval;
+ vam->result_ready = 1;
+ }
+}
+
+static void vl_api_vxlan_offload_rx_reply_t_handler_json
+ (vl_api_vxlan_offload_rx_reply_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ vat_json_node_t node;
+
+ vat_json_init_object (&node);
+ vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
+
+ vat_json_print (vam->ofp, &node);
+ vat_json_free (&node);
+
+ vam->retval = ntohl (mp->retval);
+ vam->result_ready = 1;
+}
+
static void vl_api_geneve_add_del_tunnel_reply_t_handler
(vl_api_geneve_add_del_tunnel_reply_t * mp)
{
@@ -5682,6 +5726,7 @@ _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
+_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
_(GENEVE_ADD_DEL_TUNNEL_REPLY, geneve_add_del_tunnel_reply) \
_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
_(GENEVE_TUNNEL_DETAILS, geneve_tunnel_details) \
@@ -12856,6 +12901,59 @@ api_sw_interface_tap_v2_dump (vat_main_t * vam)
return ret;
}
+static int
+api_vxlan_offload_rx (vat_main_t * vam)
+{
+ unformat_input_t *line_input = vam->input;
+ vl_api_vxlan_offload_rx_t *mp;
+ u32 hw_if_index = ~0, rx_if_index = ~0;
+ u8 is_add = 1;
+ int ret;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "del"))
+ is_add = 0;
+ else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
+ &hw_if_index))
+ ;
+ else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
+ ;
+ else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
+ &rx_if_index))
+ ;
+ else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
+ ;
+ else
+ {
+ errmsg ("parse error '%U'", format_unformat_error, line_input);
+ return -99;
+ }
+ }
+
+ if (hw_if_index == ~0)
+ {
+ errmsg ("no hw interface");
+ return -99;
+ }
+
+ if (rx_if_index == ~0)
+ {
+ errmsg ("no rx tunnel");
+ return -99;
+ }
+
+ M (VXLAN_OFFLOAD_RX, mp);
+
+ mp->hw_if_index = ntohl (hw_if_index);
+ mp->sw_if_index = ntohl (rx_if_index);
+ mp->enable = is_add;
+
+ S (mp);
+ W (ret);
+ return ret;
+}
+
static uword unformat_vxlan_decap_next
(unformat_input_t * input, va_list * args)
{
@@ -23650,6 +23748,9 @@ _(l2tpv3_interface_enable_disable, \
_(l2tpv3_set_lookup_key, \
"lookup_v6_src | lookup_v6_dst | lookup_session_id") \
_(sw_if_l2tpv3_tunnel_dump, "") \
+_(vxlan_offload_rx, \
+ "hw { <interface name> | hw_if_index <nn>} " \
+ "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
_(vxlan_add_del_tunnel, \
"src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
"{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
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
diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c
index 12b5481d828..b57313158b4 100644
--- a/src/vpp/api/custom_dump.c
+++ b/src/vpp/api/custom_dump.c
@@ -1634,6 +1634,20 @@ static void *vl_api_vxlan_add_del_tunnel_t_print
FINISH;
}
+static void *vl_api_vxlan_offload_rx_t_print
+ (vl_api_vxlan_offload_rx_t * mp, void *handle)
+{
+ u8 *s;
+ s = format (0, "SCRIPT: vxlan_offload_rx ");
+
+ s = format (s, "hw hw_if_index %d ", ntohl (mp->hw_if_index));
+ s = format (s, "rx sw_if_index %d ", ntohl (mp->sw_if_index));
+ if (!mp->enable)
+ s = format (s, "del ");
+
+ FINISH;
+}
+
static void *vl_api_vxlan_tunnel_dump_t_print
(vl_api_vxlan_tunnel_dump_t * mp, void *handle)
{
@@ -3564,6 +3578,7 @@ _(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key) \
_(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump) \
_(VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel) \
_(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump) \
+_(VXLAN_OFFLOAD_RX, vxlan_offload_rx) \
_(GENEVE_ADD_DEL_TUNNEL, geneve_add_del_tunnel) \
_(GENEVE_TUNNEL_DUMP, geneve_tunnel_dump) \
_(GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel) \