From patchwork Wed Jan 21 23:36:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 2451 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 7ACB75AA1; Thu, 22 Jan 2015 00:37:13 +0100 (CET) Received: from mail-we0-f180.google.com (mail-we0-f180.google.com [74.125.82.180]) by dpdk.org (Postfix) with ESMTP id E1D8F5A15 for ; Thu, 22 Jan 2015 00:36:57 +0100 (CET) Received: by mail-we0-f180.google.com with SMTP id m14so20772117wev.11 for ; Wed, 21 Jan 2015 15:36:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wm8nwEV/ifrObt8h1EjkZnhrR7sfwDL71HOu95bmVps=; b=Tql0O4G5QE6UpL/F3fpVR0ZKP9a8HEONmBJU4ndh3PflHmBxaBKhfyJr5hyp3jP005 m/JYqK0v0JvjbSnIQGZRlfqMpO2DGbbAdSOr0dgWa4hKBaD5VUbbLiKijDPdaS//fNLt jZUaW7kD9J0TmJ5BmSOdTApoBisPLFxyacuRYzqNgqyJ/Cg6WCgE7Mn6xpTQ1UNFdBs7 cg2Kx+JslZ/Rur676uLn1E+iu9dhEPINnoeMAKm7WYAWwRctGSOGssfzE3wEceMFap4N tdZch+suwlVxYFQkKRPNNazMuf+oJCLdMfYn3gbVw+bhdmRF4/2ULp9g3ydOdXtSob1R JV2w== X-Gm-Message-State: ALoCoQmydhXq2sJLKz8wvri/j/H4Nn/XxvCIyLsBunrv3OILIYFij+vBDdoRAsBxu+mpZHCor9Sj X-Received: by 10.194.192.4 with SMTP id hc4mr31045968wjc.59.1421883417798; Wed, 21 Jan 2015 15:36:57 -0800 (PST) Received: from glumotte.dev.6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id wa5sm1710761wjc.8.2015.01.21.15.36.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jan 2015 15:36:57 -0800 (PST) From: Olivier Matz To: dev@dpdk.org Date: Thu, 22 Jan 2015 00:36:31 +0100 Message-Id: <1421883395-27235-13-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1421883395-27235-1-git-send-email-olivier.matz@6wind.com> References: <1421883395-27235-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [RFC 12/16] testpmd: introduce parse_ipv* in csum fwd engine X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" These functions may be used to parse encapsulated layers when we will support IP over GRE tunnels. No functional change. Signed-off-by: Olivier Matz --- app/test-pmd/csumonly.c | 51 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index 3921643..b023f12 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -104,6 +104,42 @@ get_udptcp_checksum(void *l3_hdr, void *l4_hdr, uint16_t ethertype) return rte_ipv6_udptcp_cksum(l3_hdr, l4_hdr); } +/* Parse an IPv4 header to fill l3_len, l4_len, and l4_proto */ +static void +parse_ipv4(struct ipv4_hdr *ipv4_hdr, uint16_t *l3_len, uint8_t *l4_proto, + uint16_t *l4_len) +{ + struct tcp_hdr *tcp_hdr; + + *l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4; + *l4_proto = ipv4_hdr->next_proto_id; + + /* only fill l4_len for TCP, it's useful for TSO */ + if (*l4_proto == IPPROTO_TCP) { + tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + *l3_len); + *l4_len = (tcp_hdr->data_off & 0xf0) >> 2; + } else + *l4_len = 0; +} + +/* Parse an IPv6 header to fill l3_len, l4_len, and l4_proto */ +static void +parse_ipv6(struct ipv6_hdr *ipv6_hdr, uint16_t *l3_len, uint8_t *l4_proto, + uint16_t *l4_len) +{ + struct tcp_hdr *tcp_hdr; + + *l3_len = sizeof(struct ipv6_hdr); + *l4_proto = ipv6_hdr->proto; + + /* only fill l4_len for TCP, it's useful for TSO */ + if (*l4_proto == IPPROTO_TCP) { + tcp_hdr = (struct tcp_hdr *)((char *)ipv6_hdr + *l3_len); + *l4_len = (tcp_hdr->data_off & 0xf0) >> 2; + } else + *l4_len = 0; +} + /* * Parse an ethernet header to fill the ethertype, l2_len, l3_len and * ipproto. This function is able to recognize IPv4/IPv6 with one optional vlan @@ -115,7 +151,6 @@ parse_ethernet(struct ether_hdr *eth_hdr, uint16_t *ethertype, uint16_t *l2_len, { struct ipv4_hdr *ipv4_hdr; struct ipv6_hdr *ipv6_hdr; - struct tcp_hdr *tcp_hdr; *l2_len = sizeof(struct ether_hdr); *ethertype = eth_hdr->ether_type; @@ -130,26 +165,18 @@ parse_ethernet(struct ether_hdr *eth_hdr, uint16_t *ethertype, uint16_t *l2_len, switch (*ethertype) { case _htons(ETHER_TYPE_IPv4): ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr + *l2_len); - *l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4; - *l4_proto = ipv4_hdr->next_proto_id; + parse_ipv4(ipv4_hdr, l3_len, l4_proto, l4_len); break; case _htons(ETHER_TYPE_IPv6): ipv6_hdr = (struct ipv6_hdr *) ((char *)eth_hdr + *l2_len); - *l3_len = sizeof(struct ipv6_hdr); - *l4_proto = ipv6_hdr->proto; + parse_ipv6(ipv6_hdr, l3_len, l4_proto, l4_len); break; default: + *l4_len = 0; *l3_len = 0; *l4_proto = 0; break; } - - if (*l4_proto == IPPROTO_TCP) { - tcp_hdr = (struct tcp_hdr *)((char *)eth_hdr + - *l2_len + *l3_len); - *l4_len = (tcp_hdr->data_off & 0xf0) >> 2; - } else - *l4_len = 0; } /* modify the IPv4 or IPv4 source address of a packet */