All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Christophe Dubois <jcd@tribudubois.net>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org, jasowang@redhat.com
Cc: Jean-Christophe Dubois <jcd@tribudubois.net>
Subject: [Qemu-devel] [PATCH v5 02/10] net: handle optional VLAN header in checksum computation.
Date: Sat, 21 May 2016 10:01:21 +0200	[thread overview]
Message-ID: <5ce8f5e213bf3a32cf4524fee5022ef0f164fc8b.1463816701.git.jcd@tribudubois.net> (raw)
In-Reply-To: <cover.1463816701.git.jcd@tribudubois.net>

Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
---

Changes since v1:
 * Not present on v1
 
Changes since v2:
 * Not present on v2

Changes since v3:
 * local variable name change.

Changes since v4:
 * None

 net/checksum.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/net/checksum.c b/net/checksum.c
index f62b18a..62d3465 100644
--- a/net/checksum.c
+++ b/net/checksum.c
@@ -55,7 +55,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
 
 void net_checksum_calculate(uint8_t *data, int length)
 {
-    int ip_len;
+    int mac_hdr_len, ip_len;
     struct ip_header *ip;
 
     /*
@@ -64,12 +64,39 @@ void net_checksum_calculate(uint8_t *data, int length)
      * struct members (just in case).
      */
 
-    /* Ensure data has complete L2 & L3 headers. */
-    if (length < (sizeof(struct eth_header) + sizeof(struct ip_header))) {
+    /* Ensure we have at least an Eth header */
+    if (length < sizeof(struct eth_header)) {
         return;
     }
 
-    ip = (struct ip_header *)(data + sizeof(struct eth_header));
+    /* Handle the optionnal VLAN headers */
+    switch (lduw_be_p(&PKT_GET_ETH_HDR(data)->h_proto)) {
+    case ETH_P_VLAN:
+        mac_hdr_len = sizeof(struct eth_header) +
+                     sizeof(struct vlan_header);
+        break;
+    case ETH_P_DVLAN:
+        if (lduw_be_p(&PKT_GET_VLAN_HDR(data)->h_proto) == ETH_P_VLAN) {
+            mac_hdr_len = sizeof(struct eth_header) +
+                         2 * sizeof(struct vlan_header);
+        } else {
+            mac_hdr_len = sizeof(struct eth_header) +
+                         sizeof(struct vlan_header);
+        }
+        break;
+    default:
+        mac_hdr_len = sizeof(struct eth_header);
+        break;
+    }
+
+    length -= mac_hdr_len;
+
+    /* Now check we have an IP header (with an optionnal VLAN header) */
+    if (length < sizeof(struct ip_header)) {
+        return;
+    }
+
+    ip = (struct ip_header *)(data + mac_hdr_len);
 
     if (IP_HEADER_VERSION(ip) != IP_HEADER_VERSION_4) {
         return; /* not IPv4 */
-- 
2.7.4

  parent reply	other threads:[~2016-05-21  8:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-21  8:01 [Qemu-devel] [PATCH v5 00/10] Add Ethernet device for i.MX6 SOC Jean-Christophe Dubois
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 01/10] net: improve UDP/TCP checksum computation Jean-Christophe Dubois
2016-05-21  8:01 ` Jean-Christophe Dubois [this message]
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 03/10] i.MX: Fix FEC code for MDIO operation selection Jean-Christophe Dubois
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 04/10] i.MX: Fix FEC code for MDIO address selection Jean-Christophe Dubois
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 05/10] i.MX: Fix FEC code for ECR register reset value Jean-Christophe Dubois
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 06/10] i.MX: reset TX/RX descriptors when FEC is disabled Jean-Christophe Dubois
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 07/10] i.MX: Rename i.MX FEC defines to ENET_XXX Jean-Christophe Dubois
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 08/10] i.MX: move FEC device to a register array structure Jean-Christophe Dubois
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 09/10] Add ENET/Gbps Ethernet support to FEC device Jean-Christophe Dubois
2016-05-21  8:01 ` [Qemu-devel] [PATCH v5 10/10] Add ENET device to i.MX6 SOC Jean-Christophe Dubois
2016-05-30  2:19 ` [Qemu-devel] [PATCH v5 00/10] Add Ethernet device for " Jason Wang
2016-05-30  6:04   ` Jean-Christophe DUBOIS
2016-05-30  6:10     ` Jason Wang
2016-05-30 17:56       ` Jean-Christophe DUBOIS

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ce8f5e213bf3a32cf4524fee5022ef0f164fc8b.1463816701.git.jcd@tribudubois.net \
    --to=jcd@tribudubois.net \
    --cc=jasowang@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.