From patchwork Sat May 21 08:01:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Christophe Dubois X-Patchwork-Id: 9130293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 333D86048B for ; Sat, 21 May 2016 08:06:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24A3A28093 for ; Sat, 21 May 2016 08:06:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18C6528117; Sat, 21 May 2016 08:06:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BD66D28093 for ; Sat, 21 May 2016 08:05:59 +0000 (UTC) Received: from localhost ([::1]:39243 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b41v4-0002BD-SQ for patchwork-qemu-devel@patchwork.kernel.org; Sat, 21 May 2016 04:05:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b41qk-0006fS-B9 for qemu-devel@nongnu.org; Sat, 21 May 2016 04:01:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b41qe-0002x2-By for qemu-devel@nongnu.org; Sat, 21 May 2016 04:01:30 -0400 Received: from zose-mta05.web4all.fr ([185.49.20.50]:53470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b41qe-0002wx-5j for qemu-devel@nongnu.org; Sat, 21 May 2016 04:01:24 -0400 Received: from localhost (localhost [127.0.0.1]) by zose-mta05.web4all.fr (Postfix) with ESMTP id 88374405BB; Sat, 21 May 2016 10:01:23 +0200 (CEST) Received: from zose-mta05.web4all.fr ([127.0.0.1]) by localhost (zose-mta05.web4all.fr [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id AMQ3iGPhffoL; Sat, 21 May 2016 10:01:23 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zose-mta05.web4all.fr (Postfix) with ESMTP id 29E4F4058C; Sat, 21 May 2016 10:01:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at zose-mta-05.w4a.fr Received: from zose-mta05.web4all.fr ([127.0.0.1]) by localhost (zose-mta05.web4all.fr [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id zZVGLcs1Scmb; Sat, 21 May 2016 10:01:23 +0200 (CEST) Received: from localhost.localdomain (smm49-1-78-235-240-156.fbx.proxad.net [78.235.240.156]) by zose-mta05.web4all.fr (Postfix) with ESMTPSA id CE20A405BB; Sat, 21 May 2016 10:01:22 +0200 (CEST) From: Jean-Christophe Dubois To: qemu-devel@nongnu.org, peter.maydell@linaro.org, jasowang@redhat.com Date: Sat, 21 May 2016 10:01:21 +0200 Message-Id: <5ce8f5e213bf3a32cf4524fee5022ef0f164fc8b.1463816701.git.jcd@tribudubois.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.49.20.50 Subject: [Qemu-devel] [PATCH v5 02/10] net: handle optional VLAN header in checksum computation. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Christophe Dubois Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jean-Christophe Dubois --- 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 */