aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/gso
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/gso')
-rw-r--r--src/vnet/gso/gso.c1
-rw-r--r--src/vnet/gso/gso.h95
-rw-r--r--src/vnet/gso/node.c49
3 files changed, 121 insertions, 24 deletions
diff --git a/src/vnet/gso/gso.c b/src/vnet/gso/gso.c
index c741b17bdd4..cf90d22696d 100644
--- a/src/vnet/gso/gso.c
+++ b/src/vnet/gso/gso.c
@@ -16,7 +16,6 @@
#include <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vppinfra/error.h>
-#include <vnet/ethernet/ethernet.h>
#include <vnet/feature/feature.h>
#include <vnet/l2/l2_in_out_feat_arc.h>
#include <vnet/gso/gso.h>
diff --git a/src/vnet/gso/gso.h b/src/vnet/gso/gso.h
index 8e174dfd1f6..79869c2644b 100644
--- a/src/vnet/gso/gso.h
+++ b/src/vnet/gso/gso.h
@@ -16,10 +16,25 @@
#ifndef included_gso_h
#define included_gso_h
+#include <vnet/ethernet/ethernet.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
+#include <vnet/udp/udp_packet.h>
#include <vnet/vnet.h>
typedef struct
{
+ i16 l2_hdr_offset;
+ i16 l3_hdr_offset;
+ i16 l4_hdr_offset;
+ u16 l4_hdr_sz;
+ i16 outer_l2_hdr_offset;
+ i16 outer_l3_hdr_offset;
+ i16 outer_l4_hdr_offset;
+} gso_header_offset_t;
+
+typedef struct
+{
vlib_main_t *vlib_main;
vnet_main_t *vnet_main;
u16 msg_id_base;
@@ -29,6 +44,86 @@ extern gso_main_t gso_main;
int vnet_sw_interface_gso_enable_disable (u32 sw_if_index, u8 enable);
+static_always_inline gso_header_offset_t
+vnet_gso_header_offset_parser (vlib_buffer_t * b0, int is_ip6)
+{
+ gso_header_offset_t gho = { 0 };
+ u8 l4_proto = 0;
+ u8 l4_hdr_sz = 0;
+
+ if (PREDICT_TRUE ((b0->flags & (VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
+ VNET_BUFFER_F_L3_HDR_OFFSET_VALID |
+ VNET_BUFFER_F_L4_HDR_OFFSET_VALID)) ==
+ (VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
+ VNET_BUFFER_F_L3_HDR_OFFSET_VALID |
+ VNET_BUFFER_F_L4_HDR_OFFSET_VALID)))
+ {
+ gho.l2_hdr_offset = vnet_buffer (b0)->l2_hdr_offset;
+ gho.l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset;
+ gho.l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset;
+ gho.l4_hdr_sz = vnet_buffer2 (b0)->gso_l4_hdr_sz;
+ return gho;
+ }
+
+ ethernet_header_t *eh = (ethernet_header_t *) vlib_buffer_get_current (b0);
+ u16 ethertype = clib_net_to_host_u16 (eh->type);
+ u16 l2hdr_sz = sizeof (ethernet_header_t);
+
+ if (ethernet_frame_is_tagged (ethertype))
+ {
+ ethernet_vlan_header_t *vlan = (ethernet_vlan_header_t *) (eh + 1);
+
+ ethertype = clib_net_to_host_u16 (vlan->type);
+ l2hdr_sz += sizeof (*vlan);
+ if (ethertype == ETHERNET_TYPE_VLAN)
+ {
+ vlan++;
+ ethertype = clib_net_to_host_u16 (vlan->type);
+ l2hdr_sz += sizeof (*vlan);
+ }
+ }
+
+ gho.l2_hdr_offset = b0->current_data;
+ gho.l3_hdr_offset = l2hdr_sz;
+
+ if (PREDICT_TRUE (is_ip6 == 0))
+ {
+ ip4_header_t *ip4 =
+ (ip4_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz);
+ gho.l4_hdr_offset = l2hdr_sz + ip4_header_bytes (ip4);
+ l4_proto = ip4->protocol;
+ }
+ else if (PREDICT_TRUE (is_ip6))
+ {
+ ip6_header_t *ip6 =
+ (ip6_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz);
+ /* FIXME IPv6 EH traversal */
+ gho.l4_hdr_offset = l2hdr_sz + sizeof (ip6_header_t);
+ l4_proto = ip6->protocol;
+ }
+ if (l4_proto == IP_PROTOCOL_TCP)
+ {
+ tcp_header_t *tcp = (tcp_header_t *) (vlib_buffer_get_current (b0) +
+ gho.l4_hdr_offset);
+ l4_hdr_sz = tcp_header_bytes (tcp);
+ tcp->checksum = 0;
+ }
+ else if (l4_proto == IP_PROTOCOL_UDP)
+ {
+ udp_header_t *udp = (udp_header_t *) (vlib_buffer_get_current (b0) +
+ gho.l4_hdr_offset);
+ l4_hdr_sz = sizeof (*udp);
+ udp->checksum = 0;
+ }
+
+ if (b0->flags & (VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_IS_IP6))
+ {
+ gho.l4_hdr_sz = l4_hdr_sz;
+ }
+
+ return gho;
+}
+
#endif /* included_gso_h */
/*
diff --git a/src/vnet/gso/node.c b/src/vnet/gso/node.c
index 069016147d4..548189ee04c 100644
--- a/src/vnet/gso/node.c
+++ b/src/vnet/gso/node.c
@@ -90,7 +90,8 @@ static_always_inline void
tso_init_buf_from_template (vlib_main_t * vm, vlib_buffer_t * nb0,
vlib_buffer_t * b0, u16 template_data_sz,
u16 gso_size, u8 ** p_dst_ptr, u16 * p_dst_left,
- u32 next_tcp_seq, u32 flags)
+ u32 next_tcp_seq, u32 flags,
+ gso_header_offset_t * gho)
{
tso_init_buf_from_template_base (nb0, b0, flags, template_data_sz);
@@ -101,29 +102,31 @@ tso_init_buf_from_template (vlib_main_t * vm, vlib_buffer_t * nb0,
*p_dst_ptr = vlib_buffer_get_current (nb0) + template_data_sz;
tcp_header_t *tcp =
- (tcp_header_t *) (nb0->data + vnet_buffer (nb0)->l4_hdr_offset);
+ (tcp_header_t *) (vlib_buffer_get_current (nb0) + gho->l4_hdr_offset);
tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq);
}
static_always_inline void
-tso_fixup_segmented_buf (vlib_buffer_t * b0, u8 tcp_flags, int is_ip6)
+tso_fixup_segmented_buf (vlib_buffer_t * b0, u8 tcp_flags, int is_ip6,
+ gso_header_offset_t * gho)
{
- u16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset;
- u16 l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset;
- ip4_header_t *ip4 = (ip4_header_t *) (b0->data + l3_hdr_offset);
- ip6_header_t *ip6 = (ip6_header_t *) (b0->data + l3_hdr_offset);
- tcp_header_t *tcp = (tcp_header_t *) (b0->data + l4_hdr_offset);
+ ip4_header_t *ip4 =
+ (ip4_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset);
+ ip6_header_t *ip6 =
+ (ip6_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset);
+ tcp_header_t *tcp =
+ (tcp_header_t *) (vlib_buffer_get_current (b0) + gho->l4_hdr_offset);
tcp->flags = tcp_flags;
if (is_ip6)
ip6->payload_length =
clib_host_to_net_u16 (b0->current_length -
- (l4_hdr_offset - b0->current_data));
+ (gho->l4_hdr_offset - gho->l2_hdr_offset));
else
ip4->length =
clib_host_to_net_u16 (b0->current_length -
- (l3_hdr_offset - b0->current_data));
+ (gho->l3_hdr_offset - gho->l2_hdr_offset));
}
/**
@@ -137,21 +140,19 @@ tso_fixup_segmented_buf (vlib_buffer_t * b0, u8 tcp_flags, int is_ip6)
static_always_inline u32
tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd,
- u32 sbi0, vlib_buffer_t * sb0, u32 n_bytes_b0, int is_ip6)
+ u32 sbi0, vlib_buffer_t * sb0, gso_header_offset_t * gho,
+ u32 n_bytes_b0, int is_ip6)
{
u32 n_tx_bytes = 0;
- ASSERT (sb0->flags & VNET_BUFFER_F_L2_HDR_OFFSET_VALID);
- ASSERT (sb0->flags & VNET_BUFFER_F_L3_HDR_OFFSET_VALID);
- ASSERT (sb0->flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID);
u16 gso_size = vnet_buffer2 (sb0)->gso_size;
- int l4_hdr_sz = vnet_buffer2 (sb0)->gso_l4_hdr_sz;
+ int l4_hdr_sz = gho->l4_hdr_sz;
u8 save_tcp_flags = 0;
u8 tcp_flags_no_fin_psh = 0;
u32 next_tcp_seq = 0;
tcp_header_t *tcp =
- (tcp_header_t *) (sb0->data + vnet_buffer (sb0)->l4_hdr_offset);
+ (tcp_header_t *) (vlib_buffer_get_current (sb0) + gho->l4_hdr_offset);
next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number);
/* store original flags for last packet and reset FIN and PSH */
save_tcp_flags = tcp->flags;
@@ -160,8 +161,7 @@ tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd,
u32 default_bflags =
sb0->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT);
- u16 l234_sz = vnet_buffer (sb0)->l4_hdr_offset + l4_hdr_sz
- - sb0->current_data;
+ u16 l234_sz = gho->l4_hdr_offset + l4_hdr_sz - gho->l2_hdr_offset;
int first_data_size = clib_min (gso_size, sb0->current_length - l234_sz);
next_tcp_seq += first_data_size;
@@ -189,13 +189,14 @@ tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd,
src_ptr = vlib_buffer_get_current (sb0) + l234_sz + first_data_size;
src_left = sb0->current_length - l234_sz - first_data_size;
- tso_fixup_segmented_buf (b0, tcp_flags_no_fin_psh, is_ip6);
+ tso_fixup_segmented_buf (b0, tcp_flags_no_fin_psh, is_ip6, gho);
/* grab a second buffer and prepare the loop */
ASSERT (dbi < vec_len (ptd->split_buffers));
cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]);
tso_init_buf_from_template (vm, cdb0, b0, l234_sz, gso_size, &dst_ptr,
- &dst_left, next_tcp_seq, default_bflags);
+ &dst_left, next_tcp_seq, default_bflags,
+ gho);
/* an arbitrary large number to catch the runaway loops */
int nloops = 2000;
@@ -241,11 +242,11 @@ tso_segment_buffer (vlib_main_t * vm, vnet_interface_per_thread_data_t * ptd,
cdb0 = vlib_get_buffer (vm, ptd->split_buffers[dbi++]);
tso_init_buf_from_template (vm, cdb0, b0, l234_sz,
gso_size, &dst_ptr, &dst_left,
- next_tcp_seq, default_bflags);
+ next_tcp_seq, default_bflags, gho);
}
}
- tso_fixup_segmented_buf (cdb0, save_tcp_flags, is_ip6);
+ tso_fixup_segmented_buf (cdb0, save_tcp_flags, is_ip6, gho);
n_tx_bytes += cdb0->current_length;
}
@@ -446,11 +447,13 @@ vnet_gso_node_inline (vlib_main_t * vm,
to_next -= 1;
n_left_to_next += 1;
/* undo the counting. */
+ gso_header_offset_t gho;
u32 n_bytes_b0 = vlib_buffer_length_in_chain (vm, b[0]);
u32 n_tx_bytes = 0;
+ gho = vnet_gso_header_offset_parser (b[0], is_ip6);
n_tx_bytes =
- tso_segment_buffer (vm, ptd, bi0, b[0], n_bytes_b0,
+ tso_segment_buffer (vm, ptd, bi0, b[0], &gho, n_bytes_b0,
is_ip6);
if (PREDICT_FALSE (n_tx_bytes == 0))