From patchwork Wed Jul 3 02:49:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Wang X-Patchwork-Id: 1955796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WDPYB5v43z1xqb for ; Wed, 3 Jul 2024 12:55:58 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 3E70D60C2D; Wed, 3 Jul 2024 02:55:56 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 4JihOTDkgiss; Wed, 3 Jul 2024 02:55:55 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3F96260BF9 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 3F96260BF9; Wed, 3 Jul 2024 02:55:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E7A10C002B; Wed, 3 Jul 2024 02:55:54 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7C787C002A for ; Wed, 3 Jul 2024 02:55:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 5716D60C0A for ; Wed, 3 Jul 2024 02:55:53 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id LVCeC2UbUNBy for ; Wed, 3 Jul 2024 02:55:52 +0000 (UTC) X-Greylist: delayed 371 seconds by postgrey-1.37 at util1.osuosl.org; Wed, 03 Jul 2024 02:55:51 UTC DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 7E44760BF9 Authentication-Results: smtp3.osuosl.org; dmarc=none (p=none dis=none) header.from=cestc.cn DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 7E44760BF9 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=13.251.65.157; helo=smtp.cecloud.com; envelope-from=junwang01@cestc.cn; receiver= Received: from smtp.cecloud.com (sg-smtp01.cecloud.com [13.251.65.157]) by smtp3.osuosl.org (Postfix) with ESMTP id 7E44760BF9 for ; Wed, 3 Jul 2024 02:55:51 +0000 (UTC) Received: from smtp.cecloud.com (unknown [103.166.174.66]) by smtp.cecloud.com (Postfix) with ESMTP id 7DAD317A for ; Wed, 3 Jul 2024 10:49:37 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by smtp.cecloud.com (Postfix) with ESMTP id 49DB1900113 for ; Wed, 3 Jul 2024 10:49:29 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from izgc79c142y6tt9fty3vzrz.localdomain (unknown [47.122.22.90]) by smtp.cecloud.com (postfix) whith ESMTP id P1340310T281473331949936S1719974962415093_; Wed, 03 Jul 2024 10:49:29 +0800 (CST) X-RL-SENDER: junwang01@cestc.cn X-SENDER: junwang01@cestc.cn X-LOGIN-NAME: junwang01@cestc.cn X-FST-TO: dev@openvswitch.org X-RCPT-COUNT: 2 X-LOCAL-RCPT-COUNT: 0 X-MUTI-DOMAIN-COUNT: 0 X-SENDER-IP: 47.122.22.90 X-ATTACHMENT-NUM: 0 X-UNIQUE-TAG: X-System-Flag: 0 From: Jun Wang To: dev@openvswitch.org Cc: david.marchand@redhat.com Date: Wed, 3 Jul 2024 10:49:18 +0800 Message-Id: <1719974958-20931-1-git-send-email-junwang01@cestc.cn> X-Mailer: git-send-email 1.8.3.1 Subject: [ovs-dev] [PATCH v1] netdev-native-tnl: Fix inner L2 pad loss causing checksum errors. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" We encountered a scenario where, if the received packet contains padding bytes, and we then add Geneve tunnel encapsulation without carrying the padding bytes, it results in checksum errors when sending out. Therefore, adding an inner_l2_pad is necessary. For example, this type of packet format: 0000 06 6c 6a 71 e1 d3 6c e2 d3 8b ea 24 81 00 03 e9 0010 08 00 45 00 00 28 9d e5 40 00 3b 06 6e 64 0a 6f 0020 05 14 0a fe 19 06 01 bb 22 ae 59 c0 8c 61 8e 26 0030 14 e3 50 10 00 7f ce 3a 00 00 00 00 9e 38 cf 64 Fixes: 084c8087292c ("userspace: Support VXLAN and GENEVE TSO.") Signed-off-by: Jun Wang --- lib/dp-packet.h | 21 ++++++++++++++++++++- lib/netdev-native-tnl.c | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/dp-packet.h b/lib/dp-packet.h index a75b1c5..d583b28 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -176,6 +176,8 @@ struct dp_packet { ovs_be32 packet_type; /* Packet type as defined in OpenFlow */ uint16_t csum_start; /* Position to start checksumming from. */ uint16_t csum_offset; /* Offset to place checksum. */ + uint16_t inner_l2_pad_size; /* Detected inner l2 padding size. + * Padding is non-pullable. */ union { struct pkt_metadata md; uint64_t data[DP_PACKET_CONTEXT_SIZE / 8]; @@ -209,7 +211,10 @@ static inline void *dp_packet_eth(const struct dp_packet *); static inline void dp_packet_reset_offsets(struct dp_packet *); static inline void dp_packet_reset_offload(struct dp_packet *); static inline uint16_t dp_packet_l2_pad_size(const struct dp_packet *); +static inline uint16_t dp_packet_inner_l2_pad_size(const struct dp_packet *); static inline void dp_packet_set_l2_pad_size(struct dp_packet *, uint16_t); +static inline void dp_packet_set_inner_l2_pad_size(struct dp_packet *, + uint16_t); static inline void *dp_packet_l2_5(const struct dp_packet *); static inline void dp_packet_set_l2_5(struct dp_packet *, void *); static inline void *dp_packet_l3(const struct dp_packet *); @@ -435,6 +440,7 @@ static inline void dp_packet_reset_offsets(struct dp_packet *b) { b->l2_pad_size = 0; + b->inner_l2_pad_size = 0; b->l2_5_ofs = UINT16_MAX; b->l3_ofs = UINT16_MAX; b->l4_ofs = UINT16_MAX; @@ -448,6 +454,12 @@ dp_packet_l2_pad_size(const struct dp_packet *b) return b->l2_pad_size; } +static inline uint16_t +dp_packet_inner_l2_pad_size(const struct dp_packet *b) +{ + return b->inner_l2_pad_size; +} + static inline void dp_packet_set_l2_pad_size(struct dp_packet *b, uint16_t pad_size) { @@ -455,6 +467,13 @@ dp_packet_set_l2_pad_size(struct dp_packet *b, uint16_t pad_size) b->l2_pad_size = pad_size; } +static inline void +dp_packet_set_inner_l2_pad_size(struct dp_packet *b, uint16_t pad_size) +{ + ovs_assert(pad_size <= dp_packet_size(b)); + b->inner_l2_pad_size = pad_size; +} + static inline void * dp_packet_l2_5(const struct dp_packet *b) { @@ -543,7 +562,7 @@ dp_packet_inner_l4_size(const struct dp_packet *b) return OVS_LIKELY(b->inner_l4_ofs != UINT16_MAX) ? (const char *) dp_packet_tail(b) - (const char *) dp_packet_inner_l4(b) - - dp_packet_l2_pad_size(b) + - dp_packet_inner_l2_pad_size(b) : 0; } diff --git a/lib/netdev-native-tnl.c b/lib/netdev-native-tnl.c index 0f9f07f..96ffdc1 100644 --- a/lib/netdev-native-tnl.c +++ b/lib/netdev-native-tnl.c @@ -156,6 +156,7 @@ netdev_tnl_push_ip_header(struct dp_packet *packet, const void *header, struct eth_header *eth; struct ip_header *ip; struct ovs_16aligned_ip6_hdr *ip6; + uint16_t l2_pad_size; eth = dp_packet_push_uninit(packet, size); *ip_tot_size = dp_packet_size(packet) - sizeof (struct eth_header); @@ -163,7 +164,9 @@ netdev_tnl_push_ip_header(struct dp_packet *packet, const void *header, memcpy(eth, header, size); /* The encapsulated packet has type Ethernet. Adjust dp_packet. */ packet->packet_type = htonl(PT_ETH); + l2_pad_size = dp_packet_l2_pad_size(packet); dp_packet_reset_offsets(packet); + dp_packet_set_inner_l2_pad_size(packet, l2_pad_size); packet->l3_ofs = sizeof (struct eth_header); if (netdev_tnl_is_header_ipv6(header)) {