devices: fix the header offsets in af_packet 48/37448/1
authorMohsin Kazmi <sykazmi@cisco.com>
Mon, 17 Oct 2022 18:27:21 +0000 (18:27 +0000)
committerMohsin Kazmi <sykazmi@cisco.com>
Mon, 17 Oct 2022 18:32:11 +0000 (18:32 +0000)
Type: fix

Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: I7fc645c46d285ceb13903f5835c99e9b6a9e5b07

src/vnet/devices/af_packet/device.c

index 74bc1c8..1d14c9b 100644 (file)
@@ -235,29 +235,37 @@ static_always_inline void
 fill_gso_offload (vlib_buffer_t *b0, vnet_virtio_net_hdr_t *vnet_hdr)
 {
   vnet_buffer_oflags_t oflags = vnet_buffer (b0)->oflags;
+  i16 l4_hdr_offset =
+    vnet_buffer (b0)->l4_hdr_offset - vnet_buffer (b0)->l2_hdr_offset;
   if (b0->flags & VNET_BUFFER_F_IS_IP4)
     {
       ip4_header_t *ip4;
       vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
       vnet_hdr->gso_size = vnet_buffer2 (b0)->gso_size;
-      vnet_hdr->hdr_len =
-       vnet_buffer (b0)->l4_hdr_offset + vnet_buffer2 (b0)->gso_l4_hdr_sz;
+      vnet_hdr->hdr_len = l4_hdr_offset + vnet_buffer2 (b0)->gso_l4_hdr_sz;
       vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-      vnet_hdr->csum_start = vnet_buffer (b0)->l4_hdr_offset; // 0x22;
+      vnet_hdr->csum_start = l4_hdr_offset; // 0x22;
       vnet_hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
       ip4 = (ip4_header_t *) (b0->data + vnet_buffer (b0)->l3_hdr_offset);
       if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM)
        ip4->checksum = ip4_header_checksum (ip4);
+      tcp_header_t *tcp =
+       (tcp_header_t *) (b0->data + vnet_buffer (b0)->l4_hdr_offset);
+      tcp->checksum = ip4_pseudo_header_cksum (ip4);
     }
   else if (b0->flags & VNET_BUFFER_F_IS_IP6)
     {
+      ip6_header_t *ip6;
       vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
       vnet_hdr->gso_size = vnet_buffer2 (b0)->gso_size;
-      vnet_hdr->hdr_len =
-       vnet_buffer (b0)->l4_hdr_offset + vnet_buffer2 (b0)->gso_l4_hdr_sz;
+      vnet_hdr->hdr_len = l4_hdr_offset + vnet_buffer2 (b0)->gso_l4_hdr_sz;
       vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-      vnet_hdr->csum_start = vnet_buffer (b0)->l4_hdr_offset; // 0x36;
+      vnet_hdr->csum_start = l4_hdr_offset; // 0x36;
       vnet_hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
+      ip6 = (ip6_header_t *) (b0->data + vnet_buffer (b0)->l3_hdr_offset);
+      tcp_header_t *tcp =
+       (tcp_header_t *) (b0->data + vnet_buffer (b0)->l4_hdr_offset);
+      tcp->checksum = ip6_pseudo_header_cksum (ip6);
     }
 }
 
@@ -265,6 +273,8 @@ static_always_inline void
 fill_cksum_offload (vlib_buffer_t *b0, vnet_virtio_net_hdr_t *vnet_hdr)
 {
   vnet_buffer_oflags_t oflags = vnet_buffer (b0)->oflags;
+  i16 l4_hdr_offset =
+    vnet_buffer (b0)->l4_hdr_offset - vnet_buffer (b0)->l2_hdr_offset;
   if (b0->flags & VNET_BUFFER_F_IS_IP4)
     {
       ip4_header_t *ip4;
@@ -272,7 +282,7 @@ fill_cksum_offload (vlib_buffer_t *b0, vnet_virtio_net_hdr_t *vnet_hdr)
       if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM)
        ip4->checksum = ip4_header_checksum (ip4);
       vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-      vnet_hdr->csum_start = 0x22;
+      vnet_hdr->csum_start = l4_hdr_offset;
       if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)
        {
          tcp_header_t *tcp =
@@ -292,7 +302,7 @@ fill_cksum_offload (vlib_buffer_t *b0, vnet_virtio_net_hdr_t *vnet_hdr)
     {
       ip6_header_t *ip6;
       vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
-      vnet_hdr->csum_start = 0x36;
+      vnet_hdr->csum_start = l4_hdr_offset;
       ip6 = (ip6_header_t *) (b0->data + vnet_buffer (b0)->l3_hdr_offset);
       if (oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)
        {