From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 75D7A42DFC; Fri, 7 Jul 2023 22:39:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 61B0C4114A; Fri, 7 Jul 2023 22:39:15 +0200 (CEST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 4B6EA410F2 for ; Fri, 7 Jul 2023 22:39:14 +0200 (CEST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1b8bbcfd89aso13075165ad.1 for ; Fri, 07 Jul 2023 13:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688762353; x=1691354353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fyd9fvDhmU+f9LsoJiKnaY2sIp+gPp8qyRItqoaA58Y=; b=ylfMHjzVK3TrytjCFjhnS1ELqj4CU+Vt7p2JG6DxHMB4SGOC7uXASzqLh6Pv0jdL48 EWn4n4Ufj5nE2+FNZ8kcsThjLAE0rcA0VRvcLMXkhHTV3r4IzdnZ/MBFvpVxDGxc4wdy zA1KtfMNJkC7cwvV2gkrFXkI7Hl8r/xAGjVEE08ACpHL+CCM0wOmgWzN0GAqIyt1Dvq8 OoNdA14S5EHa6KqvnLhoQkggY9okLpivG6AyoxHyGmC4f/KTmyYzfVKAll7Xs6eJk4/K o39LnSstouZg6S+SD8c6Xzexdu/Z6g8V/oMfH3uN3XMxY2z7hGSJJRZX4tFYsWemfMZ1 LhBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762353; x=1691354353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fyd9fvDhmU+f9LsoJiKnaY2sIp+gPp8qyRItqoaA58Y=; b=Tpqc5x942FDGnMYQC+P0Or1hDNKozTNf3D72GgytlC92OmmGzpbp+uo1Sekm/rnEZ3 aBoXe5DlKnfie89gakoVF06h4YngIPVU+9uY/qEqABcBbUa1Hkqn1NrNAeA/hBgWdYPe I0BC66cA1caXOYzpX7TVFzjZCoeeuTrK7sV8NUu9/RJol3kV7rx/u6sMjQCRHbl2hxb9 tIWzLSIJaK5VyDZVZdPYOAfuFLx/Hqm7d0MruplR5OdAhcTdL7vT6od1ZzGjlUQoc7x7 o9ILWeHEBuLDzpUURQcPH8EpOj3vnmogTeobq2TBYhEpOEWVu21gii5wQSVsU5VbrGri 3ixA== X-Gm-Message-State: ABy/qLZUCWeyv7GDXTulNP9EWJc7dQOePDCvJ0u+UL9gw98VNwmSI/bF 4wtRMVOmAz7OVIMmIBQmNXfUBzl9725yL7Vdc/UJF1Cf X-Google-Smtp-Source: APBJJlGLQ7VRw7GM56PlY6LmRuxTbMnXSX4FjhWYcrnEyjMybaHJlkZNGuA+B+tV016nkzJV9wTspg== X-Received: by 2002:a17:902:d4ce:b0:1ac:8be5:8787 with SMTP id o14-20020a170902d4ce00b001ac8be58787mr5626394plg.21.1688762353225; Fri, 07 Jul 2023 13:39:13 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id t15-20020a170902b20f00b001b83db0bcf2sm3640493plr.141.2023.07.07.13.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:39:12 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Jiayu Hu Subject: [PATCH v4 02/11] gso: use rte_pktmbuf_mtod_offset Date: Fri, 7 Jul 2023 13:38:59 -0700 Message-Id: <20230707203908.64371-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230707203908.64371-1-stephen@networkplumber.org> References: <20230505174813.133894-1-stephen@networkplumber.org> <20230707203908.64371-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Replace explicit packet offset computations with rte_pktmbuf_mtod_offset(). Signed-off-by: Stephen Hemminger --- lib/gso/gso_common.h | 12 ++++++------ lib/gso/gso_tcp4.c | 8 ++++---- lib/gso/gso_tunnel_tcp4.c | 12 ++++++------ lib/gso/gso_tunnel_udp4.c | 18 +++++++++--------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/gso/gso_common.h b/lib/gso/gso_common.h index 9456d596d3c5..4100765f2355 100644 --- a/lib/gso/gso_common.h +++ b/lib/gso/gso_common.h @@ -52,8 +52,8 @@ update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset) { struct rte_udp_hdr *udp_hdr; - udp_hdr = (struct rte_udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - udp_offset); + udp_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr *, + udp_offset); udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset); } @@ -77,8 +77,8 @@ update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t sent_seq, { struct rte_tcp_hdr *tcp_hdr; - tcp_hdr = (struct rte_tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - l4_offset); + tcp_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_tcp_hdr *, + l4_offset); tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq); if (likely(non_tail)) tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK | @@ -104,8 +104,8 @@ update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id) { struct rte_ipv4_hdr *ipv4_hdr; - ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - l3_offset); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + l3_offset); ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset); ipv4_hdr->packet_id = rte_cpu_to_be_16(id); } diff --git a/lib/gso/gso_tcp4.c b/lib/gso/gso_tcp4.c index d31feaff95cd..e2ae4aaf6c5a 100644 --- a/lib/gso/gso_tcp4.c +++ b/lib/gso/gso_tcp4.c @@ -16,8 +16,8 @@ update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta, uint16_t l3_offset = pkt->l2_len; uint16_t l4_offset = l3_offset + pkt->l3_len; - ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char*) + - l3_offset); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + l3_offset); tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len); id = rte_be_to_cpu_16(ipv4_hdr->packet_id); sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq); @@ -46,8 +46,8 @@ gso_tcp4_segment(struct rte_mbuf *pkt, int ret; /* Don't process the fragmented packet */ - ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - pkt->l2_len); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + pkt->l2_len); frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset); if (unlikely(IS_FRAGMENTED(frag_off))) { return 0; diff --git a/lib/gso/gso_tunnel_tcp4.c b/lib/gso/gso_tunnel_tcp4.c index 1a7ef30ddebf..3a9159774b27 100644 --- a/lib/gso/gso_tunnel_tcp4.c +++ b/lib/gso/gso_tunnel_tcp4.c @@ -23,13 +23,13 @@ update_tunnel_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta, tcp_offset = inner_ipv4_offset + pkt->l3_len; /* Outer IPv4 header. */ - ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - outer_ipv4_offset); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + outer_ipv4_offset); outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id); /* Inner IPv4 header. */ - ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - inner_ipv4_offset); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + inner_ipv4_offset); inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id); tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len); @@ -65,8 +65,8 @@ gso_tunnel_tcp4_segment(struct rte_mbuf *pkt, int ret; hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len; - inner_ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - hdr_offset); + inner_ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + hdr_offset); /* * Don't process the packet whose MF bit or offset in the inner * IPv4 header are non-zero. diff --git a/lib/gso/gso_tunnel_udp4.c b/lib/gso/gso_tunnel_udp4.c index 1fc7a8dbc5aa..4fb275484ca8 100644 --- a/lib/gso/gso_tunnel_udp4.c +++ b/lib/gso/gso_tunnel_udp4.c @@ -22,13 +22,13 @@ update_tunnel_ipv4_udp_headers(struct rte_mbuf *pkt, struct rte_mbuf **segs, inner_ipv4_offset = outer_udp_offset + pkt->l2_len; /* Outer IPv4 header. */ - ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - outer_ipv4_offset); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + outer_ipv4_offset); outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id); /* Inner IPv4 header. */ - ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - inner_ipv4_offset); + ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + inner_ipv4_offset); inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id); tail_idx = nb_segs - 1; @@ -42,9 +42,9 @@ update_tunnel_ipv4_udp_headers(struct rte_mbuf *pkt, struct rte_mbuf **segs, * * Set IP fragment offset for inner IP header. */ - ipv4_hdr = (struct rte_ipv4_hdr *) - (rte_pktmbuf_mtod(segs[i], char *) + - inner_ipv4_offset); + ipv4_hdr = rte_pktmbuf_mtod_offset(segs[i], + struct rte_ipv4_hdr *, + inner_ipv4_offset); is_mf = i < tail_idx ? IPV4_HDR_MF_BIT : 0; ipv4_hdr->fragment_offset = rte_cpu_to_be_16(frag_offset | is_mf); @@ -67,8 +67,8 @@ gso_tunnel_udp4_segment(struct rte_mbuf *pkt, int ret; hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len; - inner_ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + - hdr_offset); + inner_ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, + hdr_offset); /* * Don't process the packet whose MF bit or offset in the inner * IPv4 header are non-zero. -- 2.39.2