From patchwork Tue Nov 14 23:25:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10058571 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 4B93D602A7 for ; Tue, 14 Nov 2017 23:28:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CD8329AE9 for ; Tue, 14 Nov 2017 23:28:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FFE029AEF; Tue, 14 Nov 2017 23:28:47 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 9D1EE29AE9 for ; Tue, 14 Nov 2017 23:28:46 +0000 (UTC) Received: from localhost ([::1]:33993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEkdJ-00021a-HK for patchwork-qemu-devel@patchwork.kernel.org; Tue, 14 Nov 2017 18:28:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEkaY-0000ap-CH for qemu-devel@nongnu.org; Tue, 14 Nov 2017 18:25:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEkaU-0007yL-5J for qemu-devel@nongnu.org; Tue, 14 Nov 2017 18:25:54 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:49847) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eEkaT-0007xb-VE for qemu-devel@nongnu.org; Tue, 14 Nov 2017 18:25:50 -0500 Received: by mail-pg0-x243.google.com with SMTP id 70so4060317pgf.6 for ; Tue, 14 Nov 2017 15:25:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id; bh=3nLKhP5kUgMnFcqQzrpeeJtuymdkRJuExj928U1B8Sg=; b=IceKc7FmMqvxgh+JfD+sYQpieSHPL12hDtcNA0UnEgIxGmMLjgNuuv8S4sPVt9I+Bj JCGdTbhIBowUaXFkNKFipc4eWWSDaa/QATaZnEYDfCFr1arsxu2w3Rradby7m1aLfAMd HeKFg19mZudEvvuhbOYvXyy9BB+ntcqtlg8pA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3nLKhP5kUgMnFcqQzrpeeJtuymdkRJuExj928U1B8Sg=; b=ClRmb3CMCDQORlvwI5BSrQXM0BjE/gNaI4GOjYNwIzv1cUBLLTvrCmjSdCe5+7mWWm 56jPfT6HgVfrgNkJvaCWevyFAv3SUfK6HX2JQ/nL+YTblg27MoUClP1rXUJ97gIfNaGz bqd6xL+bY8e4MihGHZtS/XEtZrTwRhmxLpAn5YdggZTQg9ffQ8ESDwX/Bwef6EqczOr2 sdMgmASII+GBTi/lPS8o4xLgRZMDDYqu/9v+iRi1071OnRkNXrAHkrmH56d2yL0pDmxF zzscXoEN9q71Ns4DuguTZ2cixmdeGMmrK2CaJxmEK54UNasbnmdhUNp0vCQcOYIp4Pd8 GL4g== X-Gm-Message-State: AJaThX5X104LkXm4CPo1s/+f+wS2IdJddX+H7pEqUgYUH/fhU/feZ+B3 Rlu5yrjKMtA5bRwIeSso4RN6vA== X-Google-Smtp-Source: AGs4zMYqIiLRlA5FMNvvAbBeKW7sVyghav8evHUV+s0CxquOuOQrLAiydPosuVDp6/Ghv1lU7IepAw== X-Received: by 10.159.235.147 with SMTP id f19mr14033616plr.42.1510701948912; Tue, 14 Nov 2017 15:25:48 -0800 (PST) Received: from eswierk-sc.localdomain (67-207-112-138.static.wiline.com. [67.207.112.138]) by smtp.gmail.com with ESMTPSA id e18sm40825630pfi.57.2017.11.14.15.25.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Nov 2017 15:25:48 -0800 (PST) To: Jason Wang , "Daniel P . Berrange" , Stefan Hajnoczi Date: Tue, 14 Nov 2017 15:25:38 -0800 Message-Id: <1510701938-53743-1-git-send-email-eswierk@skyportsystems.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH] net: Transmit zero UDP checksum as 0xFFFF 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: , X-Patchwork-Original-From: Ed Swierk via Qemu-devel From: "Denis V. Lunev\" via" Reply-To: Ed Swierk Cc: Ed Swierk , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The checksum algorithm used by IPv4, TCP and UDP allows a zero value to be represented by either 0x0000 and 0xFFFF. But per RFC 768, a zero UDP checksum must be transmitted as 0xFFFF, as 0x0000 is a special value meaning no checksum. Substitute 0xFFFF whenever a checksum is computed as zero on a UDP datagram. Doing this on IPv4 packets and TCP segments is unnecessary but legal. (While it is tempting to make the substitution in net_checksum_finish(), that function is also used by receivers to verify checksums, and in that case the expected value is always 0x0000.) Signed-off-by: Ed Swierk --- hw/net/e1000.c | 5 +++-- hw/net/net_rx_pkt.c | 3 +++ hw/net/net_tx_pkt.c | 6 ++++++ hw/net/vmxnet3.c | 7 +++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index d642314..97242a1 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -505,8 +505,9 @@ putsum(uint8_t *data, uint32_t n, uint32_t sloc, uint32_t css, uint32_t cse) if (cse && cse < n) n = cse + 1; if (sloc < n-1) { - sum = net_checksum_add(n-css, data+css); - stw_be_p(data + sloc, net_checksum_finish(sum)); + sum = net_raw_checksum(data + css, n - css); + /* For UDP, zero checksum must be sent as 0xFFFF */ + stw_be_p(data + sloc, sum ? sum : 0xffff); } } diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 1019b50..e820132 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -588,6 +588,9 @@ bool net_rx_pkt_fix_l4_csum(struct NetRxPkt *pkt) /* Calculate L4 checksum */ csum = cpu_to_be16(_net_rx_pkt_calc_l4_csum(pkt)); + if (!csum) { + csum = 0xFFFF; /* For UDP, zero checksum must be sent as 0xFFFF */ + } /* Set calculated checksum to checksum word */ iov_from_buf(pkt->vec, pkt->vec_len, diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index 20b2549..21194e7 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -136,6 +136,9 @@ void net_tx_pkt_update_ip_checksums(struct NetTxPkt *pkt) return; } + if (!csum) { + csum = 0xFFFF; /* For UDP, zero checksum must be sent as 0xFFFF */ + } iov_from_buf(&pkt->vec[NET_TX_PKT_PL_START_FRAG], pkt->payload_frags, pkt->virt_hdr.csum_offset, &csum, sizeof(csum)); } @@ -487,6 +490,9 @@ static void net_tx_pkt_do_sw_csum(struct NetTxPkt *pkt) /* Put the checksum obtained into the packet */ csum = cpu_to_be16(net_checksum_finish(csum_cntr)); + if (!csum) { + csum = 0xFFFF; /* For UDP, zero checksum must be sent as 0xFFFF */ + } iov_from_buf(iov, iov_len, csum_offset, &csum, sizeof csum); } diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 90f6943..de9c40e 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -942,6 +942,7 @@ static void vmxnet3_rx_need_csum_calculate(struct NetRxPkt *pkt, bool isip4, isip6, istcp, isudp; uint8_t *data; int len; + uint16_t sum; if (!net_rx_pkt_has_virt_hdr(pkt)) { return; @@ -969,8 +970,10 @@ static void vmxnet3_rx_need_csum_calculate(struct NetRxPkt *pkt, data = (uint8_t *)pkt_data + vhdr->csum_start; len = pkt_len - vhdr->csum_start; - /* Put the checksum obtained into the packet */ - stw_be_p(data + vhdr->csum_offset, net_raw_checksum(data, len)); + sum = net_raw_checksum(data, len); + /* Put the checksum obtained into the packet; for UDP, zero checksum */ + /* must be sent as 0xFFFF */ + stw_be_p(data + vhdr->csum_offset, sum ? sum : 0xFFFF); vhdr->flags &= ~VIRTIO_NET_HDR_F_NEEDS_CSUM; vhdr->flags |= VIRTIO_NET_HDR_F_DATA_VALID;