From patchwork Wed Feb 4 09:25:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 2954 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 251FBADFF; Wed, 4 Feb 2015 10:25:56 +0100 (CET) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) by dpdk.org (Postfix) with ESMTP id 45CF6ADFC for ; Wed, 4 Feb 2015 10:25:55 +0100 (CET) Received: by mail-we0-f181.google.com with SMTP id k48so509827wev.12 for ; Wed, 04 Feb 2015 01:25:55 -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=UhVjWBMWKEe0EhDYeQadY4K0sJsShMtxTbTC6R+hb9Y=; b=LohhkCVhhtENn8YTJoh3A/DYFyObHOaw7jGHHKVpPCMoaJEEaYVHLUQQxdRFLmDWhP ywYC1zlDKmFpbkgitHpFZI3zJ0VL2KcqPkWqPGq7JARPbPLJ8BbFz3Jh9da4d4Hp6f6h vn527uZ1bW/Gzmi/9sFtAyJWEmeQEiugnFsAa1ngxSHEAYJa/hYAAoIWdDPFfttP0Ran mE8a1FhH7RqKMcYAMKqnnlHsREqaBbSqJ8eLU7h0ulvFbMrXWNt5qyCK2EoRBVTQL2A1 5FDE+3kanNaekkqCxAtkJFCD2Or8nXXiNMnsTLz+7Ztdn6bVDk4SI1wz6hPfJmr0S1aD DT7w== X-Gm-Message-State: ALoCoQmTxzlQjlRgl0nOruHjfcN7CMYsAkdMm9xvGqZKzKh07SdUOlOMQhTdoxQIqngKKTTrmNHR X-Received: by 10.195.13.197 with SMTP id fa5mr6263956wjd.41.1423041955165; Wed, 04 Feb 2015 01:25:55 -0800 (PST) Received: from glumotte.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id a13sm2346491wic.3.2015.02.04.01.25.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Feb 2015 01:25:54 -0800 (PST) From: Olivier Matz To: dev@dpdk.org Date: Wed, 4 Feb 2015 10:25:15 +0100 Message-Id: <1423041925-26956-11-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1423041925-26956-1-git-send-email-olivier.matz@6wind.com> References: <1422623775-8050-1-git-send-email-olivier.matz@6wind.com> <1423041925-26956-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v2 10/20] 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 */